]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-2.9.1-3.11.1-201309162121.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.11.1-201309162121.patch
CommitLineData
9610710c
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..a9e5b3b 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
3368@@ -155,7 +155,7 @@ out:
3369 return n;
3370 }
3371
3372-unsigned long __clear_user(void __user *addr, unsigned long n)
3373+unsigned long ___clear_user(void __user *addr, unsigned long n)
3374 {
3375 /* See rational for this in __copy_to_user() above. */
3376 if (n < 64)
3377diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
3378index e9238b5..6ed904a 100644
3379--- a/arch/arm/mach-kirkwood/common.c
3380+++ b/arch/arm/mach-kirkwood/common.c
3381@@ -150,7 +150,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
3382 clk_gate_ops.disable(hw);
3383 }
3384
3385-static struct clk_ops clk_gate_fn_ops;
3386+static int clk_gate_fn_is_enabled(struct clk_hw *hw)
3387+{
3388+ return clk_gate_ops.is_enabled(hw);
3389+}
3390+
3391+static struct clk_ops clk_gate_fn_ops = {
3392+ .enable = clk_gate_fn_enable,
3393+ .disable = clk_gate_fn_disable,
3394+ .is_enabled = clk_gate_fn_is_enabled,
3395+};
3396
3397 static struct clk __init *clk_register_gate_fn(struct device *dev,
3398 const char *name,
3399@@ -184,14 +193,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
3400 gate_fn->fn_en = fn_en;
3401 gate_fn->fn_dis = fn_dis;
3402
3403- /* ops is the gate ops, but with our enable/disable functions */
3404- if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
3405- clk_gate_fn_ops.disable != clk_gate_fn_disable) {
3406- clk_gate_fn_ops = clk_gate_ops;
3407- clk_gate_fn_ops.enable = clk_gate_fn_enable;
3408- clk_gate_fn_ops.disable = clk_gate_fn_disable;
3409- }
3410-
3411 clk = clk_register(dev, &gate_fn->gate.hw);
3412
3413 if (IS_ERR(clk))
3414diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3415index 827d1500..2885dc6 100644
3416--- a/arch/arm/mach-omap2/board-n8x0.c
3417+++ b/arch/arm/mach-omap2/board-n8x0.c
3418@@ -627,7 +627,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3419 }
3420 #endif
3421
3422-static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3423+static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3424 .late_init = n8x0_menelaus_late_init,
3425 };
3426
3427diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
3428index f3fdd6a..3564800 100644
3429--- a/arch/arm/mach-omap2/gpmc.c
3430+++ b/arch/arm/mach-omap2/gpmc.c
3431@@ -148,7 +148,6 @@ struct omap3_gpmc_regs {
3432 };
3433
3434 static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
3435-static struct irq_chip gpmc_irq_chip;
3436 static unsigned gpmc_irq_start;
3437
3438 static struct resource gpmc_mem_root;
3439@@ -716,6 +715,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
3440
3441 static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
3442
3443+static struct irq_chip gpmc_irq_chip = {
3444+ .name = "gpmc",
3445+ .irq_startup = gpmc_irq_noop_ret,
3446+ .irq_enable = gpmc_irq_enable,
3447+ .irq_disable = gpmc_irq_disable,
3448+ .irq_shutdown = gpmc_irq_noop,
3449+ .irq_ack = gpmc_irq_noop,
3450+ .irq_mask = gpmc_irq_noop,
3451+ .irq_unmask = gpmc_irq_noop,
3452+
3453+};
3454+
3455 static int gpmc_setup_irq(void)
3456 {
3457 int i;
3458@@ -730,15 +741,6 @@ static int gpmc_setup_irq(void)
3459 return gpmc_irq_start;
3460 }
3461
3462- gpmc_irq_chip.name = "gpmc";
3463- gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
3464- gpmc_irq_chip.irq_enable = gpmc_irq_enable;
3465- gpmc_irq_chip.irq_disable = gpmc_irq_disable;
3466- gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
3467- gpmc_irq_chip.irq_ack = gpmc_irq_noop;
3468- gpmc_irq_chip.irq_mask = gpmc_irq_noop;
3469- gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
3470-
3471 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
3472 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
3473
3474diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3475index 813c615..ce467c6 100644
3476--- a/arch/arm/mach-omap2/omap-wakeupgen.c
3477+++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3478@@ -339,7 +339,7 @@ static int irq_cpu_hotplug_notify(struct notifier_block *self,
3479 return NOTIFY_OK;
3480 }
3481
3482-static struct notifier_block __refdata irq_hotplug_notifier = {
3483+static struct notifier_block irq_hotplug_notifier = {
3484 .notifier_call = irq_cpu_hotplug_notify,
3485 };
3486
3487diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
3488index f99f68e..e573e20 100644
3489--- a/arch/arm/mach-omap2/omap_device.c
3490+++ b/arch/arm/mach-omap2/omap_device.c
3491@@ -504,7 +504,7 @@ void omap_device_delete(struct omap_device *od)
3492 struct platform_device __init *omap_device_build(const char *pdev_name,
3493 int pdev_id,
3494 struct omap_hwmod *oh,
3495- void *pdata, int pdata_len)
3496+ const void *pdata, int pdata_len)
3497 {
3498 struct omap_hwmod *ohs[] = { oh };
3499
3500@@ -532,7 +532,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name,
3501 struct platform_device __init *omap_device_build_ss(const char *pdev_name,
3502 int pdev_id,
3503 struct omap_hwmod **ohs,
3504- int oh_cnt, void *pdata,
3505+ int oh_cnt, const void *pdata,
3506 int pdata_len)
3507 {
3508 int ret = -ENOMEM;
3509diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
3510index 17ca1ae..beba869 100644
3511--- a/arch/arm/mach-omap2/omap_device.h
3512+++ b/arch/arm/mach-omap2/omap_device.h
3513@@ -71,12 +71,12 @@ int omap_device_idle(struct platform_device *pdev);
3514 /* Core code interface */
3515
3516 struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
3517- struct omap_hwmod *oh, void *pdata,
3518+ struct omap_hwmod *oh, const void *pdata,
3519 int pdata_len);
3520
3521 struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
3522 struct omap_hwmod **oh, int oh_cnt,
3523- void *pdata, int pdata_len);
3524+ const void *pdata, int pdata_len);
3525
3526 struct omap_device *omap_device_alloc(struct platform_device *pdev,
3527 struct omap_hwmod **ohs, int oh_cnt);
3528diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3529index 7f4db12..0243012 100644
3530--- a/arch/arm/mach-omap2/omap_hwmod.c
3531+++ b/arch/arm/mach-omap2/omap_hwmod.c
3532@@ -194,10 +194,10 @@ struct omap_hwmod_soc_ops {
3533 int (*init_clkdm)(struct omap_hwmod *oh);
3534 void (*update_context_lost)(struct omap_hwmod *oh);
3535 int (*get_context_lost)(struct omap_hwmod *oh);
3536-};
3537+} __no_const;
3538
3539 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3540-static struct omap_hwmod_soc_ops soc_ops;
3541+static struct omap_hwmod_soc_ops soc_ops __read_only;
3542
3543 /* omap_hwmod_list contains all registered struct omap_hwmods */
3544 static LIST_HEAD(omap_hwmod_list);
3545diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
3546index d15c7bb..b2d1f0c 100644
3547--- a/arch/arm/mach-omap2/wd_timer.c
3548+++ b/arch/arm/mach-omap2/wd_timer.c
3549@@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
3550 struct omap_hwmod *oh;
3551 char *oh_name = "wd_timer2";
3552 char *dev_name = "omap_wdt";
3553- struct omap_wd_timer_platform_data pdata;
3554+ static struct omap_wd_timer_platform_data pdata = {
3555+ .read_reset_sources = prm_read_reset_sources
3556+ };
3557
3558 if (!cpu_class_is_omap2() || of_have_populated_dt())
3559 return 0;
3560@@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
3561 return -EINVAL;
3562 }
3563
3564- pdata.read_reset_sources = prm_read_reset_sources;
3565-
3566 pdev = omap_device_build(dev_name, id, oh, &pdata,
3567 sizeof(struct omap_wd_timer_platform_data));
3568 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
3569diff --git a/arch/arm/mach-tegra/cpuidle-tegra20.c b/arch/arm/mach-tegra/cpuidle-tegra20.c
3570index 706aa42..f85e9131 100644
3571--- a/arch/arm/mach-tegra/cpuidle-tegra20.c
3572+++ b/arch/arm/mach-tegra/cpuidle-tegra20.c
3573@@ -180,7 +180,7 @@ static int tegra20_idle_lp2_coupled(struct cpuidle_device *dev,
3574 bool entered_lp2 = false;
3575
3576 if (tegra_pending_sgi())
3577- ACCESS_ONCE(abort_flag) = true;
3578+ ACCESS_ONCE_RW(abort_flag) = true;
3579
3580 cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
3581
3582diff --git a/arch/arm/mach-ux500/setup.h b/arch/arm/mach-ux500/setup.h
3583index cad3ca86..1d79e0f 100644
3584--- a/arch/arm/mach-ux500/setup.h
3585+++ b/arch/arm/mach-ux500/setup.h
3586@@ -37,13 +37,6 @@ extern void ux500_timer_init(void);
3587 .type = MT_DEVICE, \
3588 }
3589
3590-#define __MEM_DEV_DESC(x, sz) { \
3591- .virtual = IO_ADDRESS(x), \
3592- .pfn = __phys_to_pfn(x), \
3593- .length = sz, \
3594- .type = MT_MEMORY, \
3595-}
3596-
3597 extern struct smp_operations ux500_smp_ops;
3598 extern void ux500_cpu_die(unsigned int cpu);
3599
3600diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3601index cd2c88e..7430282 100644
3602--- a/arch/arm/mm/Kconfig
3603+++ b/arch/arm/mm/Kconfig
3604@@ -446,7 +446,7 @@ config CPU_32v5
3605
3606 config CPU_32v6
3607 bool
3608- select CPU_USE_DOMAINS if CPU_V6 && MMU
3609+ select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3610 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3611
3612 config CPU_32v6K
3613@@ -601,6 +601,7 @@ config CPU_CP15_MPU
3614
3615 config CPU_USE_DOMAINS
3616 bool
3617+ depends on !ARM_LPAE && !PAX_KERNEXEC
3618 help
3619 This option enables or disables the use of domain switching
3620 via the set_fs() function.
3621@@ -800,6 +801,7 @@ config NEED_KUSER_HELPERS
3622 config KUSER_HELPERS
3623 bool "Enable kuser helpers in vector page" if !NEED_KUSER_HELPERS
3624 default y
3625+ depends on !(CPU_V6 || CPU_V6K || CPU_V7)
3626 help
3627 Warning: disabling this option may break user programs.
3628
3629@@ -812,7 +814,7 @@ config KUSER_HELPERS
3630 See Documentation/arm/kernel_user_helpers.txt for details.
3631
3632 However, the fixed address nature of these helpers can be used
3633- by ROP (return orientated programming) authors when creating
3634+ by ROP (Return Oriented Programming) authors when creating
3635 exploits.
3636
3637 If all of the binaries and libraries which run on your platform
3638diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
3639index 6f4585b..7b6f52b 100644
3640--- a/arch/arm/mm/alignment.c
3641+++ b/arch/arm/mm/alignment.c
3642@@ -211,10 +211,12 @@ union offset_union {
3643 #define __get16_unaligned_check(ins,val,addr) \
3644 do { \
3645 unsigned int err = 0, v, a = addr; \
3646+ pax_open_userland(); \
3647 __get8_unaligned_check(ins,v,a,err); \
3648 val = v << ((BE) ? 8 : 0); \
3649 __get8_unaligned_check(ins,v,a,err); \
3650 val |= v << ((BE) ? 0 : 8); \
3651+ pax_close_userland(); \
3652 if (err) \
3653 goto fault; \
3654 } while (0)
3655@@ -228,6 +230,7 @@ union offset_union {
3656 #define __get32_unaligned_check(ins,val,addr) \
3657 do { \
3658 unsigned int err = 0, v, a = addr; \
3659+ pax_open_userland(); \
3660 __get8_unaligned_check(ins,v,a,err); \
3661 val = v << ((BE) ? 24 : 0); \
3662 __get8_unaligned_check(ins,v,a,err); \
3663@@ -236,6 +239,7 @@ union offset_union {
3664 val |= v << ((BE) ? 8 : 16); \
3665 __get8_unaligned_check(ins,v,a,err); \
3666 val |= v << ((BE) ? 0 : 24); \
3667+ pax_close_userland(); \
3668 if (err) \
3669 goto fault; \
3670 } while (0)
3671@@ -249,6 +253,7 @@ union offset_union {
3672 #define __put16_unaligned_check(ins,val,addr) \
3673 do { \
3674 unsigned int err = 0, v = val, a = addr; \
3675+ pax_open_userland(); \
3676 __asm__( FIRST_BYTE_16 \
3677 ARM( "1: "ins" %1, [%2], #1\n" ) \
3678 THUMB( "1: "ins" %1, [%2]\n" ) \
3679@@ -268,6 +273,7 @@ union offset_union {
3680 " .popsection\n" \
3681 : "=r" (err), "=&r" (v), "=&r" (a) \
3682 : "0" (err), "1" (v), "2" (a)); \
3683+ pax_close_userland(); \
3684 if (err) \
3685 goto fault; \
3686 } while (0)
3687@@ -281,6 +287,7 @@ union offset_union {
3688 #define __put32_unaligned_check(ins,val,addr) \
3689 do { \
3690 unsigned int err = 0, v = val, a = addr; \
3691+ pax_open_userland(); \
3692 __asm__( FIRST_BYTE_32 \
3693 ARM( "1: "ins" %1, [%2], #1\n" ) \
3694 THUMB( "1: "ins" %1, [%2]\n" ) \
3695@@ -310,6 +317,7 @@ union offset_union {
3696 " .popsection\n" \
3697 : "=r" (err), "=&r" (v), "=&r" (a) \
3698 : "0" (err), "1" (v), "2" (a)); \
3699+ pax_close_userland(); \
3700 if (err) \
3701 goto fault; \
3702 } while (0)
3703diff --git a/arch/arm/mm/context.c b/arch/arm/mm/context.c
3704index 4a05444..d21968c 100644
3705--- a/arch/arm/mm/context.c
3706+++ b/arch/arm/mm/context.c
3707@@ -43,7 +43,7 @@
3708 #define NUM_USER_ASIDS ASID_FIRST_VERSION
3709
3710 static DEFINE_RAW_SPINLOCK(cpu_asid_lock);
3711-static atomic64_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3712+static atomic64_unchecked_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3713 static DECLARE_BITMAP(asid_map, NUM_USER_ASIDS);
3714
3715 static DEFINE_PER_CPU(atomic64_t, active_asids);
3716@@ -183,7 +183,7 @@ static int is_reserved_asid(u64 asid)
3717 static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3718 {
3719 u64 asid = atomic64_read(&mm->context.id);
3720- u64 generation = atomic64_read(&asid_generation);
3721+ u64 generation = atomic64_read_unchecked(&asid_generation);
3722
3723 if (asid != 0 && is_reserved_asid(asid)) {
3724 /*
3725@@ -201,7 +201,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3726 */
3727 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3728 if (asid == NUM_USER_ASIDS) {
3729- generation = atomic64_add_return(ASID_FIRST_VERSION,
3730+ generation = atomic64_add_return_unchecked(ASID_FIRST_VERSION,
3731 &asid_generation);
3732 flush_context(cpu);
3733 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3734@@ -230,14 +230,14 @@ void check_and_switch_context(struct mm_struct *mm, struct task_struct *tsk)
3735 cpu_set_reserved_ttbr0();
3736
3737 asid = atomic64_read(&mm->context.id);
3738- if (!((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS)
3739+ if (!((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS)
3740 && atomic64_xchg(&per_cpu(active_asids, cpu), asid))
3741 goto switch_mm_fastpath;
3742
3743 raw_spin_lock_irqsave(&cpu_asid_lock, flags);
3744 /* Check that our ASID belongs to the current generation. */
3745 asid = atomic64_read(&mm->context.id);
3746- if ((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS) {
3747+ if ((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS) {
3748 asid = new_context(mm, cpu);
3749 atomic64_set(&mm->context.id, asid);
3750 }
3751diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
3752index c97f794..e5aeea5 100644
3753--- a/arch/arm/mm/fault.c
3754+++ b/arch/arm/mm/fault.c
3755@@ -25,6 +25,7 @@
3756 #include <asm/system_misc.h>
3757 #include <asm/system_info.h>
3758 #include <asm/tlbflush.h>
3759+#include <asm/sections.h>
3760
3761 #include "fault.h"
3762
3763@@ -138,6 +139,20 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
3764 if (fixup_exception(regs))
3765 return;
3766
3767+#ifdef CONFIG_PAX_KERNEXEC
3768+ if ((fsr & FSR_WRITE) &&
3769+ (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
3770+ (MODULES_VADDR <= addr && addr < MODULES_END)))
3771+ {
3772+ if (current->signal->curr_ip)
3773+ 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),
3774+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3775+ else
3776+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
3777+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3778+ }
3779+#endif
3780+
3781 /*
3782 * No handler, we'll have to terminate things with extreme prejudice.
3783 */
3784@@ -174,6 +189,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
3785 }
3786 #endif
3787
3788+#ifdef CONFIG_PAX_PAGEEXEC
3789+ if (fsr & FSR_LNX_PF) {
3790+ pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
3791+ do_group_exit(SIGKILL);
3792+ }
3793+#endif
3794+
3795 tsk->thread.address = addr;
3796 tsk->thread.error_code = fsr;
3797 tsk->thread.trap_no = 14;
3798@@ -398,6 +420,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3799 }
3800 #endif /* CONFIG_MMU */
3801
3802+#ifdef CONFIG_PAX_PAGEEXEC
3803+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3804+{
3805+ long i;
3806+
3807+ printk(KERN_ERR "PAX: bytes at PC: ");
3808+ for (i = 0; i < 20; i++) {
3809+ unsigned char c;
3810+ if (get_user(c, (__force unsigned char __user *)pc+i))
3811+ printk(KERN_CONT "?? ");
3812+ else
3813+ printk(KERN_CONT "%02x ", c);
3814+ }
3815+ printk("\n");
3816+
3817+ printk(KERN_ERR "PAX: bytes at SP-4: ");
3818+ for (i = -1; i < 20; i++) {
3819+ unsigned long c;
3820+ if (get_user(c, (__force unsigned long __user *)sp+i))
3821+ printk(KERN_CONT "???????? ");
3822+ else
3823+ printk(KERN_CONT "%08lx ", c);
3824+ }
3825+ printk("\n");
3826+}
3827+#endif
3828+
3829 /*
3830 * First Level Translation Fault Handler
3831 *
3832@@ -545,9 +594,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3833 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
3834 struct siginfo info;
3835
3836+#ifdef CONFIG_PAX_MEMORY_UDEREF
3837+ if (addr < TASK_SIZE && is_domain_fault(fsr)) {
3838+ if (current->signal->curr_ip)
3839+ 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),
3840+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3841+ else
3842+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3843+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3844+ goto die;
3845+ }
3846+#endif
3847+
3848 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
3849 return;
3850
3851+die:
3852 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
3853 inf->name, fsr, addr);
3854
3855@@ -571,15 +633,68 @@ hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int, struct pt_regs *
3856 ifsr_info[nr].name = name;
3857 }
3858
3859+asmlinkage int sys_sigreturn(struct pt_regs *regs);
3860+asmlinkage int sys_rt_sigreturn(struct pt_regs *regs);
3861+
3862 asmlinkage void __exception
3863 do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
3864 {
3865 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
3866 struct siginfo info;
3867+ unsigned long pc = instruction_pointer(regs);
3868+
3869+ if (user_mode(regs)) {
3870+ unsigned long sigpage = current->mm->context.sigpage;
3871+
3872+ if (sigpage <= pc && pc < sigpage + 7*4) {
3873+ if (pc < sigpage + 3*4)
3874+ sys_sigreturn(regs);
3875+ else
3876+ sys_rt_sigreturn(regs);
3877+ return;
3878+ }
3879+ if (pc == 0xffff0fe0UL) {
3880+ /*
3881+ * PaX: __kuser_get_tls emulation
3882+ */
3883+ regs->ARM_r0 = current_thread_info()->tp_value;
3884+ regs->ARM_pc = regs->ARM_lr;
3885+ return;
3886+ }
3887+ }
3888+
3889+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3890+ else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
3891+ if (current->signal->curr_ip)
3892+ 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),
3893+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
3894+ pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
3895+ else
3896+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
3897+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
3898+ pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
3899+ goto die;
3900+ }
3901+#endif
3902+
3903+#ifdef CONFIG_PAX_REFCOUNT
3904+ if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
3905+ unsigned int bkpt;
3906+
3907+ if (!probe_kernel_address(pc, bkpt) && cpu_to_le32(bkpt) == 0xe12f1073) {
3908+ current->thread.error_code = ifsr;
3909+ current->thread.trap_no = 0;
3910+ pax_report_refcount_overflow(regs);
3911+ fixup_exception(regs);
3912+ return;
3913+ }
3914+ }
3915+#endif
3916
3917 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
3918 return;
3919
3920+die:
3921 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
3922 inf->name, ifsr, addr);
3923
3924diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
3925index cf08bdf..772656c 100644
3926--- a/arch/arm/mm/fault.h
3927+++ b/arch/arm/mm/fault.h
3928@@ -3,6 +3,7 @@
3929
3930 /*
3931 * Fault status register encodings. We steal bit 31 for our own purposes.
3932+ * Set when the FSR value is from an instruction fault.
3933 */
3934 #define FSR_LNX_PF (1 << 31)
3935 #define FSR_WRITE (1 << 11)
3936@@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
3937 }
3938 #endif
3939
3940+/* valid for LPAE and !LPAE */
3941+static inline int is_xn_fault(unsigned int fsr)
3942+{
3943+ return ((fsr_fs(fsr) & 0x3c) == 0xc);
3944+}
3945+
3946+static inline int is_domain_fault(unsigned int fsr)
3947+{
3948+ return ((fsr_fs(fsr) & 0xD) == 0x9);
3949+}
3950+
3951 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
3952 unsigned long search_exception_table(unsigned long addr);
3953
3954diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
3955index 15225d8..25e2e3c 100644
3956--- a/arch/arm/mm/init.c
3957+++ b/arch/arm/mm/init.c
3958@@ -30,6 +30,8 @@
3959 #include <asm/setup.h>
3960 #include <asm/tlb.h>
3961 #include <asm/fixmap.h>
3962+#include <asm/system_info.h>
3963+#include <asm/cp15.h>
3964
3965 #include <asm/mach/arch.h>
3966 #include <asm/mach/map.h>
3967@@ -683,7 +685,46 @@ void free_initmem(void)
3968 {
3969 #ifdef CONFIG_HAVE_TCM
3970 extern char __tcm_start, __tcm_end;
3971+#endif
3972
3973+#ifdef CONFIG_PAX_KERNEXEC
3974+ unsigned long addr;
3975+ pgd_t *pgd;
3976+ pud_t *pud;
3977+ pmd_t *pmd;
3978+ int cpu_arch = cpu_architecture();
3979+ unsigned int cr = get_cr();
3980+
3981+ if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
3982+ /* make pages tables, etc before .text NX */
3983+ for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
3984+ pgd = pgd_offset_k(addr);
3985+ pud = pud_offset(pgd, addr);
3986+ pmd = pmd_offset(pud, addr);
3987+ __section_update(pmd, addr, PMD_SECT_XN);
3988+ }
3989+ /* make init NX */
3990+ for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
3991+ pgd = pgd_offset_k(addr);
3992+ pud = pud_offset(pgd, addr);
3993+ pmd = pmd_offset(pud, addr);
3994+ __section_update(pmd, addr, PMD_SECT_XN);
3995+ }
3996+ /* make kernel code/rodata RX */
3997+ for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
3998+ pgd = pgd_offset_k(addr);
3999+ pud = pud_offset(pgd, addr);
4000+ pmd = pmd_offset(pud, addr);
4001+#ifdef CONFIG_ARM_LPAE
4002+ __section_update(pmd, addr, PMD_SECT_RDONLY);
4003+#else
4004+ __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
4005+#endif
4006+ }
4007+ }
4008+#endif
4009+
4010+#ifdef CONFIG_HAVE_TCM
4011 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
4012 free_reserved_area(&__tcm_start, &__tcm_end, -1, "TCM link");
4013 #endif
4014diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
4015index f123d6e..04bf569 100644
4016--- a/arch/arm/mm/ioremap.c
4017+++ b/arch/arm/mm/ioremap.c
4018@@ -392,9 +392,9 @@ __arm_ioremap_exec(phys_addr_t phys_addr, size_t size, bool cached)
4019 unsigned int mtype;
4020
4021 if (cached)
4022- mtype = MT_MEMORY;
4023+ mtype = MT_MEMORY_RX;
4024 else
4025- mtype = MT_MEMORY_NONCACHED;
4026+ mtype = MT_MEMORY_NONCACHED_RX;
4027
4028 return __arm_ioremap_caller(phys_addr, size, mtype,
4029 __builtin_return_address(0));
4030diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
4031index 0c63562..7128a90 100644
4032--- a/arch/arm/mm/mmap.c
4033+++ b/arch/arm/mm/mmap.c
4034@@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4035 struct vm_area_struct *vma;
4036 int do_align = 0;
4037 int aliasing = cache_is_vipt_aliasing();
4038+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4039 struct vm_unmapped_area_info info;
4040
4041 /*
4042@@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4043 if (len > TASK_SIZE)
4044 return -ENOMEM;
4045
4046+#ifdef CONFIG_PAX_RANDMMAP
4047+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4048+#endif
4049+
4050 if (addr) {
4051 if (do_align)
4052 addr = COLOUR_ALIGN(addr, pgoff);
4053@@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4054 addr = PAGE_ALIGN(addr);
4055
4056 vma = find_vma(mm, addr);
4057- if (TASK_SIZE - len >= addr &&
4058- (!vma || addr + len <= vma->vm_start))
4059+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4060 return addr;
4061 }
4062
4063@@ -99,6 +103,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4064 info.high_limit = TASK_SIZE;
4065 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4066 info.align_offset = pgoff << PAGE_SHIFT;
4067+ info.threadstack_offset = offset;
4068 return vm_unmapped_area(&info);
4069 }
4070
4071@@ -112,6 +117,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4072 unsigned long addr = addr0;
4073 int do_align = 0;
4074 int aliasing = cache_is_vipt_aliasing();
4075+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4076 struct vm_unmapped_area_info info;
4077
4078 /*
4079@@ -132,6 +138,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4080 return addr;
4081 }
4082
4083+#ifdef CONFIG_PAX_RANDMMAP
4084+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4085+#endif
4086+
4087 /* requesting a specific address */
4088 if (addr) {
4089 if (do_align)
4090@@ -139,8 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4091 else
4092 addr = PAGE_ALIGN(addr);
4093 vma = find_vma(mm, addr);
4094- if (TASK_SIZE - len >= addr &&
4095- (!vma || addr + len <= vma->vm_start))
4096+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4097 return addr;
4098 }
4099
4100@@ -150,6 +159,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4101 info.high_limit = mm->mmap_base;
4102 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4103 info.align_offset = pgoff << PAGE_SHIFT;
4104+ info.threadstack_offset = offset;
4105 addr = vm_unmapped_area(&info);
4106
4107 /*
4108@@ -173,6 +183,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4109 {
4110 unsigned long random_factor = 0UL;
4111
4112+#ifdef CONFIG_PAX_RANDMMAP
4113+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4114+#endif
4115+
4116 /* 8 bits of randomness in 20 address space bits */
4117 if ((current->flags & PF_RANDOMIZE) &&
4118 !(current->personality & ADDR_NO_RANDOMIZE))
4119@@ -180,9 +194,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4120
4121 if (mmap_is_legacy()) {
4122 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4123+
4124+#ifdef CONFIG_PAX_RANDMMAP
4125+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4126+ mm->mmap_base += mm->delta_mmap;
4127+#endif
4128+
4129 mm->get_unmapped_area = arch_get_unmapped_area;
4130 } else {
4131 mm->mmap_base = mmap_base(random_factor);
4132+
4133+#ifdef CONFIG_PAX_RANDMMAP
4134+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4135+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4136+#endif
4137+
4138 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4139 }
4140 }
4141diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
4142index 53cdbd3..670f177 100644
4143--- a/arch/arm/mm/mmu.c
4144+++ b/arch/arm/mm/mmu.c
4145@@ -36,6 +36,22 @@
4146 #include "mm.h"
4147 #include "tcm.h"
4148
4149+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4150+void modify_domain(unsigned int dom, unsigned int type)
4151+{
4152+ struct thread_info *thread = current_thread_info();
4153+ unsigned int domain = thread->cpu_domain;
4154+ /*
4155+ * DOMAIN_MANAGER might be defined to some other value,
4156+ * use the arch-defined constant
4157+ */
4158+ domain &= ~domain_val(dom, 3);
4159+ thread->cpu_domain = domain | domain_val(dom, type);
4160+ set_domain(thread->cpu_domain);
4161+}
4162+EXPORT_SYMBOL(modify_domain);
4163+#endif
4164+
4165 /*
4166 * empty_zero_page is a special page that is used for
4167 * zero-initialized data and COW.
4168@@ -228,10 +244,18 @@ __setup("noalign", noalign_setup);
4169
4170 #endif /* ifdef CONFIG_CPU_CP15 / else */
4171
4172-#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY|L_PTE_XN
4173+#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY
4174 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
4175
4176-static struct mem_type mem_types[] = {
4177+#ifdef CONFIG_PAX_KERNEXEC
4178+#define L_PTE_KERNEXEC L_PTE_RDONLY
4179+#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
4180+#else
4181+#define L_PTE_KERNEXEC L_PTE_DIRTY
4182+#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
4183+#endif
4184+
4185+static struct mem_type mem_types[] __read_only = {
4186 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
4187 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
4188 L_PTE_SHARED,
4189@@ -260,16 +284,16 @@ static struct mem_type mem_types[] = {
4190 [MT_UNCACHED] = {
4191 .prot_pte = PROT_PTE_DEVICE,
4192 .prot_l1 = PMD_TYPE_TABLE,
4193- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4194+ .prot_sect = PROT_SECT_DEVICE,
4195 .domain = DOMAIN_IO,
4196 },
4197 [MT_CACHECLEAN] = {
4198- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4199+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4200 .domain = DOMAIN_KERNEL,
4201 },
4202 #ifndef CONFIG_ARM_LPAE
4203 [MT_MINICLEAN] = {
4204- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
4205+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_RDONLY,
4206 .domain = DOMAIN_KERNEL,
4207 },
4208 #endif
4209@@ -277,36 +301,54 @@ static struct mem_type mem_types[] = {
4210 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4211 L_PTE_RDONLY,
4212 .prot_l1 = PMD_TYPE_TABLE,
4213- .domain = DOMAIN_USER,
4214+ .domain = DOMAIN_VECTORS,
4215 },
4216 [MT_HIGH_VECTORS] = {
4217 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4218 L_PTE_USER | L_PTE_RDONLY,
4219 .prot_l1 = PMD_TYPE_TABLE,
4220- .domain = DOMAIN_USER,
4221+ .domain = DOMAIN_VECTORS,
4222 },
4223- [MT_MEMORY] = {
4224+ [MT_MEMORY_RWX] = {
4225 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4226 .prot_l1 = PMD_TYPE_TABLE,
4227 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4228 .domain = DOMAIN_KERNEL,
4229 },
4230+ [MT_MEMORY_RW] = {
4231+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4232+ .prot_l1 = PMD_TYPE_TABLE,
4233+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4234+ .domain = DOMAIN_KERNEL,
4235+ },
4236+ [MT_MEMORY_RX] = {
4237+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4238+ .prot_l1 = PMD_TYPE_TABLE,
4239+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4240+ .domain = DOMAIN_KERNEL,
4241+ },
4242 [MT_ROM] = {
4243- .prot_sect = PMD_TYPE_SECT,
4244+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4245 .domain = DOMAIN_KERNEL,
4246 },
4247- [MT_MEMORY_NONCACHED] = {
4248+ [MT_MEMORY_NONCACHED_RW] = {
4249 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4250 L_PTE_MT_BUFFERABLE,
4251 .prot_l1 = PMD_TYPE_TABLE,
4252 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4253 .domain = DOMAIN_KERNEL,
4254 },
4255+ [MT_MEMORY_NONCACHED_RX] = {
4256+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
4257+ L_PTE_MT_BUFFERABLE,
4258+ .prot_l1 = PMD_TYPE_TABLE,
4259+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4260+ .domain = DOMAIN_KERNEL,
4261+ },
4262 [MT_MEMORY_DTCM] = {
4263- .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4264- L_PTE_XN,
4265+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4266 .prot_l1 = PMD_TYPE_TABLE,
4267- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4268+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4269 .domain = DOMAIN_KERNEL,
4270 },
4271 [MT_MEMORY_ITCM] = {
4272@@ -316,10 +358,10 @@ static struct mem_type mem_types[] = {
4273 },
4274 [MT_MEMORY_SO] = {
4275 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4276- L_PTE_MT_UNCACHED | L_PTE_XN,
4277+ L_PTE_MT_UNCACHED,
4278 .prot_l1 = PMD_TYPE_TABLE,
4279 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_SECT_S |
4280- PMD_SECT_UNCACHED | PMD_SECT_XN,
4281+ PMD_SECT_UNCACHED,
4282 .domain = DOMAIN_KERNEL,
4283 },
4284 [MT_MEMORY_DMA_READY] = {
4285@@ -405,9 +447,35 @@ static void __init build_mem_type_table(void)
4286 * to prevent speculative instruction fetches.
4287 */
4288 mem_types[MT_DEVICE].prot_sect |= PMD_SECT_XN;
4289+ mem_types[MT_DEVICE].prot_pte |= L_PTE_XN;
4290 mem_types[MT_DEVICE_NONSHARED].prot_sect |= PMD_SECT_XN;
4291+ mem_types[MT_DEVICE_NONSHARED].prot_pte |= L_PTE_XN;
4292 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_XN;
4293+ mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_XN;
4294 mem_types[MT_DEVICE_WC].prot_sect |= PMD_SECT_XN;
4295+ mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_XN;
4296+
4297+ /* Mark other regions on ARMv6+ as execute-never */
4298+
4299+#ifdef CONFIG_PAX_KERNEXEC
4300+ mem_types[MT_UNCACHED].prot_sect |= PMD_SECT_XN;
4301+ mem_types[MT_UNCACHED].prot_pte |= L_PTE_XN;
4302+ mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_XN;
4303+ mem_types[MT_CACHECLEAN].prot_pte |= L_PTE_XN;
4304+#ifndef CONFIG_ARM_LPAE
4305+ mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_XN;
4306+ mem_types[MT_MINICLEAN].prot_pte |= L_PTE_XN;
4307+#endif
4308+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_XN;
4309+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_XN;
4310+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_XN;
4311+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= PMD_SECT_XN;
4312+ mem_types[MT_MEMORY_DTCM].prot_sect |= PMD_SECT_XN;
4313+ mem_types[MT_MEMORY_DTCM].prot_pte |= L_PTE_XN;
4314+#endif
4315+
4316+ mem_types[MT_MEMORY_SO].prot_sect |= PMD_SECT_XN;
4317+ mem_types[MT_MEMORY_SO].prot_pte |= L_PTE_XN;
4318 }
4319 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4320 /*
4321@@ -468,6 +536,9 @@ static void __init build_mem_type_table(void)
4322 * from SVC mode and no access from userspace.
4323 */
4324 mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4325+#ifdef CONFIG_PAX_KERNEXEC
4326+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4327+#endif
4328 mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4329 mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4330 #endif
4331@@ -485,11 +556,17 @@ static void __init build_mem_type_table(void)
4332 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
4333 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
4334 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
4335- mem_types[MT_MEMORY].prot_sect |= PMD_SECT_S;
4336- mem_types[MT_MEMORY].prot_pte |= L_PTE_SHARED;
4337+ mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4338+ mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4339+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
4340+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
4341+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
4342+ mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
4343 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
4344- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_S;
4345- mem_types[MT_MEMORY_NONCACHED].prot_pte |= L_PTE_SHARED;
4346+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_S;
4347+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= L_PTE_SHARED;
4348+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_S;
4349+ mem_types[MT_MEMORY_NONCACHED_RX].prot_pte |= L_PTE_SHARED;
4350 }
4351 }
4352
4353@@ -500,15 +577,20 @@ static void __init build_mem_type_table(void)
4354 if (cpu_arch >= CPU_ARCH_ARMv6) {
4355 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4356 /* Non-cacheable Normal is XCB = 001 */
4357- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4358+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4359+ PMD_SECT_BUFFERED;
4360+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4361 PMD_SECT_BUFFERED;
4362 } else {
4363 /* For both ARMv6 and non-TEX-remapping ARMv7 */
4364- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4365+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4366+ PMD_SECT_TEX(1);
4367+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4368 PMD_SECT_TEX(1);
4369 }
4370 } else {
4371- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4372+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_BUFFERABLE;
4373+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_BUFFERABLE;
4374 }
4375
4376 #ifdef CONFIG_ARM_LPAE
4377@@ -524,6 +606,8 @@ static void __init build_mem_type_table(void)
4378 vecs_pgprot |= PTE_EXT_AF;
4379 #endif
4380
4381+ user_pgprot |= __supported_pte_mask;
4382+
4383 for (i = 0; i < 16; i++) {
4384 pteval_t v = pgprot_val(protection_map[i]);
4385 protection_map[i] = __pgprot(v | user_pgprot);
4386@@ -541,10 +625,15 @@ static void __init build_mem_type_table(void)
4387
4388 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
4389 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
4390- mem_types[MT_MEMORY].prot_sect |= ecc_mask | cp->pmd;
4391- mem_types[MT_MEMORY].prot_pte |= kern_pgprot;
4392+ mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4393+ mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4394+ mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
4395+ mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
4396+ mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
4397+ mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
4398 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
4399- mem_types[MT_MEMORY_NONCACHED].prot_sect |= ecc_mask;
4400+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= ecc_mask;
4401+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= ecc_mask;
4402 mem_types[MT_ROM].prot_sect |= cp->pmd;
4403
4404 switch (cp->pmd) {
4405@@ -1186,18 +1275,15 @@ void __init arm_mm_memblock_reserve(void)
4406 * called function. This means you can't use any function or debugging
4407 * method which may touch any device, otherwise the kernel _will_ crash.
4408 */
4409+
4410+static char vectors[PAGE_SIZE * 2] __read_only __aligned(PAGE_SIZE);
4411+
4412 static void __init devicemaps_init(struct machine_desc *mdesc)
4413 {
4414 struct map_desc map;
4415 unsigned long addr;
4416- void *vectors;
4417
4418- /*
4419- * Allocate the vector page early.
4420- */
4421- vectors = early_alloc(PAGE_SIZE * 2);
4422-
4423- early_trap_init(vectors);
4424+ early_trap_init(&vectors);
4425
4426 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
4427 pmd_clear(pmd_off_k(addr));
4428@@ -1237,7 +1323,7 @@ static void __init devicemaps_init(struct machine_desc *mdesc)
4429 * location (0xffff0000). If we aren't using high-vectors, also
4430 * create a mapping at the low-vectors virtual address.
4431 */
4432- map.pfn = __phys_to_pfn(virt_to_phys(vectors));
4433+ map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
4434 map.virtual = 0xffff0000;
4435 map.length = PAGE_SIZE;
4436 #ifdef CONFIG_KUSER_HELPERS
4437@@ -1309,8 +1395,39 @@ static void __init map_lowmem(void)
4438 map.pfn = __phys_to_pfn(start);
4439 map.virtual = __phys_to_virt(start);
4440 map.length = end - start;
4441- map.type = MT_MEMORY;
4442
4443+#ifdef CONFIG_PAX_KERNEXEC
4444+ if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
4445+ struct map_desc kernel;
4446+ struct map_desc initmap;
4447+
4448+ /* when freeing initmem we will make this RW */
4449+ initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4450+ initmap.virtual = (unsigned long)__init_begin;
4451+ initmap.length = _sdata - __init_begin;
4452+ initmap.type = MT_MEMORY_RWX;
4453+ create_mapping(&initmap);
4454+
4455+ /* when freeing initmem we will make this RX */
4456+ kernel.pfn = __phys_to_pfn(__pa(_stext));
4457+ kernel.virtual = (unsigned long)_stext;
4458+ kernel.length = __init_begin - _stext;
4459+ kernel.type = MT_MEMORY_RWX;
4460+ create_mapping(&kernel);
4461+
4462+ if (map.virtual < (unsigned long)_stext) {
4463+ map.length = (unsigned long)_stext - map.virtual;
4464+ map.type = MT_MEMORY_RWX;
4465+ create_mapping(&map);
4466+ }
4467+
4468+ map.pfn = __phys_to_pfn(__pa(_sdata));
4469+ map.virtual = (unsigned long)_sdata;
4470+ map.length = end - __pa(_sdata);
4471+ }
4472+#endif
4473+
4474+ map.type = MT_MEMORY_RW;
4475 create_mapping(&map);
4476 }
4477 }
4478diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4479index a5bc92d..0bb4730 100644
4480--- a/arch/arm/plat-omap/sram.c
4481+++ b/arch/arm/plat-omap/sram.c
4482@@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4483 * Looks like we need to preserve some bootloader code at the
4484 * beginning of SRAM for jumping to flash for reboot to work...
4485 */
4486+ pax_open_kernel();
4487 memset_io(omap_sram_base + omap_sram_skip, 0,
4488 omap_sram_size - omap_sram_skip);
4489+ pax_close_kernel();
4490 }
4491diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4492index ce6d763..cfea917 100644
4493--- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4494+++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4495@@ -47,7 +47,7 @@ struct samsung_dma_ops {
4496 int (*started)(unsigned ch);
4497 int (*flush)(unsigned ch);
4498 int (*stop)(unsigned ch);
4499-};
4500+} __no_const;
4501
4502 extern void *samsung_dmadev_get_ops(void);
4503 extern void *s3c_dma_get_ops(void);
4504diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4505index c3a58a1..78fbf54 100644
4506--- a/arch/avr32/include/asm/cache.h
4507+++ b/arch/avr32/include/asm/cache.h
4508@@ -1,8 +1,10 @@
4509 #ifndef __ASM_AVR32_CACHE_H
4510 #define __ASM_AVR32_CACHE_H
4511
4512+#include <linux/const.h>
4513+
4514 #define L1_CACHE_SHIFT 5
4515-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4516+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4517
4518 /*
4519 * Memory returned by kmalloc() may be used for DMA, so we must make
4520diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4521index d232888..87c8df1 100644
4522--- a/arch/avr32/include/asm/elf.h
4523+++ b/arch/avr32/include/asm/elf.h
4524@@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4525 the loader. We need to make sure that it is out of the way of the program
4526 that it will "exec", and that there is sufficient room for the brk. */
4527
4528-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4529+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4530
4531+#ifdef CONFIG_PAX_ASLR
4532+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4533+
4534+#define PAX_DELTA_MMAP_LEN 15
4535+#define PAX_DELTA_STACK_LEN 15
4536+#endif
4537
4538 /* This yields a mask that user programs can use to figure out what
4539 instruction set this CPU supports. This could be done in user space,
4540diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4541index 479330b..53717a8 100644
4542--- a/arch/avr32/include/asm/kmap_types.h
4543+++ b/arch/avr32/include/asm/kmap_types.h
4544@@ -2,9 +2,9 @@
4545 #define __ASM_AVR32_KMAP_TYPES_H
4546
4547 #ifdef CONFIG_DEBUG_HIGHMEM
4548-# define KM_TYPE_NR 29
4549+# define KM_TYPE_NR 30
4550 #else
4551-# define KM_TYPE_NR 14
4552+# define KM_TYPE_NR 15
4553 #endif
4554
4555 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4556diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4557index b2f2d2d..d1c85cb 100644
4558--- a/arch/avr32/mm/fault.c
4559+++ b/arch/avr32/mm/fault.c
4560@@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4561
4562 int exception_trace = 1;
4563
4564+#ifdef CONFIG_PAX_PAGEEXEC
4565+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4566+{
4567+ unsigned long i;
4568+
4569+ printk(KERN_ERR "PAX: bytes at PC: ");
4570+ for (i = 0; i < 20; i++) {
4571+ unsigned char c;
4572+ if (get_user(c, (unsigned char *)pc+i))
4573+ printk(KERN_CONT "???????? ");
4574+ else
4575+ printk(KERN_CONT "%02x ", c);
4576+ }
4577+ printk("\n");
4578+}
4579+#endif
4580+
4581 /*
4582 * This routine handles page faults. It determines the address and the
4583 * problem, and then passes it off to one of the appropriate routines.
4584@@ -174,6 +191,16 @@ bad_area:
4585 up_read(&mm->mmap_sem);
4586
4587 if (user_mode(regs)) {
4588+
4589+#ifdef CONFIG_PAX_PAGEEXEC
4590+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4591+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
4592+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
4593+ do_group_exit(SIGKILL);
4594+ }
4595+ }
4596+#endif
4597+
4598 if (exception_trace && printk_ratelimit())
4599 printk("%s%s[%d]: segfault at %08lx pc %08lx "
4600 "sp %08lx ecr %lu\n",
4601diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
4602index 568885a..f8008df 100644
4603--- a/arch/blackfin/include/asm/cache.h
4604+++ b/arch/blackfin/include/asm/cache.h
4605@@ -7,6 +7,7 @@
4606 #ifndef __ARCH_BLACKFIN_CACHE_H
4607 #define __ARCH_BLACKFIN_CACHE_H
4608
4609+#include <linux/const.h>
4610 #include <linux/linkage.h> /* for asmlinkage */
4611
4612 /*
4613@@ -14,7 +15,7 @@
4614 * Blackfin loads 32 bytes for cache
4615 */
4616 #define L1_CACHE_SHIFT 5
4617-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4618+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4619 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4620
4621 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4622diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
4623index aea2718..3639a60 100644
4624--- a/arch/cris/include/arch-v10/arch/cache.h
4625+++ b/arch/cris/include/arch-v10/arch/cache.h
4626@@ -1,8 +1,9 @@
4627 #ifndef _ASM_ARCH_CACHE_H
4628 #define _ASM_ARCH_CACHE_H
4629
4630+#include <linux/const.h>
4631 /* Etrax 100LX have 32-byte cache-lines. */
4632-#define L1_CACHE_BYTES 32
4633 #define L1_CACHE_SHIFT 5
4634+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4635
4636 #endif /* _ASM_ARCH_CACHE_H */
4637diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
4638index 7caf25d..ee65ac5 100644
4639--- a/arch/cris/include/arch-v32/arch/cache.h
4640+++ b/arch/cris/include/arch-v32/arch/cache.h
4641@@ -1,11 +1,12 @@
4642 #ifndef _ASM_CRIS_ARCH_CACHE_H
4643 #define _ASM_CRIS_ARCH_CACHE_H
4644
4645+#include <linux/const.h>
4646 #include <arch/hwregs/dma.h>
4647
4648 /* A cache-line is 32 bytes. */
4649-#define L1_CACHE_BYTES 32
4650 #define L1_CACHE_SHIFT 5
4651+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4652
4653 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4654
4655diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
4656index b86329d..6709906 100644
4657--- a/arch/frv/include/asm/atomic.h
4658+++ b/arch/frv/include/asm/atomic.h
4659@@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
4660 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
4661 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
4662
4663+#define atomic64_read_unchecked(v) atomic64_read(v)
4664+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4665+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4666+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4667+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4668+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4669+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4670+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4671+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4672+
4673 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
4674 {
4675 int c, old;
4676diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
4677index 2797163..c2a401d 100644
4678--- a/arch/frv/include/asm/cache.h
4679+++ b/arch/frv/include/asm/cache.h
4680@@ -12,10 +12,11 @@
4681 #ifndef __ASM_CACHE_H
4682 #define __ASM_CACHE_H
4683
4684+#include <linux/const.h>
4685
4686 /* bytes per L1 cache line */
4687 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
4688-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4689+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4690
4691 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4692 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4693diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
4694index 43901f2..0d8b865 100644
4695--- a/arch/frv/include/asm/kmap_types.h
4696+++ b/arch/frv/include/asm/kmap_types.h
4697@@ -2,6 +2,6 @@
4698 #ifndef _ASM_KMAP_TYPES_H
4699 #define _ASM_KMAP_TYPES_H
4700
4701-#define KM_TYPE_NR 17
4702+#define KM_TYPE_NR 18
4703
4704 #endif
4705diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
4706index 836f147..4cf23f5 100644
4707--- a/arch/frv/mm/elf-fdpic.c
4708+++ b/arch/frv/mm/elf-fdpic.c
4709@@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4710 {
4711 struct vm_area_struct *vma;
4712 struct vm_unmapped_area_info info;
4713+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4714
4715 if (len > TASK_SIZE)
4716 return -ENOMEM;
4717@@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4718 if (addr) {
4719 addr = PAGE_ALIGN(addr);
4720 vma = find_vma(current->mm, addr);
4721- if (TASK_SIZE - len >= addr &&
4722- (!vma || addr + len <= vma->vm_start))
4723+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4724 goto success;
4725 }
4726
4727@@ -85,6 +85,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4728 info.high_limit = (current->mm->start_stack - 0x00200000);
4729 info.align_mask = 0;
4730 info.align_offset = 0;
4731+ info.threadstack_offset = offset;
4732 addr = vm_unmapped_area(&info);
4733 if (!(addr & ~PAGE_MASK))
4734 goto success;
4735diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
4736index f4ca594..adc72fd6 100644
4737--- a/arch/hexagon/include/asm/cache.h
4738+++ b/arch/hexagon/include/asm/cache.h
4739@@ -21,9 +21,11 @@
4740 #ifndef __ASM_CACHE_H
4741 #define __ASM_CACHE_H
4742
4743+#include <linux/const.h>
4744+
4745 /* Bytes per L1 cache line */
4746-#define L1_CACHE_SHIFT (5)
4747-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4748+#define L1_CACHE_SHIFT 5
4749+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4750
4751 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
4752 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
4753diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
4754index 6e6fe18..a6ae668 100644
4755--- a/arch/ia64/include/asm/atomic.h
4756+++ b/arch/ia64/include/asm/atomic.h
4757@@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
4758 #define atomic64_inc(v) atomic64_add(1, (v))
4759 #define atomic64_dec(v) atomic64_sub(1, (v))
4760
4761+#define atomic64_read_unchecked(v) atomic64_read(v)
4762+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4763+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4764+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4765+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4766+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4767+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4768+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4769+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4770+
4771 /* Atomic operations are already serializing */
4772 #define smp_mb__before_atomic_dec() barrier()
4773 #define smp_mb__after_atomic_dec() barrier()
4774diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
4775index 988254a..e1ee885 100644
4776--- a/arch/ia64/include/asm/cache.h
4777+++ b/arch/ia64/include/asm/cache.h
4778@@ -1,6 +1,7 @@
4779 #ifndef _ASM_IA64_CACHE_H
4780 #define _ASM_IA64_CACHE_H
4781
4782+#include <linux/const.h>
4783
4784 /*
4785 * Copyright (C) 1998-2000 Hewlett-Packard Co
4786@@ -9,7 +10,7 @@
4787
4788 /* Bytes per L1 (data) cache line. */
4789 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
4790-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4791+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4792
4793 #ifdef CONFIG_SMP
4794 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
4795diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
4796index 5a83c5c..4d7f553 100644
4797--- a/arch/ia64/include/asm/elf.h
4798+++ b/arch/ia64/include/asm/elf.h
4799@@ -42,6 +42,13 @@
4800 */
4801 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
4802
4803+#ifdef CONFIG_PAX_ASLR
4804+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
4805+
4806+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4807+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4808+#endif
4809+
4810 #define PT_IA_64_UNWIND 0x70000001
4811
4812 /* IA-64 relocations: */
4813diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
4814index 96a8d92..617a1cf 100644
4815--- a/arch/ia64/include/asm/pgalloc.h
4816+++ b/arch/ia64/include/asm/pgalloc.h
4817@@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4818 pgd_val(*pgd_entry) = __pa(pud);
4819 }
4820
4821+static inline void
4822+pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4823+{
4824+ pgd_populate(mm, pgd_entry, pud);
4825+}
4826+
4827 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
4828 {
4829 return quicklist_alloc(0, GFP_KERNEL, NULL);
4830@@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4831 pud_val(*pud_entry) = __pa(pmd);
4832 }
4833
4834+static inline void
4835+pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4836+{
4837+ pud_populate(mm, pud_entry, pmd);
4838+}
4839+
4840 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
4841 {
4842 return quicklist_alloc(0, GFP_KERNEL, NULL);
4843diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
4844index 7935115..c0eca6a 100644
4845--- a/arch/ia64/include/asm/pgtable.h
4846+++ b/arch/ia64/include/asm/pgtable.h
4847@@ -12,7 +12,7 @@
4848 * David Mosberger-Tang <davidm@hpl.hp.com>
4849 */
4850
4851-
4852+#include <linux/const.h>
4853 #include <asm/mman.h>
4854 #include <asm/page.h>
4855 #include <asm/processor.h>
4856@@ -142,6 +142,17 @@
4857 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4858 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4859 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
4860+
4861+#ifdef CONFIG_PAX_PAGEEXEC
4862+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
4863+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4864+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4865+#else
4866+# define PAGE_SHARED_NOEXEC PAGE_SHARED
4867+# define PAGE_READONLY_NOEXEC PAGE_READONLY
4868+# define PAGE_COPY_NOEXEC PAGE_COPY
4869+#endif
4870+
4871 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
4872 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
4873 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
4874diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
4875index 54ff557..70c88b7 100644
4876--- a/arch/ia64/include/asm/spinlock.h
4877+++ b/arch/ia64/include/asm/spinlock.h
4878@@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
4879 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
4880
4881 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
4882- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
4883+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
4884 }
4885
4886 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
4887diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
4888index 449c8c0..18965fb 100644
4889--- a/arch/ia64/include/asm/uaccess.h
4890+++ b/arch/ia64/include/asm/uaccess.h
4891@@ -240,12 +240,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
4892 static inline unsigned long
4893 __copy_to_user (void __user *to, const void *from, unsigned long count)
4894 {
4895+ if (count > INT_MAX)
4896+ return count;
4897+
4898+ if (!__builtin_constant_p(count))
4899+ check_object_size(from, count, true);
4900+
4901 return __copy_user(to, (__force void __user *) from, count);
4902 }
4903
4904 static inline unsigned long
4905 __copy_from_user (void *to, const void __user *from, unsigned long count)
4906 {
4907+ if (count > INT_MAX)
4908+ return count;
4909+
4910+ if (!__builtin_constant_p(count))
4911+ check_object_size(to, count, false);
4912+
4913 return __copy_user((__force void __user *) to, from, count);
4914 }
4915
4916@@ -255,10 +267,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
4917 ({ \
4918 void __user *__cu_to = (to); \
4919 const void *__cu_from = (from); \
4920- long __cu_len = (n); \
4921+ unsigned long __cu_len = (n); \
4922 \
4923- if (__access_ok(__cu_to, __cu_len, get_fs())) \
4924+ if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
4925+ if (!__builtin_constant_p(n)) \
4926+ check_object_size(__cu_from, __cu_len, true); \
4927 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
4928+ } \
4929 __cu_len; \
4930 })
4931
4932@@ -266,11 +281,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
4933 ({ \
4934 void *__cu_to = (to); \
4935 const void __user *__cu_from = (from); \
4936- long __cu_len = (n); \
4937+ unsigned long __cu_len = (n); \
4938 \
4939 __chk_user_ptr(__cu_from); \
4940- if (__access_ok(__cu_from, __cu_len, get_fs())) \
4941+ if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
4942+ if (!__builtin_constant_p(n)) \
4943+ check_object_size(__cu_to, __cu_len, false); \
4944 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
4945+ } \
4946 __cu_len; \
4947 })
4948
4949diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
4950index 24603be..948052d 100644
4951--- a/arch/ia64/kernel/module.c
4952+++ b/arch/ia64/kernel/module.c
4953@@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
4954 void
4955 module_free (struct module *mod, void *module_region)
4956 {
4957- if (mod && mod->arch.init_unw_table &&
4958- module_region == mod->module_init) {
4959+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
4960 unw_remove_unwind_table(mod->arch.init_unw_table);
4961 mod->arch.init_unw_table = NULL;
4962 }
4963@@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
4964 }
4965
4966 static inline int
4967+in_init_rx (const struct module *mod, uint64_t addr)
4968+{
4969+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
4970+}
4971+
4972+static inline int
4973+in_init_rw (const struct module *mod, uint64_t addr)
4974+{
4975+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
4976+}
4977+
4978+static inline int
4979 in_init (const struct module *mod, uint64_t addr)
4980 {
4981- return addr - (uint64_t) mod->module_init < mod->init_size;
4982+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
4983+}
4984+
4985+static inline int
4986+in_core_rx (const struct module *mod, uint64_t addr)
4987+{
4988+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
4989+}
4990+
4991+static inline int
4992+in_core_rw (const struct module *mod, uint64_t addr)
4993+{
4994+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
4995 }
4996
4997 static inline int
4998 in_core (const struct module *mod, uint64_t addr)
4999 {
5000- return addr - (uint64_t) mod->module_core < mod->core_size;
5001+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
5002 }
5003
5004 static inline int
5005@@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
5006 break;
5007
5008 case RV_BDREL:
5009- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
5010+ if (in_init_rx(mod, val))
5011+ val -= (uint64_t) mod->module_init_rx;
5012+ else if (in_init_rw(mod, val))
5013+ val -= (uint64_t) mod->module_init_rw;
5014+ else if (in_core_rx(mod, val))
5015+ val -= (uint64_t) mod->module_core_rx;
5016+ else if (in_core_rw(mod, val))
5017+ val -= (uint64_t) mod->module_core_rw;
5018 break;
5019
5020 case RV_LTV:
5021@@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
5022 * addresses have been selected...
5023 */
5024 uint64_t gp;
5025- if (mod->core_size > MAX_LTOFF)
5026+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
5027 /*
5028 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
5029 * at the end of the module.
5030 */
5031- gp = mod->core_size - MAX_LTOFF / 2;
5032+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
5033 else
5034- gp = mod->core_size / 2;
5035- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
5036+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
5037+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
5038 mod->arch.gp = gp;
5039 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
5040 }
5041diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
5042index ab33328..f39506c 100644
5043--- a/arch/ia64/kernel/palinfo.c
5044+++ b/arch/ia64/kernel/palinfo.c
5045@@ -980,7 +980,7 @@ static int palinfo_cpu_callback(struct notifier_block *nfb,
5046 return NOTIFY_OK;
5047 }
5048
5049-static struct notifier_block __refdata palinfo_cpu_notifier =
5050+static struct notifier_block palinfo_cpu_notifier =
5051 {
5052 .notifier_call = palinfo_cpu_callback,
5053 .priority = 0,
5054diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
5055index 41e33f8..65180b2 100644
5056--- a/arch/ia64/kernel/sys_ia64.c
5057+++ b/arch/ia64/kernel/sys_ia64.c
5058@@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5059 unsigned long align_mask = 0;
5060 struct mm_struct *mm = current->mm;
5061 struct vm_unmapped_area_info info;
5062+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5063
5064 if (len > RGN_MAP_LIMIT)
5065 return -ENOMEM;
5066@@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5067 if (REGION_NUMBER(addr) == RGN_HPAGE)
5068 addr = 0;
5069 #endif
5070+
5071+#ifdef CONFIG_PAX_RANDMMAP
5072+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5073+ addr = mm->free_area_cache;
5074+ else
5075+#endif
5076+
5077 if (!addr)
5078 addr = TASK_UNMAPPED_BASE;
5079
5080@@ -61,6 +69,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5081 info.high_limit = TASK_SIZE;
5082 info.align_mask = align_mask;
5083 info.align_offset = 0;
5084+ info.threadstack_offset = offset;
5085 return vm_unmapped_area(&info);
5086 }
5087
5088diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
5089index 0ccb28f..8992469 100644
5090--- a/arch/ia64/kernel/vmlinux.lds.S
5091+++ b/arch/ia64/kernel/vmlinux.lds.S
5092@@ -198,7 +198,7 @@ SECTIONS {
5093 /* Per-cpu data: */
5094 . = ALIGN(PERCPU_PAGE_SIZE);
5095 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
5096- __phys_per_cpu_start = __per_cpu_load;
5097+ __phys_per_cpu_start = per_cpu_load;
5098 /*
5099 * ensure percpu data fits
5100 * into percpu page size
5101diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
5102index 6cf0341..d352594 100644
5103--- a/arch/ia64/mm/fault.c
5104+++ b/arch/ia64/mm/fault.c
5105@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
5106 return pte_present(pte);
5107 }
5108
5109+#ifdef CONFIG_PAX_PAGEEXEC
5110+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5111+{
5112+ unsigned long i;
5113+
5114+ printk(KERN_ERR "PAX: bytes at PC: ");
5115+ for (i = 0; i < 8; i++) {
5116+ unsigned int c;
5117+ if (get_user(c, (unsigned int *)pc+i))
5118+ printk(KERN_CONT "???????? ");
5119+ else
5120+ printk(KERN_CONT "%08x ", c);
5121+ }
5122+ printk("\n");
5123+}
5124+#endif
5125+
5126 # define VM_READ_BIT 0
5127 # define VM_WRITE_BIT 1
5128 # define VM_EXEC_BIT 2
5129@@ -149,8 +166,21 @@ retry:
5130 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
5131 goto bad_area;
5132
5133- if ((vma->vm_flags & mask) != mask)
5134+ if ((vma->vm_flags & mask) != mask) {
5135+
5136+#ifdef CONFIG_PAX_PAGEEXEC
5137+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5138+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5139+ goto bad_area;
5140+
5141+ up_read(&mm->mmap_sem);
5142+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
5143+ do_group_exit(SIGKILL);
5144+ }
5145+#endif
5146+
5147 goto bad_area;
5148+ }
5149
5150 /*
5151 * If for any reason at all we couldn't handle the fault, make
5152diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
5153index 76069c1..c2aa816 100644
5154--- a/arch/ia64/mm/hugetlbpage.c
5155+++ b/arch/ia64/mm/hugetlbpage.c
5156@@ -149,6 +149,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5157 unsigned long pgoff, unsigned long flags)
5158 {
5159 struct vm_unmapped_area_info info;
5160+ unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
5161
5162 if (len > RGN_MAP_LIMIT)
5163 return -ENOMEM;
5164@@ -172,6 +173,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5165 info.high_limit = HPAGE_REGION_BASE + RGN_MAP_LIMIT;
5166 info.align_mask = PAGE_MASK & (HPAGE_SIZE - 1);
5167 info.align_offset = 0;
5168+ info.threadstack_offset = offset;
5169 return vm_unmapped_area(&info);
5170 }
5171
5172diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
5173index b6f7f43..c04320d 100644
5174--- a/arch/ia64/mm/init.c
5175+++ b/arch/ia64/mm/init.c
5176@@ -120,6 +120,19 @@ ia64_init_addr_space (void)
5177 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
5178 vma->vm_end = vma->vm_start + PAGE_SIZE;
5179 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
5180+
5181+#ifdef CONFIG_PAX_PAGEEXEC
5182+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
5183+ vma->vm_flags &= ~VM_EXEC;
5184+
5185+#ifdef CONFIG_PAX_MPROTECT
5186+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
5187+ vma->vm_flags &= ~VM_MAYEXEC;
5188+#endif
5189+
5190+ }
5191+#endif
5192+
5193 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5194 down_write(&current->mm->mmap_sem);
5195 if (insert_vm_struct(current->mm, vma)) {
5196diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
5197index 40b3ee9..8c2c112 100644
5198--- a/arch/m32r/include/asm/cache.h
5199+++ b/arch/m32r/include/asm/cache.h
5200@@ -1,8 +1,10 @@
5201 #ifndef _ASM_M32R_CACHE_H
5202 #define _ASM_M32R_CACHE_H
5203
5204+#include <linux/const.h>
5205+
5206 /* L1 cache line size */
5207 #define L1_CACHE_SHIFT 4
5208-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5209+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5210
5211 #endif /* _ASM_M32R_CACHE_H */
5212diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
5213index 82abd15..d95ae5d 100644
5214--- a/arch/m32r/lib/usercopy.c
5215+++ b/arch/m32r/lib/usercopy.c
5216@@ -14,6 +14,9 @@
5217 unsigned long
5218 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5219 {
5220+ if ((long)n < 0)
5221+ return n;
5222+
5223 prefetch(from);
5224 if (access_ok(VERIFY_WRITE, to, n))
5225 __copy_user(to,from,n);
5226@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5227 unsigned long
5228 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
5229 {
5230+ if ((long)n < 0)
5231+ return n;
5232+
5233 prefetchw(to);
5234 if (access_ok(VERIFY_READ, from, n))
5235 __copy_user_zeroing(to,from,n);
5236diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
5237index 0395c51..5f26031 100644
5238--- a/arch/m68k/include/asm/cache.h
5239+++ b/arch/m68k/include/asm/cache.h
5240@@ -4,9 +4,11 @@
5241 #ifndef __ARCH_M68K_CACHE_H
5242 #define __ARCH_M68K_CACHE_H
5243
5244+#include <linux/const.h>
5245+
5246 /* bytes per L1 cache line */
5247 #define L1_CACHE_SHIFT 4
5248-#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
5249+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5250
5251 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5252
5253diff --git a/arch/metag/mm/hugetlbpage.c b/arch/metag/mm/hugetlbpage.c
5254index 3c52fa6..11b2ad8 100644
5255--- a/arch/metag/mm/hugetlbpage.c
5256+++ b/arch/metag/mm/hugetlbpage.c
5257@@ -200,6 +200,7 @@ hugetlb_get_unmapped_area_new_pmd(unsigned long len)
5258 info.high_limit = TASK_SIZE;
5259 info.align_mask = PAGE_MASK & HUGEPT_MASK;
5260 info.align_offset = 0;
5261+ info.threadstack_offset = 0;
5262 return vm_unmapped_area(&info);
5263 }
5264
5265diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
5266index 4efe96a..60e8699 100644
5267--- a/arch/microblaze/include/asm/cache.h
5268+++ b/arch/microblaze/include/asm/cache.h
5269@@ -13,11 +13,12 @@
5270 #ifndef _ASM_MICROBLAZE_CACHE_H
5271 #define _ASM_MICROBLAZE_CACHE_H
5272
5273+#include <linux/const.h>
5274 #include <asm/registers.h>
5275
5276 #define L1_CACHE_SHIFT 5
5277 /* word-granular cache in microblaze */
5278-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5279+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5280
5281 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5282
5283diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
5284index 08b6079..8b554d2 100644
5285--- a/arch/mips/include/asm/atomic.h
5286+++ b/arch/mips/include/asm/atomic.h
5287@@ -21,15 +21,39 @@
5288 #include <asm/cmpxchg.h>
5289 #include <asm/war.h>
5290
5291+#ifdef CONFIG_GENERIC_ATOMIC64
5292+#include <asm-generic/atomic64.h>
5293+#endif
5294+
5295 #define ATOMIC_INIT(i) { (i) }
5296
5297+#ifdef CONFIG_64BIT
5298+#define _ASM_EXTABLE(from, to) \
5299+" .section __ex_table,\"a\"\n" \
5300+" .dword " #from ", " #to"\n" \
5301+" .previous\n"
5302+#else
5303+#define _ASM_EXTABLE(from, to) \
5304+" .section __ex_table,\"a\"\n" \
5305+" .word " #from ", " #to"\n" \
5306+" .previous\n"
5307+#endif
5308+
5309 /*
5310 * atomic_read - read atomic variable
5311 * @v: pointer of type atomic_t
5312 *
5313 * Atomically reads the value of @v.
5314 */
5315-#define atomic_read(v) (*(volatile int *)&(v)->counter)
5316+static inline int atomic_read(const atomic_t *v)
5317+{
5318+ return (*(volatile const int *) &v->counter);
5319+}
5320+
5321+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5322+{
5323+ return (*(volatile const int *) &v->counter);
5324+}
5325
5326 /*
5327 * atomic_set - set atomic variable
5328@@ -38,7 +62,15 @@
5329 *
5330 * Atomically sets the value of @v to @i.
5331 */
5332-#define atomic_set(v, i) ((v)->counter = (i))
5333+static inline void atomic_set(atomic_t *v, int i)
5334+{
5335+ v->counter = i;
5336+}
5337+
5338+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5339+{
5340+ v->counter = i;
5341+}
5342
5343 /*
5344 * atomic_add - add integer to atomic variable
5345@@ -47,7 +79,67 @@
5346 *
5347 * Atomically adds @i to @v.
5348 */
5349-static __inline__ void atomic_add(int i, atomic_t * v)
5350+static __inline__ void atomic_add(int i, atomic_t *v)
5351+{
5352+ int temp;
5353+
5354+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5355+ __asm__ __volatile__(
5356+ " .set mips3 \n"
5357+ "1: ll %0, %1 # atomic_add \n"
5358+#ifdef CONFIG_PAX_REFCOUNT
5359+ /* Exception on overflow. */
5360+ "2: add %0, %2 \n"
5361+#else
5362+ " addu %0, %2 \n"
5363+#endif
5364+ " sc %0, %1 \n"
5365+ " beqzl %0, 1b \n"
5366+#ifdef CONFIG_PAX_REFCOUNT
5367+ "3: \n"
5368+ _ASM_EXTABLE(2b, 3b)
5369+#endif
5370+ " .set mips0 \n"
5371+ : "=&r" (temp), "+m" (v->counter)
5372+ : "Ir" (i));
5373+ } else if (kernel_uses_llsc) {
5374+ __asm__ __volatile__(
5375+ " .set mips3 \n"
5376+ "1: ll %0, %1 # atomic_add \n"
5377+#ifdef CONFIG_PAX_REFCOUNT
5378+ /* Exception on overflow. */
5379+ "2: add %0, %2 \n"
5380+#else
5381+ " addu %0, %2 \n"
5382+#endif
5383+ " sc %0, %1 \n"
5384+ " beqz %0, 1b \n"
5385+#ifdef CONFIG_PAX_REFCOUNT
5386+ "3: \n"
5387+ _ASM_EXTABLE(2b, 3b)
5388+#endif
5389+ " .set mips0 \n"
5390+ : "=&r" (temp), "+m" (v->counter)
5391+ : "Ir" (i));
5392+ } else {
5393+ unsigned long flags;
5394+
5395+ raw_local_irq_save(flags);
5396+ __asm__ __volatile__(
5397+#ifdef CONFIG_PAX_REFCOUNT
5398+ /* Exception on overflow. */
5399+ "1: add %0, %1 \n"
5400+ "2: \n"
5401+ _ASM_EXTABLE(1b, 2b)
5402+#else
5403+ " addu %0, %1 \n"
5404+#endif
5405+ : "+r" (v->counter) : "Ir" (i));
5406+ raw_local_irq_restore(flags);
5407+ }
5408+}
5409+
5410+static __inline__ void atomic_add_unchecked(int i, atomic_unchecked_t *v)
5411 {
5412 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5413 int temp;
5414@@ -90,7 +182,67 @@ static __inline__ void atomic_add(int i, atomic_t * v)
5415 *
5416 * Atomically subtracts @i from @v.
5417 */
5418-static __inline__ void atomic_sub(int i, atomic_t * v)
5419+static __inline__ void atomic_sub(int i, atomic_t *v)
5420+{
5421+ int temp;
5422+
5423+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5424+ __asm__ __volatile__(
5425+ " .set mips3 \n"
5426+ "1: ll %0, %1 # atomic64_sub \n"
5427+#ifdef CONFIG_PAX_REFCOUNT
5428+ /* Exception on overflow. */
5429+ "2: sub %0, %2 \n"
5430+#else
5431+ " subu %0, %2 \n"
5432+#endif
5433+ " sc %0, %1 \n"
5434+ " beqzl %0, 1b \n"
5435+#ifdef CONFIG_PAX_REFCOUNT
5436+ "3: \n"
5437+ _ASM_EXTABLE(2b, 3b)
5438+#endif
5439+ " .set mips0 \n"
5440+ : "=&r" (temp), "+m" (v->counter)
5441+ : "Ir" (i));
5442+ } else if (kernel_uses_llsc) {
5443+ __asm__ __volatile__(
5444+ " .set mips3 \n"
5445+ "1: ll %0, %1 # atomic64_sub \n"
5446+#ifdef CONFIG_PAX_REFCOUNT
5447+ /* Exception on overflow. */
5448+ "2: sub %0, %2 \n"
5449+#else
5450+ " subu %0, %2 \n"
5451+#endif
5452+ " sc %0, %1 \n"
5453+ " beqz %0, 1b \n"
5454+#ifdef CONFIG_PAX_REFCOUNT
5455+ "3: \n"
5456+ _ASM_EXTABLE(2b, 3b)
5457+#endif
5458+ " .set mips0 \n"
5459+ : "=&r" (temp), "+m" (v->counter)
5460+ : "Ir" (i));
5461+ } else {
5462+ unsigned long flags;
5463+
5464+ raw_local_irq_save(flags);
5465+ __asm__ __volatile__(
5466+#ifdef CONFIG_PAX_REFCOUNT
5467+ /* Exception on overflow. */
5468+ "1: sub %0, %1 \n"
5469+ "2: \n"
5470+ _ASM_EXTABLE(1b, 2b)
5471+#else
5472+ " subu %0, %1 \n"
5473+#endif
5474+ : "+r" (v->counter) : "Ir" (i));
5475+ raw_local_irq_restore(flags);
5476+ }
5477+}
5478+
5479+static __inline__ void atomic_sub_unchecked(long i, atomic_unchecked_t *v)
5480 {
5481 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5482 int temp;
5483@@ -129,7 +281,93 @@ static __inline__ void atomic_sub(int i, atomic_t * v)
5484 /*
5485 * Same as above, but return the result value
5486 */
5487-static __inline__ int atomic_add_return(int i, atomic_t * v)
5488+static __inline__ int atomic_add_return(int i, atomic_t *v)
5489+{
5490+ int result;
5491+ int temp;
5492+
5493+ smp_mb__before_llsc();
5494+
5495+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5496+ __asm__ __volatile__(
5497+ " .set mips3 \n"
5498+ "1: ll %1, %2 # atomic_add_return \n"
5499+#ifdef CONFIG_PAX_REFCOUNT
5500+ "2: add %0, %1, %3 \n"
5501+#else
5502+ " addu %0, %1, %3 \n"
5503+#endif
5504+ " sc %0, %2 \n"
5505+ " beqzl %0, 1b \n"
5506+#ifdef CONFIG_PAX_REFCOUNT
5507+ " b 4f \n"
5508+ " .set noreorder \n"
5509+ "3: b 5f \n"
5510+ " move %0, %1 \n"
5511+ " .set reorder \n"
5512+ _ASM_EXTABLE(2b, 3b)
5513+#endif
5514+ "4: addu %0, %1, %3 \n"
5515+#ifdef CONFIG_PAX_REFCOUNT
5516+ "5: \n"
5517+#endif
5518+ " .set mips0 \n"
5519+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5520+ : "Ir" (i));
5521+ } else if (kernel_uses_llsc) {
5522+ __asm__ __volatile__(
5523+ " .set mips3 \n"
5524+ "1: ll %1, %2 # atomic_add_return \n"
5525+#ifdef CONFIG_PAX_REFCOUNT
5526+ "2: add %0, %1, %3 \n"
5527+#else
5528+ " addu %0, %1, %3 \n"
5529+#endif
5530+ " sc %0, %2 \n"
5531+ " bnez %0, 4f \n"
5532+ " b 1b \n"
5533+#ifdef CONFIG_PAX_REFCOUNT
5534+ " .set noreorder \n"
5535+ "3: b 5f \n"
5536+ " move %0, %1 \n"
5537+ " .set reorder \n"
5538+ _ASM_EXTABLE(2b, 3b)
5539+#endif
5540+ "4: addu %0, %1, %3 \n"
5541+#ifdef CONFIG_PAX_REFCOUNT
5542+ "5: \n"
5543+#endif
5544+ " .set mips0 \n"
5545+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5546+ : "Ir" (i));
5547+ } else {
5548+ unsigned long flags;
5549+
5550+ raw_local_irq_save(flags);
5551+ __asm__ __volatile__(
5552+ " lw %0, %1 \n"
5553+#ifdef CONFIG_PAX_REFCOUNT
5554+ /* Exception on overflow. */
5555+ "1: add %0, %2 \n"
5556+#else
5557+ " addu %0, %2 \n"
5558+#endif
5559+ " sw %0, %1 \n"
5560+#ifdef CONFIG_PAX_REFCOUNT
5561+ /* Note: Dest reg is not modified on overflow */
5562+ "2: \n"
5563+ _ASM_EXTABLE(1b, 2b)
5564+#endif
5565+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5566+ raw_local_irq_restore(flags);
5567+ }
5568+
5569+ smp_llsc_mb();
5570+
5571+ return result;
5572+}
5573+
5574+static __inline__ int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5575 {
5576 int result;
5577
5578@@ -178,7 +416,93 @@ static __inline__ int atomic_add_return(int i, atomic_t * v)
5579 return result;
5580 }
5581
5582-static __inline__ int atomic_sub_return(int i, atomic_t * v)
5583+static __inline__ int atomic_sub_return(int i, atomic_t *v)
5584+{
5585+ int result;
5586+ int temp;
5587+
5588+ smp_mb__before_llsc();
5589+
5590+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5591+ __asm__ __volatile__(
5592+ " .set mips3 \n"
5593+ "1: ll %1, %2 # atomic_sub_return \n"
5594+#ifdef CONFIG_PAX_REFCOUNT
5595+ "2: sub %0, %1, %3 \n"
5596+#else
5597+ " subu %0, %1, %3 \n"
5598+#endif
5599+ " sc %0, %2 \n"
5600+ " beqzl %0, 1b \n"
5601+#ifdef CONFIG_PAX_REFCOUNT
5602+ " b 4f \n"
5603+ " .set noreorder \n"
5604+ "3: b 5f \n"
5605+ " move %0, %1 \n"
5606+ " .set reorder \n"
5607+ _ASM_EXTABLE(2b, 3b)
5608+#endif
5609+ "4: subu %0, %1, %3 \n"
5610+#ifdef CONFIG_PAX_REFCOUNT
5611+ "5: \n"
5612+#endif
5613+ " .set mips0 \n"
5614+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
5615+ : "Ir" (i), "m" (v->counter)
5616+ : "memory");
5617+ } else if (kernel_uses_llsc) {
5618+ __asm__ __volatile__(
5619+ " .set mips3 \n"
5620+ "1: ll %1, %2 # atomic_sub_return \n"
5621+#ifdef CONFIG_PAX_REFCOUNT
5622+ "2: sub %0, %1, %3 \n"
5623+#else
5624+ " subu %0, %1, %3 \n"
5625+#endif
5626+ " sc %0, %2 \n"
5627+ " bnez %0, 4f \n"
5628+ " b 1b \n"
5629+#ifdef CONFIG_PAX_REFCOUNT
5630+ " .set noreorder \n"
5631+ "3: b 5f \n"
5632+ " move %0, %1 \n"
5633+ " .set reorder \n"
5634+ _ASM_EXTABLE(2b, 3b)
5635+#endif
5636+ "4: subu %0, %1, %3 \n"
5637+#ifdef CONFIG_PAX_REFCOUNT
5638+ "5: \n"
5639+#endif
5640+ " .set mips0 \n"
5641+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5642+ : "Ir" (i));
5643+ } else {
5644+ unsigned long flags;
5645+
5646+ raw_local_irq_save(flags);
5647+ __asm__ __volatile__(
5648+ " lw %0, %1 \n"
5649+#ifdef CONFIG_PAX_REFCOUNT
5650+ /* Exception on overflow. */
5651+ "1: sub %0, %2 \n"
5652+#else
5653+ " subu %0, %2 \n"
5654+#endif
5655+ " sw %0, %1 \n"
5656+#ifdef CONFIG_PAX_REFCOUNT
5657+ /* Note: Dest reg is not modified on overflow */
5658+ "2: \n"
5659+ _ASM_EXTABLE(1b, 2b)
5660+#endif
5661+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5662+ raw_local_irq_restore(flags);
5663+ }
5664+
5665+ smp_llsc_mb();
5666+
5667+ return result;
5668+}
5669+static __inline__ int atomic_sub_return_unchecked(int i, atomic_unchecked_t *v)
5670 {
5671 int result;
5672
5673@@ -238,7 +562,7 @@ static __inline__ int atomic_sub_return(int i, atomic_t * v)
5674 * Atomically test @v and subtract @i if @v is greater or equal than @i.
5675 * The function returns the old value of @v minus @i.
5676 */
5677-static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5678+static __inline__ int atomic_sub_if_positive(int i, atomic_t *v)
5679 {
5680 int result;
5681
5682@@ -295,8 +619,26 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5683 return result;
5684 }
5685
5686-#define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5687-#define atomic_xchg(v, new) (xchg(&((v)->counter), (new)))
5688+static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
5689+{
5690+ return cmpxchg(&v->counter, old, new);
5691+}
5692+
5693+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old,
5694+ int new)
5695+{
5696+ return cmpxchg(&(v->counter), old, new);
5697+}
5698+
5699+static inline int atomic_xchg(atomic_t *v, int new)
5700+{
5701+ return xchg(&v->counter, new);
5702+}
5703+
5704+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5705+{
5706+ return xchg(&(v->counter), new);
5707+}
5708
5709 /**
5710 * __atomic_add_unless - add unless the number is a given value
5711@@ -324,6 +666,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5712
5713 #define atomic_dec_return(v) atomic_sub_return(1, (v))
5714 #define atomic_inc_return(v) atomic_add_return(1, (v))
5715+static __inline__ int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5716+{
5717+ return atomic_add_return_unchecked(1, v);
5718+}
5719
5720 /*
5721 * atomic_sub_and_test - subtract value from variable and test result
5722@@ -345,6 +691,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5723 * other cases.
5724 */
5725 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5726+static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
5727+{
5728+ return atomic_add_return_unchecked(1, v) == 0;
5729+}
5730
5731 /*
5732 * atomic_dec_and_test - decrement by 1 and test
5733@@ -369,6 +719,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5734 * Atomically increments @v by 1.
5735 */
5736 #define atomic_inc(v) atomic_add(1, (v))
5737+static __inline__ void atomic_inc_unchecked(atomic_unchecked_t *v)
5738+{
5739+ atomic_add_unchecked(1, v);
5740+}
5741
5742 /*
5743 * atomic_dec - decrement and test
5744@@ -377,6 +731,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5745 * Atomically decrements @v by 1.
5746 */
5747 #define atomic_dec(v) atomic_sub(1, (v))
5748+static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
5749+{
5750+ atomic_sub_unchecked(1, v);
5751+}
5752
5753 /*
5754 * atomic_add_negative - add and test if negative
5755@@ -398,14 +756,30 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5756 * @v: pointer of type atomic64_t
5757 *
5758 */
5759-#define atomic64_read(v) (*(volatile long *)&(v)->counter)
5760+static inline long atomic64_read(const atomic64_t *v)
5761+{
5762+ return (*(volatile const long *) &v->counter);
5763+}
5764+
5765+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
5766+{
5767+ return (*(volatile const long *) &v->counter);
5768+}
5769
5770 /*
5771 * atomic64_set - set atomic variable
5772 * @v: pointer of type atomic64_t
5773 * @i: required value
5774 */
5775-#define atomic64_set(v, i) ((v)->counter = (i))
5776+static inline void atomic64_set(atomic64_t *v, long i)
5777+{
5778+ v->counter = i;
5779+}
5780+
5781+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
5782+{
5783+ v->counter = i;
5784+}
5785
5786 /*
5787 * atomic64_add - add integer to atomic variable
5788@@ -414,7 +788,66 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5789 *
5790 * Atomically adds @i to @v.
5791 */
5792-static __inline__ void atomic64_add(long i, atomic64_t * v)
5793+static __inline__ void atomic64_add(long i, atomic64_t *v)
5794+{
5795+ long temp;
5796+
5797+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5798+ __asm__ __volatile__(
5799+ " .set mips3 \n"
5800+ "1: lld %0, %1 # atomic64_add \n"
5801+#ifdef CONFIG_PAX_REFCOUNT
5802+ /* Exception on overflow. */
5803+ "2: dadd %0, %2 \n"
5804+#else
5805+ " daddu %0, %2 \n"
5806+#endif
5807+ " scd %0, %1 \n"
5808+ " beqzl %0, 1b \n"
5809+#ifdef CONFIG_PAX_REFCOUNT
5810+ "3: \n"
5811+ _ASM_EXTABLE(2b, 3b)
5812+#endif
5813+ " .set mips0 \n"
5814+ : "=&r" (temp), "+m" (v->counter)
5815+ : "Ir" (i));
5816+ } else if (kernel_uses_llsc) {
5817+ __asm__ __volatile__(
5818+ " .set mips3 \n"
5819+ "1: lld %0, %1 # atomic64_add \n"
5820+#ifdef CONFIG_PAX_REFCOUNT
5821+ /* Exception on overflow. */
5822+ "2: dadd %0, %2 \n"
5823+#else
5824+ " daddu %0, %2 \n"
5825+#endif
5826+ " scd %0, %1 \n"
5827+ " beqz %0, 1b \n"
5828+#ifdef CONFIG_PAX_REFCOUNT
5829+ "3: \n"
5830+ _ASM_EXTABLE(2b, 3b)
5831+#endif
5832+ " .set mips0 \n"
5833+ : "=&r" (temp), "+m" (v->counter)
5834+ : "Ir" (i));
5835+ } else {
5836+ unsigned long flags;
5837+
5838+ raw_local_irq_save(flags);
5839+ __asm__ __volatile__(
5840+#ifdef CONFIG_PAX_REFCOUNT
5841+ /* Exception on overflow. */
5842+ "1: dadd %0, %1 \n"
5843+ "2: \n"
5844+ _ASM_EXTABLE(1b, 2b)
5845+#else
5846+ " daddu %0, %1 \n"
5847+#endif
5848+ : "+r" (v->counter) : "Ir" (i));
5849+ raw_local_irq_restore(flags);
5850+ }
5851+}
5852+static __inline__ void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
5853 {
5854 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5855 long temp;
5856@@ -457,7 +890,67 @@ static __inline__ void atomic64_add(long i, atomic64_t * v)
5857 *
5858 * Atomically subtracts @i from @v.
5859 */
5860-static __inline__ void atomic64_sub(long i, atomic64_t * v)
5861+static __inline__ void atomic64_sub(long i, atomic64_t *v)
5862+{
5863+ long temp;
5864+
5865+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5866+ __asm__ __volatile__(
5867+ " .set mips3 \n"
5868+ "1: lld %0, %1 # atomic64_sub \n"
5869+#ifdef CONFIG_PAX_REFCOUNT
5870+ /* Exception on overflow. */
5871+ "2: dsub %0, %2 \n"
5872+#else
5873+ " dsubu %0, %2 \n"
5874+#endif
5875+ " scd %0, %1 \n"
5876+ " beqzl %0, 1b \n"
5877+#ifdef CONFIG_PAX_REFCOUNT
5878+ "3: \n"
5879+ _ASM_EXTABLE(2b, 3b)
5880+#endif
5881+ " .set mips0 \n"
5882+ : "=&r" (temp), "+m" (v->counter)
5883+ : "Ir" (i));
5884+ } else if (kernel_uses_llsc) {
5885+ __asm__ __volatile__(
5886+ " .set mips3 \n"
5887+ "1: lld %0, %1 # atomic64_sub \n"
5888+#ifdef CONFIG_PAX_REFCOUNT
5889+ /* Exception on overflow. */
5890+ "2: dsub %0, %2 \n"
5891+#else
5892+ " dsubu %0, %2 \n"
5893+#endif
5894+ " scd %0, %1 \n"
5895+ " beqz %0, 1b \n"
5896+#ifdef CONFIG_PAX_REFCOUNT
5897+ "3: \n"
5898+ _ASM_EXTABLE(2b, 3b)
5899+#endif
5900+ " .set mips0 \n"
5901+ : "=&r" (temp), "+m" (v->counter)
5902+ : "Ir" (i));
5903+ } else {
5904+ unsigned long flags;
5905+
5906+ raw_local_irq_save(flags);
5907+ __asm__ __volatile__(
5908+#ifdef CONFIG_PAX_REFCOUNT
5909+ /* Exception on overflow. */
5910+ "1: dsub %0, %1 \n"
5911+ "2: \n"
5912+ _ASM_EXTABLE(1b, 2b)
5913+#else
5914+ " dsubu %0, %1 \n"
5915+#endif
5916+ : "+r" (v->counter) : "Ir" (i));
5917+ raw_local_irq_restore(flags);
5918+ }
5919+}
5920+
5921+static __inline__ void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
5922 {
5923 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5924 long temp;
5925@@ -496,7 +989,93 @@ static __inline__ void atomic64_sub(long i, atomic64_t * v)
5926 /*
5927 * Same as above, but return the result value
5928 */
5929-static __inline__ long atomic64_add_return(long i, atomic64_t * v)
5930+static __inline__ long atomic64_add_return(long i, atomic64_t *v)
5931+{
5932+ long result;
5933+ long temp;
5934+
5935+ smp_mb__before_llsc();
5936+
5937+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5938+ __asm__ __volatile__(
5939+ " .set mips3 \n"
5940+ "1: lld %1, %2 # atomic64_add_return \n"
5941+#ifdef CONFIG_PAX_REFCOUNT
5942+ "2: dadd %0, %1, %3 \n"
5943+#else
5944+ " daddu %0, %1, %3 \n"
5945+#endif
5946+ " scd %0, %2 \n"
5947+ " beqzl %0, 1b \n"
5948+#ifdef CONFIG_PAX_REFCOUNT
5949+ " b 4f \n"
5950+ " .set noreorder \n"
5951+ "3: b 5f \n"
5952+ " move %0, %1 \n"
5953+ " .set reorder \n"
5954+ _ASM_EXTABLE(2b, 3b)
5955+#endif
5956+ "4: daddu %0, %1, %3 \n"
5957+#ifdef CONFIG_PAX_REFCOUNT
5958+ "5: \n"
5959+#endif
5960+ " .set mips0 \n"
5961+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5962+ : "Ir" (i));
5963+ } else if (kernel_uses_llsc) {
5964+ __asm__ __volatile__(
5965+ " .set mips3 \n"
5966+ "1: lld %1, %2 # atomic64_add_return \n"
5967+#ifdef CONFIG_PAX_REFCOUNT
5968+ "2: dadd %0, %1, %3 \n"
5969+#else
5970+ " daddu %0, %1, %3 \n"
5971+#endif
5972+ " scd %0, %2 \n"
5973+ " bnez %0, 4f \n"
5974+ " b 1b \n"
5975+#ifdef CONFIG_PAX_REFCOUNT
5976+ " .set noreorder \n"
5977+ "3: b 5f \n"
5978+ " move %0, %1 \n"
5979+ " .set reorder \n"
5980+ _ASM_EXTABLE(2b, 3b)
5981+#endif
5982+ "4: daddu %0, %1, %3 \n"
5983+#ifdef CONFIG_PAX_REFCOUNT
5984+ "5: \n"
5985+#endif
5986+ " .set mips0 \n"
5987+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
5988+ : "Ir" (i), "m" (v->counter)
5989+ : "memory");
5990+ } else {
5991+ unsigned long flags;
5992+
5993+ raw_local_irq_save(flags);
5994+ __asm__ __volatile__(
5995+ " ld %0, %1 \n"
5996+#ifdef CONFIG_PAX_REFCOUNT
5997+ /* Exception on overflow. */
5998+ "1: dadd %0, %2 \n"
5999+#else
6000+ " daddu %0, %2 \n"
6001+#endif
6002+ " sd %0, %1 \n"
6003+#ifdef CONFIG_PAX_REFCOUNT
6004+ /* Note: Dest reg is not modified on overflow */
6005+ "2: \n"
6006+ _ASM_EXTABLE(1b, 2b)
6007+#endif
6008+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6009+ raw_local_irq_restore(flags);
6010+ }
6011+
6012+ smp_llsc_mb();
6013+
6014+ return result;
6015+}
6016+static __inline__ long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
6017 {
6018 long result;
6019
6020@@ -546,7 +1125,97 @@ static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6021 return result;
6022 }
6023
6024-static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6025+static __inline__ long atomic64_sub_return(long i, atomic64_t *v)
6026+{
6027+ long result;
6028+ long temp;
6029+
6030+ smp_mb__before_llsc();
6031+
6032+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6033+ long temp;
6034+
6035+ __asm__ __volatile__(
6036+ " .set mips3 \n"
6037+ "1: lld %1, %2 # atomic64_sub_return \n"
6038+#ifdef CONFIG_PAX_REFCOUNT
6039+ "2: dsub %0, %1, %3 \n"
6040+#else
6041+ " dsubu %0, %1, %3 \n"
6042+#endif
6043+ " scd %0, %2 \n"
6044+ " beqzl %0, 1b \n"
6045+#ifdef CONFIG_PAX_REFCOUNT
6046+ " b 4f \n"
6047+ " .set noreorder \n"
6048+ "3: b 5f \n"
6049+ " move %0, %1 \n"
6050+ " .set reorder \n"
6051+ _ASM_EXTABLE(2b, 3b)
6052+#endif
6053+ "4: dsubu %0, %1, %3 \n"
6054+#ifdef CONFIG_PAX_REFCOUNT
6055+ "5: \n"
6056+#endif
6057+ " .set mips0 \n"
6058+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6059+ : "Ir" (i), "m" (v->counter)
6060+ : "memory");
6061+ } else if (kernel_uses_llsc) {
6062+ __asm__ __volatile__(
6063+ " .set mips3 \n"
6064+ "1: lld %1, %2 # atomic64_sub_return \n"
6065+#ifdef CONFIG_PAX_REFCOUNT
6066+ "2: dsub %0, %1, %3 \n"
6067+#else
6068+ " dsubu %0, %1, %3 \n"
6069+#endif
6070+ " scd %0, %2 \n"
6071+ " bnez %0, 4f \n"
6072+ " b 1b \n"
6073+#ifdef CONFIG_PAX_REFCOUNT
6074+ " .set noreorder \n"
6075+ "3: b 5f \n"
6076+ " move %0, %1 \n"
6077+ " .set reorder \n"
6078+ _ASM_EXTABLE(2b, 3b)
6079+#endif
6080+ "4: dsubu %0, %1, %3 \n"
6081+#ifdef CONFIG_PAX_REFCOUNT
6082+ "5: \n"
6083+#endif
6084+ " .set mips0 \n"
6085+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6086+ : "Ir" (i), "m" (v->counter)
6087+ : "memory");
6088+ } else {
6089+ unsigned long flags;
6090+
6091+ raw_local_irq_save(flags);
6092+ __asm__ __volatile__(
6093+ " ld %0, %1 \n"
6094+#ifdef CONFIG_PAX_REFCOUNT
6095+ /* Exception on overflow. */
6096+ "1: dsub %0, %2 \n"
6097+#else
6098+ " dsubu %0, %2 \n"
6099+#endif
6100+ " sd %0, %1 \n"
6101+#ifdef CONFIG_PAX_REFCOUNT
6102+ /* Note: Dest reg is not modified on overflow */
6103+ "2: \n"
6104+ _ASM_EXTABLE(1b, 2b)
6105+#endif
6106+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6107+ raw_local_irq_restore(flags);
6108+ }
6109+
6110+ smp_llsc_mb();
6111+
6112+ return result;
6113+}
6114+
6115+static __inline__ long atomic64_sub_return_unchecked(long i, atomic64_unchecked_t *v)
6116 {
6117 long result;
6118
6119@@ -605,7 +1274,7 @@ static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6120 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6121 * The function returns the old value of @v minus @i.
6122 */
6123-static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6124+static __inline__ long atomic64_sub_if_positive(long i, atomic64_t *v)
6125 {
6126 long result;
6127
6128@@ -662,9 +1331,26 @@ static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6129 return result;
6130 }
6131
6132-#define atomic64_cmpxchg(v, o, n) \
6133- ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
6134-#define atomic64_xchg(v, new) (xchg(&((v)->counter), (new)))
6135+static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
6136+{
6137+ return cmpxchg(&v->counter, old, new);
6138+}
6139+
6140+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old,
6141+ long new)
6142+{
6143+ return cmpxchg(&(v->counter), old, new);
6144+}
6145+
6146+static inline long atomic64_xchg(atomic64_t *v, long new)
6147+{
6148+ return xchg(&v->counter, new);
6149+}
6150+
6151+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
6152+{
6153+ return xchg(&(v->counter), new);
6154+}
6155
6156 /**
6157 * atomic64_add_unless - add unless the number is a given value
6158@@ -694,6 +1380,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6159
6160 #define atomic64_dec_return(v) atomic64_sub_return(1, (v))
6161 #define atomic64_inc_return(v) atomic64_add_return(1, (v))
6162+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1, (v))
6163
6164 /*
6165 * atomic64_sub_and_test - subtract value from variable and test result
6166@@ -715,6 +1402,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6167 * other cases.
6168 */
6169 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
6170+#define atomic64_inc_and_test_unchecked(v) atomic64_add_return_unchecked(1, (v)) == 0)
6171
6172 /*
6173 * atomic64_dec_and_test - decrement by 1 and test
6174@@ -739,6 +1427,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6175 * Atomically increments @v by 1.
6176 */
6177 #define atomic64_inc(v) atomic64_add(1, (v))
6178+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1, (v))
6179
6180 /*
6181 * atomic64_dec - decrement and test
6182@@ -747,6 +1436,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6183 * Atomically decrements @v by 1.
6184 */
6185 #define atomic64_dec(v) atomic64_sub(1, (v))
6186+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1, (v))
6187
6188 /*
6189 * atomic64_add_negative - add and test if negative
6190diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
6191index b4db69f..8f3b093 100644
6192--- a/arch/mips/include/asm/cache.h
6193+++ b/arch/mips/include/asm/cache.h
6194@@ -9,10 +9,11 @@
6195 #ifndef _ASM_CACHE_H
6196 #define _ASM_CACHE_H
6197
6198+#include <linux/const.h>
6199 #include <kmalloc.h>
6200
6201 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
6202-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6203+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6204
6205 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
6206 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6207diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
6208index cf3ae24..238d22f 100644
6209--- a/arch/mips/include/asm/elf.h
6210+++ b/arch/mips/include/asm/elf.h
6211@@ -372,13 +372,16 @@ extern const char *__elf_platform;
6212 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
6213 #endif
6214
6215+#ifdef CONFIG_PAX_ASLR
6216+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6217+
6218+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6219+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6220+#endif
6221+
6222 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
6223 struct linux_binprm;
6224 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
6225 int uses_interp);
6226
6227-struct mm_struct;
6228-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6229-#define arch_randomize_brk arch_randomize_brk
6230-
6231 #endif /* _ASM_ELF_H */
6232diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
6233index c1f6afa..38cc6e9 100644
6234--- a/arch/mips/include/asm/exec.h
6235+++ b/arch/mips/include/asm/exec.h
6236@@ -12,6 +12,6 @@
6237 #ifndef _ASM_EXEC_H
6238 #define _ASM_EXEC_H
6239
6240-extern unsigned long arch_align_stack(unsigned long sp);
6241+#define arch_align_stack(x) ((x) & ~0xfUL)
6242
6243 #endif /* _ASM_EXEC_H */
6244diff --git a/arch/mips/include/asm/local.h b/arch/mips/include/asm/local.h
6245index d44622c..64990d2 100644
6246--- a/arch/mips/include/asm/local.h
6247+++ b/arch/mips/include/asm/local.h
6248@@ -12,15 +12,25 @@ typedef struct
6249 atomic_long_t a;
6250 } local_t;
6251
6252+typedef struct {
6253+ atomic_long_unchecked_t a;
6254+} local_unchecked_t;
6255+
6256 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
6257
6258 #define local_read(l) atomic_long_read(&(l)->a)
6259+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
6260 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
6261+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
6262
6263 #define local_add(i, l) atomic_long_add((i), (&(l)->a))
6264+#define local_add_unchecked(i, l) atomic_long_add_unchecked((i), (&(l)->a))
6265 #define local_sub(i, l) atomic_long_sub((i), (&(l)->a))
6266+#define local_sub_unchecked(i, l) atomic_long_sub_unchecked((i), (&(l)->a))
6267 #define local_inc(l) atomic_long_inc(&(l)->a)
6268+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
6269 #define local_dec(l) atomic_long_dec(&(l)->a)
6270+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
6271
6272 /*
6273 * Same as above, but return the result value
6274@@ -70,6 +80,51 @@ static __inline__ long local_add_return(long i, local_t * l)
6275 return result;
6276 }
6277
6278+static __inline__ long local_add_return_unchecked(long i, local_unchecked_t * l)
6279+{
6280+ unsigned long result;
6281+
6282+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6283+ unsigned long temp;
6284+
6285+ __asm__ __volatile__(
6286+ " .set mips3 \n"
6287+ "1:" __LL "%1, %2 # local_add_return \n"
6288+ " addu %0, %1, %3 \n"
6289+ __SC "%0, %2 \n"
6290+ " beqzl %0, 1b \n"
6291+ " addu %0, %1, %3 \n"
6292+ " .set mips0 \n"
6293+ : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6294+ : "Ir" (i), "m" (l->a.counter)
6295+ : "memory");
6296+ } else if (kernel_uses_llsc) {
6297+ unsigned long temp;
6298+
6299+ __asm__ __volatile__(
6300+ " .set mips3 \n"
6301+ "1:" __LL "%1, %2 # local_add_return \n"
6302+ " addu %0, %1, %3 \n"
6303+ __SC "%0, %2 \n"
6304+ " beqz %0, 1b \n"
6305+ " addu %0, %1, %3 \n"
6306+ " .set mips0 \n"
6307+ : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6308+ : "Ir" (i), "m" (l->a.counter)
6309+ : "memory");
6310+ } else {
6311+ unsigned long flags;
6312+
6313+ local_irq_save(flags);
6314+ result = l->a.counter;
6315+ result += i;
6316+ l->a.counter = result;
6317+ local_irq_restore(flags);
6318+ }
6319+
6320+ return result;
6321+}
6322+
6323 static __inline__ long local_sub_return(long i, local_t * l)
6324 {
6325 unsigned long result;
6326@@ -117,6 +172,8 @@ static __inline__ long local_sub_return(long i, local_t * l)
6327
6328 #define local_cmpxchg(l, o, n) \
6329 ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6330+#define local_cmpxchg_unchecked(l, o, n) \
6331+ ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6332 #define local_xchg(l, n) (atomic_long_xchg((&(l)->a), (n)))
6333
6334 /**
6335diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
6336index f6be474..12ad554 100644
6337--- a/arch/mips/include/asm/page.h
6338+++ b/arch/mips/include/asm/page.h
6339@@ -95,7 +95,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
6340 #ifdef CONFIG_CPU_MIPS32
6341 typedef struct { unsigned long pte_low, pte_high; } pte_t;
6342 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
6343- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
6344+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
6345 #else
6346 typedef struct { unsigned long long pte; } pte_t;
6347 #define pte_val(x) ((x).pte)
6348diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
6349index 881d18b..cea38bc 100644
6350--- a/arch/mips/include/asm/pgalloc.h
6351+++ b/arch/mips/include/asm/pgalloc.h
6352@@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6353 {
6354 set_pud(pud, __pud((unsigned long)pmd));
6355 }
6356+
6357+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6358+{
6359+ pud_populate(mm, pud, pmd);
6360+}
6361 #endif
6362
6363 /*
6364diff --git a/arch/mips/include/asm/smtc_proc.h b/arch/mips/include/asm/smtc_proc.h
6365index 25da651..ae2a259 100644
6366--- a/arch/mips/include/asm/smtc_proc.h
6367+++ b/arch/mips/include/asm/smtc_proc.h
6368@@ -18,6 +18,6 @@ extern struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6369
6370 /* Count of number of recoveries of "stolen" FPU access rights on 34K */
6371
6372-extern atomic_t smtc_fpu_recoveries;
6373+extern atomic_unchecked_t smtc_fpu_recoveries;
6374
6375 #endif /* __ASM_SMTC_PROC_H */
6376diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
6377index 61215a3..213ee0e 100644
6378--- a/arch/mips/include/asm/thread_info.h
6379+++ b/arch/mips/include/asm/thread_info.h
6380@@ -116,6 +116,8 @@ static inline struct thread_info *current_thread_info(void)
6381 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
6382 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
6383 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
6384+/* li takes a 32bit immediate */
6385+#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
6386 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
6387
6388 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
6389@@ -132,20 +134,18 @@ static inline struct thread_info *current_thread_info(void)
6390 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
6391 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
6392 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
6393+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6394
6395-#define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6396- _TIF_SYSCALL_AUDIT)
6397+#define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
6398
6399 /* work to do in syscall_trace_leave() */
6400-#define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6401- _TIF_SYSCALL_AUDIT)
6402+#define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
6403
6404 /* work to do on interrupt/exception return */
6405 #define _TIF_WORK_MASK \
6406 (_TIF_SIGPENDING | _TIF_NEED_RESCHED | _TIF_NOTIFY_RESUME)
6407 /* work to do on any return to u-space */
6408-#define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | \
6409- _TIF_WORK_SYSCALL_EXIT)
6410+#define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT | _TIF_GRSEC_SETXID)
6411
6412 #endif /* __KERNEL__ */
6413
6414diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
6415index 1188e00..41cf144 100644
6416--- a/arch/mips/kernel/binfmt_elfn32.c
6417+++ b/arch/mips/kernel/binfmt_elfn32.c
6418@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6419 #undef ELF_ET_DYN_BASE
6420 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6421
6422+#ifdef CONFIG_PAX_ASLR
6423+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6424+
6425+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6426+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6427+#endif
6428+
6429 #include <asm/processor.h>
6430 #include <linux/module.h>
6431 #include <linux/elfcore.h>
6432diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
6433index 202e581..689ca79 100644
6434--- a/arch/mips/kernel/binfmt_elfo32.c
6435+++ b/arch/mips/kernel/binfmt_elfo32.c
6436@@ -56,6 +56,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6437 #undef ELF_ET_DYN_BASE
6438 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6439
6440+#ifdef CONFIG_PAX_ASLR
6441+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6442+
6443+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6444+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6445+#endif
6446+
6447 #include <asm/processor.h>
6448
6449 /*
6450diff --git a/arch/mips/kernel/irq.c b/arch/mips/kernel/irq.c
6451index d1fea7a..45602ea 100644
6452--- a/arch/mips/kernel/irq.c
6453+++ b/arch/mips/kernel/irq.c
6454@@ -77,17 +77,17 @@ void ack_bad_irq(unsigned int irq)
6455 printk("unexpected IRQ # %d\n", irq);
6456 }
6457
6458-atomic_t irq_err_count;
6459+atomic_unchecked_t irq_err_count;
6460
6461 int arch_show_interrupts(struct seq_file *p, int prec)
6462 {
6463- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
6464+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
6465 return 0;
6466 }
6467
6468 asmlinkage void spurious_interrupt(void)
6469 {
6470- atomic_inc(&irq_err_count);
6471+ atomic_inc_unchecked(&irq_err_count);
6472 }
6473
6474 void __init init_IRQ(void)
6475diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
6476index ddc7610..8c58f17 100644
6477--- a/arch/mips/kernel/process.c
6478+++ b/arch/mips/kernel/process.c
6479@@ -566,15 +566,3 @@ unsigned long get_wchan(struct task_struct *task)
6480 out:
6481 return pc;
6482 }
6483-
6484-/*
6485- * Don't forget that the stack pointer must be aligned on a 8 bytes
6486- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
6487- */
6488-unsigned long arch_align_stack(unsigned long sp)
6489-{
6490- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6491- sp -= get_random_int() & ~PAGE_MASK;
6492-
6493- return sp & ALMASK;
6494-}
6495diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
6496index 8ae1ebe..1bcbf47 100644
6497--- a/arch/mips/kernel/ptrace.c
6498+++ b/arch/mips/kernel/ptrace.c
6499@@ -529,6 +529,10 @@ static inline int audit_arch(void)
6500 return arch;
6501 }
6502
6503+#ifdef CONFIG_GRKERNSEC_SETXID
6504+extern void gr_delayed_cred_worker(void);
6505+#endif
6506+
6507 /*
6508 * Notification of system call entry/exit
6509 * - triggered by current->work.syscall_trace
6510@@ -540,6 +544,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
6511 /* do the secure computing check first */
6512 secure_computing_strict(regs->regs[2]);
6513
6514+#ifdef CONFIG_GRKERNSEC_SETXID
6515+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6516+ gr_delayed_cred_worker();
6517+#endif
6518+
6519 if (!(current->ptrace & PT_PTRACED))
6520 goto out;
6521
6522diff --git a/arch/mips/kernel/smtc-proc.c b/arch/mips/kernel/smtc-proc.c
6523index c10aa84..9ec2e60 100644
6524--- a/arch/mips/kernel/smtc-proc.c
6525+++ b/arch/mips/kernel/smtc-proc.c
6526@@ -31,7 +31,7 @@ unsigned long selfipis[NR_CPUS];
6527
6528 struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6529
6530-atomic_t smtc_fpu_recoveries;
6531+atomic_unchecked_t smtc_fpu_recoveries;
6532
6533 static int smtc_proc_show(struct seq_file *m, void *v)
6534 {
6535@@ -48,7 +48,7 @@ static int smtc_proc_show(struct seq_file *m, void *v)
6536 for(i = 0; i < NR_CPUS; i++)
6537 seq_printf(m, "%d: %ld\n", i, smtc_cpu_stats[i].selfipis);
6538 seq_printf(m, "%d Recoveries of \"stolen\" FPU\n",
6539- atomic_read(&smtc_fpu_recoveries));
6540+ atomic_read_unchecked(&smtc_fpu_recoveries));
6541 return 0;
6542 }
6543
6544@@ -73,7 +73,7 @@ void init_smtc_stats(void)
6545 smtc_cpu_stats[i].selfipis = 0;
6546 }
6547
6548- atomic_set(&smtc_fpu_recoveries, 0);
6549+ atomic_set_unchecked(&smtc_fpu_recoveries, 0);
6550
6551 proc_create("smtc", 0444, NULL, &smtc_proc_fops);
6552 }
6553diff --git a/arch/mips/kernel/smtc.c b/arch/mips/kernel/smtc.c
6554index dfc1b91..11a2c07 100644
6555--- a/arch/mips/kernel/smtc.c
6556+++ b/arch/mips/kernel/smtc.c
6557@@ -1359,7 +1359,7 @@ void smtc_soft_dump(void)
6558 }
6559 smtc_ipi_qdump();
6560 printk("%d Recoveries of \"stolen\" FPU\n",
6561- atomic_read(&smtc_fpu_recoveries));
6562+ atomic_read_unchecked(&smtc_fpu_recoveries));
6563 }
6564
6565
6566diff --git a/arch/mips/kernel/sync-r4k.c b/arch/mips/kernel/sync-r4k.c
6567index 84536bf..79caa4d 100644
6568--- a/arch/mips/kernel/sync-r4k.c
6569+++ b/arch/mips/kernel/sync-r4k.c
6570@@ -21,8 +21,8 @@
6571 #include <asm/mipsregs.h>
6572
6573 static atomic_t count_start_flag = ATOMIC_INIT(0);
6574-static atomic_t count_count_start = ATOMIC_INIT(0);
6575-static atomic_t count_count_stop = ATOMIC_INIT(0);
6576+static atomic_unchecked_t count_count_start = ATOMIC_INIT(0);
6577+static atomic_unchecked_t count_count_stop = ATOMIC_INIT(0);
6578 static atomic_t count_reference = ATOMIC_INIT(0);
6579
6580 #define COUNTON 100
6581@@ -69,13 +69,13 @@ void synchronise_count_master(int cpu)
6582
6583 for (i = 0; i < NR_LOOPS; i++) {
6584 /* slaves loop on '!= 2' */
6585- while (atomic_read(&count_count_start) != 1)
6586+ while (atomic_read_unchecked(&count_count_start) != 1)
6587 mb();
6588- atomic_set(&count_count_stop, 0);
6589+ atomic_set_unchecked(&count_count_stop, 0);
6590 smp_wmb();
6591
6592 /* this lets the slaves write their count register */
6593- atomic_inc(&count_count_start);
6594+ atomic_inc_unchecked(&count_count_start);
6595
6596 /*
6597 * Everyone initialises count in the last loop:
6598@@ -86,11 +86,11 @@ void synchronise_count_master(int cpu)
6599 /*
6600 * Wait for all slaves to leave the synchronization point:
6601 */
6602- while (atomic_read(&count_count_stop) != 1)
6603+ while (atomic_read_unchecked(&count_count_stop) != 1)
6604 mb();
6605- atomic_set(&count_count_start, 0);
6606+ atomic_set_unchecked(&count_count_start, 0);
6607 smp_wmb();
6608- atomic_inc(&count_count_stop);
6609+ atomic_inc_unchecked(&count_count_stop);
6610 }
6611 /* Arrange for an interrupt in a short while */
6612 write_c0_compare(read_c0_count() + COUNTON);
6613@@ -131,8 +131,8 @@ void synchronise_count_slave(int cpu)
6614 initcount = atomic_read(&count_reference);
6615
6616 for (i = 0; i < NR_LOOPS; i++) {
6617- atomic_inc(&count_count_start);
6618- while (atomic_read(&count_count_start) != 2)
6619+ atomic_inc_unchecked(&count_count_start);
6620+ while (atomic_read_unchecked(&count_count_start) != 2)
6621 mb();
6622
6623 /*
6624@@ -141,8 +141,8 @@ void synchronise_count_slave(int cpu)
6625 if (i == NR_LOOPS-1)
6626 write_c0_count(initcount);
6627
6628- atomic_inc(&count_count_stop);
6629- while (atomic_read(&count_count_stop) != 2)
6630+ atomic_inc_unchecked(&count_count_stop);
6631+ while (atomic_read_unchecked(&count_count_stop) != 2)
6632 mb();
6633 }
6634 /* Arrange for an interrupt in a short while */
6635diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
6636index aec3408..74d79d3 100644
6637--- a/arch/mips/kernel/traps.c
6638+++ b/arch/mips/kernel/traps.c
6639@@ -683,7 +683,18 @@ asmlinkage void do_ov(struct pt_regs *regs)
6640 siginfo_t info;
6641
6642 prev_state = exception_enter();
6643- die_if_kernel("Integer overflow", regs);
6644+ if (unlikely(!user_mode(regs))) {
6645+
6646+#ifdef CONFIG_PAX_REFCOUNT
6647+ if (fixup_exception(regs)) {
6648+ pax_report_refcount_overflow(regs);
6649+ exception_exit(prev_state);
6650+ return;
6651+ }
6652+#endif
6653+
6654+ die("Integer overflow", regs);
6655+ }
6656
6657 info.si_code = FPE_INTOVF;
6658 info.si_signo = SIGFPE;
6659diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
6660index 85df1cd..4f0a4de 100644
6661--- a/arch/mips/mm/fault.c
6662+++ b/arch/mips/mm/fault.c
6663@@ -28,6 +28,23 @@
6664 #include <asm/highmem.h> /* For VMALLOC_END */
6665 #include <linux/kdebug.h>
6666
6667+#ifdef CONFIG_PAX_PAGEEXEC
6668+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6669+{
6670+ unsigned long i;
6671+
6672+ printk(KERN_ERR "PAX: bytes at PC: ");
6673+ for (i = 0; i < 5; i++) {
6674+ unsigned int c;
6675+ if (get_user(c, (unsigned int *)pc+i))
6676+ printk(KERN_CONT "???????? ");
6677+ else
6678+ printk(KERN_CONT "%08x ", c);
6679+ }
6680+ printk("\n");
6681+}
6682+#endif
6683+
6684 /*
6685 * This routine handles page faults. It determines the address,
6686 * and the problem, and then passes it off to one of the appropriate
6687@@ -197,6 +214,14 @@ bad_area:
6688 bad_area_nosemaphore:
6689 /* User mode accesses just cause a SIGSEGV */
6690 if (user_mode(regs)) {
6691+
6692+#ifdef CONFIG_PAX_PAGEEXEC
6693+ if (cpu_has_rixi && (mm->pax_flags & MF_PAX_PAGEEXEC) && !write && address == instruction_pointer(regs)) {
6694+ pax_report_fault(regs, (void *)address, (void *)user_stack_pointer(regs));
6695+ do_group_exit(SIGKILL);
6696+ }
6697+#endif
6698+
6699 tsk->thread.cp0_badvaddr = address;
6700 tsk->thread.error_code = write;
6701 #if 0
6702diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
6703index f1baadd..8537544 100644
6704--- a/arch/mips/mm/mmap.c
6705+++ b/arch/mips/mm/mmap.c
6706@@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6707 struct vm_area_struct *vma;
6708 unsigned long addr = addr0;
6709 int do_color_align;
6710+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
6711 struct vm_unmapped_area_info info;
6712
6713 if (unlikely(len > TASK_SIZE))
6714@@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6715 do_color_align = 1;
6716
6717 /* requesting a specific address */
6718+
6719+#ifdef CONFIG_PAX_RANDMMAP
6720+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
6721+#endif
6722+
6723 if (addr) {
6724 if (do_color_align)
6725 addr = COLOUR_ALIGN(addr, pgoff);
6726@@ -91,14 +97,14 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6727 addr = PAGE_ALIGN(addr);
6728
6729 vma = find_vma(mm, addr);
6730- if (TASK_SIZE - len >= addr &&
6731- (!vma || addr + len <= vma->vm_start))
6732+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len, offset))
6733 return addr;
6734 }
6735
6736 info.length = len;
6737 info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;
6738 info.align_offset = pgoff << PAGE_SHIFT;
6739+ info.threadstack_offset = offset;
6740
6741 if (dir == DOWN) {
6742 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
6743@@ -146,6 +152,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6744 {
6745 unsigned long random_factor = 0UL;
6746
6747+#ifdef CONFIG_PAX_RANDMMAP
6748+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
6749+#endif
6750+
6751 if (current->flags & PF_RANDOMIZE) {
6752 random_factor = get_random_int();
6753 random_factor = random_factor << PAGE_SHIFT;
6754@@ -157,40 +167,25 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6755
6756 if (mmap_is_legacy()) {
6757 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
6758+
6759+#ifdef CONFIG_PAX_RANDMMAP
6760+ if (mm->pax_flags & MF_PAX_RANDMMAP)
6761+ mm->mmap_base += mm->delta_mmap;
6762+#endif
6763+
6764 mm->get_unmapped_area = arch_get_unmapped_area;
6765 } else {
6766 mm->mmap_base = mmap_base(random_factor);
6767+
6768+#ifdef CONFIG_PAX_RANDMMAP
6769+ if (mm->pax_flags & MF_PAX_RANDMMAP)
6770+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
6771+#endif
6772+
6773 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
6774 }
6775 }
6776
6777-static inline unsigned long brk_rnd(void)
6778-{
6779- unsigned long rnd = get_random_int();
6780-
6781- rnd = rnd << PAGE_SHIFT;
6782- /* 8MB for 32bit, 256MB for 64bit */
6783- if (TASK_IS_32BIT_ADDR)
6784- rnd = rnd & 0x7ffffful;
6785- else
6786- rnd = rnd & 0xffffffful;
6787-
6788- return rnd;
6789-}
6790-
6791-unsigned long arch_randomize_brk(struct mm_struct *mm)
6792-{
6793- unsigned long base = mm->brk;
6794- unsigned long ret;
6795-
6796- ret = PAGE_ALIGN(base + brk_rnd());
6797-
6798- if (ret < mm->brk)
6799- return mm->brk;
6800-
6801- return ret;
6802-}
6803-
6804 int __virt_addr_valid(const volatile void *kaddr)
6805 {
6806 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
6807diff --git a/arch/mips/sgi-ip27/ip27-nmi.c b/arch/mips/sgi-ip27/ip27-nmi.c
6808index a2358b4..7cead4f 100644
6809--- a/arch/mips/sgi-ip27/ip27-nmi.c
6810+++ b/arch/mips/sgi-ip27/ip27-nmi.c
6811@@ -187,9 +187,9 @@ void
6812 cont_nmi_dump(void)
6813 {
6814 #ifndef REAL_NMI_SIGNAL
6815- static atomic_t nmied_cpus = ATOMIC_INIT(0);
6816+ static atomic_unchecked_t nmied_cpus = ATOMIC_INIT(0);
6817
6818- atomic_inc(&nmied_cpus);
6819+ atomic_inc_unchecked(&nmied_cpus);
6820 #endif
6821 /*
6822 * Only allow 1 cpu to proceed
6823@@ -233,7 +233,7 @@ cont_nmi_dump(void)
6824 udelay(10000);
6825 }
6826 #else
6827- while (atomic_read(&nmied_cpus) != num_online_cpus());
6828+ while (atomic_read_unchecked(&nmied_cpus) != num_online_cpus());
6829 #endif
6830
6831 /*
6832diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
6833index 967d144..db12197 100644
6834--- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
6835+++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
6836@@ -11,12 +11,14 @@
6837 #ifndef _ASM_PROC_CACHE_H
6838 #define _ASM_PROC_CACHE_H
6839
6840+#include <linux/const.h>
6841+
6842 /* L1 cache */
6843
6844 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
6845 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
6846-#define L1_CACHE_BYTES 16 /* bytes per entry */
6847 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
6848+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
6849 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
6850
6851 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
6852diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
6853index bcb5df2..84fabd2 100644
6854--- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
6855+++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
6856@@ -16,13 +16,15 @@
6857 #ifndef _ASM_PROC_CACHE_H
6858 #define _ASM_PROC_CACHE_H
6859
6860+#include <linux/const.h>
6861+
6862 /*
6863 * L1 cache
6864 */
6865 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
6866 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
6867-#define L1_CACHE_BYTES 32 /* bytes per entry */
6868 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
6869+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
6870 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
6871
6872 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
6873diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
6874index 4ce7a01..449202a 100644
6875--- a/arch/openrisc/include/asm/cache.h
6876+++ b/arch/openrisc/include/asm/cache.h
6877@@ -19,11 +19,13 @@
6878 #ifndef __ASM_OPENRISC_CACHE_H
6879 #define __ASM_OPENRISC_CACHE_H
6880
6881+#include <linux/const.h>
6882+
6883 /* FIXME: How can we replace these with values from the CPU...
6884 * they shouldn't be hard-coded!
6885 */
6886
6887-#define L1_CACHE_BYTES 16
6888 #define L1_CACHE_SHIFT 4
6889+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6890
6891 #endif /* __ASM_OPENRISC_CACHE_H */
6892diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
6893index 472886c..00e7df9 100644
6894--- a/arch/parisc/include/asm/atomic.h
6895+++ b/arch/parisc/include/asm/atomic.h
6896@@ -252,6 +252,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
6897 return dec;
6898 }
6899
6900+#define atomic64_read_unchecked(v) atomic64_read(v)
6901+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
6902+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
6903+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
6904+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
6905+#define atomic64_inc_unchecked(v) atomic64_inc(v)
6906+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
6907+#define atomic64_dec_unchecked(v) atomic64_dec(v)
6908+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
6909+
6910 #endif /* !CONFIG_64BIT */
6911
6912
6913diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
6914index 47f11c7..3420df2 100644
6915--- a/arch/parisc/include/asm/cache.h
6916+++ b/arch/parisc/include/asm/cache.h
6917@@ -5,6 +5,7 @@
6918 #ifndef __ARCH_PARISC_CACHE_H
6919 #define __ARCH_PARISC_CACHE_H
6920
6921+#include <linux/const.h>
6922
6923 /*
6924 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
6925@@ -15,13 +16,13 @@
6926 * just ruin performance.
6927 */
6928 #ifdef CONFIG_PA20
6929-#define L1_CACHE_BYTES 64
6930 #define L1_CACHE_SHIFT 6
6931 #else
6932-#define L1_CACHE_BYTES 32
6933 #define L1_CACHE_SHIFT 5
6934 #endif
6935
6936+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6937+
6938 #ifndef __ASSEMBLY__
6939
6940 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6941diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
6942index ad2b503..bdf1651 100644
6943--- a/arch/parisc/include/asm/elf.h
6944+++ b/arch/parisc/include/asm/elf.h
6945@@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
6946
6947 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
6948
6949+#ifdef CONFIG_PAX_ASLR
6950+#define PAX_ELF_ET_DYN_BASE 0x10000UL
6951+
6952+#define PAX_DELTA_MMAP_LEN 16
6953+#define PAX_DELTA_STACK_LEN 16
6954+#endif
6955+
6956 /* This yields a mask that user programs can use to figure out what
6957 instruction set this CPU supports. This could be done in user space,
6958 but it's not easy, and we've already done it here. */
6959diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
6960index fc987a1..6e068ef 100644
6961--- a/arch/parisc/include/asm/pgalloc.h
6962+++ b/arch/parisc/include/asm/pgalloc.h
6963@@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
6964 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
6965 }
6966
6967+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
6968+{
6969+ pgd_populate(mm, pgd, pmd);
6970+}
6971+
6972 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
6973 {
6974 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
6975@@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
6976 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
6977 #define pmd_free(mm, x) do { } while (0)
6978 #define pgd_populate(mm, pmd, pte) BUG()
6979+#define pgd_populate_kernel(mm, pmd, pte) BUG()
6980
6981 #endif
6982
6983diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
6984index 34899b5..02dd060 100644
6985--- a/arch/parisc/include/asm/pgtable.h
6986+++ b/arch/parisc/include/asm/pgtable.h
6987@@ -223,6 +223,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
6988 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
6989 #define PAGE_COPY PAGE_EXECREAD
6990 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
6991+
6992+#ifdef CONFIG_PAX_PAGEEXEC
6993+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
6994+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
6995+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
6996+#else
6997+# define PAGE_SHARED_NOEXEC PAGE_SHARED
6998+# define PAGE_COPY_NOEXEC PAGE_COPY
6999+# define PAGE_READONLY_NOEXEC PAGE_READONLY
7000+#endif
7001+
7002 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
7003 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
7004 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
7005diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
7006index e0a8235..ce2f1e1 100644
7007--- a/arch/parisc/include/asm/uaccess.h
7008+++ b/arch/parisc/include/asm/uaccess.h
7009@@ -245,10 +245,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
7010 const void __user *from,
7011 unsigned long n)
7012 {
7013- int sz = __compiletime_object_size(to);
7014+ size_t sz = __compiletime_object_size(to);
7015 int ret = -EFAULT;
7016
7017- if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
7018+ if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
7019 ret = __copy_from_user(to, from, n);
7020 else
7021 copy_from_user_overflow();
7022diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
7023index 2a625fb..9908930 100644
7024--- a/arch/parisc/kernel/module.c
7025+++ b/arch/parisc/kernel/module.c
7026@@ -98,16 +98,38 @@
7027
7028 /* three functions to determine where in the module core
7029 * or init pieces the location is */
7030+static inline int in_init_rx(struct module *me, void *loc)
7031+{
7032+ return (loc >= me->module_init_rx &&
7033+ loc < (me->module_init_rx + me->init_size_rx));
7034+}
7035+
7036+static inline int in_init_rw(struct module *me, void *loc)
7037+{
7038+ return (loc >= me->module_init_rw &&
7039+ loc < (me->module_init_rw + me->init_size_rw));
7040+}
7041+
7042 static inline int in_init(struct module *me, void *loc)
7043 {
7044- return (loc >= me->module_init &&
7045- loc <= (me->module_init + me->init_size));
7046+ return in_init_rx(me, loc) || in_init_rw(me, loc);
7047+}
7048+
7049+static inline int in_core_rx(struct module *me, void *loc)
7050+{
7051+ return (loc >= me->module_core_rx &&
7052+ loc < (me->module_core_rx + me->core_size_rx));
7053+}
7054+
7055+static inline int in_core_rw(struct module *me, void *loc)
7056+{
7057+ return (loc >= me->module_core_rw &&
7058+ loc < (me->module_core_rw + me->core_size_rw));
7059 }
7060
7061 static inline int in_core(struct module *me, void *loc)
7062 {
7063- return (loc >= me->module_core &&
7064- loc <= (me->module_core + me->core_size));
7065+ return in_core_rx(me, loc) || in_core_rw(me, loc);
7066 }
7067
7068 static inline int in_local(struct module *me, void *loc)
7069@@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
7070 }
7071
7072 /* align things a bit */
7073- me->core_size = ALIGN(me->core_size, 16);
7074- me->arch.got_offset = me->core_size;
7075- me->core_size += gots * sizeof(struct got_entry);
7076+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
7077+ me->arch.got_offset = me->core_size_rw;
7078+ me->core_size_rw += gots * sizeof(struct got_entry);
7079
7080- me->core_size = ALIGN(me->core_size, 16);
7081- me->arch.fdesc_offset = me->core_size;
7082- me->core_size += fdescs * sizeof(Elf_Fdesc);
7083+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
7084+ me->arch.fdesc_offset = me->core_size_rw;
7085+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
7086
7087 me->arch.got_max = gots;
7088 me->arch.fdesc_max = fdescs;
7089@@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7090
7091 BUG_ON(value == 0);
7092
7093- got = me->module_core + me->arch.got_offset;
7094+ got = me->module_core_rw + me->arch.got_offset;
7095 for (i = 0; got[i].addr; i++)
7096 if (got[i].addr == value)
7097 goto out;
7098@@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7099 #ifdef CONFIG_64BIT
7100 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7101 {
7102- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
7103+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
7104
7105 if (!value) {
7106 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
7107@@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7108
7109 /* Create new one */
7110 fdesc->addr = value;
7111- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7112+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7113 return (Elf_Addr)fdesc;
7114 }
7115 #endif /* CONFIG_64BIT */
7116@@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
7117
7118 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
7119 end = table + sechdrs[me->arch.unwind_section].sh_size;
7120- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7121+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7122
7123 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
7124 me->arch.unwind_section, table, end, gp);
7125diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
7126index 5dfd248..64914ac 100644
7127--- a/arch/parisc/kernel/sys_parisc.c
7128+++ b/arch/parisc/kernel/sys_parisc.c
7129@@ -33,9 +33,11 @@
7130 #include <linux/utsname.h>
7131 #include <linux/personality.h>
7132
7133-static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
7134+static unsigned long get_unshared_area(struct file *filp, unsigned long addr, unsigned long len,
7135+ unsigned long flags)
7136 {
7137 struct vm_unmapped_area_info info;
7138+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7139
7140 info.flags = 0;
7141 info.length = len;
7142@@ -43,6 +45,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
7143 info.high_limit = TASK_SIZE;
7144 info.align_mask = 0;
7145 info.align_offset = 0;
7146+ info.threadstack_offset = offset;
7147 return vm_unmapped_area(&info);
7148 }
7149
7150@@ -61,10 +64,11 @@ static int get_offset(struct address_space *mapping)
7151 return (unsigned long) mapping >> 8;
7152 }
7153
7154-static unsigned long get_shared_area(struct address_space *mapping,
7155- unsigned long addr, unsigned long len, unsigned long pgoff)
7156+static unsigned long get_shared_area(struct file *filp, struct address_space *mapping,
7157+ unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags)
7158 {
7159 struct vm_unmapped_area_info info;
7160+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7161
7162 info.flags = 0;
7163 info.length = len;
7164@@ -72,6 +76,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
7165 info.high_limit = TASK_SIZE;
7166 info.align_mask = PAGE_MASK & (SHMLBA - 1);
7167 info.align_offset = (get_offset(mapping) + pgoff) << PAGE_SHIFT;
7168+ info.threadstack_offset = offset;
7169 return vm_unmapped_area(&info);
7170 }
7171
7172@@ -86,15 +91,22 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7173 return -EINVAL;
7174 return addr;
7175 }
7176- if (!addr)
7177+ if (!addr) {
7178 addr = TASK_UNMAPPED_BASE;
7179
7180+#ifdef CONFIG_PAX_RANDMMAP
7181+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
7182+ addr += current->mm->delta_mmap;
7183+#endif
7184+
7185+ }
7186+
7187 if (filp) {
7188- addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
7189+ addr = get_shared_area(filp, filp->f_mapping, addr, len, pgoff, flags);
7190 } else if(flags & MAP_SHARED) {
7191- addr = get_shared_area(NULL, addr, len, pgoff);
7192+ addr = get_shared_area(filp, NULL, addr, len, pgoff, flags);
7193 } else {
7194- addr = get_unshared_area(addr, len);
7195+ addr = get_unshared_area(filp, addr, len, flags);
7196 }
7197 return addr;
7198 }
7199diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
7200index 04e47c6..7a8faf6 100644
7201--- a/arch/parisc/kernel/traps.c
7202+++ b/arch/parisc/kernel/traps.c
7203@@ -727,9 +727,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
7204
7205 down_read(&current->mm->mmap_sem);
7206 vma = find_vma(current->mm,regs->iaoq[0]);
7207- if (vma && (regs->iaoq[0] >= vma->vm_start)
7208- && (vma->vm_flags & VM_EXEC)) {
7209-
7210+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
7211 fault_address = regs->iaoq[0];
7212 fault_space = regs->iasq[0];
7213
7214diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
7215index f247a34..dc0f219 100644
7216--- a/arch/parisc/mm/fault.c
7217+++ b/arch/parisc/mm/fault.c
7218@@ -15,6 +15,7 @@
7219 #include <linux/sched.h>
7220 #include <linux/interrupt.h>
7221 #include <linux/module.h>
7222+#include <linux/unistd.h>
7223
7224 #include <asm/uaccess.h>
7225 #include <asm/traps.h>
7226@@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
7227 static unsigned long
7228 parisc_acctyp(unsigned long code, unsigned int inst)
7229 {
7230- if (code == 6 || code == 16)
7231+ if (code == 6 || code == 7 || code == 16)
7232 return VM_EXEC;
7233
7234 switch (inst & 0xf0000000) {
7235@@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
7236 }
7237 #endif
7238
7239+#ifdef CONFIG_PAX_PAGEEXEC
7240+/*
7241+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
7242+ *
7243+ * returns 1 when task should be killed
7244+ * 2 when rt_sigreturn trampoline was detected
7245+ * 3 when unpatched PLT trampoline was detected
7246+ */
7247+static int pax_handle_fetch_fault(struct pt_regs *regs)
7248+{
7249+
7250+#ifdef CONFIG_PAX_EMUPLT
7251+ int err;
7252+
7253+ do { /* PaX: unpatched PLT emulation */
7254+ unsigned int bl, depwi;
7255+
7256+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
7257+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
7258+
7259+ if (err)
7260+ break;
7261+
7262+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
7263+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
7264+
7265+ err = get_user(ldw, (unsigned int *)addr);
7266+ err |= get_user(bv, (unsigned int *)(addr+4));
7267+ err |= get_user(ldw2, (unsigned int *)(addr+8));
7268+
7269+ if (err)
7270+ break;
7271+
7272+ if (ldw == 0x0E801096U &&
7273+ bv == 0xEAC0C000U &&
7274+ ldw2 == 0x0E881095U)
7275+ {
7276+ unsigned int resolver, map;
7277+
7278+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
7279+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
7280+ if (err)
7281+ break;
7282+
7283+ regs->gr[20] = instruction_pointer(regs)+8;
7284+ regs->gr[21] = map;
7285+ regs->gr[22] = resolver;
7286+ regs->iaoq[0] = resolver | 3UL;
7287+ regs->iaoq[1] = regs->iaoq[0] + 4;
7288+ return 3;
7289+ }
7290+ }
7291+ } while (0);
7292+#endif
7293+
7294+#ifdef CONFIG_PAX_EMUTRAMP
7295+
7296+#ifndef CONFIG_PAX_EMUSIGRT
7297+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
7298+ return 1;
7299+#endif
7300+
7301+ do { /* PaX: rt_sigreturn emulation */
7302+ unsigned int ldi1, ldi2, bel, nop;
7303+
7304+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
7305+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
7306+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
7307+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
7308+
7309+ if (err)
7310+ break;
7311+
7312+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
7313+ ldi2 == 0x3414015AU &&
7314+ bel == 0xE4008200U &&
7315+ nop == 0x08000240U)
7316+ {
7317+ regs->gr[25] = (ldi1 & 2) >> 1;
7318+ regs->gr[20] = __NR_rt_sigreturn;
7319+ regs->gr[31] = regs->iaoq[1] + 16;
7320+ regs->sr[0] = regs->iasq[1];
7321+ regs->iaoq[0] = 0x100UL;
7322+ regs->iaoq[1] = regs->iaoq[0] + 4;
7323+ regs->iasq[0] = regs->sr[2];
7324+ regs->iasq[1] = regs->sr[2];
7325+ return 2;
7326+ }
7327+ } while (0);
7328+#endif
7329+
7330+ return 1;
7331+}
7332+
7333+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7334+{
7335+ unsigned long i;
7336+
7337+ printk(KERN_ERR "PAX: bytes at PC: ");
7338+ for (i = 0; i < 5; i++) {
7339+ unsigned int c;
7340+ if (get_user(c, (unsigned int *)pc+i))
7341+ printk(KERN_CONT "???????? ");
7342+ else
7343+ printk(KERN_CONT "%08x ", c);
7344+ }
7345+ printk("\n");
7346+}
7347+#endif
7348+
7349 int fixup_exception(struct pt_regs *regs)
7350 {
7351 const struct exception_table_entry *fix;
7352@@ -194,8 +305,33 @@ good_area:
7353
7354 acc_type = parisc_acctyp(code,regs->iir);
7355
7356- if ((vma->vm_flags & acc_type) != acc_type)
7357+ if ((vma->vm_flags & acc_type) != acc_type) {
7358+
7359+#ifdef CONFIG_PAX_PAGEEXEC
7360+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
7361+ (address & ~3UL) == instruction_pointer(regs))
7362+ {
7363+ up_read(&mm->mmap_sem);
7364+ switch (pax_handle_fetch_fault(regs)) {
7365+
7366+#ifdef CONFIG_PAX_EMUPLT
7367+ case 3:
7368+ return;
7369+#endif
7370+
7371+#ifdef CONFIG_PAX_EMUTRAMP
7372+ case 2:
7373+ return;
7374+#endif
7375+
7376+ }
7377+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
7378+ do_group_exit(SIGKILL);
7379+ }
7380+#endif
7381+
7382 goto bad_area;
7383+ }
7384
7385 /*
7386 * If for any reason at all we couldn't handle the fault, make
7387diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
7388index e3b1d41..8e81edf 100644
7389--- a/arch/powerpc/include/asm/atomic.h
7390+++ b/arch/powerpc/include/asm/atomic.h
7391@@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
7392 return t1;
7393 }
7394
7395+#define atomic64_read_unchecked(v) atomic64_read(v)
7396+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7397+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7398+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7399+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7400+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7401+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7402+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7403+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7404+
7405 #endif /* __powerpc64__ */
7406
7407 #endif /* __KERNEL__ */
7408diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
7409index 9e495c9..b6878e5 100644
7410--- a/arch/powerpc/include/asm/cache.h
7411+++ b/arch/powerpc/include/asm/cache.h
7412@@ -3,6 +3,7 @@
7413
7414 #ifdef __KERNEL__
7415
7416+#include <linux/const.h>
7417
7418 /* bytes per L1 cache line */
7419 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
7420@@ -22,7 +23,7 @@
7421 #define L1_CACHE_SHIFT 7
7422 #endif
7423
7424-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7425+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7426
7427 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7428
7429diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
7430index cc0655a..13eac2e 100644
7431--- a/arch/powerpc/include/asm/elf.h
7432+++ b/arch/powerpc/include/asm/elf.h
7433@@ -28,8 +28,19 @@
7434 the loader. We need to make sure that it is out of the way of the program
7435 that it will "exec", and that there is sufficient room for the brk. */
7436
7437-extern unsigned long randomize_et_dyn(unsigned long base);
7438-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
7439+#define ELF_ET_DYN_BASE (0x20000000)
7440+
7441+#ifdef CONFIG_PAX_ASLR
7442+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
7443+
7444+#ifdef __powerpc64__
7445+#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
7446+#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
7447+#else
7448+#define PAX_DELTA_MMAP_LEN 15
7449+#define PAX_DELTA_STACK_LEN 15
7450+#endif
7451+#endif
7452
7453 /*
7454 * Our registers are always unsigned longs, whether we're a 32 bit
7455@@ -123,10 +134,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
7456 (0x7ff >> (PAGE_SHIFT - 12)) : \
7457 (0x3ffff >> (PAGE_SHIFT - 12)))
7458
7459-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
7460-#define arch_randomize_brk arch_randomize_brk
7461-
7462-
7463 #ifdef CONFIG_SPU_BASE
7464 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
7465 #define NT_SPU 1
7466diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
7467index 8196e9c..d83a9f3 100644
7468--- a/arch/powerpc/include/asm/exec.h
7469+++ b/arch/powerpc/include/asm/exec.h
7470@@ -4,6 +4,6 @@
7471 #ifndef _ASM_POWERPC_EXEC_H
7472 #define _ASM_POWERPC_EXEC_H
7473
7474-extern unsigned long arch_align_stack(unsigned long sp);
7475+#define arch_align_stack(x) ((x) & ~0xfUL)
7476
7477 #endif /* _ASM_POWERPC_EXEC_H */
7478diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
7479index 5acabbd..7ea14fa 100644
7480--- a/arch/powerpc/include/asm/kmap_types.h
7481+++ b/arch/powerpc/include/asm/kmap_types.h
7482@@ -10,7 +10,7 @@
7483 * 2 of the License, or (at your option) any later version.
7484 */
7485
7486-#define KM_TYPE_NR 16
7487+#define KM_TYPE_NR 17
7488
7489 #endif /* __KERNEL__ */
7490 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
7491diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
7492index 8565c25..2865190 100644
7493--- a/arch/powerpc/include/asm/mman.h
7494+++ b/arch/powerpc/include/asm/mman.h
7495@@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
7496 }
7497 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
7498
7499-static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
7500+static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
7501 {
7502 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
7503 }
7504diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
7505index b9f4262..dcf04f7 100644
7506--- a/arch/powerpc/include/asm/page.h
7507+++ b/arch/powerpc/include/asm/page.h
7508@@ -230,8 +230,9 @@ extern long long virt_phys_offset;
7509 * and needs to be executable. This means the whole heap ends
7510 * up being executable.
7511 */
7512-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
7513- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7514+#define VM_DATA_DEFAULT_FLAGS32 \
7515+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
7516+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7517
7518 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
7519 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7520@@ -259,6 +260,9 @@ extern long long virt_phys_offset;
7521 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
7522 #endif
7523
7524+#define ktla_ktva(addr) (addr)
7525+#define ktva_ktla(addr) (addr)
7526+
7527 #ifndef CONFIG_PPC_BOOK3S_64
7528 /*
7529 * Use the top bit of the higher-level page table entries to indicate whether
7530diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
7531index 88693ce..ac6f9ab 100644
7532--- a/arch/powerpc/include/asm/page_64.h
7533+++ b/arch/powerpc/include/asm/page_64.h
7534@@ -153,15 +153,18 @@ do { \
7535 * stack by default, so in the absence of a PT_GNU_STACK program header
7536 * we turn execute permission off.
7537 */
7538-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
7539- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7540+#define VM_STACK_DEFAULT_FLAGS32 \
7541+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
7542+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7543
7544 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
7545 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7546
7547+#ifndef CONFIG_PAX_PAGEEXEC
7548 #define VM_STACK_DEFAULT_FLAGS \
7549 (is_32bit_task() ? \
7550 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
7551+#endif
7552
7553 #include <asm-generic/getorder.h>
7554
7555diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
7556index f65e27b..23ffb5b 100644
7557--- a/arch/powerpc/include/asm/pgalloc-64.h
7558+++ b/arch/powerpc/include/asm/pgalloc-64.h
7559@@ -53,6 +53,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
7560 #ifndef CONFIG_PPC_64K_PAGES
7561
7562 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
7563+#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
7564
7565 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
7566 {
7567@@ -70,6 +71,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
7568 pud_set(pud, (unsigned long)pmd);
7569 }
7570
7571+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
7572+{
7573+ pud_populate(mm, pud, pmd);
7574+}
7575+
7576 #define pmd_populate(mm, pmd, pte_page) \
7577 pmd_populate_kernel(mm, pmd, page_address(pte_page))
7578 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
7579@@ -171,6 +177,7 @@ extern void __tlb_remove_table(void *_table);
7580 #endif
7581
7582 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
7583+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
7584
7585 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
7586 pte_t *pte)
7587diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
7588index 7d6eacf..14c0240 100644
7589--- a/arch/powerpc/include/asm/pgtable.h
7590+++ b/arch/powerpc/include/asm/pgtable.h
7591@@ -2,6 +2,7 @@
7592 #define _ASM_POWERPC_PGTABLE_H
7593 #ifdef __KERNEL__
7594
7595+#include <linux/const.h>
7596 #ifndef __ASSEMBLY__
7597 #include <asm/processor.h> /* For TASK_SIZE */
7598 #include <asm/mmu.h>
7599diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
7600index 4aad413..85d86bf 100644
7601--- a/arch/powerpc/include/asm/pte-hash32.h
7602+++ b/arch/powerpc/include/asm/pte-hash32.h
7603@@ -21,6 +21,7 @@
7604 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
7605 #define _PAGE_USER 0x004 /* usermode access allowed */
7606 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
7607+#define _PAGE_EXEC _PAGE_GUARDED
7608 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
7609 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
7610 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
7611diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
7612index 99222e2..f629aef 100644
7613--- a/arch/powerpc/include/asm/reg.h
7614+++ b/arch/powerpc/include/asm/reg.h
7615@@ -234,6 +234,7 @@
7616 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
7617 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
7618 #define DSISR_NOHPTE 0x40000000 /* no translation found */
7619+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
7620 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
7621 #define DSISR_ISSTORE 0x02000000 /* access was a store */
7622 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
7623diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
7624index 48cfc85..891382f 100644
7625--- a/arch/powerpc/include/asm/smp.h
7626+++ b/arch/powerpc/include/asm/smp.h
7627@@ -50,7 +50,7 @@ struct smp_ops_t {
7628 int (*cpu_disable)(void);
7629 void (*cpu_die)(unsigned int nr);
7630 int (*cpu_bootable)(unsigned int nr);
7631-};
7632+} __no_const;
7633
7634 extern void smp_send_debugger_break(void);
7635 extern void start_secondary_resume(void);
7636diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
7637index ba7b197..d292e26 100644
7638--- a/arch/powerpc/include/asm/thread_info.h
7639+++ b/arch/powerpc/include/asm/thread_info.h
7640@@ -93,7 +93,6 @@ static inline struct thread_info *current_thread_info(void)
7641 #define TIF_POLLING_NRFLAG 3 /* true if poll_idle() is polling
7642 TIF_NEED_RESCHED */
7643 #define TIF_32BIT 4 /* 32 bit binary */
7644-#define TIF_PERFMON_WORK 5 /* work for pfm_handle_work() */
7645 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
7646 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
7647 #define TIF_SINGLESTEP 8 /* singlestepping active */
7648@@ -107,6 +106,9 @@ static inline struct thread_info *current_thread_info(void)
7649 #define TIF_EMULATE_STACK_STORE 16 /* Is an instruction emulation
7650 for stack store? */
7651 #define TIF_MEMDIE 17 /* is terminating due to OOM killer */
7652+#define TIF_PERFMON_WORK 18 /* work for pfm_handle_work() */
7653+/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
7654+#define TIF_GRSEC_SETXID 5 /* update credentials on syscall entry/exit */
7655
7656 /* as above, but as bit values */
7657 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
7658@@ -126,9 +128,10 @@ static inline struct thread_info *current_thread_info(void)
7659 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
7660 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
7661 #define _TIF_NOHZ (1<<TIF_NOHZ)
7662+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
7663 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
7664 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
7665- _TIF_NOHZ)
7666+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
7667
7668 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
7669 _TIF_NOTIFY_RESUME | _TIF_UPROBE)
7670diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
7671index 9485b43..4718d50 100644
7672--- a/arch/powerpc/include/asm/uaccess.h
7673+++ b/arch/powerpc/include/asm/uaccess.h
7674@@ -318,52 +318,6 @@ do { \
7675 extern unsigned long __copy_tofrom_user(void __user *to,
7676 const void __user *from, unsigned long size);
7677
7678-#ifndef __powerpc64__
7679-
7680-static inline unsigned long copy_from_user(void *to,
7681- const void __user *from, unsigned long n)
7682-{
7683- unsigned long over;
7684-
7685- if (access_ok(VERIFY_READ, from, n))
7686- return __copy_tofrom_user((__force void __user *)to, from, n);
7687- if ((unsigned long)from < TASK_SIZE) {
7688- over = (unsigned long)from + n - TASK_SIZE;
7689- return __copy_tofrom_user((__force void __user *)to, from,
7690- n - over) + over;
7691- }
7692- return n;
7693-}
7694-
7695-static inline unsigned long copy_to_user(void __user *to,
7696- const void *from, unsigned long n)
7697-{
7698- unsigned long over;
7699-
7700- if (access_ok(VERIFY_WRITE, to, n))
7701- return __copy_tofrom_user(to, (__force void __user *)from, n);
7702- if ((unsigned long)to < TASK_SIZE) {
7703- over = (unsigned long)to + n - TASK_SIZE;
7704- return __copy_tofrom_user(to, (__force void __user *)from,
7705- n - over) + over;
7706- }
7707- return n;
7708-}
7709-
7710-#else /* __powerpc64__ */
7711-
7712-#define __copy_in_user(to, from, size) \
7713- __copy_tofrom_user((to), (from), (size))
7714-
7715-extern unsigned long copy_from_user(void *to, const void __user *from,
7716- unsigned long n);
7717-extern unsigned long copy_to_user(void __user *to, const void *from,
7718- unsigned long n);
7719-extern unsigned long copy_in_user(void __user *to, const void __user *from,
7720- unsigned long n);
7721-
7722-#endif /* __powerpc64__ */
7723-
7724 static inline unsigned long __copy_from_user_inatomic(void *to,
7725 const void __user *from, unsigned long n)
7726 {
7727@@ -387,6 +341,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
7728 if (ret == 0)
7729 return 0;
7730 }
7731+
7732+ if (!__builtin_constant_p(n))
7733+ check_object_size(to, n, false);
7734+
7735 return __copy_tofrom_user((__force void __user *)to, from, n);
7736 }
7737
7738@@ -413,6 +371,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
7739 if (ret == 0)
7740 return 0;
7741 }
7742+
7743+ if (!__builtin_constant_p(n))
7744+ check_object_size(from, n, true);
7745+
7746 return __copy_tofrom_user(to, (__force const void __user *)from, n);
7747 }
7748
7749@@ -430,6 +392,92 @@ static inline unsigned long __copy_to_user(void __user *to,
7750 return __copy_to_user_inatomic(to, from, size);
7751 }
7752
7753+#ifndef __powerpc64__
7754+
7755+static inline unsigned long __must_check copy_from_user(void *to,
7756+ const void __user *from, unsigned long n)
7757+{
7758+ unsigned long over;
7759+
7760+ if ((long)n < 0)
7761+ return n;
7762+
7763+ if (access_ok(VERIFY_READ, from, n)) {
7764+ if (!__builtin_constant_p(n))
7765+ check_object_size(to, n, false);
7766+ return __copy_tofrom_user((__force void __user *)to, from, n);
7767+ }
7768+ if ((unsigned long)from < TASK_SIZE) {
7769+ over = (unsigned long)from + n - TASK_SIZE;
7770+ if (!__builtin_constant_p(n - over))
7771+ check_object_size(to, n - over, false);
7772+ return __copy_tofrom_user((__force void __user *)to, from,
7773+ n - over) + over;
7774+ }
7775+ return n;
7776+}
7777+
7778+static inline unsigned long __must_check copy_to_user(void __user *to,
7779+ const void *from, unsigned long n)
7780+{
7781+ unsigned long over;
7782+
7783+ if ((long)n < 0)
7784+ return n;
7785+
7786+ if (access_ok(VERIFY_WRITE, to, n)) {
7787+ if (!__builtin_constant_p(n))
7788+ check_object_size(from, n, true);
7789+ return __copy_tofrom_user(to, (__force void __user *)from, n);
7790+ }
7791+ if ((unsigned long)to < TASK_SIZE) {
7792+ over = (unsigned long)to + n - TASK_SIZE;
7793+ if (!__builtin_constant_p(n))
7794+ check_object_size(from, n - over, true);
7795+ return __copy_tofrom_user(to, (__force void __user *)from,
7796+ n - over) + over;
7797+ }
7798+ return n;
7799+}
7800+
7801+#else /* __powerpc64__ */
7802+
7803+#define __copy_in_user(to, from, size) \
7804+ __copy_tofrom_user((to), (from), (size))
7805+
7806+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
7807+{
7808+ if ((long)n < 0 || n > INT_MAX)
7809+ return n;
7810+
7811+ if (!__builtin_constant_p(n))
7812+ check_object_size(to, n, false);
7813+
7814+ if (likely(access_ok(VERIFY_READ, from, n)))
7815+ n = __copy_from_user(to, from, n);
7816+ else
7817+ memset(to, 0, n);
7818+ return n;
7819+}
7820+
7821+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
7822+{
7823+ if ((long)n < 0 || n > INT_MAX)
7824+ return n;
7825+
7826+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
7827+ if (!__builtin_constant_p(n))
7828+ check_object_size(from, n, true);
7829+ n = __copy_to_user(to, from, n);
7830+ }
7831+ return n;
7832+}
7833+
7834+extern unsigned long copy_in_user(void __user *to, const void __user *from,
7835+ unsigned long n);
7836+
7837+#endif /* __powerpc64__ */
7838+
7839 extern unsigned long __clear_user(void __user *addr, unsigned long size);
7840
7841 static inline unsigned long clear_user(void __user *addr, unsigned long size)
7842diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
7843index 645170a..6cf0271 100644
7844--- a/arch/powerpc/kernel/exceptions-64e.S
7845+++ b/arch/powerpc/kernel/exceptions-64e.S
7846@@ -757,6 +757,7 @@ storage_fault_common:
7847 std r14,_DAR(r1)
7848 std r15,_DSISR(r1)
7849 addi r3,r1,STACK_FRAME_OVERHEAD
7850+ bl .save_nvgprs
7851 mr r4,r14
7852 mr r5,r15
7853 ld r14,PACA_EXGEN+EX_R14(r13)
7854@@ -765,8 +766,7 @@ storage_fault_common:
7855 cmpdi r3,0
7856 bne- 1f
7857 b .ret_from_except_lite
7858-1: bl .save_nvgprs
7859- mr r5,r3
7860+1: mr r5,r3
7861 addi r3,r1,STACK_FRAME_OVERHEAD
7862 ld r4,_DAR(r1)
7863 bl .bad_page_fault
7864diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
7865index 902ca3c..e942155 100644
7866--- a/arch/powerpc/kernel/exceptions-64s.S
7867+++ b/arch/powerpc/kernel/exceptions-64s.S
7868@@ -1357,10 +1357,10 @@ handle_page_fault:
7869 11: ld r4,_DAR(r1)
7870 ld r5,_DSISR(r1)
7871 addi r3,r1,STACK_FRAME_OVERHEAD
7872+ bl .save_nvgprs
7873 bl .do_page_fault
7874 cmpdi r3,0
7875 beq+ 12f
7876- bl .save_nvgprs
7877 mr r5,r3
7878 addi r3,r1,STACK_FRAME_OVERHEAD
7879 lwz r4,_DAR(r1)
7880diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
7881index 2e3200c..72095ce 100644
7882--- a/arch/powerpc/kernel/module_32.c
7883+++ b/arch/powerpc/kernel/module_32.c
7884@@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
7885 me->arch.core_plt_section = i;
7886 }
7887 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
7888- printk("Module doesn't contain .plt or .init.plt sections.\n");
7889+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
7890 return -ENOEXEC;
7891 }
7892
7893@@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
7894
7895 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
7896 /* Init, or core PLT? */
7897- if (location >= mod->module_core
7898- && location < mod->module_core + mod->core_size)
7899+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
7900+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
7901 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
7902- else
7903+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
7904+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
7905 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
7906+ else {
7907+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
7908+ return ~0UL;
7909+ }
7910
7911 /* Find this entry, or if that fails, the next avail. entry */
7912 while (entry->jump[0]) {
7913diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
7914index 8083be2..10aa352 100644
7915--- a/arch/powerpc/kernel/process.c
7916+++ b/arch/powerpc/kernel/process.c
7917@@ -884,8 +884,8 @@ void show_regs(struct pt_regs * regs)
7918 * Lookup NIP late so we have the best change of getting the
7919 * above info out without failing
7920 */
7921- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
7922- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
7923+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
7924+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
7925 #endif
7926 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
7927 printk("PACATMSCRATCH [%llx]\n", get_paca()->tm_scratch);
7928@@ -1349,10 +1349,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
7929 newsp = stack[0];
7930 ip = stack[STACK_FRAME_LR_SAVE];
7931 if (!firstframe || ip != lr) {
7932- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
7933+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
7934 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
7935 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
7936- printk(" (%pS)",
7937+ printk(" (%pA)",
7938 (void *)current->ret_stack[curr_frame].ret);
7939 curr_frame--;
7940 }
7941@@ -1372,7 +1372,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
7942 struct pt_regs *regs = (struct pt_regs *)
7943 (sp + STACK_FRAME_OVERHEAD);
7944 lr = regs->link;
7945- printk("--- Exception: %lx at %pS\n LR = %pS\n",
7946+ printk("--- Exception: %lx at %pA\n LR = %pA\n",
7947 regs->trap, (void *)regs->nip, (void *)lr);
7948 firstframe = 1;
7949 }
7950@@ -1408,58 +1408,3 @@ void notrace __ppc64_runlatch_off(void)
7951 mtspr(SPRN_CTRLT, ctrl);
7952 }
7953 #endif /* CONFIG_PPC64 */
7954-
7955-unsigned long arch_align_stack(unsigned long sp)
7956-{
7957- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7958- sp -= get_random_int() & ~PAGE_MASK;
7959- return sp & ~0xf;
7960-}
7961-
7962-static inline unsigned long brk_rnd(void)
7963-{
7964- unsigned long rnd = 0;
7965-
7966- /* 8MB for 32bit, 1GB for 64bit */
7967- if (is_32bit_task())
7968- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
7969- else
7970- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
7971-
7972- return rnd << PAGE_SHIFT;
7973-}
7974-
7975-unsigned long arch_randomize_brk(struct mm_struct *mm)
7976-{
7977- unsigned long base = mm->brk;
7978- unsigned long ret;
7979-
7980-#ifdef CONFIG_PPC_STD_MMU_64
7981- /*
7982- * If we are using 1TB segments and we are allowed to randomise
7983- * the heap, we can put it above 1TB so it is backed by a 1TB
7984- * segment. Otherwise the heap will be in the bottom 1TB
7985- * which always uses 256MB segments and this may result in a
7986- * performance penalty.
7987- */
7988- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
7989- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
7990-#endif
7991-
7992- ret = PAGE_ALIGN(base + brk_rnd());
7993-
7994- if (ret < mm->brk)
7995- return mm->brk;
7996-
7997- return ret;
7998-}
7999-
8000-unsigned long randomize_et_dyn(unsigned long base)
8001-{
8002- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
8003-
8004- if (ret < base)
8005- return base;
8006-
8007- return ret;
8008-}
8009diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
8010index 9a0d24c..e7fbedf 100644
8011--- a/arch/powerpc/kernel/ptrace.c
8012+++ b/arch/powerpc/kernel/ptrace.c
8013@@ -1761,6 +1761,10 @@ long arch_ptrace(struct task_struct *child, long request,
8014 return ret;
8015 }
8016
8017+#ifdef CONFIG_GRKERNSEC_SETXID
8018+extern void gr_delayed_cred_worker(void);
8019+#endif
8020+
8021 /*
8022 * We must return the syscall number to actually look up in the table.
8023 * This can be -1L to skip running any syscall at all.
8024@@ -1773,6 +1777,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
8025
8026 secure_computing_strict(regs->gpr[0]);
8027
8028+#ifdef CONFIG_GRKERNSEC_SETXID
8029+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8030+ gr_delayed_cred_worker();
8031+#endif
8032+
8033 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
8034 tracehook_report_syscall_entry(regs))
8035 /*
8036@@ -1807,6 +1816,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
8037 {
8038 int step;
8039
8040+#ifdef CONFIG_GRKERNSEC_SETXID
8041+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8042+ gr_delayed_cred_worker();
8043+#endif
8044+
8045 audit_syscall_exit(regs);
8046
8047 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
8048diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
8049index 0f83122..c0aca6a 100644
8050--- a/arch/powerpc/kernel/signal_32.c
8051+++ b/arch/powerpc/kernel/signal_32.c
8052@@ -987,7 +987,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
8053 /* Save user registers on the stack */
8054 frame = &rt_sf->uc.uc_mcontext;
8055 addr = frame;
8056- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
8057+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8058 sigret = 0;
8059 tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp;
8060 } else {
8061diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
8062index 887e99d..310bc11 100644
8063--- a/arch/powerpc/kernel/signal_64.c
8064+++ b/arch/powerpc/kernel/signal_64.c
8065@@ -751,7 +751,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
8066 #endif
8067
8068 /* Set up to return from userspace. */
8069- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
8070+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8071 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
8072 } else {
8073 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
8074diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
8075index e435bc0..41c2964 100644
8076--- a/arch/powerpc/kernel/traps.c
8077+++ b/arch/powerpc/kernel/traps.c
8078@@ -141,6 +141,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
8079 return flags;
8080 }
8081
8082+extern void gr_handle_kernel_exploit(void);
8083+
8084 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8085 int signr)
8086 {
8087@@ -190,6 +192,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8088 panic("Fatal exception in interrupt");
8089 if (panic_on_oops)
8090 panic("Fatal exception");
8091+
8092+ gr_handle_kernel_exploit();
8093+
8094 do_exit(signr);
8095 }
8096
8097diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
8098index 1d9c926..25f4741 100644
8099--- a/arch/powerpc/kernel/vdso.c
8100+++ b/arch/powerpc/kernel/vdso.c
8101@@ -34,6 +34,7 @@
8102 #include <asm/firmware.h>
8103 #include <asm/vdso.h>
8104 #include <asm/vdso_datapage.h>
8105+#include <asm/mman.h>
8106
8107 #include "setup.h"
8108
8109@@ -222,7 +223,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8110 vdso_base = VDSO32_MBASE;
8111 #endif
8112
8113- current->mm->context.vdso_base = 0;
8114+ current->mm->context.vdso_base = ~0UL;
8115
8116 /* vDSO has a problem and was disabled, just don't "enable" it for the
8117 * process
8118@@ -242,7 +243,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8119 vdso_base = get_unmapped_area(NULL, vdso_base,
8120 (vdso_pages << PAGE_SHIFT) +
8121 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
8122- 0, 0);
8123+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
8124 if (IS_ERR_VALUE(vdso_base)) {
8125 rc = vdso_base;
8126 goto fail_mmapsem;
8127diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
8128index 5eea6f3..5d10396 100644
8129--- a/arch/powerpc/lib/usercopy_64.c
8130+++ b/arch/powerpc/lib/usercopy_64.c
8131@@ -9,22 +9,6 @@
8132 #include <linux/module.h>
8133 #include <asm/uaccess.h>
8134
8135-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
8136-{
8137- if (likely(access_ok(VERIFY_READ, from, n)))
8138- n = __copy_from_user(to, from, n);
8139- else
8140- memset(to, 0, n);
8141- return n;
8142-}
8143-
8144-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
8145-{
8146- if (likely(access_ok(VERIFY_WRITE, to, n)))
8147- n = __copy_to_user(to, from, n);
8148- return n;
8149-}
8150-
8151 unsigned long copy_in_user(void __user *to, const void __user *from,
8152 unsigned long n)
8153 {
8154@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
8155 return n;
8156 }
8157
8158-EXPORT_SYMBOL(copy_from_user);
8159-EXPORT_SYMBOL(copy_to_user);
8160 EXPORT_SYMBOL(copy_in_user);
8161
8162diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
8163index 8726779..a33c512 100644
8164--- a/arch/powerpc/mm/fault.c
8165+++ b/arch/powerpc/mm/fault.c
8166@@ -33,6 +33,10 @@
8167 #include <linux/magic.h>
8168 #include <linux/ratelimit.h>
8169 #include <linux/context_tracking.h>
8170+#include <linux/slab.h>
8171+#include <linux/pagemap.h>
8172+#include <linux/compiler.h>
8173+#include <linux/unistd.h>
8174
8175 #include <asm/firmware.h>
8176 #include <asm/page.h>
8177@@ -69,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
8178 }
8179 #endif
8180
8181+#ifdef CONFIG_PAX_PAGEEXEC
8182+/*
8183+ * PaX: decide what to do with offenders (regs->nip = fault address)
8184+ *
8185+ * returns 1 when task should be killed
8186+ */
8187+static int pax_handle_fetch_fault(struct pt_regs *regs)
8188+{
8189+ return 1;
8190+}
8191+
8192+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
8193+{
8194+ unsigned long i;
8195+
8196+ printk(KERN_ERR "PAX: bytes at PC: ");
8197+ for (i = 0; i < 5; i++) {
8198+ unsigned int c;
8199+ if (get_user(c, (unsigned int __user *)pc+i))
8200+ printk(KERN_CONT "???????? ");
8201+ else
8202+ printk(KERN_CONT "%08x ", c);
8203+ }
8204+ printk("\n");
8205+}
8206+#endif
8207+
8208 /*
8209 * Check whether the instruction at regs->nip is a store using
8210 * an update addressing form which will update r1.
8211@@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
8212 * indicate errors in DSISR but can validly be set in SRR1.
8213 */
8214 if (trap == 0x400)
8215- error_code &= 0x48200000;
8216+ error_code &= 0x58200000;
8217 else
8218 is_write = error_code & DSISR_ISSTORE;
8219 #else
8220@@ -371,7 +402,7 @@ good_area:
8221 * "undefined". Of those that can be set, this is the only
8222 * one which seems bad.
8223 */
8224- if (error_code & 0x10000000)
8225+ if (error_code & DSISR_GUARDED)
8226 /* Guarded storage error. */
8227 goto bad_area;
8228 #endif /* CONFIG_8xx */
8229@@ -386,7 +417,7 @@ good_area:
8230 * processors use the same I/D cache coherency mechanism
8231 * as embedded.
8232 */
8233- if (error_code & DSISR_PROTFAULT)
8234+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
8235 goto bad_area;
8236 #endif /* CONFIG_PPC_STD_MMU */
8237
8238@@ -471,6 +502,23 @@ bad_area:
8239 bad_area_nosemaphore:
8240 /* User mode accesses cause a SIGSEGV */
8241 if (user_mode(regs)) {
8242+
8243+#ifdef CONFIG_PAX_PAGEEXEC
8244+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
8245+#ifdef CONFIG_PPC_STD_MMU
8246+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
8247+#else
8248+ if (is_exec && regs->nip == address) {
8249+#endif
8250+ switch (pax_handle_fetch_fault(regs)) {
8251+ }
8252+
8253+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
8254+ do_group_exit(SIGKILL);
8255+ }
8256+ }
8257+#endif
8258+
8259 _exception(SIGSEGV, regs, code, address);
8260 goto bail;
8261 }
8262diff --git a/arch/powerpc/mm/mmap.c b/arch/powerpc/mm/mmap.c
8263index cb8bdbe..d770680 100644
8264--- a/arch/powerpc/mm/mmap.c
8265+++ b/arch/powerpc/mm/mmap.c
8266@@ -57,6 +57,10 @@ static unsigned long mmap_rnd(void)
8267 {
8268 unsigned long rnd = 0;
8269
8270+#ifdef CONFIG_PAX_RANDMMAP
8271+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8272+#endif
8273+
8274 if (current->flags & PF_RANDOMIZE) {
8275 /* 8MB for 32bit, 1GB for 64bit */
8276 if (is_32bit_task())
8277@@ -91,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8278 */
8279 if (mmap_is_legacy()) {
8280 mm->mmap_base = TASK_UNMAPPED_BASE;
8281+
8282+#ifdef CONFIG_PAX_RANDMMAP
8283+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8284+ mm->mmap_base += mm->delta_mmap;
8285+#endif
8286+
8287 mm->get_unmapped_area = arch_get_unmapped_area;
8288 } else {
8289 mm->mmap_base = mmap_base();
8290+
8291+#ifdef CONFIG_PAX_RANDMMAP
8292+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8293+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8294+#endif
8295+
8296 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8297 }
8298 }
8299diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
8300index 3e99c14..f00953c 100644
8301--- a/arch/powerpc/mm/slice.c
8302+++ b/arch/powerpc/mm/slice.c
8303@@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
8304 if ((mm->task_size - len) < addr)
8305 return 0;
8306 vma = find_vma(mm, addr);
8307- return (!vma || (addr + len) <= vma->vm_start);
8308+ return check_heap_stack_gap(vma, addr, len, 0);
8309 }
8310
8311 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
8312@@ -277,6 +277,12 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
8313 info.align_offset = 0;
8314
8315 addr = TASK_UNMAPPED_BASE;
8316+
8317+#ifdef CONFIG_PAX_RANDMMAP
8318+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8319+ addr += mm->delta_mmap;
8320+#endif
8321+
8322 while (addr < TASK_SIZE) {
8323 info.low_limit = addr;
8324 if (!slice_scan_available(addr, available, 1, &addr))
8325@@ -410,6 +416,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
8326 if (fixed && addr > (mm->task_size - len))
8327 return -EINVAL;
8328
8329+#ifdef CONFIG_PAX_RANDMMAP
8330+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
8331+ addr = 0;
8332+#endif
8333+
8334 /* If hint, make sure it matches our alignment restrictions */
8335 if (!fixed && addr) {
8336 addr = _ALIGN_UP(addr, 1ul << pshift);
8337diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
8338index 9098692..3d54cd1 100644
8339--- a/arch/powerpc/platforms/cell/spufs/file.c
8340+++ b/arch/powerpc/platforms/cell/spufs/file.c
8341@@ -280,9 +280,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
8342 return VM_FAULT_NOPAGE;
8343 }
8344
8345-static int spufs_mem_mmap_access(struct vm_area_struct *vma,
8346+static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
8347 unsigned long address,
8348- void *buf, int len, int write)
8349+ void *buf, size_t len, int write)
8350 {
8351 struct spu_context *ctx = vma->vm_file->private_data;
8352 unsigned long offset = address - vma->vm_start;
8353diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
8354index c797832..ce575c8 100644
8355--- a/arch/s390/include/asm/atomic.h
8356+++ b/arch/s390/include/asm/atomic.h
8357@@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
8358 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
8359 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
8360
8361+#define atomic64_read_unchecked(v) atomic64_read(v)
8362+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
8363+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
8364+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
8365+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
8366+#define atomic64_inc_unchecked(v) atomic64_inc(v)
8367+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
8368+#define atomic64_dec_unchecked(v) atomic64_dec(v)
8369+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
8370+
8371 #define smp_mb__before_atomic_dec() smp_mb()
8372 #define smp_mb__after_atomic_dec() smp_mb()
8373 #define smp_mb__before_atomic_inc() smp_mb()
8374diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
8375index 4d7ccac..d03d0ad 100644
8376--- a/arch/s390/include/asm/cache.h
8377+++ b/arch/s390/include/asm/cache.h
8378@@ -9,8 +9,10 @@
8379 #ifndef __ARCH_S390_CACHE_H
8380 #define __ARCH_S390_CACHE_H
8381
8382-#define L1_CACHE_BYTES 256
8383+#include <linux/const.h>
8384+
8385 #define L1_CACHE_SHIFT 8
8386+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8387 #define NET_SKB_PAD 32
8388
8389 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
8390diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
8391index 78f4f87..598ce39 100644
8392--- a/arch/s390/include/asm/elf.h
8393+++ b/arch/s390/include/asm/elf.h
8394@@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
8395 the loader. We need to make sure that it is out of the way of the program
8396 that it will "exec", and that there is sufficient room for the brk. */
8397
8398-extern unsigned long randomize_et_dyn(unsigned long base);
8399-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
8400+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
8401+
8402+#ifdef CONFIG_PAX_ASLR
8403+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
8404+
8405+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
8406+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
8407+#endif
8408
8409 /* This yields a mask that user programs can use to figure out what
8410 instruction set this CPU supports. */
8411@@ -222,9 +228,6 @@ struct linux_binprm;
8412 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
8413 int arch_setup_additional_pages(struct linux_binprm *, int);
8414
8415-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
8416-#define arch_randomize_brk arch_randomize_brk
8417-
8418 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
8419
8420 #endif
8421diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
8422index c4a93d6..4d2a9b4 100644
8423--- a/arch/s390/include/asm/exec.h
8424+++ b/arch/s390/include/asm/exec.h
8425@@ -7,6 +7,6 @@
8426 #ifndef __ASM_EXEC_H
8427 #define __ASM_EXEC_H
8428
8429-extern unsigned long arch_align_stack(unsigned long sp);
8430+#define arch_align_stack(x) ((x) & ~0xfUL)
8431
8432 #endif /* __ASM_EXEC_H */
8433diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
8434index 9c33ed4..e40cbef 100644
8435--- a/arch/s390/include/asm/uaccess.h
8436+++ b/arch/s390/include/asm/uaccess.h
8437@@ -252,6 +252,10 @@ static inline unsigned long __must_check
8438 copy_to_user(void __user *to, const void *from, unsigned long n)
8439 {
8440 might_fault();
8441+
8442+ if ((long)n < 0)
8443+ return n;
8444+
8445 return __copy_to_user(to, from, n);
8446 }
8447
8448@@ -275,6 +279,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
8449 static inline unsigned long __must_check
8450 __copy_from_user(void *to, const void __user *from, unsigned long n)
8451 {
8452+ if ((long)n < 0)
8453+ return n;
8454+
8455 if (__builtin_constant_p(n) && (n <= 256))
8456 return uaccess.copy_from_user_small(n, from, to);
8457 else
8458@@ -306,10 +313,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
8459 static inline unsigned long __must_check
8460 copy_from_user(void *to, const void __user *from, unsigned long n)
8461 {
8462- unsigned int sz = __compiletime_object_size(to);
8463+ size_t sz = __compiletime_object_size(to);
8464
8465 might_fault();
8466- if (unlikely(sz != -1 && sz < n)) {
8467+
8468+ if ((long)n < 0)
8469+ return n;
8470+
8471+ if (unlikely(sz != (size_t)-1 && sz < n)) {
8472 copy_from_user_overflow();
8473 return n;
8474 }
8475diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
8476index 7845e15..59c4353 100644
8477--- a/arch/s390/kernel/module.c
8478+++ b/arch/s390/kernel/module.c
8479@@ -169,11 +169,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
8480
8481 /* Increase core size by size of got & plt and set start
8482 offsets for got and plt. */
8483- me->core_size = ALIGN(me->core_size, 4);
8484- me->arch.got_offset = me->core_size;
8485- me->core_size += me->arch.got_size;
8486- me->arch.plt_offset = me->core_size;
8487- me->core_size += me->arch.plt_size;
8488+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
8489+ me->arch.got_offset = me->core_size_rw;
8490+ me->core_size_rw += me->arch.got_size;
8491+ me->arch.plt_offset = me->core_size_rx;
8492+ me->core_size_rx += me->arch.plt_size;
8493 return 0;
8494 }
8495
8496@@ -289,7 +289,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8497 if (info->got_initialized == 0) {
8498 Elf_Addr *gotent;
8499
8500- gotent = me->module_core + me->arch.got_offset +
8501+ gotent = me->module_core_rw + me->arch.got_offset +
8502 info->got_offset;
8503 *gotent = val;
8504 info->got_initialized = 1;
8505@@ -312,7 +312,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8506 rc = apply_rela_bits(loc, val, 0, 64, 0);
8507 else if (r_type == R_390_GOTENT ||
8508 r_type == R_390_GOTPLTENT) {
8509- val += (Elf_Addr) me->module_core - loc;
8510+ val += (Elf_Addr) me->module_core_rw - loc;
8511 rc = apply_rela_bits(loc, val, 1, 32, 1);
8512 }
8513 break;
8514@@ -325,7 +325,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8515 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
8516 if (info->plt_initialized == 0) {
8517 unsigned int *ip;
8518- ip = me->module_core + me->arch.plt_offset +
8519+ ip = me->module_core_rx + me->arch.plt_offset +
8520 info->plt_offset;
8521 #ifndef CONFIG_64BIT
8522 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
8523@@ -350,7 +350,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8524 val - loc + 0xffffUL < 0x1ffffeUL) ||
8525 (r_type == R_390_PLT32DBL &&
8526 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
8527- val = (Elf_Addr) me->module_core +
8528+ val = (Elf_Addr) me->module_core_rx +
8529 me->arch.plt_offset +
8530 info->plt_offset;
8531 val += rela->r_addend - loc;
8532@@ -372,7 +372,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8533 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
8534 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
8535 val = val + rela->r_addend -
8536- ((Elf_Addr) me->module_core + me->arch.got_offset);
8537+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
8538 if (r_type == R_390_GOTOFF16)
8539 rc = apply_rela_bits(loc, val, 0, 16, 0);
8540 else if (r_type == R_390_GOTOFF32)
8541@@ -382,7 +382,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8542 break;
8543 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
8544 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
8545- val = (Elf_Addr) me->module_core + me->arch.got_offset +
8546+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
8547 rela->r_addend - loc;
8548 if (r_type == R_390_GOTPC)
8549 rc = apply_rela_bits(loc, val, 1, 32, 0);
8550diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
8551index 2bc3edd..ab9d598 100644
8552--- a/arch/s390/kernel/process.c
8553+++ b/arch/s390/kernel/process.c
8554@@ -236,39 +236,3 @@ unsigned long get_wchan(struct task_struct *p)
8555 }
8556 return 0;
8557 }
8558-
8559-unsigned long arch_align_stack(unsigned long sp)
8560-{
8561- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8562- sp -= get_random_int() & ~PAGE_MASK;
8563- return sp & ~0xf;
8564-}
8565-
8566-static inline unsigned long brk_rnd(void)
8567-{
8568- /* 8MB for 32bit, 1GB for 64bit */
8569- if (is_32bit_task())
8570- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
8571- else
8572- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
8573-}
8574-
8575-unsigned long arch_randomize_brk(struct mm_struct *mm)
8576-{
8577- unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
8578-
8579- if (ret < mm->brk)
8580- return mm->brk;
8581- return ret;
8582-}
8583-
8584-unsigned long randomize_et_dyn(unsigned long base)
8585-{
8586- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
8587-
8588- if (!(current->flags & PF_RANDOMIZE))
8589- return base;
8590- if (ret < base)
8591- return base;
8592- return ret;
8593-}
8594diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
8595index 4002329..99b67cb 100644
8596--- a/arch/s390/mm/mmap.c
8597+++ b/arch/s390/mm/mmap.c
8598@@ -90,9 +90,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8599 */
8600 if (mmap_is_legacy()) {
8601 mm->mmap_base = TASK_UNMAPPED_BASE;
8602+
8603+#ifdef CONFIG_PAX_RANDMMAP
8604+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8605+ mm->mmap_base += mm->delta_mmap;
8606+#endif
8607+
8608 mm->get_unmapped_area = arch_get_unmapped_area;
8609 } else {
8610 mm->mmap_base = mmap_base();
8611+
8612+#ifdef CONFIG_PAX_RANDMMAP
8613+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8614+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8615+#endif
8616+
8617 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8618 }
8619 }
8620@@ -173,9 +185,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8621 */
8622 if (mmap_is_legacy()) {
8623 mm->mmap_base = TASK_UNMAPPED_BASE;
8624+
8625+#ifdef CONFIG_PAX_RANDMMAP
8626+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8627+ mm->mmap_base += mm->delta_mmap;
8628+#endif
8629+
8630 mm->get_unmapped_area = s390_get_unmapped_area;
8631 } else {
8632 mm->mmap_base = mmap_base();
8633+
8634+#ifdef CONFIG_PAX_RANDMMAP
8635+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8636+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8637+#endif
8638+
8639 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
8640 }
8641 }
8642diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
8643index ae3d59f..f65f075 100644
8644--- a/arch/score/include/asm/cache.h
8645+++ b/arch/score/include/asm/cache.h
8646@@ -1,7 +1,9 @@
8647 #ifndef _ASM_SCORE_CACHE_H
8648 #define _ASM_SCORE_CACHE_H
8649
8650+#include <linux/const.h>
8651+
8652 #define L1_CACHE_SHIFT 4
8653-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8654+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8655
8656 #endif /* _ASM_SCORE_CACHE_H */
8657diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
8658index f9f3cd5..58ff438 100644
8659--- a/arch/score/include/asm/exec.h
8660+++ b/arch/score/include/asm/exec.h
8661@@ -1,6 +1,6 @@
8662 #ifndef _ASM_SCORE_EXEC_H
8663 #define _ASM_SCORE_EXEC_H
8664
8665-extern unsigned long arch_align_stack(unsigned long sp);
8666+#define arch_align_stack(x) (x)
8667
8668 #endif /* _ASM_SCORE_EXEC_H */
8669diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
8670index f4c6d02..e9355c3 100644
8671--- a/arch/score/kernel/process.c
8672+++ b/arch/score/kernel/process.c
8673@@ -116,8 +116,3 @@ unsigned long get_wchan(struct task_struct *task)
8674
8675 return task_pt_regs(task)->cp0_epc;
8676 }
8677-
8678-unsigned long arch_align_stack(unsigned long sp)
8679-{
8680- return sp;
8681-}
8682diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
8683index ef9e555..331bd29 100644
8684--- a/arch/sh/include/asm/cache.h
8685+++ b/arch/sh/include/asm/cache.h
8686@@ -9,10 +9,11 @@
8687 #define __ASM_SH_CACHE_H
8688 #ifdef __KERNEL__
8689
8690+#include <linux/const.h>
8691 #include <linux/init.h>
8692 #include <cpu/cache.h>
8693
8694-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8695+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8696
8697 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
8698
8699diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
8700index 6777177..cb5e44f 100644
8701--- a/arch/sh/mm/mmap.c
8702+++ b/arch/sh/mm/mmap.c
8703@@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
8704 struct mm_struct *mm = current->mm;
8705 struct vm_area_struct *vma;
8706 int do_colour_align;
8707+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8708 struct vm_unmapped_area_info info;
8709
8710 if (flags & MAP_FIXED) {
8711@@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
8712 if (filp || (flags & MAP_SHARED))
8713 do_colour_align = 1;
8714
8715+#ifdef CONFIG_PAX_RANDMMAP
8716+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8717+#endif
8718+
8719 if (addr) {
8720 if (do_colour_align)
8721 addr = COLOUR_ALIGN(addr, pgoff);
8722@@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
8723 addr = PAGE_ALIGN(addr);
8724
8725 vma = find_vma(mm, addr);
8726- if (TASK_SIZE - len >= addr &&
8727- (!vma || addr + len <= vma->vm_start))
8728+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8729 return addr;
8730 }
8731
8732 info.flags = 0;
8733 info.length = len;
8734- info.low_limit = TASK_UNMAPPED_BASE;
8735+ info.low_limit = mm->mmap_base;
8736 info.high_limit = TASK_SIZE;
8737 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
8738 info.align_offset = pgoff << PAGE_SHIFT;
8739@@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8740 struct mm_struct *mm = current->mm;
8741 unsigned long addr = addr0;
8742 int do_colour_align;
8743+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8744 struct vm_unmapped_area_info info;
8745
8746 if (flags & MAP_FIXED) {
8747@@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8748 if (filp || (flags & MAP_SHARED))
8749 do_colour_align = 1;
8750
8751+#ifdef CONFIG_PAX_RANDMMAP
8752+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8753+#endif
8754+
8755 /* requesting a specific address */
8756 if (addr) {
8757 if (do_colour_align)
8758@@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8759 addr = PAGE_ALIGN(addr);
8760
8761 vma = find_vma(mm, addr);
8762- if (TASK_SIZE - len >= addr &&
8763- (!vma || addr + len <= vma->vm_start))
8764+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8765 return addr;
8766 }
8767
8768@@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8769 VM_BUG_ON(addr != -ENOMEM);
8770 info.flags = 0;
8771 info.low_limit = TASK_UNMAPPED_BASE;
8772+
8773+#ifdef CONFIG_PAX_RANDMMAP
8774+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8775+ info.low_limit += mm->delta_mmap;
8776+#endif
8777+
8778 info.high_limit = TASK_SIZE;
8779 addr = vm_unmapped_area(&info);
8780 }
8781diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
8782index be56a24..443328f 100644
8783--- a/arch/sparc/include/asm/atomic_64.h
8784+++ b/arch/sparc/include/asm/atomic_64.h
8785@@ -14,18 +14,40 @@
8786 #define ATOMIC64_INIT(i) { (i) }
8787
8788 #define atomic_read(v) (*(volatile int *)&(v)->counter)
8789+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
8790+{
8791+ return v->counter;
8792+}
8793 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
8794+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
8795+{
8796+ return v->counter;
8797+}
8798
8799 #define atomic_set(v, i) (((v)->counter) = i)
8800+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
8801+{
8802+ v->counter = i;
8803+}
8804 #define atomic64_set(v, i) (((v)->counter) = i)
8805+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
8806+{
8807+ v->counter = i;
8808+}
8809
8810 extern void atomic_add(int, atomic_t *);
8811+extern void atomic_add_unchecked(int, atomic_unchecked_t *);
8812 extern void atomic64_add(long, atomic64_t *);
8813+extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
8814 extern void atomic_sub(int, atomic_t *);
8815+extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
8816 extern void atomic64_sub(long, atomic64_t *);
8817+extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
8818
8819 extern int atomic_add_ret(int, atomic_t *);
8820+extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
8821 extern long atomic64_add_ret(long, atomic64_t *);
8822+extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
8823 extern int atomic_sub_ret(int, atomic_t *);
8824 extern long atomic64_sub_ret(long, atomic64_t *);
8825
8826@@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
8827 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
8828
8829 #define atomic_inc_return(v) atomic_add_ret(1, v)
8830+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
8831+{
8832+ return atomic_add_ret_unchecked(1, v);
8833+}
8834 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
8835+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
8836+{
8837+ return atomic64_add_ret_unchecked(1, v);
8838+}
8839
8840 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
8841 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
8842
8843 #define atomic_add_return(i, v) atomic_add_ret(i, v)
8844+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
8845+{
8846+ return atomic_add_ret_unchecked(i, v);
8847+}
8848 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
8849+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
8850+{
8851+ return atomic64_add_ret_unchecked(i, v);
8852+}
8853
8854 /*
8855 * atomic_inc_and_test - increment and test
8856@@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
8857 * other cases.
8858 */
8859 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
8860+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
8861+{
8862+ return atomic_inc_return_unchecked(v) == 0;
8863+}
8864 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
8865
8866 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
8867@@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
8868 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
8869
8870 #define atomic_inc(v) atomic_add(1, v)
8871+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
8872+{
8873+ atomic_add_unchecked(1, v);
8874+}
8875 #define atomic64_inc(v) atomic64_add(1, v)
8876+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
8877+{
8878+ atomic64_add_unchecked(1, v);
8879+}
8880
8881 #define atomic_dec(v) atomic_sub(1, v)
8882+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
8883+{
8884+ atomic_sub_unchecked(1, v);
8885+}
8886 #define atomic64_dec(v) atomic64_sub(1, v)
8887+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
8888+{
8889+ atomic64_sub_unchecked(1, v);
8890+}
8891
8892 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
8893 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
8894
8895 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
8896+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
8897+{
8898+ return cmpxchg(&v->counter, old, new);
8899+}
8900 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
8901+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
8902+{
8903+ return xchg(&v->counter, new);
8904+}
8905
8906 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
8907 {
8908- int c, old;
8909+ int c, old, new;
8910 c = atomic_read(v);
8911 for (;;) {
8912- if (unlikely(c == (u)))
8913+ if (unlikely(c == u))
8914 break;
8915- old = atomic_cmpxchg((v), c, c + (a));
8916+
8917+ asm volatile("addcc %2, %0, %0\n"
8918+
8919+#ifdef CONFIG_PAX_REFCOUNT
8920+ "tvs %%icc, 6\n"
8921+#endif
8922+
8923+ : "=r" (new)
8924+ : "0" (c), "ir" (a)
8925+ : "cc");
8926+
8927+ old = atomic_cmpxchg(v, c, new);
8928 if (likely(old == c))
8929 break;
8930 c = old;
8931@@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
8932 #define atomic64_cmpxchg(v, o, n) \
8933 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
8934 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
8935+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
8936+{
8937+ return xchg(&v->counter, new);
8938+}
8939
8940 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
8941 {
8942- long c, old;
8943+ long c, old, new;
8944 c = atomic64_read(v);
8945 for (;;) {
8946- if (unlikely(c == (u)))
8947+ if (unlikely(c == u))
8948 break;
8949- old = atomic64_cmpxchg((v), c, c + (a));
8950+
8951+ asm volatile("addcc %2, %0, %0\n"
8952+
8953+#ifdef CONFIG_PAX_REFCOUNT
8954+ "tvs %%xcc, 6\n"
8955+#endif
8956+
8957+ : "=r" (new)
8958+ : "0" (c), "ir" (a)
8959+ : "cc");
8960+
8961+ old = atomic64_cmpxchg(v, c, new);
8962 if (likely(old == c))
8963 break;
8964 c = old;
8965 }
8966- return c != (u);
8967+ return c != u;
8968 }
8969
8970 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
8971diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
8972index 5bb6991..5c2132e 100644
8973--- a/arch/sparc/include/asm/cache.h
8974+++ b/arch/sparc/include/asm/cache.h
8975@@ -7,10 +7,12 @@
8976 #ifndef _SPARC_CACHE_H
8977 #define _SPARC_CACHE_H
8978
8979+#include <linux/const.h>
8980+
8981 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
8982
8983 #define L1_CACHE_SHIFT 5
8984-#define L1_CACHE_BYTES 32
8985+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8986
8987 #ifdef CONFIG_SPARC32
8988 #define SMP_CACHE_BYTES_SHIFT 5
8989diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
8990index a24e41f..47677ff 100644
8991--- a/arch/sparc/include/asm/elf_32.h
8992+++ b/arch/sparc/include/asm/elf_32.h
8993@@ -114,6 +114,13 @@ typedef struct {
8994
8995 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
8996
8997+#ifdef CONFIG_PAX_ASLR
8998+#define PAX_ELF_ET_DYN_BASE 0x10000UL
8999+
9000+#define PAX_DELTA_MMAP_LEN 16
9001+#define PAX_DELTA_STACK_LEN 16
9002+#endif
9003+
9004 /* This yields a mask that user programs can use to figure out what
9005 instruction set this cpu supports. This can NOT be done in userspace
9006 on Sparc. */
9007diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
9008index 370ca1e..d4f4a98 100644
9009--- a/arch/sparc/include/asm/elf_64.h
9010+++ b/arch/sparc/include/asm/elf_64.h
9011@@ -189,6 +189,13 @@ typedef struct {
9012 #define ELF_ET_DYN_BASE 0x0000010000000000UL
9013 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
9014
9015+#ifdef CONFIG_PAX_ASLR
9016+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
9017+
9018+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
9019+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
9020+#endif
9021+
9022 extern unsigned long sparc64_elf_hwcap;
9023 #define ELF_HWCAP sparc64_elf_hwcap
9024
9025diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
9026index 9b1c36d..209298b 100644
9027--- a/arch/sparc/include/asm/pgalloc_32.h
9028+++ b/arch/sparc/include/asm/pgalloc_32.h
9029@@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
9030 }
9031
9032 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
9033+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
9034
9035 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
9036 unsigned long address)
9037diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
9038index bcfe063..b333142 100644
9039--- a/arch/sparc/include/asm/pgalloc_64.h
9040+++ b/arch/sparc/include/asm/pgalloc_64.h
9041@@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
9042 }
9043
9044 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
9045+#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
9046
9047 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
9048 {
9049diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
9050index 502f632..da1917f 100644
9051--- a/arch/sparc/include/asm/pgtable_32.h
9052+++ b/arch/sparc/include/asm/pgtable_32.h
9053@@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
9054 #define PAGE_SHARED SRMMU_PAGE_SHARED
9055 #define PAGE_COPY SRMMU_PAGE_COPY
9056 #define PAGE_READONLY SRMMU_PAGE_RDONLY
9057+#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
9058+#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
9059+#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
9060 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
9061
9062 /* Top-level page directory - dummy used by init-mm.
9063@@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
9064
9065 /* xwr */
9066 #define __P000 PAGE_NONE
9067-#define __P001 PAGE_READONLY
9068-#define __P010 PAGE_COPY
9069-#define __P011 PAGE_COPY
9070+#define __P001 PAGE_READONLY_NOEXEC
9071+#define __P010 PAGE_COPY_NOEXEC
9072+#define __P011 PAGE_COPY_NOEXEC
9073 #define __P100 PAGE_READONLY
9074 #define __P101 PAGE_READONLY
9075 #define __P110 PAGE_COPY
9076 #define __P111 PAGE_COPY
9077
9078 #define __S000 PAGE_NONE
9079-#define __S001 PAGE_READONLY
9080-#define __S010 PAGE_SHARED
9081-#define __S011 PAGE_SHARED
9082+#define __S001 PAGE_READONLY_NOEXEC
9083+#define __S010 PAGE_SHARED_NOEXEC
9084+#define __S011 PAGE_SHARED_NOEXEC
9085 #define __S100 PAGE_READONLY
9086 #define __S101 PAGE_READONLY
9087 #define __S110 PAGE_SHARED
9088diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
9089index 79da178..c2eede8 100644
9090--- a/arch/sparc/include/asm/pgtsrmmu.h
9091+++ b/arch/sparc/include/asm/pgtsrmmu.h
9092@@ -115,6 +115,11 @@
9093 SRMMU_EXEC | SRMMU_REF)
9094 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
9095 SRMMU_EXEC | SRMMU_REF)
9096+
9097+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
9098+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9099+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9100+
9101 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
9102 SRMMU_DIRTY | SRMMU_REF)
9103
9104diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
9105index 9689176..63c18ea 100644
9106--- a/arch/sparc/include/asm/spinlock_64.h
9107+++ b/arch/sparc/include/asm/spinlock_64.h
9108@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
9109
9110 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
9111
9112-static void inline arch_read_lock(arch_rwlock_t *lock)
9113+static inline void arch_read_lock(arch_rwlock_t *lock)
9114 {
9115 unsigned long tmp1, tmp2;
9116
9117 __asm__ __volatile__ (
9118 "1: ldsw [%2], %0\n"
9119 " brlz,pn %0, 2f\n"
9120-"4: add %0, 1, %1\n"
9121+"4: addcc %0, 1, %1\n"
9122+
9123+#ifdef CONFIG_PAX_REFCOUNT
9124+" tvs %%icc, 6\n"
9125+#endif
9126+
9127 " cas [%2], %0, %1\n"
9128 " cmp %0, %1\n"
9129 " bne,pn %%icc, 1b\n"
9130@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
9131 " .previous"
9132 : "=&r" (tmp1), "=&r" (tmp2)
9133 : "r" (lock)
9134- : "memory");
9135+ : "memory", "cc");
9136 }
9137
9138-static int inline arch_read_trylock(arch_rwlock_t *lock)
9139+static inline int arch_read_trylock(arch_rwlock_t *lock)
9140 {
9141 int tmp1, tmp2;
9142
9143@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9144 "1: ldsw [%2], %0\n"
9145 " brlz,a,pn %0, 2f\n"
9146 " mov 0, %0\n"
9147-" add %0, 1, %1\n"
9148+" addcc %0, 1, %1\n"
9149+
9150+#ifdef CONFIG_PAX_REFCOUNT
9151+" tvs %%icc, 6\n"
9152+#endif
9153+
9154 " cas [%2], %0, %1\n"
9155 " cmp %0, %1\n"
9156 " bne,pn %%icc, 1b\n"
9157@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9158 return tmp1;
9159 }
9160
9161-static void inline arch_read_unlock(arch_rwlock_t *lock)
9162+static inline void arch_read_unlock(arch_rwlock_t *lock)
9163 {
9164 unsigned long tmp1, tmp2;
9165
9166 __asm__ __volatile__(
9167 "1: lduw [%2], %0\n"
9168-" sub %0, 1, %1\n"
9169+" subcc %0, 1, %1\n"
9170+
9171+#ifdef CONFIG_PAX_REFCOUNT
9172+" tvs %%icc, 6\n"
9173+#endif
9174+
9175 " cas [%2], %0, %1\n"
9176 " cmp %0, %1\n"
9177 " bne,pn %%xcc, 1b\n"
9178@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
9179 : "memory");
9180 }
9181
9182-static void inline arch_write_lock(arch_rwlock_t *lock)
9183+static inline void arch_write_lock(arch_rwlock_t *lock)
9184 {
9185 unsigned long mask, tmp1, tmp2;
9186
9187@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
9188 : "memory");
9189 }
9190
9191-static void inline arch_write_unlock(arch_rwlock_t *lock)
9192+static inline void arch_write_unlock(arch_rwlock_t *lock)
9193 {
9194 __asm__ __volatile__(
9195 " stw %%g0, [%0]"
9196@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
9197 : "memory");
9198 }
9199
9200-static int inline arch_write_trylock(arch_rwlock_t *lock)
9201+static inline int arch_write_trylock(arch_rwlock_t *lock)
9202 {
9203 unsigned long mask, tmp1, tmp2, result;
9204
9205diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
9206index dd38075..e7cac83 100644
9207--- a/arch/sparc/include/asm/thread_info_32.h
9208+++ b/arch/sparc/include/asm/thread_info_32.h
9209@@ -49,6 +49,8 @@ struct thread_info {
9210 unsigned long w_saved;
9211
9212 struct restart_block restart_block;
9213+
9214+ unsigned long lowest_stack;
9215 };
9216
9217 /*
9218diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
9219index d5e5042..9bfee76 100644
9220--- a/arch/sparc/include/asm/thread_info_64.h
9221+++ b/arch/sparc/include/asm/thread_info_64.h
9222@@ -63,6 +63,8 @@ struct thread_info {
9223 struct pt_regs *kern_una_regs;
9224 unsigned int kern_una_insn;
9225
9226+ unsigned long lowest_stack;
9227+
9228 unsigned long fpregs[0] __attribute__ ((aligned(64)));
9229 };
9230
9231@@ -192,10 +194,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
9232 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
9233 /* flag bit 6 is available */
9234 #define TIF_32BIT 7 /* 32-bit binary */
9235-/* flag bit 8 is available */
9236+#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
9237 #define TIF_SECCOMP 9 /* secure computing */
9238 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
9239 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
9240+
9241 /* NOTE: Thread flags >= 12 should be ones we have no interest
9242 * in using in assembly, else we can't use the mask as
9243 * an immediate value in instructions such as andcc.
9244@@ -214,12 +217,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
9245 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
9246 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
9247 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
9248+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
9249
9250 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
9251 _TIF_DO_NOTIFY_RESUME_MASK | \
9252 _TIF_NEED_RESCHED)
9253 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
9254
9255+#define _TIF_WORK_SYSCALL \
9256+ (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
9257+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
9258+
9259+
9260 /*
9261 * Thread-synchronous status.
9262 *
9263diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
9264index 0167d26..767bb0c 100644
9265--- a/arch/sparc/include/asm/uaccess.h
9266+++ b/arch/sparc/include/asm/uaccess.h
9267@@ -1,5 +1,6 @@
9268 #ifndef ___ASM_SPARC_UACCESS_H
9269 #define ___ASM_SPARC_UACCESS_H
9270+
9271 #if defined(__sparc__) && defined(__arch64__)
9272 #include <asm/uaccess_64.h>
9273 #else
9274diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
9275index 53a28dd..50c38c3 100644
9276--- a/arch/sparc/include/asm/uaccess_32.h
9277+++ b/arch/sparc/include/asm/uaccess_32.h
9278@@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
9279
9280 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
9281 {
9282- if (n && __access_ok((unsigned long) to, n))
9283+ if ((long)n < 0)
9284+ return n;
9285+
9286+ if (n && __access_ok((unsigned long) to, n)) {
9287+ if (!__builtin_constant_p(n))
9288+ check_object_size(from, n, true);
9289 return __copy_user(to, (__force void __user *) from, n);
9290- else
9291+ } else
9292 return n;
9293 }
9294
9295 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
9296 {
9297+ if ((long)n < 0)
9298+ return n;
9299+
9300+ if (!__builtin_constant_p(n))
9301+ check_object_size(from, n, true);
9302+
9303 return __copy_user(to, (__force void __user *) from, n);
9304 }
9305
9306 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
9307 {
9308- if (n && __access_ok((unsigned long) from, n))
9309+ if ((long)n < 0)
9310+ return n;
9311+
9312+ if (n && __access_ok((unsigned long) from, n)) {
9313+ if (!__builtin_constant_p(n))
9314+ check_object_size(to, n, false);
9315 return __copy_user((__force void __user *) to, from, n);
9316- else
9317+ } else
9318 return n;
9319 }
9320
9321 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
9322 {
9323+ if ((long)n < 0)
9324+ return n;
9325+
9326 return __copy_user((__force void __user *) to, from, n);
9327 }
9328
9329diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
9330index e562d3c..191f176 100644
9331--- a/arch/sparc/include/asm/uaccess_64.h
9332+++ b/arch/sparc/include/asm/uaccess_64.h
9333@@ -10,6 +10,7 @@
9334 #include <linux/compiler.h>
9335 #include <linux/string.h>
9336 #include <linux/thread_info.h>
9337+#include <linux/kernel.h>
9338 #include <asm/asi.h>
9339 #include <asm/spitfire.h>
9340 #include <asm-generic/uaccess-unaligned.h>
9341@@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
9342 static inline unsigned long __must_check
9343 copy_from_user(void *to, const void __user *from, unsigned long size)
9344 {
9345- unsigned long ret = ___copy_from_user(to, from, size);
9346+ unsigned long ret;
9347
9348+ if ((long)size < 0 || size > INT_MAX)
9349+ return size;
9350+
9351+ if (!__builtin_constant_p(size))
9352+ check_object_size(to, size, false);
9353+
9354+ ret = ___copy_from_user(to, from, size);
9355 if (unlikely(ret))
9356 ret = copy_from_user_fixup(to, from, size);
9357
9358@@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
9359 static inline unsigned long __must_check
9360 copy_to_user(void __user *to, const void *from, unsigned long size)
9361 {
9362- unsigned long ret = ___copy_to_user(to, from, size);
9363+ unsigned long ret;
9364
9365+ if ((long)size < 0 || size > INT_MAX)
9366+ return size;
9367+
9368+ if (!__builtin_constant_p(size))
9369+ check_object_size(from, size, true);
9370+
9371+ ret = ___copy_to_user(to, from, size);
9372 if (unlikely(ret))
9373 ret = copy_to_user_fixup(to, from, size);
9374 return ret;
9375diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
9376index d432fb2..6056af1 100644
9377--- a/arch/sparc/kernel/Makefile
9378+++ b/arch/sparc/kernel/Makefile
9379@@ -3,7 +3,7 @@
9380 #
9381
9382 asflags-y := -ansi
9383-ccflags-y := -Werror
9384+#ccflags-y := -Werror
9385
9386 extra-y := head_$(BITS).o
9387
9388diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
9389index fdd819d..5af08c8 100644
9390--- a/arch/sparc/kernel/process_32.c
9391+++ b/arch/sparc/kernel/process_32.c
9392@@ -116,14 +116,14 @@ void show_regs(struct pt_regs *r)
9393
9394 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
9395 r->psr, r->pc, r->npc, r->y, print_tainted());
9396- printk("PC: <%pS>\n", (void *) r->pc);
9397+ printk("PC: <%pA>\n", (void *) r->pc);
9398 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
9399 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
9400 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
9401 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
9402 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
9403 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
9404- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
9405+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
9406
9407 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
9408 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
9409@@ -160,7 +160,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
9410 rw = (struct reg_window32 *) fp;
9411 pc = rw->ins[7];
9412 printk("[%08lx : ", pc);
9413- printk("%pS ] ", (void *) pc);
9414+ printk("%pA ] ", (void *) pc);
9415 fp = rw->ins[6];
9416 } while (++count < 16);
9417 printk("\n");
9418diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
9419index baebab2..9cd13b1 100644
9420--- a/arch/sparc/kernel/process_64.c
9421+++ b/arch/sparc/kernel/process_64.c
9422@@ -158,7 +158,7 @@ static void show_regwindow(struct pt_regs *regs)
9423 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
9424 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
9425 if (regs->tstate & TSTATE_PRIV)
9426- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
9427+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
9428 }
9429
9430 void show_regs(struct pt_regs *regs)
9431@@ -167,7 +167,7 @@ void show_regs(struct pt_regs *regs)
9432
9433 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
9434 regs->tpc, regs->tnpc, regs->y, print_tainted());
9435- printk("TPC: <%pS>\n", (void *) regs->tpc);
9436+ printk("TPC: <%pA>\n", (void *) regs->tpc);
9437 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
9438 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
9439 regs->u_regs[3]);
9440@@ -180,7 +180,7 @@ void show_regs(struct pt_regs *regs)
9441 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
9442 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
9443 regs->u_regs[15]);
9444- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
9445+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
9446 show_regwindow(regs);
9447 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
9448 }
9449@@ -269,7 +269,7 @@ void arch_trigger_all_cpu_backtrace(void)
9450 ((tp && tp->task) ? tp->task->pid : -1));
9451
9452 if (gp->tstate & TSTATE_PRIV) {
9453- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
9454+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
9455 (void *) gp->tpc,
9456 (void *) gp->o7,
9457 (void *) gp->i7,
9458diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
9459index 79cc0d1..ec62734 100644
9460--- a/arch/sparc/kernel/prom_common.c
9461+++ b/arch/sparc/kernel/prom_common.c
9462@@ -144,7 +144,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
9463
9464 unsigned int prom_early_allocated __initdata;
9465
9466-static struct of_pdt_ops prom_sparc_ops __initdata = {
9467+static struct of_pdt_ops prom_sparc_ops __initconst = {
9468 .nextprop = prom_common_nextprop,
9469 .getproplen = prom_getproplen,
9470 .getproperty = prom_getproperty,
9471diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
9472index 7ff45e4..a58f271 100644
9473--- a/arch/sparc/kernel/ptrace_64.c
9474+++ b/arch/sparc/kernel/ptrace_64.c
9475@@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
9476 return ret;
9477 }
9478
9479+#ifdef CONFIG_GRKERNSEC_SETXID
9480+extern void gr_delayed_cred_worker(void);
9481+#endif
9482+
9483 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
9484 {
9485 int ret = 0;
9486@@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
9487 /* do the secure computing check first */
9488 secure_computing_strict(regs->u_regs[UREG_G1]);
9489
9490+#ifdef CONFIG_GRKERNSEC_SETXID
9491+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9492+ gr_delayed_cred_worker();
9493+#endif
9494+
9495 if (test_thread_flag(TIF_SYSCALL_TRACE))
9496 ret = tracehook_report_syscall_entry(regs);
9497
9498@@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
9499
9500 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
9501 {
9502+#ifdef CONFIG_GRKERNSEC_SETXID
9503+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9504+ gr_delayed_cred_worker();
9505+#endif
9506+
9507 audit_syscall_exit(regs);
9508
9509 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
9510diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
9511index e142545..fd29654 100644
9512--- a/arch/sparc/kernel/smp_64.c
9513+++ b/arch/sparc/kernel/smp_64.c
9514@@ -869,8 +869,8 @@ extern unsigned long xcall_flush_dcache_page_cheetah;
9515 extern unsigned long xcall_flush_dcache_page_spitfire;
9516
9517 #ifdef CONFIG_DEBUG_DCFLUSH
9518-extern atomic_t dcpage_flushes;
9519-extern atomic_t dcpage_flushes_xcall;
9520+extern atomic_unchecked_t dcpage_flushes;
9521+extern atomic_unchecked_t dcpage_flushes_xcall;
9522 #endif
9523
9524 static inline void __local_flush_dcache_page(struct page *page)
9525@@ -894,7 +894,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
9526 return;
9527
9528 #ifdef CONFIG_DEBUG_DCFLUSH
9529- atomic_inc(&dcpage_flushes);
9530+ atomic_inc_unchecked(&dcpage_flushes);
9531 #endif
9532
9533 this_cpu = get_cpu();
9534@@ -918,7 +918,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
9535 xcall_deliver(data0, __pa(pg_addr),
9536 (u64) pg_addr, cpumask_of(cpu));
9537 #ifdef CONFIG_DEBUG_DCFLUSH
9538- atomic_inc(&dcpage_flushes_xcall);
9539+ atomic_inc_unchecked(&dcpage_flushes_xcall);
9540 #endif
9541 }
9542 }
9543@@ -937,7 +937,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
9544 preempt_disable();
9545
9546 #ifdef CONFIG_DEBUG_DCFLUSH
9547- atomic_inc(&dcpage_flushes);
9548+ atomic_inc_unchecked(&dcpage_flushes);
9549 #endif
9550 data0 = 0;
9551 pg_addr = page_address(page);
9552@@ -954,7 +954,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
9553 xcall_deliver(data0, __pa(pg_addr),
9554 (u64) pg_addr, cpu_online_mask);
9555 #ifdef CONFIG_DEBUG_DCFLUSH
9556- atomic_inc(&dcpage_flushes_xcall);
9557+ atomic_inc_unchecked(&dcpage_flushes_xcall);
9558 #endif
9559 }
9560 __local_flush_dcache_page(page);
9561diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
9562index 3a8d184..49498a8 100644
9563--- a/arch/sparc/kernel/sys_sparc_32.c
9564+++ b/arch/sparc/kernel/sys_sparc_32.c
9565@@ -52,7 +52,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9566 if (len > TASK_SIZE - PAGE_SIZE)
9567 return -ENOMEM;
9568 if (!addr)
9569- addr = TASK_UNMAPPED_BASE;
9570+ addr = current->mm->mmap_base;
9571
9572 info.flags = 0;
9573 info.length = len;
9574diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
9575index 51561b8..8256764 100644
9576--- a/arch/sparc/kernel/sys_sparc_64.c
9577+++ b/arch/sparc/kernel/sys_sparc_64.c
9578@@ -90,13 +90,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9579 struct vm_area_struct * vma;
9580 unsigned long task_size = TASK_SIZE;
9581 int do_color_align;
9582+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9583 struct vm_unmapped_area_info info;
9584
9585 if (flags & MAP_FIXED) {
9586 /* We do not accept a shared mapping if it would violate
9587 * cache aliasing constraints.
9588 */
9589- if ((flags & MAP_SHARED) &&
9590+ if ((filp || (flags & MAP_SHARED)) &&
9591 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
9592 return -EINVAL;
9593 return addr;
9594@@ -111,6 +112,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9595 if (filp || (flags & MAP_SHARED))
9596 do_color_align = 1;
9597
9598+#ifdef CONFIG_PAX_RANDMMAP
9599+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9600+#endif
9601+
9602 if (addr) {
9603 if (do_color_align)
9604 addr = COLOR_ALIGN(addr, pgoff);
9605@@ -118,22 +123,28 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9606 addr = PAGE_ALIGN(addr);
9607
9608 vma = find_vma(mm, addr);
9609- if (task_size - len >= addr &&
9610- (!vma || addr + len <= vma->vm_start))
9611+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9612 return addr;
9613 }
9614
9615 info.flags = 0;
9616 info.length = len;
9617- info.low_limit = TASK_UNMAPPED_BASE;
9618+ info.low_limit = mm->mmap_base;
9619 info.high_limit = min(task_size, VA_EXCLUDE_START);
9620 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
9621 info.align_offset = pgoff << PAGE_SHIFT;
9622+ info.threadstack_offset = offset;
9623 addr = vm_unmapped_area(&info);
9624
9625 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
9626 VM_BUG_ON(addr != -ENOMEM);
9627 info.low_limit = VA_EXCLUDE_END;
9628+
9629+#ifdef CONFIG_PAX_RANDMMAP
9630+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9631+ info.low_limit += mm->delta_mmap;
9632+#endif
9633+
9634 info.high_limit = task_size;
9635 addr = vm_unmapped_area(&info);
9636 }
9637@@ -151,6 +162,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9638 unsigned long task_size = STACK_TOP32;
9639 unsigned long addr = addr0;
9640 int do_color_align;
9641+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9642 struct vm_unmapped_area_info info;
9643
9644 /* This should only ever run for 32-bit processes. */
9645@@ -160,7 +172,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9646 /* We do not accept a shared mapping if it would violate
9647 * cache aliasing constraints.
9648 */
9649- if ((flags & MAP_SHARED) &&
9650+ if ((filp || (flags & MAP_SHARED)) &&
9651 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
9652 return -EINVAL;
9653 return addr;
9654@@ -173,6 +185,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9655 if (filp || (flags & MAP_SHARED))
9656 do_color_align = 1;
9657
9658+#ifdef CONFIG_PAX_RANDMMAP
9659+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9660+#endif
9661+
9662 /* requesting a specific address */
9663 if (addr) {
9664 if (do_color_align)
9665@@ -181,8 +197,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9666 addr = PAGE_ALIGN(addr);
9667
9668 vma = find_vma(mm, addr);
9669- if (task_size - len >= addr &&
9670- (!vma || addr + len <= vma->vm_start))
9671+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9672 return addr;
9673 }
9674
9675@@ -192,6 +207,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9676 info.high_limit = mm->mmap_base;
9677 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
9678 info.align_offset = pgoff << PAGE_SHIFT;
9679+ info.threadstack_offset = offset;
9680 addr = vm_unmapped_area(&info);
9681
9682 /*
9683@@ -204,6 +220,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9684 VM_BUG_ON(addr != -ENOMEM);
9685 info.flags = 0;
9686 info.low_limit = TASK_UNMAPPED_BASE;
9687+
9688+#ifdef CONFIG_PAX_RANDMMAP
9689+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9690+ info.low_limit += mm->delta_mmap;
9691+#endif
9692+
9693 info.high_limit = STACK_TOP32;
9694 addr = vm_unmapped_area(&info);
9695 }
9696@@ -260,10 +282,14 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u
9697 EXPORT_SYMBOL(get_fb_unmapped_area);
9698
9699 /* Essentially the same as PowerPC. */
9700-static unsigned long mmap_rnd(void)
9701+static unsigned long mmap_rnd(struct mm_struct *mm)
9702 {
9703 unsigned long rnd = 0UL;
9704
9705+#ifdef CONFIG_PAX_RANDMMAP
9706+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9707+#endif
9708+
9709 if (current->flags & PF_RANDOMIZE) {
9710 unsigned long val = get_random_int();
9711 if (test_thread_flag(TIF_32BIT))
9712@@ -276,7 +302,7 @@ static unsigned long mmap_rnd(void)
9713
9714 void arch_pick_mmap_layout(struct mm_struct *mm)
9715 {
9716- unsigned long random_factor = mmap_rnd();
9717+ unsigned long random_factor = mmap_rnd(mm);
9718 unsigned long gap;
9719
9720 /*
9721@@ -289,6 +315,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9722 gap == RLIM_INFINITY ||
9723 sysctl_legacy_va_layout) {
9724 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
9725+
9726+#ifdef CONFIG_PAX_RANDMMAP
9727+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9728+ mm->mmap_base += mm->delta_mmap;
9729+#endif
9730+
9731 mm->get_unmapped_area = arch_get_unmapped_area;
9732 } else {
9733 /* We know it's 32-bit */
9734@@ -300,6 +332,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9735 gap = (task_size / 6 * 5);
9736
9737 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
9738+
9739+#ifdef CONFIG_PAX_RANDMMAP
9740+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9741+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9742+#endif
9743+
9744 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9745 }
9746 }
9747diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
9748index 22a1098..6255eb9 100644
9749--- a/arch/sparc/kernel/syscalls.S
9750+++ b/arch/sparc/kernel/syscalls.S
9751@@ -52,7 +52,7 @@ sys32_rt_sigreturn:
9752 #endif
9753 .align 32
9754 1: ldx [%g6 + TI_FLAGS], %l5
9755- andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
9756+ andcc %l5, _TIF_WORK_SYSCALL, %g0
9757 be,pt %icc, rtrap
9758 nop
9759 call syscall_trace_leave
9760@@ -184,7 +184,7 @@ linux_sparc_syscall32:
9761
9762 srl %i5, 0, %o5 ! IEU1
9763 srl %i2, 0, %o2 ! 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_trace32 ! CTI
9767 mov %i0, %l5 ! IEU1
9768 call %l7 ! CTI Group brk forced
9769@@ -207,7 +207,7 @@ linux_sparc_syscall:
9770
9771 mov %i3, %o3 ! IEU1
9772 mov %i4, %o4 ! IEU0 Group
9773- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
9774+ andcc %l0, _TIF_WORK_SYSCALL, %g0
9775 bne,pn %icc, linux_syscall_trace ! CTI Group
9776 mov %i0, %l5 ! IEU0
9777 2: call %l7 ! CTI Group brk forced
9778@@ -223,7 +223,7 @@ ret_sys_call:
9779
9780 cmp %o0, -ERESTART_RESTARTBLOCK
9781 bgeu,pn %xcc, 1f
9782- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
9783+ andcc %l0, _TIF_WORK_SYSCALL, %g0
9784 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
9785
9786 2:
9787diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
9788index 6629829..036032d 100644
9789--- a/arch/sparc/kernel/traps_32.c
9790+++ b/arch/sparc/kernel/traps_32.c
9791@@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
9792 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
9793 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
9794
9795+extern void gr_handle_kernel_exploit(void);
9796+
9797 void die_if_kernel(char *str, struct pt_regs *regs)
9798 {
9799 static int die_counter;
9800@@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
9801 count++ < 30 &&
9802 (((unsigned long) rw) >= PAGE_OFFSET) &&
9803 !(((unsigned long) rw) & 0x7)) {
9804- printk("Caller[%08lx]: %pS\n", rw->ins[7],
9805+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
9806 (void *) rw->ins[7]);
9807 rw = (struct reg_window32 *)rw->ins[6];
9808 }
9809 }
9810 printk("Instruction DUMP:");
9811 instruction_dump ((unsigned long *) regs->pc);
9812- if(regs->psr & PSR_PS)
9813+ if(regs->psr & PSR_PS) {
9814+ gr_handle_kernel_exploit();
9815 do_exit(SIGKILL);
9816+ }
9817 do_exit(SIGSEGV);
9818 }
9819
9820diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
9821index b3f833a..f485f80 100644
9822--- a/arch/sparc/kernel/traps_64.c
9823+++ b/arch/sparc/kernel/traps_64.c
9824@@ -76,7 +76,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
9825 i + 1,
9826 p->trapstack[i].tstate, p->trapstack[i].tpc,
9827 p->trapstack[i].tnpc, p->trapstack[i].tt);
9828- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
9829+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
9830 }
9831 }
9832
9833@@ -96,6 +96,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
9834
9835 lvl -= 0x100;
9836 if (regs->tstate & TSTATE_PRIV) {
9837+
9838+#ifdef CONFIG_PAX_REFCOUNT
9839+ if (lvl == 6)
9840+ pax_report_refcount_overflow(regs);
9841+#endif
9842+
9843 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
9844 die_if_kernel(buffer, regs);
9845 }
9846@@ -114,11 +120,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
9847 void bad_trap_tl1(struct pt_regs *regs, long lvl)
9848 {
9849 char buffer[32];
9850-
9851+
9852 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
9853 0, lvl, SIGTRAP) == NOTIFY_STOP)
9854 return;
9855
9856+#ifdef CONFIG_PAX_REFCOUNT
9857+ if (lvl == 6)
9858+ pax_report_refcount_overflow(regs);
9859+#endif
9860+
9861 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
9862
9863 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
9864@@ -1142,7 +1153,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
9865 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
9866 printk("%s" "ERROR(%d): ",
9867 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
9868- printk("TPC<%pS>\n", (void *) regs->tpc);
9869+ printk("TPC<%pA>\n", (void *) regs->tpc);
9870 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
9871 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
9872 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
9873@@ -1749,7 +1760,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_EMERG "TPC<%pS>\n", (void *) regs->tpc);
9878+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
9879 panic("Irrecoverable Cheetah+ parity error.");
9880 }
9881
9882@@ -1757,7 +1768,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
9883 smp_processor_id(),
9884 (type & 0x1) ? 'I' : 'D',
9885 regs->tpc);
9886- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
9887+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
9888 }
9889
9890 struct sun4v_error_entry {
9891@@ -1830,8 +1841,8 @@ struct sun4v_error_entry {
9892 /*0x38*/u64 reserved_5;
9893 };
9894
9895-static atomic_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
9896-static atomic_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
9897+static atomic_unchecked_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
9898+static atomic_unchecked_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
9899
9900 static const char *sun4v_err_type_to_str(u8 type)
9901 {
9902@@ -1923,7 +1934,7 @@ static void sun4v_report_real_raddr(const char *pfx, struct pt_regs *regs)
9903 }
9904
9905 static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
9906- int cpu, const char *pfx, atomic_t *ocnt)
9907+ int cpu, const char *pfx, atomic_unchecked_t *ocnt)
9908 {
9909 u64 *raw_ptr = (u64 *) ent;
9910 u32 attrs;
9911@@ -1981,8 +1992,8 @@ static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
9912
9913 show_regs(regs);
9914
9915- if ((cnt = atomic_read(ocnt)) != 0) {
9916- atomic_set(ocnt, 0);
9917+ if ((cnt = atomic_read_unchecked(ocnt)) != 0) {
9918+ atomic_set_unchecked(ocnt, 0);
9919 wmb();
9920 printk("%s: Queue overflowed %d times.\n",
9921 pfx, cnt);
9922@@ -2036,7 +2047,7 @@ void sun4v_resum_error(struct pt_regs *regs, unsigned long offset)
9923 */
9924 void sun4v_resum_overflow(struct pt_regs *regs)
9925 {
9926- atomic_inc(&sun4v_resum_oflow_cnt);
9927+ atomic_inc_unchecked(&sun4v_resum_oflow_cnt);
9928 }
9929
9930 /* We run with %pil set to PIL_NORMAL_MAX and PSTATE_IE enabled in %pstate.
9931@@ -2089,7 +2100,7 @@ void sun4v_nonresum_overflow(struct pt_regs *regs)
9932 /* XXX Actually even this can make not that much sense. Perhaps
9933 * XXX we should just pull the plug and panic directly from here?
9934 */
9935- atomic_inc(&sun4v_nonresum_oflow_cnt);
9936+ atomic_inc_unchecked(&sun4v_nonresum_oflow_cnt);
9937 }
9938
9939 unsigned long sun4v_err_itlb_vaddr;
9940@@ -2104,9 +2115,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
9941
9942 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
9943 regs->tpc, tl);
9944- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
9945+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
9946 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
9947- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
9948+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
9949 (void *) regs->u_regs[UREG_I7]);
9950 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
9951 "pte[%lx] error[%lx]\n",
9952@@ -2128,9 +2139,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
9953
9954 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
9955 regs->tpc, tl);
9956- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
9957+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
9958 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
9959- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
9960+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
9961 (void *) regs->u_regs[UREG_I7]);
9962 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
9963 "pte[%lx] error[%lx]\n",
9964@@ -2336,13 +2347,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
9965 fp = (unsigned long)sf->fp + STACK_BIAS;
9966 }
9967
9968- printk(" [%016lx] %pS\n", pc, (void *) pc);
9969+ printk(" [%016lx] %pA\n", pc, (void *) pc);
9970 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
9971 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
9972 int index = tsk->curr_ret_stack;
9973 if (tsk->ret_stack && index >= graph) {
9974 pc = tsk->ret_stack[index - graph].ret;
9975- printk(" [%016lx] %pS\n", pc, (void *) pc);
9976+ printk(" [%016lx] %pA\n", pc, (void *) pc);
9977 graph++;
9978 }
9979 }
9980@@ -2360,6 +2371,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
9981 return (struct reg_window *) (fp + STACK_BIAS);
9982 }
9983
9984+extern void gr_handle_kernel_exploit(void);
9985+
9986 void die_if_kernel(char *str, struct pt_regs *regs)
9987 {
9988 static int die_counter;
9989@@ -2388,7 +2401,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
9990 while (rw &&
9991 count++ < 30 &&
9992 kstack_valid(tp, (unsigned long) rw)) {
9993- printk("Caller[%016lx]: %pS\n", rw->ins[7],
9994+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
9995 (void *) rw->ins[7]);
9996
9997 rw = kernel_stack_up(rw);
9998@@ -2401,8 +2414,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
9999 }
10000 user_instruction_dump ((unsigned int __user *) regs->tpc);
10001 }
10002- if (regs->tstate & TSTATE_PRIV)
10003+ if (regs->tstate & TSTATE_PRIV) {
10004+ gr_handle_kernel_exploit();
10005 do_exit(SIGKILL);
10006+ }
10007 do_exit(SIGSEGV);
10008 }
10009 EXPORT_SYMBOL(die_if_kernel);
10010diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
10011index 8201c25e..072a2a7 100644
10012--- a/arch/sparc/kernel/unaligned_64.c
10013+++ b/arch/sparc/kernel/unaligned_64.c
10014@@ -286,7 +286,7 @@ static void log_unaligned(struct pt_regs *regs)
10015 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
10016
10017 if (__ratelimit(&ratelimit)) {
10018- printk("Kernel unaligned access at TPC[%lx] %pS\n",
10019+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
10020 regs->tpc, (void *) regs->tpc);
10021 }
10022 }
10023diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
10024index dbe119b..089c7c1 100644
10025--- a/arch/sparc/lib/Makefile
10026+++ b/arch/sparc/lib/Makefile
10027@@ -2,7 +2,7 @@
10028 #
10029
10030 asflags-y := -ansi -DST_DIV0=0x02
10031-ccflags-y := -Werror
10032+#ccflags-y := -Werror
10033
10034 lib-$(CONFIG_SPARC32) += ashrdi3.o
10035 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
10036diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
10037index 85c233d..68500e0 100644
10038--- a/arch/sparc/lib/atomic_64.S
10039+++ b/arch/sparc/lib/atomic_64.S
10040@@ -17,7 +17,12 @@
10041 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10042 BACKOFF_SETUP(%o2)
10043 1: lduw [%o1], %g1
10044- add %g1, %o0, %g7
10045+ addcc %g1, %o0, %g7
10046+
10047+#ifdef CONFIG_PAX_REFCOUNT
10048+ tvs %icc, 6
10049+#endif
10050+
10051 cas [%o1], %g1, %g7
10052 cmp %g1, %g7
10053 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10054@@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10055 2: BACKOFF_SPIN(%o2, %o3, 1b)
10056 ENDPROC(atomic_add)
10057
10058+ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10059+ BACKOFF_SETUP(%o2)
10060+1: lduw [%o1], %g1
10061+ add %g1, %o0, %g7
10062+ cas [%o1], %g1, %g7
10063+ cmp %g1, %g7
10064+ bne,pn %icc, 2f
10065+ nop
10066+ retl
10067+ nop
10068+2: BACKOFF_SPIN(%o2, %o3, 1b)
10069+ENDPROC(atomic_add_unchecked)
10070+
10071 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10072 BACKOFF_SETUP(%o2)
10073 1: lduw [%o1], %g1
10074- sub %g1, %o0, %g7
10075+ subcc %g1, %o0, %g7
10076+
10077+#ifdef CONFIG_PAX_REFCOUNT
10078+ tvs %icc, 6
10079+#endif
10080+
10081 cas [%o1], %g1, %g7
10082 cmp %g1, %g7
10083 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10084@@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10085 2: BACKOFF_SPIN(%o2, %o3, 1b)
10086 ENDPROC(atomic_sub)
10087
10088+ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10089+ BACKOFF_SETUP(%o2)
10090+1: lduw [%o1], %g1
10091+ sub %g1, %o0, %g7
10092+ cas [%o1], %g1, %g7
10093+ cmp %g1, %g7
10094+ bne,pn %icc, 2f
10095+ nop
10096+ retl
10097+ nop
10098+2: BACKOFF_SPIN(%o2, %o3, 1b)
10099+ENDPROC(atomic_sub_unchecked)
10100+
10101 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10102 BACKOFF_SETUP(%o2)
10103 1: lduw [%o1], %g1
10104- add %g1, %o0, %g7
10105+ addcc %g1, %o0, %g7
10106+
10107+#ifdef CONFIG_PAX_REFCOUNT
10108+ tvs %icc, 6
10109+#endif
10110+
10111 cas [%o1], %g1, %g7
10112 cmp %g1, %g7
10113 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10114@@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10115 2: BACKOFF_SPIN(%o2, %o3, 1b)
10116 ENDPROC(atomic_add_ret)
10117
10118+ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10119+ BACKOFF_SETUP(%o2)
10120+1: lduw [%o1], %g1
10121+ addcc %g1, %o0, %g7
10122+ cas [%o1], %g1, %g7
10123+ cmp %g1, %g7
10124+ bne,pn %icc, 2f
10125+ add %g7, %o0, %g7
10126+ sra %g7, 0, %o0
10127+ retl
10128+ nop
10129+2: BACKOFF_SPIN(%o2, %o3, 1b)
10130+ENDPROC(atomic_add_ret_unchecked)
10131+
10132 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
10133 BACKOFF_SETUP(%o2)
10134 1: lduw [%o1], %g1
10135- sub %g1, %o0, %g7
10136+ subcc %g1, %o0, %g7
10137+
10138+#ifdef CONFIG_PAX_REFCOUNT
10139+ tvs %icc, 6
10140+#endif
10141+
10142 cas [%o1], %g1, %g7
10143 cmp %g1, %g7
10144 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10145@@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
10146 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10147 BACKOFF_SETUP(%o2)
10148 1: ldx [%o1], %g1
10149- add %g1, %o0, %g7
10150+ addcc %g1, %o0, %g7
10151+
10152+#ifdef CONFIG_PAX_REFCOUNT
10153+ tvs %xcc, 6
10154+#endif
10155+
10156 casx [%o1], %g1, %g7
10157 cmp %g1, %g7
10158 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10159@@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10160 2: BACKOFF_SPIN(%o2, %o3, 1b)
10161 ENDPROC(atomic64_add)
10162
10163+ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10164+ BACKOFF_SETUP(%o2)
10165+1: ldx [%o1], %g1
10166+ addcc %g1, %o0, %g7
10167+ casx [%o1], %g1, %g7
10168+ cmp %g1, %g7
10169+ bne,pn %xcc, 2f
10170+ nop
10171+ retl
10172+ nop
10173+2: BACKOFF_SPIN(%o2, %o3, 1b)
10174+ENDPROC(atomic64_add_unchecked)
10175+
10176 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10177 BACKOFF_SETUP(%o2)
10178 1: ldx [%o1], %g1
10179- sub %g1, %o0, %g7
10180+ subcc %g1, %o0, %g7
10181+
10182+#ifdef CONFIG_PAX_REFCOUNT
10183+ tvs %xcc, 6
10184+#endif
10185+
10186 casx [%o1], %g1, %g7
10187 cmp %g1, %g7
10188 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10189@@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10190 2: BACKOFF_SPIN(%o2, %o3, 1b)
10191 ENDPROC(atomic64_sub)
10192
10193+ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10194+ BACKOFF_SETUP(%o2)
10195+1: ldx [%o1], %g1
10196+ subcc %g1, %o0, %g7
10197+ casx [%o1], %g1, %g7
10198+ cmp %g1, %g7
10199+ bne,pn %xcc, 2f
10200+ nop
10201+ retl
10202+ nop
10203+2: BACKOFF_SPIN(%o2, %o3, 1b)
10204+ENDPROC(atomic64_sub_unchecked)
10205+
10206 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10207 BACKOFF_SETUP(%o2)
10208 1: ldx [%o1], %g1
10209- add %g1, %o0, %g7
10210+ addcc %g1, %o0, %g7
10211+
10212+#ifdef CONFIG_PAX_REFCOUNT
10213+ tvs %xcc, 6
10214+#endif
10215+
10216 casx [%o1], %g1, %g7
10217 cmp %g1, %g7
10218 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10219@@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10220 2: BACKOFF_SPIN(%o2, %o3, 1b)
10221 ENDPROC(atomic64_add_ret)
10222
10223+ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10224+ BACKOFF_SETUP(%o2)
10225+1: ldx [%o1], %g1
10226+ addcc %g1, %o0, %g7
10227+ casx [%o1], %g1, %g7
10228+ cmp %g1, %g7
10229+ bne,pn %xcc, 2f
10230+ add %g7, %o0, %g7
10231+ mov %g7, %o0
10232+ retl
10233+ nop
10234+2: BACKOFF_SPIN(%o2, %o3, 1b)
10235+ENDPROC(atomic64_add_ret_unchecked)
10236+
10237 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
10238 BACKOFF_SETUP(%o2)
10239 1: ldx [%o1], %g1
10240- sub %g1, %o0, %g7
10241+ subcc %g1, %o0, %g7
10242+
10243+#ifdef CONFIG_PAX_REFCOUNT
10244+ tvs %xcc, 6
10245+#endif
10246+
10247 casx [%o1], %g1, %g7
10248 cmp %g1, %g7
10249 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10250diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
10251index 0c4e35e..745d3e4 100644
10252--- a/arch/sparc/lib/ksyms.c
10253+++ b/arch/sparc/lib/ksyms.c
10254@@ -109,12 +109,18 @@ EXPORT_SYMBOL(__downgrade_write);
10255
10256 /* Atomic counter implementation. */
10257 EXPORT_SYMBOL(atomic_add);
10258+EXPORT_SYMBOL(atomic_add_unchecked);
10259 EXPORT_SYMBOL(atomic_add_ret);
10260+EXPORT_SYMBOL(atomic_add_ret_unchecked);
10261 EXPORT_SYMBOL(atomic_sub);
10262+EXPORT_SYMBOL(atomic_sub_unchecked);
10263 EXPORT_SYMBOL(atomic_sub_ret);
10264 EXPORT_SYMBOL(atomic64_add);
10265+EXPORT_SYMBOL(atomic64_add_unchecked);
10266 EXPORT_SYMBOL(atomic64_add_ret);
10267+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
10268 EXPORT_SYMBOL(atomic64_sub);
10269+EXPORT_SYMBOL(atomic64_sub_unchecked);
10270 EXPORT_SYMBOL(atomic64_sub_ret);
10271 EXPORT_SYMBOL(atomic64_dec_if_positive);
10272
10273diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
10274index 30c3ecc..736f015 100644
10275--- a/arch/sparc/mm/Makefile
10276+++ b/arch/sparc/mm/Makefile
10277@@ -2,7 +2,7 @@
10278 #
10279
10280 asflags-y := -ansi
10281-ccflags-y := -Werror
10282+#ccflags-y := -Werror
10283
10284 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
10285 obj-y += fault_$(BITS).o
10286diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
10287index e98bfda..ea8d221 100644
10288--- a/arch/sparc/mm/fault_32.c
10289+++ b/arch/sparc/mm/fault_32.c
10290@@ -21,6 +21,9 @@
10291 #include <linux/perf_event.h>
10292 #include <linux/interrupt.h>
10293 #include <linux/kdebug.h>
10294+#include <linux/slab.h>
10295+#include <linux/pagemap.h>
10296+#include <linux/compiler.h>
10297
10298 #include <asm/page.h>
10299 #include <asm/pgtable.h>
10300@@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
10301 return safe_compute_effective_address(regs, insn);
10302 }
10303
10304+#ifdef CONFIG_PAX_PAGEEXEC
10305+#ifdef CONFIG_PAX_DLRESOLVE
10306+static void pax_emuplt_close(struct vm_area_struct *vma)
10307+{
10308+ vma->vm_mm->call_dl_resolve = 0UL;
10309+}
10310+
10311+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
10312+{
10313+ unsigned int *kaddr;
10314+
10315+ vmf->page = alloc_page(GFP_HIGHUSER);
10316+ if (!vmf->page)
10317+ return VM_FAULT_OOM;
10318+
10319+ kaddr = kmap(vmf->page);
10320+ memset(kaddr, 0, PAGE_SIZE);
10321+ kaddr[0] = 0x9DE3BFA8U; /* save */
10322+ flush_dcache_page(vmf->page);
10323+ kunmap(vmf->page);
10324+ return VM_FAULT_MAJOR;
10325+}
10326+
10327+static const struct vm_operations_struct pax_vm_ops = {
10328+ .close = pax_emuplt_close,
10329+ .fault = pax_emuplt_fault
10330+};
10331+
10332+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
10333+{
10334+ int ret;
10335+
10336+ INIT_LIST_HEAD(&vma->anon_vma_chain);
10337+ vma->vm_mm = current->mm;
10338+ vma->vm_start = addr;
10339+ vma->vm_end = addr + PAGE_SIZE;
10340+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
10341+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
10342+ vma->vm_ops = &pax_vm_ops;
10343+
10344+ ret = insert_vm_struct(current->mm, vma);
10345+ if (ret)
10346+ return ret;
10347+
10348+ ++current->mm->total_vm;
10349+ return 0;
10350+}
10351+#endif
10352+
10353+/*
10354+ * PaX: decide what to do with offenders (regs->pc = fault address)
10355+ *
10356+ * returns 1 when task should be killed
10357+ * 2 when patched PLT trampoline was detected
10358+ * 3 when unpatched PLT trampoline was detected
10359+ */
10360+static int pax_handle_fetch_fault(struct pt_regs *regs)
10361+{
10362+
10363+#ifdef CONFIG_PAX_EMUPLT
10364+ int err;
10365+
10366+ do { /* PaX: patched PLT emulation #1 */
10367+ unsigned int sethi1, sethi2, jmpl;
10368+
10369+ err = get_user(sethi1, (unsigned int *)regs->pc);
10370+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
10371+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
10372+
10373+ if (err)
10374+ break;
10375+
10376+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
10377+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
10378+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
10379+ {
10380+ unsigned int addr;
10381+
10382+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
10383+ addr = regs->u_regs[UREG_G1];
10384+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
10385+ regs->pc = addr;
10386+ regs->npc = addr+4;
10387+ return 2;
10388+ }
10389+ } while (0);
10390+
10391+ do { /* PaX: patched PLT emulation #2 */
10392+ unsigned int ba;
10393+
10394+ err = get_user(ba, (unsigned int *)regs->pc);
10395+
10396+ if (err)
10397+ break;
10398+
10399+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
10400+ unsigned int addr;
10401+
10402+ if ((ba & 0xFFC00000U) == 0x30800000U)
10403+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
10404+ else
10405+ addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
10406+ regs->pc = addr;
10407+ regs->npc = addr+4;
10408+ return 2;
10409+ }
10410+ } while (0);
10411+
10412+ do { /* PaX: patched PLT emulation #3 */
10413+ unsigned int sethi, bajmpl, nop;
10414+
10415+ err = get_user(sethi, (unsigned int *)regs->pc);
10416+ err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
10417+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
10418+
10419+ if (err)
10420+ break;
10421+
10422+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10423+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
10424+ nop == 0x01000000U)
10425+ {
10426+ unsigned int addr;
10427+
10428+ addr = (sethi & 0x003FFFFFU) << 10;
10429+ regs->u_regs[UREG_G1] = addr;
10430+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
10431+ addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
10432+ else
10433+ addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
10434+ regs->pc = addr;
10435+ regs->npc = addr+4;
10436+ return 2;
10437+ }
10438+ } while (0);
10439+
10440+ do { /* PaX: unpatched PLT emulation step 1 */
10441+ unsigned int sethi, ba, nop;
10442+
10443+ err = get_user(sethi, (unsigned int *)regs->pc);
10444+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
10445+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
10446+
10447+ if (err)
10448+ break;
10449+
10450+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10451+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
10452+ nop == 0x01000000U)
10453+ {
10454+ unsigned int addr, save, call;
10455+
10456+ if ((ba & 0xFFC00000U) == 0x30800000U)
10457+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
10458+ else
10459+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
10460+
10461+ err = get_user(save, (unsigned int *)addr);
10462+ err |= get_user(call, (unsigned int *)(addr+4));
10463+ err |= get_user(nop, (unsigned int *)(addr+8));
10464+ if (err)
10465+ break;
10466+
10467+#ifdef CONFIG_PAX_DLRESOLVE
10468+ if (save == 0x9DE3BFA8U &&
10469+ (call & 0xC0000000U) == 0x40000000U &&
10470+ nop == 0x01000000U)
10471+ {
10472+ struct vm_area_struct *vma;
10473+ unsigned long call_dl_resolve;
10474+
10475+ down_read(&current->mm->mmap_sem);
10476+ call_dl_resolve = current->mm->call_dl_resolve;
10477+ up_read(&current->mm->mmap_sem);
10478+ if (likely(call_dl_resolve))
10479+ goto emulate;
10480+
10481+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
10482+
10483+ down_write(&current->mm->mmap_sem);
10484+ if (current->mm->call_dl_resolve) {
10485+ call_dl_resolve = current->mm->call_dl_resolve;
10486+ up_write(&current->mm->mmap_sem);
10487+ if (vma)
10488+ kmem_cache_free(vm_area_cachep, vma);
10489+ goto emulate;
10490+ }
10491+
10492+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
10493+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
10494+ up_write(&current->mm->mmap_sem);
10495+ if (vma)
10496+ kmem_cache_free(vm_area_cachep, vma);
10497+ return 1;
10498+ }
10499+
10500+ if (pax_insert_vma(vma, call_dl_resolve)) {
10501+ up_write(&current->mm->mmap_sem);
10502+ kmem_cache_free(vm_area_cachep, vma);
10503+ return 1;
10504+ }
10505+
10506+ current->mm->call_dl_resolve = call_dl_resolve;
10507+ up_write(&current->mm->mmap_sem);
10508+
10509+emulate:
10510+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
10511+ regs->pc = call_dl_resolve;
10512+ regs->npc = addr+4;
10513+ return 3;
10514+ }
10515+#endif
10516+
10517+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
10518+ if ((save & 0xFFC00000U) == 0x05000000U &&
10519+ (call & 0xFFFFE000U) == 0x85C0A000U &&
10520+ nop == 0x01000000U)
10521+ {
10522+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
10523+ regs->u_regs[UREG_G2] = addr + 4;
10524+ addr = (save & 0x003FFFFFU) << 10;
10525+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
10526+ regs->pc = addr;
10527+ regs->npc = addr+4;
10528+ return 3;
10529+ }
10530+ }
10531+ } while (0);
10532+
10533+ do { /* PaX: unpatched PLT emulation step 2 */
10534+ unsigned int save, call, nop;
10535+
10536+ err = get_user(save, (unsigned int *)(regs->pc-4));
10537+ err |= get_user(call, (unsigned int *)regs->pc);
10538+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
10539+ if (err)
10540+ break;
10541+
10542+ if (save == 0x9DE3BFA8U &&
10543+ (call & 0xC0000000U) == 0x40000000U &&
10544+ nop == 0x01000000U)
10545+ {
10546+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
10547+
10548+ regs->u_regs[UREG_RETPC] = regs->pc;
10549+ regs->pc = dl_resolve;
10550+ regs->npc = dl_resolve+4;
10551+ return 3;
10552+ }
10553+ } while (0);
10554+#endif
10555+
10556+ return 1;
10557+}
10558+
10559+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
10560+{
10561+ unsigned long i;
10562+
10563+ printk(KERN_ERR "PAX: bytes at PC: ");
10564+ for (i = 0; i < 8; i++) {
10565+ unsigned int c;
10566+ if (get_user(c, (unsigned int *)pc+i))
10567+ printk(KERN_CONT "???????? ");
10568+ else
10569+ printk(KERN_CONT "%08x ", c);
10570+ }
10571+ printk("\n");
10572+}
10573+#endif
10574+
10575 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
10576 int text_fault)
10577 {
10578@@ -230,6 +504,24 @@ good_area:
10579 if (!(vma->vm_flags & VM_WRITE))
10580 goto bad_area;
10581 } else {
10582+
10583+#ifdef CONFIG_PAX_PAGEEXEC
10584+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
10585+ up_read(&mm->mmap_sem);
10586+ switch (pax_handle_fetch_fault(regs)) {
10587+
10588+#ifdef CONFIG_PAX_EMUPLT
10589+ case 2:
10590+ case 3:
10591+ return;
10592+#endif
10593+
10594+ }
10595+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
10596+ do_group_exit(SIGKILL);
10597+ }
10598+#endif
10599+
10600 /* Allow reads even for write-only mappings */
10601 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
10602 goto bad_area;
10603diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
10604index 5062ff3..e0b75f3 100644
10605--- a/arch/sparc/mm/fault_64.c
10606+++ b/arch/sparc/mm/fault_64.c
10607@@ -21,6 +21,9 @@
10608 #include <linux/kprobes.h>
10609 #include <linux/kdebug.h>
10610 #include <linux/percpu.h>
10611+#include <linux/slab.h>
10612+#include <linux/pagemap.h>
10613+#include <linux/compiler.h>
10614
10615 #include <asm/page.h>
10616 #include <asm/pgtable.h>
10617@@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
10618 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
10619 regs->tpc);
10620 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
10621- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
10622+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
10623 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
10624 dump_stack();
10625 unhandled_fault(regs->tpc, current, regs);
10626@@ -270,6 +273,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
10627 show_regs(regs);
10628 }
10629
10630+#ifdef CONFIG_PAX_PAGEEXEC
10631+#ifdef CONFIG_PAX_DLRESOLVE
10632+static void pax_emuplt_close(struct vm_area_struct *vma)
10633+{
10634+ vma->vm_mm->call_dl_resolve = 0UL;
10635+}
10636+
10637+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
10638+{
10639+ unsigned int *kaddr;
10640+
10641+ vmf->page = alloc_page(GFP_HIGHUSER);
10642+ if (!vmf->page)
10643+ return VM_FAULT_OOM;
10644+
10645+ kaddr = kmap(vmf->page);
10646+ memset(kaddr, 0, PAGE_SIZE);
10647+ kaddr[0] = 0x9DE3BFA8U; /* save */
10648+ flush_dcache_page(vmf->page);
10649+ kunmap(vmf->page);
10650+ return VM_FAULT_MAJOR;
10651+}
10652+
10653+static const struct vm_operations_struct pax_vm_ops = {
10654+ .close = pax_emuplt_close,
10655+ .fault = pax_emuplt_fault
10656+};
10657+
10658+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
10659+{
10660+ int ret;
10661+
10662+ INIT_LIST_HEAD(&vma->anon_vma_chain);
10663+ vma->vm_mm = current->mm;
10664+ vma->vm_start = addr;
10665+ vma->vm_end = addr + PAGE_SIZE;
10666+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
10667+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
10668+ vma->vm_ops = &pax_vm_ops;
10669+
10670+ ret = insert_vm_struct(current->mm, vma);
10671+ if (ret)
10672+ return ret;
10673+
10674+ ++current->mm->total_vm;
10675+ return 0;
10676+}
10677+#endif
10678+
10679+/*
10680+ * PaX: decide what to do with offenders (regs->tpc = fault address)
10681+ *
10682+ * returns 1 when task should be killed
10683+ * 2 when patched PLT trampoline was detected
10684+ * 3 when unpatched PLT trampoline was detected
10685+ */
10686+static int pax_handle_fetch_fault(struct pt_regs *regs)
10687+{
10688+
10689+#ifdef CONFIG_PAX_EMUPLT
10690+ int err;
10691+
10692+ do { /* PaX: patched PLT emulation #1 */
10693+ unsigned int sethi1, sethi2, jmpl;
10694+
10695+ err = get_user(sethi1, (unsigned int *)regs->tpc);
10696+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
10697+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
10698+
10699+ if (err)
10700+ break;
10701+
10702+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
10703+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
10704+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
10705+ {
10706+ unsigned long addr;
10707+
10708+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
10709+ addr = regs->u_regs[UREG_G1];
10710+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
10711+
10712+ if (test_thread_flag(TIF_32BIT))
10713+ addr &= 0xFFFFFFFFUL;
10714+
10715+ regs->tpc = addr;
10716+ regs->tnpc = addr+4;
10717+ return 2;
10718+ }
10719+ } while (0);
10720+
10721+ do { /* PaX: patched PLT emulation #2 */
10722+ unsigned int ba;
10723+
10724+ err = get_user(ba, (unsigned int *)regs->tpc);
10725+
10726+ if (err)
10727+ break;
10728+
10729+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
10730+ unsigned long addr;
10731+
10732+ if ((ba & 0xFFC00000U) == 0x30800000U)
10733+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
10734+ else
10735+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
10736+
10737+ if (test_thread_flag(TIF_32BIT))
10738+ addr &= 0xFFFFFFFFUL;
10739+
10740+ regs->tpc = addr;
10741+ regs->tnpc = addr+4;
10742+ return 2;
10743+ }
10744+ } while (0);
10745+
10746+ do { /* PaX: patched PLT emulation #3 */
10747+ unsigned int sethi, bajmpl, nop;
10748+
10749+ err = get_user(sethi, (unsigned int *)regs->tpc);
10750+ err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
10751+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
10752+
10753+ if (err)
10754+ break;
10755+
10756+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10757+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
10758+ nop == 0x01000000U)
10759+ {
10760+ unsigned long addr;
10761+
10762+ addr = (sethi & 0x003FFFFFU) << 10;
10763+ regs->u_regs[UREG_G1] = addr;
10764+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
10765+ addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
10766+ else
10767+ addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
10768+
10769+ if (test_thread_flag(TIF_32BIT))
10770+ addr &= 0xFFFFFFFFUL;
10771+
10772+ regs->tpc = addr;
10773+ regs->tnpc = addr+4;
10774+ return 2;
10775+ }
10776+ } while (0);
10777+
10778+ do { /* PaX: patched PLT emulation #4 */
10779+ unsigned int sethi, mov1, call, mov2;
10780+
10781+ err = get_user(sethi, (unsigned int *)regs->tpc);
10782+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
10783+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
10784+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
10785+
10786+ if (err)
10787+ break;
10788+
10789+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10790+ mov1 == 0x8210000FU &&
10791+ (call & 0xC0000000U) == 0x40000000U &&
10792+ mov2 == 0x9E100001U)
10793+ {
10794+ unsigned long addr;
10795+
10796+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
10797+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
10798+
10799+ if (test_thread_flag(TIF_32BIT))
10800+ addr &= 0xFFFFFFFFUL;
10801+
10802+ regs->tpc = addr;
10803+ regs->tnpc = addr+4;
10804+ return 2;
10805+ }
10806+ } while (0);
10807+
10808+ do { /* PaX: patched PLT emulation #5 */
10809+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
10810+
10811+ err = get_user(sethi, (unsigned int *)regs->tpc);
10812+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
10813+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
10814+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
10815+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
10816+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
10817+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
10818+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
10819+
10820+ if (err)
10821+ break;
10822+
10823+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10824+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
10825+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
10826+ (or1 & 0xFFFFE000U) == 0x82106000U &&
10827+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
10828+ sllx == 0x83287020U &&
10829+ jmpl == 0x81C04005U &&
10830+ nop == 0x01000000U)
10831+ {
10832+ unsigned long addr;
10833+
10834+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
10835+ regs->u_regs[UREG_G1] <<= 32;
10836+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
10837+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
10838+ regs->tpc = addr;
10839+ regs->tnpc = addr+4;
10840+ return 2;
10841+ }
10842+ } while (0);
10843+
10844+ do { /* PaX: patched PLT emulation #6 */
10845+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
10846+
10847+ err = get_user(sethi, (unsigned int *)regs->tpc);
10848+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
10849+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
10850+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
10851+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
10852+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
10853+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
10854+
10855+ if (err)
10856+ break;
10857+
10858+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10859+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
10860+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
10861+ sllx == 0x83287020U &&
10862+ (or & 0xFFFFE000U) == 0x8A116000U &&
10863+ jmpl == 0x81C04005U &&
10864+ nop == 0x01000000U)
10865+ {
10866+ unsigned long addr;
10867+
10868+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
10869+ regs->u_regs[UREG_G1] <<= 32;
10870+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
10871+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
10872+ regs->tpc = addr;
10873+ regs->tnpc = addr+4;
10874+ return 2;
10875+ }
10876+ } while (0);
10877+
10878+ do { /* PaX: unpatched PLT emulation step 1 */
10879+ unsigned int sethi, ba, nop;
10880+
10881+ err = get_user(sethi, (unsigned int *)regs->tpc);
10882+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
10883+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
10884+
10885+ if (err)
10886+ break;
10887+
10888+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10889+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
10890+ nop == 0x01000000U)
10891+ {
10892+ unsigned long addr;
10893+ unsigned int save, call;
10894+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
10895+
10896+ if ((ba & 0xFFC00000U) == 0x30800000U)
10897+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
10898+ else
10899+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
10900+
10901+ if (test_thread_flag(TIF_32BIT))
10902+ addr &= 0xFFFFFFFFUL;
10903+
10904+ err = get_user(save, (unsigned int *)addr);
10905+ err |= get_user(call, (unsigned int *)(addr+4));
10906+ err |= get_user(nop, (unsigned int *)(addr+8));
10907+ if (err)
10908+ break;
10909+
10910+#ifdef CONFIG_PAX_DLRESOLVE
10911+ if (save == 0x9DE3BFA8U &&
10912+ (call & 0xC0000000U) == 0x40000000U &&
10913+ nop == 0x01000000U)
10914+ {
10915+ struct vm_area_struct *vma;
10916+ unsigned long call_dl_resolve;
10917+
10918+ down_read(&current->mm->mmap_sem);
10919+ call_dl_resolve = current->mm->call_dl_resolve;
10920+ up_read(&current->mm->mmap_sem);
10921+ if (likely(call_dl_resolve))
10922+ goto emulate;
10923+
10924+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
10925+
10926+ down_write(&current->mm->mmap_sem);
10927+ if (current->mm->call_dl_resolve) {
10928+ call_dl_resolve = current->mm->call_dl_resolve;
10929+ up_write(&current->mm->mmap_sem);
10930+ if (vma)
10931+ kmem_cache_free(vm_area_cachep, vma);
10932+ goto emulate;
10933+ }
10934+
10935+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
10936+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
10937+ up_write(&current->mm->mmap_sem);
10938+ if (vma)
10939+ kmem_cache_free(vm_area_cachep, vma);
10940+ return 1;
10941+ }
10942+
10943+ if (pax_insert_vma(vma, call_dl_resolve)) {
10944+ up_write(&current->mm->mmap_sem);
10945+ kmem_cache_free(vm_area_cachep, vma);
10946+ return 1;
10947+ }
10948+
10949+ current->mm->call_dl_resolve = call_dl_resolve;
10950+ up_write(&current->mm->mmap_sem);
10951+
10952+emulate:
10953+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
10954+ regs->tpc = call_dl_resolve;
10955+ regs->tnpc = addr+4;
10956+ return 3;
10957+ }
10958+#endif
10959+
10960+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
10961+ if ((save & 0xFFC00000U) == 0x05000000U &&
10962+ (call & 0xFFFFE000U) == 0x85C0A000U &&
10963+ nop == 0x01000000U)
10964+ {
10965+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
10966+ regs->u_regs[UREG_G2] = addr + 4;
10967+ addr = (save & 0x003FFFFFU) << 10;
10968+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
10969+
10970+ if (test_thread_flag(TIF_32BIT))
10971+ addr &= 0xFFFFFFFFUL;
10972+
10973+ regs->tpc = addr;
10974+ regs->tnpc = addr+4;
10975+ return 3;
10976+ }
10977+
10978+ /* PaX: 64-bit PLT stub */
10979+ err = get_user(sethi1, (unsigned int *)addr);
10980+ err |= get_user(sethi2, (unsigned int *)(addr+4));
10981+ err |= get_user(or1, (unsigned int *)(addr+8));
10982+ err |= get_user(or2, (unsigned int *)(addr+12));
10983+ err |= get_user(sllx, (unsigned int *)(addr+16));
10984+ err |= get_user(add, (unsigned int *)(addr+20));
10985+ err |= get_user(jmpl, (unsigned int *)(addr+24));
10986+ err |= get_user(nop, (unsigned int *)(addr+28));
10987+ if (err)
10988+ break;
10989+
10990+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
10991+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
10992+ (or1 & 0xFFFFE000U) == 0x88112000U &&
10993+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
10994+ sllx == 0x89293020U &&
10995+ add == 0x8A010005U &&
10996+ jmpl == 0x89C14000U &&
10997+ nop == 0x01000000U)
10998+ {
10999+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11000+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11001+ regs->u_regs[UREG_G4] <<= 32;
11002+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11003+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
11004+ regs->u_regs[UREG_G4] = addr + 24;
11005+ addr = regs->u_regs[UREG_G5];
11006+ regs->tpc = addr;
11007+ regs->tnpc = addr+4;
11008+ return 3;
11009+ }
11010+ }
11011+ } while (0);
11012+
11013+#ifdef CONFIG_PAX_DLRESOLVE
11014+ do { /* PaX: unpatched PLT emulation step 2 */
11015+ unsigned int save, call, nop;
11016+
11017+ err = get_user(save, (unsigned int *)(regs->tpc-4));
11018+ err |= get_user(call, (unsigned int *)regs->tpc);
11019+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
11020+ if (err)
11021+ break;
11022+
11023+ if (save == 0x9DE3BFA8U &&
11024+ (call & 0xC0000000U) == 0x40000000U &&
11025+ nop == 0x01000000U)
11026+ {
11027+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11028+
11029+ if (test_thread_flag(TIF_32BIT))
11030+ dl_resolve &= 0xFFFFFFFFUL;
11031+
11032+ regs->u_regs[UREG_RETPC] = regs->tpc;
11033+ regs->tpc = dl_resolve;
11034+ regs->tnpc = dl_resolve+4;
11035+ return 3;
11036+ }
11037+ } while (0);
11038+#endif
11039+
11040+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
11041+ unsigned int sethi, ba, nop;
11042+
11043+ err = get_user(sethi, (unsigned int *)regs->tpc);
11044+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11045+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11046+
11047+ if (err)
11048+ break;
11049+
11050+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11051+ (ba & 0xFFF00000U) == 0x30600000U &&
11052+ nop == 0x01000000U)
11053+ {
11054+ unsigned long addr;
11055+
11056+ addr = (sethi & 0x003FFFFFU) << 10;
11057+ regs->u_regs[UREG_G1] = addr;
11058+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11059+
11060+ if (test_thread_flag(TIF_32BIT))
11061+ addr &= 0xFFFFFFFFUL;
11062+
11063+ regs->tpc = addr;
11064+ regs->tnpc = addr+4;
11065+ return 2;
11066+ }
11067+ } while (0);
11068+
11069+#endif
11070+
11071+ return 1;
11072+}
11073+
11074+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11075+{
11076+ unsigned long i;
11077+
11078+ printk(KERN_ERR "PAX: bytes at PC: ");
11079+ for (i = 0; i < 8; i++) {
11080+ unsigned int c;
11081+ if (get_user(c, (unsigned int *)pc+i))
11082+ printk(KERN_CONT "???????? ");
11083+ else
11084+ printk(KERN_CONT "%08x ", c);
11085+ }
11086+ printk("\n");
11087+}
11088+#endif
11089+
11090 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
11091 {
11092 struct mm_struct *mm = current->mm;
11093@@ -341,6 +804,29 @@ retry:
11094 if (!vma)
11095 goto bad_area;
11096
11097+#ifdef CONFIG_PAX_PAGEEXEC
11098+ /* PaX: detect ITLB misses on non-exec pages */
11099+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
11100+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
11101+ {
11102+ if (address != regs->tpc)
11103+ goto good_area;
11104+
11105+ up_read(&mm->mmap_sem);
11106+ switch (pax_handle_fetch_fault(regs)) {
11107+
11108+#ifdef CONFIG_PAX_EMUPLT
11109+ case 2:
11110+ case 3:
11111+ return;
11112+#endif
11113+
11114+ }
11115+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
11116+ do_group_exit(SIGKILL);
11117+ }
11118+#endif
11119+
11120 /* Pure DTLB misses do not tell us whether the fault causing
11121 * load/store/atomic was a write or not, it only says that there
11122 * was no match. So in such a case we (carefully) read the
11123diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
11124index d2b5944..d878f3c 100644
11125--- a/arch/sparc/mm/hugetlbpage.c
11126+++ b/arch/sparc/mm/hugetlbpage.c
11127@@ -28,7 +28,8 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11128 unsigned long addr,
11129 unsigned long len,
11130 unsigned long pgoff,
11131- unsigned long flags)
11132+ unsigned long flags,
11133+ unsigned long offset)
11134 {
11135 unsigned long task_size = TASK_SIZE;
11136 struct vm_unmapped_area_info info;
11137@@ -38,15 +39,22 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11138
11139 info.flags = 0;
11140 info.length = len;
11141- info.low_limit = TASK_UNMAPPED_BASE;
11142+ info.low_limit = mm->mmap_base;
11143 info.high_limit = min(task_size, VA_EXCLUDE_START);
11144 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11145 info.align_offset = 0;
11146+ info.threadstack_offset = offset;
11147 addr = vm_unmapped_area(&info);
11148
11149 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
11150 VM_BUG_ON(addr != -ENOMEM);
11151 info.low_limit = VA_EXCLUDE_END;
11152+
11153+#ifdef CONFIG_PAX_RANDMMAP
11154+ if (mm->pax_flags & MF_PAX_RANDMMAP)
11155+ info.low_limit += mm->delta_mmap;
11156+#endif
11157+
11158 info.high_limit = task_size;
11159 addr = vm_unmapped_area(&info);
11160 }
11161@@ -58,7 +66,8 @@ static unsigned long
11162 hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11163 const unsigned long len,
11164 const unsigned long pgoff,
11165- const unsigned long flags)
11166+ const unsigned long flags,
11167+ const unsigned long offset)
11168 {
11169 struct mm_struct *mm = current->mm;
11170 unsigned long addr = addr0;
11171@@ -73,6 +82,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11172 info.high_limit = mm->mmap_base;
11173 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11174 info.align_offset = 0;
11175+ info.threadstack_offset = offset;
11176 addr = vm_unmapped_area(&info);
11177
11178 /*
11179@@ -85,6 +95,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11180 VM_BUG_ON(addr != -ENOMEM);
11181 info.flags = 0;
11182 info.low_limit = TASK_UNMAPPED_BASE;
11183+
11184+#ifdef CONFIG_PAX_RANDMMAP
11185+ if (mm->pax_flags & MF_PAX_RANDMMAP)
11186+ info.low_limit += mm->delta_mmap;
11187+#endif
11188+
11189 info.high_limit = STACK_TOP32;
11190 addr = vm_unmapped_area(&info);
11191 }
11192@@ -99,6 +115,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
11193 struct mm_struct *mm = current->mm;
11194 struct vm_area_struct *vma;
11195 unsigned long task_size = TASK_SIZE;
11196+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
11197
11198 if (test_thread_flag(TIF_32BIT))
11199 task_size = STACK_TOP32;
11200@@ -114,19 +131,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
11201 return addr;
11202 }
11203
11204+#ifdef CONFIG_PAX_RANDMMAP
11205+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
11206+#endif
11207+
11208 if (addr) {
11209 addr = ALIGN(addr, HPAGE_SIZE);
11210 vma = find_vma(mm, addr);
11211- if (task_size - len >= addr &&
11212- (!vma || addr + len <= vma->vm_start))
11213+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
11214 return addr;
11215 }
11216 if (mm->get_unmapped_area == arch_get_unmapped_area)
11217 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
11218- pgoff, flags);
11219+ pgoff, flags, offset);
11220 else
11221 return hugetlb_get_unmapped_area_topdown(file, addr, len,
11222- pgoff, flags);
11223+ pgoff, flags, offset);
11224 }
11225
11226 pte_t *huge_pte_alloc(struct mm_struct *mm,
11227diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
11228index ed82eda..0d80e77 100644
11229--- a/arch/sparc/mm/init_64.c
11230+++ b/arch/sparc/mm/init_64.c
11231@@ -188,9 +188,9 @@ unsigned long sparc64_kern_sec_context __read_mostly;
11232 int num_kernel_image_mappings;
11233
11234 #ifdef CONFIG_DEBUG_DCFLUSH
11235-atomic_t dcpage_flushes = ATOMIC_INIT(0);
11236+atomic_unchecked_t dcpage_flushes = ATOMIC_INIT(0);
11237 #ifdef CONFIG_SMP
11238-atomic_t dcpage_flushes_xcall = ATOMIC_INIT(0);
11239+atomic_unchecked_t dcpage_flushes_xcall = ATOMIC_INIT(0);
11240 #endif
11241 #endif
11242
11243@@ -198,7 +198,7 @@ inline void flush_dcache_page_impl(struct page *page)
11244 {
11245 BUG_ON(tlb_type == hypervisor);
11246 #ifdef CONFIG_DEBUG_DCFLUSH
11247- atomic_inc(&dcpage_flushes);
11248+ atomic_inc_unchecked(&dcpage_flushes);
11249 #endif
11250
11251 #ifdef DCACHE_ALIASING_POSSIBLE
11252@@ -466,10 +466,10 @@ void mmu_info(struct seq_file *m)
11253
11254 #ifdef CONFIG_DEBUG_DCFLUSH
11255 seq_printf(m, "DCPageFlushes\t: %d\n",
11256- atomic_read(&dcpage_flushes));
11257+ atomic_read_unchecked(&dcpage_flushes));
11258 #ifdef CONFIG_SMP
11259 seq_printf(m, "DCPageFlushesXC\t: %d\n",
11260- atomic_read(&dcpage_flushes_xcall));
11261+ atomic_read_unchecked(&dcpage_flushes_xcall));
11262 #endif /* CONFIG_SMP */
11263 #endif /* CONFIG_DEBUG_DCFLUSH */
11264 }
11265diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
11266index f4500c6..889656c 100644
11267--- a/arch/tile/include/asm/atomic_64.h
11268+++ b/arch/tile/include/asm/atomic_64.h
11269@@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
11270
11271 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
11272
11273+#define atomic64_read_unchecked(v) atomic64_read(v)
11274+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
11275+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
11276+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
11277+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
11278+#define atomic64_inc_unchecked(v) atomic64_inc(v)
11279+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
11280+#define atomic64_dec_unchecked(v) atomic64_dec(v)
11281+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
11282+
11283 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
11284 #define smp_mb__before_atomic_dec() smp_mb()
11285 #define smp_mb__after_atomic_dec() smp_mb()
11286diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
11287index a9a5299..0fce79e 100644
11288--- a/arch/tile/include/asm/cache.h
11289+++ b/arch/tile/include/asm/cache.h
11290@@ -15,11 +15,12 @@
11291 #ifndef _ASM_TILE_CACHE_H
11292 #define _ASM_TILE_CACHE_H
11293
11294+#include <linux/const.h>
11295 #include <arch/chip.h>
11296
11297 /* bytes per L1 data cache line */
11298 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
11299-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11300+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11301
11302 /* bytes per L2 cache line */
11303 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
11304diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
11305index e4d44bd..99927a3 100644
11306--- a/arch/tile/include/asm/uaccess.h
11307+++ b/arch/tile/include/asm/uaccess.h
11308@@ -408,9 +408,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
11309 const void __user *from,
11310 unsigned long n)
11311 {
11312- int sz = __compiletime_object_size(to);
11313+ size_t sz = __compiletime_object_size(to);
11314
11315- if (likely(sz == -1 || sz >= n))
11316+ if (likely(sz == (size_t)-1 || sz >= n))
11317 n = _copy_from_user(to, from, n);
11318 else
11319 copy_from_user_overflow();
11320diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
11321index 650ccff..45fe2d6 100644
11322--- a/arch/tile/mm/hugetlbpage.c
11323+++ b/arch/tile/mm/hugetlbpage.c
11324@@ -239,6 +239,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
11325 info.high_limit = TASK_SIZE;
11326 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
11327 info.align_offset = 0;
11328+ info.threadstack_offset = 0;
11329 return vm_unmapped_area(&info);
11330 }
11331
11332@@ -256,6 +257,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
11333 info.high_limit = current->mm->mmap_base;
11334 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
11335 info.align_offset = 0;
11336+ info.threadstack_offset = 0;
11337 addr = vm_unmapped_area(&info);
11338
11339 /*
11340diff --git a/arch/um/Makefile b/arch/um/Makefile
11341index 133f7de..1d6f2f1 100644
11342--- a/arch/um/Makefile
11343+++ b/arch/um/Makefile
11344@@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
11345 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
11346 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
11347
11348+ifdef CONSTIFY_PLUGIN
11349+USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
11350+endif
11351+
11352 #This will adjust *FLAGS accordingly to the platform.
11353 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
11354
11355diff --git a/arch/um/defconfig b/arch/um/defconfig
11356index 08107a7..ab22afe 100644
11357--- a/arch/um/defconfig
11358+++ b/arch/um/defconfig
11359@@ -51,7 +51,6 @@ CONFIG_X86_CMPXCHG=y
11360 CONFIG_X86_L1_CACHE_SHIFT=5
11361 CONFIG_X86_XADD=y
11362 CONFIG_X86_PPRO_FENCE=y
11363-CONFIG_X86_WP_WORKS_OK=y
11364 CONFIG_X86_INVLPG=y
11365 CONFIG_X86_BSWAP=y
11366 CONFIG_X86_POPAD_OK=y
11367diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
11368index 19e1bdd..3665b77 100644
11369--- a/arch/um/include/asm/cache.h
11370+++ b/arch/um/include/asm/cache.h
11371@@ -1,6 +1,7 @@
11372 #ifndef __UM_CACHE_H
11373 #define __UM_CACHE_H
11374
11375+#include <linux/const.h>
11376
11377 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
11378 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
11379@@ -12,6 +13,6 @@
11380 # define L1_CACHE_SHIFT 5
11381 #endif
11382
11383-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11384+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11385
11386 #endif
11387diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
11388index 2e0a6b1..a64d0f5 100644
11389--- a/arch/um/include/asm/kmap_types.h
11390+++ b/arch/um/include/asm/kmap_types.h
11391@@ -8,6 +8,6 @@
11392
11393 /* No more #include "asm/arch/kmap_types.h" ! */
11394
11395-#define KM_TYPE_NR 14
11396+#define KM_TYPE_NR 15
11397
11398 #endif
11399diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
11400index 5ff53d9..5850cdf 100644
11401--- a/arch/um/include/asm/page.h
11402+++ b/arch/um/include/asm/page.h
11403@@ -14,6 +14,9 @@
11404 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
11405 #define PAGE_MASK (~(PAGE_SIZE-1))
11406
11407+#define ktla_ktva(addr) (addr)
11408+#define ktva_ktla(addr) (addr)
11409+
11410 #ifndef __ASSEMBLY__
11411
11412 struct page;
11413diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
11414index 0032f92..cd151e0 100644
11415--- a/arch/um/include/asm/pgtable-3level.h
11416+++ b/arch/um/include/asm/pgtable-3level.h
11417@@ -58,6 +58,7 @@
11418 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
11419 #define pud_populate(mm, pud, pmd) \
11420 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
11421+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
11422
11423 #ifdef CONFIG_64BIT
11424 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
11425diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
11426index bbcef52..6a2a483 100644
11427--- a/arch/um/kernel/process.c
11428+++ b/arch/um/kernel/process.c
11429@@ -367,22 +367,6 @@ int singlestepping(void * t)
11430 return 2;
11431 }
11432
11433-/*
11434- * Only x86 and x86_64 have an arch_align_stack().
11435- * All other arches have "#define arch_align_stack(x) (x)"
11436- * in their asm/system.h
11437- * As this is included in UML from asm-um/system-generic.h,
11438- * we can use it to behave as the subarch does.
11439- */
11440-#ifndef arch_align_stack
11441-unsigned long arch_align_stack(unsigned long sp)
11442-{
11443- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
11444- sp -= get_random_int() % 8192;
11445- return sp & ~0xf;
11446-}
11447-#endif
11448-
11449 unsigned long get_wchan(struct task_struct *p)
11450 {
11451 unsigned long stack_page, sp, ip;
11452diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
11453index ad8f795..2c7eec6 100644
11454--- a/arch/unicore32/include/asm/cache.h
11455+++ b/arch/unicore32/include/asm/cache.h
11456@@ -12,8 +12,10 @@
11457 #ifndef __UNICORE_CACHE_H__
11458 #define __UNICORE_CACHE_H__
11459
11460-#define L1_CACHE_SHIFT (5)
11461-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11462+#include <linux/const.h>
11463+
11464+#define L1_CACHE_SHIFT 5
11465+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11466
11467 /*
11468 * Memory returned by kmalloc() may be used for DMA, so we must make
11469diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
11470index b32ebf9..5704f98 100644
11471--- a/arch/x86/Kconfig
11472+++ b/arch/x86/Kconfig
11473@@ -248,7 +248,7 @@ config X86_HT
11474
11475 config X86_32_LAZY_GS
11476 def_bool y
11477- depends on X86_32 && !CC_STACKPROTECTOR
11478+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
11479
11480 config ARCH_HWEIGHT_CFLAGS
11481 string
11482@@ -1088,6 +1088,7 @@ config MICROCODE_EARLY
11483
11484 config X86_MSR
11485 tristate "/dev/cpu/*/msr - Model-specific register support"
11486+ depends on !GRKERNSEC_KMEM
11487 ---help---
11488 This device gives privileged processes access to the x86
11489 Model-Specific Registers (MSRs). It is a character device with
11490@@ -1111,7 +1112,7 @@ choice
11491
11492 config NOHIGHMEM
11493 bool "off"
11494- depends on !X86_NUMAQ
11495+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
11496 ---help---
11497 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
11498 However, the address space of 32-bit x86 processors is only 4
11499@@ -1148,7 +1149,7 @@ config NOHIGHMEM
11500
11501 config HIGHMEM4G
11502 bool "4GB"
11503- depends on !X86_NUMAQ
11504+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
11505 ---help---
11506 Select this if you have a 32-bit processor and between 1 and 4
11507 gigabytes of physical RAM.
11508@@ -1201,7 +1202,7 @@ config PAGE_OFFSET
11509 hex
11510 default 0xB0000000 if VMSPLIT_3G_OPT
11511 default 0x80000000 if VMSPLIT_2G
11512- default 0x78000000 if VMSPLIT_2G_OPT
11513+ default 0x70000000 if VMSPLIT_2G_OPT
11514 default 0x40000000 if VMSPLIT_1G
11515 default 0xC0000000
11516 depends on X86_32
11517@@ -1599,6 +1600,7 @@ config SECCOMP
11518
11519 config CC_STACKPROTECTOR
11520 bool "Enable -fstack-protector buffer overflow detection"
11521+ depends on X86_64 || !PAX_MEMORY_UDEREF
11522 ---help---
11523 This option turns on the -fstack-protector GCC feature. This
11524 feature puts, at the beginning of functions, a canary value on
11525@@ -1718,6 +1720,8 @@ config X86_NEED_RELOCS
11526 config PHYSICAL_ALIGN
11527 hex "Alignment value to which kernel should be aligned" if X86_32
11528 default "0x1000000"
11529+ range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
11530+ range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
11531 range 0x2000 0x1000000
11532 ---help---
11533 This value puts the alignment restrictions on physical address
11534@@ -1793,9 +1797,10 @@ config DEBUG_HOTPLUG_CPU0
11535 If unsure, say N.
11536
11537 config COMPAT_VDSO
11538- def_bool y
11539+ def_bool n
11540 prompt "Compat VDSO support"
11541 depends on X86_32 || IA32_EMULATION
11542+ depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
11543 ---help---
11544 Map the 32-bit VDSO to the predictable old-style address too.
11545
11546diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
11547index c026cca..14657ae 100644
11548--- a/arch/x86/Kconfig.cpu
11549+++ b/arch/x86/Kconfig.cpu
11550@@ -319,7 +319,7 @@ config X86_PPRO_FENCE
11551
11552 config X86_F00F_BUG
11553 def_bool y
11554- depends on M586MMX || M586TSC || M586 || M486
11555+ depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
11556
11557 config X86_INVD_BUG
11558 def_bool y
11559@@ -327,7 +327,7 @@ config X86_INVD_BUG
11560
11561 config X86_ALIGNMENT_16
11562 def_bool y
11563- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
11564+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
11565
11566 config X86_INTEL_USERCOPY
11567 def_bool y
11568@@ -373,7 +373,7 @@ config X86_CMPXCHG64
11569 # generates cmov.
11570 config X86_CMOV
11571 def_bool y
11572- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
11573+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
11574
11575 config X86_MINIMUM_CPU_FAMILY
11576 int
11577diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
11578index 78d91af..8ceb94b 100644
11579--- a/arch/x86/Kconfig.debug
11580+++ b/arch/x86/Kconfig.debug
11581@@ -74,7 +74,7 @@ config X86_PTDUMP
11582 config DEBUG_RODATA
11583 bool "Write protect kernel read-only data structures"
11584 default y
11585- depends on DEBUG_KERNEL
11586+ depends on DEBUG_KERNEL && BROKEN
11587 ---help---
11588 Mark the kernel read-only data as write-protected in the pagetables,
11589 in order to catch accidental (and incorrect) writes to such const
11590@@ -92,7 +92,7 @@ config DEBUG_RODATA_TEST
11591
11592 config DEBUG_SET_MODULE_RONX
11593 bool "Set loadable kernel module data as NX and text as RO"
11594- depends on MODULES
11595+ depends on MODULES && BROKEN
11596 ---help---
11597 This option helps catch unintended modifications to loadable
11598 kernel module's text and read-only data. It also prevents execution
11599diff --git a/arch/x86/Makefile b/arch/x86/Makefile
11600index 07639c6..6f2c901 100644
11601--- a/arch/x86/Makefile
11602+++ b/arch/x86/Makefile
11603@@ -54,6 +54,7 @@ else
11604 UTS_MACHINE := x86_64
11605 CHECKFLAGS += -D__x86_64__ -m64
11606
11607+ biarch := $(call cc-option,-m64)
11608 KBUILD_AFLAGS += -m64
11609 KBUILD_CFLAGS += -m64
11610
11611@@ -241,3 +242,12 @@ define archhelp
11612 echo ' FDINITRD=file initrd for the booted kernel'
11613 echo ' kvmconfig - Enable additional options for guest kernel support'
11614 endef
11615+
11616+define OLD_LD
11617+
11618+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
11619+*** Please upgrade your binutils to 2.18 or newer
11620+endef
11621+
11622+archprepare:
11623+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
11624diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
11625index 379814b..add62ce 100644
11626--- a/arch/x86/boot/Makefile
11627+++ b/arch/x86/boot/Makefile
11628@@ -65,6 +65,9 @@ KBUILD_CFLAGS := $(USERINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
11629 $(call cc-option, -fno-stack-protector) \
11630 $(call cc-option, -mpreferred-stack-boundary=2)
11631 KBUILD_CFLAGS += $(call cc-option, -m32)
11632+ifdef CONSTIFY_PLUGIN
11633+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
11634+endif
11635 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
11636 GCOV_PROFILE := n
11637
11638diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
11639index 878e4b9..20537ab 100644
11640--- a/arch/x86/boot/bitops.h
11641+++ b/arch/x86/boot/bitops.h
11642@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
11643 u8 v;
11644 const u32 *p = (const u32 *)addr;
11645
11646- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
11647+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
11648 return v;
11649 }
11650
11651@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
11652
11653 static inline void set_bit(int nr, void *addr)
11654 {
11655- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
11656+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
11657 }
11658
11659 #endif /* BOOT_BITOPS_H */
11660diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
11661index 5b75319..331a4ca 100644
11662--- a/arch/x86/boot/boot.h
11663+++ b/arch/x86/boot/boot.h
11664@@ -85,7 +85,7 @@ static inline void io_delay(void)
11665 static inline u16 ds(void)
11666 {
11667 u16 seg;
11668- asm("movw %%ds,%0" : "=rm" (seg));
11669+ asm volatile("movw %%ds,%0" : "=rm" (seg));
11670 return seg;
11671 }
11672
11673@@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
11674 static inline int memcmp(const void *s1, const void *s2, size_t len)
11675 {
11676 u8 diff;
11677- asm("repe; cmpsb; setnz %0"
11678+ asm volatile("repe; cmpsb; setnz %0"
11679 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
11680 return diff;
11681 }
11682diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
11683index dcd90df..c830d7d 100644
11684--- a/arch/x86/boot/compressed/Makefile
11685+++ b/arch/x86/boot/compressed/Makefile
11686@@ -15,6 +15,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
11687 KBUILD_CFLAGS += $(cflags-y)
11688 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
11689 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
11690+ifdef CONSTIFY_PLUGIN
11691+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
11692+endif
11693
11694 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
11695 GCOV_PROFILE := n
11696diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
11697index b7388a4..03844ec 100644
11698--- a/arch/x86/boot/compressed/eboot.c
11699+++ b/arch/x86/boot/compressed/eboot.c
11700@@ -150,7 +150,6 @@ again:
11701 *addr = max_addr;
11702 }
11703
11704-free_pool:
11705 efi_call_phys1(sys_table->boottime->free_pool, map);
11706
11707 fail:
11708@@ -214,7 +213,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
11709 if (i == map_size / desc_size)
11710 status = EFI_NOT_FOUND;
11711
11712-free_pool:
11713 efi_call_phys1(sys_table->boottime->free_pool, map);
11714 fail:
11715 return status;
11716diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
11717index a53440e..c3dbf1e 100644
11718--- a/arch/x86/boot/compressed/efi_stub_32.S
11719+++ b/arch/x86/boot/compressed/efi_stub_32.S
11720@@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
11721 * parameter 2, ..., param n. To make things easy, we save the return
11722 * address of efi_call_phys in a global variable.
11723 */
11724- popl %ecx
11725- movl %ecx, saved_return_addr(%edx)
11726- /* get the function pointer into ECX*/
11727- popl %ecx
11728- movl %ecx, efi_rt_function_ptr(%edx)
11729+ popl saved_return_addr(%edx)
11730+ popl efi_rt_function_ptr(%edx)
11731
11732 /*
11733 * 3. Call the physical function.
11734 */
11735- call *%ecx
11736+ call *efi_rt_function_ptr(%edx)
11737
11738 /*
11739 * 4. Balance the stack. And because EAX contain the return value,
11740@@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
11741 1: popl %edx
11742 subl $1b, %edx
11743
11744- movl efi_rt_function_ptr(%edx), %ecx
11745- pushl %ecx
11746+ pushl efi_rt_function_ptr(%edx)
11747
11748 /*
11749 * 10. Push the saved return address onto the stack and return.
11750 */
11751- movl saved_return_addr(%edx), %ecx
11752- pushl %ecx
11753- ret
11754+ jmpl *saved_return_addr(%edx)
11755 ENDPROC(efi_call_phys)
11756 .previous
11757
11758diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
11759index 1e3184f..0d11e2e 100644
11760--- a/arch/x86/boot/compressed/head_32.S
11761+++ b/arch/x86/boot/compressed/head_32.S
11762@@ -118,7 +118,7 @@ preferred_addr:
11763 notl %eax
11764 andl %eax, %ebx
11765 #else
11766- movl $LOAD_PHYSICAL_ADDR, %ebx
11767+ movl $____LOAD_PHYSICAL_ADDR, %ebx
11768 #endif
11769
11770 /* Target address to relocate to for decompression */
11771@@ -204,7 +204,7 @@ relocated:
11772 * and where it was actually loaded.
11773 */
11774 movl %ebp, %ebx
11775- subl $LOAD_PHYSICAL_ADDR, %ebx
11776+ subl $____LOAD_PHYSICAL_ADDR, %ebx
11777 jz 2f /* Nothing to be done if loaded at compiled addr. */
11778 /*
11779 * Process relocations.
11780@@ -212,8 +212,7 @@ relocated:
11781
11782 1: subl $4, %edi
11783 movl (%edi), %ecx
11784- testl %ecx, %ecx
11785- jz 2f
11786+ jecxz 2f
11787 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
11788 jmp 1b
11789 2:
11790diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
11791index 06e71c2..88a98264 100644
11792--- a/arch/x86/boot/compressed/head_64.S
11793+++ b/arch/x86/boot/compressed/head_64.S
11794@@ -95,7 +95,7 @@ ENTRY(startup_32)
11795 notl %eax
11796 andl %eax, %ebx
11797 #else
11798- movl $LOAD_PHYSICAL_ADDR, %ebx
11799+ movl $____LOAD_PHYSICAL_ADDR, %ebx
11800 #endif
11801
11802 /* Target address to relocate to for decompression */
11803@@ -270,7 +270,7 @@ preferred_addr:
11804 notq %rax
11805 andq %rax, %rbp
11806 #else
11807- movq $LOAD_PHYSICAL_ADDR, %rbp
11808+ movq $____LOAD_PHYSICAL_ADDR, %rbp
11809 #endif
11810
11811 /* Target address to relocate to for decompression */
11812@@ -361,8 +361,8 @@ gdt:
11813 .long gdt
11814 .word 0
11815 .quad 0x0000000000000000 /* NULL descriptor */
11816- .quad 0x00af9a000000ffff /* __KERNEL_CS */
11817- .quad 0x00cf92000000ffff /* __KERNEL_DS */
11818+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
11819+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
11820 .quad 0x0080890000000000 /* TS descriptor */
11821 .quad 0x0000000000000000 /* TS continued */
11822 gdt_end:
11823diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
11824index 0319c88..7c1931f 100644
11825--- a/arch/x86/boot/compressed/misc.c
11826+++ b/arch/x86/boot/compressed/misc.c
11827@@ -307,7 +307,7 @@ static void parse_elf(void *output)
11828 case PT_LOAD:
11829 #ifdef CONFIG_RELOCATABLE
11830 dest = output;
11831- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
11832+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
11833 #else
11834 dest = (void *)(phdr->p_paddr);
11835 #endif
11836@@ -358,7 +358,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
11837 error("Destination address too large");
11838 #endif
11839 #ifndef CONFIG_RELOCATABLE
11840- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
11841+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
11842 error("Wrong destination address");
11843 #endif
11844
11845diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
11846index 4d3ff03..e4972ff 100644
11847--- a/arch/x86/boot/cpucheck.c
11848+++ b/arch/x86/boot/cpucheck.c
11849@@ -74,7 +74,7 @@ static int has_fpu(void)
11850 u16 fcw = -1, fsw = -1;
11851 u32 cr0;
11852
11853- asm("movl %%cr0,%0" : "=r" (cr0));
11854+ asm volatile("movl %%cr0,%0" : "=r" (cr0));
11855 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
11856 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
11857 asm volatile("movl %0,%%cr0" : : "r" (cr0));
11858@@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
11859 {
11860 u32 f0, f1;
11861
11862- asm("pushfl ; "
11863+ asm volatile("pushfl ; "
11864 "pushfl ; "
11865 "popl %0 ; "
11866 "movl %0,%1 ; "
11867@@ -115,7 +115,7 @@ static void get_flags(void)
11868 set_bit(X86_FEATURE_FPU, cpu.flags);
11869
11870 if (has_eflag(X86_EFLAGS_ID)) {
11871- asm("cpuid"
11872+ asm volatile("cpuid"
11873 : "=a" (max_intel_level),
11874 "=b" (cpu_vendor[0]),
11875 "=d" (cpu_vendor[1]),
11876@@ -124,7 +124,7 @@ static void get_flags(void)
11877
11878 if (max_intel_level >= 0x00000001 &&
11879 max_intel_level <= 0x0000ffff) {
11880- asm("cpuid"
11881+ asm volatile("cpuid"
11882 : "=a" (tfms),
11883 "=c" (cpu.flags[4]),
11884 "=d" (cpu.flags[0])
11885@@ -136,7 +136,7 @@ static void get_flags(void)
11886 cpu.model += ((tfms >> 16) & 0xf) << 4;
11887 }
11888
11889- asm("cpuid"
11890+ asm volatile("cpuid"
11891 : "=a" (max_amd_level)
11892 : "a" (0x80000000)
11893 : "ebx", "ecx", "edx");
11894@@ -144,7 +144,7 @@ static void get_flags(void)
11895 if (max_amd_level >= 0x80000001 &&
11896 max_amd_level <= 0x8000ffff) {
11897 u32 eax = 0x80000001;
11898- asm("cpuid"
11899+ asm volatile("cpuid"
11900 : "+a" (eax),
11901 "=c" (cpu.flags[6]),
11902 "=d" (cpu.flags[1])
11903@@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
11904 u32 ecx = MSR_K7_HWCR;
11905 u32 eax, edx;
11906
11907- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
11908+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
11909 eax &= ~(1 << 15);
11910- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
11911+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
11912
11913 get_flags(); /* Make sure it really did something */
11914 err = check_flags();
11915@@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
11916 u32 ecx = MSR_VIA_FCR;
11917 u32 eax, edx;
11918
11919- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
11920+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
11921 eax |= (1<<1)|(1<<7);
11922- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
11923+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
11924
11925 set_bit(X86_FEATURE_CX8, cpu.flags);
11926 err = check_flags();
11927@@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
11928 u32 eax, edx;
11929 u32 level = 1;
11930
11931- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
11932- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
11933- asm("cpuid"
11934+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
11935+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
11936+ asm volatile("cpuid"
11937 : "+a" (level), "=d" (cpu.flags[0])
11938 : : "ecx", "ebx");
11939- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
11940+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
11941
11942 err = check_flags();
11943 }
11944diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
11945index 9ec06a1..2c25e79 100644
11946--- a/arch/x86/boot/header.S
11947+++ b/arch/x86/boot/header.S
11948@@ -409,10 +409,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
11949 # single linked list of
11950 # struct setup_data
11951
11952-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
11953+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
11954
11955 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
11956+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
11957+#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
11958+#else
11959 #define VO_INIT_SIZE (VO__end - VO__text)
11960+#endif
11961 #if ZO_INIT_SIZE > VO_INIT_SIZE
11962 #define INIT_SIZE ZO_INIT_SIZE
11963 #else
11964diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
11965index db75d07..8e6d0af 100644
11966--- a/arch/x86/boot/memory.c
11967+++ b/arch/x86/boot/memory.c
11968@@ -19,7 +19,7 @@
11969
11970 static int detect_memory_e820(void)
11971 {
11972- int count = 0;
11973+ unsigned int count = 0;
11974 struct biosregs ireg, oreg;
11975 struct e820entry *desc = boot_params.e820_map;
11976 static struct e820entry buf; /* static so it is zeroed */
11977diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
11978index 11e8c6e..fdbb1ed 100644
11979--- a/arch/x86/boot/video-vesa.c
11980+++ b/arch/x86/boot/video-vesa.c
11981@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
11982
11983 boot_params.screen_info.vesapm_seg = oreg.es;
11984 boot_params.screen_info.vesapm_off = oreg.di;
11985+ boot_params.screen_info.vesapm_size = oreg.cx;
11986 }
11987
11988 /*
11989diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
11990index 43eda28..5ab5fdb 100644
11991--- a/arch/x86/boot/video.c
11992+++ b/arch/x86/boot/video.c
11993@@ -96,7 +96,7 @@ static void store_mode_params(void)
11994 static unsigned int get_entry(void)
11995 {
11996 char entry_buf[4];
11997- int i, len = 0;
11998+ unsigned int i, len = 0;
11999 int key;
12000 unsigned int v;
12001
12002diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
12003index 9105655..5e37f27 100644
12004--- a/arch/x86/crypto/aes-x86_64-asm_64.S
12005+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
12006@@ -8,6 +8,8 @@
12007 * including this sentence is retained in full.
12008 */
12009
12010+#include <asm/alternative-asm.h>
12011+
12012 .extern crypto_ft_tab
12013 .extern crypto_it_tab
12014 .extern crypto_fl_tab
12015@@ -70,6 +72,8 @@
12016 je B192; \
12017 leaq 32(r9),r9;
12018
12019+#define ret pax_force_retaddr 0, 1; ret
12020+
12021 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
12022 movq r1,r2; \
12023 movq r3,r4; \
12024diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
12025index 477e9d7..3ab339f 100644
12026--- a/arch/x86/crypto/aesni-intel_asm.S
12027+++ b/arch/x86/crypto/aesni-intel_asm.S
12028@@ -31,6 +31,7 @@
12029
12030 #include <linux/linkage.h>
12031 #include <asm/inst.h>
12032+#include <asm/alternative-asm.h>
12033
12034 #ifdef __x86_64__
12035 .data
12036@@ -1441,6 +1442,7 @@ _return_T_done_decrypt:
12037 pop %r14
12038 pop %r13
12039 pop %r12
12040+ pax_force_retaddr 0, 1
12041 ret
12042 ENDPROC(aesni_gcm_dec)
12043
12044@@ -1705,6 +1707,7 @@ _return_T_done_encrypt:
12045 pop %r14
12046 pop %r13
12047 pop %r12
12048+ pax_force_retaddr 0, 1
12049 ret
12050 ENDPROC(aesni_gcm_enc)
12051
12052@@ -1722,6 +1725,7 @@ _key_expansion_256a:
12053 pxor %xmm1, %xmm0
12054 movaps %xmm0, (TKEYP)
12055 add $0x10, TKEYP
12056+ pax_force_retaddr_bts
12057 ret
12058 ENDPROC(_key_expansion_128)
12059 ENDPROC(_key_expansion_256a)
12060@@ -1748,6 +1752,7 @@ _key_expansion_192a:
12061 shufps $0b01001110, %xmm2, %xmm1
12062 movaps %xmm1, 0x10(TKEYP)
12063 add $0x20, TKEYP
12064+ pax_force_retaddr_bts
12065 ret
12066 ENDPROC(_key_expansion_192a)
12067
12068@@ -1768,6 +1773,7 @@ _key_expansion_192b:
12069
12070 movaps %xmm0, (TKEYP)
12071 add $0x10, TKEYP
12072+ pax_force_retaddr_bts
12073 ret
12074 ENDPROC(_key_expansion_192b)
12075
12076@@ -1781,6 +1787,7 @@ _key_expansion_256b:
12077 pxor %xmm1, %xmm2
12078 movaps %xmm2, (TKEYP)
12079 add $0x10, TKEYP
12080+ pax_force_retaddr_bts
12081 ret
12082 ENDPROC(_key_expansion_256b)
12083
12084@@ -1894,6 +1901,7 @@ ENTRY(aesni_set_key)
12085 #ifndef __x86_64__
12086 popl KEYP
12087 #endif
12088+ pax_force_retaddr 0, 1
12089 ret
12090 ENDPROC(aesni_set_key)
12091
12092@@ -1916,6 +1924,7 @@ ENTRY(aesni_enc)
12093 popl KLEN
12094 popl KEYP
12095 #endif
12096+ pax_force_retaddr 0, 1
12097 ret
12098 ENDPROC(aesni_enc)
12099
12100@@ -1974,6 +1983,7 @@ _aesni_enc1:
12101 AESENC KEY STATE
12102 movaps 0x70(TKEYP), KEY
12103 AESENCLAST KEY STATE
12104+ pax_force_retaddr_bts
12105 ret
12106 ENDPROC(_aesni_enc1)
12107
12108@@ -2083,6 +2093,7 @@ _aesni_enc4:
12109 AESENCLAST KEY STATE2
12110 AESENCLAST KEY STATE3
12111 AESENCLAST KEY STATE4
12112+ pax_force_retaddr_bts
12113 ret
12114 ENDPROC(_aesni_enc4)
12115
12116@@ -2106,6 +2117,7 @@ ENTRY(aesni_dec)
12117 popl KLEN
12118 popl KEYP
12119 #endif
12120+ pax_force_retaddr 0, 1
12121 ret
12122 ENDPROC(aesni_dec)
12123
12124@@ -2164,6 +2176,7 @@ _aesni_dec1:
12125 AESDEC KEY STATE
12126 movaps 0x70(TKEYP), KEY
12127 AESDECLAST KEY STATE
12128+ pax_force_retaddr_bts
12129 ret
12130 ENDPROC(_aesni_dec1)
12131
12132@@ -2273,6 +2286,7 @@ _aesni_dec4:
12133 AESDECLAST KEY STATE2
12134 AESDECLAST KEY STATE3
12135 AESDECLAST KEY STATE4
12136+ pax_force_retaddr_bts
12137 ret
12138 ENDPROC(_aesni_dec4)
12139
12140@@ -2331,6 +2345,7 @@ ENTRY(aesni_ecb_enc)
12141 popl KEYP
12142 popl LEN
12143 #endif
12144+ pax_force_retaddr 0, 1
12145 ret
12146 ENDPROC(aesni_ecb_enc)
12147
12148@@ -2390,6 +2405,7 @@ ENTRY(aesni_ecb_dec)
12149 popl KEYP
12150 popl LEN
12151 #endif
12152+ pax_force_retaddr 0, 1
12153 ret
12154 ENDPROC(aesni_ecb_dec)
12155
12156@@ -2432,6 +2448,7 @@ ENTRY(aesni_cbc_enc)
12157 popl LEN
12158 popl IVP
12159 #endif
12160+ pax_force_retaddr 0, 1
12161 ret
12162 ENDPROC(aesni_cbc_enc)
12163
12164@@ -2523,6 +2540,7 @@ ENTRY(aesni_cbc_dec)
12165 popl LEN
12166 popl IVP
12167 #endif
12168+ pax_force_retaddr 0, 1
12169 ret
12170 ENDPROC(aesni_cbc_dec)
12171
12172@@ -2550,6 +2568,7 @@ _aesni_inc_init:
12173 mov $1, TCTR_LOW
12174 MOVQ_R64_XMM TCTR_LOW INC
12175 MOVQ_R64_XMM CTR TCTR_LOW
12176+ pax_force_retaddr_bts
12177 ret
12178 ENDPROC(_aesni_inc_init)
12179
12180@@ -2579,6 +2598,7 @@ _aesni_inc:
12181 .Linc_low:
12182 movaps CTR, IV
12183 PSHUFB_XMM BSWAP_MASK IV
12184+ pax_force_retaddr_bts
12185 ret
12186 ENDPROC(_aesni_inc)
12187
12188@@ -2640,6 +2660,7 @@ ENTRY(aesni_ctr_enc)
12189 .Lctr_enc_ret:
12190 movups IV, (IVP)
12191 .Lctr_enc_just_ret:
12192+ pax_force_retaddr 0, 1
12193 ret
12194 ENDPROC(aesni_ctr_enc)
12195
12196@@ -2766,6 +2787,7 @@ ENTRY(aesni_xts_crypt8)
12197 pxor INC, STATE4
12198 movdqu STATE4, 0x70(OUTP)
12199
12200+ pax_force_retaddr 0, 1
12201 ret
12202 ENDPROC(aesni_xts_crypt8)
12203
12204diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
12205index 246c670..4d1ed00 100644
12206--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
12207+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
12208@@ -21,6 +21,7 @@
12209 */
12210
12211 #include <linux/linkage.h>
12212+#include <asm/alternative-asm.h>
12213
12214 .file "blowfish-x86_64-asm.S"
12215 .text
12216@@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
12217 jnz .L__enc_xor;
12218
12219 write_block();
12220+ pax_force_retaddr 0, 1
12221 ret;
12222 .L__enc_xor:
12223 xor_block();
12224+ pax_force_retaddr 0, 1
12225 ret;
12226 ENDPROC(__blowfish_enc_blk)
12227
12228@@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
12229
12230 movq %r11, %rbp;
12231
12232+ pax_force_retaddr 0, 1
12233 ret;
12234 ENDPROC(blowfish_dec_blk)
12235
12236@@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
12237
12238 popq %rbx;
12239 popq %rbp;
12240+ pax_force_retaddr 0, 1
12241 ret;
12242
12243 .L__enc_xor4:
12244@@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
12245
12246 popq %rbx;
12247 popq %rbp;
12248+ pax_force_retaddr 0, 1
12249 ret;
12250 ENDPROC(__blowfish_enc_blk_4way)
12251
12252@@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
12253 popq %rbx;
12254 popq %rbp;
12255
12256+ pax_force_retaddr 0, 1
12257 ret;
12258 ENDPROC(blowfish_dec_blk_4way)
12259diff --git a/arch/x86/crypto/camellia-aesni-avx-asm_64.S b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
12260index ce71f92..2dd5b1e 100644
12261--- a/arch/x86/crypto/camellia-aesni-avx-asm_64.S
12262+++ b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
12263@@ -16,6 +16,7 @@
12264 */
12265
12266 #include <linux/linkage.h>
12267+#include <asm/alternative-asm.h>
12268
12269 #define CAMELLIA_TABLE_BYTE_LEN 272
12270
12271@@ -191,6 +192,7 @@ roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
12272 roundsm16(%xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7,
12273 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14, %xmm15,
12274 %rcx, (%r9));
12275+ pax_force_retaddr_bts
12276 ret;
12277 ENDPROC(roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
12278
12279@@ -199,6 +201,7 @@ roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
12280 roundsm16(%xmm4, %xmm5, %xmm6, %xmm7, %xmm0, %xmm1, %xmm2, %xmm3,
12281 %xmm12, %xmm13, %xmm14, %xmm15, %xmm8, %xmm9, %xmm10, %xmm11,
12282 %rax, (%r9));
12283+ pax_force_retaddr_bts
12284 ret;
12285 ENDPROC(roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
12286
12287@@ -780,6 +783,7 @@ __camellia_enc_blk16:
12288 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
12289 %xmm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 16(%rax));
12290
12291+ pax_force_retaddr_bts
12292 ret;
12293
12294 .align 8
12295@@ -865,6 +869,7 @@ __camellia_dec_blk16:
12296 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
12297 %xmm15, (key_table)(CTX), (%rax), 1 * 16(%rax));
12298
12299+ pax_force_retaddr_bts
12300 ret;
12301
12302 .align 8
12303@@ -904,6 +909,7 @@ ENTRY(camellia_ecb_enc_16way)
12304 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12305 %xmm8, %rsi);
12306
12307+ pax_force_retaddr 0, 1
12308 ret;
12309 ENDPROC(camellia_ecb_enc_16way)
12310
12311@@ -932,6 +938,7 @@ ENTRY(camellia_ecb_dec_16way)
12312 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12313 %xmm8, %rsi);
12314
12315+ pax_force_retaddr 0, 1
12316 ret;
12317 ENDPROC(camellia_ecb_dec_16way)
12318
12319@@ -981,6 +988,7 @@ ENTRY(camellia_cbc_dec_16way)
12320 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12321 %xmm8, %rsi);
12322
12323+ pax_force_retaddr 0, 1
12324 ret;
12325 ENDPROC(camellia_cbc_dec_16way)
12326
12327@@ -1092,6 +1100,7 @@ ENTRY(camellia_ctr_16way)
12328 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12329 %xmm8, %rsi);
12330
12331+ pax_force_retaddr 0, 1
12332 ret;
12333 ENDPROC(camellia_ctr_16way)
12334
12335@@ -1234,6 +1243,7 @@ camellia_xts_crypt_16way:
12336 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12337 %xmm8, %rsi);
12338
12339+ pax_force_retaddr 0, 1
12340 ret;
12341 ENDPROC(camellia_xts_crypt_16way)
12342
12343diff --git a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
12344index 0e0b886..8fc756a 100644
12345--- a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
12346+++ b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
12347@@ -11,6 +11,7 @@
12348 */
12349
12350 #include <linux/linkage.h>
12351+#include <asm/alternative-asm.h>
12352
12353 #define CAMELLIA_TABLE_BYTE_LEN 272
12354
12355@@ -230,6 +231,7 @@ roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
12356 roundsm32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
12357 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15,
12358 %rcx, (%r9));
12359+ pax_force_retaddr_bts
12360 ret;
12361 ENDPROC(roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
12362
12363@@ -238,6 +240,7 @@ roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
12364 roundsm32(%ymm4, %ymm5, %ymm6, %ymm7, %ymm0, %ymm1, %ymm2, %ymm3,
12365 %ymm12, %ymm13, %ymm14, %ymm15, %ymm8, %ymm9, %ymm10, %ymm11,
12366 %rax, (%r9));
12367+ pax_force_retaddr_bts
12368 ret;
12369 ENDPROC(roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
12370
12371@@ -820,6 +823,7 @@ __camellia_enc_blk32:
12372 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
12373 %ymm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 32(%rax));
12374
12375+ pax_force_retaddr_bts
12376 ret;
12377
12378 .align 8
12379@@ -905,6 +909,7 @@ __camellia_dec_blk32:
12380 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
12381 %ymm15, (key_table)(CTX), (%rax), 1 * 32(%rax));
12382
12383+ pax_force_retaddr_bts
12384 ret;
12385
12386 .align 8
12387@@ -948,6 +953,7 @@ ENTRY(camellia_ecb_enc_32way)
12388
12389 vzeroupper;
12390
12391+ pax_force_retaddr 0, 1
12392 ret;
12393 ENDPROC(camellia_ecb_enc_32way)
12394
12395@@ -980,6 +986,7 @@ ENTRY(camellia_ecb_dec_32way)
12396
12397 vzeroupper;
12398
12399+ pax_force_retaddr 0, 1
12400 ret;
12401 ENDPROC(camellia_ecb_dec_32way)
12402
12403@@ -1046,6 +1053,7 @@ ENTRY(camellia_cbc_dec_32way)
12404
12405 vzeroupper;
12406
12407+ pax_force_retaddr 0, 1
12408 ret;
12409 ENDPROC(camellia_cbc_dec_32way)
12410
12411@@ -1184,6 +1192,7 @@ ENTRY(camellia_ctr_32way)
12412
12413 vzeroupper;
12414
12415+ pax_force_retaddr 0, 1
12416 ret;
12417 ENDPROC(camellia_ctr_32way)
12418
12419@@ -1349,6 +1358,7 @@ camellia_xts_crypt_32way:
12420
12421 vzeroupper;
12422
12423+ pax_force_retaddr 0, 1
12424 ret;
12425 ENDPROC(camellia_xts_crypt_32way)
12426
12427diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
12428index 310319c..ce174a4 100644
12429--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
12430+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
12431@@ -21,6 +21,7 @@
12432 */
12433
12434 #include <linux/linkage.h>
12435+#include <asm/alternative-asm.h>
12436
12437 .file "camellia-x86_64-asm_64.S"
12438 .text
12439@@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
12440 enc_outunpack(mov, RT1);
12441
12442 movq RRBP, %rbp;
12443+ pax_force_retaddr 0, 1
12444 ret;
12445
12446 .L__enc_xor:
12447 enc_outunpack(xor, RT1);
12448
12449 movq RRBP, %rbp;
12450+ pax_force_retaddr 0, 1
12451 ret;
12452 ENDPROC(__camellia_enc_blk)
12453
12454@@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
12455 dec_outunpack();
12456
12457 movq RRBP, %rbp;
12458+ pax_force_retaddr 0, 1
12459 ret;
12460 ENDPROC(camellia_dec_blk)
12461
12462@@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
12463
12464 movq RRBP, %rbp;
12465 popq %rbx;
12466+ pax_force_retaddr 0, 1
12467 ret;
12468
12469 .L__enc2_xor:
12470@@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
12471
12472 movq RRBP, %rbp;
12473 popq %rbx;
12474+ pax_force_retaddr 0, 1
12475 ret;
12476 ENDPROC(__camellia_enc_blk_2way)
12477
12478@@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
12479
12480 movq RRBP, %rbp;
12481 movq RXOR, %rbx;
12482+ pax_force_retaddr 0, 1
12483 ret;
12484 ENDPROC(camellia_dec_blk_2way)
12485diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
12486index c35fd5d..c1ee236 100644
12487--- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
12488+++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
12489@@ -24,6 +24,7 @@
12490 */
12491
12492 #include <linux/linkage.h>
12493+#include <asm/alternative-asm.h>
12494
12495 .file "cast5-avx-x86_64-asm_64.S"
12496
12497@@ -281,6 +282,7 @@ __cast5_enc_blk16:
12498 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
12499 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
12500
12501+ pax_force_retaddr 0, 1
12502 ret;
12503 ENDPROC(__cast5_enc_blk16)
12504
12505@@ -352,6 +354,7 @@ __cast5_dec_blk16:
12506 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
12507 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
12508
12509+ pax_force_retaddr 0, 1
12510 ret;
12511
12512 .L__skip_dec:
12513@@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
12514 vmovdqu RR4, (6*4*4)(%r11);
12515 vmovdqu RL4, (7*4*4)(%r11);
12516
12517+ pax_force_retaddr
12518 ret;
12519 ENDPROC(cast5_ecb_enc_16way)
12520
12521@@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
12522 vmovdqu RR4, (6*4*4)(%r11);
12523 vmovdqu RL4, (7*4*4)(%r11);
12524
12525+ pax_force_retaddr
12526 ret;
12527 ENDPROC(cast5_ecb_dec_16way)
12528
12529@@ -469,6 +474,7 @@ ENTRY(cast5_cbc_dec_16way)
12530
12531 popq %r12;
12532
12533+ pax_force_retaddr
12534 ret;
12535 ENDPROC(cast5_cbc_dec_16way)
12536
12537@@ -542,5 +548,6 @@ ENTRY(cast5_ctr_16way)
12538
12539 popq %r12;
12540
12541+ pax_force_retaddr
12542 ret;
12543 ENDPROC(cast5_ctr_16way)
12544diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
12545index e3531f8..18ded3a 100644
12546--- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
12547+++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
12548@@ -24,6 +24,7 @@
12549 */
12550
12551 #include <linux/linkage.h>
12552+#include <asm/alternative-asm.h>
12553 #include "glue_helper-asm-avx.S"
12554
12555 .file "cast6-avx-x86_64-asm_64.S"
12556@@ -295,6 +296,7 @@ __cast6_enc_blk8:
12557 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
12558 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
12559
12560+ pax_force_retaddr 0, 1
12561 ret;
12562 ENDPROC(__cast6_enc_blk8)
12563
12564@@ -340,6 +342,7 @@ __cast6_dec_blk8:
12565 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
12566 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
12567
12568+ pax_force_retaddr 0, 1
12569 ret;
12570 ENDPROC(__cast6_dec_blk8)
12571
12572@@ -358,6 +361,7 @@ ENTRY(cast6_ecb_enc_8way)
12573
12574 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12575
12576+ pax_force_retaddr
12577 ret;
12578 ENDPROC(cast6_ecb_enc_8way)
12579
12580@@ -376,6 +380,7 @@ ENTRY(cast6_ecb_dec_8way)
12581
12582 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12583
12584+ pax_force_retaddr
12585 ret;
12586 ENDPROC(cast6_ecb_dec_8way)
12587
12588@@ -399,6 +404,7 @@ ENTRY(cast6_cbc_dec_8way)
12589
12590 popq %r12;
12591
12592+ pax_force_retaddr
12593 ret;
12594 ENDPROC(cast6_cbc_dec_8way)
12595
12596@@ -424,6 +430,7 @@ ENTRY(cast6_ctr_8way)
12597
12598 popq %r12;
12599
12600+ pax_force_retaddr
12601 ret;
12602 ENDPROC(cast6_ctr_8way)
12603
12604@@ -446,6 +453,7 @@ ENTRY(cast6_xts_enc_8way)
12605 /* dst <= regs xor IVs(in dst) */
12606 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12607
12608+ pax_force_retaddr
12609 ret;
12610 ENDPROC(cast6_xts_enc_8way)
12611
12612@@ -468,5 +476,6 @@ ENTRY(cast6_xts_dec_8way)
12613 /* dst <= regs xor IVs(in dst) */
12614 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12615
12616+ pax_force_retaddr
12617 ret;
12618 ENDPROC(cast6_xts_dec_8way)
12619diff --git a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
12620index dbc4339..3d868c5 100644
12621--- a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
12622+++ b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
12623@@ -45,6 +45,7 @@
12624
12625 #include <asm/inst.h>
12626 #include <linux/linkage.h>
12627+#include <asm/alternative-asm.h>
12628
12629 ## ISCSI CRC 32 Implementation with crc32 and pclmulqdq Instruction
12630
12631@@ -312,6 +313,7 @@ do_return:
12632 popq %rsi
12633 popq %rdi
12634 popq %rbx
12635+ pax_force_retaddr 0, 1
12636 ret
12637
12638 ################################################################
12639diff --git a/arch/x86/crypto/ghash-clmulni-intel_asm.S b/arch/x86/crypto/ghash-clmulni-intel_asm.S
12640index 586f41a..d02851e 100644
12641--- a/arch/x86/crypto/ghash-clmulni-intel_asm.S
12642+++ b/arch/x86/crypto/ghash-clmulni-intel_asm.S
12643@@ -18,6 +18,7 @@
12644
12645 #include <linux/linkage.h>
12646 #include <asm/inst.h>
12647+#include <asm/alternative-asm.h>
12648
12649 .data
12650
12651@@ -93,6 +94,7 @@ __clmul_gf128mul_ble:
12652 psrlq $1, T2
12653 pxor T2, T1
12654 pxor T1, DATA
12655+ pax_force_retaddr
12656 ret
12657 ENDPROC(__clmul_gf128mul_ble)
12658
12659@@ -105,6 +107,7 @@ ENTRY(clmul_ghash_mul)
12660 call __clmul_gf128mul_ble
12661 PSHUFB_XMM BSWAP DATA
12662 movups DATA, (%rdi)
12663+ pax_force_retaddr
12664 ret
12665 ENDPROC(clmul_ghash_mul)
12666
12667@@ -132,6 +135,7 @@ ENTRY(clmul_ghash_update)
12668 PSHUFB_XMM BSWAP DATA
12669 movups DATA, (%rdi)
12670 .Lupdate_just_ret:
12671+ pax_force_retaddr
12672 ret
12673 ENDPROC(clmul_ghash_update)
12674
12675@@ -157,5 +161,6 @@ ENTRY(clmul_ghash_setkey)
12676 pand .Lpoly, %xmm1
12677 pxor %xmm1, %xmm0
12678 movups %xmm0, (%rdi)
12679+ pax_force_retaddr
12680 ret
12681 ENDPROC(clmul_ghash_setkey)
12682diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
12683index 9279e0b..9270820 100644
12684--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
12685+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
12686@@ -1,4 +1,5 @@
12687 #include <linux/linkage.h>
12688+#include <asm/alternative-asm.h>
12689
12690 # enter salsa20_encrypt_bytes
12691 ENTRY(salsa20_encrypt_bytes)
12692@@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
12693 add %r11,%rsp
12694 mov %rdi,%rax
12695 mov %rsi,%rdx
12696+ pax_force_retaddr 0, 1
12697 ret
12698 # bytesatleast65:
12699 ._bytesatleast65:
12700@@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
12701 add %r11,%rsp
12702 mov %rdi,%rax
12703 mov %rsi,%rdx
12704+ pax_force_retaddr
12705 ret
12706 ENDPROC(salsa20_keysetup)
12707
12708@@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
12709 add %r11,%rsp
12710 mov %rdi,%rax
12711 mov %rsi,%rdx
12712+ pax_force_retaddr
12713 ret
12714 ENDPROC(salsa20_ivsetup)
12715diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
12716index 2f202f4..d9164d6 100644
12717--- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
12718+++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
12719@@ -24,6 +24,7 @@
12720 */
12721
12722 #include <linux/linkage.h>
12723+#include <asm/alternative-asm.h>
12724 #include "glue_helper-asm-avx.S"
12725
12726 .file "serpent-avx-x86_64-asm_64.S"
12727@@ -618,6 +619,7 @@ __serpent_enc_blk8_avx:
12728 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
12729 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
12730
12731+ pax_force_retaddr
12732 ret;
12733 ENDPROC(__serpent_enc_blk8_avx)
12734
12735@@ -672,6 +674,7 @@ __serpent_dec_blk8_avx:
12736 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
12737 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
12738
12739+ pax_force_retaddr
12740 ret;
12741 ENDPROC(__serpent_dec_blk8_avx)
12742
12743@@ -688,6 +691,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
12744
12745 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12746
12747+ pax_force_retaddr
12748 ret;
12749 ENDPROC(serpent_ecb_enc_8way_avx)
12750
12751@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
12752
12753 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
12754
12755+ pax_force_retaddr
12756 ret;
12757 ENDPROC(serpent_ecb_dec_8way_avx)
12758
12759@@ -720,6 +725,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
12760
12761 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
12762
12763+ pax_force_retaddr
12764 ret;
12765 ENDPROC(serpent_cbc_dec_8way_avx)
12766
12767@@ -738,6 +744,7 @@ ENTRY(serpent_ctr_8way_avx)
12768
12769 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12770
12771+ pax_force_retaddr
12772 ret;
12773 ENDPROC(serpent_ctr_8way_avx)
12774
12775@@ -758,6 +765,7 @@ ENTRY(serpent_xts_enc_8way_avx)
12776 /* dst <= regs xor IVs(in dst) */
12777 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12778
12779+ pax_force_retaddr
12780 ret;
12781 ENDPROC(serpent_xts_enc_8way_avx)
12782
12783@@ -778,5 +786,6 @@ ENTRY(serpent_xts_dec_8way_avx)
12784 /* dst <= regs xor IVs(in dst) */
12785 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
12786
12787+ pax_force_retaddr
12788 ret;
12789 ENDPROC(serpent_xts_dec_8way_avx)
12790diff --git a/arch/x86/crypto/serpent-avx2-asm_64.S b/arch/x86/crypto/serpent-avx2-asm_64.S
12791index b222085..abd483c 100644
12792--- a/arch/x86/crypto/serpent-avx2-asm_64.S
12793+++ b/arch/x86/crypto/serpent-avx2-asm_64.S
12794@@ -15,6 +15,7 @@
12795 */
12796
12797 #include <linux/linkage.h>
12798+#include <asm/alternative-asm.h>
12799 #include "glue_helper-asm-avx2.S"
12800
12801 .file "serpent-avx2-asm_64.S"
12802@@ -610,6 +611,7 @@ __serpent_enc_blk16:
12803 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
12804 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
12805
12806+ pax_force_retaddr
12807 ret;
12808 ENDPROC(__serpent_enc_blk16)
12809
12810@@ -664,6 +666,7 @@ __serpent_dec_blk16:
12811 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
12812 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
12813
12814+ pax_force_retaddr
12815 ret;
12816 ENDPROC(__serpent_dec_blk16)
12817
12818@@ -684,6 +687,7 @@ ENTRY(serpent_ecb_enc_16way)
12819
12820 vzeroupper;
12821
12822+ pax_force_retaddr
12823 ret;
12824 ENDPROC(serpent_ecb_enc_16way)
12825
12826@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_16way)
12827
12828 vzeroupper;
12829
12830+ pax_force_retaddr
12831 ret;
12832 ENDPROC(serpent_ecb_dec_16way)
12833
12834@@ -725,6 +730,7 @@ ENTRY(serpent_cbc_dec_16way)
12835
12836 vzeroupper;
12837
12838+ pax_force_retaddr
12839 ret;
12840 ENDPROC(serpent_cbc_dec_16way)
12841
12842@@ -748,6 +754,7 @@ ENTRY(serpent_ctr_16way)
12843
12844 vzeroupper;
12845
12846+ pax_force_retaddr
12847 ret;
12848 ENDPROC(serpent_ctr_16way)
12849
12850@@ -772,6 +779,7 @@ ENTRY(serpent_xts_enc_16way)
12851
12852 vzeroupper;
12853
12854+ pax_force_retaddr
12855 ret;
12856 ENDPROC(serpent_xts_enc_16way)
12857
12858@@ -796,5 +804,6 @@ ENTRY(serpent_xts_dec_16way)
12859
12860 vzeroupper;
12861
12862+ pax_force_retaddr
12863 ret;
12864 ENDPROC(serpent_xts_dec_16way)
12865diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
12866index acc066c..1559cc4 100644
12867--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
12868+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
12869@@ -25,6 +25,7 @@
12870 */
12871
12872 #include <linux/linkage.h>
12873+#include <asm/alternative-asm.h>
12874
12875 .file "serpent-sse2-x86_64-asm_64.S"
12876 .text
12877@@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
12878 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
12879 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
12880
12881+ pax_force_retaddr
12882 ret;
12883
12884 .L__enc_xor8:
12885 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
12886 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
12887
12888+ pax_force_retaddr
12889 ret;
12890 ENDPROC(__serpent_enc_blk_8way)
12891
12892@@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
12893 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
12894 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
12895
12896+ pax_force_retaddr
12897 ret;
12898 ENDPROC(serpent_dec_blk_8way)
12899diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
12900index a410950..3356d42 100644
12901--- a/arch/x86/crypto/sha1_ssse3_asm.S
12902+++ b/arch/x86/crypto/sha1_ssse3_asm.S
12903@@ -29,6 +29,7 @@
12904 */
12905
12906 #include <linux/linkage.h>
12907+#include <asm/alternative-asm.h>
12908
12909 #define CTX %rdi // arg1
12910 #define BUF %rsi // arg2
12911@@ -104,6 +105,7 @@
12912 pop %r12
12913 pop %rbp
12914 pop %rbx
12915+ pax_force_retaddr 0, 1
12916 ret
12917
12918 ENDPROC(\name)
12919diff --git a/arch/x86/crypto/sha256-avx-asm.S b/arch/x86/crypto/sha256-avx-asm.S
12920index 642f156..4ab07b9 100644
12921--- a/arch/x86/crypto/sha256-avx-asm.S
12922+++ b/arch/x86/crypto/sha256-avx-asm.S
12923@@ -49,6 +49,7 @@
12924
12925 #ifdef CONFIG_AS_AVX
12926 #include <linux/linkage.h>
12927+#include <asm/alternative-asm.h>
12928
12929 ## assume buffers not aligned
12930 #define VMOVDQ vmovdqu
12931@@ -460,6 +461,7 @@ done_hash:
12932 popq %r13
12933 popq %rbp
12934 popq %rbx
12935+ pax_force_retaddr 0, 1
12936 ret
12937 ENDPROC(sha256_transform_avx)
12938
12939diff --git a/arch/x86/crypto/sha256-avx2-asm.S b/arch/x86/crypto/sha256-avx2-asm.S
12940index 9e86944..2e7f95a 100644
12941--- a/arch/x86/crypto/sha256-avx2-asm.S
12942+++ b/arch/x86/crypto/sha256-avx2-asm.S
12943@@ -50,6 +50,7 @@
12944
12945 #ifdef CONFIG_AS_AVX2
12946 #include <linux/linkage.h>
12947+#include <asm/alternative-asm.h>
12948
12949 ## assume buffers not aligned
12950 #define VMOVDQ vmovdqu
12951@@ -720,6 +721,7 @@ done_hash:
12952 popq %r12
12953 popq %rbp
12954 popq %rbx
12955+ pax_force_retaddr 0, 1
12956 ret
12957 ENDPROC(sha256_transform_rorx)
12958
12959diff --git a/arch/x86/crypto/sha256-ssse3-asm.S b/arch/x86/crypto/sha256-ssse3-asm.S
12960index f833b74..c36ed14 100644
12961--- a/arch/x86/crypto/sha256-ssse3-asm.S
12962+++ b/arch/x86/crypto/sha256-ssse3-asm.S
12963@@ -47,6 +47,7 @@
12964 ########################################################################
12965
12966 #include <linux/linkage.h>
12967+#include <asm/alternative-asm.h>
12968
12969 ## assume buffers not aligned
12970 #define MOVDQ movdqu
12971@@ -471,6 +472,7 @@ done_hash:
12972 popq %rbp
12973 popq %rbx
12974
12975+ pax_force_retaddr 0, 1
12976 ret
12977 ENDPROC(sha256_transform_ssse3)
12978
12979diff --git a/arch/x86/crypto/sha512-avx-asm.S b/arch/x86/crypto/sha512-avx-asm.S
12980index 974dde9..4533d34 100644
12981--- a/arch/x86/crypto/sha512-avx-asm.S
12982+++ b/arch/x86/crypto/sha512-avx-asm.S
12983@@ -49,6 +49,7 @@
12984
12985 #ifdef CONFIG_AS_AVX
12986 #include <linux/linkage.h>
12987+#include <asm/alternative-asm.h>
12988
12989 .text
12990
12991@@ -364,6 +365,7 @@ updateblock:
12992 mov frame_RSPSAVE(%rsp), %rsp
12993
12994 nowork:
12995+ pax_force_retaddr 0, 1
12996 ret
12997 ENDPROC(sha512_transform_avx)
12998
12999diff --git a/arch/x86/crypto/sha512-avx2-asm.S b/arch/x86/crypto/sha512-avx2-asm.S
13000index 568b961..061ef1d 100644
13001--- a/arch/x86/crypto/sha512-avx2-asm.S
13002+++ b/arch/x86/crypto/sha512-avx2-asm.S
13003@@ -51,6 +51,7 @@
13004
13005 #ifdef CONFIG_AS_AVX2
13006 #include <linux/linkage.h>
13007+#include <asm/alternative-asm.h>
13008
13009 .text
13010
13011@@ -678,6 +679,7 @@ done_hash:
13012
13013 # Restore Stack Pointer
13014 mov frame_RSPSAVE(%rsp), %rsp
13015+ pax_force_retaddr 0, 1
13016 ret
13017 ENDPROC(sha512_transform_rorx)
13018
13019diff --git a/arch/x86/crypto/sha512-ssse3-asm.S b/arch/x86/crypto/sha512-ssse3-asm.S
13020index fb56855..e23914f 100644
13021--- a/arch/x86/crypto/sha512-ssse3-asm.S
13022+++ b/arch/x86/crypto/sha512-ssse3-asm.S
13023@@ -48,6 +48,7 @@
13024 ########################################################################
13025
13026 #include <linux/linkage.h>
13027+#include <asm/alternative-asm.h>
13028
13029 .text
13030
13031@@ -363,6 +364,7 @@ updateblock:
13032 mov frame_RSPSAVE(%rsp), %rsp
13033
13034 nowork:
13035+ pax_force_retaddr 0, 1
13036 ret
13037 ENDPROC(sha512_transform_ssse3)
13038
13039diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
13040index 0505813..63b1d00 100644
13041--- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
13042+++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
13043@@ -24,6 +24,7 @@
13044 */
13045
13046 #include <linux/linkage.h>
13047+#include <asm/alternative-asm.h>
13048 #include "glue_helper-asm-avx.S"
13049
13050 .file "twofish-avx-x86_64-asm_64.S"
13051@@ -284,6 +285,7 @@ __twofish_enc_blk8:
13052 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
13053 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
13054
13055+ pax_force_retaddr 0, 1
13056 ret;
13057 ENDPROC(__twofish_enc_blk8)
13058
13059@@ -324,6 +326,7 @@ __twofish_dec_blk8:
13060 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
13061 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
13062
13063+ pax_force_retaddr 0, 1
13064 ret;
13065 ENDPROC(__twofish_dec_blk8)
13066
13067@@ -342,6 +345,7 @@ ENTRY(twofish_ecb_enc_8way)
13068
13069 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
13070
13071+ pax_force_retaddr 0, 1
13072 ret;
13073 ENDPROC(twofish_ecb_enc_8way)
13074
13075@@ -360,6 +364,7 @@ ENTRY(twofish_ecb_dec_8way)
13076
13077 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13078
13079+ pax_force_retaddr 0, 1
13080 ret;
13081 ENDPROC(twofish_ecb_dec_8way)
13082
13083@@ -383,6 +388,7 @@ ENTRY(twofish_cbc_dec_8way)
13084
13085 popq %r12;
13086
13087+ pax_force_retaddr 0, 1
13088 ret;
13089 ENDPROC(twofish_cbc_dec_8way)
13090
13091@@ -408,6 +414,7 @@ ENTRY(twofish_ctr_8way)
13092
13093 popq %r12;
13094
13095+ pax_force_retaddr 0, 1
13096 ret;
13097 ENDPROC(twofish_ctr_8way)
13098
13099@@ -430,6 +437,7 @@ ENTRY(twofish_xts_enc_8way)
13100 /* dst <= regs xor IVs(in dst) */
13101 store_xts_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
13102
13103+ pax_force_retaddr 0, 1
13104 ret;
13105 ENDPROC(twofish_xts_enc_8way)
13106
13107@@ -452,5 +460,6 @@ ENTRY(twofish_xts_dec_8way)
13108 /* dst <= regs xor IVs(in dst) */
13109 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13110
13111+ pax_force_retaddr 0, 1
13112 ret;
13113 ENDPROC(twofish_xts_dec_8way)
13114diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
13115index 1c3b7ce..b365c5e 100644
13116--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
13117+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
13118@@ -21,6 +21,7 @@
13119 */
13120
13121 #include <linux/linkage.h>
13122+#include <asm/alternative-asm.h>
13123
13124 .file "twofish-x86_64-asm-3way.S"
13125 .text
13126@@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
13127 popq %r13;
13128 popq %r14;
13129 popq %r15;
13130+ pax_force_retaddr 0, 1
13131 ret;
13132
13133 .L__enc_xor3:
13134@@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
13135 popq %r13;
13136 popq %r14;
13137 popq %r15;
13138+ pax_force_retaddr 0, 1
13139 ret;
13140 ENDPROC(__twofish_enc_blk_3way)
13141
13142@@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
13143 popq %r13;
13144 popq %r14;
13145 popq %r15;
13146+ pax_force_retaddr 0, 1
13147 ret;
13148 ENDPROC(twofish_dec_blk_3way)
13149diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
13150index a039d21..29e7615 100644
13151--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
13152+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
13153@@ -22,6 +22,7 @@
13154
13155 #include <linux/linkage.h>
13156 #include <asm/asm-offsets.h>
13157+#include <asm/alternative-asm.h>
13158
13159 #define a_offset 0
13160 #define b_offset 4
13161@@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
13162
13163 popq R1
13164 movq $1,%rax
13165+ pax_force_retaddr 0, 1
13166 ret
13167 ENDPROC(twofish_enc_blk)
13168
13169@@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
13170
13171 popq R1
13172 movq $1,%rax
13173+ pax_force_retaddr 0, 1
13174 ret
13175 ENDPROC(twofish_dec_blk)
13176diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
13177index bae3aba..c1788c1 100644
13178--- a/arch/x86/ia32/ia32_aout.c
13179+++ b/arch/x86/ia32/ia32_aout.c
13180@@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
13181 unsigned long dump_start, dump_size;
13182 struct user32 dump;
13183
13184+ memset(&dump, 0, sizeof(dump));
13185+
13186 fs = get_fs();
13187 set_fs(KERNEL_DS);
13188 has_dumped = 1;
13189diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
13190index bccfca6..a312009 100644
13191--- a/arch/x86/ia32/ia32_signal.c
13192+++ b/arch/x86/ia32/ia32_signal.c
13193@@ -338,7 +338,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
13194 sp -= frame_size;
13195 /* Align the stack pointer according to the i386 ABI,
13196 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
13197- sp = ((sp + 4) & -16ul) - 4;
13198+ sp = ((sp - 12) & -16ul) - 4;
13199 return (void __user *) sp;
13200 }
13201
13202@@ -396,7 +396,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
13203 * These are actually not used anymore, but left because some
13204 * gdb versions depend on them as a marker.
13205 */
13206- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
13207+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
13208 } put_user_catch(err);
13209
13210 if (err)
13211@@ -438,7 +438,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
13212 0xb8,
13213 __NR_ia32_rt_sigreturn,
13214 0x80cd,
13215- 0,
13216+ 0
13217 };
13218
13219 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
13220@@ -457,20 +457,22 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
13221 else
13222 put_user_ex(0, &frame->uc.uc_flags);
13223 put_user_ex(0, &frame->uc.uc_link);
13224- err |= __compat_save_altstack(&frame->uc.uc_stack, regs->sp);
13225+ __compat_save_altstack_ex(&frame->uc.uc_stack, regs->sp);
13226
13227 if (ksig->ka.sa.sa_flags & SA_RESTORER)
13228 restorer = ksig->ka.sa.sa_restorer;
13229+ else if (current->mm->context.vdso)
13230+ /* Return stub is in 32bit vsyscall page */
13231+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
13232 else
13233- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
13234- rt_sigreturn);
13235+ restorer = &frame->retcode;
13236 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
13237
13238 /*
13239 * Not actually used anymore, but left because some gdb
13240 * versions need it.
13241 */
13242- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
13243+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
13244 } put_user_catch(err);
13245
13246 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
13247diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
13248index 474dc1b..9297c58 100644
13249--- a/arch/x86/ia32/ia32entry.S
13250+++ b/arch/x86/ia32/ia32entry.S
13251@@ -15,8 +15,10 @@
13252 #include <asm/irqflags.h>
13253 #include <asm/asm.h>
13254 #include <asm/smap.h>
13255+#include <asm/pgtable.h>
13256 #include <linux/linkage.h>
13257 #include <linux/err.h>
13258+#include <asm/alternative-asm.h>
13259
13260 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
13261 #include <linux/elf-em.h>
13262@@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
13263 ENDPROC(native_irq_enable_sysexit)
13264 #endif
13265
13266+ .macro pax_enter_kernel_user
13267+ pax_set_fptr_mask
13268+#ifdef CONFIG_PAX_MEMORY_UDEREF
13269+ call pax_enter_kernel_user
13270+#endif
13271+ .endm
13272+
13273+ .macro pax_exit_kernel_user
13274+#ifdef CONFIG_PAX_MEMORY_UDEREF
13275+ call pax_exit_kernel_user
13276+#endif
13277+#ifdef CONFIG_PAX_RANDKSTACK
13278+ pushq %rax
13279+ pushq %r11
13280+ call pax_randomize_kstack
13281+ popq %r11
13282+ popq %rax
13283+#endif
13284+ .endm
13285+
13286+ .macro pax_erase_kstack
13287+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
13288+ call pax_erase_kstack
13289+#endif
13290+ .endm
13291+
13292 /*
13293 * 32bit SYSENTER instruction entry.
13294 *
13295@@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
13296 CFI_REGISTER rsp,rbp
13297 SWAPGS_UNSAFE_STACK
13298 movq PER_CPU_VAR(kernel_stack), %rsp
13299- addq $(KERNEL_STACK_OFFSET),%rsp
13300- /*
13301- * No need to follow this irqs on/off section: the syscall
13302- * disabled irqs, here we enable it straight after entry:
13303- */
13304- ENABLE_INTERRUPTS(CLBR_NONE)
13305 movl %ebp,%ebp /* zero extension */
13306 pushq_cfi $__USER32_DS
13307 /*CFI_REL_OFFSET ss,0*/
13308@@ -135,24 +157,49 @@ ENTRY(ia32_sysenter_target)
13309 CFI_REL_OFFSET rsp,0
13310 pushfq_cfi
13311 /*CFI_REL_OFFSET rflags,0*/
13312- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
13313- CFI_REGISTER rip,r10
13314+ orl $X86_EFLAGS_IF,(%rsp)
13315+ GET_THREAD_INFO(%r11)
13316+ movl TI_sysenter_return(%r11), %r11d
13317+ CFI_REGISTER rip,r11
13318 pushq_cfi $__USER32_CS
13319 /*CFI_REL_OFFSET cs,0*/
13320 movl %eax, %eax
13321- pushq_cfi %r10
13322+ pushq_cfi %r11
13323 CFI_REL_OFFSET rip,0
13324 pushq_cfi %rax
13325 cld
13326 SAVE_ARGS 0,1,0
13327+ pax_enter_kernel_user
13328+
13329+#ifdef CONFIG_PAX_RANDKSTACK
13330+ pax_erase_kstack
13331+#endif
13332+
13333+ /*
13334+ * No need to follow this irqs on/off section: the syscall
13335+ * disabled irqs, here we enable it straight after entry:
13336+ */
13337+ ENABLE_INTERRUPTS(CLBR_NONE)
13338 /* no need to do an access_ok check here because rbp has been
13339 32bit zero extended */
13340+
13341+#ifdef CONFIG_PAX_MEMORY_UDEREF
13342+ addq pax_user_shadow_base,%rbp
13343+ ASM_PAX_OPEN_USERLAND
13344+#endif
13345+
13346 ASM_STAC
13347 1: movl (%rbp),%ebp
13348 _ASM_EXTABLE(1b,ia32_badarg)
13349 ASM_CLAC
13350- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13351- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13352+
13353+#ifdef CONFIG_PAX_MEMORY_UDEREF
13354+ ASM_PAX_CLOSE_USERLAND
13355+#endif
13356+
13357+ GET_THREAD_INFO(%r11)
13358+ orl $TS_COMPAT,TI_status(%r11)
13359+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
13360 CFI_REMEMBER_STATE
13361 jnz sysenter_tracesys
13362 cmpq $(IA32_NR_syscalls-1),%rax
13363@@ -162,12 +209,15 @@ sysenter_do_call:
13364 sysenter_dispatch:
13365 call *ia32_sys_call_table(,%rax,8)
13366 movq %rax,RAX-ARGOFFSET(%rsp)
13367+ GET_THREAD_INFO(%r11)
13368 DISABLE_INTERRUPTS(CLBR_NONE)
13369 TRACE_IRQS_OFF
13370- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13371+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
13372 jnz sysexit_audit
13373 sysexit_from_sys_call:
13374- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13375+ pax_exit_kernel_user
13376+ pax_erase_kstack
13377+ andl $~TS_COMPAT,TI_status(%r11)
13378 /* clear IF, that popfq doesn't enable interrupts early */
13379 andl $~0x200,EFLAGS-R11(%rsp)
13380 movl RIP-R11(%rsp),%edx /* User %eip */
13381@@ -193,6 +243,9 @@ sysexit_from_sys_call:
13382 movl %eax,%esi /* 2nd arg: syscall number */
13383 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
13384 call __audit_syscall_entry
13385+
13386+ pax_erase_kstack
13387+
13388 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
13389 cmpq $(IA32_NR_syscalls-1),%rax
13390 ja ia32_badsys
13391@@ -204,7 +257,7 @@ sysexit_from_sys_call:
13392 .endm
13393
13394 .macro auditsys_exit exit
13395- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13396+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
13397 jnz ia32_ret_from_sys_call
13398 TRACE_IRQS_ON
13399 ENABLE_INTERRUPTS(CLBR_NONE)
13400@@ -215,11 +268,12 @@ sysexit_from_sys_call:
13401 1: setbe %al /* 1 if error, 0 if not */
13402 movzbl %al,%edi /* zero-extend that into %edi */
13403 call __audit_syscall_exit
13404+ GET_THREAD_INFO(%r11)
13405 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
13406 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
13407 DISABLE_INTERRUPTS(CLBR_NONE)
13408 TRACE_IRQS_OFF
13409- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13410+ testl %edi,TI_flags(%r11)
13411 jz \exit
13412 CLEAR_RREGS -ARGOFFSET
13413 jmp int_with_check
13414@@ -237,7 +291,7 @@ sysexit_audit:
13415
13416 sysenter_tracesys:
13417 #ifdef CONFIG_AUDITSYSCALL
13418- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13419+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
13420 jz sysenter_auditsys
13421 #endif
13422 SAVE_REST
13423@@ -249,6 +303,9 @@ sysenter_tracesys:
13424 RESTORE_REST
13425 cmpq $(IA32_NR_syscalls-1),%rax
13426 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
13427+
13428+ pax_erase_kstack
13429+
13430 jmp sysenter_do_call
13431 CFI_ENDPROC
13432 ENDPROC(ia32_sysenter_target)
13433@@ -276,19 +333,25 @@ ENDPROC(ia32_sysenter_target)
13434 ENTRY(ia32_cstar_target)
13435 CFI_STARTPROC32 simple
13436 CFI_SIGNAL_FRAME
13437- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
13438+ CFI_DEF_CFA rsp,0
13439 CFI_REGISTER rip,rcx
13440 /*CFI_REGISTER rflags,r11*/
13441 SWAPGS_UNSAFE_STACK
13442 movl %esp,%r8d
13443 CFI_REGISTER rsp,r8
13444 movq PER_CPU_VAR(kernel_stack),%rsp
13445+ SAVE_ARGS 8*6,0,0
13446+ pax_enter_kernel_user
13447+
13448+#ifdef CONFIG_PAX_RANDKSTACK
13449+ pax_erase_kstack
13450+#endif
13451+
13452 /*
13453 * No need to follow this irqs on/off section: the syscall
13454 * disabled irqs and here we enable it straight after entry:
13455 */
13456 ENABLE_INTERRUPTS(CLBR_NONE)
13457- SAVE_ARGS 8,0,0
13458 movl %eax,%eax /* zero extension */
13459 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
13460 movq %rcx,RIP-ARGOFFSET(%rsp)
13461@@ -304,12 +367,25 @@ ENTRY(ia32_cstar_target)
13462 /* no need to do an access_ok check here because r8 has been
13463 32bit zero extended */
13464 /* hardware stack frame is complete now */
13465+
13466+#ifdef CONFIG_PAX_MEMORY_UDEREF
13467+ ASM_PAX_OPEN_USERLAND
13468+ movq pax_user_shadow_base,%r8
13469+ addq RSP-ARGOFFSET(%rsp),%r8
13470+#endif
13471+
13472 ASM_STAC
13473 1: movl (%r8),%r9d
13474 _ASM_EXTABLE(1b,ia32_badarg)
13475 ASM_CLAC
13476- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13477- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13478+
13479+#ifdef CONFIG_PAX_MEMORY_UDEREF
13480+ ASM_PAX_CLOSE_USERLAND
13481+#endif
13482+
13483+ GET_THREAD_INFO(%r11)
13484+ orl $TS_COMPAT,TI_status(%r11)
13485+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
13486 CFI_REMEMBER_STATE
13487 jnz cstar_tracesys
13488 cmpq $IA32_NR_syscalls-1,%rax
13489@@ -319,12 +395,15 @@ cstar_do_call:
13490 cstar_dispatch:
13491 call *ia32_sys_call_table(,%rax,8)
13492 movq %rax,RAX-ARGOFFSET(%rsp)
13493+ GET_THREAD_INFO(%r11)
13494 DISABLE_INTERRUPTS(CLBR_NONE)
13495 TRACE_IRQS_OFF
13496- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13497+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
13498 jnz sysretl_audit
13499 sysretl_from_sys_call:
13500- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13501+ pax_exit_kernel_user
13502+ pax_erase_kstack
13503+ andl $~TS_COMPAT,TI_status(%r11)
13504 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
13505 movl RIP-ARGOFFSET(%rsp),%ecx
13506 CFI_REGISTER rip,rcx
13507@@ -352,7 +431,7 @@ sysretl_audit:
13508
13509 cstar_tracesys:
13510 #ifdef CONFIG_AUDITSYSCALL
13511- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13512+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
13513 jz cstar_auditsys
13514 #endif
13515 xchgl %r9d,%ebp
13516@@ -366,11 +445,19 @@ cstar_tracesys:
13517 xchgl %ebp,%r9d
13518 cmpq $(IA32_NR_syscalls-1),%rax
13519 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
13520+
13521+ pax_erase_kstack
13522+
13523 jmp cstar_do_call
13524 END(ia32_cstar_target)
13525
13526 ia32_badarg:
13527 ASM_CLAC
13528+
13529+#ifdef CONFIG_PAX_MEMORY_UDEREF
13530+ ASM_PAX_CLOSE_USERLAND
13531+#endif
13532+
13533 movq $-EFAULT,%rax
13534 jmp ia32_sysret
13535 CFI_ENDPROC
13536@@ -407,19 +494,26 @@ ENTRY(ia32_syscall)
13537 CFI_REL_OFFSET rip,RIP-RIP
13538 PARAVIRT_ADJUST_EXCEPTION_FRAME
13539 SWAPGS
13540- /*
13541- * No need to follow this irqs on/off section: the syscall
13542- * disabled irqs and here we enable it straight after entry:
13543- */
13544- ENABLE_INTERRUPTS(CLBR_NONE)
13545 movl %eax,%eax
13546 pushq_cfi %rax
13547 cld
13548 /* note the registers are not zero extended to the sf.
13549 this could be a problem. */
13550 SAVE_ARGS 0,1,0
13551- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13552- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13553+ pax_enter_kernel_user
13554+
13555+#ifdef CONFIG_PAX_RANDKSTACK
13556+ pax_erase_kstack
13557+#endif
13558+
13559+ /*
13560+ * No need to follow this irqs on/off section: the syscall
13561+ * disabled irqs and here we enable it straight after entry:
13562+ */
13563+ ENABLE_INTERRUPTS(CLBR_NONE)
13564+ GET_THREAD_INFO(%r11)
13565+ orl $TS_COMPAT,TI_status(%r11)
13566+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
13567 jnz ia32_tracesys
13568 cmpq $(IA32_NR_syscalls-1),%rax
13569 ja ia32_badsys
13570@@ -442,6 +536,9 @@ ia32_tracesys:
13571 RESTORE_REST
13572 cmpq $(IA32_NR_syscalls-1),%rax
13573 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
13574+
13575+ pax_erase_kstack
13576+
13577 jmp ia32_do_call
13578 END(ia32_syscall)
13579
13580diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
13581index 8e0ceec..af13504 100644
13582--- a/arch/x86/ia32/sys_ia32.c
13583+++ b/arch/x86/ia32/sys_ia32.c
13584@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
13585 */
13586 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
13587 {
13588- typeof(ubuf->st_uid) uid = 0;
13589- typeof(ubuf->st_gid) gid = 0;
13590+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
13591+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
13592 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
13593 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
13594 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
13595diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
13596index 372231c..a5aa1a1 100644
13597--- a/arch/x86/include/asm/alternative-asm.h
13598+++ b/arch/x86/include/asm/alternative-asm.h
13599@@ -18,6 +18,45 @@
13600 .endm
13601 #endif
13602
13603+#ifdef KERNEXEC_PLUGIN
13604+ .macro pax_force_retaddr_bts rip=0
13605+ btsq $63,\rip(%rsp)
13606+ .endm
13607+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
13608+ .macro pax_force_retaddr rip=0, reload=0
13609+ btsq $63,\rip(%rsp)
13610+ .endm
13611+ .macro pax_force_fptr ptr
13612+ btsq $63,\ptr
13613+ .endm
13614+ .macro pax_set_fptr_mask
13615+ .endm
13616+#endif
13617+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
13618+ .macro pax_force_retaddr rip=0, reload=0
13619+ .if \reload
13620+ pax_set_fptr_mask
13621+ .endif
13622+ orq %r10,\rip(%rsp)
13623+ .endm
13624+ .macro pax_force_fptr ptr
13625+ orq %r10,\ptr
13626+ .endm
13627+ .macro pax_set_fptr_mask
13628+ movabs $0x8000000000000000,%r10
13629+ .endm
13630+#endif
13631+#else
13632+ .macro pax_force_retaddr rip=0, reload=0
13633+ .endm
13634+ .macro pax_force_fptr ptr
13635+ .endm
13636+ .macro pax_force_retaddr_bts rip=0
13637+ .endm
13638+ .macro pax_set_fptr_mask
13639+ .endm
13640+#endif
13641+
13642 .macro altinstruction_entry orig alt feature orig_len alt_len
13643 .long \orig - .
13644 .long \alt - .
13645diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
13646index 58ed6d9..f1cbe58 100644
13647--- a/arch/x86/include/asm/alternative.h
13648+++ b/arch/x86/include/asm/alternative.h
13649@@ -105,7 +105,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
13650 ".pushsection .discard,\"aw\",@progbits\n" \
13651 DISCARD_ENTRY(1) \
13652 ".popsection\n" \
13653- ".pushsection .altinstr_replacement, \"ax\"\n" \
13654+ ".pushsection .altinstr_replacement, \"a\"\n" \
13655 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
13656 ".popsection"
13657
13658@@ -119,7 +119,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
13659 DISCARD_ENTRY(1) \
13660 DISCARD_ENTRY(2) \
13661 ".popsection\n" \
13662- ".pushsection .altinstr_replacement, \"ax\"\n" \
13663+ ".pushsection .altinstr_replacement, \"a\"\n" \
13664 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
13665 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
13666 ".popsection"
13667diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
13668index f8119b5..7209d5b 100644
13669--- a/arch/x86/include/asm/apic.h
13670+++ b/arch/x86/include/asm/apic.h
13671@@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
13672
13673 #ifdef CONFIG_X86_LOCAL_APIC
13674
13675-extern unsigned int apic_verbosity;
13676+extern int apic_verbosity;
13677 extern int local_apic_timer_c2_ok;
13678
13679 extern int disable_apic;
13680diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
13681index 20370c6..a2eb9b0 100644
13682--- a/arch/x86/include/asm/apm.h
13683+++ b/arch/x86/include/asm/apm.h
13684@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_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 %%al\n\t"
13691 "popl %%ebp\n\t"
13692 "popl %%edi\n\t"
13693@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
13694 __asm__ __volatile__(APM_DO_ZERO_SEGS
13695 "pushl %%edi\n\t"
13696 "pushl %%ebp\n\t"
13697- "lcall *%%cs:apm_bios_entry\n\t"
13698+ "lcall *%%ss:apm_bios_entry\n\t"
13699 "setc %%bl\n\t"
13700 "popl %%ebp\n\t"
13701 "popl %%edi\n\t"
13702diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
13703index 722aa3b..3a0bb27 100644
13704--- a/arch/x86/include/asm/atomic.h
13705+++ b/arch/x86/include/asm/atomic.h
13706@@ -22,7 +22,18 @@
13707 */
13708 static inline int atomic_read(const atomic_t *v)
13709 {
13710- return (*(volatile int *)&(v)->counter);
13711+ return (*(volatile const int *)&(v)->counter);
13712+}
13713+
13714+/**
13715+ * atomic_read_unchecked - read atomic variable
13716+ * @v: pointer of type atomic_unchecked_t
13717+ *
13718+ * Atomically reads the value of @v.
13719+ */
13720+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
13721+{
13722+ return (*(volatile const int *)&(v)->counter);
13723 }
13724
13725 /**
13726@@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
13727 }
13728
13729 /**
13730+ * atomic_set_unchecked - set atomic variable
13731+ * @v: pointer of type atomic_unchecked_t
13732+ * @i: required value
13733+ *
13734+ * Atomically sets the value of @v to @i.
13735+ */
13736+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
13737+{
13738+ v->counter = i;
13739+}
13740+
13741+/**
13742 * atomic_add - add integer to atomic variable
13743 * @i: integer value to add
13744 * @v: pointer of type atomic_t
13745@@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
13746 */
13747 static inline void atomic_add(int i, atomic_t *v)
13748 {
13749- asm volatile(LOCK_PREFIX "addl %1,%0"
13750+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
13751+
13752+#ifdef CONFIG_PAX_REFCOUNT
13753+ "jno 0f\n"
13754+ LOCK_PREFIX "subl %1,%0\n"
13755+ "int $4\n0:\n"
13756+ _ASM_EXTABLE(0b, 0b)
13757+#endif
13758+
13759+ : "+m" (v->counter)
13760+ : "ir" (i));
13761+}
13762+
13763+/**
13764+ * atomic_add_unchecked - add integer to atomic variable
13765+ * @i: integer value to add
13766+ * @v: pointer of type atomic_unchecked_t
13767+ *
13768+ * Atomically adds @i to @v.
13769+ */
13770+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
13771+{
13772+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
13773 : "+m" (v->counter)
13774 : "ir" (i));
13775 }
13776@@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
13777 */
13778 static inline void atomic_sub(int i, atomic_t *v)
13779 {
13780- asm volatile(LOCK_PREFIX "subl %1,%0"
13781+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
13782+
13783+#ifdef CONFIG_PAX_REFCOUNT
13784+ "jno 0f\n"
13785+ LOCK_PREFIX "addl %1,%0\n"
13786+ "int $4\n0:\n"
13787+ _ASM_EXTABLE(0b, 0b)
13788+#endif
13789+
13790+ : "+m" (v->counter)
13791+ : "ir" (i));
13792+}
13793+
13794+/**
13795+ * atomic_sub_unchecked - subtract integer from atomic variable
13796+ * @i: integer value to subtract
13797+ * @v: pointer of type atomic_unchecked_t
13798+ *
13799+ * Atomically subtracts @i from @v.
13800+ */
13801+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
13802+{
13803+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
13804 : "+m" (v->counter)
13805 : "ir" (i));
13806 }
13807@@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
13808 {
13809 unsigned char c;
13810
13811- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
13812+ asm volatile(LOCK_PREFIX "subl %2,%0\n"
13813+
13814+#ifdef CONFIG_PAX_REFCOUNT
13815+ "jno 0f\n"
13816+ LOCK_PREFIX "addl %2,%0\n"
13817+ "int $4\n0:\n"
13818+ _ASM_EXTABLE(0b, 0b)
13819+#endif
13820+
13821+ "sete %1\n"
13822 : "+m" (v->counter), "=qm" (c)
13823 : "ir" (i) : "memory");
13824 return c;
13825@@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
13826 */
13827 static inline void atomic_inc(atomic_t *v)
13828 {
13829- asm volatile(LOCK_PREFIX "incl %0"
13830+ asm volatile(LOCK_PREFIX "incl %0\n"
13831+
13832+#ifdef CONFIG_PAX_REFCOUNT
13833+ "jno 0f\n"
13834+ LOCK_PREFIX "decl %0\n"
13835+ "int $4\n0:\n"
13836+ _ASM_EXTABLE(0b, 0b)
13837+#endif
13838+
13839+ : "+m" (v->counter));
13840+}
13841+
13842+/**
13843+ * atomic_inc_unchecked - increment atomic variable
13844+ * @v: pointer of type atomic_unchecked_t
13845+ *
13846+ * Atomically increments @v by 1.
13847+ */
13848+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
13849+{
13850+ asm volatile(LOCK_PREFIX "incl %0\n"
13851 : "+m" (v->counter));
13852 }
13853
13854@@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
13855 */
13856 static inline void atomic_dec(atomic_t *v)
13857 {
13858- asm volatile(LOCK_PREFIX "decl %0"
13859+ asm volatile(LOCK_PREFIX "decl %0\n"
13860+
13861+#ifdef CONFIG_PAX_REFCOUNT
13862+ "jno 0f\n"
13863+ LOCK_PREFIX "incl %0\n"
13864+ "int $4\n0:\n"
13865+ _ASM_EXTABLE(0b, 0b)
13866+#endif
13867+
13868+ : "+m" (v->counter));
13869+}
13870+
13871+/**
13872+ * atomic_dec_unchecked - decrement atomic variable
13873+ * @v: pointer of type atomic_unchecked_t
13874+ *
13875+ * Atomically decrements @v by 1.
13876+ */
13877+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
13878+{
13879+ asm volatile(LOCK_PREFIX "decl %0\n"
13880 : "+m" (v->counter));
13881 }
13882
13883@@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
13884 {
13885 unsigned char c;
13886
13887- asm volatile(LOCK_PREFIX "decl %0; sete %1"
13888+ asm volatile(LOCK_PREFIX "decl %0\n"
13889+
13890+#ifdef CONFIG_PAX_REFCOUNT
13891+ "jno 0f\n"
13892+ LOCK_PREFIX "incl %0\n"
13893+ "int $4\n0:\n"
13894+ _ASM_EXTABLE(0b, 0b)
13895+#endif
13896+
13897+ "sete %1\n"
13898 : "+m" (v->counter), "=qm" (c)
13899 : : "memory");
13900 return c != 0;
13901@@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
13902 {
13903 unsigned char c;
13904
13905- asm volatile(LOCK_PREFIX "incl %0; sete %1"
13906+ asm volatile(LOCK_PREFIX "incl %0\n"
13907+
13908+#ifdef CONFIG_PAX_REFCOUNT
13909+ "jno 0f\n"
13910+ LOCK_PREFIX "decl %0\n"
13911+ "int $4\n0:\n"
13912+ _ASM_EXTABLE(0b, 0b)
13913+#endif
13914+
13915+ "sete %1\n"
13916+ : "+m" (v->counter), "=qm" (c)
13917+ : : "memory");
13918+ return c != 0;
13919+}
13920+
13921+/**
13922+ * atomic_inc_and_test_unchecked - increment and test
13923+ * @v: pointer of type atomic_unchecked_t
13924+ *
13925+ * Atomically increments @v by 1
13926+ * and returns true if the result is zero, or false for all
13927+ * other cases.
13928+ */
13929+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
13930+{
13931+ unsigned char c;
13932+
13933+ asm volatile(LOCK_PREFIX "incl %0\n"
13934+ "sete %1\n"
13935 : "+m" (v->counter), "=qm" (c)
13936 : : "memory");
13937 return c != 0;
13938@@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
13939 {
13940 unsigned char c;
13941
13942- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
13943+ asm volatile(LOCK_PREFIX "addl %2,%0\n"
13944+
13945+#ifdef CONFIG_PAX_REFCOUNT
13946+ "jno 0f\n"
13947+ LOCK_PREFIX "subl %2,%0\n"
13948+ "int $4\n0:\n"
13949+ _ASM_EXTABLE(0b, 0b)
13950+#endif
13951+
13952+ "sets %1\n"
13953 : "+m" (v->counter), "=qm" (c)
13954 : "ir" (i) : "memory");
13955 return c;
13956@@ -172,6 +334,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
13957 */
13958 static inline int atomic_add_return(int i, atomic_t *v)
13959 {
13960+ return i + xadd_check_overflow(&v->counter, i);
13961+}
13962+
13963+/**
13964+ * atomic_add_return_unchecked - add integer and return
13965+ * @i: integer value to add
13966+ * @v: pointer of type atomic_unchecked_t
13967+ *
13968+ * Atomically adds @i to @v and returns @i + @v
13969+ */
13970+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
13971+{
13972 return i + xadd(&v->counter, i);
13973 }
13974
13975@@ -188,6 +362,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
13976 }
13977
13978 #define atomic_inc_return(v) (atomic_add_return(1, v))
13979+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
13980+{
13981+ return atomic_add_return_unchecked(1, v);
13982+}
13983 #define atomic_dec_return(v) (atomic_sub_return(1, v))
13984
13985 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
13986@@ -195,11 +373,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
13987 return cmpxchg(&v->counter, old, new);
13988 }
13989
13990+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
13991+{
13992+ return cmpxchg(&v->counter, old, new);
13993+}
13994+
13995 static inline int atomic_xchg(atomic_t *v, int new)
13996 {
13997 return xchg(&v->counter, new);
13998 }
13999
14000+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
14001+{
14002+ return xchg(&v->counter, new);
14003+}
14004+
14005 /**
14006 * __atomic_add_unless - add unless the number is already a given value
14007 * @v: pointer of type atomic_t
14008@@ -211,12 +399,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
14009 */
14010 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
14011 {
14012- int c, old;
14013+ int c, old, new;
14014 c = atomic_read(v);
14015 for (;;) {
14016- if (unlikely(c == (u)))
14017+ if (unlikely(c == u))
14018 break;
14019- old = atomic_cmpxchg((v), c, c + (a));
14020+
14021+ asm volatile("addl %2,%0\n"
14022+
14023+#ifdef CONFIG_PAX_REFCOUNT
14024+ "jno 0f\n"
14025+ "subl %2,%0\n"
14026+ "int $4\n0:\n"
14027+ _ASM_EXTABLE(0b, 0b)
14028+#endif
14029+
14030+ : "=r" (new)
14031+ : "0" (c), "ir" (a));
14032+
14033+ old = atomic_cmpxchg(v, c, new);
14034 if (likely(old == c))
14035 break;
14036 c = old;
14037@@ -225,6 +426,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
14038 }
14039
14040 /**
14041+ * atomic_inc_not_zero_hint - increment if not null
14042+ * @v: pointer of type atomic_t
14043+ * @hint: probable value of the atomic before the increment
14044+ *
14045+ * This version of atomic_inc_not_zero() gives a hint of probable
14046+ * value of the atomic. This helps processor to not read the memory
14047+ * before doing the atomic read/modify/write cycle, lowering
14048+ * number of bus transactions on some arches.
14049+ *
14050+ * Returns: 0 if increment was not done, 1 otherwise.
14051+ */
14052+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
14053+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
14054+{
14055+ int val, c = hint, new;
14056+
14057+ /* sanity test, should be removed by compiler if hint is a constant */
14058+ if (!hint)
14059+ return __atomic_add_unless(v, 1, 0);
14060+
14061+ do {
14062+ asm volatile("incl %0\n"
14063+
14064+#ifdef CONFIG_PAX_REFCOUNT
14065+ "jno 0f\n"
14066+ "decl %0\n"
14067+ "int $4\n0:\n"
14068+ _ASM_EXTABLE(0b, 0b)
14069+#endif
14070+
14071+ : "=r" (new)
14072+ : "0" (c));
14073+
14074+ val = atomic_cmpxchg(v, c, new);
14075+ if (val == c)
14076+ return 1;
14077+ c = val;
14078+ } while (c);
14079+
14080+ return 0;
14081+}
14082+
14083+/**
14084 * atomic_inc_short - increment of a short integer
14085 * @v: pointer to type int
14086 *
14087@@ -253,14 +497,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
14088 #endif
14089
14090 /* These are x86-specific, used by some header files */
14091-#define atomic_clear_mask(mask, addr) \
14092- asm volatile(LOCK_PREFIX "andl %0,%1" \
14093- : : "r" (~(mask)), "m" (*(addr)) : "memory")
14094+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
14095+{
14096+ asm volatile(LOCK_PREFIX "andl %1,%0"
14097+ : "+m" (v->counter)
14098+ : "r" (~(mask))
14099+ : "memory");
14100+}
14101
14102-#define atomic_set_mask(mask, addr) \
14103- asm volatile(LOCK_PREFIX "orl %0,%1" \
14104- : : "r" ((unsigned)(mask)), "m" (*(addr)) \
14105- : "memory")
14106+static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
14107+{
14108+ asm volatile(LOCK_PREFIX "andl %1,%0"
14109+ : "+m" (v->counter)
14110+ : "r" (~(mask))
14111+ : "memory");
14112+}
14113+
14114+static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
14115+{
14116+ asm volatile(LOCK_PREFIX "orl %1,%0"
14117+ : "+m" (v->counter)
14118+ : "r" (mask)
14119+ : "memory");
14120+}
14121+
14122+static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
14123+{
14124+ asm volatile(LOCK_PREFIX "orl %1,%0"
14125+ : "+m" (v->counter)
14126+ : "r" (mask)
14127+ : "memory");
14128+}
14129
14130 /* Atomic operations are already serializing on x86 */
14131 #define smp_mb__before_atomic_dec() barrier()
14132diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
14133index b154de7..aadebd8 100644
14134--- a/arch/x86/include/asm/atomic64_32.h
14135+++ b/arch/x86/include/asm/atomic64_32.h
14136@@ -12,6 +12,14 @@ typedef struct {
14137 u64 __aligned(8) counter;
14138 } atomic64_t;
14139
14140+#ifdef CONFIG_PAX_REFCOUNT
14141+typedef struct {
14142+ u64 __aligned(8) counter;
14143+} atomic64_unchecked_t;
14144+#else
14145+typedef atomic64_t atomic64_unchecked_t;
14146+#endif
14147+
14148 #define ATOMIC64_INIT(val) { (val) }
14149
14150 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
14151@@ -37,21 +45,31 @@ typedef struct {
14152 ATOMIC64_DECL_ONE(sym##_386)
14153
14154 ATOMIC64_DECL_ONE(add_386);
14155+ATOMIC64_DECL_ONE(add_unchecked_386);
14156 ATOMIC64_DECL_ONE(sub_386);
14157+ATOMIC64_DECL_ONE(sub_unchecked_386);
14158 ATOMIC64_DECL_ONE(inc_386);
14159+ATOMIC64_DECL_ONE(inc_unchecked_386);
14160 ATOMIC64_DECL_ONE(dec_386);
14161+ATOMIC64_DECL_ONE(dec_unchecked_386);
14162 #endif
14163
14164 #define alternative_atomic64(f, out, in...) \
14165 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
14166
14167 ATOMIC64_DECL(read);
14168+ATOMIC64_DECL(read_unchecked);
14169 ATOMIC64_DECL(set);
14170+ATOMIC64_DECL(set_unchecked);
14171 ATOMIC64_DECL(xchg);
14172 ATOMIC64_DECL(add_return);
14173+ATOMIC64_DECL(add_return_unchecked);
14174 ATOMIC64_DECL(sub_return);
14175+ATOMIC64_DECL(sub_return_unchecked);
14176 ATOMIC64_DECL(inc_return);
14177+ATOMIC64_DECL(inc_return_unchecked);
14178 ATOMIC64_DECL(dec_return);
14179+ATOMIC64_DECL(dec_return_unchecked);
14180 ATOMIC64_DECL(dec_if_positive);
14181 ATOMIC64_DECL(inc_not_zero);
14182 ATOMIC64_DECL(add_unless);
14183@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
14184 }
14185
14186 /**
14187+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
14188+ * @p: pointer to type atomic64_unchecked_t
14189+ * @o: expected value
14190+ * @n: new value
14191+ *
14192+ * Atomically sets @v to @n if it was equal to @o and returns
14193+ * the old value.
14194+ */
14195+
14196+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
14197+{
14198+ return cmpxchg64(&v->counter, o, n);
14199+}
14200+
14201+/**
14202 * atomic64_xchg - xchg atomic64 variable
14203 * @v: pointer to type atomic64_t
14204 * @n: value to assign
14205@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
14206 }
14207
14208 /**
14209+ * atomic64_set_unchecked - set atomic64 variable
14210+ * @v: pointer to type atomic64_unchecked_t
14211+ * @n: value to assign
14212+ *
14213+ * Atomically sets the value of @v to @n.
14214+ */
14215+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
14216+{
14217+ unsigned high = (unsigned)(i >> 32);
14218+ unsigned low = (unsigned)i;
14219+ alternative_atomic64(set, /* no output */,
14220+ "S" (v), "b" (low), "c" (high)
14221+ : "eax", "edx", "memory");
14222+}
14223+
14224+/**
14225 * atomic64_read - read atomic64 variable
14226 * @v: pointer to type atomic64_t
14227 *
14228@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
14229 }
14230
14231 /**
14232+ * atomic64_read_unchecked - read atomic64 variable
14233+ * @v: pointer to type atomic64_unchecked_t
14234+ *
14235+ * Atomically reads the value of @v and returns it.
14236+ */
14237+static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
14238+{
14239+ long long r;
14240+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
14241+ return r;
14242+ }
14243+
14244+/**
14245 * atomic64_add_return - add and return
14246 * @i: integer value to add
14247 * @v: pointer to type atomic64_t
14248@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
14249 return i;
14250 }
14251
14252+/**
14253+ * atomic64_add_return_unchecked - add and return
14254+ * @i: integer value to add
14255+ * @v: pointer to type atomic64_unchecked_t
14256+ *
14257+ * Atomically adds @i to @v and returns @i + *@v
14258+ */
14259+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
14260+{
14261+ alternative_atomic64(add_return_unchecked,
14262+ ASM_OUTPUT2("+A" (i), "+c" (v)),
14263+ ASM_NO_INPUT_CLOBBER("memory"));
14264+ return i;
14265+}
14266+
14267 /*
14268 * Other variants with different arithmetic operators:
14269 */
14270@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
14271 return a;
14272 }
14273
14274+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
14275+{
14276+ long long a;
14277+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
14278+ "S" (v) : "memory", "ecx");
14279+ return a;
14280+}
14281+
14282 static inline long long atomic64_dec_return(atomic64_t *v)
14283 {
14284 long long a;
14285@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
14286 }
14287
14288 /**
14289+ * atomic64_add_unchecked - add integer to atomic64 variable
14290+ * @i: integer value to add
14291+ * @v: pointer to type atomic64_unchecked_t
14292+ *
14293+ * Atomically adds @i to @v.
14294+ */
14295+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
14296+{
14297+ __alternative_atomic64(add_unchecked, add_return_unchecked,
14298+ ASM_OUTPUT2("+A" (i), "+c" (v)),
14299+ ASM_NO_INPUT_CLOBBER("memory"));
14300+ return i;
14301+}
14302+
14303+/**
14304 * atomic64_sub - subtract the atomic64 variable
14305 * @i: integer value to subtract
14306 * @v: pointer to type atomic64_t
14307diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
14308index 0e1cbfc..5623683 100644
14309--- a/arch/x86/include/asm/atomic64_64.h
14310+++ b/arch/x86/include/asm/atomic64_64.h
14311@@ -18,7 +18,19 @@
14312 */
14313 static inline long atomic64_read(const atomic64_t *v)
14314 {
14315- return (*(volatile long *)&(v)->counter);
14316+ return (*(volatile const long *)&(v)->counter);
14317+}
14318+
14319+/**
14320+ * atomic64_read_unchecked - read atomic64 variable
14321+ * @v: pointer of type atomic64_unchecked_t
14322+ *
14323+ * Atomically reads the value of @v.
14324+ * Doesn't imply a read memory barrier.
14325+ */
14326+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
14327+{
14328+ return (*(volatile const long *)&(v)->counter);
14329 }
14330
14331 /**
14332@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
14333 }
14334
14335 /**
14336+ * atomic64_set_unchecked - set atomic64 variable
14337+ * @v: pointer to type atomic64_unchecked_t
14338+ * @i: required value
14339+ *
14340+ * Atomically sets the value of @v to @i.
14341+ */
14342+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
14343+{
14344+ v->counter = i;
14345+}
14346+
14347+/**
14348 * atomic64_add - add integer to atomic64 variable
14349 * @i: integer value to add
14350 * @v: pointer to type atomic64_t
14351@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
14352 */
14353 static inline void atomic64_add(long i, atomic64_t *v)
14354 {
14355+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
14356+
14357+#ifdef CONFIG_PAX_REFCOUNT
14358+ "jno 0f\n"
14359+ LOCK_PREFIX "subq %1,%0\n"
14360+ "int $4\n0:\n"
14361+ _ASM_EXTABLE(0b, 0b)
14362+#endif
14363+
14364+ : "=m" (v->counter)
14365+ : "er" (i), "m" (v->counter));
14366+}
14367+
14368+/**
14369+ * atomic64_add_unchecked - add integer to atomic64 variable
14370+ * @i: integer value to add
14371+ * @v: pointer to type atomic64_unchecked_t
14372+ *
14373+ * Atomically adds @i to @v.
14374+ */
14375+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
14376+{
14377 asm volatile(LOCK_PREFIX "addq %1,%0"
14378 : "=m" (v->counter)
14379 : "er" (i), "m" (v->counter));
14380@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
14381 */
14382 static inline void atomic64_sub(long i, atomic64_t *v)
14383 {
14384- asm volatile(LOCK_PREFIX "subq %1,%0"
14385+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
14386+
14387+#ifdef CONFIG_PAX_REFCOUNT
14388+ "jno 0f\n"
14389+ LOCK_PREFIX "addq %1,%0\n"
14390+ "int $4\n0:\n"
14391+ _ASM_EXTABLE(0b, 0b)
14392+#endif
14393+
14394+ : "=m" (v->counter)
14395+ : "er" (i), "m" (v->counter));
14396+}
14397+
14398+/**
14399+ * atomic64_sub_unchecked - subtract the atomic64 variable
14400+ * @i: integer value to subtract
14401+ * @v: pointer to type atomic64_unchecked_t
14402+ *
14403+ * Atomically subtracts @i from @v.
14404+ */
14405+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
14406+{
14407+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
14408 : "=m" (v->counter)
14409 : "er" (i), "m" (v->counter));
14410 }
14411@@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
14412 {
14413 unsigned char c;
14414
14415- asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
14416+ asm volatile(LOCK_PREFIX "subq %2,%0\n"
14417+
14418+#ifdef CONFIG_PAX_REFCOUNT
14419+ "jno 0f\n"
14420+ LOCK_PREFIX "addq %2,%0\n"
14421+ "int $4\n0:\n"
14422+ _ASM_EXTABLE(0b, 0b)
14423+#endif
14424+
14425+ "sete %1\n"
14426 : "=m" (v->counter), "=qm" (c)
14427 : "er" (i), "m" (v->counter) : "memory");
14428 return c;
14429@@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
14430 */
14431 static inline void atomic64_inc(atomic64_t *v)
14432 {
14433+ asm volatile(LOCK_PREFIX "incq %0\n"
14434+
14435+#ifdef CONFIG_PAX_REFCOUNT
14436+ "jno 0f\n"
14437+ LOCK_PREFIX "decq %0\n"
14438+ "int $4\n0:\n"
14439+ _ASM_EXTABLE(0b, 0b)
14440+#endif
14441+
14442+ : "=m" (v->counter)
14443+ : "m" (v->counter));
14444+}
14445+
14446+/**
14447+ * atomic64_inc_unchecked - increment atomic64 variable
14448+ * @v: pointer to type atomic64_unchecked_t
14449+ *
14450+ * Atomically increments @v by 1.
14451+ */
14452+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
14453+{
14454 asm volatile(LOCK_PREFIX "incq %0"
14455 : "=m" (v->counter)
14456 : "m" (v->counter));
14457@@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
14458 */
14459 static inline void atomic64_dec(atomic64_t *v)
14460 {
14461- asm volatile(LOCK_PREFIX "decq %0"
14462+ asm volatile(LOCK_PREFIX "decq %0\n"
14463+
14464+#ifdef CONFIG_PAX_REFCOUNT
14465+ "jno 0f\n"
14466+ LOCK_PREFIX "incq %0\n"
14467+ "int $4\n0:\n"
14468+ _ASM_EXTABLE(0b, 0b)
14469+#endif
14470+
14471+ : "=m" (v->counter)
14472+ : "m" (v->counter));
14473+}
14474+
14475+/**
14476+ * atomic64_dec_unchecked - decrement atomic64 variable
14477+ * @v: pointer to type atomic64_t
14478+ *
14479+ * Atomically decrements @v by 1.
14480+ */
14481+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
14482+{
14483+ asm volatile(LOCK_PREFIX "decq %0\n"
14484 : "=m" (v->counter)
14485 : "m" (v->counter));
14486 }
14487@@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
14488 {
14489 unsigned char c;
14490
14491- asm volatile(LOCK_PREFIX "decq %0; sete %1"
14492+ asm volatile(LOCK_PREFIX "decq %0\n"
14493+
14494+#ifdef CONFIG_PAX_REFCOUNT
14495+ "jno 0f\n"
14496+ LOCK_PREFIX "incq %0\n"
14497+ "int $4\n0:\n"
14498+ _ASM_EXTABLE(0b, 0b)
14499+#endif
14500+
14501+ "sete %1\n"
14502 : "=m" (v->counter), "=qm" (c)
14503 : "m" (v->counter) : "memory");
14504 return c != 0;
14505@@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
14506 {
14507 unsigned char c;
14508
14509- asm volatile(LOCK_PREFIX "incq %0; sete %1"
14510+ asm volatile(LOCK_PREFIX "incq %0\n"
14511+
14512+#ifdef CONFIG_PAX_REFCOUNT
14513+ "jno 0f\n"
14514+ LOCK_PREFIX "decq %0\n"
14515+ "int $4\n0:\n"
14516+ _ASM_EXTABLE(0b, 0b)
14517+#endif
14518+
14519+ "sete %1\n"
14520 : "=m" (v->counter), "=qm" (c)
14521 : "m" (v->counter) : "memory");
14522 return c != 0;
14523@@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
14524 {
14525 unsigned char c;
14526
14527- asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
14528+ asm volatile(LOCK_PREFIX "addq %2,%0\n"
14529+
14530+#ifdef CONFIG_PAX_REFCOUNT
14531+ "jno 0f\n"
14532+ LOCK_PREFIX "subq %2,%0\n"
14533+ "int $4\n0:\n"
14534+ _ASM_EXTABLE(0b, 0b)
14535+#endif
14536+
14537+ "sets %1\n"
14538 : "=m" (v->counter), "=qm" (c)
14539 : "er" (i), "m" (v->counter) : "memory");
14540 return c;
14541@@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
14542 */
14543 static inline long atomic64_add_return(long i, atomic64_t *v)
14544 {
14545+ return i + xadd_check_overflow(&v->counter, i);
14546+}
14547+
14548+/**
14549+ * atomic64_add_return_unchecked - add and return
14550+ * @i: integer value to add
14551+ * @v: pointer to type atomic64_unchecked_t
14552+ *
14553+ * Atomically adds @i to @v and returns @i + @v
14554+ */
14555+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
14556+{
14557 return i + xadd(&v->counter, i);
14558 }
14559
14560@@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
14561 }
14562
14563 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
14564+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
14565+{
14566+ return atomic64_add_return_unchecked(1, v);
14567+}
14568 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
14569
14570 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
14571@@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
14572 return cmpxchg(&v->counter, old, new);
14573 }
14574
14575+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
14576+{
14577+ return cmpxchg(&v->counter, old, new);
14578+}
14579+
14580 static inline long atomic64_xchg(atomic64_t *v, long new)
14581 {
14582 return xchg(&v->counter, new);
14583@@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
14584 */
14585 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
14586 {
14587- long c, old;
14588+ long c, old, new;
14589 c = atomic64_read(v);
14590 for (;;) {
14591- if (unlikely(c == (u)))
14592+ if (unlikely(c == u))
14593 break;
14594- old = atomic64_cmpxchg((v), c, c + (a));
14595+
14596+ asm volatile("add %2,%0\n"
14597+
14598+#ifdef CONFIG_PAX_REFCOUNT
14599+ "jno 0f\n"
14600+ "sub %2,%0\n"
14601+ "int $4\n0:\n"
14602+ _ASM_EXTABLE(0b, 0b)
14603+#endif
14604+
14605+ : "=r" (new)
14606+ : "0" (c), "ir" (a));
14607+
14608+ old = atomic64_cmpxchg(v, c, new);
14609 if (likely(old == c))
14610 break;
14611 c = old;
14612 }
14613- return c != (u);
14614+ return c != u;
14615 }
14616
14617 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
14618diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
14619index 6dfd019..28e188d 100644
14620--- a/arch/x86/include/asm/bitops.h
14621+++ b/arch/x86/include/asm/bitops.h
14622@@ -40,7 +40,7 @@
14623 * a mask operation on a byte.
14624 */
14625 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
14626-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
14627+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
14628 #define CONST_MASK(nr) (1 << ((nr) & 7))
14629
14630 /**
14631@@ -486,7 +486,7 @@ static inline int fls(int x)
14632 * at position 64.
14633 */
14634 #ifdef CONFIG_X86_64
14635-static __always_inline int fls64(__u64 x)
14636+static __always_inline long fls64(__u64 x)
14637 {
14638 int bitpos = -1;
14639 /*
14640diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
14641index 4fa687a..60f2d39 100644
14642--- a/arch/x86/include/asm/boot.h
14643+++ b/arch/x86/include/asm/boot.h
14644@@ -6,10 +6,15 @@
14645 #include <uapi/asm/boot.h>
14646
14647 /* Physical address where kernel should be loaded. */
14648-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
14649+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
14650 + (CONFIG_PHYSICAL_ALIGN - 1)) \
14651 & ~(CONFIG_PHYSICAL_ALIGN - 1))
14652
14653+#ifndef __ASSEMBLY__
14654+extern unsigned char __LOAD_PHYSICAL_ADDR[];
14655+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
14656+#endif
14657+
14658 /* Minimum kernel alignment, as a power of two */
14659 #ifdef CONFIG_X86_64
14660 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
14661diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
14662index 48f99f1..d4765f9 100644
14663--- a/arch/x86/include/asm/cache.h
14664+++ b/arch/x86/include/asm/cache.h
14665@@ -5,12 +5,17 @@
14666
14667 /* L1 cache line size */
14668 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
14669-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
14670+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
14671
14672 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
14673+#ifdef MODULE
14674+#define __read_only __attribute__((__section__(".rodata")))
14675+#else
14676+#define __read_only __attribute__((__section__(".data..read_only")))
14677+#endif
14678
14679 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
14680-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
14681+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
14682
14683 #ifdef CONFIG_X86_VSMP
14684 #ifdef CONFIG_SMP
14685diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
14686index 9863ee3..4a1f8e1 100644
14687--- a/arch/x86/include/asm/cacheflush.h
14688+++ b/arch/x86/include/asm/cacheflush.h
14689@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
14690 unsigned long pg_flags = pg->flags & _PGMT_MASK;
14691
14692 if (pg_flags == _PGMT_DEFAULT)
14693- return -1;
14694+ return ~0UL;
14695 else if (pg_flags == _PGMT_WC)
14696 return _PAGE_CACHE_WC;
14697 else if (pg_flags == _PGMT_UC_MINUS)
14698diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
14699index 46fc474..b02b0f9 100644
14700--- a/arch/x86/include/asm/checksum_32.h
14701+++ b/arch/x86/include/asm/checksum_32.h
14702@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
14703 int len, __wsum sum,
14704 int *src_err_ptr, int *dst_err_ptr);
14705
14706+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
14707+ int len, __wsum sum,
14708+ int *src_err_ptr, int *dst_err_ptr);
14709+
14710+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
14711+ int len, __wsum sum,
14712+ int *src_err_ptr, int *dst_err_ptr);
14713+
14714 /*
14715 * Note: when you get a NULL pointer exception here this means someone
14716 * passed in an incorrect kernel address to one of these functions.
14717@@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
14718 int *err_ptr)
14719 {
14720 might_sleep();
14721- return csum_partial_copy_generic((__force void *)src, dst,
14722+ return csum_partial_copy_generic_from_user((__force void *)src, dst,
14723 len, sum, err_ptr, NULL);
14724 }
14725
14726@@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
14727 {
14728 might_sleep();
14729 if (access_ok(VERIFY_WRITE, dst, len))
14730- return csum_partial_copy_generic(src, (__force void *)dst,
14731+ return csum_partial_copy_generic_to_user(src, (__force void *)dst,
14732 len, sum, NULL, err_ptr);
14733
14734 if (len)
14735diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
14736index d47786a..ce1b05d 100644
14737--- a/arch/x86/include/asm/cmpxchg.h
14738+++ b/arch/x86/include/asm/cmpxchg.h
14739@@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
14740 __compiletime_error("Bad argument size for cmpxchg");
14741 extern void __xadd_wrong_size(void)
14742 __compiletime_error("Bad argument size for xadd");
14743+extern void __xadd_check_overflow_wrong_size(void)
14744+ __compiletime_error("Bad argument size for xadd_check_overflow");
14745 extern void __add_wrong_size(void)
14746 __compiletime_error("Bad argument size for add");
14747+extern void __add_check_overflow_wrong_size(void)
14748+ __compiletime_error("Bad argument size for add_check_overflow");
14749
14750 /*
14751 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
14752@@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
14753 __ret; \
14754 })
14755
14756+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
14757+ ({ \
14758+ __typeof__ (*(ptr)) __ret = (arg); \
14759+ switch (sizeof(*(ptr))) { \
14760+ case __X86_CASE_L: \
14761+ asm volatile (lock #op "l %0, %1\n" \
14762+ "jno 0f\n" \
14763+ "mov %0,%1\n" \
14764+ "int $4\n0:\n" \
14765+ _ASM_EXTABLE(0b, 0b) \
14766+ : "+r" (__ret), "+m" (*(ptr)) \
14767+ : : "memory", "cc"); \
14768+ break; \
14769+ case __X86_CASE_Q: \
14770+ asm volatile (lock #op "q %q0, %1\n" \
14771+ "jno 0f\n" \
14772+ "mov %0,%1\n" \
14773+ "int $4\n0:\n" \
14774+ _ASM_EXTABLE(0b, 0b) \
14775+ : "+r" (__ret), "+m" (*(ptr)) \
14776+ : : "memory", "cc"); \
14777+ break; \
14778+ default: \
14779+ __ ## op ## _check_overflow_wrong_size(); \
14780+ } \
14781+ __ret; \
14782+ })
14783+
14784 /*
14785 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
14786 * Since this is generally used to protect other memory information, we
14787@@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
14788 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
14789 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
14790
14791+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
14792+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
14793+
14794 #define __add(ptr, inc, lock) \
14795 ({ \
14796 __typeof__ (*(ptr)) __ret = (inc); \
14797diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
14798index 59c6c40..5e0b22c 100644
14799--- a/arch/x86/include/asm/compat.h
14800+++ b/arch/x86/include/asm/compat.h
14801@@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
14802 typedef u32 compat_uint_t;
14803 typedef u32 compat_ulong_t;
14804 typedef u64 __attribute__((aligned(4))) compat_u64;
14805-typedef u32 compat_uptr_t;
14806+typedef u32 __user compat_uptr_t;
14807
14808 struct compat_timespec {
14809 compat_time_t tv_sec;
14810diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
14811index 47538a6..44902d1 100644
14812--- a/arch/x86/include/asm/cpufeature.h
14813+++ b/arch/x86/include/asm/cpufeature.h
14814@@ -203,7 +203,7 @@
14815 #define X86_FEATURE_DECODEASSISTS (8*32+12) /* AMD Decode Assists support */
14816 #define X86_FEATURE_PAUSEFILTER (8*32+13) /* AMD filtered pause intercept */
14817 #define X86_FEATURE_PFTHRESHOLD (8*32+14) /* AMD pause filter threshold */
14818-
14819+#define X86_FEATURE_STRONGUDEREF (8*32+31) /* PaX PCID based strong UDEREF */
14820
14821 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */
14822 #define X86_FEATURE_FSGSBASE (9*32+ 0) /* {RD/WR}{FS/GS}BASE instructions*/
14823@@ -211,7 +211,7 @@
14824 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
14825 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
14826 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
14827-#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
14828+#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
14829 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
14830 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
14831 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
14832@@ -353,6 +353,7 @@ extern const char * const x86_power_flags[32];
14833 #undef cpu_has_centaur_mcr
14834 #define cpu_has_centaur_mcr 0
14835
14836+#define cpu_has_pcid boot_cpu_has(X86_FEATURE_PCID)
14837 #endif /* CONFIG_X86_64 */
14838
14839 #if __GNUC__ >= 4
14840@@ -403,7 +404,8 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
14841
14842 #ifdef CONFIG_X86_DEBUG_STATIC_CPU_HAS
14843 t_warn:
14844- warn_pre_alternatives();
14845+ if (bit != X86_FEATURE_PCID && bit != X86_FEATURE_INVPCID)
14846+ warn_pre_alternatives();
14847 return false;
14848 #endif
14849 #else /* GCC_VERSION >= 40500 */
14850@@ -421,7 +423,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
14851 ".section .discard,\"aw\",@progbits\n"
14852 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
14853 ".previous\n"
14854- ".section .altinstr_replacement,\"ax\"\n"
14855+ ".section .altinstr_replacement,\"a\"\n"
14856 "3: movb $1,%0\n"
14857 "4:\n"
14858 ".previous\n"
14859@@ -457,7 +459,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
14860 " .byte 2b - 1b\n" /* src len */
14861 " .byte 4f - 3f\n" /* repl len */
14862 ".previous\n"
14863- ".section .altinstr_replacement,\"ax\"\n"
14864+ ".section .altinstr_replacement,\"a\"\n"
14865 "3: .byte 0xe9\n .long %l[t_no] - 2b\n"
14866 "4:\n"
14867 ".previous\n"
14868@@ -490,7 +492,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
14869 ".section .discard,\"aw\",@progbits\n"
14870 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
14871 ".previous\n"
14872- ".section .altinstr_replacement,\"ax\"\n"
14873+ ".section .altinstr_replacement,\"a\"\n"
14874 "3: movb $0,%0\n"
14875 "4:\n"
14876 ".previous\n"
14877@@ -504,7 +506,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
14878 ".section .discard,\"aw\",@progbits\n"
14879 " .byte 0xff + (6f-5f) - (4b-3b)\n" /* size check */
14880 ".previous\n"
14881- ".section .altinstr_replacement,\"ax\"\n"
14882+ ".section .altinstr_replacement,\"a\"\n"
14883 "5: movb $1,%0\n"
14884 "6:\n"
14885 ".previous\n"
14886diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
14887index b90e5df..b462c91 100644
14888--- a/arch/x86/include/asm/desc.h
14889+++ b/arch/x86/include/asm/desc.h
14890@@ -4,6 +4,7 @@
14891 #include <asm/desc_defs.h>
14892 #include <asm/ldt.h>
14893 #include <asm/mmu.h>
14894+#include <asm/pgtable.h>
14895
14896 #include <linux/smp.h>
14897 #include <linux/percpu.h>
14898@@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
14899
14900 desc->type = (info->read_exec_only ^ 1) << 1;
14901 desc->type |= info->contents << 2;
14902+ desc->type |= info->seg_not_present ^ 1;
14903
14904 desc->s = 1;
14905 desc->dpl = 0x3;
14906@@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
14907 }
14908
14909 extern struct desc_ptr idt_descr;
14910-extern gate_desc idt_table[];
14911-extern struct desc_ptr debug_idt_descr;
14912-extern gate_desc debug_idt_table[];
14913-
14914-struct gdt_page {
14915- struct desc_struct gdt[GDT_ENTRIES];
14916-} __attribute__((aligned(PAGE_SIZE)));
14917-
14918-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
14919+extern gate_desc idt_table[IDT_ENTRIES];
14920+extern const struct desc_ptr debug_idt_descr;
14921+extern gate_desc debug_idt_table[IDT_ENTRIES];
14922
14923+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
14924 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
14925 {
14926- return per_cpu(gdt_page, cpu).gdt;
14927+ return cpu_gdt_table[cpu];
14928 }
14929
14930 #ifdef CONFIG_X86_64
14931@@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
14932 unsigned long base, unsigned dpl, unsigned flags,
14933 unsigned short seg)
14934 {
14935- gate->a = (seg << 16) | (base & 0xffff);
14936- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
14937+ gate->gate.offset_low = base;
14938+ gate->gate.seg = seg;
14939+ gate->gate.reserved = 0;
14940+ gate->gate.type = type;
14941+ gate->gate.s = 0;
14942+ gate->gate.dpl = dpl;
14943+ gate->gate.p = 1;
14944+ gate->gate.offset_high = base >> 16;
14945 }
14946
14947 #endif
14948@@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
14949
14950 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
14951 {
14952+ pax_open_kernel();
14953 memcpy(&idt[entry], gate, sizeof(*gate));
14954+ pax_close_kernel();
14955 }
14956
14957 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
14958 {
14959+ pax_open_kernel();
14960 memcpy(&ldt[entry], desc, 8);
14961+ pax_close_kernel();
14962 }
14963
14964 static inline void
14965@@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
14966 default: size = sizeof(*gdt); break;
14967 }
14968
14969+ pax_open_kernel();
14970 memcpy(&gdt[entry], desc, size);
14971+ pax_close_kernel();
14972 }
14973
14974 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
14975@@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
14976
14977 static inline void native_load_tr_desc(void)
14978 {
14979+ pax_open_kernel();
14980 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
14981+ pax_close_kernel();
14982 }
14983
14984 static inline void native_load_gdt(const struct desc_ptr *dtr)
14985@@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
14986 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
14987 unsigned int i;
14988
14989+ pax_open_kernel();
14990 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
14991 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
14992+ pax_close_kernel();
14993 }
14994
14995 #define _LDT_empty(info) \
14996@@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
14997 preempt_enable();
14998 }
14999
15000-static inline unsigned long get_desc_base(const struct desc_struct *desc)
15001+static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
15002 {
15003 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
15004 }
15005@@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
15006 }
15007
15008 #ifdef CONFIG_X86_64
15009-static inline void set_nmi_gate(int gate, void *addr)
15010+static inline void set_nmi_gate(int gate, const void *addr)
15011 {
15012 gate_desc s;
15013
15014@@ -321,8 +334,8 @@ static inline void set_nmi_gate(int gate, void *addr)
15015 #endif
15016
15017 #ifdef CONFIG_TRACING
15018-extern struct desc_ptr trace_idt_descr;
15019-extern gate_desc trace_idt_table[];
15020+extern const struct desc_ptr trace_idt_descr;
15021+extern gate_desc trace_idt_table[IDT_ENTRIES];
15022 static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
15023 {
15024 write_idt_entry(trace_idt_table, entry, gate);
15025@@ -333,7 +346,7 @@ static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
15026 }
15027 #endif
15028
15029-static inline void _set_gate(int gate, unsigned type, void *addr,
15030+static inline void _set_gate(int gate, unsigned type, const void *addr,
15031 unsigned dpl, unsigned ist, unsigned seg)
15032 {
15033 gate_desc s;
15034@@ -353,7 +366,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
15035 * Pentium F0 0F bugfix can have resulted in the mapped
15036 * IDT being write-protected.
15037 */
15038-static inline void set_intr_gate(unsigned int n, void *addr)
15039+static inline void set_intr_gate(unsigned int n, const void *addr)
15040 {
15041 BUG_ON((unsigned)n > 0xFF);
15042 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
15043@@ -410,19 +423,19 @@ static inline void __alloc_intr_gate(unsigned int n, void *addr)
15044 /*
15045 * This routine sets up an interrupt gate at directory privilege level 3.
15046 */
15047-static inline void set_system_intr_gate(unsigned int n, void *addr)
15048+static inline void set_system_intr_gate(unsigned int n, const void *addr)
15049 {
15050 BUG_ON((unsigned)n > 0xFF);
15051 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
15052 }
15053
15054-static inline void set_system_trap_gate(unsigned int n, void *addr)
15055+static inline void set_system_trap_gate(unsigned int n, const void *addr)
15056 {
15057 BUG_ON((unsigned)n > 0xFF);
15058 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
15059 }
15060
15061-static inline void set_trap_gate(unsigned int n, void *addr)
15062+static inline void set_trap_gate(unsigned int n, const void *addr)
15063 {
15064 BUG_ON((unsigned)n > 0xFF);
15065 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
15066@@ -431,16 +444,16 @@ static inline void set_trap_gate(unsigned int n, void *addr)
15067 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
15068 {
15069 BUG_ON((unsigned)n > 0xFF);
15070- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
15071+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
15072 }
15073
15074-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
15075+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
15076 {
15077 BUG_ON((unsigned)n > 0xFF);
15078 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
15079 }
15080
15081-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
15082+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
15083 {
15084 BUG_ON((unsigned)n > 0xFF);
15085 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
15086@@ -512,4 +525,17 @@ static inline void load_current_idt(void)
15087 else
15088 load_idt((const struct desc_ptr *)&idt_descr);
15089 }
15090+
15091+#ifdef CONFIG_X86_32
15092+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
15093+{
15094+ struct desc_struct d;
15095+
15096+ if (likely(limit))
15097+ limit = (limit - 1UL) >> PAGE_SHIFT;
15098+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
15099+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
15100+}
15101+#endif
15102+
15103 #endif /* _ASM_X86_DESC_H */
15104diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
15105index 278441f..b95a174 100644
15106--- a/arch/x86/include/asm/desc_defs.h
15107+++ b/arch/x86/include/asm/desc_defs.h
15108@@ -31,6 +31,12 @@ struct desc_struct {
15109 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
15110 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
15111 };
15112+ struct {
15113+ u16 offset_low;
15114+ u16 seg;
15115+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
15116+ unsigned offset_high: 16;
15117+ } gate;
15118 };
15119 } __attribute__((packed));
15120
15121diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
15122index ced283a..ffe04cc 100644
15123--- a/arch/x86/include/asm/div64.h
15124+++ b/arch/x86/include/asm/div64.h
15125@@ -39,7 +39,7 @@
15126 __mod; \
15127 })
15128
15129-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
15130+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
15131 {
15132 union {
15133 u64 v64;
15134diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
15135index 9c999c1..3860cb8 100644
15136--- a/arch/x86/include/asm/elf.h
15137+++ b/arch/x86/include/asm/elf.h
15138@@ -243,7 +243,25 @@ extern int force_personality32;
15139 the loader. We need to make sure that it is out of the way of the program
15140 that it will "exec", and that there is sufficient room for the brk. */
15141
15142+#ifdef CONFIG_PAX_SEGMEXEC
15143+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
15144+#else
15145 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
15146+#endif
15147+
15148+#ifdef CONFIG_PAX_ASLR
15149+#ifdef CONFIG_X86_32
15150+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
15151+
15152+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
15153+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
15154+#else
15155+#define PAX_ELF_ET_DYN_BASE 0x400000UL
15156+
15157+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
15158+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
15159+#endif
15160+#endif
15161
15162 /* This yields a mask that user programs can use to figure out what
15163 instruction set this CPU supports. This could be done in user space,
15164@@ -296,16 +314,12 @@ do { \
15165
15166 #define ARCH_DLINFO \
15167 do { \
15168- if (vdso_enabled) \
15169- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
15170- (unsigned long)current->mm->context.vdso); \
15171+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
15172 } while (0)
15173
15174 #define ARCH_DLINFO_X32 \
15175 do { \
15176- if (vdso_enabled) \
15177- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
15178- (unsigned long)current->mm->context.vdso); \
15179+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
15180 } while (0)
15181
15182 #define AT_SYSINFO 32
15183@@ -320,7 +334,7 @@ else \
15184
15185 #endif /* !CONFIG_X86_32 */
15186
15187-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
15188+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
15189
15190 #define VDSO_ENTRY \
15191 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
15192@@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
15193 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
15194 #define compat_arch_setup_additional_pages syscall32_setup_pages
15195
15196-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
15197-#define arch_randomize_brk arch_randomize_brk
15198-
15199 /*
15200 * True on X86_32 or when emulating IA32 on X86_64
15201 */
15202diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
15203index 77a99ac..39ff7f5 100644
15204--- a/arch/x86/include/asm/emergency-restart.h
15205+++ b/arch/x86/include/asm/emergency-restart.h
15206@@ -1,6 +1,6 @@
15207 #ifndef _ASM_X86_EMERGENCY_RESTART_H
15208 #define _ASM_X86_EMERGENCY_RESTART_H
15209
15210-extern void machine_emergency_restart(void);
15211+extern void machine_emergency_restart(void) __noreturn;
15212
15213 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
15214diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
15215index 4d0bda7..221da4d 100644
15216--- a/arch/x86/include/asm/fpu-internal.h
15217+++ b/arch/x86/include/asm/fpu-internal.h
15218@@ -124,8 +124,11 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
15219 #define user_insn(insn, output, input...) \
15220 ({ \
15221 int err; \
15222+ pax_open_userland(); \
15223 asm volatile(ASM_STAC "\n" \
15224- "1:" #insn "\n\t" \
15225+ "1:" \
15226+ __copyuser_seg \
15227+ #insn "\n\t" \
15228 "2: " ASM_CLAC "\n" \
15229 ".section .fixup,\"ax\"\n" \
15230 "3: movl $-1,%[err]\n" \
15231@@ -134,6 +137,7 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
15232 _ASM_EXTABLE(1b, 3b) \
15233 : [err] "=r" (err), output \
15234 : "0"(0), input); \
15235+ pax_close_userland(); \
15236 err; \
15237 })
15238
15239@@ -298,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
15240 "emms\n\t" /* clear stack tags */
15241 "fildl %P[addr]", /* set F?P to defined value */
15242 X86_FEATURE_FXSAVE_LEAK,
15243- [addr] "m" (tsk->thread.fpu.has_fpu));
15244+ [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
15245
15246 return fpu_restore_checking(&tsk->thread.fpu);
15247 }
15248diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
15249index be27ba1..04a8801 100644
15250--- a/arch/x86/include/asm/futex.h
15251+++ b/arch/x86/include/asm/futex.h
15252@@ -12,6 +12,7 @@
15253 #include <asm/smap.h>
15254
15255 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
15256+ typecheck(u32 __user *, uaddr); \
15257 asm volatile("\t" ASM_STAC "\n" \
15258 "1:\t" insn "\n" \
15259 "2:\t" ASM_CLAC "\n" \
15260@@ -20,15 +21,16 @@
15261 "\tjmp\t2b\n" \
15262 "\t.previous\n" \
15263 _ASM_EXTABLE(1b, 3b) \
15264- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
15265+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
15266 : "i" (-EFAULT), "0" (oparg), "1" (0))
15267
15268 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
15269+ typecheck(u32 __user *, uaddr); \
15270 asm volatile("\t" ASM_STAC "\n" \
15271 "1:\tmovl %2, %0\n" \
15272 "\tmovl\t%0, %3\n" \
15273 "\t" insn "\n" \
15274- "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
15275+ "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
15276 "\tjnz\t1b\n" \
15277 "3:\t" ASM_CLAC "\n" \
15278 "\t.section .fixup,\"ax\"\n" \
15279@@ -38,7 +40,7 @@
15280 _ASM_EXTABLE(1b, 4b) \
15281 _ASM_EXTABLE(2b, 4b) \
15282 : "=&a" (oldval), "=&r" (ret), \
15283- "+m" (*uaddr), "=&r" (tem) \
15284+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
15285 : "r" (oparg), "i" (-EFAULT), "1" (0))
15286
15287 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
15288@@ -57,12 +59,13 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
15289
15290 pagefault_disable();
15291
15292+ pax_open_userland();
15293 switch (op) {
15294 case FUTEX_OP_SET:
15295- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
15296+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
15297 break;
15298 case FUTEX_OP_ADD:
15299- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
15300+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
15301 uaddr, oparg);
15302 break;
15303 case FUTEX_OP_OR:
15304@@ -77,6 +80,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
15305 default:
15306 ret = -ENOSYS;
15307 }
15308+ pax_close_userland();
15309
15310 pagefault_enable();
15311
15312@@ -115,18 +119,20 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
15313 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
15314 return -EFAULT;
15315
15316+ pax_open_userland();
15317 asm volatile("\t" ASM_STAC "\n"
15318- "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
15319+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
15320 "2:\t" ASM_CLAC "\n"
15321 "\t.section .fixup, \"ax\"\n"
15322 "3:\tmov %3, %0\n"
15323 "\tjmp 2b\n"
15324 "\t.previous\n"
15325 _ASM_EXTABLE(1b, 3b)
15326- : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
15327+ : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
15328 : "i" (-EFAULT), "r" (newval), "1" (oldval)
15329 : "memory"
15330 );
15331+ pax_close_userland();
15332
15333 *uval = oldval;
15334 return ret;
15335diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
15336index e4ac559..c1c0c87 100644
15337--- a/arch/x86/include/asm/hw_irq.h
15338+++ b/arch/x86/include/asm/hw_irq.h
15339@@ -165,8 +165,8 @@ extern void setup_ioapic_dest(void);
15340 extern void enable_IO_APIC(void);
15341
15342 /* Statistics */
15343-extern atomic_t irq_err_count;
15344-extern atomic_t irq_mis_count;
15345+extern atomic_unchecked_t irq_err_count;
15346+extern atomic_unchecked_t irq_mis_count;
15347
15348 /* EISA */
15349 extern void eisa_set_level_irq(unsigned int irq);
15350diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
15351index a203659..9889f1c 100644
15352--- a/arch/x86/include/asm/i8259.h
15353+++ b/arch/x86/include/asm/i8259.h
15354@@ -62,7 +62,7 @@ struct legacy_pic {
15355 void (*init)(int auto_eoi);
15356 int (*irq_pending)(unsigned int irq);
15357 void (*make_irq)(unsigned int irq);
15358-};
15359+} __do_const;
15360
15361 extern struct legacy_pic *legacy_pic;
15362 extern struct legacy_pic null_legacy_pic;
15363diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
15364index 34f69cb..6d95446 100644
15365--- a/arch/x86/include/asm/io.h
15366+++ b/arch/x86/include/asm/io.h
15367@@ -51,12 +51,12 @@ static inline void name(type val, volatile void __iomem *addr) \
15368 "m" (*(volatile type __force *)addr) barrier); }
15369
15370 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
15371-build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
15372-build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
15373+build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
15374+build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
15375
15376 build_mmio_read(__readb, "b", unsigned char, "=q", )
15377-build_mmio_read(__readw, "w", unsigned short, "=r", )
15378-build_mmio_read(__readl, "l", unsigned int, "=r", )
15379+build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
15380+build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
15381
15382 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
15383 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
15384@@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
15385 return ioremap_nocache(offset, size);
15386 }
15387
15388-extern void iounmap(volatile void __iomem *addr);
15389+extern void iounmap(const volatile void __iomem *addr);
15390
15391 extern void set_iounmap_nonlazy(void);
15392
15393@@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
15394
15395 #include <linux/vmalloc.h>
15396
15397+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
15398+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
15399+{
15400+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
15401+}
15402+
15403+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
15404+{
15405+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
15406+}
15407+
15408 /*
15409 * Convert a virtual cached pointer to an uncached pointer
15410 */
15411diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
15412index bba3cf8..06bc8da 100644
15413--- a/arch/x86/include/asm/irqflags.h
15414+++ b/arch/x86/include/asm/irqflags.h
15415@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
15416 sti; \
15417 sysexit
15418
15419+#define GET_CR0_INTO_RDI mov %cr0, %rdi
15420+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
15421+#define GET_CR3_INTO_RDI mov %cr3, %rdi
15422+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
15423+
15424 #else
15425 #define INTERRUPT_RETURN iret
15426 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
15427diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
15428index 5a6d287..f815789 100644
15429--- a/arch/x86/include/asm/kprobes.h
15430+++ b/arch/x86/include/asm/kprobes.h
15431@@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
15432 #define RELATIVEJUMP_SIZE 5
15433 #define RELATIVECALL_OPCODE 0xe8
15434 #define RELATIVE_ADDR_SIZE 4
15435-#define MAX_STACK_SIZE 64
15436-#define MIN_STACK_SIZE(ADDR) \
15437- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
15438- THREAD_SIZE - (unsigned long)(ADDR))) \
15439- ? (MAX_STACK_SIZE) \
15440- : (((unsigned long)current_thread_info()) + \
15441- THREAD_SIZE - (unsigned long)(ADDR)))
15442+#define MAX_STACK_SIZE 64UL
15443+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
15444
15445 #define flush_insn_slot(p) do { } while (0)
15446
15447diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
15448index 2d89e39..baee879 100644
15449--- a/arch/x86/include/asm/local.h
15450+++ b/arch/x86/include/asm/local.h
15451@@ -10,33 +10,97 @@ typedef struct {
15452 atomic_long_t a;
15453 } local_t;
15454
15455+typedef struct {
15456+ atomic_long_unchecked_t a;
15457+} local_unchecked_t;
15458+
15459 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
15460
15461 #define local_read(l) atomic_long_read(&(l)->a)
15462+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
15463 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
15464+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
15465
15466 static inline void local_inc(local_t *l)
15467 {
15468- asm volatile(_ASM_INC "%0"
15469+ asm volatile(_ASM_INC "%0\n"
15470+
15471+#ifdef CONFIG_PAX_REFCOUNT
15472+ "jno 0f\n"
15473+ _ASM_DEC "%0\n"
15474+ "int $4\n0:\n"
15475+ _ASM_EXTABLE(0b, 0b)
15476+#endif
15477+
15478+ : "+m" (l->a.counter));
15479+}
15480+
15481+static inline void local_inc_unchecked(local_unchecked_t *l)
15482+{
15483+ asm volatile(_ASM_INC "%0\n"
15484 : "+m" (l->a.counter));
15485 }
15486
15487 static inline void local_dec(local_t *l)
15488 {
15489- asm volatile(_ASM_DEC "%0"
15490+ asm volatile(_ASM_DEC "%0\n"
15491+
15492+#ifdef CONFIG_PAX_REFCOUNT
15493+ "jno 0f\n"
15494+ _ASM_INC "%0\n"
15495+ "int $4\n0:\n"
15496+ _ASM_EXTABLE(0b, 0b)
15497+#endif
15498+
15499+ : "+m" (l->a.counter));
15500+}
15501+
15502+static inline void local_dec_unchecked(local_unchecked_t *l)
15503+{
15504+ asm volatile(_ASM_DEC "%0\n"
15505 : "+m" (l->a.counter));
15506 }
15507
15508 static inline void local_add(long i, local_t *l)
15509 {
15510- asm volatile(_ASM_ADD "%1,%0"
15511+ asm volatile(_ASM_ADD "%1,%0\n"
15512+
15513+#ifdef CONFIG_PAX_REFCOUNT
15514+ "jno 0f\n"
15515+ _ASM_SUB "%1,%0\n"
15516+ "int $4\n0:\n"
15517+ _ASM_EXTABLE(0b, 0b)
15518+#endif
15519+
15520+ : "+m" (l->a.counter)
15521+ : "ir" (i));
15522+}
15523+
15524+static inline void local_add_unchecked(long i, local_unchecked_t *l)
15525+{
15526+ asm volatile(_ASM_ADD "%1,%0\n"
15527 : "+m" (l->a.counter)
15528 : "ir" (i));
15529 }
15530
15531 static inline void local_sub(long i, local_t *l)
15532 {
15533- asm volatile(_ASM_SUB "%1,%0"
15534+ asm volatile(_ASM_SUB "%1,%0\n"
15535+
15536+#ifdef CONFIG_PAX_REFCOUNT
15537+ "jno 0f\n"
15538+ _ASM_ADD "%1,%0\n"
15539+ "int $4\n0:\n"
15540+ _ASM_EXTABLE(0b, 0b)
15541+#endif
15542+
15543+ : "+m" (l->a.counter)
15544+ : "ir" (i));
15545+}
15546+
15547+static inline void local_sub_unchecked(long i, local_unchecked_t *l)
15548+{
15549+ asm volatile(_ASM_SUB "%1,%0\n"
15550 : "+m" (l->a.counter)
15551 : "ir" (i));
15552 }
15553@@ -54,7 +118,16 @@ static inline int local_sub_and_test(long i, local_t *l)
15554 {
15555 unsigned char c;
15556
15557- asm volatile(_ASM_SUB "%2,%0; sete %1"
15558+ asm volatile(_ASM_SUB "%2,%0\n"
15559+
15560+#ifdef CONFIG_PAX_REFCOUNT
15561+ "jno 0f\n"
15562+ _ASM_ADD "%2,%0\n"
15563+ "int $4\n0:\n"
15564+ _ASM_EXTABLE(0b, 0b)
15565+#endif
15566+
15567+ "sete %1\n"
15568 : "+m" (l->a.counter), "=qm" (c)
15569 : "ir" (i) : "memory");
15570 return c;
15571@@ -72,7 +145,16 @@ static inline int local_dec_and_test(local_t *l)
15572 {
15573 unsigned char c;
15574
15575- asm volatile(_ASM_DEC "%0; sete %1"
15576+ asm volatile(_ASM_DEC "%0\n"
15577+
15578+#ifdef CONFIG_PAX_REFCOUNT
15579+ "jno 0f\n"
15580+ _ASM_INC "%0\n"
15581+ "int $4\n0:\n"
15582+ _ASM_EXTABLE(0b, 0b)
15583+#endif
15584+
15585+ "sete %1\n"
15586 : "+m" (l->a.counter), "=qm" (c)
15587 : : "memory");
15588 return c != 0;
15589@@ -90,7 +172,16 @@ static inline int local_inc_and_test(local_t *l)
15590 {
15591 unsigned char c;
15592
15593- asm volatile(_ASM_INC "%0; sete %1"
15594+ asm volatile(_ASM_INC "%0\n"
15595+
15596+#ifdef CONFIG_PAX_REFCOUNT
15597+ "jno 0f\n"
15598+ _ASM_DEC "%0\n"
15599+ "int $4\n0:\n"
15600+ _ASM_EXTABLE(0b, 0b)
15601+#endif
15602+
15603+ "sete %1\n"
15604 : "+m" (l->a.counter), "=qm" (c)
15605 : : "memory");
15606 return c != 0;
15607@@ -109,7 +200,16 @@ static inline int local_add_negative(long i, local_t *l)
15608 {
15609 unsigned char c;
15610
15611- asm volatile(_ASM_ADD "%2,%0; sets %1"
15612+ asm volatile(_ASM_ADD "%2,%0\n"
15613+
15614+#ifdef CONFIG_PAX_REFCOUNT
15615+ "jno 0f\n"
15616+ _ASM_SUB "%2,%0\n"
15617+ "int $4\n0:\n"
15618+ _ASM_EXTABLE(0b, 0b)
15619+#endif
15620+
15621+ "sets %1\n"
15622 : "+m" (l->a.counter), "=qm" (c)
15623 : "ir" (i) : "memory");
15624 return c;
15625@@ -125,6 +225,30 @@ static inline int local_add_negative(long i, local_t *l)
15626 static inline long local_add_return(long i, local_t *l)
15627 {
15628 long __i = i;
15629+ asm volatile(_ASM_XADD "%0, %1\n"
15630+
15631+#ifdef CONFIG_PAX_REFCOUNT
15632+ "jno 0f\n"
15633+ _ASM_MOV "%0,%1\n"
15634+ "int $4\n0:\n"
15635+ _ASM_EXTABLE(0b, 0b)
15636+#endif
15637+
15638+ : "+r" (i), "+m" (l->a.counter)
15639+ : : "memory");
15640+ return i + __i;
15641+}
15642+
15643+/**
15644+ * local_add_return_unchecked - add and return
15645+ * @i: integer value to add
15646+ * @l: pointer to type local_unchecked_t
15647+ *
15648+ * Atomically adds @i to @l and returns @i + @l
15649+ */
15650+static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
15651+{
15652+ long __i = i;
15653 asm volatile(_ASM_XADD "%0, %1;"
15654 : "+r" (i), "+m" (l->a.counter)
15655 : : "memory");
15656@@ -141,6 +265,8 @@ static inline long local_sub_return(long i, local_t *l)
15657
15658 #define local_cmpxchg(l, o, n) \
15659 (cmpxchg_local(&((l)->a.counter), (o), (n)))
15660+#define local_cmpxchg_unchecked(l, o, n) \
15661+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
15662 /* Always has a lock prefix */
15663 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
15664
15665diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
15666new file mode 100644
15667index 0000000..2bfd3ba
15668--- /dev/null
15669+++ b/arch/x86/include/asm/mman.h
15670@@ -0,0 +1,15 @@
15671+#ifndef _X86_MMAN_H
15672+#define _X86_MMAN_H
15673+
15674+#include <uapi/asm/mman.h>
15675+
15676+#ifdef __KERNEL__
15677+#ifndef __ASSEMBLY__
15678+#ifdef CONFIG_X86_32
15679+#define arch_mmap_check i386_mmap_check
15680+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
15681+#endif
15682+#endif
15683+#endif
15684+
15685+#endif /* X86_MMAN_H */
15686diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
15687index 5f55e69..e20bfb1 100644
15688--- a/arch/x86/include/asm/mmu.h
15689+++ b/arch/x86/include/asm/mmu.h
15690@@ -9,7 +9,7 @@
15691 * we put the segment information here.
15692 */
15693 typedef struct {
15694- void *ldt;
15695+ struct desc_struct *ldt;
15696 int size;
15697
15698 #ifdef CONFIG_X86_64
15699@@ -18,7 +18,19 @@ typedef struct {
15700 #endif
15701
15702 struct mutex lock;
15703- void *vdso;
15704+ unsigned long vdso;
15705+
15706+#ifdef CONFIG_X86_32
15707+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
15708+ unsigned long user_cs_base;
15709+ unsigned long user_cs_limit;
15710+
15711+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
15712+ cpumask_t cpu_user_cs_mask;
15713+#endif
15714+
15715+#endif
15716+#endif
15717 } mm_context_t;
15718
15719 #ifdef CONFIG_SMP
15720diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
15721index cdbf367..ce8f82b 100644
15722--- a/arch/x86/include/asm/mmu_context.h
15723+++ b/arch/x86/include/asm/mmu_context.h
15724@@ -24,6 +24,20 @@ void destroy_context(struct mm_struct *mm);
15725
15726 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
15727 {
15728+
15729+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15730+ if (!(static_cpu_has(X86_FEATURE_PCID))) {
15731+ unsigned int i;
15732+ pgd_t *pgd;
15733+
15734+ pax_open_kernel();
15735+ pgd = get_cpu_pgd(smp_processor_id(), kernel);
15736+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
15737+ set_pgd_batched(pgd+i, native_make_pgd(0));
15738+ pax_close_kernel();
15739+ }
15740+#endif
15741+
15742 #ifdef CONFIG_SMP
15743 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
15744 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
15745@@ -34,16 +48,55 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
15746 struct task_struct *tsk)
15747 {
15748 unsigned cpu = smp_processor_id();
15749+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
15750+ int tlbstate = TLBSTATE_OK;
15751+#endif
15752
15753 if (likely(prev != next)) {
15754 #ifdef CONFIG_SMP
15755+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
15756+ tlbstate = this_cpu_read(cpu_tlbstate.state);
15757+#endif
15758 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
15759 this_cpu_write(cpu_tlbstate.active_mm, next);
15760 #endif
15761 cpumask_set_cpu(cpu, mm_cpumask(next));
15762
15763 /* Re-load page tables */
15764+#ifdef CONFIG_PAX_PER_CPU_PGD
15765+ pax_open_kernel();
15766+
15767+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15768+ if (static_cpu_has(X86_FEATURE_PCID))
15769+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
15770+ else
15771+#endif
15772+
15773+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
15774+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
15775+ pax_close_kernel();
15776+ 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));
15777+
15778+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15779+ if (static_cpu_has(X86_FEATURE_PCID)) {
15780+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
15781+ u64 descriptor[2];
15782+ descriptor[0] = PCID_USER;
15783+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
15784+ } else {
15785+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
15786+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
15787+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
15788+ else
15789+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
15790+ }
15791+ } else
15792+#endif
15793+
15794+ load_cr3(get_cpu_pgd(cpu, kernel));
15795+#else
15796 load_cr3(next->pgd);
15797+#endif
15798
15799 /* stop flush ipis for the previous mm */
15800 cpumask_clear_cpu(cpu, mm_cpumask(prev));
15801@@ -53,9 +106,63 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
15802 */
15803 if (unlikely(prev->context.ldt != next->context.ldt))
15804 load_LDT_nolock(&next->context);
15805- }
15806+
15807+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
15808+ if (!(__supported_pte_mask & _PAGE_NX)) {
15809+ smp_mb__before_clear_bit();
15810+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
15811+ smp_mb__after_clear_bit();
15812+ cpu_set(cpu, next->context.cpu_user_cs_mask);
15813+ }
15814+#endif
15815+
15816+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
15817+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
15818+ prev->context.user_cs_limit != next->context.user_cs_limit))
15819+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
15820 #ifdef CONFIG_SMP
15821+ else if (unlikely(tlbstate != TLBSTATE_OK))
15822+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
15823+#endif
15824+#endif
15825+
15826+ }
15827 else {
15828+
15829+#ifdef CONFIG_PAX_PER_CPU_PGD
15830+ pax_open_kernel();
15831+
15832+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15833+ if (static_cpu_has(X86_FEATURE_PCID))
15834+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
15835+ else
15836+#endif
15837+
15838+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
15839+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
15840+ pax_close_kernel();
15841+ 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));
15842+
15843+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15844+ if (static_cpu_has(X86_FEATURE_PCID)) {
15845+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
15846+ u64 descriptor[2];
15847+ descriptor[0] = PCID_USER;
15848+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
15849+ } else {
15850+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
15851+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
15852+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
15853+ else
15854+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
15855+ }
15856+ } else
15857+#endif
15858+
15859+ load_cr3(get_cpu_pgd(cpu, kernel));
15860+#endif
15861+
15862+#ifdef CONFIG_SMP
15863 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
15864 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
15865
15866@@ -64,11 +171,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
15867 * tlb flush IPI delivery. We must reload CR3
15868 * to make sure to use no freed page tables.
15869 */
15870+
15871+#ifndef CONFIG_PAX_PER_CPU_PGD
15872 load_cr3(next->pgd);
15873+#endif
15874+
15875 load_LDT_nolock(&next->context);
15876+
15877+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
15878+ if (!(__supported_pte_mask & _PAGE_NX))
15879+ cpu_set(cpu, next->context.cpu_user_cs_mask);
15880+#endif
15881+
15882+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
15883+#ifdef CONFIG_PAX_PAGEEXEC
15884+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
15885+#endif
15886+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
15887+#endif
15888+
15889 }
15890+#endif
15891 }
15892-#endif
15893 }
15894
15895 #define activate_mm(prev, next) \
15896diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
15897index e3b7819..b257c64 100644
15898--- a/arch/x86/include/asm/module.h
15899+++ b/arch/x86/include/asm/module.h
15900@@ -5,6 +5,7 @@
15901
15902 #ifdef CONFIG_X86_64
15903 /* X86_64 does not define MODULE_PROC_FAMILY */
15904+#define MODULE_PROC_FAMILY ""
15905 #elif defined CONFIG_M486
15906 #define MODULE_PROC_FAMILY "486 "
15907 #elif defined CONFIG_M586
15908@@ -57,8 +58,20 @@
15909 #error unknown processor family
15910 #endif
15911
15912-#ifdef CONFIG_X86_32
15913-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
15914+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
15915+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
15916+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
15917+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
15918+#else
15919+#define MODULE_PAX_KERNEXEC ""
15920 #endif
15921
15922+#ifdef CONFIG_PAX_MEMORY_UDEREF
15923+#define MODULE_PAX_UDEREF "UDEREF "
15924+#else
15925+#define MODULE_PAX_UDEREF ""
15926+#endif
15927+
15928+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
15929+
15930 #endif /* _ASM_X86_MODULE_H */
15931diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
15932index 86f9301..b365cda 100644
15933--- a/arch/x86/include/asm/nmi.h
15934+++ b/arch/x86/include/asm/nmi.h
15935@@ -40,11 +40,11 @@ struct nmiaction {
15936 nmi_handler_t handler;
15937 unsigned long flags;
15938 const char *name;
15939-};
15940+} __do_const;
15941
15942 #define register_nmi_handler(t, fn, fg, n, init...) \
15943 ({ \
15944- static struct nmiaction init fn##_na = { \
15945+ static const struct nmiaction init fn##_na = { \
15946 .handler = (fn), \
15947 .name = (n), \
15948 .flags = (fg), \
15949@@ -52,7 +52,7 @@ struct nmiaction {
15950 __register_nmi_handler((t), &fn##_na); \
15951 })
15952
15953-int __register_nmi_handler(unsigned int, struct nmiaction *);
15954+int __register_nmi_handler(unsigned int, const struct nmiaction *);
15955
15956 void unregister_nmi_handler(unsigned int, const char *);
15957
15958diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
15959index c878924..21f4889 100644
15960--- a/arch/x86/include/asm/page.h
15961+++ b/arch/x86/include/asm/page.h
15962@@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
15963 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
15964
15965 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
15966+#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
15967
15968 #define __boot_va(x) __va(x)
15969 #define __boot_pa(x) __pa(x)
15970diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
15971index 0f1ddee..e2fc3d1 100644
15972--- a/arch/x86/include/asm/page_64.h
15973+++ b/arch/x86/include/asm/page_64.h
15974@@ -7,9 +7,9 @@
15975
15976 /* duplicated to the one in bootmem.h */
15977 extern unsigned long max_pfn;
15978-extern unsigned long phys_base;
15979+extern const unsigned long phys_base;
15980
15981-static inline unsigned long __phys_addr_nodebug(unsigned long x)
15982+static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
15983 {
15984 unsigned long y = x - __START_KERNEL_map;
15985
15986diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
15987index cfdc9ee..3f7b5d6 100644
15988--- a/arch/x86/include/asm/paravirt.h
15989+++ b/arch/x86/include/asm/paravirt.h
15990@@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
15991 return (pmd_t) { ret };
15992 }
15993
15994-static inline pmdval_t pmd_val(pmd_t pmd)
15995+static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
15996 {
15997 pmdval_t ret;
15998
15999@@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
16000 val);
16001 }
16002
16003+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
16004+{
16005+ pgdval_t val = native_pgd_val(pgd);
16006+
16007+ if (sizeof(pgdval_t) > sizeof(long))
16008+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
16009+ val, (u64)val >> 32);
16010+ else
16011+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
16012+ val);
16013+}
16014+
16015 static inline void pgd_clear(pgd_t *pgdp)
16016 {
16017 set_pgd(pgdp, __pgd(0));
16018@@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
16019 pv_mmu_ops.set_fixmap(idx, phys, flags);
16020 }
16021
16022+#ifdef CONFIG_PAX_KERNEXEC
16023+static inline unsigned long pax_open_kernel(void)
16024+{
16025+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
16026+}
16027+
16028+static inline unsigned long pax_close_kernel(void)
16029+{
16030+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
16031+}
16032+#else
16033+static inline unsigned long pax_open_kernel(void) { return 0; }
16034+static inline unsigned long pax_close_kernel(void) { return 0; }
16035+#endif
16036+
16037 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
16038
16039 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
16040@@ -926,7 +953,7 @@ extern void default_banner(void);
16041
16042 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
16043 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
16044-#define PARA_INDIRECT(addr) *%cs:addr
16045+#define PARA_INDIRECT(addr) *%ss:addr
16046 #endif
16047
16048 #define INTERRUPT_RETURN \
16049@@ -1001,6 +1028,21 @@ extern void default_banner(void);
16050 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
16051 CLBR_NONE, \
16052 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
16053+
16054+#define GET_CR0_INTO_RDI \
16055+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
16056+ mov %rax,%rdi
16057+
16058+#define SET_RDI_INTO_CR0 \
16059+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
16060+
16061+#define GET_CR3_INTO_RDI \
16062+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
16063+ mov %rax,%rdi
16064+
16065+#define SET_RDI_INTO_CR3 \
16066+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
16067+
16068 #endif /* CONFIG_X86_32 */
16069
16070 #endif /* __ASSEMBLY__ */
16071diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
16072index 0db1fca..52310cc 100644
16073--- a/arch/x86/include/asm/paravirt_types.h
16074+++ b/arch/x86/include/asm/paravirt_types.h
16075@@ -84,7 +84,7 @@ struct pv_init_ops {
16076 */
16077 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
16078 unsigned long addr, unsigned len);
16079-};
16080+} __no_const;
16081
16082
16083 struct pv_lazy_ops {
16084@@ -98,7 +98,7 @@ struct pv_time_ops {
16085 unsigned long long (*sched_clock)(void);
16086 unsigned long long (*steal_clock)(int cpu);
16087 unsigned long (*get_tsc_khz)(void);
16088-};
16089+} __no_const;
16090
16091 struct pv_cpu_ops {
16092 /* hooks for various privileged instructions */
16093@@ -192,7 +192,7 @@ struct pv_cpu_ops {
16094
16095 void (*start_context_switch)(struct task_struct *prev);
16096 void (*end_context_switch)(struct task_struct *next);
16097-};
16098+} __no_const;
16099
16100 struct pv_irq_ops {
16101 /*
16102@@ -223,7 +223,7 @@ struct pv_apic_ops {
16103 unsigned long start_eip,
16104 unsigned long start_esp);
16105 #endif
16106-};
16107+} __no_const;
16108
16109 struct pv_mmu_ops {
16110 unsigned long (*read_cr2)(void);
16111@@ -313,6 +313,7 @@ struct pv_mmu_ops {
16112 struct paravirt_callee_save make_pud;
16113
16114 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
16115+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
16116 #endif /* PAGETABLE_LEVELS == 4 */
16117 #endif /* PAGETABLE_LEVELS >= 3 */
16118
16119@@ -324,6 +325,12 @@ struct pv_mmu_ops {
16120 an mfn. We can tell which is which from the index. */
16121 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
16122 phys_addr_t phys, pgprot_t flags);
16123+
16124+#ifdef CONFIG_PAX_KERNEXEC
16125+ unsigned long (*pax_open_kernel)(void);
16126+ unsigned long (*pax_close_kernel)(void);
16127+#endif
16128+
16129 };
16130
16131 struct arch_spinlock;
16132@@ -334,7 +341,7 @@ struct pv_lock_ops {
16133 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
16134 int (*spin_trylock)(struct arch_spinlock *lock);
16135 void (*spin_unlock)(struct arch_spinlock *lock);
16136-};
16137+} __no_const;
16138
16139 /* This contains all the paravirt structures: we get a convenient
16140 * number for each function using the offset which we use to indicate
16141diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
16142index b4389a4..7024269 100644
16143--- a/arch/x86/include/asm/pgalloc.h
16144+++ b/arch/x86/include/asm/pgalloc.h
16145@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
16146 pmd_t *pmd, pte_t *pte)
16147 {
16148 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
16149+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
16150+}
16151+
16152+static inline void pmd_populate_user(struct mm_struct *mm,
16153+ pmd_t *pmd, pte_t *pte)
16154+{
16155+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
16156 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
16157 }
16158
16159@@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
16160
16161 #ifdef CONFIG_X86_PAE
16162 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
16163+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
16164+{
16165+ pud_populate(mm, pudp, pmd);
16166+}
16167 #else /* !CONFIG_X86_PAE */
16168 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
16169 {
16170 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
16171 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
16172 }
16173+
16174+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
16175+{
16176+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
16177+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
16178+}
16179 #endif /* CONFIG_X86_PAE */
16180
16181 #if PAGETABLE_LEVELS > 3
16182@@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
16183 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
16184 }
16185
16186+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
16187+{
16188+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
16189+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
16190+}
16191+
16192 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
16193 {
16194 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
16195diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
16196index 3bf2dd0..23d2a9f 100644
16197--- a/arch/x86/include/asm/pgtable-2level.h
16198+++ b/arch/x86/include/asm/pgtable-2level.h
16199@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
16200
16201 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
16202 {
16203+ pax_open_kernel();
16204 *pmdp = pmd;
16205+ pax_close_kernel();
16206 }
16207
16208 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
16209diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
16210index 81bb91b..9392125 100644
16211--- a/arch/x86/include/asm/pgtable-3level.h
16212+++ b/arch/x86/include/asm/pgtable-3level.h
16213@@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
16214
16215 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
16216 {
16217+ pax_open_kernel();
16218 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
16219+ pax_close_kernel();
16220 }
16221
16222 static inline void native_set_pud(pud_t *pudp, pud_t pud)
16223 {
16224+ pax_open_kernel();
16225 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
16226+ pax_close_kernel();
16227 }
16228
16229 /*
16230diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
16231index 1c00631..845f898 100644
16232--- a/arch/x86/include/asm/pgtable.h
16233+++ b/arch/x86/include/asm/pgtable.h
16234@@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
16235
16236 #ifndef __PAGETABLE_PUD_FOLDED
16237 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
16238+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
16239 #define pgd_clear(pgd) native_pgd_clear(pgd)
16240 #endif
16241
16242@@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
16243
16244 #define arch_end_context_switch(prev) do {} while(0)
16245
16246+#define pax_open_kernel() native_pax_open_kernel()
16247+#define pax_close_kernel() native_pax_close_kernel()
16248 #endif /* CONFIG_PARAVIRT */
16249
16250+#define __HAVE_ARCH_PAX_OPEN_KERNEL
16251+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
16252+
16253+#ifdef CONFIG_PAX_KERNEXEC
16254+static inline unsigned long native_pax_open_kernel(void)
16255+{
16256+ unsigned long cr0;
16257+
16258+ preempt_disable();
16259+ barrier();
16260+ cr0 = read_cr0() ^ X86_CR0_WP;
16261+ BUG_ON(cr0 & X86_CR0_WP);
16262+ write_cr0(cr0);
16263+ return cr0 ^ X86_CR0_WP;
16264+}
16265+
16266+static inline unsigned long native_pax_close_kernel(void)
16267+{
16268+ unsigned long cr0;
16269+
16270+ cr0 = read_cr0() ^ X86_CR0_WP;
16271+ BUG_ON(!(cr0 & X86_CR0_WP));
16272+ write_cr0(cr0);
16273+ barrier();
16274+ preempt_enable_no_resched();
16275+ return cr0 ^ X86_CR0_WP;
16276+}
16277+#else
16278+static inline unsigned long native_pax_open_kernel(void) { return 0; }
16279+static inline unsigned long native_pax_close_kernel(void) { return 0; }
16280+#endif
16281+
16282 /*
16283 * The following only work if pte_present() is true.
16284 * Undefined behaviour if not..
16285 */
16286+static inline int pte_user(pte_t pte)
16287+{
16288+ return pte_val(pte) & _PAGE_USER;
16289+}
16290+
16291 static inline int pte_dirty(pte_t pte)
16292 {
16293 return pte_flags(pte) & _PAGE_DIRTY;
16294@@ -147,6 +187,11 @@ static inline unsigned long pud_pfn(pud_t pud)
16295 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
16296 }
16297
16298+static inline unsigned long pgd_pfn(pgd_t pgd)
16299+{
16300+ return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
16301+}
16302+
16303 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
16304
16305 static inline int pmd_large(pmd_t pte)
16306@@ -200,9 +245,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
16307 return pte_clear_flags(pte, _PAGE_RW);
16308 }
16309
16310+static inline pte_t pte_mkread(pte_t pte)
16311+{
16312+ return __pte(pte_val(pte) | _PAGE_USER);
16313+}
16314+
16315 static inline pte_t pte_mkexec(pte_t pte)
16316 {
16317- return pte_clear_flags(pte, _PAGE_NX);
16318+#ifdef CONFIG_X86_PAE
16319+ if (__supported_pte_mask & _PAGE_NX)
16320+ return pte_clear_flags(pte, _PAGE_NX);
16321+ else
16322+#endif
16323+ return pte_set_flags(pte, _PAGE_USER);
16324+}
16325+
16326+static inline pte_t pte_exprotect(pte_t pte)
16327+{
16328+#ifdef CONFIG_X86_PAE
16329+ if (__supported_pte_mask & _PAGE_NX)
16330+ return pte_set_flags(pte, _PAGE_NX);
16331+ else
16332+#endif
16333+ return pte_clear_flags(pte, _PAGE_USER);
16334 }
16335
16336 static inline pte_t pte_mkdirty(pte_t pte)
16337@@ -444,6 +509,16 @@ pte_t *populate_extra_pte(unsigned long vaddr);
16338 #endif
16339
16340 #ifndef __ASSEMBLY__
16341+
16342+#ifdef CONFIG_PAX_PER_CPU_PGD
16343+extern pgd_t cpu_pgd[NR_CPUS][2][PTRS_PER_PGD];
16344+enum cpu_pgd_type {kernel = 0, user = 1};
16345+static inline pgd_t *get_cpu_pgd(unsigned int cpu, enum cpu_pgd_type type)
16346+{
16347+ return cpu_pgd[cpu][type];
16348+}
16349+#endif
16350+
16351 #include <linux/mm_types.h>
16352 #include <linux/log2.h>
16353
16354@@ -576,7 +651,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
16355 * Currently stuck as a macro due to indirect forward reference to
16356 * linux/mmzone.h's __section_mem_map_addr() definition:
16357 */
16358-#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
16359+#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
16360
16361 /* Find an entry in the second-level page table.. */
16362 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
16363@@ -616,7 +691,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
16364 * Currently stuck as a macro due to indirect forward reference to
16365 * linux/mmzone.h's __section_mem_map_addr() definition:
16366 */
16367-#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
16368+#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
16369
16370 /* to find an entry in a page-table-directory. */
16371 static inline unsigned long pud_index(unsigned long address)
16372@@ -631,7 +706,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
16373
16374 static inline int pgd_bad(pgd_t pgd)
16375 {
16376- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
16377+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
16378 }
16379
16380 static inline int pgd_none(pgd_t pgd)
16381@@ -654,7 +729,12 @@ static inline int pgd_none(pgd_t pgd)
16382 * pgd_offset() returns a (pgd_t *)
16383 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
16384 */
16385-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
16386+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
16387+
16388+#ifdef CONFIG_PAX_PER_CPU_PGD
16389+#define pgd_offset_cpu(cpu, type, address) (get_cpu_pgd(cpu, type) + pgd_index(address))
16390+#endif
16391+
16392 /*
16393 * a shortcut which implies the use of the kernel's pgd, instead
16394 * of a process's
16395@@ -665,6 +745,23 @@ static inline int pgd_none(pgd_t pgd)
16396 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
16397 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
16398
16399+#ifdef CONFIG_X86_32
16400+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
16401+#else
16402+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
16403+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
16404+
16405+#ifdef CONFIG_PAX_MEMORY_UDEREF
16406+#ifdef __ASSEMBLY__
16407+#define pax_user_shadow_base pax_user_shadow_base(%rip)
16408+#else
16409+extern unsigned long pax_user_shadow_base;
16410+extern pgdval_t clone_pgd_mask;
16411+#endif
16412+#endif
16413+
16414+#endif
16415+
16416 #ifndef __ASSEMBLY__
16417
16418 extern int direct_gbpages;
16419@@ -831,11 +928,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
16420 * dst and src can be on the same page, but the range must not overlap,
16421 * and must not cross a page boundary.
16422 */
16423-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
16424+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
16425 {
16426- memcpy(dst, src, count * sizeof(pgd_t));
16427+ pax_open_kernel();
16428+ while (count--)
16429+ *dst++ = *src++;
16430+ pax_close_kernel();
16431 }
16432
16433+#ifdef CONFIG_PAX_PER_CPU_PGD
16434+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
16435+#endif
16436+
16437+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16438+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
16439+#else
16440+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
16441+#endif
16442+
16443 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
16444 static inline int page_level_shift(enum pg_level level)
16445 {
16446diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
16447index 9ee3221..b979c6b 100644
16448--- a/arch/x86/include/asm/pgtable_32.h
16449+++ b/arch/x86/include/asm/pgtable_32.h
16450@@ -25,9 +25,6 @@
16451 struct mm_struct;
16452 struct vm_area_struct;
16453
16454-extern pgd_t swapper_pg_dir[1024];
16455-extern pgd_t initial_page_table[1024];
16456-
16457 static inline void pgtable_cache_init(void) { }
16458 static inline void check_pgt_cache(void) { }
16459 void paging_init(void);
16460@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
16461 # include <asm/pgtable-2level.h>
16462 #endif
16463
16464+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
16465+extern pgd_t initial_page_table[PTRS_PER_PGD];
16466+#ifdef CONFIG_X86_PAE
16467+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
16468+#endif
16469+
16470 #if defined(CONFIG_HIGHPTE)
16471 #define pte_offset_map(dir, address) \
16472 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
16473@@ -62,12 +65,17 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
16474 /* Clear a kernel PTE and flush it from the TLB */
16475 #define kpte_clear_flush(ptep, vaddr) \
16476 do { \
16477+ pax_open_kernel(); \
16478 pte_clear(&init_mm, (vaddr), (ptep)); \
16479+ pax_close_kernel(); \
16480 __flush_tlb_one((vaddr)); \
16481 } while (0)
16482
16483 #endif /* !__ASSEMBLY__ */
16484
16485+#define HAVE_ARCH_UNMAPPED_AREA
16486+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
16487+
16488 /*
16489 * kern_addr_valid() is (1) for FLATMEM and (0) for
16490 * SPARSEMEM and DISCONTIGMEM
16491diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
16492index ed5903b..c7fe163 100644
16493--- a/arch/x86/include/asm/pgtable_32_types.h
16494+++ b/arch/x86/include/asm/pgtable_32_types.h
16495@@ -8,7 +8,7 @@
16496 */
16497 #ifdef CONFIG_X86_PAE
16498 # include <asm/pgtable-3level_types.h>
16499-# define PMD_SIZE (1UL << PMD_SHIFT)
16500+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
16501 # define PMD_MASK (~(PMD_SIZE - 1))
16502 #else
16503 # include <asm/pgtable-2level_types.h>
16504@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
16505 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
16506 #endif
16507
16508+#ifdef CONFIG_PAX_KERNEXEC
16509+#ifndef __ASSEMBLY__
16510+extern unsigned char MODULES_EXEC_VADDR[];
16511+extern unsigned char MODULES_EXEC_END[];
16512+#endif
16513+#include <asm/boot.h>
16514+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
16515+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
16516+#else
16517+#define ktla_ktva(addr) (addr)
16518+#define ktva_ktla(addr) (addr)
16519+#endif
16520+
16521 #define MODULES_VADDR VMALLOC_START
16522 #define MODULES_END VMALLOC_END
16523 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
16524diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
16525index e22c1db..23a625a 100644
16526--- a/arch/x86/include/asm/pgtable_64.h
16527+++ b/arch/x86/include/asm/pgtable_64.h
16528@@ -16,10 +16,14 @@
16529
16530 extern pud_t level3_kernel_pgt[512];
16531 extern pud_t level3_ident_pgt[512];
16532+extern pud_t level3_vmalloc_start_pgt[512];
16533+extern pud_t level3_vmalloc_end_pgt[512];
16534+extern pud_t level3_vmemmap_pgt[512];
16535+extern pud_t level2_vmemmap_pgt[512];
16536 extern pmd_t level2_kernel_pgt[512];
16537 extern pmd_t level2_fixmap_pgt[512];
16538-extern pmd_t level2_ident_pgt[512];
16539-extern pgd_t init_level4_pgt[];
16540+extern pmd_t level2_ident_pgt[512*2];
16541+extern pgd_t init_level4_pgt[512];
16542
16543 #define swapper_pg_dir init_level4_pgt
16544
16545@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
16546
16547 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
16548 {
16549+ pax_open_kernel();
16550 *pmdp = pmd;
16551+ pax_close_kernel();
16552 }
16553
16554 static inline void native_pmd_clear(pmd_t *pmd)
16555@@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
16556
16557 static inline void native_set_pud(pud_t *pudp, pud_t pud)
16558 {
16559+ pax_open_kernel();
16560 *pudp = pud;
16561+ pax_close_kernel();
16562 }
16563
16564 static inline void native_pud_clear(pud_t *pud)
16565@@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
16566
16567 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
16568 {
16569+ pax_open_kernel();
16570+ *pgdp = pgd;
16571+ pax_close_kernel();
16572+}
16573+
16574+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
16575+{
16576 *pgdp = pgd;
16577 }
16578
16579diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
16580index 2d88344..4679fc3 100644
16581--- a/arch/x86/include/asm/pgtable_64_types.h
16582+++ b/arch/x86/include/asm/pgtable_64_types.h
16583@@ -61,6 +61,11 @@ typedef struct { pteval_t pte; } pte_t;
16584 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
16585 #define MODULES_END _AC(0xffffffffff000000, UL)
16586 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
16587+#define MODULES_EXEC_VADDR MODULES_VADDR
16588+#define MODULES_EXEC_END MODULES_END
16589+
16590+#define ktla_ktva(addr) (addr)
16591+#define ktva_ktla(addr) (addr)
16592
16593 #define EARLY_DYNAMIC_PAGE_TABLES 64
16594
16595diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
16596index f4843e0..a2526f8 100644
16597--- a/arch/x86/include/asm/pgtable_types.h
16598+++ b/arch/x86/include/asm/pgtable_types.h
16599@@ -16,13 +16,12 @@
16600 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
16601 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
16602 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
16603-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
16604+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
16605 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
16606 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
16607 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
16608-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
16609-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
16610-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
16611+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
16612+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
16613 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
16614
16615 /* If _PAGE_BIT_PRESENT is clear, we use these: */
16616@@ -40,7 +39,6 @@
16617 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
16618 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
16619 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
16620-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
16621 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
16622 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
16623 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
16624@@ -84,8 +82,10 @@
16625
16626 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
16627 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
16628-#else
16629+#elif defined(CONFIG_KMEMCHECK)
16630 #define _PAGE_NX (_AT(pteval_t, 0))
16631+#else
16632+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
16633 #endif
16634
16635 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
16636@@ -143,6 +143,9 @@
16637 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
16638 _PAGE_ACCESSED)
16639
16640+#define PAGE_READONLY_NOEXEC PAGE_READONLY
16641+#define PAGE_SHARED_NOEXEC PAGE_SHARED
16642+
16643 #define __PAGE_KERNEL_EXEC \
16644 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
16645 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
16646@@ -153,7 +156,7 @@
16647 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
16648 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
16649 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
16650-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
16651+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
16652 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
16653 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
16654 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
16655@@ -215,8 +218,8 @@
16656 * bits are combined, this will alow user to access the high address mapped
16657 * VDSO in the presence of CONFIG_COMPAT_VDSO
16658 */
16659-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
16660-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
16661+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
16662+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
16663 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
16664 #endif
16665
16666@@ -254,7 +257,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
16667 {
16668 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
16669 }
16670+#endif
16671
16672+#if PAGETABLE_LEVELS == 3
16673+#include <asm-generic/pgtable-nopud.h>
16674+#endif
16675+
16676+#if PAGETABLE_LEVELS == 2
16677+#include <asm-generic/pgtable-nopmd.h>
16678+#endif
16679+
16680+#ifndef __ASSEMBLY__
16681 #if PAGETABLE_LEVELS > 3
16682 typedef struct { pudval_t pud; } pud_t;
16683
16684@@ -268,8 +281,6 @@ static inline pudval_t native_pud_val(pud_t pud)
16685 return pud.pud;
16686 }
16687 #else
16688-#include <asm-generic/pgtable-nopud.h>
16689-
16690 static inline pudval_t native_pud_val(pud_t pud)
16691 {
16692 return native_pgd_val(pud.pgd);
16693@@ -289,8 +300,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
16694 return pmd.pmd;
16695 }
16696 #else
16697-#include <asm-generic/pgtable-nopmd.h>
16698-
16699 static inline pmdval_t native_pmd_val(pmd_t pmd)
16700 {
16701 return native_pgd_val(pmd.pud.pgd);
16702@@ -330,7 +339,6 @@ typedef struct page *pgtable_t;
16703
16704 extern pteval_t __supported_pte_mask;
16705 extern void set_nx(void);
16706-extern int nx_enabled;
16707
16708 #define pgprot_writecombine pgprot_writecombine
16709 extern pgprot_t pgprot_writecombine(pgprot_t prot);
16710diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
16711index 24cf5ae..4d9fa2d 100644
16712--- a/arch/x86/include/asm/processor.h
16713+++ b/arch/x86/include/asm/processor.h
16714@@ -199,9 +199,21 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
16715 : "memory");
16716 }
16717
16718+/* invpcid (%rdx),%rax */
16719+#define __ASM_INVPCID ".byte 0x66,0x0f,0x38,0x82,0x02"
16720+
16721+#define INVPCID_SINGLE_ADDRESS 0UL
16722+#define INVPCID_SINGLE_CONTEXT 1UL
16723+#define INVPCID_ALL_GLOBAL 2UL
16724+#define INVPCID_ALL_MONGLOBAL 3UL
16725+
16726+#define PCID_KERNEL 0UL
16727+#define PCID_USER 1UL
16728+#define PCID_NOFLUSH (1UL << 63)
16729+
16730 static inline void load_cr3(pgd_t *pgdir)
16731 {
16732- write_cr3(__pa(pgdir));
16733+ write_cr3(__pa(pgdir) | PCID_KERNEL);
16734 }
16735
16736 #ifdef CONFIG_X86_32
16737@@ -283,7 +295,7 @@ struct tss_struct {
16738
16739 } ____cacheline_aligned;
16740
16741-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
16742+extern struct tss_struct init_tss[NR_CPUS];
16743
16744 /*
16745 * Save the original ist values for checking stack pointers during debugging
16746@@ -453,6 +465,7 @@ struct thread_struct {
16747 unsigned short ds;
16748 unsigned short fsindex;
16749 unsigned short gsindex;
16750+ unsigned short ss;
16751 #endif
16752 #ifdef CONFIG_X86_32
16753 unsigned long ip;
16754@@ -553,29 +566,8 @@ static inline void load_sp0(struct tss_struct *tss,
16755 extern unsigned long mmu_cr4_features;
16756 extern u32 *trampoline_cr4_features;
16757
16758-static inline void set_in_cr4(unsigned long mask)
16759-{
16760- unsigned long cr4;
16761-
16762- mmu_cr4_features |= mask;
16763- if (trampoline_cr4_features)
16764- *trampoline_cr4_features = mmu_cr4_features;
16765- cr4 = read_cr4();
16766- cr4 |= mask;
16767- write_cr4(cr4);
16768-}
16769-
16770-static inline void clear_in_cr4(unsigned long mask)
16771-{
16772- unsigned long cr4;
16773-
16774- mmu_cr4_features &= ~mask;
16775- if (trampoline_cr4_features)
16776- *trampoline_cr4_features = mmu_cr4_features;
16777- cr4 = read_cr4();
16778- cr4 &= ~mask;
16779- write_cr4(cr4);
16780-}
16781+extern void set_in_cr4(unsigned long mask);
16782+extern void clear_in_cr4(unsigned long mask);
16783
16784 typedef struct {
16785 unsigned long seg;
16786@@ -824,11 +816,18 @@ static inline void spin_lock_prefetch(const void *x)
16787 */
16788 #define TASK_SIZE PAGE_OFFSET
16789 #define TASK_SIZE_MAX TASK_SIZE
16790+
16791+#ifdef CONFIG_PAX_SEGMEXEC
16792+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
16793+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
16794+#else
16795 #define STACK_TOP TASK_SIZE
16796-#define STACK_TOP_MAX STACK_TOP
16797+#endif
16798+
16799+#define STACK_TOP_MAX TASK_SIZE
16800
16801 #define INIT_THREAD { \
16802- .sp0 = sizeof(init_stack) + (long)&init_stack, \
16803+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
16804 .vm86_info = NULL, \
16805 .sysenter_cs = __KERNEL_CS, \
16806 .io_bitmap_ptr = NULL, \
16807@@ -842,7 +841,7 @@ static inline void spin_lock_prefetch(const void *x)
16808 */
16809 #define INIT_TSS { \
16810 .x86_tss = { \
16811- .sp0 = sizeof(init_stack) + (long)&init_stack, \
16812+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
16813 .ss0 = __KERNEL_DS, \
16814 .ss1 = __KERNEL_CS, \
16815 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
16816@@ -853,11 +852,7 @@ static inline void spin_lock_prefetch(const void *x)
16817 extern unsigned long thread_saved_pc(struct task_struct *tsk);
16818
16819 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
16820-#define KSTK_TOP(info) \
16821-({ \
16822- unsigned long *__ptr = (unsigned long *)(info); \
16823- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
16824-})
16825+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
16826
16827 /*
16828 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
16829@@ -872,7 +867,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
16830 #define task_pt_regs(task) \
16831 ({ \
16832 struct pt_regs *__regs__; \
16833- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
16834+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
16835 __regs__ - 1; \
16836 })
16837
16838@@ -882,13 +877,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
16839 /*
16840 * User space process size. 47bits minus one guard page.
16841 */
16842-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
16843+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
16844
16845 /* This decides where the kernel will search for a free chunk of vm
16846 * space during mmap's.
16847 */
16848 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
16849- 0xc0000000 : 0xFFFFe000)
16850+ 0xc0000000 : 0xFFFFf000)
16851
16852 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
16853 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
16854@@ -899,11 +894,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
16855 #define STACK_TOP_MAX TASK_SIZE_MAX
16856
16857 #define INIT_THREAD { \
16858- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
16859+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
16860 }
16861
16862 #define INIT_TSS { \
16863- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
16864+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
16865 }
16866
16867 /*
16868@@ -931,6 +926,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
16869 */
16870 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
16871
16872+#ifdef CONFIG_PAX_SEGMEXEC
16873+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
16874+#endif
16875+
16876 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
16877
16878 /* Get/set a process' ability to use the timestamp counter instruction */
16879@@ -943,7 +942,8 @@ extern int set_tsc_mode(unsigned int val);
16880 extern u16 amd_get_nb_id(int cpu);
16881
16882 struct aperfmperf {
16883- u64 aperf, mperf;
16884+ u64 aperf __intentional_overflow(0);
16885+ u64 mperf __intentional_overflow(0);
16886 };
16887
16888 static inline void get_aperfmperf(struct aperfmperf *am)
16889@@ -971,7 +971,7 @@ unsigned long calc_aperfmperf_ratio(struct aperfmperf *old,
16890 return ratio;
16891 }
16892
16893-extern unsigned long arch_align_stack(unsigned long sp);
16894+#define arch_align_stack(x) ((x) & ~0xfUL)
16895 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
16896
16897 void default_idle(void);
16898@@ -981,6 +981,6 @@ bool xen_set_default_idle(void);
16899 #define xen_set_default_idle 0
16900 #endif
16901
16902-void stop_this_cpu(void *dummy);
16903+void stop_this_cpu(void *dummy) __noreturn;
16904 void df_debug(struct pt_regs *regs, long error_code);
16905 #endif /* _ASM_X86_PROCESSOR_H */
16906diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
16907index 942a086..6c26446 100644
16908--- a/arch/x86/include/asm/ptrace.h
16909+++ b/arch/x86/include/asm/ptrace.h
16910@@ -85,28 +85,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
16911 }
16912
16913 /*
16914- * user_mode_vm(regs) determines whether a register set came from user mode.
16915+ * user_mode(regs) determines whether a register set came from user mode.
16916 * This is true if V8086 mode was enabled OR if the register set was from
16917 * protected mode with RPL-3 CS value. This tricky test checks that with
16918 * one comparison. Many places in the kernel can bypass this full check
16919- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
16920+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
16921+ * be used.
16922 */
16923-static inline int user_mode(struct pt_regs *regs)
16924+static inline int user_mode_novm(struct pt_regs *regs)
16925 {
16926 #ifdef CONFIG_X86_32
16927 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
16928 #else
16929- return !!(regs->cs & 3);
16930+ return !!(regs->cs & SEGMENT_RPL_MASK);
16931 #endif
16932 }
16933
16934-static inline int user_mode_vm(struct pt_regs *regs)
16935+static inline int user_mode(struct pt_regs *regs)
16936 {
16937 #ifdef CONFIG_X86_32
16938 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
16939 USER_RPL;
16940 #else
16941- return user_mode(regs);
16942+ return user_mode_novm(regs);
16943 #endif
16944 }
16945
16946@@ -122,15 +123,16 @@ static inline int v8086_mode(struct pt_regs *regs)
16947 #ifdef CONFIG_X86_64
16948 static inline bool user_64bit_mode(struct pt_regs *regs)
16949 {
16950+ unsigned long cs = regs->cs & 0xffff;
16951 #ifndef CONFIG_PARAVIRT
16952 /*
16953 * On non-paravirt systems, this is the only long mode CPL 3
16954 * selector. We do not allow long mode selectors in the LDT.
16955 */
16956- return regs->cs == __USER_CS;
16957+ return cs == __USER_CS;
16958 #else
16959 /* Headers are too twisted for this to go in paravirt.h. */
16960- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
16961+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
16962 #endif
16963 }
16964
16965@@ -181,9 +183,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
16966 * Traps from the kernel do not save sp and ss.
16967 * Use the helper function to retrieve sp.
16968 */
16969- if (offset == offsetof(struct pt_regs, sp) &&
16970- regs->cs == __KERNEL_CS)
16971- return kernel_stack_pointer(regs);
16972+ if (offset == offsetof(struct pt_regs, sp)) {
16973+ unsigned long cs = regs->cs & 0xffff;
16974+ if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
16975+ return kernel_stack_pointer(regs);
16976+ }
16977 #endif
16978 return *(unsigned long *)((unsigned long)regs + offset);
16979 }
16980diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
16981index 9c6b890..5305f53 100644
16982--- a/arch/x86/include/asm/realmode.h
16983+++ b/arch/x86/include/asm/realmode.h
16984@@ -22,16 +22,14 @@ struct real_mode_header {
16985 #endif
16986 /* APM/BIOS reboot */
16987 u32 machine_real_restart_asm;
16988-#ifdef CONFIG_X86_64
16989 u32 machine_real_restart_seg;
16990-#endif
16991 };
16992
16993 /* This must match data at trampoline_32/64.S */
16994 struct trampoline_header {
16995 #ifdef CONFIG_X86_32
16996 u32 start;
16997- u16 gdt_pad;
16998+ u16 boot_cs;
16999 u16 gdt_limit;
17000 u32 gdt_base;
17001 #else
17002diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
17003index a82c4f1..ac45053 100644
17004--- a/arch/x86/include/asm/reboot.h
17005+++ b/arch/x86/include/asm/reboot.h
17006@@ -6,13 +6,13 @@
17007 struct pt_regs;
17008
17009 struct machine_ops {
17010- void (*restart)(char *cmd);
17011- void (*halt)(void);
17012- void (*power_off)(void);
17013+ void (* __noreturn restart)(char *cmd);
17014+ void (* __noreturn halt)(void);
17015+ void (* __noreturn power_off)(void);
17016 void (*shutdown)(void);
17017 void (*crash_shutdown)(struct pt_regs *);
17018- void (*emergency_restart)(void);
17019-};
17020+ void (* __noreturn emergency_restart)(void);
17021+} __no_const;
17022
17023 extern struct machine_ops machine_ops;
17024
17025diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
17026index cad82c9..2e5c5c1 100644
17027--- a/arch/x86/include/asm/rwsem.h
17028+++ b/arch/x86/include/asm/rwsem.h
17029@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
17030 {
17031 asm volatile("# beginning down_read\n\t"
17032 LOCK_PREFIX _ASM_INC "(%1)\n\t"
17033+
17034+#ifdef CONFIG_PAX_REFCOUNT
17035+ "jno 0f\n"
17036+ LOCK_PREFIX _ASM_DEC "(%1)\n"
17037+ "int $4\n0:\n"
17038+ _ASM_EXTABLE(0b, 0b)
17039+#endif
17040+
17041 /* adds 0x00000001 */
17042 " jns 1f\n"
17043 " call call_rwsem_down_read_failed\n"
17044@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
17045 "1:\n\t"
17046 " mov %1,%2\n\t"
17047 " add %3,%2\n\t"
17048+
17049+#ifdef CONFIG_PAX_REFCOUNT
17050+ "jno 0f\n"
17051+ "sub %3,%2\n"
17052+ "int $4\n0:\n"
17053+ _ASM_EXTABLE(0b, 0b)
17054+#endif
17055+
17056 " jle 2f\n\t"
17057 LOCK_PREFIX " cmpxchg %2,%0\n\t"
17058 " jnz 1b\n\t"
17059@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
17060 long tmp;
17061 asm volatile("# beginning down_write\n\t"
17062 LOCK_PREFIX " xadd %1,(%2)\n\t"
17063+
17064+#ifdef CONFIG_PAX_REFCOUNT
17065+ "jno 0f\n"
17066+ "mov %1,(%2)\n"
17067+ "int $4\n0:\n"
17068+ _ASM_EXTABLE(0b, 0b)
17069+#endif
17070+
17071 /* adds 0xffff0001, returns the old value */
17072 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
17073 /* was the active mask 0 before? */
17074@@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
17075 long tmp;
17076 asm volatile("# beginning __up_read\n\t"
17077 LOCK_PREFIX " xadd %1,(%2)\n\t"
17078+
17079+#ifdef CONFIG_PAX_REFCOUNT
17080+ "jno 0f\n"
17081+ "mov %1,(%2)\n"
17082+ "int $4\n0:\n"
17083+ _ASM_EXTABLE(0b, 0b)
17084+#endif
17085+
17086 /* subtracts 1, returns the old value */
17087 " jns 1f\n\t"
17088 " call call_rwsem_wake\n" /* expects old value in %edx */
17089@@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
17090 long tmp;
17091 asm volatile("# beginning __up_write\n\t"
17092 LOCK_PREFIX " xadd %1,(%2)\n\t"
17093+
17094+#ifdef CONFIG_PAX_REFCOUNT
17095+ "jno 0f\n"
17096+ "mov %1,(%2)\n"
17097+ "int $4\n0:\n"
17098+ _ASM_EXTABLE(0b, 0b)
17099+#endif
17100+
17101 /* subtracts 0xffff0001, returns the old value */
17102 " jns 1f\n\t"
17103 " call call_rwsem_wake\n" /* expects old value in %edx */
17104@@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
17105 {
17106 asm volatile("# beginning __downgrade_write\n\t"
17107 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
17108+
17109+#ifdef CONFIG_PAX_REFCOUNT
17110+ "jno 0f\n"
17111+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
17112+ "int $4\n0:\n"
17113+ _ASM_EXTABLE(0b, 0b)
17114+#endif
17115+
17116 /*
17117 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
17118 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
17119@@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
17120 */
17121 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
17122 {
17123- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
17124+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
17125+
17126+#ifdef CONFIG_PAX_REFCOUNT
17127+ "jno 0f\n"
17128+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
17129+ "int $4\n0:\n"
17130+ _ASM_EXTABLE(0b, 0b)
17131+#endif
17132+
17133 : "+m" (sem->count)
17134 : "er" (delta));
17135 }
17136@@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
17137 */
17138 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
17139 {
17140- return delta + xadd(&sem->count, delta);
17141+ return delta + xadd_check_overflow(&sem->count, delta);
17142 }
17143
17144 #endif /* __KERNEL__ */
17145diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
17146index c48a950..bc40804 100644
17147--- a/arch/x86/include/asm/segment.h
17148+++ b/arch/x86/include/asm/segment.h
17149@@ -64,10 +64,15 @@
17150 * 26 - ESPFIX small SS
17151 * 27 - per-cpu [ offset to per-cpu data area ]
17152 * 28 - stack_canary-20 [ for stack protector ]
17153- * 29 - unused
17154- * 30 - unused
17155+ * 29 - PCI BIOS CS
17156+ * 30 - PCI BIOS DS
17157 * 31 - TSS for double fault handler
17158 */
17159+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
17160+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
17161+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
17162+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
17163+
17164 #define GDT_ENTRY_TLS_MIN 6
17165 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
17166
17167@@ -79,6 +84,8 @@
17168
17169 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
17170
17171+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
17172+
17173 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
17174
17175 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
17176@@ -104,6 +111,12 @@
17177 #define __KERNEL_STACK_CANARY 0
17178 #endif
17179
17180+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
17181+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
17182+
17183+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
17184+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
17185+
17186 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
17187
17188 /*
17189@@ -141,7 +154,7 @@
17190 */
17191
17192 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
17193-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
17194+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
17195
17196
17197 #else
17198@@ -165,6 +178,8 @@
17199 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
17200 #define __USER32_DS __USER_DS
17201
17202+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
17203+
17204 #define GDT_ENTRY_TSS 8 /* needs two entries */
17205 #define GDT_ENTRY_LDT 10 /* needs two entries */
17206 #define GDT_ENTRY_TLS_MIN 12
17207@@ -173,6 +188,8 @@
17208 #define GDT_ENTRY_PER_CPU 15 /* Abused to load per CPU data from limit */
17209 #define __PER_CPU_SEG (GDT_ENTRY_PER_CPU * 8 + 3)
17210
17211+#define GDT_ENTRY_UDEREF_KERNEL_DS 16
17212+
17213 /* TLS indexes for 64bit - hardcoded in arch_prctl */
17214 #define FS_TLS 0
17215 #define GS_TLS 1
17216@@ -180,12 +197,14 @@
17217 #define GS_TLS_SEL ((GDT_ENTRY_TLS_MIN+GS_TLS)*8 + 3)
17218 #define FS_TLS_SEL ((GDT_ENTRY_TLS_MIN+FS_TLS)*8 + 3)
17219
17220-#define GDT_ENTRIES 16
17221+#define GDT_ENTRIES 17
17222
17223 #endif
17224
17225 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
17226+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
17227 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
17228+#define __UDEREF_KERNEL_DS (GDT_ENTRY_UDEREF_KERNEL_DS*8)
17229 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
17230 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
17231 #ifndef CONFIG_PARAVIRT
17232@@ -265,7 +284,7 @@ static inline unsigned long get_limit(unsigned long segment)
17233 {
17234 unsigned long __limit;
17235 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
17236- return __limit + 1;
17237+ return __limit;
17238 }
17239
17240 #endif /* !__ASSEMBLY__ */
17241diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
17242index 8d3120f..352b440 100644
17243--- a/arch/x86/include/asm/smap.h
17244+++ b/arch/x86/include/asm/smap.h
17245@@ -25,11 +25,40 @@
17246
17247 #include <asm/alternative-asm.h>
17248
17249+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17250+#define ASM_PAX_OPEN_USERLAND \
17251+ 661: jmp 663f; \
17252+ .pushsection .altinstr_replacement, "a" ; \
17253+ 662: pushq %rax; nop; \
17254+ .popsection ; \
17255+ .pushsection .altinstructions, "a" ; \
17256+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
17257+ .popsection ; \
17258+ call __pax_open_userland; \
17259+ popq %rax; \
17260+ 663:
17261+
17262+#define ASM_PAX_CLOSE_USERLAND \
17263+ 661: jmp 663f; \
17264+ .pushsection .altinstr_replacement, "a" ; \
17265+ 662: pushq %rax; nop; \
17266+ .popsection; \
17267+ .pushsection .altinstructions, "a" ; \
17268+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
17269+ .popsection; \
17270+ call __pax_close_userland; \
17271+ popq %rax; \
17272+ 663:
17273+#else
17274+#define ASM_PAX_OPEN_USERLAND
17275+#define ASM_PAX_CLOSE_USERLAND
17276+#endif
17277+
17278 #ifdef CONFIG_X86_SMAP
17279
17280 #define ASM_CLAC \
17281 661: ASM_NOP3 ; \
17282- .pushsection .altinstr_replacement, "ax" ; \
17283+ .pushsection .altinstr_replacement, "a" ; \
17284 662: __ASM_CLAC ; \
17285 .popsection ; \
17286 .pushsection .altinstructions, "a" ; \
17287@@ -38,7 +67,7 @@
17288
17289 #define ASM_STAC \
17290 661: ASM_NOP3 ; \
17291- .pushsection .altinstr_replacement, "ax" ; \
17292+ .pushsection .altinstr_replacement, "a" ; \
17293 662: __ASM_STAC ; \
17294 .popsection ; \
17295 .pushsection .altinstructions, "a" ; \
17296@@ -56,6 +85,37 @@
17297
17298 #include <asm/alternative.h>
17299
17300+#define __HAVE_ARCH_PAX_OPEN_USERLAND
17301+#define __HAVE_ARCH_PAX_CLOSE_USERLAND
17302+
17303+extern void __pax_open_userland(void);
17304+static __always_inline unsigned long pax_open_userland(void)
17305+{
17306+
17307+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17308+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[open]", X86_FEATURE_STRONGUDEREF)
17309+ :
17310+ : [open] "i" (__pax_open_userland)
17311+ : "memory", "rax");
17312+#endif
17313+
17314+ return 0;
17315+}
17316+
17317+extern void __pax_close_userland(void);
17318+static __always_inline unsigned long pax_close_userland(void)
17319+{
17320+
17321+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17322+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[close]", X86_FEATURE_STRONGUDEREF)
17323+ :
17324+ : [close] "i" (__pax_close_userland)
17325+ : "memory", "rax");
17326+#endif
17327+
17328+ return 0;
17329+}
17330+
17331 #ifdef CONFIG_X86_SMAP
17332
17333 static __always_inline void clac(void)
17334diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
17335index 4137890..03fa172 100644
17336--- a/arch/x86/include/asm/smp.h
17337+++ b/arch/x86/include/asm/smp.h
17338@@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
17339 /* cpus sharing the last level cache: */
17340 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
17341 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
17342-DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
17343+DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
17344
17345 static inline struct cpumask *cpu_sibling_mask(int cpu)
17346 {
17347@@ -79,7 +79,7 @@ struct smp_ops {
17348
17349 void (*send_call_func_ipi)(const struct cpumask *mask);
17350 void (*send_call_func_single_ipi)(int cpu);
17351-};
17352+} __no_const;
17353
17354 /* Globals due to paravirt */
17355 extern void set_cpu_sibling_map(int cpu);
17356@@ -191,14 +191,8 @@ extern unsigned disabled_cpus;
17357 extern int safe_smp_processor_id(void);
17358
17359 #elif defined(CONFIG_X86_64_SMP)
17360-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
17361-
17362-#define stack_smp_processor_id() \
17363-({ \
17364- struct thread_info *ti; \
17365- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
17366- ti->cpu; \
17367-})
17368+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
17369+#define stack_smp_processor_id() raw_smp_processor_id()
17370 #define safe_smp_processor_id() smp_processor_id()
17371
17372 #endif
17373diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
17374index e3ddd7d..3611fce 100644
17375--- a/arch/x86/include/asm/spinlock.h
17376+++ b/arch/x86/include/asm/spinlock.h
17377@@ -172,6 +172,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
17378 static inline void arch_read_lock(arch_rwlock_t *rw)
17379 {
17380 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
17381+
17382+#ifdef CONFIG_PAX_REFCOUNT
17383+ "jno 0f\n"
17384+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
17385+ "int $4\n0:\n"
17386+ _ASM_EXTABLE(0b, 0b)
17387+#endif
17388+
17389 "jns 1f\n"
17390 "call __read_lock_failed\n\t"
17391 "1:\n"
17392@@ -181,6 +189,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
17393 static inline void arch_write_lock(arch_rwlock_t *rw)
17394 {
17395 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
17396+
17397+#ifdef CONFIG_PAX_REFCOUNT
17398+ "jno 0f\n"
17399+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
17400+ "int $4\n0:\n"
17401+ _ASM_EXTABLE(0b, 0b)
17402+#endif
17403+
17404 "jz 1f\n"
17405 "call __write_lock_failed\n\t"
17406 "1:\n"
17407@@ -210,13 +226,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
17408
17409 static inline void arch_read_unlock(arch_rwlock_t *rw)
17410 {
17411- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
17412+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
17413+
17414+#ifdef CONFIG_PAX_REFCOUNT
17415+ "jno 0f\n"
17416+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
17417+ "int $4\n0:\n"
17418+ _ASM_EXTABLE(0b, 0b)
17419+#endif
17420+
17421 :"+m" (rw->lock) : : "memory");
17422 }
17423
17424 static inline void arch_write_unlock(arch_rwlock_t *rw)
17425 {
17426- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
17427+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
17428+
17429+#ifdef CONFIG_PAX_REFCOUNT
17430+ "jno 0f\n"
17431+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
17432+ "int $4\n0:\n"
17433+ _ASM_EXTABLE(0b, 0b)
17434+#endif
17435+
17436 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
17437 }
17438
17439diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
17440index 6a99859..03cb807 100644
17441--- a/arch/x86/include/asm/stackprotector.h
17442+++ b/arch/x86/include/asm/stackprotector.h
17443@@ -47,7 +47,7 @@
17444 * head_32 for boot CPU and setup_per_cpu_areas() for others.
17445 */
17446 #define GDT_STACK_CANARY_INIT \
17447- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
17448+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
17449
17450 /*
17451 * Initialize the stackprotector canary value.
17452@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
17453
17454 static inline void load_stack_canary_segment(void)
17455 {
17456-#ifdef CONFIG_X86_32
17457+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
17458 asm volatile ("mov %0, %%gs" : : "r" (0));
17459 #endif
17460 }
17461diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
17462index 70bbe39..4ae2bd4 100644
17463--- a/arch/x86/include/asm/stacktrace.h
17464+++ b/arch/x86/include/asm/stacktrace.h
17465@@ -11,28 +11,20 @@
17466
17467 extern int kstack_depth_to_print;
17468
17469-struct thread_info;
17470+struct task_struct;
17471 struct stacktrace_ops;
17472
17473-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
17474- unsigned long *stack,
17475- unsigned long bp,
17476- const struct stacktrace_ops *ops,
17477- void *data,
17478- unsigned long *end,
17479- int *graph);
17480+typedef unsigned long walk_stack_t(struct task_struct *task,
17481+ void *stack_start,
17482+ unsigned long *stack,
17483+ unsigned long bp,
17484+ const struct stacktrace_ops *ops,
17485+ void *data,
17486+ unsigned long *end,
17487+ int *graph);
17488
17489-extern unsigned long
17490-print_context_stack(struct thread_info *tinfo,
17491- unsigned long *stack, unsigned long bp,
17492- const struct stacktrace_ops *ops, void *data,
17493- unsigned long *end, int *graph);
17494-
17495-extern unsigned long
17496-print_context_stack_bp(struct thread_info *tinfo,
17497- unsigned long *stack, unsigned long bp,
17498- const struct stacktrace_ops *ops, void *data,
17499- unsigned long *end, int *graph);
17500+extern walk_stack_t print_context_stack;
17501+extern walk_stack_t print_context_stack_bp;
17502
17503 /* Generic stack tracer with callbacks */
17504
17505@@ -40,7 +32,7 @@ struct stacktrace_ops {
17506 void (*address)(void *data, unsigned long address, int reliable);
17507 /* On negative return stop dumping */
17508 int (*stack)(void *data, char *name);
17509- walk_stack_t walk_stack;
17510+ walk_stack_t *walk_stack;
17511 };
17512
17513 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
17514diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
17515index 4ec45b3..a4f0a8a 100644
17516--- a/arch/x86/include/asm/switch_to.h
17517+++ b/arch/x86/include/asm/switch_to.h
17518@@ -108,7 +108,7 @@ do { \
17519 "call __switch_to\n\t" \
17520 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
17521 __switch_canary \
17522- "movq %P[thread_info](%%rsi),%%r8\n\t" \
17523+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
17524 "movq %%rax,%%rdi\n\t" \
17525 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
17526 "jnz ret_from_fork\n\t" \
17527@@ -119,7 +119,7 @@ do { \
17528 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
17529 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
17530 [_tif_fork] "i" (_TIF_FORK), \
17531- [thread_info] "i" (offsetof(struct task_struct, stack)), \
17532+ [thread_info] "m" (current_tinfo), \
17533 [current_task] "m" (current_task) \
17534 __switch_canary_iparam \
17535 : "memory", "cc" __EXTRA_CLOBBER)
17536diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
17537index 2781119..618b59b 100644
17538--- a/arch/x86/include/asm/thread_info.h
17539+++ b/arch/x86/include/asm/thread_info.h
17540@@ -10,6 +10,7 @@
17541 #include <linux/compiler.h>
17542 #include <asm/page.h>
17543 #include <asm/types.h>
17544+#include <asm/percpu.h>
17545
17546 /*
17547 * low level task data that entry.S needs immediate access to
17548@@ -23,7 +24,6 @@ struct exec_domain;
17549 #include <linux/atomic.h>
17550
17551 struct thread_info {
17552- struct task_struct *task; /* main task structure */
17553 struct exec_domain *exec_domain; /* execution domain */
17554 __u32 flags; /* low level flags */
17555 __u32 status; /* thread synchronous flags */
17556@@ -33,19 +33,13 @@ struct thread_info {
17557 mm_segment_t addr_limit;
17558 struct restart_block restart_block;
17559 void __user *sysenter_return;
17560-#ifdef CONFIG_X86_32
17561- unsigned long previous_esp; /* ESP of the previous stack in
17562- case of nested (IRQ) stacks
17563- */
17564- __u8 supervisor_stack[0];
17565-#endif
17566+ unsigned long lowest_stack;
17567 unsigned int sig_on_uaccess_error:1;
17568 unsigned int uaccess_err:1; /* uaccess failed */
17569 };
17570
17571-#define INIT_THREAD_INFO(tsk) \
17572+#define INIT_THREAD_INFO \
17573 { \
17574- .task = &tsk, \
17575 .exec_domain = &default_exec_domain, \
17576 .flags = 0, \
17577 .cpu = 0, \
17578@@ -56,7 +50,7 @@ struct thread_info {
17579 }, \
17580 }
17581
17582-#define init_thread_info (init_thread_union.thread_info)
17583+#define init_thread_info (init_thread_union.stack)
17584 #define init_stack (init_thread_union.stack)
17585
17586 #else /* !__ASSEMBLY__ */
17587@@ -96,6 +90,7 @@ struct thread_info {
17588 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
17589 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
17590 #define TIF_X32 30 /* 32-bit native x86-64 binary */
17591+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
17592
17593 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
17594 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
17595@@ -119,17 +114,18 @@ struct thread_info {
17596 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
17597 #define _TIF_ADDR32 (1 << TIF_ADDR32)
17598 #define _TIF_X32 (1 << TIF_X32)
17599+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
17600
17601 /* work to do in syscall_trace_enter() */
17602 #define _TIF_WORK_SYSCALL_ENTRY \
17603 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
17604 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
17605- _TIF_NOHZ)
17606+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
17607
17608 /* work to do in syscall_trace_leave() */
17609 #define _TIF_WORK_SYSCALL_EXIT \
17610 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
17611- _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
17612+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
17613
17614 /* work to do on interrupt/exception return */
17615 #define _TIF_WORK_MASK \
17616@@ -140,7 +136,7 @@ struct thread_info {
17617 /* work to do on any return to user space */
17618 #define _TIF_ALLWORK_MASK \
17619 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
17620- _TIF_NOHZ)
17621+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
17622
17623 /* Only used for 64 bit */
17624 #define _TIF_DO_NOTIFY_MASK \
17625@@ -156,45 +152,40 @@ struct thread_info {
17626
17627 #define PREEMPT_ACTIVE 0x10000000
17628
17629-#ifdef CONFIG_X86_32
17630-
17631-#define STACK_WARN (THREAD_SIZE/8)
17632-/*
17633- * macros/functions for gaining access to the thread information structure
17634- *
17635- * preempt_count needs to be 1 initially, until the scheduler is functional.
17636- */
17637-#ifndef __ASSEMBLY__
17638-
17639-
17640-/* how to get the current stack pointer from C */
17641-register unsigned long current_stack_pointer asm("esp") __used;
17642-
17643-/* how to get the thread information struct from C */
17644-static inline struct thread_info *current_thread_info(void)
17645-{
17646- return (struct thread_info *)
17647- (current_stack_pointer & ~(THREAD_SIZE - 1));
17648-}
17649-
17650-#else /* !__ASSEMBLY__ */
17651-
17652+#ifdef __ASSEMBLY__
17653 /* how to get the thread information struct from ASM */
17654 #define GET_THREAD_INFO(reg) \
17655- movl $-THREAD_SIZE, reg; \
17656- andl %esp, reg
17657+ mov PER_CPU_VAR(current_tinfo), reg
17658
17659 /* use this one if reg already contains %esp */
17660-#define GET_THREAD_INFO_WITH_ESP(reg) \
17661- andl $-THREAD_SIZE, reg
17662+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
17663+#else
17664+/* how to get the thread information struct from C */
17665+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
17666+
17667+static __always_inline struct thread_info *current_thread_info(void)
17668+{
17669+ return this_cpu_read_stable(current_tinfo);
17670+}
17671+#endif
17672+
17673+#ifdef CONFIG_X86_32
17674+
17675+#define STACK_WARN (THREAD_SIZE/8)
17676+/*
17677+ * macros/functions for gaining access to the thread information structure
17678+ *
17679+ * preempt_count needs to be 1 initially, until the scheduler is functional.
17680+ */
17681+#ifndef __ASSEMBLY__
17682+
17683+/* how to get the current stack pointer from C */
17684+register unsigned long current_stack_pointer asm("esp") __used;
17685
17686 #endif
17687
17688 #else /* X86_32 */
17689
17690-#include <asm/percpu.h>
17691-#define KERNEL_STACK_OFFSET (5*8)
17692-
17693 /*
17694 * macros/functions for gaining access to the thread information structure
17695 * preempt_count needs to be 1 initially, until the scheduler is functional.
17696@@ -202,27 +193,8 @@ static inline struct thread_info *current_thread_info(void)
17697 #ifndef __ASSEMBLY__
17698 DECLARE_PER_CPU(unsigned long, kernel_stack);
17699
17700-static inline struct thread_info *current_thread_info(void)
17701-{
17702- struct thread_info *ti;
17703- ti = (void *)(this_cpu_read_stable(kernel_stack) +
17704- KERNEL_STACK_OFFSET - THREAD_SIZE);
17705- return ti;
17706-}
17707-
17708-#else /* !__ASSEMBLY__ */
17709-
17710-/* how to get the thread information struct from ASM */
17711-#define GET_THREAD_INFO(reg) \
17712- movq PER_CPU_VAR(kernel_stack),reg ; \
17713- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
17714-
17715-/*
17716- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
17717- * a certain register (to be used in assembler memory operands).
17718- */
17719-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
17720-
17721+/* how to get the current stack pointer from C */
17722+register unsigned long current_stack_pointer asm("rsp") __used;
17723 #endif
17724
17725 #endif /* !X86_32 */
17726@@ -281,5 +253,12 @@ static inline bool is_ia32_task(void)
17727 extern void arch_task_cache_init(void);
17728 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
17729 extern void arch_release_task_struct(struct task_struct *tsk);
17730+
17731+#define __HAVE_THREAD_FUNCTIONS
17732+#define task_thread_info(task) (&(task)->tinfo)
17733+#define task_stack_page(task) ((task)->stack)
17734+#define setup_thread_stack(p, org) do {} while (0)
17735+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
17736+
17737 #endif
17738 #endif /* _ASM_X86_THREAD_INFO_H */
17739diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
17740index cf51200..63ff068 100644
17741--- a/arch/x86/include/asm/tlbflush.h
17742+++ b/arch/x86/include/asm/tlbflush.h
17743@@ -17,18 +17,44 @@
17744
17745 static inline void __native_flush_tlb(void)
17746 {
17747+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
17748+ u64 descriptor[2];
17749+
17750+ descriptor[0] = PCID_KERNEL;
17751+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_MONGLOBAL) : "memory");
17752+ return;
17753+ }
17754+
17755+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17756+ if (static_cpu_has(X86_FEATURE_PCID)) {
17757+ unsigned int cpu = raw_get_cpu();
17758+
17759+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17760+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17761+ raw_put_cpu_no_resched();
17762+ return;
17763+ }
17764+#endif
17765+
17766 native_write_cr3(native_read_cr3());
17767 }
17768
17769 static inline void __native_flush_tlb_global_irq_disabled(void)
17770 {
17771- unsigned long cr4;
17772+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
17773+ u64 descriptor[2];
17774
17775- cr4 = native_read_cr4();
17776- /* clear PGE */
17777- native_write_cr4(cr4 & ~X86_CR4_PGE);
17778- /* write old PGE again and flush TLBs */
17779- native_write_cr4(cr4);
17780+ descriptor[0] = PCID_KERNEL;
17781+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_GLOBAL) : "memory");
17782+ } else {
17783+ unsigned long cr4;
17784+
17785+ cr4 = native_read_cr4();
17786+ /* clear PGE */
17787+ native_write_cr4(cr4 & ~X86_CR4_PGE);
17788+ /* write old PGE again and flush TLBs */
17789+ native_write_cr4(cr4);
17790+ }
17791 }
17792
17793 static inline void __native_flush_tlb_global(void)
17794@@ -49,6 +75,42 @@ static inline void __native_flush_tlb_global(void)
17795
17796 static inline void __native_flush_tlb_single(unsigned long addr)
17797 {
17798+
17799+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
17800+ u64 descriptor[2];
17801+
17802+ descriptor[0] = PCID_KERNEL;
17803+ descriptor[1] = addr;
17804+
17805+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17806+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) || addr >= TASK_SIZE_MAX) {
17807+ if (addr < TASK_SIZE_MAX)
17808+ descriptor[1] += pax_user_shadow_base;
17809+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
17810+ }
17811+
17812+ descriptor[0] = PCID_USER;
17813+ descriptor[1] = addr;
17814+#endif
17815+
17816+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
17817+ return;
17818+ }
17819+
17820+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17821+ if (static_cpu_has(X86_FEATURE_PCID)) {
17822+ unsigned int cpu = raw_get_cpu();
17823+
17824+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
17825+ asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
17826+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17827+ raw_put_cpu_no_resched();
17828+
17829+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) && addr < TASK_SIZE_MAX)
17830+ addr += pax_user_shadow_base;
17831+ }
17832+#endif
17833+
17834 asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
17835 }
17836
17837diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
17838index 5ee2687..74590b9 100644
17839--- a/arch/x86/include/asm/uaccess.h
17840+++ b/arch/x86/include/asm/uaccess.h
17841@@ -7,6 +7,7 @@
17842 #include <linux/compiler.h>
17843 #include <linux/thread_info.h>
17844 #include <linux/string.h>
17845+#include <linux/sched.h>
17846 #include <asm/asm.h>
17847 #include <asm/page.h>
17848 #include <asm/smap.h>
17849@@ -29,7 +30,12 @@
17850
17851 #define get_ds() (KERNEL_DS)
17852 #define get_fs() (current_thread_info()->addr_limit)
17853+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
17854+void __set_fs(mm_segment_t x);
17855+void set_fs(mm_segment_t x);
17856+#else
17857 #define set_fs(x) (current_thread_info()->addr_limit = (x))
17858+#endif
17859
17860 #define segment_eq(a, b) ((a).seg == (b).seg)
17861
17862@@ -77,8 +83,33 @@
17863 * checks that the pointer is in the user space range - after calling
17864 * this function, memory access functions may still return -EFAULT.
17865 */
17866-#define access_ok(type, addr, size) \
17867- (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
17868+#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
17869+#define access_ok(type, addr, size) \
17870+({ \
17871+ long __size = size; \
17872+ unsigned long __addr = (unsigned long)addr; \
17873+ unsigned long __addr_ao = __addr & PAGE_MASK; \
17874+ unsigned long __end_ao = __addr + __size - 1; \
17875+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
17876+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
17877+ while(__addr_ao <= __end_ao) { \
17878+ char __c_ao; \
17879+ __addr_ao += PAGE_SIZE; \
17880+ if (__size > PAGE_SIZE) \
17881+ cond_resched(); \
17882+ if (__get_user(__c_ao, (char __user *)__addr)) \
17883+ break; \
17884+ if (type != VERIFY_WRITE) { \
17885+ __addr = __addr_ao; \
17886+ continue; \
17887+ } \
17888+ if (__put_user(__c_ao, (char __user *)__addr)) \
17889+ break; \
17890+ __addr = __addr_ao; \
17891+ } \
17892+ } \
17893+ __ret_ao; \
17894+})
17895
17896 /*
17897 * The exception table consists of pairs of addresses relative to the
17898@@ -165,10 +196,12 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
17899 register __inttype(*(ptr)) __val_gu asm("%edx"); \
17900 __chk_user_ptr(ptr); \
17901 might_fault(); \
17902+ pax_open_userland(); \
17903 asm volatile("call __get_user_%P3" \
17904 : "=a" (__ret_gu), "=r" (__val_gu) \
17905 : "0" (ptr), "i" (sizeof(*(ptr)))); \
17906 (x) = (__typeof__(*(ptr))) __val_gu; \
17907+ pax_close_userland(); \
17908 __ret_gu; \
17909 })
17910
17911@@ -176,13 +209,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
17912 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
17913 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
17914
17915-
17916+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
17917+#define __copyuser_seg "gs;"
17918+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
17919+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
17920+#else
17921+#define __copyuser_seg
17922+#define __COPYUSER_SET_ES
17923+#define __COPYUSER_RESTORE_ES
17924+#endif
17925
17926 #ifdef CONFIG_X86_32
17927 #define __put_user_asm_u64(x, addr, err, errret) \
17928 asm volatile(ASM_STAC "\n" \
17929- "1: movl %%eax,0(%2)\n" \
17930- "2: movl %%edx,4(%2)\n" \
17931+ "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
17932+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
17933 "3: " ASM_CLAC "\n" \
17934 ".section .fixup,\"ax\"\n" \
17935 "4: movl %3,%0\n" \
17936@@ -195,8 +236,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
17937
17938 #define __put_user_asm_ex_u64(x, addr) \
17939 asm volatile(ASM_STAC "\n" \
17940- "1: movl %%eax,0(%1)\n" \
17941- "2: movl %%edx,4(%1)\n" \
17942+ "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
17943+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
17944 "3: " ASM_CLAC "\n" \
17945 _ASM_EXTABLE_EX(1b, 2b) \
17946 _ASM_EXTABLE_EX(2b, 3b) \
17947@@ -246,7 +287,8 @@ extern void __put_user_8(void);
17948 __typeof__(*(ptr)) __pu_val; \
17949 __chk_user_ptr(ptr); \
17950 might_fault(); \
17951- __pu_val = x; \
17952+ __pu_val = (x); \
17953+ pax_open_userland(); \
17954 switch (sizeof(*(ptr))) { \
17955 case 1: \
17956 __put_user_x(1, __pu_val, ptr, __ret_pu); \
17957@@ -264,6 +306,7 @@ extern void __put_user_8(void);
17958 __put_user_x(X, __pu_val, ptr, __ret_pu); \
17959 break; \
17960 } \
17961+ pax_close_userland(); \
17962 __ret_pu; \
17963 })
17964
17965@@ -344,8 +387,10 @@ do { \
17966 } while (0)
17967
17968 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
17969+do { \
17970+ pax_open_userland(); \
17971 asm volatile(ASM_STAC "\n" \
17972- "1: mov"itype" %2,%"rtype"1\n" \
17973+ "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
17974 "2: " ASM_CLAC "\n" \
17975 ".section .fixup,\"ax\"\n" \
17976 "3: mov %3,%0\n" \
17977@@ -353,8 +398,10 @@ do { \
17978 " jmp 2b\n" \
17979 ".previous\n" \
17980 _ASM_EXTABLE(1b, 3b) \
17981- : "=r" (err), ltype(x) \
17982- : "m" (__m(addr)), "i" (errret), "0" (err))
17983+ : "=r" (err), ltype (x) \
17984+ : "m" (__m(addr)), "i" (errret), "0" (err)); \
17985+ pax_close_userland(); \
17986+} while (0)
17987
17988 #define __get_user_size_ex(x, ptr, size) \
17989 do { \
17990@@ -378,7 +425,7 @@ do { \
17991 } while (0)
17992
17993 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
17994- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
17995+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
17996 "2:\n" \
17997 _ASM_EXTABLE_EX(1b, 2b) \
17998 : ltype(x) : "m" (__m(addr)))
17999@@ -395,13 +442,24 @@ do { \
18000 int __gu_err; \
18001 unsigned long __gu_val; \
18002 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
18003- (x) = (__force __typeof__(*(ptr)))__gu_val; \
18004+ (x) = (__typeof__(*(ptr)))__gu_val; \
18005 __gu_err; \
18006 })
18007
18008 /* FIXME: this hack is definitely wrong -AK */
18009 struct __large_struct { unsigned long buf[100]; };
18010-#define __m(x) (*(struct __large_struct __user *)(x))
18011+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18012+#define ____m(x) \
18013+({ \
18014+ unsigned long ____x = (unsigned long)(x); \
18015+ if (____x < pax_user_shadow_base) \
18016+ ____x += pax_user_shadow_base; \
18017+ (typeof(x))____x; \
18018+})
18019+#else
18020+#define ____m(x) (x)
18021+#endif
18022+#define __m(x) (*(struct __large_struct __user *)____m(x))
18023
18024 /*
18025 * Tell gcc we read from memory instead of writing: this is because
18026@@ -409,8 +467,10 @@ struct __large_struct { unsigned long buf[100]; };
18027 * aliasing issues.
18028 */
18029 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
18030+do { \
18031+ pax_open_userland(); \
18032 asm volatile(ASM_STAC "\n" \
18033- "1: mov"itype" %"rtype"1,%2\n" \
18034+ "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
18035 "2: " ASM_CLAC "\n" \
18036 ".section .fixup,\"ax\"\n" \
18037 "3: mov %3,%0\n" \
18038@@ -418,10 +478,12 @@ struct __large_struct { unsigned long buf[100]; };
18039 ".previous\n" \
18040 _ASM_EXTABLE(1b, 3b) \
18041 : "=r"(err) \
18042- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
18043+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err));\
18044+ pax_close_userland(); \
18045+} while (0)
18046
18047 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
18048- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
18049+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
18050 "2:\n" \
18051 _ASM_EXTABLE_EX(1b, 2b) \
18052 : : ltype(x), "m" (__m(addr)))
18053@@ -431,11 +493,13 @@ struct __large_struct { unsigned long buf[100]; };
18054 */
18055 #define uaccess_try do { \
18056 current_thread_info()->uaccess_err = 0; \
18057+ pax_open_userland(); \
18058 stac(); \
18059 barrier();
18060
18061 #define uaccess_catch(err) \
18062 clac(); \
18063+ pax_close_userland(); \
18064 (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
18065 } while (0)
18066
18067@@ -460,8 +524,12 @@ struct __large_struct { unsigned long buf[100]; };
18068 * On error, the variable @x is set to zero.
18069 */
18070
18071+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18072+#define __get_user(x, ptr) get_user((x), (ptr))
18073+#else
18074 #define __get_user(x, ptr) \
18075 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
18076+#endif
18077
18078 /**
18079 * __put_user: - Write a simple value into user space, with less checking.
18080@@ -483,8 +551,12 @@ struct __large_struct { unsigned long buf[100]; };
18081 * Returns zero on success, or -EFAULT on error.
18082 */
18083
18084+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18085+#define __put_user(x, ptr) put_user((x), (ptr))
18086+#else
18087 #define __put_user(x, ptr) \
18088 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
18089+#endif
18090
18091 #define __get_user_unaligned __get_user
18092 #define __put_user_unaligned __put_user
18093@@ -502,7 +574,7 @@ struct __large_struct { unsigned long buf[100]; };
18094 #define get_user_ex(x, ptr) do { \
18095 unsigned long __gue_val; \
18096 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
18097- (x) = (__force __typeof__(*(ptr)))__gue_val; \
18098+ (x) = (__typeof__(*(ptr)))__gue_val; \
18099 } while (0)
18100
18101 #define put_user_try uaccess_try
18102@@ -519,8 +591,8 @@ strncpy_from_user(char *dst, const char __user *src, long count);
18103 extern __must_check long strlen_user(const char __user *str);
18104 extern __must_check long strnlen_user(const char __user *str, long n);
18105
18106-unsigned long __must_check clear_user(void __user *mem, unsigned long len);
18107-unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
18108+unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
18109+unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
18110
18111 /*
18112 * movsl can be slow when source and dest are not both 8-byte aligned
18113diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
18114index 7f760a9..04b1c65 100644
18115--- a/arch/x86/include/asm/uaccess_32.h
18116+++ b/arch/x86/include/asm/uaccess_32.h
18117@@ -11,15 +11,15 @@
18118 #include <asm/page.h>
18119
18120 unsigned long __must_check __copy_to_user_ll
18121- (void __user *to, const void *from, unsigned long n);
18122+ (void __user *to, const void *from, unsigned long n) __size_overflow(3);
18123 unsigned long __must_check __copy_from_user_ll
18124- (void *to, const void __user *from, unsigned long n);
18125+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
18126 unsigned long __must_check __copy_from_user_ll_nozero
18127- (void *to, const void __user *from, unsigned long n);
18128+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
18129 unsigned long __must_check __copy_from_user_ll_nocache
18130- (void *to, const void __user *from, unsigned long n);
18131+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
18132 unsigned long __must_check __copy_from_user_ll_nocache_nozero
18133- (void *to, const void __user *from, unsigned long n);
18134+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
18135
18136 /**
18137 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
18138@@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
18139 static __always_inline unsigned long __must_check
18140 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
18141 {
18142+ if ((long)n < 0)
18143+ return n;
18144+
18145+ check_object_size(from, n, true);
18146+
18147 if (__builtin_constant_p(n)) {
18148 unsigned long ret;
18149
18150@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
18151 __copy_to_user(void __user *to, const void *from, unsigned long n)
18152 {
18153 might_fault();
18154+
18155 return __copy_to_user_inatomic(to, from, n);
18156 }
18157
18158 static __always_inline unsigned long
18159 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
18160 {
18161+ if ((long)n < 0)
18162+ return n;
18163+
18164 /* Avoid zeroing the tail if the copy fails..
18165 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
18166 * but as the zeroing behaviour is only significant when n is not
18167@@ -137,6 +146,12 @@ static __always_inline unsigned long
18168 __copy_from_user(void *to, const void __user *from, unsigned long n)
18169 {
18170 might_fault();
18171+
18172+ if ((long)n < 0)
18173+ return n;
18174+
18175+ check_object_size(to, n, false);
18176+
18177 if (__builtin_constant_p(n)) {
18178 unsigned long ret;
18179
18180@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
18181 const void __user *from, unsigned long n)
18182 {
18183 might_fault();
18184+
18185+ if ((long)n < 0)
18186+ return n;
18187+
18188 if (__builtin_constant_p(n)) {
18189 unsigned long ret;
18190
18191@@ -181,15 +200,19 @@ static __always_inline unsigned long
18192 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
18193 unsigned long n)
18194 {
18195- return __copy_from_user_ll_nocache_nozero(to, from, n);
18196+ if ((long)n < 0)
18197+ return n;
18198+
18199+ return __copy_from_user_ll_nocache_nozero(to, from, n);
18200 }
18201
18202-unsigned long __must_check copy_to_user(void __user *to,
18203- const void *from, unsigned long n);
18204-unsigned long __must_check _copy_from_user(void *to,
18205- const void __user *from,
18206- unsigned long n);
18207-
18208+extern void copy_to_user_overflow(void)
18209+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
18210+ __compiletime_error("copy_to_user() buffer size is not provably correct")
18211+#else
18212+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
18213+#endif
18214+;
18215
18216 extern void copy_from_user_overflow(void)
18217 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
18218@@ -199,17 +222,60 @@ extern void copy_from_user_overflow(void)
18219 #endif
18220 ;
18221
18222-static inline unsigned long __must_check copy_from_user(void *to,
18223- const void __user *from,
18224- unsigned long n)
18225+/**
18226+ * copy_to_user: - Copy a block of data into user space.
18227+ * @to: Destination address, in user space.
18228+ * @from: Source address, in kernel space.
18229+ * @n: Number of bytes to copy.
18230+ *
18231+ * Context: User context only. This function may sleep.
18232+ *
18233+ * Copy data from kernel space to user space.
18234+ *
18235+ * Returns number of bytes that could not be copied.
18236+ * On success, this will be zero.
18237+ */
18238+static inline unsigned long __must_check
18239+copy_to_user(void __user *to, const void *from, unsigned long n)
18240 {
18241- int sz = __compiletime_object_size(to);
18242+ size_t sz = __compiletime_object_size(from);
18243
18244- if (likely(sz == -1 || sz >= n))
18245- n = _copy_from_user(to, from, n);
18246- else
18247+ if (unlikely(sz != (size_t)-1 && sz < n))
18248+ copy_to_user_overflow();
18249+ else if (access_ok(VERIFY_WRITE, to, n))
18250+ n = __copy_to_user(to, from, n);
18251+ return n;
18252+}
18253+
18254+/**
18255+ * copy_from_user: - Copy a block of data from user space.
18256+ * @to: Destination address, in kernel space.
18257+ * @from: Source address, in user space.
18258+ * @n: Number of bytes to copy.
18259+ *
18260+ * Context: User context only. This function may sleep.
18261+ *
18262+ * Copy data from user space to kernel space.
18263+ *
18264+ * Returns number of bytes that could not be copied.
18265+ * On success, this will be zero.
18266+ *
18267+ * If some data could not be copied, this function will pad the copied
18268+ * data to the requested size using zero bytes.
18269+ */
18270+static inline unsigned long __must_check
18271+copy_from_user(void *to, const void __user *from, unsigned long n)
18272+{
18273+ size_t sz = __compiletime_object_size(to);
18274+
18275+ check_object_size(to, n, false);
18276+
18277+ if (unlikely(sz != (size_t)-1 && sz < n))
18278 copy_from_user_overflow();
18279-
18280+ else if (access_ok(VERIFY_READ, from, n))
18281+ n = __copy_from_user(to, from, n);
18282+ else if ((long)n > 0)
18283+ memset(to, 0, n);
18284 return n;
18285 }
18286
18287diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
18288index 4f7923d..20cb24e 100644
18289--- a/arch/x86/include/asm/uaccess_64.h
18290+++ b/arch/x86/include/asm/uaccess_64.h
18291@@ -10,6 +10,9 @@
18292 #include <asm/alternative.h>
18293 #include <asm/cpufeature.h>
18294 #include <asm/page.h>
18295+#include <asm/pgtable.h>
18296+
18297+#define set_fs(x) (current_thread_info()->addr_limit = (x))
18298
18299 /*
18300 * Copy To/From Userspace
18301@@ -17,13 +20,13 @@
18302
18303 /* Handles exceptions in both to and from, but doesn't do access_ok */
18304 __must_check unsigned long
18305-copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
18306+copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
18307 __must_check unsigned long
18308-copy_user_generic_string(void *to, const void *from, unsigned len);
18309+copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
18310 __must_check unsigned long
18311-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
18312+copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
18313
18314-static __always_inline __must_check unsigned long
18315+static __always_inline __must_check __size_overflow(3) unsigned long
18316 copy_user_generic(void *to, const void *from, unsigned len)
18317 {
18318 unsigned ret;
18319@@ -41,142 +44,204 @@ copy_user_generic(void *to, const void *from, unsigned len)
18320 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
18321 "=d" (len)),
18322 "1" (to), "2" (from), "3" (len)
18323- : "memory", "rcx", "r8", "r9", "r10", "r11");
18324+ : "memory", "rcx", "r8", "r9", "r11");
18325 return ret;
18326 }
18327
18328+static __always_inline __must_check unsigned long
18329+__copy_to_user(void __user *to, const void *from, unsigned long len);
18330+static __always_inline __must_check unsigned long
18331+__copy_from_user(void *to, const void __user *from, unsigned long len);
18332 __must_check unsigned long
18333-_copy_to_user(void __user *to, const void *from, unsigned len);
18334-__must_check unsigned long
18335-_copy_from_user(void *to, const void __user *from, unsigned len);
18336-__must_check unsigned long
18337-copy_in_user(void __user *to, const void __user *from, unsigned len);
18338+copy_in_user(void __user *to, const void __user *from, unsigned long len);
18339+
18340+extern void copy_to_user_overflow(void)
18341+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
18342+ __compiletime_error("copy_to_user() buffer size is not provably correct")
18343+#else
18344+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
18345+#endif
18346+;
18347+
18348+extern void copy_from_user_overflow(void)
18349+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
18350+ __compiletime_error("copy_from_user() buffer size is not provably correct")
18351+#else
18352+ __compiletime_warning("copy_from_user() buffer size is not provably correct")
18353+#endif
18354+;
18355
18356 static inline unsigned long __must_check copy_from_user(void *to,
18357 const void __user *from,
18358 unsigned long n)
18359 {
18360- int sz = __compiletime_object_size(to);
18361-
18362 might_fault();
18363- if (likely(sz == -1 || sz >= n))
18364- n = _copy_from_user(to, from, n);
18365-#ifdef CONFIG_DEBUG_VM
18366- else
18367- WARN(1, "Buffer overflow detected!\n");
18368-#endif
18369+
18370+ check_object_size(to, n, false);
18371+
18372+ if (access_ok(VERIFY_READ, from, n))
18373+ n = __copy_from_user(to, from, n);
18374+ else if (n < INT_MAX)
18375+ memset(to, 0, n);
18376 return n;
18377 }
18378
18379 static __always_inline __must_check
18380-int copy_to_user(void __user *dst, const void *src, unsigned size)
18381+int copy_to_user(void __user *dst, const void *src, unsigned long size)
18382 {
18383 might_fault();
18384
18385- return _copy_to_user(dst, src, size);
18386+ if (access_ok(VERIFY_WRITE, dst, size))
18387+ size = __copy_to_user(dst, src, size);
18388+ return size;
18389 }
18390
18391 static __always_inline __must_check
18392-int __copy_from_user(void *dst, const void __user *src, unsigned size)
18393+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
18394 {
18395- int ret = 0;
18396+ size_t sz = __compiletime_object_size(dst);
18397+ unsigned ret = 0;
18398
18399 might_fault();
18400+
18401+ if (size > INT_MAX)
18402+ return size;
18403+
18404+ check_object_size(dst, size, false);
18405+
18406+#ifdef CONFIG_PAX_MEMORY_UDEREF
18407+ if (!__access_ok(VERIFY_READ, src, size))
18408+ return size;
18409+#endif
18410+
18411+ if (unlikely(sz != (size_t)-1 && sz < size)) {
18412+ copy_from_user_overflow();
18413+ return size;
18414+ }
18415+
18416 if (!__builtin_constant_p(size))
18417- return copy_user_generic(dst, (__force void *)src, size);
18418+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
18419 switch (size) {
18420- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
18421+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
18422 ret, "b", "b", "=q", 1);
18423 return ret;
18424- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
18425+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
18426 ret, "w", "w", "=r", 2);
18427 return ret;
18428- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
18429+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
18430 ret, "l", "k", "=r", 4);
18431 return ret;
18432- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
18433+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
18434 ret, "q", "", "=r", 8);
18435 return ret;
18436 case 10:
18437- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
18438+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
18439 ret, "q", "", "=r", 10);
18440 if (unlikely(ret))
18441 return ret;
18442 __get_user_asm(*(u16 *)(8 + (char *)dst),
18443- (u16 __user *)(8 + (char __user *)src),
18444+ (const u16 __user *)(8 + (const char __user *)src),
18445 ret, "w", "w", "=r", 2);
18446 return ret;
18447 case 16:
18448- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
18449+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
18450 ret, "q", "", "=r", 16);
18451 if (unlikely(ret))
18452 return ret;
18453 __get_user_asm(*(u64 *)(8 + (char *)dst),
18454- (u64 __user *)(8 + (char __user *)src),
18455+ (const u64 __user *)(8 + (const char __user *)src),
18456 ret, "q", "", "=r", 8);
18457 return ret;
18458 default:
18459- return copy_user_generic(dst, (__force void *)src, size);
18460+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
18461 }
18462 }
18463
18464 static __always_inline __must_check
18465-int __copy_to_user(void __user *dst, const void *src, unsigned size)
18466+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
18467 {
18468- int ret = 0;
18469+ size_t sz = __compiletime_object_size(src);
18470+ unsigned ret = 0;
18471
18472 might_fault();
18473+
18474+ if (size > INT_MAX)
18475+ return size;
18476+
18477+ check_object_size(src, size, true);
18478+
18479+#ifdef CONFIG_PAX_MEMORY_UDEREF
18480+ if (!__access_ok(VERIFY_WRITE, dst, size))
18481+ return size;
18482+#endif
18483+
18484+ if (unlikely(sz != (size_t)-1 && sz < size)) {
18485+ copy_to_user_overflow();
18486+ return size;
18487+ }
18488+
18489 if (!__builtin_constant_p(size))
18490- return copy_user_generic((__force void *)dst, src, size);
18491+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
18492 switch (size) {
18493- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
18494+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
18495 ret, "b", "b", "iq", 1);
18496 return ret;
18497- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
18498+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
18499 ret, "w", "w", "ir", 2);
18500 return ret;
18501- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
18502+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
18503 ret, "l", "k", "ir", 4);
18504 return ret;
18505- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
18506+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
18507 ret, "q", "", "er", 8);
18508 return ret;
18509 case 10:
18510- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
18511+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
18512 ret, "q", "", "er", 10);
18513 if (unlikely(ret))
18514 return ret;
18515 asm("":::"memory");
18516- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
18517+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
18518 ret, "w", "w", "ir", 2);
18519 return ret;
18520 case 16:
18521- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
18522+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
18523 ret, "q", "", "er", 16);
18524 if (unlikely(ret))
18525 return ret;
18526 asm("":::"memory");
18527- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
18528+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
18529 ret, "q", "", "er", 8);
18530 return ret;
18531 default:
18532- return copy_user_generic((__force void *)dst, src, size);
18533+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
18534 }
18535 }
18536
18537 static __always_inline __must_check
18538-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
18539+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
18540 {
18541- int ret = 0;
18542+ unsigned ret = 0;
18543
18544 might_fault();
18545+
18546+ if (size > INT_MAX)
18547+ return size;
18548+
18549+#ifdef CONFIG_PAX_MEMORY_UDEREF
18550+ if (!__access_ok(VERIFY_READ, src, size))
18551+ return size;
18552+ if (!__access_ok(VERIFY_WRITE, dst, size))
18553+ return size;
18554+#endif
18555+
18556 if (!__builtin_constant_p(size))
18557- return copy_user_generic((__force void *)dst,
18558- (__force void *)src, size);
18559+ return copy_user_generic((__force_kernel void *)____m(dst),
18560+ (__force_kernel const void *)____m(src), size);
18561 switch (size) {
18562 case 1: {
18563 u8 tmp;
18564- __get_user_asm(tmp, (u8 __user *)src,
18565+ __get_user_asm(tmp, (const u8 __user *)src,
18566 ret, "b", "b", "=q", 1);
18567 if (likely(!ret))
18568 __put_user_asm(tmp, (u8 __user *)dst,
18569@@ -185,7 +250,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
18570 }
18571 case 2: {
18572 u16 tmp;
18573- __get_user_asm(tmp, (u16 __user *)src,
18574+ __get_user_asm(tmp, (const u16 __user *)src,
18575 ret, "w", "w", "=r", 2);
18576 if (likely(!ret))
18577 __put_user_asm(tmp, (u16 __user *)dst,
18578@@ -195,7 +260,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
18579
18580 case 4: {
18581 u32 tmp;
18582- __get_user_asm(tmp, (u32 __user *)src,
18583+ __get_user_asm(tmp, (const u32 __user *)src,
18584 ret, "l", "k", "=r", 4);
18585 if (likely(!ret))
18586 __put_user_asm(tmp, (u32 __user *)dst,
18587@@ -204,7 +269,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
18588 }
18589 case 8: {
18590 u64 tmp;
18591- __get_user_asm(tmp, (u64 __user *)src,
18592+ __get_user_asm(tmp, (const u64 __user *)src,
18593 ret, "q", "", "=r", 8);
18594 if (likely(!ret))
18595 __put_user_asm(tmp, (u64 __user *)dst,
18596@@ -212,41 +277,74 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
18597 return ret;
18598 }
18599 default:
18600- return copy_user_generic((__force void *)dst,
18601- (__force void *)src, size);
18602+ return copy_user_generic((__force_kernel void *)____m(dst),
18603+ (__force_kernel const void *)____m(src), size);
18604 }
18605 }
18606
18607-static __must_check __always_inline int
18608-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
18609+static __must_check __always_inline unsigned long
18610+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
18611 {
18612- return copy_user_generic(dst, (__force const void *)src, size);
18613+ if (size > INT_MAX)
18614+ return size;
18615+
18616+#ifdef CONFIG_PAX_MEMORY_UDEREF
18617+ if (!__access_ok(VERIFY_READ, src, size))
18618+ return size;
18619+#endif
18620+
18621+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
18622 }
18623
18624-static __must_check __always_inline int
18625-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
18626+static __must_check __always_inline unsigned long
18627+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
18628 {
18629- return copy_user_generic((__force void *)dst, src, size);
18630+ if (size > INT_MAX)
18631+ return size;
18632+
18633+#ifdef CONFIG_PAX_MEMORY_UDEREF
18634+ if (!__access_ok(VERIFY_WRITE, dst, size))
18635+ return size;
18636+#endif
18637+
18638+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
18639 }
18640
18641-extern long __copy_user_nocache(void *dst, const void __user *src,
18642- unsigned size, int zerorest);
18643+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
18644+ unsigned long size, int zerorest) __size_overflow(3);
18645
18646-static inline int
18647-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
18648+static inline unsigned long
18649+__copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
18650 {
18651 might_fault();
18652+
18653+ if (size > INT_MAX)
18654+ return size;
18655+
18656+#ifdef CONFIG_PAX_MEMORY_UDEREF
18657+ if (!__access_ok(VERIFY_READ, src, size))
18658+ return size;
18659+#endif
18660+
18661 return __copy_user_nocache(dst, src, size, 1);
18662 }
18663
18664-static inline int
18665+static inline unsigned long
18666 __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
18667- unsigned size)
18668+ unsigned long size)
18669 {
18670+ if (size > INT_MAX)
18671+ return size;
18672+
18673+#ifdef CONFIG_PAX_MEMORY_UDEREF
18674+ if (!__access_ok(VERIFY_READ, src, size))
18675+ return size;
18676+#endif
18677+
18678 return __copy_user_nocache(dst, src, size, 0);
18679 }
18680
18681 unsigned long
18682-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
18683+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
18684
18685 #endif /* _ASM_X86_UACCESS_64_H */
18686diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
18687index 5b238981..77fdd78 100644
18688--- a/arch/x86/include/asm/word-at-a-time.h
18689+++ b/arch/x86/include/asm/word-at-a-time.h
18690@@ -11,7 +11,7 @@
18691 * and shift, for example.
18692 */
18693 struct word_at_a_time {
18694- const unsigned long one_bits, high_bits;
18695+ unsigned long one_bits, high_bits;
18696 };
18697
18698 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
18699diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
18700index 828a156..650e625 100644
18701--- a/arch/x86/include/asm/x86_init.h
18702+++ b/arch/x86/include/asm/x86_init.h
18703@@ -129,7 +129,7 @@ struct x86_init_ops {
18704 struct x86_init_timers timers;
18705 struct x86_init_iommu iommu;
18706 struct x86_init_pci pci;
18707-};
18708+} __no_const;
18709
18710 /**
18711 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
18712@@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
18713 void (*setup_percpu_clockev)(void);
18714 void (*early_percpu_clock_init)(void);
18715 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
18716-};
18717+} __no_const;
18718
18719 struct timespec;
18720
18721@@ -168,7 +168,7 @@ struct x86_platform_ops {
18722 void (*save_sched_clock_state)(void);
18723 void (*restore_sched_clock_state)(void);
18724 void (*apic_post_init)(void);
18725-};
18726+} __no_const;
18727
18728 struct pci_dev;
18729 struct msi_msg;
18730@@ -182,7 +182,7 @@ struct x86_msi_ops {
18731 void (*teardown_msi_irqs)(struct pci_dev *dev);
18732 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
18733 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
18734-};
18735+} __no_const;
18736
18737 struct IO_APIC_route_entry;
18738 struct io_apic_irq_attr;
18739@@ -203,7 +203,7 @@ struct x86_io_apic_ops {
18740 unsigned int destination, int vector,
18741 struct io_apic_irq_attr *attr);
18742 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
18743-};
18744+} __no_const;
18745
18746 extern struct x86_init_ops x86_init;
18747 extern struct x86_cpuinit_ops x86_cpuinit;
18748diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
18749index 0415cda..3b22adc 100644
18750--- a/arch/x86/include/asm/xsave.h
18751+++ b/arch/x86/include/asm/xsave.h
18752@@ -70,8 +70,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
18753 if (unlikely(err))
18754 return -EFAULT;
18755
18756+ pax_open_userland();
18757 __asm__ __volatile__(ASM_STAC "\n"
18758- "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
18759+ "1:"
18760+ __copyuser_seg
18761+ ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
18762 "2: " ASM_CLAC "\n"
18763 ".section .fixup,\"ax\"\n"
18764 "3: movl $-1,%[err]\n"
18765@@ -81,18 +84,22 @@ static inline int xsave_user(struct xsave_struct __user *buf)
18766 : [err] "=r" (err)
18767 : "D" (buf), "a" (-1), "d" (-1), "0" (0)
18768 : "memory");
18769+ pax_close_userland();
18770 return err;
18771 }
18772
18773 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
18774 {
18775 int err;
18776- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
18777+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
18778 u32 lmask = mask;
18779 u32 hmask = mask >> 32;
18780
18781+ pax_open_userland();
18782 __asm__ __volatile__(ASM_STAC "\n"
18783- "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
18784+ "1:"
18785+ __copyuser_seg
18786+ ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
18787 "2: " ASM_CLAC "\n"
18788 ".section .fixup,\"ax\"\n"
18789 "3: movl $-1,%[err]\n"
18790@@ -102,6 +109,7 @@ static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
18791 : [err] "=r" (err)
18792 : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
18793 : "memory"); /* memory required? */
18794+ pax_close_userland();
18795 return err;
18796 }
18797
18798diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
18799index bbae024..e1528f9 100644
18800--- a/arch/x86/include/uapi/asm/e820.h
18801+++ b/arch/x86/include/uapi/asm/e820.h
18802@@ -63,7 +63,7 @@ struct e820map {
18803 #define ISA_START_ADDRESS 0xa0000
18804 #define ISA_END_ADDRESS 0x100000
18805
18806-#define BIOS_BEGIN 0x000a0000
18807+#define BIOS_BEGIN 0x000c0000
18808 #define BIOS_END 0x00100000
18809
18810 #define BIOS_ROM_BASE 0xffe00000
18811diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
18812index 88d99ea..9fc7e17 100644
18813--- a/arch/x86/kernel/Makefile
18814+++ b/arch/x86/kernel/Makefile
18815@@ -24,7 +24,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
18816 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
18817 obj-$(CONFIG_IRQ_WORK) += irq_work.o
18818 obj-y += probe_roms.o
18819-obj-$(CONFIG_X86_32) += i386_ksyms_32.o
18820+obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
18821 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
18822 obj-y += syscall_$(BITS).o
18823 obj-$(CONFIG_X86_64) += vsyscall_64.o
18824diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
18825index 2627a81..cd8325e 100644
18826--- a/arch/x86/kernel/acpi/boot.c
18827+++ b/arch/x86/kernel/acpi/boot.c
18828@@ -1368,7 +1368,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
18829 * If your system is blacklisted here, but you find that acpi=force
18830 * works for you, please contact linux-acpi@vger.kernel.org
18831 */
18832-static struct dmi_system_id __initdata acpi_dmi_table[] = {
18833+static const struct dmi_system_id __initconst acpi_dmi_table[] = {
18834 /*
18835 * Boxes that need ACPI disabled
18836 */
18837@@ -1443,7 +1443,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
18838 };
18839
18840 /* second table for DMI checks that should run after early-quirks */
18841-static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
18842+static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
18843 /*
18844 * HP laptops which use a DSDT reporting as HP/SB400/10000,
18845 * which includes some code which overrides all temperature
18846diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
18847index 3312010..a65ca7b 100644
18848--- a/arch/x86/kernel/acpi/sleep.c
18849+++ b/arch/x86/kernel/acpi/sleep.c
18850@@ -88,8 +88,12 @@ int x86_acpi_suspend_lowlevel(void)
18851 #else /* CONFIG_64BIT */
18852 #ifdef CONFIG_SMP
18853 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
18854+
18855+ pax_open_kernel();
18856 early_gdt_descr.address =
18857 (unsigned long)get_cpu_gdt_table(smp_processor_id());
18858+ pax_close_kernel();
18859+
18860 initial_gs = per_cpu_offset(smp_processor_id());
18861 #endif
18862 initial_code = (unsigned long)wakeup_long64;
18863diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
18864index d1daa66..59fecba 100644
18865--- a/arch/x86/kernel/acpi/wakeup_32.S
18866+++ b/arch/x86/kernel/acpi/wakeup_32.S
18867@@ -29,13 +29,11 @@ wakeup_pmode_return:
18868 # and restore the stack ... but you need gdt for this to work
18869 movl saved_context_esp, %esp
18870
18871- movl %cs:saved_magic, %eax
18872- cmpl $0x12345678, %eax
18873+ cmpl $0x12345678, saved_magic
18874 jne bogus_magic
18875
18876 # jump to place where we left off
18877- movl saved_eip, %eax
18878- jmp *%eax
18879+ jmp *(saved_eip)
18880
18881 bogus_magic:
18882 jmp bogus_magic
18883diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
18884index c15cf9a..0e63558 100644
18885--- a/arch/x86/kernel/alternative.c
18886+++ b/arch/x86/kernel/alternative.c
18887@@ -268,6 +268,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
18888 */
18889 for (a = start; a < end; a++) {
18890 instr = (u8 *)&a->instr_offset + a->instr_offset;
18891+
18892+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18893+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
18894+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
18895+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
18896+#endif
18897+
18898 replacement = (u8 *)&a->repl_offset + a->repl_offset;
18899 BUG_ON(a->replacementlen > a->instrlen);
18900 BUG_ON(a->instrlen > sizeof(insnbuf));
18901@@ -299,10 +306,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
18902 for (poff = start; poff < end; poff++) {
18903 u8 *ptr = (u8 *)poff + *poff;
18904
18905+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18906+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
18907+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
18908+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
18909+#endif
18910+
18911 if (!*poff || ptr < text || ptr >= text_end)
18912 continue;
18913 /* turn DS segment override prefix into lock prefix */
18914- if (*ptr == 0x3e)
18915+ if (*ktla_ktva(ptr) == 0x3e)
18916 text_poke(ptr, ((unsigned char []){0xf0}), 1);
18917 }
18918 mutex_unlock(&text_mutex);
18919@@ -317,10 +330,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
18920 for (poff = start; poff < end; poff++) {
18921 u8 *ptr = (u8 *)poff + *poff;
18922
18923+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18924+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
18925+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
18926+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
18927+#endif
18928+
18929 if (!*poff || ptr < text || ptr >= text_end)
18930 continue;
18931 /* turn lock prefix into DS segment override prefix */
18932- if (*ptr == 0xf0)
18933+ if (*ktla_ktva(ptr) == 0xf0)
18934 text_poke(ptr, ((unsigned char []){0x3E}), 1);
18935 }
18936 mutex_unlock(&text_mutex);
18937@@ -468,7 +487,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
18938
18939 BUG_ON(p->len > MAX_PATCH_LEN);
18940 /* prep the buffer with the original instructions */
18941- memcpy(insnbuf, p->instr, p->len);
18942+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
18943 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
18944 (unsigned long)p->instr, p->len);
18945
18946@@ -515,7 +534,7 @@ void __init alternative_instructions(void)
18947 if (!uniproc_patched || num_possible_cpus() == 1)
18948 free_init_pages("SMP alternatives",
18949 (unsigned long)__smp_locks,
18950- (unsigned long)__smp_locks_end);
18951+ PAGE_ALIGN((unsigned long)__smp_locks_end));
18952 #endif
18953
18954 apply_paravirt(__parainstructions, __parainstructions_end);
18955@@ -535,13 +554,17 @@ void __init alternative_instructions(void)
18956 * instructions. And on the local CPU you need to be protected again NMI or MCE
18957 * handlers seeing an inconsistent instruction while you patch.
18958 */
18959-void *__init_or_module text_poke_early(void *addr, const void *opcode,
18960+void *__kprobes text_poke_early(void *addr, const void *opcode,
18961 size_t len)
18962 {
18963 unsigned long flags;
18964 local_irq_save(flags);
18965- memcpy(addr, opcode, len);
18966+
18967+ pax_open_kernel();
18968+ memcpy(ktla_ktva(addr), opcode, len);
18969 sync_core();
18970+ pax_close_kernel();
18971+
18972 local_irq_restore(flags);
18973 /* Could also do a CLFLUSH here to speed up CPU recovery; but
18974 that causes hangs on some VIA CPUs. */
18975@@ -563,36 +586,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
18976 */
18977 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
18978 {
18979- unsigned long flags;
18980- char *vaddr;
18981+ unsigned char *vaddr = ktla_ktva(addr);
18982 struct page *pages[2];
18983- int i;
18984+ size_t i;
18985
18986 if (!core_kernel_text((unsigned long)addr)) {
18987- pages[0] = vmalloc_to_page(addr);
18988- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
18989+ pages[0] = vmalloc_to_page(vaddr);
18990+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
18991 } else {
18992- pages[0] = virt_to_page(addr);
18993+ pages[0] = virt_to_page(vaddr);
18994 WARN_ON(!PageReserved(pages[0]));
18995- pages[1] = virt_to_page(addr + PAGE_SIZE);
18996+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
18997 }
18998 BUG_ON(!pages[0]);
18999- local_irq_save(flags);
19000- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
19001- if (pages[1])
19002- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
19003- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
19004- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
19005- clear_fixmap(FIX_TEXT_POKE0);
19006- if (pages[1])
19007- clear_fixmap(FIX_TEXT_POKE1);
19008- local_flush_tlb();
19009- sync_core();
19010- /* Could also do a CLFLUSH here to speed up CPU recovery; but
19011- that causes hangs on some VIA CPUs. */
19012+ text_poke_early(addr, opcode, len);
19013 for (i = 0; i < len; i++)
19014- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
19015- local_irq_restore(flags);
19016+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
19017 return addr;
19018 }
19019
19020diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
19021index eca89c5..d566b78 100644
19022--- a/arch/x86/kernel/apic/apic.c
19023+++ b/arch/x86/kernel/apic/apic.c
19024@@ -190,7 +190,7 @@ int first_system_vector = 0xfe;
19025 /*
19026 * Debug level, exported for io_apic.c
19027 */
19028-unsigned int apic_verbosity;
19029+int apic_verbosity;
19030
19031 int pic_mode;
19032
19033@@ -1985,7 +1985,7 @@ static inline void __smp_error_interrupt(struct pt_regs *regs)
19034 apic_write(APIC_ESR, 0);
19035 v1 = apic_read(APIC_ESR);
19036 ack_APIC_irq();
19037- atomic_inc(&irq_err_count);
19038+ atomic_inc_unchecked(&irq_err_count);
19039
19040 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
19041 smp_processor_id(), v0 , v1);
19042diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
19043index 00c77cf..2dc6a2d 100644
19044--- a/arch/x86/kernel/apic/apic_flat_64.c
19045+++ b/arch/x86/kernel/apic/apic_flat_64.c
19046@@ -157,7 +157,7 @@ static int flat_probe(void)
19047 return 1;
19048 }
19049
19050-static struct apic apic_flat = {
19051+static struct apic apic_flat __read_only = {
19052 .name = "flat",
19053 .probe = flat_probe,
19054 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
19055@@ -271,7 +271,7 @@ static int physflat_probe(void)
19056 return 0;
19057 }
19058
19059-static struct apic apic_physflat = {
19060+static struct apic apic_physflat __read_only = {
19061
19062 .name = "physical flat",
19063 .probe = physflat_probe,
19064diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
19065index e145f28..2752888 100644
19066--- a/arch/x86/kernel/apic/apic_noop.c
19067+++ b/arch/x86/kernel/apic/apic_noop.c
19068@@ -119,7 +119,7 @@ static void noop_apic_write(u32 reg, u32 v)
19069 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
19070 }
19071
19072-struct apic apic_noop = {
19073+struct apic apic_noop __read_only = {
19074 .name = "noop",
19075 .probe = noop_probe,
19076 .acpi_madt_oem_check = NULL,
19077diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
19078index d50e364..543bee3 100644
19079--- a/arch/x86/kernel/apic/bigsmp_32.c
19080+++ b/arch/x86/kernel/apic/bigsmp_32.c
19081@@ -152,7 +152,7 @@ static int probe_bigsmp(void)
19082 return dmi_bigsmp;
19083 }
19084
19085-static struct apic apic_bigsmp = {
19086+static struct apic apic_bigsmp __read_only = {
19087
19088 .name = "bigsmp",
19089 .probe = probe_bigsmp,
19090diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c
19091index c552247..587a316 100644
19092--- a/arch/x86/kernel/apic/es7000_32.c
19093+++ b/arch/x86/kernel/apic/es7000_32.c
19094@@ -608,8 +608,7 @@ static int es7000_mps_oem_check_cluster(struct mpc_table *mpc, char *oem,
19095 return ret && es7000_apic_is_cluster();
19096 }
19097
19098-/* We've been warned by a false positive warning.Use __refdata to keep calm. */
19099-static struct apic __refdata apic_es7000_cluster = {
19100+static struct apic apic_es7000_cluster __read_only = {
19101
19102 .name = "es7000",
19103 .probe = probe_es7000,
19104@@ -675,7 +674,7 @@ static struct apic __refdata apic_es7000_cluster = {
19105 .x86_32_early_logical_apicid = es7000_early_logical_apicid,
19106 };
19107
19108-static struct apic __refdata apic_es7000 = {
19109+static struct apic apic_es7000 __read_only = {
19110
19111 .name = "es7000",
19112 .probe = probe_es7000,
19113diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
19114index 9ed796c..e930fe4 100644
19115--- a/arch/x86/kernel/apic/io_apic.c
19116+++ b/arch/x86/kernel/apic/io_apic.c
19117@@ -1060,7 +1060,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
19118 }
19119 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
19120
19121-void lock_vector_lock(void)
19122+void lock_vector_lock(void) __acquires(vector_lock)
19123 {
19124 /* Used to the online set of cpus does not change
19125 * during assign_irq_vector.
19126@@ -1068,7 +1068,7 @@ void lock_vector_lock(void)
19127 raw_spin_lock(&vector_lock);
19128 }
19129
19130-void unlock_vector_lock(void)
19131+void unlock_vector_lock(void) __releases(vector_lock)
19132 {
19133 raw_spin_unlock(&vector_lock);
19134 }
19135@@ -2362,7 +2362,7 @@ static void ack_apic_edge(struct irq_data *data)
19136 ack_APIC_irq();
19137 }
19138
19139-atomic_t irq_mis_count;
19140+atomic_unchecked_t irq_mis_count;
19141
19142 #ifdef CONFIG_GENERIC_PENDING_IRQ
19143 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
19144@@ -2503,7 +2503,7 @@ static void ack_apic_level(struct irq_data *data)
19145 * at the cpu.
19146 */
19147 if (!(v & (1 << (i & 0x1f)))) {
19148- atomic_inc(&irq_mis_count);
19149+ atomic_inc_unchecked(&irq_mis_count);
19150
19151 eoi_ioapic_irq(irq, cfg);
19152 }
19153diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
19154index 1e42e8f..daacf44 100644
19155--- a/arch/x86/kernel/apic/numaq_32.c
19156+++ b/arch/x86/kernel/apic/numaq_32.c
19157@@ -455,8 +455,7 @@ static void numaq_setup_portio_remap(void)
19158 (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
19159 }
19160
19161-/* Use __refdata to keep false positive warning calm. */
19162-static struct apic __refdata apic_numaq = {
19163+static struct apic apic_numaq __read_only = {
19164
19165 .name = "NUMAQ",
19166 .probe = probe_numaq,
19167diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
19168index eb35ef9..f184a21 100644
19169--- a/arch/x86/kernel/apic/probe_32.c
19170+++ b/arch/x86/kernel/apic/probe_32.c
19171@@ -72,7 +72,7 @@ static int probe_default(void)
19172 return 1;
19173 }
19174
19175-static struct apic apic_default = {
19176+static struct apic apic_default __read_only = {
19177
19178 .name = "default",
19179 .probe = probe_default,
19180diff --git a/arch/x86/kernel/apic/summit_32.c b/arch/x86/kernel/apic/summit_32.c
19181index 77c95c0..434f8a4 100644
19182--- a/arch/x86/kernel/apic/summit_32.c
19183+++ b/arch/x86/kernel/apic/summit_32.c
19184@@ -486,7 +486,7 @@ void setup_summit(void)
19185 }
19186 #endif
19187
19188-static struct apic apic_summit = {
19189+static struct apic apic_summit __read_only = {
19190
19191 .name = "summit",
19192 .probe = probe_summit,
19193diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
19194index 140e29d..d88bc95 100644
19195--- a/arch/x86/kernel/apic/x2apic_cluster.c
19196+++ b/arch/x86/kernel/apic/x2apic_cluster.c
19197@@ -183,7 +183,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
19198 return notifier_from_errno(err);
19199 }
19200
19201-static struct notifier_block __refdata x2apic_cpu_notifier = {
19202+static struct notifier_block x2apic_cpu_notifier = {
19203 .notifier_call = update_clusterinfo,
19204 };
19205
19206@@ -235,7 +235,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
19207 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
19208 }
19209
19210-static struct apic apic_x2apic_cluster = {
19211+static struct apic apic_x2apic_cluster __read_only = {
19212
19213 .name = "cluster x2apic",
19214 .probe = x2apic_cluster_probe,
19215diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
19216index 562a76d..a003c0f 100644
19217--- a/arch/x86/kernel/apic/x2apic_phys.c
19218+++ b/arch/x86/kernel/apic/x2apic_phys.c
19219@@ -89,7 +89,7 @@ static int x2apic_phys_probe(void)
19220 return apic == &apic_x2apic_phys;
19221 }
19222
19223-static struct apic apic_x2apic_phys = {
19224+static struct apic apic_x2apic_phys __read_only = {
19225
19226 .name = "physical x2apic",
19227 .probe = x2apic_phys_probe,
19228diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
19229index 1191ac1..2335fa4 100644
19230--- a/arch/x86/kernel/apic/x2apic_uv_x.c
19231+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
19232@@ -357,7 +357,7 @@ static int uv_probe(void)
19233 return apic == &apic_x2apic_uv_x;
19234 }
19235
19236-static struct apic __refdata apic_x2apic_uv_x = {
19237+static struct apic apic_x2apic_uv_x __read_only = {
19238
19239 .name = "UV large system",
19240 .probe = uv_probe,
19241diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
19242index 53a4e27..038760a 100644
19243--- a/arch/x86/kernel/apm_32.c
19244+++ b/arch/x86/kernel/apm_32.c
19245@@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
19246 * This is for buggy BIOS's that refer to (real mode) segment 0x40
19247 * even though they are called in protected mode.
19248 */
19249-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
19250+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
19251 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
19252
19253 static const char driver_version[] = "1.16ac"; /* no spaces */
19254@@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
19255 BUG_ON(cpu != 0);
19256 gdt = get_cpu_gdt_table(cpu);
19257 save_desc_40 = gdt[0x40 / 8];
19258+
19259+ pax_open_kernel();
19260 gdt[0x40 / 8] = bad_bios_desc;
19261+ pax_close_kernel();
19262
19263 apm_irq_save(flags);
19264 APM_DO_SAVE_SEGS;
19265@@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
19266 &call->esi);
19267 APM_DO_RESTORE_SEGS;
19268 apm_irq_restore(flags);
19269+
19270+ pax_open_kernel();
19271 gdt[0x40 / 8] = save_desc_40;
19272+ pax_close_kernel();
19273+
19274 put_cpu();
19275
19276 return call->eax & 0xff;
19277@@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
19278 BUG_ON(cpu != 0);
19279 gdt = get_cpu_gdt_table(cpu);
19280 save_desc_40 = gdt[0x40 / 8];
19281+
19282+ pax_open_kernel();
19283 gdt[0x40 / 8] = bad_bios_desc;
19284+ pax_close_kernel();
19285
19286 apm_irq_save(flags);
19287 APM_DO_SAVE_SEGS;
19288@@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
19289 &call->eax);
19290 APM_DO_RESTORE_SEGS;
19291 apm_irq_restore(flags);
19292+
19293+ pax_open_kernel();
19294 gdt[0x40 / 8] = save_desc_40;
19295+ pax_close_kernel();
19296+
19297 put_cpu();
19298 return error;
19299 }
19300@@ -2362,12 +2376,15 @@ static int __init apm_init(void)
19301 * code to that CPU.
19302 */
19303 gdt = get_cpu_gdt_table(0);
19304+
19305+ pax_open_kernel();
19306 set_desc_base(&gdt[APM_CS >> 3],
19307 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
19308 set_desc_base(&gdt[APM_CS_16 >> 3],
19309 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
19310 set_desc_base(&gdt[APM_DS >> 3],
19311 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
19312+ pax_close_kernel();
19313
19314 proc_create("apm", 0, NULL, &apm_file_ops);
19315
19316diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
19317index 2861082..6d4718e 100644
19318--- a/arch/x86/kernel/asm-offsets.c
19319+++ b/arch/x86/kernel/asm-offsets.c
19320@@ -33,6 +33,8 @@ void common(void) {
19321 OFFSET(TI_status, thread_info, status);
19322 OFFSET(TI_addr_limit, thread_info, addr_limit);
19323 OFFSET(TI_preempt_count, thread_info, preempt_count);
19324+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
19325+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
19326
19327 BLANK();
19328 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
19329@@ -53,8 +55,26 @@ void common(void) {
19330 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
19331 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
19332 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
19333+
19334+#ifdef CONFIG_PAX_KERNEXEC
19335+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
19336 #endif
19337
19338+#ifdef CONFIG_PAX_MEMORY_UDEREF
19339+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
19340+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
19341+#ifdef CONFIG_X86_64
19342+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
19343+#endif
19344+#endif
19345+
19346+#endif
19347+
19348+ BLANK();
19349+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
19350+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
19351+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
19352+
19353 #ifdef CONFIG_XEN
19354 BLANK();
19355 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
19356diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
19357index e7c798b..2b2019b 100644
19358--- a/arch/x86/kernel/asm-offsets_64.c
19359+++ b/arch/x86/kernel/asm-offsets_64.c
19360@@ -77,6 +77,7 @@ int main(void)
19361 BLANK();
19362 #undef ENTRY
19363
19364+ DEFINE(TSS_size, sizeof(struct tss_struct));
19365 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
19366 BLANK();
19367
19368diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
19369index 47b56a7..efc2bc6 100644
19370--- a/arch/x86/kernel/cpu/Makefile
19371+++ b/arch/x86/kernel/cpu/Makefile
19372@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
19373 CFLAGS_REMOVE_perf_event.o = -pg
19374 endif
19375
19376-# Make sure load_percpu_segment has no stackprotector
19377-nostackp := $(call cc-option, -fno-stack-protector)
19378-CFLAGS_common.o := $(nostackp)
19379-
19380 obj-y := intel_cacheinfo.o scattered.o topology.o
19381 obj-y += proc.o capflags.o powerflags.o common.o
19382 obj-y += rdrand.o
19383diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
19384index 08a0890..e557865 100644
19385--- a/arch/x86/kernel/cpu/amd.c
19386+++ b/arch/x86/kernel/cpu/amd.c
19387@@ -743,7 +743,7 @@ static void init_amd(struct cpuinfo_x86 *c)
19388 static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
19389 {
19390 /* AMD errata T13 (order #21922) */
19391- if ((c->x86 == 6)) {
19392+ if (c->x86 == 6) {
19393 /* Duron Rev A0 */
19394 if (c->x86_model == 3 && c->x86_mask == 0)
19395 size = 64;
19396diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
19397index 25eb274..3a92d93 100644
19398--- a/arch/x86/kernel/cpu/common.c
19399+++ b/arch/x86/kernel/cpu/common.c
19400@@ -88,60 +88,6 @@ static const struct cpu_dev default_cpu = {
19401
19402 static const struct cpu_dev *this_cpu = &default_cpu;
19403
19404-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
19405-#ifdef CONFIG_X86_64
19406- /*
19407- * We need valid kernel segments for data and code in long mode too
19408- * IRET will check the segment types kkeil 2000/10/28
19409- * Also sysret mandates a special GDT layout
19410- *
19411- * TLS descriptors are currently at a different place compared to i386.
19412- * Hopefully nobody expects them at a fixed place (Wine?)
19413- */
19414- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
19415- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
19416- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
19417- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
19418- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
19419- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
19420-#else
19421- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
19422- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
19423- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
19424- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
19425- /*
19426- * Segments used for calling PnP BIOS have byte granularity.
19427- * They code segments and data segments have fixed 64k limits,
19428- * the transfer segment sizes are set at run time.
19429- */
19430- /* 32-bit code */
19431- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
19432- /* 16-bit code */
19433- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
19434- /* 16-bit data */
19435- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
19436- /* 16-bit data */
19437- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
19438- /* 16-bit data */
19439- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
19440- /*
19441- * The APM segments have byte granularity and their bases
19442- * are set at run time. All have 64k limits.
19443- */
19444- /* 32-bit code */
19445- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
19446- /* 16-bit code */
19447- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
19448- /* data */
19449- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
19450-
19451- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
19452- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
19453- GDT_STACK_CANARY_INIT
19454-#endif
19455-} };
19456-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
19457-
19458 static int __init x86_xsave_setup(char *s)
19459 {
19460 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
19461@@ -288,6 +234,57 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
19462 set_in_cr4(X86_CR4_SMAP);
19463 }
19464
19465+#ifdef CONFIG_X86_64
19466+static __init int setup_disable_pcid(char *arg)
19467+{
19468+ setup_clear_cpu_cap(X86_FEATURE_PCID);
19469+
19470+#ifdef CONFIG_PAX_MEMORY_UDEREF
19471+ if (clone_pgd_mask != ~(pgdval_t)0UL)
19472+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
19473+#endif
19474+
19475+ return 1;
19476+}
19477+__setup("nopcid", setup_disable_pcid);
19478+
19479+static void setup_pcid(struct cpuinfo_x86 *c)
19480+{
19481+ if (!cpu_has(c, X86_FEATURE_PCID)) {
19482+
19483+#ifdef CONFIG_PAX_MEMORY_UDEREF
19484+ if (clone_pgd_mask != ~(pgdval_t)0UL) {
19485+ pax_open_kernel();
19486+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
19487+ pax_close_kernel();
19488+ printk("PAX: slow and weak UDEREF enabled\n");
19489+ } else
19490+ printk("PAX: UDEREF disabled\n");
19491+#endif
19492+
19493+ return;
19494+ }
19495+
19496+ printk("PAX: PCID detected\n");
19497+ set_in_cr4(X86_CR4_PCIDE);
19498+
19499+#ifdef CONFIG_PAX_MEMORY_UDEREF
19500+ pax_open_kernel();
19501+ clone_pgd_mask = ~(pgdval_t)0UL;
19502+ pax_close_kernel();
19503+ if (pax_user_shadow_base)
19504+ printk("PAX: weak UDEREF enabled\n");
19505+ else {
19506+ set_cpu_cap(c, X86_FEATURE_STRONGUDEREF);
19507+ printk("PAX: strong UDEREF enabled\n");
19508+ }
19509+#endif
19510+
19511+ if (cpu_has(c, X86_FEATURE_INVPCID))
19512+ printk("PAX: INVPCID detected\n");
19513+}
19514+#endif
19515+
19516 /*
19517 * Some CPU features depend on higher CPUID levels, which may not always
19518 * be available due to CPUID level capping or broken virtualization
19519@@ -386,7 +383,7 @@ void switch_to_new_gdt(int cpu)
19520 {
19521 struct desc_ptr gdt_descr;
19522
19523- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
19524+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
19525 gdt_descr.size = GDT_SIZE - 1;
19526 load_gdt(&gdt_descr);
19527 /* Reload the per-cpu base */
19528@@ -875,6 +872,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
19529 setup_smep(c);
19530 setup_smap(c);
19531
19532+#ifdef CONFIG_X86_64
19533+ setup_pcid(c);
19534+#endif
19535+
19536 /*
19537 * The vendor-specific functions might have changed features.
19538 * Now we do "generic changes."
19539@@ -883,6 +884,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
19540 /* Filter out anything that depends on CPUID levels we don't have */
19541 filter_cpuid_features(c, true);
19542
19543+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
19544+ setup_clear_cpu_cap(X86_FEATURE_SEP);
19545+#endif
19546+
19547 /* If the model name is still unset, do table lookup. */
19548 if (!c->x86_model_id[0]) {
19549 const char *p;
19550@@ -1070,10 +1075,12 @@ static __init int setup_disablecpuid(char *arg)
19551 }
19552 __setup("clearcpuid=", setup_disablecpuid);
19553
19554+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
19555+EXPORT_PER_CPU_SYMBOL(current_tinfo);
19556+
19557 #ifdef CONFIG_X86_64
19558-struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
19559-struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1,
19560- (unsigned long) debug_idt_table };
19561+struct desc_ptr idt_descr __read_only = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
19562+const struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) debug_idt_table };
19563
19564 DEFINE_PER_CPU_FIRST(union irq_stack_union,
19565 irq_stack_union) __aligned(PAGE_SIZE);
19566@@ -1087,7 +1094,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
19567 EXPORT_PER_CPU_SYMBOL(current_task);
19568
19569 DEFINE_PER_CPU(unsigned long, kernel_stack) =
19570- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
19571+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
19572 EXPORT_PER_CPU_SYMBOL(kernel_stack);
19573
19574 DEFINE_PER_CPU(char *, irq_stack_ptr) =
19575@@ -1232,7 +1239,7 @@ void cpu_init(void)
19576 load_ucode_ap();
19577
19578 cpu = stack_smp_processor_id();
19579- t = &per_cpu(init_tss, cpu);
19580+ t = init_tss + cpu;
19581 oist = &per_cpu(orig_ist, cpu);
19582
19583 #ifdef CONFIG_NUMA
19584@@ -1267,7 +1274,6 @@ void cpu_init(void)
19585 wrmsrl(MSR_KERNEL_GS_BASE, 0);
19586 barrier();
19587
19588- x86_configure_nx();
19589 enable_x2apic();
19590
19591 /*
19592@@ -1319,7 +1325,7 @@ void cpu_init(void)
19593 {
19594 int cpu = smp_processor_id();
19595 struct task_struct *curr = current;
19596- struct tss_struct *t = &per_cpu(init_tss, cpu);
19597+ struct tss_struct *t = init_tss + cpu;
19598 struct thread_struct *thread = &curr->thread;
19599
19600 show_ucode_info_early();
19601diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
19602index 1414c90..1159406 100644
19603--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
19604+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
19605@@ -1014,6 +1014,22 @@ static struct attribute *default_attrs[] = {
19606 };
19607
19608 #ifdef CONFIG_AMD_NB
19609+static struct attribute *default_attrs_amd_nb[] = {
19610+ &type.attr,
19611+ &level.attr,
19612+ &coherency_line_size.attr,
19613+ &physical_line_partition.attr,
19614+ &ways_of_associativity.attr,
19615+ &number_of_sets.attr,
19616+ &size.attr,
19617+ &shared_cpu_map.attr,
19618+ &shared_cpu_list.attr,
19619+ NULL,
19620+ NULL,
19621+ NULL,
19622+ NULL
19623+};
19624+
19625 static struct attribute **amd_l3_attrs(void)
19626 {
19627 static struct attribute **attrs;
19628@@ -1024,18 +1040,7 @@ static struct attribute **amd_l3_attrs(void)
19629
19630 n = ARRAY_SIZE(default_attrs);
19631
19632- if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
19633- n += 2;
19634-
19635- if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
19636- n += 1;
19637-
19638- attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
19639- if (attrs == NULL)
19640- return attrs = default_attrs;
19641-
19642- for (n = 0; default_attrs[n]; n++)
19643- attrs[n] = default_attrs[n];
19644+ attrs = default_attrs_amd_nb;
19645
19646 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
19647 attrs[n++] = &cache_disable_0.attr;
19648@@ -1086,6 +1091,13 @@ static struct kobj_type ktype_cache = {
19649 .default_attrs = default_attrs,
19650 };
19651
19652+#ifdef CONFIG_AMD_NB
19653+static struct kobj_type ktype_cache_amd_nb = {
19654+ .sysfs_ops = &sysfs_ops,
19655+ .default_attrs = default_attrs_amd_nb,
19656+};
19657+#endif
19658+
19659 static struct kobj_type ktype_percpu_entry = {
19660 .sysfs_ops = &sysfs_ops,
19661 };
19662@@ -1151,20 +1163,26 @@ static int cache_add_dev(struct device *dev)
19663 return retval;
19664 }
19665
19666+#ifdef CONFIG_AMD_NB
19667+ amd_l3_attrs();
19668+#endif
19669+
19670 for (i = 0; i < num_cache_leaves; i++) {
19671+ struct kobj_type *ktype;
19672+
19673 this_object = INDEX_KOBJECT_PTR(cpu, i);
19674 this_object->cpu = cpu;
19675 this_object->index = i;
19676
19677 this_leaf = CPUID4_INFO_IDX(cpu, i);
19678
19679- ktype_cache.default_attrs = default_attrs;
19680+ ktype = &ktype_cache;
19681 #ifdef CONFIG_AMD_NB
19682 if (this_leaf->base.nb)
19683- ktype_cache.default_attrs = amd_l3_attrs();
19684+ ktype = &ktype_cache_amd_nb;
19685 #endif
19686 retval = kobject_init_and_add(&(this_object->kobj),
19687- &ktype_cache,
19688+ ktype,
19689 per_cpu(ici_cache_kobject, cpu),
19690 "index%1lu", i);
19691 if (unlikely(retval)) {
19692diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
19693index 87a65c9..92fcce6 100644
19694--- a/arch/x86/kernel/cpu/mcheck/mce.c
19695+++ b/arch/x86/kernel/cpu/mcheck/mce.c
19696@@ -45,6 +45,7 @@
19697 #include <asm/processor.h>
19698 #include <asm/mce.h>
19699 #include <asm/msr.h>
19700+#include <asm/local.h>
19701
19702 #include "mce-internal.h"
19703
19704@@ -249,7 +250,7 @@ static void print_mce(struct mce *m)
19705 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
19706 m->cs, m->ip);
19707
19708- if (m->cs == __KERNEL_CS)
19709+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
19710 print_symbol("{%s}", m->ip);
19711 pr_cont("\n");
19712 }
19713@@ -282,10 +283,10 @@ static void print_mce(struct mce *m)
19714
19715 #define PANIC_TIMEOUT 5 /* 5 seconds */
19716
19717-static atomic_t mce_paniced;
19718+static atomic_unchecked_t mce_paniced;
19719
19720 static int fake_panic;
19721-static atomic_t mce_fake_paniced;
19722+static atomic_unchecked_t mce_fake_paniced;
19723
19724 /* Panic in progress. Enable interrupts and wait for final IPI */
19725 static void wait_for_panic(void)
19726@@ -309,7 +310,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
19727 /*
19728 * Make sure only one CPU runs in machine check panic
19729 */
19730- if (atomic_inc_return(&mce_paniced) > 1)
19731+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
19732 wait_for_panic();
19733 barrier();
19734
19735@@ -317,7 +318,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
19736 console_verbose();
19737 } else {
19738 /* Don't log too much for fake panic */
19739- if (atomic_inc_return(&mce_fake_paniced) > 1)
19740+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
19741 return;
19742 }
19743 /* First print corrected ones that are still unlogged */
19744@@ -356,7 +357,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
19745 if (!fake_panic) {
19746 if (panic_timeout == 0)
19747 panic_timeout = mca_cfg.panic_timeout;
19748- panic(msg);
19749+ panic("%s", msg);
19750 } else
19751 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
19752 }
19753@@ -686,7 +687,7 @@ static int mce_timed_out(u64 *t)
19754 * might have been modified by someone else.
19755 */
19756 rmb();
19757- if (atomic_read(&mce_paniced))
19758+ if (atomic_read_unchecked(&mce_paniced))
19759 wait_for_panic();
19760 if (!mca_cfg.monarch_timeout)
19761 goto out;
19762@@ -1657,7 +1658,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
19763 }
19764
19765 /* Call the installed machine check handler for this CPU setup. */
19766-void (*machine_check_vector)(struct pt_regs *, long error_code) =
19767+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
19768 unexpected_machine_check;
19769
19770 /*
19771@@ -1680,7 +1681,9 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
19772 return;
19773 }
19774
19775+ pax_open_kernel();
19776 machine_check_vector = do_machine_check;
19777+ pax_close_kernel();
19778
19779 __mcheck_cpu_init_generic();
19780 __mcheck_cpu_init_vendor(c);
19781@@ -1694,7 +1697,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
19782 */
19783
19784 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
19785-static int mce_chrdev_open_count; /* #times opened */
19786+static local_t mce_chrdev_open_count; /* #times opened */
19787 static int mce_chrdev_open_exclu; /* already open exclusive? */
19788
19789 static int mce_chrdev_open(struct inode *inode, struct file *file)
19790@@ -1702,7 +1705,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
19791 spin_lock(&mce_chrdev_state_lock);
19792
19793 if (mce_chrdev_open_exclu ||
19794- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
19795+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
19796 spin_unlock(&mce_chrdev_state_lock);
19797
19798 return -EBUSY;
19799@@ -1710,7 +1713,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
19800
19801 if (file->f_flags & O_EXCL)
19802 mce_chrdev_open_exclu = 1;
19803- mce_chrdev_open_count++;
19804+ local_inc(&mce_chrdev_open_count);
19805
19806 spin_unlock(&mce_chrdev_state_lock);
19807
19808@@ -1721,7 +1724,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
19809 {
19810 spin_lock(&mce_chrdev_state_lock);
19811
19812- mce_chrdev_open_count--;
19813+ local_dec(&mce_chrdev_open_count);
19814 mce_chrdev_open_exclu = 0;
19815
19816 spin_unlock(&mce_chrdev_state_lock);
19817@@ -2376,7 +2379,7 @@ static __init void mce_init_banks(void)
19818
19819 for (i = 0; i < mca_cfg.banks; i++) {
19820 struct mce_bank *b = &mce_banks[i];
19821- struct device_attribute *a = &b->attr;
19822+ device_attribute_no_const *a = &b->attr;
19823
19824 sysfs_attr_init(&a->attr);
19825 a->attr.name = b->attrname;
19826@@ -2444,7 +2447,7 @@ struct dentry *mce_get_debugfs_dir(void)
19827 static void mce_reset(void)
19828 {
19829 cpu_missing = 0;
19830- atomic_set(&mce_fake_paniced, 0);
19831+ atomic_set_unchecked(&mce_fake_paniced, 0);
19832 atomic_set(&mce_executing, 0);
19833 atomic_set(&mce_callin, 0);
19834 atomic_set(&global_nwo, 0);
19835diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
19836index 1c044b1..37a2a43 100644
19837--- a/arch/x86/kernel/cpu/mcheck/p5.c
19838+++ b/arch/x86/kernel/cpu/mcheck/p5.c
19839@@ -11,6 +11,7 @@
19840 #include <asm/processor.h>
19841 #include <asm/mce.h>
19842 #include <asm/msr.h>
19843+#include <asm/pgtable.h>
19844
19845 /* By default disabled */
19846 int mce_p5_enabled __read_mostly;
19847@@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
19848 if (!cpu_has(c, X86_FEATURE_MCE))
19849 return;
19850
19851+ pax_open_kernel();
19852 machine_check_vector = pentium_machine_check;
19853+ pax_close_kernel();
19854 /* Make sure the vector pointer is visible before we enable MCEs: */
19855 wmb();
19856
19857diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
19858index e9a701a..35317d6 100644
19859--- a/arch/x86/kernel/cpu/mcheck/winchip.c
19860+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
19861@@ -10,6 +10,7 @@
19862 #include <asm/processor.h>
19863 #include <asm/mce.h>
19864 #include <asm/msr.h>
19865+#include <asm/pgtable.h>
19866
19867 /* Machine check handler for WinChip C6: */
19868 static void winchip_machine_check(struct pt_regs *regs, long error_code)
19869@@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
19870 {
19871 u32 lo, hi;
19872
19873+ pax_open_kernel();
19874 machine_check_vector = winchip_machine_check;
19875+ pax_close_kernel();
19876 /* Make sure the vector pointer is visible before we enable MCEs: */
19877 wmb();
19878
19879diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
19880index f961de9..8a9d332 100644
19881--- a/arch/x86/kernel/cpu/mtrr/main.c
19882+++ b/arch/x86/kernel/cpu/mtrr/main.c
19883@@ -66,7 +66,7 @@ static DEFINE_MUTEX(mtrr_mutex);
19884 u64 size_or_mask, size_and_mask;
19885 static bool mtrr_aps_delayed_init;
19886
19887-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
19888+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
19889
19890 const struct mtrr_ops *mtrr_if;
19891
19892diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
19893index df5e41f..816c719 100644
19894--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
19895+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
19896@@ -25,7 +25,7 @@ struct mtrr_ops {
19897 int (*validate_add_page)(unsigned long base, unsigned long size,
19898 unsigned int type);
19899 int (*have_wrcomb)(void);
19900-};
19901+} __do_const;
19902
19903 extern int generic_get_free_region(unsigned long base, unsigned long size,
19904 int replace_reg);
19905diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
19906index a7c7305..b9705ab 100644
19907--- a/arch/x86/kernel/cpu/perf_event.c
19908+++ b/arch/x86/kernel/cpu/perf_event.c
19909@@ -1348,7 +1348,7 @@ static void __init pmu_check_apic(void)
19910 pr_info("no hardware sampling interrupt available.\n");
19911 }
19912
19913-static struct attribute_group x86_pmu_format_group = {
19914+static attribute_group_no_const x86_pmu_format_group = {
19915 .name = "format",
19916 .attrs = NULL,
19917 };
19918@@ -1447,7 +1447,7 @@ static struct attribute *events_attr[] = {
19919 NULL,
19920 };
19921
19922-static struct attribute_group x86_pmu_events_group = {
19923+static attribute_group_no_const x86_pmu_events_group = {
19924 .name = "events",
19925 .attrs = events_attr,
19926 };
19927@@ -1957,7 +1957,7 @@ static unsigned long get_segment_base(unsigned int segment)
19928 if (idx > GDT_ENTRIES)
19929 return 0;
19930
19931- desc = __this_cpu_ptr(&gdt_page.gdt[0]);
19932+ desc = get_cpu_gdt_table(smp_processor_id());
19933 }
19934
19935 return get_desc_base(desc + idx);
19936@@ -2047,7 +2047,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
19937 break;
19938
19939 perf_callchain_store(entry, frame.return_address);
19940- fp = frame.next_frame;
19941+ fp = (const void __force_user *)frame.next_frame;
19942 }
19943 }
19944
19945diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
19946index 639d128..e92d7e5 100644
19947--- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c
19948+++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
19949@@ -405,7 +405,7 @@ static void perf_iommu_del(struct perf_event *event, int flags)
19950 static __init int _init_events_attrs(struct perf_amd_iommu *perf_iommu)
19951 {
19952 struct attribute **attrs;
19953- struct attribute_group *attr_group;
19954+ attribute_group_no_const *attr_group;
19955 int i = 0, j;
19956
19957 while (amd_iommu_v2_event_descs[i].attr.attr.name)
19958diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
19959index a45d8d4..8abd32c 100644
19960--- a/arch/x86/kernel/cpu/perf_event_intel.c
19961+++ b/arch/x86/kernel/cpu/perf_event_intel.c
19962@@ -2099,10 +2099,10 @@ __init int intel_pmu_init(void)
19963 * v2 and above have a perf capabilities MSR
19964 */
19965 if (version > 1) {
19966- u64 capabilities;
19967+ u64 capabilities = x86_pmu.intel_cap.capabilities;
19968
19969- rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
19970- x86_pmu.intel_cap.capabilities = capabilities;
19971+ if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
19972+ x86_pmu.intel_cap.capabilities = capabilities;
19973 }
19974
19975 intel_ds_init();
19976diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
19977index 1fb6c72..f5fa2a3 100644
19978--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
19979+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
19980@@ -3095,7 +3095,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
19981 static int __init uncore_type_init(struct intel_uncore_type *type)
19982 {
19983 struct intel_uncore_pmu *pmus;
19984- struct attribute_group *attr_group;
19985+ attribute_group_no_const *attr_group;
19986 struct attribute **attrs;
19987 int i, j;
19988
19989diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
19990index 47b3d00c..2cf1751 100644
19991--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
19992+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
19993@@ -488,7 +488,7 @@ struct intel_uncore_box {
19994 struct uncore_event_desc {
19995 struct kobj_attribute attr;
19996 const char *config;
19997-};
19998+} __do_const;
19999
20000 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
20001 { \
20002diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
20003index 7d9481c..99c7e4b 100644
20004--- a/arch/x86/kernel/cpuid.c
20005+++ b/arch/x86/kernel/cpuid.c
20006@@ -170,7 +170,7 @@ static int cpuid_class_cpu_callback(struct notifier_block *nfb,
20007 return notifier_from_errno(err);
20008 }
20009
20010-static struct notifier_block __refdata cpuid_class_cpu_notifier =
20011+static struct notifier_block cpuid_class_cpu_notifier =
20012 {
20013 .notifier_call = cpuid_class_cpu_callback,
20014 };
20015diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
20016index 74467fe..18793d5 100644
20017--- a/arch/x86/kernel/crash.c
20018+++ b/arch/x86/kernel/crash.c
20019@@ -58,10 +58,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
20020 {
20021 #ifdef CONFIG_X86_32
20022 struct pt_regs fixed_regs;
20023-#endif
20024
20025-#ifdef CONFIG_X86_32
20026- if (!user_mode_vm(regs)) {
20027+ if (!user_mode(regs)) {
20028 crash_fixup_ss_esp(&fixed_regs, regs);
20029 regs = &fixed_regs;
20030 }
20031diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
20032index afa64ad..dce67dd 100644
20033--- a/arch/x86/kernel/crash_dump_64.c
20034+++ b/arch/x86/kernel/crash_dump_64.c
20035@@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
20036 return -ENOMEM;
20037
20038 if (userbuf) {
20039- if (copy_to_user(buf, vaddr + offset, csize)) {
20040+ if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
20041 iounmap(vaddr);
20042 return -EFAULT;
20043 }
20044diff --git a/arch/x86/kernel/doublefault.c b/arch/x86/kernel/doublefault.c
20045index 5d3fe8d..02e1429 100644
20046--- a/arch/x86/kernel/doublefault.c
20047+++ b/arch/x86/kernel/doublefault.c
20048@@ -13,7 +13,7 @@
20049
20050 #define DOUBLEFAULT_STACKSIZE (1024)
20051 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
20052-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
20053+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
20054
20055 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
20056
20057@@ -23,7 +23,7 @@ static void doublefault_fn(void)
20058 unsigned long gdt, tss;
20059
20060 native_store_gdt(&gdt_desc);
20061- gdt = gdt_desc.address;
20062+ gdt = (unsigned long)gdt_desc.address;
20063
20064 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
20065
20066@@ -60,10 +60,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
20067 /* 0x2 bit is always set */
20068 .flags = X86_EFLAGS_SF | 0x2,
20069 .sp = STACK_START,
20070- .es = __USER_DS,
20071+ .es = __KERNEL_DS,
20072 .cs = __KERNEL_CS,
20073 .ss = __KERNEL_DS,
20074- .ds = __USER_DS,
20075+ .ds = __KERNEL_DS,
20076 .fs = __KERNEL_PERCPU,
20077
20078 .__cr3 = __pa_nodebug(swapper_pg_dir),
20079diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
20080index deb6421..76bbc12 100644
20081--- a/arch/x86/kernel/dumpstack.c
20082+++ b/arch/x86/kernel/dumpstack.c
20083@@ -2,6 +2,9 @@
20084 * Copyright (C) 1991, 1992 Linus Torvalds
20085 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
20086 */
20087+#ifdef CONFIG_GRKERNSEC_HIDESYM
20088+#define __INCLUDED_BY_HIDESYM 1
20089+#endif
20090 #include <linux/kallsyms.h>
20091 #include <linux/kprobes.h>
20092 #include <linux/uaccess.h>
20093@@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
20094 static void
20095 print_ftrace_graph_addr(unsigned long addr, void *data,
20096 const struct stacktrace_ops *ops,
20097- struct thread_info *tinfo, int *graph)
20098+ struct task_struct *task, int *graph)
20099 {
20100- struct task_struct *task;
20101 unsigned long ret_addr;
20102 int index;
20103
20104 if (addr != (unsigned long)return_to_handler)
20105 return;
20106
20107- task = tinfo->task;
20108 index = task->curr_ret_stack;
20109
20110 if (!task->ret_stack || index < *graph)
20111@@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
20112 static inline void
20113 print_ftrace_graph_addr(unsigned long addr, void *data,
20114 const struct stacktrace_ops *ops,
20115- struct thread_info *tinfo, int *graph)
20116+ struct task_struct *task, int *graph)
20117 { }
20118 #endif
20119
20120@@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
20121 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
20122 */
20123
20124-static inline int valid_stack_ptr(struct thread_info *tinfo,
20125- void *p, unsigned int size, void *end)
20126+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
20127 {
20128- void *t = tinfo;
20129 if (end) {
20130 if (p < end && p >= (end-THREAD_SIZE))
20131 return 1;
20132@@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
20133 }
20134
20135 unsigned long
20136-print_context_stack(struct thread_info *tinfo,
20137+print_context_stack(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 {
20142 struct stack_frame *frame = (struct stack_frame *)bp;
20143
20144- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
20145+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
20146 unsigned long addr;
20147
20148 addr = *stack;
20149@@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
20150 } else {
20151 ops->address(data, addr, 0);
20152 }
20153- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
20154+ print_ftrace_graph_addr(addr, data, ops, task, graph);
20155 }
20156 stack++;
20157 }
20158@@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
20159 EXPORT_SYMBOL_GPL(print_context_stack);
20160
20161 unsigned long
20162-print_context_stack_bp(struct thread_info *tinfo,
20163+print_context_stack_bp(struct task_struct *task, void *stack_start,
20164 unsigned long *stack, unsigned long bp,
20165 const struct stacktrace_ops *ops, void *data,
20166 unsigned long *end, int *graph)
20167@@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
20168 struct stack_frame *frame = (struct stack_frame *)bp;
20169 unsigned long *ret_addr = &frame->return_address;
20170
20171- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
20172+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
20173 unsigned long addr = *ret_addr;
20174
20175 if (!__kernel_text_address(addr))
20176@@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
20177 ops->address(data, addr, 1);
20178 frame = frame->next_frame;
20179 ret_addr = &frame->return_address;
20180- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
20181+ print_ftrace_graph_addr(addr, data, ops, task, graph);
20182 }
20183
20184 return (unsigned long)frame;
20185@@ -150,7 +149,7 @@ static int print_trace_stack(void *data, char *name)
20186 static void print_trace_address(void *data, unsigned long addr, int reliable)
20187 {
20188 touch_nmi_watchdog();
20189- printk(data);
20190+ printk("%s", (char *)data);
20191 printk_address(addr, reliable);
20192 }
20193
20194@@ -219,6 +218,8 @@ unsigned __kprobes long oops_begin(void)
20195 }
20196 EXPORT_SYMBOL_GPL(oops_begin);
20197
20198+extern void gr_handle_kernel_exploit(void);
20199+
20200 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
20201 {
20202 if (regs && kexec_should_crash(current))
20203@@ -240,7 +241,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
20204 panic("Fatal exception in interrupt");
20205 if (panic_on_oops)
20206 panic("Fatal exception");
20207- do_exit(signr);
20208+
20209+ gr_handle_kernel_exploit();
20210+
20211+ do_group_exit(signr);
20212 }
20213
20214 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
20215@@ -268,7 +272,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
20216 print_modules();
20217 show_regs(regs);
20218 #ifdef CONFIG_X86_32
20219- if (user_mode_vm(regs)) {
20220+ if (user_mode(regs)) {
20221 sp = regs->sp;
20222 ss = regs->ss & 0xffff;
20223 } else {
20224@@ -296,7 +300,7 @@ void die(const char *str, struct pt_regs *regs, long err)
20225 unsigned long flags = oops_begin();
20226 int sig = SIGSEGV;
20227
20228- if (!user_mode_vm(regs))
20229+ if (!user_mode(regs))
20230 report_bug(regs->ip, regs);
20231
20232 if (__die(str, regs, err))
20233diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
20234index f2a1770..540657f 100644
20235--- a/arch/x86/kernel/dumpstack_32.c
20236+++ b/arch/x86/kernel/dumpstack_32.c
20237@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20238 bp = stack_frame(task, regs);
20239
20240 for (;;) {
20241- struct thread_info *context;
20242+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
20243
20244- context = (struct thread_info *)
20245- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
20246- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
20247+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
20248
20249- stack = (unsigned long *)context->previous_esp;
20250- if (!stack)
20251+ if (stack_start == task_stack_page(task))
20252 break;
20253+ stack = *(unsigned long **)stack_start;
20254 if (ops->stack(data, "IRQ") < 0)
20255 break;
20256 touch_nmi_watchdog();
20257@@ -87,27 +85,28 @@ void show_regs(struct pt_regs *regs)
20258 int i;
20259
20260 show_regs_print_info(KERN_EMERG);
20261- __show_regs(regs, !user_mode_vm(regs));
20262+ __show_regs(regs, !user_mode(regs));
20263
20264 /*
20265 * When in-kernel, we also print out the stack and code at the
20266 * time of the fault..
20267 */
20268- if (!user_mode_vm(regs)) {
20269+ if (!user_mode(regs)) {
20270 unsigned int code_prologue = code_bytes * 43 / 64;
20271 unsigned int code_len = code_bytes;
20272 unsigned char c;
20273 u8 *ip;
20274+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
20275
20276 pr_emerg("Stack:\n");
20277 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
20278
20279 pr_emerg("Code:");
20280
20281- ip = (u8 *)regs->ip - code_prologue;
20282+ ip = (u8 *)regs->ip - code_prologue + cs_base;
20283 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
20284 /* try starting at IP */
20285- ip = (u8 *)regs->ip;
20286+ ip = (u8 *)regs->ip + cs_base;
20287 code_len = code_len - code_prologue + 1;
20288 }
20289 for (i = 0; i < code_len; i++, ip++) {
20290@@ -116,7 +115,7 @@ void show_regs(struct pt_regs *regs)
20291 pr_cont(" Bad EIP value.");
20292 break;
20293 }
20294- if (ip == (u8 *)regs->ip)
20295+ if (ip == (u8 *)regs->ip + cs_base)
20296 pr_cont(" <%02x>", c);
20297 else
20298 pr_cont(" %02x", c);
20299@@ -129,6 +128,7 @@ int is_valid_bugaddr(unsigned long ip)
20300 {
20301 unsigned short ud2;
20302
20303+ ip = ktla_ktva(ip);
20304 if (ip < PAGE_OFFSET)
20305 return 0;
20306 if (probe_kernel_address((unsigned short *)ip, ud2))
20307@@ -136,3 +136,15 @@ int is_valid_bugaddr(unsigned long ip)
20308
20309 return ud2 == 0x0b0f;
20310 }
20311+
20312+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
20313+void pax_check_alloca(unsigned long size)
20314+{
20315+ unsigned long sp = (unsigned long)&sp, stack_left;
20316+
20317+ /* all kernel stacks are of the same size */
20318+ stack_left = sp & (THREAD_SIZE - 1);
20319+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
20320+}
20321+EXPORT_SYMBOL(pax_check_alloca);
20322+#endif
20323diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
20324index addb207..99635fa 100644
20325--- a/arch/x86/kernel/dumpstack_64.c
20326+++ b/arch/x86/kernel/dumpstack_64.c
20327@@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20328 unsigned long *irq_stack_end =
20329 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
20330 unsigned used = 0;
20331- struct thread_info *tinfo;
20332 int graph = 0;
20333 unsigned long dummy;
20334+ void *stack_start;
20335
20336 if (!task)
20337 task = current;
20338@@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20339 * current stack address. If the stacks consist of nested
20340 * exceptions
20341 */
20342- tinfo = task_thread_info(task);
20343 for (;;) {
20344 char *id;
20345 unsigned long *estack_end;
20346+
20347 estack_end = in_exception_stack(cpu, (unsigned long)stack,
20348 &used, &id);
20349
20350@@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20351 if (ops->stack(data, id) < 0)
20352 break;
20353
20354- bp = ops->walk_stack(tinfo, stack, bp, ops,
20355+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
20356 data, estack_end, &graph);
20357 ops->stack(data, "<EOE>");
20358 /*
20359@@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20360 * second-to-last pointer (index -2 to end) in the
20361 * exception stack:
20362 */
20363+ if ((u16)estack_end[-1] != __KERNEL_DS)
20364+ goto out;
20365 stack = (unsigned long *) estack_end[-2];
20366 continue;
20367 }
20368@@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20369 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
20370 if (ops->stack(data, "IRQ") < 0)
20371 break;
20372- bp = ops->walk_stack(tinfo, stack, bp,
20373+ bp = ops->walk_stack(task, irq_stack, stack, bp,
20374 ops, data, irq_stack_end, &graph);
20375 /*
20376 * We link to the next stack (which would be
20377@@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20378 /*
20379 * This handles the process stack:
20380 */
20381- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
20382+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
20383+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
20384+out:
20385 put_cpu();
20386 }
20387 EXPORT_SYMBOL(dump_trace);
20388@@ -300,3 +304,50 @@ int is_valid_bugaddr(unsigned long ip)
20389
20390 return ud2 == 0x0b0f;
20391 }
20392+
20393+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
20394+void pax_check_alloca(unsigned long size)
20395+{
20396+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
20397+ unsigned cpu, used;
20398+ char *id;
20399+
20400+ /* check the process stack first */
20401+ stack_start = (unsigned long)task_stack_page(current);
20402+ stack_end = stack_start + THREAD_SIZE;
20403+ if (likely(stack_start <= sp && sp < stack_end)) {
20404+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
20405+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
20406+ return;
20407+ }
20408+
20409+ cpu = get_cpu();
20410+
20411+ /* check the irq stacks */
20412+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
20413+ stack_start = stack_end - IRQ_STACK_SIZE;
20414+ if (stack_start <= sp && sp < stack_end) {
20415+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
20416+ put_cpu();
20417+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
20418+ return;
20419+ }
20420+
20421+ /* check the exception stacks */
20422+ used = 0;
20423+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
20424+ stack_start = stack_end - EXCEPTION_STKSZ;
20425+ if (stack_end && stack_start <= sp && sp < stack_end) {
20426+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
20427+ put_cpu();
20428+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
20429+ return;
20430+ }
20431+
20432+ put_cpu();
20433+
20434+ /* unknown stack */
20435+ BUG();
20436+}
20437+EXPORT_SYMBOL(pax_check_alloca);
20438+#endif
20439diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
20440index d32abea..74daf4f 100644
20441--- a/arch/x86/kernel/e820.c
20442+++ b/arch/x86/kernel/e820.c
20443@@ -800,8 +800,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
20444
20445 static void early_panic(char *msg)
20446 {
20447- early_printk(msg);
20448- panic(msg);
20449+ early_printk("%s", msg);
20450+ panic("%s", msg);
20451 }
20452
20453 static int userdef __initdata;
20454diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
20455index d15f575..d692043 100644
20456--- a/arch/x86/kernel/early_printk.c
20457+++ b/arch/x86/kernel/early_printk.c
20458@@ -7,6 +7,7 @@
20459 #include <linux/pci_regs.h>
20460 #include <linux/pci_ids.h>
20461 #include <linux/errno.h>
20462+#include <linux/sched.h>
20463 #include <asm/io.h>
20464 #include <asm/processor.h>
20465 #include <asm/fcntl.h>
20466diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
20467index 2cfbc3a..b756682 100644
20468--- a/arch/x86/kernel/entry_32.S
20469+++ b/arch/x86/kernel/entry_32.S
20470@@ -177,13 +177,153 @@
20471 /*CFI_REL_OFFSET gs, PT_GS*/
20472 .endm
20473 .macro SET_KERNEL_GS reg
20474+
20475+#ifdef CONFIG_CC_STACKPROTECTOR
20476 movl $(__KERNEL_STACK_CANARY), \reg
20477+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
20478+ movl $(__USER_DS), \reg
20479+#else
20480+ xorl \reg, \reg
20481+#endif
20482+
20483 movl \reg, %gs
20484 .endm
20485
20486 #endif /* CONFIG_X86_32_LAZY_GS */
20487
20488-.macro SAVE_ALL
20489+.macro pax_enter_kernel
20490+#ifdef CONFIG_PAX_KERNEXEC
20491+ call pax_enter_kernel
20492+#endif
20493+.endm
20494+
20495+.macro pax_exit_kernel
20496+#ifdef CONFIG_PAX_KERNEXEC
20497+ call pax_exit_kernel
20498+#endif
20499+.endm
20500+
20501+#ifdef CONFIG_PAX_KERNEXEC
20502+ENTRY(pax_enter_kernel)
20503+#ifdef CONFIG_PARAVIRT
20504+ pushl %eax
20505+ pushl %ecx
20506+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
20507+ mov %eax, %esi
20508+#else
20509+ mov %cr0, %esi
20510+#endif
20511+ bts $16, %esi
20512+ jnc 1f
20513+ mov %cs, %esi
20514+ cmp $__KERNEL_CS, %esi
20515+ jz 3f
20516+ ljmp $__KERNEL_CS, $3f
20517+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
20518+2:
20519+#ifdef CONFIG_PARAVIRT
20520+ mov %esi, %eax
20521+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
20522+#else
20523+ mov %esi, %cr0
20524+#endif
20525+3:
20526+#ifdef CONFIG_PARAVIRT
20527+ popl %ecx
20528+ popl %eax
20529+#endif
20530+ ret
20531+ENDPROC(pax_enter_kernel)
20532+
20533+ENTRY(pax_exit_kernel)
20534+#ifdef CONFIG_PARAVIRT
20535+ pushl %eax
20536+ pushl %ecx
20537+#endif
20538+ mov %cs, %esi
20539+ cmp $__KERNEXEC_KERNEL_CS, %esi
20540+ jnz 2f
20541+#ifdef CONFIG_PARAVIRT
20542+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
20543+ mov %eax, %esi
20544+#else
20545+ mov %cr0, %esi
20546+#endif
20547+ btr $16, %esi
20548+ ljmp $__KERNEL_CS, $1f
20549+1:
20550+#ifdef CONFIG_PARAVIRT
20551+ mov %esi, %eax
20552+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
20553+#else
20554+ mov %esi, %cr0
20555+#endif
20556+2:
20557+#ifdef CONFIG_PARAVIRT
20558+ popl %ecx
20559+ popl %eax
20560+#endif
20561+ ret
20562+ENDPROC(pax_exit_kernel)
20563+#endif
20564+
20565+ .macro pax_erase_kstack
20566+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
20567+ call pax_erase_kstack
20568+#endif
20569+ .endm
20570+
20571+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
20572+/*
20573+ * ebp: thread_info
20574+ */
20575+ENTRY(pax_erase_kstack)
20576+ pushl %edi
20577+ pushl %ecx
20578+ pushl %eax
20579+
20580+ mov TI_lowest_stack(%ebp), %edi
20581+ mov $-0xBEEF, %eax
20582+ std
20583+
20584+1: mov %edi, %ecx
20585+ and $THREAD_SIZE_asm - 1, %ecx
20586+ shr $2, %ecx
20587+ repne scasl
20588+ jecxz 2f
20589+
20590+ cmp $2*16, %ecx
20591+ jc 2f
20592+
20593+ mov $2*16, %ecx
20594+ repe scasl
20595+ jecxz 2f
20596+ jne 1b
20597+
20598+2: cld
20599+ mov %esp, %ecx
20600+ sub %edi, %ecx
20601+
20602+ cmp $THREAD_SIZE_asm, %ecx
20603+ jb 3f
20604+ ud2
20605+3:
20606+
20607+ shr $2, %ecx
20608+ rep stosl
20609+
20610+ mov TI_task_thread_sp0(%ebp), %edi
20611+ sub $128, %edi
20612+ mov %edi, TI_lowest_stack(%ebp)
20613+
20614+ popl %eax
20615+ popl %ecx
20616+ popl %edi
20617+ ret
20618+ENDPROC(pax_erase_kstack)
20619+#endif
20620+
20621+.macro __SAVE_ALL _DS
20622 cld
20623 PUSH_GS
20624 pushl_cfi %fs
20625@@ -206,7 +346,7 @@
20626 CFI_REL_OFFSET ecx, 0
20627 pushl_cfi %ebx
20628 CFI_REL_OFFSET ebx, 0
20629- movl $(__USER_DS), %edx
20630+ movl $\_DS, %edx
20631 movl %edx, %ds
20632 movl %edx, %es
20633 movl $(__KERNEL_PERCPU), %edx
20634@@ -214,6 +354,15 @@
20635 SET_KERNEL_GS %edx
20636 .endm
20637
20638+.macro SAVE_ALL
20639+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
20640+ __SAVE_ALL __KERNEL_DS
20641+ pax_enter_kernel
20642+#else
20643+ __SAVE_ALL __USER_DS
20644+#endif
20645+.endm
20646+
20647 .macro RESTORE_INT_REGS
20648 popl_cfi %ebx
20649 CFI_RESTORE ebx
20650@@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
20651 popfl_cfi
20652 jmp syscall_exit
20653 CFI_ENDPROC
20654-END(ret_from_fork)
20655+ENDPROC(ret_from_fork)
20656
20657 ENTRY(ret_from_kernel_thread)
20658 CFI_STARTPROC
20659@@ -344,7 +493,15 @@ ret_from_intr:
20660 andl $SEGMENT_RPL_MASK, %eax
20661 #endif
20662 cmpl $USER_RPL, %eax
20663+
20664+#ifdef CONFIG_PAX_KERNEXEC
20665+ jae resume_userspace
20666+
20667+ pax_exit_kernel
20668+ jmp resume_kernel
20669+#else
20670 jb resume_kernel # not returning to v8086 or userspace
20671+#endif
20672
20673 ENTRY(resume_userspace)
20674 LOCKDEP_SYS_EXIT
20675@@ -356,8 +513,8 @@ ENTRY(resume_userspace)
20676 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
20677 # int/exception return?
20678 jne work_pending
20679- jmp restore_all
20680-END(ret_from_exception)
20681+ jmp restore_all_pax
20682+ENDPROC(ret_from_exception)
20683
20684 #ifdef CONFIG_PREEMPT
20685 ENTRY(resume_kernel)
20686@@ -372,7 +529,7 @@ need_resched:
20687 jz restore_all
20688 call preempt_schedule_irq
20689 jmp need_resched
20690-END(resume_kernel)
20691+ENDPROC(resume_kernel)
20692 #endif
20693 CFI_ENDPROC
20694 /*
20695@@ -406,30 +563,45 @@ sysenter_past_esp:
20696 /*CFI_REL_OFFSET cs, 0*/
20697 /*
20698 * Push current_thread_info()->sysenter_return to the stack.
20699- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
20700- * pushed above; +8 corresponds to copy_thread's esp0 setting.
20701 */
20702- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
20703+ pushl_cfi $0
20704 CFI_REL_OFFSET eip, 0
20705
20706 pushl_cfi %eax
20707 SAVE_ALL
20708+ GET_THREAD_INFO(%ebp)
20709+ movl TI_sysenter_return(%ebp),%ebp
20710+ movl %ebp,PT_EIP(%esp)
20711 ENABLE_INTERRUPTS(CLBR_NONE)
20712
20713 /*
20714 * Load the potential sixth argument from user stack.
20715 * Careful about security.
20716 */
20717+ movl PT_OLDESP(%esp),%ebp
20718+
20719+#ifdef CONFIG_PAX_MEMORY_UDEREF
20720+ mov PT_OLDSS(%esp),%ds
20721+1: movl %ds:(%ebp),%ebp
20722+ push %ss
20723+ pop %ds
20724+#else
20725 cmpl $__PAGE_OFFSET-3,%ebp
20726 jae syscall_fault
20727 ASM_STAC
20728 1: movl (%ebp),%ebp
20729 ASM_CLAC
20730+#endif
20731+
20732 movl %ebp,PT_EBP(%esp)
20733 _ASM_EXTABLE(1b,syscall_fault)
20734
20735 GET_THREAD_INFO(%ebp)
20736
20737+#ifdef CONFIG_PAX_RANDKSTACK
20738+ pax_erase_kstack
20739+#endif
20740+
20741 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
20742 jnz sysenter_audit
20743 sysenter_do_call:
20744@@ -444,12 +616,24 @@ sysenter_do_call:
20745 testl $_TIF_ALLWORK_MASK, %ecx
20746 jne sysexit_audit
20747 sysenter_exit:
20748+
20749+#ifdef CONFIG_PAX_RANDKSTACK
20750+ pushl_cfi %eax
20751+ movl %esp, %eax
20752+ call pax_randomize_kstack
20753+ popl_cfi %eax
20754+#endif
20755+
20756+ pax_erase_kstack
20757+
20758 /* if something modifies registers it must also disable sysexit */
20759 movl PT_EIP(%esp), %edx
20760 movl PT_OLDESP(%esp), %ecx
20761 xorl %ebp,%ebp
20762 TRACE_IRQS_ON
20763 1: mov PT_FS(%esp), %fs
20764+2: mov PT_DS(%esp), %ds
20765+3: mov PT_ES(%esp), %es
20766 PTGS_TO_GS
20767 ENABLE_INTERRUPTS_SYSEXIT
20768
20769@@ -466,6 +650,9 @@ sysenter_audit:
20770 movl %eax,%edx /* 2nd arg: syscall number */
20771 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
20772 call __audit_syscall_entry
20773+
20774+ pax_erase_kstack
20775+
20776 pushl_cfi %ebx
20777 movl PT_EAX(%esp),%eax /* reload syscall number */
20778 jmp sysenter_do_call
20779@@ -491,10 +678,16 @@ sysexit_audit:
20780
20781 CFI_ENDPROC
20782 .pushsection .fixup,"ax"
20783-2: movl $0,PT_FS(%esp)
20784+4: movl $0,PT_FS(%esp)
20785+ jmp 1b
20786+5: movl $0,PT_DS(%esp)
20787+ jmp 1b
20788+6: movl $0,PT_ES(%esp)
20789 jmp 1b
20790 .popsection
20791- _ASM_EXTABLE(1b,2b)
20792+ _ASM_EXTABLE(1b,4b)
20793+ _ASM_EXTABLE(2b,5b)
20794+ _ASM_EXTABLE(3b,6b)
20795 PTGS_TO_GS_EX
20796 ENDPROC(ia32_sysenter_target)
20797
20798@@ -509,6 +702,11 @@ ENTRY(system_call)
20799 pushl_cfi %eax # save orig_eax
20800 SAVE_ALL
20801 GET_THREAD_INFO(%ebp)
20802+
20803+#ifdef CONFIG_PAX_RANDKSTACK
20804+ pax_erase_kstack
20805+#endif
20806+
20807 # system call tracing in operation / emulation
20808 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
20809 jnz syscall_trace_entry
20810@@ -527,6 +725,15 @@ syscall_exit:
20811 testl $_TIF_ALLWORK_MASK, %ecx # current->work
20812 jne syscall_exit_work
20813
20814+restore_all_pax:
20815+
20816+#ifdef CONFIG_PAX_RANDKSTACK
20817+ movl %esp, %eax
20818+ call pax_randomize_kstack
20819+#endif
20820+
20821+ pax_erase_kstack
20822+
20823 restore_all:
20824 TRACE_IRQS_IRET
20825 restore_all_notrace:
20826@@ -583,14 +790,34 @@ ldt_ss:
20827 * compensating for the offset by changing to the ESPFIX segment with
20828 * a base address that matches for the difference.
20829 */
20830-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
20831+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
20832 mov %esp, %edx /* load kernel esp */
20833 mov PT_OLDESP(%esp), %eax /* load userspace esp */
20834 mov %dx, %ax /* eax: new kernel esp */
20835 sub %eax, %edx /* offset (low word is 0) */
20836+#ifdef CONFIG_SMP
20837+ movl PER_CPU_VAR(cpu_number), %ebx
20838+ shll $PAGE_SHIFT_asm, %ebx
20839+ addl $cpu_gdt_table, %ebx
20840+#else
20841+ movl $cpu_gdt_table, %ebx
20842+#endif
20843 shr $16, %edx
20844- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
20845- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
20846+
20847+#ifdef CONFIG_PAX_KERNEXEC
20848+ mov %cr0, %esi
20849+ btr $16, %esi
20850+ mov %esi, %cr0
20851+#endif
20852+
20853+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
20854+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
20855+
20856+#ifdef CONFIG_PAX_KERNEXEC
20857+ bts $16, %esi
20858+ mov %esi, %cr0
20859+#endif
20860+
20861 pushl_cfi $__ESPFIX_SS
20862 pushl_cfi %eax /* new kernel esp */
20863 /* Disable interrupts, but do not irqtrace this section: we
20864@@ -619,20 +846,18 @@ work_resched:
20865 movl TI_flags(%ebp), %ecx
20866 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
20867 # than syscall tracing?
20868- jz restore_all
20869+ jz restore_all_pax
20870 testb $_TIF_NEED_RESCHED, %cl
20871 jnz work_resched
20872
20873 work_notifysig: # deal with pending signals and
20874 # notify-resume requests
20875+ movl %esp, %eax
20876 #ifdef CONFIG_VM86
20877 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
20878- movl %esp, %eax
20879 jne work_notifysig_v86 # returning to kernel-space or
20880 # vm86-space
20881 1:
20882-#else
20883- movl %esp, %eax
20884 #endif
20885 TRACE_IRQS_ON
20886 ENABLE_INTERRUPTS(CLBR_NONE)
20887@@ -653,7 +878,7 @@ work_notifysig_v86:
20888 movl %eax, %esp
20889 jmp 1b
20890 #endif
20891-END(work_pending)
20892+ENDPROC(work_pending)
20893
20894 # perform syscall exit tracing
20895 ALIGN
20896@@ -661,11 +886,14 @@ syscall_trace_entry:
20897 movl $-ENOSYS,PT_EAX(%esp)
20898 movl %esp, %eax
20899 call syscall_trace_enter
20900+
20901+ pax_erase_kstack
20902+
20903 /* What it returned is what we'll actually use. */
20904 cmpl $(NR_syscalls), %eax
20905 jnae syscall_call
20906 jmp syscall_exit
20907-END(syscall_trace_entry)
20908+ENDPROC(syscall_trace_entry)
20909
20910 # perform syscall exit tracing
20911 ALIGN
20912@@ -678,21 +906,25 @@ syscall_exit_work:
20913 movl %esp, %eax
20914 call syscall_trace_leave
20915 jmp resume_userspace
20916-END(syscall_exit_work)
20917+ENDPROC(syscall_exit_work)
20918 CFI_ENDPROC
20919
20920 RING0_INT_FRAME # can't unwind into user space anyway
20921 syscall_fault:
20922+#ifdef CONFIG_PAX_MEMORY_UDEREF
20923+ push %ss
20924+ pop %ds
20925+#endif
20926 ASM_CLAC
20927 GET_THREAD_INFO(%ebp)
20928 movl $-EFAULT,PT_EAX(%esp)
20929 jmp resume_userspace
20930-END(syscall_fault)
20931+ENDPROC(syscall_fault)
20932
20933 syscall_badsys:
20934 movl $-ENOSYS,PT_EAX(%esp)
20935 jmp resume_userspace
20936-END(syscall_badsys)
20937+ENDPROC(syscall_badsys)
20938 CFI_ENDPROC
20939 /*
20940 * End of kprobes section
20941@@ -708,8 +940,15 @@ END(syscall_badsys)
20942 * normal stack and adjusts ESP with the matching offset.
20943 */
20944 /* fixup the stack */
20945- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
20946- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
20947+#ifdef CONFIG_SMP
20948+ movl PER_CPU_VAR(cpu_number), %ebx
20949+ shll $PAGE_SHIFT_asm, %ebx
20950+ addl $cpu_gdt_table, %ebx
20951+#else
20952+ movl $cpu_gdt_table, %ebx
20953+#endif
20954+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
20955+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
20956 shl $16, %eax
20957 addl %esp, %eax /* the adjusted stack pointer */
20958 pushl_cfi $__KERNEL_DS
20959@@ -762,7 +1001,7 @@ vector=vector+1
20960 .endr
20961 2: jmp common_interrupt
20962 .endr
20963-END(irq_entries_start)
20964+ENDPROC(irq_entries_start)
20965
20966 .previous
20967 END(interrupt)
20968@@ -823,7 +1062,7 @@ ENTRY(coprocessor_error)
20969 pushl_cfi $do_coprocessor_error
20970 jmp error_code
20971 CFI_ENDPROC
20972-END(coprocessor_error)
20973+ENDPROC(coprocessor_error)
20974
20975 ENTRY(simd_coprocessor_error)
20976 RING0_INT_FRAME
20977@@ -836,7 +1075,7 @@ ENTRY(simd_coprocessor_error)
20978 .section .altinstructions,"a"
20979 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
20980 .previous
20981-.section .altinstr_replacement,"ax"
20982+.section .altinstr_replacement,"a"
20983 663: pushl $do_simd_coprocessor_error
20984 664:
20985 .previous
20986@@ -845,7 +1084,7 @@ ENTRY(simd_coprocessor_error)
20987 #endif
20988 jmp error_code
20989 CFI_ENDPROC
20990-END(simd_coprocessor_error)
20991+ENDPROC(simd_coprocessor_error)
20992
20993 ENTRY(device_not_available)
20994 RING0_INT_FRAME
20995@@ -854,18 +1093,18 @@ ENTRY(device_not_available)
20996 pushl_cfi $do_device_not_available
20997 jmp error_code
20998 CFI_ENDPROC
20999-END(device_not_available)
21000+ENDPROC(device_not_available)
21001
21002 #ifdef CONFIG_PARAVIRT
21003 ENTRY(native_iret)
21004 iret
21005 _ASM_EXTABLE(native_iret, iret_exc)
21006-END(native_iret)
21007+ENDPROC(native_iret)
21008
21009 ENTRY(native_irq_enable_sysexit)
21010 sti
21011 sysexit
21012-END(native_irq_enable_sysexit)
21013+ENDPROC(native_irq_enable_sysexit)
21014 #endif
21015
21016 ENTRY(overflow)
21017@@ -875,7 +1114,7 @@ ENTRY(overflow)
21018 pushl_cfi $do_overflow
21019 jmp error_code
21020 CFI_ENDPROC
21021-END(overflow)
21022+ENDPROC(overflow)
21023
21024 ENTRY(bounds)
21025 RING0_INT_FRAME
21026@@ -884,7 +1123,7 @@ ENTRY(bounds)
21027 pushl_cfi $do_bounds
21028 jmp error_code
21029 CFI_ENDPROC
21030-END(bounds)
21031+ENDPROC(bounds)
21032
21033 ENTRY(invalid_op)
21034 RING0_INT_FRAME
21035@@ -893,7 +1132,7 @@ ENTRY(invalid_op)
21036 pushl_cfi $do_invalid_op
21037 jmp error_code
21038 CFI_ENDPROC
21039-END(invalid_op)
21040+ENDPROC(invalid_op)
21041
21042 ENTRY(coprocessor_segment_overrun)
21043 RING0_INT_FRAME
21044@@ -902,7 +1141,7 @@ ENTRY(coprocessor_segment_overrun)
21045 pushl_cfi $do_coprocessor_segment_overrun
21046 jmp error_code
21047 CFI_ENDPROC
21048-END(coprocessor_segment_overrun)
21049+ENDPROC(coprocessor_segment_overrun)
21050
21051 ENTRY(invalid_TSS)
21052 RING0_EC_FRAME
21053@@ -910,7 +1149,7 @@ ENTRY(invalid_TSS)
21054 pushl_cfi $do_invalid_TSS
21055 jmp error_code
21056 CFI_ENDPROC
21057-END(invalid_TSS)
21058+ENDPROC(invalid_TSS)
21059
21060 ENTRY(segment_not_present)
21061 RING0_EC_FRAME
21062@@ -918,7 +1157,7 @@ ENTRY(segment_not_present)
21063 pushl_cfi $do_segment_not_present
21064 jmp error_code
21065 CFI_ENDPROC
21066-END(segment_not_present)
21067+ENDPROC(segment_not_present)
21068
21069 ENTRY(stack_segment)
21070 RING0_EC_FRAME
21071@@ -926,7 +1165,7 @@ ENTRY(stack_segment)
21072 pushl_cfi $do_stack_segment
21073 jmp error_code
21074 CFI_ENDPROC
21075-END(stack_segment)
21076+ENDPROC(stack_segment)
21077
21078 ENTRY(alignment_check)
21079 RING0_EC_FRAME
21080@@ -934,7 +1173,7 @@ ENTRY(alignment_check)
21081 pushl_cfi $do_alignment_check
21082 jmp error_code
21083 CFI_ENDPROC
21084-END(alignment_check)
21085+ENDPROC(alignment_check)
21086
21087 ENTRY(divide_error)
21088 RING0_INT_FRAME
21089@@ -943,7 +1182,7 @@ ENTRY(divide_error)
21090 pushl_cfi $do_divide_error
21091 jmp error_code
21092 CFI_ENDPROC
21093-END(divide_error)
21094+ENDPROC(divide_error)
21095
21096 #ifdef CONFIG_X86_MCE
21097 ENTRY(machine_check)
21098@@ -953,7 +1192,7 @@ ENTRY(machine_check)
21099 pushl_cfi machine_check_vector
21100 jmp error_code
21101 CFI_ENDPROC
21102-END(machine_check)
21103+ENDPROC(machine_check)
21104 #endif
21105
21106 ENTRY(spurious_interrupt_bug)
21107@@ -963,7 +1202,7 @@ ENTRY(spurious_interrupt_bug)
21108 pushl_cfi $do_spurious_interrupt_bug
21109 jmp error_code
21110 CFI_ENDPROC
21111-END(spurious_interrupt_bug)
21112+ENDPROC(spurious_interrupt_bug)
21113 /*
21114 * End of kprobes section
21115 */
21116@@ -1073,7 +1312,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
21117
21118 ENTRY(mcount)
21119 ret
21120-END(mcount)
21121+ENDPROC(mcount)
21122
21123 ENTRY(ftrace_caller)
21124 cmpl $0, function_trace_stop
21125@@ -1106,7 +1345,7 @@ ftrace_graph_call:
21126 .globl ftrace_stub
21127 ftrace_stub:
21128 ret
21129-END(ftrace_caller)
21130+ENDPROC(ftrace_caller)
21131
21132 ENTRY(ftrace_regs_caller)
21133 pushf /* push flags before compare (in cs location) */
21134@@ -1207,7 +1446,7 @@ trace:
21135 popl %ecx
21136 popl %eax
21137 jmp ftrace_stub
21138-END(mcount)
21139+ENDPROC(mcount)
21140 #endif /* CONFIG_DYNAMIC_FTRACE */
21141 #endif /* CONFIG_FUNCTION_TRACER */
21142
21143@@ -1225,7 +1464,7 @@ ENTRY(ftrace_graph_caller)
21144 popl %ecx
21145 popl %eax
21146 ret
21147-END(ftrace_graph_caller)
21148+ENDPROC(ftrace_graph_caller)
21149
21150 .globl return_to_handler
21151 return_to_handler:
21152@@ -1281,15 +1520,18 @@ error_code:
21153 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
21154 REG_TO_PTGS %ecx
21155 SET_KERNEL_GS %ecx
21156- movl $(__USER_DS), %ecx
21157+ movl $(__KERNEL_DS), %ecx
21158 movl %ecx, %ds
21159 movl %ecx, %es
21160+
21161+ pax_enter_kernel
21162+
21163 TRACE_IRQS_OFF
21164 movl %esp,%eax # pt_regs pointer
21165 call *%edi
21166 jmp ret_from_exception
21167 CFI_ENDPROC
21168-END(page_fault)
21169+ENDPROC(page_fault)
21170
21171 /*
21172 * Debug traps and NMI can happen at the one SYSENTER instruction
21173@@ -1332,7 +1574,7 @@ debug_stack_correct:
21174 call do_debug
21175 jmp ret_from_exception
21176 CFI_ENDPROC
21177-END(debug)
21178+ENDPROC(debug)
21179
21180 /*
21181 * NMI is doubly nasty. It can happen _while_ we're handling
21182@@ -1370,6 +1612,9 @@ nmi_stack_correct:
21183 xorl %edx,%edx # zero error code
21184 movl %esp,%eax # pt_regs pointer
21185 call do_nmi
21186+
21187+ pax_exit_kernel
21188+
21189 jmp restore_all_notrace
21190 CFI_ENDPROC
21191
21192@@ -1406,12 +1651,15 @@ nmi_espfix_stack:
21193 FIXUP_ESPFIX_STACK # %eax == %esp
21194 xorl %edx,%edx # zero error code
21195 call do_nmi
21196+
21197+ pax_exit_kernel
21198+
21199 RESTORE_REGS
21200 lss 12+4(%esp), %esp # back to espfix stack
21201 CFI_ADJUST_CFA_OFFSET -24
21202 jmp irq_return
21203 CFI_ENDPROC
21204-END(nmi)
21205+ENDPROC(nmi)
21206
21207 ENTRY(int3)
21208 RING0_INT_FRAME
21209@@ -1424,14 +1672,14 @@ ENTRY(int3)
21210 call do_int3
21211 jmp ret_from_exception
21212 CFI_ENDPROC
21213-END(int3)
21214+ENDPROC(int3)
21215
21216 ENTRY(general_protection)
21217 RING0_EC_FRAME
21218 pushl_cfi $do_general_protection
21219 jmp error_code
21220 CFI_ENDPROC
21221-END(general_protection)
21222+ENDPROC(general_protection)
21223
21224 #ifdef CONFIG_KVM_GUEST
21225 ENTRY(async_page_fault)
21226@@ -1440,7 +1688,7 @@ ENTRY(async_page_fault)
21227 pushl_cfi $do_async_page_fault
21228 jmp error_code
21229 CFI_ENDPROC
21230-END(async_page_fault)
21231+ENDPROC(async_page_fault)
21232 #endif
21233
21234 /*
21235diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
21236index 1b69951..8430a6d 100644
21237--- a/arch/x86/kernel/entry_64.S
21238+++ b/arch/x86/kernel/entry_64.S
21239@@ -59,6 +59,8 @@
21240 #include <asm/context_tracking.h>
21241 #include <asm/smap.h>
21242 #include <linux/err.h>
21243+#include <asm/pgtable.h>
21244+#include <asm/alternative-asm.h>
21245
21246 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
21247 #include <linux/elf-em.h>
21248@@ -80,8 +82,9 @@
21249 #ifdef CONFIG_DYNAMIC_FTRACE
21250
21251 ENTRY(function_hook)
21252+ pax_force_retaddr
21253 retq
21254-END(function_hook)
21255+ENDPROC(function_hook)
21256
21257 /* skip is set if stack has been adjusted */
21258 .macro ftrace_caller_setup skip=0
21259@@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
21260 #endif
21261
21262 GLOBAL(ftrace_stub)
21263+ pax_force_retaddr
21264 retq
21265-END(ftrace_caller)
21266+ENDPROC(ftrace_caller)
21267
21268 ENTRY(ftrace_regs_caller)
21269 /* Save the current flags before compare (in SS location)*/
21270@@ -191,7 +195,7 @@ ftrace_restore_flags:
21271 popfq
21272 jmp ftrace_stub
21273
21274-END(ftrace_regs_caller)
21275+ENDPROC(ftrace_regs_caller)
21276
21277
21278 #else /* ! CONFIG_DYNAMIC_FTRACE */
21279@@ -212,6 +216,7 @@ ENTRY(function_hook)
21280 #endif
21281
21282 GLOBAL(ftrace_stub)
21283+ pax_force_retaddr
21284 retq
21285
21286 trace:
21287@@ -225,12 +230,13 @@ trace:
21288 #endif
21289 subq $MCOUNT_INSN_SIZE, %rdi
21290
21291+ pax_force_fptr ftrace_trace_function
21292 call *ftrace_trace_function
21293
21294 MCOUNT_RESTORE_FRAME
21295
21296 jmp ftrace_stub
21297-END(function_hook)
21298+ENDPROC(function_hook)
21299 #endif /* CONFIG_DYNAMIC_FTRACE */
21300 #endif /* CONFIG_FUNCTION_TRACER */
21301
21302@@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
21303
21304 MCOUNT_RESTORE_FRAME
21305
21306+ pax_force_retaddr
21307 retq
21308-END(ftrace_graph_caller)
21309+ENDPROC(ftrace_graph_caller)
21310
21311 GLOBAL(return_to_handler)
21312 subq $24, %rsp
21313@@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
21314 movq 8(%rsp), %rdx
21315 movq (%rsp), %rax
21316 addq $24, %rsp
21317+ pax_force_fptr %rdi
21318 jmp *%rdi
21319+ENDPROC(return_to_handler)
21320 #endif
21321
21322
21323@@ -284,6 +293,430 @@ ENTRY(native_usergs_sysret64)
21324 ENDPROC(native_usergs_sysret64)
21325 #endif /* CONFIG_PARAVIRT */
21326
21327+ .macro ljmpq sel, off
21328+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
21329+ .byte 0x48; ljmp *1234f(%rip)
21330+ .pushsection .rodata
21331+ .align 16
21332+ 1234: .quad \off; .word \sel
21333+ .popsection
21334+#else
21335+ pushq $\sel
21336+ pushq $\off
21337+ lretq
21338+#endif
21339+ .endm
21340+
21341+ .macro pax_enter_kernel
21342+ pax_set_fptr_mask
21343+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
21344+ call pax_enter_kernel
21345+#endif
21346+ .endm
21347+
21348+ .macro pax_exit_kernel
21349+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
21350+ call pax_exit_kernel
21351+#endif
21352+
21353+ .endm
21354+
21355+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
21356+ENTRY(pax_enter_kernel)
21357+ pushq %rdi
21358+
21359+#ifdef CONFIG_PARAVIRT
21360+ PV_SAVE_REGS(CLBR_RDI)
21361+#endif
21362+
21363+#ifdef CONFIG_PAX_KERNEXEC
21364+ GET_CR0_INTO_RDI
21365+ bts $16,%rdi
21366+ jnc 3f
21367+ mov %cs,%edi
21368+ cmp $__KERNEL_CS,%edi
21369+ jnz 2f
21370+1:
21371+#endif
21372+
21373+#ifdef CONFIG_PAX_MEMORY_UDEREF
21374+ 661: jmp 111f
21375+ .pushsection .altinstr_replacement, "a"
21376+ 662: ASM_NOP2
21377+ .popsection
21378+ .pushsection .altinstructions, "a"
21379+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
21380+ .popsection
21381+ GET_CR3_INTO_RDI
21382+ cmp $0,%dil
21383+ jnz 112f
21384+ mov $__KERNEL_DS,%edi
21385+ mov %edi,%ss
21386+ jmp 111f
21387+112: cmp $1,%dil
21388+ jz 113f
21389+ ud2
21390+113: sub $4097,%rdi
21391+ bts $63,%rdi
21392+ SET_RDI_INTO_CR3
21393+ mov $__UDEREF_KERNEL_DS,%edi
21394+ mov %edi,%ss
21395+111:
21396+#endif
21397+
21398+#ifdef CONFIG_PARAVIRT
21399+ PV_RESTORE_REGS(CLBR_RDI)
21400+#endif
21401+
21402+ popq %rdi
21403+ pax_force_retaddr
21404+ retq
21405+
21406+#ifdef CONFIG_PAX_KERNEXEC
21407+2: ljmpq __KERNEL_CS,1b
21408+3: ljmpq __KERNEXEC_KERNEL_CS,4f
21409+4: SET_RDI_INTO_CR0
21410+ jmp 1b
21411+#endif
21412+ENDPROC(pax_enter_kernel)
21413+
21414+ENTRY(pax_exit_kernel)
21415+ pushq %rdi
21416+
21417+#ifdef CONFIG_PARAVIRT
21418+ PV_SAVE_REGS(CLBR_RDI)
21419+#endif
21420+
21421+#ifdef CONFIG_PAX_KERNEXEC
21422+ mov %cs,%rdi
21423+ cmp $__KERNEXEC_KERNEL_CS,%edi
21424+ jz 2f
21425+ GET_CR0_INTO_RDI
21426+ bts $16,%rdi
21427+ jnc 4f
21428+1:
21429+#endif
21430+
21431+#ifdef CONFIG_PAX_MEMORY_UDEREF
21432+ 661: jmp 111f
21433+ .pushsection .altinstr_replacement, "a"
21434+ 662: ASM_NOP2
21435+ .popsection
21436+ .pushsection .altinstructions, "a"
21437+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
21438+ .popsection
21439+ mov %ss,%edi
21440+ cmp $__UDEREF_KERNEL_DS,%edi
21441+ jnz 111f
21442+ GET_CR3_INTO_RDI
21443+ cmp $0,%dil
21444+ jz 112f
21445+ ud2
21446+112: add $4097,%rdi
21447+ bts $63,%rdi
21448+ SET_RDI_INTO_CR3
21449+ mov $__KERNEL_DS,%edi
21450+ mov %edi,%ss
21451+111:
21452+#endif
21453+
21454+#ifdef CONFIG_PARAVIRT
21455+ PV_RESTORE_REGS(CLBR_RDI);
21456+#endif
21457+
21458+ popq %rdi
21459+ pax_force_retaddr
21460+ retq
21461+
21462+#ifdef CONFIG_PAX_KERNEXEC
21463+2: GET_CR0_INTO_RDI
21464+ btr $16,%rdi
21465+ jnc 4f
21466+ ljmpq __KERNEL_CS,3f
21467+3: SET_RDI_INTO_CR0
21468+ jmp 1b
21469+4: ud2
21470+ jmp 4b
21471+#endif
21472+ENDPROC(pax_exit_kernel)
21473+#endif
21474+
21475+ .macro pax_enter_kernel_user
21476+ pax_set_fptr_mask
21477+#ifdef CONFIG_PAX_MEMORY_UDEREF
21478+ call pax_enter_kernel_user
21479+#endif
21480+ .endm
21481+
21482+ .macro pax_exit_kernel_user
21483+#ifdef CONFIG_PAX_MEMORY_UDEREF
21484+ call pax_exit_kernel_user
21485+#endif
21486+#ifdef CONFIG_PAX_RANDKSTACK
21487+ pushq %rax
21488+ pushq %r11
21489+ call pax_randomize_kstack
21490+ popq %r11
21491+ popq %rax
21492+#endif
21493+ .endm
21494+
21495+#ifdef CONFIG_PAX_MEMORY_UDEREF
21496+ENTRY(pax_enter_kernel_user)
21497+ pushq %rdi
21498+ pushq %rbx
21499+
21500+#ifdef CONFIG_PARAVIRT
21501+ PV_SAVE_REGS(CLBR_RDI)
21502+#endif
21503+
21504+ 661: jmp 111f
21505+ .pushsection .altinstr_replacement, "a"
21506+ 662: ASM_NOP2
21507+ .popsection
21508+ .pushsection .altinstructions, "a"
21509+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
21510+ .popsection
21511+ GET_CR3_INTO_RDI
21512+ cmp $1,%dil
21513+ jnz 4f
21514+ sub $4097,%rdi
21515+ bts $63,%rdi
21516+ SET_RDI_INTO_CR3
21517+ jmp 3f
21518+111:
21519+
21520+ GET_CR3_INTO_RDI
21521+ mov %rdi,%rbx
21522+ add $__START_KERNEL_map,%rbx
21523+ sub phys_base(%rip),%rbx
21524+
21525+#ifdef CONFIG_PARAVIRT
21526+ cmpl $0, pv_info+PARAVIRT_enabled
21527+ jz 1f
21528+ pushq %rdi
21529+ i = 0
21530+ .rept USER_PGD_PTRS
21531+ mov i*8(%rbx),%rsi
21532+ mov $0,%sil
21533+ lea i*8(%rbx),%rdi
21534+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
21535+ i = i + 1
21536+ .endr
21537+ popq %rdi
21538+ jmp 2f
21539+1:
21540+#endif
21541+
21542+ i = 0
21543+ .rept USER_PGD_PTRS
21544+ movb $0,i*8(%rbx)
21545+ i = i + 1
21546+ .endr
21547+
21548+2: SET_RDI_INTO_CR3
21549+
21550+#ifdef CONFIG_PAX_KERNEXEC
21551+ GET_CR0_INTO_RDI
21552+ bts $16,%rdi
21553+ SET_RDI_INTO_CR0
21554+#endif
21555+
21556+3:
21557+
21558+#ifdef CONFIG_PARAVIRT
21559+ PV_RESTORE_REGS(CLBR_RDI)
21560+#endif
21561+
21562+ popq %rbx
21563+ popq %rdi
21564+ pax_force_retaddr
21565+ retq
21566+4: ud2
21567+ENDPROC(pax_enter_kernel_user)
21568+
21569+ENTRY(pax_exit_kernel_user)
21570+ pushq %rdi
21571+ pushq %rbx
21572+
21573+#ifdef CONFIG_PARAVIRT
21574+ PV_SAVE_REGS(CLBR_RDI)
21575+#endif
21576+
21577+ GET_CR3_INTO_RDI
21578+ 661: jmp 1f
21579+ .pushsection .altinstr_replacement, "a"
21580+ 662: ASM_NOP2
21581+ .popsection
21582+ .pushsection .altinstructions, "a"
21583+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
21584+ .popsection
21585+ cmp $0,%dil
21586+ jnz 3f
21587+ add $4097,%rdi
21588+ bts $63,%rdi
21589+ SET_RDI_INTO_CR3
21590+ jmp 2f
21591+1:
21592+
21593+ mov %rdi,%rbx
21594+
21595+#ifdef CONFIG_PAX_KERNEXEC
21596+ GET_CR0_INTO_RDI
21597+ btr $16,%rdi
21598+ jnc 3f
21599+ SET_RDI_INTO_CR0
21600+#endif
21601+
21602+ add $__START_KERNEL_map,%rbx
21603+ sub phys_base(%rip),%rbx
21604+
21605+#ifdef CONFIG_PARAVIRT
21606+ cmpl $0, pv_info+PARAVIRT_enabled
21607+ jz 1f
21608+ i = 0
21609+ .rept USER_PGD_PTRS
21610+ mov i*8(%rbx),%rsi
21611+ mov $0x67,%sil
21612+ lea i*8(%rbx),%rdi
21613+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
21614+ i = i + 1
21615+ .endr
21616+ jmp 2f
21617+1:
21618+#endif
21619+
21620+ i = 0
21621+ .rept USER_PGD_PTRS
21622+ movb $0x67,i*8(%rbx)
21623+ i = i + 1
21624+ .endr
21625+2:
21626+
21627+#ifdef CONFIG_PARAVIRT
21628+ PV_RESTORE_REGS(CLBR_RDI)
21629+#endif
21630+
21631+ popq %rbx
21632+ popq %rdi
21633+ pax_force_retaddr
21634+ retq
21635+3: ud2
21636+ENDPROC(pax_exit_kernel_user)
21637+#endif
21638+
21639+ .macro pax_enter_kernel_nmi
21640+ pax_set_fptr_mask
21641+
21642+#ifdef CONFIG_PAX_KERNEXEC
21643+ GET_CR0_INTO_RDI
21644+ bts $16,%rdi
21645+ jc 110f
21646+ SET_RDI_INTO_CR0
21647+ or $2,%ebx
21648+110:
21649+#endif
21650+
21651+#ifdef CONFIG_PAX_MEMORY_UDEREF
21652+ 661: jmp 111f
21653+ .pushsection .altinstr_replacement, "a"
21654+ 662: ASM_NOP2
21655+ .popsection
21656+ .pushsection .altinstructions, "a"
21657+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
21658+ .popsection
21659+ GET_CR3_INTO_RDI
21660+ cmp $0,%dil
21661+ jz 111f
21662+ sub $4097,%rdi
21663+ or $4,%ebx
21664+ bts $63,%rdi
21665+ SET_RDI_INTO_CR3
21666+ mov $__UDEREF_KERNEL_DS,%edi
21667+ mov %edi,%ss
21668+111:
21669+#endif
21670+ .endm
21671+
21672+ .macro pax_exit_kernel_nmi
21673+#ifdef CONFIG_PAX_KERNEXEC
21674+ btr $1,%ebx
21675+ jnc 110f
21676+ GET_CR0_INTO_RDI
21677+ btr $16,%rdi
21678+ SET_RDI_INTO_CR0
21679+110:
21680+#endif
21681+
21682+#ifdef CONFIG_PAX_MEMORY_UDEREF
21683+ btr $2,%ebx
21684+ jnc 111f
21685+ GET_CR3_INTO_RDI
21686+ add $4097,%rdi
21687+ bts $63,%rdi
21688+ SET_RDI_INTO_CR3
21689+ mov $__KERNEL_DS,%edi
21690+ mov %edi,%ss
21691+111:
21692+#endif
21693+ .endm
21694+
21695+ .macro pax_erase_kstack
21696+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21697+ call pax_erase_kstack
21698+#endif
21699+ .endm
21700+
21701+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21702+ENTRY(pax_erase_kstack)
21703+ pushq %rdi
21704+ pushq %rcx
21705+ pushq %rax
21706+ pushq %r11
21707+
21708+ GET_THREAD_INFO(%r11)
21709+ mov TI_lowest_stack(%r11), %rdi
21710+ mov $-0xBEEF, %rax
21711+ std
21712+
21713+1: mov %edi, %ecx
21714+ and $THREAD_SIZE_asm - 1, %ecx
21715+ shr $3, %ecx
21716+ repne scasq
21717+ jecxz 2f
21718+
21719+ cmp $2*8, %ecx
21720+ jc 2f
21721+
21722+ mov $2*8, %ecx
21723+ repe scasq
21724+ jecxz 2f
21725+ jne 1b
21726+
21727+2: cld
21728+ mov %esp, %ecx
21729+ sub %edi, %ecx
21730+
21731+ cmp $THREAD_SIZE_asm, %rcx
21732+ jb 3f
21733+ ud2
21734+3:
21735+
21736+ shr $3, %ecx
21737+ rep stosq
21738+
21739+ mov TI_task_thread_sp0(%r11), %rdi
21740+ sub $256, %rdi
21741+ mov %rdi, TI_lowest_stack(%r11)
21742+
21743+ popq %r11
21744+ popq %rax
21745+ popq %rcx
21746+ popq %rdi
21747+ pax_force_retaddr
21748+ ret
21749+ENDPROC(pax_erase_kstack)
21750+#endif
21751
21752 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
21753 #ifdef CONFIG_TRACE_IRQFLAGS
21754@@ -375,8 +808,8 @@ ENDPROC(native_usergs_sysret64)
21755 .endm
21756
21757 .macro UNFAKE_STACK_FRAME
21758- addq $8*6, %rsp
21759- CFI_ADJUST_CFA_OFFSET -(6*8)
21760+ addq $8*6 + ARG_SKIP, %rsp
21761+ CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
21762 .endm
21763
21764 /*
21765@@ -463,7 +896,7 @@ ENDPROC(native_usergs_sysret64)
21766 movq %rsp, %rsi
21767
21768 leaq -RBP(%rsp),%rdi /* arg1 for handler */
21769- testl $3, CS-RBP(%rsi)
21770+ testb $3, CS-RBP(%rsi)
21771 je 1f
21772 SWAPGS
21773 /*
21774@@ -498,9 +931,10 @@ ENTRY(save_rest)
21775 movq_cfi r15, R15+16
21776 movq %r11, 8(%rsp) /* return address */
21777 FIXUP_TOP_OF_STACK %r11, 16
21778+ pax_force_retaddr
21779 ret
21780 CFI_ENDPROC
21781-END(save_rest)
21782+ENDPROC(save_rest)
21783
21784 /* save complete stack frame */
21785 .pushsection .kprobes.text, "ax"
21786@@ -529,9 +963,10 @@ ENTRY(save_paranoid)
21787 js 1f /* negative -> in kernel */
21788 SWAPGS
21789 xorl %ebx,%ebx
21790-1: ret
21791+1: pax_force_retaddr_bts
21792+ ret
21793 CFI_ENDPROC
21794-END(save_paranoid)
21795+ENDPROC(save_paranoid)
21796 .popsection
21797
21798 /*
21799@@ -553,7 +988,7 @@ ENTRY(ret_from_fork)
21800
21801 RESTORE_REST
21802
21803- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
21804+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
21805 jz 1f
21806
21807 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
21808@@ -571,7 +1006,7 @@ ENTRY(ret_from_fork)
21809 RESTORE_REST
21810 jmp int_ret_from_sys_call
21811 CFI_ENDPROC
21812-END(ret_from_fork)
21813+ENDPROC(ret_from_fork)
21814
21815 /*
21816 * System call entry. Up to 6 arguments in registers are supported.
21817@@ -608,7 +1043,7 @@ END(ret_from_fork)
21818 ENTRY(system_call)
21819 CFI_STARTPROC simple
21820 CFI_SIGNAL_FRAME
21821- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
21822+ CFI_DEF_CFA rsp,0
21823 CFI_REGISTER rip,rcx
21824 /*CFI_REGISTER rflags,r11*/
21825 SWAPGS_UNSAFE_STACK
21826@@ -621,16 +1056,23 @@ GLOBAL(system_call_after_swapgs)
21827
21828 movq %rsp,PER_CPU_VAR(old_rsp)
21829 movq PER_CPU_VAR(kernel_stack),%rsp
21830+ SAVE_ARGS 8*6,0
21831+ pax_enter_kernel_user
21832+
21833+#ifdef CONFIG_PAX_RANDKSTACK
21834+ pax_erase_kstack
21835+#endif
21836+
21837 /*
21838 * No need to follow this irqs off/on section - it's straight
21839 * and short:
21840 */
21841 ENABLE_INTERRUPTS(CLBR_NONE)
21842- SAVE_ARGS 8,0
21843 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
21844 movq %rcx,RIP-ARGOFFSET(%rsp)
21845 CFI_REL_OFFSET rip,RIP-ARGOFFSET
21846- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
21847+ GET_THREAD_INFO(%rcx)
21848+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
21849 jnz tracesys
21850 system_call_fastpath:
21851 #if __SYSCALL_MASK == ~0
21852@@ -640,7 +1082,7 @@ system_call_fastpath:
21853 cmpl $__NR_syscall_max,%eax
21854 #endif
21855 ja badsys
21856- movq %r10,%rcx
21857+ movq R10-ARGOFFSET(%rsp),%rcx
21858 call *sys_call_table(,%rax,8) # XXX: rip relative
21859 movq %rax,RAX-ARGOFFSET(%rsp)
21860 /*
21861@@ -654,10 +1096,13 @@ sysret_check:
21862 LOCKDEP_SYS_EXIT
21863 DISABLE_INTERRUPTS(CLBR_NONE)
21864 TRACE_IRQS_OFF
21865- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
21866+ GET_THREAD_INFO(%rcx)
21867+ movl TI_flags(%rcx),%edx
21868 andl %edi,%edx
21869 jnz sysret_careful
21870 CFI_REMEMBER_STATE
21871+ pax_exit_kernel_user
21872+ pax_erase_kstack
21873 /*
21874 * sysretq will re-enable interrupts:
21875 */
21876@@ -709,14 +1154,18 @@ badsys:
21877 * jump back to the normal fast path.
21878 */
21879 auditsys:
21880- movq %r10,%r9 /* 6th arg: 4th syscall arg */
21881+ movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
21882 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
21883 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
21884 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
21885 movq %rax,%rsi /* 2nd arg: syscall number */
21886 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
21887 call __audit_syscall_entry
21888+
21889+ pax_erase_kstack
21890+
21891 LOAD_ARGS 0 /* reload call-clobbered registers */
21892+ pax_set_fptr_mask
21893 jmp system_call_fastpath
21894
21895 /*
21896@@ -737,7 +1186,7 @@ sysret_audit:
21897 /* Do syscall tracing */
21898 tracesys:
21899 #ifdef CONFIG_AUDITSYSCALL
21900- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
21901+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
21902 jz auditsys
21903 #endif
21904 SAVE_REST
21905@@ -745,12 +1194,16 @@ tracesys:
21906 FIXUP_TOP_OF_STACK %rdi
21907 movq %rsp,%rdi
21908 call syscall_trace_enter
21909+
21910+ pax_erase_kstack
21911+
21912 /*
21913 * Reload arg registers from stack in case ptrace changed them.
21914 * We don't reload %rax because syscall_trace_enter() returned
21915 * the value it wants us to use in the table lookup.
21916 */
21917 LOAD_ARGS ARGOFFSET, 1
21918+ pax_set_fptr_mask
21919 RESTORE_REST
21920 #if __SYSCALL_MASK == ~0
21921 cmpq $__NR_syscall_max,%rax
21922@@ -759,7 +1212,7 @@ tracesys:
21923 cmpl $__NR_syscall_max,%eax
21924 #endif
21925 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
21926- movq %r10,%rcx /* fixup for C */
21927+ movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
21928 call *sys_call_table(,%rax,8)
21929 movq %rax,RAX-ARGOFFSET(%rsp)
21930 /* Use IRET because user could have changed frame */
21931@@ -780,7 +1233,9 @@ GLOBAL(int_with_check)
21932 andl %edi,%edx
21933 jnz int_careful
21934 andl $~TS_COMPAT,TI_status(%rcx)
21935- jmp retint_swapgs
21936+ pax_exit_kernel_user
21937+ pax_erase_kstack
21938+ jmp retint_swapgs_pax
21939
21940 /* Either reschedule or signal or syscall exit tracking needed. */
21941 /* First do a reschedule test. */
21942@@ -826,7 +1281,7 @@ int_restore_rest:
21943 TRACE_IRQS_OFF
21944 jmp int_with_check
21945 CFI_ENDPROC
21946-END(system_call)
21947+ENDPROC(system_call)
21948
21949 .macro FORK_LIKE func
21950 ENTRY(stub_\func)
21951@@ -839,9 +1294,10 @@ ENTRY(stub_\func)
21952 DEFAULT_FRAME 0 8 /* offset 8: return address */
21953 call sys_\func
21954 RESTORE_TOP_OF_STACK %r11, 8
21955+ pax_force_retaddr
21956 ret $REST_SKIP /* pop extended registers */
21957 CFI_ENDPROC
21958-END(stub_\func)
21959+ENDPROC(stub_\func)
21960 .endm
21961
21962 .macro FIXED_FRAME label,func
21963@@ -851,9 +1307,10 @@ ENTRY(\label)
21964 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
21965 call \func
21966 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
21967+ pax_force_retaddr
21968 ret
21969 CFI_ENDPROC
21970-END(\label)
21971+ENDPROC(\label)
21972 .endm
21973
21974 FORK_LIKE clone
21975@@ -870,9 +1327,10 @@ ENTRY(ptregscall_common)
21976 movq_cfi_restore R12+8, r12
21977 movq_cfi_restore RBP+8, rbp
21978 movq_cfi_restore RBX+8, rbx
21979+ pax_force_retaddr
21980 ret $REST_SKIP /* pop extended registers */
21981 CFI_ENDPROC
21982-END(ptregscall_common)
21983+ENDPROC(ptregscall_common)
21984
21985 ENTRY(stub_execve)
21986 CFI_STARTPROC
21987@@ -885,7 +1343,7 @@ ENTRY(stub_execve)
21988 RESTORE_REST
21989 jmp int_ret_from_sys_call
21990 CFI_ENDPROC
21991-END(stub_execve)
21992+ENDPROC(stub_execve)
21993
21994 /*
21995 * sigreturn is special because it needs to restore all registers on return.
21996@@ -902,7 +1360,7 @@ ENTRY(stub_rt_sigreturn)
21997 RESTORE_REST
21998 jmp int_ret_from_sys_call
21999 CFI_ENDPROC
22000-END(stub_rt_sigreturn)
22001+ENDPROC(stub_rt_sigreturn)
22002
22003 #ifdef CONFIG_X86_X32_ABI
22004 ENTRY(stub_x32_rt_sigreturn)
22005@@ -916,7 +1374,7 @@ ENTRY(stub_x32_rt_sigreturn)
22006 RESTORE_REST
22007 jmp int_ret_from_sys_call
22008 CFI_ENDPROC
22009-END(stub_x32_rt_sigreturn)
22010+ENDPROC(stub_x32_rt_sigreturn)
22011
22012 ENTRY(stub_x32_execve)
22013 CFI_STARTPROC
22014@@ -930,7 +1388,7 @@ ENTRY(stub_x32_execve)
22015 RESTORE_REST
22016 jmp int_ret_from_sys_call
22017 CFI_ENDPROC
22018-END(stub_x32_execve)
22019+ENDPROC(stub_x32_execve)
22020
22021 #endif
22022
22023@@ -967,7 +1425,7 @@ vector=vector+1
22024 2: jmp common_interrupt
22025 .endr
22026 CFI_ENDPROC
22027-END(irq_entries_start)
22028+ENDPROC(irq_entries_start)
22029
22030 .previous
22031 END(interrupt)
22032@@ -987,6 +1445,16 @@ END(interrupt)
22033 subq $ORIG_RAX-RBP, %rsp
22034 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
22035 SAVE_ARGS_IRQ
22036+#ifdef CONFIG_PAX_MEMORY_UDEREF
22037+ testb $3, CS(%rdi)
22038+ jnz 1f
22039+ pax_enter_kernel
22040+ jmp 2f
22041+1: pax_enter_kernel_user
22042+2:
22043+#else
22044+ pax_enter_kernel
22045+#endif
22046 call \func
22047 .endm
22048
22049@@ -1019,7 +1487,7 @@ ret_from_intr:
22050
22051 exit_intr:
22052 GET_THREAD_INFO(%rcx)
22053- testl $3,CS-ARGOFFSET(%rsp)
22054+ testb $3,CS-ARGOFFSET(%rsp)
22055 je retint_kernel
22056
22057 /* Interrupt came from user space */
22058@@ -1041,12 +1509,16 @@ retint_swapgs: /* return to user-space */
22059 * The iretq could re-enable interrupts:
22060 */
22061 DISABLE_INTERRUPTS(CLBR_ANY)
22062+ pax_exit_kernel_user
22063+retint_swapgs_pax:
22064 TRACE_IRQS_IRETQ
22065 SWAPGS
22066 jmp restore_args
22067
22068 retint_restore_args: /* return to kernel space */
22069 DISABLE_INTERRUPTS(CLBR_ANY)
22070+ pax_exit_kernel
22071+ pax_force_retaddr (RIP-ARGOFFSET)
22072 /*
22073 * The iretq could re-enable interrupts:
22074 */
22075@@ -1129,7 +1601,7 @@ ENTRY(retint_kernel)
22076 #endif
22077
22078 CFI_ENDPROC
22079-END(common_interrupt)
22080+ENDPROC(common_interrupt)
22081 /*
22082 * End of kprobes section
22083 */
22084@@ -1147,7 +1619,7 @@ ENTRY(\sym)
22085 interrupt \do_sym
22086 jmp ret_from_intr
22087 CFI_ENDPROC
22088-END(\sym)
22089+ENDPROC(\sym)
22090 .endm
22091
22092 #ifdef CONFIG_TRACING
22093@@ -1230,12 +1702,22 @@ ENTRY(\sym)
22094 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
22095 call error_entry
22096 DEFAULT_FRAME 0
22097+#ifdef CONFIG_PAX_MEMORY_UDEREF
22098+ testb $3, CS(%rsp)
22099+ jnz 1f
22100+ pax_enter_kernel
22101+ jmp 2f
22102+1: pax_enter_kernel_user
22103+2:
22104+#else
22105+ pax_enter_kernel
22106+#endif
22107 movq %rsp,%rdi /* pt_regs pointer */
22108 xorl %esi,%esi /* no error code */
22109 call \do_sym
22110 jmp error_exit /* %ebx: no swapgs flag */
22111 CFI_ENDPROC
22112-END(\sym)
22113+ENDPROC(\sym)
22114 .endm
22115
22116 .macro paranoidzeroentry sym do_sym
22117@@ -1248,15 +1730,25 @@ ENTRY(\sym)
22118 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
22119 call save_paranoid
22120 TRACE_IRQS_OFF
22121+#ifdef CONFIG_PAX_MEMORY_UDEREF
22122+ testb $3, CS(%rsp)
22123+ jnz 1f
22124+ pax_enter_kernel
22125+ jmp 2f
22126+1: pax_enter_kernel_user
22127+2:
22128+#else
22129+ pax_enter_kernel
22130+#endif
22131 movq %rsp,%rdi /* pt_regs pointer */
22132 xorl %esi,%esi /* no error code */
22133 call \do_sym
22134 jmp paranoid_exit /* %ebx: no swapgs flag */
22135 CFI_ENDPROC
22136-END(\sym)
22137+ENDPROC(\sym)
22138 .endm
22139
22140-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
22141+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
22142 .macro paranoidzeroentry_ist sym do_sym ist
22143 ENTRY(\sym)
22144 INTR_FRAME
22145@@ -1267,14 +1759,30 @@ ENTRY(\sym)
22146 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
22147 call save_paranoid
22148 TRACE_IRQS_OFF_DEBUG
22149+#ifdef CONFIG_PAX_MEMORY_UDEREF
22150+ testb $3, CS(%rsp)
22151+ jnz 1f
22152+ pax_enter_kernel
22153+ jmp 2f
22154+1: pax_enter_kernel_user
22155+2:
22156+#else
22157+ pax_enter_kernel
22158+#endif
22159 movq %rsp,%rdi /* pt_regs pointer */
22160 xorl %esi,%esi /* no error code */
22161+#ifdef CONFIG_SMP
22162+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
22163+ lea init_tss(%r12), %r12
22164+#else
22165+ lea init_tss(%rip), %r12
22166+#endif
22167 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
22168 call \do_sym
22169 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
22170 jmp paranoid_exit /* %ebx: no swapgs flag */
22171 CFI_ENDPROC
22172-END(\sym)
22173+ENDPROC(\sym)
22174 .endm
22175
22176 .macro errorentry sym do_sym
22177@@ -1286,13 +1794,23 @@ ENTRY(\sym)
22178 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
22179 call error_entry
22180 DEFAULT_FRAME 0
22181+#ifdef CONFIG_PAX_MEMORY_UDEREF
22182+ testb $3, CS(%rsp)
22183+ jnz 1f
22184+ pax_enter_kernel
22185+ jmp 2f
22186+1: pax_enter_kernel_user
22187+2:
22188+#else
22189+ pax_enter_kernel
22190+#endif
22191 movq %rsp,%rdi /* pt_regs pointer */
22192 movq ORIG_RAX(%rsp),%rsi /* get error code */
22193 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
22194 call \do_sym
22195 jmp error_exit /* %ebx: no swapgs flag */
22196 CFI_ENDPROC
22197-END(\sym)
22198+ENDPROC(\sym)
22199 .endm
22200
22201 /* error code is on the stack already */
22202@@ -1306,13 +1824,23 @@ ENTRY(\sym)
22203 call save_paranoid
22204 DEFAULT_FRAME 0
22205 TRACE_IRQS_OFF
22206+#ifdef CONFIG_PAX_MEMORY_UDEREF
22207+ testb $3, CS(%rsp)
22208+ jnz 1f
22209+ pax_enter_kernel
22210+ jmp 2f
22211+1: pax_enter_kernel_user
22212+2:
22213+#else
22214+ pax_enter_kernel
22215+#endif
22216 movq %rsp,%rdi /* pt_regs pointer */
22217 movq ORIG_RAX(%rsp),%rsi /* get error code */
22218 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
22219 call \do_sym
22220 jmp paranoid_exit /* %ebx: no swapgs flag */
22221 CFI_ENDPROC
22222-END(\sym)
22223+ENDPROC(\sym)
22224 .endm
22225
22226 zeroentry divide_error do_divide_error
22227@@ -1342,9 +1870,10 @@ gs_change:
22228 2: mfence /* workaround */
22229 SWAPGS
22230 popfq_cfi
22231+ pax_force_retaddr
22232 ret
22233 CFI_ENDPROC
22234-END(native_load_gs_index)
22235+ENDPROC(native_load_gs_index)
22236
22237 _ASM_EXTABLE(gs_change,bad_gs)
22238 .section .fixup,"ax"
22239@@ -1372,9 +1901,10 @@ ENTRY(call_softirq)
22240 CFI_DEF_CFA_REGISTER rsp
22241 CFI_ADJUST_CFA_OFFSET -8
22242 decl PER_CPU_VAR(irq_count)
22243+ pax_force_retaddr
22244 ret
22245 CFI_ENDPROC
22246-END(call_softirq)
22247+ENDPROC(call_softirq)
22248
22249 #ifdef CONFIG_XEN
22250 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
22251@@ -1412,7 +1942,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
22252 decl PER_CPU_VAR(irq_count)
22253 jmp error_exit
22254 CFI_ENDPROC
22255-END(xen_do_hypervisor_callback)
22256+ENDPROC(xen_do_hypervisor_callback)
22257
22258 /*
22259 * Hypervisor uses this for application faults while it executes.
22260@@ -1471,7 +2001,7 @@ ENTRY(xen_failsafe_callback)
22261 SAVE_ALL
22262 jmp error_exit
22263 CFI_ENDPROC
22264-END(xen_failsafe_callback)
22265+ENDPROC(xen_failsafe_callback)
22266
22267 apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
22268 xen_hvm_callback_vector xen_evtchn_do_upcall
22269@@ -1523,18 +2053,33 @@ ENTRY(paranoid_exit)
22270 DEFAULT_FRAME
22271 DISABLE_INTERRUPTS(CLBR_NONE)
22272 TRACE_IRQS_OFF_DEBUG
22273- testl %ebx,%ebx /* swapgs needed? */
22274+ testl $1,%ebx /* swapgs needed? */
22275 jnz paranoid_restore
22276- testl $3,CS(%rsp)
22277+ testb $3,CS(%rsp)
22278 jnz paranoid_userspace
22279+#ifdef CONFIG_PAX_MEMORY_UDEREF
22280+ pax_exit_kernel
22281+ TRACE_IRQS_IRETQ 0
22282+ SWAPGS_UNSAFE_STACK
22283+ RESTORE_ALL 8
22284+ pax_force_retaddr_bts
22285+ jmp irq_return
22286+#endif
22287 paranoid_swapgs:
22288+#ifdef CONFIG_PAX_MEMORY_UDEREF
22289+ pax_exit_kernel_user
22290+#else
22291+ pax_exit_kernel
22292+#endif
22293 TRACE_IRQS_IRETQ 0
22294 SWAPGS_UNSAFE_STACK
22295 RESTORE_ALL 8
22296 jmp irq_return
22297 paranoid_restore:
22298+ pax_exit_kernel
22299 TRACE_IRQS_IRETQ_DEBUG 0
22300 RESTORE_ALL 8
22301+ pax_force_retaddr_bts
22302 jmp irq_return
22303 paranoid_userspace:
22304 GET_THREAD_INFO(%rcx)
22305@@ -1563,7 +2108,7 @@ paranoid_schedule:
22306 TRACE_IRQS_OFF
22307 jmp paranoid_userspace
22308 CFI_ENDPROC
22309-END(paranoid_exit)
22310+ENDPROC(paranoid_exit)
22311
22312 /*
22313 * Exception entry point. This expects an error code/orig_rax on the stack.
22314@@ -1590,12 +2135,13 @@ ENTRY(error_entry)
22315 movq_cfi r14, R14+8
22316 movq_cfi r15, R15+8
22317 xorl %ebx,%ebx
22318- testl $3,CS+8(%rsp)
22319+ testb $3,CS+8(%rsp)
22320 je error_kernelspace
22321 error_swapgs:
22322 SWAPGS
22323 error_sti:
22324 TRACE_IRQS_OFF
22325+ pax_force_retaddr_bts
22326 ret
22327
22328 /*
22329@@ -1622,7 +2168,7 @@ bstep_iret:
22330 movq %rcx,RIP+8(%rsp)
22331 jmp error_swapgs
22332 CFI_ENDPROC
22333-END(error_entry)
22334+ENDPROC(error_entry)
22335
22336
22337 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
22338@@ -1633,7 +2179,7 @@ ENTRY(error_exit)
22339 DISABLE_INTERRUPTS(CLBR_NONE)
22340 TRACE_IRQS_OFF
22341 GET_THREAD_INFO(%rcx)
22342- testl %eax,%eax
22343+ testl $1,%eax
22344 jne retint_kernel
22345 LOCKDEP_SYS_EXIT_IRQ
22346 movl TI_flags(%rcx),%edx
22347@@ -1642,7 +2188,7 @@ ENTRY(error_exit)
22348 jnz retint_careful
22349 jmp retint_swapgs
22350 CFI_ENDPROC
22351-END(error_exit)
22352+ENDPROC(error_exit)
22353
22354 /*
22355 * Test if a given stack is an NMI stack or not.
22356@@ -1700,9 +2246,11 @@ ENTRY(nmi)
22357 * If %cs was not the kernel segment, then the NMI triggered in user
22358 * space, which means it is definitely not nested.
22359 */
22360+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
22361+ je 1f
22362 cmpl $__KERNEL_CS, 16(%rsp)
22363 jne first_nmi
22364-
22365+1:
22366 /*
22367 * Check the special variable on the stack to see if NMIs are
22368 * executing.
22369@@ -1736,8 +2284,7 @@ nested_nmi:
22370
22371 1:
22372 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
22373- leaq -1*8(%rsp), %rdx
22374- movq %rdx, %rsp
22375+ subq $8, %rsp
22376 CFI_ADJUST_CFA_OFFSET 1*8
22377 leaq -10*8(%rsp), %rdx
22378 pushq_cfi $__KERNEL_DS
22379@@ -1755,6 +2302,7 @@ nested_nmi_out:
22380 CFI_RESTORE rdx
22381
22382 /* No need to check faults here */
22383+# pax_force_retaddr_bts
22384 INTERRUPT_RETURN
22385
22386 CFI_RESTORE_STATE
22387@@ -1871,6 +2419,8 @@ end_repeat_nmi:
22388 */
22389 movq %cr2, %r12
22390
22391+ pax_enter_kernel_nmi
22392+
22393 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
22394 movq %rsp,%rdi
22395 movq $-1,%rsi
22396@@ -1883,26 +2433,31 @@ end_repeat_nmi:
22397 movq %r12, %cr2
22398 1:
22399
22400- testl %ebx,%ebx /* swapgs needed? */
22401+ testl $1,%ebx /* swapgs needed? */
22402 jnz nmi_restore
22403 nmi_swapgs:
22404 SWAPGS_UNSAFE_STACK
22405 nmi_restore:
22406+ pax_exit_kernel_nmi
22407 /* Pop the extra iret frame at once */
22408 RESTORE_ALL 6*8
22409+ testb $3, 8(%rsp)
22410+ jnz 1f
22411+ pax_force_retaddr_bts
22412+1:
22413
22414 /* Clear the NMI executing stack variable */
22415 movq $0, 5*8(%rsp)
22416 jmp irq_return
22417 CFI_ENDPROC
22418-END(nmi)
22419+ENDPROC(nmi)
22420
22421 ENTRY(ignore_sysret)
22422 CFI_STARTPROC
22423 mov $-ENOSYS,%eax
22424 sysret
22425 CFI_ENDPROC
22426-END(ignore_sysret)
22427+ENDPROC(ignore_sysret)
22428
22429 /*
22430 * End of kprobes section
22431diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
22432index 42a392a..fbbd930 100644
22433--- a/arch/x86/kernel/ftrace.c
22434+++ b/arch/x86/kernel/ftrace.c
22435@@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
22436 {
22437 unsigned char replaced[MCOUNT_INSN_SIZE];
22438
22439+ ip = ktla_ktva(ip);
22440+
22441 /*
22442 * Note: Due to modules and __init, code can
22443 * disappear and change, we need to protect against faulting
22444@@ -227,7 +229,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
22445 unsigned char old[MCOUNT_INSN_SIZE], *new;
22446 int ret;
22447
22448- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
22449+ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
22450 new = ftrace_call_replace(ip, (unsigned long)func);
22451
22452 /* See comment above by declaration of modifying_ftrace_code */
22453@@ -238,7 +240,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
22454 /* Also update the regs callback function */
22455 if (!ret) {
22456 ip = (unsigned long)(&ftrace_regs_call);
22457- memcpy(old, &ftrace_regs_call, MCOUNT_INSN_SIZE);
22458+ memcpy(old, ktla_ktva((void *)&ftrace_regs_call), MCOUNT_INSN_SIZE);
22459 new = ftrace_call_replace(ip, (unsigned long)func);
22460 ret = ftrace_modify_code(ip, old, new);
22461 }
22462@@ -279,7 +281,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
22463 * kernel identity mapping to modify code.
22464 */
22465 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
22466- ip = (unsigned long)__va(__pa_symbol(ip));
22467+ ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
22468
22469 return probe_kernel_write((void *)ip, val, size);
22470 }
22471@@ -289,7 +291,7 @@ static int add_break(unsigned long ip, const char *old)
22472 unsigned char replaced[MCOUNT_INSN_SIZE];
22473 unsigned char brk = BREAKPOINT_INSTRUCTION;
22474
22475- if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
22476+ if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
22477 return -EFAULT;
22478
22479 /* Make sure it is what we expect it to be */
22480@@ -637,7 +639,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
22481 return ret;
22482
22483 fail_update:
22484- probe_kernel_write((void *)ip, &old_code[0], 1);
22485+ probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
22486 goto out;
22487 }
22488
22489@@ -670,6 +672,8 @@ static int ftrace_mod_jmp(unsigned long ip,
22490 {
22491 unsigned char code[MCOUNT_INSN_SIZE];
22492
22493+ ip = ktla_ktva(ip);
22494+
22495 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
22496 return -EFAULT;
22497
22498diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
22499index 55b6761..a6456fc 100644
22500--- a/arch/x86/kernel/head64.c
22501+++ b/arch/x86/kernel/head64.c
22502@@ -67,12 +67,12 @@ again:
22503 pgd = *pgd_p;
22504
22505 /*
22506- * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
22507- * critical -- __PAGE_OFFSET would point us back into the dynamic
22508+ * The use of __early_va rather than __va here is critical:
22509+ * __va would point us back into the dynamic
22510 * range and we might end up looping forever...
22511 */
22512 if (pgd)
22513- pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
22514+ pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
22515 else {
22516 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
22517 reset_early_page_tables();
22518@@ -82,13 +82,13 @@ again:
22519 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
22520 for (i = 0; i < PTRS_PER_PUD; i++)
22521 pud_p[i] = 0;
22522- *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
22523+ *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
22524 }
22525 pud_p += pud_index(address);
22526 pud = *pud_p;
22527
22528 if (pud)
22529- pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
22530+ pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
22531 else {
22532 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
22533 reset_early_page_tables();
22534@@ -98,7 +98,7 @@ again:
22535 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
22536 for (i = 0; i < PTRS_PER_PMD; i++)
22537 pmd_p[i] = 0;
22538- *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
22539+ *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
22540 }
22541 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
22542 pmd_p[pmd_index(address)] = pmd;
22543@@ -175,7 +175,6 @@ void __init x86_64_start_kernel(char * real_mode_data)
22544 if (console_loglevel == 10)
22545 early_printk("Kernel alive\n");
22546
22547- clear_page(init_level4_pgt);
22548 /* set init_level4_pgt kernel high mapping*/
22549 init_level4_pgt[511] = early_level4_pgt[511];
22550
22551diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
22552index 5dd87a8..d68b3f4 100644
22553--- a/arch/x86/kernel/head_32.S
22554+++ b/arch/x86/kernel/head_32.S
22555@@ -26,6 +26,12 @@
22556 /* Physical address */
22557 #define pa(X) ((X) - __PAGE_OFFSET)
22558
22559+#ifdef CONFIG_PAX_KERNEXEC
22560+#define ta(X) (X)
22561+#else
22562+#define ta(X) ((X) - __PAGE_OFFSET)
22563+#endif
22564+
22565 /*
22566 * References to members of the new_cpu_data structure.
22567 */
22568@@ -55,11 +61,7 @@
22569 * and small than max_low_pfn, otherwise will waste some page table entries
22570 */
22571
22572-#if PTRS_PER_PMD > 1
22573-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
22574-#else
22575-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
22576-#endif
22577+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
22578
22579 /* Number of possible pages in the lowmem region */
22580 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
22581@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
22582 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
22583
22584 /*
22585+ * Real beginning of normal "text" segment
22586+ */
22587+ENTRY(stext)
22588+ENTRY(_stext)
22589+
22590+/*
22591 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
22592 * %esi points to the real-mode code as a 32-bit pointer.
22593 * CS and DS must be 4 GB flat segments, but we don't depend on
22594@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
22595 * can.
22596 */
22597 __HEAD
22598+
22599+#ifdef CONFIG_PAX_KERNEXEC
22600+ jmp startup_32
22601+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
22602+.fill PAGE_SIZE-5,1,0xcc
22603+#endif
22604+
22605 ENTRY(startup_32)
22606 movl pa(stack_start),%ecx
22607
22608@@ -106,6 +121,59 @@ ENTRY(startup_32)
22609 2:
22610 leal -__PAGE_OFFSET(%ecx),%esp
22611
22612+#ifdef CONFIG_SMP
22613+ movl $pa(cpu_gdt_table),%edi
22614+ movl $__per_cpu_load,%eax
22615+ movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
22616+ rorl $16,%eax
22617+ movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
22618+ movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
22619+ movl $__per_cpu_end - 1,%eax
22620+ subl $__per_cpu_start,%eax
22621+ movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
22622+#endif
22623+
22624+#ifdef CONFIG_PAX_MEMORY_UDEREF
22625+ movl $NR_CPUS,%ecx
22626+ movl $pa(cpu_gdt_table),%edi
22627+1:
22628+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
22629+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
22630+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
22631+ addl $PAGE_SIZE_asm,%edi
22632+ loop 1b
22633+#endif
22634+
22635+#ifdef CONFIG_PAX_KERNEXEC
22636+ movl $pa(boot_gdt),%edi
22637+ movl $__LOAD_PHYSICAL_ADDR,%eax
22638+ movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
22639+ rorl $16,%eax
22640+ movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
22641+ movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
22642+ rorl $16,%eax
22643+
22644+ ljmp $(__BOOT_CS),$1f
22645+1:
22646+
22647+ movl $NR_CPUS,%ecx
22648+ movl $pa(cpu_gdt_table),%edi
22649+ addl $__PAGE_OFFSET,%eax
22650+1:
22651+ movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
22652+ movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
22653+ movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
22654+ movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
22655+ rorl $16,%eax
22656+ movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
22657+ movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
22658+ movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
22659+ movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
22660+ rorl $16,%eax
22661+ addl $PAGE_SIZE_asm,%edi
22662+ loop 1b
22663+#endif
22664+
22665 /*
22666 * Clear BSS first so that there are no surprises...
22667 */
22668@@ -201,8 +269,11 @@ ENTRY(startup_32)
22669 movl %eax, pa(max_pfn_mapped)
22670
22671 /* Do early initialization of the fixmap area */
22672- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
22673- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
22674+#ifdef CONFIG_COMPAT_VDSO
22675+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
22676+#else
22677+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
22678+#endif
22679 #else /* Not PAE */
22680
22681 page_pde_offset = (__PAGE_OFFSET >> 20);
22682@@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
22683 movl %eax, pa(max_pfn_mapped)
22684
22685 /* Do early initialization of the fixmap area */
22686- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
22687- movl %eax,pa(initial_page_table+0xffc)
22688+#ifdef CONFIG_COMPAT_VDSO
22689+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
22690+#else
22691+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
22692+#endif
22693 #endif
22694
22695 #ifdef CONFIG_PARAVIRT
22696@@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
22697 cmpl $num_subarch_entries, %eax
22698 jae bad_subarch
22699
22700- movl pa(subarch_entries)(,%eax,4), %eax
22701- subl $__PAGE_OFFSET, %eax
22702- jmp *%eax
22703+ jmp *pa(subarch_entries)(,%eax,4)
22704
22705 bad_subarch:
22706 WEAK(lguest_entry)
22707@@ -261,10 +333,10 @@ WEAK(xen_entry)
22708 __INITDATA
22709
22710 subarch_entries:
22711- .long default_entry /* normal x86/PC */
22712- .long lguest_entry /* lguest hypervisor */
22713- .long xen_entry /* Xen hypervisor */
22714- .long default_entry /* Moorestown MID */
22715+ .long ta(default_entry) /* normal x86/PC */
22716+ .long ta(lguest_entry) /* lguest hypervisor */
22717+ .long ta(xen_entry) /* Xen hypervisor */
22718+ .long ta(default_entry) /* Moorestown MID */
22719 num_subarch_entries = (. - subarch_entries) / 4
22720 .previous
22721 #else
22722@@ -354,6 +426,7 @@ default_entry:
22723 movl pa(mmu_cr4_features),%eax
22724 movl %eax,%cr4
22725
22726+#ifdef CONFIG_X86_PAE
22727 testb $X86_CR4_PAE, %al # check if PAE is enabled
22728 jz enable_paging
22729
22730@@ -382,6 +455,9 @@ default_entry:
22731 /* Make changes effective */
22732 wrmsr
22733
22734+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
22735+#endif
22736+
22737 enable_paging:
22738
22739 /*
22740@@ -449,14 +525,20 @@ is486:
22741 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
22742 movl %eax,%ss # after changing gdt.
22743
22744- movl $(__USER_DS),%eax # DS/ES contains default USER segment
22745+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
22746 movl %eax,%ds
22747 movl %eax,%es
22748
22749 movl $(__KERNEL_PERCPU), %eax
22750 movl %eax,%fs # set this cpu's percpu
22751
22752+#ifdef CONFIG_CC_STACKPROTECTOR
22753 movl $(__KERNEL_STACK_CANARY),%eax
22754+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
22755+ movl $(__USER_DS),%eax
22756+#else
22757+ xorl %eax,%eax
22758+#endif
22759 movl %eax,%gs
22760
22761 xorl %eax,%eax # Clear LDT
22762@@ -512,8 +594,11 @@ setup_once:
22763 * relocation. Manually set base address in stack canary
22764 * segment descriptor.
22765 */
22766- movl $gdt_page,%eax
22767+ movl $cpu_gdt_table,%eax
22768 movl $stack_canary,%ecx
22769+#ifdef CONFIG_SMP
22770+ addl $__per_cpu_load,%ecx
22771+#endif
22772 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
22773 shrl $16, %ecx
22774 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
22775@@ -544,7 +629,7 @@ ENDPROC(early_idt_handlers)
22776 /* This is global to keep gas from relaxing the jumps */
22777 ENTRY(early_idt_handler)
22778 cld
22779- cmpl $2,%ss:early_recursion_flag
22780+ cmpl $1,%ss:early_recursion_flag
22781 je hlt_loop
22782 incl %ss:early_recursion_flag
22783
22784@@ -582,8 +667,8 @@ ENTRY(early_idt_handler)
22785 pushl (20+6*4)(%esp) /* trapno */
22786 pushl $fault_msg
22787 call printk
22788-#endif
22789 call dump_stack
22790+#endif
22791 hlt_loop:
22792 hlt
22793 jmp hlt_loop
22794@@ -602,8 +687,11 @@ ENDPROC(early_idt_handler)
22795 /* This is the default interrupt "handler" :-) */
22796 ALIGN
22797 ignore_int:
22798- cld
22799 #ifdef CONFIG_PRINTK
22800+ cmpl $2,%ss:early_recursion_flag
22801+ je hlt_loop
22802+ incl %ss:early_recursion_flag
22803+ cld
22804 pushl %eax
22805 pushl %ecx
22806 pushl %edx
22807@@ -612,9 +700,6 @@ ignore_int:
22808 movl $(__KERNEL_DS),%eax
22809 movl %eax,%ds
22810 movl %eax,%es
22811- cmpl $2,early_recursion_flag
22812- je hlt_loop
22813- incl early_recursion_flag
22814 pushl 16(%esp)
22815 pushl 24(%esp)
22816 pushl 32(%esp)
22817@@ -648,29 +733,34 @@ ENTRY(setup_once_ref)
22818 /*
22819 * BSS section
22820 */
22821-__PAGE_ALIGNED_BSS
22822- .align PAGE_SIZE
22823 #ifdef CONFIG_X86_PAE
22824+.section .initial_pg_pmd,"a",@progbits
22825 initial_pg_pmd:
22826 .fill 1024*KPMDS,4,0
22827 #else
22828+.section .initial_page_table,"a",@progbits
22829 ENTRY(initial_page_table)
22830 .fill 1024,4,0
22831 #endif
22832+.section .initial_pg_fixmap,"a",@progbits
22833 initial_pg_fixmap:
22834 .fill 1024,4,0
22835+.section .empty_zero_page,"a",@progbits
22836 ENTRY(empty_zero_page)
22837 .fill 4096,1,0
22838+.section .swapper_pg_dir,"a",@progbits
22839 ENTRY(swapper_pg_dir)
22840+#ifdef CONFIG_X86_PAE
22841+ .fill 4,8,0
22842+#else
22843 .fill 1024,4,0
22844+#endif
22845
22846 /*
22847 * This starts the data section.
22848 */
22849 #ifdef CONFIG_X86_PAE
22850-__PAGE_ALIGNED_DATA
22851- /* Page-aligned for the benefit of paravirt? */
22852- .align PAGE_SIZE
22853+.section .initial_page_table,"a",@progbits
22854 ENTRY(initial_page_table)
22855 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
22856 # if KPMDS == 3
22857@@ -689,12 +779,20 @@ ENTRY(initial_page_table)
22858 # error "Kernel PMDs should be 1, 2 or 3"
22859 # endif
22860 .align PAGE_SIZE /* needs to be page-sized too */
22861+
22862+#ifdef CONFIG_PAX_PER_CPU_PGD
22863+ENTRY(cpu_pgd)
22864+ .rept 2*NR_CPUS
22865+ .fill 4,8,0
22866+ .endr
22867+#endif
22868+
22869 #endif
22870
22871 .data
22872 .balign 4
22873 ENTRY(stack_start)
22874- .long init_thread_union+THREAD_SIZE
22875+ .long init_thread_union+THREAD_SIZE-8
22876
22877 __INITRODATA
22878 int_msg:
22879@@ -722,7 +820,7 @@ fault_msg:
22880 * segment size, and 32-bit linear address value:
22881 */
22882
22883- .data
22884+.section .rodata,"a",@progbits
22885 .globl boot_gdt_descr
22886 .globl idt_descr
22887
22888@@ -731,7 +829,7 @@ fault_msg:
22889 .word 0 # 32 bit align gdt_desc.address
22890 boot_gdt_descr:
22891 .word __BOOT_DS+7
22892- .long boot_gdt - __PAGE_OFFSET
22893+ .long pa(boot_gdt)
22894
22895 .word 0 # 32-bit align idt_desc.address
22896 idt_descr:
22897@@ -742,7 +840,7 @@ idt_descr:
22898 .word 0 # 32 bit align gdt_desc.address
22899 ENTRY(early_gdt_descr)
22900 .word GDT_ENTRIES*8-1
22901- .long gdt_page /* Overwritten for secondary CPUs */
22902+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
22903
22904 /*
22905 * The boot_gdt must mirror the equivalent in setup.S and is
22906@@ -751,5 +849,65 @@ ENTRY(early_gdt_descr)
22907 .align L1_CACHE_BYTES
22908 ENTRY(boot_gdt)
22909 .fill GDT_ENTRY_BOOT_CS,8,0
22910- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
22911- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
22912+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
22913+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
22914+
22915+ .align PAGE_SIZE_asm
22916+ENTRY(cpu_gdt_table)
22917+ .rept NR_CPUS
22918+ .quad 0x0000000000000000 /* NULL descriptor */
22919+ .quad 0x0000000000000000 /* 0x0b reserved */
22920+ .quad 0x0000000000000000 /* 0x13 reserved */
22921+ .quad 0x0000000000000000 /* 0x1b reserved */
22922+
22923+#ifdef CONFIG_PAX_KERNEXEC
22924+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
22925+#else
22926+ .quad 0x0000000000000000 /* 0x20 unused */
22927+#endif
22928+
22929+ .quad 0x0000000000000000 /* 0x28 unused */
22930+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
22931+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
22932+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
22933+ .quad 0x0000000000000000 /* 0x4b reserved */
22934+ .quad 0x0000000000000000 /* 0x53 reserved */
22935+ .quad 0x0000000000000000 /* 0x5b reserved */
22936+
22937+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
22938+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
22939+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
22940+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
22941+
22942+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
22943+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
22944+
22945+ /*
22946+ * Segments used for calling PnP BIOS have byte granularity.
22947+ * The code segments and data segments have fixed 64k limits,
22948+ * the transfer segment sizes are set at run time.
22949+ */
22950+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
22951+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
22952+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
22953+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
22954+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
22955+
22956+ /*
22957+ * The APM segments have byte granularity and their bases
22958+ * are set at run time. All have 64k limits.
22959+ */
22960+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
22961+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
22962+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
22963+
22964+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
22965+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
22966+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
22967+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
22968+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
22969+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
22970+
22971+ /* Be sure this is zeroed to avoid false validations in Xen */
22972+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
22973+ .endr
22974diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
22975index e1aabdb..73dcad8 100644
22976--- a/arch/x86/kernel/head_64.S
22977+++ b/arch/x86/kernel/head_64.S
22978@@ -20,6 +20,8 @@
22979 #include <asm/processor-flags.h>
22980 #include <asm/percpu.h>
22981 #include <asm/nops.h>
22982+#include <asm/cpufeature.h>
22983+#include <asm/alternative-asm.h>
22984
22985 #ifdef CONFIG_PARAVIRT
22986 #include <asm/asm-offsets.h>
22987@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
22988 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
22989 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
22990 L3_START_KERNEL = pud_index(__START_KERNEL_map)
22991+L4_VMALLOC_START = pgd_index(VMALLOC_START)
22992+L3_VMALLOC_START = pud_index(VMALLOC_START)
22993+L4_VMALLOC_END = pgd_index(VMALLOC_END)
22994+L3_VMALLOC_END = pud_index(VMALLOC_END)
22995+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
22996+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
22997
22998 .text
22999 __HEAD
23000@@ -89,11 +97,23 @@ startup_64:
23001 * Fixup the physical addresses in the page table
23002 */
23003 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
23004+ addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
23005+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
23006+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
23007+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
23008+ addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
23009
23010- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
23011- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
23012+ addq %rbp, level3_ident_pgt + (0*8)(%rip)
23013+#ifndef CONFIG_XEN
23014+ addq %rbp, level3_ident_pgt + (1*8)(%rip)
23015+#endif
23016
23017- addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
23018+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
23019+
23020+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
23021+ addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
23022+
23023+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
23024
23025 /*
23026 * Set up the identity mapping for the switchover. These
23027@@ -177,8 +197,8 @@ ENTRY(secondary_startup_64)
23028 movq $(init_level4_pgt - __START_KERNEL_map), %rax
23029 1:
23030
23031- /* Enable PAE mode and PGE */
23032- movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
23033+ /* Enable PAE mode and PSE/PGE */
23034+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
23035 movq %rcx, %cr4
23036
23037 /* Setup early boot stage 4 level pagetables. */
23038@@ -199,10 +219,18 @@ ENTRY(secondary_startup_64)
23039 movl $MSR_EFER, %ecx
23040 rdmsr
23041 btsl $_EFER_SCE, %eax /* Enable System Call */
23042- btl $20,%edi /* No Execute supported? */
23043+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
23044 jnc 1f
23045 btsl $_EFER_NX, %eax
23046 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
23047+ leaq init_level4_pgt(%rip), %rdi
23048+#ifndef CONFIG_EFI
23049+ btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
23050+#endif
23051+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
23052+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
23053+ btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
23054+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
23055 1: wrmsr /* Make changes effective */
23056
23057 /* Setup cr0 */
23058@@ -282,6 +310,7 @@ ENTRY(secondary_startup_64)
23059 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
23060 * address given in m16:64.
23061 */
23062+ pax_set_fptr_mask
23063 movq initial_code(%rip),%rax
23064 pushq $0 # fake return address to stop unwinder
23065 pushq $__KERNEL_CS # set correct cs
23066@@ -388,7 +417,7 @@ ENTRY(early_idt_handler)
23067 call dump_stack
23068 #ifdef CONFIG_KALLSYMS
23069 leaq early_idt_ripmsg(%rip),%rdi
23070- movq 40(%rsp),%rsi # %rip again
23071+ movq 88(%rsp),%rsi # %rip again
23072 call __print_symbol
23073 #endif
23074 #endif /* EARLY_PRINTK */
23075@@ -416,6 +445,7 @@ ENDPROC(early_idt_handler)
23076 early_recursion_flag:
23077 .long 0
23078
23079+ .section .rodata,"a",@progbits
23080 #ifdef CONFIG_EARLY_PRINTK
23081 early_idt_msg:
23082 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
23083@@ -443,29 +473,52 @@ NEXT_PAGE(early_level4_pgt)
23084 NEXT_PAGE(early_dynamic_pgts)
23085 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
23086
23087- .data
23088+ .section .rodata,"a",@progbits
23089
23090-#ifndef CONFIG_XEN
23091 NEXT_PAGE(init_level4_pgt)
23092- .fill 512,8,0
23093-#else
23094-NEXT_PAGE(init_level4_pgt)
23095- .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
23096 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
23097 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
23098+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
23099+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
23100+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
23101+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
23102+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
23103+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
23104 .org init_level4_pgt + L4_START_KERNEL*8, 0
23105 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
23106 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
23107
23108+#ifdef CONFIG_PAX_PER_CPU_PGD
23109+NEXT_PAGE(cpu_pgd)
23110+ .rept 2*NR_CPUS
23111+ .fill 512,8,0
23112+ .endr
23113+#endif
23114+
23115 NEXT_PAGE(level3_ident_pgt)
23116 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
23117+#ifdef CONFIG_XEN
23118 .fill 511, 8, 0
23119+#else
23120+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
23121+ .fill 510,8,0
23122+#endif
23123+
23124+NEXT_PAGE(level3_vmalloc_start_pgt)
23125+ .fill 512,8,0
23126+
23127+NEXT_PAGE(level3_vmalloc_end_pgt)
23128+ .fill 512,8,0
23129+
23130+NEXT_PAGE(level3_vmemmap_pgt)
23131+ .fill L3_VMEMMAP_START,8,0
23132+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
23133+
23134 NEXT_PAGE(level2_ident_pgt)
23135- /* Since I easily can, map the first 1G.
23136+ /* Since I easily can, map the first 2G.
23137 * Don't set NX because code runs from these pages.
23138 */
23139- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
23140-#endif
23141+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
23142
23143 NEXT_PAGE(level3_kernel_pgt)
23144 .fill L3_START_KERNEL,8,0
23145@@ -473,6 +526,9 @@ NEXT_PAGE(level3_kernel_pgt)
23146 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
23147 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
23148
23149+NEXT_PAGE(level2_vmemmap_pgt)
23150+ .fill 512,8,0
23151+
23152 NEXT_PAGE(level2_kernel_pgt)
23153 /*
23154 * 512 MB kernel mapping. We spend a full page on this pagetable
23155@@ -488,30 +544,62 @@ NEXT_PAGE(level2_kernel_pgt)
23156 KERNEL_IMAGE_SIZE/PMD_SIZE)
23157
23158 NEXT_PAGE(level2_fixmap_pgt)
23159- .fill 506,8,0
23160- .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
23161- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
23162- .fill 5,8,0
23163+ .fill 507,8,0
23164+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
23165+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
23166+ .fill 4,8,0
23167
23168-NEXT_PAGE(level1_fixmap_pgt)
23169+NEXT_PAGE(level1_vsyscall_pgt)
23170 .fill 512,8,0
23171
23172 #undef PMDS
23173
23174- .data
23175+ .align PAGE_SIZE
23176+ENTRY(cpu_gdt_table)
23177+ .rept NR_CPUS
23178+ .quad 0x0000000000000000 /* NULL descriptor */
23179+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
23180+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
23181+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
23182+ .quad 0x00cffb000000ffff /* __USER32_CS */
23183+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
23184+ .quad 0x00affb000000ffff /* __USER_CS */
23185+
23186+#ifdef CONFIG_PAX_KERNEXEC
23187+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
23188+#else
23189+ .quad 0x0 /* unused */
23190+#endif
23191+
23192+ .quad 0,0 /* TSS */
23193+ .quad 0,0 /* LDT */
23194+ .quad 0,0,0 /* three TLS descriptors */
23195+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
23196+ /* asm/segment.h:GDT_ENTRIES must match this */
23197+
23198+#ifdef CONFIG_PAX_MEMORY_UDEREF
23199+ .quad 0x00cf93000000ffff /* __UDEREF_KERNEL_DS */
23200+#else
23201+ .quad 0x0 /* unused */
23202+#endif
23203+
23204+ /* zero the remaining page */
23205+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
23206+ .endr
23207+
23208 .align 16
23209 .globl early_gdt_descr
23210 early_gdt_descr:
23211 .word GDT_ENTRIES*8-1
23212 early_gdt_descr_base:
23213- .quad INIT_PER_CPU_VAR(gdt_page)
23214+ .quad cpu_gdt_table
23215
23216 ENTRY(phys_base)
23217 /* This must match the first entry in level2_kernel_pgt */
23218 .quad 0x0000000000000000
23219
23220 #include "../../x86/xen/xen-head.S"
23221-
23222- __PAGE_ALIGNED_BSS
23223+
23224+ .section .rodata,"a",@progbits
23225 NEXT_PAGE(empty_zero_page)
23226 .skip PAGE_SIZE
23227diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
23228index 0fa6912..b37438b 100644
23229--- a/arch/x86/kernel/i386_ksyms_32.c
23230+++ b/arch/x86/kernel/i386_ksyms_32.c
23231@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
23232 EXPORT_SYMBOL(cmpxchg8b_emu);
23233 #endif
23234
23235+EXPORT_SYMBOL_GPL(cpu_gdt_table);
23236+
23237 /* Networking helper routines. */
23238 EXPORT_SYMBOL(csum_partial_copy_generic);
23239+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
23240+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
23241
23242 EXPORT_SYMBOL(__get_user_1);
23243 EXPORT_SYMBOL(__get_user_2);
23244@@ -37,3 +41,11 @@ EXPORT_SYMBOL(strstr);
23245
23246 EXPORT_SYMBOL(csum_partial);
23247 EXPORT_SYMBOL(empty_zero_page);
23248+
23249+#ifdef CONFIG_PAX_KERNEXEC
23250+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
23251+#endif
23252+
23253+#ifdef CONFIG_PAX_PER_CPU_PGD
23254+EXPORT_SYMBOL(cpu_pgd);
23255+#endif
23256diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
23257index 5d576ab..1403a03 100644
23258--- a/arch/x86/kernel/i387.c
23259+++ b/arch/x86/kernel/i387.c
23260@@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
23261 static inline bool interrupted_user_mode(void)
23262 {
23263 struct pt_regs *regs = get_irq_regs();
23264- return regs && user_mode_vm(regs);
23265+ return regs && user_mode(regs);
23266 }
23267
23268 /*
23269diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
23270index 9a5c460..84868423 100644
23271--- a/arch/x86/kernel/i8259.c
23272+++ b/arch/x86/kernel/i8259.c
23273@@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
23274 static void make_8259A_irq(unsigned int irq)
23275 {
23276 disable_irq_nosync(irq);
23277- io_apic_irqs &= ~(1<<irq);
23278+ io_apic_irqs &= ~(1UL<<irq);
23279 irq_set_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
23280 i8259A_chip.name);
23281 enable_irq(irq);
23282@@ -209,7 +209,7 @@ spurious_8259A_irq:
23283 "spurious 8259A interrupt: IRQ%d.\n", irq);
23284 spurious_irq_mask |= irqmask;
23285 }
23286- atomic_inc(&irq_err_count);
23287+ atomic_inc_unchecked(&irq_err_count);
23288 /*
23289 * Theoretically we do not have to handle this IRQ,
23290 * but in Linux this does not cause problems and is
23291@@ -333,14 +333,16 @@ static void init_8259A(int auto_eoi)
23292 /* (slave's support for AEOI in flat mode is to be investigated) */
23293 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
23294
23295+ pax_open_kernel();
23296 if (auto_eoi)
23297 /*
23298 * In AEOI mode we just have to mask the interrupt
23299 * when acking.
23300 */
23301- i8259A_chip.irq_mask_ack = disable_8259A_irq;
23302+ *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
23303 else
23304- i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
23305+ *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
23306+ pax_close_kernel();
23307
23308 udelay(100); /* wait for 8259A to initialize */
23309
23310diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
23311index a979b5b..1d6db75 100644
23312--- a/arch/x86/kernel/io_delay.c
23313+++ b/arch/x86/kernel/io_delay.c
23314@@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
23315 * Quirk table for systems that misbehave (lock up, etc.) if port
23316 * 0x80 is used:
23317 */
23318-static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
23319+static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
23320 {
23321 .callback = dmi_io_delay_0xed_port,
23322 .ident = "Compaq Presario V6000",
23323diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
23324index 4ddaf66..6292f4e 100644
23325--- a/arch/x86/kernel/ioport.c
23326+++ b/arch/x86/kernel/ioport.c
23327@@ -6,6 +6,7 @@
23328 #include <linux/sched.h>
23329 #include <linux/kernel.h>
23330 #include <linux/capability.h>
23331+#include <linux/security.h>
23332 #include <linux/errno.h>
23333 #include <linux/types.h>
23334 #include <linux/ioport.h>
23335@@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
23336
23337 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
23338 return -EINVAL;
23339+#ifdef CONFIG_GRKERNSEC_IO
23340+ if (turn_on && grsec_disable_privio) {
23341+ gr_handle_ioperm();
23342+ return -EPERM;
23343+ }
23344+#endif
23345 if (turn_on && !capable(CAP_SYS_RAWIO))
23346 return -EPERM;
23347
23348@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
23349 * because the ->io_bitmap_max value must match the bitmap
23350 * contents:
23351 */
23352- tss = &per_cpu(init_tss, get_cpu());
23353+ tss = init_tss + get_cpu();
23354
23355 if (turn_on)
23356 bitmap_clear(t->io_bitmap_ptr, from, num);
23357@@ -103,6 +110,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
23358 return -EINVAL;
23359 /* Trying to gain more privileges? */
23360 if (level > old) {
23361+#ifdef CONFIG_GRKERNSEC_IO
23362+ if (grsec_disable_privio) {
23363+ gr_handle_iopl();
23364+ return -EPERM;
23365+ }
23366+#endif
23367 if (!capable(CAP_SYS_RAWIO))
23368 return -EPERM;
23369 }
23370diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
23371index 3a8185c..3c042ee 100644
23372--- a/arch/x86/kernel/irq.c
23373+++ b/arch/x86/kernel/irq.c
23374@@ -21,7 +21,7 @@
23375 #define CREATE_TRACE_POINTS
23376 #include <asm/trace/irq_vectors.h>
23377
23378-atomic_t irq_err_count;
23379+atomic_unchecked_t irq_err_count;
23380
23381 /* Function pointer for generic interrupt vector handling */
23382 void (*x86_platform_ipi_callback)(void) = NULL;
23383@@ -125,9 +125,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
23384 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
23385 seq_printf(p, " Machine check polls\n");
23386 #endif
23387- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
23388+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
23389 #if defined(CONFIG_X86_IO_APIC)
23390- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
23391+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
23392 #endif
23393 return 0;
23394 }
23395@@ -167,7 +167,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
23396
23397 u64 arch_irq_stat(void)
23398 {
23399- u64 sum = atomic_read(&irq_err_count);
23400+ u64 sum = atomic_read_unchecked(&irq_err_count);
23401 return sum;
23402 }
23403
23404diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
23405index 4186755..784efa0 100644
23406--- a/arch/x86/kernel/irq_32.c
23407+++ b/arch/x86/kernel/irq_32.c
23408@@ -39,7 +39,7 @@ static int check_stack_overflow(void)
23409 __asm__ __volatile__("andl %%esp,%0" :
23410 "=r" (sp) : "0" (THREAD_SIZE - 1));
23411
23412- return sp < (sizeof(struct thread_info) + STACK_WARN);
23413+ return sp < STACK_WARN;
23414 }
23415
23416 static void print_stack_overflow(void)
23417@@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
23418 * per-CPU IRQ handling contexts (thread information and stack)
23419 */
23420 union irq_ctx {
23421- struct thread_info tinfo;
23422- u32 stack[THREAD_SIZE/sizeof(u32)];
23423+ unsigned long previous_esp;
23424+ u32 stack[THREAD_SIZE/sizeof(u32)];
23425 } __attribute__((aligned(THREAD_SIZE)));
23426
23427 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
23428@@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
23429 static inline int
23430 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
23431 {
23432- union irq_ctx *curctx, *irqctx;
23433+ union irq_ctx *irqctx;
23434 u32 *isp, arg1, arg2;
23435
23436- curctx = (union irq_ctx *) current_thread_info();
23437 irqctx = __this_cpu_read(hardirq_ctx);
23438
23439 /*
23440@@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
23441 * handler) we can't do that and just have to keep using the
23442 * current stack (which is the irq stack already after all)
23443 */
23444- if (unlikely(curctx == irqctx))
23445+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
23446 return 0;
23447
23448 /* build the stack frame on the IRQ stack */
23449- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
23450- irqctx->tinfo.task = curctx->tinfo.task;
23451- irqctx->tinfo.previous_esp = current_stack_pointer;
23452+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
23453+ irqctx->previous_esp = current_stack_pointer;
23454
23455- /* Copy the preempt_count so that the [soft]irq checks work. */
23456- irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
23457+#ifdef CONFIG_PAX_MEMORY_UDEREF
23458+ __set_fs(MAKE_MM_SEG(0));
23459+#endif
23460
23461 if (unlikely(overflow))
23462 call_on_stack(print_stack_overflow, isp);
23463@@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
23464 : "0" (irq), "1" (desc), "2" (isp),
23465 "D" (desc->handle_irq)
23466 : "memory", "cc", "ecx");
23467+
23468+#ifdef CONFIG_PAX_MEMORY_UDEREF
23469+ __set_fs(current_thread_info()->addr_limit);
23470+#endif
23471+
23472 return 1;
23473 }
23474
23475@@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
23476 */
23477 void irq_ctx_init(int cpu)
23478 {
23479- union irq_ctx *irqctx;
23480-
23481 if (per_cpu(hardirq_ctx, cpu))
23482 return;
23483
23484- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
23485- THREADINFO_GFP,
23486- THREAD_SIZE_ORDER));
23487- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
23488- irqctx->tinfo.cpu = cpu;
23489- irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
23490- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
23491+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
23492+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
23493
23494- per_cpu(hardirq_ctx, cpu) = irqctx;
23495-
23496- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
23497- THREADINFO_GFP,
23498- THREAD_SIZE_ORDER));
23499- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
23500- irqctx->tinfo.cpu = cpu;
23501- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
23502-
23503- per_cpu(softirq_ctx, cpu) = irqctx;
23504+ printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
23505+ cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
23506
23507 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
23508 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
23509@@ -152,7 +141,6 @@ void irq_ctx_init(int cpu)
23510 asmlinkage void do_softirq(void)
23511 {
23512 unsigned long flags;
23513- struct thread_info *curctx;
23514 union irq_ctx *irqctx;
23515 u32 *isp;
23516
23517@@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
23518 local_irq_save(flags);
23519
23520 if (local_softirq_pending()) {
23521- curctx = current_thread_info();
23522 irqctx = __this_cpu_read(softirq_ctx);
23523- irqctx->tinfo.task = curctx->task;
23524- irqctx->tinfo.previous_esp = current_stack_pointer;
23525+ irqctx->previous_esp = current_stack_pointer;
23526
23527 /* build the stack frame on the softirq stack */
23528- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
23529+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
23530+
23531+#ifdef CONFIG_PAX_MEMORY_UDEREF
23532+ __set_fs(MAKE_MM_SEG(0));
23533+#endif
23534
23535 call_on_stack(__do_softirq, isp);
23536+
23537+#ifdef CONFIG_PAX_MEMORY_UDEREF
23538+ __set_fs(current_thread_info()->addr_limit);
23539+#endif
23540+
23541 /*
23542 * Shouldn't happen, we returned above if in_interrupt():
23543 */
23544@@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
23545 if (unlikely(!desc))
23546 return false;
23547
23548- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
23549+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
23550 if (unlikely(overflow))
23551 print_stack_overflow();
23552 desc->handle_irq(irq, desc);
23553diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
23554index d04d3ec..ea4b374 100644
23555--- a/arch/x86/kernel/irq_64.c
23556+++ b/arch/x86/kernel/irq_64.c
23557@@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
23558 u64 estack_top, estack_bottom;
23559 u64 curbase = (u64)task_stack_page(current);
23560
23561- if (user_mode_vm(regs))
23562+ if (user_mode(regs))
23563 return;
23564
23565 if (regs->sp >= curbase + sizeof(struct thread_info) +
23566diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
23567index dc1404b..bbc43e7 100644
23568--- a/arch/x86/kernel/kdebugfs.c
23569+++ b/arch/x86/kernel/kdebugfs.c
23570@@ -27,7 +27,7 @@ struct setup_data_node {
23571 u32 len;
23572 };
23573
23574-static ssize_t setup_data_read(struct file *file, char __user *user_buf,
23575+static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
23576 size_t count, loff_t *ppos)
23577 {
23578 struct setup_data_node *node = file->private_data;
23579diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
23580index 836f832..a8bda67 100644
23581--- a/arch/x86/kernel/kgdb.c
23582+++ b/arch/x86/kernel/kgdb.c
23583@@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
23584 #ifdef CONFIG_X86_32
23585 switch (regno) {
23586 case GDB_SS:
23587- if (!user_mode_vm(regs))
23588+ if (!user_mode(regs))
23589 *(unsigned long *)mem = __KERNEL_DS;
23590 break;
23591 case GDB_SP:
23592- if (!user_mode_vm(regs))
23593+ if (!user_mode(regs))
23594 *(unsigned long *)mem = kernel_stack_pointer(regs);
23595 break;
23596 case GDB_GS:
23597@@ -229,7 +229,10 @@ static void kgdb_correct_hw_break(void)
23598 bp->attr.bp_addr = breakinfo[breakno].addr;
23599 bp->attr.bp_len = breakinfo[breakno].len;
23600 bp->attr.bp_type = breakinfo[breakno].type;
23601- info->address = breakinfo[breakno].addr;
23602+ if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
23603+ info->address = ktla_ktva(breakinfo[breakno].addr);
23604+ else
23605+ info->address = breakinfo[breakno].addr;
23606 info->len = breakinfo[breakno].len;
23607 info->type = breakinfo[breakno].type;
23608 val = arch_install_hw_breakpoint(bp);
23609@@ -476,12 +479,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
23610 case 'k':
23611 /* clear the trace bit */
23612 linux_regs->flags &= ~X86_EFLAGS_TF;
23613- atomic_set(&kgdb_cpu_doing_single_step, -1);
23614+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
23615
23616 /* set the trace bit if we're stepping */
23617 if (remcomInBuffer[0] == 's') {
23618 linux_regs->flags |= X86_EFLAGS_TF;
23619- atomic_set(&kgdb_cpu_doing_single_step,
23620+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
23621 raw_smp_processor_id());
23622 }
23623
23624@@ -546,7 +549,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
23625
23626 switch (cmd) {
23627 case DIE_DEBUG:
23628- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
23629+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
23630 if (user_mode(regs))
23631 return single_step_cont(regs, args);
23632 break;
23633@@ -751,11 +754,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
23634 #endif /* CONFIG_DEBUG_RODATA */
23635
23636 bpt->type = BP_BREAKPOINT;
23637- err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
23638+ err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
23639 BREAK_INSTR_SIZE);
23640 if (err)
23641 return err;
23642- err = probe_kernel_write((char *)bpt->bpt_addr,
23643+ err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
23644 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
23645 #ifdef CONFIG_DEBUG_RODATA
23646 if (!err)
23647@@ -768,7 +771,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
23648 return -EBUSY;
23649 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
23650 BREAK_INSTR_SIZE);
23651- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
23652+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
23653 if (err)
23654 return err;
23655 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
23656@@ -793,13 +796,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
23657 if (mutex_is_locked(&text_mutex))
23658 goto knl_write;
23659 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
23660- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
23661+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
23662 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
23663 goto knl_write;
23664 return err;
23665 knl_write:
23666 #endif /* CONFIG_DEBUG_RODATA */
23667- return probe_kernel_write((char *)bpt->bpt_addr,
23668+ return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
23669 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
23670 }
23671
23672diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
23673index 211bce4..6e2580a 100644
23674--- a/arch/x86/kernel/kprobes/core.c
23675+++ b/arch/x86/kernel/kprobes/core.c
23676@@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
23677 s32 raddr;
23678 } __packed *insn;
23679
23680- insn = (struct __arch_relative_insn *)from;
23681+ insn = (struct __arch_relative_insn *)ktla_ktva(from);
23682+
23683+ pax_open_kernel();
23684 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
23685 insn->op = op;
23686+ pax_close_kernel();
23687 }
23688
23689 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
23690@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
23691 kprobe_opcode_t opcode;
23692 kprobe_opcode_t *orig_opcodes = opcodes;
23693
23694- if (search_exception_tables((unsigned long)opcodes))
23695+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
23696 return 0; /* Page fault may occur on this address. */
23697
23698 retry:
23699@@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
23700 * for the first byte, we can recover the original instruction
23701 * from it and kp->opcode.
23702 */
23703- memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
23704+ memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
23705 buf[0] = kp->opcode;
23706- return (unsigned long)buf;
23707+ return ktva_ktla((unsigned long)buf);
23708 }
23709
23710 /*
23711@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
23712 /* Another subsystem puts a breakpoint, failed to recover */
23713 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
23714 return 0;
23715+ pax_open_kernel();
23716 memcpy(dest, insn.kaddr, insn.length);
23717+ pax_close_kernel();
23718
23719 #ifdef CONFIG_X86_64
23720 if (insn_rip_relative(&insn)) {
23721@@ -359,7 +364,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
23722 return 0;
23723 }
23724 disp = (u8 *) dest + insn_offset_displacement(&insn);
23725+ pax_open_kernel();
23726 *(s32 *) disp = (s32) newdisp;
23727+ pax_close_kernel();
23728 }
23729 #endif
23730 return insn.length;
23731@@ -498,7 +505,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
23732 * nor set current_kprobe, because it doesn't use single
23733 * stepping.
23734 */
23735- regs->ip = (unsigned long)p->ainsn.insn;
23736+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
23737 preempt_enable_no_resched();
23738 return;
23739 }
23740@@ -515,9 +522,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
23741 regs->flags &= ~X86_EFLAGS_IF;
23742 /* single step inline if the instruction is an int3 */
23743 if (p->opcode == BREAKPOINT_INSTRUCTION)
23744- regs->ip = (unsigned long)p->addr;
23745+ regs->ip = ktla_ktva((unsigned long)p->addr);
23746 else
23747- regs->ip = (unsigned long)p->ainsn.insn;
23748+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
23749 }
23750
23751 /*
23752@@ -596,7 +603,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
23753 setup_singlestep(p, regs, kcb, 0);
23754 return 1;
23755 }
23756- } else if (*addr != BREAKPOINT_INSTRUCTION) {
23757+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
23758 /*
23759 * The breakpoint instruction was removed right
23760 * after we hit it. Another cpu has removed
23761@@ -642,6 +649,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
23762 " movq %rax, 152(%rsp)\n"
23763 RESTORE_REGS_STRING
23764 " popfq\n"
23765+#ifdef KERNEXEC_PLUGIN
23766+ " btsq $63,(%rsp)\n"
23767+#endif
23768 #else
23769 " pushf\n"
23770 SAVE_REGS_STRING
23771@@ -779,7 +789,7 @@ static void __kprobes
23772 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
23773 {
23774 unsigned long *tos = stack_addr(regs);
23775- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
23776+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
23777 unsigned long orig_ip = (unsigned long)p->addr;
23778 kprobe_opcode_t *insn = p->ainsn.insn;
23779
23780@@ -961,7 +971,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
23781 struct die_args *args = data;
23782 int ret = NOTIFY_DONE;
23783
23784- if (args->regs && user_mode_vm(args->regs))
23785+ if (args->regs && user_mode(args->regs))
23786 return ret;
23787
23788 switch (val) {
23789diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
23790index 76dc6f0..66bdfc3 100644
23791--- a/arch/x86/kernel/kprobes/opt.c
23792+++ b/arch/x86/kernel/kprobes/opt.c
23793@@ -79,6 +79,7 @@ found:
23794 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
23795 static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
23796 {
23797+ pax_open_kernel();
23798 #ifdef CONFIG_X86_64
23799 *addr++ = 0x48;
23800 *addr++ = 0xbf;
23801@@ -86,6 +87,7 @@ static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long v
23802 *addr++ = 0xb8;
23803 #endif
23804 *(unsigned long *)addr = val;
23805+ pax_close_kernel();
23806 }
23807
23808 static void __used __kprobes kprobes_optinsn_template_holder(void)
23809@@ -338,7 +340,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
23810 * Verify if the address gap is in 2GB range, because this uses
23811 * a relative jump.
23812 */
23813- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
23814+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
23815 if (abs(rel) > 0x7fffffff)
23816 return -ERANGE;
23817
23818@@ -353,16 +355,18 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
23819 op->optinsn.size = ret;
23820
23821 /* Copy arch-dep-instance from template */
23822- memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
23823+ pax_open_kernel();
23824+ memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
23825+ pax_close_kernel();
23826
23827 /* Set probe information */
23828 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
23829
23830 /* Set probe function call */
23831- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
23832+ synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
23833
23834 /* Set returning jmp instruction at the tail of out-of-line buffer */
23835- synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
23836+ synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
23837 (u8 *)op->kp.addr + op->optinsn.size);
23838
23839 flush_icache_range((unsigned long) buf,
23840@@ -385,7 +389,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
23841 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
23842
23843 /* Backup instructions which will be replaced by jump address */
23844- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
23845+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
23846 RELATIVE_ADDR_SIZE);
23847
23848 insn_buf[0] = RELATIVEJUMP_OPCODE;
23849@@ -483,7 +487,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
23850 /* This kprobe is really able to run optimized path. */
23851 op = container_of(p, struct optimized_kprobe, kp);
23852 /* Detour through copied instructions */
23853- regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
23854+ regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
23855 if (!reenter)
23856 reset_current_kprobe();
23857 preempt_enable_no_resched();
23858diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
23859index ebc9873..1b9724b 100644
23860--- a/arch/x86/kernel/ldt.c
23861+++ b/arch/x86/kernel/ldt.c
23862@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
23863 if (reload) {
23864 #ifdef CONFIG_SMP
23865 preempt_disable();
23866- load_LDT(pc);
23867+ load_LDT_nolock(pc);
23868 if (!cpumask_equal(mm_cpumask(current->mm),
23869 cpumask_of(smp_processor_id())))
23870 smp_call_function(flush_ldt, current->mm, 1);
23871 preempt_enable();
23872 #else
23873- load_LDT(pc);
23874+ load_LDT_nolock(pc);
23875 #endif
23876 }
23877 if (oldsize) {
23878@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
23879 return err;
23880
23881 for (i = 0; i < old->size; i++)
23882- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
23883+ write_ldt_entry(new->ldt, i, old->ldt + i);
23884 return 0;
23885 }
23886
23887@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
23888 retval = copy_ldt(&mm->context, &old_mm->context);
23889 mutex_unlock(&old_mm->context.lock);
23890 }
23891+
23892+ if (tsk == current) {
23893+ mm->context.vdso = 0;
23894+
23895+#ifdef CONFIG_X86_32
23896+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23897+ mm->context.user_cs_base = 0UL;
23898+ mm->context.user_cs_limit = ~0UL;
23899+
23900+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
23901+ cpus_clear(mm->context.cpu_user_cs_mask);
23902+#endif
23903+
23904+#endif
23905+#endif
23906+
23907+ }
23908+
23909 return retval;
23910 }
23911
23912@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
23913 }
23914 }
23915
23916+#ifdef CONFIG_PAX_SEGMEXEC
23917+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
23918+ error = -EINVAL;
23919+ goto out_unlock;
23920+ }
23921+#endif
23922+
23923 fill_ldt(&ldt, &ldt_info);
23924 if (oldmode)
23925 ldt.avl = 0;
23926diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
23927index 5b19e4d..6476a76 100644
23928--- a/arch/x86/kernel/machine_kexec_32.c
23929+++ b/arch/x86/kernel/machine_kexec_32.c
23930@@ -26,7 +26,7 @@
23931 #include <asm/cacheflush.h>
23932 #include <asm/debugreg.h>
23933
23934-static void set_idt(void *newidt, __u16 limit)
23935+static void set_idt(struct desc_struct *newidt, __u16 limit)
23936 {
23937 struct desc_ptr curidt;
23938
23939@@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
23940 }
23941
23942
23943-static void set_gdt(void *newgdt, __u16 limit)
23944+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
23945 {
23946 struct desc_ptr curgdt;
23947
23948@@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
23949 }
23950
23951 control_page = page_address(image->control_code_page);
23952- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
23953+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
23954
23955 relocate_kernel_ptr = control_page;
23956 page_list[PA_CONTROL_PAGE] = __pa(control_page);
23957diff --git a/arch/x86/kernel/microcode_core.c b/arch/x86/kernel/microcode_core.c
23958index 15c9876..0a43909 100644
23959--- a/arch/x86/kernel/microcode_core.c
23960+++ b/arch/x86/kernel/microcode_core.c
23961@@ -513,7 +513,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
23962 return NOTIFY_OK;
23963 }
23964
23965-static struct notifier_block __refdata mc_cpu_notifier = {
23966+static struct notifier_block mc_cpu_notifier = {
23967 .notifier_call = mc_cpu_callback,
23968 };
23969
23970diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
23971index 5fb2ceb..3ae90bb 100644
23972--- a/arch/x86/kernel/microcode_intel.c
23973+++ b/arch/x86/kernel/microcode_intel.c
23974@@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
23975
23976 static int get_ucode_user(void *to, const void *from, size_t n)
23977 {
23978- return copy_from_user(to, from, n);
23979+ return copy_from_user(to, (const void __force_user *)from, n);
23980 }
23981
23982 static enum ucode_state
23983 request_microcode_user(int cpu, const void __user *buf, size_t size)
23984 {
23985- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
23986+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
23987 }
23988
23989 static void microcode_fini_cpu(int cpu)
23990diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
23991index 216a4d7..228255a 100644
23992--- a/arch/x86/kernel/module.c
23993+++ b/arch/x86/kernel/module.c
23994@@ -43,15 +43,60 @@ do { \
23995 } while (0)
23996 #endif
23997
23998-void *module_alloc(unsigned long size)
23999+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
24000 {
24001- if (PAGE_ALIGN(size) > MODULES_LEN)
24002+ if (!size || PAGE_ALIGN(size) > MODULES_LEN)
24003 return NULL;
24004 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
24005- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
24006+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
24007 -1, __builtin_return_address(0));
24008 }
24009
24010+void *module_alloc(unsigned long size)
24011+{
24012+
24013+#ifdef CONFIG_PAX_KERNEXEC
24014+ return __module_alloc(size, PAGE_KERNEL);
24015+#else
24016+ return __module_alloc(size, PAGE_KERNEL_EXEC);
24017+#endif
24018+
24019+}
24020+
24021+#ifdef CONFIG_PAX_KERNEXEC
24022+#ifdef CONFIG_X86_32
24023+void *module_alloc_exec(unsigned long size)
24024+{
24025+ struct vm_struct *area;
24026+
24027+ if (size == 0)
24028+ return NULL;
24029+
24030+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
24031+ return area ? area->addr : NULL;
24032+}
24033+EXPORT_SYMBOL(module_alloc_exec);
24034+
24035+void module_free_exec(struct module *mod, void *module_region)
24036+{
24037+ vunmap(module_region);
24038+}
24039+EXPORT_SYMBOL(module_free_exec);
24040+#else
24041+void module_free_exec(struct module *mod, void *module_region)
24042+{
24043+ module_free(mod, module_region);
24044+}
24045+EXPORT_SYMBOL(module_free_exec);
24046+
24047+void *module_alloc_exec(unsigned long size)
24048+{
24049+ return __module_alloc(size, PAGE_KERNEL_RX);
24050+}
24051+EXPORT_SYMBOL(module_alloc_exec);
24052+#endif
24053+#endif
24054+
24055 #ifdef CONFIG_X86_32
24056 int apply_relocate(Elf32_Shdr *sechdrs,
24057 const char *strtab,
24058@@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
24059 unsigned int i;
24060 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
24061 Elf32_Sym *sym;
24062- uint32_t *location;
24063+ uint32_t *plocation, location;
24064
24065 DEBUGP("Applying relocate section %u to %u\n",
24066 relsec, sechdrs[relsec].sh_info);
24067 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
24068 /* This is where to make the change */
24069- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
24070- + rel[i].r_offset;
24071+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
24072+ location = (uint32_t)plocation;
24073+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
24074+ plocation = ktla_ktva((void *)plocation);
24075 /* This is the symbol it is referring to. Note that all
24076 undefined symbols have been resolved. */
24077 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
24078@@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
24079 switch (ELF32_R_TYPE(rel[i].r_info)) {
24080 case R_386_32:
24081 /* We add the value into the location given */
24082- *location += sym->st_value;
24083+ pax_open_kernel();
24084+ *plocation += sym->st_value;
24085+ pax_close_kernel();
24086 break;
24087 case R_386_PC32:
24088 /* Add the value, subtract its position */
24089- *location += sym->st_value - (uint32_t)location;
24090+ pax_open_kernel();
24091+ *plocation += sym->st_value - location;
24092+ pax_close_kernel();
24093 break;
24094 default:
24095 pr_err("%s: Unknown relocation: %u\n",
24096@@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
24097 case R_X86_64_NONE:
24098 break;
24099 case R_X86_64_64:
24100+ pax_open_kernel();
24101 *(u64 *)loc = val;
24102+ pax_close_kernel();
24103 break;
24104 case R_X86_64_32:
24105+ pax_open_kernel();
24106 *(u32 *)loc = val;
24107+ pax_close_kernel();
24108 if (val != *(u32 *)loc)
24109 goto overflow;
24110 break;
24111 case R_X86_64_32S:
24112+ pax_open_kernel();
24113 *(s32 *)loc = val;
24114+ pax_close_kernel();
24115 if ((s64)val != *(s32 *)loc)
24116 goto overflow;
24117 break;
24118 case R_X86_64_PC32:
24119 val -= (u64)loc;
24120+ pax_open_kernel();
24121 *(u32 *)loc = val;
24122+ pax_close_kernel();
24123+
24124 #if 0
24125 if ((s64)val != *(s32 *)loc)
24126 goto overflow;
24127diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
24128index 88458fa..349f7a4 100644
24129--- a/arch/x86/kernel/msr.c
24130+++ b/arch/x86/kernel/msr.c
24131@@ -233,7 +233,7 @@ static int msr_class_cpu_callback(struct notifier_block *nfb,
24132 return notifier_from_errno(err);
24133 }
24134
24135-static struct notifier_block __refdata msr_class_cpu_notifier = {
24136+static struct notifier_block msr_class_cpu_notifier = {
24137 .notifier_call = msr_class_cpu_callback,
24138 };
24139
24140diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
24141index ba77ebc..65da999 100644
24142--- a/arch/x86/kernel/nmi.c
24143+++ b/arch/x86/kernel/nmi.c
24144@@ -138,7 +138,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
24145 return handled;
24146 }
24147
24148-int __register_nmi_handler(unsigned int type, struct nmiaction *action)
24149+int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
24150 {
24151 struct nmi_desc *desc = nmi_to_desc(type);
24152 unsigned long flags;
24153@@ -162,9 +162,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
24154 * event confuses some handlers (kdump uses this flag)
24155 */
24156 if (action->flags & NMI_FLAG_FIRST)
24157- list_add_rcu(&action->list, &desc->head);
24158+ pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
24159 else
24160- list_add_tail_rcu(&action->list, &desc->head);
24161+ pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
24162
24163 spin_unlock_irqrestore(&desc->lock, flags);
24164 return 0;
24165@@ -187,7 +187,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
24166 if (!strcmp(n->name, name)) {
24167 WARN(in_nmi(),
24168 "Trying to free NMI (%s) from NMI context!\n", n->name);
24169- list_del_rcu(&n->list);
24170+ pax_list_del_rcu((struct list_head *)&n->list);
24171 break;
24172 }
24173 }
24174@@ -512,6 +512,17 @@ static inline void nmi_nesting_postprocess(void)
24175 dotraplinkage notrace __kprobes void
24176 do_nmi(struct pt_regs *regs, long error_code)
24177 {
24178+
24179+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
24180+ if (!user_mode(regs)) {
24181+ unsigned long cs = regs->cs & 0xFFFF;
24182+ unsigned long ip = ktva_ktla(regs->ip);
24183+
24184+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
24185+ regs->ip = ip;
24186+ }
24187+#endif
24188+
24189 nmi_nesting_preprocess(regs);
24190
24191 nmi_enter();
24192diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
24193index 6d9582e..f746287 100644
24194--- a/arch/x86/kernel/nmi_selftest.c
24195+++ b/arch/x86/kernel/nmi_selftest.c
24196@@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
24197 {
24198 /* trap all the unknown NMIs we may generate */
24199 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
24200- __initdata);
24201+ __initconst);
24202 }
24203
24204 static void __init cleanup_nmi_testsuite(void)
24205@@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
24206 unsigned long timeout;
24207
24208 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
24209- NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
24210+ NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
24211 nmi_fail = FAILURE;
24212 return;
24213 }
24214diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
24215index 676b8c7..870ba04 100644
24216--- a/arch/x86/kernel/paravirt-spinlocks.c
24217+++ b/arch/x86/kernel/paravirt-spinlocks.c
24218@@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
24219 arch_spin_lock(lock);
24220 }
24221
24222-struct pv_lock_ops pv_lock_ops = {
24223+struct pv_lock_ops pv_lock_ops __read_only = {
24224 #ifdef CONFIG_SMP
24225 .spin_is_locked = __ticket_spin_is_locked,
24226 .spin_is_contended = __ticket_spin_is_contended,
24227diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
24228index cd6de64..27c6af0 100644
24229--- a/arch/x86/kernel/paravirt.c
24230+++ b/arch/x86/kernel/paravirt.c
24231@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
24232 {
24233 return x;
24234 }
24235+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
24236+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
24237+#endif
24238
24239 void __init default_banner(void)
24240 {
24241@@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
24242 if (opfunc == NULL)
24243 /* If there's no function, patch it with a ud2a (BUG) */
24244 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
24245- else if (opfunc == _paravirt_nop)
24246+ else if (opfunc == (void *)_paravirt_nop)
24247 /* If the operation is a nop, then nop the callsite */
24248 ret = paravirt_patch_nop();
24249
24250 /* identity functions just return their single argument */
24251- else if (opfunc == _paravirt_ident_32)
24252+ else if (opfunc == (void *)_paravirt_ident_32)
24253 ret = paravirt_patch_ident_32(insnbuf, len);
24254- else if (opfunc == _paravirt_ident_64)
24255+ else if (opfunc == (void *)_paravirt_ident_64)
24256 ret = paravirt_patch_ident_64(insnbuf, len);
24257+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
24258+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
24259+ ret = paravirt_patch_ident_64(insnbuf, len);
24260+#endif
24261
24262 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
24263 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
24264@@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
24265 if (insn_len > len || start == NULL)
24266 insn_len = len;
24267 else
24268- memcpy(insnbuf, start, insn_len);
24269+ memcpy(insnbuf, ktla_ktva(start), insn_len);
24270
24271 return insn_len;
24272 }
24273@@ -304,7 +311,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
24274 return this_cpu_read(paravirt_lazy_mode);
24275 }
24276
24277-struct pv_info pv_info = {
24278+struct pv_info pv_info __read_only = {
24279 .name = "bare hardware",
24280 .paravirt_enabled = 0,
24281 .kernel_rpl = 0,
24282@@ -315,16 +322,16 @@ struct pv_info pv_info = {
24283 #endif
24284 };
24285
24286-struct pv_init_ops pv_init_ops = {
24287+struct pv_init_ops pv_init_ops __read_only = {
24288 .patch = native_patch,
24289 };
24290
24291-struct pv_time_ops pv_time_ops = {
24292+struct pv_time_ops pv_time_ops __read_only = {
24293 .sched_clock = native_sched_clock,
24294 .steal_clock = native_steal_clock,
24295 };
24296
24297-struct pv_irq_ops pv_irq_ops = {
24298+struct pv_irq_ops pv_irq_ops __read_only = {
24299 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
24300 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
24301 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
24302@@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
24303 #endif
24304 };
24305
24306-struct pv_cpu_ops pv_cpu_ops = {
24307+struct pv_cpu_ops pv_cpu_ops __read_only = {
24308 .cpuid = native_cpuid,
24309 .get_debugreg = native_get_debugreg,
24310 .set_debugreg = native_set_debugreg,
24311@@ -394,21 +401,26 @@ struct pv_cpu_ops pv_cpu_ops = {
24312 .end_context_switch = paravirt_nop,
24313 };
24314
24315-struct pv_apic_ops pv_apic_ops = {
24316+struct pv_apic_ops pv_apic_ops __read_only= {
24317 #ifdef CONFIG_X86_LOCAL_APIC
24318 .startup_ipi_hook = paravirt_nop,
24319 #endif
24320 };
24321
24322-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
24323+#ifdef CONFIG_X86_32
24324+#ifdef CONFIG_X86_PAE
24325+/* 64-bit pagetable entries */
24326+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
24327+#else
24328 /* 32-bit pagetable entries */
24329 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
24330+#endif
24331 #else
24332 /* 64-bit pagetable entries */
24333 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
24334 #endif
24335
24336-struct pv_mmu_ops pv_mmu_ops = {
24337+struct pv_mmu_ops pv_mmu_ops __read_only = {
24338
24339 .read_cr2 = native_read_cr2,
24340 .write_cr2 = native_write_cr2,
24341@@ -458,6 +470,7 @@ struct pv_mmu_ops pv_mmu_ops = {
24342 .make_pud = PTE_IDENT,
24343
24344 .set_pgd = native_set_pgd,
24345+ .set_pgd_batched = native_set_pgd_batched,
24346 #endif
24347 #endif /* PAGETABLE_LEVELS >= 3 */
24348
24349@@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
24350 },
24351
24352 .set_fixmap = native_set_fixmap,
24353+
24354+#ifdef CONFIG_PAX_KERNEXEC
24355+ .pax_open_kernel = native_pax_open_kernel,
24356+ .pax_close_kernel = native_pax_close_kernel,
24357+#endif
24358+
24359 };
24360
24361 EXPORT_SYMBOL_GPL(pv_time_ops);
24362diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
24363index 299d493..2ccb0ee 100644
24364--- a/arch/x86/kernel/pci-calgary_64.c
24365+++ b/arch/x86/kernel/pci-calgary_64.c
24366@@ -1339,7 +1339,7 @@ static void __init get_tce_space_from_tar(void)
24367 tce_space = be64_to_cpu(readq(target));
24368 tce_space = tce_space & TAR_SW_BITS;
24369
24370- tce_space = tce_space & (~specified_table_size);
24371+ tce_space = tce_space & (~(unsigned long)specified_table_size);
24372 info->tce_space = (u64 *)__va(tce_space);
24373 }
24374 }
24375diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
24376index 35ccf75..7a15747 100644
24377--- a/arch/x86/kernel/pci-iommu_table.c
24378+++ b/arch/x86/kernel/pci-iommu_table.c
24379@@ -2,7 +2,7 @@
24380 #include <asm/iommu_table.h>
24381 #include <linux/string.h>
24382 #include <linux/kallsyms.h>
24383-
24384+#include <linux/sched.h>
24385
24386 #define DEBUG 1
24387
24388diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
24389index 6c483ba..d10ce2f 100644
24390--- a/arch/x86/kernel/pci-swiotlb.c
24391+++ b/arch/x86/kernel/pci-swiotlb.c
24392@@ -32,7 +32,7 @@ static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
24393 void *vaddr, dma_addr_t dma_addr,
24394 struct dma_attrs *attrs)
24395 {
24396- swiotlb_free_coherent(dev, size, vaddr, dma_addr);
24397+ swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
24398 }
24399
24400 static struct dma_map_ops swiotlb_dma_ops = {
24401diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
24402index 83369e5..52b93f0 100644
24403--- a/arch/x86/kernel/process.c
24404+++ b/arch/x86/kernel/process.c
24405@@ -36,7 +36,8 @@
24406 * section. Since TSS's are completely CPU-local, we want them
24407 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
24408 */
24409-DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
24410+struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
24411+EXPORT_SYMBOL(init_tss);
24412
24413 #ifdef CONFIG_X86_64
24414 static DEFINE_PER_CPU(unsigned char, is_idle);
24415@@ -92,7 +93,7 @@ void arch_task_cache_init(void)
24416 task_xstate_cachep =
24417 kmem_cache_create("task_xstate", xstate_size,
24418 __alignof__(union thread_xstate),
24419- SLAB_PANIC | SLAB_NOTRACK, NULL);
24420+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
24421 }
24422
24423 /*
24424@@ -105,7 +106,7 @@ void exit_thread(void)
24425 unsigned long *bp = t->io_bitmap_ptr;
24426
24427 if (bp) {
24428- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
24429+ struct tss_struct *tss = init_tss + get_cpu();
24430
24431 t->io_bitmap_ptr = NULL;
24432 clear_thread_flag(TIF_IO_BITMAP);
24433@@ -125,6 +126,9 @@ void flush_thread(void)
24434 {
24435 struct task_struct *tsk = current;
24436
24437+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
24438+ loadsegment(gs, 0);
24439+#endif
24440 flush_ptrace_hw_breakpoint(tsk);
24441 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
24442 drop_init_fpu(tsk);
24443@@ -271,7 +275,7 @@ static void __exit_idle(void)
24444 void exit_idle(void)
24445 {
24446 /* idle loop has pid 0 */
24447- if (current->pid)
24448+ if (task_pid_nr(current))
24449 return;
24450 __exit_idle();
24451 }
24452@@ -327,7 +331,7 @@ bool xen_set_default_idle(void)
24453 return ret;
24454 }
24455 #endif
24456-void stop_this_cpu(void *dummy)
24457+__noreturn void stop_this_cpu(void *dummy)
24458 {
24459 local_irq_disable();
24460 /*
24461@@ -456,16 +460,37 @@ static int __init idle_setup(char *str)
24462 }
24463 early_param("idle", idle_setup);
24464
24465-unsigned long arch_align_stack(unsigned long sp)
24466+#ifdef CONFIG_PAX_RANDKSTACK
24467+void pax_randomize_kstack(struct pt_regs *regs)
24468 {
24469- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
24470- sp -= get_random_int() % 8192;
24471- return sp & ~0xf;
24472-}
24473+ struct thread_struct *thread = &current->thread;
24474+ unsigned long time;
24475
24476-unsigned long arch_randomize_brk(struct mm_struct *mm)
24477-{
24478- unsigned long range_end = mm->brk + 0x02000000;
24479- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
24480-}
24481+ if (!randomize_va_space)
24482+ return;
24483+
24484+ if (v8086_mode(regs))
24485+ return;
24486
24487+ rdtscl(time);
24488+
24489+ /* P4 seems to return a 0 LSB, ignore it */
24490+#ifdef CONFIG_MPENTIUM4
24491+ time &= 0x3EUL;
24492+ time <<= 2;
24493+#elif defined(CONFIG_X86_64)
24494+ time &= 0xFUL;
24495+ time <<= 4;
24496+#else
24497+ time &= 0x1FUL;
24498+ time <<= 3;
24499+#endif
24500+
24501+ thread->sp0 ^= time;
24502+ load_sp0(init_tss + smp_processor_id(), thread);
24503+
24504+#ifdef CONFIG_X86_64
24505+ this_cpu_write(kernel_stack, thread->sp0);
24506+#endif
24507+}
24508+#endif
24509diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
24510index f8adefc..4bce3d6 100644
24511--- a/arch/x86/kernel/process_32.c
24512+++ b/arch/x86/kernel/process_32.c
24513@@ -65,6 +65,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
24514 unsigned long thread_saved_pc(struct task_struct *tsk)
24515 {
24516 return ((unsigned long *)tsk->thread.sp)[3];
24517+//XXX return tsk->thread.eip;
24518 }
24519
24520 void __show_regs(struct pt_regs *regs, int all)
24521@@ -74,19 +75,18 @@ void __show_regs(struct pt_regs *regs, int all)
24522 unsigned long sp;
24523 unsigned short ss, gs;
24524
24525- if (user_mode_vm(regs)) {
24526+ if (user_mode(regs)) {
24527 sp = regs->sp;
24528 ss = regs->ss & 0xffff;
24529- gs = get_user_gs(regs);
24530 } else {
24531 sp = kernel_stack_pointer(regs);
24532 savesegment(ss, ss);
24533- savesegment(gs, gs);
24534 }
24535+ gs = get_user_gs(regs);
24536
24537 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
24538 (u16)regs->cs, regs->ip, regs->flags,
24539- smp_processor_id());
24540+ raw_smp_processor_id());
24541 print_symbol("EIP is at %s\n", regs->ip);
24542
24543 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
24544@@ -133,20 +133,21 @@ void release_thread(struct task_struct *dead_task)
24545 int copy_thread(unsigned long clone_flags, unsigned long sp,
24546 unsigned long arg, struct task_struct *p)
24547 {
24548- struct pt_regs *childregs = task_pt_regs(p);
24549+ struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
24550 struct task_struct *tsk;
24551 int err;
24552
24553 p->thread.sp = (unsigned long) childregs;
24554 p->thread.sp0 = (unsigned long) (childregs+1);
24555+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
24556
24557 if (unlikely(p->flags & PF_KTHREAD)) {
24558 /* kernel thread */
24559 memset(childregs, 0, sizeof(struct pt_regs));
24560 p->thread.ip = (unsigned long) ret_from_kernel_thread;
24561- task_user_gs(p) = __KERNEL_STACK_CANARY;
24562- childregs->ds = __USER_DS;
24563- childregs->es = __USER_DS;
24564+ savesegment(gs, childregs->gs);
24565+ childregs->ds = __KERNEL_DS;
24566+ childregs->es = __KERNEL_DS;
24567 childregs->fs = __KERNEL_PERCPU;
24568 childregs->bx = sp; /* function */
24569 childregs->bp = arg;
24570@@ -253,7 +254,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24571 struct thread_struct *prev = &prev_p->thread,
24572 *next = &next_p->thread;
24573 int cpu = smp_processor_id();
24574- struct tss_struct *tss = &per_cpu(init_tss, cpu);
24575+ struct tss_struct *tss = init_tss + cpu;
24576 fpu_switch_t fpu;
24577
24578 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
24579@@ -277,6 +278,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24580 */
24581 lazy_save_gs(prev->gs);
24582
24583+#ifdef CONFIG_PAX_MEMORY_UDEREF
24584+ __set_fs(task_thread_info(next_p)->addr_limit);
24585+#endif
24586+
24587 /*
24588 * Load the per-thread Thread-Local Storage descriptor.
24589 */
24590@@ -307,6 +312,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24591 */
24592 arch_end_context_switch(next_p);
24593
24594+ this_cpu_write(current_task, next_p);
24595+ this_cpu_write(current_tinfo, &next_p->tinfo);
24596+
24597 /*
24598 * Restore %gs if needed (which is common)
24599 */
24600@@ -315,8 +323,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24601
24602 switch_fpu_finish(next_p, fpu);
24603
24604- this_cpu_write(current_task, next_p);
24605-
24606 return prev_p;
24607 }
24608
24609@@ -346,4 +352,3 @@ unsigned long get_wchan(struct task_struct *p)
24610 } while (count++ < 16);
24611 return 0;
24612 }
24613-
24614diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
24615index 05646ba..0c2906d 100644
24616--- a/arch/x86/kernel/process_64.c
24617+++ b/arch/x86/kernel/process_64.c
24618@@ -158,10 +158,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
24619 struct pt_regs *childregs;
24620 struct task_struct *me = current;
24621
24622- p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
24623+ p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
24624 childregs = task_pt_regs(p);
24625 p->thread.sp = (unsigned long) childregs;
24626 p->thread.usersp = me->thread.usersp;
24627+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
24628 set_tsk_thread_flag(p, TIF_FORK);
24629 p->fpu_counter = 0;
24630 p->thread.io_bitmap_ptr = NULL;
24631@@ -172,6 +173,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
24632 p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
24633 savesegment(es, p->thread.es);
24634 savesegment(ds, p->thread.ds);
24635+ savesegment(ss, p->thread.ss);
24636+ BUG_ON(p->thread.ss == __UDEREF_KERNEL_DS);
24637 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
24638
24639 if (unlikely(p->flags & PF_KTHREAD)) {
24640@@ -280,7 +283,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24641 struct thread_struct *prev = &prev_p->thread;
24642 struct thread_struct *next = &next_p->thread;
24643 int cpu = smp_processor_id();
24644- struct tss_struct *tss = &per_cpu(init_tss, cpu);
24645+ struct tss_struct *tss = init_tss + cpu;
24646 unsigned fsindex, gsindex;
24647 fpu_switch_t fpu;
24648
24649@@ -303,6 +306,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24650 if (unlikely(next->ds | prev->ds))
24651 loadsegment(ds, next->ds);
24652
24653+ savesegment(ss, prev->ss);
24654+ if (unlikely(next->ss != prev->ss))
24655+ loadsegment(ss, next->ss);
24656
24657 /* We must save %fs and %gs before load_TLS() because
24658 * %fs and %gs may be cleared by load_TLS().
24659@@ -362,10 +368,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24660 prev->usersp = this_cpu_read(old_rsp);
24661 this_cpu_write(old_rsp, next->usersp);
24662 this_cpu_write(current_task, next_p);
24663+ this_cpu_write(current_tinfo, &next_p->tinfo);
24664
24665- this_cpu_write(kernel_stack,
24666- (unsigned long)task_stack_page(next_p) +
24667- THREAD_SIZE - KERNEL_STACK_OFFSET);
24668+ this_cpu_write(kernel_stack, next->sp0);
24669
24670 /*
24671 * Now maybe reload the debug registers and handle I/O bitmaps
24672@@ -434,12 +439,11 @@ unsigned long get_wchan(struct task_struct *p)
24673 if (!p || p == current || p->state == TASK_RUNNING)
24674 return 0;
24675 stack = (unsigned long)task_stack_page(p);
24676- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
24677+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
24678 return 0;
24679 fp = *(u64 *)(p->thread.sp);
24680 do {
24681- if (fp < (unsigned long)stack ||
24682- fp >= (unsigned long)stack+THREAD_SIZE)
24683+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
24684 return 0;
24685 ip = *(u64 *)(fp+8);
24686 if (!in_sched_functions(ip))
24687diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
24688index 7461f50..1334029 100644
24689--- a/arch/x86/kernel/ptrace.c
24690+++ b/arch/x86/kernel/ptrace.c
24691@@ -184,14 +184,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
24692 {
24693 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
24694 unsigned long sp = (unsigned long)&regs->sp;
24695- struct thread_info *tinfo;
24696
24697- if (context == (sp & ~(THREAD_SIZE - 1)))
24698+ if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
24699 return sp;
24700
24701- tinfo = (struct thread_info *)context;
24702- if (tinfo->previous_esp)
24703- return tinfo->previous_esp;
24704+ sp = *(unsigned long *)context;
24705+ if (sp)
24706+ return sp;
24707
24708 return (unsigned long)regs;
24709 }
24710@@ -588,7 +587,7 @@ static void ptrace_triggered(struct perf_event *bp,
24711 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
24712 {
24713 int i;
24714- int dr7 = 0;
24715+ unsigned long dr7 = 0;
24716 struct arch_hw_breakpoint *info;
24717
24718 for (i = 0; i < HBP_NUM; i++) {
24719@@ -822,7 +821,7 @@ long arch_ptrace(struct task_struct *child, long request,
24720 unsigned long addr, unsigned long data)
24721 {
24722 int ret;
24723- unsigned long __user *datap = (unsigned long __user *)data;
24724+ unsigned long __user *datap = (__force unsigned long __user *)data;
24725
24726 switch (request) {
24727 /* read the word at location addr in the USER area. */
24728@@ -907,14 +906,14 @@ long arch_ptrace(struct task_struct *child, long request,
24729 if ((int) addr < 0)
24730 return -EIO;
24731 ret = do_get_thread_area(child, addr,
24732- (struct user_desc __user *)data);
24733+ (__force struct user_desc __user *) data);
24734 break;
24735
24736 case PTRACE_SET_THREAD_AREA:
24737 if ((int) addr < 0)
24738 return -EIO;
24739 ret = do_set_thread_area(child, addr,
24740- (struct user_desc __user *)data, 0);
24741+ (__force struct user_desc __user *) data, 0);
24742 break;
24743 #endif
24744
24745@@ -1292,7 +1291,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
24746
24747 #ifdef CONFIG_X86_64
24748
24749-static struct user_regset x86_64_regsets[] __read_mostly = {
24750+static user_regset_no_const x86_64_regsets[] __read_only = {
24751 [REGSET_GENERAL] = {
24752 .core_note_type = NT_PRSTATUS,
24753 .n = sizeof(struct user_regs_struct) / sizeof(long),
24754@@ -1333,7 +1332,7 @@ static const struct user_regset_view user_x86_64_view = {
24755 #endif /* CONFIG_X86_64 */
24756
24757 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
24758-static struct user_regset x86_32_regsets[] __read_mostly = {
24759+static user_regset_no_const x86_32_regsets[] __read_only = {
24760 [REGSET_GENERAL] = {
24761 .core_note_type = NT_PRSTATUS,
24762 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
24763@@ -1386,7 +1385,7 @@ static const struct user_regset_view user_x86_32_view = {
24764 */
24765 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
24766
24767-void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
24768+void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
24769 {
24770 #ifdef CONFIG_X86_64
24771 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
24772@@ -1421,7 +1420,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
24773 memset(info, 0, sizeof(*info));
24774 info->si_signo = SIGTRAP;
24775 info->si_code = si_code;
24776- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
24777+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
24778 }
24779
24780 void user_single_step_siginfo(struct task_struct *tsk,
24781@@ -1450,6 +1449,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
24782 # define IS_IA32 0
24783 #endif
24784
24785+#ifdef CONFIG_GRKERNSEC_SETXID
24786+extern void gr_delayed_cred_worker(void);
24787+#endif
24788+
24789 /*
24790 * We must return the syscall number to actually look up in the table.
24791 * This can be -1L to skip running any syscall at all.
24792@@ -1460,6 +1463,11 @@ long syscall_trace_enter(struct pt_regs *regs)
24793
24794 user_exit();
24795
24796+#ifdef CONFIG_GRKERNSEC_SETXID
24797+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
24798+ gr_delayed_cred_worker();
24799+#endif
24800+
24801 /*
24802 * If we stepped into a sysenter/syscall insn, it trapped in
24803 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
24804@@ -1515,6 +1523,11 @@ void syscall_trace_leave(struct pt_regs *regs)
24805 */
24806 user_exit();
24807
24808+#ifdef CONFIG_GRKERNSEC_SETXID
24809+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
24810+ gr_delayed_cred_worker();
24811+#endif
24812+
24813 audit_syscall_exit(regs);
24814
24815 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
24816diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
24817index 2cb9470..ff1fd80 100644
24818--- a/arch/x86/kernel/pvclock.c
24819+++ b/arch/x86/kernel/pvclock.c
24820@@ -43,11 +43,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
24821 return pv_tsc_khz;
24822 }
24823
24824-static atomic64_t last_value = ATOMIC64_INIT(0);
24825+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
24826
24827 void pvclock_resume(void)
24828 {
24829- atomic64_set(&last_value, 0);
24830+ atomic64_set_unchecked(&last_value, 0);
24831 }
24832
24833 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
24834@@ -92,11 +92,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
24835 * updating at the same time, and one of them could be slightly behind,
24836 * making the assumption that last_value always go forward fail to hold.
24837 */
24838- last = atomic64_read(&last_value);
24839+ last = atomic64_read_unchecked(&last_value);
24840 do {
24841 if (ret < last)
24842 return last;
24843- last = atomic64_cmpxchg(&last_value, last, ret);
24844+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
24845 } while (unlikely(last != ret));
24846
24847 return ret;
24848diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
24849index 563ed91..b9c3313 100644
24850--- a/arch/x86/kernel/reboot.c
24851+++ b/arch/x86/kernel/reboot.c
24852@@ -68,6 +68,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
24853
24854 void __noreturn machine_real_restart(unsigned int type)
24855 {
24856+
24857+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
24858+ struct desc_struct *gdt;
24859+#endif
24860+
24861 local_irq_disable();
24862
24863 /*
24864@@ -95,7 +100,29 @@ void __noreturn machine_real_restart(unsigned int type)
24865
24866 /* Jump to the identity-mapped low memory code */
24867 #ifdef CONFIG_X86_32
24868- asm volatile("jmpl *%0" : :
24869+
24870+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
24871+ gdt = get_cpu_gdt_table(smp_processor_id());
24872+ pax_open_kernel();
24873+#ifdef CONFIG_PAX_MEMORY_UDEREF
24874+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
24875+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
24876+ loadsegment(ds, __KERNEL_DS);
24877+ loadsegment(es, __KERNEL_DS);
24878+ loadsegment(ss, __KERNEL_DS);
24879+#endif
24880+#ifdef CONFIG_PAX_KERNEXEC
24881+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
24882+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
24883+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
24884+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
24885+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
24886+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
24887+#endif
24888+ pax_close_kernel();
24889+#endif
24890+
24891+ asm volatile("ljmpl *%0" : :
24892 "rm" (real_mode_header->machine_real_restart_asm),
24893 "a" (type));
24894 #else
24895@@ -442,7 +469,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
24896 * try to force a triple fault and then cycle between hitting the keyboard
24897 * controller and doing that
24898 */
24899-static void native_machine_emergency_restart(void)
24900+static void __noreturn native_machine_emergency_restart(void)
24901 {
24902 int i;
24903 int attempt = 0;
24904@@ -551,13 +578,13 @@ void native_machine_shutdown(void)
24905 #endif
24906 }
24907
24908-static void __machine_emergency_restart(int emergency)
24909+static void __noreturn __machine_emergency_restart(int emergency)
24910 {
24911 reboot_emergency = emergency;
24912 machine_ops.emergency_restart();
24913 }
24914
24915-static void native_machine_restart(char *__unused)
24916+static void __noreturn native_machine_restart(char *__unused)
24917 {
24918 pr_notice("machine restart\n");
24919
24920@@ -566,7 +593,7 @@ static void native_machine_restart(char *__unused)
24921 __machine_emergency_restart(0);
24922 }
24923
24924-static void native_machine_halt(void)
24925+static void __noreturn native_machine_halt(void)
24926 {
24927 /* Stop other cpus and apics */
24928 machine_shutdown();
24929@@ -576,7 +603,7 @@ static void native_machine_halt(void)
24930 stop_this_cpu(NULL);
24931 }
24932
24933-static void native_machine_power_off(void)
24934+static void __noreturn native_machine_power_off(void)
24935 {
24936 if (pm_power_off) {
24937 if (!reboot_force)
24938@@ -585,9 +612,10 @@ static void native_machine_power_off(void)
24939 }
24940 /* A fallback in case there is no PM info available */
24941 tboot_shutdown(TB_SHUTDOWN_HALT);
24942+ unreachable();
24943 }
24944
24945-struct machine_ops machine_ops = {
24946+struct machine_ops machine_ops __read_only = {
24947 .power_off = native_machine_power_off,
24948 .shutdown = native_machine_shutdown,
24949 .emergency_restart = native_machine_emergency_restart,
24950diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
24951index c8e41e9..64049ef 100644
24952--- a/arch/x86/kernel/reboot_fixups_32.c
24953+++ b/arch/x86/kernel/reboot_fixups_32.c
24954@@ -57,7 +57,7 @@ struct device_fixup {
24955 unsigned int vendor;
24956 unsigned int device;
24957 void (*reboot_fixup)(struct pci_dev *);
24958-};
24959+} __do_const;
24960
24961 /*
24962 * PCI ids solely used for fixups_table go here
24963diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
24964index 3fd2c69..16ef367 100644
24965--- a/arch/x86/kernel/relocate_kernel_64.S
24966+++ b/arch/x86/kernel/relocate_kernel_64.S
24967@@ -11,6 +11,7 @@
24968 #include <asm/kexec.h>
24969 #include <asm/processor-flags.h>
24970 #include <asm/pgtable_types.h>
24971+#include <asm/alternative-asm.h>
24972
24973 /*
24974 * Must be relocatable PIC code callable as a C function
24975@@ -96,8 +97,7 @@ relocate_kernel:
24976
24977 /* jump to identity mapped page */
24978 addq $(identity_mapped - relocate_kernel), %r8
24979- pushq %r8
24980- ret
24981+ jmp *%r8
24982
24983 identity_mapped:
24984 /* set return address to 0 if not preserving context */
24985@@ -167,6 +167,7 @@ identity_mapped:
24986 xorl %r14d, %r14d
24987 xorl %r15d, %r15d
24988
24989+ pax_force_retaddr 0, 1
24990 ret
24991
24992 1:
24993diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
24994index f8ec578..0cc110a 100644
24995--- a/arch/x86/kernel/setup.c
24996+++ b/arch/x86/kernel/setup.c
24997@@ -110,6 +110,7 @@
24998 #include <asm/mce.h>
24999 #include <asm/alternative.h>
25000 #include <asm/prom.h>
25001+#include <asm/boot.h>
25002
25003 /*
25004 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
25005@@ -205,12 +206,50 @@ EXPORT_SYMBOL(boot_cpu_data);
25006 #endif
25007
25008
25009-#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
25010-unsigned long mmu_cr4_features;
25011+#ifdef CONFIG_X86_64
25012+unsigned long mmu_cr4_features __read_only = X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE;
25013+#elif defined(CONFIG_X86_PAE)
25014+unsigned long mmu_cr4_features __read_only = X86_CR4_PAE;
25015 #else
25016-unsigned long mmu_cr4_features = X86_CR4_PAE;
25017+unsigned long mmu_cr4_features __read_only;
25018 #endif
25019
25020+void set_in_cr4(unsigned long mask)
25021+{
25022+ unsigned long cr4 = read_cr4();
25023+
25024+ if ((cr4 & mask) == mask && cr4 == mmu_cr4_features)
25025+ return;
25026+
25027+ pax_open_kernel();
25028+ mmu_cr4_features |= mask;
25029+ pax_close_kernel();
25030+
25031+ if (trampoline_cr4_features)
25032+ *trampoline_cr4_features = mmu_cr4_features;
25033+ cr4 |= mask;
25034+ write_cr4(cr4);
25035+}
25036+EXPORT_SYMBOL(set_in_cr4);
25037+
25038+void clear_in_cr4(unsigned long mask)
25039+{
25040+ unsigned long cr4 = read_cr4();
25041+
25042+ if (!(cr4 & mask) && cr4 == mmu_cr4_features)
25043+ return;
25044+
25045+ pax_open_kernel();
25046+ mmu_cr4_features &= ~mask;
25047+ pax_close_kernel();
25048+
25049+ if (trampoline_cr4_features)
25050+ *trampoline_cr4_features = mmu_cr4_features;
25051+ cr4 &= ~mask;
25052+ write_cr4(cr4);
25053+}
25054+EXPORT_SYMBOL(clear_in_cr4);
25055+
25056 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
25057 int bootloader_type, bootloader_version;
25058
25059@@ -444,7 +483,7 @@ static void __init parse_setup_data(void)
25060
25061 switch (data->type) {
25062 case SETUP_E820_EXT:
25063- parse_e820_ext(data);
25064+ parse_e820_ext((struct setup_data __force_kernel *)data);
25065 break;
25066 case SETUP_DTB:
25067 add_dtb(pa_data);
25068@@ -771,7 +810,7 @@ static void __init trim_bios_range(void)
25069 * area (640->1Mb) as ram even though it is not.
25070 * take them out.
25071 */
25072- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
25073+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
25074
25075 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
25076 }
25077@@ -779,7 +818,7 @@ static void __init trim_bios_range(void)
25078 /* called before trim_bios_range() to spare extra sanitize */
25079 static void __init e820_add_kernel_range(void)
25080 {
25081- u64 start = __pa_symbol(_text);
25082+ u64 start = __pa_symbol(ktla_ktva(_text));
25083 u64 size = __pa_symbol(_end) - start;
25084
25085 /*
25086@@ -841,8 +880,12 @@ static void __init trim_low_memory_range(void)
25087
25088 void __init setup_arch(char **cmdline_p)
25089 {
25090+#ifdef CONFIG_X86_32
25091+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
25092+#else
25093 memblock_reserve(__pa_symbol(_text),
25094 (unsigned long)__bss_stop - (unsigned long)_text);
25095+#endif
25096
25097 early_reserve_initrd();
25098
25099@@ -934,14 +977,14 @@ void __init setup_arch(char **cmdline_p)
25100
25101 if (!boot_params.hdr.root_flags)
25102 root_mountflags &= ~MS_RDONLY;
25103- init_mm.start_code = (unsigned long) _text;
25104- init_mm.end_code = (unsigned long) _etext;
25105+ init_mm.start_code = ktla_ktva((unsigned long) _text);
25106+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
25107 init_mm.end_data = (unsigned long) _edata;
25108 init_mm.brk = _brk_end;
25109
25110- code_resource.start = __pa_symbol(_text);
25111- code_resource.end = __pa_symbol(_etext)-1;
25112- data_resource.start = __pa_symbol(_etext);
25113+ code_resource.start = __pa_symbol(ktla_ktva(_text));
25114+ code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
25115+ data_resource.start = __pa_symbol(_sdata);
25116 data_resource.end = __pa_symbol(_edata)-1;
25117 bss_resource.start = __pa_symbol(__bss_start);
25118 bss_resource.end = __pa_symbol(__bss_stop)-1;
25119diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
25120index 5cdff03..80fa283 100644
25121--- a/arch/x86/kernel/setup_percpu.c
25122+++ b/arch/x86/kernel/setup_percpu.c
25123@@ -21,19 +21,17 @@
25124 #include <asm/cpu.h>
25125 #include <asm/stackprotector.h>
25126
25127-DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
25128+#ifdef CONFIG_SMP
25129+DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
25130 EXPORT_PER_CPU_SYMBOL(cpu_number);
25131+#endif
25132
25133-#ifdef CONFIG_X86_64
25134 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
25135-#else
25136-#define BOOT_PERCPU_OFFSET 0
25137-#endif
25138
25139 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
25140 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
25141
25142-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
25143+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
25144 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
25145 };
25146 EXPORT_SYMBOL(__per_cpu_offset);
25147@@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
25148 {
25149 #ifdef CONFIG_NEED_MULTIPLE_NODES
25150 pg_data_t *last = NULL;
25151- unsigned int cpu;
25152+ int cpu;
25153
25154 for_each_possible_cpu(cpu) {
25155 int node = early_cpu_to_node(cpu);
25156@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
25157 {
25158 #ifdef CONFIG_X86_32
25159 struct desc_struct gdt;
25160+ unsigned long base = per_cpu_offset(cpu);
25161
25162- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
25163- 0x2 | DESCTYPE_S, 0x8);
25164- gdt.s = 1;
25165+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
25166+ 0x83 | DESCTYPE_S, 0xC);
25167 write_gdt_entry(get_cpu_gdt_table(cpu),
25168 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
25169 #endif
25170@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
25171 /* alrighty, percpu areas up and running */
25172 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
25173 for_each_possible_cpu(cpu) {
25174+#ifdef CONFIG_CC_STACKPROTECTOR
25175+#ifdef CONFIG_X86_32
25176+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
25177+#endif
25178+#endif
25179 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
25180 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
25181 per_cpu(cpu_number, cpu) = cpu;
25182@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
25183 */
25184 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
25185 #endif
25186+#ifdef CONFIG_CC_STACKPROTECTOR
25187+#ifdef CONFIG_X86_32
25188+ if (!cpu)
25189+ per_cpu(stack_canary.canary, cpu) = canary;
25190+#endif
25191+#endif
25192 /*
25193 * Up to this point, the boot CPU has been using .init.data
25194 * area. Reload any changed state for the boot CPU.
25195diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
25196index cf91358..a7081ea 100644
25197--- a/arch/x86/kernel/signal.c
25198+++ b/arch/x86/kernel/signal.c
25199@@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
25200 * Align the stack pointer according to the i386 ABI,
25201 * i.e. so that on function entry ((sp + 4) & 15) == 0.
25202 */
25203- sp = ((sp + 4) & -16ul) - 4;
25204+ sp = ((sp - 12) & -16ul) - 4;
25205 #else /* !CONFIG_X86_32 */
25206 sp = round_down(sp, 16) - 8;
25207 #endif
25208@@ -298,9 +298,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
25209 }
25210
25211 if (current->mm->context.vdso)
25212- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
25213+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
25214 else
25215- restorer = &frame->retcode;
25216+ restorer = (void __user *)&frame->retcode;
25217 if (ksig->ka.sa.sa_flags & SA_RESTORER)
25218 restorer = ksig->ka.sa.sa_restorer;
25219
25220@@ -314,7 +314,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
25221 * reasons and because gdb uses it as a signature to notice
25222 * signal handler stack frames.
25223 */
25224- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
25225+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
25226
25227 if (err)
25228 return -EFAULT;
25229@@ -358,10 +358,13 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
25230 else
25231 put_user_ex(0, &frame->uc.uc_flags);
25232 put_user_ex(0, &frame->uc.uc_link);
25233- err |= __save_altstack(&frame->uc.uc_stack, regs->sp);
25234+ __save_altstack_ex(&frame->uc.uc_stack, regs->sp);
25235
25236 /* Set up to return from userspace. */
25237- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
25238+ if (current->mm->context.vdso)
25239+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
25240+ else
25241+ restorer = (void __user *)&frame->retcode;
25242 if (ksig->ka.sa.sa_flags & SA_RESTORER)
25243 restorer = ksig->ka.sa.sa_restorer;
25244 put_user_ex(restorer, &frame->pretcode);
25245@@ -373,7 +376,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
25246 * reasons and because gdb uses it as a signature to notice
25247 * signal handler stack frames.
25248 */
25249- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
25250+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
25251 } put_user_catch(err);
25252
25253 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
25254@@ -423,7 +426,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
25255 else
25256 put_user_ex(0, &frame->uc.uc_flags);
25257 put_user_ex(0, &frame->uc.uc_link);
25258- err |= __save_altstack(&frame->uc.uc_stack, regs->sp);
25259+ __save_altstack_ex(&frame->uc.uc_stack, regs->sp);
25260
25261 /* Set up to return from userspace. If provided, use a stub
25262 already in userspace. */
25263@@ -609,7 +612,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
25264 {
25265 int usig = signr_convert(ksig->sig);
25266 sigset_t *set = sigmask_to_save();
25267- compat_sigset_t *cset = (compat_sigset_t *) set;
25268+ sigset_t sigcopy;
25269+ compat_sigset_t *cset;
25270+
25271+ sigcopy = *set;
25272+
25273+ cset = (compat_sigset_t *) &sigcopy;
25274
25275 /* Set up the stack frame */
25276 if (is_ia32_frame()) {
25277@@ -620,7 +628,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
25278 } else if (is_x32_frame()) {
25279 return x32_setup_rt_frame(ksig, cset, regs);
25280 } else {
25281- return __setup_rt_frame(ksig->sig, ksig, set, regs);
25282+ return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
25283 }
25284 }
25285
25286diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
25287index cdaa347..f5af55d 100644
25288--- a/arch/x86/kernel/smp.c
25289+++ b/arch/x86/kernel/smp.c
25290@@ -341,7 +341,7 @@ static int __init nonmi_ipi_setup(char *str)
25291
25292 __setup("nonmi_ipi", nonmi_ipi_setup);
25293
25294-struct smp_ops smp_ops = {
25295+struct smp_ops smp_ops __read_only = {
25296 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
25297 .smp_prepare_cpus = native_smp_prepare_cpus,
25298 .smp_cpus_done = native_smp_cpus_done,
25299diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
25300index aecc98a..0244a53 100644
25301--- a/arch/x86/kernel/smpboot.c
25302+++ b/arch/x86/kernel/smpboot.c
25303@@ -251,14 +251,18 @@ static void notrace start_secondary(void *unused)
25304
25305 enable_start_cpu0 = 0;
25306
25307-#ifdef CONFIG_X86_32
25308- /* switch away from the initial page table */
25309- load_cr3(swapper_pg_dir);
25310- __flush_tlb_all();
25311-#endif
25312-
25313 /* otherwise gcc will move up smp_processor_id before the cpu_init */
25314 barrier();
25315+
25316+ /* switch away from the initial page table */
25317+#ifdef CONFIG_PAX_PER_CPU_PGD
25318+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
25319+ __flush_tlb_all();
25320+#elif defined(CONFIG_X86_32)
25321+ load_cr3(swapper_pg_dir);
25322+ __flush_tlb_all();
25323+#endif
25324+
25325 /*
25326 * Check TSC synchronization with the BP:
25327 */
25328@@ -748,6 +752,7 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
25329 idle->thread.sp = (unsigned long) (((struct pt_regs *)
25330 (THREAD_SIZE + task_stack_page(idle))) - 1);
25331 per_cpu(current_task, cpu) = idle;
25332+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
25333
25334 #ifdef CONFIG_X86_32
25335 /* Stack for startup_32 can be just as for start_secondary onwards */
25336@@ -755,11 +760,13 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
25337 #else
25338 clear_tsk_thread_flag(idle, TIF_FORK);
25339 initial_gs = per_cpu_offset(cpu);
25340- per_cpu(kernel_stack, cpu) =
25341- (unsigned long)task_stack_page(idle) -
25342- KERNEL_STACK_OFFSET + THREAD_SIZE;
25343+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
25344 #endif
25345+
25346+ pax_open_kernel();
25347 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
25348+ pax_close_kernel();
25349+
25350 initial_code = (unsigned long)start_secondary;
25351 stack_start = idle->thread.sp;
25352
25353@@ -908,6 +915,15 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
25354 /* the FPU context is blank, nobody can own it */
25355 __cpu_disable_lazy_restore(cpu);
25356
25357+#ifdef CONFIG_PAX_PER_CPU_PGD
25358+ clone_pgd_range(get_cpu_pgd(cpu, kernel) + KERNEL_PGD_BOUNDARY,
25359+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25360+ KERNEL_PGD_PTRS);
25361+ clone_pgd_range(get_cpu_pgd(cpu, user) + KERNEL_PGD_BOUNDARY,
25362+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25363+ KERNEL_PGD_PTRS);
25364+#endif
25365+
25366 err = do_boot_cpu(apicid, cpu, tidle);
25367 if (err) {
25368 pr_debug("do_boot_cpu failed %d\n", err);
25369diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
25370index 9b4d51d..5d28b58 100644
25371--- a/arch/x86/kernel/step.c
25372+++ b/arch/x86/kernel/step.c
25373@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
25374 struct desc_struct *desc;
25375 unsigned long base;
25376
25377- seg &= ~7UL;
25378+ seg >>= 3;
25379
25380 mutex_lock(&child->mm->context.lock);
25381- if (unlikely((seg >> 3) >= child->mm->context.size))
25382+ if (unlikely(seg >= child->mm->context.size))
25383 addr = -1L; /* bogus selector, access would fault */
25384 else {
25385 desc = child->mm->context.ldt + seg;
25386@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
25387 addr += base;
25388 }
25389 mutex_unlock(&child->mm->context.lock);
25390- }
25391+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
25392+ addr = ktla_ktva(addr);
25393
25394 return addr;
25395 }
25396@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
25397 unsigned char opcode[15];
25398 unsigned long addr = convert_ip_to_linear(child, regs);
25399
25400+ if (addr == -EINVAL)
25401+ return 0;
25402+
25403 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
25404 for (i = 0; i < copied; i++) {
25405 switch (opcode[i]) {
25406diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
25407new file mode 100644
25408index 0000000..5877189
25409--- /dev/null
25410+++ b/arch/x86/kernel/sys_i386_32.c
25411@@ -0,0 +1,189 @@
25412+/*
25413+ * This file contains various random system calls that
25414+ * have a non-standard calling sequence on the Linux/i386
25415+ * platform.
25416+ */
25417+
25418+#include <linux/errno.h>
25419+#include <linux/sched.h>
25420+#include <linux/mm.h>
25421+#include <linux/fs.h>
25422+#include <linux/smp.h>
25423+#include <linux/sem.h>
25424+#include <linux/msg.h>
25425+#include <linux/shm.h>
25426+#include <linux/stat.h>
25427+#include <linux/syscalls.h>
25428+#include <linux/mman.h>
25429+#include <linux/file.h>
25430+#include <linux/utsname.h>
25431+#include <linux/ipc.h>
25432+#include <linux/elf.h>
25433+
25434+#include <linux/uaccess.h>
25435+#include <linux/unistd.h>
25436+
25437+#include <asm/syscalls.h>
25438+
25439+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
25440+{
25441+ unsigned long pax_task_size = TASK_SIZE;
25442+
25443+#ifdef CONFIG_PAX_SEGMEXEC
25444+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
25445+ pax_task_size = SEGMEXEC_TASK_SIZE;
25446+#endif
25447+
25448+ if (flags & MAP_FIXED)
25449+ if (len > pax_task_size || addr > pax_task_size - len)
25450+ return -EINVAL;
25451+
25452+ return 0;
25453+}
25454+
25455+/*
25456+ * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
25457+ */
25458+static unsigned long get_align_mask(void)
25459+{
25460+ if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
25461+ return 0;
25462+
25463+ if (!(current->flags & PF_RANDOMIZE))
25464+ return 0;
25465+
25466+ return va_align.mask;
25467+}
25468+
25469+unsigned long
25470+arch_get_unmapped_area(struct file *filp, unsigned long addr,
25471+ unsigned long len, unsigned long pgoff, unsigned long flags)
25472+{
25473+ struct mm_struct *mm = current->mm;
25474+ struct vm_area_struct *vma;
25475+ unsigned long pax_task_size = TASK_SIZE;
25476+ struct vm_unmapped_area_info info;
25477+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
25478+
25479+#ifdef CONFIG_PAX_SEGMEXEC
25480+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
25481+ pax_task_size = SEGMEXEC_TASK_SIZE;
25482+#endif
25483+
25484+ pax_task_size -= PAGE_SIZE;
25485+
25486+ if (len > pax_task_size)
25487+ return -ENOMEM;
25488+
25489+ if (flags & MAP_FIXED)
25490+ return addr;
25491+
25492+#ifdef CONFIG_PAX_RANDMMAP
25493+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
25494+#endif
25495+
25496+ if (addr) {
25497+ addr = PAGE_ALIGN(addr);
25498+ if (pax_task_size - len >= addr) {
25499+ vma = find_vma(mm, addr);
25500+ if (check_heap_stack_gap(vma, addr, len, offset))
25501+ return addr;
25502+ }
25503+ }
25504+
25505+ info.flags = 0;
25506+ info.length = len;
25507+ info.align_mask = filp ? get_align_mask() : 0;
25508+ info.align_offset = pgoff << PAGE_SHIFT;
25509+ info.threadstack_offset = offset;
25510+
25511+#ifdef CONFIG_PAX_PAGEEXEC
25512+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
25513+ info.low_limit = 0x00110000UL;
25514+ info.high_limit = mm->start_code;
25515+
25516+#ifdef CONFIG_PAX_RANDMMAP
25517+ if (mm->pax_flags & MF_PAX_RANDMMAP)
25518+ info.low_limit += mm->delta_mmap & 0x03FFF000UL;
25519+#endif
25520+
25521+ if (info.low_limit < info.high_limit) {
25522+ addr = vm_unmapped_area(&info);
25523+ if (!IS_ERR_VALUE(addr))
25524+ return addr;
25525+ }
25526+ } else
25527+#endif
25528+
25529+ info.low_limit = mm->mmap_base;
25530+ info.high_limit = pax_task_size;
25531+
25532+ return vm_unmapped_area(&info);
25533+}
25534+
25535+unsigned long
25536+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
25537+ const unsigned long len, const unsigned long pgoff,
25538+ const unsigned long flags)
25539+{
25540+ struct vm_area_struct *vma;
25541+ struct mm_struct *mm = current->mm;
25542+ unsigned long addr = addr0, pax_task_size = TASK_SIZE;
25543+ struct vm_unmapped_area_info info;
25544+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
25545+
25546+#ifdef CONFIG_PAX_SEGMEXEC
25547+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
25548+ pax_task_size = SEGMEXEC_TASK_SIZE;
25549+#endif
25550+
25551+ pax_task_size -= PAGE_SIZE;
25552+
25553+ /* requested length too big for entire address space */
25554+ if (len > pax_task_size)
25555+ return -ENOMEM;
25556+
25557+ if (flags & MAP_FIXED)
25558+ return addr;
25559+
25560+#ifdef CONFIG_PAX_PAGEEXEC
25561+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
25562+ goto bottomup;
25563+#endif
25564+
25565+#ifdef CONFIG_PAX_RANDMMAP
25566+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
25567+#endif
25568+
25569+ /* requesting a specific address */
25570+ if (addr) {
25571+ addr = PAGE_ALIGN(addr);
25572+ if (pax_task_size - len >= addr) {
25573+ vma = find_vma(mm, addr);
25574+ if (check_heap_stack_gap(vma, addr, len, offset))
25575+ return addr;
25576+ }
25577+ }
25578+
25579+ info.flags = VM_UNMAPPED_AREA_TOPDOWN;
25580+ info.length = len;
25581+ info.low_limit = PAGE_SIZE;
25582+ info.high_limit = mm->mmap_base;
25583+ info.align_mask = filp ? get_align_mask() : 0;
25584+ info.align_offset = pgoff << PAGE_SHIFT;
25585+ info.threadstack_offset = offset;
25586+
25587+ addr = vm_unmapped_area(&info);
25588+ if (!(addr & ~PAGE_MASK))
25589+ return addr;
25590+ VM_BUG_ON(addr != -ENOMEM);
25591+
25592+bottomup:
25593+ /*
25594+ * A failed mmap() very likely causes application failure,
25595+ * so fall back to the bottom-up function here. This scenario
25596+ * can happen with large stack limits and large mmap()
25597+ * allocations.
25598+ */
25599+ return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
25600+}
25601diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
25602index 30277e2..5664a29 100644
25603--- a/arch/x86/kernel/sys_x86_64.c
25604+++ b/arch/x86/kernel/sys_x86_64.c
25605@@ -81,8 +81,8 @@ out:
25606 return error;
25607 }
25608
25609-static void find_start_end(unsigned long flags, unsigned long *begin,
25610- unsigned long *end)
25611+static void find_start_end(struct mm_struct *mm, unsigned long flags,
25612+ unsigned long *begin, unsigned long *end)
25613 {
25614 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
25615 unsigned long new_begin;
25616@@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
25617 *begin = new_begin;
25618 }
25619 } else {
25620- *begin = current->mm->mmap_legacy_base;
25621+ *begin = mm->mmap_legacy_base;
25622 *end = TASK_SIZE;
25623 }
25624 }
25625@@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
25626 struct vm_area_struct *vma;
25627 struct vm_unmapped_area_info info;
25628 unsigned long begin, end;
25629+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
25630
25631 if (flags & MAP_FIXED)
25632 return addr;
25633
25634- find_start_end(flags, &begin, &end);
25635+ find_start_end(mm, flags, &begin, &end);
25636
25637 if (len > end)
25638 return -ENOMEM;
25639
25640+#ifdef CONFIG_PAX_RANDMMAP
25641+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
25642+#endif
25643+
25644 if (addr) {
25645 addr = PAGE_ALIGN(addr);
25646 vma = find_vma(mm, addr);
25647- if (end - len >= addr &&
25648- (!vma || addr + len <= vma->vm_start))
25649+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
25650 return addr;
25651 }
25652
25653@@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
25654 info.high_limit = end;
25655 info.align_mask = filp ? get_align_mask() : 0;
25656 info.align_offset = pgoff << PAGE_SHIFT;
25657+ info.threadstack_offset = offset;
25658 return vm_unmapped_area(&info);
25659 }
25660
25661@@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
25662 struct mm_struct *mm = current->mm;
25663 unsigned long addr = addr0;
25664 struct vm_unmapped_area_info info;
25665+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
25666
25667 /* requested length too big for entire address space */
25668 if (len > TASK_SIZE)
25669@@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
25670 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
25671 goto bottomup;
25672
25673+#ifdef CONFIG_PAX_RANDMMAP
25674+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
25675+#endif
25676+
25677 /* requesting a specific address */
25678 if (addr) {
25679 addr = PAGE_ALIGN(addr);
25680 vma = find_vma(mm, addr);
25681- if (TASK_SIZE - len >= addr &&
25682- (!vma || addr + len <= vma->vm_start))
25683+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
25684 return addr;
25685 }
25686
25687@@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
25688 info.high_limit = mm->mmap_base;
25689 info.align_mask = filp ? get_align_mask() : 0;
25690 info.align_offset = pgoff << PAGE_SHIFT;
25691+ info.threadstack_offset = offset;
25692 addr = vm_unmapped_area(&info);
25693 if (!(addr & ~PAGE_MASK))
25694 return addr;
25695diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
25696index addf7b5..f960685 100644
25697--- a/arch/x86/kernel/tboot.c
25698+++ b/arch/x86/kernel/tboot.c
25699@@ -221,7 +221,7 @@ static int tboot_setup_sleep(void)
25700
25701 void tboot_shutdown(u32 shutdown_type)
25702 {
25703- void (*shutdown)(void);
25704+ void (* __noreturn shutdown)(void);
25705
25706 if (!tboot_enabled())
25707 return;
25708@@ -243,7 +243,7 @@ void tboot_shutdown(u32 shutdown_type)
25709
25710 switch_to_tboot_pt();
25711
25712- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
25713+ shutdown = (void *)tboot->shutdown_entry;
25714 shutdown();
25715
25716 /* should not reach here */
25717@@ -301,7 +301,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
25718 return 0;
25719 }
25720
25721-static atomic_t ap_wfs_count;
25722+static atomic_unchecked_t ap_wfs_count;
25723
25724 static int tboot_wait_for_aps(int num_aps)
25725 {
25726@@ -325,9 +325,9 @@ static int tboot_cpu_callback(struct notifier_block *nfb, unsigned long action,
25727 {
25728 switch (action) {
25729 case CPU_DYING:
25730- atomic_inc(&ap_wfs_count);
25731+ atomic_inc_unchecked(&ap_wfs_count);
25732 if (num_online_cpus() == 1)
25733- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
25734+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
25735 return NOTIFY_BAD;
25736 break;
25737 }
25738@@ -413,7 +413,7 @@ static __init int tboot_late_init(void)
25739
25740 tboot_create_trampoline();
25741
25742- atomic_set(&ap_wfs_count, 0);
25743+ atomic_set_unchecked(&ap_wfs_count, 0);
25744 register_hotcpu_notifier(&tboot_cpu_notifier);
25745
25746 #ifdef CONFIG_DEBUG_FS
25747diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
25748index 24d3c91..d06b473 100644
25749--- a/arch/x86/kernel/time.c
25750+++ b/arch/x86/kernel/time.c
25751@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
25752 {
25753 unsigned long pc = instruction_pointer(regs);
25754
25755- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
25756+ if (!user_mode(regs) && in_lock_functions(pc)) {
25757 #ifdef CONFIG_FRAME_POINTER
25758- return *(unsigned long *)(regs->bp + sizeof(long));
25759+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
25760 #else
25761 unsigned long *sp =
25762 (unsigned long *)kernel_stack_pointer(regs);
25763@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
25764 * or above a saved flags. Eflags has bits 22-31 zero,
25765 * kernel addresses don't.
25766 */
25767+
25768+#ifdef CONFIG_PAX_KERNEXEC
25769+ return ktla_ktva(sp[0]);
25770+#else
25771 if (sp[0] >> 22)
25772 return sp[0];
25773 if (sp[1] >> 22)
25774 return sp[1];
25775 #endif
25776+
25777+#endif
25778 }
25779 return pc;
25780 }
25781diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
25782index f7fec09..9991981 100644
25783--- a/arch/x86/kernel/tls.c
25784+++ b/arch/x86/kernel/tls.c
25785@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
25786 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
25787 return -EINVAL;
25788
25789+#ifdef CONFIG_PAX_SEGMEXEC
25790+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
25791+ return -EINVAL;
25792+#endif
25793+
25794 set_tls_desc(p, idx, &info, 1);
25795
25796 return 0;
25797@@ -200,7 +205,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
25798
25799 if (kbuf)
25800 info = kbuf;
25801- else if (__copy_from_user(infobuf, ubuf, count))
25802+ else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
25803 return -EFAULT;
25804 else
25805 info = infobuf;
25806diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c
25807index 1c113db..287b42e 100644
25808--- a/arch/x86/kernel/tracepoint.c
25809+++ b/arch/x86/kernel/tracepoint.c
25810@@ -9,11 +9,11 @@
25811 #include <linux/atomic.h>
25812
25813 atomic_t trace_idt_ctr = ATOMIC_INIT(0);
25814-struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
25815+const struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
25816 (unsigned long) trace_idt_table };
25817
25818 /* No need to be aligned, but done to keep all IDTs defined the same way. */
25819-gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
25820+gate_desc trace_idt_table[NR_VECTORS] __page_aligned_rodata;
25821
25822 static int trace_irq_vector_refcount;
25823 static DEFINE_MUTEX(irq_vector_mutex);
25824diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
25825index 1b23a1c..910de0d 100644
25826--- a/arch/x86/kernel/traps.c
25827+++ b/arch/x86/kernel/traps.c
25828@@ -65,7 +65,7 @@
25829 #include <asm/proto.h>
25830
25831 /* No need to be aligned, but done to keep all IDTs defined the same way. */
25832-gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
25833+gate_desc debug_idt_table[NR_VECTORS] __page_aligned_rodata;
25834 #else
25835 #include <asm/processor-flags.h>
25836 #include <asm/setup.h>
25837@@ -74,7 +74,7 @@ asmlinkage int system_call(void);
25838 #endif
25839
25840 /* Must be page-aligned because the real IDT is used in a fixmap. */
25841-gate_desc idt_table[NR_VECTORS] __page_aligned_bss;
25842+gate_desc idt_table[NR_VECTORS] __page_aligned_rodata;
25843
25844 DECLARE_BITMAP(used_vectors, NR_VECTORS);
25845 EXPORT_SYMBOL_GPL(used_vectors);
25846@@ -106,11 +106,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
25847 }
25848
25849 static int __kprobes
25850-do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
25851+do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
25852 struct pt_regs *regs, long error_code)
25853 {
25854 #ifdef CONFIG_X86_32
25855- if (regs->flags & X86_VM_MASK) {
25856+ if (v8086_mode(regs)) {
25857 /*
25858 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
25859 * On nmi (interrupt 2), do_trap should not be called.
25860@@ -123,12 +123,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
25861 return -1;
25862 }
25863 #endif
25864- if (!user_mode(regs)) {
25865+ if (!user_mode_novm(regs)) {
25866 if (!fixup_exception(regs)) {
25867 tsk->thread.error_code = error_code;
25868 tsk->thread.trap_nr = trapnr;
25869+
25870+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25871+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
25872+ str = "PAX: suspicious stack segment fault";
25873+#endif
25874+
25875 die(str, regs, error_code);
25876 }
25877+
25878+#ifdef CONFIG_PAX_REFCOUNT
25879+ if (trapnr == 4)
25880+ pax_report_refcount_overflow(regs);
25881+#endif
25882+
25883 return 0;
25884 }
25885
25886@@ -136,7 +148,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
25887 }
25888
25889 static void __kprobes
25890-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
25891+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
25892 long error_code, siginfo_t *info)
25893 {
25894 struct task_struct *tsk = current;
25895@@ -160,7 +172,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
25896 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
25897 printk_ratelimit()) {
25898 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
25899- tsk->comm, tsk->pid, str,
25900+ tsk->comm, task_pid_nr(tsk), str,
25901 regs->ip, regs->sp, error_code);
25902 print_vma_addr(" in ", regs->ip);
25903 pr_cont("\n");
25904@@ -276,7 +288,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
25905 conditional_sti(regs);
25906
25907 #ifdef CONFIG_X86_32
25908- if (regs->flags & X86_VM_MASK) {
25909+ if (v8086_mode(regs)) {
25910 local_irq_enable();
25911 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
25912 goto exit;
25913@@ -284,18 +296,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
25914 #endif
25915
25916 tsk = current;
25917- if (!user_mode(regs)) {
25918+ if (!user_mode_novm(regs)) {
25919 if (fixup_exception(regs))
25920 goto exit;
25921
25922 tsk->thread.error_code = error_code;
25923 tsk->thread.trap_nr = X86_TRAP_GP;
25924 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
25925- X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
25926+ X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
25927+
25928+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25929+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
25930+ die("PAX: suspicious general protection fault", regs, error_code);
25931+ else
25932+#endif
25933+
25934 die("general protection fault", regs, error_code);
25935+ }
25936 goto exit;
25937 }
25938
25939+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
25940+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
25941+ struct mm_struct *mm = tsk->mm;
25942+ unsigned long limit;
25943+
25944+ down_write(&mm->mmap_sem);
25945+ limit = mm->context.user_cs_limit;
25946+ if (limit < TASK_SIZE) {
25947+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
25948+ up_write(&mm->mmap_sem);
25949+ return;
25950+ }
25951+ up_write(&mm->mmap_sem);
25952+ }
25953+#endif
25954+
25955 tsk->thread.error_code = error_code;
25956 tsk->thread.trap_nr = X86_TRAP_GP;
25957
25958@@ -453,7 +489,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
25959 /* It's safe to allow irq's after DR6 has been saved */
25960 preempt_conditional_sti(regs);
25961
25962- if (regs->flags & X86_VM_MASK) {
25963+ if (v8086_mode(regs)) {
25964 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
25965 X86_TRAP_DB);
25966 preempt_conditional_cli(regs);
25967@@ -468,7 +504,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
25968 * We already checked v86 mode above, so we can check for kernel mode
25969 * by just checking the CPL of CS.
25970 */
25971- if ((dr6 & DR_STEP) && !user_mode(regs)) {
25972+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
25973 tsk->thread.debugreg6 &= ~DR_STEP;
25974 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
25975 regs->flags &= ~X86_EFLAGS_TF;
25976@@ -500,7 +536,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
25977 return;
25978 conditional_sti(regs);
25979
25980- if (!user_mode_vm(regs))
25981+ if (!user_mode(regs))
25982 {
25983 if (!fixup_exception(regs)) {
25984 task->thread.error_code = error_code;
25985diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
25986index 2ed8459..7cf329f 100644
25987--- a/arch/x86/kernel/uprobes.c
25988+++ b/arch/x86/kernel/uprobes.c
25989@@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
25990 int ret = NOTIFY_DONE;
25991
25992 /* We are only interested in userspace traps */
25993- if (regs && !user_mode_vm(regs))
25994+ if (regs && !user_mode(regs))
25995 return NOTIFY_DONE;
25996
25997 switch (val) {
25998@@ -719,7 +719,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
25999
26000 if (ncopied != rasize) {
26001 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
26002- "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
26003+ "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
26004
26005 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
26006 }
26007diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
26008index b9242ba..50c5edd 100644
26009--- a/arch/x86/kernel/verify_cpu.S
26010+++ b/arch/x86/kernel/verify_cpu.S
26011@@ -20,6 +20,7 @@
26012 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
26013 * arch/x86/kernel/trampoline_64.S: secondary processor verification
26014 * arch/x86/kernel/head_32.S: processor startup
26015+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
26016 *
26017 * verify_cpu, returns the status of longmode and SSE in register %eax.
26018 * 0: Success 1: Failure
26019diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
26020index e8edcf5..27f9344 100644
26021--- a/arch/x86/kernel/vm86_32.c
26022+++ b/arch/x86/kernel/vm86_32.c
26023@@ -44,6 +44,7 @@
26024 #include <linux/ptrace.h>
26025 #include <linux/audit.h>
26026 #include <linux/stddef.h>
26027+#include <linux/grsecurity.h>
26028
26029 #include <asm/uaccess.h>
26030 #include <asm/io.h>
26031@@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
26032 do_exit(SIGSEGV);
26033 }
26034
26035- tss = &per_cpu(init_tss, get_cpu());
26036+ tss = init_tss + get_cpu();
26037 current->thread.sp0 = current->thread.saved_sp0;
26038 current->thread.sysenter_cs = __KERNEL_CS;
26039 load_sp0(tss, &current->thread);
26040@@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
26041
26042 if (tsk->thread.saved_sp0)
26043 return -EPERM;
26044+
26045+#ifdef CONFIG_GRKERNSEC_VM86
26046+ if (!capable(CAP_SYS_RAWIO)) {
26047+ gr_handle_vm86();
26048+ return -EPERM;
26049+ }
26050+#endif
26051+
26052 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
26053 offsetof(struct kernel_vm86_struct, vm86plus) -
26054 sizeof(info.regs));
26055@@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
26056 int tmp;
26057 struct vm86plus_struct __user *v86;
26058
26059+#ifdef CONFIG_GRKERNSEC_VM86
26060+ if (!capable(CAP_SYS_RAWIO)) {
26061+ gr_handle_vm86();
26062+ return -EPERM;
26063+ }
26064+#endif
26065+
26066 tsk = current;
26067 switch (cmd) {
26068 case VM86_REQUEST_IRQ:
26069@@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
26070 tsk->thread.saved_fs = info->regs32->fs;
26071 tsk->thread.saved_gs = get_user_gs(info->regs32);
26072
26073- tss = &per_cpu(init_tss, get_cpu());
26074+ tss = init_tss + get_cpu();
26075 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
26076 if (cpu_has_sep)
26077 tsk->thread.sysenter_cs = 0;
26078@@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
26079 goto cannot_handle;
26080 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
26081 goto cannot_handle;
26082- intr_ptr = (unsigned long __user *) (i << 2);
26083+ intr_ptr = (__force unsigned long __user *) (i << 2);
26084 if (get_user(segoffs, intr_ptr))
26085 goto cannot_handle;
26086 if ((segoffs >> 16) == BIOSSEG)
26087diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
26088index 10c4f30..65408b9 100644
26089--- a/arch/x86/kernel/vmlinux.lds.S
26090+++ b/arch/x86/kernel/vmlinux.lds.S
26091@@ -26,6 +26,13 @@
26092 #include <asm/page_types.h>
26093 #include <asm/cache.h>
26094 #include <asm/boot.h>
26095+#include <asm/segment.h>
26096+
26097+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26098+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
26099+#else
26100+#define __KERNEL_TEXT_OFFSET 0
26101+#endif
26102
26103 #undef i386 /* in case the preprocessor is a 32bit one */
26104
26105@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
26106
26107 PHDRS {
26108 text PT_LOAD FLAGS(5); /* R_E */
26109+#ifdef CONFIG_X86_32
26110+ module PT_LOAD FLAGS(5); /* R_E */
26111+#endif
26112+#ifdef CONFIG_XEN
26113+ rodata PT_LOAD FLAGS(5); /* R_E */
26114+#else
26115+ rodata PT_LOAD FLAGS(4); /* R__ */
26116+#endif
26117 data PT_LOAD FLAGS(6); /* RW_ */
26118-#ifdef CONFIG_X86_64
26119+ init.begin PT_LOAD FLAGS(6); /* RW_ */
26120 #ifdef CONFIG_SMP
26121 percpu PT_LOAD FLAGS(6); /* RW_ */
26122 #endif
26123+ text.init PT_LOAD FLAGS(5); /* R_E */
26124+ text.exit PT_LOAD FLAGS(5); /* R_E */
26125 init PT_LOAD FLAGS(7); /* RWE */
26126-#endif
26127 note PT_NOTE FLAGS(0); /* ___ */
26128 }
26129
26130 SECTIONS
26131 {
26132 #ifdef CONFIG_X86_32
26133- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
26134- phys_startup_32 = startup_32 - LOAD_OFFSET;
26135+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
26136 #else
26137- . = __START_KERNEL;
26138- phys_startup_64 = startup_64 - LOAD_OFFSET;
26139+ . = __START_KERNEL;
26140 #endif
26141
26142 /* Text and read-only data */
26143- .text : AT(ADDR(.text) - LOAD_OFFSET) {
26144- _text = .;
26145+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
26146 /* bootstrapping code */
26147+#ifdef CONFIG_X86_32
26148+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
26149+#else
26150+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
26151+#endif
26152+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
26153+ _text = .;
26154 HEAD_TEXT
26155 . = ALIGN(8);
26156 _stext = .;
26157@@ -104,13 +124,47 @@ SECTIONS
26158 IRQENTRY_TEXT
26159 *(.fixup)
26160 *(.gnu.warning)
26161- /* End of text section */
26162- _etext = .;
26163 } :text = 0x9090
26164
26165- NOTES :text :note
26166+ . += __KERNEL_TEXT_OFFSET;
26167
26168- EXCEPTION_TABLE(16) :text = 0x9090
26169+#ifdef CONFIG_X86_32
26170+ . = ALIGN(PAGE_SIZE);
26171+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
26172+
26173+#ifdef CONFIG_PAX_KERNEXEC
26174+ MODULES_EXEC_VADDR = .;
26175+ BYTE(0)
26176+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
26177+ . = ALIGN(HPAGE_SIZE) - 1;
26178+ MODULES_EXEC_END = .;
26179+#endif
26180+
26181+ } :module
26182+#endif
26183+
26184+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
26185+ /* End of text section */
26186+ BYTE(0)
26187+ _etext = . - __KERNEL_TEXT_OFFSET;
26188+ }
26189+
26190+#ifdef CONFIG_X86_32
26191+ . = ALIGN(PAGE_SIZE);
26192+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
26193+ . = ALIGN(PAGE_SIZE);
26194+ *(.empty_zero_page)
26195+ *(.initial_pg_fixmap)
26196+ *(.initial_pg_pmd)
26197+ *(.initial_page_table)
26198+ *(.swapper_pg_dir)
26199+ } :rodata
26200+#endif
26201+
26202+ . = ALIGN(PAGE_SIZE);
26203+ NOTES :rodata :note
26204+
26205+ EXCEPTION_TABLE(16) :rodata
26206
26207 #if defined(CONFIG_DEBUG_RODATA)
26208 /* .text should occupy whole number of pages */
26209@@ -122,16 +176,20 @@ SECTIONS
26210
26211 /* Data */
26212 .data : AT(ADDR(.data) - LOAD_OFFSET) {
26213+
26214+#ifdef CONFIG_PAX_KERNEXEC
26215+ . = ALIGN(HPAGE_SIZE);
26216+#else
26217+ . = ALIGN(PAGE_SIZE);
26218+#endif
26219+
26220 /* Start of data section */
26221 _sdata = .;
26222
26223 /* init_task */
26224 INIT_TASK_DATA(THREAD_SIZE)
26225
26226-#ifdef CONFIG_X86_32
26227- /* 32 bit has nosave before _edata */
26228 NOSAVE_DATA
26229-#endif
26230
26231 PAGE_ALIGNED_DATA(PAGE_SIZE)
26232
26233@@ -172,12 +230,19 @@ SECTIONS
26234 #endif /* CONFIG_X86_64 */
26235
26236 /* Init code and data - will be freed after init */
26237- . = ALIGN(PAGE_SIZE);
26238 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
26239+ BYTE(0)
26240+
26241+#ifdef CONFIG_PAX_KERNEXEC
26242+ . = ALIGN(HPAGE_SIZE);
26243+#else
26244+ . = ALIGN(PAGE_SIZE);
26245+#endif
26246+
26247 __init_begin = .; /* paired with __init_end */
26248- }
26249+ } :init.begin
26250
26251-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
26252+#ifdef CONFIG_SMP
26253 /*
26254 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
26255 * output PHDR, so the next output section - .init.text - should
26256@@ -186,12 +251,27 @@ SECTIONS
26257 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
26258 #endif
26259
26260- INIT_TEXT_SECTION(PAGE_SIZE)
26261-#ifdef CONFIG_X86_64
26262- :init
26263-#endif
26264+ . = ALIGN(PAGE_SIZE);
26265+ init_begin = .;
26266+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
26267+ VMLINUX_SYMBOL(_sinittext) = .;
26268+ INIT_TEXT
26269+ VMLINUX_SYMBOL(_einittext) = .;
26270+ . = ALIGN(PAGE_SIZE);
26271+ } :text.init
26272
26273- INIT_DATA_SECTION(16)
26274+ /*
26275+ * .exit.text is discard at runtime, not link time, to deal with
26276+ * references from .altinstructions and .eh_frame
26277+ */
26278+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
26279+ EXIT_TEXT
26280+ . = ALIGN(16);
26281+ } :text.exit
26282+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
26283+
26284+ . = ALIGN(PAGE_SIZE);
26285+ INIT_DATA_SECTION(16) :init
26286
26287 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
26288 __x86_cpu_dev_start = .;
26289@@ -253,19 +333,12 @@ SECTIONS
26290 }
26291
26292 . = ALIGN(8);
26293- /*
26294- * .exit.text is discard at runtime, not link time, to deal with
26295- * references from .altinstructions and .eh_frame
26296- */
26297- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
26298- EXIT_TEXT
26299- }
26300
26301 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
26302 EXIT_DATA
26303 }
26304
26305-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
26306+#ifndef CONFIG_SMP
26307 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
26308 #endif
26309
26310@@ -284,16 +357,10 @@ SECTIONS
26311 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
26312 __smp_locks = .;
26313 *(.smp_locks)
26314- . = ALIGN(PAGE_SIZE);
26315 __smp_locks_end = .;
26316+ . = ALIGN(PAGE_SIZE);
26317 }
26318
26319-#ifdef CONFIG_X86_64
26320- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
26321- NOSAVE_DATA
26322- }
26323-#endif
26324-
26325 /* BSS */
26326 . = ALIGN(PAGE_SIZE);
26327 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
26328@@ -309,6 +376,7 @@ SECTIONS
26329 __brk_base = .;
26330 . += 64 * 1024; /* 64k alignment slop space */
26331 *(.brk_reservation) /* areas brk users have reserved */
26332+ . = ALIGN(HPAGE_SIZE);
26333 __brk_limit = .;
26334 }
26335
26336@@ -335,13 +403,12 @@ SECTIONS
26337 * for the boot processor.
26338 */
26339 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
26340-INIT_PER_CPU(gdt_page);
26341 INIT_PER_CPU(irq_stack_union);
26342
26343 /*
26344 * Build-time check on the image size:
26345 */
26346-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
26347+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
26348 "kernel image bigger than KERNEL_IMAGE_SIZE");
26349
26350 #ifdef CONFIG_SMP
26351diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
26352index 1f96f93..d5c8f7a 100644
26353--- a/arch/x86/kernel/vsyscall_64.c
26354+++ b/arch/x86/kernel/vsyscall_64.c
26355@@ -56,15 +56,13 @@
26356 DEFINE_VVAR(int, vgetcpu_mode);
26357 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
26358
26359-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
26360+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
26361
26362 static int __init vsyscall_setup(char *str)
26363 {
26364 if (str) {
26365 if (!strcmp("emulate", str))
26366 vsyscall_mode = EMULATE;
26367- else if (!strcmp("native", str))
26368- vsyscall_mode = NATIVE;
26369 else if (!strcmp("none", str))
26370 vsyscall_mode = NONE;
26371 else
26372@@ -323,8 +321,7 @@ do_ret:
26373 return true;
26374
26375 sigsegv:
26376- force_sig(SIGSEGV, current);
26377- return true;
26378+ do_group_exit(SIGKILL);
26379 }
26380
26381 /*
26382@@ -377,10 +374,7 @@ void __init map_vsyscall(void)
26383 extern char __vvar_page;
26384 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
26385
26386- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
26387- vsyscall_mode == NATIVE
26388- ? PAGE_KERNEL_VSYSCALL
26389- : PAGE_KERNEL_VVAR);
26390+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
26391 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
26392 (unsigned long)VSYSCALL_START);
26393
26394diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
26395index b014d94..e775258 100644
26396--- a/arch/x86/kernel/x8664_ksyms_64.c
26397+++ b/arch/x86/kernel/x8664_ksyms_64.c
26398@@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
26399 EXPORT_SYMBOL(copy_user_generic_unrolled);
26400 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
26401 EXPORT_SYMBOL(__copy_user_nocache);
26402-EXPORT_SYMBOL(_copy_from_user);
26403-EXPORT_SYMBOL(_copy_to_user);
26404
26405 EXPORT_SYMBOL(copy_page);
26406 EXPORT_SYMBOL(clear_page);
26407@@ -66,3 +64,7 @@ EXPORT_SYMBOL(empty_zero_page);
26408 #ifndef CONFIG_PARAVIRT
26409 EXPORT_SYMBOL(native_load_gs_index);
26410 #endif
26411+
26412+#ifdef CONFIG_PAX_PER_CPU_PGD
26413+EXPORT_SYMBOL(cpu_pgd);
26414+#endif
26415diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
26416index 5f24c71..1dadf09 100644
26417--- a/arch/x86/kernel/x86_init.c
26418+++ b/arch/x86/kernel/x86_init.c
26419@@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit = {
26420 static void default_nmi_init(void) { };
26421 static int default_i8042_detect(void) { return 1; };
26422
26423-struct x86_platform_ops x86_platform = {
26424+struct x86_platform_ops x86_platform __read_only = {
26425 .calibrate_tsc = native_calibrate_tsc,
26426 .get_wallclock = mach_get_cmos_time,
26427 .set_wallclock = mach_set_rtc_mmss,
26428@@ -107,7 +107,7 @@ struct x86_platform_ops x86_platform = {
26429 };
26430
26431 EXPORT_SYMBOL_GPL(x86_platform);
26432-struct x86_msi_ops x86_msi = {
26433+struct x86_msi_ops x86_msi __read_only = {
26434 .setup_msi_irqs = native_setup_msi_irqs,
26435 .compose_msi_msg = native_compose_msi_msg,
26436 .teardown_msi_irq = native_teardown_msi_irq,
26437@@ -116,7 +116,7 @@ struct x86_msi_ops x86_msi = {
26438 .setup_hpet_msi = default_setup_hpet_msi,
26439 };
26440
26441-struct x86_io_apic_ops x86_io_apic_ops = {
26442+struct x86_io_apic_ops x86_io_apic_ops __read_only = {
26443 .init = native_io_apic_init_mappings,
26444 .read = native_io_apic_read,
26445 .write = native_io_apic_write,
26446diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
26447index 422fd82..c3687ca 100644
26448--- a/arch/x86/kernel/xsave.c
26449+++ b/arch/x86/kernel/xsave.c
26450@@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
26451 {
26452 int err;
26453
26454+ buf = (struct xsave_struct __user *)____m(buf);
26455 if (use_xsave())
26456 err = xsave_user(buf);
26457 else if (use_fxsr())
26458@@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
26459 */
26460 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
26461 {
26462+ buf = (void __user *)____m(buf);
26463 if (use_xsave()) {
26464 if ((unsigned long)buf % 64 || fx_only) {
26465 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
26466diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
26467index a20ecb5..d0e2194 100644
26468--- a/arch/x86/kvm/cpuid.c
26469+++ b/arch/x86/kvm/cpuid.c
26470@@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
26471 struct kvm_cpuid2 *cpuid,
26472 struct kvm_cpuid_entry2 __user *entries)
26473 {
26474- int r;
26475+ int r, i;
26476
26477 r = -E2BIG;
26478 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
26479 goto out;
26480 r = -EFAULT;
26481- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
26482- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
26483+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
26484 goto out;
26485+ for (i = 0; i < cpuid->nent; ++i) {
26486+ struct kvm_cpuid_entry2 cpuid_entry;
26487+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
26488+ goto out;
26489+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
26490+ }
26491 vcpu->arch.cpuid_nent = cpuid->nent;
26492 kvm_apic_set_version(vcpu);
26493 kvm_x86_ops->cpuid_update(vcpu);
26494@@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
26495 struct kvm_cpuid2 *cpuid,
26496 struct kvm_cpuid_entry2 __user *entries)
26497 {
26498- int r;
26499+ int r, i;
26500
26501 r = -E2BIG;
26502 if (cpuid->nent < vcpu->arch.cpuid_nent)
26503 goto out;
26504 r = -EFAULT;
26505- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
26506- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
26507+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
26508 goto out;
26509+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
26510+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
26511+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
26512+ goto out;
26513+ }
26514 return 0;
26515
26516 out:
26517diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
26518index afc1124..3e431f2 100644
26519--- a/arch/x86/kvm/lapic.c
26520+++ b/arch/x86/kvm/lapic.c
26521@@ -55,7 +55,7 @@
26522 #define APIC_BUS_CYCLE_NS 1
26523
26524 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
26525-#define apic_debug(fmt, arg...)
26526+#define apic_debug(fmt, arg...) do {} while (0)
26527
26528 #define APIC_LVT_NUM 6
26529 /* 14 is the version for Xeon and Pentium 8.4.8*/
26530diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
26531index 7769699..c8aca4a7f 100644
26532--- a/arch/x86/kvm/paging_tmpl.h
26533+++ b/arch/x86/kvm/paging_tmpl.h
26534@@ -208,7 +208,7 @@ retry_walk:
26535 if (unlikely(kvm_is_error_hva(host_addr)))
26536 goto error;
26537
26538- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
26539+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
26540 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
26541 goto error;
26542 walker->ptep_user[walker->level - 1] = ptep_user;
26543diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
26544index c0bc803..6837a50 100644
26545--- a/arch/x86/kvm/svm.c
26546+++ b/arch/x86/kvm/svm.c
26547@@ -3501,7 +3501,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
26548 int cpu = raw_smp_processor_id();
26549
26550 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
26551+
26552+ pax_open_kernel();
26553 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
26554+ pax_close_kernel();
26555+
26556 load_TR_desc();
26557 }
26558
26559@@ -3902,6 +3906,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
26560 #endif
26561 #endif
26562
26563+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
26564+ __set_fs(current_thread_info()->addr_limit);
26565+#endif
26566+
26567 reload_tss(vcpu);
26568
26569 local_irq_disable();
26570diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
26571index 064d0be..f5f758e 100644
26572--- a/arch/x86/kvm/vmx.c
26573+++ b/arch/x86/kvm/vmx.c
26574@@ -1311,12 +1311,12 @@ static void vmcs_write64(unsigned long field, u64 value)
26575 #endif
26576 }
26577
26578-static void vmcs_clear_bits(unsigned long field, u32 mask)
26579+static void vmcs_clear_bits(unsigned long field, unsigned long mask)
26580 {
26581 vmcs_writel(field, vmcs_readl(field) & ~mask);
26582 }
26583
26584-static void vmcs_set_bits(unsigned long field, u32 mask)
26585+static void vmcs_set_bits(unsigned long field, unsigned long mask)
26586 {
26587 vmcs_writel(field, vmcs_readl(field) | mask);
26588 }
26589@@ -1517,7 +1517,11 @@ static void reload_tss(void)
26590 struct desc_struct *descs;
26591
26592 descs = (void *)gdt->address;
26593+
26594+ pax_open_kernel();
26595 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
26596+ pax_close_kernel();
26597+
26598 load_TR_desc();
26599 }
26600
26601@@ -1741,6 +1745,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
26602 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
26603 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
26604
26605+#ifdef CONFIG_PAX_PER_CPU_PGD
26606+ vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
26607+#endif
26608+
26609 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
26610 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
26611 vmx->loaded_vmcs->cpu = cpu;
26612@@ -2940,8 +2948,11 @@ static __init int hardware_setup(void)
26613 if (!cpu_has_vmx_flexpriority())
26614 flexpriority_enabled = 0;
26615
26616- if (!cpu_has_vmx_tpr_shadow())
26617- kvm_x86_ops->update_cr8_intercept = NULL;
26618+ if (!cpu_has_vmx_tpr_shadow()) {
26619+ pax_open_kernel();
26620+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
26621+ pax_close_kernel();
26622+ }
26623
26624 if (enable_ept && !cpu_has_vmx_ept_2m_page())
26625 kvm_disable_largepages();
26626@@ -2952,13 +2963,15 @@ static __init int hardware_setup(void)
26627 if (!cpu_has_vmx_apicv())
26628 enable_apicv = 0;
26629
26630+ pax_open_kernel();
26631 if (enable_apicv)
26632- kvm_x86_ops->update_cr8_intercept = NULL;
26633+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
26634 else {
26635- kvm_x86_ops->hwapic_irr_update = NULL;
26636- kvm_x86_ops->deliver_posted_interrupt = NULL;
26637- kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
26638+ *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
26639+ *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
26640+ *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
26641 }
26642+ pax_close_kernel();
26643
26644 if (nested)
26645 nested_vmx_setup_ctls_msrs();
26646@@ -4081,7 +4094,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
26647
26648 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
26649 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
26650+
26651+#ifndef CONFIG_PAX_PER_CPU_PGD
26652 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
26653+#endif
26654
26655 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
26656 #ifdef CONFIG_X86_64
26657@@ -4103,7 +4119,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
26658 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
26659 vmx->host_idt_base = dt.address;
26660
26661- vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
26662+ vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
26663
26664 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
26665 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
26666@@ -7039,6 +7055,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
26667 "jmp 2f \n\t"
26668 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
26669 "2: "
26670+
26671+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26672+ "ljmp %[cs],$3f\n\t"
26673+ "3: "
26674+#endif
26675+
26676 /* Save guest registers, load host registers, keep flags */
26677 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
26678 "pop %0 \n\t"
26679@@ -7091,6 +7113,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
26680 #endif
26681 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
26682 [wordsize]"i"(sizeof(ulong))
26683+
26684+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26685+ ,[cs]"i"(__KERNEL_CS)
26686+#endif
26687+
26688 : "cc", "memory"
26689 #ifdef CONFIG_X86_64
26690 , "rax", "rbx", "rdi", "rsi"
26691@@ -7104,7 +7131,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
26692 if (debugctlmsr)
26693 update_debugctlmsr(debugctlmsr);
26694
26695-#ifndef CONFIG_X86_64
26696+#ifdef CONFIG_X86_32
26697 /*
26698 * The sysexit path does not restore ds/es, so we must set them to
26699 * a reasonable value ourselves.
26700@@ -7113,8 +7140,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
26701 * may be executed in interrupt context, which saves and restore segments
26702 * around it, nullifying its effect.
26703 */
26704- loadsegment(ds, __USER_DS);
26705- loadsegment(es, __USER_DS);
26706+ loadsegment(ds, __KERNEL_DS);
26707+ loadsegment(es, __KERNEL_DS);
26708+ loadsegment(ss, __KERNEL_DS);
26709+
26710+#ifdef CONFIG_PAX_KERNEXEC
26711+ loadsegment(fs, __KERNEL_PERCPU);
26712+#endif
26713+
26714+#ifdef CONFIG_PAX_MEMORY_UDEREF
26715+ __set_fs(current_thread_info()->addr_limit);
26716+#endif
26717+
26718 #endif
26719
26720 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
26721diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
26722index d21bce5..fdae9f1 100644
26723--- a/arch/x86/kvm/x86.c
26724+++ b/arch/x86/kvm/x86.c
26725@@ -1766,8 +1766,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
26726 {
26727 struct kvm *kvm = vcpu->kvm;
26728 int lm = is_long_mode(vcpu);
26729- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
26730- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
26731+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
26732+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
26733 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
26734 : kvm->arch.xen_hvm_config.blob_size_32;
26735 u32 page_num = data & ~PAGE_MASK;
26736@@ -2650,6 +2650,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
26737 if (n < msr_list.nmsrs)
26738 goto out;
26739 r = -EFAULT;
26740+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
26741+ goto out;
26742 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
26743 num_msrs_to_save * sizeof(u32)))
26744 goto out;
26745@@ -5344,7 +5346,7 @@ static struct notifier_block pvclock_gtod_notifier = {
26746 };
26747 #endif
26748
26749-int kvm_arch_init(void *opaque)
26750+int kvm_arch_init(const void *opaque)
26751 {
26752 int r;
26753 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
26754diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
26755index 6a22c19..1763f04 100644
26756--- a/arch/x86/lguest/boot.c
26757+++ b/arch/x86/lguest/boot.c
26758@@ -1201,9 +1201,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
26759 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
26760 * Launcher to reboot us.
26761 */
26762-static void lguest_restart(char *reason)
26763+static __noreturn void lguest_restart(char *reason)
26764 {
26765 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
26766+ BUG();
26767 }
26768
26769 /*G:050
26770diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
26771index 00933d5..3a64af9 100644
26772--- a/arch/x86/lib/atomic64_386_32.S
26773+++ b/arch/x86/lib/atomic64_386_32.S
26774@@ -48,6 +48,10 @@ BEGIN(read)
26775 movl (v), %eax
26776 movl 4(v), %edx
26777 RET_ENDP
26778+BEGIN(read_unchecked)
26779+ movl (v), %eax
26780+ movl 4(v), %edx
26781+RET_ENDP
26782 #undef v
26783
26784 #define v %esi
26785@@ -55,6 +59,10 @@ BEGIN(set)
26786 movl %ebx, (v)
26787 movl %ecx, 4(v)
26788 RET_ENDP
26789+BEGIN(set_unchecked)
26790+ movl %ebx, (v)
26791+ movl %ecx, 4(v)
26792+RET_ENDP
26793 #undef v
26794
26795 #define v %esi
26796@@ -70,6 +78,20 @@ RET_ENDP
26797 BEGIN(add)
26798 addl %eax, (v)
26799 adcl %edx, 4(v)
26800+
26801+#ifdef CONFIG_PAX_REFCOUNT
26802+ jno 0f
26803+ subl %eax, (v)
26804+ sbbl %edx, 4(v)
26805+ int $4
26806+0:
26807+ _ASM_EXTABLE(0b, 0b)
26808+#endif
26809+
26810+RET_ENDP
26811+BEGIN(add_unchecked)
26812+ addl %eax, (v)
26813+ adcl %edx, 4(v)
26814 RET_ENDP
26815 #undef v
26816
26817@@ -77,6 +99,24 @@ RET_ENDP
26818 BEGIN(add_return)
26819 addl (v), %eax
26820 adcl 4(v), %edx
26821+
26822+#ifdef CONFIG_PAX_REFCOUNT
26823+ into
26824+1234:
26825+ _ASM_EXTABLE(1234b, 2f)
26826+#endif
26827+
26828+ movl %eax, (v)
26829+ movl %edx, 4(v)
26830+
26831+#ifdef CONFIG_PAX_REFCOUNT
26832+2:
26833+#endif
26834+
26835+RET_ENDP
26836+BEGIN(add_return_unchecked)
26837+ addl (v), %eax
26838+ adcl 4(v), %edx
26839 movl %eax, (v)
26840 movl %edx, 4(v)
26841 RET_ENDP
26842@@ -86,6 +126,20 @@ RET_ENDP
26843 BEGIN(sub)
26844 subl %eax, (v)
26845 sbbl %edx, 4(v)
26846+
26847+#ifdef CONFIG_PAX_REFCOUNT
26848+ jno 0f
26849+ addl %eax, (v)
26850+ adcl %edx, 4(v)
26851+ int $4
26852+0:
26853+ _ASM_EXTABLE(0b, 0b)
26854+#endif
26855+
26856+RET_ENDP
26857+BEGIN(sub_unchecked)
26858+ subl %eax, (v)
26859+ sbbl %edx, 4(v)
26860 RET_ENDP
26861 #undef v
26862
26863@@ -96,6 +150,27 @@ BEGIN(sub_return)
26864 sbbl $0, %edx
26865 addl (v), %eax
26866 adcl 4(v), %edx
26867+
26868+#ifdef CONFIG_PAX_REFCOUNT
26869+ into
26870+1234:
26871+ _ASM_EXTABLE(1234b, 2f)
26872+#endif
26873+
26874+ movl %eax, (v)
26875+ movl %edx, 4(v)
26876+
26877+#ifdef CONFIG_PAX_REFCOUNT
26878+2:
26879+#endif
26880+
26881+RET_ENDP
26882+BEGIN(sub_return_unchecked)
26883+ negl %edx
26884+ negl %eax
26885+ sbbl $0, %edx
26886+ addl (v), %eax
26887+ adcl 4(v), %edx
26888 movl %eax, (v)
26889 movl %edx, 4(v)
26890 RET_ENDP
26891@@ -105,6 +180,20 @@ RET_ENDP
26892 BEGIN(inc)
26893 addl $1, (v)
26894 adcl $0, 4(v)
26895+
26896+#ifdef CONFIG_PAX_REFCOUNT
26897+ jno 0f
26898+ subl $1, (v)
26899+ sbbl $0, 4(v)
26900+ int $4
26901+0:
26902+ _ASM_EXTABLE(0b, 0b)
26903+#endif
26904+
26905+RET_ENDP
26906+BEGIN(inc_unchecked)
26907+ addl $1, (v)
26908+ adcl $0, 4(v)
26909 RET_ENDP
26910 #undef v
26911
26912@@ -114,6 +203,26 @@ BEGIN(inc_return)
26913 movl 4(v), %edx
26914 addl $1, %eax
26915 adcl $0, %edx
26916+
26917+#ifdef CONFIG_PAX_REFCOUNT
26918+ into
26919+1234:
26920+ _ASM_EXTABLE(1234b, 2f)
26921+#endif
26922+
26923+ movl %eax, (v)
26924+ movl %edx, 4(v)
26925+
26926+#ifdef CONFIG_PAX_REFCOUNT
26927+2:
26928+#endif
26929+
26930+RET_ENDP
26931+BEGIN(inc_return_unchecked)
26932+ movl (v), %eax
26933+ movl 4(v), %edx
26934+ addl $1, %eax
26935+ adcl $0, %edx
26936 movl %eax, (v)
26937 movl %edx, 4(v)
26938 RET_ENDP
26939@@ -123,6 +232,20 @@ RET_ENDP
26940 BEGIN(dec)
26941 subl $1, (v)
26942 sbbl $0, 4(v)
26943+
26944+#ifdef CONFIG_PAX_REFCOUNT
26945+ jno 0f
26946+ addl $1, (v)
26947+ adcl $0, 4(v)
26948+ int $4
26949+0:
26950+ _ASM_EXTABLE(0b, 0b)
26951+#endif
26952+
26953+RET_ENDP
26954+BEGIN(dec_unchecked)
26955+ subl $1, (v)
26956+ sbbl $0, 4(v)
26957 RET_ENDP
26958 #undef v
26959
26960@@ -132,6 +255,26 @@ BEGIN(dec_return)
26961 movl 4(v), %edx
26962 subl $1, %eax
26963 sbbl $0, %edx
26964+
26965+#ifdef CONFIG_PAX_REFCOUNT
26966+ into
26967+1234:
26968+ _ASM_EXTABLE(1234b, 2f)
26969+#endif
26970+
26971+ movl %eax, (v)
26972+ movl %edx, 4(v)
26973+
26974+#ifdef CONFIG_PAX_REFCOUNT
26975+2:
26976+#endif
26977+
26978+RET_ENDP
26979+BEGIN(dec_return_unchecked)
26980+ movl (v), %eax
26981+ movl 4(v), %edx
26982+ subl $1, %eax
26983+ sbbl $0, %edx
26984 movl %eax, (v)
26985 movl %edx, 4(v)
26986 RET_ENDP
26987@@ -143,6 +286,13 @@ BEGIN(add_unless)
26988 adcl %edx, %edi
26989 addl (v), %eax
26990 adcl 4(v), %edx
26991+
26992+#ifdef CONFIG_PAX_REFCOUNT
26993+ into
26994+1234:
26995+ _ASM_EXTABLE(1234b, 2f)
26996+#endif
26997+
26998 cmpl %eax, %ecx
26999 je 3f
27000 1:
27001@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
27002 1:
27003 addl $1, %eax
27004 adcl $0, %edx
27005+
27006+#ifdef CONFIG_PAX_REFCOUNT
27007+ into
27008+1234:
27009+ _ASM_EXTABLE(1234b, 2f)
27010+#endif
27011+
27012 movl %eax, (v)
27013 movl %edx, 4(v)
27014 movl $1, %eax
27015@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
27016 movl 4(v), %edx
27017 subl $1, %eax
27018 sbbl $0, %edx
27019+
27020+#ifdef CONFIG_PAX_REFCOUNT
27021+ into
27022+1234:
27023+ _ASM_EXTABLE(1234b, 1f)
27024+#endif
27025+
27026 js 1f
27027 movl %eax, (v)
27028 movl %edx, 4(v)
27029diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
27030index f5cc9eb..51fa319 100644
27031--- a/arch/x86/lib/atomic64_cx8_32.S
27032+++ b/arch/x86/lib/atomic64_cx8_32.S
27033@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
27034 CFI_STARTPROC
27035
27036 read64 %ecx
27037+ pax_force_retaddr
27038 ret
27039 CFI_ENDPROC
27040 ENDPROC(atomic64_read_cx8)
27041
27042+ENTRY(atomic64_read_unchecked_cx8)
27043+ CFI_STARTPROC
27044+
27045+ read64 %ecx
27046+ pax_force_retaddr
27047+ ret
27048+ CFI_ENDPROC
27049+ENDPROC(atomic64_read_unchecked_cx8)
27050+
27051 ENTRY(atomic64_set_cx8)
27052 CFI_STARTPROC
27053
27054@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
27055 cmpxchg8b (%esi)
27056 jne 1b
27057
27058+ pax_force_retaddr
27059 ret
27060 CFI_ENDPROC
27061 ENDPROC(atomic64_set_cx8)
27062
27063+ENTRY(atomic64_set_unchecked_cx8)
27064+ CFI_STARTPROC
27065+
27066+1:
27067+/* we don't need LOCK_PREFIX since aligned 64-bit writes
27068+ * are atomic on 586 and newer */
27069+ cmpxchg8b (%esi)
27070+ jne 1b
27071+
27072+ pax_force_retaddr
27073+ ret
27074+ CFI_ENDPROC
27075+ENDPROC(atomic64_set_unchecked_cx8)
27076+
27077 ENTRY(atomic64_xchg_cx8)
27078 CFI_STARTPROC
27079
27080@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
27081 cmpxchg8b (%esi)
27082 jne 1b
27083
27084+ pax_force_retaddr
27085 ret
27086 CFI_ENDPROC
27087 ENDPROC(atomic64_xchg_cx8)
27088
27089-.macro addsub_return func ins insc
27090-ENTRY(atomic64_\func\()_return_cx8)
27091+.macro addsub_return func ins insc unchecked=""
27092+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
27093 CFI_STARTPROC
27094 SAVE ebp
27095 SAVE ebx
27096@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
27097 movl %edx, %ecx
27098 \ins\()l %esi, %ebx
27099 \insc\()l %edi, %ecx
27100+
27101+.ifb \unchecked
27102+#ifdef CONFIG_PAX_REFCOUNT
27103+ into
27104+2:
27105+ _ASM_EXTABLE(2b, 3f)
27106+#endif
27107+.endif
27108+
27109 LOCK_PREFIX
27110 cmpxchg8b (%ebp)
27111 jne 1b
27112-
27113-10:
27114 movl %ebx, %eax
27115 movl %ecx, %edx
27116+
27117+.ifb \unchecked
27118+#ifdef CONFIG_PAX_REFCOUNT
27119+3:
27120+#endif
27121+.endif
27122+
27123 RESTORE edi
27124 RESTORE esi
27125 RESTORE ebx
27126 RESTORE ebp
27127+ pax_force_retaddr
27128 ret
27129 CFI_ENDPROC
27130-ENDPROC(atomic64_\func\()_return_cx8)
27131+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
27132 .endm
27133
27134 addsub_return add add adc
27135 addsub_return sub sub sbb
27136+addsub_return add add adc _unchecked
27137+addsub_return sub sub sbb _unchecked
27138
27139-.macro incdec_return func ins insc
27140-ENTRY(atomic64_\func\()_return_cx8)
27141+.macro incdec_return func ins insc unchecked=""
27142+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
27143 CFI_STARTPROC
27144 SAVE ebx
27145
27146@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
27147 movl %edx, %ecx
27148 \ins\()l $1, %ebx
27149 \insc\()l $0, %ecx
27150+
27151+.ifb \unchecked
27152+#ifdef CONFIG_PAX_REFCOUNT
27153+ into
27154+2:
27155+ _ASM_EXTABLE(2b, 3f)
27156+#endif
27157+.endif
27158+
27159 LOCK_PREFIX
27160 cmpxchg8b (%esi)
27161 jne 1b
27162
27163-10:
27164 movl %ebx, %eax
27165 movl %ecx, %edx
27166+
27167+.ifb \unchecked
27168+#ifdef CONFIG_PAX_REFCOUNT
27169+3:
27170+#endif
27171+.endif
27172+
27173 RESTORE ebx
27174+ pax_force_retaddr
27175 ret
27176 CFI_ENDPROC
27177-ENDPROC(atomic64_\func\()_return_cx8)
27178+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
27179 .endm
27180
27181 incdec_return inc add adc
27182 incdec_return dec sub sbb
27183+incdec_return inc add adc _unchecked
27184+incdec_return dec sub sbb _unchecked
27185
27186 ENTRY(atomic64_dec_if_positive_cx8)
27187 CFI_STARTPROC
27188@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
27189 movl %edx, %ecx
27190 subl $1, %ebx
27191 sbb $0, %ecx
27192+
27193+#ifdef CONFIG_PAX_REFCOUNT
27194+ into
27195+1234:
27196+ _ASM_EXTABLE(1234b, 2f)
27197+#endif
27198+
27199 js 2f
27200 LOCK_PREFIX
27201 cmpxchg8b (%esi)
27202@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
27203 movl %ebx, %eax
27204 movl %ecx, %edx
27205 RESTORE ebx
27206+ pax_force_retaddr
27207 ret
27208 CFI_ENDPROC
27209 ENDPROC(atomic64_dec_if_positive_cx8)
27210@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
27211 movl %edx, %ecx
27212 addl %ebp, %ebx
27213 adcl %edi, %ecx
27214+
27215+#ifdef CONFIG_PAX_REFCOUNT
27216+ into
27217+1234:
27218+ _ASM_EXTABLE(1234b, 3f)
27219+#endif
27220+
27221 LOCK_PREFIX
27222 cmpxchg8b (%esi)
27223 jne 1b
27224@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
27225 CFI_ADJUST_CFA_OFFSET -8
27226 RESTORE ebx
27227 RESTORE ebp
27228+ pax_force_retaddr
27229 ret
27230 4:
27231 cmpl %edx, 4(%esp)
27232@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
27233 xorl %ecx, %ecx
27234 addl $1, %ebx
27235 adcl %edx, %ecx
27236+
27237+#ifdef CONFIG_PAX_REFCOUNT
27238+ into
27239+1234:
27240+ _ASM_EXTABLE(1234b, 3f)
27241+#endif
27242+
27243 LOCK_PREFIX
27244 cmpxchg8b (%esi)
27245 jne 1b
27246@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
27247 movl $1, %eax
27248 3:
27249 RESTORE ebx
27250+ pax_force_retaddr
27251 ret
27252 CFI_ENDPROC
27253 ENDPROC(atomic64_inc_not_zero_cx8)
27254diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
27255index e78b8ee..7e173a8 100644
27256--- a/arch/x86/lib/checksum_32.S
27257+++ b/arch/x86/lib/checksum_32.S
27258@@ -29,7 +29,8 @@
27259 #include <asm/dwarf2.h>
27260 #include <asm/errno.h>
27261 #include <asm/asm.h>
27262-
27263+#include <asm/segment.h>
27264+
27265 /*
27266 * computes a partial checksum, e.g. for TCP/UDP fragments
27267 */
27268@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
27269
27270 #define ARGBASE 16
27271 #define FP 12
27272-
27273-ENTRY(csum_partial_copy_generic)
27274+
27275+ENTRY(csum_partial_copy_generic_to_user)
27276 CFI_STARTPROC
27277+
27278+#ifdef CONFIG_PAX_MEMORY_UDEREF
27279+ pushl_cfi %gs
27280+ popl_cfi %es
27281+ jmp csum_partial_copy_generic
27282+#endif
27283+
27284+ENTRY(csum_partial_copy_generic_from_user)
27285+
27286+#ifdef CONFIG_PAX_MEMORY_UDEREF
27287+ pushl_cfi %gs
27288+ popl_cfi %ds
27289+#endif
27290+
27291+ENTRY(csum_partial_copy_generic)
27292 subl $4,%esp
27293 CFI_ADJUST_CFA_OFFSET 4
27294 pushl_cfi %edi
27295@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
27296 jmp 4f
27297 SRC(1: movw (%esi), %bx )
27298 addl $2, %esi
27299-DST( movw %bx, (%edi) )
27300+DST( movw %bx, %es:(%edi) )
27301 addl $2, %edi
27302 addw %bx, %ax
27303 adcl $0, %eax
27304@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
27305 SRC(1: movl (%esi), %ebx )
27306 SRC( movl 4(%esi), %edx )
27307 adcl %ebx, %eax
27308-DST( movl %ebx, (%edi) )
27309+DST( movl %ebx, %es:(%edi) )
27310 adcl %edx, %eax
27311-DST( movl %edx, 4(%edi) )
27312+DST( movl %edx, %es:4(%edi) )
27313
27314 SRC( movl 8(%esi), %ebx )
27315 SRC( movl 12(%esi), %edx )
27316 adcl %ebx, %eax
27317-DST( movl %ebx, 8(%edi) )
27318+DST( movl %ebx, %es:8(%edi) )
27319 adcl %edx, %eax
27320-DST( movl %edx, 12(%edi) )
27321+DST( movl %edx, %es:12(%edi) )
27322
27323 SRC( movl 16(%esi), %ebx )
27324 SRC( movl 20(%esi), %edx )
27325 adcl %ebx, %eax
27326-DST( movl %ebx, 16(%edi) )
27327+DST( movl %ebx, %es:16(%edi) )
27328 adcl %edx, %eax
27329-DST( movl %edx, 20(%edi) )
27330+DST( movl %edx, %es:20(%edi) )
27331
27332 SRC( movl 24(%esi), %ebx )
27333 SRC( movl 28(%esi), %edx )
27334 adcl %ebx, %eax
27335-DST( movl %ebx, 24(%edi) )
27336+DST( movl %ebx, %es:24(%edi) )
27337 adcl %edx, %eax
27338-DST( movl %edx, 28(%edi) )
27339+DST( movl %edx, %es:28(%edi) )
27340
27341 lea 32(%esi), %esi
27342 lea 32(%edi), %edi
27343@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
27344 shrl $2, %edx # This clears CF
27345 SRC(3: movl (%esi), %ebx )
27346 adcl %ebx, %eax
27347-DST( movl %ebx, (%edi) )
27348+DST( movl %ebx, %es:(%edi) )
27349 lea 4(%esi), %esi
27350 lea 4(%edi), %edi
27351 dec %edx
27352@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
27353 jb 5f
27354 SRC( movw (%esi), %cx )
27355 leal 2(%esi), %esi
27356-DST( movw %cx, (%edi) )
27357+DST( movw %cx, %es:(%edi) )
27358 leal 2(%edi), %edi
27359 je 6f
27360 shll $16,%ecx
27361 SRC(5: movb (%esi), %cl )
27362-DST( movb %cl, (%edi) )
27363+DST( movb %cl, %es:(%edi) )
27364 6: addl %ecx, %eax
27365 adcl $0, %eax
27366 7:
27367@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
27368
27369 6001:
27370 movl ARGBASE+20(%esp), %ebx # src_err_ptr
27371- movl $-EFAULT, (%ebx)
27372+ movl $-EFAULT, %ss:(%ebx)
27373
27374 # zero the complete destination - computing the rest
27375 # is too much work
27376@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
27377
27378 6002:
27379 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
27380- movl $-EFAULT,(%ebx)
27381+ movl $-EFAULT,%ss:(%ebx)
27382 jmp 5000b
27383
27384 .previous
27385
27386+ pushl_cfi %ss
27387+ popl_cfi %ds
27388+ pushl_cfi %ss
27389+ popl_cfi %es
27390 popl_cfi %ebx
27391 CFI_RESTORE ebx
27392 popl_cfi %esi
27393@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
27394 popl_cfi %ecx # equivalent to addl $4,%esp
27395 ret
27396 CFI_ENDPROC
27397-ENDPROC(csum_partial_copy_generic)
27398+ENDPROC(csum_partial_copy_generic_to_user)
27399
27400 #else
27401
27402 /* Version for PentiumII/PPro */
27403
27404 #define ROUND1(x) \
27405+ nop; nop; nop; \
27406 SRC(movl x(%esi), %ebx ) ; \
27407 addl %ebx, %eax ; \
27408- DST(movl %ebx, x(%edi) ) ;
27409+ DST(movl %ebx, %es:x(%edi)) ;
27410
27411 #define ROUND(x) \
27412+ nop; nop; nop; \
27413 SRC(movl x(%esi), %ebx ) ; \
27414 adcl %ebx, %eax ; \
27415- DST(movl %ebx, x(%edi) ) ;
27416+ DST(movl %ebx, %es:x(%edi)) ;
27417
27418 #define ARGBASE 12
27419-
27420-ENTRY(csum_partial_copy_generic)
27421+
27422+ENTRY(csum_partial_copy_generic_to_user)
27423 CFI_STARTPROC
27424+
27425+#ifdef CONFIG_PAX_MEMORY_UDEREF
27426+ pushl_cfi %gs
27427+ popl_cfi %es
27428+ jmp csum_partial_copy_generic
27429+#endif
27430+
27431+ENTRY(csum_partial_copy_generic_from_user)
27432+
27433+#ifdef CONFIG_PAX_MEMORY_UDEREF
27434+ pushl_cfi %gs
27435+ popl_cfi %ds
27436+#endif
27437+
27438+ENTRY(csum_partial_copy_generic)
27439 pushl_cfi %ebx
27440 CFI_REL_OFFSET ebx, 0
27441 pushl_cfi %edi
27442@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
27443 subl %ebx, %edi
27444 lea -1(%esi),%edx
27445 andl $-32,%edx
27446- lea 3f(%ebx,%ebx), %ebx
27447+ lea 3f(%ebx,%ebx,2), %ebx
27448 testl %esi, %esi
27449 jmp *%ebx
27450 1: addl $64,%esi
27451@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
27452 jb 5f
27453 SRC( movw (%esi), %dx )
27454 leal 2(%esi), %esi
27455-DST( movw %dx, (%edi) )
27456+DST( movw %dx, %es:(%edi) )
27457 leal 2(%edi), %edi
27458 je 6f
27459 shll $16,%edx
27460 5:
27461 SRC( movb (%esi), %dl )
27462-DST( movb %dl, (%edi) )
27463+DST( movb %dl, %es:(%edi) )
27464 6: addl %edx, %eax
27465 adcl $0, %eax
27466 7:
27467 .section .fixup, "ax"
27468 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
27469- movl $-EFAULT, (%ebx)
27470+ movl $-EFAULT, %ss:(%ebx)
27471 # zero the complete destination (computing the rest is too much work)
27472 movl ARGBASE+8(%esp),%edi # dst
27473 movl ARGBASE+12(%esp),%ecx # len
27474@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
27475 rep; stosb
27476 jmp 7b
27477 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
27478- movl $-EFAULT, (%ebx)
27479+ movl $-EFAULT, %ss:(%ebx)
27480 jmp 7b
27481 .previous
27482
27483+#ifdef CONFIG_PAX_MEMORY_UDEREF
27484+ pushl_cfi %ss
27485+ popl_cfi %ds
27486+ pushl_cfi %ss
27487+ popl_cfi %es
27488+#endif
27489+
27490 popl_cfi %esi
27491 CFI_RESTORE esi
27492 popl_cfi %edi
27493@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
27494 CFI_RESTORE ebx
27495 ret
27496 CFI_ENDPROC
27497-ENDPROC(csum_partial_copy_generic)
27498+ENDPROC(csum_partial_copy_generic_to_user)
27499
27500 #undef ROUND
27501 #undef ROUND1
27502diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
27503index f2145cf..cea889d 100644
27504--- a/arch/x86/lib/clear_page_64.S
27505+++ b/arch/x86/lib/clear_page_64.S
27506@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
27507 movl $4096/8,%ecx
27508 xorl %eax,%eax
27509 rep stosq
27510+ pax_force_retaddr
27511 ret
27512 CFI_ENDPROC
27513 ENDPROC(clear_page_c)
27514@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
27515 movl $4096,%ecx
27516 xorl %eax,%eax
27517 rep stosb
27518+ pax_force_retaddr
27519 ret
27520 CFI_ENDPROC
27521 ENDPROC(clear_page_c_e)
27522@@ -43,6 +45,7 @@ ENTRY(clear_page)
27523 leaq 64(%rdi),%rdi
27524 jnz .Lloop
27525 nop
27526+ pax_force_retaddr
27527 ret
27528 CFI_ENDPROC
27529 .Lclear_page_end:
27530@@ -58,7 +61,7 @@ ENDPROC(clear_page)
27531
27532 #include <asm/cpufeature.h>
27533
27534- .section .altinstr_replacement,"ax"
27535+ .section .altinstr_replacement,"a"
27536 1: .byte 0xeb /* jmp <disp8> */
27537 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
27538 2: .byte 0xeb /* jmp <disp8> */
27539diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
27540index 1e572c5..2a162cd 100644
27541--- a/arch/x86/lib/cmpxchg16b_emu.S
27542+++ b/arch/x86/lib/cmpxchg16b_emu.S
27543@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
27544
27545 popf
27546 mov $1, %al
27547+ pax_force_retaddr
27548 ret
27549
27550 not_same:
27551 popf
27552 xor %al,%al
27553+ pax_force_retaddr
27554 ret
27555
27556 CFI_ENDPROC
27557diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
27558index 176cca6..1166c50 100644
27559--- a/arch/x86/lib/copy_page_64.S
27560+++ b/arch/x86/lib/copy_page_64.S
27561@@ -9,6 +9,7 @@ copy_page_rep:
27562 CFI_STARTPROC
27563 movl $4096/8, %ecx
27564 rep movsq
27565+ pax_force_retaddr
27566 ret
27567 CFI_ENDPROC
27568 ENDPROC(copy_page_rep)
27569@@ -20,12 +21,14 @@ ENDPROC(copy_page_rep)
27570
27571 ENTRY(copy_page)
27572 CFI_STARTPROC
27573- subq $2*8, %rsp
27574- CFI_ADJUST_CFA_OFFSET 2*8
27575+ subq $3*8, %rsp
27576+ CFI_ADJUST_CFA_OFFSET 3*8
27577 movq %rbx, (%rsp)
27578 CFI_REL_OFFSET rbx, 0
27579 movq %r12, 1*8(%rsp)
27580 CFI_REL_OFFSET r12, 1*8
27581+ movq %r13, 2*8(%rsp)
27582+ CFI_REL_OFFSET r13, 2*8
27583
27584 movl $(4096/64)-5, %ecx
27585 .p2align 4
27586@@ -36,7 +39,7 @@ ENTRY(copy_page)
27587 movq 0x8*2(%rsi), %rdx
27588 movq 0x8*3(%rsi), %r8
27589 movq 0x8*4(%rsi), %r9
27590- movq 0x8*5(%rsi), %r10
27591+ movq 0x8*5(%rsi), %r13
27592 movq 0x8*6(%rsi), %r11
27593 movq 0x8*7(%rsi), %r12
27594
27595@@ -47,7 +50,7 @@ ENTRY(copy_page)
27596 movq %rdx, 0x8*2(%rdi)
27597 movq %r8, 0x8*3(%rdi)
27598 movq %r9, 0x8*4(%rdi)
27599- movq %r10, 0x8*5(%rdi)
27600+ movq %r13, 0x8*5(%rdi)
27601 movq %r11, 0x8*6(%rdi)
27602 movq %r12, 0x8*7(%rdi)
27603
27604@@ -66,7 +69,7 @@ ENTRY(copy_page)
27605 movq 0x8*2(%rsi), %rdx
27606 movq 0x8*3(%rsi), %r8
27607 movq 0x8*4(%rsi), %r9
27608- movq 0x8*5(%rsi), %r10
27609+ movq 0x8*5(%rsi), %r13
27610 movq 0x8*6(%rsi), %r11
27611 movq 0x8*7(%rsi), %r12
27612
27613@@ -75,7 +78,7 @@ ENTRY(copy_page)
27614 movq %rdx, 0x8*2(%rdi)
27615 movq %r8, 0x8*3(%rdi)
27616 movq %r9, 0x8*4(%rdi)
27617- movq %r10, 0x8*5(%rdi)
27618+ movq %r13, 0x8*5(%rdi)
27619 movq %r11, 0x8*6(%rdi)
27620 movq %r12, 0x8*7(%rdi)
27621
27622@@ -87,8 +90,11 @@ ENTRY(copy_page)
27623 CFI_RESTORE rbx
27624 movq 1*8(%rsp), %r12
27625 CFI_RESTORE r12
27626- addq $2*8, %rsp
27627- CFI_ADJUST_CFA_OFFSET -2*8
27628+ movq 2*8(%rsp), %r13
27629+ CFI_RESTORE r13
27630+ addq $3*8, %rsp
27631+ CFI_ADJUST_CFA_OFFSET -3*8
27632+ pax_force_retaddr
27633 ret
27634 .Lcopy_page_end:
27635 CFI_ENDPROC
27636@@ -99,7 +105,7 @@ ENDPROC(copy_page)
27637
27638 #include <asm/cpufeature.h>
27639
27640- .section .altinstr_replacement,"ax"
27641+ .section .altinstr_replacement,"a"
27642 1: .byte 0xeb /* jmp <disp8> */
27643 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
27644 2:
27645diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
27646index a30ca15..6b3f4e1 100644
27647--- a/arch/x86/lib/copy_user_64.S
27648+++ b/arch/x86/lib/copy_user_64.S
27649@@ -18,31 +18,7 @@
27650 #include <asm/alternative-asm.h>
27651 #include <asm/asm.h>
27652 #include <asm/smap.h>
27653-
27654-/*
27655- * By placing feature2 after feature1 in altinstructions section, we logically
27656- * implement:
27657- * If CPU has feature2, jmp to alt2 is used
27658- * else if CPU has feature1, jmp to alt1 is used
27659- * else jmp to orig is used.
27660- */
27661- .macro ALTERNATIVE_JUMP feature1,feature2,orig,alt1,alt2
27662-0:
27663- .byte 0xe9 /* 32bit jump */
27664- .long \orig-1f /* by default jump to orig */
27665-1:
27666- .section .altinstr_replacement,"ax"
27667-2: .byte 0xe9 /* near jump with 32bit immediate */
27668- .long \alt1-1b /* offset */ /* or alternatively to alt1 */
27669-3: .byte 0xe9 /* near jump with 32bit immediate */
27670- .long \alt2-1b /* offset */ /* or alternatively to alt2 */
27671- .previous
27672-
27673- .section .altinstructions,"a"
27674- altinstruction_entry 0b,2b,\feature1,5,5
27675- altinstruction_entry 0b,3b,\feature2,5,5
27676- .previous
27677- .endm
27678+#include <asm/pgtable.h>
27679
27680 .macro ALIGN_DESTINATION
27681 #ifdef FIX_ALIGNMENT
27682@@ -70,52 +46,6 @@
27683 #endif
27684 .endm
27685
27686-/* Standard copy_to_user with segment limit checking */
27687-ENTRY(_copy_to_user)
27688- CFI_STARTPROC
27689- GET_THREAD_INFO(%rax)
27690- movq %rdi,%rcx
27691- addq %rdx,%rcx
27692- jc bad_to_user
27693- cmpq TI_addr_limit(%rax),%rcx
27694- ja bad_to_user
27695- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
27696- copy_user_generic_unrolled,copy_user_generic_string, \
27697- copy_user_enhanced_fast_string
27698- CFI_ENDPROC
27699-ENDPROC(_copy_to_user)
27700-
27701-/* Standard copy_from_user with segment limit checking */
27702-ENTRY(_copy_from_user)
27703- CFI_STARTPROC
27704- GET_THREAD_INFO(%rax)
27705- movq %rsi,%rcx
27706- addq %rdx,%rcx
27707- jc bad_from_user
27708- cmpq TI_addr_limit(%rax),%rcx
27709- ja bad_from_user
27710- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
27711- copy_user_generic_unrolled,copy_user_generic_string, \
27712- copy_user_enhanced_fast_string
27713- CFI_ENDPROC
27714-ENDPROC(_copy_from_user)
27715-
27716- .section .fixup,"ax"
27717- /* must zero dest */
27718-ENTRY(bad_from_user)
27719-bad_from_user:
27720- CFI_STARTPROC
27721- movl %edx,%ecx
27722- xorl %eax,%eax
27723- rep
27724- stosb
27725-bad_to_user:
27726- movl %edx,%eax
27727- ret
27728- CFI_ENDPROC
27729-ENDPROC(bad_from_user)
27730- .previous
27731-
27732 /*
27733 * copy_user_generic_unrolled - memory copy with exception handling.
27734 * This version is for CPUs like P4 that don't have efficient micro
27735@@ -131,6 +61,7 @@ ENDPROC(bad_from_user)
27736 */
27737 ENTRY(copy_user_generic_unrolled)
27738 CFI_STARTPROC
27739+ ASM_PAX_OPEN_USERLAND
27740 ASM_STAC
27741 cmpl $8,%edx
27742 jb 20f /* less then 8 bytes, go to byte copy loop */
27743@@ -141,19 +72,19 @@ ENTRY(copy_user_generic_unrolled)
27744 jz 17f
27745 1: movq (%rsi),%r8
27746 2: movq 1*8(%rsi),%r9
27747-3: movq 2*8(%rsi),%r10
27748+3: movq 2*8(%rsi),%rax
27749 4: movq 3*8(%rsi),%r11
27750 5: movq %r8,(%rdi)
27751 6: movq %r9,1*8(%rdi)
27752-7: movq %r10,2*8(%rdi)
27753+7: movq %rax,2*8(%rdi)
27754 8: movq %r11,3*8(%rdi)
27755 9: movq 4*8(%rsi),%r8
27756 10: movq 5*8(%rsi),%r9
27757-11: movq 6*8(%rsi),%r10
27758+11: movq 6*8(%rsi),%rax
27759 12: movq 7*8(%rsi),%r11
27760 13: movq %r8,4*8(%rdi)
27761 14: movq %r9,5*8(%rdi)
27762-15: movq %r10,6*8(%rdi)
27763+15: movq %rax,6*8(%rdi)
27764 16: movq %r11,7*8(%rdi)
27765 leaq 64(%rsi),%rsi
27766 leaq 64(%rdi),%rdi
27767@@ -180,6 +111,8 @@ ENTRY(copy_user_generic_unrolled)
27768 jnz 21b
27769 23: xor %eax,%eax
27770 ASM_CLAC
27771+ ASM_PAX_CLOSE_USERLAND
27772+ pax_force_retaddr
27773 ret
27774
27775 .section .fixup,"ax"
27776@@ -235,6 +168,7 @@ ENDPROC(copy_user_generic_unrolled)
27777 */
27778 ENTRY(copy_user_generic_string)
27779 CFI_STARTPROC
27780+ ASM_PAX_OPEN_USERLAND
27781 ASM_STAC
27782 andl %edx,%edx
27783 jz 4f
27784@@ -251,6 +185,8 @@ ENTRY(copy_user_generic_string)
27785 movsb
27786 4: xorl %eax,%eax
27787 ASM_CLAC
27788+ ASM_PAX_CLOSE_USERLAND
27789+ pax_force_retaddr
27790 ret
27791
27792 .section .fixup,"ax"
27793@@ -278,6 +214,7 @@ ENDPROC(copy_user_generic_string)
27794 */
27795 ENTRY(copy_user_enhanced_fast_string)
27796 CFI_STARTPROC
27797+ ASM_PAX_OPEN_USERLAND
27798 ASM_STAC
27799 andl %edx,%edx
27800 jz 2f
27801@@ -286,6 +223,8 @@ ENTRY(copy_user_enhanced_fast_string)
27802 movsb
27803 2: xorl %eax,%eax
27804 ASM_CLAC
27805+ ASM_PAX_CLOSE_USERLAND
27806+ pax_force_retaddr
27807 ret
27808
27809 .section .fixup,"ax"
27810diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
27811index 6a4f43c..55d26f2 100644
27812--- a/arch/x86/lib/copy_user_nocache_64.S
27813+++ b/arch/x86/lib/copy_user_nocache_64.S
27814@@ -8,6 +8,7 @@
27815
27816 #include <linux/linkage.h>
27817 #include <asm/dwarf2.h>
27818+#include <asm/alternative-asm.h>
27819
27820 #define FIX_ALIGNMENT 1
27821
27822@@ -16,6 +17,7 @@
27823 #include <asm/thread_info.h>
27824 #include <asm/asm.h>
27825 #include <asm/smap.h>
27826+#include <asm/pgtable.h>
27827
27828 .macro ALIGN_DESTINATION
27829 #ifdef FIX_ALIGNMENT
27830@@ -49,6 +51,16 @@
27831 */
27832 ENTRY(__copy_user_nocache)
27833 CFI_STARTPROC
27834+
27835+#ifdef CONFIG_PAX_MEMORY_UDEREF
27836+ mov pax_user_shadow_base,%rcx
27837+ cmp %rcx,%rsi
27838+ jae 1f
27839+ add %rcx,%rsi
27840+1:
27841+#endif
27842+
27843+ ASM_PAX_OPEN_USERLAND
27844 ASM_STAC
27845 cmpl $8,%edx
27846 jb 20f /* less then 8 bytes, go to byte copy loop */
27847@@ -59,19 +71,19 @@ ENTRY(__copy_user_nocache)
27848 jz 17f
27849 1: movq (%rsi),%r8
27850 2: movq 1*8(%rsi),%r9
27851-3: movq 2*8(%rsi),%r10
27852+3: movq 2*8(%rsi),%rax
27853 4: movq 3*8(%rsi),%r11
27854 5: movnti %r8,(%rdi)
27855 6: movnti %r9,1*8(%rdi)
27856-7: movnti %r10,2*8(%rdi)
27857+7: movnti %rax,2*8(%rdi)
27858 8: movnti %r11,3*8(%rdi)
27859 9: movq 4*8(%rsi),%r8
27860 10: movq 5*8(%rsi),%r9
27861-11: movq 6*8(%rsi),%r10
27862+11: movq 6*8(%rsi),%rax
27863 12: movq 7*8(%rsi),%r11
27864 13: movnti %r8,4*8(%rdi)
27865 14: movnti %r9,5*8(%rdi)
27866-15: movnti %r10,6*8(%rdi)
27867+15: movnti %rax,6*8(%rdi)
27868 16: movnti %r11,7*8(%rdi)
27869 leaq 64(%rsi),%rsi
27870 leaq 64(%rdi),%rdi
27871@@ -98,7 +110,9 @@ ENTRY(__copy_user_nocache)
27872 jnz 21b
27873 23: xorl %eax,%eax
27874 ASM_CLAC
27875+ ASM_PAX_CLOSE_USERLAND
27876 sfence
27877+ pax_force_retaddr
27878 ret
27879
27880 .section .fixup,"ax"
27881diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
27882index 2419d5f..953ee51 100644
27883--- a/arch/x86/lib/csum-copy_64.S
27884+++ b/arch/x86/lib/csum-copy_64.S
27885@@ -9,6 +9,7 @@
27886 #include <asm/dwarf2.h>
27887 #include <asm/errno.h>
27888 #include <asm/asm.h>
27889+#include <asm/alternative-asm.h>
27890
27891 /*
27892 * Checksum copy with exception handling.
27893@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
27894 CFI_RESTORE rbp
27895 addq $7*8, %rsp
27896 CFI_ADJUST_CFA_OFFSET -7*8
27897+ pax_force_retaddr 0, 1
27898 ret
27899 CFI_RESTORE_STATE
27900
27901diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
27902index 25b7ae8..c40113e 100644
27903--- a/arch/x86/lib/csum-wrappers_64.c
27904+++ b/arch/x86/lib/csum-wrappers_64.c
27905@@ -52,8 +52,12 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
27906 len -= 2;
27907 }
27908 }
27909- isum = csum_partial_copy_generic((__force const void *)src,
27910+ pax_open_userland();
27911+ stac();
27912+ isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
27913 dst, len, isum, errp, NULL);
27914+ clac();
27915+ pax_close_userland();
27916 if (unlikely(*errp))
27917 goto out_err;
27918
27919@@ -105,8 +109,13 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
27920 }
27921
27922 *errp = 0;
27923- return csum_partial_copy_generic(src, (void __force *)dst,
27924+ pax_open_userland();
27925+ stac();
27926+ isum = csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
27927 len, isum, NULL, errp);
27928+ clac();
27929+ pax_close_userland();
27930+ return isum;
27931 }
27932 EXPORT_SYMBOL(csum_partial_copy_to_user);
27933
27934diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
27935index a451235..1daa956 100644
27936--- a/arch/x86/lib/getuser.S
27937+++ b/arch/x86/lib/getuser.S
27938@@ -33,17 +33,40 @@
27939 #include <asm/thread_info.h>
27940 #include <asm/asm.h>
27941 #include <asm/smap.h>
27942+#include <asm/segment.h>
27943+#include <asm/pgtable.h>
27944+#include <asm/alternative-asm.h>
27945+
27946+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
27947+#define __copyuser_seg gs;
27948+#else
27949+#define __copyuser_seg
27950+#endif
27951
27952 .text
27953 ENTRY(__get_user_1)
27954 CFI_STARTPROC
27955+
27956+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
27957 GET_THREAD_INFO(%_ASM_DX)
27958 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
27959 jae bad_get_user
27960 ASM_STAC
27961-1: movzbl (%_ASM_AX),%edx
27962+
27963+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
27964+ mov pax_user_shadow_base,%_ASM_DX
27965+ cmp %_ASM_DX,%_ASM_AX
27966+ jae 1234f
27967+ add %_ASM_DX,%_ASM_AX
27968+1234:
27969+#endif
27970+
27971+#endif
27972+
27973+1: __copyuser_seg movzbl (%_ASM_AX),%edx
27974 xor %eax,%eax
27975 ASM_CLAC
27976+ pax_force_retaddr
27977 ret
27978 CFI_ENDPROC
27979 ENDPROC(__get_user_1)
27980@@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
27981 ENTRY(__get_user_2)
27982 CFI_STARTPROC
27983 add $1,%_ASM_AX
27984+
27985+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
27986 jc bad_get_user
27987 GET_THREAD_INFO(%_ASM_DX)
27988 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
27989 jae bad_get_user
27990 ASM_STAC
27991-2: movzwl -1(%_ASM_AX),%edx
27992+
27993+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
27994+ mov pax_user_shadow_base,%_ASM_DX
27995+ cmp %_ASM_DX,%_ASM_AX
27996+ jae 1234f
27997+ add %_ASM_DX,%_ASM_AX
27998+1234:
27999+#endif
28000+
28001+#endif
28002+
28003+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
28004 xor %eax,%eax
28005 ASM_CLAC
28006+ pax_force_retaddr
28007 ret
28008 CFI_ENDPROC
28009 ENDPROC(__get_user_2)
28010@@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
28011 ENTRY(__get_user_4)
28012 CFI_STARTPROC
28013 add $3,%_ASM_AX
28014+
28015+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28016 jc bad_get_user
28017 GET_THREAD_INFO(%_ASM_DX)
28018 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
28019 jae bad_get_user
28020 ASM_STAC
28021-3: movl -3(%_ASM_AX),%edx
28022+
28023+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28024+ mov pax_user_shadow_base,%_ASM_DX
28025+ cmp %_ASM_DX,%_ASM_AX
28026+ jae 1234f
28027+ add %_ASM_DX,%_ASM_AX
28028+1234:
28029+#endif
28030+
28031+#endif
28032+
28033+3: __copyuser_seg movl -3(%_ASM_AX),%edx
28034 xor %eax,%eax
28035 ASM_CLAC
28036+ pax_force_retaddr
28037 ret
28038 CFI_ENDPROC
28039 ENDPROC(__get_user_4)
28040@@ -86,10 +137,20 @@ ENTRY(__get_user_8)
28041 GET_THREAD_INFO(%_ASM_DX)
28042 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
28043 jae bad_get_user
28044+
28045+#ifdef CONFIG_PAX_MEMORY_UDEREF
28046+ mov pax_user_shadow_base,%_ASM_DX
28047+ cmp %_ASM_DX,%_ASM_AX
28048+ jae 1234f
28049+ add %_ASM_DX,%_ASM_AX
28050+1234:
28051+#endif
28052+
28053 ASM_STAC
28054 4: movq -7(%_ASM_AX),%rdx
28055 xor %eax,%eax
28056 ASM_CLAC
28057+ pax_force_retaddr
28058 ret
28059 #else
28060 add $7,%_ASM_AX
28061@@ -98,10 +159,11 @@ ENTRY(__get_user_8)
28062 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
28063 jae bad_get_user_8
28064 ASM_STAC
28065-4: movl -7(%_ASM_AX),%edx
28066-5: movl -3(%_ASM_AX),%ecx
28067+4: __copyuser_seg movl -7(%_ASM_AX),%edx
28068+5: __copyuser_seg movl -3(%_ASM_AX),%ecx
28069 xor %eax,%eax
28070 ASM_CLAC
28071+ pax_force_retaddr
28072 ret
28073 #endif
28074 CFI_ENDPROC
28075@@ -113,6 +175,7 @@ bad_get_user:
28076 xor %edx,%edx
28077 mov $(-EFAULT),%_ASM_AX
28078 ASM_CLAC
28079+ pax_force_retaddr
28080 ret
28081 CFI_ENDPROC
28082 END(bad_get_user)
28083@@ -124,6 +187,7 @@ bad_get_user_8:
28084 xor %ecx,%ecx
28085 mov $(-EFAULT),%_ASM_AX
28086 ASM_CLAC
28087+ pax_force_retaddr
28088 ret
28089 CFI_ENDPROC
28090 END(bad_get_user_8)
28091diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
28092index 54fcffe..7be149e 100644
28093--- a/arch/x86/lib/insn.c
28094+++ b/arch/x86/lib/insn.c
28095@@ -20,8 +20,10 @@
28096
28097 #ifdef __KERNEL__
28098 #include <linux/string.h>
28099+#include <asm/pgtable_types.h>
28100 #else
28101 #include <string.h>
28102+#define ktla_ktva(addr) addr
28103 #endif
28104 #include <asm/inat.h>
28105 #include <asm/insn.h>
28106@@ -53,8 +55,8 @@
28107 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
28108 {
28109 memset(insn, 0, sizeof(*insn));
28110- insn->kaddr = kaddr;
28111- insn->next_byte = kaddr;
28112+ insn->kaddr = ktla_ktva(kaddr);
28113+ insn->next_byte = ktla_ktva(kaddr);
28114 insn->x86_64 = x86_64 ? 1 : 0;
28115 insn->opnd_bytes = 4;
28116 if (x86_64)
28117diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
28118index 05a95e7..326f2fa 100644
28119--- a/arch/x86/lib/iomap_copy_64.S
28120+++ b/arch/x86/lib/iomap_copy_64.S
28121@@ -17,6 +17,7 @@
28122
28123 #include <linux/linkage.h>
28124 #include <asm/dwarf2.h>
28125+#include <asm/alternative-asm.h>
28126
28127 /*
28128 * override generic version in lib/iomap_copy.c
28129@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
28130 CFI_STARTPROC
28131 movl %edx,%ecx
28132 rep movsd
28133+ pax_force_retaddr
28134 ret
28135 CFI_ENDPROC
28136 ENDPROC(__iowrite32_copy)
28137diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
28138index 56313a3..9b59269 100644
28139--- a/arch/x86/lib/memcpy_64.S
28140+++ b/arch/x86/lib/memcpy_64.S
28141@@ -24,7 +24,7 @@
28142 * This gets patched over the unrolled variant (below) via the
28143 * alternative instructions framework:
28144 */
28145- .section .altinstr_replacement, "ax", @progbits
28146+ .section .altinstr_replacement, "a", @progbits
28147 .Lmemcpy_c:
28148 movq %rdi, %rax
28149 movq %rdx, %rcx
28150@@ -33,6 +33,7 @@
28151 rep movsq
28152 movl %edx, %ecx
28153 rep movsb
28154+ pax_force_retaddr
28155 ret
28156 .Lmemcpy_e:
28157 .previous
28158@@ -44,11 +45,12 @@
28159 * This gets patched over the unrolled variant (below) via the
28160 * alternative instructions framework:
28161 */
28162- .section .altinstr_replacement, "ax", @progbits
28163+ .section .altinstr_replacement, "a", @progbits
28164 .Lmemcpy_c_e:
28165 movq %rdi, %rax
28166 movq %rdx, %rcx
28167 rep movsb
28168+ pax_force_retaddr
28169 ret
28170 .Lmemcpy_e_e:
28171 .previous
28172@@ -76,13 +78,13 @@ ENTRY(memcpy)
28173 */
28174 movq 0*8(%rsi), %r8
28175 movq 1*8(%rsi), %r9
28176- movq 2*8(%rsi), %r10
28177+ movq 2*8(%rsi), %rcx
28178 movq 3*8(%rsi), %r11
28179 leaq 4*8(%rsi), %rsi
28180
28181 movq %r8, 0*8(%rdi)
28182 movq %r9, 1*8(%rdi)
28183- movq %r10, 2*8(%rdi)
28184+ movq %rcx, 2*8(%rdi)
28185 movq %r11, 3*8(%rdi)
28186 leaq 4*8(%rdi), %rdi
28187 jae .Lcopy_forward_loop
28188@@ -105,12 +107,12 @@ ENTRY(memcpy)
28189 subq $0x20, %rdx
28190 movq -1*8(%rsi), %r8
28191 movq -2*8(%rsi), %r9
28192- movq -3*8(%rsi), %r10
28193+ movq -3*8(%rsi), %rcx
28194 movq -4*8(%rsi), %r11
28195 leaq -4*8(%rsi), %rsi
28196 movq %r8, -1*8(%rdi)
28197 movq %r9, -2*8(%rdi)
28198- movq %r10, -3*8(%rdi)
28199+ movq %rcx, -3*8(%rdi)
28200 movq %r11, -4*8(%rdi)
28201 leaq -4*8(%rdi), %rdi
28202 jae .Lcopy_backward_loop
28203@@ -130,12 +132,13 @@ ENTRY(memcpy)
28204 */
28205 movq 0*8(%rsi), %r8
28206 movq 1*8(%rsi), %r9
28207- movq -2*8(%rsi, %rdx), %r10
28208+ movq -2*8(%rsi, %rdx), %rcx
28209 movq -1*8(%rsi, %rdx), %r11
28210 movq %r8, 0*8(%rdi)
28211 movq %r9, 1*8(%rdi)
28212- movq %r10, -2*8(%rdi, %rdx)
28213+ movq %rcx, -2*8(%rdi, %rdx)
28214 movq %r11, -1*8(%rdi, %rdx)
28215+ pax_force_retaddr
28216 retq
28217 .p2align 4
28218 .Lless_16bytes:
28219@@ -148,6 +151,7 @@ ENTRY(memcpy)
28220 movq -1*8(%rsi, %rdx), %r9
28221 movq %r8, 0*8(%rdi)
28222 movq %r9, -1*8(%rdi, %rdx)
28223+ pax_force_retaddr
28224 retq
28225 .p2align 4
28226 .Lless_8bytes:
28227@@ -161,6 +165,7 @@ ENTRY(memcpy)
28228 movl -4(%rsi, %rdx), %r8d
28229 movl %ecx, (%rdi)
28230 movl %r8d, -4(%rdi, %rdx)
28231+ pax_force_retaddr
28232 retq
28233 .p2align 4
28234 .Lless_3bytes:
28235@@ -179,6 +184,7 @@ ENTRY(memcpy)
28236 movb %cl, (%rdi)
28237
28238 .Lend:
28239+ pax_force_retaddr
28240 retq
28241 CFI_ENDPROC
28242 ENDPROC(memcpy)
28243diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
28244index 65268a6..5aa7815 100644
28245--- a/arch/x86/lib/memmove_64.S
28246+++ b/arch/x86/lib/memmove_64.S
28247@@ -61,13 +61,13 @@ ENTRY(memmove)
28248 5:
28249 sub $0x20, %rdx
28250 movq 0*8(%rsi), %r11
28251- movq 1*8(%rsi), %r10
28252+ movq 1*8(%rsi), %rcx
28253 movq 2*8(%rsi), %r9
28254 movq 3*8(%rsi), %r8
28255 leaq 4*8(%rsi), %rsi
28256
28257 movq %r11, 0*8(%rdi)
28258- movq %r10, 1*8(%rdi)
28259+ movq %rcx, 1*8(%rdi)
28260 movq %r9, 2*8(%rdi)
28261 movq %r8, 3*8(%rdi)
28262 leaq 4*8(%rdi), %rdi
28263@@ -81,10 +81,10 @@ ENTRY(memmove)
28264 4:
28265 movq %rdx, %rcx
28266 movq -8(%rsi, %rdx), %r11
28267- lea -8(%rdi, %rdx), %r10
28268+ lea -8(%rdi, %rdx), %r9
28269 shrq $3, %rcx
28270 rep movsq
28271- movq %r11, (%r10)
28272+ movq %r11, (%r9)
28273 jmp 13f
28274 .Lmemmove_end_forward:
28275
28276@@ -95,14 +95,14 @@ ENTRY(memmove)
28277 7:
28278 movq %rdx, %rcx
28279 movq (%rsi), %r11
28280- movq %rdi, %r10
28281+ movq %rdi, %r9
28282 leaq -8(%rsi, %rdx), %rsi
28283 leaq -8(%rdi, %rdx), %rdi
28284 shrq $3, %rcx
28285 std
28286 rep movsq
28287 cld
28288- movq %r11, (%r10)
28289+ movq %r11, (%r9)
28290 jmp 13f
28291
28292 /*
28293@@ -127,13 +127,13 @@ ENTRY(memmove)
28294 8:
28295 subq $0x20, %rdx
28296 movq -1*8(%rsi), %r11
28297- movq -2*8(%rsi), %r10
28298+ movq -2*8(%rsi), %rcx
28299 movq -3*8(%rsi), %r9
28300 movq -4*8(%rsi), %r8
28301 leaq -4*8(%rsi), %rsi
28302
28303 movq %r11, -1*8(%rdi)
28304- movq %r10, -2*8(%rdi)
28305+ movq %rcx, -2*8(%rdi)
28306 movq %r9, -3*8(%rdi)
28307 movq %r8, -4*8(%rdi)
28308 leaq -4*8(%rdi), %rdi
28309@@ -151,11 +151,11 @@ ENTRY(memmove)
28310 * Move data from 16 bytes to 31 bytes.
28311 */
28312 movq 0*8(%rsi), %r11
28313- movq 1*8(%rsi), %r10
28314+ movq 1*8(%rsi), %rcx
28315 movq -2*8(%rsi, %rdx), %r9
28316 movq -1*8(%rsi, %rdx), %r8
28317 movq %r11, 0*8(%rdi)
28318- movq %r10, 1*8(%rdi)
28319+ movq %rcx, 1*8(%rdi)
28320 movq %r9, -2*8(%rdi, %rdx)
28321 movq %r8, -1*8(%rdi, %rdx)
28322 jmp 13f
28323@@ -167,9 +167,9 @@ ENTRY(memmove)
28324 * Move data from 8 bytes to 15 bytes.
28325 */
28326 movq 0*8(%rsi), %r11
28327- movq -1*8(%rsi, %rdx), %r10
28328+ movq -1*8(%rsi, %rdx), %r9
28329 movq %r11, 0*8(%rdi)
28330- movq %r10, -1*8(%rdi, %rdx)
28331+ movq %r9, -1*8(%rdi, %rdx)
28332 jmp 13f
28333 10:
28334 cmpq $4, %rdx
28335@@ -178,9 +178,9 @@ ENTRY(memmove)
28336 * Move data from 4 bytes to 7 bytes.
28337 */
28338 movl (%rsi), %r11d
28339- movl -4(%rsi, %rdx), %r10d
28340+ movl -4(%rsi, %rdx), %r9d
28341 movl %r11d, (%rdi)
28342- movl %r10d, -4(%rdi, %rdx)
28343+ movl %r9d, -4(%rdi, %rdx)
28344 jmp 13f
28345 11:
28346 cmp $2, %rdx
28347@@ -189,9 +189,9 @@ ENTRY(memmove)
28348 * Move data from 2 bytes to 3 bytes.
28349 */
28350 movw (%rsi), %r11w
28351- movw -2(%rsi, %rdx), %r10w
28352+ movw -2(%rsi, %rdx), %r9w
28353 movw %r11w, (%rdi)
28354- movw %r10w, -2(%rdi, %rdx)
28355+ movw %r9w, -2(%rdi, %rdx)
28356 jmp 13f
28357 12:
28358 cmp $1, %rdx
28359@@ -202,14 +202,16 @@ ENTRY(memmove)
28360 movb (%rsi), %r11b
28361 movb %r11b, (%rdi)
28362 13:
28363+ pax_force_retaddr
28364 retq
28365 CFI_ENDPROC
28366
28367- .section .altinstr_replacement,"ax"
28368+ .section .altinstr_replacement,"a"
28369 .Lmemmove_begin_forward_efs:
28370 /* Forward moving data. */
28371 movq %rdx, %rcx
28372 rep movsb
28373+ pax_force_retaddr
28374 retq
28375 .Lmemmove_end_forward_efs:
28376 .previous
28377diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
28378index 2dcb380..50a78bc 100644
28379--- a/arch/x86/lib/memset_64.S
28380+++ b/arch/x86/lib/memset_64.S
28381@@ -16,7 +16,7 @@
28382 *
28383 * rax original destination
28384 */
28385- .section .altinstr_replacement, "ax", @progbits
28386+ .section .altinstr_replacement, "a", @progbits
28387 .Lmemset_c:
28388 movq %rdi,%r9
28389 movq %rdx,%rcx
28390@@ -30,6 +30,7 @@
28391 movl %edx,%ecx
28392 rep stosb
28393 movq %r9,%rax
28394+ pax_force_retaddr
28395 ret
28396 .Lmemset_e:
28397 .previous
28398@@ -45,13 +46,14 @@
28399 *
28400 * rax original destination
28401 */
28402- .section .altinstr_replacement, "ax", @progbits
28403+ .section .altinstr_replacement, "a", @progbits
28404 .Lmemset_c_e:
28405 movq %rdi,%r9
28406 movb %sil,%al
28407 movq %rdx,%rcx
28408 rep stosb
28409 movq %r9,%rax
28410+ pax_force_retaddr
28411 ret
28412 .Lmemset_e_e:
28413 .previous
28414@@ -59,7 +61,7 @@
28415 ENTRY(memset)
28416 ENTRY(__memset)
28417 CFI_STARTPROC
28418- movq %rdi,%r10
28419+ movq %rdi,%r11
28420
28421 /* expand byte value */
28422 movzbl %sil,%ecx
28423@@ -117,7 +119,8 @@ ENTRY(__memset)
28424 jnz .Lloop_1
28425
28426 .Lende:
28427- movq %r10,%rax
28428+ movq %r11,%rax
28429+ pax_force_retaddr
28430 ret
28431
28432 CFI_RESTORE_STATE
28433diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
28434index c9f2d9b..e7fd2c0 100644
28435--- a/arch/x86/lib/mmx_32.c
28436+++ b/arch/x86/lib/mmx_32.c
28437@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
28438 {
28439 void *p;
28440 int i;
28441+ unsigned long cr0;
28442
28443 if (unlikely(in_interrupt()))
28444 return __memcpy(to, from, len);
28445@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
28446 kernel_fpu_begin();
28447
28448 __asm__ __volatile__ (
28449- "1: prefetch (%0)\n" /* This set is 28 bytes */
28450- " prefetch 64(%0)\n"
28451- " prefetch 128(%0)\n"
28452- " prefetch 192(%0)\n"
28453- " prefetch 256(%0)\n"
28454+ "1: prefetch (%1)\n" /* This set is 28 bytes */
28455+ " prefetch 64(%1)\n"
28456+ " prefetch 128(%1)\n"
28457+ " prefetch 192(%1)\n"
28458+ " prefetch 256(%1)\n"
28459 "2: \n"
28460 ".section .fixup, \"ax\"\n"
28461- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28462+ "3: \n"
28463+
28464+#ifdef CONFIG_PAX_KERNEXEC
28465+ " movl %%cr0, %0\n"
28466+ " movl %0, %%eax\n"
28467+ " andl $0xFFFEFFFF, %%eax\n"
28468+ " movl %%eax, %%cr0\n"
28469+#endif
28470+
28471+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28472+
28473+#ifdef CONFIG_PAX_KERNEXEC
28474+ " movl %0, %%cr0\n"
28475+#endif
28476+
28477 " jmp 2b\n"
28478 ".previous\n"
28479 _ASM_EXTABLE(1b, 3b)
28480- : : "r" (from));
28481+ : "=&r" (cr0) : "r" (from) : "ax");
28482
28483 for ( ; i > 5; i--) {
28484 __asm__ __volatile__ (
28485- "1: prefetch 320(%0)\n"
28486- "2: movq (%0), %%mm0\n"
28487- " movq 8(%0), %%mm1\n"
28488- " movq 16(%0), %%mm2\n"
28489- " movq 24(%0), %%mm3\n"
28490- " movq %%mm0, (%1)\n"
28491- " movq %%mm1, 8(%1)\n"
28492- " movq %%mm2, 16(%1)\n"
28493- " movq %%mm3, 24(%1)\n"
28494- " movq 32(%0), %%mm0\n"
28495- " movq 40(%0), %%mm1\n"
28496- " movq 48(%0), %%mm2\n"
28497- " movq 56(%0), %%mm3\n"
28498- " movq %%mm0, 32(%1)\n"
28499- " movq %%mm1, 40(%1)\n"
28500- " movq %%mm2, 48(%1)\n"
28501- " movq %%mm3, 56(%1)\n"
28502+ "1: prefetch 320(%1)\n"
28503+ "2: movq (%1), %%mm0\n"
28504+ " movq 8(%1), %%mm1\n"
28505+ " movq 16(%1), %%mm2\n"
28506+ " movq 24(%1), %%mm3\n"
28507+ " movq %%mm0, (%2)\n"
28508+ " movq %%mm1, 8(%2)\n"
28509+ " movq %%mm2, 16(%2)\n"
28510+ " movq %%mm3, 24(%2)\n"
28511+ " movq 32(%1), %%mm0\n"
28512+ " movq 40(%1), %%mm1\n"
28513+ " movq 48(%1), %%mm2\n"
28514+ " movq 56(%1), %%mm3\n"
28515+ " movq %%mm0, 32(%2)\n"
28516+ " movq %%mm1, 40(%2)\n"
28517+ " movq %%mm2, 48(%2)\n"
28518+ " movq %%mm3, 56(%2)\n"
28519 ".section .fixup, \"ax\"\n"
28520- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28521+ "3:\n"
28522+
28523+#ifdef CONFIG_PAX_KERNEXEC
28524+ " movl %%cr0, %0\n"
28525+ " movl %0, %%eax\n"
28526+ " andl $0xFFFEFFFF, %%eax\n"
28527+ " movl %%eax, %%cr0\n"
28528+#endif
28529+
28530+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28531+
28532+#ifdef CONFIG_PAX_KERNEXEC
28533+ " movl %0, %%cr0\n"
28534+#endif
28535+
28536 " jmp 2b\n"
28537 ".previous\n"
28538 _ASM_EXTABLE(1b, 3b)
28539- : : "r" (from), "r" (to) : "memory");
28540+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
28541
28542 from += 64;
28543 to += 64;
28544@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
28545 static void fast_copy_page(void *to, void *from)
28546 {
28547 int i;
28548+ unsigned long cr0;
28549
28550 kernel_fpu_begin();
28551
28552@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
28553 * but that is for later. -AV
28554 */
28555 __asm__ __volatile__(
28556- "1: prefetch (%0)\n"
28557- " prefetch 64(%0)\n"
28558- " prefetch 128(%0)\n"
28559- " prefetch 192(%0)\n"
28560- " prefetch 256(%0)\n"
28561+ "1: prefetch (%1)\n"
28562+ " prefetch 64(%1)\n"
28563+ " prefetch 128(%1)\n"
28564+ " prefetch 192(%1)\n"
28565+ " prefetch 256(%1)\n"
28566 "2: \n"
28567 ".section .fixup, \"ax\"\n"
28568- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28569+ "3: \n"
28570+
28571+#ifdef CONFIG_PAX_KERNEXEC
28572+ " movl %%cr0, %0\n"
28573+ " movl %0, %%eax\n"
28574+ " andl $0xFFFEFFFF, %%eax\n"
28575+ " movl %%eax, %%cr0\n"
28576+#endif
28577+
28578+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28579+
28580+#ifdef CONFIG_PAX_KERNEXEC
28581+ " movl %0, %%cr0\n"
28582+#endif
28583+
28584 " jmp 2b\n"
28585 ".previous\n"
28586- _ASM_EXTABLE(1b, 3b) : : "r" (from));
28587+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
28588
28589 for (i = 0; i < (4096-320)/64; i++) {
28590 __asm__ __volatile__ (
28591- "1: prefetch 320(%0)\n"
28592- "2: movq (%0), %%mm0\n"
28593- " movntq %%mm0, (%1)\n"
28594- " movq 8(%0), %%mm1\n"
28595- " movntq %%mm1, 8(%1)\n"
28596- " movq 16(%0), %%mm2\n"
28597- " movntq %%mm2, 16(%1)\n"
28598- " movq 24(%0), %%mm3\n"
28599- " movntq %%mm3, 24(%1)\n"
28600- " movq 32(%0), %%mm4\n"
28601- " movntq %%mm4, 32(%1)\n"
28602- " movq 40(%0), %%mm5\n"
28603- " movntq %%mm5, 40(%1)\n"
28604- " movq 48(%0), %%mm6\n"
28605- " movntq %%mm6, 48(%1)\n"
28606- " movq 56(%0), %%mm7\n"
28607- " movntq %%mm7, 56(%1)\n"
28608+ "1: prefetch 320(%1)\n"
28609+ "2: movq (%1), %%mm0\n"
28610+ " movntq %%mm0, (%2)\n"
28611+ " movq 8(%1), %%mm1\n"
28612+ " movntq %%mm1, 8(%2)\n"
28613+ " movq 16(%1), %%mm2\n"
28614+ " movntq %%mm2, 16(%2)\n"
28615+ " movq 24(%1), %%mm3\n"
28616+ " movntq %%mm3, 24(%2)\n"
28617+ " movq 32(%1), %%mm4\n"
28618+ " movntq %%mm4, 32(%2)\n"
28619+ " movq 40(%1), %%mm5\n"
28620+ " movntq %%mm5, 40(%2)\n"
28621+ " movq 48(%1), %%mm6\n"
28622+ " movntq %%mm6, 48(%2)\n"
28623+ " movq 56(%1), %%mm7\n"
28624+ " movntq %%mm7, 56(%2)\n"
28625 ".section .fixup, \"ax\"\n"
28626- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28627+ "3:\n"
28628+
28629+#ifdef CONFIG_PAX_KERNEXEC
28630+ " movl %%cr0, %0\n"
28631+ " movl %0, %%eax\n"
28632+ " andl $0xFFFEFFFF, %%eax\n"
28633+ " movl %%eax, %%cr0\n"
28634+#endif
28635+
28636+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28637+
28638+#ifdef CONFIG_PAX_KERNEXEC
28639+ " movl %0, %%cr0\n"
28640+#endif
28641+
28642 " jmp 2b\n"
28643 ".previous\n"
28644- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
28645+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
28646
28647 from += 64;
28648 to += 64;
28649@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
28650 static void fast_copy_page(void *to, void *from)
28651 {
28652 int i;
28653+ unsigned long cr0;
28654
28655 kernel_fpu_begin();
28656
28657 __asm__ __volatile__ (
28658- "1: prefetch (%0)\n"
28659- " prefetch 64(%0)\n"
28660- " prefetch 128(%0)\n"
28661- " prefetch 192(%0)\n"
28662- " prefetch 256(%0)\n"
28663+ "1: prefetch (%1)\n"
28664+ " prefetch 64(%1)\n"
28665+ " prefetch 128(%1)\n"
28666+ " prefetch 192(%1)\n"
28667+ " prefetch 256(%1)\n"
28668 "2: \n"
28669 ".section .fixup, \"ax\"\n"
28670- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28671+ "3: \n"
28672+
28673+#ifdef CONFIG_PAX_KERNEXEC
28674+ " movl %%cr0, %0\n"
28675+ " movl %0, %%eax\n"
28676+ " andl $0xFFFEFFFF, %%eax\n"
28677+ " movl %%eax, %%cr0\n"
28678+#endif
28679+
28680+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28681+
28682+#ifdef CONFIG_PAX_KERNEXEC
28683+ " movl %0, %%cr0\n"
28684+#endif
28685+
28686 " jmp 2b\n"
28687 ".previous\n"
28688- _ASM_EXTABLE(1b, 3b) : : "r" (from));
28689+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
28690
28691 for (i = 0; i < 4096/64; i++) {
28692 __asm__ __volatile__ (
28693- "1: prefetch 320(%0)\n"
28694- "2: movq (%0), %%mm0\n"
28695- " movq 8(%0), %%mm1\n"
28696- " movq 16(%0), %%mm2\n"
28697- " movq 24(%0), %%mm3\n"
28698- " movq %%mm0, (%1)\n"
28699- " movq %%mm1, 8(%1)\n"
28700- " movq %%mm2, 16(%1)\n"
28701- " movq %%mm3, 24(%1)\n"
28702- " movq 32(%0), %%mm0\n"
28703- " movq 40(%0), %%mm1\n"
28704- " movq 48(%0), %%mm2\n"
28705- " movq 56(%0), %%mm3\n"
28706- " movq %%mm0, 32(%1)\n"
28707- " movq %%mm1, 40(%1)\n"
28708- " movq %%mm2, 48(%1)\n"
28709- " movq %%mm3, 56(%1)\n"
28710+ "1: prefetch 320(%1)\n"
28711+ "2: movq (%1), %%mm0\n"
28712+ " movq 8(%1), %%mm1\n"
28713+ " movq 16(%1), %%mm2\n"
28714+ " movq 24(%1), %%mm3\n"
28715+ " movq %%mm0, (%2)\n"
28716+ " movq %%mm1, 8(%2)\n"
28717+ " movq %%mm2, 16(%2)\n"
28718+ " movq %%mm3, 24(%2)\n"
28719+ " movq 32(%1), %%mm0\n"
28720+ " movq 40(%1), %%mm1\n"
28721+ " movq 48(%1), %%mm2\n"
28722+ " movq 56(%1), %%mm3\n"
28723+ " movq %%mm0, 32(%2)\n"
28724+ " movq %%mm1, 40(%2)\n"
28725+ " movq %%mm2, 48(%2)\n"
28726+ " movq %%mm3, 56(%2)\n"
28727 ".section .fixup, \"ax\"\n"
28728- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28729+ "3:\n"
28730+
28731+#ifdef CONFIG_PAX_KERNEXEC
28732+ " movl %%cr0, %0\n"
28733+ " movl %0, %%eax\n"
28734+ " andl $0xFFFEFFFF, %%eax\n"
28735+ " movl %%eax, %%cr0\n"
28736+#endif
28737+
28738+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28739+
28740+#ifdef CONFIG_PAX_KERNEXEC
28741+ " movl %0, %%cr0\n"
28742+#endif
28743+
28744 " jmp 2b\n"
28745 ".previous\n"
28746 _ASM_EXTABLE(1b, 3b)
28747- : : "r" (from), "r" (to) : "memory");
28748+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
28749
28750 from += 64;
28751 to += 64;
28752diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
28753index f6d13ee..aca5f0b 100644
28754--- a/arch/x86/lib/msr-reg.S
28755+++ b/arch/x86/lib/msr-reg.S
28756@@ -3,6 +3,7 @@
28757 #include <asm/dwarf2.h>
28758 #include <asm/asm.h>
28759 #include <asm/msr.h>
28760+#include <asm/alternative-asm.h>
28761
28762 #ifdef CONFIG_X86_64
28763 /*
28764@@ -16,7 +17,7 @@ ENTRY(\op\()_safe_regs)
28765 CFI_STARTPROC
28766 pushq_cfi %rbx
28767 pushq_cfi %rbp
28768- movq %rdi, %r10 /* Save pointer */
28769+ movq %rdi, %r9 /* Save pointer */
28770 xorl %r11d, %r11d /* Return value */
28771 movl (%rdi), %eax
28772 movl 4(%rdi), %ecx
28773@@ -27,16 +28,17 @@ ENTRY(\op\()_safe_regs)
28774 movl 28(%rdi), %edi
28775 CFI_REMEMBER_STATE
28776 1: \op
28777-2: movl %eax, (%r10)
28778+2: movl %eax, (%r9)
28779 movl %r11d, %eax /* Return value */
28780- movl %ecx, 4(%r10)
28781- movl %edx, 8(%r10)
28782- movl %ebx, 12(%r10)
28783- movl %ebp, 20(%r10)
28784- movl %esi, 24(%r10)
28785- movl %edi, 28(%r10)
28786+ movl %ecx, 4(%r9)
28787+ movl %edx, 8(%r9)
28788+ movl %ebx, 12(%r9)
28789+ movl %ebp, 20(%r9)
28790+ movl %esi, 24(%r9)
28791+ movl %edi, 28(%r9)
28792 popq_cfi %rbp
28793 popq_cfi %rbx
28794+ pax_force_retaddr
28795 ret
28796 3:
28797 CFI_RESTORE_STATE
28798diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
28799index fc6ba17..d4d989d 100644
28800--- a/arch/x86/lib/putuser.S
28801+++ b/arch/x86/lib/putuser.S
28802@@ -16,7 +16,9 @@
28803 #include <asm/errno.h>
28804 #include <asm/asm.h>
28805 #include <asm/smap.h>
28806-
28807+#include <asm/segment.h>
28808+#include <asm/pgtable.h>
28809+#include <asm/alternative-asm.h>
28810
28811 /*
28812 * __put_user_X
28813@@ -30,57 +32,125 @@
28814 * as they get called from within inline assembly.
28815 */
28816
28817-#define ENTER CFI_STARTPROC ; \
28818- GET_THREAD_INFO(%_ASM_BX)
28819-#define EXIT ASM_CLAC ; \
28820- ret ; \
28821+#define ENTER CFI_STARTPROC
28822+#define EXIT ASM_CLAC ; \
28823+ pax_force_retaddr ; \
28824+ ret ; \
28825 CFI_ENDPROC
28826
28827+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28828+#define _DEST %_ASM_CX,%_ASM_BX
28829+#else
28830+#define _DEST %_ASM_CX
28831+#endif
28832+
28833+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
28834+#define __copyuser_seg gs;
28835+#else
28836+#define __copyuser_seg
28837+#endif
28838+
28839 .text
28840 ENTRY(__put_user_1)
28841 ENTER
28842+
28843+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28844+ GET_THREAD_INFO(%_ASM_BX)
28845 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
28846 jae bad_put_user
28847 ASM_STAC
28848-1: movb %al,(%_ASM_CX)
28849+
28850+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28851+ mov pax_user_shadow_base,%_ASM_BX
28852+ cmp %_ASM_BX,%_ASM_CX
28853+ jb 1234f
28854+ xor %ebx,%ebx
28855+1234:
28856+#endif
28857+
28858+#endif
28859+
28860+1: __copyuser_seg movb %al,(_DEST)
28861 xor %eax,%eax
28862 EXIT
28863 ENDPROC(__put_user_1)
28864
28865 ENTRY(__put_user_2)
28866 ENTER
28867+
28868+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28869+ GET_THREAD_INFO(%_ASM_BX)
28870 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
28871 sub $1,%_ASM_BX
28872 cmp %_ASM_BX,%_ASM_CX
28873 jae bad_put_user
28874 ASM_STAC
28875-2: movw %ax,(%_ASM_CX)
28876+
28877+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28878+ mov pax_user_shadow_base,%_ASM_BX
28879+ cmp %_ASM_BX,%_ASM_CX
28880+ jb 1234f
28881+ xor %ebx,%ebx
28882+1234:
28883+#endif
28884+
28885+#endif
28886+
28887+2: __copyuser_seg movw %ax,(_DEST)
28888 xor %eax,%eax
28889 EXIT
28890 ENDPROC(__put_user_2)
28891
28892 ENTRY(__put_user_4)
28893 ENTER
28894+
28895+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28896+ GET_THREAD_INFO(%_ASM_BX)
28897 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
28898 sub $3,%_ASM_BX
28899 cmp %_ASM_BX,%_ASM_CX
28900 jae bad_put_user
28901 ASM_STAC
28902-3: movl %eax,(%_ASM_CX)
28903+
28904+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28905+ mov pax_user_shadow_base,%_ASM_BX
28906+ cmp %_ASM_BX,%_ASM_CX
28907+ jb 1234f
28908+ xor %ebx,%ebx
28909+1234:
28910+#endif
28911+
28912+#endif
28913+
28914+3: __copyuser_seg movl %eax,(_DEST)
28915 xor %eax,%eax
28916 EXIT
28917 ENDPROC(__put_user_4)
28918
28919 ENTRY(__put_user_8)
28920 ENTER
28921+
28922+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28923+ GET_THREAD_INFO(%_ASM_BX)
28924 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
28925 sub $7,%_ASM_BX
28926 cmp %_ASM_BX,%_ASM_CX
28927 jae bad_put_user
28928 ASM_STAC
28929-4: mov %_ASM_AX,(%_ASM_CX)
28930+
28931+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28932+ mov pax_user_shadow_base,%_ASM_BX
28933+ cmp %_ASM_BX,%_ASM_CX
28934+ jb 1234f
28935+ xor %ebx,%ebx
28936+1234:
28937+#endif
28938+
28939+#endif
28940+
28941+4: __copyuser_seg mov %_ASM_AX,(_DEST)
28942 #ifdef CONFIG_X86_32
28943-5: movl %edx,4(%_ASM_CX)
28944+5: __copyuser_seg movl %edx,4(_DEST)
28945 #endif
28946 xor %eax,%eax
28947 EXIT
28948diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
28949index 1cad221..de671ee 100644
28950--- a/arch/x86/lib/rwlock.S
28951+++ b/arch/x86/lib/rwlock.S
28952@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
28953 FRAME
28954 0: LOCK_PREFIX
28955 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
28956+
28957+#ifdef CONFIG_PAX_REFCOUNT
28958+ jno 1234f
28959+ LOCK_PREFIX
28960+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
28961+ int $4
28962+1234:
28963+ _ASM_EXTABLE(1234b, 1234b)
28964+#endif
28965+
28966 1: rep; nop
28967 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
28968 jne 1b
28969 LOCK_PREFIX
28970 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
28971+
28972+#ifdef CONFIG_PAX_REFCOUNT
28973+ jno 1234f
28974+ LOCK_PREFIX
28975+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
28976+ int $4
28977+1234:
28978+ _ASM_EXTABLE(1234b, 1234b)
28979+#endif
28980+
28981 jnz 0b
28982 ENDFRAME
28983+ pax_force_retaddr
28984 ret
28985 CFI_ENDPROC
28986 END(__write_lock_failed)
28987@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
28988 FRAME
28989 0: LOCK_PREFIX
28990 READ_LOCK_SIZE(inc) (%__lock_ptr)
28991+
28992+#ifdef CONFIG_PAX_REFCOUNT
28993+ jno 1234f
28994+ LOCK_PREFIX
28995+ READ_LOCK_SIZE(dec) (%__lock_ptr)
28996+ int $4
28997+1234:
28998+ _ASM_EXTABLE(1234b, 1234b)
28999+#endif
29000+
29001 1: rep; nop
29002 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
29003 js 1b
29004 LOCK_PREFIX
29005 READ_LOCK_SIZE(dec) (%__lock_ptr)
29006+
29007+#ifdef CONFIG_PAX_REFCOUNT
29008+ jno 1234f
29009+ LOCK_PREFIX
29010+ READ_LOCK_SIZE(inc) (%__lock_ptr)
29011+ int $4
29012+1234:
29013+ _ASM_EXTABLE(1234b, 1234b)
29014+#endif
29015+
29016 js 0b
29017 ENDFRAME
29018+ pax_force_retaddr
29019 ret
29020 CFI_ENDPROC
29021 END(__read_lock_failed)
29022diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
29023index 5dff5f0..cadebf4 100644
29024--- a/arch/x86/lib/rwsem.S
29025+++ b/arch/x86/lib/rwsem.S
29026@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
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_down_read_failed)
29034@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
29035 movq %rax,%rdi
29036 call rwsem_down_write_failed
29037 restore_common_regs
29038+ pax_force_retaddr
29039 ret
29040 CFI_ENDPROC
29041 ENDPROC(call_rwsem_down_write_failed)
29042@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
29043 movq %rax,%rdi
29044 call rwsem_wake
29045 restore_common_regs
29046-1: ret
29047+1: pax_force_retaddr
29048+ ret
29049 CFI_ENDPROC
29050 ENDPROC(call_rwsem_wake)
29051
29052@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
29053 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
29054 CFI_RESTORE __ASM_REG(dx)
29055 restore_common_regs
29056+ pax_force_retaddr
29057 ret
29058 CFI_ENDPROC
29059 ENDPROC(call_rwsem_downgrade_wake)
29060diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
29061index a63efd6..ccecad8 100644
29062--- a/arch/x86/lib/thunk_64.S
29063+++ b/arch/x86/lib/thunk_64.S
29064@@ -8,6 +8,7 @@
29065 #include <linux/linkage.h>
29066 #include <asm/dwarf2.h>
29067 #include <asm/calling.h>
29068+#include <asm/alternative-asm.h>
29069
29070 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
29071 .macro THUNK name, func, put_ret_addr_in_rdi=0
29072@@ -41,5 +42,6 @@
29073 SAVE_ARGS
29074 restore:
29075 RESTORE_ARGS
29076+ pax_force_retaddr
29077 ret
29078 CFI_ENDPROC
29079diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
29080index 3eb18ac..6890bc3 100644
29081--- a/arch/x86/lib/usercopy_32.c
29082+++ b/arch/x86/lib/usercopy_32.c
29083@@ -42,11 +42,13 @@ do { \
29084 int __d0; \
29085 might_fault(); \
29086 __asm__ __volatile__( \
29087+ __COPYUSER_SET_ES \
29088 ASM_STAC "\n" \
29089 "0: rep; stosl\n" \
29090 " movl %2,%0\n" \
29091 "1: rep; stosb\n" \
29092 "2: " ASM_CLAC "\n" \
29093+ __COPYUSER_RESTORE_ES \
29094 ".section .fixup,\"ax\"\n" \
29095 "3: lea 0(%2,%0,4),%0\n" \
29096 " jmp 2b\n" \
29097@@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
29098
29099 #ifdef CONFIG_X86_INTEL_USERCOPY
29100 static unsigned long
29101-__copy_user_intel(void __user *to, const void *from, unsigned long size)
29102+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
29103 {
29104 int d0, d1;
29105 __asm__ __volatile__(
29106@@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
29107 " .align 2,0x90\n"
29108 "3: movl 0(%4), %%eax\n"
29109 "4: movl 4(%4), %%edx\n"
29110- "5: movl %%eax, 0(%3)\n"
29111- "6: movl %%edx, 4(%3)\n"
29112+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
29113+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
29114 "7: movl 8(%4), %%eax\n"
29115 "8: movl 12(%4),%%edx\n"
29116- "9: movl %%eax, 8(%3)\n"
29117- "10: movl %%edx, 12(%3)\n"
29118+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
29119+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
29120 "11: movl 16(%4), %%eax\n"
29121 "12: movl 20(%4), %%edx\n"
29122- "13: movl %%eax, 16(%3)\n"
29123- "14: movl %%edx, 20(%3)\n"
29124+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
29125+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
29126 "15: movl 24(%4), %%eax\n"
29127 "16: movl 28(%4), %%edx\n"
29128- "17: movl %%eax, 24(%3)\n"
29129- "18: movl %%edx, 28(%3)\n"
29130+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
29131+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
29132 "19: movl 32(%4), %%eax\n"
29133 "20: movl 36(%4), %%edx\n"
29134- "21: movl %%eax, 32(%3)\n"
29135- "22: movl %%edx, 36(%3)\n"
29136+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
29137+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
29138 "23: movl 40(%4), %%eax\n"
29139 "24: movl 44(%4), %%edx\n"
29140- "25: movl %%eax, 40(%3)\n"
29141- "26: movl %%edx, 44(%3)\n"
29142+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
29143+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
29144 "27: movl 48(%4), %%eax\n"
29145 "28: movl 52(%4), %%edx\n"
29146- "29: movl %%eax, 48(%3)\n"
29147- "30: movl %%edx, 52(%3)\n"
29148+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
29149+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
29150 "31: movl 56(%4), %%eax\n"
29151 "32: movl 60(%4), %%edx\n"
29152- "33: movl %%eax, 56(%3)\n"
29153- "34: movl %%edx, 60(%3)\n"
29154+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
29155+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
29156 " addl $-64, %0\n"
29157 " addl $64, %4\n"
29158 " addl $64, %3\n"
29159@@ -149,10 +151,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
29160 " shrl $2, %0\n"
29161 " andl $3, %%eax\n"
29162 " cld\n"
29163+ __COPYUSER_SET_ES
29164 "99: rep; movsl\n"
29165 "36: movl %%eax, %0\n"
29166 "37: rep; movsb\n"
29167 "100:\n"
29168+ __COPYUSER_RESTORE_ES
29169 ".section .fixup,\"ax\"\n"
29170 "101: lea 0(%%eax,%0,4),%0\n"
29171 " jmp 100b\n"
29172@@ -202,46 +206,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
29173 }
29174
29175 static unsigned long
29176+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
29177+{
29178+ int d0, d1;
29179+ __asm__ __volatile__(
29180+ " .align 2,0x90\n"
29181+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
29182+ " cmpl $67, %0\n"
29183+ " jbe 3f\n"
29184+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
29185+ " .align 2,0x90\n"
29186+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
29187+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
29188+ "5: movl %%eax, 0(%3)\n"
29189+ "6: movl %%edx, 4(%3)\n"
29190+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
29191+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
29192+ "9: movl %%eax, 8(%3)\n"
29193+ "10: movl %%edx, 12(%3)\n"
29194+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
29195+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
29196+ "13: movl %%eax, 16(%3)\n"
29197+ "14: movl %%edx, 20(%3)\n"
29198+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
29199+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
29200+ "17: movl %%eax, 24(%3)\n"
29201+ "18: movl %%edx, 28(%3)\n"
29202+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
29203+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
29204+ "21: movl %%eax, 32(%3)\n"
29205+ "22: movl %%edx, 36(%3)\n"
29206+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
29207+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
29208+ "25: movl %%eax, 40(%3)\n"
29209+ "26: movl %%edx, 44(%3)\n"
29210+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
29211+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
29212+ "29: movl %%eax, 48(%3)\n"
29213+ "30: movl %%edx, 52(%3)\n"
29214+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
29215+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
29216+ "33: movl %%eax, 56(%3)\n"
29217+ "34: movl %%edx, 60(%3)\n"
29218+ " addl $-64, %0\n"
29219+ " addl $64, %4\n"
29220+ " addl $64, %3\n"
29221+ " cmpl $63, %0\n"
29222+ " ja 1b\n"
29223+ "35: movl %0, %%eax\n"
29224+ " shrl $2, %0\n"
29225+ " andl $3, %%eax\n"
29226+ " cld\n"
29227+ "99: rep; "__copyuser_seg" movsl\n"
29228+ "36: movl %%eax, %0\n"
29229+ "37: rep; "__copyuser_seg" movsb\n"
29230+ "100:\n"
29231+ ".section .fixup,\"ax\"\n"
29232+ "101: lea 0(%%eax,%0,4),%0\n"
29233+ " jmp 100b\n"
29234+ ".previous\n"
29235+ _ASM_EXTABLE(1b,100b)
29236+ _ASM_EXTABLE(2b,100b)
29237+ _ASM_EXTABLE(3b,100b)
29238+ _ASM_EXTABLE(4b,100b)
29239+ _ASM_EXTABLE(5b,100b)
29240+ _ASM_EXTABLE(6b,100b)
29241+ _ASM_EXTABLE(7b,100b)
29242+ _ASM_EXTABLE(8b,100b)
29243+ _ASM_EXTABLE(9b,100b)
29244+ _ASM_EXTABLE(10b,100b)
29245+ _ASM_EXTABLE(11b,100b)
29246+ _ASM_EXTABLE(12b,100b)
29247+ _ASM_EXTABLE(13b,100b)
29248+ _ASM_EXTABLE(14b,100b)
29249+ _ASM_EXTABLE(15b,100b)
29250+ _ASM_EXTABLE(16b,100b)
29251+ _ASM_EXTABLE(17b,100b)
29252+ _ASM_EXTABLE(18b,100b)
29253+ _ASM_EXTABLE(19b,100b)
29254+ _ASM_EXTABLE(20b,100b)
29255+ _ASM_EXTABLE(21b,100b)
29256+ _ASM_EXTABLE(22b,100b)
29257+ _ASM_EXTABLE(23b,100b)
29258+ _ASM_EXTABLE(24b,100b)
29259+ _ASM_EXTABLE(25b,100b)
29260+ _ASM_EXTABLE(26b,100b)
29261+ _ASM_EXTABLE(27b,100b)
29262+ _ASM_EXTABLE(28b,100b)
29263+ _ASM_EXTABLE(29b,100b)
29264+ _ASM_EXTABLE(30b,100b)
29265+ _ASM_EXTABLE(31b,100b)
29266+ _ASM_EXTABLE(32b,100b)
29267+ _ASM_EXTABLE(33b,100b)
29268+ _ASM_EXTABLE(34b,100b)
29269+ _ASM_EXTABLE(35b,100b)
29270+ _ASM_EXTABLE(36b,100b)
29271+ _ASM_EXTABLE(37b,100b)
29272+ _ASM_EXTABLE(99b,101b)
29273+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
29274+ : "1"(to), "2"(from), "0"(size)
29275+ : "eax", "edx", "memory");
29276+ return size;
29277+}
29278+
29279+static unsigned long __size_overflow(3)
29280 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
29281 {
29282 int d0, d1;
29283 __asm__ __volatile__(
29284 " .align 2,0x90\n"
29285- "0: movl 32(%4), %%eax\n"
29286+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
29287 " cmpl $67, %0\n"
29288 " jbe 2f\n"
29289- "1: movl 64(%4), %%eax\n"
29290+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
29291 " .align 2,0x90\n"
29292- "2: movl 0(%4), %%eax\n"
29293- "21: movl 4(%4), %%edx\n"
29294+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
29295+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
29296 " movl %%eax, 0(%3)\n"
29297 " movl %%edx, 4(%3)\n"
29298- "3: movl 8(%4), %%eax\n"
29299- "31: movl 12(%4),%%edx\n"
29300+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
29301+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
29302 " movl %%eax, 8(%3)\n"
29303 " movl %%edx, 12(%3)\n"
29304- "4: movl 16(%4), %%eax\n"
29305- "41: movl 20(%4), %%edx\n"
29306+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
29307+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
29308 " movl %%eax, 16(%3)\n"
29309 " movl %%edx, 20(%3)\n"
29310- "10: movl 24(%4), %%eax\n"
29311- "51: movl 28(%4), %%edx\n"
29312+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
29313+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
29314 " movl %%eax, 24(%3)\n"
29315 " movl %%edx, 28(%3)\n"
29316- "11: movl 32(%4), %%eax\n"
29317- "61: movl 36(%4), %%edx\n"
29318+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
29319+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
29320 " movl %%eax, 32(%3)\n"
29321 " movl %%edx, 36(%3)\n"
29322- "12: movl 40(%4), %%eax\n"
29323- "71: movl 44(%4), %%edx\n"
29324+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
29325+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
29326 " movl %%eax, 40(%3)\n"
29327 " movl %%edx, 44(%3)\n"
29328- "13: movl 48(%4), %%eax\n"
29329- "81: movl 52(%4), %%edx\n"
29330+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
29331+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
29332 " movl %%eax, 48(%3)\n"
29333 " movl %%edx, 52(%3)\n"
29334- "14: movl 56(%4), %%eax\n"
29335- "91: movl 60(%4), %%edx\n"
29336+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
29337+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
29338 " movl %%eax, 56(%3)\n"
29339 " movl %%edx, 60(%3)\n"
29340 " addl $-64, %0\n"
29341@@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
29342 " shrl $2, %0\n"
29343 " andl $3, %%eax\n"
29344 " cld\n"
29345- "6: rep; movsl\n"
29346+ "6: rep; "__copyuser_seg" movsl\n"
29347 " movl %%eax,%0\n"
29348- "7: rep; movsb\n"
29349+ "7: rep; "__copyuser_seg" movsb\n"
29350 "8:\n"
29351 ".section .fixup,\"ax\"\n"
29352 "9: lea 0(%%eax,%0,4),%0\n"
29353@@ -298,48 +406,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
29354 * hyoshiok@miraclelinux.com
29355 */
29356
29357-static unsigned long __copy_user_zeroing_intel_nocache(void *to,
29358+static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
29359 const void __user *from, unsigned long size)
29360 {
29361 int d0, d1;
29362
29363 __asm__ __volatile__(
29364 " .align 2,0x90\n"
29365- "0: movl 32(%4), %%eax\n"
29366+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
29367 " cmpl $67, %0\n"
29368 " jbe 2f\n"
29369- "1: movl 64(%4), %%eax\n"
29370+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
29371 " .align 2,0x90\n"
29372- "2: movl 0(%4), %%eax\n"
29373- "21: movl 4(%4), %%edx\n"
29374+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
29375+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
29376 " movnti %%eax, 0(%3)\n"
29377 " movnti %%edx, 4(%3)\n"
29378- "3: movl 8(%4), %%eax\n"
29379- "31: movl 12(%4),%%edx\n"
29380+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
29381+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
29382 " movnti %%eax, 8(%3)\n"
29383 " movnti %%edx, 12(%3)\n"
29384- "4: movl 16(%4), %%eax\n"
29385- "41: movl 20(%4), %%edx\n"
29386+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
29387+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
29388 " movnti %%eax, 16(%3)\n"
29389 " movnti %%edx, 20(%3)\n"
29390- "10: movl 24(%4), %%eax\n"
29391- "51: movl 28(%4), %%edx\n"
29392+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
29393+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
29394 " movnti %%eax, 24(%3)\n"
29395 " movnti %%edx, 28(%3)\n"
29396- "11: movl 32(%4), %%eax\n"
29397- "61: movl 36(%4), %%edx\n"
29398+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
29399+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
29400 " movnti %%eax, 32(%3)\n"
29401 " movnti %%edx, 36(%3)\n"
29402- "12: movl 40(%4), %%eax\n"
29403- "71: movl 44(%4), %%edx\n"
29404+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
29405+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
29406 " movnti %%eax, 40(%3)\n"
29407 " movnti %%edx, 44(%3)\n"
29408- "13: movl 48(%4), %%eax\n"
29409- "81: movl 52(%4), %%edx\n"
29410+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
29411+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
29412 " movnti %%eax, 48(%3)\n"
29413 " movnti %%edx, 52(%3)\n"
29414- "14: movl 56(%4), %%eax\n"
29415- "91: movl 60(%4), %%edx\n"
29416+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
29417+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
29418 " movnti %%eax, 56(%3)\n"
29419 " movnti %%edx, 60(%3)\n"
29420 " addl $-64, %0\n"
29421@@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
29422 " shrl $2, %0\n"
29423 " andl $3, %%eax\n"
29424 " cld\n"
29425- "6: rep; movsl\n"
29426+ "6: rep; "__copyuser_seg" movsl\n"
29427 " movl %%eax,%0\n"
29428- "7: rep; movsb\n"
29429+ "7: rep; "__copyuser_seg" movsb\n"
29430 "8:\n"
29431 ".section .fixup,\"ax\"\n"
29432 "9: lea 0(%%eax,%0,4),%0\n"
29433@@ -392,48 +500,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
29434 return size;
29435 }
29436
29437-static unsigned long __copy_user_intel_nocache(void *to,
29438+static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
29439 const void __user *from, unsigned long size)
29440 {
29441 int d0, d1;
29442
29443 __asm__ __volatile__(
29444 " .align 2,0x90\n"
29445- "0: movl 32(%4), %%eax\n"
29446+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
29447 " cmpl $67, %0\n"
29448 " jbe 2f\n"
29449- "1: movl 64(%4), %%eax\n"
29450+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
29451 " .align 2,0x90\n"
29452- "2: movl 0(%4), %%eax\n"
29453- "21: movl 4(%4), %%edx\n"
29454+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
29455+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
29456 " movnti %%eax, 0(%3)\n"
29457 " movnti %%edx, 4(%3)\n"
29458- "3: movl 8(%4), %%eax\n"
29459- "31: movl 12(%4),%%edx\n"
29460+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
29461+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
29462 " movnti %%eax, 8(%3)\n"
29463 " movnti %%edx, 12(%3)\n"
29464- "4: movl 16(%4), %%eax\n"
29465- "41: movl 20(%4), %%edx\n"
29466+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
29467+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
29468 " movnti %%eax, 16(%3)\n"
29469 " movnti %%edx, 20(%3)\n"
29470- "10: movl 24(%4), %%eax\n"
29471- "51: movl 28(%4), %%edx\n"
29472+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
29473+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
29474 " movnti %%eax, 24(%3)\n"
29475 " movnti %%edx, 28(%3)\n"
29476- "11: movl 32(%4), %%eax\n"
29477- "61: movl 36(%4), %%edx\n"
29478+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
29479+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
29480 " movnti %%eax, 32(%3)\n"
29481 " movnti %%edx, 36(%3)\n"
29482- "12: movl 40(%4), %%eax\n"
29483- "71: movl 44(%4), %%edx\n"
29484+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
29485+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
29486 " movnti %%eax, 40(%3)\n"
29487 " movnti %%edx, 44(%3)\n"
29488- "13: movl 48(%4), %%eax\n"
29489- "81: movl 52(%4), %%edx\n"
29490+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
29491+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
29492 " movnti %%eax, 48(%3)\n"
29493 " movnti %%edx, 52(%3)\n"
29494- "14: movl 56(%4), %%eax\n"
29495- "91: movl 60(%4), %%edx\n"
29496+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
29497+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
29498 " movnti %%eax, 56(%3)\n"
29499 " movnti %%edx, 60(%3)\n"
29500 " addl $-64, %0\n"
29501@@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
29502 " shrl $2, %0\n"
29503 " andl $3, %%eax\n"
29504 " cld\n"
29505- "6: rep; movsl\n"
29506+ "6: rep; "__copyuser_seg" movsl\n"
29507 " movl %%eax,%0\n"
29508- "7: rep; movsb\n"
29509+ "7: rep; "__copyuser_seg" movsb\n"
29510 "8:\n"
29511 ".section .fixup,\"ax\"\n"
29512 "9: lea 0(%%eax,%0,4),%0\n"
29513@@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
29514 */
29515 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
29516 unsigned long size);
29517-unsigned long __copy_user_intel(void __user *to, const void *from,
29518+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
29519+ unsigned long size);
29520+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
29521 unsigned long size);
29522 unsigned long __copy_user_zeroing_intel_nocache(void *to,
29523 const void __user *from, unsigned long size);
29524 #endif /* CONFIG_X86_INTEL_USERCOPY */
29525
29526 /* Generic arbitrary sized copy. */
29527-#define __copy_user(to, from, size) \
29528+#define __copy_user(to, from, size, prefix, set, restore) \
29529 do { \
29530 int __d0, __d1, __d2; \
29531 __asm__ __volatile__( \
29532+ set \
29533 " cmp $7,%0\n" \
29534 " jbe 1f\n" \
29535 " movl %1,%0\n" \
29536 " negl %0\n" \
29537 " andl $7,%0\n" \
29538 " subl %0,%3\n" \
29539- "4: rep; movsb\n" \
29540+ "4: rep; "prefix"movsb\n" \
29541 " movl %3,%0\n" \
29542 " shrl $2,%0\n" \
29543 " andl $3,%3\n" \
29544 " .align 2,0x90\n" \
29545- "0: rep; movsl\n" \
29546+ "0: rep; "prefix"movsl\n" \
29547 " movl %3,%0\n" \
29548- "1: rep; movsb\n" \
29549+ "1: rep; "prefix"movsb\n" \
29550 "2:\n" \
29551+ restore \
29552 ".section .fixup,\"ax\"\n" \
29553 "5: addl %3,%0\n" \
29554 " jmp 2b\n" \
29555@@ -538,14 +650,14 @@ do { \
29556 " negl %0\n" \
29557 " andl $7,%0\n" \
29558 " subl %0,%3\n" \
29559- "4: rep; movsb\n" \
29560+ "4: rep; "__copyuser_seg"movsb\n" \
29561 " movl %3,%0\n" \
29562 " shrl $2,%0\n" \
29563 " andl $3,%3\n" \
29564 " .align 2,0x90\n" \
29565- "0: rep; movsl\n" \
29566+ "0: rep; "__copyuser_seg"movsl\n" \
29567 " movl %3,%0\n" \
29568- "1: rep; movsb\n" \
29569+ "1: rep; "__copyuser_seg"movsb\n" \
29570 "2:\n" \
29571 ".section .fixup,\"ax\"\n" \
29572 "5: addl %3,%0\n" \
29573@@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
29574 {
29575 stac();
29576 if (movsl_is_ok(to, from, n))
29577- __copy_user(to, from, n);
29578+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
29579 else
29580- n = __copy_user_intel(to, from, n);
29581+ n = __generic_copy_to_user_intel(to, from, n);
29582 clac();
29583 return n;
29584 }
29585@@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
29586 {
29587 stac();
29588 if (movsl_is_ok(to, from, n))
29589- __copy_user(to, from, n);
29590+ __copy_user(to, from, n, __copyuser_seg, "", "");
29591 else
29592- n = __copy_user_intel((void __user *)to,
29593- (const void *)from, n);
29594+ n = __generic_copy_from_user_intel(to, from, n);
29595 clac();
29596 return n;
29597 }
29598@@ -632,60 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
29599 if (n > 64 && cpu_has_xmm2)
29600 n = __copy_user_intel_nocache(to, from, n);
29601 else
29602- __copy_user(to, from, n);
29603+ __copy_user(to, from, n, __copyuser_seg, "", "");
29604 #else
29605- __copy_user(to, from, n);
29606+ __copy_user(to, from, n, __copyuser_seg, "", "");
29607 #endif
29608 clac();
29609 return n;
29610 }
29611 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
29612
29613-/**
29614- * copy_to_user: - Copy a block of data into user space.
29615- * @to: Destination address, in user space.
29616- * @from: Source address, in kernel space.
29617- * @n: Number of bytes to copy.
29618- *
29619- * Context: User context only. This function may sleep.
29620- *
29621- * Copy data from kernel space to user space.
29622- *
29623- * Returns number of bytes that could not be copied.
29624- * On success, this will be zero.
29625- */
29626-unsigned long
29627-copy_to_user(void __user *to, const void *from, unsigned long n)
29628+#ifdef CONFIG_PAX_MEMORY_UDEREF
29629+void __set_fs(mm_segment_t x)
29630 {
29631- if (access_ok(VERIFY_WRITE, to, n))
29632- n = __copy_to_user(to, from, n);
29633- return n;
29634+ switch (x.seg) {
29635+ case 0:
29636+ loadsegment(gs, 0);
29637+ break;
29638+ case TASK_SIZE_MAX:
29639+ loadsegment(gs, __USER_DS);
29640+ break;
29641+ case -1UL:
29642+ loadsegment(gs, __KERNEL_DS);
29643+ break;
29644+ default:
29645+ BUG();
29646+ }
29647 }
29648-EXPORT_SYMBOL(copy_to_user);
29649+EXPORT_SYMBOL(__set_fs);
29650
29651-/**
29652- * copy_from_user: - Copy a block of data from user space.
29653- * @to: Destination address, in kernel space.
29654- * @from: Source address, in user space.
29655- * @n: Number of bytes to copy.
29656- *
29657- * Context: User context only. This function may sleep.
29658- *
29659- * Copy data from user space to kernel space.
29660- *
29661- * Returns number of bytes that could not be copied.
29662- * On success, this will be zero.
29663- *
29664- * If some data could not be copied, this function will pad the copied
29665- * data to the requested size using zero bytes.
29666- */
29667-unsigned long
29668-_copy_from_user(void *to, const void __user *from, unsigned long n)
29669+void set_fs(mm_segment_t x)
29670 {
29671- if (access_ok(VERIFY_READ, from, n))
29672- n = __copy_from_user(to, from, n);
29673- else
29674- memset(to, 0, n);
29675- return n;
29676+ current_thread_info()->addr_limit = x;
29677+ __set_fs(x);
29678 }
29679-EXPORT_SYMBOL(_copy_from_user);
29680+EXPORT_SYMBOL(set_fs);
29681+#endif
29682diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
29683index 906fea3..0194a18 100644
29684--- a/arch/x86/lib/usercopy_64.c
29685+++ b/arch/x86/lib/usercopy_64.c
29686@@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
29687 might_fault();
29688 /* no memory constraint because it doesn't change any memory gcc knows
29689 about */
29690+ pax_open_userland();
29691 stac();
29692 asm volatile(
29693 " testq %[size8],%[size8]\n"
29694@@ -39,9 +40,10 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
29695 _ASM_EXTABLE(0b,3b)
29696 _ASM_EXTABLE(1b,2b)
29697 : [size8] "=&c"(size), [dst] "=&D" (__d0)
29698- : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
29699+ : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
29700 [zero] "r" (0UL), [eight] "r" (8UL));
29701 clac();
29702+ pax_close_userland();
29703 return size;
29704 }
29705 EXPORT_SYMBOL(__clear_user);
29706@@ -54,12 +56,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
29707 }
29708 EXPORT_SYMBOL(clear_user);
29709
29710-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
29711+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
29712 {
29713- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
29714- return copy_user_generic((__force void *)to, (__force void *)from, len);
29715- }
29716- return len;
29717+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
29718+ return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
29719+ return len;
29720 }
29721 EXPORT_SYMBOL(copy_in_user);
29722
29723@@ -69,11 +70,13 @@ EXPORT_SYMBOL(copy_in_user);
29724 * it is not necessary to optimize tail handling.
29725 */
29726 unsigned long
29727-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
29728+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
29729 {
29730 char c;
29731 unsigned zero_len;
29732
29733+ clac();
29734+ pax_close_userland();
29735 for (; len; --len, to++) {
29736 if (__get_user_nocheck(c, from++, sizeof(char)))
29737 break;
29738@@ -84,6 +87,5 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
29739 for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
29740 if (__put_user_nocheck(c, to++, sizeof(char)))
29741 break;
29742- clac();
29743 return len;
29744 }
29745diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
29746index 23d8e5f..9ccc13a 100644
29747--- a/arch/x86/mm/Makefile
29748+++ b/arch/x86/mm/Makefile
29749@@ -28,3 +28,7 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o
29750 obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
29751
29752 obj-$(CONFIG_MEMTEST) += memtest.o
29753+
29754+quote:="
29755+obj-$(CONFIG_X86_64) += uderef_64.o
29756+CFLAGS_uderef_64.o := $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
29757diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
29758index 903ec1e..c4166b2 100644
29759--- a/arch/x86/mm/extable.c
29760+++ b/arch/x86/mm/extable.c
29761@@ -6,12 +6,24 @@
29762 static inline unsigned long
29763 ex_insn_addr(const struct exception_table_entry *x)
29764 {
29765- return (unsigned long)&x->insn + x->insn;
29766+ unsigned long reloc = 0;
29767+
29768+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
29769+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
29770+#endif
29771+
29772+ return (unsigned long)&x->insn + x->insn + reloc;
29773 }
29774 static inline unsigned long
29775 ex_fixup_addr(const struct exception_table_entry *x)
29776 {
29777- return (unsigned long)&x->fixup + x->fixup;
29778+ unsigned long reloc = 0;
29779+
29780+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
29781+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
29782+#endif
29783+
29784+ return (unsigned long)&x->fixup + x->fixup + reloc;
29785 }
29786
29787 int fixup_exception(struct pt_regs *regs)
29788@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
29789 unsigned long new_ip;
29790
29791 #ifdef CONFIG_PNPBIOS
29792- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
29793+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
29794 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
29795 extern u32 pnp_bios_is_utter_crap;
29796 pnp_bios_is_utter_crap = 1;
29797@@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
29798 i += 4;
29799 p->fixup -= i;
29800 i += 4;
29801+
29802+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
29803+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
29804+ p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
29805+ p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
29806+#endif
29807+
29808 }
29809 }
29810
29811diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
29812index 654be4a..a4a3da1 100644
29813--- a/arch/x86/mm/fault.c
29814+++ b/arch/x86/mm/fault.c
29815@@ -14,11 +14,18 @@
29816 #include <linux/hugetlb.h> /* hstate_index_to_shift */
29817 #include <linux/prefetch.h> /* prefetchw */
29818 #include <linux/context_tracking.h> /* exception_enter(), ... */
29819+#include <linux/unistd.h>
29820+#include <linux/compiler.h>
29821
29822 #include <asm/traps.h> /* dotraplinkage, ... */
29823 #include <asm/pgalloc.h> /* pgd_*(), ... */
29824 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
29825 #include <asm/fixmap.h> /* VSYSCALL_START */
29826+#include <asm/tlbflush.h>
29827+
29828+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29829+#include <asm/stacktrace.h>
29830+#endif
29831
29832 /*
29833 * Page fault error code bits:
29834@@ -56,7 +63,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
29835 int ret = 0;
29836
29837 /* kprobe_running() needs smp_processor_id() */
29838- if (kprobes_built_in() && !user_mode_vm(regs)) {
29839+ if (kprobes_built_in() && !user_mode(regs)) {
29840 preempt_disable();
29841 if (kprobe_running() && kprobe_fault_handler(regs, 14))
29842 ret = 1;
29843@@ -117,7 +124,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
29844 return !instr_lo || (instr_lo>>1) == 1;
29845 case 0x00:
29846 /* Prefetch instruction is 0x0F0D or 0x0F18 */
29847- if (probe_kernel_address(instr, opcode))
29848+ if (user_mode(regs)) {
29849+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
29850+ return 0;
29851+ } else if (probe_kernel_address(instr, opcode))
29852 return 0;
29853
29854 *prefetch = (instr_lo == 0xF) &&
29855@@ -151,7 +161,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
29856 while (instr < max_instr) {
29857 unsigned char opcode;
29858
29859- if (probe_kernel_address(instr, opcode))
29860+ if (user_mode(regs)) {
29861+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
29862+ break;
29863+ } else if (probe_kernel_address(instr, opcode))
29864 break;
29865
29866 instr++;
29867@@ -182,6 +195,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
29868 force_sig_info(si_signo, &info, tsk);
29869 }
29870
29871+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
29872+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
29873+#endif
29874+
29875+#ifdef CONFIG_PAX_EMUTRAMP
29876+static int pax_handle_fetch_fault(struct pt_regs *regs);
29877+#endif
29878+
29879+#ifdef CONFIG_PAX_PAGEEXEC
29880+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
29881+{
29882+ pgd_t *pgd;
29883+ pud_t *pud;
29884+ pmd_t *pmd;
29885+
29886+ pgd = pgd_offset(mm, address);
29887+ if (!pgd_present(*pgd))
29888+ return NULL;
29889+ pud = pud_offset(pgd, address);
29890+ if (!pud_present(*pud))
29891+ return NULL;
29892+ pmd = pmd_offset(pud, address);
29893+ if (!pmd_present(*pmd))
29894+ return NULL;
29895+ return pmd;
29896+}
29897+#endif
29898+
29899 DEFINE_SPINLOCK(pgd_lock);
29900 LIST_HEAD(pgd_list);
29901
29902@@ -232,10 +273,27 @@ void vmalloc_sync_all(void)
29903 for (address = VMALLOC_START & PMD_MASK;
29904 address >= TASK_SIZE && address < FIXADDR_TOP;
29905 address += PMD_SIZE) {
29906+
29907+#ifdef CONFIG_PAX_PER_CPU_PGD
29908+ unsigned long cpu;
29909+#else
29910 struct page *page;
29911+#endif
29912
29913 spin_lock(&pgd_lock);
29914+
29915+#ifdef CONFIG_PAX_PER_CPU_PGD
29916+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
29917+ pgd_t *pgd = get_cpu_pgd(cpu, user);
29918+ pmd_t *ret;
29919+
29920+ ret = vmalloc_sync_one(pgd, address);
29921+ if (!ret)
29922+ break;
29923+ pgd = get_cpu_pgd(cpu, kernel);
29924+#else
29925 list_for_each_entry(page, &pgd_list, lru) {
29926+ pgd_t *pgd;
29927 spinlock_t *pgt_lock;
29928 pmd_t *ret;
29929
29930@@ -243,8 +301,14 @@ void vmalloc_sync_all(void)
29931 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
29932
29933 spin_lock(pgt_lock);
29934- ret = vmalloc_sync_one(page_address(page), address);
29935+ pgd = page_address(page);
29936+#endif
29937+
29938+ ret = vmalloc_sync_one(pgd, address);
29939+
29940+#ifndef CONFIG_PAX_PER_CPU_PGD
29941 spin_unlock(pgt_lock);
29942+#endif
29943
29944 if (!ret)
29945 break;
29946@@ -278,6 +342,12 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
29947 * an interrupt in the middle of a task switch..
29948 */
29949 pgd_paddr = read_cr3();
29950+
29951+#ifdef CONFIG_PAX_PER_CPU_PGD
29952+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (pgd_paddr & __PHYSICAL_MASK));
29953+ vmalloc_sync_one(__va(pgd_paddr + PAGE_SIZE), address);
29954+#endif
29955+
29956 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
29957 if (!pmd_k)
29958 return -1;
29959@@ -373,11 +443,25 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
29960 * happen within a race in page table update. In the later
29961 * case just flush:
29962 */
29963- pgd = pgd_offset(current->active_mm, address);
29964+
29965 pgd_ref = pgd_offset_k(address);
29966 if (pgd_none(*pgd_ref))
29967 return -1;
29968
29969+#ifdef CONFIG_PAX_PER_CPU_PGD
29970+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (read_cr3() & __PHYSICAL_MASK));
29971+ pgd = pgd_offset_cpu(smp_processor_id(), user, address);
29972+ if (pgd_none(*pgd)) {
29973+ set_pgd(pgd, *pgd_ref);
29974+ arch_flush_lazy_mmu_mode();
29975+ } else {
29976+ BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
29977+ }
29978+ pgd = pgd_offset_cpu(smp_processor_id(), kernel, address);
29979+#else
29980+ pgd = pgd_offset(current->active_mm, address);
29981+#endif
29982+
29983 if (pgd_none(*pgd)) {
29984 set_pgd(pgd, *pgd_ref);
29985 arch_flush_lazy_mmu_mode();
29986@@ -543,7 +627,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
29987 static int is_errata100(struct pt_regs *regs, unsigned long address)
29988 {
29989 #ifdef CONFIG_X86_64
29990- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
29991+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
29992 return 1;
29993 #endif
29994 return 0;
29995@@ -570,7 +654,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
29996 }
29997
29998 static const char nx_warning[] = KERN_CRIT
29999-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
30000+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
30001
30002 static void
30003 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
30004@@ -579,15 +663,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
30005 if (!oops_may_print())
30006 return;
30007
30008- if (error_code & PF_INSTR) {
30009+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
30010 unsigned int level;
30011
30012 pte_t *pte = lookup_address(address, &level);
30013
30014 if (pte && pte_present(*pte) && !pte_exec(*pte))
30015- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
30016+ printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
30017 }
30018
30019+#ifdef CONFIG_PAX_KERNEXEC
30020+ if (init_mm.start_code <= address && address < init_mm.end_code) {
30021+ if (current->signal->curr_ip)
30022+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
30023+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
30024+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
30025+ else
30026+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
30027+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
30028+ }
30029+#endif
30030+
30031 printk(KERN_ALERT "BUG: unable to handle kernel ");
30032 if (address < PAGE_SIZE)
30033 printk(KERN_CONT "NULL pointer dereference");
30034@@ -750,6 +846,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
30035 return;
30036 }
30037 #endif
30038+
30039+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
30040+ if (pax_is_fetch_fault(regs, error_code, address)) {
30041+
30042+#ifdef CONFIG_PAX_EMUTRAMP
30043+ switch (pax_handle_fetch_fault(regs)) {
30044+ case 2:
30045+ return;
30046+ }
30047+#endif
30048+
30049+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
30050+ do_group_exit(SIGKILL);
30051+ }
30052+#endif
30053+
30054 /* Kernel addresses are always protection faults: */
30055 if (address >= TASK_SIZE)
30056 error_code |= PF_PROT;
30057@@ -835,7 +947,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
30058 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
30059 printk(KERN_ERR
30060 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
30061- tsk->comm, tsk->pid, address);
30062+ tsk->comm, task_pid_nr(tsk), address);
30063 code = BUS_MCEERR_AR;
30064 }
30065 #endif
30066@@ -898,6 +1010,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
30067 return 1;
30068 }
30069
30070+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
30071+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
30072+{
30073+ pte_t *pte;
30074+ pmd_t *pmd;
30075+ spinlock_t *ptl;
30076+ unsigned char pte_mask;
30077+
30078+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
30079+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
30080+ return 0;
30081+
30082+ /* PaX: it's our fault, let's handle it if we can */
30083+
30084+ /* PaX: take a look at read faults before acquiring any locks */
30085+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
30086+ /* instruction fetch attempt from a protected page in user mode */
30087+ up_read(&mm->mmap_sem);
30088+
30089+#ifdef CONFIG_PAX_EMUTRAMP
30090+ switch (pax_handle_fetch_fault(regs)) {
30091+ case 2:
30092+ return 1;
30093+ }
30094+#endif
30095+
30096+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
30097+ do_group_exit(SIGKILL);
30098+ }
30099+
30100+ pmd = pax_get_pmd(mm, address);
30101+ if (unlikely(!pmd))
30102+ return 0;
30103+
30104+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
30105+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
30106+ pte_unmap_unlock(pte, ptl);
30107+ return 0;
30108+ }
30109+
30110+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
30111+ /* write attempt to a protected page in user mode */
30112+ pte_unmap_unlock(pte, ptl);
30113+ return 0;
30114+ }
30115+
30116+#ifdef CONFIG_SMP
30117+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
30118+#else
30119+ if (likely(address > get_limit(regs->cs)))
30120+#endif
30121+ {
30122+ set_pte(pte, pte_mkread(*pte));
30123+ __flush_tlb_one(address);
30124+ pte_unmap_unlock(pte, ptl);
30125+ up_read(&mm->mmap_sem);
30126+ return 1;
30127+ }
30128+
30129+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
30130+
30131+ /*
30132+ * PaX: fill DTLB with user rights and retry
30133+ */
30134+ __asm__ __volatile__ (
30135+ "orb %2,(%1)\n"
30136+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
30137+/*
30138+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
30139+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
30140+ * page fault when examined during a TLB load attempt. this is true not only
30141+ * for PTEs holding a non-present entry but also present entries that will
30142+ * raise a page fault (such as those set up by PaX, or the copy-on-write
30143+ * mechanism). in effect it means that we do *not* need to flush the TLBs
30144+ * for our target pages since their PTEs are simply not in the TLBs at all.
30145+
30146+ * the best thing in omitting it is that we gain around 15-20% speed in the
30147+ * fast path of the page fault handler and can get rid of tracing since we
30148+ * can no longer flush unintended entries.
30149+ */
30150+ "invlpg (%0)\n"
30151+#endif
30152+ __copyuser_seg"testb $0,(%0)\n"
30153+ "xorb %3,(%1)\n"
30154+ :
30155+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
30156+ : "memory", "cc");
30157+ pte_unmap_unlock(pte, ptl);
30158+ up_read(&mm->mmap_sem);
30159+ return 1;
30160+}
30161+#endif
30162+
30163 /*
30164 * Handle a spurious fault caused by a stale TLB entry.
30165 *
30166@@ -964,6 +1169,9 @@ int show_unhandled_signals = 1;
30167 static inline int
30168 access_error(unsigned long error_code, struct vm_area_struct *vma)
30169 {
30170+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
30171+ return 1;
30172+
30173 if (error_code & PF_WRITE) {
30174 /* write, present and write, not present: */
30175 if (unlikely(!(vma->vm_flags & VM_WRITE)))
30176@@ -992,7 +1200,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
30177 if (error_code & PF_USER)
30178 return false;
30179
30180- if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
30181+ if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
30182 return false;
30183
30184 return true;
30185@@ -1008,18 +1216,33 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
30186 {
30187 struct vm_area_struct *vma;
30188 struct task_struct *tsk;
30189- unsigned long address;
30190 struct mm_struct *mm;
30191 int fault;
30192 int write = error_code & PF_WRITE;
30193 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
30194 (write ? FAULT_FLAG_WRITE : 0);
30195
30196- tsk = current;
30197- mm = tsk->mm;
30198-
30199 /* Get the faulting address: */
30200- address = read_cr2();
30201+ unsigned long address = read_cr2();
30202+
30203+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30204+ if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
30205+ if (!search_exception_tables(regs->ip)) {
30206+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
30207+ bad_area_nosemaphore(regs, error_code, address);
30208+ return;
30209+ }
30210+ if (address < pax_user_shadow_base) {
30211+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
30212+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
30213+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
30214+ } else
30215+ address -= pax_user_shadow_base;
30216+ }
30217+#endif
30218+
30219+ tsk = current;
30220+ mm = tsk->mm;
30221
30222 /*
30223 * Detect and handle instructions that would cause a page fault for
30224@@ -1080,7 +1303,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
30225 * User-mode registers count as a user access even for any
30226 * potential system fault or CPU buglet:
30227 */
30228- if (user_mode_vm(regs)) {
30229+ if (user_mode(regs)) {
30230 local_irq_enable();
30231 error_code |= PF_USER;
30232 } else {
30233@@ -1142,6 +1365,11 @@ retry:
30234 might_sleep();
30235 }
30236
30237+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
30238+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
30239+ return;
30240+#endif
30241+
30242 vma = find_vma(mm, address);
30243 if (unlikely(!vma)) {
30244 bad_area(regs, error_code, address);
30245@@ -1153,18 +1381,24 @@ retry:
30246 bad_area(regs, error_code, address);
30247 return;
30248 }
30249- if (error_code & PF_USER) {
30250- /*
30251- * Accessing the stack below %sp is always a bug.
30252- * The large cushion allows instructions like enter
30253- * and pusha to work. ("enter $65535, $31" pushes
30254- * 32 pointers and then decrements %sp by 65535.)
30255- */
30256- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
30257- bad_area(regs, error_code, address);
30258- return;
30259- }
30260+ /*
30261+ * Accessing the stack below %sp is always a bug.
30262+ * The large cushion allows instructions like enter
30263+ * and pusha to work. ("enter $65535, $31" pushes
30264+ * 32 pointers and then decrements %sp by 65535.)
30265+ */
30266+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
30267+ bad_area(regs, error_code, address);
30268+ return;
30269 }
30270+
30271+#ifdef CONFIG_PAX_SEGMEXEC
30272+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
30273+ bad_area(regs, error_code, address);
30274+ return;
30275+ }
30276+#endif
30277+
30278 if (unlikely(expand_stack(vma, address))) {
30279 bad_area(regs, error_code, address);
30280 return;
30281@@ -1230,3 +1464,292 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
30282 __do_page_fault(regs, error_code);
30283 exception_exit(prev_state);
30284 }
30285+
30286+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
30287+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
30288+{
30289+ struct mm_struct *mm = current->mm;
30290+ unsigned long ip = regs->ip;
30291+
30292+ if (v8086_mode(regs))
30293+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
30294+
30295+#ifdef CONFIG_PAX_PAGEEXEC
30296+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
30297+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
30298+ return true;
30299+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
30300+ return true;
30301+ return false;
30302+ }
30303+#endif
30304+
30305+#ifdef CONFIG_PAX_SEGMEXEC
30306+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
30307+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
30308+ return true;
30309+ return false;
30310+ }
30311+#endif
30312+
30313+ return false;
30314+}
30315+#endif
30316+
30317+#ifdef CONFIG_PAX_EMUTRAMP
30318+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
30319+{
30320+ int err;
30321+
30322+ do { /* PaX: libffi trampoline emulation */
30323+ unsigned char mov, jmp;
30324+ unsigned int addr1, addr2;
30325+
30326+#ifdef CONFIG_X86_64
30327+ if ((regs->ip + 9) >> 32)
30328+ break;
30329+#endif
30330+
30331+ err = get_user(mov, (unsigned char __user *)regs->ip);
30332+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
30333+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
30334+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
30335+
30336+ if (err)
30337+ break;
30338+
30339+ if (mov == 0xB8 && jmp == 0xE9) {
30340+ regs->ax = addr1;
30341+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
30342+ return 2;
30343+ }
30344+ } while (0);
30345+
30346+ do { /* PaX: gcc trampoline emulation #1 */
30347+ unsigned char mov1, mov2;
30348+ unsigned short jmp;
30349+ unsigned int addr1, addr2;
30350+
30351+#ifdef CONFIG_X86_64
30352+ if ((regs->ip + 11) >> 32)
30353+ break;
30354+#endif
30355+
30356+ err = get_user(mov1, (unsigned char __user *)regs->ip);
30357+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
30358+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
30359+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
30360+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
30361+
30362+ if (err)
30363+ break;
30364+
30365+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
30366+ regs->cx = addr1;
30367+ regs->ax = addr2;
30368+ regs->ip = addr2;
30369+ return 2;
30370+ }
30371+ } while (0);
30372+
30373+ do { /* PaX: gcc trampoline emulation #2 */
30374+ unsigned char mov, jmp;
30375+ unsigned int addr1, addr2;
30376+
30377+#ifdef CONFIG_X86_64
30378+ if ((regs->ip + 9) >> 32)
30379+ break;
30380+#endif
30381+
30382+ err = get_user(mov, (unsigned char __user *)regs->ip);
30383+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
30384+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
30385+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
30386+
30387+ if (err)
30388+ break;
30389+
30390+ if (mov == 0xB9 && jmp == 0xE9) {
30391+ regs->cx = addr1;
30392+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
30393+ return 2;
30394+ }
30395+ } while (0);
30396+
30397+ return 1; /* PaX in action */
30398+}
30399+
30400+#ifdef CONFIG_X86_64
30401+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
30402+{
30403+ int err;
30404+
30405+ do { /* PaX: libffi trampoline emulation */
30406+ unsigned short mov1, mov2, jmp1;
30407+ unsigned char stcclc, jmp2;
30408+ unsigned long addr1, addr2;
30409+
30410+ err = get_user(mov1, (unsigned short __user *)regs->ip);
30411+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
30412+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
30413+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
30414+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
30415+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
30416+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
30417+
30418+ if (err)
30419+ break;
30420+
30421+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
30422+ regs->r11 = addr1;
30423+ regs->r10 = addr2;
30424+ if (stcclc == 0xF8)
30425+ regs->flags &= ~X86_EFLAGS_CF;
30426+ else
30427+ regs->flags |= X86_EFLAGS_CF;
30428+ regs->ip = addr1;
30429+ return 2;
30430+ }
30431+ } while (0);
30432+
30433+ do { /* PaX: gcc trampoline emulation #1 */
30434+ unsigned short mov1, mov2, jmp1;
30435+ unsigned char jmp2;
30436+ unsigned int addr1;
30437+ unsigned long addr2;
30438+
30439+ err = get_user(mov1, (unsigned short __user *)regs->ip);
30440+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
30441+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
30442+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
30443+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
30444+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
30445+
30446+ if (err)
30447+ break;
30448+
30449+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
30450+ regs->r11 = addr1;
30451+ regs->r10 = addr2;
30452+ regs->ip = addr1;
30453+ return 2;
30454+ }
30455+ } while (0);
30456+
30457+ do { /* PaX: gcc trampoline emulation #2 */
30458+ unsigned short mov1, mov2, jmp1;
30459+ unsigned char jmp2;
30460+ unsigned long addr1, addr2;
30461+
30462+ err = get_user(mov1, (unsigned short __user *)regs->ip);
30463+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
30464+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
30465+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
30466+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
30467+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
30468+
30469+ if (err)
30470+ break;
30471+
30472+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
30473+ regs->r11 = addr1;
30474+ regs->r10 = addr2;
30475+ regs->ip = addr1;
30476+ return 2;
30477+ }
30478+ } while (0);
30479+
30480+ return 1; /* PaX in action */
30481+}
30482+#endif
30483+
30484+/*
30485+ * PaX: decide what to do with offenders (regs->ip = fault address)
30486+ *
30487+ * returns 1 when task should be killed
30488+ * 2 when gcc trampoline was detected
30489+ */
30490+static int pax_handle_fetch_fault(struct pt_regs *regs)
30491+{
30492+ if (v8086_mode(regs))
30493+ return 1;
30494+
30495+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
30496+ return 1;
30497+
30498+#ifdef CONFIG_X86_32
30499+ return pax_handle_fetch_fault_32(regs);
30500+#else
30501+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
30502+ return pax_handle_fetch_fault_32(regs);
30503+ else
30504+ return pax_handle_fetch_fault_64(regs);
30505+#endif
30506+}
30507+#endif
30508+
30509+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
30510+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
30511+{
30512+ long i;
30513+
30514+ printk(KERN_ERR "PAX: bytes at PC: ");
30515+ for (i = 0; i < 20; i++) {
30516+ unsigned char c;
30517+ if (get_user(c, (unsigned char __force_user *)pc+i))
30518+ printk(KERN_CONT "?? ");
30519+ else
30520+ printk(KERN_CONT "%02x ", c);
30521+ }
30522+ printk("\n");
30523+
30524+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
30525+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
30526+ unsigned long c;
30527+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
30528+#ifdef CONFIG_X86_32
30529+ printk(KERN_CONT "???????? ");
30530+#else
30531+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
30532+ printk(KERN_CONT "???????? ???????? ");
30533+ else
30534+ printk(KERN_CONT "???????????????? ");
30535+#endif
30536+ } else {
30537+#ifdef CONFIG_X86_64
30538+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
30539+ printk(KERN_CONT "%08x ", (unsigned int)c);
30540+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
30541+ } else
30542+#endif
30543+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
30544+ }
30545+ }
30546+ printk("\n");
30547+}
30548+#endif
30549+
30550+/**
30551+ * probe_kernel_write(): safely attempt to write to a location
30552+ * @dst: address to write to
30553+ * @src: pointer to the data that shall be written
30554+ * @size: size of the data chunk
30555+ *
30556+ * Safely write to address @dst from the buffer at @src. If a kernel fault
30557+ * happens, handle that and return -EFAULT.
30558+ */
30559+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
30560+{
30561+ long ret;
30562+ mm_segment_t old_fs = get_fs();
30563+
30564+ set_fs(KERNEL_DS);
30565+ pagefault_disable();
30566+ pax_open_kernel();
30567+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
30568+ pax_close_kernel();
30569+ pagefault_enable();
30570+ set_fs(old_fs);
30571+
30572+ return ret ? -EFAULT : 0;
30573+}
30574diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
30575index dd74e46..7d26398 100644
30576--- a/arch/x86/mm/gup.c
30577+++ b/arch/x86/mm/gup.c
30578@@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
30579 addr = start;
30580 len = (unsigned long) nr_pages << PAGE_SHIFT;
30581 end = start + len;
30582- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
30583+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
30584 (void __user *)start, len)))
30585 return 0;
30586
30587diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
30588index 4500142..53a363c 100644
30589--- a/arch/x86/mm/highmem_32.c
30590+++ b/arch/x86/mm/highmem_32.c
30591@@ -45,7 +45,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
30592 idx = type + KM_TYPE_NR*smp_processor_id();
30593 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
30594 BUG_ON(!pte_none(*(kmap_pte-idx)));
30595+
30596+ pax_open_kernel();
30597 set_pte(kmap_pte-idx, mk_pte(page, prot));
30598+ pax_close_kernel();
30599+
30600 arch_flush_lazy_mmu_mode();
30601
30602 return (void *)vaddr;
30603diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
30604index 7e73e8c..11d3b86 100644
30605--- a/arch/x86/mm/hugetlbpage.c
30606+++ b/arch/x86/mm/hugetlbpage.c
30607@@ -84,23 +84,30 @@ int pud_huge(pud_t pud)
30608 #ifdef HAVE_ARCH_HUGETLB_UNMAPPED_AREA
30609 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
30610 unsigned long addr, unsigned long len,
30611- unsigned long pgoff, unsigned long flags)
30612+ unsigned long pgoff, unsigned long flags, unsigned long offset)
30613 {
30614 struct hstate *h = hstate_file(file);
30615 struct vm_unmapped_area_info info;
30616-
30617+
30618 info.flags = 0;
30619 info.length = len;
30620 info.low_limit = TASK_UNMAPPED_BASE;
30621+
30622+#ifdef CONFIG_PAX_RANDMMAP
30623+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
30624+ info.low_limit += current->mm->delta_mmap;
30625+#endif
30626+
30627 info.high_limit = TASK_SIZE;
30628 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
30629 info.align_offset = 0;
30630+ info.threadstack_offset = offset;
30631 return vm_unmapped_area(&info);
30632 }
30633
30634 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
30635 unsigned long addr0, unsigned long len,
30636- unsigned long pgoff, unsigned long flags)
30637+ unsigned long pgoff, unsigned long flags, unsigned long offset)
30638 {
30639 struct hstate *h = hstate_file(file);
30640 struct vm_unmapped_area_info info;
30641@@ -112,6 +119,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
30642 info.high_limit = current->mm->mmap_base;
30643 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
30644 info.align_offset = 0;
30645+ info.threadstack_offset = offset;
30646 addr = vm_unmapped_area(&info);
30647
30648 /*
30649@@ -124,6 +132,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
30650 VM_BUG_ON(addr != -ENOMEM);
30651 info.flags = 0;
30652 info.low_limit = TASK_UNMAPPED_BASE;
30653+
30654+#ifdef CONFIG_PAX_RANDMMAP
30655+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
30656+ info.low_limit += current->mm->delta_mmap;
30657+#endif
30658+
30659 info.high_limit = TASK_SIZE;
30660 addr = vm_unmapped_area(&info);
30661 }
30662@@ -138,10 +152,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
30663 struct hstate *h = hstate_file(file);
30664 struct mm_struct *mm = current->mm;
30665 struct vm_area_struct *vma;
30666+ unsigned long pax_task_size = TASK_SIZE;
30667+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
30668
30669 if (len & ~huge_page_mask(h))
30670 return -EINVAL;
30671- if (len > TASK_SIZE)
30672+
30673+#ifdef CONFIG_PAX_SEGMEXEC
30674+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
30675+ pax_task_size = SEGMEXEC_TASK_SIZE;
30676+#endif
30677+
30678+ pax_task_size -= PAGE_SIZE;
30679+
30680+ if (len > pax_task_size)
30681 return -ENOMEM;
30682
30683 if (flags & MAP_FIXED) {
30684@@ -150,19 +174,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
30685 return addr;
30686 }
30687
30688+#ifdef CONFIG_PAX_RANDMMAP
30689+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
30690+#endif
30691+
30692 if (addr) {
30693 addr = ALIGN(addr, huge_page_size(h));
30694 vma = find_vma(mm, addr);
30695- if (TASK_SIZE - len >= addr &&
30696- (!vma || addr + len <= vma->vm_start))
30697+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
30698 return addr;
30699 }
30700 if (mm->get_unmapped_area == arch_get_unmapped_area)
30701 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
30702- pgoff, flags);
30703+ pgoff, flags, offset);
30704 else
30705 return hugetlb_get_unmapped_area_topdown(file, addr, len,
30706- pgoff, flags);
30707+ pgoff, flags, offset);
30708 }
30709
30710 #endif /*HAVE_ARCH_HUGETLB_UNMAPPED_AREA*/
30711diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
30712index 04664cd..dae6e5d 100644
30713--- a/arch/x86/mm/init.c
30714+++ b/arch/x86/mm/init.c
30715@@ -4,6 +4,7 @@
30716 #include <linux/swap.h>
30717 #include <linux/memblock.h>
30718 #include <linux/bootmem.h> /* for max_low_pfn */
30719+#include <linux/tboot.h>
30720
30721 #include <asm/cacheflush.h>
30722 #include <asm/e820.h>
30723@@ -17,6 +18,8 @@
30724 #include <asm/proto.h>
30725 #include <asm/dma.h> /* for MAX_DMA_PFN */
30726 #include <asm/microcode.h>
30727+#include <asm/desc.h>
30728+#include <asm/bios_ebda.h>
30729
30730 #include "mm_internal.h"
30731
30732@@ -465,7 +468,18 @@ void __init init_mem_mapping(void)
30733 early_ioremap_page_table_range_init();
30734 #endif
30735
30736+#ifdef CONFIG_PAX_PER_CPU_PGD
30737+ clone_pgd_range(get_cpu_pgd(0, kernel) + KERNEL_PGD_BOUNDARY,
30738+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
30739+ KERNEL_PGD_PTRS);
30740+ clone_pgd_range(get_cpu_pgd(0, user) + KERNEL_PGD_BOUNDARY,
30741+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
30742+ KERNEL_PGD_PTRS);
30743+ load_cr3(get_cpu_pgd(0, kernel));
30744+#else
30745 load_cr3(swapper_pg_dir);
30746+#endif
30747+
30748 __flush_tlb_all();
30749
30750 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
30751@@ -481,10 +495,40 @@ void __init init_mem_mapping(void)
30752 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
30753 * mmio resources as well as potential bios/acpi data regions.
30754 */
30755+
30756+#ifdef CONFIG_GRKERNSEC_KMEM
30757+static unsigned int ebda_start __read_only;
30758+static unsigned int ebda_end __read_only;
30759+#endif
30760+
30761 int devmem_is_allowed(unsigned long pagenr)
30762 {
30763- if (pagenr < 256)
30764+#ifdef CONFIG_GRKERNSEC_KMEM
30765+ /* allow BDA */
30766+ if (!pagenr)
30767 return 1;
30768+ /* allow EBDA */
30769+ if (pagenr >= ebda_start && pagenr < ebda_end)
30770+ return 1;
30771+ /* if tboot is in use, allow access to its hardcoded serial log range */
30772+ if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
30773+ return 1;
30774+#else
30775+ if (!pagenr)
30776+ return 1;
30777+#ifdef CONFIG_VM86
30778+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
30779+ return 1;
30780+#endif
30781+#endif
30782+
30783+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
30784+ return 1;
30785+#ifdef CONFIG_GRKERNSEC_KMEM
30786+ /* throw out everything else below 1MB */
30787+ if (pagenr <= 256)
30788+ return 0;
30789+#endif
30790 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
30791 return 0;
30792 if (!page_is_ram(pagenr))
30793@@ -530,8 +574,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
30794 #endif
30795 }
30796
30797+#ifdef CONFIG_GRKERNSEC_KMEM
30798+static inline void gr_init_ebda(void)
30799+{
30800+ unsigned int ebda_addr;
30801+ unsigned int ebda_size = 0;
30802+
30803+ ebda_addr = get_bios_ebda();
30804+ if (ebda_addr) {
30805+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
30806+ ebda_size <<= 10;
30807+ }
30808+ if (ebda_addr && ebda_size) {
30809+ ebda_start = ebda_addr >> PAGE_SHIFT;
30810+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
30811+ } else {
30812+ ebda_start = 0x9f000 >> PAGE_SHIFT;
30813+ ebda_end = 0xa0000 >> PAGE_SHIFT;
30814+ }
30815+}
30816+#else
30817+static inline void gr_init_ebda(void) { }
30818+#endif
30819+
30820 void free_initmem(void)
30821 {
30822+#ifdef CONFIG_PAX_KERNEXEC
30823+#ifdef CONFIG_X86_32
30824+ /* PaX: limit KERNEL_CS to actual size */
30825+ unsigned long addr, limit;
30826+ struct desc_struct d;
30827+ int cpu;
30828+#else
30829+ pgd_t *pgd;
30830+ pud_t *pud;
30831+ pmd_t *pmd;
30832+ unsigned long addr, end;
30833+#endif
30834+#endif
30835+
30836+ gr_init_ebda();
30837+
30838+#ifdef CONFIG_PAX_KERNEXEC
30839+#ifdef CONFIG_X86_32
30840+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
30841+ limit = (limit - 1UL) >> PAGE_SHIFT;
30842+
30843+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
30844+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
30845+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
30846+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
30847+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
30848+ }
30849+
30850+ /* PaX: make KERNEL_CS read-only */
30851+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
30852+ if (!paravirt_enabled())
30853+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
30854+/*
30855+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
30856+ pgd = pgd_offset_k(addr);
30857+ pud = pud_offset(pgd, addr);
30858+ pmd = pmd_offset(pud, addr);
30859+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
30860+ }
30861+*/
30862+#ifdef CONFIG_X86_PAE
30863+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
30864+/*
30865+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
30866+ pgd = pgd_offset_k(addr);
30867+ pud = pud_offset(pgd, addr);
30868+ pmd = pmd_offset(pud, addr);
30869+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
30870+ }
30871+*/
30872+#endif
30873+
30874+#ifdef CONFIG_MODULES
30875+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
30876+#endif
30877+
30878+#else
30879+ /* PaX: make kernel code/rodata read-only, rest non-executable */
30880+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
30881+ pgd = pgd_offset_k(addr);
30882+ pud = pud_offset(pgd, addr);
30883+ pmd = pmd_offset(pud, addr);
30884+ if (!pmd_present(*pmd))
30885+ continue;
30886+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
30887+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
30888+ else
30889+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
30890+ }
30891+
30892+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
30893+ end = addr + KERNEL_IMAGE_SIZE;
30894+ for (; addr < end; addr += PMD_SIZE) {
30895+ pgd = pgd_offset_k(addr);
30896+ pud = pud_offset(pgd, addr);
30897+ pmd = pmd_offset(pud, addr);
30898+ if (!pmd_present(*pmd))
30899+ continue;
30900+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
30901+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
30902+ }
30903+#endif
30904+
30905+ flush_tlb_all();
30906+#endif
30907+
30908 free_init_pages("unused kernel",
30909 (unsigned long)(&__init_begin),
30910 (unsigned long)(&__init_end));
30911diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
30912index 4287f1f..3b99c71 100644
30913--- a/arch/x86/mm/init_32.c
30914+++ b/arch/x86/mm/init_32.c
30915@@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
30916 bool __read_mostly __vmalloc_start_set = false;
30917
30918 /*
30919- * Creates a middle page table and puts a pointer to it in the
30920- * given global directory entry. This only returns the gd entry
30921- * in non-PAE compilation mode, since the middle layer is folded.
30922- */
30923-static pmd_t * __init one_md_table_init(pgd_t *pgd)
30924-{
30925- pud_t *pud;
30926- pmd_t *pmd_table;
30927-
30928-#ifdef CONFIG_X86_PAE
30929- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
30930- pmd_table = (pmd_t *)alloc_low_page();
30931- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
30932- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
30933- pud = pud_offset(pgd, 0);
30934- BUG_ON(pmd_table != pmd_offset(pud, 0));
30935-
30936- return pmd_table;
30937- }
30938-#endif
30939- pud = pud_offset(pgd, 0);
30940- pmd_table = pmd_offset(pud, 0);
30941-
30942- return pmd_table;
30943-}
30944-
30945-/*
30946 * Create a page table and place a pointer to it in a middle page
30947 * directory entry:
30948 */
30949@@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
30950 pte_t *page_table = (pte_t *)alloc_low_page();
30951
30952 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
30953+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
30954+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
30955+#else
30956 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
30957+#endif
30958 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
30959 }
30960
30961 return pte_offset_kernel(pmd, 0);
30962 }
30963
30964+static pmd_t * __init one_md_table_init(pgd_t *pgd)
30965+{
30966+ pud_t *pud;
30967+ pmd_t *pmd_table;
30968+
30969+ pud = pud_offset(pgd, 0);
30970+ pmd_table = pmd_offset(pud, 0);
30971+
30972+ return pmd_table;
30973+}
30974+
30975 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
30976 {
30977 int pgd_idx = pgd_index(vaddr);
30978@@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
30979 int pgd_idx, pmd_idx;
30980 unsigned long vaddr;
30981 pgd_t *pgd;
30982+ pud_t *pud;
30983 pmd_t *pmd;
30984 pte_t *pte = NULL;
30985 unsigned long count = page_table_range_init_count(start, end);
30986@@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
30987 pgd = pgd_base + pgd_idx;
30988
30989 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
30990- pmd = one_md_table_init(pgd);
30991- pmd = pmd + pmd_index(vaddr);
30992+ pud = pud_offset(pgd, vaddr);
30993+ pmd = pmd_offset(pud, vaddr);
30994+
30995+#ifdef CONFIG_X86_PAE
30996+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
30997+#endif
30998+
30999 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
31000 pmd++, pmd_idx++) {
31001 pte = page_table_kmap_check(one_page_table_init(pmd),
31002@@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
31003 }
31004 }
31005
31006-static inline int is_kernel_text(unsigned long addr)
31007+static inline int is_kernel_text(unsigned long start, unsigned long end)
31008 {
31009- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
31010- return 1;
31011- return 0;
31012+ if ((start > ktla_ktva((unsigned long)_etext) ||
31013+ end <= ktla_ktva((unsigned long)_stext)) &&
31014+ (start > ktla_ktva((unsigned long)_einittext) ||
31015+ end <= ktla_ktva((unsigned long)_sinittext)) &&
31016+
31017+#ifdef CONFIG_ACPI_SLEEP
31018+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
31019+#endif
31020+
31021+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
31022+ return 0;
31023+ return 1;
31024 }
31025
31026 /*
31027@@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
31028 unsigned long last_map_addr = end;
31029 unsigned long start_pfn, end_pfn;
31030 pgd_t *pgd_base = swapper_pg_dir;
31031- int pgd_idx, pmd_idx, pte_ofs;
31032+ unsigned int pgd_idx, pmd_idx, pte_ofs;
31033 unsigned long pfn;
31034 pgd_t *pgd;
31035+ pud_t *pud;
31036 pmd_t *pmd;
31037 pte_t *pte;
31038 unsigned pages_2m, pages_4k;
31039@@ -291,8 +295,13 @@ repeat:
31040 pfn = start_pfn;
31041 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
31042 pgd = pgd_base + pgd_idx;
31043- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
31044- pmd = one_md_table_init(pgd);
31045+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
31046+ pud = pud_offset(pgd, 0);
31047+ pmd = pmd_offset(pud, 0);
31048+
31049+#ifdef CONFIG_X86_PAE
31050+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
31051+#endif
31052
31053 if (pfn >= end_pfn)
31054 continue;
31055@@ -304,14 +313,13 @@ repeat:
31056 #endif
31057 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
31058 pmd++, pmd_idx++) {
31059- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
31060+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
31061
31062 /*
31063 * Map with big pages if possible, otherwise
31064 * create normal page tables:
31065 */
31066 if (use_pse) {
31067- unsigned int addr2;
31068 pgprot_t prot = PAGE_KERNEL_LARGE;
31069 /*
31070 * first pass will use the same initial
31071@@ -322,11 +330,7 @@ repeat:
31072 _PAGE_PSE);
31073
31074 pfn &= PMD_MASK >> PAGE_SHIFT;
31075- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
31076- PAGE_OFFSET + PAGE_SIZE-1;
31077-
31078- if (is_kernel_text(addr) ||
31079- is_kernel_text(addr2))
31080+ if (is_kernel_text(address, address + PMD_SIZE))
31081 prot = PAGE_KERNEL_LARGE_EXEC;
31082
31083 pages_2m++;
31084@@ -343,7 +347,7 @@ repeat:
31085 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
31086 pte += pte_ofs;
31087 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
31088- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
31089+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
31090 pgprot_t prot = PAGE_KERNEL;
31091 /*
31092 * first pass will use the same initial
31093@@ -351,7 +355,7 @@ repeat:
31094 */
31095 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
31096
31097- if (is_kernel_text(addr))
31098+ if (is_kernel_text(address, address + PAGE_SIZE))
31099 prot = PAGE_KERNEL_EXEC;
31100
31101 pages_4k++;
31102@@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
31103
31104 pud = pud_offset(pgd, va);
31105 pmd = pmd_offset(pud, va);
31106- if (!pmd_present(*pmd))
31107+ if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
31108 break;
31109
31110 /* should not be large page here */
31111@@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
31112
31113 static void __init pagetable_init(void)
31114 {
31115- pgd_t *pgd_base = swapper_pg_dir;
31116-
31117- permanent_kmaps_init(pgd_base);
31118+ permanent_kmaps_init(swapper_pg_dir);
31119 }
31120
31121-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
31122+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
31123 EXPORT_SYMBOL_GPL(__supported_pte_mask);
31124
31125 /* user-defined highmem size */
31126@@ -787,10 +789,10 @@ void __init mem_init(void)
31127 ((unsigned long)&__init_end -
31128 (unsigned long)&__init_begin) >> 10,
31129
31130- (unsigned long)&_etext, (unsigned long)&_edata,
31131- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
31132+ (unsigned long)&_sdata, (unsigned long)&_edata,
31133+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
31134
31135- (unsigned long)&_text, (unsigned long)&_etext,
31136+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
31137 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
31138
31139 /*
31140@@ -880,6 +882,7 @@ void set_kernel_text_rw(void)
31141 if (!kernel_set_to_readonly)
31142 return;
31143
31144+ start = ktla_ktva(start);
31145 pr_debug("Set kernel text: %lx - %lx for read write\n",
31146 start, start+size);
31147
31148@@ -894,6 +897,7 @@ void set_kernel_text_ro(void)
31149 if (!kernel_set_to_readonly)
31150 return;
31151
31152+ start = ktla_ktva(start);
31153 pr_debug("Set kernel text: %lx - %lx for read only\n",
31154 start, start+size);
31155
31156@@ -922,6 +926,7 @@ void mark_rodata_ro(void)
31157 unsigned long start = PFN_ALIGN(_text);
31158 unsigned long size = PFN_ALIGN(_etext) - start;
31159
31160+ start = ktla_ktva(start);
31161 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
31162 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
31163 size >> 10);
31164diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
31165index 104d56a..62ba13f 100644
31166--- a/arch/x86/mm/init_64.c
31167+++ b/arch/x86/mm/init_64.c
31168@@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
31169 * around without checking the pgd every time.
31170 */
31171
31172-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
31173+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
31174 EXPORT_SYMBOL_GPL(__supported_pte_mask);
31175
31176 int force_personality32;
31177@@ -184,12 +184,29 @@ void sync_global_pgds(unsigned long start, unsigned long end)
31178
31179 for (address = start; address <= end; address += PGDIR_SIZE) {
31180 const pgd_t *pgd_ref = pgd_offset_k(address);
31181+
31182+#ifdef CONFIG_PAX_PER_CPU_PGD
31183+ unsigned long cpu;
31184+#else
31185 struct page *page;
31186+#endif
31187
31188 if (pgd_none(*pgd_ref))
31189 continue;
31190
31191 spin_lock(&pgd_lock);
31192+
31193+#ifdef CONFIG_PAX_PER_CPU_PGD
31194+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
31195+ pgd_t *pgd = pgd_offset_cpu(cpu, user, address);
31196+
31197+ if (pgd_none(*pgd))
31198+ set_pgd(pgd, *pgd_ref);
31199+ else
31200+ BUG_ON(pgd_page_vaddr(*pgd)
31201+ != pgd_page_vaddr(*pgd_ref));
31202+ pgd = pgd_offset_cpu(cpu, kernel, address);
31203+#else
31204 list_for_each_entry(page, &pgd_list, lru) {
31205 pgd_t *pgd;
31206 spinlock_t *pgt_lock;
31207@@ -198,6 +215,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
31208 /* the pgt_lock only for Xen */
31209 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
31210 spin_lock(pgt_lock);
31211+#endif
31212
31213 if (pgd_none(*pgd))
31214 set_pgd(pgd, *pgd_ref);
31215@@ -205,7 +223,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
31216 BUG_ON(pgd_page_vaddr(*pgd)
31217 != pgd_page_vaddr(*pgd_ref));
31218
31219+#ifndef CONFIG_PAX_PER_CPU_PGD
31220 spin_unlock(pgt_lock);
31221+#endif
31222+
31223 }
31224 spin_unlock(&pgd_lock);
31225 }
31226@@ -238,7 +259,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
31227 {
31228 if (pgd_none(*pgd)) {
31229 pud_t *pud = (pud_t *)spp_getpage();
31230- pgd_populate(&init_mm, pgd, pud);
31231+ pgd_populate_kernel(&init_mm, pgd, pud);
31232 if (pud != pud_offset(pgd, 0))
31233 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
31234 pud, pud_offset(pgd, 0));
31235@@ -250,7 +271,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
31236 {
31237 if (pud_none(*pud)) {
31238 pmd_t *pmd = (pmd_t *) spp_getpage();
31239- pud_populate(&init_mm, pud, pmd);
31240+ pud_populate_kernel(&init_mm, pud, pmd);
31241 if (pmd != pmd_offset(pud, 0))
31242 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
31243 pmd, pmd_offset(pud, 0));
31244@@ -279,7 +300,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
31245 pmd = fill_pmd(pud, vaddr);
31246 pte = fill_pte(pmd, vaddr);
31247
31248+ pax_open_kernel();
31249 set_pte(pte, new_pte);
31250+ pax_close_kernel();
31251
31252 /*
31253 * It's enough to flush this one mapping.
31254@@ -338,14 +361,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
31255 pgd = pgd_offset_k((unsigned long)__va(phys));
31256 if (pgd_none(*pgd)) {
31257 pud = (pud_t *) spp_getpage();
31258- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
31259- _PAGE_USER));
31260+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
31261 }
31262 pud = pud_offset(pgd, (unsigned long)__va(phys));
31263 if (pud_none(*pud)) {
31264 pmd = (pmd_t *) spp_getpage();
31265- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
31266- _PAGE_USER));
31267+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
31268 }
31269 pmd = pmd_offset(pud, phys);
31270 BUG_ON(!pmd_none(*pmd));
31271@@ -586,7 +607,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
31272 prot);
31273
31274 spin_lock(&init_mm.page_table_lock);
31275- pud_populate(&init_mm, pud, pmd);
31276+ pud_populate_kernel(&init_mm, pud, pmd);
31277 spin_unlock(&init_mm.page_table_lock);
31278 }
31279 __flush_tlb_all();
31280@@ -627,7 +648,7 @@ kernel_physical_mapping_init(unsigned long start,
31281 page_size_mask);
31282
31283 spin_lock(&init_mm.page_table_lock);
31284- pgd_populate(&init_mm, pgd, pud);
31285+ pgd_populate_kernel(&init_mm, pgd, pud);
31286 spin_unlock(&init_mm.page_table_lock);
31287 pgd_changed = true;
31288 }
31289@@ -1188,8 +1209,8 @@ int kern_addr_valid(unsigned long addr)
31290 static struct vm_area_struct gate_vma = {
31291 .vm_start = VSYSCALL_START,
31292 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
31293- .vm_page_prot = PAGE_READONLY_EXEC,
31294- .vm_flags = VM_READ | VM_EXEC
31295+ .vm_page_prot = PAGE_READONLY,
31296+ .vm_flags = VM_READ
31297 };
31298
31299 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
31300@@ -1223,7 +1244,7 @@ int in_gate_area_no_mm(unsigned long addr)
31301
31302 const char *arch_vma_name(struct vm_area_struct *vma)
31303 {
31304- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
31305+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
31306 return "[vdso]";
31307 if (vma == &gate_vma)
31308 return "[vsyscall]";
31309diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
31310index 7b179b4..6bd17777 100644
31311--- a/arch/x86/mm/iomap_32.c
31312+++ b/arch/x86/mm/iomap_32.c
31313@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
31314 type = kmap_atomic_idx_push();
31315 idx = type + KM_TYPE_NR * smp_processor_id();
31316 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
31317+
31318+ pax_open_kernel();
31319 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
31320+ pax_close_kernel();
31321+
31322 arch_flush_lazy_mmu_mode();
31323
31324 return (void *)vaddr;
31325diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
31326index 0215e2c..1c62dab 100644
31327--- a/arch/x86/mm/ioremap.c
31328+++ b/arch/x86/mm/ioremap.c
31329@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
31330 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
31331 int is_ram = page_is_ram(pfn);
31332
31333- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
31334+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
31335 return NULL;
31336 WARN_ON_ONCE(is_ram);
31337 }
31338@@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
31339 *
31340 * Caller must ensure there is only one unmapping for the same pointer.
31341 */
31342-void iounmap(volatile void __iomem *addr)
31343+void iounmap(const volatile void __iomem *addr)
31344 {
31345 struct vm_struct *p, *o;
31346
31347@@ -310,6 +310,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
31348
31349 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
31350 if (page_is_ram(start >> PAGE_SHIFT))
31351+#ifdef CONFIG_HIGHMEM
31352+ if ((start >> PAGE_SHIFT) < max_low_pfn)
31353+#endif
31354 return __va(phys);
31355
31356 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
31357@@ -322,6 +325,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
31358 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
31359 {
31360 if (page_is_ram(phys >> PAGE_SHIFT))
31361+#ifdef CONFIG_HIGHMEM
31362+ if ((phys >> PAGE_SHIFT) < max_low_pfn)
31363+#endif
31364 return;
31365
31366 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
31367@@ -339,7 +345,7 @@ static int __init early_ioremap_debug_setup(char *str)
31368 early_param("early_ioremap_debug", early_ioremap_debug_setup);
31369
31370 static __initdata int after_paging_init;
31371-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
31372+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
31373
31374 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
31375 {
31376@@ -376,8 +382,7 @@ void __init early_ioremap_init(void)
31377 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
31378
31379 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
31380- memset(bm_pte, 0, sizeof(bm_pte));
31381- pmd_populate_kernel(&init_mm, pmd, bm_pte);
31382+ pmd_populate_user(&init_mm, pmd, bm_pte);
31383
31384 /*
31385 * The boot-ioremap range spans multiple pmds, for which
31386diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
31387index d87dd6d..bf3fa66 100644
31388--- a/arch/x86/mm/kmemcheck/kmemcheck.c
31389+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
31390@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
31391 * memory (e.g. tracked pages)? For now, we need this to avoid
31392 * invoking kmemcheck for PnP BIOS calls.
31393 */
31394- if (regs->flags & X86_VM_MASK)
31395+ if (v8086_mode(regs))
31396 return false;
31397- if (regs->cs != __KERNEL_CS)
31398+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
31399 return false;
31400
31401 pte = kmemcheck_pte_lookup(address);
31402diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
31403index 25e7e13..1964579 100644
31404--- a/arch/x86/mm/mmap.c
31405+++ b/arch/x86/mm/mmap.c
31406@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
31407 * Leave an at least ~128 MB hole with possible stack randomization.
31408 */
31409 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
31410-#define MAX_GAP (TASK_SIZE/6*5)
31411+#define MAX_GAP (pax_task_size/6*5)
31412
31413 static int mmap_is_legacy(void)
31414 {
31415@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
31416 return rnd << PAGE_SHIFT;
31417 }
31418
31419-static unsigned long mmap_base(void)
31420+static unsigned long mmap_base(struct mm_struct *mm)
31421 {
31422 unsigned long gap = rlimit(RLIMIT_STACK);
31423+ unsigned long pax_task_size = TASK_SIZE;
31424+
31425+#ifdef CONFIG_PAX_SEGMEXEC
31426+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
31427+ pax_task_size = SEGMEXEC_TASK_SIZE;
31428+#endif
31429
31430 if (gap < MIN_GAP)
31431 gap = MIN_GAP;
31432 else if (gap > MAX_GAP)
31433 gap = MAX_GAP;
31434
31435- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
31436+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
31437 }
31438
31439 /*
31440 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
31441 * does, but not when emulating X86_32
31442 */
31443-static unsigned long mmap_legacy_base(void)
31444+static unsigned long mmap_legacy_base(struct mm_struct *mm)
31445 {
31446- if (mmap_is_ia32())
31447+ if (mmap_is_ia32()) {
31448+
31449+#ifdef CONFIG_PAX_SEGMEXEC
31450+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
31451+ return SEGMEXEC_TASK_UNMAPPED_BASE;
31452+ else
31453+#endif
31454+
31455 return TASK_UNMAPPED_BASE;
31456- else
31457+ } else
31458 return TASK_UNMAPPED_BASE + mmap_rnd();
31459 }
31460
31461@@ -112,8 +125,15 @@ static unsigned long mmap_legacy_base(void)
31462 */
31463 void arch_pick_mmap_layout(struct mm_struct *mm)
31464 {
31465- mm->mmap_legacy_base = mmap_legacy_base();
31466- mm->mmap_base = mmap_base();
31467+ mm->mmap_legacy_base = mmap_legacy_base(mm);
31468+ mm->mmap_base = mmap_base(mm);
31469+
31470+#ifdef CONFIG_PAX_RANDMMAP
31471+ if (mm->pax_flags & MF_PAX_RANDMMAP) {
31472+ mm->mmap_legacy_base += mm->delta_mmap;
31473+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
31474+ }
31475+#endif
31476
31477 if (mmap_is_legacy()) {
31478 mm->mmap_base = mm->mmap_legacy_base;
31479diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
31480index 0057a7a..95c7edd 100644
31481--- a/arch/x86/mm/mmio-mod.c
31482+++ b/arch/x86/mm/mmio-mod.c
31483@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
31484 break;
31485 default:
31486 {
31487- unsigned char *ip = (unsigned char *)instptr;
31488+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
31489 my_trace->opcode = MMIO_UNKNOWN_OP;
31490 my_trace->width = 0;
31491 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
31492@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
31493 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
31494 void __iomem *addr)
31495 {
31496- static atomic_t next_id;
31497+ static atomic_unchecked_t next_id;
31498 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
31499 /* These are page-unaligned. */
31500 struct mmiotrace_map map = {
31501@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
31502 .private = trace
31503 },
31504 .phys = offset,
31505- .id = atomic_inc_return(&next_id)
31506+ .id = atomic_inc_return_unchecked(&next_id)
31507 };
31508 map.map_id = trace->id;
31509
31510@@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
31511 ioremap_trace_core(offset, size, addr);
31512 }
31513
31514-static void iounmap_trace_core(volatile void __iomem *addr)
31515+static void iounmap_trace_core(const volatile void __iomem *addr)
31516 {
31517 struct mmiotrace_map map = {
31518 .phys = 0,
31519@@ -328,7 +328,7 @@ not_enabled:
31520 }
31521 }
31522
31523-void mmiotrace_iounmap(volatile void __iomem *addr)
31524+void mmiotrace_iounmap(const volatile void __iomem *addr)
31525 {
31526 might_sleep();
31527 if (is_enabled()) /* recheck and proper locking in *_core() */
31528diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
31529index 8bf93ba..dbcd670 100644
31530--- a/arch/x86/mm/numa.c
31531+++ b/arch/x86/mm/numa.c
31532@@ -474,7 +474,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
31533 return true;
31534 }
31535
31536-static int __init numa_register_memblks(struct numa_meminfo *mi)
31537+static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
31538 {
31539 unsigned long uninitialized_var(pfn_align);
31540 int i, nid;
31541diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
31542index d0b1773..4c3327c 100644
31543--- a/arch/x86/mm/pageattr-test.c
31544+++ b/arch/x86/mm/pageattr-test.c
31545@@ -36,7 +36,7 @@ enum {
31546
31547 static int pte_testbit(pte_t pte)
31548 {
31549- return pte_flags(pte) & _PAGE_UNUSED1;
31550+ return pte_flags(pte) & _PAGE_CPA_TEST;
31551 }
31552
31553 struct split_state {
31554diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
31555index bb32480..75f2f5e 100644
31556--- a/arch/x86/mm/pageattr.c
31557+++ b/arch/x86/mm/pageattr.c
31558@@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
31559 */
31560 #ifdef CONFIG_PCI_BIOS
31561 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
31562- pgprot_val(forbidden) |= _PAGE_NX;
31563+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
31564 #endif
31565
31566 /*
31567@@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
31568 * Does not cover __inittext since that is gone later on. On
31569 * 64bit we do not enforce !NX on the low mapping
31570 */
31571- if (within(address, (unsigned long)_text, (unsigned long)_etext))
31572- pgprot_val(forbidden) |= _PAGE_NX;
31573+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
31574+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
31575
31576+#ifdef CONFIG_DEBUG_RODATA
31577 /*
31578 * The .rodata section needs to be read-only. Using the pfn
31579 * catches all aliases.
31580@@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
31581 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
31582 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
31583 pgprot_val(forbidden) |= _PAGE_RW;
31584+#endif
31585
31586 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
31587 /*
31588@@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
31589 }
31590 #endif
31591
31592+#ifdef CONFIG_PAX_KERNEXEC
31593+ if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
31594+ pgprot_val(forbidden) |= _PAGE_RW;
31595+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
31596+ }
31597+#endif
31598+
31599 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
31600
31601 return prot;
31602@@ -400,23 +409,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
31603 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
31604 {
31605 /* change init_mm */
31606+ pax_open_kernel();
31607 set_pte_atomic(kpte, pte);
31608+
31609 #ifdef CONFIG_X86_32
31610 if (!SHARED_KERNEL_PMD) {
31611+
31612+#ifdef CONFIG_PAX_PER_CPU_PGD
31613+ unsigned long cpu;
31614+#else
31615 struct page *page;
31616+#endif
31617
31618+#ifdef CONFIG_PAX_PER_CPU_PGD
31619+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
31620+ pgd_t *pgd = get_cpu_pgd(cpu, kernel);
31621+#else
31622 list_for_each_entry(page, &pgd_list, lru) {
31623- pgd_t *pgd;
31624+ pgd_t *pgd = (pgd_t *)page_address(page);
31625+#endif
31626+
31627 pud_t *pud;
31628 pmd_t *pmd;
31629
31630- pgd = (pgd_t *)page_address(page) + pgd_index(address);
31631+ pgd += pgd_index(address);
31632 pud = pud_offset(pgd, address);
31633 pmd = pmd_offset(pud, address);
31634 set_pte_atomic((pte_t *)pmd, pte);
31635 }
31636 }
31637 #endif
31638+ pax_close_kernel();
31639 }
31640
31641 static int
31642diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
31643index 6574388..87e9bef 100644
31644--- a/arch/x86/mm/pat.c
31645+++ b/arch/x86/mm/pat.c
31646@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
31647
31648 if (!entry) {
31649 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
31650- current->comm, current->pid, start, end - 1);
31651+ current->comm, task_pid_nr(current), start, end - 1);
31652 return -EINVAL;
31653 }
31654
31655@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31656
31657 while (cursor < to) {
31658 if (!devmem_is_allowed(pfn)) {
31659- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
31660- current->comm, from, to - 1);
31661+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
31662+ current->comm, from, to - 1, cursor);
31663 return 0;
31664 }
31665 cursor += PAGE_SIZE;
31666@@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
31667 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
31668 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
31669 "for [mem %#010Lx-%#010Lx]\n",
31670- current->comm, current->pid,
31671+ current->comm, task_pid_nr(current),
31672 cattr_name(flags),
31673 base, (unsigned long long)(base + size-1));
31674 return -EINVAL;
31675@@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
31676 flags = lookup_memtype(paddr);
31677 if (want_flags != flags) {
31678 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
31679- current->comm, current->pid,
31680+ current->comm, task_pid_nr(current),
31681 cattr_name(want_flags),
31682 (unsigned long long)paddr,
31683 (unsigned long long)(paddr + size - 1),
31684@@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
31685 free_memtype(paddr, paddr + size);
31686 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
31687 " for [mem %#010Lx-%#010Lx], got %s\n",
31688- current->comm, current->pid,
31689+ current->comm, task_pid_nr(current),
31690 cattr_name(want_flags),
31691 (unsigned long long)paddr,
31692 (unsigned long long)(paddr + size - 1),
31693diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
31694index 415f6c4..d319983 100644
31695--- a/arch/x86/mm/pat_rbtree.c
31696+++ b/arch/x86/mm/pat_rbtree.c
31697@@ -160,7 +160,7 @@ success:
31698
31699 failure:
31700 printk(KERN_INFO "%s:%d conflicting memory types "
31701- "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
31702+ "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
31703 end, cattr_name(found_type), cattr_name(match->type));
31704 return -EBUSY;
31705 }
31706diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
31707index 9f0614d..92ae64a 100644
31708--- a/arch/x86/mm/pf_in.c
31709+++ b/arch/x86/mm/pf_in.c
31710@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
31711 int i;
31712 enum reason_type rv = OTHERS;
31713
31714- p = (unsigned char *)ins_addr;
31715+ p = (unsigned char *)ktla_ktva(ins_addr);
31716 p += skip_prefix(p, &prf);
31717 p += get_opcode(p, &opcode);
31718
31719@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
31720 struct prefix_bits prf;
31721 int i;
31722
31723- p = (unsigned char *)ins_addr;
31724+ p = (unsigned char *)ktla_ktva(ins_addr);
31725 p += skip_prefix(p, &prf);
31726 p += get_opcode(p, &opcode);
31727
31728@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
31729 struct prefix_bits prf;
31730 int i;
31731
31732- p = (unsigned char *)ins_addr;
31733+ p = (unsigned char *)ktla_ktva(ins_addr);
31734 p += skip_prefix(p, &prf);
31735 p += get_opcode(p, &opcode);
31736
31737@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
31738 struct prefix_bits prf;
31739 int i;
31740
31741- p = (unsigned char *)ins_addr;
31742+ p = (unsigned char *)ktla_ktva(ins_addr);
31743 p += skip_prefix(p, &prf);
31744 p += get_opcode(p, &opcode);
31745 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
31746@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
31747 struct prefix_bits prf;
31748 int i;
31749
31750- p = (unsigned char *)ins_addr;
31751+ p = (unsigned char *)ktla_ktva(ins_addr);
31752 p += skip_prefix(p, &prf);
31753 p += get_opcode(p, &opcode);
31754 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
31755diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
31756index dfa537a..fd45c64 100644
31757--- a/arch/x86/mm/pgtable.c
31758+++ b/arch/x86/mm/pgtable.c
31759@@ -91,10 +91,67 @@ static inline void pgd_list_del(pgd_t *pgd)
31760 list_del(&page->lru);
31761 }
31762
31763-#define UNSHARED_PTRS_PER_PGD \
31764- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
31765+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31766+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
31767
31768+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
31769+{
31770+ unsigned int count = USER_PGD_PTRS;
31771
31772+ if (!pax_user_shadow_base)
31773+ return;
31774+
31775+ while (count--)
31776+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
31777+}
31778+#endif
31779+
31780+#ifdef CONFIG_PAX_PER_CPU_PGD
31781+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
31782+{
31783+ unsigned int count = USER_PGD_PTRS;
31784+
31785+ while (count--) {
31786+ pgd_t pgd;
31787+
31788+#ifdef CONFIG_X86_64
31789+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
31790+#else
31791+ pgd = *src++;
31792+#endif
31793+
31794+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31795+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
31796+#endif
31797+
31798+ *dst++ = pgd;
31799+ }
31800+
31801+}
31802+#endif
31803+
31804+#ifdef CONFIG_X86_64
31805+#define pxd_t pud_t
31806+#define pyd_t pgd_t
31807+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
31808+#define pxd_free(mm, pud) pud_free((mm), (pud))
31809+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
31810+#define pyd_offset(mm, address) pgd_offset((mm), (address))
31811+#define PYD_SIZE PGDIR_SIZE
31812+#else
31813+#define pxd_t pmd_t
31814+#define pyd_t pud_t
31815+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
31816+#define pxd_free(mm, pud) pmd_free((mm), (pud))
31817+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
31818+#define pyd_offset(mm, address) pud_offset((mm), (address))
31819+#define PYD_SIZE PUD_SIZE
31820+#endif
31821+
31822+#ifdef CONFIG_PAX_PER_CPU_PGD
31823+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
31824+static inline void pgd_dtor(pgd_t *pgd) {}
31825+#else
31826 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
31827 {
31828 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
31829@@ -135,6 +192,7 @@ static void pgd_dtor(pgd_t *pgd)
31830 pgd_list_del(pgd);
31831 spin_unlock(&pgd_lock);
31832 }
31833+#endif
31834
31835 /*
31836 * List of all pgd's needed for non-PAE so it can invalidate entries
31837@@ -147,7 +205,7 @@ static void pgd_dtor(pgd_t *pgd)
31838 * -- nyc
31839 */
31840
31841-#ifdef CONFIG_X86_PAE
31842+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
31843 /*
31844 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
31845 * updating the top-level pagetable entries to guarantee the
31846@@ -159,7 +217,7 @@ static void pgd_dtor(pgd_t *pgd)
31847 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
31848 * and initialize the kernel pmds here.
31849 */
31850-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
31851+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
31852
31853 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
31854 {
31855@@ -177,36 +235,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
31856 */
31857 flush_tlb_mm(mm);
31858 }
31859+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
31860+#define PREALLOCATED_PXDS USER_PGD_PTRS
31861 #else /* !CONFIG_X86_PAE */
31862
31863 /* No need to prepopulate any pagetable entries in non-PAE modes. */
31864-#define PREALLOCATED_PMDS 0
31865+#define PREALLOCATED_PXDS 0
31866
31867 #endif /* CONFIG_X86_PAE */
31868
31869-static void free_pmds(pmd_t *pmds[])
31870+static void free_pxds(pxd_t *pxds[])
31871 {
31872 int i;
31873
31874- for(i = 0; i < PREALLOCATED_PMDS; i++)
31875- if (pmds[i])
31876- free_page((unsigned long)pmds[i]);
31877+ for(i = 0; i < PREALLOCATED_PXDS; i++)
31878+ if (pxds[i])
31879+ free_page((unsigned long)pxds[i]);
31880 }
31881
31882-static int preallocate_pmds(pmd_t *pmds[])
31883+static int preallocate_pxds(pxd_t *pxds[])
31884 {
31885 int i;
31886 bool failed = false;
31887
31888- for(i = 0; i < PREALLOCATED_PMDS; i++) {
31889- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
31890- if (pmd == NULL)
31891+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
31892+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
31893+ if (pxd == NULL)
31894 failed = true;
31895- pmds[i] = pmd;
31896+ pxds[i] = pxd;
31897 }
31898
31899 if (failed) {
31900- free_pmds(pmds);
31901+ free_pxds(pxds);
31902 return -ENOMEM;
31903 }
31904
31905@@ -219,49 +279,52 @@ static int preallocate_pmds(pmd_t *pmds[])
31906 * preallocate which never got a corresponding vma will need to be
31907 * freed manually.
31908 */
31909-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
31910+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
31911 {
31912 int i;
31913
31914- for(i = 0; i < PREALLOCATED_PMDS; i++) {
31915+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
31916 pgd_t pgd = pgdp[i];
31917
31918 if (pgd_val(pgd) != 0) {
31919- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
31920+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
31921
31922- pgdp[i] = native_make_pgd(0);
31923+ set_pgd(pgdp + i, native_make_pgd(0));
31924
31925- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
31926- pmd_free(mm, pmd);
31927+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
31928+ pxd_free(mm, pxd);
31929 }
31930 }
31931 }
31932
31933-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
31934+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
31935 {
31936- pud_t *pud;
31937+ pyd_t *pyd;
31938 int i;
31939
31940- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
31941+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
31942 return;
31943
31944- pud = pud_offset(pgd, 0);
31945-
31946- for (i = 0; i < PREALLOCATED_PMDS; i++, pud++) {
31947- pmd_t *pmd = pmds[i];
31948+#ifdef CONFIG_X86_64
31949+ pyd = pyd_offset(mm, 0L);
31950+#else
31951+ pyd = pyd_offset(pgd, 0L);
31952+#endif
31953
31954+ for (i = 0; i < PREALLOCATED_PXDS; i++, pyd++) {
31955+ pxd_t *pxd = pxds[i];
31956 if (i >= KERNEL_PGD_BOUNDARY)
31957- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
31958- sizeof(pmd_t) * PTRS_PER_PMD);
31959+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
31960+ sizeof(pxd_t) * PTRS_PER_PMD);
31961
31962- pud_populate(mm, pud, pmd);
31963+ pyd_populate(mm, pyd, pxd);
31964 }
31965 }
31966
31967 pgd_t *pgd_alloc(struct mm_struct *mm)
31968 {
31969 pgd_t *pgd;
31970- pmd_t *pmds[PREALLOCATED_PMDS];
31971+ pxd_t *pxds[PREALLOCATED_PXDS];
31972
31973 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
31974
31975@@ -270,11 +333,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
31976
31977 mm->pgd = pgd;
31978
31979- if (preallocate_pmds(pmds) != 0)
31980+ if (preallocate_pxds(pxds) != 0)
31981 goto out_free_pgd;
31982
31983 if (paravirt_pgd_alloc(mm) != 0)
31984- goto out_free_pmds;
31985+ goto out_free_pxds;
31986
31987 /*
31988 * Make sure that pre-populating the pmds is atomic with
31989@@ -284,14 +347,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
31990 spin_lock(&pgd_lock);
31991
31992 pgd_ctor(mm, pgd);
31993- pgd_prepopulate_pmd(mm, pgd, pmds);
31994+ pgd_prepopulate_pxd(mm, pgd, pxds);
31995
31996 spin_unlock(&pgd_lock);
31997
31998 return pgd;
31999
32000-out_free_pmds:
32001- free_pmds(pmds);
32002+out_free_pxds:
32003+ free_pxds(pxds);
32004 out_free_pgd:
32005 free_page((unsigned long)pgd);
32006 out:
32007@@ -300,7 +363,7 @@ out:
32008
32009 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
32010 {
32011- pgd_mop_up_pmds(mm, pgd);
32012+ pgd_mop_up_pxds(mm, pgd);
32013 pgd_dtor(pgd);
32014 paravirt_pgd_free(mm, pgd);
32015 free_page((unsigned long)pgd);
32016diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
32017index a69bcb8..19068ab 100644
32018--- a/arch/x86/mm/pgtable_32.c
32019+++ b/arch/x86/mm/pgtable_32.c
32020@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
32021 return;
32022 }
32023 pte = pte_offset_kernel(pmd, vaddr);
32024+
32025+ pax_open_kernel();
32026 if (pte_val(pteval))
32027 set_pte_at(&init_mm, vaddr, pte, pteval);
32028 else
32029 pte_clear(&init_mm, vaddr, pte);
32030+ pax_close_kernel();
32031
32032 /*
32033 * It's enough to flush this one mapping.
32034diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
32035index e666cbb..61788c45 100644
32036--- a/arch/x86/mm/physaddr.c
32037+++ b/arch/x86/mm/physaddr.c
32038@@ -10,7 +10,7 @@
32039 #ifdef CONFIG_X86_64
32040
32041 #ifdef CONFIG_DEBUG_VIRTUAL
32042-unsigned long __phys_addr(unsigned long x)
32043+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
32044 {
32045 unsigned long y = x - __START_KERNEL_map;
32046
32047@@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
32048 #else
32049
32050 #ifdef CONFIG_DEBUG_VIRTUAL
32051-unsigned long __phys_addr(unsigned long x)
32052+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
32053 {
32054 unsigned long phys_addr = x - PAGE_OFFSET;
32055 /* VMALLOC_* aren't constants */
32056diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
32057index 90555bf..f5f1828 100644
32058--- a/arch/x86/mm/setup_nx.c
32059+++ b/arch/x86/mm/setup_nx.c
32060@@ -5,8 +5,10 @@
32061 #include <asm/pgtable.h>
32062 #include <asm/proto.h>
32063
32064+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
32065 static int disable_nx;
32066
32067+#ifndef CONFIG_PAX_PAGEEXEC
32068 /*
32069 * noexec = on|off
32070 *
32071@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
32072 return 0;
32073 }
32074 early_param("noexec", noexec_setup);
32075+#endif
32076+
32077+#endif
32078
32079 void x86_configure_nx(void)
32080 {
32081+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
32082 if (cpu_has_nx && !disable_nx)
32083 __supported_pte_mask |= _PAGE_NX;
32084 else
32085+#endif
32086 __supported_pte_mask &= ~_PAGE_NX;
32087 }
32088
32089diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
32090index 282375f..e03a98f 100644
32091--- a/arch/x86/mm/tlb.c
32092+++ b/arch/x86/mm/tlb.c
32093@@ -48,7 +48,11 @@ void leave_mm(int cpu)
32094 BUG();
32095 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
32096 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
32097+
32098+#ifndef CONFIG_PAX_PER_CPU_PGD
32099 load_cr3(swapper_pg_dir);
32100+#endif
32101+
32102 }
32103 }
32104 EXPORT_SYMBOL_GPL(leave_mm);
32105diff --git a/arch/x86/mm/uderef_64.c b/arch/x86/mm/uderef_64.c
32106new file mode 100644
32107index 0000000..dace51c
32108--- /dev/null
32109+++ b/arch/x86/mm/uderef_64.c
32110@@ -0,0 +1,37 @@
32111+#include <linux/mm.h>
32112+#include <asm/pgtable.h>
32113+#include <asm/uaccess.h>
32114+
32115+#ifdef CONFIG_PAX_MEMORY_UDEREF
32116+/* PaX: due to the special call convention these functions must
32117+ * - remain leaf functions under all configurations,
32118+ * - never be called directly, only dereferenced from the wrappers.
32119+ */
32120+void __pax_open_userland(void)
32121+{
32122+ unsigned int cpu;
32123+
32124+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
32125+ return;
32126+
32127+ cpu = raw_get_cpu();
32128+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_KERNEL);
32129+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
32130+ raw_put_cpu_no_resched();
32131+}
32132+EXPORT_SYMBOL(__pax_open_userland);
32133+
32134+void __pax_close_userland(void)
32135+{
32136+ unsigned int cpu;
32137+
32138+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
32139+ return;
32140+
32141+ cpu = raw_get_cpu();
32142+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_USER);
32143+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
32144+ raw_put_cpu_no_resched();
32145+}
32146+EXPORT_SYMBOL(__pax_close_userland);
32147+#endif
32148diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
32149index 877b9a1..a8ecf42 100644
32150--- a/arch/x86/net/bpf_jit.S
32151+++ b/arch/x86/net/bpf_jit.S
32152@@ -9,6 +9,7 @@
32153 */
32154 #include <linux/linkage.h>
32155 #include <asm/dwarf2.h>
32156+#include <asm/alternative-asm.h>
32157
32158 /*
32159 * Calling convention :
32160@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
32161 jle bpf_slow_path_word
32162 mov (SKBDATA,%rsi),%eax
32163 bswap %eax /* ntohl() */
32164+ pax_force_retaddr
32165 ret
32166
32167 sk_load_half:
32168@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
32169 jle bpf_slow_path_half
32170 movzwl (SKBDATA,%rsi),%eax
32171 rol $8,%ax # ntohs()
32172+ pax_force_retaddr
32173 ret
32174
32175 sk_load_byte:
32176@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
32177 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
32178 jle bpf_slow_path_byte
32179 movzbl (SKBDATA,%rsi),%eax
32180+ pax_force_retaddr
32181 ret
32182
32183 /**
32184@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
32185 movzbl (SKBDATA,%rsi),%ebx
32186 and $15,%bl
32187 shl $2,%bl
32188+ pax_force_retaddr
32189 ret
32190
32191 /* rsi contains offset and can be scratched */
32192@@ -109,6 +114,7 @@ bpf_slow_path_word:
32193 js bpf_error
32194 mov -12(%rbp),%eax
32195 bswap %eax
32196+ pax_force_retaddr
32197 ret
32198
32199 bpf_slow_path_half:
32200@@ -117,12 +123,14 @@ bpf_slow_path_half:
32201 mov -12(%rbp),%ax
32202 rol $8,%ax
32203 movzwl %ax,%eax
32204+ pax_force_retaddr
32205 ret
32206
32207 bpf_slow_path_byte:
32208 bpf_slow_path_common(1)
32209 js bpf_error
32210 movzbl -12(%rbp),%eax
32211+ pax_force_retaddr
32212 ret
32213
32214 bpf_slow_path_byte_msh:
32215@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
32216 and $15,%al
32217 shl $2,%al
32218 xchg %eax,%ebx
32219+ pax_force_retaddr
32220 ret
32221
32222 #define sk_negative_common(SIZE) \
32223@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
32224 sk_negative_common(4)
32225 mov (%rax), %eax
32226 bswap %eax
32227+ pax_force_retaddr
32228 ret
32229
32230 bpf_slow_path_half_neg:
32231@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
32232 mov (%rax),%ax
32233 rol $8,%ax
32234 movzwl %ax,%eax
32235+ pax_force_retaddr
32236 ret
32237
32238 bpf_slow_path_byte_neg:
32239@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
32240 .globl sk_load_byte_negative_offset
32241 sk_negative_common(1)
32242 movzbl (%rax), %eax
32243+ pax_force_retaddr
32244 ret
32245
32246 bpf_slow_path_byte_msh_neg:
32247@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
32248 and $15,%al
32249 shl $2,%al
32250 xchg %eax,%ebx
32251+ pax_force_retaddr
32252 ret
32253
32254 bpf_error:
32255@@ -197,4 +210,5 @@ bpf_error:
32256 xor %eax,%eax
32257 mov -8(%rbp),%rbx
32258 leaveq
32259+ pax_force_retaddr
32260 ret
32261diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
32262index 79c216a..08d39cc 100644
32263--- a/arch/x86/net/bpf_jit_comp.c
32264+++ b/arch/x86/net/bpf_jit_comp.c
32265@@ -50,13 +50,90 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
32266 return ptr + len;
32267 }
32268
32269+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32270+#define MAX_INSTR_CODE_SIZE 96
32271+#else
32272+#define MAX_INSTR_CODE_SIZE 64
32273+#endif
32274+
32275 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
32276
32277 #define EMIT1(b1) EMIT(b1, 1)
32278 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
32279 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
32280 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
32281+
32282+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32283+/* original constant will appear in ecx */
32284+#define DILUTE_CONST_SEQUENCE(_off, _key) \
32285+do { \
32286+ /* mov ecx, randkey */ \
32287+ EMIT1(0xb9); \
32288+ EMIT(_key, 4); \
32289+ /* xor ecx, randkey ^ off */ \
32290+ EMIT2(0x81, 0xf1); \
32291+ EMIT((_key) ^ (_off), 4); \
32292+} while (0)
32293+
32294+#define EMIT1_off32(b1, _off) \
32295+do { \
32296+ switch (b1) { \
32297+ case 0x05: /* add eax, imm32 */ \
32298+ case 0x2d: /* sub eax, imm32 */ \
32299+ case 0x25: /* and eax, imm32 */ \
32300+ case 0x0d: /* or eax, imm32 */ \
32301+ case 0xb8: /* mov eax, imm32 */ \
32302+ case 0x35: /* xor eax, imm32 */ \
32303+ case 0x3d: /* cmp eax, imm32 */ \
32304+ case 0xa9: /* test eax, imm32 */ \
32305+ DILUTE_CONST_SEQUENCE(_off, randkey); \
32306+ EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
32307+ break; \
32308+ case 0xbb: /* mov ebx, imm32 */ \
32309+ DILUTE_CONST_SEQUENCE(_off, randkey); \
32310+ /* mov ebx, ecx */ \
32311+ EMIT2(0x89, 0xcb); \
32312+ break; \
32313+ case 0xbe: /* mov esi, imm32 */ \
32314+ DILUTE_CONST_SEQUENCE(_off, randkey); \
32315+ /* mov esi, ecx */ \
32316+ EMIT2(0x89, 0xce); \
32317+ break; \
32318+ case 0xe8: /* call rel imm32, always to known funcs */ \
32319+ EMIT1(b1); \
32320+ EMIT(_off, 4); \
32321+ break; \
32322+ case 0xe9: /* jmp rel imm32 */ \
32323+ EMIT1(b1); \
32324+ EMIT(_off, 4); \
32325+ /* prevent fall-through, we're not called if off = 0 */ \
32326+ EMIT(0xcccccccc, 4); \
32327+ EMIT(0xcccccccc, 4); \
32328+ break; \
32329+ default: \
32330+ BUILD_BUG(); \
32331+ } \
32332+} while (0)
32333+
32334+#define EMIT2_off32(b1, b2, _off) \
32335+do { \
32336+ if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
32337+ EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
32338+ EMIT(randkey, 4); \
32339+ EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
32340+ EMIT((_off) - randkey, 4); \
32341+ } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
32342+ DILUTE_CONST_SEQUENCE(_off, randkey); \
32343+ /* imul eax, ecx */ \
32344+ EMIT3(0x0f, 0xaf, 0xc1); \
32345+ } else { \
32346+ BUILD_BUG(); \
32347+ } \
32348+} while (0)
32349+#else
32350 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
32351+#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
32352+#endif
32353
32354 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
32355 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
32356@@ -91,6 +168,24 @@ do { \
32357 #define X86_JBE 0x76
32358 #define X86_JA 0x77
32359
32360+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32361+#define APPEND_FLOW_VERIFY() \
32362+do { \
32363+ /* mov ecx, randkey */ \
32364+ EMIT1(0xb9); \
32365+ EMIT(randkey, 4); \
32366+ /* cmp ecx, randkey */ \
32367+ EMIT2(0x81, 0xf9); \
32368+ EMIT(randkey, 4); \
32369+ /* jz after 8 int 3s */ \
32370+ EMIT2(0x74, 0x08); \
32371+ EMIT(0xcccccccc, 4); \
32372+ EMIT(0xcccccccc, 4); \
32373+} while (0)
32374+#else
32375+#define APPEND_FLOW_VERIFY() do { } while (0)
32376+#endif
32377+
32378 #define EMIT_COND_JMP(op, offset) \
32379 do { \
32380 if (is_near(offset)) \
32381@@ -98,6 +193,7 @@ do { \
32382 else { \
32383 EMIT2(0x0f, op + 0x10); \
32384 EMIT(offset, 4); /* jxx .+off32 */ \
32385+ APPEND_FLOW_VERIFY(); \
32386 } \
32387 } while (0)
32388
32389@@ -145,55 +241,54 @@ static int pkt_type_offset(void)
32390 return -1;
32391 }
32392
32393-struct bpf_binary_header {
32394- unsigned int pages;
32395- /* Note : for security reasons, bpf code will follow a randomly
32396- * sized amount of int3 instructions
32397- */
32398- u8 image[];
32399-};
32400-
32401-static struct bpf_binary_header *bpf_alloc_binary(unsigned int proglen,
32402+/* Note : for security reasons, bpf code will follow a randomly
32403+ * sized amount of int3 instructions
32404+ */
32405+static u8 *bpf_alloc_binary(unsigned int proglen,
32406 u8 **image_ptr)
32407 {
32408 unsigned int sz, hole;
32409- struct bpf_binary_header *header;
32410+ u8 *header;
32411
32412 /* Most of BPF filters are really small,
32413 * but if some of them fill a page, allow at least
32414 * 128 extra bytes to insert a random section of int3
32415 */
32416- sz = round_up(proglen + sizeof(*header) + 128, PAGE_SIZE);
32417- header = module_alloc(sz);
32418+ sz = round_up(proglen + 128, PAGE_SIZE);
32419+ header = module_alloc_exec(sz);
32420 if (!header)
32421 return NULL;
32422
32423+ pax_open_kernel();
32424 memset(header, 0xcc, sz); /* fill whole space with int3 instructions */
32425+ pax_close_kernel();
32426
32427- header->pages = sz / PAGE_SIZE;
32428- hole = sz - (proglen + sizeof(*header));
32429+ hole = PAGE_SIZE - (proglen & ~PAGE_MASK);
32430
32431 /* insert a random number of int3 instructions before BPF code */
32432- *image_ptr = &header->image[prandom_u32() % hole];
32433+ *image_ptr = &header[prandom_u32() % hole];
32434 return header;
32435 }
32436
32437 void bpf_jit_compile(struct sk_filter *fp)
32438 {
32439- u8 temp[64];
32440+ u8 temp[MAX_INSTR_CODE_SIZE];
32441 u8 *prog;
32442 unsigned int proglen, oldproglen = 0;
32443 int ilen, i;
32444 int t_offset, f_offset;
32445 u8 t_op, f_op, seen = 0, pass;
32446 u8 *image = NULL;
32447- struct bpf_binary_header *header = NULL;
32448+ u8 *header = NULL;
32449 u8 *func;
32450 int pc_ret0 = -1; /* bpf index of first RET #0 instruction (if any) */
32451 unsigned int cleanup_addr; /* epilogue code offset */
32452 unsigned int *addrs;
32453 const struct sock_filter *filter = fp->insns;
32454 int flen = fp->len;
32455+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32456+ unsigned int randkey;
32457+#endif
32458
32459 if (!bpf_jit_enable)
32460 return;
32461@@ -202,11 +297,15 @@ void bpf_jit_compile(struct sk_filter *fp)
32462 if (addrs == NULL)
32463 return;
32464
32465+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32466+ randkey = get_random_int();
32467+#endif
32468+
32469 /* Before first pass, make a rough estimation of addrs[]
32470- * each bpf instruction is translated to less than 64 bytes
32471+ * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
32472 */
32473 for (proglen = 0, i = 0; i < flen; i++) {
32474- proglen += 64;
32475+ proglen += MAX_INSTR_CODE_SIZE;
32476 addrs[i] = proglen;
32477 }
32478 cleanup_addr = proglen; /* epilogue address */
32479@@ -317,10 +416,8 @@ void bpf_jit_compile(struct sk_filter *fp)
32480 case BPF_S_ALU_MUL_K: /* A *= K */
32481 if (is_imm8(K))
32482 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
32483- else {
32484- EMIT2(0x69, 0xc0); /* imul imm32,%eax */
32485- EMIT(K, 4);
32486- }
32487+ else
32488+ EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
32489 break;
32490 case BPF_S_ALU_DIV_X: /* A /= X; */
32491 seen |= SEEN_XREG;
32492@@ -360,13 +457,23 @@ void bpf_jit_compile(struct sk_filter *fp)
32493 break;
32494 case BPF_S_ALU_MOD_K: /* A %= K; */
32495 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
32496+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32497+ DILUTE_CONST_SEQUENCE(K, randkey);
32498+#else
32499 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
32500+#endif
32501 EMIT2(0xf7, 0xf1); /* div %ecx */
32502 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
32503 break;
32504 case BPF_S_ALU_DIV_K: /* A = reciprocal_divide(A, K); */
32505+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32506+ DILUTE_CONST_SEQUENCE(K, randkey);
32507+ // imul rax, rcx
32508+ EMIT4(0x48, 0x0f, 0xaf, 0xc1);
32509+#else
32510 EMIT3(0x48, 0x69, 0xc0); /* imul imm32,%rax,%rax */
32511 EMIT(K, 4);
32512+#endif
32513 EMIT4(0x48, 0xc1, 0xe8, 0x20); /* shr $0x20,%rax */
32514 break;
32515 case BPF_S_ALU_AND_X:
32516@@ -637,8 +744,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
32517 if (is_imm8(K)) {
32518 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
32519 } else {
32520- EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
32521- EMIT(K, 4);
32522+ EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
32523 }
32524 } else {
32525 EMIT2(0x89,0xde); /* mov %ebx,%esi */
32526@@ -728,10 +834,12 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
32527 if (unlikely(proglen + ilen > oldproglen)) {
32528 pr_err("bpb_jit_compile fatal error\n");
32529 kfree(addrs);
32530- module_free(NULL, header);
32531+ module_free_exec(NULL, image);
32532 return;
32533 }
32534+ pax_open_kernel();
32535 memcpy(image + proglen, temp, ilen);
32536+ pax_close_kernel();
32537 }
32538 proglen += ilen;
32539 addrs[i] = proglen;
32540@@ -764,7 +872,6 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
32541
32542 if (image) {
32543 bpf_flush_icache(header, image + proglen);
32544- set_memory_ro((unsigned long)header, header->pages);
32545 fp->bpf_func = (void *)image;
32546 }
32547 out:
32548@@ -776,9 +883,7 @@ void bpf_jit_free(struct sk_filter *fp)
32549 {
32550 if (fp->bpf_func != sk_run_filter) {
32551 unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
32552- struct bpf_binary_header *header = (void *)addr;
32553-
32554- set_memory_rw(addr, header->pages);
32555- module_free(NULL, header);
32556+ set_memory_rw(addr, 1);
32557+ module_free_exec(NULL, (void *)addr);
32558 }
32559 }
32560diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
32561index d6aa6e8..266395a 100644
32562--- a/arch/x86/oprofile/backtrace.c
32563+++ b/arch/x86/oprofile/backtrace.c
32564@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
32565 struct stack_frame_ia32 *fp;
32566 unsigned long bytes;
32567
32568- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
32569+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
32570 if (bytes != sizeof(bufhead))
32571 return NULL;
32572
32573- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
32574+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
32575
32576 oprofile_add_trace(bufhead[0].return_address);
32577
32578@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
32579 struct stack_frame bufhead[2];
32580 unsigned long bytes;
32581
32582- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
32583+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
32584 if (bytes != sizeof(bufhead))
32585 return NULL;
32586
32587@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
32588 {
32589 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
32590
32591- if (!user_mode_vm(regs)) {
32592+ if (!user_mode(regs)) {
32593 unsigned long stack = kernel_stack_pointer(regs);
32594 if (depth)
32595 dump_trace(NULL, regs, (unsigned long *)stack, 0,
32596diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
32597index 48768df..ba9143c 100644
32598--- a/arch/x86/oprofile/nmi_int.c
32599+++ b/arch/x86/oprofile/nmi_int.c
32600@@ -23,6 +23,7 @@
32601 #include <asm/nmi.h>
32602 #include <asm/msr.h>
32603 #include <asm/apic.h>
32604+#include <asm/pgtable.h>
32605
32606 #include "op_counter.h"
32607 #include "op_x86_model.h"
32608@@ -774,8 +775,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
32609 if (ret)
32610 return ret;
32611
32612- if (!model->num_virt_counters)
32613- model->num_virt_counters = model->num_counters;
32614+ if (!model->num_virt_counters) {
32615+ pax_open_kernel();
32616+ *(unsigned int *)&model->num_virt_counters = model->num_counters;
32617+ pax_close_kernel();
32618+ }
32619
32620 mux_init(ops);
32621
32622diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
32623index b2b9443..be58856 100644
32624--- a/arch/x86/oprofile/op_model_amd.c
32625+++ b/arch/x86/oprofile/op_model_amd.c
32626@@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
32627 num_counters = AMD64_NUM_COUNTERS;
32628 }
32629
32630- op_amd_spec.num_counters = num_counters;
32631- op_amd_spec.num_controls = num_counters;
32632- op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
32633+ pax_open_kernel();
32634+ *(unsigned int *)&op_amd_spec.num_counters = num_counters;
32635+ *(unsigned int *)&op_amd_spec.num_controls = num_counters;
32636+ *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
32637+ pax_close_kernel();
32638
32639 return 0;
32640 }
32641diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
32642index d90528e..0127e2b 100644
32643--- a/arch/x86/oprofile/op_model_ppro.c
32644+++ b/arch/x86/oprofile/op_model_ppro.c
32645@@ -19,6 +19,7 @@
32646 #include <asm/msr.h>
32647 #include <asm/apic.h>
32648 #include <asm/nmi.h>
32649+#include <asm/pgtable.h>
32650
32651 #include "op_x86_model.h"
32652 #include "op_counter.h"
32653@@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
32654
32655 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
32656
32657- op_arch_perfmon_spec.num_counters = num_counters;
32658- op_arch_perfmon_spec.num_controls = num_counters;
32659+ pax_open_kernel();
32660+ *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
32661+ *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
32662+ pax_close_kernel();
32663 }
32664
32665 static int arch_perfmon_init(struct oprofile_operations *ignore)
32666diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
32667index 71e8a67..6a313bb 100644
32668--- a/arch/x86/oprofile/op_x86_model.h
32669+++ b/arch/x86/oprofile/op_x86_model.h
32670@@ -52,7 +52,7 @@ struct op_x86_model_spec {
32671 void (*switch_ctrl)(struct op_x86_model_spec const *model,
32672 struct op_msrs const * const msrs);
32673 #endif
32674-};
32675+} __do_const;
32676
32677 struct op_counter_config;
32678
32679diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
32680index 372e9b8..e775a6c 100644
32681--- a/arch/x86/pci/irq.c
32682+++ b/arch/x86/pci/irq.c
32683@@ -50,7 +50,7 @@ struct irq_router {
32684 struct irq_router_handler {
32685 u16 vendor;
32686 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
32687-};
32688+} __do_const;
32689
32690 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
32691 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
32692@@ -794,7 +794,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
32693 return 0;
32694 }
32695
32696-static __initdata struct irq_router_handler pirq_routers[] = {
32697+static __initconst const struct irq_router_handler pirq_routers[] = {
32698 { PCI_VENDOR_ID_INTEL, intel_router_probe },
32699 { PCI_VENDOR_ID_AL, ali_router_probe },
32700 { PCI_VENDOR_ID_ITE, ite_router_probe },
32701@@ -821,7 +821,7 @@ static struct pci_dev *pirq_router_dev;
32702 static void __init pirq_find_router(struct irq_router *r)
32703 {
32704 struct irq_routing_table *rt = pirq_table;
32705- struct irq_router_handler *h;
32706+ const struct irq_router_handler *h;
32707
32708 #ifdef CONFIG_PCI_BIOS
32709 if (!rt->signature) {
32710@@ -1094,7 +1094,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
32711 return 0;
32712 }
32713
32714-static struct dmi_system_id __initdata pciirq_dmi_table[] = {
32715+static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
32716 {
32717 .callback = fix_broken_hp_bios_irq9,
32718 .ident = "HP Pavilion N5400 Series Laptop",
32719diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
32720index 6eb18c4..20d83de 100644
32721--- a/arch/x86/pci/mrst.c
32722+++ b/arch/x86/pci/mrst.c
32723@@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
32724 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
32725 pci_mmcfg_late_init();
32726 pcibios_enable_irq = mrst_pci_irq_enable;
32727- pci_root_ops = pci_mrst_ops;
32728+ pax_open_kernel();
32729+ memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
32730+ pax_close_kernel();
32731 pci_soc_mode = 1;
32732 /* Continue with standard init */
32733 return 1;
32734diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
32735index c77b24a..c979855 100644
32736--- a/arch/x86/pci/pcbios.c
32737+++ b/arch/x86/pci/pcbios.c
32738@@ -79,7 +79,7 @@ union bios32 {
32739 static struct {
32740 unsigned long address;
32741 unsigned short segment;
32742-} bios32_indirect = { 0, __KERNEL_CS };
32743+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
32744
32745 /*
32746 * Returns the entry point for the given service, NULL on error
32747@@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
32748 unsigned long length; /* %ecx */
32749 unsigned long entry; /* %edx */
32750 unsigned long flags;
32751+ struct desc_struct d, *gdt;
32752
32753 local_irq_save(flags);
32754- __asm__("lcall *(%%edi); cld"
32755+
32756+ gdt = get_cpu_gdt_table(smp_processor_id());
32757+
32758+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
32759+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
32760+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
32761+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
32762+
32763+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
32764 : "=a" (return_code),
32765 "=b" (address),
32766 "=c" (length),
32767 "=d" (entry)
32768 : "0" (service),
32769 "1" (0),
32770- "D" (&bios32_indirect));
32771+ "D" (&bios32_indirect),
32772+ "r"(__PCIBIOS_DS)
32773+ : "memory");
32774+
32775+ pax_open_kernel();
32776+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
32777+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
32778+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
32779+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
32780+ pax_close_kernel();
32781+
32782 local_irq_restore(flags);
32783
32784 switch (return_code) {
32785- case 0:
32786- return address + entry;
32787- case 0x80: /* Not present */
32788- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
32789- return 0;
32790- default: /* Shouldn't happen */
32791- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
32792- service, return_code);
32793+ case 0: {
32794+ int cpu;
32795+ unsigned char flags;
32796+
32797+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
32798+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
32799+ printk(KERN_WARNING "bios32_service: not valid\n");
32800 return 0;
32801+ }
32802+ address = address + PAGE_OFFSET;
32803+ length += 16UL; /* some BIOSs underreport this... */
32804+ flags = 4;
32805+ if (length >= 64*1024*1024) {
32806+ length >>= PAGE_SHIFT;
32807+ flags |= 8;
32808+ }
32809+
32810+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
32811+ gdt = get_cpu_gdt_table(cpu);
32812+ pack_descriptor(&d, address, length, 0x9b, flags);
32813+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
32814+ pack_descriptor(&d, address, length, 0x93, flags);
32815+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
32816+ }
32817+ return entry;
32818+ }
32819+ case 0x80: /* Not present */
32820+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
32821+ return 0;
32822+ default: /* Shouldn't happen */
32823+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
32824+ service, return_code);
32825+ return 0;
32826 }
32827 }
32828
32829 static struct {
32830 unsigned long address;
32831 unsigned short segment;
32832-} pci_indirect = { 0, __KERNEL_CS };
32833+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
32834
32835-static int pci_bios_present;
32836+static int pci_bios_present __read_only;
32837
32838 static int check_pcibios(void)
32839 {
32840@@ -131,11 +174,13 @@ static int check_pcibios(void)
32841 unsigned long flags, pcibios_entry;
32842
32843 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
32844- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
32845+ pci_indirect.address = pcibios_entry;
32846
32847 local_irq_save(flags);
32848- __asm__(
32849- "lcall *(%%edi); cld\n\t"
32850+ __asm__("movw %w6, %%ds\n\t"
32851+ "lcall *%%ss:(%%edi); cld\n\t"
32852+ "push %%ss\n\t"
32853+ "pop %%ds\n\t"
32854 "jc 1f\n\t"
32855 "xor %%ah, %%ah\n"
32856 "1:"
32857@@ -144,7 +189,8 @@ static int check_pcibios(void)
32858 "=b" (ebx),
32859 "=c" (ecx)
32860 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
32861- "D" (&pci_indirect)
32862+ "D" (&pci_indirect),
32863+ "r" (__PCIBIOS_DS)
32864 : "memory");
32865 local_irq_restore(flags);
32866
32867@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32868
32869 switch (len) {
32870 case 1:
32871- __asm__("lcall *(%%esi); cld\n\t"
32872+ __asm__("movw %w6, %%ds\n\t"
32873+ "lcall *%%ss:(%%esi); cld\n\t"
32874+ "push %%ss\n\t"
32875+ "pop %%ds\n\t"
32876 "jc 1f\n\t"
32877 "xor %%ah, %%ah\n"
32878 "1:"
32879@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32880 : "1" (PCIBIOS_READ_CONFIG_BYTE),
32881 "b" (bx),
32882 "D" ((long)reg),
32883- "S" (&pci_indirect));
32884+ "S" (&pci_indirect),
32885+ "r" (__PCIBIOS_DS));
32886 /*
32887 * Zero-extend the result beyond 8 bits, do not trust the
32888 * BIOS having done it:
32889@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32890 *value &= 0xff;
32891 break;
32892 case 2:
32893- __asm__("lcall *(%%esi); cld\n\t"
32894+ __asm__("movw %w6, %%ds\n\t"
32895+ "lcall *%%ss:(%%esi); cld\n\t"
32896+ "push %%ss\n\t"
32897+ "pop %%ds\n\t"
32898 "jc 1f\n\t"
32899 "xor %%ah, %%ah\n"
32900 "1:"
32901@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32902 : "1" (PCIBIOS_READ_CONFIG_WORD),
32903 "b" (bx),
32904 "D" ((long)reg),
32905- "S" (&pci_indirect));
32906+ "S" (&pci_indirect),
32907+ "r" (__PCIBIOS_DS));
32908 /*
32909 * Zero-extend the result beyond 16 bits, do not trust the
32910 * BIOS having done it:
32911@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32912 *value &= 0xffff;
32913 break;
32914 case 4:
32915- __asm__("lcall *(%%esi); cld\n\t"
32916+ __asm__("movw %w6, %%ds\n\t"
32917+ "lcall *%%ss:(%%esi); cld\n\t"
32918+ "push %%ss\n\t"
32919+ "pop %%ds\n\t"
32920 "jc 1f\n\t"
32921 "xor %%ah, %%ah\n"
32922 "1:"
32923@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32924 : "1" (PCIBIOS_READ_CONFIG_DWORD),
32925 "b" (bx),
32926 "D" ((long)reg),
32927- "S" (&pci_indirect));
32928+ "S" (&pci_indirect),
32929+ "r" (__PCIBIOS_DS));
32930 break;
32931 }
32932
32933@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
32934
32935 switch (len) {
32936 case 1:
32937- __asm__("lcall *(%%esi); cld\n\t"
32938+ __asm__("movw %w6, %%ds\n\t"
32939+ "lcall *%%ss:(%%esi); cld\n\t"
32940+ "push %%ss\n\t"
32941+ "pop %%ds\n\t"
32942 "jc 1f\n\t"
32943 "xor %%ah, %%ah\n"
32944 "1:"
32945@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
32946 "c" (value),
32947 "b" (bx),
32948 "D" ((long)reg),
32949- "S" (&pci_indirect));
32950+ "S" (&pci_indirect),
32951+ "r" (__PCIBIOS_DS));
32952 break;
32953 case 2:
32954- __asm__("lcall *(%%esi); cld\n\t"
32955+ __asm__("movw %w6, %%ds\n\t"
32956+ "lcall *%%ss:(%%esi); cld\n\t"
32957+ "push %%ss\n\t"
32958+ "pop %%ds\n\t"
32959 "jc 1f\n\t"
32960 "xor %%ah, %%ah\n"
32961 "1:"
32962@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
32963 "c" (value),
32964 "b" (bx),
32965 "D" ((long)reg),
32966- "S" (&pci_indirect));
32967+ "S" (&pci_indirect),
32968+ "r" (__PCIBIOS_DS));
32969 break;
32970 case 4:
32971- __asm__("lcall *(%%esi); cld\n\t"
32972+ __asm__("movw %w6, %%ds\n\t"
32973+ "lcall *%%ss:(%%esi); cld\n\t"
32974+ "push %%ss\n\t"
32975+ "pop %%ds\n\t"
32976 "jc 1f\n\t"
32977 "xor %%ah, %%ah\n"
32978 "1:"
32979@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
32980 "c" (value),
32981 "b" (bx),
32982 "D" ((long)reg),
32983- "S" (&pci_indirect));
32984+ "S" (&pci_indirect),
32985+ "r" (__PCIBIOS_DS));
32986 break;
32987 }
32988
32989@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
32990
32991 DBG("PCI: Fetching IRQ routing table... ");
32992 __asm__("push %%es\n\t"
32993+ "movw %w8, %%ds\n\t"
32994 "push %%ds\n\t"
32995 "pop %%es\n\t"
32996- "lcall *(%%esi); cld\n\t"
32997+ "lcall *%%ss:(%%esi); cld\n\t"
32998 "pop %%es\n\t"
32999+ "push %%ss\n\t"
33000+ "pop %%ds\n"
33001 "jc 1f\n\t"
33002 "xor %%ah, %%ah\n"
33003 "1:"
33004@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
33005 "1" (0),
33006 "D" ((long) &opt),
33007 "S" (&pci_indirect),
33008- "m" (opt)
33009+ "m" (opt),
33010+ "r" (__PCIBIOS_DS)
33011 : "memory");
33012 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
33013 if (ret & 0xff00)
33014@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
33015 {
33016 int ret;
33017
33018- __asm__("lcall *(%%esi); cld\n\t"
33019+ __asm__("movw %w5, %%ds\n\t"
33020+ "lcall *%%ss:(%%esi); cld\n\t"
33021+ "push %%ss\n\t"
33022+ "pop %%ds\n"
33023 "jc 1f\n\t"
33024 "xor %%ah, %%ah\n"
33025 "1:"
33026@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
33027 : "0" (PCIBIOS_SET_PCI_HW_INT),
33028 "b" ((dev->bus->number << 8) | dev->devfn),
33029 "c" ((irq << 8) | (pin + 10)),
33030- "S" (&pci_indirect));
33031+ "S" (&pci_indirect),
33032+ "r" (__PCIBIOS_DS));
33033 return !(ret & 0xff00);
33034 }
33035 EXPORT_SYMBOL(pcibios_set_irq_routing);
33036diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
33037index 40e4469..d915bf9 100644
33038--- a/arch/x86/platform/efi/efi_32.c
33039+++ b/arch/x86/platform/efi/efi_32.c
33040@@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
33041 {
33042 struct desc_ptr gdt_descr;
33043
33044+#ifdef CONFIG_PAX_KERNEXEC
33045+ struct desc_struct d;
33046+#endif
33047+
33048 local_irq_save(efi_rt_eflags);
33049
33050 load_cr3(initial_page_table);
33051 __flush_tlb_all();
33052
33053+#ifdef CONFIG_PAX_KERNEXEC
33054+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
33055+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
33056+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
33057+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
33058+#endif
33059+
33060 gdt_descr.address = __pa(get_cpu_gdt_table(0));
33061 gdt_descr.size = GDT_SIZE - 1;
33062 load_gdt(&gdt_descr);
33063@@ -58,11 +69,24 @@ void efi_call_phys_epilog(void)
33064 {
33065 struct desc_ptr gdt_descr;
33066
33067+#ifdef CONFIG_PAX_KERNEXEC
33068+ struct desc_struct d;
33069+
33070+ memset(&d, 0, sizeof d);
33071+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
33072+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
33073+#endif
33074+
33075 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
33076 gdt_descr.size = GDT_SIZE - 1;
33077 load_gdt(&gdt_descr);
33078
33079+#ifdef CONFIG_PAX_PER_CPU_PGD
33080+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
33081+#else
33082 load_cr3(swapper_pg_dir);
33083+#endif
33084+
33085 __flush_tlb_all();
33086
33087 local_irq_restore(efi_rt_eflags);
33088diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
33089index 39a0e7f1..872396e 100644
33090--- a/arch/x86/platform/efi/efi_64.c
33091+++ b/arch/x86/platform/efi/efi_64.c
33092@@ -76,6 +76,11 @@ void __init efi_call_phys_prelog(void)
33093 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
33094 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
33095 }
33096+
33097+#ifdef CONFIG_PAX_PER_CPU_PGD
33098+ load_cr3(swapper_pg_dir);
33099+#endif
33100+
33101 __flush_tlb_all();
33102 }
33103
33104@@ -89,6 +94,11 @@ void __init efi_call_phys_epilog(void)
33105 for (pgd = 0; pgd < n_pgds; pgd++)
33106 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
33107 kfree(save_pgd);
33108+
33109+#ifdef CONFIG_PAX_PER_CPU_PGD
33110+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
33111+#endif
33112+
33113 __flush_tlb_all();
33114 local_irq_restore(efi_flags);
33115 early_code_mapping_set_exec(0);
33116diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
33117index fbe66e6..eae5e38 100644
33118--- a/arch/x86/platform/efi/efi_stub_32.S
33119+++ b/arch/x86/platform/efi/efi_stub_32.S
33120@@ -6,7 +6,9 @@
33121 */
33122
33123 #include <linux/linkage.h>
33124+#include <linux/init.h>
33125 #include <asm/page_types.h>
33126+#include <asm/segment.h>
33127
33128 /*
33129 * efi_call_phys(void *, ...) is a function with variable parameters.
33130@@ -20,7 +22,7 @@
33131 * service functions will comply with gcc calling convention, too.
33132 */
33133
33134-.text
33135+__INIT
33136 ENTRY(efi_call_phys)
33137 /*
33138 * 0. The function can only be called in Linux kernel. So CS has been
33139@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
33140 * The mapping of lower virtual memory has been created in prelog and
33141 * epilog.
33142 */
33143- movl $1f, %edx
33144- subl $__PAGE_OFFSET, %edx
33145- jmp *%edx
33146+#ifdef CONFIG_PAX_KERNEXEC
33147+ movl $(__KERNEXEC_EFI_DS), %edx
33148+ mov %edx, %ds
33149+ mov %edx, %es
33150+ mov %edx, %ss
33151+ addl $2f,(1f)
33152+ ljmp *(1f)
33153+
33154+__INITDATA
33155+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
33156+.previous
33157+
33158+2:
33159+ subl $2b,(1b)
33160+#else
33161+ jmp 1f-__PAGE_OFFSET
33162 1:
33163+#endif
33164
33165 /*
33166 * 2. Now on the top of stack is the return
33167@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
33168 * parameter 2, ..., param n. To make things easy, we save the return
33169 * address of efi_call_phys in a global variable.
33170 */
33171- popl %edx
33172- movl %edx, saved_return_addr
33173- /* get the function pointer into ECX*/
33174- popl %ecx
33175- movl %ecx, efi_rt_function_ptr
33176- movl $2f, %edx
33177- subl $__PAGE_OFFSET, %edx
33178- pushl %edx
33179+ popl (saved_return_addr)
33180+ popl (efi_rt_function_ptr)
33181
33182 /*
33183 * 3. Clear PG bit in %CR0.
33184@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
33185 /*
33186 * 5. Call the physical function.
33187 */
33188- jmp *%ecx
33189+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
33190
33191-2:
33192 /*
33193 * 6. After EFI runtime service returns, control will return to
33194 * following instruction. We'd better readjust stack pointer first.
33195@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
33196 movl %cr0, %edx
33197 orl $0x80000000, %edx
33198 movl %edx, %cr0
33199- jmp 1f
33200-1:
33201+
33202 /*
33203 * 8. Now restore the virtual mode from flat mode by
33204 * adding EIP with PAGE_OFFSET.
33205 */
33206- movl $1f, %edx
33207- jmp *%edx
33208+#ifdef CONFIG_PAX_KERNEXEC
33209+ movl $(__KERNEL_DS), %edx
33210+ mov %edx, %ds
33211+ mov %edx, %es
33212+ mov %edx, %ss
33213+ ljmp $(__KERNEL_CS),$1f
33214+#else
33215+ jmp 1f+__PAGE_OFFSET
33216+#endif
33217 1:
33218
33219 /*
33220 * 9. Balance the stack. And because EAX contain the return value,
33221 * we'd better not clobber it.
33222 */
33223- leal efi_rt_function_ptr, %edx
33224- movl (%edx), %ecx
33225- pushl %ecx
33226+ pushl (efi_rt_function_ptr)
33227
33228 /*
33229- * 10. Push the saved return address onto the stack and return.
33230+ * 10. Return to the saved return address.
33231 */
33232- leal saved_return_addr, %edx
33233- movl (%edx), %ecx
33234- pushl %ecx
33235- ret
33236+ jmpl *(saved_return_addr)
33237 ENDPROC(efi_call_phys)
33238 .previous
33239
33240-.data
33241+__INITDATA
33242 saved_return_addr:
33243 .long 0
33244 efi_rt_function_ptr:
33245diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
33246index 4c07cca..2c8427d 100644
33247--- a/arch/x86/platform/efi/efi_stub_64.S
33248+++ b/arch/x86/platform/efi/efi_stub_64.S
33249@@ -7,6 +7,7 @@
33250 */
33251
33252 #include <linux/linkage.h>
33253+#include <asm/alternative-asm.h>
33254
33255 #define SAVE_XMM \
33256 mov %rsp, %rax; \
33257@@ -40,6 +41,7 @@ ENTRY(efi_call0)
33258 call *%rdi
33259 addq $32, %rsp
33260 RESTORE_XMM
33261+ pax_force_retaddr 0, 1
33262 ret
33263 ENDPROC(efi_call0)
33264
33265@@ -50,6 +52,7 @@ ENTRY(efi_call1)
33266 call *%rdi
33267 addq $32, %rsp
33268 RESTORE_XMM
33269+ pax_force_retaddr 0, 1
33270 ret
33271 ENDPROC(efi_call1)
33272
33273@@ -60,6 +63,7 @@ ENTRY(efi_call2)
33274 call *%rdi
33275 addq $32, %rsp
33276 RESTORE_XMM
33277+ pax_force_retaddr 0, 1
33278 ret
33279 ENDPROC(efi_call2)
33280
33281@@ -71,6 +75,7 @@ ENTRY(efi_call3)
33282 call *%rdi
33283 addq $32, %rsp
33284 RESTORE_XMM
33285+ pax_force_retaddr 0, 1
33286 ret
33287 ENDPROC(efi_call3)
33288
33289@@ -83,6 +88,7 @@ ENTRY(efi_call4)
33290 call *%rdi
33291 addq $32, %rsp
33292 RESTORE_XMM
33293+ pax_force_retaddr 0, 1
33294 ret
33295 ENDPROC(efi_call4)
33296
33297@@ -96,6 +102,7 @@ ENTRY(efi_call5)
33298 call *%rdi
33299 addq $48, %rsp
33300 RESTORE_XMM
33301+ pax_force_retaddr 0, 1
33302 ret
33303 ENDPROC(efi_call5)
33304
33305@@ -112,5 +119,6 @@ ENTRY(efi_call6)
33306 call *%rdi
33307 addq $48, %rsp
33308 RESTORE_XMM
33309+ pax_force_retaddr 0, 1
33310 ret
33311 ENDPROC(efi_call6)
33312diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
33313index 47fe66f..6206449 100644
33314--- a/arch/x86/platform/mrst/mrst.c
33315+++ b/arch/x86/platform/mrst/mrst.c
33316@@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
33317 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
33318 int sfi_mrtc_num;
33319
33320-static void mrst_power_off(void)
33321+static __noreturn void mrst_power_off(void)
33322 {
33323+ BUG();
33324 }
33325
33326-static void mrst_reboot(void)
33327+static __noreturn void mrst_reboot(void)
33328 {
33329 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
33330+ BUG();
33331 }
33332
33333 /* parse all the mtimer info to a static mtimer array */
33334diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
33335index d6ee929..3637cb5 100644
33336--- a/arch/x86/platform/olpc/olpc_dt.c
33337+++ b/arch/x86/platform/olpc/olpc_dt.c
33338@@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
33339 return res;
33340 }
33341
33342-static struct of_pdt_ops prom_olpc_ops __initdata = {
33343+static struct of_pdt_ops prom_olpc_ops __initconst = {
33344 .nextprop = olpc_dt_nextprop,
33345 .getproplen = olpc_dt_getproplen,
33346 .getproperty = olpc_dt_getproperty,
33347diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
33348index 1cf5b30..fd45732 100644
33349--- a/arch/x86/power/cpu.c
33350+++ b/arch/x86/power/cpu.c
33351@@ -137,11 +137,8 @@ static void do_fpu_end(void)
33352 static void fix_processor_context(void)
33353 {
33354 int cpu = smp_processor_id();
33355- struct tss_struct *t = &per_cpu(init_tss, cpu);
33356-#ifdef CONFIG_X86_64
33357- struct desc_struct *desc = get_cpu_gdt_table(cpu);
33358- tss_desc tss;
33359-#endif
33360+ struct tss_struct *t = init_tss + cpu;
33361+
33362 set_tss_desc(cpu, t); /*
33363 * This just modifies memory; should not be
33364 * necessary. But... This is necessary, because
33365@@ -150,10 +147,6 @@ static void fix_processor_context(void)
33366 */
33367
33368 #ifdef CONFIG_X86_64
33369- memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
33370- tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
33371- write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
33372-
33373 syscall_init(); /* This sets MSR_*STAR and related */
33374 #endif
33375 load_TR_desc(); /* This does ltr */
33376diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
33377index a44f457..9140171 100644
33378--- a/arch/x86/realmode/init.c
33379+++ b/arch/x86/realmode/init.c
33380@@ -70,7 +70,13 @@ void __init setup_real_mode(void)
33381 __va(real_mode_header->trampoline_header);
33382
33383 #ifdef CONFIG_X86_32
33384- trampoline_header->start = __pa_symbol(startup_32_smp);
33385+ trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
33386+
33387+#ifdef CONFIG_PAX_KERNEXEC
33388+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
33389+#endif
33390+
33391+ trampoline_header->boot_cs = __BOOT_CS;
33392 trampoline_header->gdt_limit = __BOOT_DS + 7;
33393 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
33394 #else
33395@@ -86,7 +92,7 @@ void __init setup_real_mode(void)
33396 *trampoline_cr4_features = read_cr4();
33397
33398 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
33399- trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
33400+ trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
33401 trampoline_pgd[511] = init_level4_pgt[511].pgd;
33402 #endif
33403 }
33404diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
33405index 8869287..d577672 100644
33406--- a/arch/x86/realmode/rm/Makefile
33407+++ b/arch/x86/realmode/rm/Makefile
33408@@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
33409 $(call cc-option, -fno-unit-at-a-time)) \
33410 $(call cc-option, -fno-stack-protector) \
33411 $(call cc-option, -mpreferred-stack-boundary=2)
33412+ifdef CONSTIFY_PLUGIN
33413+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
33414+endif
33415 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
33416 GCOV_PROFILE := n
33417diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
33418index a28221d..93c40f1 100644
33419--- a/arch/x86/realmode/rm/header.S
33420+++ b/arch/x86/realmode/rm/header.S
33421@@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
33422 #endif
33423 /* APM/BIOS reboot */
33424 .long pa_machine_real_restart_asm
33425-#ifdef CONFIG_X86_64
33426+#ifdef CONFIG_X86_32
33427+ .long __KERNEL_CS
33428+#else
33429 .long __KERNEL32_CS
33430 #endif
33431 END(real_mode_header)
33432diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
33433index c1b2791..f9e31c7 100644
33434--- a/arch/x86/realmode/rm/trampoline_32.S
33435+++ b/arch/x86/realmode/rm/trampoline_32.S
33436@@ -25,6 +25,12 @@
33437 #include <asm/page_types.h>
33438 #include "realmode.h"
33439
33440+#ifdef CONFIG_PAX_KERNEXEC
33441+#define ta(X) (X)
33442+#else
33443+#define ta(X) (pa_ ## X)
33444+#endif
33445+
33446 .text
33447 .code16
33448
33449@@ -39,8 +45,6 @@ ENTRY(trampoline_start)
33450
33451 cli # We should be safe anyway
33452
33453- movl tr_start, %eax # where we need to go
33454-
33455 movl $0xA5A5A5A5, trampoline_status
33456 # write marker for master knows we're running
33457
33458@@ -56,7 +60,7 @@ ENTRY(trampoline_start)
33459 movw $1, %dx # protected mode (PE) bit
33460 lmsw %dx # into protected mode
33461
33462- ljmpl $__BOOT_CS, $pa_startup_32
33463+ ljmpl *(trampoline_header)
33464
33465 .section ".text32","ax"
33466 .code32
33467@@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
33468 .balign 8
33469 GLOBAL(trampoline_header)
33470 tr_start: .space 4
33471- tr_gdt_pad: .space 2
33472+ tr_boot_cs: .space 2
33473 tr_gdt: .space 6
33474 END(trampoline_header)
33475
33476diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
33477index bb360dc..d0fd8f8 100644
33478--- a/arch/x86/realmode/rm/trampoline_64.S
33479+++ b/arch/x86/realmode/rm/trampoline_64.S
33480@@ -94,6 +94,7 @@ ENTRY(startup_32)
33481 movl %edx, %gs
33482
33483 movl pa_tr_cr4, %eax
33484+ andl $~X86_CR4_PCIDE, %eax
33485 movl %eax, %cr4 # Enable PAE mode
33486
33487 # Setup trampoline 4 level pagetables
33488@@ -107,7 +108,7 @@ ENTRY(startup_32)
33489 wrmsr
33490
33491 # Enable paging and in turn activate Long Mode
33492- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
33493+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
33494 movl %eax, %cr0
33495
33496 /*
33497diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
33498index e812034..c747134 100644
33499--- a/arch/x86/tools/Makefile
33500+++ b/arch/x86/tools/Makefile
33501@@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
33502
33503 $(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
33504
33505-HOST_EXTRACFLAGS += -I$(srctree)/tools/include
33506+HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
33507 hostprogs-y += relocs
33508 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
33509 relocs: $(obj)/relocs
33510diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
33511index f7bab68..b6d9886 100644
33512--- a/arch/x86/tools/relocs.c
33513+++ b/arch/x86/tools/relocs.c
33514@@ -1,5 +1,7 @@
33515 /* This is included from relocs_32/64.c */
33516
33517+#include "../../../include/generated/autoconf.h"
33518+
33519 #define ElfW(type) _ElfW(ELF_BITS, type)
33520 #define _ElfW(bits, type) __ElfW(bits, type)
33521 #define __ElfW(bits, type) Elf##bits##_##type
33522@@ -11,6 +13,7 @@
33523 #define Elf_Sym ElfW(Sym)
33524
33525 static Elf_Ehdr ehdr;
33526+static Elf_Phdr *phdr;
33527
33528 struct relocs {
33529 uint32_t *offset;
33530@@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
33531 }
33532 }
33533
33534+static void read_phdrs(FILE *fp)
33535+{
33536+ unsigned int i;
33537+
33538+ phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
33539+ if (!phdr) {
33540+ die("Unable to allocate %d program headers\n",
33541+ ehdr.e_phnum);
33542+ }
33543+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
33544+ die("Seek to %d failed: %s\n",
33545+ ehdr.e_phoff, strerror(errno));
33546+ }
33547+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
33548+ die("Cannot read ELF program headers: %s\n",
33549+ strerror(errno));
33550+ }
33551+ for(i = 0; i < ehdr.e_phnum; i++) {
33552+ phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
33553+ phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
33554+ phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
33555+ phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
33556+ phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
33557+ phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
33558+ phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
33559+ phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
33560+ }
33561+
33562+}
33563+
33564 static void read_shdrs(FILE *fp)
33565 {
33566- int i;
33567+ unsigned int i;
33568 Elf_Shdr shdr;
33569
33570 secs = calloc(ehdr.e_shnum, sizeof(struct section));
33571@@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
33572
33573 static void read_strtabs(FILE *fp)
33574 {
33575- int i;
33576+ unsigned int i;
33577 for (i = 0; i < ehdr.e_shnum; i++) {
33578 struct section *sec = &secs[i];
33579 if (sec->shdr.sh_type != SHT_STRTAB) {
33580@@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
33581
33582 static void read_symtabs(FILE *fp)
33583 {
33584- int i,j;
33585+ unsigned int i,j;
33586 for (i = 0; i < ehdr.e_shnum; i++) {
33587 struct section *sec = &secs[i];
33588 if (sec->shdr.sh_type != SHT_SYMTAB) {
33589@@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
33590 }
33591
33592
33593-static void read_relocs(FILE *fp)
33594+static void read_relocs(FILE *fp, int use_real_mode)
33595 {
33596- int i,j;
33597+ unsigned int i,j;
33598+ uint32_t base;
33599+
33600 for (i = 0; i < ehdr.e_shnum; i++) {
33601 struct section *sec = &secs[i];
33602 if (sec->shdr.sh_type != SHT_REL_TYPE) {
33603@@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
33604 die("Cannot read symbol table: %s\n",
33605 strerror(errno));
33606 }
33607+ base = 0;
33608+
33609+#ifdef CONFIG_X86_32
33610+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
33611+ if (phdr[j].p_type != PT_LOAD )
33612+ continue;
33613+ 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)
33614+ continue;
33615+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
33616+ break;
33617+ }
33618+#endif
33619+
33620 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
33621 Elf_Rel *rel = &sec->reltab[j];
33622- rel->r_offset = elf_addr_to_cpu(rel->r_offset);
33623+ rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
33624 rel->r_info = elf_xword_to_cpu(rel->r_info);
33625 #if (SHT_REL_TYPE == SHT_RELA)
33626 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
33627@@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
33628
33629 static void print_absolute_symbols(void)
33630 {
33631- int i;
33632+ unsigned int i;
33633 const char *format;
33634
33635 if (ELF_BITS == 64)
33636@@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
33637 for (i = 0; i < ehdr.e_shnum; i++) {
33638 struct section *sec = &secs[i];
33639 char *sym_strtab;
33640- int j;
33641+ unsigned int j;
33642
33643 if (sec->shdr.sh_type != SHT_SYMTAB) {
33644 continue;
33645@@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
33646
33647 static void print_absolute_relocs(void)
33648 {
33649- int i, printed = 0;
33650+ unsigned int i, printed = 0;
33651 const char *format;
33652
33653 if (ELF_BITS == 64)
33654@@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
33655 struct section *sec_applies, *sec_symtab;
33656 char *sym_strtab;
33657 Elf_Sym *sh_symtab;
33658- int j;
33659+ unsigned int j;
33660 if (sec->shdr.sh_type != SHT_REL_TYPE) {
33661 continue;
33662 }
33663@@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
33664 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
33665 Elf_Sym *sym, const char *symname))
33666 {
33667- int i;
33668+ unsigned int i;
33669 /* Walk through the relocations */
33670 for (i = 0; i < ehdr.e_shnum; i++) {
33671 char *sym_strtab;
33672 Elf_Sym *sh_symtab;
33673 struct section *sec_applies, *sec_symtab;
33674- int j;
33675+ unsigned int j;
33676 struct section *sec = &secs[i];
33677
33678 if (sec->shdr.sh_type != SHT_REL_TYPE) {
33679@@ -812,6 +860,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
33680 {
33681 unsigned r_type = ELF32_R_TYPE(rel->r_info);
33682 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
33683+ char *sym_strtab = sec->link->link->strtab;
33684+
33685+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
33686+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
33687+ return 0;
33688+
33689+#ifdef CONFIG_PAX_KERNEXEC
33690+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
33691+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
33692+ return 0;
33693+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
33694+ return 0;
33695+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
33696+ return 0;
33697+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
33698+ return 0;
33699+#endif
33700
33701 switch (r_type) {
33702 case R_386_NONE:
33703@@ -950,7 +1015,7 @@ static int write32_as_text(uint32_t v, FILE *f)
33704
33705 static void emit_relocs(int as_text, int use_real_mode)
33706 {
33707- int i;
33708+ unsigned int i;
33709 int (*write_reloc)(uint32_t, FILE *) = write32;
33710 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
33711 const char *symname);
33712@@ -1026,10 +1091,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
33713 {
33714 regex_init(use_real_mode);
33715 read_ehdr(fp);
33716+ read_phdrs(fp);
33717 read_shdrs(fp);
33718 read_strtabs(fp);
33719 read_symtabs(fp);
33720- read_relocs(fp);
33721+ read_relocs(fp, use_real_mode);
33722 if (ELF_BITS == 64)
33723 percpu_init();
33724 if (show_absolute_syms) {
33725diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
33726index 80ffa5b..a33bd15 100644
33727--- a/arch/x86/um/tls_32.c
33728+++ b/arch/x86/um/tls_32.c
33729@@ -260,7 +260,7 @@ out:
33730 if (unlikely(task == current &&
33731 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
33732 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
33733- "without flushed TLS.", current->pid);
33734+ "without flushed TLS.", task_pid_nr(current));
33735 }
33736
33737 return 0;
33738diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
33739index fd14be1..e3c79c0 100644
33740--- a/arch/x86/vdso/Makefile
33741+++ b/arch/x86/vdso/Makefile
33742@@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
33743 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
33744 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
33745
33746-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
33747+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
33748 GCOV_PROFILE := n
33749
33750 #
33751diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
33752index d6bfb87..876ee18 100644
33753--- a/arch/x86/vdso/vdso32-setup.c
33754+++ b/arch/x86/vdso/vdso32-setup.c
33755@@ -25,6 +25,7 @@
33756 #include <asm/tlbflush.h>
33757 #include <asm/vdso.h>
33758 #include <asm/proto.h>
33759+#include <asm/mman.h>
33760
33761 enum {
33762 VDSO_DISABLED = 0,
33763@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
33764 void enable_sep_cpu(void)
33765 {
33766 int cpu = get_cpu();
33767- struct tss_struct *tss = &per_cpu(init_tss, cpu);
33768+ struct tss_struct *tss = init_tss + cpu;
33769
33770 if (!boot_cpu_has(X86_FEATURE_SEP)) {
33771 put_cpu();
33772@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
33773 gate_vma.vm_start = FIXADDR_USER_START;
33774 gate_vma.vm_end = FIXADDR_USER_END;
33775 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
33776- gate_vma.vm_page_prot = __P101;
33777+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
33778
33779 return 0;
33780 }
33781@@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
33782 if (compat)
33783 addr = VDSO_HIGH_BASE;
33784 else {
33785- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
33786+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
33787 if (IS_ERR_VALUE(addr)) {
33788 ret = addr;
33789 goto up_fail;
33790 }
33791 }
33792
33793- current->mm->context.vdso = (void *)addr;
33794+ current->mm->context.vdso = addr;
33795
33796 if (compat_uses_vma || !compat) {
33797 /*
33798@@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
33799 }
33800
33801 current_thread_info()->sysenter_return =
33802- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
33803+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
33804
33805 up_fail:
33806 if (ret)
33807- current->mm->context.vdso = NULL;
33808+ current->mm->context.vdso = 0;
33809
33810 up_write(&mm->mmap_sem);
33811
33812@@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
33813
33814 const char *arch_vma_name(struct vm_area_struct *vma)
33815 {
33816- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
33817+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
33818 return "[vdso]";
33819+
33820+#ifdef CONFIG_PAX_SEGMEXEC
33821+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
33822+ return "[vdso]";
33823+#endif
33824+
33825 return NULL;
33826 }
33827
33828@@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
33829 * Check to see if the corresponding task was created in compat vdso
33830 * mode.
33831 */
33832- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
33833+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
33834 return &gate_vma;
33835 return NULL;
33836 }
33837diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
33838index 431e875..cbb23f3 100644
33839--- a/arch/x86/vdso/vma.c
33840+++ b/arch/x86/vdso/vma.c
33841@@ -16,8 +16,6 @@
33842 #include <asm/vdso.h>
33843 #include <asm/page.h>
33844
33845-unsigned int __read_mostly vdso_enabled = 1;
33846-
33847 extern char vdso_start[], vdso_end[];
33848 extern unsigned short vdso_sync_cpuid;
33849
33850@@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
33851 * unaligned here as a result of stack start randomization.
33852 */
33853 addr = PAGE_ALIGN(addr);
33854- addr = align_vdso_addr(addr);
33855
33856 return addr;
33857 }
33858@@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
33859 unsigned size)
33860 {
33861 struct mm_struct *mm = current->mm;
33862- unsigned long addr;
33863+ unsigned long addr = 0;
33864 int ret;
33865
33866- if (!vdso_enabled)
33867- return 0;
33868-
33869 down_write(&mm->mmap_sem);
33870+
33871+#ifdef CONFIG_PAX_RANDMMAP
33872+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
33873+#endif
33874+
33875 addr = vdso_addr(mm->start_stack, size);
33876+ addr = align_vdso_addr(addr);
33877 addr = get_unmapped_area(NULL, addr, size, 0, 0);
33878 if (IS_ERR_VALUE(addr)) {
33879 ret = addr;
33880 goto up_fail;
33881 }
33882
33883- current->mm->context.vdso = (void *)addr;
33884+ mm->context.vdso = addr;
33885
33886 ret = install_special_mapping(mm, addr, size,
33887 VM_READ|VM_EXEC|
33888 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
33889 pages);
33890- if (ret) {
33891- current->mm->context.vdso = NULL;
33892- goto up_fail;
33893- }
33894+ if (ret)
33895+ mm->context.vdso = 0;
33896
33897 up_fail:
33898 up_write(&mm->mmap_sem);
33899@@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
33900 vdsox32_size);
33901 }
33902 #endif
33903-
33904-static __init int vdso_setup(char *s)
33905-{
33906- vdso_enabled = simple_strtoul(s, NULL, 0);
33907- return 0;
33908-}
33909-__setup("vdso=", vdso_setup);
33910diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
33911index 193097e..7590269 100644
33912--- a/arch/x86/xen/enlighten.c
33913+++ b/arch/x86/xen/enlighten.c
33914@@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
33915
33916 struct shared_info xen_dummy_shared_info;
33917
33918-void *xen_initial_gdt;
33919-
33920 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
33921 __read_mostly int xen_have_vector_callback;
33922 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
33923@@ -542,8 +540,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
33924 {
33925 unsigned long va = dtr->address;
33926 unsigned int size = dtr->size + 1;
33927- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
33928- unsigned long frames[pages];
33929+ unsigned long frames[65536 / PAGE_SIZE];
33930 int f;
33931
33932 /*
33933@@ -591,8 +588,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
33934 {
33935 unsigned long va = dtr->address;
33936 unsigned int size = dtr->size + 1;
33937- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
33938- unsigned long frames[pages];
33939+ unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
33940 int f;
33941
33942 /*
33943@@ -600,7 +596,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
33944 * 8-byte entries, or 16 4k pages..
33945 */
33946
33947- BUG_ON(size > 65536);
33948+ BUG_ON(size > GDT_SIZE);
33949 BUG_ON(va & ~PAGE_MASK);
33950
33951 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
33952@@ -985,7 +981,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
33953 return 0;
33954 }
33955
33956-static void set_xen_basic_apic_ops(void)
33957+static void __init set_xen_basic_apic_ops(void)
33958 {
33959 apic->read = xen_apic_read;
33960 apic->write = xen_apic_write;
33961@@ -1290,30 +1286,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
33962 #endif
33963 };
33964
33965-static void xen_reboot(int reason)
33966+static __noreturn void xen_reboot(int reason)
33967 {
33968 struct sched_shutdown r = { .reason = reason };
33969
33970- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
33971- BUG();
33972+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
33973+ BUG();
33974 }
33975
33976-static void xen_restart(char *msg)
33977+static __noreturn void xen_restart(char *msg)
33978 {
33979 xen_reboot(SHUTDOWN_reboot);
33980 }
33981
33982-static void xen_emergency_restart(void)
33983+static __noreturn void xen_emergency_restart(void)
33984 {
33985 xen_reboot(SHUTDOWN_reboot);
33986 }
33987
33988-static void xen_machine_halt(void)
33989+static __noreturn void xen_machine_halt(void)
33990 {
33991 xen_reboot(SHUTDOWN_poweroff);
33992 }
33993
33994-static void xen_machine_power_off(void)
33995+static __noreturn void xen_machine_power_off(void)
33996 {
33997 if (pm_power_off)
33998 pm_power_off();
33999@@ -1464,7 +1460,17 @@ asmlinkage void __init xen_start_kernel(void)
34000 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
34001
34002 /* Work out if we support NX */
34003- x86_configure_nx();
34004+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
34005+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
34006+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
34007+ unsigned l, h;
34008+
34009+ __supported_pte_mask |= _PAGE_NX;
34010+ rdmsr(MSR_EFER, l, h);
34011+ l |= EFER_NX;
34012+ wrmsr(MSR_EFER, l, h);
34013+ }
34014+#endif
34015
34016 xen_setup_features();
34017
34018@@ -1495,13 +1501,6 @@ asmlinkage void __init xen_start_kernel(void)
34019
34020 machine_ops = xen_machine_ops;
34021
34022- /*
34023- * The only reliable way to retain the initial address of the
34024- * percpu gdt_page is to remember it here, so we can go and
34025- * mark it RW later, when the initial percpu area is freed.
34026- */
34027- xen_initial_gdt = &per_cpu(gdt_page, 0);
34028-
34029 xen_smp_init();
34030
34031 #ifdef CONFIG_ACPI_NUMA
34032diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
34033index fdc3ba2..3daee39 100644
34034--- a/arch/x86/xen/mmu.c
34035+++ b/arch/x86/xen/mmu.c
34036@@ -1894,6 +1894,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
34037 /* L3_k[510] -> level2_kernel_pgt
34038 * L3_i[511] -> level2_fixmap_pgt */
34039 convert_pfn_mfn(level3_kernel_pgt);
34040+ convert_pfn_mfn(level3_vmalloc_start_pgt);
34041+ convert_pfn_mfn(level3_vmalloc_end_pgt);
34042+ convert_pfn_mfn(level3_vmemmap_pgt);
34043
34044 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
34045 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
34046@@ -1923,8 +1926,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
34047 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
34048 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
34049 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
34050+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
34051+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
34052+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
34053 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
34054 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
34055+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
34056 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
34057 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
34058
34059@@ -2108,6 +2115,7 @@ static void __init xen_post_allocator_init(void)
34060 pv_mmu_ops.set_pud = xen_set_pud;
34061 #if PAGETABLE_LEVELS == 4
34062 pv_mmu_ops.set_pgd = xen_set_pgd;
34063+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
34064 #endif
34065
34066 /* This will work as long as patching hasn't happened yet
34067@@ -2186,6 +2194,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
34068 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
34069 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
34070 .set_pgd = xen_set_pgd_hyper,
34071+ .set_pgd_batched = xen_set_pgd_hyper,
34072
34073 .alloc_pud = xen_alloc_pmd_init,
34074 .release_pud = xen_release_pmd_init,
34075diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
34076index b81c88e..2cbe7b8 100644
34077--- a/arch/x86/xen/smp.c
34078+++ b/arch/x86/xen/smp.c
34079@@ -272,11 +272,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
34080 {
34081 BUG_ON(smp_processor_id() != 0);
34082 native_smp_prepare_boot_cpu();
34083-
34084- /* We've switched to the "real" per-cpu gdt, so make sure the
34085- old memory can be recycled */
34086- make_lowmem_page_readwrite(xen_initial_gdt);
34087-
34088 xen_filter_cpu_maps();
34089 xen_setup_vcpu_info_placement();
34090 }
34091@@ -346,7 +341,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
34092 ctxt->user_regs.ss = __KERNEL_DS;
34093 #ifdef CONFIG_X86_32
34094 ctxt->user_regs.fs = __KERNEL_PERCPU;
34095- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
34096+ savesegment(gs, ctxt->user_regs.gs);
34097 #else
34098 ctxt->gs_base_kernel = per_cpu_offset(cpu);
34099 #endif
34100@@ -356,8 +351,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
34101
34102 {
34103 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
34104- ctxt->user_regs.ds = __USER_DS;
34105- ctxt->user_regs.es = __USER_DS;
34106+ ctxt->user_regs.ds = __KERNEL_DS;
34107+ ctxt->user_regs.es = __KERNEL_DS;
34108
34109 xen_copy_trap_info(ctxt->trap_ctxt);
34110
34111@@ -402,13 +397,12 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle)
34112 int rc;
34113
34114 per_cpu(current_task, cpu) = idle;
34115+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
34116 #ifdef CONFIG_X86_32
34117 irq_ctx_init(cpu);
34118 #else
34119 clear_tsk_thread_flag(idle, TIF_FORK);
34120- per_cpu(kernel_stack, cpu) =
34121- (unsigned long)task_stack_page(idle) -
34122- KERNEL_STACK_OFFSET + THREAD_SIZE;
34123+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
34124 #endif
34125 xen_setup_runstate_info(cpu);
34126 xen_setup_timer(cpu);
34127@@ -678,7 +672,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
34128
34129 void __init xen_smp_init(void)
34130 {
34131- smp_ops = xen_smp_ops;
34132+ memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
34133 xen_fill_possible_map();
34134 xen_init_spinlocks();
34135 }
34136diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
34137index 33ca6e4..0ded929 100644
34138--- a/arch/x86/xen/xen-asm_32.S
34139+++ b/arch/x86/xen/xen-asm_32.S
34140@@ -84,14 +84,14 @@ ENTRY(xen_iret)
34141 ESP_OFFSET=4 # bytes pushed onto stack
34142
34143 /*
34144- * Store vcpu_info pointer for easy access. Do it this way to
34145- * avoid having to reload %fs
34146+ * Store vcpu_info pointer for easy access.
34147 */
34148 #ifdef CONFIG_SMP
34149- GET_THREAD_INFO(%eax)
34150- movl %ss:TI_cpu(%eax), %eax
34151- movl %ss:__per_cpu_offset(,%eax,4), %eax
34152- mov %ss:xen_vcpu(%eax), %eax
34153+ push %fs
34154+ mov $(__KERNEL_PERCPU), %eax
34155+ mov %eax, %fs
34156+ mov PER_CPU_VAR(xen_vcpu), %eax
34157+ pop %fs
34158 #else
34159 movl %ss:xen_vcpu, %eax
34160 #endif
34161diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
34162index 7faed58..ba4427c 100644
34163--- a/arch/x86/xen/xen-head.S
34164+++ b/arch/x86/xen/xen-head.S
34165@@ -19,6 +19,17 @@ ENTRY(startup_xen)
34166 #ifdef CONFIG_X86_32
34167 mov %esi,xen_start_info
34168 mov $init_thread_union+THREAD_SIZE,%esp
34169+#ifdef CONFIG_SMP
34170+ movl $cpu_gdt_table,%edi
34171+ movl $__per_cpu_load,%eax
34172+ movw %ax,__KERNEL_PERCPU + 2(%edi)
34173+ rorl $16,%eax
34174+ movb %al,__KERNEL_PERCPU + 4(%edi)
34175+ movb %ah,__KERNEL_PERCPU + 7(%edi)
34176+ movl $__per_cpu_end - 1,%eax
34177+ subl $__per_cpu_start,%eax
34178+ movw %ax,__KERNEL_PERCPU + 0(%edi)
34179+#endif
34180 #else
34181 mov %rsi,xen_start_info
34182 mov $init_thread_union+THREAD_SIZE,%rsp
34183diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
34184index 86782c5..fa272c8 100644
34185--- a/arch/x86/xen/xen-ops.h
34186+++ b/arch/x86/xen/xen-ops.h
34187@@ -10,8 +10,6 @@
34188 extern const char xen_hypervisor_callback[];
34189 extern const char xen_failsafe_callback[];
34190
34191-extern void *xen_initial_gdt;
34192-
34193 struct trap_info;
34194 void xen_copy_trap_info(struct trap_info *traps);
34195
34196diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
34197index 525bd3d..ef888b1 100644
34198--- a/arch/xtensa/variants/dc232b/include/variant/core.h
34199+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
34200@@ -119,9 +119,9 @@
34201 ----------------------------------------------------------------------*/
34202
34203 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
34204-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
34205 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
34206 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
34207+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
34208
34209 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
34210 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
34211diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
34212index 2f33760..835e50a 100644
34213--- a/arch/xtensa/variants/fsf/include/variant/core.h
34214+++ b/arch/xtensa/variants/fsf/include/variant/core.h
34215@@ -11,6 +11,7 @@
34216 #ifndef _XTENSA_CORE_H
34217 #define _XTENSA_CORE_H
34218
34219+#include <linux/const.h>
34220
34221 /****************************************************************************
34222 Parameters Useful for Any Code, USER or PRIVILEGED
34223@@ -112,9 +113,9 @@
34224 ----------------------------------------------------------------------*/
34225
34226 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
34227-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
34228 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
34229 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
34230+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
34231
34232 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
34233 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
34234diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
34235index af00795..2bb8105 100644
34236--- a/arch/xtensa/variants/s6000/include/variant/core.h
34237+++ b/arch/xtensa/variants/s6000/include/variant/core.h
34238@@ -11,6 +11,7 @@
34239 #ifndef _XTENSA_CORE_CONFIGURATION_H
34240 #define _XTENSA_CORE_CONFIGURATION_H
34241
34242+#include <linux/const.h>
34243
34244 /****************************************************************************
34245 Parameters Useful for Any Code, USER or PRIVILEGED
34246@@ -118,9 +119,9 @@
34247 ----------------------------------------------------------------------*/
34248
34249 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
34250-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
34251 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
34252 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
34253+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
34254
34255 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
34256 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
34257diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
34258index 290792a..416f287 100644
34259--- a/block/blk-cgroup.c
34260+++ b/block/blk-cgroup.c
34261@@ -808,7 +808,7 @@ static void blkcg_css_free(struct cgroup *cgroup)
34262
34263 static struct cgroup_subsys_state *blkcg_css_alloc(struct cgroup *cgroup)
34264 {
34265- static atomic64_t id_seq = ATOMIC64_INIT(0);
34266+ static atomic64_unchecked_t id_seq = ATOMIC64_INIT(0);
34267 struct blkcg *blkcg;
34268 struct cgroup *parent = cgroup->parent;
34269
34270@@ -823,7 +823,7 @@ static struct cgroup_subsys_state *blkcg_css_alloc(struct cgroup *cgroup)
34271
34272 blkcg->cfq_weight = CFQ_WEIGHT_DEFAULT;
34273 blkcg->cfq_leaf_weight = CFQ_WEIGHT_DEFAULT;
34274- blkcg->id = atomic64_inc_return(&id_seq); /* root is 0, start from 1 */
34275+ blkcg->id = atomic64_inc_return_unchecked(&id_seq); /* root is 0, start from 1 */
34276 done:
34277 spin_lock_init(&blkcg->lock);
34278 INIT_RADIX_TREE(&blkcg->blkg_tree, GFP_ATOMIC);
34279diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
34280index 4b8d9b54..ff76220 100644
34281--- a/block/blk-iopoll.c
34282+++ b/block/blk-iopoll.c
34283@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
34284 }
34285 EXPORT_SYMBOL(blk_iopoll_complete);
34286
34287-static void blk_iopoll_softirq(struct softirq_action *h)
34288+static void blk_iopoll_softirq(void)
34289 {
34290 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
34291 int rearm = 0, budget = blk_iopoll_budget;
34292diff --git a/block/blk-map.c b/block/blk-map.c
34293index 623e1cd..ca1e109 100644
34294--- a/block/blk-map.c
34295+++ b/block/blk-map.c
34296@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
34297 if (!len || !kbuf)
34298 return -EINVAL;
34299
34300- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
34301+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
34302 if (do_copy)
34303 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
34304 else
34305diff --git a/block/blk-softirq.c b/block/blk-softirq.c
34306index ec9e606..2244d4e 100644
34307--- a/block/blk-softirq.c
34308+++ b/block/blk-softirq.c
34309@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
34310 * Softirq action handler - move entries to local list and loop over them
34311 * while passing them to the queue registered handler.
34312 */
34313-static void blk_done_softirq(struct softirq_action *h)
34314+static void blk_done_softirq(void)
34315 {
34316 struct list_head *cpu_list, local_list;
34317
34318diff --git a/block/bsg.c b/block/bsg.c
34319index 420a5a9..23834aa 100644
34320--- a/block/bsg.c
34321+++ b/block/bsg.c
34322@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
34323 struct sg_io_v4 *hdr, struct bsg_device *bd,
34324 fmode_t has_write_perm)
34325 {
34326+ unsigned char tmpcmd[sizeof(rq->__cmd)];
34327+ unsigned char *cmdptr;
34328+
34329 if (hdr->request_len > BLK_MAX_CDB) {
34330 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
34331 if (!rq->cmd)
34332 return -ENOMEM;
34333- }
34334+ cmdptr = rq->cmd;
34335+ } else
34336+ cmdptr = tmpcmd;
34337
34338- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
34339+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
34340 hdr->request_len))
34341 return -EFAULT;
34342
34343+ if (cmdptr != rq->cmd)
34344+ memcpy(rq->cmd, cmdptr, hdr->request_len);
34345+
34346 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
34347 if (blk_verify_command(rq->cmd, has_write_perm))
34348 return -EPERM;
34349diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
34350index 7e5d474..0cf0017 100644
34351--- a/block/compat_ioctl.c
34352+++ b/block/compat_ioctl.c
34353@@ -341,7 +341,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
34354 err |= __get_user(f->spec1, &uf->spec1);
34355 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
34356 err |= __get_user(name, &uf->name);
34357- f->name = compat_ptr(name);
34358+ f->name = (void __force_kernel *)compat_ptr(name);
34359 if (err) {
34360 err = -EFAULT;
34361 goto out;
34362diff --git a/block/genhd.c b/block/genhd.c
34363index dadf42b..48dc887 100644
34364--- a/block/genhd.c
34365+++ b/block/genhd.c
34366@@ -467,21 +467,24 @@ static char *bdevt_str(dev_t devt, char *buf)
34367
34368 /*
34369 * Register device numbers dev..(dev+range-1)
34370- * range must be nonzero
34371+ * Noop if @range is zero.
34372 * The hash chain is sorted on range, so that subranges can override.
34373 */
34374 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
34375 struct kobject *(*probe)(dev_t, int *, void *),
34376 int (*lock)(dev_t, void *), void *data)
34377 {
34378- kobj_map(bdev_map, devt, range, module, probe, lock, data);
34379+ if (range)
34380+ kobj_map(bdev_map, devt, range, module, probe, lock, data);
34381 }
34382
34383 EXPORT_SYMBOL(blk_register_region);
34384
34385+/* undo blk_register_region(), noop if @range is zero */
34386 void blk_unregister_region(dev_t devt, unsigned long range)
34387 {
34388- kobj_unmap(bdev_map, devt, range);
34389+ if (range)
34390+ kobj_unmap(bdev_map, devt, range);
34391 }
34392
34393 EXPORT_SYMBOL(blk_unregister_region);
34394diff --git a/block/partitions/efi.c b/block/partitions/efi.c
34395index c85fc89..51e690b 100644
34396--- a/block/partitions/efi.c
34397+++ b/block/partitions/efi.c
34398@@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
34399 if (!gpt)
34400 return NULL;
34401
34402+ if (!le32_to_cpu(gpt->num_partition_entries))
34403+ return NULL;
34404+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
34405+ if (!pte)
34406+ return NULL;
34407+
34408 count = le32_to_cpu(gpt->num_partition_entries) *
34409 le32_to_cpu(gpt->sizeof_partition_entry);
34410- if (!count)
34411- return NULL;
34412- pte = kmalloc(count, GFP_KERNEL);
34413- if (!pte)
34414- return NULL;
34415-
34416 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
34417 (u8 *) pte,
34418 count) < count) {
34419diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
34420index a5ffcc9..3cedc9c 100644
34421--- a/block/scsi_ioctl.c
34422+++ b/block/scsi_ioctl.c
34423@@ -224,8 +224,20 @@ EXPORT_SYMBOL(blk_verify_command);
34424 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
34425 struct sg_io_hdr *hdr, fmode_t mode)
34426 {
34427- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
34428+ unsigned char tmpcmd[sizeof(rq->__cmd)];
34429+ unsigned char *cmdptr;
34430+
34431+ if (rq->cmd != rq->__cmd)
34432+ cmdptr = rq->cmd;
34433+ else
34434+ cmdptr = tmpcmd;
34435+
34436+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
34437 return -EFAULT;
34438+
34439+ if (cmdptr != rq->cmd)
34440+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
34441+
34442 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
34443 return -EPERM;
34444
34445@@ -434,6 +446,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
34446 int err;
34447 unsigned int in_len, out_len, bytes, opcode, cmdlen;
34448 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
34449+ unsigned char tmpcmd[sizeof(rq->__cmd)];
34450+ unsigned char *cmdptr;
34451
34452 if (!sic)
34453 return -EINVAL;
34454@@ -467,9 +481,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
34455 */
34456 err = -EFAULT;
34457 rq->cmd_len = cmdlen;
34458- if (copy_from_user(rq->cmd, sic->data, cmdlen))
34459+
34460+ if (rq->cmd != rq->__cmd)
34461+ cmdptr = rq->cmd;
34462+ else
34463+ cmdptr = tmpcmd;
34464+
34465+ if (copy_from_user(cmdptr, sic->data, cmdlen))
34466 goto error;
34467
34468+ if (rq->cmd != cmdptr)
34469+ memcpy(rq->cmd, cmdptr, cmdlen);
34470+
34471 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
34472 goto error;
34473
34474diff --git a/crypto/api.c b/crypto/api.c
34475index 3b61803..37c4c72 100644
34476--- a/crypto/api.c
34477+++ b/crypto/api.c
34478@@ -34,6 +34,8 @@ EXPORT_SYMBOL_GPL(crypto_alg_sem);
34479 BLOCKING_NOTIFIER_HEAD(crypto_chain);
34480 EXPORT_SYMBOL_GPL(crypto_chain);
34481
34482+static struct crypto_alg *crypto_larval_wait(struct crypto_alg *alg);
34483+
34484 struct crypto_alg *crypto_mod_get(struct crypto_alg *alg)
34485 {
34486 return try_module_get(alg->cra_module) ? crypto_alg_get(alg) : NULL;
34487@@ -144,8 +146,11 @@ static struct crypto_alg *crypto_larval_add(const char *name, u32 type,
34488 }
34489 up_write(&crypto_alg_sem);
34490
34491- if (alg != &larval->alg)
34492+ if (alg != &larval->alg) {
34493 kfree(larval);
34494+ if (crypto_is_larval(alg))
34495+ alg = crypto_larval_wait(alg);
34496+ }
34497
34498 return alg;
34499 }
34500diff --git a/crypto/cryptd.c b/crypto/cryptd.c
34501index 7bdd61b..afec999 100644
34502--- a/crypto/cryptd.c
34503+++ b/crypto/cryptd.c
34504@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
34505
34506 struct cryptd_blkcipher_request_ctx {
34507 crypto_completion_t complete;
34508-};
34509+} __no_const;
34510
34511 struct cryptd_hash_ctx {
34512 struct crypto_shash *child;
34513@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
34514
34515 struct cryptd_aead_request_ctx {
34516 crypto_completion_t complete;
34517-};
34518+} __no_const;
34519
34520 static void cryptd_queue_worker(struct work_struct *work);
34521
34522diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
34523index f8c920c..ab2cb5a 100644
34524--- a/crypto/pcrypt.c
34525+++ b/crypto/pcrypt.c
34526@@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
34527 int ret;
34528
34529 pinst->kobj.kset = pcrypt_kset;
34530- ret = kobject_add(&pinst->kobj, NULL, name);
34531+ ret = kobject_add(&pinst->kobj, NULL, "%s", name);
34532 if (!ret)
34533 kobject_uevent(&pinst->kobj, KOBJ_ADD);
34534
34535diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
34536index f220d64..d359ad6 100644
34537--- a/drivers/acpi/apei/apei-internal.h
34538+++ b/drivers/acpi/apei/apei-internal.h
34539@@ -20,7 +20,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
34540 struct apei_exec_ins_type {
34541 u32 flags;
34542 apei_exec_ins_func_t run;
34543-};
34544+} __do_const;
34545
34546 struct apei_exec_context {
34547 u32 ip;
34548diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
34549index 33dc6a0..4b24b47 100644
34550--- a/drivers/acpi/apei/cper.c
34551+++ b/drivers/acpi/apei/cper.c
34552@@ -39,12 +39,12 @@
34553 */
34554 u64 cper_next_record_id(void)
34555 {
34556- static atomic64_t seq;
34557+ static atomic64_unchecked_t seq;
34558
34559- if (!atomic64_read(&seq))
34560- atomic64_set(&seq, ((u64)get_seconds()) << 32);
34561+ if (!atomic64_read_unchecked(&seq))
34562+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
34563
34564- return atomic64_inc_return(&seq);
34565+ return atomic64_inc_return_unchecked(&seq);
34566 }
34567 EXPORT_SYMBOL_GPL(cper_next_record_id);
34568
34569diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
34570index ec9b57d..9682b3a 100644
34571--- a/drivers/acpi/apei/ghes.c
34572+++ b/drivers/acpi/apei/ghes.c
34573@@ -478,7 +478,7 @@ static void __ghes_print_estatus(const char *pfx,
34574 const struct acpi_hest_generic *generic,
34575 const struct acpi_hest_generic_status *estatus)
34576 {
34577- static atomic_t seqno;
34578+ static atomic_unchecked_t seqno;
34579 unsigned int curr_seqno;
34580 char pfx_seq[64];
34581
34582@@ -489,7 +489,7 @@ static void __ghes_print_estatus(const char *pfx,
34583 else
34584 pfx = KERN_ERR;
34585 }
34586- curr_seqno = atomic_inc_return(&seqno);
34587+ curr_seqno = atomic_inc_return_unchecked(&seqno);
34588 snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
34589 printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
34590 pfx_seq, generic->header.source_id);
34591diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
34592index be60399..778b33e8 100644
34593--- a/drivers/acpi/bgrt.c
34594+++ b/drivers/acpi/bgrt.c
34595@@ -87,8 +87,10 @@ static int __init bgrt_init(void)
34596 return -ENODEV;
34597
34598 sysfs_bin_attr_init(&image_attr);
34599- image_attr.private = bgrt_image;
34600- image_attr.size = bgrt_image_size;
34601+ pax_open_kernel();
34602+ *(void **)&image_attr.private = bgrt_image;
34603+ *(size_t *)&image_attr.size = bgrt_image_size;
34604+ pax_close_kernel();
34605
34606 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
34607 if (!bgrt_kobj)
34608diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
34609index cb96296..b81293b 100644
34610--- a/drivers/acpi/blacklist.c
34611+++ b/drivers/acpi/blacklist.c
34612@@ -52,7 +52,7 @@ struct acpi_blacklist_item {
34613 u32 is_critical_error;
34614 };
34615
34616-static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
34617+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
34618
34619 /*
34620 * POLICY: If *anything* doesn't work, put it on the blacklist.
34621@@ -193,7 +193,7 @@ static int __init dmi_disable_osi_win7(const struct dmi_system_id *d)
34622 return 0;
34623 }
34624
34625-static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
34626+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
34627 {
34628 .callback = dmi_disable_osi_vista,
34629 .ident = "Fujitsu Siemens",
34630diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
34631index f98dd00..7b69865 100644
34632--- a/drivers/acpi/processor_idle.c
34633+++ b/drivers/acpi/processor_idle.c
34634@@ -992,7 +992,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
34635 {
34636 int i, count = CPUIDLE_DRIVER_STATE_START;
34637 struct acpi_processor_cx *cx;
34638- struct cpuidle_state *state;
34639+ cpuidle_state_no_const *state;
34640 struct cpuidle_driver *drv = &acpi_idle_driver;
34641
34642 if (!pr->flags.power_setup_done)
34643diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
34644index 05306a5..733d1f0 100644
34645--- a/drivers/acpi/sysfs.c
34646+++ b/drivers/acpi/sysfs.c
34647@@ -423,11 +423,11 @@ static u32 num_counters;
34648 static struct attribute **all_attrs;
34649 static u32 acpi_gpe_count;
34650
34651-static struct attribute_group interrupt_stats_attr_group = {
34652+static attribute_group_no_const interrupt_stats_attr_group = {
34653 .name = "interrupts",
34654 };
34655
34656-static struct kobj_attribute *counter_attrs;
34657+static kobj_attribute_no_const *counter_attrs;
34658
34659 static void delete_gpe_attr_array(void)
34660 {
34661diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
34662index acfd0f7..e5acb08 100644
34663--- a/drivers/ata/libahci.c
34664+++ b/drivers/ata/libahci.c
34665@@ -1231,7 +1231,7 @@ int ahci_kick_engine(struct ata_port *ap)
34666 }
34667 EXPORT_SYMBOL_GPL(ahci_kick_engine);
34668
34669-static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
34670+static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
34671 struct ata_taskfile *tf, int is_cmd, u16 flags,
34672 unsigned long timeout_msec)
34673 {
34674diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
34675index c24354d..335c975 100644
34676--- a/drivers/ata/libata-core.c
34677+++ b/drivers/ata/libata-core.c
34678@@ -98,7 +98,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
34679 static void ata_dev_xfermask(struct ata_device *dev);
34680 static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
34681
34682-atomic_t ata_print_id = ATOMIC_INIT(0);
34683+atomic_unchecked_t ata_print_id = ATOMIC_INIT(0);
34684
34685 struct ata_force_param {
34686 const char *name;
34687@@ -4792,7 +4792,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
34688 struct ata_port *ap;
34689 unsigned int tag;
34690
34691- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
34692+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
34693 ap = qc->ap;
34694
34695 qc->flags = 0;
34696@@ -4808,7 +4808,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
34697 struct ata_port *ap;
34698 struct ata_link *link;
34699
34700- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
34701+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
34702 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
34703 ap = qc->ap;
34704 link = qc->dev->link;
34705@@ -5927,6 +5927,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
34706 return;
34707
34708 spin_lock(&lock);
34709+ pax_open_kernel();
34710
34711 for (cur = ops->inherits; cur; cur = cur->inherits) {
34712 void **inherit = (void **)cur;
34713@@ -5940,8 +5941,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
34714 if (IS_ERR(*pp))
34715 *pp = NULL;
34716
34717- ops->inherits = NULL;
34718+ *(struct ata_port_operations **)&ops->inherits = NULL;
34719
34720+ pax_close_kernel();
34721 spin_unlock(&lock);
34722 }
34723
34724@@ -6134,7 +6136,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
34725
34726 /* give ports names and add SCSI hosts */
34727 for (i = 0; i < host->n_ports; i++) {
34728- host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
34729+ host->ports[i]->print_id = atomic_inc_return_unchecked(&ata_print_id);
34730 host->ports[i]->local_port_no = i + 1;
34731 }
34732
34733diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
34734index b1e880a..8cf82e1 100644
34735--- a/drivers/ata/libata-scsi.c
34736+++ b/drivers/ata/libata-scsi.c
34737@@ -4104,7 +4104,7 @@ int ata_sas_port_init(struct ata_port *ap)
34738
34739 if (rc)
34740 return rc;
34741- ap->print_id = atomic_inc_return(&ata_print_id);
34742+ ap->print_id = atomic_inc_return_unchecked(&ata_print_id);
34743 return 0;
34744 }
34745 EXPORT_SYMBOL_GPL(ata_sas_port_init);
34746diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
34747index 577d902b..cb4781e 100644
34748--- a/drivers/ata/libata.h
34749+++ b/drivers/ata/libata.h
34750@@ -53,7 +53,7 @@ enum {
34751 ATA_DNXFER_QUIET = (1 << 31),
34752 };
34753
34754-extern atomic_t ata_print_id;
34755+extern atomic_unchecked_t ata_print_id;
34756 extern int atapi_passthru16;
34757 extern int libata_fua;
34758 extern int libata_noacpi;
34759diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
34760index 848ed32..132f39d 100644
34761--- a/drivers/ata/pata_arasan_cf.c
34762+++ b/drivers/ata/pata_arasan_cf.c
34763@@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
34764 /* Handle platform specific quirks */
34765 if (quirk) {
34766 if (quirk & CF_BROKEN_PIO) {
34767- ap->ops->set_piomode = NULL;
34768+ pax_open_kernel();
34769+ *(void **)&ap->ops->set_piomode = NULL;
34770+ pax_close_kernel();
34771 ap->pio_mask = 0;
34772 }
34773 if (quirk & CF_BROKEN_MWDMA)
34774diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
34775index f9b983a..887b9d8 100644
34776--- a/drivers/atm/adummy.c
34777+++ b/drivers/atm/adummy.c
34778@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
34779 vcc->pop(vcc, skb);
34780 else
34781 dev_kfree_skb_any(skb);
34782- atomic_inc(&vcc->stats->tx);
34783+ atomic_inc_unchecked(&vcc->stats->tx);
34784
34785 return 0;
34786 }
34787diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
34788index 62a7607..cc4be104 100644
34789--- a/drivers/atm/ambassador.c
34790+++ b/drivers/atm/ambassador.c
34791@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
34792 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
34793
34794 // VC layer stats
34795- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
34796+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
34797
34798 // free the descriptor
34799 kfree (tx_descr);
34800@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
34801 dump_skb ("<<<", vc, skb);
34802
34803 // VC layer stats
34804- atomic_inc(&atm_vcc->stats->rx);
34805+ atomic_inc_unchecked(&atm_vcc->stats->rx);
34806 __net_timestamp(skb);
34807 // end of our responsibility
34808 atm_vcc->push (atm_vcc, skb);
34809@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
34810 } else {
34811 PRINTK (KERN_INFO, "dropped over-size frame");
34812 // should we count this?
34813- atomic_inc(&atm_vcc->stats->rx_drop);
34814+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
34815 }
34816
34817 } else {
34818@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
34819 }
34820
34821 if (check_area (skb->data, skb->len)) {
34822- atomic_inc(&atm_vcc->stats->tx_err);
34823+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
34824 return -ENOMEM; // ?
34825 }
34826
34827diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
34828index 0e3f8f9..765a7a5 100644
34829--- a/drivers/atm/atmtcp.c
34830+++ b/drivers/atm/atmtcp.c
34831@@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
34832 if (vcc->pop) vcc->pop(vcc,skb);
34833 else dev_kfree_skb(skb);
34834 if (dev_data) return 0;
34835- atomic_inc(&vcc->stats->tx_err);
34836+ atomic_inc_unchecked(&vcc->stats->tx_err);
34837 return -ENOLINK;
34838 }
34839 size = skb->len+sizeof(struct atmtcp_hdr);
34840@@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
34841 if (!new_skb) {
34842 if (vcc->pop) vcc->pop(vcc,skb);
34843 else dev_kfree_skb(skb);
34844- atomic_inc(&vcc->stats->tx_err);
34845+ atomic_inc_unchecked(&vcc->stats->tx_err);
34846 return -ENOBUFS;
34847 }
34848 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
34849@@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
34850 if (vcc->pop) vcc->pop(vcc,skb);
34851 else dev_kfree_skb(skb);
34852 out_vcc->push(out_vcc,new_skb);
34853- atomic_inc(&vcc->stats->tx);
34854- atomic_inc(&out_vcc->stats->rx);
34855+ atomic_inc_unchecked(&vcc->stats->tx);
34856+ atomic_inc_unchecked(&out_vcc->stats->rx);
34857 return 0;
34858 }
34859
34860@@ -299,7 +299,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
34861 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
34862 read_unlock(&vcc_sklist_lock);
34863 if (!out_vcc) {
34864- atomic_inc(&vcc->stats->tx_err);
34865+ atomic_inc_unchecked(&vcc->stats->tx_err);
34866 goto done;
34867 }
34868 skb_pull(skb,sizeof(struct atmtcp_hdr));
34869@@ -311,8 +311,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
34870 __net_timestamp(new_skb);
34871 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
34872 out_vcc->push(out_vcc,new_skb);
34873- atomic_inc(&vcc->stats->tx);
34874- atomic_inc(&out_vcc->stats->rx);
34875+ atomic_inc_unchecked(&vcc->stats->tx);
34876+ atomic_inc_unchecked(&out_vcc->stats->rx);
34877 done:
34878 if (vcc->pop) vcc->pop(vcc,skb);
34879 else dev_kfree_skb(skb);
34880diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
34881index b1955ba..b179940 100644
34882--- a/drivers/atm/eni.c
34883+++ b/drivers/atm/eni.c
34884@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
34885 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
34886 vcc->dev->number);
34887 length = 0;
34888- atomic_inc(&vcc->stats->rx_err);
34889+ atomic_inc_unchecked(&vcc->stats->rx_err);
34890 }
34891 else {
34892 length = ATM_CELL_SIZE-1; /* no HEC */
34893@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
34894 size);
34895 }
34896 eff = length = 0;
34897- atomic_inc(&vcc->stats->rx_err);
34898+ atomic_inc_unchecked(&vcc->stats->rx_err);
34899 }
34900 else {
34901 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
34902@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
34903 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
34904 vcc->dev->number,vcc->vci,length,size << 2,descr);
34905 length = eff = 0;
34906- atomic_inc(&vcc->stats->rx_err);
34907+ atomic_inc_unchecked(&vcc->stats->rx_err);
34908 }
34909 }
34910 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
34911@@ -767,7 +767,7 @@ rx_dequeued++;
34912 vcc->push(vcc,skb);
34913 pushed++;
34914 }
34915- atomic_inc(&vcc->stats->rx);
34916+ atomic_inc_unchecked(&vcc->stats->rx);
34917 }
34918 wake_up(&eni_dev->rx_wait);
34919 }
34920@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
34921 PCI_DMA_TODEVICE);
34922 if (vcc->pop) vcc->pop(vcc,skb);
34923 else dev_kfree_skb_irq(skb);
34924- atomic_inc(&vcc->stats->tx);
34925+ atomic_inc_unchecked(&vcc->stats->tx);
34926 wake_up(&eni_dev->tx_wait);
34927 dma_complete++;
34928 }
34929diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
34930index b41c948..a002b17 100644
34931--- a/drivers/atm/firestream.c
34932+++ b/drivers/atm/firestream.c
34933@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
34934 }
34935 }
34936
34937- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
34938+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
34939
34940 fs_dprintk (FS_DEBUG_TXMEM, "i");
34941 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
34942@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
34943 #endif
34944 skb_put (skb, qe->p1 & 0xffff);
34945 ATM_SKB(skb)->vcc = atm_vcc;
34946- atomic_inc(&atm_vcc->stats->rx);
34947+ atomic_inc_unchecked(&atm_vcc->stats->rx);
34948 __net_timestamp(skb);
34949 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
34950 atm_vcc->push (atm_vcc, skb);
34951@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
34952 kfree (pe);
34953 }
34954 if (atm_vcc)
34955- atomic_inc(&atm_vcc->stats->rx_drop);
34956+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
34957 break;
34958 case 0x1f: /* Reassembly abort: no buffers. */
34959 /* Silently increment error counter. */
34960 if (atm_vcc)
34961- atomic_inc(&atm_vcc->stats->rx_drop);
34962+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
34963 break;
34964 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
34965 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
34966diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
34967index 204814e..cede831 100644
34968--- a/drivers/atm/fore200e.c
34969+++ b/drivers/atm/fore200e.c
34970@@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
34971 #endif
34972 /* check error condition */
34973 if (*entry->status & STATUS_ERROR)
34974- atomic_inc(&vcc->stats->tx_err);
34975+ atomic_inc_unchecked(&vcc->stats->tx_err);
34976 else
34977- atomic_inc(&vcc->stats->tx);
34978+ atomic_inc_unchecked(&vcc->stats->tx);
34979 }
34980 }
34981
34982@@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
34983 if (skb == NULL) {
34984 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
34985
34986- atomic_inc(&vcc->stats->rx_drop);
34987+ atomic_inc_unchecked(&vcc->stats->rx_drop);
34988 return -ENOMEM;
34989 }
34990
34991@@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
34992
34993 dev_kfree_skb_any(skb);
34994
34995- atomic_inc(&vcc->stats->rx_drop);
34996+ atomic_inc_unchecked(&vcc->stats->rx_drop);
34997 return -ENOMEM;
34998 }
34999
35000 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
35001
35002 vcc->push(vcc, skb);
35003- atomic_inc(&vcc->stats->rx);
35004+ atomic_inc_unchecked(&vcc->stats->rx);
35005
35006 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
35007
35008@@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
35009 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
35010 fore200e->atm_dev->number,
35011 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
35012- atomic_inc(&vcc->stats->rx_err);
35013+ atomic_inc_unchecked(&vcc->stats->rx_err);
35014 }
35015 }
35016
35017@@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
35018 goto retry_here;
35019 }
35020
35021- atomic_inc(&vcc->stats->tx_err);
35022+ atomic_inc_unchecked(&vcc->stats->tx_err);
35023
35024 fore200e->tx_sat++;
35025 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
35026diff --git a/drivers/atm/he.c b/drivers/atm/he.c
35027index 507362a..a845e57 100644
35028--- a/drivers/atm/he.c
35029+++ b/drivers/atm/he.c
35030@@ -1698,7 +1698,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
35031
35032 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
35033 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
35034- atomic_inc(&vcc->stats->rx_drop);
35035+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35036 goto return_host_buffers;
35037 }
35038
35039@@ -1725,7 +1725,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
35040 RBRQ_LEN_ERR(he_dev->rbrq_head)
35041 ? "LEN_ERR" : "",
35042 vcc->vpi, vcc->vci);
35043- atomic_inc(&vcc->stats->rx_err);
35044+ atomic_inc_unchecked(&vcc->stats->rx_err);
35045 goto return_host_buffers;
35046 }
35047
35048@@ -1777,7 +1777,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
35049 vcc->push(vcc, skb);
35050 spin_lock(&he_dev->global_lock);
35051
35052- atomic_inc(&vcc->stats->rx);
35053+ atomic_inc_unchecked(&vcc->stats->rx);
35054
35055 return_host_buffers:
35056 ++pdus_assembled;
35057@@ -2103,7 +2103,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
35058 tpd->vcc->pop(tpd->vcc, tpd->skb);
35059 else
35060 dev_kfree_skb_any(tpd->skb);
35061- atomic_inc(&tpd->vcc->stats->tx_err);
35062+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
35063 }
35064 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
35065 return;
35066@@ -2515,7 +2515,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35067 vcc->pop(vcc, skb);
35068 else
35069 dev_kfree_skb_any(skb);
35070- atomic_inc(&vcc->stats->tx_err);
35071+ atomic_inc_unchecked(&vcc->stats->tx_err);
35072 return -EINVAL;
35073 }
35074
35075@@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35076 vcc->pop(vcc, skb);
35077 else
35078 dev_kfree_skb_any(skb);
35079- atomic_inc(&vcc->stats->tx_err);
35080+ atomic_inc_unchecked(&vcc->stats->tx_err);
35081 return -EINVAL;
35082 }
35083 #endif
35084@@ -2538,7 +2538,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35085 vcc->pop(vcc, skb);
35086 else
35087 dev_kfree_skb_any(skb);
35088- atomic_inc(&vcc->stats->tx_err);
35089+ atomic_inc_unchecked(&vcc->stats->tx_err);
35090 spin_unlock_irqrestore(&he_dev->global_lock, flags);
35091 return -ENOMEM;
35092 }
35093@@ -2580,7 +2580,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35094 vcc->pop(vcc, skb);
35095 else
35096 dev_kfree_skb_any(skb);
35097- atomic_inc(&vcc->stats->tx_err);
35098+ atomic_inc_unchecked(&vcc->stats->tx_err);
35099 spin_unlock_irqrestore(&he_dev->global_lock, flags);
35100 return -ENOMEM;
35101 }
35102@@ -2611,7 +2611,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35103 __enqueue_tpd(he_dev, tpd, cid);
35104 spin_unlock_irqrestore(&he_dev->global_lock, flags);
35105
35106- atomic_inc(&vcc->stats->tx);
35107+ atomic_inc_unchecked(&vcc->stats->tx);
35108
35109 return 0;
35110 }
35111diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
35112index 1dc0519..1aadaf7 100644
35113--- a/drivers/atm/horizon.c
35114+++ b/drivers/atm/horizon.c
35115@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
35116 {
35117 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
35118 // VC layer stats
35119- atomic_inc(&vcc->stats->rx);
35120+ atomic_inc_unchecked(&vcc->stats->rx);
35121 __net_timestamp(skb);
35122 // end of our responsibility
35123 vcc->push (vcc, skb);
35124@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
35125 dev->tx_iovec = NULL;
35126
35127 // VC layer stats
35128- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
35129+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
35130
35131 // free the skb
35132 hrz_kfree_skb (skb);
35133diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
35134index 272f009..a18ba55 100644
35135--- a/drivers/atm/idt77252.c
35136+++ b/drivers/atm/idt77252.c
35137@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
35138 else
35139 dev_kfree_skb(skb);
35140
35141- atomic_inc(&vcc->stats->tx);
35142+ atomic_inc_unchecked(&vcc->stats->tx);
35143 }
35144
35145 atomic_dec(&scq->used);
35146@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35147 if ((sb = dev_alloc_skb(64)) == NULL) {
35148 printk("%s: Can't allocate buffers for aal0.\n",
35149 card->name);
35150- atomic_add(i, &vcc->stats->rx_drop);
35151+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
35152 break;
35153 }
35154 if (!atm_charge(vcc, sb->truesize)) {
35155 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
35156 card->name);
35157- atomic_add(i - 1, &vcc->stats->rx_drop);
35158+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
35159 dev_kfree_skb(sb);
35160 break;
35161 }
35162@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35163 ATM_SKB(sb)->vcc = vcc;
35164 __net_timestamp(sb);
35165 vcc->push(vcc, sb);
35166- atomic_inc(&vcc->stats->rx);
35167+ atomic_inc_unchecked(&vcc->stats->rx);
35168
35169 cell += ATM_CELL_PAYLOAD;
35170 }
35171@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35172 "(CDC: %08x)\n",
35173 card->name, len, rpp->len, readl(SAR_REG_CDC));
35174 recycle_rx_pool_skb(card, rpp);
35175- atomic_inc(&vcc->stats->rx_err);
35176+ atomic_inc_unchecked(&vcc->stats->rx_err);
35177 return;
35178 }
35179 if (stat & SAR_RSQE_CRC) {
35180 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
35181 recycle_rx_pool_skb(card, rpp);
35182- atomic_inc(&vcc->stats->rx_err);
35183+ atomic_inc_unchecked(&vcc->stats->rx_err);
35184 return;
35185 }
35186 if (skb_queue_len(&rpp->queue) > 1) {
35187@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35188 RXPRINTK("%s: Can't alloc RX skb.\n",
35189 card->name);
35190 recycle_rx_pool_skb(card, rpp);
35191- atomic_inc(&vcc->stats->rx_err);
35192+ atomic_inc_unchecked(&vcc->stats->rx_err);
35193 return;
35194 }
35195 if (!atm_charge(vcc, skb->truesize)) {
35196@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35197 __net_timestamp(skb);
35198
35199 vcc->push(vcc, skb);
35200- atomic_inc(&vcc->stats->rx);
35201+ atomic_inc_unchecked(&vcc->stats->rx);
35202
35203 return;
35204 }
35205@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35206 __net_timestamp(skb);
35207
35208 vcc->push(vcc, skb);
35209- atomic_inc(&vcc->stats->rx);
35210+ atomic_inc_unchecked(&vcc->stats->rx);
35211
35212 if (skb->truesize > SAR_FB_SIZE_3)
35213 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
35214@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
35215 if (vcc->qos.aal != ATM_AAL0) {
35216 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
35217 card->name, vpi, vci);
35218- atomic_inc(&vcc->stats->rx_drop);
35219+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35220 goto drop;
35221 }
35222
35223 if ((sb = dev_alloc_skb(64)) == NULL) {
35224 printk("%s: Can't allocate buffers for AAL0.\n",
35225 card->name);
35226- atomic_inc(&vcc->stats->rx_err);
35227+ atomic_inc_unchecked(&vcc->stats->rx_err);
35228 goto drop;
35229 }
35230
35231@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
35232 ATM_SKB(sb)->vcc = vcc;
35233 __net_timestamp(sb);
35234 vcc->push(vcc, sb);
35235- atomic_inc(&vcc->stats->rx);
35236+ atomic_inc_unchecked(&vcc->stats->rx);
35237
35238 drop:
35239 skb_pull(queue, 64);
35240@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
35241
35242 if (vc == NULL) {
35243 printk("%s: NULL connection in send().\n", card->name);
35244- atomic_inc(&vcc->stats->tx_err);
35245+ atomic_inc_unchecked(&vcc->stats->tx_err);
35246 dev_kfree_skb(skb);
35247 return -EINVAL;
35248 }
35249 if (!test_bit(VCF_TX, &vc->flags)) {
35250 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
35251- atomic_inc(&vcc->stats->tx_err);
35252+ atomic_inc_unchecked(&vcc->stats->tx_err);
35253 dev_kfree_skb(skb);
35254 return -EINVAL;
35255 }
35256@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
35257 break;
35258 default:
35259 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
35260- atomic_inc(&vcc->stats->tx_err);
35261+ atomic_inc_unchecked(&vcc->stats->tx_err);
35262 dev_kfree_skb(skb);
35263 return -EINVAL;
35264 }
35265
35266 if (skb_shinfo(skb)->nr_frags != 0) {
35267 printk("%s: No scatter-gather yet.\n", card->name);
35268- atomic_inc(&vcc->stats->tx_err);
35269+ atomic_inc_unchecked(&vcc->stats->tx_err);
35270 dev_kfree_skb(skb);
35271 return -EINVAL;
35272 }
35273@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
35274
35275 err = queue_skb(card, vc, skb, oam);
35276 if (err) {
35277- atomic_inc(&vcc->stats->tx_err);
35278+ atomic_inc_unchecked(&vcc->stats->tx_err);
35279 dev_kfree_skb(skb);
35280 return err;
35281 }
35282@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
35283 skb = dev_alloc_skb(64);
35284 if (!skb) {
35285 printk("%s: Out of memory in send_oam().\n", card->name);
35286- atomic_inc(&vcc->stats->tx_err);
35287+ atomic_inc_unchecked(&vcc->stats->tx_err);
35288 return -ENOMEM;
35289 }
35290 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
35291diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
35292index 4217f29..88f547a 100644
35293--- a/drivers/atm/iphase.c
35294+++ b/drivers/atm/iphase.c
35295@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
35296 status = (u_short) (buf_desc_ptr->desc_mode);
35297 if (status & (RX_CER | RX_PTE | RX_OFL))
35298 {
35299- atomic_inc(&vcc->stats->rx_err);
35300+ atomic_inc_unchecked(&vcc->stats->rx_err);
35301 IF_ERR(printk("IA: bad packet, dropping it");)
35302 if (status & RX_CER) {
35303 IF_ERR(printk(" cause: packet CRC error\n");)
35304@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
35305 len = dma_addr - buf_addr;
35306 if (len > iadev->rx_buf_sz) {
35307 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
35308- atomic_inc(&vcc->stats->rx_err);
35309+ atomic_inc_unchecked(&vcc->stats->rx_err);
35310 goto out_free_desc;
35311 }
35312
35313@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
35314 ia_vcc = INPH_IA_VCC(vcc);
35315 if (ia_vcc == NULL)
35316 {
35317- atomic_inc(&vcc->stats->rx_err);
35318+ atomic_inc_unchecked(&vcc->stats->rx_err);
35319 atm_return(vcc, skb->truesize);
35320 dev_kfree_skb_any(skb);
35321 goto INCR_DLE;
35322@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
35323 if ((length > iadev->rx_buf_sz) || (length >
35324 (skb->len - sizeof(struct cpcs_trailer))))
35325 {
35326- atomic_inc(&vcc->stats->rx_err);
35327+ atomic_inc_unchecked(&vcc->stats->rx_err);
35328 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
35329 length, skb->len);)
35330 atm_return(vcc, skb->truesize);
35331@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
35332
35333 IF_RX(printk("rx_dle_intr: skb push");)
35334 vcc->push(vcc,skb);
35335- atomic_inc(&vcc->stats->rx);
35336+ atomic_inc_unchecked(&vcc->stats->rx);
35337 iadev->rx_pkt_cnt++;
35338 }
35339 INCR_DLE:
35340@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
35341 {
35342 struct k_sonet_stats *stats;
35343 stats = &PRIV(_ia_dev[board])->sonet_stats;
35344- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
35345- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
35346- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
35347- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
35348- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
35349- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
35350- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
35351- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
35352- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
35353+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
35354+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
35355+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
35356+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
35357+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
35358+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
35359+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
35360+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
35361+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
35362 }
35363 ia_cmds.status = 0;
35364 break;
35365@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
35366 if ((desc == 0) || (desc > iadev->num_tx_desc))
35367 {
35368 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
35369- atomic_inc(&vcc->stats->tx);
35370+ atomic_inc_unchecked(&vcc->stats->tx);
35371 if (vcc->pop)
35372 vcc->pop(vcc, skb);
35373 else
35374@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
35375 ATM_DESC(skb) = vcc->vci;
35376 skb_queue_tail(&iadev->tx_dma_q, skb);
35377
35378- atomic_inc(&vcc->stats->tx);
35379+ atomic_inc_unchecked(&vcc->stats->tx);
35380 iadev->tx_pkt_cnt++;
35381 /* Increment transaction counter */
35382 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
35383
35384 #if 0
35385 /* add flow control logic */
35386- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
35387+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
35388 if (iavcc->vc_desc_cnt > 10) {
35389 vcc->tx_quota = vcc->tx_quota * 3 / 4;
35390 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
35391diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
35392index fa7d701..1e404c7 100644
35393--- a/drivers/atm/lanai.c
35394+++ b/drivers/atm/lanai.c
35395@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
35396 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
35397 lanai_endtx(lanai, lvcc);
35398 lanai_free_skb(lvcc->tx.atmvcc, skb);
35399- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
35400+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
35401 }
35402
35403 /* Try to fill the buffer - don't call unless there is backlog */
35404@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
35405 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
35406 __net_timestamp(skb);
35407 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
35408- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
35409+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
35410 out:
35411 lvcc->rx.buf.ptr = end;
35412 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
35413@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
35414 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
35415 "vcc %d\n", lanai->number, (unsigned int) s, vci);
35416 lanai->stats.service_rxnotaal5++;
35417- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
35418+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
35419 return 0;
35420 }
35421 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
35422@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
35423 int bytes;
35424 read_unlock(&vcc_sklist_lock);
35425 DPRINTK("got trashed rx pdu on vci %d\n", vci);
35426- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
35427+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
35428 lvcc->stats.x.aal5.service_trash++;
35429 bytes = (SERVICE_GET_END(s) * 16) -
35430 (((unsigned long) lvcc->rx.buf.ptr) -
35431@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
35432 }
35433 if (s & SERVICE_STREAM) {
35434 read_unlock(&vcc_sklist_lock);
35435- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
35436+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
35437 lvcc->stats.x.aal5.service_stream++;
35438 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
35439 "PDU on VCI %d!\n", lanai->number, vci);
35440@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
35441 return 0;
35442 }
35443 DPRINTK("got rx crc error on vci %d\n", vci);
35444- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
35445+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
35446 lvcc->stats.x.aal5.service_rxcrc++;
35447 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
35448 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
35449diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
35450index 6587dc2..149833d 100644
35451--- a/drivers/atm/nicstar.c
35452+++ b/drivers/atm/nicstar.c
35453@@ -1641,7 +1641,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
35454 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
35455 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
35456 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@@ -1649,7 +1649,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
35463 if (!vc->tx) {
35464 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
35465 card->index);
35466- atomic_inc(&vcc->stats->tx_err);
35467+ atomic_inc_unchecked(&vcc->stats->tx_err);
35468 dev_kfree_skb_any(skb);
35469 return -EINVAL;
35470 }
35471@@ -1657,14 +1657,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
35472 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
35473 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
35474 card->index);
35475- atomic_inc(&vcc->stats->tx_err);
35476+ atomic_inc_unchecked(&vcc->stats->tx_err);
35477 dev_kfree_skb_any(skb);
35478 return -EINVAL;
35479 }
35480
35481 if (skb_shinfo(skb)->nr_frags != 0) {
35482 printk("nicstar%d: No scatter-gather yet.\n", card->index);
35483- atomic_inc(&vcc->stats->tx_err);
35484+ atomic_inc_unchecked(&vcc->stats->tx_err);
35485 dev_kfree_skb_any(skb);
35486 return -EINVAL;
35487 }
35488@@ -1712,11 +1712,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
35489 }
35490
35491 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
35492- atomic_inc(&vcc->stats->tx_err);
35493+ atomic_inc_unchecked(&vcc->stats->tx_err);
35494 dev_kfree_skb_any(skb);
35495 return -EIO;
35496 }
35497- atomic_inc(&vcc->stats->tx);
35498+ atomic_inc_unchecked(&vcc->stats->tx);
35499
35500 return 0;
35501 }
35502@@ -2033,14 +2033,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35503 printk
35504 ("nicstar%d: Can't allocate buffers for aal0.\n",
35505 card->index);
35506- atomic_add(i, &vcc->stats->rx_drop);
35507+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
35508 break;
35509 }
35510 if (!atm_charge(vcc, sb->truesize)) {
35511 RXPRINTK
35512 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
35513 card->index);
35514- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
35515+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
35516 dev_kfree_skb_any(sb);
35517 break;
35518 }
35519@@ -2055,7 +2055,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35520 ATM_SKB(sb)->vcc = vcc;
35521 __net_timestamp(sb);
35522 vcc->push(vcc, sb);
35523- atomic_inc(&vcc->stats->rx);
35524+ atomic_inc_unchecked(&vcc->stats->rx);
35525 cell += ATM_CELL_PAYLOAD;
35526 }
35527
35528@@ -2072,7 +2072,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35529 if (iovb == NULL) {
35530 printk("nicstar%d: Out of iovec buffers.\n",
35531 card->index);
35532- atomic_inc(&vcc->stats->rx_drop);
35533+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35534 recycle_rx_buf(card, skb);
35535 return;
35536 }
35537@@ -2096,7 +2096,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35538 small or large buffer itself. */
35539 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
35540 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
35541- atomic_inc(&vcc->stats->rx_err);
35542+ atomic_inc_unchecked(&vcc->stats->rx_err);
35543 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
35544 NS_MAX_IOVECS);
35545 NS_PRV_IOVCNT(iovb) = 0;
35546@@ -2116,7 +2116,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35547 ("nicstar%d: Expected a small buffer, and this is not one.\n",
35548 card->index);
35549 which_list(card, skb);
35550- atomic_inc(&vcc->stats->rx_err);
35551+ atomic_inc_unchecked(&vcc->stats->rx_err);
35552 recycle_rx_buf(card, skb);
35553 vc->rx_iov = NULL;
35554 recycle_iov_buf(card, iovb);
35555@@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35556 ("nicstar%d: Expected a large buffer, and this is not one.\n",
35557 card->index);
35558 which_list(card, skb);
35559- atomic_inc(&vcc->stats->rx_err);
35560+ atomic_inc_unchecked(&vcc->stats->rx_err);
35561 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
35562 NS_PRV_IOVCNT(iovb));
35563 vc->rx_iov = NULL;
35564@@ -2152,7 +2152,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35565 printk(" - PDU size mismatch.\n");
35566 else
35567 printk(".\n");
35568- atomic_inc(&vcc->stats->rx_err);
35569+ atomic_inc_unchecked(&vcc->stats->rx_err);
35570 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
35571 NS_PRV_IOVCNT(iovb));
35572 vc->rx_iov = NULL;
35573@@ -2166,7 +2166,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35574 /* skb points to a small buffer */
35575 if (!atm_charge(vcc, skb->truesize)) {
35576 push_rxbufs(card, skb);
35577- atomic_inc(&vcc->stats->rx_drop);
35578+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35579 } else {
35580 skb_put(skb, len);
35581 dequeue_sm_buf(card, skb);
35582@@ -2176,7 +2176,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35583 ATM_SKB(skb)->vcc = vcc;
35584 __net_timestamp(skb);
35585 vcc->push(vcc, skb);
35586- atomic_inc(&vcc->stats->rx);
35587+ atomic_inc_unchecked(&vcc->stats->rx);
35588 }
35589 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
35590 struct sk_buff *sb;
35591@@ -2187,7 +2187,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35592 if (len <= NS_SMBUFSIZE) {
35593 if (!atm_charge(vcc, sb->truesize)) {
35594 push_rxbufs(card, sb);
35595- atomic_inc(&vcc->stats->rx_drop);
35596+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35597 } else {
35598 skb_put(sb, len);
35599 dequeue_sm_buf(card, sb);
35600@@ -2197,7 +2197,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35601 ATM_SKB(sb)->vcc = vcc;
35602 __net_timestamp(sb);
35603 vcc->push(vcc, sb);
35604- atomic_inc(&vcc->stats->rx);
35605+ atomic_inc_unchecked(&vcc->stats->rx);
35606 }
35607
35608 push_rxbufs(card, skb);
35609@@ -2206,7 +2206,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35610
35611 if (!atm_charge(vcc, skb->truesize)) {
35612 push_rxbufs(card, skb);
35613- atomic_inc(&vcc->stats->rx_drop);
35614+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35615 } else {
35616 dequeue_lg_buf(card, skb);
35617 #ifdef NS_USE_DESTRUCTORS
35618@@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35619 ATM_SKB(skb)->vcc = vcc;
35620 __net_timestamp(skb);
35621 vcc->push(vcc, skb);
35622- atomic_inc(&vcc->stats->rx);
35623+ atomic_inc_unchecked(&vcc->stats->rx);
35624 }
35625
35626 push_rxbufs(card, sb);
35627@@ -2240,7 +2240,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35628 printk
35629 ("nicstar%d: Out of huge buffers.\n",
35630 card->index);
35631- atomic_inc(&vcc->stats->rx_drop);
35632+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35633 recycle_iovec_rx_bufs(card,
35634 (struct iovec *)
35635 iovb->data,
35636@@ -2291,7 +2291,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35637 card->hbpool.count++;
35638 } else
35639 dev_kfree_skb_any(hb);
35640- atomic_inc(&vcc->stats->rx_drop);
35641+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35642 } else {
35643 /* Copy the small buffer to the huge buffer */
35644 sb = (struct sk_buff *)iov->iov_base;
35645@@ -2328,7 +2328,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35646 #endif /* NS_USE_DESTRUCTORS */
35647 __net_timestamp(hb);
35648 vcc->push(vcc, hb);
35649- atomic_inc(&vcc->stats->rx);
35650+ atomic_inc_unchecked(&vcc->stats->rx);
35651 }
35652 }
35653
35654diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
35655index 32784d1..4a8434a 100644
35656--- a/drivers/atm/solos-pci.c
35657+++ b/drivers/atm/solos-pci.c
35658@@ -838,7 +838,7 @@ void solos_bh(unsigned long card_arg)
35659 }
35660 atm_charge(vcc, skb->truesize);
35661 vcc->push(vcc, skb);
35662- atomic_inc(&vcc->stats->rx);
35663+ atomic_inc_unchecked(&vcc->stats->rx);
35664 break;
35665
35666 case PKT_STATUS:
35667@@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
35668 vcc = SKB_CB(oldskb)->vcc;
35669
35670 if (vcc) {
35671- atomic_inc(&vcc->stats->tx);
35672+ atomic_inc_unchecked(&vcc->stats->tx);
35673 solos_pop(vcc, oldskb);
35674 } else {
35675 dev_kfree_skb_irq(oldskb);
35676diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
35677index 0215934..ce9f5b1 100644
35678--- a/drivers/atm/suni.c
35679+++ b/drivers/atm/suni.c
35680@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
35681
35682
35683 #define ADD_LIMITED(s,v) \
35684- atomic_add((v),&stats->s); \
35685- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
35686+ atomic_add_unchecked((v),&stats->s); \
35687+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
35688
35689
35690 static void suni_hz(unsigned long from_timer)
35691diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
35692index 5120a96..e2572bd 100644
35693--- a/drivers/atm/uPD98402.c
35694+++ b/drivers/atm/uPD98402.c
35695@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
35696 struct sonet_stats tmp;
35697 int error = 0;
35698
35699- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
35700+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
35701 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
35702 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
35703 if (zero && !error) {
35704@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
35705
35706
35707 #define ADD_LIMITED(s,v) \
35708- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
35709- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
35710- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
35711+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
35712+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
35713+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
35714
35715
35716 static void stat_event(struct atm_dev *dev)
35717@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
35718 if (reason & uPD98402_INT_PFM) stat_event(dev);
35719 if (reason & uPD98402_INT_PCO) {
35720 (void) GET(PCOCR); /* clear interrupt cause */
35721- atomic_add(GET(HECCT),
35722+ atomic_add_unchecked(GET(HECCT),
35723 &PRIV(dev)->sonet_stats.uncorr_hcs);
35724 }
35725 if ((reason & uPD98402_INT_RFO) &&
35726@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
35727 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
35728 uPD98402_INT_LOS),PIMR); /* enable them */
35729 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
35730- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
35731- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
35732- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
35733+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
35734+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
35735+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
35736 return 0;
35737 }
35738
35739diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
35740index 969c3c2..9b72956 100644
35741--- a/drivers/atm/zatm.c
35742+++ b/drivers/atm/zatm.c
35743@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
35744 }
35745 if (!size) {
35746 dev_kfree_skb_irq(skb);
35747- if (vcc) atomic_inc(&vcc->stats->rx_err);
35748+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
35749 continue;
35750 }
35751 if (!atm_charge(vcc,skb->truesize)) {
35752@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
35753 skb->len = size;
35754 ATM_SKB(skb)->vcc = vcc;
35755 vcc->push(vcc,skb);
35756- atomic_inc(&vcc->stats->rx);
35757+ atomic_inc_unchecked(&vcc->stats->rx);
35758 }
35759 zout(pos & 0xffff,MTA(mbx));
35760 #if 0 /* probably a stupid idea */
35761@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
35762 skb_queue_head(&zatm_vcc->backlog,skb);
35763 break;
35764 }
35765- atomic_inc(&vcc->stats->tx);
35766+ atomic_inc_unchecked(&vcc->stats->tx);
35767 wake_up(&zatm_vcc->tx_wait);
35768 }
35769
35770diff --git a/drivers/base/bus.c b/drivers/base/bus.c
35771index d414331..b4dd4ba 100644
35772--- a/drivers/base/bus.c
35773+++ b/drivers/base/bus.c
35774@@ -1163,7 +1163,7 @@ int subsys_interface_register(struct subsys_interface *sif)
35775 return -EINVAL;
35776
35777 mutex_lock(&subsys->p->mutex);
35778- list_add_tail(&sif->node, &subsys->p->interfaces);
35779+ pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
35780 if (sif->add_dev) {
35781 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
35782 while ((dev = subsys_dev_iter_next(&iter)))
35783@@ -1188,7 +1188,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
35784 subsys = sif->subsys;
35785
35786 mutex_lock(&subsys->p->mutex);
35787- list_del_init(&sif->node);
35788+ pax_list_del_init((struct list_head *)&sif->node);
35789 if (sif->remove_dev) {
35790 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
35791 while ((dev = subsys_dev_iter_next(&iter)))
35792diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
35793index 7413d06..79155fa 100644
35794--- a/drivers/base/devtmpfs.c
35795+++ b/drivers/base/devtmpfs.c
35796@@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
35797 if (!thread)
35798 return 0;
35799
35800- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
35801+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
35802 if (err)
35803 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
35804 else
35805@@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
35806 *err = sys_unshare(CLONE_NEWNS);
35807 if (*err)
35808 goto out;
35809- *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
35810+ *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
35811 if (*err)
35812 goto out;
35813- sys_chdir("/.."); /* will traverse into overmounted root */
35814- sys_chroot(".");
35815+ sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
35816+ sys_chroot((char __force_user *)".");
35817 complete(&setup_done);
35818 while (1) {
35819 spin_lock(&req_lock);
35820diff --git a/drivers/base/node.c b/drivers/base/node.c
35821index 7616a77c..8f57f51 100644
35822--- a/drivers/base/node.c
35823+++ b/drivers/base/node.c
35824@@ -626,7 +626,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
35825 struct node_attr {
35826 struct device_attribute attr;
35827 enum node_states state;
35828-};
35829+} __do_const;
35830
35831 static ssize_t show_node_state(struct device *dev,
35832 struct device_attribute *attr, char *buf)
35833diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
35834index bfb8955..42c9b9a 100644
35835--- a/drivers/base/power/domain.c
35836+++ b/drivers/base/power/domain.c
35837@@ -1850,7 +1850,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
35838 {
35839 struct cpuidle_driver *cpuidle_drv;
35840 struct gpd_cpu_data *cpu_data;
35841- struct cpuidle_state *idle_state;
35842+ cpuidle_state_no_const *idle_state;
35843 int ret = 0;
35844
35845 if (IS_ERR_OR_NULL(genpd) || state < 0)
35846@@ -1918,7 +1918,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
35847 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
35848 {
35849 struct gpd_cpu_data *cpu_data;
35850- struct cpuidle_state *idle_state;
35851+ cpuidle_state_no_const *idle_state;
35852 int ret = 0;
35853
35854 if (IS_ERR_OR_NULL(genpd))
35855diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
35856index a53ebd2..8f73eeb 100644
35857--- a/drivers/base/power/sysfs.c
35858+++ b/drivers/base/power/sysfs.c
35859@@ -185,7 +185,7 @@ static ssize_t rtpm_status_show(struct device *dev,
35860 return -EIO;
35861 }
35862 }
35863- return sprintf(buf, p);
35864+ return sprintf(buf, "%s", p);
35865 }
35866
35867 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
35868diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
35869index 2d56f41..8830f19 100644
35870--- a/drivers/base/power/wakeup.c
35871+++ b/drivers/base/power/wakeup.c
35872@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
35873 * They need to be modified together atomically, so it's better to use one
35874 * atomic variable to hold them both.
35875 */
35876-static atomic_t combined_event_count = ATOMIC_INIT(0);
35877+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
35878
35879 #define IN_PROGRESS_BITS (sizeof(int) * 4)
35880 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
35881
35882 static void split_counters(unsigned int *cnt, unsigned int *inpr)
35883 {
35884- unsigned int comb = atomic_read(&combined_event_count);
35885+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
35886
35887 *cnt = (comb >> IN_PROGRESS_BITS);
35888 *inpr = comb & MAX_IN_PROGRESS;
35889@@ -395,7 +395,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
35890 ws->start_prevent_time = ws->last_time;
35891
35892 /* Increment the counter of events in progress. */
35893- cec = atomic_inc_return(&combined_event_count);
35894+ cec = atomic_inc_return_unchecked(&combined_event_count);
35895
35896 trace_wakeup_source_activate(ws->name, cec);
35897 }
35898@@ -521,7 +521,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
35899 * Increment the counter of registered wakeup events and decrement the
35900 * couter of wakeup events in progress simultaneously.
35901 */
35902- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
35903+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
35904 trace_wakeup_source_deactivate(ws->name, cec);
35905
35906 split_counters(&cnt, &inpr);
35907diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
35908index e8d11b6..7b1b36f 100644
35909--- a/drivers/base/syscore.c
35910+++ b/drivers/base/syscore.c
35911@@ -21,7 +21,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
35912 void register_syscore_ops(struct syscore_ops *ops)
35913 {
35914 mutex_lock(&syscore_ops_lock);
35915- list_add_tail(&ops->node, &syscore_ops_list);
35916+ pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
35917 mutex_unlock(&syscore_ops_lock);
35918 }
35919 EXPORT_SYMBOL_GPL(register_syscore_ops);
35920@@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
35921 void unregister_syscore_ops(struct syscore_ops *ops)
35922 {
35923 mutex_lock(&syscore_ops_lock);
35924- list_del(&ops->node);
35925+ pax_list_del((struct list_head *)&ops->node);
35926 mutex_unlock(&syscore_ops_lock);
35927 }
35928 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
35929diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
35930index 62b6c2c..4a11354 100644
35931--- a/drivers/block/cciss.c
35932+++ b/drivers/block/cciss.c
35933@@ -1189,6 +1189,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
35934 int err;
35935 u32 cp;
35936
35937+ memset(&arg64, 0, sizeof(arg64));
35938+
35939 err = 0;
35940 err |=
35941 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
35942@@ -3010,7 +3012,7 @@ static void start_io(ctlr_info_t *h)
35943 while (!list_empty(&h->reqQ)) {
35944 c = list_entry(h->reqQ.next, CommandList_struct, list);
35945 /* can't do anything if fifo is full */
35946- if ((h->access.fifo_full(h))) {
35947+ if ((h->access->fifo_full(h))) {
35948 dev_warn(&h->pdev->dev, "fifo full\n");
35949 break;
35950 }
35951@@ -3020,7 +3022,7 @@ static void start_io(ctlr_info_t *h)
35952 h->Qdepth--;
35953
35954 /* Tell the controller execute command */
35955- h->access.submit_command(h, c);
35956+ h->access->submit_command(h, c);
35957
35958 /* Put job onto the completed Q */
35959 addQ(&h->cmpQ, c);
35960@@ -3446,17 +3448,17 @@ startio:
35961
35962 static inline unsigned long get_next_completion(ctlr_info_t *h)
35963 {
35964- return h->access.command_completed(h);
35965+ return h->access->command_completed(h);
35966 }
35967
35968 static inline int interrupt_pending(ctlr_info_t *h)
35969 {
35970- return h->access.intr_pending(h);
35971+ return h->access->intr_pending(h);
35972 }
35973
35974 static inline long interrupt_not_for_us(ctlr_info_t *h)
35975 {
35976- return ((h->access.intr_pending(h) == 0) ||
35977+ return ((h->access->intr_pending(h) == 0) ||
35978 (h->interrupts_enabled == 0));
35979 }
35980
35981@@ -3489,7 +3491,7 @@ static inline u32 next_command(ctlr_info_t *h)
35982 u32 a;
35983
35984 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
35985- return h->access.command_completed(h);
35986+ return h->access->command_completed(h);
35987
35988 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
35989 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
35990@@ -4046,7 +4048,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
35991 trans_support & CFGTBL_Trans_use_short_tags);
35992
35993 /* Change the access methods to the performant access methods */
35994- h->access = SA5_performant_access;
35995+ h->access = &SA5_performant_access;
35996 h->transMethod = CFGTBL_Trans_Performant;
35997
35998 return;
35999@@ -4319,7 +4321,7 @@ static int cciss_pci_init(ctlr_info_t *h)
36000 if (prod_index < 0)
36001 return -ENODEV;
36002 h->product_name = products[prod_index].product_name;
36003- h->access = *(products[prod_index].access);
36004+ h->access = products[prod_index].access;
36005
36006 if (cciss_board_disabled(h)) {
36007 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
36008@@ -5051,7 +5053,7 @@ reinit_after_soft_reset:
36009 }
36010
36011 /* make sure the board interrupts are off */
36012- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36013+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36014 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
36015 if (rc)
36016 goto clean2;
36017@@ -5101,7 +5103,7 @@ reinit_after_soft_reset:
36018 * fake ones to scoop up any residual completions.
36019 */
36020 spin_lock_irqsave(&h->lock, flags);
36021- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36022+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36023 spin_unlock_irqrestore(&h->lock, flags);
36024 free_irq(h->intr[h->intr_mode], h);
36025 rc = cciss_request_irq(h, cciss_msix_discard_completions,
36026@@ -5121,9 +5123,9 @@ reinit_after_soft_reset:
36027 dev_info(&h->pdev->dev, "Board READY.\n");
36028 dev_info(&h->pdev->dev,
36029 "Waiting for stale completions to drain.\n");
36030- h->access.set_intr_mask(h, CCISS_INTR_ON);
36031+ h->access->set_intr_mask(h, CCISS_INTR_ON);
36032 msleep(10000);
36033- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36034+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36035
36036 rc = controller_reset_failed(h->cfgtable);
36037 if (rc)
36038@@ -5146,7 +5148,7 @@ reinit_after_soft_reset:
36039 cciss_scsi_setup(h);
36040
36041 /* Turn the interrupts on so we can service requests */
36042- h->access.set_intr_mask(h, CCISS_INTR_ON);
36043+ h->access->set_intr_mask(h, CCISS_INTR_ON);
36044
36045 /* Get the firmware version */
36046 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
36047@@ -5218,7 +5220,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
36048 kfree(flush_buf);
36049 if (return_code != IO_OK)
36050 dev_warn(&h->pdev->dev, "Error flushing cache\n");
36051- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36052+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36053 free_irq(h->intr[h->intr_mode], h);
36054 }
36055
36056diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
36057index 7fda30e..eb5dfe0 100644
36058--- a/drivers/block/cciss.h
36059+++ b/drivers/block/cciss.h
36060@@ -101,7 +101,7 @@ struct ctlr_info
36061 /* information about each logical volume */
36062 drive_info_struct *drv[CISS_MAX_LUN];
36063
36064- struct access_method access;
36065+ struct access_method *access;
36066
36067 /* queue and queue Info */
36068 struct list_head reqQ;
36069diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
36070index 639d26b..fd6ad1f 100644
36071--- a/drivers/block/cpqarray.c
36072+++ b/drivers/block/cpqarray.c
36073@@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
36074 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
36075 goto Enomem4;
36076 }
36077- hba[i]->access.set_intr_mask(hba[i], 0);
36078+ hba[i]->access->set_intr_mask(hba[i], 0);
36079 if (request_irq(hba[i]->intr, do_ida_intr,
36080 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
36081 {
36082@@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
36083 add_timer(&hba[i]->timer);
36084
36085 /* Enable IRQ now that spinlock and rate limit timer are set up */
36086- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
36087+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
36088
36089 for(j=0; j<NWD; j++) {
36090 struct gendisk *disk = ida_gendisk[i][j];
36091@@ -694,7 +694,7 @@ DBGINFO(
36092 for(i=0; i<NR_PRODUCTS; i++) {
36093 if (board_id == products[i].board_id) {
36094 c->product_name = products[i].product_name;
36095- c->access = *(products[i].access);
36096+ c->access = products[i].access;
36097 break;
36098 }
36099 }
36100@@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
36101 hba[ctlr]->intr = intr;
36102 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
36103 hba[ctlr]->product_name = products[j].product_name;
36104- hba[ctlr]->access = *(products[j].access);
36105+ hba[ctlr]->access = products[j].access;
36106 hba[ctlr]->ctlr = ctlr;
36107 hba[ctlr]->board_id = board_id;
36108 hba[ctlr]->pci_dev = NULL; /* not PCI */
36109@@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
36110
36111 while((c = h->reqQ) != NULL) {
36112 /* Can't do anything if we're busy */
36113- if (h->access.fifo_full(h) == 0)
36114+ if (h->access->fifo_full(h) == 0)
36115 return;
36116
36117 /* Get the first entry from the request Q */
36118@@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
36119 h->Qdepth--;
36120
36121 /* Tell the controller to do our bidding */
36122- h->access.submit_command(h, c);
36123+ h->access->submit_command(h, c);
36124
36125 /* Get onto the completion Q */
36126 addQ(&h->cmpQ, c);
36127@@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
36128 unsigned long flags;
36129 __u32 a,a1;
36130
36131- istat = h->access.intr_pending(h);
36132+ istat = h->access->intr_pending(h);
36133 /* Is this interrupt for us? */
36134 if (istat == 0)
36135 return IRQ_NONE;
36136@@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
36137 */
36138 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
36139 if (istat & FIFO_NOT_EMPTY) {
36140- while((a = h->access.command_completed(h))) {
36141+ while((a = h->access->command_completed(h))) {
36142 a1 = a; a &= ~3;
36143 if ((c = h->cmpQ) == NULL)
36144 {
36145@@ -1193,6 +1193,7 @@ out_passthru:
36146 ida_pci_info_struct pciinfo;
36147
36148 if (!arg) return -EINVAL;
36149+ memset(&pciinfo, 0, sizeof(pciinfo));
36150 pciinfo.bus = host->pci_dev->bus->number;
36151 pciinfo.dev_fn = host->pci_dev->devfn;
36152 pciinfo.board_id = host->board_id;
36153@@ -1447,11 +1448,11 @@ static int sendcmd(
36154 /*
36155 * Disable interrupt
36156 */
36157- info_p->access.set_intr_mask(info_p, 0);
36158+ info_p->access->set_intr_mask(info_p, 0);
36159 /* Make sure there is room in the command FIFO */
36160 /* Actually it should be completely empty at this time. */
36161 for (i = 200000; i > 0; i--) {
36162- temp = info_p->access.fifo_full(info_p);
36163+ temp = info_p->access->fifo_full(info_p);
36164 if (temp != 0) {
36165 break;
36166 }
36167@@ -1464,7 +1465,7 @@ DBG(
36168 /*
36169 * Send the cmd
36170 */
36171- info_p->access.submit_command(info_p, c);
36172+ info_p->access->submit_command(info_p, c);
36173 complete = pollcomplete(ctlr);
36174
36175 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
36176@@ -1547,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
36177 * we check the new geometry. Then turn interrupts back on when
36178 * we're done.
36179 */
36180- host->access.set_intr_mask(host, 0);
36181+ host->access->set_intr_mask(host, 0);
36182 getgeometry(ctlr);
36183- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
36184+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
36185
36186 for(i=0; i<NWD; i++) {
36187 struct gendisk *disk = ida_gendisk[ctlr][i];
36188@@ -1589,7 +1590,7 @@ static int pollcomplete(int ctlr)
36189 /* Wait (up to 2 seconds) for a command to complete */
36190
36191 for (i = 200000; i > 0; i--) {
36192- done = hba[ctlr]->access.command_completed(hba[ctlr]);
36193+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
36194 if (done == 0) {
36195 udelay(10); /* a short fixed delay */
36196 } else
36197diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
36198index be73e9d..7fbf140 100644
36199--- a/drivers/block/cpqarray.h
36200+++ b/drivers/block/cpqarray.h
36201@@ -99,7 +99,7 @@ struct ctlr_info {
36202 drv_info_t drv[NWD];
36203 struct proc_dir_entry *proc;
36204
36205- struct access_method access;
36206+ struct access_method *access;
36207
36208 cmdlist_t *reqQ;
36209 cmdlist_t *cmpQ;
36210diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
36211index 2d7f608..11245fe 100644
36212--- a/drivers/block/drbd/drbd_int.h
36213+++ b/drivers/block/drbd/drbd_int.h
36214@@ -582,7 +582,7 @@ struct drbd_epoch {
36215 struct drbd_tconn *tconn;
36216 struct list_head list;
36217 unsigned int barrier_nr;
36218- atomic_t epoch_size; /* increased on every request added. */
36219+ atomic_unchecked_t epoch_size; /* increased on every request added. */
36220 atomic_t active; /* increased on every req. added, and dec on every finished. */
36221 unsigned long flags;
36222 };
36223@@ -1022,7 +1022,7 @@ struct drbd_conf {
36224 unsigned int al_tr_number;
36225 int al_tr_cycle;
36226 wait_queue_head_t seq_wait;
36227- atomic_t packet_seq;
36228+ atomic_unchecked_t packet_seq;
36229 unsigned int peer_seq;
36230 spinlock_t peer_seq_lock;
36231 unsigned int minor;
36232@@ -1572,7 +1572,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
36233 char __user *uoptval;
36234 int err;
36235
36236- uoptval = (char __user __force *)optval;
36237+ uoptval = (char __force_user *)optval;
36238
36239 set_fs(KERNEL_DS);
36240 if (level == SOL_SOCKET)
36241diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
36242index 55635ed..40e837c 100644
36243--- a/drivers/block/drbd/drbd_main.c
36244+++ b/drivers/block/drbd/drbd_main.c
36245@@ -1317,7 +1317,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packet cmd,
36246 p->sector = sector;
36247 p->block_id = block_id;
36248 p->blksize = blksize;
36249- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
36250+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
36251 return drbd_send_command(mdev, sock, cmd, sizeof(*p), NULL, 0);
36252 }
36253
36254@@ -1619,7 +1619,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
36255 return -EIO;
36256 p->sector = cpu_to_be64(req->i.sector);
36257 p->block_id = (unsigned long)req;
36258- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
36259+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
36260 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
36261 if (mdev->state.conn >= C_SYNC_SOURCE &&
36262 mdev->state.conn <= C_PAUSED_SYNC_T)
36263@@ -2574,8 +2574,8 @@ void conn_destroy(struct kref *kref)
36264 {
36265 struct drbd_tconn *tconn = container_of(kref, struct drbd_tconn, kref);
36266
36267- if (atomic_read(&tconn->current_epoch->epoch_size) != 0)
36268- conn_err(tconn, "epoch_size:%d\n", atomic_read(&tconn->current_epoch->epoch_size));
36269+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size) != 0)
36270+ conn_err(tconn, "epoch_size:%d\n", atomic_read_unchecked(&tconn->current_epoch->epoch_size));
36271 kfree(tconn->current_epoch);
36272
36273 idr_destroy(&tconn->volumes);
36274diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
36275index 8cc1e64..ba7ffa9 100644
36276--- a/drivers/block/drbd/drbd_nl.c
36277+++ b/drivers/block/drbd/drbd_nl.c
36278@@ -3440,7 +3440,7 @@ out:
36279
36280 void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
36281 {
36282- static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
36283+ static atomic_unchecked_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
36284 struct sk_buff *msg;
36285 struct drbd_genlmsghdr *d_out;
36286 unsigned seq;
36287@@ -3453,7 +3453,7 @@ void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
36288 return;
36289 }
36290
36291- seq = atomic_inc_return(&drbd_genl_seq);
36292+ seq = atomic_inc_return_unchecked(&drbd_genl_seq);
36293 msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
36294 if (!msg)
36295 goto failed;
36296diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
36297index cc29cd3..d4b058b 100644
36298--- a/drivers/block/drbd/drbd_receiver.c
36299+++ b/drivers/block/drbd/drbd_receiver.c
36300@@ -834,7 +834,7 @@ int drbd_connected(struct drbd_conf *mdev)
36301 {
36302 int err;
36303
36304- atomic_set(&mdev->packet_seq, 0);
36305+ atomic_set_unchecked(&mdev->packet_seq, 0);
36306 mdev->peer_seq = 0;
36307
36308 mdev->state_mutex = mdev->tconn->agreed_pro_version < 100 ?
36309@@ -1193,7 +1193,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
36310 do {
36311 next_epoch = NULL;
36312
36313- epoch_size = atomic_read(&epoch->epoch_size);
36314+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
36315
36316 switch (ev & ~EV_CLEANUP) {
36317 case EV_PUT:
36318@@ -1233,7 +1233,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
36319 rv = FE_DESTROYED;
36320 } else {
36321 epoch->flags = 0;
36322- atomic_set(&epoch->epoch_size, 0);
36323+ atomic_set_unchecked(&epoch->epoch_size, 0);
36324 /* atomic_set(&epoch->active, 0); is already zero */
36325 if (rv == FE_STILL_LIVE)
36326 rv = FE_RECYCLED;
36327@@ -1451,7 +1451,7 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
36328 conn_wait_active_ee_empty(tconn);
36329 drbd_flush(tconn);
36330
36331- if (atomic_read(&tconn->current_epoch->epoch_size)) {
36332+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
36333 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
36334 if (epoch)
36335 break;
36336@@ -1464,11 +1464,11 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
36337 }
36338
36339 epoch->flags = 0;
36340- atomic_set(&epoch->epoch_size, 0);
36341+ atomic_set_unchecked(&epoch->epoch_size, 0);
36342 atomic_set(&epoch->active, 0);
36343
36344 spin_lock(&tconn->epoch_lock);
36345- if (atomic_read(&tconn->current_epoch->epoch_size)) {
36346+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
36347 list_add(&epoch->list, &tconn->current_epoch->list);
36348 tconn->current_epoch = epoch;
36349 tconn->epochs++;
36350@@ -2172,7 +2172,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
36351
36352 err = wait_for_and_update_peer_seq(mdev, peer_seq);
36353 drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size);
36354- atomic_inc(&tconn->current_epoch->epoch_size);
36355+ atomic_inc_unchecked(&tconn->current_epoch->epoch_size);
36356 err2 = drbd_drain_block(mdev, pi->size);
36357 if (!err)
36358 err = err2;
36359@@ -2206,7 +2206,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
36360
36361 spin_lock(&tconn->epoch_lock);
36362 peer_req->epoch = tconn->current_epoch;
36363- atomic_inc(&peer_req->epoch->epoch_size);
36364+ atomic_inc_unchecked(&peer_req->epoch->epoch_size);
36365 atomic_inc(&peer_req->epoch->active);
36366 spin_unlock(&tconn->epoch_lock);
36367
36368@@ -4347,7 +4347,7 @@ struct data_cmd {
36369 int expect_payload;
36370 size_t pkt_size;
36371 int (*fn)(struct drbd_tconn *, struct packet_info *);
36372-};
36373+} __do_const;
36374
36375 static struct data_cmd drbd_cmd_handler[] = {
36376 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
36377@@ -4467,7 +4467,7 @@ static void conn_disconnect(struct drbd_tconn *tconn)
36378 if (!list_empty(&tconn->current_epoch->list))
36379 conn_err(tconn, "ASSERTION FAILED: tconn->current_epoch->list not empty\n");
36380 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
36381- atomic_set(&tconn->current_epoch->epoch_size, 0);
36382+ atomic_set_unchecked(&tconn->current_epoch->epoch_size, 0);
36383 tconn->send.seen_any_write_yet = false;
36384
36385 conn_info(tconn, "Connection closed\n");
36386@@ -5223,7 +5223,7 @@ static int tconn_finish_peer_reqs(struct drbd_tconn *tconn)
36387 struct asender_cmd {
36388 size_t pkt_size;
36389 int (*fn)(struct drbd_tconn *tconn, struct packet_info *);
36390-};
36391+} __do_const;
36392
36393 static struct asender_cmd asender_tbl[] = {
36394 [P_PING] = { 0, got_Ping },
36395diff --git a/drivers/block/loop.c b/drivers/block/loop.c
36396index 40e7155..df5c79a 100644
36397--- a/drivers/block/loop.c
36398+++ b/drivers/block/loop.c
36399@@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
36400
36401 file_start_write(file);
36402 set_fs(get_ds());
36403- bw = file->f_op->write(file, buf, len, &pos);
36404+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
36405 set_fs(old_fs);
36406 file_end_write(file);
36407 if (likely(bw == len))
36408diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
36409index f5d0ea1..c62380a 100644
36410--- a/drivers/block/pktcdvd.c
36411+++ b/drivers/block/pktcdvd.c
36412@@ -84,7 +84,7 @@
36413 #define MAX_SPEED 0xffff
36414
36415 #define ZONE(sector, pd) (((sector) + (pd)->offset) & \
36416- ~(sector_t)((pd)->settings.size - 1))
36417+ ~(sector_t)((pd)->settings.size - 1UL))
36418
36419 static DEFINE_MUTEX(pktcdvd_mutex);
36420 static struct pktcdvd_device *pkt_devs[MAX_WRITERS];
36421diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
36422index 8a3aff7..d7538c2 100644
36423--- a/drivers/cdrom/cdrom.c
36424+++ b/drivers/cdrom/cdrom.c
36425@@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
36426 ENSURE(reset, CDC_RESET);
36427 ENSURE(generic_packet, CDC_GENERIC_PACKET);
36428 cdi->mc_flags = 0;
36429- cdo->n_minors = 0;
36430 cdi->options = CDO_USE_FFLAGS;
36431
36432 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
36433@@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
36434 else
36435 cdi->cdda_method = CDDA_OLD;
36436
36437- if (!cdo->generic_packet)
36438- cdo->generic_packet = cdrom_dummy_generic_packet;
36439+ if (!cdo->generic_packet) {
36440+ pax_open_kernel();
36441+ *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
36442+ pax_close_kernel();
36443+ }
36444
36445 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
36446 mutex_lock(&cdrom_mutex);
36447@@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
36448 if (cdi->exit)
36449 cdi->exit(cdi);
36450
36451- cdi->ops->n_minors--;
36452 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
36453 }
36454
36455@@ -2107,7 +2108,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
36456 */
36457 nr = nframes;
36458 do {
36459- cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
36460+ cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
36461 if (cgc.buffer)
36462 break;
36463
36464@@ -3429,7 +3430,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
36465 struct cdrom_device_info *cdi;
36466 int ret;
36467
36468- ret = scnprintf(info + *pos, max_size - *pos, header);
36469+ ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
36470 if (!ret)
36471 return 1;
36472
36473diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
36474index 5980cb9..6d7bd7e 100644
36475--- a/drivers/cdrom/gdrom.c
36476+++ b/drivers/cdrom/gdrom.c
36477@@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
36478 .audio_ioctl = gdrom_audio_ioctl,
36479 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
36480 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
36481- .n_minors = 1,
36482 };
36483
36484 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
36485diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
36486index 1421997..33f5d6d 100644
36487--- a/drivers/char/Kconfig
36488+++ b/drivers/char/Kconfig
36489@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
36490
36491 config DEVKMEM
36492 bool "/dev/kmem virtual device support"
36493- default y
36494+ default n
36495+ depends on !GRKERNSEC_KMEM
36496 help
36497 Say Y here if you want to support the /dev/kmem device. The
36498 /dev/kmem device is rarely used, but can be used for certain
36499@@ -570,6 +571,7 @@ config DEVPORT
36500 bool
36501 depends on !M68K
36502 depends on ISA || PCI
36503+ depends on !GRKERNSEC_KMEM
36504 default y
36505
36506 source "drivers/s390/char/Kconfig"
36507diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
36508index a48e05b..6bac831 100644
36509--- a/drivers/char/agp/compat_ioctl.c
36510+++ b/drivers/char/agp/compat_ioctl.c
36511@@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
36512 return -ENOMEM;
36513 }
36514
36515- if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
36516+ if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
36517 sizeof(*usegment) * ureserve.seg_count)) {
36518 kfree(usegment);
36519 kfree(ksegment);
36520diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
36521index 1b19239..b87b143 100644
36522--- a/drivers/char/agp/frontend.c
36523+++ b/drivers/char/agp/frontend.c
36524@@ -819,7 +819,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
36525 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
36526 return -EFAULT;
36527
36528- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
36529+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
36530 return -EFAULT;
36531
36532 client = agp_find_client_by_pid(reserve.pid);
36533@@ -849,7 +849,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
36534 if (segment == NULL)
36535 return -ENOMEM;
36536
36537- if (copy_from_user(segment, (void __user *) reserve.seg_list,
36538+ if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
36539 sizeof(struct agp_segment) * reserve.seg_count)) {
36540 kfree(segment);
36541 return -EFAULT;
36542diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
36543index 4f94375..413694e 100644
36544--- a/drivers/char/genrtc.c
36545+++ b/drivers/char/genrtc.c
36546@@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
36547 switch (cmd) {
36548
36549 case RTC_PLL_GET:
36550+ memset(&pll, 0, sizeof(pll));
36551 if (get_rtc_pll(&pll))
36552 return -EINVAL;
36553 else
36554diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
36555index 448ce5e..3a76625 100644
36556--- a/drivers/char/hpet.c
36557+++ b/drivers/char/hpet.c
36558@@ -559,7 +559,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
36559 }
36560
36561 static int
36562-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
36563+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
36564 struct hpet_info *info)
36565 {
36566 struct hpet_timer __iomem *timer;
36567diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
36568index 86fe45c..c0ea948 100644
36569--- a/drivers/char/hw_random/intel-rng.c
36570+++ b/drivers/char/hw_random/intel-rng.c
36571@@ -314,7 +314,7 @@ PFX "RNG, try using the 'no_fwh_detect' option.\n";
36572
36573 if (no_fwh_detect)
36574 return -ENODEV;
36575- printk(warning);
36576+ printk("%s", warning);
36577 return -EBUSY;
36578 }
36579
36580diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
36581index 4445fa1..7c6de37 100644
36582--- a/drivers/char/ipmi/ipmi_msghandler.c
36583+++ b/drivers/char/ipmi/ipmi_msghandler.c
36584@@ -420,7 +420,7 @@ struct ipmi_smi {
36585 struct proc_dir_entry *proc_dir;
36586 char proc_dir_name[10];
36587
36588- atomic_t stats[IPMI_NUM_STATS];
36589+ atomic_unchecked_t stats[IPMI_NUM_STATS];
36590
36591 /*
36592 * run_to_completion duplicate of smb_info, smi_info
36593@@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
36594
36595
36596 #define ipmi_inc_stat(intf, stat) \
36597- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
36598+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
36599 #define ipmi_get_stat(intf, stat) \
36600- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
36601+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
36602
36603 static int is_lan_addr(struct ipmi_addr *addr)
36604 {
36605@@ -2883,7 +2883,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
36606 INIT_LIST_HEAD(&intf->cmd_rcvrs);
36607 init_waitqueue_head(&intf->waitq);
36608 for (i = 0; i < IPMI_NUM_STATS; i++)
36609- atomic_set(&intf->stats[i], 0);
36610+ atomic_set_unchecked(&intf->stats[i], 0);
36611
36612 intf->proc_dir = NULL;
36613
36614diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
36615index af4b23f..79806fc 100644
36616--- a/drivers/char/ipmi/ipmi_si_intf.c
36617+++ b/drivers/char/ipmi/ipmi_si_intf.c
36618@@ -275,7 +275,7 @@ struct smi_info {
36619 unsigned char slave_addr;
36620
36621 /* Counters and things for the proc filesystem. */
36622- atomic_t stats[SI_NUM_STATS];
36623+ atomic_unchecked_t stats[SI_NUM_STATS];
36624
36625 struct task_struct *thread;
36626
36627@@ -284,9 +284,9 @@ struct smi_info {
36628 };
36629
36630 #define smi_inc_stat(smi, stat) \
36631- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
36632+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
36633 #define smi_get_stat(smi, stat) \
36634- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
36635+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
36636
36637 #define SI_MAX_PARMS 4
36638
36639@@ -3258,7 +3258,7 @@ static int try_smi_init(struct smi_info *new_smi)
36640 atomic_set(&new_smi->req_events, 0);
36641 new_smi->run_to_completion = 0;
36642 for (i = 0; i < SI_NUM_STATS; i++)
36643- atomic_set(&new_smi->stats[i], 0);
36644+ atomic_set_unchecked(&new_smi->stats[i], 0);
36645
36646 new_smi->interrupt_disabled = 1;
36647 atomic_set(&new_smi->stop_operation, 0);
36648diff --git a/drivers/char/mem.c b/drivers/char/mem.c
36649index f895a8c..2bc9147 100644
36650--- a/drivers/char/mem.c
36651+++ b/drivers/char/mem.c
36652@@ -18,6 +18,7 @@
36653 #include <linux/raw.h>
36654 #include <linux/tty.h>
36655 #include <linux/capability.h>
36656+#include <linux/security.h>
36657 #include <linux/ptrace.h>
36658 #include <linux/device.h>
36659 #include <linux/highmem.h>
36660@@ -37,6 +38,10 @@
36661
36662 #define DEVPORT_MINOR 4
36663
36664+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
36665+extern const struct file_operations grsec_fops;
36666+#endif
36667+
36668 static inline unsigned long size_inside_page(unsigned long start,
36669 unsigned long size)
36670 {
36671@@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
36672
36673 while (cursor < to) {
36674 if (!devmem_is_allowed(pfn)) {
36675+#ifdef CONFIG_GRKERNSEC_KMEM
36676+ gr_handle_mem_readwrite(from, to);
36677+#else
36678 printk(KERN_INFO
36679 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
36680 current->comm, from, to);
36681+#endif
36682 return 0;
36683 }
36684 cursor += PAGE_SIZE;
36685@@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
36686 }
36687 return 1;
36688 }
36689+#elif defined(CONFIG_GRKERNSEC_KMEM)
36690+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
36691+{
36692+ return 0;
36693+}
36694 #else
36695 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
36696 {
36697@@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
36698
36699 while (count > 0) {
36700 unsigned long remaining;
36701+ char *temp;
36702
36703 sz = size_inside_page(p, count);
36704
36705@@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
36706 if (!ptr)
36707 return -EFAULT;
36708
36709- remaining = copy_to_user(buf, ptr, sz);
36710+#ifdef CONFIG_PAX_USERCOPY
36711+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
36712+ if (!temp) {
36713+ unxlate_dev_mem_ptr(p, ptr);
36714+ return -ENOMEM;
36715+ }
36716+ memcpy(temp, ptr, sz);
36717+#else
36718+ temp = ptr;
36719+#endif
36720+
36721+ remaining = copy_to_user(buf, temp, sz);
36722+
36723+#ifdef CONFIG_PAX_USERCOPY
36724+ kfree(temp);
36725+#endif
36726+
36727 unxlate_dev_mem_ptr(p, ptr);
36728 if (remaining)
36729 return -EFAULT;
36730@@ -364,9 +395,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
36731 size_t count, loff_t *ppos)
36732 {
36733 unsigned long p = *ppos;
36734- ssize_t low_count, read, sz;
36735+ ssize_t low_count, read, sz, err = 0;
36736 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
36737- int err = 0;
36738
36739 read = 0;
36740 if (p < (unsigned long) high_memory) {
36741@@ -388,6 +418,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
36742 }
36743 #endif
36744 while (low_count > 0) {
36745+ char *temp;
36746+
36747 sz = size_inside_page(p, low_count);
36748
36749 /*
36750@@ -397,7 +429,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
36751 */
36752 kbuf = xlate_dev_kmem_ptr((char *)p);
36753
36754- if (copy_to_user(buf, kbuf, sz))
36755+#ifdef CONFIG_PAX_USERCOPY
36756+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
36757+ if (!temp)
36758+ return -ENOMEM;
36759+ memcpy(temp, kbuf, sz);
36760+#else
36761+ temp = kbuf;
36762+#endif
36763+
36764+ err = copy_to_user(buf, temp, sz);
36765+
36766+#ifdef CONFIG_PAX_USERCOPY
36767+ kfree(temp);
36768+#endif
36769+
36770+ if (err)
36771 return -EFAULT;
36772 buf += sz;
36773 p += sz;
36774@@ -822,6 +869,9 @@ static const struct memdev {
36775 #ifdef CONFIG_PRINTK
36776 [11] = { "kmsg", 0644, &kmsg_fops, NULL },
36777 #endif
36778+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
36779+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
36780+#endif
36781 };
36782
36783 static int memory_open(struct inode *inode, struct file *filp)
36784@@ -893,7 +943,7 @@ static int __init chr_dev_init(void)
36785 continue;
36786
36787 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
36788- NULL, devlist[minor].name);
36789+ NULL, "%s", devlist[minor].name);
36790 }
36791
36792 return tty_init();
36793diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
36794index 9df78e2..01ba9ae 100644
36795--- a/drivers/char/nvram.c
36796+++ b/drivers/char/nvram.c
36797@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
36798
36799 spin_unlock_irq(&rtc_lock);
36800
36801- if (copy_to_user(buf, contents, tmp - contents))
36802+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
36803 return -EFAULT;
36804
36805 *ppos = i;
36806diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
36807index 5c5cc00..ac9edb7 100644
36808--- a/drivers/char/pcmcia/synclink_cs.c
36809+++ b/drivers/char/pcmcia/synclink_cs.c
36810@@ -2345,9 +2345,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
36811
36812 if (debug_level >= DEBUG_LEVEL_INFO)
36813 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
36814- __FILE__, __LINE__, info->device_name, port->count);
36815+ __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
36816
36817- WARN_ON(!port->count);
36818+ WARN_ON(!atomic_read(&port->count));
36819
36820 if (tty_port_close_start(port, tty, filp) == 0)
36821 goto cleanup;
36822@@ -2365,7 +2365,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
36823 cleanup:
36824 if (debug_level >= DEBUG_LEVEL_INFO)
36825 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
36826- tty->driver->name, port->count);
36827+ tty->driver->name, atomic_read(&port->count));
36828 }
36829
36830 /* Wait until the transmitter is empty.
36831@@ -2507,7 +2507,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
36832
36833 if (debug_level >= DEBUG_LEVEL_INFO)
36834 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
36835- __FILE__, __LINE__, tty->driver->name, port->count);
36836+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
36837
36838 /* If port is closing, signal caller to try again */
36839 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
36840@@ -2527,11 +2527,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
36841 goto cleanup;
36842 }
36843 spin_lock(&port->lock);
36844- port->count++;
36845+ atomic_inc(&port->count);
36846 spin_unlock(&port->lock);
36847 spin_unlock_irqrestore(&info->netlock, flags);
36848
36849- if (port->count == 1) {
36850+ if (atomic_read(&port->count) == 1) {
36851 /* 1st open on this device, init hardware */
36852 retval = startup(info, tty);
36853 if (retval < 0)
36854@@ -3920,7 +3920,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
36855 unsigned short new_crctype;
36856
36857 /* return error if TTY interface open */
36858- if (info->port.count)
36859+ if (atomic_read(&info->port.count))
36860 return -EBUSY;
36861
36862 switch (encoding)
36863@@ -4024,7 +4024,7 @@ static int hdlcdev_open(struct net_device *dev)
36864
36865 /* arbitrate between network and tty opens */
36866 spin_lock_irqsave(&info->netlock, flags);
36867- if (info->port.count != 0 || info->netcount != 0) {
36868+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
36869 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
36870 spin_unlock_irqrestore(&info->netlock, flags);
36871 return -EBUSY;
36872@@ -4114,7 +4114,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
36873 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
36874
36875 /* return error if TTY interface open */
36876- if (info->port.count)
36877+ if (atomic_read(&info->port.count))
36878 return -EBUSY;
36879
36880 if (cmd != SIOCWANDEV)
36881diff --git a/drivers/char/random.c b/drivers/char/random.c
36882index 0d91fe5..f8e37b0 100644
36883--- a/drivers/char/random.c
36884+++ b/drivers/char/random.c
36885@@ -272,8 +272,13 @@
36886 /*
36887 * Configuration information
36888 */
36889+#ifdef CONFIG_GRKERNSEC_RANDNET
36890+#define INPUT_POOL_WORDS 512
36891+#define OUTPUT_POOL_WORDS 128
36892+#else
36893 #define INPUT_POOL_WORDS 128
36894 #define OUTPUT_POOL_WORDS 32
36895+#endif
36896 #define SEC_XFER_SIZE 512
36897 #define EXTRACT_SIZE 10
36898
36899@@ -313,10 +318,17 @@ static struct poolinfo {
36900 int poolwords;
36901 int tap1, tap2, tap3, tap4, tap5;
36902 } poolinfo_table[] = {
36903+#ifdef CONFIG_GRKERNSEC_RANDNET
36904+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
36905+ { 512, 411, 308, 208, 104, 1 },
36906+ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
36907+ { 128, 103, 76, 51, 25, 1 },
36908+#else
36909 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
36910 { 128, 103, 76, 51, 25, 1 },
36911 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
36912 { 32, 26, 20, 14, 7, 1 },
36913+#endif
36914 #if 0
36915 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
36916 { 2048, 1638, 1231, 819, 411, 1 },
36917@@ -524,8 +536,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
36918 input_rotate += i ? 7 : 14;
36919 }
36920
36921- ACCESS_ONCE(r->input_rotate) = input_rotate;
36922- ACCESS_ONCE(r->add_ptr) = i;
36923+ ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
36924+ ACCESS_ONCE_RW(r->add_ptr) = i;
36925 smp_wmb();
36926
36927 if (out)
36928@@ -1032,7 +1044,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
36929
36930 extract_buf(r, tmp);
36931 i = min_t(int, nbytes, EXTRACT_SIZE);
36932- if (copy_to_user(buf, tmp, i)) {
36933+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
36934 ret = -EFAULT;
36935 break;
36936 }
36937@@ -1368,7 +1380,7 @@ EXPORT_SYMBOL(generate_random_uuid);
36938 #include <linux/sysctl.h>
36939
36940 static int min_read_thresh = 8, min_write_thresh;
36941-static int max_read_thresh = INPUT_POOL_WORDS * 32;
36942+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
36943 static int max_write_thresh = INPUT_POOL_WORDS * 32;
36944 static char sysctl_bootid[16];
36945
36946@@ -1384,7 +1396,7 @@ static char sysctl_bootid[16];
36947 static int proc_do_uuid(struct ctl_table *table, int write,
36948 void __user *buffer, size_t *lenp, loff_t *ppos)
36949 {
36950- struct ctl_table fake_table;
36951+ ctl_table_no_const fake_table;
36952 unsigned char buf[64], tmp_uuid[16], *uuid;
36953
36954 uuid = table->data;
36955diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
36956index bf2349db..5456d53 100644
36957--- a/drivers/char/sonypi.c
36958+++ b/drivers/char/sonypi.c
36959@@ -54,6 +54,7 @@
36960
36961 #include <asm/uaccess.h>
36962 #include <asm/io.h>
36963+#include <asm/local.h>
36964
36965 #include <linux/sonypi.h>
36966
36967@@ -490,7 +491,7 @@ static struct sonypi_device {
36968 spinlock_t fifo_lock;
36969 wait_queue_head_t fifo_proc_list;
36970 struct fasync_struct *fifo_async;
36971- int open_count;
36972+ local_t open_count;
36973 int model;
36974 struct input_dev *input_jog_dev;
36975 struct input_dev *input_key_dev;
36976@@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
36977 static int sonypi_misc_release(struct inode *inode, struct file *file)
36978 {
36979 mutex_lock(&sonypi_device.lock);
36980- sonypi_device.open_count--;
36981+ local_dec(&sonypi_device.open_count);
36982 mutex_unlock(&sonypi_device.lock);
36983 return 0;
36984 }
36985@@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
36986 {
36987 mutex_lock(&sonypi_device.lock);
36988 /* Flush input queue on first open */
36989- if (!sonypi_device.open_count)
36990+ if (!local_read(&sonypi_device.open_count))
36991 kfifo_reset(&sonypi_device.fifo);
36992- sonypi_device.open_count++;
36993+ local_inc(&sonypi_device.open_count);
36994 mutex_unlock(&sonypi_device.lock);
36995
36996 return 0;
36997diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
36998index 64420b3..5c40b56 100644
36999--- a/drivers/char/tpm/tpm_acpi.c
37000+++ b/drivers/char/tpm/tpm_acpi.c
37001@@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
37002 virt = acpi_os_map_memory(start, len);
37003 if (!virt) {
37004 kfree(log->bios_event_log);
37005+ log->bios_event_log = NULL;
37006 printk("%s: ERROR - Unable to map memory\n", __func__);
37007 return -EIO;
37008 }
37009
37010- memcpy_fromio(log->bios_event_log, virt, len);
37011+ memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
37012
37013 acpi_os_unmap_memory(virt, len);
37014 return 0;
37015diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
37016index 84ddc55..1d32f1e 100644
37017--- a/drivers/char/tpm/tpm_eventlog.c
37018+++ b/drivers/char/tpm/tpm_eventlog.c
37019@@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
37020 event = addr;
37021
37022 if ((event->event_type == 0 && event->event_size == 0) ||
37023- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
37024+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
37025 return NULL;
37026
37027 return addr;
37028@@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
37029 return NULL;
37030
37031 if ((event->event_type == 0 && event->event_size == 0) ||
37032- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
37033+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
37034 return NULL;
37035
37036 (*pos)++;
37037@@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
37038 int i;
37039
37040 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
37041- seq_putc(m, data[i]);
37042+ if (!seq_putc(m, data[i]))
37043+ return -EFAULT;
37044
37045 return 0;
37046 }
37047diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
37048index fc45567..fa2a590 100644
37049--- a/drivers/char/virtio_console.c
37050+++ b/drivers/char/virtio_console.c
37051@@ -682,7 +682,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
37052 if (to_user) {
37053 ssize_t ret;
37054
37055- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
37056+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
37057 if (ret)
37058 return -EFAULT;
37059 } else {
37060@@ -785,7 +785,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
37061 if (!port_has_data(port) && !port->host_connected)
37062 return 0;
37063
37064- return fill_readbuf(port, ubuf, count, true);
37065+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
37066 }
37067
37068 static int wait_port_writable(struct port *port, bool nonblock)
37069diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
37070index a33f46f..a720eed 100644
37071--- a/drivers/clk/clk-composite.c
37072+++ b/drivers/clk/clk-composite.c
37073@@ -122,7 +122,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
37074 struct clk *clk;
37075 struct clk_init_data init;
37076 struct clk_composite *composite;
37077- struct clk_ops *clk_composite_ops;
37078+ clk_ops_no_const *clk_composite_ops;
37079
37080 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
37081 if (!composite) {
37082diff --git a/drivers/clk/socfpga/clk.c b/drivers/clk/socfpga/clk.c
37083index 5bb848c..f00ff83 100644
37084--- a/drivers/clk/socfpga/clk.c
37085+++ b/drivers/clk/socfpga/clk.c
37086@@ -22,6 +22,7 @@
37087 #include <linux/clk-provider.h>
37088 #include <linux/io.h>
37089 #include <linux/of.h>
37090+#include <asm/pgtable.h>
37091
37092 /* Clock Manager offsets */
37093 #define CLKMGR_CTRL 0x0
37094@@ -152,8 +153,10 @@ static __init struct clk *socfpga_clk_init(struct device_node *node,
37095 streq(clk_name, "periph_pll") ||
37096 streq(clk_name, "sdram_pll")) {
37097 socfpga_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
37098- clk_pll_ops.enable = clk_gate_ops.enable;
37099- clk_pll_ops.disable = clk_gate_ops.disable;
37100+ pax_open_kernel();
37101+ *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
37102+ *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
37103+ pax_close_kernel();
37104 }
37105
37106 clk = clk_register(NULL, &socfpga_clk->hw.hw);
37107diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
37108index 3926402..37b580d 100644
37109--- a/drivers/cpufreq/acpi-cpufreq.c
37110+++ b/drivers/cpufreq/acpi-cpufreq.c
37111@@ -173,7 +173,7 @@ static ssize_t show_global_boost(struct kobject *kobj,
37112 return sprintf(buf, "%u\n", boost_enabled);
37113 }
37114
37115-static struct global_attr global_boost = __ATTR(boost, 0644,
37116+static global_attr_no_const global_boost = __ATTR(boost, 0644,
37117 show_global_boost,
37118 store_global_boost);
37119
37120@@ -722,8 +722,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
37121 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
37122 per_cpu(acfreq_data, cpu) = data;
37123
37124- if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
37125- acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
37126+ if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
37127+ pax_open_kernel();
37128+ *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
37129+ pax_close_kernel();
37130+ }
37131
37132 result = acpi_processor_register_performance(data->acpi_data, cpu);
37133 if (result)
37134@@ -851,7 +854,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
37135 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
37136 break;
37137 case ACPI_ADR_SPACE_FIXED_HARDWARE:
37138- acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
37139+ pax_open_kernel();
37140+ *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
37141+ pax_close_kernel();
37142 policy->cur = get_cur_freq_on_cpu(cpu);
37143 break;
37144 default:
37145@@ -862,8 +867,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
37146 acpi_processor_notify_smm(THIS_MODULE);
37147
37148 /* Check for APERF/MPERF support in hardware */
37149- if (boot_cpu_has(X86_FEATURE_APERFMPERF))
37150- acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf;
37151+ if (boot_cpu_has(X86_FEATURE_APERFMPERF)) {
37152+ pax_open_kernel();
37153+ *(void **)&acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf;
37154+ pax_close_kernel();
37155+ }
37156
37157 pr_debug("CPU%u - ACPI performance management activated.\n", cpu);
37158 for (i = 0; i < perf->state_count; i++)
37159diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
37160index f0a5e2b..0a7ee46 100644
37161--- a/drivers/cpufreq/cpufreq.c
37162+++ b/drivers/cpufreq/cpufreq.c
37163@@ -1959,7 +1959,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
37164 return NOTIFY_OK;
37165 }
37166
37167-static struct notifier_block __refdata cpufreq_cpu_notifier = {
37168+static struct notifier_block cpufreq_cpu_notifier = {
37169 .notifier_call = cpufreq_cpu_callback,
37170 };
37171
37172@@ -1991,8 +1991,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
37173
37174 pr_debug("trying to register driver %s\n", driver_data->name);
37175
37176- if (driver_data->setpolicy)
37177- driver_data->flags |= CPUFREQ_CONST_LOOPS;
37178+ if (driver_data->setpolicy) {
37179+ pax_open_kernel();
37180+ *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
37181+ pax_close_kernel();
37182+ }
37183
37184 write_lock_irqsave(&cpufreq_driver_lock, flags);
37185 if (cpufreq_driver) {
37186diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
37187index e59afaa..a53a3ff 100644
37188--- a/drivers/cpufreq/cpufreq_governor.c
37189+++ b/drivers/cpufreq/cpufreq_governor.c
37190@@ -191,7 +191,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
37191 struct dbs_data *dbs_data;
37192 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
37193 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
37194- struct od_ops *od_ops = NULL;
37195+ const struct od_ops *od_ops = NULL;
37196 struct od_dbs_tuners *od_tuners = NULL;
37197 struct cs_dbs_tuners *cs_tuners = NULL;
37198 struct cpu_dbs_common_info *cpu_cdbs;
37199@@ -257,7 +257,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
37200
37201 if ((cdata->governor == GOV_CONSERVATIVE) &&
37202 (!policy->governor->initialized)) {
37203- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
37204+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
37205
37206 cpufreq_register_notifier(cs_ops->notifier_block,
37207 CPUFREQ_TRANSITION_NOTIFIER);
37208@@ -277,7 +277,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
37209
37210 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
37211 (policy->governor->initialized == 1)) {
37212- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
37213+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
37214
37215 cpufreq_unregister_notifier(cs_ops->notifier_block,
37216 CPUFREQ_TRANSITION_NOTIFIER);
37217diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
37218index d5f12b4..eb30af1 100644
37219--- a/drivers/cpufreq/cpufreq_governor.h
37220+++ b/drivers/cpufreq/cpufreq_governor.h
37221@@ -204,7 +204,7 @@ struct common_dbs_data {
37222 void (*exit)(struct dbs_data *dbs_data);
37223
37224 /* Governor specific ops, see below */
37225- void *gov_ops;
37226+ const void *gov_ops;
37227 };
37228
37229 /* Governer Per policy data */
37230@@ -224,7 +224,7 @@ struct od_ops {
37231 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
37232 unsigned int freq_next, unsigned int relation);
37233 void (*freq_increase)(struct cpufreq_policy *p, unsigned int freq);
37234-};
37235+} __no_const;
37236
37237 struct cs_ops {
37238 struct notifier_block *notifier_block;
37239diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
37240index c087347..989aa2e 100644
37241--- a/drivers/cpufreq/cpufreq_ondemand.c
37242+++ b/drivers/cpufreq/cpufreq_ondemand.c
37243@@ -560,7 +560,7 @@ static void od_exit(struct dbs_data *dbs_data)
37244
37245 define_get_cpu_dbs_routines(od_cpu_dbs_info);
37246
37247-static struct od_ops od_ops = {
37248+static struct od_ops od_ops __read_only = {
37249 .powersave_bias_init_cpu = ondemand_powersave_bias_init_cpu,
37250 .powersave_bias_target = generic_powersave_bias_target,
37251 .freq_increase = dbs_freq_increase,
37252@@ -615,14 +615,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
37253 (struct cpufreq_policy *, unsigned int, unsigned int),
37254 unsigned int powersave_bias)
37255 {
37256- od_ops.powersave_bias_target = f;
37257+ pax_open_kernel();
37258+ *(void **)&od_ops.powersave_bias_target = f;
37259+ pax_close_kernel();
37260 od_set_powersave_bias(powersave_bias);
37261 }
37262 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
37263
37264 void od_unregister_powersave_bias_handler(void)
37265 {
37266- od_ops.powersave_bias_target = generic_powersave_bias_target;
37267+ pax_open_kernel();
37268+ *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
37269+ pax_close_kernel();
37270 od_set_powersave_bias(0);
37271 }
37272 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
37273diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
37274index d37568c..fbb19a1 100644
37275--- a/drivers/cpufreq/cpufreq_stats.c
37276+++ b/drivers/cpufreq/cpufreq_stats.c
37277@@ -365,7 +365,7 @@ static int cpufreq_stat_cpu_callback(struct notifier_block *nfb,
37278 }
37279
37280 /* priority=1 so this will get called before cpufreq_remove_dev */
37281-static struct notifier_block cpufreq_stat_cpu_notifier __refdata = {
37282+static struct notifier_block cpufreq_stat_cpu_notifier = {
37283 .notifier_call = cpufreq_stat_cpu_callback,
37284 .priority = 1,
37285 };
37286diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
37287index 9ee7817..17b658e 100644
37288--- a/drivers/cpufreq/p4-clockmod.c
37289+++ b/drivers/cpufreq/p4-clockmod.c
37290@@ -160,10 +160,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
37291 case 0x0F: /* Core Duo */
37292 case 0x16: /* Celeron Core */
37293 case 0x1C: /* Atom */
37294- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37295+ pax_open_kernel();
37296+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37297+ pax_close_kernel();
37298 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
37299 case 0x0D: /* Pentium M (Dothan) */
37300- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37301+ pax_open_kernel();
37302+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37303+ pax_close_kernel();
37304 /* fall through */
37305 case 0x09: /* Pentium M (Banias) */
37306 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
37307@@ -175,7 +179,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
37308
37309 /* on P-4s, the TSC runs with constant frequency independent whether
37310 * throttling is active or not. */
37311- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37312+ pax_open_kernel();
37313+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37314+ pax_close_kernel();
37315
37316 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
37317 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
37318diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
37319index 880ee29..2445bc6 100644
37320--- a/drivers/cpufreq/sparc-us3-cpufreq.c
37321+++ b/drivers/cpufreq/sparc-us3-cpufreq.c
37322@@ -18,14 +18,12 @@
37323 #include <asm/head.h>
37324 #include <asm/timer.h>
37325
37326-static struct cpufreq_driver *cpufreq_us3_driver;
37327-
37328 struct us3_freq_percpu_info {
37329 struct cpufreq_frequency_table table[4];
37330 };
37331
37332 /* Indexed by cpu number. */
37333-static struct us3_freq_percpu_info *us3_freq_table;
37334+static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
37335
37336 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
37337 * in the Safari config register.
37338@@ -186,12 +184,25 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
37339
37340 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
37341 {
37342- if (cpufreq_us3_driver)
37343- us3_set_cpu_divider_index(policy, 0);
37344+ us3_set_cpu_divider_index(policy->cpu, 0);
37345
37346 return 0;
37347 }
37348
37349+static int __init us3_freq_init(void);
37350+static void __exit us3_freq_exit(void);
37351+
37352+static struct cpufreq_driver cpufreq_us3_driver = {
37353+ .init = us3_freq_cpu_init,
37354+ .verify = us3_freq_verify,
37355+ .target = us3_freq_target,
37356+ .get = us3_freq_get,
37357+ .exit = us3_freq_cpu_exit,
37358+ .owner = THIS_MODULE,
37359+ .name = "UltraSPARC-III",
37360+
37361+};
37362+
37363 static int __init us3_freq_init(void)
37364 {
37365 unsigned long manuf, impl, ver;
37366@@ -208,57 +219,15 @@ static int __init us3_freq_init(void)
37367 (impl == CHEETAH_IMPL ||
37368 impl == CHEETAH_PLUS_IMPL ||
37369 impl == JAGUAR_IMPL ||
37370- impl == PANTHER_IMPL)) {
37371- struct cpufreq_driver *driver;
37372-
37373- ret = -ENOMEM;
37374- driver = kzalloc(sizeof(struct cpufreq_driver), GFP_KERNEL);
37375- if (!driver)
37376- goto err_out;
37377-
37378- us3_freq_table = kzalloc(
37379- (NR_CPUS * sizeof(struct us3_freq_percpu_info)),
37380- GFP_KERNEL);
37381- if (!us3_freq_table)
37382- goto err_out;
37383-
37384- driver->init = us3_freq_cpu_init;
37385- driver->verify = us3_freq_verify;
37386- driver->target = us3_freq_target;
37387- driver->get = us3_freq_get;
37388- driver->exit = us3_freq_cpu_exit;
37389- driver->owner = THIS_MODULE,
37390- strcpy(driver->name, "UltraSPARC-III");
37391-
37392- cpufreq_us3_driver = driver;
37393- ret = cpufreq_register_driver(driver);
37394- if (ret)
37395- goto err_out;
37396-
37397- return 0;
37398-
37399-err_out:
37400- if (driver) {
37401- kfree(driver);
37402- cpufreq_us3_driver = NULL;
37403- }
37404- kfree(us3_freq_table);
37405- us3_freq_table = NULL;
37406- return ret;
37407- }
37408+ impl == PANTHER_IMPL))
37409+ return cpufreq_register_driver(&cpufreq_us3_driver);
37410
37411 return -ENODEV;
37412 }
37413
37414 static void __exit us3_freq_exit(void)
37415 {
37416- if (cpufreq_us3_driver) {
37417- cpufreq_unregister_driver(cpufreq_us3_driver);
37418- kfree(cpufreq_us3_driver);
37419- cpufreq_us3_driver = NULL;
37420- kfree(us3_freq_table);
37421- us3_freq_table = NULL;
37422- }
37423+ cpufreq_unregister_driver(&cpufreq_us3_driver);
37424 }
37425
37426 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
37427diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
37428index 0915e71..53376ed 100644
37429--- a/drivers/cpufreq/speedstep-centrino.c
37430+++ b/drivers/cpufreq/speedstep-centrino.c
37431@@ -353,8 +353,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
37432 !cpu_has(cpu, X86_FEATURE_EST))
37433 return -ENODEV;
37434
37435- if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
37436- centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
37437+ if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
37438+ pax_open_kernel();
37439+ *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
37440+ pax_close_kernel();
37441+ }
37442
37443 if (policy->cpu != 0)
37444 return -ENODEV;
37445diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c
37446index fdc432f..98e64e2 100644
37447--- a/drivers/cpuidle/cpuidle.c
37448+++ b/drivers/cpuidle/cpuidle.c
37449@@ -254,7 +254,7 @@ static int poll_idle(struct cpuidle_device *dev,
37450
37451 static void poll_idle_init(struct cpuidle_driver *drv)
37452 {
37453- struct cpuidle_state *state = &drv->states[0];
37454+ cpuidle_state_no_const *state = &drv->states[0];
37455
37456 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
37457 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
37458diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
37459index ea2f8e7..70ac501 100644
37460--- a/drivers/cpuidle/governor.c
37461+++ b/drivers/cpuidle/governor.c
37462@@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
37463 mutex_lock(&cpuidle_lock);
37464 if (__cpuidle_find_governor(gov->name) == NULL) {
37465 ret = 0;
37466- list_add_tail(&gov->governor_list, &cpuidle_governors);
37467+ pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
37468 if (!cpuidle_curr_governor ||
37469 cpuidle_curr_governor->rating < gov->rating)
37470 cpuidle_switch_governor(gov);
37471@@ -135,7 +135,7 @@ void cpuidle_unregister_governor(struct cpuidle_governor *gov)
37472 new_gov = cpuidle_replace_governor(gov->rating);
37473 cpuidle_switch_governor(new_gov);
37474 }
37475- list_del(&gov->governor_list);
37476+ pax_list_del((struct list_head *)&gov->governor_list);
37477 mutex_unlock(&cpuidle_lock);
37478 }
37479
37480diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
37481index 428754a..8bdf9cc 100644
37482--- a/drivers/cpuidle/sysfs.c
37483+++ b/drivers/cpuidle/sysfs.c
37484@@ -131,7 +131,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
37485 NULL
37486 };
37487
37488-static struct attribute_group cpuidle_attr_group = {
37489+static attribute_group_no_const cpuidle_attr_group = {
37490 .attrs = cpuidle_default_attrs,
37491 .name = "cpuidle",
37492 };
37493diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
37494index 12fea3e..1e28f47 100644
37495--- a/drivers/crypto/hifn_795x.c
37496+++ b/drivers/crypto/hifn_795x.c
37497@@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
37498 MODULE_PARM_DESC(hifn_pll_ref,
37499 "PLL reference clock (pci[freq] or ext[freq], default ext)");
37500
37501-static atomic_t hifn_dev_number;
37502+static atomic_unchecked_t hifn_dev_number;
37503
37504 #define ACRYPTO_OP_DECRYPT 0
37505 #define ACRYPTO_OP_ENCRYPT 1
37506@@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
37507 goto err_out_disable_pci_device;
37508
37509 snprintf(name, sizeof(name), "hifn%d",
37510- atomic_inc_return(&hifn_dev_number)-1);
37511+ atomic_inc_return_unchecked(&hifn_dev_number)-1);
37512
37513 err = pci_request_regions(pdev, name);
37514 if (err)
37515diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
37516index e94e619..f7e249c 100644
37517--- a/drivers/devfreq/devfreq.c
37518+++ b/drivers/devfreq/devfreq.c
37519@@ -607,7 +607,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
37520 goto err_out;
37521 }
37522
37523- list_add(&governor->node, &devfreq_governor_list);
37524+ pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
37525
37526 list_for_each_entry(devfreq, &devfreq_list, node) {
37527 int ret = 0;
37528@@ -695,7 +695,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
37529 }
37530 }
37531
37532- list_del(&governor->node);
37533+ pax_list_del((struct list_head *)&governor->node);
37534 err_out:
37535 mutex_unlock(&devfreq_list_lock);
37536
37537diff --git a/drivers/dma/sh/shdma.c b/drivers/dma/sh/shdma.c
37538index 5039fbc..841169f 100644
37539--- a/drivers/dma/sh/shdma.c
37540+++ b/drivers/dma/sh/shdma.c
37541@@ -488,7 +488,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
37542 return ret;
37543 }
37544
37545-static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
37546+static struct notifier_block sh_dmae_nmi_notifier = {
37547 .notifier_call = sh_dmae_nmi_handler,
37548
37549 /* Run before NMI debug handler and KGDB */
37550diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
37551index 211021d..201d47f 100644
37552--- a/drivers/edac/edac_device.c
37553+++ b/drivers/edac/edac_device.c
37554@@ -474,9 +474,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
37555 */
37556 int edac_device_alloc_index(void)
37557 {
37558- static atomic_t device_indexes = ATOMIC_INIT(0);
37559+ static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
37560
37561- return atomic_inc_return(&device_indexes) - 1;
37562+ return atomic_inc_return_unchecked(&device_indexes) - 1;
37563 }
37564 EXPORT_SYMBOL_GPL(edac_device_alloc_index);
37565
37566diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
37567index e7c32c4..6397af1 100644
37568--- a/drivers/edac/edac_mc_sysfs.c
37569+++ b/drivers/edac/edac_mc_sysfs.c
37570@@ -148,7 +148,7 @@ static const char * const edac_caps[] = {
37571 struct dev_ch_attribute {
37572 struct device_attribute attr;
37573 int channel;
37574-};
37575+} __do_const;
37576
37577 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
37578 struct dev_ch_attribute dev_attr_legacy_##_name = \
37579@@ -1005,14 +1005,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
37580 }
37581
37582 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
37583+ pax_open_kernel();
37584 if (mci->get_sdram_scrub_rate) {
37585- dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
37586- dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
37587+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
37588+ *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
37589 }
37590 if (mci->set_sdram_scrub_rate) {
37591- dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
37592- dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
37593+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
37594+ *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
37595 }
37596+ pax_close_kernel();
37597 err = device_create_file(&mci->dev,
37598 &dev_attr_sdram_scrub_rate);
37599 if (err) {
37600diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
37601index dd370f9..0281629 100644
37602--- a/drivers/edac/edac_pci.c
37603+++ b/drivers/edac/edac_pci.c
37604@@ -29,7 +29,7 @@
37605
37606 static DEFINE_MUTEX(edac_pci_ctls_mutex);
37607 static LIST_HEAD(edac_pci_list);
37608-static atomic_t pci_indexes = ATOMIC_INIT(0);
37609+static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
37610
37611 /*
37612 * edac_pci_alloc_ctl_info
37613@@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
37614 */
37615 int edac_pci_alloc_index(void)
37616 {
37617- return atomic_inc_return(&pci_indexes) - 1;
37618+ return atomic_inc_return_unchecked(&pci_indexes) - 1;
37619 }
37620 EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
37621
37622diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
37623index e8658e4..22746d6 100644
37624--- a/drivers/edac/edac_pci_sysfs.c
37625+++ b/drivers/edac/edac_pci_sysfs.c
37626@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
37627 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
37628 static int edac_pci_poll_msec = 1000; /* one second workq period */
37629
37630-static atomic_t pci_parity_count = ATOMIC_INIT(0);
37631-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
37632+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
37633+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
37634
37635 static struct kobject *edac_pci_top_main_kobj;
37636 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
37637@@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
37638 void *value;
37639 ssize_t(*show) (void *, char *);
37640 ssize_t(*store) (void *, const char *, size_t);
37641-};
37642+} __do_const;
37643
37644 /* Set of show/store abstract level functions for PCI Parity object */
37645 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
37646@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37647 edac_printk(KERN_CRIT, EDAC_PCI,
37648 "Signaled System Error on %s\n",
37649 pci_name(dev));
37650- atomic_inc(&pci_nonparity_count);
37651+ atomic_inc_unchecked(&pci_nonparity_count);
37652 }
37653
37654 if (status & (PCI_STATUS_PARITY)) {
37655@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37656 "Master Data Parity Error on %s\n",
37657 pci_name(dev));
37658
37659- atomic_inc(&pci_parity_count);
37660+ atomic_inc_unchecked(&pci_parity_count);
37661 }
37662
37663 if (status & (PCI_STATUS_DETECTED_PARITY)) {
37664@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37665 "Detected Parity Error on %s\n",
37666 pci_name(dev));
37667
37668- atomic_inc(&pci_parity_count);
37669+ atomic_inc_unchecked(&pci_parity_count);
37670 }
37671 }
37672
37673@@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37674 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
37675 "Signaled System Error on %s\n",
37676 pci_name(dev));
37677- atomic_inc(&pci_nonparity_count);
37678+ atomic_inc_unchecked(&pci_nonparity_count);
37679 }
37680
37681 if (status & (PCI_STATUS_PARITY)) {
37682@@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37683 "Master Data Parity Error on "
37684 "%s\n", pci_name(dev));
37685
37686- atomic_inc(&pci_parity_count);
37687+ atomic_inc_unchecked(&pci_parity_count);
37688 }
37689
37690 if (status & (PCI_STATUS_DETECTED_PARITY)) {
37691@@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37692 "Detected Parity Error on %s\n",
37693 pci_name(dev));
37694
37695- atomic_inc(&pci_parity_count);
37696+ atomic_inc_unchecked(&pci_parity_count);
37697 }
37698 }
37699 }
37700@@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
37701 if (!check_pci_errors)
37702 return;
37703
37704- before_count = atomic_read(&pci_parity_count);
37705+ before_count = atomic_read_unchecked(&pci_parity_count);
37706
37707 /* scan all PCI devices looking for a Parity Error on devices and
37708 * bridges.
37709@@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
37710 /* Only if operator has selected panic on PCI Error */
37711 if (edac_pci_get_panic_on_pe()) {
37712 /* If the count is different 'after' from 'before' */
37713- if (before_count != atomic_read(&pci_parity_count))
37714+ if (before_count != atomic_read_unchecked(&pci_parity_count))
37715 panic("EDAC: PCI Parity Error");
37716 }
37717 }
37718diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
37719index 51b7e3a..aa8a3e8 100644
37720--- a/drivers/edac/mce_amd.h
37721+++ b/drivers/edac/mce_amd.h
37722@@ -77,7 +77,7 @@ struct amd_decoder_ops {
37723 bool (*mc0_mce)(u16, u8);
37724 bool (*mc1_mce)(u16, u8);
37725 bool (*mc2_mce)(u16, u8);
37726-};
37727+} __no_const;
37728
37729 void amd_report_gart_errors(bool);
37730 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
37731diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
37732index 57ea7f4..af06b76 100644
37733--- a/drivers/firewire/core-card.c
37734+++ b/drivers/firewire/core-card.c
37735@@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
37736 const struct fw_card_driver *driver,
37737 struct device *device)
37738 {
37739- static atomic_t index = ATOMIC_INIT(-1);
37740+ static atomic_unchecked_t index = ATOMIC_INIT(-1);
37741
37742- card->index = atomic_inc_return(&index);
37743+ card->index = atomic_inc_return_unchecked(&index);
37744 card->driver = driver;
37745 card->device = device;
37746 card->current_tlabel = 0;
37747@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
37748
37749 void fw_core_remove_card(struct fw_card *card)
37750 {
37751- struct fw_card_driver dummy_driver = dummy_driver_template;
37752+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
37753
37754 card->driver->update_phy_reg(card, 4,
37755 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
37756diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
37757index de4aa40..49ab1f2 100644
37758--- a/drivers/firewire/core-device.c
37759+++ b/drivers/firewire/core-device.c
37760@@ -253,7 +253,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
37761 struct config_rom_attribute {
37762 struct device_attribute attr;
37763 u32 key;
37764-};
37765+} __do_const;
37766
37767 static ssize_t show_immediate(struct device *dev,
37768 struct device_attribute *dattr, char *buf)
37769diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
37770index 28a94c7..58da63a 100644
37771--- a/drivers/firewire/core-transaction.c
37772+++ b/drivers/firewire/core-transaction.c
37773@@ -38,6 +38,7 @@
37774 #include <linux/timer.h>
37775 #include <linux/types.h>
37776 #include <linux/workqueue.h>
37777+#include <linux/sched.h>
37778
37779 #include <asm/byteorder.h>
37780
37781diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
37782index 515a42c..5ecf3ba 100644
37783--- a/drivers/firewire/core.h
37784+++ b/drivers/firewire/core.h
37785@@ -111,6 +111,7 @@ struct fw_card_driver {
37786
37787 int (*stop_iso)(struct fw_iso_context *ctx);
37788 };
37789+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
37790
37791 void fw_card_initialize(struct fw_card *card,
37792 const struct fw_card_driver *driver, struct device *device);
37793diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
37794index 94a58a0..f5eba42 100644
37795--- a/drivers/firmware/dmi-id.c
37796+++ b/drivers/firmware/dmi-id.c
37797@@ -16,7 +16,7 @@
37798 struct dmi_device_attribute{
37799 struct device_attribute dev_attr;
37800 int field;
37801-};
37802+} __do_const;
37803 #define to_dmi_dev_attr(_dev_attr) \
37804 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
37805
37806diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
37807index 232fa8f..386c255 100644
37808--- a/drivers/firmware/dmi_scan.c
37809+++ b/drivers/firmware/dmi_scan.c
37810@@ -504,11 +504,6 @@ void __init dmi_scan_machine(void)
37811 }
37812 }
37813 else {
37814- /*
37815- * no iounmap() for that ioremap(); it would be a no-op, but
37816- * it's so early in setup that sucker gets confused into doing
37817- * what it shouldn't if we actually call it.
37818- */
37819 p = dmi_ioremap(0xF0000, 0x10000);
37820 if (p == NULL)
37821 goto error;
37822@@ -806,7 +801,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
37823 if (buf == NULL)
37824 return -1;
37825
37826- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
37827+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
37828
37829 iounmap(buf);
37830 return 0;
37831diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
37832index 5145fa3..0d3babd 100644
37833--- a/drivers/firmware/efi/efi.c
37834+++ b/drivers/firmware/efi/efi.c
37835@@ -65,14 +65,16 @@ static struct attribute_group efi_subsys_attr_group = {
37836 };
37837
37838 static struct efivars generic_efivars;
37839-static struct efivar_operations generic_ops;
37840+static efivar_operations_no_const generic_ops __read_only;
37841
37842 static int generic_ops_register(void)
37843 {
37844- generic_ops.get_variable = efi.get_variable;
37845- generic_ops.set_variable = efi.set_variable;
37846- generic_ops.get_next_variable = efi.get_next_variable;
37847- generic_ops.query_variable_store = efi_query_variable_store;
37848+ pax_open_kernel();
37849+ *(void **)&generic_ops.get_variable = efi.get_variable;
37850+ *(void **)&generic_ops.set_variable = efi.set_variable;
37851+ *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
37852+ *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
37853+ pax_close_kernel();
37854
37855 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
37856 }
37857diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
37858index 8a7432a..28fb839 100644
37859--- a/drivers/firmware/efi/efivars.c
37860+++ b/drivers/firmware/efi/efivars.c
37861@@ -452,7 +452,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
37862 static int
37863 create_efivars_bin_attributes(void)
37864 {
37865- struct bin_attribute *attr;
37866+ bin_attribute_no_const *attr;
37867 int error;
37868
37869 /* new_var */
37870diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
37871index 2a90ba6..07f3733 100644
37872--- a/drivers/firmware/google/memconsole.c
37873+++ b/drivers/firmware/google/memconsole.c
37874@@ -147,7 +147,9 @@ static int __init memconsole_init(void)
37875 if (!found_memconsole())
37876 return -ENODEV;
37877
37878- memconsole_bin_attr.size = memconsole_length;
37879+ pax_open_kernel();
37880+ *(size_t *)&memconsole_bin_attr.size = memconsole_length;
37881+ pax_close_kernel();
37882
37883 ret = sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
37884
37885diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
37886index 2729e3d..f9deca1 100644
37887--- a/drivers/gpio/gpio-ich.c
37888+++ b/drivers/gpio/gpio-ich.c
37889@@ -71,7 +71,7 @@ struct ichx_desc {
37890 /* Some chipsets have quirks, let these use their own request/get */
37891 int (*request)(struct gpio_chip *chip, unsigned offset);
37892 int (*get)(struct gpio_chip *chip, unsigned offset);
37893-};
37894+} __do_const;
37895
37896 static struct {
37897 spinlock_t lock;
37898diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
37899index 9902732..64b62dd 100644
37900--- a/drivers/gpio/gpio-vr41xx.c
37901+++ b/drivers/gpio/gpio-vr41xx.c
37902@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
37903 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
37904 maskl, pendl, maskh, pendh);
37905
37906- atomic_inc(&irq_err_count);
37907+ atomic_inc_unchecked(&irq_err_count);
37908
37909 return -EINVAL;
37910 }
37911diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
37912index 6a64749..0767a9f 100644
37913--- a/drivers/gpu/drm/drm_crtc_helper.c
37914+++ b/drivers/gpu/drm/drm_crtc_helper.c
37915@@ -322,7 +322,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
37916 struct drm_crtc *tmp;
37917 int crtc_mask = 1;
37918
37919- WARN(!crtc, "checking null crtc?\n");
37920+ BUG_ON(!crtc);
37921
37922 dev = crtc->dev;
37923
37924diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
37925index 99fcd7c..13cf6c5 100644
37926--- a/drivers/gpu/drm/drm_drv.c
37927+++ b/drivers/gpu/drm/drm_drv.c
37928@@ -307,7 +307,7 @@ module_exit(drm_core_exit);
37929 /**
37930 * Copy and IOCTL return string to user space
37931 */
37932-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
37933+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
37934 {
37935 int len;
37936
37937@@ -377,7 +377,7 @@ long drm_ioctl(struct file *filp,
37938 struct drm_file *file_priv = filp->private_data;
37939 struct drm_device *dev;
37940 const struct drm_ioctl_desc *ioctl = NULL;
37941- drm_ioctl_t *func;
37942+ drm_ioctl_no_const_t func;
37943 unsigned int nr = DRM_IOCTL_NR(cmd);
37944 int retcode = -EINVAL;
37945 char stack_kdata[128];
37946@@ -390,7 +390,7 @@ long drm_ioctl(struct file *filp,
37947 return -ENODEV;
37948
37949 atomic_inc(&dev->ioctl_count);
37950- atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
37951+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
37952 ++file_priv->ioctl_count;
37953
37954 if ((nr >= DRM_CORE_IOCTL_COUNT) &&
37955diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
37956index 3a24385..4e426e0 100644
37957--- a/drivers/gpu/drm/drm_fops.c
37958+++ b/drivers/gpu/drm/drm_fops.c
37959@@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
37960 }
37961
37962 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
37963- atomic_set(&dev->counts[i], 0);
37964+ atomic_set_unchecked(&dev->counts[i], 0);
37965
37966 dev->sigdata.lock = NULL;
37967
37968@@ -135,7 +135,7 @@ int drm_open(struct inode *inode, struct file *filp)
37969 if (drm_device_is_unplugged(dev))
37970 return -ENODEV;
37971
37972- if (!dev->open_count++)
37973+ if (local_inc_return(&dev->open_count) == 1)
37974 need_setup = 1;
37975 mutex_lock(&dev->struct_mutex);
37976 old_imapping = inode->i_mapping;
37977@@ -151,7 +151,7 @@ int drm_open(struct inode *inode, struct file *filp)
37978 retcode = drm_open_helper(inode, filp, dev);
37979 if (retcode)
37980 goto err_undo;
37981- atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
37982+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
37983 if (need_setup) {
37984 retcode = drm_setup(dev);
37985 if (retcode)
37986@@ -166,7 +166,7 @@ err_undo:
37987 iput(container_of(dev->dev_mapping, struct inode, i_data));
37988 dev->dev_mapping = old_mapping;
37989 mutex_unlock(&dev->struct_mutex);
37990- dev->open_count--;
37991+ local_dec(&dev->open_count);
37992 return retcode;
37993 }
37994 EXPORT_SYMBOL(drm_open);
37995@@ -456,7 +456,7 @@ int drm_release(struct inode *inode, struct file *filp)
37996
37997 mutex_lock(&drm_global_mutex);
37998
37999- DRM_DEBUG("open_count = %d\n", dev->open_count);
38000+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
38001
38002 if (dev->driver->preclose)
38003 dev->driver->preclose(dev, file_priv);
38004@@ -465,10 +465,10 @@ int drm_release(struct inode *inode, struct file *filp)
38005 * Begin inline drm_release
38006 */
38007
38008- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
38009+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
38010 task_pid_nr(current),
38011 (long)old_encode_dev(file_priv->minor->device),
38012- dev->open_count);
38013+ local_read(&dev->open_count));
38014
38015 /* Release any auth tokens that might point to this file_priv,
38016 (do that under the drm_global_mutex) */
38017@@ -565,8 +565,8 @@ int drm_release(struct inode *inode, struct file *filp)
38018 * End inline drm_release
38019 */
38020
38021- atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
38022- if (!--dev->open_count) {
38023+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
38024+ if (local_dec_and_test(&dev->open_count)) {
38025 if (atomic_read(&dev->ioctl_count)) {
38026 DRM_ERROR("Device busy: %d\n",
38027 atomic_read(&dev->ioctl_count));
38028diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
38029index f731116..629842c 100644
38030--- a/drivers/gpu/drm/drm_global.c
38031+++ b/drivers/gpu/drm/drm_global.c
38032@@ -36,7 +36,7 @@
38033 struct drm_global_item {
38034 struct mutex mutex;
38035 void *object;
38036- int refcount;
38037+ atomic_t refcount;
38038 };
38039
38040 static struct drm_global_item glob[DRM_GLOBAL_NUM];
38041@@ -49,7 +49,7 @@ void drm_global_init(void)
38042 struct drm_global_item *item = &glob[i];
38043 mutex_init(&item->mutex);
38044 item->object = NULL;
38045- item->refcount = 0;
38046+ atomic_set(&item->refcount, 0);
38047 }
38048 }
38049
38050@@ -59,7 +59,7 @@ void drm_global_release(void)
38051 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
38052 struct drm_global_item *item = &glob[i];
38053 BUG_ON(item->object != NULL);
38054- BUG_ON(item->refcount != 0);
38055+ BUG_ON(atomic_read(&item->refcount) != 0);
38056 }
38057 }
38058
38059@@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
38060 void *object;
38061
38062 mutex_lock(&item->mutex);
38063- if (item->refcount == 0) {
38064+ if (atomic_read(&item->refcount) == 0) {
38065 item->object = kzalloc(ref->size, GFP_KERNEL);
38066 if (unlikely(item->object == NULL)) {
38067 ret = -ENOMEM;
38068@@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
38069 goto out_err;
38070
38071 }
38072- ++item->refcount;
38073+ atomic_inc(&item->refcount);
38074 ref->object = item->object;
38075 object = item->object;
38076 mutex_unlock(&item->mutex);
38077@@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
38078 struct drm_global_item *item = &glob[ref->global_type];
38079
38080 mutex_lock(&item->mutex);
38081- BUG_ON(item->refcount == 0);
38082+ BUG_ON(atomic_read(&item->refcount) == 0);
38083 BUG_ON(ref->object != item->object);
38084- if (--item->refcount == 0) {
38085+ if (atomic_dec_and_test(&item->refcount)) {
38086 ref->release(ref);
38087 item->object = NULL;
38088 }
38089diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
38090index d4b20ce..77a8d41 100644
38091--- a/drivers/gpu/drm/drm_info.c
38092+++ b/drivers/gpu/drm/drm_info.c
38093@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
38094 struct drm_local_map *map;
38095 struct drm_map_list *r_list;
38096
38097- /* Hardcoded from _DRM_FRAME_BUFFER,
38098- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
38099- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
38100- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
38101+ static const char * const types[] = {
38102+ [_DRM_FRAME_BUFFER] = "FB",
38103+ [_DRM_REGISTERS] = "REG",
38104+ [_DRM_SHM] = "SHM",
38105+ [_DRM_AGP] = "AGP",
38106+ [_DRM_SCATTER_GATHER] = "SG",
38107+ [_DRM_CONSISTENT] = "PCI",
38108+ [_DRM_GEM] = "GEM" };
38109 const char *type;
38110 int i;
38111
38112@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
38113 map = r_list->map;
38114 if (!map)
38115 continue;
38116- if (map->type < 0 || map->type > 5)
38117+ if (map->type >= ARRAY_SIZE(types))
38118 type = "??";
38119 else
38120 type = types[map->type];
38121@@ -253,7 +257,11 @@ int drm_vma_info(struct seq_file *m, void *data)
38122 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
38123 vma->vm_flags & VM_LOCKED ? 'l' : '-',
38124 vma->vm_flags & VM_IO ? 'i' : '-',
38125+#ifdef CONFIG_GRKERNSEC_HIDESYM
38126+ 0);
38127+#else
38128 vma->vm_pgoff);
38129+#endif
38130
38131 #if defined(__i386__)
38132 pgprot = pgprot_val(vma->vm_page_prot);
38133diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
38134index 2f4c434..dd12cd2 100644
38135--- a/drivers/gpu/drm/drm_ioc32.c
38136+++ b/drivers/gpu/drm/drm_ioc32.c
38137@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
38138 request = compat_alloc_user_space(nbytes);
38139 if (!access_ok(VERIFY_WRITE, request, nbytes))
38140 return -EFAULT;
38141- list = (struct drm_buf_desc *) (request + 1);
38142+ list = (struct drm_buf_desc __user *) (request + 1);
38143
38144 if (__put_user(count, &request->count)
38145 || __put_user(list, &request->list))
38146@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
38147 request = compat_alloc_user_space(nbytes);
38148 if (!access_ok(VERIFY_WRITE, request, nbytes))
38149 return -EFAULT;
38150- list = (struct drm_buf_pub *) (request + 1);
38151+ list = (struct drm_buf_pub __user *) (request + 1);
38152
38153 if (__put_user(count, &request->count)
38154 || __put_user(list, &request->list))
38155@@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
38156 return 0;
38157 }
38158
38159-drm_ioctl_compat_t *drm_compat_ioctls[] = {
38160+drm_ioctl_compat_t drm_compat_ioctls[] = {
38161 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
38162 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
38163 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
38164@@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
38165 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38166 {
38167 unsigned int nr = DRM_IOCTL_NR(cmd);
38168- drm_ioctl_compat_t *fn;
38169 int ret;
38170
38171 /* Assume that ioctls without an explicit compat routine will just
38172@@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38173 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
38174 return drm_ioctl(filp, cmd, arg);
38175
38176- fn = drm_compat_ioctls[nr];
38177-
38178- if (fn != NULL)
38179- ret = (*fn) (filp, cmd, arg);
38180+ if (drm_compat_ioctls[nr] != NULL)
38181+ ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
38182 else
38183 ret = drm_ioctl(filp, cmd, arg);
38184
38185diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
38186index ffd7a7b..a64643e 100644
38187--- a/drivers/gpu/drm/drm_ioctl.c
38188+++ b/drivers/gpu/drm/drm_ioctl.c
38189@@ -265,7 +265,7 @@ int drm_getstats(struct drm_device *dev, void *data,
38190 stats->data[i].value =
38191 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
38192 else
38193- stats->data[i].value = atomic_read(&dev->counts[i]);
38194+ stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
38195 stats->data[i].type = dev->types[i];
38196 }
38197
38198diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
38199index d752c96..fe08455 100644
38200--- a/drivers/gpu/drm/drm_lock.c
38201+++ b/drivers/gpu/drm/drm_lock.c
38202@@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
38203 if (drm_lock_take(&master->lock, lock->context)) {
38204 master->lock.file_priv = file_priv;
38205 master->lock.lock_time = jiffies;
38206- atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
38207+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
38208 break; /* Got lock */
38209 }
38210
38211@@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
38212 return -EINVAL;
38213 }
38214
38215- atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
38216+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
38217
38218 if (drm_lock_free(&master->lock, lock->context)) {
38219 /* FIXME: Should really bail out here. */
38220diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
38221index 327ca19..684d3c0 100644
38222--- a/drivers/gpu/drm/drm_stub.c
38223+++ b/drivers/gpu/drm/drm_stub.c
38224@@ -495,7 +495,7 @@ void drm_unplug_dev(struct drm_device *dev)
38225
38226 drm_device_set_unplugged(dev);
38227
38228- if (dev->open_count == 0) {
38229+ if (local_read(&dev->open_count) == 0) {
38230 drm_put_dev(dev);
38231 }
38232 mutex_unlock(&drm_global_mutex);
38233diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
38234index 2290b3b..22056a1 100644
38235--- a/drivers/gpu/drm/drm_sysfs.c
38236+++ b/drivers/gpu/drm/drm_sysfs.c
38237@@ -524,7 +524,7 @@ EXPORT_SYMBOL(drm_sysfs_hotplug_event);
38238 int drm_sysfs_device_add(struct drm_minor *minor)
38239 {
38240 int err;
38241- char *minor_str;
38242+ const char *minor_str;
38243
38244 minor->kdev.parent = minor->dev->dev;
38245
38246diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
38247index ada49ed..29275a0 100644
38248--- a/drivers/gpu/drm/i810/i810_dma.c
38249+++ b/drivers/gpu/drm/i810/i810_dma.c
38250@@ -945,8 +945,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
38251 dma->buflist[vertex->idx],
38252 vertex->discard, vertex->used);
38253
38254- atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
38255- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
38256+ atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
38257+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
38258 sarea_priv->last_enqueue = dev_priv->counter - 1;
38259 sarea_priv->last_dispatch = (int)hw_status[5];
38260
38261@@ -1106,8 +1106,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
38262 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
38263 mc->last_render);
38264
38265- atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
38266- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
38267+ atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
38268+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
38269 sarea_priv->last_enqueue = dev_priv->counter - 1;
38270 sarea_priv->last_dispatch = (int)hw_status[5];
38271
38272diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
38273index 6e0acad..93c8289 100644
38274--- a/drivers/gpu/drm/i810/i810_drv.h
38275+++ b/drivers/gpu/drm/i810/i810_drv.h
38276@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
38277 int page_flipping;
38278
38279 wait_queue_head_t irq_queue;
38280- atomic_t irq_received;
38281- atomic_t irq_emitted;
38282+ atomic_unchecked_t irq_received;
38283+ atomic_unchecked_t irq_emitted;
38284
38285 int front_offset;
38286 } drm_i810_private_t;
38287diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
38288index 47d6c74..279123f 100644
38289--- a/drivers/gpu/drm/i915/i915_debugfs.c
38290+++ b/drivers/gpu/drm/i915/i915_debugfs.c
38291@@ -541,7 +541,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
38292 I915_READ(GTIMR));
38293 }
38294 seq_printf(m, "Interrupts received: %d\n",
38295- atomic_read(&dev_priv->irq_received));
38296+ atomic_read_unchecked(&dev_priv->irq_received));
38297 for_each_ring(ring, dev_priv, i) {
38298 if (IS_GEN6(dev) || IS_GEN7(dev)) {
38299 seq_printf(m,
38300diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
38301index f466980..8f2883f 100644
38302--- a/drivers/gpu/drm/i915/i915_dma.c
38303+++ b/drivers/gpu/drm/i915/i915_dma.c
38304@@ -1260,7 +1260,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
38305 bool can_switch;
38306
38307 spin_lock(&dev->count_lock);
38308- can_switch = (dev->open_count == 0);
38309+ can_switch = (local_read(&dev->open_count) == 0);
38310 spin_unlock(&dev->count_lock);
38311 return can_switch;
38312 }
38313diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
38314index 1929bff..dab130d 100644
38315--- a/drivers/gpu/drm/i915/i915_drv.h
38316+++ b/drivers/gpu/drm/i915/i915_drv.h
38317@@ -1028,7 +1028,7 @@ typedef struct drm_i915_private {
38318 drm_dma_handle_t *status_page_dmah;
38319 struct resource mch_res;
38320
38321- atomic_t irq_received;
38322+ atomic_unchecked_t irq_received;
38323
38324 /* protects the irq masks */
38325 spinlock_t irq_lock;
38326diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
38327index 87a3227..cd13d8f 100644
38328--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
38329+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
38330@@ -727,9 +727,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
38331
38332 static int
38333 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
38334- int count)
38335+ unsigned int count)
38336 {
38337- int i;
38338+ unsigned int i;
38339 int relocs_total = 0;
38340 int relocs_max = INT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
38341
38342diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
38343index 3c59584..500f2e9 100644
38344--- a/drivers/gpu/drm/i915/i915_ioc32.c
38345+++ b/drivers/gpu/drm/i915/i915_ioc32.c
38346@@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
38347 (unsigned long)request);
38348 }
38349
38350-static drm_ioctl_compat_t *i915_compat_ioctls[] = {
38351+static drm_ioctl_compat_t i915_compat_ioctls[] = {
38352 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
38353 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
38354 [DRM_I915_GETPARAM] = compat_i915_getparam,
38355@@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
38356 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38357 {
38358 unsigned int nr = DRM_IOCTL_NR(cmd);
38359- drm_ioctl_compat_t *fn = NULL;
38360 int ret;
38361
38362 if (nr < DRM_COMMAND_BASE)
38363 return drm_compat_ioctl(filp, cmd, arg);
38364
38365- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
38366- fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
38367-
38368- if (fn != NULL)
38369+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
38370+ drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
38371 ret = (*fn) (filp, cmd, arg);
38372- else
38373+ } else
38374 ret = drm_ioctl(filp, cmd, arg);
38375
38376 return ret;
38377diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
38378index 3d92a7c..9a9cfd7 100644
38379--- a/drivers/gpu/drm/i915/i915_irq.c
38380+++ b/drivers/gpu/drm/i915/i915_irq.c
38381@@ -970,7 +970,7 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
38382 int pipe;
38383 u32 pipe_stats[I915_MAX_PIPES];
38384
38385- atomic_inc(&dev_priv->irq_received);
38386+ atomic_inc_unchecked(&dev_priv->irq_received);
38387
38388 while (true) {
38389 iir = I915_READ(VLV_IIR);
38390@@ -1187,7 +1187,7 @@ static irqreturn_t ivybridge_irq_handler(int irq, void *arg)
38391 irqreturn_t ret = IRQ_NONE;
38392 int i;
38393
38394- atomic_inc(&dev_priv->irq_received);
38395+ atomic_inc_unchecked(&dev_priv->irq_received);
38396
38397 /* We get interrupts on unclaimed registers, so check for this before we
38398 * do any I915_{READ,WRITE}. */
38399@@ -1307,7 +1307,7 @@ static irqreturn_t ironlake_irq_handler(int irq, void *arg)
38400 int ret = IRQ_NONE;
38401 u32 de_iir, gt_iir, de_ier, pm_iir, sde_ier;
38402
38403- atomic_inc(&dev_priv->irq_received);
38404+ atomic_inc_unchecked(&dev_priv->irq_received);
38405
38406 /* disable master interrupt before clearing iir */
38407 de_ier = I915_READ(DEIER);
38408@@ -2566,7 +2566,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
38409 {
38410 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38411
38412- atomic_set(&dev_priv->irq_received, 0);
38413+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38414
38415 I915_WRITE(HWSTAM, 0xeffe);
38416
38417@@ -2588,7 +2588,7 @@ static void ivybridge_irq_preinstall(struct drm_device *dev)
38418 {
38419 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38420
38421- atomic_set(&dev_priv->irq_received, 0);
38422+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38423
38424 I915_WRITE(HWSTAM, 0xeffe);
38425
38426@@ -2616,7 +2616,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
38427 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38428 int pipe;
38429
38430- atomic_set(&dev_priv->irq_received, 0);
38431+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38432
38433 /* VLV magic */
38434 I915_WRITE(VLV_IMR, 0);
38435@@ -2928,7 +2928,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
38436 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38437 int pipe;
38438
38439- atomic_set(&dev_priv->irq_received, 0);
38440+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38441
38442 for_each_pipe(pipe)
38443 I915_WRITE(PIPESTAT(pipe), 0);
38444@@ -3007,7 +3007,7 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg)
38445 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
38446 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
38447
38448- atomic_inc(&dev_priv->irq_received);
38449+ atomic_inc_unchecked(&dev_priv->irq_received);
38450
38451 iir = I915_READ16(IIR);
38452 if (iir == 0)
38453@@ -3082,7 +3082,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
38454 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38455 int pipe;
38456
38457- atomic_set(&dev_priv->irq_received, 0);
38458+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38459
38460 if (I915_HAS_HOTPLUG(dev)) {
38461 I915_WRITE(PORT_HOTPLUG_EN, 0);
38462@@ -3181,7 +3181,7 @@ static irqreturn_t i915_irq_handler(int irq, void *arg)
38463 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
38464 int pipe, ret = IRQ_NONE;
38465
38466- atomic_inc(&dev_priv->irq_received);
38467+ atomic_inc_unchecked(&dev_priv->irq_received);
38468
38469 iir = I915_READ(IIR);
38470 do {
38471@@ -3305,7 +3305,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
38472 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38473 int pipe;
38474
38475- atomic_set(&dev_priv->irq_received, 0);
38476+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38477
38478 I915_WRITE(PORT_HOTPLUG_EN, 0);
38479 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
38480@@ -3414,7 +3414,7 @@ static irqreturn_t i965_irq_handler(int irq, void *arg)
38481 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
38482 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
38483
38484- atomic_inc(&dev_priv->irq_received);
38485+ atomic_inc_unchecked(&dev_priv->irq_received);
38486
38487 iir = I915_READ(IIR);
38488
38489diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
38490index be79f47..95e150b 100644
38491--- a/drivers/gpu/drm/i915/intel_display.c
38492+++ b/drivers/gpu/drm/i915/intel_display.c
38493@@ -9418,13 +9418,13 @@ struct intel_quirk {
38494 int subsystem_vendor;
38495 int subsystem_device;
38496 void (*hook)(struct drm_device *dev);
38497-};
38498+} __do_const;
38499
38500 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
38501 struct intel_dmi_quirk {
38502 void (*hook)(struct drm_device *dev);
38503 const struct dmi_system_id (*dmi_id_list)[];
38504-};
38505+} __do_const;
38506
38507 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
38508 {
38509@@ -9432,18 +9432,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
38510 return 1;
38511 }
38512
38513-static const struct intel_dmi_quirk intel_dmi_quirks[] = {
38514+static const struct dmi_system_id intel_dmi_quirks_table[] = {
38515 {
38516- .dmi_id_list = &(const struct dmi_system_id[]) {
38517- {
38518- .callback = intel_dmi_reverse_brightness,
38519- .ident = "NCR Corporation",
38520- .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
38521- DMI_MATCH(DMI_PRODUCT_NAME, ""),
38522- },
38523- },
38524- { } /* terminating entry */
38525+ .callback = intel_dmi_reverse_brightness,
38526+ .ident = "NCR Corporation",
38527+ .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
38528+ DMI_MATCH(DMI_PRODUCT_NAME, ""),
38529 },
38530+ },
38531+ { } /* terminating entry */
38532+};
38533+
38534+static const struct intel_dmi_quirk intel_dmi_quirks[] = {
38535+ {
38536+ .dmi_id_list = &intel_dmi_quirks_table,
38537 .hook = quirk_invert_brightness,
38538 },
38539 };
38540diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
38541index 54558a0..2d97005 100644
38542--- a/drivers/gpu/drm/mga/mga_drv.h
38543+++ b/drivers/gpu/drm/mga/mga_drv.h
38544@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
38545 u32 clear_cmd;
38546 u32 maccess;
38547
38548- atomic_t vbl_received; /**< Number of vblanks received. */
38549+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
38550 wait_queue_head_t fence_queue;
38551- atomic_t last_fence_retired;
38552+ atomic_unchecked_t last_fence_retired;
38553 u32 next_fence_to_post;
38554
38555 unsigned int fb_cpp;
38556diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
38557index 709e90d..89a1c0d 100644
38558--- a/drivers/gpu/drm/mga/mga_ioc32.c
38559+++ b/drivers/gpu/drm/mga/mga_ioc32.c
38560@@ -189,7 +189,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
38561 return 0;
38562 }
38563
38564-drm_ioctl_compat_t *mga_compat_ioctls[] = {
38565+drm_ioctl_compat_t mga_compat_ioctls[] = {
38566 [DRM_MGA_INIT] = compat_mga_init,
38567 [DRM_MGA_GETPARAM] = compat_mga_getparam,
38568 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
38569@@ -207,18 +207,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
38570 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38571 {
38572 unsigned int nr = DRM_IOCTL_NR(cmd);
38573- drm_ioctl_compat_t *fn = NULL;
38574 int ret;
38575
38576 if (nr < DRM_COMMAND_BASE)
38577 return drm_compat_ioctl(filp, cmd, arg);
38578
38579- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
38580- fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
38581-
38582- if (fn != NULL)
38583+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
38584+ drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
38585 ret = (*fn) (filp, cmd, arg);
38586- else
38587+ } else
38588 ret = drm_ioctl(filp, cmd, arg);
38589
38590 return ret;
38591diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
38592index 598c281..60d590e 100644
38593--- a/drivers/gpu/drm/mga/mga_irq.c
38594+++ b/drivers/gpu/drm/mga/mga_irq.c
38595@@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
38596 if (crtc != 0)
38597 return 0;
38598
38599- return atomic_read(&dev_priv->vbl_received);
38600+ return atomic_read_unchecked(&dev_priv->vbl_received);
38601 }
38602
38603
38604@@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
38605 /* VBLANK interrupt */
38606 if (status & MGA_VLINEPEN) {
38607 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
38608- atomic_inc(&dev_priv->vbl_received);
38609+ atomic_inc_unchecked(&dev_priv->vbl_received);
38610 drm_handle_vblank(dev, 0);
38611 handled = 1;
38612 }
38613@@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
38614 if ((prim_start & ~0x03) != (prim_end & ~0x03))
38615 MGA_WRITE(MGA_PRIMEND, prim_end);
38616
38617- atomic_inc(&dev_priv->last_fence_retired);
38618+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
38619 DRM_WAKEUP(&dev_priv->fence_queue);
38620 handled = 1;
38621 }
38622@@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
38623 * using fences.
38624 */
38625 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
38626- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
38627+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
38628 - *sequence) <= (1 << 23)));
38629
38630 *sequence = cur_fence;
38631diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
38632index 3e72876..d1c15ad 100644
38633--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
38634+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
38635@@ -965,7 +965,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
38636 struct bit_table {
38637 const char id;
38638 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
38639-};
38640+} __no_const;
38641
38642 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
38643
38644diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
38645index 41ff7e0..fa854ef 100644
38646--- a/drivers/gpu/drm/nouveau/nouveau_drm.h
38647+++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
38648@@ -92,7 +92,6 @@ struct nouveau_drm {
38649 struct drm_global_reference mem_global_ref;
38650 struct ttm_bo_global_ref bo_global_ref;
38651 struct ttm_bo_device bdev;
38652- atomic_t validate_sequence;
38653 int (*move)(struct nouveau_channel *,
38654 struct ttm_buffer_object *,
38655 struct ttm_mem_reg *, struct ttm_mem_reg *);
38656diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
38657index 08214bc..9208577 100644
38658--- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
38659+++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
38660@@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
38661 unsigned long arg)
38662 {
38663 unsigned int nr = DRM_IOCTL_NR(cmd);
38664- drm_ioctl_compat_t *fn = NULL;
38665+ drm_ioctl_compat_t fn = NULL;
38666 int ret;
38667
38668 if (nr < DRM_COMMAND_BASE)
38669diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
38670index 25d3495..d81aaf6 100644
38671--- a/drivers/gpu/drm/nouveau/nouveau_vga.c
38672+++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
38673@@ -62,7 +62,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
38674 bool can_switch;
38675
38676 spin_lock(&dev->count_lock);
38677- can_switch = (dev->open_count == 0);
38678+ can_switch = (local_read(&dev->open_count) == 0);
38679 spin_unlock(&dev->count_lock);
38680 return can_switch;
38681 }
38682diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
38683index 1dfd84c..104896c 100644
38684--- a/drivers/gpu/drm/qxl/qxl_ttm.c
38685+++ b/drivers/gpu/drm/qxl/qxl_ttm.c
38686@@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
38687 }
38688 }
38689
38690-static struct vm_operations_struct qxl_ttm_vm_ops;
38691+static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
38692 static const struct vm_operations_struct *ttm_vm_ops;
38693
38694 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
38695@@ -147,8 +147,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
38696 return r;
38697 if (unlikely(ttm_vm_ops == NULL)) {
38698 ttm_vm_ops = vma->vm_ops;
38699+ pax_open_kernel();
38700 qxl_ttm_vm_ops = *ttm_vm_ops;
38701 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
38702+ pax_close_kernel();
38703 }
38704 vma->vm_ops = &qxl_ttm_vm_ops;
38705 return 0;
38706@@ -556,25 +558,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
38707 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
38708 {
38709 #if defined(CONFIG_DEBUG_FS)
38710- static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
38711- static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
38712- unsigned i;
38713+ static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
38714+ {
38715+ .name = "qxl_mem_mm",
38716+ .show = &qxl_mm_dump_table,
38717+ },
38718+ {
38719+ .name = "qxl_surf_mm",
38720+ .show = &qxl_mm_dump_table,
38721+ }
38722+ };
38723
38724- for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
38725- if (i == 0)
38726- sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
38727- else
38728- sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
38729- qxl_mem_types_list[i].name = qxl_mem_types_names[i];
38730- qxl_mem_types_list[i].show = &qxl_mm_dump_table;
38731- qxl_mem_types_list[i].driver_features = 0;
38732- if (i == 0)
38733- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
38734- else
38735- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
38736+ pax_open_kernel();
38737+ *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
38738+ *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
38739+ pax_close_kernel();
38740
38741- }
38742- return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
38743+ return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
38744 #else
38745 return 0;
38746 #endif
38747diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
38748index d4660cf..70dbe65 100644
38749--- a/drivers/gpu/drm/r128/r128_cce.c
38750+++ b/drivers/gpu/drm/r128/r128_cce.c
38751@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
38752
38753 /* GH: Simple idle check.
38754 */
38755- atomic_set(&dev_priv->idle_count, 0);
38756+ atomic_set_unchecked(&dev_priv->idle_count, 0);
38757
38758 /* We don't support anything other than bus-mastering ring mode,
38759 * but the ring can be in either AGP or PCI space for the ring
38760diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
38761index 930c71b..499aded 100644
38762--- a/drivers/gpu/drm/r128/r128_drv.h
38763+++ b/drivers/gpu/drm/r128/r128_drv.h
38764@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
38765 int is_pci;
38766 unsigned long cce_buffers_offset;
38767
38768- atomic_t idle_count;
38769+ atomic_unchecked_t idle_count;
38770
38771 int page_flipping;
38772 int current_page;
38773 u32 crtc_offset;
38774 u32 crtc_offset_cntl;
38775
38776- atomic_t vbl_received;
38777+ atomic_unchecked_t vbl_received;
38778
38779 u32 color_fmt;
38780 unsigned int front_offset;
38781diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
38782index a954c54..9cc595c 100644
38783--- a/drivers/gpu/drm/r128/r128_ioc32.c
38784+++ b/drivers/gpu/drm/r128/r128_ioc32.c
38785@@ -177,7 +177,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
38786 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
38787 }
38788
38789-drm_ioctl_compat_t *r128_compat_ioctls[] = {
38790+drm_ioctl_compat_t r128_compat_ioctls[] = {
38791 [DRM_R128_INIT] = compat_r128_init,
38792 [DRM_R128_DEPTH] = compat_r128_depth,
38793 [DRM_R128_STIPPLE] = compat_r128_stipple,
38794@@ -196,18 +196,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
38795 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38796 {
38797 unsigned int nr = DRM_IOCTL_NR(cmd);
38798- drm_ioctl_compat_t *fn = NULL;
38799 int ret;
38800
38801 if (nr < DRM_COMMAND_BASE)
38802 return drm_compat_ioctl(filp, cmd, arg);
38803
38804- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
38805- fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
38806-
38807- if (fn != NULL)
38808+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
38809+ drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
38810 ret = (*fn) (filp, cmd, arg);
38811- else
38812+ } else
38813 ret = drm_ioctl(filp, cmd, arg);
38814
38815 return ret;
38816diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
38817index 2ea4f09..d391371 100644
38818--- a/drivers/gpu/drm/r128/r128_irq.c
38819+++ b/drivers/gpu/drm/r128/r128_irq.c
38820@@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
38821 if (crtc != 0)
38822 return 0;
38823
38824- return atomic_read(&dev_priv->vbl_received);
38825+ return atomic_read_unchecked(&dev_priv->vbl_received);
38826 }
38827
38828 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
38829@@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
38830 /* VBLANK interrupt */
38831 if (status & R128_CRTC_VBLANK_INT) {
38832 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
38833- atomic_inc(&dev_priv->vbl_received);
38834+ atomic_inc_unchecked(&dev_priv->vbl_received);
38835 drm_handle_vblank(dev, 0);
38836 return IRQ_HANDLED;
38837 }
38838diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
38839index 19bb7e6..de7e2a2 100644
38840--- a/drivers/gpu/drm/r128/r128_state.c
38841+++ b/drivers/gpu/drm/r128/r128_state.c
38842@@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
38843
38844 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
38845 {
38846- if (atomic_read(&dev_priv->idle_count) == 0)
38847+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
38848 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
38849 else
38850- atomic_set(&dev_priv->idle_count, 0);
38851+ atomic_set_unchecked(&dev_priv->idle_count, 0);
38852 }
38853
38854 #endif
38855diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
38856index af85299..ed9ac8d 100644
38857--- a/drivers/gpu/drm/radeon/mkregtable.c
38858+++ b/drivers/gpu/drm/radeon/mkregtable.c
38859@@ -624,14 +624,14 @@ static int parser_auth(struct table *t, const char *filename)
38860 regex_t mask_rex;
38861 regmatch_t match[4];
38862 char buf[1024];
38863- size_t end;
38864+ long end;
38865 int len;
38866 int done = 0;
38867 int r;
38868 unsigned o;
38869 struct offset *offset;
38870 char last_reg_s[10];
38871- int last_reg;
38872+ unsigned long last_reg;
38873
38874 if (regcomp
38875 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
38876diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
38877index 63398ae..669e045 100644
38878--- a/drivers/gpu/drm/radeon/radeon_device.c
38879+++ b/drivers/gpu/drm/radeon/radeon_device.c
38880@@ -1105,7 +1105,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
38881 bool can_switch;
38882
38883 spin_lock(&dev->count_lock);
38884- can_switch = (dev->open_count == 0);
38885+ can_switch = (local_read(&dev->open_count) == 0);
38886 spin_unlock(&dev->count_lock);
38887 return can_switch;
38888 }
38889diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
38890index b369d42..8dd04eb 100644
38891--- a/drivers/gpu/drm/radeon/radeon_drv.h
38892+++ b/drivers/gpu/drm/radeon/radeon_drv.h
38893@@ -258,7 +258,7 @@ typedef struct drm_radeon_private {
38894
38895 /* SW interrupt */
38896 wait_queue_head_t swi_queue;
38897- atomic_t swi_emitted;
38898+ atomic_unchecked_t swi_emitted;
38899 int vblank_crtc;
38900 uint32_t irq_enable_reg;
38901 uint32_t r500_disp_irq_reg;
38902diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
38903index c180df8..5fd8186 100644
38904--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
38905+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
38906@@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
38907 request = compat_alloc_user_space(sizeof(*request));
38908 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
38909 || __put_user(req32.param, &request->param)
38910- || __put_user((void __user *)(unsigned long)req32.value,
38911+ || __put_user((unsigned long)req32.value,
38912 &request->value))
38913 return -EFAULT;
38914
38915@@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
38916 #define compat_radeon_cp_setparam NULL
38917 #endif /* X86_64 || IA64 */
38918
38919-static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
38920+static drm_ioctl_compat_t radeon_compat_ioctls[] = {
38921 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
38922 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
38923 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
38924@@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
38925 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38926 {
38927 unsigned int nr = DRM_IOCTL_NR(cmd);
38928- drm_ioctl_compat_t *fn = NULL;
38929 int ret;
38930
38931 if (nr < DRM_COMMAND_BASE)
38932 return drm_compat_ioctl(filp, cmd, arg);
38933
38934- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
38935- fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
38936-
38937- if (fn != NULL)
38938+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
38939+ drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
38940 ret = (*fn) (filp, cmd, arg);
38941- else
38942+ } else
38943 ret = drm_ioctl(filp, cmd, arg);
38944
38945 return ret;
38946diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
38947index 8d68e97..9dcfed8 100644
38948--- a/drivers/gpu/drm/radeon/radeon_irq.c
38949+++ b/drivers/gpu/drm/radeon/radeon_irq.c
38950@@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
38951 unsigned int ret;
38952 RING_LOCALS;
38953
38954- atomic_inc(&dev_priv->swi_emitted);
38955- ret = atomic_read(&dev_priv->swi_emitted);
38956+ atomic_inc_unchecked(&dev_priv->swi_emitted);
38957+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
38958
38959 BEGIN_RING(4);
38960 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
38961@@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
38962 drm_radeon_private_t *dev_priv =
38963 (drm_radeon_private_t *) dev->dev_private;
38964
38965- atomic_set(&dev_priv->swi_emitted, 0);
38966+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
38967 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
38968
38969 dev->max_vblank_count = 0x001fffff;
38970diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
38971index 4d20910..6726b6d 100644
38972--- a/drivers/gpu/drm/radeon/radeon_state.c
38973+++ b/drivers/gpu/drm/radeon/radeon_state.c
38974@@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
38975 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
38976 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
38977
38978- if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
38979+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
38980 sarea_priv->nbox * sizeof(depth_boxes[0])))
38981 return -EFAULT;
38982
38983@@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
38984 {
38985 drm_radeon_private_t *dev_priv = dev->dev_private;
38986 drm_radeon_getparam_t *param = data;
38987- int value;
38988+ int value = 0;
38989
38990 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
38991
38992diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
38993index 6c0ce89..57a2529 100644
38994--- a/drivers/gpu/drm/radeon/radeon_ttm.c
38995+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
38996@@ -782,7 +782,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
38997 man->size = size >> PAGE_SHIFT;
38998 }
38999
39000-static struct vm_operations_struct radeon_ttm_vm_ops;
39001+static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
39002 static const struct vm_operations_struct *ttm_vm_ops = NULL;
39003
39004 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
39005@@ -823,8 +823,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
39006 }
39007 if (unlikely(ttm_vm_ops == NULL)) {
39008 ttm_vm_ops = vma->vm_ops;
39009+ pax_open_kernel();
39010 radeon_ttm_vm_ops = *ttm_vm_ops;
39011 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
39012+ pax_close_kernel();
39013 }
39014 vma->vm_ops = &radeon_ttm_vm_ops;
39015 return 0;
39016@@ -853,38 +855,33 @@ static int radeon_mm_dump_table(struct seq_file *m, void *data)
39017 static int radeon_ttm_debugfs_init(struct radeon_device *rdev)
39018 {
39019 #if defined(CONFIG_DEBUG_FS)
39020- static struct drm_info_list radeon_mem_types_list[RADEON_DEBUGFS_MEM_TYPES+2];
39021- static char radeon_mem_types_names[RADEON_DEBUGFS_MEM_TYPES+2][32];
39022+ static struct drm_info_list radeon_mem_types_list[RADEON_DEBUGFS_MEM_TYPES+2] = {
39023+ {
39024+ .name = "radeon_vram_mm",
39025+ .show = &radeon_mm_dump_table,
39026+ },
39027+ {
39028+ .name = "radeon_gtt_mm",
39029+ .show = &radeon_mm_dump_table,
39030+ },
39031+ {
39032+ .name = "ttm_page_pool",
39033+ .show = &ttm_page_alloc_debugfs,
39034+ },
39035+ {
39036+ .name = "ttm_dma_page_pool",
39037+ .show = &ttm_dma_page_alloc_debugfs,
39038+ },
39039+ };
39040 unsigned i;
39041
39042- for (i = 0; i < RADEON_DEBUGFS_MEM_TYPES; i++) {
39043- if (i == 0)
39044- sprintf(radeon_mem_types_names[i], "radeon_vram_mm");
39045- else
39046- sprintf(radeon_mem_types_names[i], "radeon_gtt_mm");
39047- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
39048- radeon_mem_types_list[i].show = &radeon_mm_dump_table;
39049- radeon_mem_types_list[i].driver_features = 0;
39050- if (i == 0)
39051- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
39052- else
39053- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
39054-
39055- }
39056- /* Add ttm page pool to debugfs */
39057- sprintf(radeon_mem_types_names[i], "ttm_page_pool");
39058- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
39059- radeon_mem_types_list[i].show = &ttm_page_alloc_debugfs;
39060- radeon_mem_types_list[i].driver_features = 0;
39061- radeon_mem_types_list[i++].data = NULL;
39062+ pax_open_kernel();
39063+ *(void **)&radeon_mem_types_list[0].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
39064+ *(void **)&radeon_mem_types_list[1].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
39065+ pax_close_kernel();
39066 #ifdef CONFIG_SWIOTLB
39067- if (swiotlb_nr_tbl()) {
39068- sprintf(radeon_mem_types_names[i], "ttm_dma_page_pool");
39069- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
39070- radeon_mem_types_list[i].show = &ttm_dma_page_alloc_debugfs;
39071- radeon_mem_types_list[i].driver_features = 0;
39072- radeon_mem_types_list[i++].data = NULL;
39073- }
39074+ if (swiotlb_nr_tbl())
39075+ i++;
39076 #endif
39077 return radeon_debugfs_add_files(rdev, radeon_mem_types_list, i);
39078
39079diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
39080index d8ddfb3..609de1d 100644
39081--- a/drivers/gpu/drm/radeon/rs690.c
39082+++ b/drivers/gpu/drm/radeon/rs690.c
39083@@ -345,9 +345,11 @@ static void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
39084 if (max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
39085 rdev->pm.sideport_bandwidth.full)
39086 max_bandwidth = rdev->pm.sideport_bandwidth;
39087- read_delay_latency.full = dfixed_const(370 * 800 * 1000);
39088+ read_delay_latency.full = dfixed_const(800 * 1000);
39089 read_delay_latency.full = dfixed_div(read_delay_latency,
39090 rdev->pm.igp_sideport_mclk);
39091+ a.full = dfixed_const(370);
39092+ read_delay_latency.full = dfixed_mul(read_delay_latency, a);
39093 } else {
39094 if (max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
39095 rdev->pm.k8_bandwidth.full)
39096diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
39097index dbc2def..0a9f710 100644
39098--- a/drivers/gpu/drm/ttm/ttm_memory.c
39099+++ b/drivers/gpu/drm/ttm/ttm_memory.c
39100@@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
39101 zone->glob = glob;
39102 glob->zone_kernel = zone;
39103 ret = kobject_init_and_add(
39104- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
39105+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
39106 if (unlikely(ret != 0)) {
39107 kobject_put(&zone->kobj);
39108 return ret;
39109@@ -347,7 +347,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
39110 zone->glob = glob;
39111 glob->zone_dma32 = zone;
39112 ret = kobject_init_and_add(
39113- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
39114+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
39115 if (unlikely(ret != 0)) {
39116 kobject_put(&zone->kobj);
39117 return ret;
39118diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
39119index bd2a3b4..122d9ad 100644
39120--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
39121+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
39122@@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
39123 static int ttm_pool_mm_shrink(struct shrinker *shrink,
39124 struct shrink_control *sc)
39125 {
39126- static atomic_t start_pool = ATOMIC_INIT(0);
39127+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
39128 unsigned i;
39129- unsigned pool_offset = atomic_add_return(1, &start_pool);
39130+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
39131 struct ttm_page_pool *pool;
39132 int shrink_pages = sc->nr_to_scan;
39133
39134diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
39135index 97e9d61..bf23c461 100644
39136--- a/drivers/gpu/drm/udl/udl_fb.c
39137+++ b/drivers/gpu/drm/udl/udl_fb.c
39138@@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
39139 fb_deferred_io_cleanup(info);
39140 kfree(info->fbdefio);
39141 info->fbdefio = NULL;
39142- info->fbops->fb_mmap = udl_fb_mmap;
39143 }
39144
39145 pr_warn("released /dev/fb%d user=%d count=%d\n",
39146diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
39147index 893a650..6190d3b 100644
39148--- a/drivers/gpu/drm/via/via_drv.h
39149+++ b/drivers/gpu/drm/via/via_drv.h
39150@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
39151 typedef uint32_t maskarray_t[5];
39152
39153 typedef struct drm_via_irq {
39154- atomic_t irq_received;
39155+ atomic_unchecked_t irq_received;
39156 uint32_t pending_mask;
39157 uint32_t enable_mask;
39158 wait_queue_head_t irq_queue;
39159@@ -75,7 +75,7 @@ typedef struct drm_via_private {
39160 struct timeval last_vblank;
39161 int last_vblank_valid;
39162 unsigned usec_per_vblank;
39163- atomic_t vbl_received;
39164+ atomic_unchecked_t vbl_received;
39165 drm_via_state_t hc_state;
39166 char pci_buf[VIA_PCI_BUF_SIZE];
39167 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
39168diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
39169index ac98964..5dbf512 100644
39170--- a/drivers/gpu/drm/via/via_irq.c
39171+++ b/drivers/gpu/drm/via/via_irq.c
39172@@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
39173 if (crtc != 0)
39174 return 0;
39175
39176- return atomic_read(&dev_priv->vbl_received);
39177+ return atomic_read_unchecked(&dev_priv->vbl_received);
39178 }
39179
39180 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
39181@@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
39182
39183 status = VIA_READ(VIA_REG_INTERRUPT);
39184 if (status & VIA_IRQ_VBLANK_PENDING) {
39185- atomic_inc(&dev_priv->vbl_received);
39186- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
39187+ atomic_inc_unchecked(&dev_priv->vbl_received);
39188+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
39189 do_gettimeofday(&cur_vblank);
39190 if (dev_priv->last_vblank_valid) {
39191 dev_priv->usec_per_vblank =
39192@@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
39193 dev_priv->last_vblank = cur_vblank;
39194 dev_priv->last_vblank_valid = 1;
39195 }
39196- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
39197+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
39198 DRM_DEBUG("US per vblank is: %u\n",
39199 dev_priv->usec_per_vblank);
39200 }
39201@@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
39202
39203 for (i = 0; i < dev_priv->num_irqs; ++i) {
39204 if (status & cur_irq->pending_mask) {
39205- atomic_inc(&cur_irq->irq_received);
39206+ atomic_inc_unchecked(&cur_irq->irq_received);
39207 DRM_WAKEUP(&cur_irq->irq_queue);
39208 handled = 1;
39209 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
39210@@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
39211 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
39212 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
39213 masks[irq][4]));
39214- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
39215+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
39216 } else {
39217 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
39218 (((cur_irq_sequence =
39219- atomic_read(&cur_irq->irq_received)) -
39220+ atomic_read_unchecked(&cur_irq->irq_received)) -
39221 *sequence) <= (1 << 23)));
39222 }
39223 *sequence = cur_irq_sequence;
39224@@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
39225 }
39226
39227 for (i = 0; i < dev_priv->num_irqs; ++i) {
39228- atomic_set(&cur_irq->irq_received, 0);
39229+ atomic_set_unchecked(&cur_irq->irq_received, 0);
39230 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
39231 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
39232 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
39233@@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
39234 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
39235 case VIA_IRQ_RELATIVE:
39236 irqwait->request.sequence +=
39237- atomic_read(&cur_irq->irq_received);
39238+ atomic_read_unchecked(&cur_irq->irq_received);
39239 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
39240 case VIA_IRQ_ABSOLUTE:
39241 break;
39242diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
39243index 13aeda7..4a952d1 100644
39244--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
39245+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
39246@@ -290,7 +290,7 @@ struct vmw_private {
39247 * Fencing and IRQs.
39248 */
39249
39250- atomic_t marker_seq;
39251+ atomic_unchecked_t marker_seq;
39252 wait_queue_head_t fence_queue;
39253 wait_queue_head_t fifo_queue;
39254 int fence_queue_waiters; /* Protected by hw_mutex */
39255diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
39256index 3eb1486..0a47ee9 100644
39257--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
39258+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
39259@@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
39260 (unsigned int) min,
39261 (unsigned int) fifo->capabilities);
39262
39263- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
39264+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
39265 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
39266 vmw_marker_queue_init(&fifo->marker_queue);
39267 return vmw_fifo_send_fence(dev_priv, &dummy);
39268@@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
39269 if (reserveable)
39270 iowrite32(bytes, fifo_mem +
39271 SVGA_FIFO_RESERVED);
39272- return fifo_mem + (next_cmd >> 2);
39273+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
39274 } else {
39275 need_bounce = true;
39276 }
39277@@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
39278
39279 fm = vmw_fifo_reserve(dev_priv, bytes);
39280 if (unlikely(fm == NULL)) {
39281- *seqno = atomic_read(&dev_priv->marker_seq);
39282+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
39283 ret = -ENOMEM;
39284 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
39285 false, 3*HZ);
39286@@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
39287 }
39288
39289 do {
39290- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
39291+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
39292 } while (*seqno == 0);
39293
39294 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
39295diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
39296index c509d40..3b640c3 100644
39297--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
39298+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
39299@@ -138,7 +138,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
39300 int ret;
39301
39302 num_clips = arg->num_clips;
39303- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
39304+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
39305
39306 if (unlikely(num_clips == 0))
39307 return 0;
39308@@ -222,7 +222,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
39309 int ret;
39310
39311 num_clips = arg->num_clips;
39312- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
39313+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
39314
39315 if (unlikely(num_clips == 0))
39316 return 0;
39317diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
39318index 4640adb..e1384ed 100644
39319--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
39320+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
39321@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
39322 * emitted. Then the fence is stale and signaled.
39323 */
39324
39325- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
39326+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
39327 > VMW_FENCE_WRAP);
39328
39329 return ret;
39330@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
39331
39332 if (fifo_idle)
39333 down_read(&fifo_state->rwsem);
39334- signal_seq = atomic_read(&dev_priv->marker_seq);
39335+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
39336 ret = 0;
39337
39338 for (;;) {
39339diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
39340index 8a8725c2..afed796 100644
39341--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
39342+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
39343@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
39344 while (!vmw_lag_lt(queue, us)) {
39345 spin_lock(&queue->lock);
39346 if (list_empty(&queue->head))
39347- seqno = atomic_read(&dev_priv->marker_seq);
39348+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
39349 else {
39350 marker = list_first_entry(&queue->head,
39351 struct vmw_marker, head);
39352diff --git a/drivers/gpu/host1x/drm/dc.c b/drivers/gpu/host1x/drm/dc.c
39353index 5360e5a..c2c0d26 100644
39354--- a/drivers/gpu/host1x/drm/dc.c
39355+++ b/drivers/gpu/host1x/drm/dc.c
39356@@ -1004,7 +1004,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
39357 }
39358
39359 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
39360- dc->debugfs_files[i].data = dc;
39361+ *(void **)&dc->debugfs_files[i].data = dc;
39362
39363 err = drm_debugfs_create_files(dc->debugfs_files,
39364 ARRAY_SIZE(debugfs_files),
39365diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
39366index 36668d1..9f4ccb0 100644
39367--- a/drivers/hid/hid-core.c
39368+++ b/drivers/hid/hid-core.c
39369@@ -63,6 +63,8 @@ struct hid_report *hid_register_report(struct hid_device *device, unsigned type,
39370 struct hid_report_enum *report_enum = device->report_enum + type;
39371 struct hid_report *report;
39372
39373+ if (id >= HID_MAX_IDS)
39374+ return NULL;
39375 if (report_enum->report_id_hash[id])
39376 return report_enum->report_id_hash[id];
39377
39378@@ -404,8 +406,10 @@ static int hid_parser_global(struct hid_parser *parser, struct hid_item *item)
39379
39380 case HID_GLOBAL_ITEM_TAG_REPORT_ID:
39381 parser->global.report_id = item_udata(item);
39382- if (parser->global.report_id == 0) {
39383- hid_err(parser->device, "report_id 0 is invalid\n");
39384+ if (parser->global.report_id == 0 ||
39385+ parser->global.report_id >= HID_MAX_IDS) {
39386+ hid_err(parser->device, "report_id %u is invalid\n",
39387+ parser->global.report_id);
39388 return -1;
39389 }
39390 return 0;
39391@@ -575,7 +579,7 @@ static void hid_close_report(struct hid_device *device)
39392 for (i = 0; i < HID_REPORT_TYPES; i++) {
39393 struct hid_report_enum *report_enum = device->report_enum + i;
39394
39395- for (j = 0; j < 256; j++) {
39396+ for (j = 0; j < HID_MAX_IDS; j++) {
39397 struct hid_report *report = report_enum->report_id_hash[j];
39398 if (report)
39399 hid_free_report(report);
39400@@ -755,6 +759,56 @@ int hid_parse_report(struct hid_device *hid, __u8 *start, unsigned size)
39401 }
39402 EXPORT_SYMBOL_GPL(hid_parse_report);
39403
39404+static const char * const hid_report_names[] = {
39405+ "HID_INPUT_REPORT",
39406+ "HID_OUTPUT_REPORT",
39407+ "HID_FEATURE_REPORT",
39408+};
39409+/**
39410+ * hid_validate_report - validate existing device report
39411+ *
39412+ * @device: hid device
39413+ * @type: which report type to examine
39414+ * @id: which report ID to examine (0 for first)
39415+ * @fields: expected number of fields
39416+ * @report_counts: expected number of values per field
39417+ *
39418+ * Validate the report details after parsing.
39419+ */
39420+struct hid_report *hid_validate_report(struct hid_device *hid,
39421+ unsigned int type, unsigned int id,
39422+ unsigned int fields,
39423+ unsigned int report_counts)
39424+{
39425+ struct hid_report *report;
39426+ unsigned int i;
39427+
39428+ if (type > HID_FEATURE_REPORT) {
39429+ hid_err(hid, "invalid HID report %u\n", type);
39430+ return NULL;
39431+ }
39432+
39433+ report = hid->report_enum[type].report_id_hash[id];
39434+ if (!report) {
39435+ hid_err(hid, "missing %s %u\n", hid_report_names[type], id);
39436+ return NULL;
39437+ }
39438+ if (report->maxfield < fields) {
39439+ hid_err(hid, "not enough fields in %s %u\n",
39440+ hid_report_names[type], id);
39441+ return NULL;
39442+ }
39443+ for (i = 0; i < fields; i++) {
39444+ if (report->field[i]->report_count < report_counts) {
39445+ hid_err(hid, "not enough values in %s %u fields\n",
39446+ hid_report_names[type], id);
39447+ return NULL;
39448+ }
39449+ }
39450+ return report;
39451+}
39452+EXPORT_SYMBOL_GPL(hid_validate_report);
39453+
39454 /**
39455 * hid_open_report - open a driver-specific device report
39456 *
39457@@ -1152,7 +1206,12 @@ EXPORT_SYMBOL_GPL(hid_output_report);
39458
39459 int hid_set_field(struct hid_field *field, unsigned offset, __s32 value)
39460 {
39461- unsigned size = field->report_size;
39462+ unsigned size;
39463+
39464+ if (!field)
39465+ return -1;
39466+
39467+ size = field->report_size;
39468
39469 hid_dump_input(field->report->device, field->usage + offset, value);
39470
39471@@ -2285,7 +2344,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
39472
39473 int hid_add_device(struct hid_device *hdev)
39474 {
39475- static atomic_t id = ATOMIC_INIT(0);
39476+ static atomic_unchecked_t id = ATOMIC_INIT(0);
39477 int ret;
39478
39479 if (WARN_ON(hdev->status & HID_STAT_ADDED))
39480@@ -2319,7 +2378,7 @@ int hid_add_device(struct hid_device *hdev)
39481 /* XXX hack, any other cleaner solution after the driver core
39482 * is converted to allow more than 20 bytes as the device name? */
39483 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
39484- hdev->vendor, hdev->product, atomic_inc_return(&id));
39485+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
39486
39487 hid_debug_register(hdev, dev_name(&hdev->dev));
39488 ret = device_add(&hdev->dev);
39489diff --git a/drivers/hid/hid-lenovo-tpkbd.c b/drivers/hid/hid-lenovo-tpkbd.c
39490index 07837f5..b697ada 100644
39491--- a/drivers/hid/hid-lenovo-tpkbd.c
39492+++ b/drivers/hid/hid-lenovo-tpkbd.c
39493@@ -341,6 +341,11 @@ static int tpkbd_probe_tp(struct hid_device *hdev)
39494 char *name_mute, *name_micmute;
39495 int ret;
39496
39497+ /* Validate required reports. */
39498+ if (!hid_validate_report(hdev, HID_OUTPUT_REPORT, 4, 4, 1) ||
39499+ !hid_validate_report(hdev, HID_OUTPUT_REPORT, 3, 1, 2))
39500+ return -ENODEV;
39501+
39502 if (sysfs_create_group(&hdev->dev.kobj,
39503 &tpkbd_attr_group_pointer)) {
39504 hid_warn(hdev, "Could not create sysfs group\n");
39505diff --git a/drivers/hid/hid-lg2ff.c b/drivers/hid/hid-lg2ff.c
39506index b3cd150..9805197 100644
39507--- a/drivers/hid/hid-lg2ff.c
39508+++ b/drivers/hid/hid-lg2ff.c
39509@@ -64,26 +64,13 @@ int lg2ff_init(struct hid_device *hid)
39510 struct hid_report *report;
39511 struct hid_input *hidinput = list_entry(hid->inputs.next,
39512 struct hid_input, list);
39513- struct list_head *report_list =
39514- &hid->report_enum[HID_OUTPUT_REPORT].report_list;
39515 struct input_dev *dev = hidinput->input;
39516 int error;
39517
39518- if (list_empty(report_list)) {
39519- hid_err(hid, "no output report found\n");
39520+ /* Check that the report looks ok */
39521+ report = hid_validate_report(hid, HID_OUTPUT_REPORT, 0, 1, 7);
39522+ if (!report)
39523 return -ENODEV;
39524- }
39525-
39526- report = list_entry(report_list->next, struct hid_report, list);
39527-
39528- if (report->maxfield < 1) {
39529- hid_err(hid, "output report is empty\n");
39530- return -ENODEV;
39531- }
39532- if (report->field[0]->report_count < 7) {
39533- hid_err(hid, "not enough values in the field\n");
39534- return -ENODEV;
39535- }
39536
39537 lg2ff = kmalloc(sizeof(struct lg2ff_device), GFP_KERNEL);
39538 if (!lg2ff)
39539diff --git a/drivers/hid/hid-lg3ff.c b/drivers/hid/hid-lg3ff.c
39540index e52f181..53ac79b 100644
39541--- a/drivers/hid/hid-lg3ff.c
39542+++ b/drivers/hid/hid-lg3ff.c
39543@@ -66,10 +66,11 @@ static int hid_lg3ff_play(struct input_dev *dev, void *data,
39544 int x, y;
39545
39546 /*
39547- * Maxusage should always be 63 (maximum fields)
39548- * likely a better way to ensure this data is clean
39549+ * Available values in the field should always be 63, but we only use up to
39550+ * 35. Instead, clear the entire area, however big it is.
39551 */
39552- memset(report->field[0]->value, 0, sizeof(__s32)*report->field[0]->maxusage);
39553+ memset(report->field[0]->value, 0,
39554+ sizeof(__s32) * report->field[0]->report_count);
39555
39556 switch (effect->type) {
39557 case FF_CONSTANT:
39558@@ -129,32 +130,14 @@ static const signed short ff3_joystick_ac[] = {
39559 int lg3ff_init(struct hid_device *hid)
39560 {
39561 struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list);
39562- struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list;
39563 struct input_dev *dev = hidinput->input;
39564- struct hid_report *report;
39565- struct hid_field *field;
39566 const signed short *ff_bits = ff3_joystick_ac;
39567 int error;
39568 int i;
39569
39570- /* Find the report to use */
39571- if (list_empty(report_list)) {
39572- hid_err(hid, "No output report found\n");
39573- return -1;
39574- }
39575-
39576 /* Check that the report looks ok */
39577- report = list_entry(report_list->next, struct hid_report, list);
39578- if (!report) {
39579- hid_err(hid, "NULL output report\n");
39580- return -1;
39581- }
39582-
39583- field = report->field[0];
39584- if (!field) {
39585- hid_err(hid, "NULL field\n");
39586- return -1;
39587- }
39588+ if (!hid_validate_report(hid, HID_OUTPUT_REPORT, 0, 1, 35))
39589+ return -ENODEV;
39590
39591 /* Assume single fixed device G940 */
39592 for (i = 0; ff_bits[i] >= 0; i++)
39593diff --git a/drivers/hid/hid-lg4ff.c b/drivers/hid/hid-lg4ff.c
39594index 0ddae2a..8b89f0f 100644
39595--- a/drivers/hid/hid-lg4ff.c
39596+++ b/drivers/hid/hid-lg4ff.c
39597@@ -484,34 +484,16 @@ static enum led_brightness lg4ff_led_get_brightness(struct led_classdev *led_cde
39598 int lg4ff_init(struct hid_device *hid)
39599 {
39600 struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list);
39601- struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list;
39602 struct input_dev *dev = hidinput->input;
39603- struct hid_report *report;
39604- struct hid_field *field;
39605 struct lg4ff_device_entry *entry;
39606 struct lg_drv_data *drv_data;
39607 struct usb_device_descriptor *udesc;
39608 int error, i, j;
39609 __u16 bcdDevice, rev_maj, rev_min;
39610
39611- /* Find the report to use */
39612- if (list_empty(report_list)) {
39613- hid_err(hid, "No output report found\n");
39614- return -1;
39615- }
39616-
39617 /* Check that the report looks ok */
39618- report = list_entry(report_list->next, struct hid_report, list);
39619- if (!report) {
39620- hid_err(hid, "NULL output report\n");
39621+ if (!hid_validate_report(hid, HID_OUTPUT_REPORT, 0, 1, 7))
39622 return -1;
39623- }
39624-
39625- field = report->field[0];
39626- if (!field) {
39627- hid_err(hid, "NULL field\n");
39628- return -1;
39629- }
39630
39631 /* Check what wheel has been connected */
39632 for (i = 0; i < ARRAY_SIZE(lg4ff_devices); i++) {
39633diff --git a/drivers/hid/hid-lgff.c b/drivers/hid/hid-lgff.c
39634index d7ea8c8..a84fb40 100644
39635--- a/drivers/hid/hid-lgff.c
39636+++ b/drivers/hid/hid-lgff.c
39637@@ -128,27 +128,14 @@ static void hid_lgff_set_autocenter(struct input_dev *dev, u16 magnitude)
39638 int lgff_init(struct hid_device* hid)
39639 {
39640 struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list);
39641- struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list;
39642 struct input_dev *dev = hidinput->input;
39643- struct hid_report *report;
39644- struct hid_field *field;
39645 const signed short *ff_bits = ff_joystick;
39646 int error;
39647 int i;
39648
39649- /* Find the report to use */
39650- if (list_empty(report_list)) {
39651- hid_err(hid, "No output report found\n");
39652- return -1;
39653- }
39654-
39655 /* Check that the report looks ok */
39656- report = list_entry(report_list->next, struct hid_report, list);
39657- field = report->field[0];
39658- if (!field) {
39659- hid_err(hid, "NULL field\n");
39660- return -1;
39661- }
39662+ if (!hid_validate_report(hid, HID_OUTPUT_REPORT, 0, 1, 7))
39663+ return -ENODEV;
39664
39665 for (i = 0; i < ARRAY_SIZE(devices); i++) {
39666 if (dev->id.vendor == devices[i].idVendor &&
39667diff --git a/drivers/hid/hid-logitech-dj.c b/drivers/hid/hid-logitech-dj.c
39668index cd33084..7b99c2a 100644
39669--- a/drivers/hid/hid-logitech-dj.c
39670+++ b/drivers/hid/hid-logitech-dj.c
39671@@ -461,7 +461,7 @@ static int logi_dj_recv_send_report(struct dj_receiver_dev *djrcv_dev,
39672 struct hid_report *report;
39673 struct hid_report_enum *output_report_enum;
39674 u8 *data = (u8 *)(&dj_report->device_index);
39675- int i;
39676+ unsigned int i, length;
39677
39678 output_report_enum = &hdev->report_enum[HID_OUTPUT_REPORT];
39679 report = output_report_enum->report_id_hash[REPORT_ID_DJ_SHORT];
39680@@ -471,7 +471,9 @@ static int logi_dj_recv_send_report(struct dj_receiver_dev *djrcv_dev,
39681 return -ENODEV;
39682 }
39683
39684- for (i = 0; i < report->field[0]->report_count; i++)
39685+ length = min_t(size_t, sizeof(*dj_report) - 1,
39686+ report->field[0]->report_count);
39687+ for (i = 0; i < length; i++)
39688 report->field[0]->value[i] = data[i];
39689
39690 hid_hw_request(hdev, report, HID_REQ_SET_REPORT);
39691@@ -783,6 +785,12 @@ static int logi_dj_probe(struct hid_device *hdev,
39692 goto hid_parse_fail;
39693 }
39694
39695+ if (!hid_validate_report(hdev, HID_OUTPUT_REPORT, REPORT_ID_DJ_SHORT,
39696+ 1, 3)) {
39697+ retval = -ENODEV;
39698+ goto hid_parse_fail;
39699+ }
39700+
39701 /* Starts the usb device and connects to upper interfaces hiddev and
39702 * hidraw */
39703 retval = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
39704diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c
39705index cb0e361..2aa275e 100644
39706--- a/drivers/hid/hid-multitouch.c
39707+++ b/drivers/hid/hid-multitouch.c
39708@@ -330,9 +330,18 @@ static void mt_feature_mapping(struct hid_device *hdev,
39709 break;
39710 }
39711 }
39712+ /* Ignore if value index is out of bounds. */
39713+ if (td->inputmode_index < 0 ||
39714+ td->inputmode_index >= field->report_count) {
39715+ dev_err(&hdev->dev, "HID_DG_INPUTMODE out of range\n");
39716+ td->inputmode = -1;
39717+ }
39718
39719 break;
39720 case HID_DG_CONTACTMAX:
39721+ /* Ignore if value count is out of bounds. */
39722+ if (field->report_count < 1)
39723+ break;
39724 td->maxcontact_report_id = field->report->id;
39725 td->maxcontacts = field->value[0];
39726 if (!td->maxcontacts &&
39727@@ -743,15 +752,21 @@ static void mt_touch_report(struct hid_device *hid, struct hid_report *report)
39728 unsigned count;
39729 int r, n;
39730
39731+ if (report->maxfield == 0)
39732+ return;
39733+
39734 /*
39735 * Includes multi-packet support where subsequent
39736 * packets are sent with zero contactcount.
39737 */
39738- if (td->cc_index >= 0) {
39739- struct hid_field *field = report->field[td->cc_index];
39740- int value = field->value[td->cc_value_index];
39741- if (value)
39742- td->num_expected = value;
39743+ if (td->cc_index >= 0 && td->cc_index < report->maxfield) {
39744+ field = report->field[td->cc_index];
39745+ if (td->cc_value_index >= 0 &&
39746+ td->cc_value_index < field->report_count) {
39747+ int value = field->value[td->cc_value_index];
39748+ if (value)
39749+ td->num_expected = value;
39750+ }
39751 }
39752
39753 for (r = 0; r < report->maxfield; r++) {
39754diff --git a/drivers/hid/hid-ntrig.c b/drivers/hid/hid-ntrig.c
39755index ef95102..5482156 100644
39756--- a/drivers/hid/hid-ntrig.c
39757+++ b/drivers/hid/hid-ntrig.c
39758@@ -115,7 +115,8 @@ static inline int ntrig_get_mode(struct hid_device *hdev)
39759 struct hid_report *report = hdev->report_enum[HID_FEATURE_REPORT].
39760 report_id_hash[0x0d];
39761
39762- if (!report)
39763+ if (!report || report->maxfield < 1 ||
39764+ report->field[0]->report_count < 1)
39765 return -EINVAL;
39766
39767 hid_hw_request(hdev, report, HID_REQ_GET_REPORT);
39768diff --git a/drivers/hid/hid-picolcd_core.c b/drivers/hid/hid-picolcd_core.c
39769index b48092d..72bba1e 100644
39770--- a/drivers/hid/hid-picolcd_core.c
39771+++ b/drivers/hid/hid-picolcd_core.c
39772@@ -290,7 +290,7 @@ static ssize_t picolcd_operation_mode_store(struct device *dev,
39773 buf += 10;
39774 cnt -= 10;
39775 }
39776- if (!report)
39777+ if (!report || report->maxfield < 1)
39778 return -EINVAL;
39779
39780 while (cnt > 0 && (buf[cnt-1] == '\n' || buf[cnt-1] == '\r'))
39781diff --git a/drivers/hid/hid-pl.c b/drivers/hid/hid-pl.c
39782index d29112f..2dcd7d9 100644
39783--- a/drivers/hid/hid-pl.c
39784+++ b/drivers/hid/hid-pl.c
39785@@ -132,8 +132,14 @@ static int plff_init(struct hid_device *hid)
39786 strong = &report->field[0]->value[2];
39787 weak = &report->field[0]->value[3];
39788 debug("detected single-field device");
39789- } else if (report->maxfield >= 4 && report->field[0]->maxusage == 1 &&
39790- report->field[0]->usage[0].hid == (HID_UP_LED | 0x43)) {
39791+ } else if (report->field[0]->maxusage == 1 &&
39792+ report->field[0]->usage[0].hid ==
39793+ (HID_UP_LED | 0x43) &&
39794+ report->maxfield >= 4 &&
39795+ report->field[0]->report_count >= 1 &&
39796+ report->field[1]->report_count >= 1 &&
39797+ report->field[2]->report_count >= 1 &&
39798+ report->field[3]->report_count >= 1) {
39799 report->field[0]->value[0] = 0x00;
39800 report->field[1]->value[0] = 0x00;
39801 strong = &report->field[2]->value[0];
39802diff --git a/drivers/hid/hid-sensor-hub.c b/drivers/hid/hid-sensor-hub.c
39803index ca749810..aa34755 100644
39804--- a/drivers/hid/hid-sensor-hub.c
39805+++ b/drivers/hid/hid-sensor-hub.c
39806@@ -221,7 +221,8 @@ int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
39807
39808 mutex_lock(&data->mutex);
39809 report = sensor_hub_report(report_id, hsdev->hdev, HID_FEATURE_REPORT);
39810- if (!report || (field_index >= report->maxfield)) {
39811+ if (!report || (field_index >= report->maxfield) ||
39812+ report->field[field_index]->report_count < 1) {
39813 ret = -EINVAL;
39814 goto done_proc;
39815 }
39816diff --git a/drivers/hid/hid-steelseries.c b/drivers/hid/hid-steelseries.c
39817index d164911..ef42e86 100644
39818--- a/drivers/hid/hid-steelseries.c
39819+++ b/drivers/hid/hid-steelseries.c
39820@@ -249,6 +249,11 @@ static int steelseries_srws1_probe(struct hid_device *hdev,
39821 goto err_free;
39822 }
39823
39824+ if (!hid_validate_report(hdev, HID_OUTPUT_REPORT, 0, 1, 16)) {
39825+ ret = -ENODEV;
39826+ goto err_free;
39827+ }
39828+
39829 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
39830 if (ret) {
39831 hid_err(hdev, "hw start failed\n");
39832diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
39833index c13fb5b..55a3802 100644
39834--- a/drivers/hid/hid-wiimote-debug.c
39835+++ b/drivers/hid/hid-wiimote-debug.c
39836@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
39837 else if (size == 0)
39838 return -EIO;
39839
39840- if (copy_to_user(u, buf, size))
39841+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
39842 return -EFAULT;
39843
39844 *off += size;
39845diff --git a/drivers/hid/hid-zpff.c b/drivers/hid/hid-zpff.c
39846index 6ec28a3..b124991 100644
39847--- a/drivers/hid/hid-zpff.c
39848+++ b/drivers/hid/hid-zpff.c
39849@@ -68,22 +68,12 @@ static int zpff_init(struct hid_device *hid)
39850 struct hid_report *report;
39851 struct hid_input *hidinput = list_entry(hid->inputs.next,
39852 struct hid_input, list);
39853- struct list_head *report_list =
39854- &hid->report_enum[HID_OUTPUT_REPORT].report_list;
39855 struct input_dev *dev = hidinput->input;
39856 int error;
39857
39858- if (list_empty(report_list)) {
39859- hid_err(hid, "no output report found\n");
39860+ report = hid_validate_report(hid, HID_OUTPUT_REPORT, 0, 4, 1);
39861+ if (!report)
39862 return -ENODEV;
39863- }
39864-
39865- report = list_entry(report_list->next, struct hid_report, list);
39866-
39867- if (report->maxfield < 4) {
39868- hid_err(hid, "not enough fields in report\n");
39869- return -ENODEV;
39870- }
39871
39872 zpff = kzalloc(sizeof(struct zpff_device), GFP_KERNEL);
39873 if (!zpff)
39874diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
39875index fc307e0..2b255e8 100644
39876--- a/drivers/hid/uhid.c
39877+++ b/drivers/hid/uhid.c
39878@@ -47,7 +47,7 @@ struct uhid_device {
39879 struct mutex report_lock;
39880 wait_queue_head_t report_wait;
39881 atomic_t report_done;
39882- atomic_t report_id;
39883+ atomic_unchecked_t report_id;
39884 struct uhid_event report_buf;
39885 };
39886
39887@@ -187,7 +187,7 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum,
39888
39889 spin_lock_irqsave(&uhid->qlock, flags);
39890 ev->type = UHID_FEATURE;
39891- ev->u.feature.id = atomic_inc_return(&uhid->report_id);
39892+ ev->u.feature.id = atomic_inc_return_unchecked(&uhid->report_id);
39893 ev->u.feature.rnum = rnum;
39894 ev->u.feature.rtype = report_type;
39895
39896@@ -471,7 +471,7 @@ static int uhid_dev_feature_answer(struct uhid_device *uhid,
39897 spin_lock_irqsave(&uhid->qlock, flags);
39898
39899 /* id for old report; drop it silently */
39900- if (atomic_read(&uhid->report_id) != ev->u.feature_answer.id)
39901+ if (atomic_read_unchecked(&uhid->report_id) != ev->u.feature_answer.id)
39902 goto unlock;
39903 if (atomic_read(&uhid->report_done))
39904 goto unlock;
39905diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
39906index 6de6c98..18319e9 100644
39907--- a/drivers/hv/channel.c
39908+++ b/drivers/hv/channel.c
39909@@ -406,8 +406,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
39910 int ret = 0;
39911 int t;
39912
39913- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
39914- atomic_inc(&vmbus_connection.next_gpadl_handle);
39915+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
39916+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
39917
39918 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
39919 if (ret)
39920diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
39921index 88f4096..e50452e 100644
39922--- a/drivers/hv/hv.c
39923+++ b/drivers/hv/hv.c
39924@@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
39925 u64 output_address = (output) ? virt_to_phys(output) : 0;
39926 u32 output_address_hi = output_address >> 32;
39927 u32 output_address_lo = output_address & 0xFFFFFFFF;
39928- void *hypercall_page = hv_context.hypercall_page;
39929+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
39930
39931 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
39932 "=a"(hv_status_lo) : "d" (control_hi),
39933diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
39934index deb5c25..ed2d4fd 100644
39935--- a/drivers/hv/hv_balloon.c
39936+++ b/drivers/hv/hv_balloon.c
39937@@ -464,7 +464,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
39938
39939 module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
39940 MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
39941-static atomic_t trans_id = ATOMIC_INIT(0);
39942+static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
39943
39944 static int dm_ring_size = (5 * PAGE_SIZE);
39945
39946@@ -825,7 +825,7 @@ static void hot_add_req(struct work_struct *dummy)
39947 memset(&resp, 0, sizeof(struct dm_hot_add_response));
39948 resp.hdr.type = DM_MEM_HOT_ADD_RESPONSE;
39949 resp.hdr.size = sizeof(struct dm_hot_add_response);
39950- resp.hdr.trans_id = atomic_inc_return(&trans_id);
39951+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
39952
39953 #ifdef CONFIG_MEMORY_HOTPLUG
39954 pg_start = dm->ha_wrk.ha_page_range.finfo.start_page;
39955@@ -960,7 +960,7 @@ static void post_status(struct hv_dynmem_device *dm)
39956 memset(&status, 0, sizeof(struct dm_status));
39957 status.hdr.type = DM_STATUS_REPORT;
39958 status.hdr.size = sizeof(struct dm_status);
39959- status.hdr.trans_id = atomic_inc_return(&trans_id);
39960+ status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
39961
39962 /*
39963 * The host expects the guest to report free memory.
39964@@ -980,7 +980,7 @@ static void post_status(struct hv_dynmem_device *dm)
39965 * send the status. This can happen if we were interrupted
39966 * after we picked our transaction ID.
39967 */
39968- if (status.hdr.trans_id != atomic_read(&trans_id))
39969+ if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
39970 return;
39971
39972 vmbus_sendpacket(dm->dev->channel, &status,
39973@@ -1081,7 +1081,7 @@ static void balloon_up(struct work_struct *dummy)
39974 bl_resp = (struct dm_balloon_response *)send_buffer;
39975 memset(send_buffer, 0, PAGE_SIZE);
39976 bl_resp->hdr.type = DM_BALLOON_RESPONSE;
39977- bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
39978+ bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
39979 bl_resp->hdr.size = sizeof(struct dm_balloon_response);
39980 bl_resp->more_pages = 1;
39981
39982@@ -1152,7 +1152,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
39983
39984 memset(&resp, 0, sizeof(struct dm_unballoon_response));
39985 resp.hdr.type = DM_UNBALLOON_RESPONSE;
39986- resp.hdr.trans_id = atomic_inc_return(&trans_id);
39987+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
39988 resp.hdr.size = sizeof(struct dm_unballoon_response);
39989
39990 vmbus_sendpacket(dm_device.dev->channel, &resp,
39991@@ -1215,7 +1215,7 @@ static void version_resp(struct hv_dynmem_device *dm,
39992 memset(&version_req, 0, sizeof(struct dm_version_request));
39993 version_req.hdr.type = DM_VERSION_REQUEST;
39994 version_req.hdr.size = sizeof(struct dm_version_request);
39995- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
39996+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
39997 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
39998 version_req.is_last_attempt = 1;
39999
40000@@ -1385,7 +1385,7 @@ static int balloon_probe(struct hv_device *dev,
40001 memset(&version_req, 0, sizeof(struct dm_version_request));
40002 version_req.hdr.type = DM_VERSION_REQUEST;
40003 version_req.hdr.size = sizeof(struct dm_version_request);
40004- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
40005+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40006 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
40007 version_req.is_last_attempt = 0;
40008
40009@@ -1416,7 +1416,7 @@ static int balloon_probe(struct hv_device *dev,
40010 memset(&cap_msg, 0, sizeof(struct dm_capabilities));
40011 cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
40012 cap_msg.hdr.size = sizeof(struct dm_capabilities);
40013- cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
40014+ cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40015
40016 cap_msg.caps.cap_bits.balloon = 1;
40017 cap_msg.caps.cap_bits.hot_add = 1;
40018diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
40019index d84918f..7f38f9f 100644
40020--- a/drivers/hv/hyperv_vmbus.h
40021+++ b/drivers/hv/hyperv_vmbus.h
40022@@ -595,7 +595,7 @@ enum vmbus_connect_state {
40023 struct vmbus_connection {
40024 enum vmbus_connect_state conn_state;
40025
40026- atomic_t next_gpadl_handle;
40027+ atomic_unchecked_t next_gpadl_handle;
40028
40029 /*
40030 * Represents channel interrupts. Each bit position represents a
40031diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
40032index e8e071f..5b4b245 100644
40033--- a/drivers/hv/vmbus_drv.c
40034+++ b/drivers/hv/vmbus_drv.c
40035@@ -672,10 +672,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
40036 {
40037 int ret = 0;
40038
40039- static atomic_t device_num = ATOMIC_INIT(0);
40040+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
40041
40042 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
40043- atomic_inc_return(&device_num));
40044+ atomic_inc_return_unchecked(&device_num));
40045
40046 child_device_obj->device.bus = &hv_bus;
40047 child_device_obj->device.parent = &hv_acpi_dev->dev;
40048diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
40049index 6351aba..dc4aaf4 100644
40050--- a/drivers/hwmon/acpi_power_meter.c
40051+++ b/drivers/hwmon/acpi_power_meter.c
40052@@ -117,7 +117,7 @@ struct sensor_template {
40053 struct device_attribute *devattr,
40054 const char *buf, size_t count);
40055 int index;
40056-};
40057+} __do_const;
40058
40059 /* Averaging interval */
40060 static int update_avg_interval(struct acpi_power_meter_resource *resource)
40061@@ -629,7 +629,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
40062 struct sensor_template *attrs)
40063 {
40064 struct device *dev = &resource->acpi_dev->dev;
40065- struct sensor_device_attribute *sensors =
40066+ sensor_device_attribute_no_const *sensors =
40067 &resource->sensors[resource->num_sensors];
40068 int res = 0;
40069
40070diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
40071index 62c2e32..8f2859a 100644
40072--- a/drivers/hwmon/applesmc.c
40073+++ b/drivers/hwmon/applesmc.c
40074@@ -1084,7 +1084,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
40075 {
40076 struct applesmc_node_group *grp;
40077 struct applesmc_dev_attr *node;
40078- struct attribute *attr;
40079+ attribute_no_const *attr;
40080 int ret, i;
40081
40082 for (grp = groups; grp->format; grp++) {
40083diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
40084index b25c643..a13460d 100644
40085--- a/drivers/hwmon/asus_atk0110.c
40086+++ b/drivers/hwmon/asus_atk0110.c
40087@@ -152,10 +152,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
40088 struct atk_sensor_data {
40089 struct list_head list;
40090 struct atk_data *data;
40091- struct device_attribute label_attr;
40092- struct device_attribute input_attr;
40093- struct device_attribute limit1_attr;
40094- struct device_attribute limit2_attr;
40095+ device_attribute_no_const label_attr;
40096+ device_attribute_no_const input_attr;
40097+ device_attribute_no_const limit1_attr;
40098+ device_attribute_no_const limit2_attr;
40099 char label_attr_name[ATTR_NAME_SIZE];
40100 char input_attr_name[ATTR_NAME_SIZE];
40101 char limit1_attr_name[ATTR_NAME_SIZE];
40102@@ -275,7 +275,7 @@ static ssize_t atk_name_show(struct device *dev,
40103 static struct device_attribute atk_name_attr =
40104 __ATTR(name, 0444, atk_name_show, NULL);
40105
40106-static void atk_init_attribute(struct device_attribute *attr, char *name,
40107+static void atk_init_attribute(device_attribute_no_const *attr, char *name,
40108 sysfs_show_func show)
40109 {
40110 sysfs_attr_init(&attr->attr);
40111diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
40112index 2e5e2dc..5208b31 100644
40113--- a/drivers/hwmon/coretemp.c
40114+++ b/drivers/hwmon/coretemp.c
40115@@ -785,7 +785,7 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
40116 return NOTIFY_OK;
40117 }
40118
40119-static struct notifier_block coretemp_cpu_notifier __refdata = {
40120+static struct notifier_block coretemp_cpu_notifier = {
40121 .notifier_call = coretemp_cpu_callback,
40122 };
40123
40124diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
40125index 1429f6e..ee03d59 100644
40126--- a/drivers/hwmon/ibmaem.c
40127+++ b/drivers/hwmon/ibmaem.c
40128@@ -926,7 +926,7 @@ static int aem_register_sensors(struct aem_data *data,
40129 struct aem_rw_sensor_template *rw)
40130 {
40131 struct device *dev = &data->pdev->dev;
40132- struct sensor_device_attribute *sensors = data->sensors;
40133+ sensor_device_attribute_no_const *sensors = data->sensors;
40134 int err;
40135
40136 /* Set up read-only sensors */
40137diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
40138index 708081b..fe2d4ab 100644
40139--- a/drivers/hwmon/iio_hwmon.c
40140+++ b/drivers/hwmon/iio_hwmon.c
40141@@ -73,7 +73,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
40142 {
40143 struct device *dev = &pdev->dev;
40144 struct iio_hwmon_state *st;
40145- struct sensor_device_attribute *a;
40146+ sensor_device_attribute_no_const *a;
40147 int ret, i;
40148 int in_i = 1, temp_i = 1, curr_i = 1;
40149 enum iio_chan_type type;
40150diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
40151index 9add6092..ee7ba3f 100644
40152--- a/drivers/hwmon/pmbus/pmbus_core.c
40153+++ b/drivers/hwmon/pmbus/pmbus_core.c
40154@@ -781,7 +781,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
40155 return 0;
40156 }
40157
40158-static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
40159+static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
40160 const char *name,
40161 umode_t mode,
40162 ssize_t (*show)(struct device *dev,
40163@@ -798,7 +798,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
40164 dev_attr->store = store;
40165 }
40166
40167-static void pmbus_attr_init(struct sensor_device_attribute *a,
40168+static void pmbus_attr_init(sensor_device_attribute_no_const *a,
40169 const char *name,
40170 umode_t mode,
40171 ssize_t (*show)(struct device *dev,
40172@@ -820,7 +820,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
40173 u16 reg, u8 mask)
40174 {
40175 struct pmbus_boolean *boolean;
40176- struct sensor_device_attribute *a;
40177+ sensor_device_attribute_no_const *a;
40178
40179 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
40180 if (!boolean)
40181@@ -845,7 +845,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
40182 bool update, bool readonly)
40183 {
40184 struct pmbus_sensor *sensor;
40185- struct device_attribute *a;
40186+ device_attribute_no_const *a;
40187
40188 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
40189 if (!sensor)
40190@@ -876,7 +876,7 @@ static int pmbus_add_label(struct pmbus_data *data,
40191 const char *lstring, int index)
40192 {
40193 struct pmbus_label *label;
40194- struct device_attribute *a;
40195+ device_attribute_no_const *a;
40196
40197 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
40198 if (!label)
40199diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
40200index 2507f90..1645765 100644
40201--- a/drivers/hwmon/sht15.c
40202+++ b/drivers/hwmon/sht15.c
40203@@ -169,7 +169,7 @@ struct sht15_data {
40204 int supply_uv;
40205 bool supply_uv_valid;
40206 struct work_struct update_supply_work;
40207- atomic_t interrupt_handled;
40208+ atomic_unchecked_t interrupt_handled;
40209 };
40210
40211 /**
40212@@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
40213 ret = gpio_direction_input(data->pdata->gpio_data);
40214 if (ret)
40215 return ret;
40216- atomic_set(&data->interrupt_handled, 0);
40217+ atomic_set_unchecked(&data->interrupt_handled, 0);
40218
40219 enable_irq(gpio_to_irq(data->pdata->gpio_data));
40220 if (gpio_get_value(data->pdata->gpio_data) == 0) {
40221 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
40222 /* Only relevant if the interrupt hasn't occurred. */
40223- if (!atomic_read(&data->interrupt_handled))
40224+ if (!atomic_read_unchecked(&data->interrupt_handled))
40225 schedule_work(&data->read_work);
40226 }
40227 ret = wait_event_timeout(data->wait_queue,
40228@@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
40229
40230 /* First disable the interrupt */
40231 disable_irq_nosync(irq);
40232- atomic_inc(&data->interrupt_handled);
40233+ atomic_inc_unchecked(&data->interrupt_handled);
40234 /* Then schedule a reading work struct */
40235 if (data->state != SHT15_READING_NOTHING)
40236 schedule_work(&data->read_work);
40237@@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
40238 * If not, then start the interrupt again - care here as could
40239 * have gone low in meantime so verify it hasn't!
40240 */
40241- atomic_set(&data->interrupt_handled, 0);
40242+ atomic_set_unchecked(&data->interrupt_handled, 0);
40243 enable_irq(gpio_to_irq(data->pdata->gpio_data));
40244 /* If still not occurred or another handler was scheduled */
40245 if (gpio_get_value(data->pdata->gpio_data)
40246- || atomic_read(&data->interrupt_handled))
40247+ || atomic_read_unchecked(&data->interrupt_handled))
40248 return;
40249 }
40250
40251diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
40252index 38944e9..ae9e5ed 100644
40253--- a/drivers/hwmon/via-cputemp.c
40254+++ b/drivers/hwmon/via-cputemp.c
40255@@ -296,7 +296,7 @@ static int via_cputemp_cpu_callback(struct notifier_block *nfb,
40256 return NOTIFY_OK;
40257 }
40258
40259-static struct notifier_block via_cputemp_cpu_notifier __refdata = {
40260+static struct notifier_block via_cputemp_cpu_notifier = {
40261 .notifier_call = via_cputemp_cpu_callback,
40262 };
40263
40264diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
40265index 07f01ac..d79ad3d 100644
40266--- a/drivers/i2c/busses/i2c-amd756-s4882.c
40267+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
40268@@ -43,7 +43,7 @@
40269 extern struct i2c_adapter amd756_smbus;
40270
40271 static struct i2c_adapter *s4882_adapter;
40272-static struct i2c_algorithm *s4882_algo;
40273+static i2c_algorithm_no_const *s4882_algo;
40274
40275 /* Wrapper access functions for multiplexed SMBus */
40276 static DEFINE_MUTEX(amd756_lock);
40277diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
40278index 2ca268d..c6acbdf 100644
40279--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
40280+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
40281@@ -41,7 +41,7 @@
40282 extern struct i2c_adapter *nforce2_smbus;
40283
40284 static struct i2c_adapter *s4985_adapter;
40285-static struct i2c_algorithm *s4985_algo;
40286+static i2c_algorithm_no_const *s4985_algo;
40287
40288 /* Wrapper access functions for multiplexed SMBus */
40289 static DEFINE_MUTEX(nforce2_lock);
40290diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
40291index c3ccdea..5b3dc1a 100644
40292--- a/drivers/i2c/i2c-dev.c
40293+++ b/drivers/i2c/i2c-dev.c
40294@@ -271,7 +271,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
40295 break;
40296 }
40297
40298- data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
40299+ data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
40300 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
40301 if (IS_ERR(rdwr_pa[i].buf)) {
40302 res = PTR_ERR(rdwr_pa[i].buf);
40303diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
40304index 0b510ba..4fbb5085 100644
40305--- a/drivers/ide/ide-cd.c
40306+++ b/drivers/ide/ide-cd.c
40307@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
40308 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
40309 if ((unsigned long)buf & alignment
40310 || blk_rq_bytes(rq) & q->dma_pad_mask
40311- || object_is_on_stack(buf))
40312+ || object_starts_on_stack(buf))
40313 drive->dma = 0;
40314 }
40315 }
40316diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
40317index e145931..08bfc59 100644
40318--- a/drivers/iio/industrialio-core.c
40319+++ b/drivers/iio/industrialio-core.c
40320@@ -506,7 +506,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
40321 }
40322
40323 static
40324-int __iio_device_attr_init(struct device_attribute *dev_attr,
40325+int __iio_device_attr_init(device_attribute_no_const *dev_attr,
40326 const char *postfix,
40327 struct iio_chan_spec const *chan,
40328 ssize_t (*readfunc)(struct device *dev,
40329diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
40330index 784b97c..c9ceadf 100644
40331--- a/drivers/infiniband/core/cm.c
40332+++ b/drivers/infiniband/core/cm.c
40333@@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
40334
40335 struct cm_counter_group {
40336 struct kobject obj;
40337- atomic_long_t counter[CM_ATTR_COUNT];
40338+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
40339 };
40340
40341 struct cm_counter_attribute {
40342@@ -1395,7 +1395,7 @@ static void cm_dup_req_handler(struct cm_work *work,
40343 struct ib_mad_send_buf *msg = NULL;
40344 int ret;
40345
40346- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40347+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40348 counter[CM_REQ_COUNTER]);
40349
40350 /* Quick state check to discard duplicate REQs. */
40351@@ -1779,7 +1779,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
40352 if (!cm_id_priv)
40353 return;
40354
40355- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40356+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40357 counter[CM_REP_COUNTER]);
40358 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
40359 if (ret)
40360@@ -1946,7 +1946,7 @@ static int cm_rtu_handler(struct cm_work *work)
40361 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
40362 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
40363 spin_unlock_irq(&cm_id_priv->lock);
40364- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40365+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40366 counter[CM_RTU_COUNTER]);
40367 goto out;
40368 }
40369@@ -2129,7 +2129,7 @@ static int cm_dreq_handler(struct cm_work *work)
40370 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
40371 dreq_msg->local_comm_id);
40372 if (!cm_id_priv) {
40373- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40374+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40375 counter[CM_DREQ_COUNTER]);
40376 cm_issue_drep(work->port, work->mad_recv_wc);
40377 return -EINVAL;
40378@@ -2154,7 +2154,7 @@ static int cm_dreq_handler(struct cm_work *work)
40379 case IB_CM_MRA_REP_RCVD:
40380 break;
40381 case IB_CM_TIMEWAIT:
40382- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40383+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40384 counter[CM_DREQ_COUNTER]);
40385 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
40386 goto unlock;
40387@@ -2168,7 +2168,7 @@ static int cm_dreq_handler(struct cm_work *work)
40388 cm_free_msg(msg);
40389 goto deref;
40390 case IB_CM_DREQ_RCVD:
40391- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40392+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40393 counter[CM_DREQ_COUNTER]);
40394 goto unlock;
40395 default:
40396@@ -2535,7 +2535,7 @@ static int cm_mra_handler(struct cm_work *work)
40397 ib_modify_mad(cm_id_priv->av.port->mad_agent,
40398 cm_id_priv->msg, timeout)) {
40399 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
40400- atomic_long_inc(&work->port->
40401+ atomic_long_inc_unchecked(&work->port->
40402 counter_group[CM_RECV_DUPLICATES].
40403 counter[CM_MRA_COUNTER]);
40404 goto out;
40405@@ -2544,7 +2544,7 @@ static int cm_mra_handler(struct cm_work *work)
40406 break;
40407 case IB_CM_MRA_REQ_RCVD:
40408 case IB_CM_MRA_REP_RCVD:
40409- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40410+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40411 counter[CM_MRA_COUNTER]);
40412 /* fall through */
40413 default:
40414@@ -2706,7 +2706,7 @@ static int cm_lap_handler(struct cm_work *work)
40415 case IB_CM_LAP_IDLE:
40416 break;
40417 case IB_CM_MRA_LAP_SENT:
40418- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40419+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40420 counter[CM_LAP_COUNTER]);
40421 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
40422 goto unlock;
40423@@ -2722,7 +2722,7 @@ static int cm_lap_handler(struct cm_work *work)
40424 cm_free_msg(msg);
40425 goto deref;
40426 case IB_CM_LAP_RCVD:
40427- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40428+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40429 counter[CM_LAP_COUNTER]);
40430 goto unlock;
40431 default:
40432@@ -3006,7 +3006,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
40433 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
40434 if (cur_cm_id_priv) {
40435 spin_unlock_irq(&cm.lock);
40436- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40437+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40438 counter[CM_SIDR_REQ_COUNTER]);
40439 goto out; /* Duplicate message. */
40440 }
40441@@ -3218,10 +3218,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
40442 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
40443 msg->retries = 1;
40444
40445- atomic_long_add(1 + msg->retries,
40446+ atomic_long_add_unchecked(1 + msg->retries,
40447 &port->counter_group[CM_XMIT].counter[attr_index]);
40448 if (msg->retries)
40449- atomic_long_add(msg->retries,
40450+ atomic_long_add_unchecked(msg->retries,
40451 &port->counter_group[CM_XMIT_RETRIES].
40452 counter[attr_index]);
40453
40454@@ -3431,7 +3431,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
40455 }
40456
40457 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
40458- atomic_long_inc(&port->counter_group[CM_RECV].
40459+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
40460 counter[attr_id - CM_ATTR_ID_OFFSET]);
40461
40462 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
40463@@ -3636,7 +3636,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
40464 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
40465
40466 return sprintf(buf, "%ld\n",
40467- atomic_long_read(&group->counter[cm_attr->index]));
40468+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
40469 }
40470
40471 static const struct sysfs_ops cm_counter_ops = {
40472diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
40473index 9f5ad7c..588cd84 100644
40474--- a/drivers/infiniband/core/fmr_pool.c
40475+++ b/drivers/infiniband/core/fmr_pool.c
40476@@ -98,8 +98,8 @@ struct ib_fmr_pool {
40477
40478 struct task_struct *thread;
40479
40480- atomic_t req_ser;
40481- atomic_t flush_ser;
40482+ atomic_unchecked_t req_ser;
40483+ atomic_unchecked_t flush_ser;
40484
40485 wait_queue_head_t force_wait;
40486 };
40487@@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
40488 struct ib_fmr_pool *pool = pool_ptr;
40489
40490 do {
40491- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
40492+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
40493 ib_fmr_batch_release(pool);
40494
40495- atomic_inc(&pool->flush_ser);
40496+ atomic_inc_unchecked(&pool->flush_ser);
40497 wake_up_interruptible(&pool->force_wait);
40498
40499 if (pool->flush_function)
40500@@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
40501 }
40502
40503 set_current_state(TASK_INTERRUPTIBLE);
40504- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
40505+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
40506 !kthread_should_stop())
40507 schedule();
40508 __set_current_state(TASK_RUNNING);
40509@@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
40510 pool->dirty_watermark = params->dirty_watermark;
40511 pool->dirty_len = 0;
40512 spin_lock_init(&pool->pool_lock);
40513- atomic_set(&pool->req_ser, 0);
40514- atomic_set(&pool->flush_ser, 0);
40515+ atomic_set_unchecked(&pool->req_ser, 0);
40516+ atomic_set_unchecked(&pool->flush_ser, 0);
40517 init_waitqueue_head(&pool->force_wait);
40518
40519 pool->thread = kthread_run(ib_fmr_cleanup_thread,
40520@@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
40521 }
40522 spin_unlock_irq(&pool->pool_lock);
40523
40524- serial = atomic_inc_return(&pool->req_ser);
40525+ serial = atomic_inc_return_unchecked(&pool->req_ser);
40526 wake_up_process(pool->thread);
40527
40528 if (wait_event_interruptible(pool->force_wait,
40529- atomic_read(&pool->flush_ser) - serial >= 0))
40530+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
40531 return -EINTR;
40532
40533 return 0;
40534@@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
40535 } else {
40536 list_add_tail(&fmr->list, &pool->dirty_list);
40537 if (++pool->dirty_len >= pool->dirty_watermark) {
40538- atomic_inc(&pool->req_ser);
40539+ atomic_inc_unchecked(&pool->req_ser);
40540 wake_up_process(pool->thread);
40541 }
40542 }
40543diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
40544index 4cb8eb2..146bf60 100644
40545--- a/drivers/infiniband/hw/cxgb4/mem.c
40546+++ b/drivers/infiniband/hw/cxgb4/mem.c
40547@@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
40548 int err;
40549 struct fw_ri_tpte tpt;
40550 u32 stag_idx;
40551- static atomic_t key;
40552+ static atomic_unchecked_t key;
40553
40554 if (c4iw_fatal_error(rdev))
40555 return -EIO;
40556@@ -266,7 +266,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
40557 if (rdev->stats.stag.cur > rdev->stats.stag.max)
40558 rdev->stats.stag.max = rdev->stats.stag.cur;
40559 mutex_unlock(&rdev->stats.lock);
40560- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
40561+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
40562 }
40563 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
40564 __func__, stag_state, type, pdid, stag_idx);
40565diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
40566index 79b3dbc..96e5fcc 100644
40567--- a/drivers/infiniband/hw/ipath/ipath_rc.c
40568+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
40569@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
40570 struct ib_atomic_eth *ateth;
40571 struct ipath_ack_entry *e;
40572 u64 vaddr;
40573- atomic64_t *maddr;
40574+ atomic64_unchecked_t *maddr;
40575 u64 sdata;
40576 u32 rkey;
40577 u8 next;
40578@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
40579 IB_ACCESS_REMOTE_ATOMIC)))
40580 goto nack_acc_unlck;
40581 /* Perform atomic OP and save result. */
40582- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
40583+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
40584 sdata = be64_to_cpu(ateth->swap_data);
40585 e = &qp->s_ack_queue[qp->r_head_ack_queue];
40586 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
40587- (u64) atomic64_add_return(sdata, maddr) - sdata :
40588+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
40589 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
40590 be64_to_cpu(ateth->compare_data),
40591 sdata);
40592diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
40593index 1f95bba..9530f87 100644
40594--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
40595+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
40596@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
40597 unsigned long flags;
40598 struct ib_wc wc;
40599 u64 sdata;
40600- atomic64_t *maddr;
40601+ atomic64_unchecked_t *maddr;
40602 enum ib_wc_status send_status;
40603
40604 /*
40605@@ -382,11 +382,11 @@ again:
40606 IB_ACCESS_REMOTE_ATOMIC)))
40607 goto acc_err;
40608 /* Perform atomic OP and save result. */
40609- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
40610+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
40611 sdata = wqe->wr.wr.atomic.compare_add;
40612 *(u64 *) sqp->s_sge.sge.vaddr =
40613 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
40614- (u64) atomic64_add_return(sdata, maddr) - sdata :
40615+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
40616 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
40617 sdata, wqe->wr.wr.atomic.swap);
40618 goto send_comp;
40619diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
40620index f2a3f48..673ec79 100644
40621--- a/drivers/infiniband/hw/mlx4/mad.c
40622+++ b/drivers/infiniband/hw/mlx4/mad.c
40623@@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
40624
40625 __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
40626 {
40627- return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
40628+ return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
40629 cpu_to_be64(0xff00000000000000LL);
40630 }
40631
40632diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
40633index 25b2cdf..099ff97 100644
40634--- a/drivers/infiniband/hw/mlx4/mcg.c
40635+++ b/drivers/infiniband/hw/mlx4/mcg.c
40636@@ -1040,7 +1040,7 @@ int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
40637 {
40638 char name[20];
40639
40640- atomic_set(&ctx->tid, 0);
40641+ atomic_set_unchecked(&ctx->tid, 0);
40642 sprintf(name, "mlx4_ib_mcg%d", ctx->port);
40643 ctx->mcg_wq = create_singlethread_workqueue(name);
40644 if (!ctx->mcg_wq)
40645diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
40646index f61ec26..ebf72cf 100644
40647--- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
40648+++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
40649@@ -398,7 +398,7 @@ struct mlx4_ib_demux_ctx {
40650 struct list_head mcg_mgid0_list;
40651 struct workqueue_struct *mcg_wq;
40652 struct mlx4_ib_demux_pv_ctx **tun;
40653- atomic_t tid;
40654+ atomic_unchecked_t tid;
40655 int flushing; /* flushing the work queue */
40656 };
40657
40658diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
40659index 9d3e5c1..d9afe4a 100644
40660--- a/drivers/infiniband/hw/mthca/mthca_cmd.c
40661+++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
40662@@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
40663 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
40664 }
40665
40666-int mthca_QUERY_FW(struct mthca_dev *dev)
40667+int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
40668 {
40669 struct mthca_mailbox *mailbox;
40670 u32 *outbox;
40671diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
40672index ed9a989..e0c5871 100644
40673--- a/drivers/infiniband/hw/mthca/mthca_mr.c
40674+++ b/drivers/infiniband/hw/mthca/mthca_mr.c
40675@@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
40676 return key;
40677 }
40678
40679-int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
40680+int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
40681 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
40682 {
40683 struct mthca_mailbox *mailbox;
40684diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
40685index 4291410..d2ab1fb 100644
40686--- a/drivers/infiniband/hw/nes/nes.c
40687+++ b/drivers/infiniband/hw/nes/nes.c
40688@@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
40689 LIST_HEAD(nes_adapter_list);
40690 static LIST_HEAD(nes_dev_list);
40691
40692-atomic_t qps_destroyed;
40693+atomic_unchecked_t qps_destroyed;
40694
40695 static unsigned int ee_flsh_adapter;
40696 static unsigned int sysfs_nonidx_addr;
40697@@ -269,7 +269,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
40698 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
40699 struct nes_adapter *nesadapter = nesdev->nesadapter;
40700
40701- atomic_inc(&qps_destroyed);
40702+ atomic_inc_unchecked(&qps_destroyed);
40703
40704 /* Free the control structures */
40705
40706diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
40707index 33cc589..3bd6538 100644
40708--- a/drivers/infiniband/hw/nes/nes.h
40709+++ b/drivers/infiniband/hw/nes/nes.h
40710@@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
40711 extern unsigned int wqm_quanta;
40712 extern struct list_head nes_adapter_list;
40713
40714-extern atomic_t cm_connects;
40715-extern atomic_t cm_accepts;
40716-extern atomic_t cm_disconnects;
40717-extern atomic_t cm_closes;
40718-extern atomic_t cm_connecteds;
40719-extern atomic_t cm_connect_reqs;
40720-extern atomic_t cm_rejects;
40721-extern atomic_t mod_qp_timouts;
40722-extern atomic_t qps_created;
40723-extern atomic_t qps_destroyed;
40724-extern atomic_t sw_qps_destroyed;
40725+extern atomic_unchecked_t cm_connects;
40726+extern atomic_unchecked_t cm_accepts;
40727+extern atomic_unchecked_t cm_disconnects;
40728+extern atomic_unchecked_t cm_closes;
40729+extern atomic_unchecked_t cm_connecteds;
40730+extern atomic_unchecked_t cm_connect_reqs;
40731+extern atomic_unchecked_t cm_rejects;
40732+extern atomic_unchecked_t mod_qp_timouts;
40733+extern atomic_unchecked_t qps_created;
40734+extern atomic_unchecked_t qps_destroyed;
40735+extern atomic_unchecked_t sw_qps_destroyed;
40736 extern u32 mh_detected;
40737 extern u32 mh_pauses_sent;
40738 extern u32 cm_packets_sent;
40739@@ -196,16 +196,16 @@ extern u32 cm_packets_created;
40740 extern u32 cm_packets_received;
40741 extern u32 cm_packets_dropped;
40742 extern u32 cm_packets_retrans;
40743-extern atomic_t cm_listens_created;
40744-extern atomic_t cm_listens_destroyed;
40745+extern atomic_unchecked_t cm_listens_created;
40746+extern atomic_unchecked_t cm_listens_destroyed;
40747 extern u32 cm_backlog_drops;
40748-extern atomic_t cm_loopbacks;
40749-extern atomic_t cm_nodes_created;
40750-extern atomic_t cm_nodes_destroyed;
40751-extern atomic_t cm_accel_dropped_pkts;
40752-extern atomic_t cm_resets_recvd;
40753-extern atomic_t pau_qps_created;
40754-extern atomic_t pau_qps_destroyed;
40755+extern atomic_unchecked_t cm_loopbacks;
40756+extern atomic_unchecked_t cm_nodes_created;
40757+extern atomic_unchecked_t cm_nodes_destroyed;
40758+extern atomic_unchecked_t cm_accel_dropped_pkts;
40759+extern atomic_unchecked_t cm_resets_recvd;
40760+extern atomic_unchecked_t pau_qps_created;
40761+extern atomic_unchecked_t pau_qps_destroyed;
40762
40763 extern u32 int_mod_timer_init;
40764 extern u32 int_mod_cq_depth_256;
40765diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
40766index 24b9f1a..00fd004 100644
40767--- a/drivers/infiniband/hw/nes/nes_cm.c
40768+++ b/drivers/infiniband/hw/nes/nes_cm.c
40769@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
40770 u32 cm_packets_retrans;
40771 u32 cm_packets_created;
40772 u32 cm_packets_received;
40773-atomic_t cm_listens_created;
40774-atomic_t cm_listens_destroyed;
40775+atomic_unchecked_t cm_listens_created;
40776+atomic_unchecked_t cm_listens_destroyed;
40777 u32 cm_backlog_drops;
40778-atomic_t cm_loopbacks;
40779-atomic_t cm_nodes_created;
40780-atomic_t cm_nodes_destroyed;
40781-atomic_t cm_accel_dropped_pkts;
40782-atomic_t cm_resets_recvd;
40783+atomic_unchecked_t cm_loopbacks;
40784+atomic_unchecked_t cm_nodes_created;
40785+atomic_unchecked_t cm_nodes_destroyed;
40786+atomic_unchecked_t cm_accel_dropped_pkts;
40787+atomic_unchecked_t cm_resets_recvd;
40788
40789 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
40790 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
40791@@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
40792
40793 static struct nes_cm_core *g_cm_core;
40794
40795-atomic_t cm_connects;
40796-atomic_t cm_accepts;
40797-atomic_t cm_disconnects;
40798-atomic_t cm_closes;
40799-atomic_t cm_connecteds;
40800-atomic_t cm_connect_reqs;
40801-atomic_t cm_rejects;
40802+atomic_unchecked_t cm_connects;
40803+atomic_unchecked_t cm_accepts;
40804+atomic_unchecked_t cm_disconnects;
40805+atomic_unchecked_t cm_closes;
40806+atomic_unchecked_t cm_connecteds;
40807+atomic_unchecked_t cm_connect_reqs;
40808+atomic_unchecked_t cm_rejects;
40809
40810 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
40811 {
40812@@ -1272,7 +1272,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
40813 kfree(listener);
40814 listener = NULL;
40815 ret = 0;
40816- atomic_inc(&cm_listens_destroyed);
40817+ atomic_inc_unchecked(&cm_listens_destroyed);
40818 } else {
40819 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
40820 }
40821@@ -1466,7 +1466,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
40822 cm_node->rem_mac);
40823
40824 add_hte_node(cm_core, cm_node);
40825- atomic_inc(&cm_nodes_created);
40826+ atomic_inc_unchecked(&cm_nodes_created);
40827
40828 return cm_node;
40829 }
40830@@ -1524,7 +1524,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
40831 }
40832
40833 atomic_dec(&cm_core->node_cnt);
40834- atomic_inc(&cm_nodes_destroyed);
40835+ atomic_inc_unchecked(&cm_nodes_destroyed);
40836 nesqp = cm_node->nesqp;
40837 if (nesqp) {
40838 nesqp->cm_node = NULL;
40839@@ -1588,7 +1588,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
40840
40841 static void drop_packet(struct sk_buff *skb)
40842 {
40843- atomic_inc(&cm_accel_dropped_pkts);
40844+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
40845 dev_kfree_skb_any(skb);
40846 }
40847
40848@@ -1651,7 +1651,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
40849 {
40850
40851 int reset = 0; /* whether to send reset in case of err.. */
40852- atomic_inc(&cm_resets_recvd);
40853+ atomic_inc_unchecked(&cm_resets_recvd);
40854 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
40855 " refcnt=%d\n", cm_node, cm_node->state,
40856 atomic_read(&cm_node->ref_count));
40857@@ -2292,7 +2292,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
40858 rem_ref_cm_node(cm_node->cm_core, cm_node);
40859 return NULL;
40860 }
40861- atomic_inc(&cm_loopbacks);
40862+ atomic_inc_unchecked(&cm_loopbacks);
40863 loopbackremotenode->loopbackpartner = cm_node;
40864 loopbackremotenode->tcp_cntxt.rcv_wscale =
40865 NES_CM_DEFAULT_RCV_WND_SCALE;
40866@@ -2567,7 +2567,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
40867 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
40868 else {
40869 rem_ref_cm_node(cm_core, cm_node);
40870- atomic_inc(&cm_accel_dropped_pkts);
40871+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
40872 dev_kfree_skb_any(skb);
40873 }
40874 break;
40875@@ -2875,7 +2875,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
40876
40877 if ((cm_id) && (cm_id->event_handler)) {
40878 if (issue_disconn) {
40879- atomic_inc(&cm_disconnects);
40880+ atomic_inc_unchecked(&cm_disconnects);
40881 cm_event.event = IW_CM_EVENT_DISCONNECT;
40882 cm_event.status = disconn_status;
40883 cm_event.local_addr = cm_id->local_addr;
40884@@ -2897,7 +2897,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
40885 }
40886
40887 if (issue_close) {
40888- atomic_inc(&cm_closes);
40889+ atomic_inc_unchecked(&cm_closes);
40890 nes_disconnect(nesqp, 1);
40891
40892 cm_id->provider_data = nesqp;
40893@@ -3033,7 +3033,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
40894
40895 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
40896 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
40897- atomic_inc(&cm_accepts);
40898+ atomic_inc_unchecked(&cm_accepts);
40899
40900 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
40901 netdev_refcnt_read(nesvnic->netdev));
40902@@ -3228,7 +3228,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
40903 struct nes_cm_core *cm_core;
40904 u8 *start_buff;
40905
40906- atomic_inc(&cm_rejects);
40907+ atomic_inc_unchecked(&cm_rejects);
40908 cm_node = (struct nes_cm_node *)cm_id->provider_data;
40909 loopback = cm_node->loopbackpartner;
40910 cm_core = cm_node->cm_core;
40911@@ -3288,7 +3288,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
40912 ntohl(cm_id->local_addr.sin_addr.s_addr),
40913 ntohs(cm_id->local_addr.sin_port));
40914
40915- atomic_inc(&cm_connects);
40916+ atomic_inc_unchecked(&cm_connects);
40917 nesqp->active_conn = 1;
40918
40919 /* cache the cm_id in the qp */
40920@@ -3398,7 +3398,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
40921 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
40922 return err;
40923 }
40924- atomic_inc(&cm_listens_created);
40925+ atomic_inc_unchecked(&cm_listens_created);
40926 }
40927
40928 cm_id->add_ref(cm_id);
40929@@ -3499,7 +3499,7 @@ static void cm_event_connected(struct nes_cm_event *event)
40930
40931 if (nesqp->destroyed)
40932 return;
40933- atomic_inc(&cm_connecteds);
40934+ atomic_inc_unchecked(&cm_connecteds);
40935 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
40936 " local port 0x%04X. jiffies = %lu.\n",
40937 nesqp->hwqp.qp_id,
40938@@ -3679,7 +3679,7 @@ static void cm_event_reset(struct nes_cm_event *event)
40939
40940 cm_id->add_ref(cm_id);
40941 ret = cm_id->event_handler(cm_id, &cm_event);
40942- atomic_inc(&cm_closes);
40943+ atomic_inc_unchecked(&cm_closes);
40944 cm_event.event = IW_CM_EVENT_CLOSE;
40945 cm_event.status = 0;
40946 cm_event.provider_data = cm_id->provider_data;
40947@@ -3715,7 +3715,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
40948 return;
40949 cm_id = cm_node->cm_id;
40950
40951- atomic_inc(&cm_connect_reqs);
40952+ atomic_inc_unchecked(&cm_connect_reqs);
40953 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
40954 cm_node, cm_id, jiffies);
40955
40956@@ -3755,7 +3755,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
40957 return;
40958 cm_id = cm_node->cm_id;
40959
40960- atomic_inc(&cm_connect_reqs);
40961+ atomic_inc_unchecked(&cm_connect_reqs);
40962 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
40963 cm_node, cm_id, jiffies);
40964
40965diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
40966index 4166452..fc952c3 100644
40967--- a/drivers/infiniband/hw/nes/nes_mgt.c
40968+++ b/drivers/infiniband/hw/nes/nes_mgt.c
40969@@ -40,8 +40,8 @@
40970 #include "nes.h"
40971 #include "nes_mgt.h"
40972
40973-atomic_t pau_qps_created;
40974-atomic_t pau_qps_destroyed;
40975+atomic_unchecked_t pau_qps_created;
40976+atomic_unchecked_t pau_qps_destroyed;
40977
40978 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
40979 {
40980@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
40981 {
40982 struct sk_buff *skb;
40983 unsigned long flags;
40984- atomic_inc(&pau_qps_destroyed);
40985+ atomic_inc_unchecked(&pau_qps_destroyed);
40986
40987 /* Free packets that have not yet been forwarded */
40988 /* Lock is acquired by skb_dequeue when removing the skb */
40989@@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
40990 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
40991 skb_queue_head_init(&nesqp->pau_list);
40992 spin_lock_init(&nesqp->pau_lock);
40993- atomic_inc(&pau_qps_created);
40994+ atomic_inc_unchecked(&pau_qps_created);
40995 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
40996 }
40997
40998diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
40999index 49eb511..a774366 100644
41000--- a/drivers/infiniband/hw/nes/nes_nic.c
41001+++ b/drivers/infiniband/hw/nes/nes_nic.c
41002@@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
41003 target_stat_values[++index] = mh_detected;
41004 target_stat_values[++index] = mh_pauses_sent;
41005 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
41006- target_stat_values[++index] = atomic_read(&cm_connects);
41007- target_stat_values[++index] = atomic_read(&cm_accepts);
41008- target_stat_values[++index] = atomic_read(&cm_disconnects);
41009- target_stat_values[++index] = atomic_read(&cm_connecteds);
41010- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
41011- target_stat_values[++index] = atomic_read(&cm_rejects);
41012- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
41013- target_stat_values[++index] = atomic_read(&qps_created);
41014- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
41015- target_stat_values[++index] = atomic_read(&qps_destroyed);
41016- target_stat_values[++index] = atomic_read(&cm_closes);
41017+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
41018+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
41019+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
41020+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
41021+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
41022+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
41023+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
41024+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
41025+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
41026+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
41027+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
41028 target_stat_values[++index] = cm_packets_sent;
41029 target_stat_values[++index] = cm_packets_bounced;
41030 target_stat_values[++index] = cm_packets_created;
41031 target_stat_values[++index] = cm_packets_received;
41032 target_stat_values[++index] = cm_packets_dropped;
41033 target_stat_values[++index] = cm_packets_retrans;
41034- target_stat_values[++index] = atomic_read(&cm_listens_created);
41035- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
41036+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
41037+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
41038 target_stat_values[++index] = cm_backlog_drops;
41039- target_stat_values[++index] = atomic_read(&cm_loopbacks);
41040- target_stat_values[++index] = atomic_read(&cm_nodes_created);
41041- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
41042- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
41043- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
41044+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
41045+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
41046+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
41047+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
41048+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
41049 target_stat_values[++index] = nesadapter->free_4kpbl;
41050 target_stat_values[++index] = nesadapter->free_256pbl;
41051 target_stat_values[++index] = int_mod_timer_init;
41052 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
41053 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
41054 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
41055- target_stat_values[++index] = atomic_read(&pau_qps_created);
41056- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
41057+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
41058+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
41059 }
41060
41061 /**
41062diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
41063index 5b53ca5..443da3c 100644
41064--- a/drivers/infiniband/hw/nes/nes_verbs.c
41065+++ b/drivers/infiniband/hw/nes/nes_verbs.c
41066@@ -46,9 +46,9 @@
41067
41068 #include <rdma/ib_umem.h>
41069
41070-atomic_t mod_qp_timouts;
41071-atomic_t qps_created;
41072-atomic_t sw_qps_destroyed;
41073+atomic_unchecked_t mod_qp_timouts;
41074+atomic_unchecked_t qps_created;
41075+atomic_unchecked_t sw_qps_destroyed;
41076
41077 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
41078
41079@@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
41080 if (init_attr->create_flags)
41081 return ERR_PTR(-EINVAL);
41082
41083- atomic_inc(&qps_created);
41084+ atomic_inc_unchecked(&qps_created);
41085 switch (init_attr->qp_type) {
41086 case IB_QPT_RC:
41087 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
41088@@ -1466,7 +1466,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
41089 struct iw_cm_event cm_event;
41090 int ret = 0;
41091
41092- atomic_inc(&sw_qps_destroyed);
41093+ atomic_inc_unchecked(&sw_qps_destroyed);
41094 nesqp->destroyed = 1;
41095
41096 /* Blow away the connection if it exists. */
41097diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
41098index 4a9af79..b993f75 100644
41099--- a/drivers/infiniband/hw/qib/qib.h
41100+++ b/drivers/infiniband/hw/qib/qib.h
41101@@ -52,6 +52,7 @@
41102 #include <linux/kref.h>
41103 #include <linux/sched.h>
41104 #include <linux/kthread.h>
41105+#include <linux/slab.h>
41106
41107 #include "qib_common.h"
41108 #include "qib_verbs.h"
41109diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
41110index da739d9..da1c7f4 100644
41111--- a/drivers/input/gameport/gameport.c
41112+++ b/drivers/input/gameport/gameport.c
41113@@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
41114 */
41115 static void gameport_init_port(struct gameport *gameport)
41116 {
41117- static atomic_t gameport_no = ATOMIC_INIT(0);
41118+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
41119
41120 __module_get(THIS_MODULE);
41121
41122 mutex_init(&gameport->drv_mutex);
41123 device_initialize(&gameport->dev);
41124 dev_set_name(&gameport->dev, "gameport%lu",
41125- (unsigned long)atomic_inc_return(&gameport_no) - 1);
41126+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
41127 gameport->dev.bus = &gameport_bus;
41128 gameport->dev.release = gameport_release_port;
41129 if (gameport->parent)
41130diff --git a/drivers/input/input.c b/drivers/input/input.c
41131index c044699..174d71a 100644
41132--- a/drivers/input/input.c
41133+++ b/drivers/input/input.c
41134@@ -2019,7 +2019,7 @@ static void devm_input_device_unregister(struct device *dev, void *res)
41135 */
41136 int input_register_device(struct input_dev *dev)
41137 {
41138- static atomic_t input_no = ATOMIC_INIT(0);
41139+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
41140 struct input_devres *devres = NULL;
41141 struct input_handler *handler;
41142 unsigned int packet_size;
41143@@ -2074,7 +2074,7 @@ int input_register_device(struct input_dev *dev)
41144 dev->setkeycode = input_default_setkeycode;
41145
41146 dev_set_name(&dev->dev, "input%ld",
41147- (unsigned long) atomic_inc_return(&input_no) - 1);
41148+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
41149
41150 error = device_add(&dev->dev);
41151 if (error)
41152diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
41153index 04c69af..5f92d00 100644
41154--- a/drivers/input/joystick/sidewinder.c
41155+++ b/drivers/input/joystick/sidewinder.c
41156@@ -30,6 +30,7 @@
41157 #include <linux/kernel.h>
41158 #include <linux/module.h>
41159 #include <linux/slab.h>
41160+#include <linux/sched.h>
41161 #include <linux/init.h>
41162 #include <linux/input.h>
41163 #include <linux/gameport.h>
41164diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
41165index 75e3b10..fb390fd 100644
41166--- a/drivers/input/joystick/xpad.c
41167+++ b/drivers/input/joystick/xpad.c
41168@@ -736,7 +736,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
41169
41170 static int xpad_led_probe(struct usb_xpad *xpad)
41171 {
41172- static atomic_t led_seq = ATOMIC_INIT(0);
41173+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
41174 long led_no;
41175 struct xpad_led *led;
41176 struct led_classdev *led_cdev;
41177@@ -749,7 +749,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
41178 if (!led)
41179 return -ENOMEM;
41180
41181- led_no = (long)atomic_inc_return(&led_seq) - 1;
41182+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
41183
41184 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
41185 led->xpad = xpad;
41186diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
41187index e204f26..8459f15 100644
41188--- a/drivers/input/misc/ims-pcu.c
41189+++ b/drivers/input/misc/ims-pcu.c
41190@@ -1621,7 +1621,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
41191
41192 static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
41193 {
41194- static atomic_t device_no = ATOMIC_INIT(0);
41195+ static atomic_unchecked_t device_no = ATOMIC_INIT(0);
41196
41197 const struct ims_pcu_device_info *info;
41198 u8 device_id;
41199@@ -1653,7 +1653,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
41200 }
41201
41202 /* Device appears to be operable, complete initialization */
41203- pcu->device_no = atomic_inc_return(&device_no) - 1;
41204+ pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
41205
41206 error = ims_pcu_setup_backlight(pcu);
41207 if (error)
41208diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
41209index 2f0b39d..7370f13 100644
41210--- a/drivers/input/mouse/psmouse.h
41211+++ b/drivers/input/mouse/psmouse.h
41212@@ -116,7 +116,7 @@ struct psmouse_attribute {
41213 ssize_t (*set)(struct psmouse *psmouse, void *data,
41214 const char *buf, size_t count);
41215 bool protect;
41216-};
41217+} __do_const;
41218 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
41219
41220 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
41221diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
41222index 4c842c3..590b0bf 100644
41223--- a/drivers/input/mousedev.c
41224+++ b/drivers/input/mousedev.c
41225@@ -738,7 +738,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
41226
41227 spin_unlock_irq(&client->packet_lock);
41228
41229- if (copy_to_user(buffer, data, count))
41230+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
41231 return -EFAULT;
41232
41233 return count;
41234diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
41235index 25fc597..558bf3b3 100644
41236--- a/drivers/input/serio/serio.c
41237+++ b/drivers/input/serio/serio.c
41238@@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
41239 */
41240 static void serio_init_port(struct serio *serio)
41241 {
41242- static atomic_t serio_no = ATOMIC_INIT(0);
41243+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
41244
41245 __module_get(THIS_MODULE);
41246
41247@@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
41248 mutex_init(&serio->drv_mutex);
41249 device_initialize(&serio->dev);
41250 dev_set_name(&serio->dev, "serio%ld",
41251- (long)atomic_inc_return(&serio_no) - 1);
41252+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
41253 serio->dev.bus = &serio_bus;
41254 serio->dev.release = serio_release_port;
41255 serio->dev.groups = serio_device_attr_groups;
41256diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
41257index 59df2e7..8f1cafb 100644
41258--- a/drivers/input/serio/serio_raw.c
41259+++ b/drivers/input/serio/serio_raw.c
41260@@ -293,7 +293,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
41261
41262 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
41263 {
41264- static atomic_t serio_raw_no = ATOMIC_INIT(0);
41265+ static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
41266 struct serio_raw *serio_raw;
41267 int err;
41268
41269@@ -304,7 +304,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
41270 }
41271
41272 snprintf(serio_raw->name, sizeof(serio_raw->name),
41273- "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
41274+ "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
41275 kref_init(&serio_raw->kref);
41276 INIT_LIST_HEAD(&serio_raw->client_list);
41277 init_waitqueue_head(&serio_raw->wait);
41278diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
41279index fbe9ca7..dbee61d 100644
41280--- a/drivers/iommu/iommu.c
41281+++ b/drivers/iommu/iommu.c
41282@@ -583,7 +583,7 @@ static struct notifier_block iommu_bus_nb = {
41283 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
41284 {
41285 bus_register_notifier(bus, &iommu_bus_nb);
41286- bus_for_each_dev(bus, NULL, ops, add_iommu_group);
41287+ bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
41288 }
41289
41290 /**
41291diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
41292index 39f81ae..2660096 100644
41293--- a/drivers/iommu/irq_remapping.c
41294+++ b/drivers/iommu/irq_remapping.c
41295@@ -356,7 +356,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
41296 void panic_if_irq_remap(const char *msg)
41297 {
41298 if (irq_remapping_enabled)
41299- panic(msg);
41300+ panic("%s", msg);
41301 }
41302
41303 static void ir_ack_apic_edge(struct irq_data *data)
41304@@ -377,10 +377,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
41305
41306 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
41307 {
41308- chip->irq_print_chip = ir_print_prefix;
41309- chip->irq_ack = ir_ack_apic_edge;
41310- chip->irq_eoi = ir_ack_apic_level;
41311- chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
41312+ pax_open_kernel();
41313+ *(void **)&chip->irq_print_chip = ir_print_prefix;
41314+ *(void **)&chip->irq_ack = ir_ack_apic_edge;
41315+ *(void **)&chip->irq_eoi = ir_ack_apic_level;
41316+ *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
41317+ pax_close_kernel();
41318 }
41319
41320 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
41321diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
41322index ee7c503..5d4ce08 100644
41323--- a/drivers/irqchip/irq-gic.c
41324+++ b/drivers/irqchip/irq-gic.c
41325@@ -84,7 +84,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
41326 * Supported arch specific GIC irq extension.
41327 * Default make them NULL.
41328 */
41329-struct irq_chip gic_arch_extn = {
41330+irq_chip_no_const gic_arch_extn = {
41331 .irq_eoi = NULL,
41332 .irq_mask = NULL,
41333 .irq_unmask = NULL,
41334@@ -333,7 +333,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
41335 chained_irq_exit(chip, desc);
41336 }
41337
41338-static struct irq_chip gic_chip = {
41339+static irq_chip_no_const gic_chip __read_only = {
41340 .name = "GIC",
41341 .irq_mask = gic_mask_irq,
41342 .irq_unmask = gic_unmask_irq,
41343diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
41344index ac6f72b..81150f2 100644
41345--- a/drivers/isdn/capi/capi.c
41346+++ b/drivers/isdn/capi/capi.c
41347@@ -81,8 +81,8 @@ struct capiminor {
41348
41349 struct capi20_appl *ap;
41350 u32 ncci;
41351- atomic_t datahandle;
41352- atomic_t msgid;
41353+ atomic_unchecked_t datahandle;
41354+ atomic_unchecked_t msgid;
41355
41356 struct tty_port port;
41357 int ttyinstop;
41358@@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
41359 capimsg_setu16(s, 2, mp->ap->applid);
41360 capimsg_setu8 (s, 4, CAPI_DATA_B3);
41361 capimsg_setu8 (s, 5, CAPI_RESP);
41362- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
41363+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
41364 capimsg_setu32(s, 8, mp->ncci);
41365 capimsg_setu16(s, 12, datahandle);
41366 }
41367@@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
41368 mp->outbytes -= len;
41369 spin_unlock_bh(&mp->outlock);
41370
41371- datahandle = atomic_inc_return(&mp->datahandle);
41372+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
41373 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
41374 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
41375 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
41376 capimsg_setu16(skb->data, 2, mp->ap->applid);
41377 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
41378 capimsg_setu8 (skb->data, 5, CAPI_REQ);
41379- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
41380+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
41381 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
41382 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
41383 capimsg_setu16(skb->data, 16, len); /* Data length */
41384diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
41385index 600c79b..3752bab 100644
41386--- a/drivers/isdn/gigaset/interface.c
41387+++ b/drivers/isdn/gigaset/interface.c
41388@@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
41389 }
41390 tty->driver_data = cs;
41391
41392- ++cs->port.count;
41393+ atomic_inc(&cs->port.count);
41394
41395- if (cs->port.count == 1) {
41396+ if (atomic_read(&cs->port.count) == 1) {
41397 tty_port_tty_set(&cs->port, tty);
41398 cs->port.low_latency = 1;
41399 }
41400@@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
41401
41402 if (!cs->connected)
41403 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
41404- else if (!cs->port.count)
41405+ else if (!atomic_read(&cs->port.count))
41406 dev_warn(cs->dev, "%s: device not opened\n", __func__);
41407- else if (!--cs->port.count)
41408+ else if (!atomic_dec_return(&cs->port.count))
41409 tty_port_tty_set(&cs->port, NULL);
41410
41411 mutex_unlock(&cs->mutex);
41412diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
41413index d0a41cb..f0cdb8c 100644
41414--- a/drivers/isdn/gigaset/usb-gigaset.c
41415+++ b/drivers/isdn/gigaset/usb-gigaset.c
41416@@ -547,7 +547,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
41417 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
41418 memcpy(cs->hw.usb->bchars, buf, 6);
41419 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
41420- 0, 0, &buf, 6, 2000);
41421+ 0, 0, buf, 6, 2000);
41422 }
41423
41424 static void gigaset_freebcshw(struct bc_state *bcs)
41425diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
41426index 4d9b195..455075c 100644
41427--- a/drivers/isdn/hardware/avm/b1.c
41428+++ b/drivers/isdn/hardware/avm/b1.c
41429@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
41430 }
41431 if (left) {
41432 if (t4file->user) {
41433- if (copy_from_user(buf, dp, left))
41434+ if (left > sizeof buf || copy_from_user(buf, dp, left))
41435 return -EFAULT;
41436 } else {
41437 memcpy(buf, dp, left);
41438@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
41439 }
41440 if (left) {
41441 if (config->user) {
41442- if (copy_from_user(buf, dp, left))
41443+ if (left > sizeof buf || copy_from_user(buf, dp, left))
41444 return -EFAULT;
41445 } else {
41446 memcpy(buf, dp, left);
41447diff --git a/drivers/isdn/hisax/amd7930_fn.c b/drivers/isdn/hisax/amd7930_fn.c
41448index 1063bab..36817e0 100644
41449--- a/drivers/isdn/hisax/amd7930_fn.c
41450+++ b/drivers/isdn/hisax/amd7930_fn.c
41451@@ -314,7 +314,7 @@ Amd7930_empty_Dfifo(struct IsdnCardState *cs, int flag)
41452
41453 t += sprintf(t, "Amd7930: empty_Dfifo cnt: %d |", cs->rcvidx);
41454 QuickHex(t, cs->rcvbuf, cs->rcvidx);
41455- debugl1(cs, cs->dlog);
41456+ debugl1(cs, "%s", cs->dlog);
41457 }
41458 /* moves received data in sk-buffer */
41459 memcpy(skb_put(skb, cs->rcvidx), cs->rcvbuf, cs->rcvidx);
41460@@ -406,7 +406,7 @@ Amd7930_fill_Dfifo(struct IsdnCardState *cs)
41461
41462 t += sprintf(t, "Amd7930: fill_Dfifo cnt: %d |", count);
41463 QuickHex(t, deb_ptr, count);
41464- debugl1(cs, cs->dlog);
41465+ debugl1(cs, "%s", cs->dlog);
41466 }
41467 /* AMD interrupts on */
41468 AmdIrqOn(cs);
41469diff --git a/drivers/isdn/hisax/avm_pci.c b/drivers/isdn/hisax/avm_pci.c
41470index ee9b9a0..d1427bd 100644
41471--- a/drivers/isdn/hisax/avm_pci.c
41472+++ b/drivers/isdn/hisax/avm_pci.c
41473@@ -285,7 +285,7 @@ hdlc_empty_fifo(struct BCState *bcs, int count)
41474 t += sprintf(t, "hdlc_empty_fifo %c cnt %d",
41475 bcs->channel ? 'B' : 'A', count);
41476 QuickHex(t, p, count);
41477- debugl1(cs, bcs->blog);
41478+ debugl1(cs, "%s", bcs->blog);
41479 }
41480 }
41481
41482@@ -345,7 +345,7 @@ hdlc_fill_fifo(struct BCState *bcs)
41483 t += sprintf(t, "hdlc_fill_fifo %c cnt %d",
41484 bcs->channel ? 'B' : 'A', count);
41485 QuickHex(t, p, count);
41486- debugl1(cs, bcs->blog);
41487+ debugl1(cs, "%s", bcs->blog);
41488 }
41489 }
41490
41491diff --git a/drivers/isdn/hisax/config.c b/drivers/isdn/hisax/config.c
41492index bf04d2a..b33f53b 100644
41493--- a/drivers/isdn/hisax/config.c
41494+++ b/drivers/isdn/hisax/config.c
41495@@ -1896,7 +1896,7 @@ static void EChannel_proc_rcv(struct hisax_d_if *d_if)
41496 ptr--;
41497 *ptr++ = '\n';
41498 *ptr = 0;
41499- HiSax_putstatus(cs, NULL, cs->dlog);
41500+ HiSax_putstatus(cs, NULL, "%s", cs->dlog);
41501 } else
41502 HiSax_putstatus(cs, "LogEcho: ",
41503 "warning Frame too big (%d)",
41504diff --git a/drivers/isdn/hisax/diva.c b/drivers/isdn/hisax/diva.c
41505index 8d0cf6e..4fc90de 100644
41506--- a/drivers/isdn/hisax/diva.c
41507+++ b/drivers/isdn/hisax/diva.c
41508@@ -427,7 +427,7 @@ Memhscx_empty_fifo(struct BCState *bcs, int count)
41509 t += sprintf(t, "hscx_empty_fifo %c cnt %d",
41510 bcs->hw.hscx.hscx ? 'B' : 'A', count);
41511 QuickHex(t, ptr, count);
41512- debugl1(cs, bcs->blog);
41513+ debugl1(cs, "%s", bcs->blog);
41514 }
41515 }
41516
41517@@ -469,7 +469,7 @@ Memhscx_fill_fifo(struct BCState *bcs)
41518 t += sprintf(t, "hscx_fill_fifo %c cnt %d",
41519 bcs->hw.hscx.hscx ? 'B' : 'A', count);
41520 QuickHex(t, ptr, count);
41521- debugl1(cs, bcs->blog);
41522+ debugl1(cs, "%s", bcs->blog);
41523 }
41524 }
41525
41526diff --git a/drivers/isdn/hisax/elsa.c b/drivers/isdn/hisax/elsa.c
41527index 1df6f9a..2be1c8a 100644
41528--- a/drivers/isdn/hisax/elsa.c
41529+++ b/drivers/isdn/hisax/elsa.c
41530@@ -535,7 +535,7 @@ check_arcofi(struct IsdnCardState *cs)
41531 t = tmp;
41532 t += sprintf(tmp, "Arcofi data");
41533 QuickHex(t, p, cs->dc.isac.mon_rxp);
41534- debugl1(cs, tmp);
41535+ debugl1(cs, "%s", tmp);
41536 if ((cs->dc.isac.mon_rxp == 2) && (cs->dc.isac.mon_rx[0] == 0xa0)) {
41537 switch (cs->dc.isac.mon_rx[1]) {
41538 case 0x80:
41539diff --git a/drivers/isdn/hisax/elsa_ser.c b/drivers/isdn/hisax/elsa_ser.c
41540index d4c98d3..3f84dd8 100644
41541--- a/drivers/isdn/hisax/elsa_ser.c
41542+++ b/drivers/isdn/hisax/elsa_ser.c
41543@@ -344,7 +344,7 @@ static inline void receive_chars(struct IsdnCardState *cs,
41544
41545 t += sprintf(t, "modem read cnt %d", cs->hw.elsa.rcvcnt);
41546 QuickHex(t, cs->hw.elsa.rcvbuf, cs->hw.elsa.rcvcnt);
41547- debugl1(cs, tmp);
41548+ debugl1(cs, "%s", tmp);
41549 }
41550 cs->hw.elsa.rcvcnt = 0;
41551 }
41552diff --git a/drivers/isdn/hisax/hfc_pci.c b/drivers/isdn/hisax/hfc_pci.c
41553index 3ccd724..497bd02 100644
41554--- a/drivers/isdn/hisax/hfc_pci.c
41555+++ b/drivers/isdn/hisax/hfc_pci.c
41556@@ -901,7 +901,7 @@ Begin:
41557 ptr--;
41558 *ptr++ = '\n';
41559 *ptr = 0;
41560- HiSax_putstatus(cs, NULL, cs->dlog);
41561+ HiSax_putstatus(cs, NULL, "%s", cs->dlog);
41562 } else
41563 HiSax_putstatus(cs, "LogEcho: ", "warning Frame too big (%d)", total - 3);
41564 }
41565diff --git a/drivers/isdn/hisax/hfc_sx.c b/drivers/isdn/hisax/hfc_sx.c
41566index dc4574f..fa1fefd 100644
41567--- a/drivers/isdn/hisax/hfc_sx.c
41568+++ b/drivers/isdn/hisax/hfc_sx.c
41569@@ -674,7 +674,7 @@ receive_emsg(struct IsdnCardState *cs)
41570 ptr--;
41571 *ptr++ = '\n';
41572 *ptr = 0;
41573- HiSax_putstatus(cs, NULL, cs->dlog);
41574+ HiSax_putstatus(cs, NULL, "%s", cs->dlog);
41575 } else
41576 HiSax_putstatus(cs, "LogEcho: ", "warning Frame too big (%d)", skb->len);
41577 }
41578diff --git a/drivers/isdn/hisax/hscx_irq.c b/drivers/isdn/hisax/hscx_irq.c
41579index f398d48..a8d6188 100644
41580--- a/drivers/isdn/hisax/hscx_irq.c
41581+++ b/drivers/isdn/hisax/hscx_irq.c
41582@@ -75,7 +75,7 @@ hscx_empty_fifo(struct BCState *bcs, int count)
41583 t += sprintf(t, "hscx_empty_fifo %c cnt %d",
41584 bcs->hw.hscx.hscx ? 'B' : 'A', count);
41585 QuickHex(t, ptr, count);
41586- debugl1(cs, bcs->blog);
41587+ debugl1(cs, "%s", bcs->blog);
41588 }
41589 }
41590
41591@@ -115,7 +115,7 @@ hscx_fill_fifo(struct BCState *bcs)
41592 t += sprintf(t, "hscx_fill_fifo %c cnt %d",
41593 bcs->hw.hscx.hscx ? 'B' : 'A', count);
41594 QuickHex(t, ptr, count);
41595- debugl1(cs, bcs->blog);
41596+ debugl1(cs, "%s", bcs->blog);
41597 }
41598 }
41599
41600diff --git a/drivers/isdn/hisax/icc.c b/drivers/isdn/hisax/icc.c
41601index db5321f..51dae91 100644
41602--- a/drivers/isdn/hisax/icc.c
41603+++ b/drivers/isdn/hisax/icc.c
41604@@ -134,7 +134,7 @@ icc_empty_fifo(struct IsdnCardState *cs, int count)
41605
41606 t += sprintf(t, "icc_empty_fifo cnt %d", count);
41607 QuickHex(t, ptr, count);
41608- debugl1(cs, cs->dlog);
41609+ debugl1(cs, "%s", cs->dlog);
41610 }
41611 }
41612
41613@@ -176,7 +176,7 @@ icc_fill_fifo(struct IsdnCardState *cs)
41614
41615 t += sprintf(t, "icc_fill_fifo cnt %d", count);
41616 QuickHex(t, ptr, count);
41617- debugl1(cs, cs->dlog);
41618+ debugl1(cs, "%s", cs->dlog);
41619 }
41620 }
41621
41622diff --git a/drivers/isdn/hisax/ipacx.c b/drivers/isdn/hisax/ipacx.c
41623index 74feb5c..5faa5de 100644
41624--- a/drivers/isdn/hisax/ipacx.c
41625+++ b/drivers/isdn/hisax/ipacx.c
41626@@ -260,7 +260,7 @@ dch_empty_fifo(struct IsdnCardState *cs, int count)
41627
41628 t += sprintf(t, "dch_empty_fifo() cnt %d", count);
41629 QuickHex(t, ptr, count);
41630- debugl1(cs, cs->dlog);
41631+ debugl1(cs, "%s", cs->dlog);
41632 }
41633 }
41634
41635@@ -307,7 +307,7 @@ dch_fill_fifo(struct IsdnCardState *cs)
41636
41637 t += sprintf(t, "dch_fill_fifo() cnt %d", count);
41638 QuickHex(t, ptr, count);
41639- debugl1(cs, cs->dlog);
41640+ debugl1(cs, "%s", cs->dlog);
41641 }
41642 }
41643
41644@@ -539,7 +539,7 @@ bch_empty_fifo(struct BCState *bcs, int count)
41645
41646 t += sprintf(t, "bch_empty_fifo() B-%d cnt %d", hscx, count);
41647 QuickHex(t, ptr, count);
41648- debugl1(cs, bcs->blog);
41649+ debugl1(cs, "%s", bcs->blog);
41650 }
41651 }
41652
41653@@ -582,7 +582,7 @@ bch_fill_fifo(struct BCState *bcs)
41654
41655 t += sprintf(t, "chb_fill_fifo() B-%d cnt %d", hscx, count);
41656 QuickHex(t, ptr, count);
41657- debugl1(cs, bcs->blog);
41658+ debugl1(cs, "%s", bcs->blog);
41659 }
41660 }
41661
41662diff --git a/drivers/isdn/hisax/isac.c b/drivers/isdn/hisax/isac.c
41663index a365ccc..7fdf78f 100644
41664--- a/drivers/isdn/hisax/isac.c
41665+++ b/drivers/isdn/hisax/isac.c
41666@@ -137,7 +137,7 @@ isac_empty_fifo(struct IsdnCardState *cs, int count)
41667
41668 t += sprintf(t, "isac_empty_fifo cnt %d", count);
41669 QuickHex(t, ptr, count);
41670- debugl1(cs, cs->dlog);
41671+ debugl1(cs, "%s", cs->dlog);
41672 }
41673 }
41674
41675@@ -179,7 +179,7 @@ isac_fill_fifo(struct IsdnCardState *cs)
41676
41677 t += sprintf(t, "isac_fill_fifo cnt %d", count);
41678 QuickHex(t, ptr, count);
41679- debugl1(cs, cs->dlog);
41680+ debugl1(cs, "%s", cs->dlog);
41681 }
41682 }
41683
41684diff --git a/drivers/isdn/hisax/isar.c b/drivers/isdn/hisax/isar.c
41685index 7fdf347..f4956c7 100644
41686--- a/drivers/isdn/hisax/isar.c
41687+++ b/drivers/isdn/hisax/isar.c
41688@@ -74,7 +74,7 @@ sendmsg(struct IsdnCardState *cs, u_char his, u_char creg, u_char len,
41689 t = tmp;
41690 t += sprintf(t, "sendmbox cnt %d", len);
41691 QuickHex(t, &msg[len-i], (i > 64) ? 64 : i);
41692- debugl1(cs, tmp);
41693+ debugl1(cs, "%s", tmp);
41694 i -= 64;
41695 }
41696 }
41697@@ -105,7 +105,7 @@ rcv_mbox(struct IsdnCardState *cs, struct isar_reg *ireg, u_char *msg)
41698 t = tmp;
41699 t += sprintf(t, "rcv_mbox cnt %d", ireg->clsb);
41700 QuickHex(t, &msg[ireg->clsb - i], (i > 64) ? 64 : i);
41701- debugl1(cs, tmp);
41702+ debugl1(cs, "%s", tmp);
41703 i -= 64;
41704 }
41705 }
41706@@ -1248,7 +1248,7 @@ isar_int_main(struct IsdnCardState *cs)
41707 tp += sprintf(debbuf, "msg iis(%x) msb(%x)",
41708 ireg->iis, ireg->cmsb);
41709 QuickHex(tp, (u_char *)ireg->par, ireg->clsb);
41710- debugl1(cs, debbuf);
41711+ debugl1(cs, "%s", debbuf);
41712 }
41713 break;
41714 case ISAR_IIS_INVMSG:
41715diff --git a/drivers/isdn/hisax/jade.c b/drivers/isdn/hisax/jade.c
41716index f946c58..e2ae787 100644
41717--- a/drivers/isdn/hisax/jade.c
41718+++ b/drivers/isdn/hisax/jade.c
41719@@ -81,10 +81,7 @@ modejade(struct BCState *bcs, int mode, int bc)
41720 int jade = bcs->hw.hscx.hscx;
41721
41722 if (cs->debug & L1_DEB_HSCX) {
41723- char tmp[40];
41724- sprintf(tmp, "jade %c mode %d ichan %d",
41725- 'A' + jade, mode, bc);
41726- debugl1(cs, tmp);
41727+ debugl1(cs, "jade %c mode %d ichan %d", 'A' + jade, mode, bc);
41728 }
41729 bcs->mode = mode;
41730 bcs->channel = bc;
41731@@ -257,23 +254,18 @@ void
41732 clear_pending_jade_ints(struct IsdnCardState *cs)
41733 {
41734 int val;
41735- char tmp[64];
41736
41737 cs->BC_Write_Reg(cs, 0, jade_HDLC_IMR, 0x00);
41738 cs->BC_Write_Reg(cs, 1, jade_HDLC_IMR, 0x00);
41739
41740 val = cs->BC_Read_Reg(cs, 1, jade_HDLC_ISR);
41741- sprintf(tmp, "jade B ISTA %x", val);
41742- debugl1(cs, tmp);
41743+ debugl1(cs, "jade B ISTA %x", val);
41744 val = cs->BC_Read_Reg(cs, 0, jade_HDLC_ISR);
41745- sprintf(tmp, "jade A ISTA %x", val);
41746- debugl1(cs, tmp);
41747+ debugl1(cs, "jade A ISTA %x", val);
41748 val = cs->BC_Read_Reg(cs, 1, jade_HDLC_STAR);
41749- sprintf(tmp, "jade B STAR %x", val);
41750- debugl1(cs, tmp);
41751+ debugl1(cs, "jade B STAR %x", val);
41752 val = cs->BC_Read_Reg(cs, 0, jade_HDLC_STAR);
41753- sprintf(tmp, "jade A STAR %x", val);
41754- debugl1(cs, tmp);
41755+ debugl1(cs, "jade A STAR %x", val);
41756 /* Unmask ints */
41757 cs->BC_Write_Reg(cs, 0, jade_HDLC_IMR, 0xF8);
41758 cs->BC_Write_Reg(cs, 1, jade_HDLC_IMR, 0xF8);
41759diff --git a/drivers/isdn/hisax/jade_irq.c b/drivers/isdn/hisax/jade_irq.c
41760index f521fc8..b930da9 100644
41761--- a/drivers/isdn/hisax/jade_irq.c
41762+++ b/drivers/isdn/hisax/jade_irq.c
41763@@ -65,7 +65,7 @@ jade_empty_fifo(struct BCState *bcs, int count)
41764 t += sprintf(t, "jade_empty_fifo %c cnt %d",
41765 bcs->hw.hscx.hscx ? 'B' : 'A', count);
41766 QuickHex(t, ptr, count);
41767- debugl1(cs, bcs->blog);
41768+ debugl1(cs, "%s", bcs->blog);
41769 }
41770 }
41771
41772@@ -105,7 +105,7 @@ jade_fill_fifo(struct BCState *bcs)
41773 t += sprintf(t, "jade_fill_fifo %c cnt %d",
41774 bcs->hw.hscx.hscx ? 'B' : 'A', count);
41775 QuickHex(t, ptr, count);
41776- debugl1(cs, bcs->blog);
41777+ debugl1(cs, "%s", bcs->blog);
41778 }
41779 }
41780
41781diff --git a/drivers/isdn/hisax/l3_1tr6.c b/drivers/isdn/hisax/l3_1tr6.c
41782index 4c1bca5..875402e 100644
41783--- a/drivers/isdn/hisax/l3_1tr6.c
41784+++ b/drivers/isdn/hisax/l3_1tr6.c
41785@@ -63,7 +63,7 @@ l3_1tr6_error(struct l3_process *pc, u_char *msg, struct sk_buff *skb)
41786 {
41787 dev_kfree_skb(skb);
41788 if (pc->st->l3.debug & L3_DEB_WARN)
41789- l3_debug(pc->st, msg);
41790+ l3_debug(pc->st, "%s", msg);
41791 l3_1tr6_release_req(pc, 0, NULL);
41792 }
41793
41794@@ -161,7 +161,6 @@ l3_1tr6_setup(struct l3_process *pc, u_char pr, void *arg)
41795 {
41796 u_char *p;
41797 int bcfound = 0;
41798- char tmp[80];
41799 struct sk_buff *skb = arg;
41800
41801 /* Channel Identification */
41802@@ -214,10 +213,9 @@ l3_1tr6_setup(struct l3_process *pc, u_char pr, void *arg)
41803 /* Signal all services, linklevel takes care of Service-Indicator */
41804 if (bcfound) {
41805 if ((pc->para.setup.si1 != 7) && (pc->st->l3.debug & L3_DEB_WARN)) {
41806- sprintf(tmp, "non-digital call: %s -> %s",
41807+ l3_debug(pc->st, "non-digital call: %s -> %s",
41808 pc->para.setup.phone,
41809 pc->para.setup.eazmsn);
41810- l3_debug(pc->st, tmp);
41811 }
41812 newl3state(pc, 6);
41813 pc->st->l3.l3l4(pc->st, CC_SETUP | INDICATION, pc);
41814@@ -301,7 +299,7 @@ l3_1tr6_info(struct l3_process *pc, u_char pr, void *arg)
41815 {
41816 u_char *p;
41817 int i, tmpcharge = 0;
41818- char a_charge[8], tmp[32];
41819+ char a_charge[8];
41820 struct sk_buff *skb = arg;
41821
41822 p = skb->data;
41823@@ -316,8 +314,8 @@ l3_1tr6_info(struct l3_process *pc, u_char pr, void *arg)
41824 pc->st->l3.l3l4(pc->st, CC_CHARGE | INDICATION, pc);
41825 }
41826 if (pc->st->l3.debug & L3_DEB_CHARGE) {
41827- sprintf(tmp, "charging info %d", pc->para.chargeinfo);
41828- l3_debug(pc->st, tmp);
41829+ l3_debug(pc->st, "charging info %d",
41830+ pc->para.chargeinfo);
41831 }
41832 } else if (pc->st->l3.debug & L3_DEB_CHARGE)
41833 l3_debug(pc->st, "charging info not found");
41834@@ -399,7 +397,7 @@ l3_1tr6_disc(struct l3_process *pc, u_char pr, void *arg)
41835 struct sk_buff *skb = arg;
41836 u_char *p;
41837 int i, tmpcharge = 0;
41838- char a_charge[8], tmp[32];
41839+ char a_charge[8];
41840
41841 StopAllL3Timer(pc);
41842 p = skb->data;
41843@@ -414,8 +412,8 @@ l3_1tr6_disc(struct l3_process *pc, u_char pr, void *arg)
41844 pc->st->l3.l3l4(pc->st, CC_CHARGE | INDICATION, pc);
41845 }
41846 if (pc->st->l3.debug & L3_DEB_CHARGE) {
41847- sprintf(tmp, "charging info %d", pc->para.chargeinfo);
41848- l3_debug(pc->st, tmp);
41849+ l3_debug(pc->st, "charging info %d",
41850+ pc->para.chargeinfo);
41851 }
41852 } else if (pc->st->l3.debug & L3_DEB_CHARGE)
41853 l3_debug(pc->st, "charging info not found");
41854@@ -746,7 +744,6 @@ up1tr6(struct PStack *st, int pr, void *arg)
41855 int i, mt, cr;
41856 struct l3_process *proc;
41857 struct sk_buff *skb = arg;
41858- char tmp[80];
41859
41860 switch (pr) {
41861 case (DL_DATA | INDICATION):
41862@@ -762,26 +759,23 @@ up1tr6(struct PStack *st, int pr, void *arg)
41863 }
41864 if (skb->len < 4) {
41865 if (st->l3.debug & L3_DEB_PROTERR) {
41866- sprintf(tmp, "up1tr6 len only %d", skb->len);
41867- l3_debug(st, tmp);
41868+ l3_debug(st, "up1tr6 len only %d", skb->len);
41869 }
41870 dev_kfree_skb(skb);
41871 return;
41872 }
41873 if ((skb->data[0] & 0xfe) != PROTO_DIS_N0) {
41874 if (st->l3.debug & L3_DEB_PROTERR) {
41875- sprintf(tmp, "up1tr6%sunexpected discriminator %x message len %d",
41876+ l3_debug(st, "up1tr6%sunexpected discriminator %x message len %d",
41877 (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ",
41878 skb->data[0], skb->len);
41879- l3_debug(st, tmp);
41880 }
41881 dev_kfree_skb(skb);
41882 return;
41883 }
41884 if (skb->data[1] != 1) {
41885 if (st->l3.debug & L3_DEB_PROTERR) {
41886- sprintf(tmp, "up1tr6 CR len not 1");
41887- l3_debug(st, tmp);
41888+ l3_debug(st, "up1tr6 CR len not 1");
41889 }
41890 dev_kfree_skb(skb);
41891 return;
41892@@ -791,9 +785,8 @@ up1tr6(struct PStack *st, int pr, void *arg)
41893 if (skb->data[0] == PROTO_DIS_N0) {
41894 dev_kfree_skb(skb);
41895 if (st->l3.debug & L3_DEB_STATE) {
41896- sprintf(tmp, "up1tr6%s N0 mt %x unhandled",
41897+ l3_debug(st, "up1tr6%s N0 mt %x unhandled",
41898 (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ", mt);
41899- l3_debug(st, tmp);
41900 }
41901 } else if (skb->data[0] == PROTO_DIS_N1) {
41902 if (!(proc = getl3proc(st, cr))) {
41903@@ -801,8 +794,7 @@ up1tr6(struct PStack *st, int pr, void *arg)
41904 if (cr < 128) {
41905 if (!(proc = new_l3_process(st, cr))) {
41906 if (st->l3.debug & L3_DEB_PROTERR) {
41907- sprintf(tmp, "up1tr6 no roc mem");
41908- l3_debug(st, tmp);
41909+ l3_debug(st, "up1tr6 no roc mem");
41910 }
41911 dev_kfree_skb(skb);
41912 return;
41913@@ -821,8 +813,7 @@ up1tr6(struct PStack *st, int pr, void *arg)
41914 } else {
41915 if (!(proc = new_l3_process(st, cr))) {
41916 if (st->l3.debug & L3_DEB_PROTERR) {
41917- sprintf(tmp, "up1tr6 no roc mem");
41918- l3_debug(st, tmp);
41919+ l3_debug(st, "up1tr6 no roc mem");
41920 }
41921 dev_kfree_skb(skb);
41922 return;
41923@@ -837,18 +828,16 @@ up1tr6(struct PStack *st, int pr, void *arg)
41924 if (i == ARRAY_SIZE(datastln1)) {
41925 dev_kfree_skb(skb);
41926 if (st->l3.debug & L3_DEB_STATE) {
41927- sprintf(tmp, "up1tr6%sstate %d mt %x unhandled",
41928+ l3_debug(st, "up1tr6%sstate %d mt %x unhandled",
41929 (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ",
41930 proc->state, mt);
41931- l3_debug(st, tmp);
41932 }
41933 return;
41934 } else {
41935 if (st->l3.debug & L3_DEB_STATE) {
41936- sprintf(tmp, "up1tr6%sstate %d mt %x",
41937+ l3_debug(st, "up1tr6%sstate %d mt %x",
41938 (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ",
41939 proc->state, mt);
41940- l3_debug(st, tmp);
41941 }
41942 datastln1[i].rout(proc, pr, skb);
41943 }
41944@@ -861,7 +850,6 @@ down1tr6(struct PStack *st, int pr, void *arg)
41945 int i, cr;
41946 struct l3_process *proc;
41947 struct Channel *chan;
41948- char tmp[80];
41949
41950 if ((DL_ESTABLISH | REQUEST) == pr) {
41951 l3_msg(st, pr, NULL);
41952@@ -888,15 +876,13 @@ down1tr6(struct PStack *st, int pr, void *arg)
41953 break;
41954 if (i == ARRAY_SIZE(downstl)) {
41955 if (st->l3.debug & L3_DEB_STATE) {
41956- sprintf(tmp, "down1tr6 state %d prim %d unhandled",
41957+ l3_debug(st, "down1tr6 state %d prim %d unhandled",
41958 proc->state, pr);
41959- l3_debug(st, tmp);
41960 }
41961 } else {
41962 if (st->l3.debug & L3_DEB_STATE) {
41963- sprintf(tmp, "down1tr6 state %d prim %d",
41964+ l3_debug(st, "down1tr6 state %d prim %d",
41965 proc->state, pr);
41966- l3_debug(st, tmp);
41967 }
41968 downstl[i].rout(proc, pr, arg);
41969 }
41970diff --git a/drivers/isdn/hisax/netjet.c b/drivers/isdn/hisax/netjet.c
41971index b646eed..233e432 100644
41972--- a/drivers/isdn/hisax/netjet.c
41973+++ b/drivers/isdn/hisax/netjet.c
41974@@ -176,7 +176,7 @@ static void printframe(struct IsdnCardState *cs, u_char *buf, int count, char *s
41975 else
41976 j = i;
41977 QuickHex(t, p, j);
41978- debugl1(cs, tmp);
41979+ debugl1(cs, "%s", tmp);
41980 p += j;
41981 i -= j;
41982 t = tmp;
41983diff --git a/drivers/isdn/hisax/q931.c b/drivers/isdn/hisax/q931.c
41984index 041bf52..af1b020 100644
41985--- a/drivers/isdn/hisax/q931.c
41986+++ b/drivers/isdn/hisax/q931.c
41987@@ -1179,7 +1179,7 @@ LogFrame(struct IsdnCardState *cs, u_char *buf, int size)
41988 dp--;
41989 *dp++ = '\n';
41990 *dp = 0;
41991- HiSax_putstatus(cs, NULL, cs->dlog);
41992+ HiSax_putstatus(cs, NULL, "%s", cs->dlog);
41993 } else
41994 HiSax_putstatus(cs, "LogFrame: ", "warning Frame too big (%d)", size);
41995 }
41996@@ -1246,7 +1246,7 @@ dlogframe(struct IsdnCardState *cs, struct sk_buff *skb, int dir)
41997 }
41998 if (finish) {
41999 *dp = 0;
42000- HiSax_putstatus(cs, NULL, cs->dlog);
42001+ HiSax_putstatus(cs, NULL, "%s", cs->dlog);
42002 return;
42003 }
42004 if ((0xfe & buf[0]) == PROTO_DIS_N0) { /* 1TR6 */
42005@@ -1509,5 +1509,5 @@ dlogframe(struct IsdnCardState *cs, struct sk_buff *skb, int dir)
42006 dp += sprintf(dp, "Unknown protocol %x!", buf[0]);
42007 }
42008 *dp = 0;
42009- HiSax_putstatus(cs, NULL, cs->dlog);
42010+ HiSax_putstatus(cs, NULL, "%s", cs->dlog);
42011 }
42012diff --git a/drivers/isdn/hisax/w6692.c b/drivers/isdn/hisax/w6692.c
42013index d8cac69..a858955 100644
42014--- a/drivers/isdn/hisax/w6692.c
42015+++ b/drivers/isdn/hisax/w6692.c
42016@@ -154,7 +154,7 @@ W6692_empty_fifo(struct IsdnCardState *cs, int count)
42017
42018 t += sprintf(t, "W6692_empty_fifo cnt %d", count);
42019 QuickHex(t, ptr, count);
42020- debugl1(cs, cs->dlog);
42021+ debugl1(cs, "%s", cs->dlog);
42022 }
42023 }
42024
42025@@ -196,7 +196,7 @@ W6692_fill_fifo(struct IsdnCardState *cs)
42026
42027 t += sprintf(t, "W6692_fill_fifo cnt %d", count);
42028 QuickHex(t, ptr, count);
42029- debugl1(cs, cs->dlog);
42030+ debugl1(cs, "%s", cs->dlog);
42031 }
42032 }
42033
42034@@ -226,7 +226,7 @@ W6692B_empty_fifo(struct BCState *bcs, int count)
42035 t += sprintf(t, "W6692B_empty_fifo %c cnt %d",
42036 bcs->channel + '1', count);
42037 QuickHex(t, ptr, count);
42038- debugl1(cs, bcs->blog);
42039+ debugl1(cs, "%s", bcs->blog);
42040 }
42041 }
42042
42043@@ -264,7 +264,7 @@ W6692B_fill_fifo(struct BCState *bcs)
42044 t += sprintf(t, "W6692B_fill_fifo %c cnt %d",
42045 bcs->channel + '1', count);
42046 QuickHex(t, ptr, count);
42047- debugl1(cs, bcs->blog);
42048+ debugl1(cs, "%s", bcs->blog);
42049 }
42050 }
42051
42052diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
42053index 9bb12ba..d4262f7 100644
42054--- a/drivers/isdn/i4l/isdn_common.c
42055+++ b/drivers/isdn/i4l/isdn_common.c
42056@@ -1651,6 +1651,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
42057 } else
42058 return -EINVAL;
42059 case IIOCDBGVAR:
42060+ if (!capable(CAP_SYS_RAWIO))
42061+ return -EPERM;
42062 if (arg) {
42063 if (copy_to_user(argp, &dev, sizeof(ulong)))
42064 return -EFAULT;
42065diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
42066index 3c5f249..5fac4d0 100644
42067--- a/drivers/isdn/i4l/isdn_tty.c
42068+++ b/drivers/isdn/i4l/isdn_tty.c
42069@@ -1508,9 +1508,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
42070
42071 #ifdef ISDN_DEBUG_MODEM_OPEN
42072 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
42073- port->count);
42074+ atomic_read(&port->count));
42075 #endif
42076- port->count++;
42077+ atomic_inc(&port->count);
42078 port->tty = tty;
42079 /*
42080 * Start up serial port
42081@@ -1554,7 +1554,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
42082 #endif
42083 return;
42084 }
42085- if ((tty->count == 1) && (port->count != 1)) {
42086+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
42087 /*
42088 * Uh, oh. tty->count is 1, which means that the tty
42089 * structure will be freed. Info->count should always
42090@@ -1563,15 +1563,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
42091 * serial port won't be shutdown.
42092 */
42093 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
42094- "info->count is %d\n", port->count);
42095- port->count = 1;
42096+ "info->count is %d\n", atomic_read(&port->count));
42097+ atomic_set(&port->count, 1);
42098 }
42099- if (--port->count < 0) {
42100+ if (atomic_dec_return(&port->count) < 0) {
42101 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
42102- info->line, port->count);
42103- port->count = 0;
42104+ info->line, atomic_read(&port->count));
42105+ atomic_set(&port->count, 0);
42106 }
42107- if (port->count) {
42108+ if (atomic_read(&port->count)) {
42109 #ifdef ISDN_DEBUG_MODEM_OPEN
42110 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
42111 #endif
42112@@ -1625,7 +1625,7 @@ isdn_tty_hangup(struct tty_struct *tty)
42113 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
42114 return;
42115 isdn_tty_shutdown(info);
42116- port->count = 0;
42117+ atomic_set(&port->count, 0);
42118 port->flags &= ~ASYNC_NORMAL_ACTIVE;
42119 port->tty = NULL;
42120 wake_up_interruptible(&port->open_wait);
42121@@ -1970,7 +1970,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
42122 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
42123 modem_info *info = &dev->mdm.info[i];
42124
42125- if (info->port.count == 0)
42126+ if (atomic_read(&info->port.count) == 0)
42127 continue;
42128 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
42129 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
42130diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
42131index e74df7c..03a03ba 100644
42132--- a/drivers/isdn/icn/icn.c
42133+++ b/drivers/isdn/icn/icn.c
42134@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
42135 if (count > len)
42136 count = len;
42137 if (user) {
42138- if (copy_from_user(msg, buf, count))
42139+ if (count > sizeof msg || copy_from_user(msg, buf, count))
42140 return -EFAULT;
42141 } else
42142 memcpy(msg, buf, count);
42143diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
42144index 6a8405d..0bd1c7e 100644
42145--- a/drivers/leds/leds-clevo-mail.c
42146+++ b/drivers/leds/leds-clevo-mail.c
42147@@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
42148 * detected as working, but in reality it is not) as low as
42149 * possible.
42150 */
42151-static struct dmi_system_id __initdata clevo_mail_led_dmi_table[] = {
42152+static const struct dmi_system_id __initconst clevo_mail_led_dmi_table[] = {
42153 {
42154 .callback = clevo_mail_led_dmi_callback,
42155 .ident = "Clevo D410J",
42156diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
42157index 64e204e..c6bf189 100644
42158--- a/drivers/leds/leds-ss4200.c
42159+++ b/drivers/leds/leds-ss4200.c
42160@@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
42161 * detected as working, but in reality it is not) as low as
42162 * possible.
42163 */
42164-static struct dmi_system_id __initdata nas_led_whitelist[] = {
42165+static const struct dmi_system_id __initconst nas_led_whitelist[] = {
42166 {
42167 .callback = ss4200_led_dmi_callback,
42168 .ident = "Intel SS4200-E",
42169diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
42170index 0bf1e4e..b4bf44e 100644
42171--- a/drivers/lguest/core.c
42172+++ b/drivers/lguest/core.c
42173@@ -97,9 +97,17 @@ static __init int map_switcher(void)
42174 * The end address needs +1 because __get_vm_area allocates an
42175 * extra guard page, so we need space for that.
42176 */
42177+
42178+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
42179+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
42180+ VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
42181+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
42182+#else
42183 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
42184 VM_ALLOC, switcher_addr, switcher_addr
42185 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
42186+#endif
42187+
42188 if (!switcher_vma) {
42189 err = -ENOMEM;
42190 printk("lguest: could not map switcher pages high\n");
42191@@ -124,7 +132,7 @@ static __init int map_switcher(void)
42192 * Now the Switcher is mapped at the right address, we can't fail!
42193 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
42194 */
42195- memcpy(switcher_vma->addr, start_switcher_text,
42196+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
42197 end_switcher_text - start_switcher_text);
42198
42199 printk(KERN_INFO "lguest: mapped switcher at %p\n",
42200diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
42201index a35d8d1..59fb772 100644
42202--- a/drivers/lguest/page_tables.c
42203+++ b/drivers/lguest/page_tables.c
42204@@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
42205 /*:*/
42206
42207 #ifdef CONFIG_X86_PAE
42208-static void release_pmd(pmd_t *spmd)
42209+static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
42210 {
42211 /* If the entry's not present, there's nothing to release. */
42212 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
42213diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
42214index 5169239..47cb4db 100644
42215--- a/drivers/lguest/x86/core.c
42216+++ b/drivers/lguest/x86/core.c
42217@@ -59,7 +59,7 @@ static struct {
42218 /* Offset from where switcher.S was compiled to where we've copied it */
42219 static unsigned long switcher_offset(void)
42220 {
42221- return switcher_addr - (unsigned long)start_switcher_text;
42222+ return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
42223 }
42224
42225 /* This cpu's struct lguest_pages (after the Switcher text page) */
42226@@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
42227 * These copies are pretty cheap, so we do them unconditionally: */
42228 /* Save the current Host top-level page directory.
42229 */
42230+
42231+#ifdef CONFIG_PAX_PER_CPU_PGD
42232+ pages->state.host_cr3 = read_cr3();
42233+#else
42234 pages->state.host_cr3 = __pa(current->mm->pgd);
42235+#endif
42236+
42237 /*
42238 * Set up the Guest's page tables to see this CPU's pages (and no
42239 * other CPU's pages).
42240@@ -475,7 +481,7 @@ void __init lguest_arch_host_init(void)
42241 * compiled-in switcher code and the high-mapped copy we just made.
42242 */
42243 for (i = 0; i < IDT_ENTRIES; i++)
42244- default_idt_entries[i] += switcher_offset();
42245+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
42246
42247 /*
42248 * Set up the Switcher's per-cpu areas.
42249@@ -558,7 +564,7 @@ void __init lguest_arch_host_init(void)
42250 * it will be undisturbed when we switch. To change %cs and jump we
42251 * need this structure to feed to Intel's "lcall" instruction.
42252 */
42253- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
42254+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
42255 lguest_entry.segment = LGUEST_CS;
42256
42257 /*
42258diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
42259index 40634b0..4f5855e 100644
42260--- a/drivers/lguest/x86/switcher_32.S
42261+++ b/drivers/lguest/x86/switcher_32.S
42262@@ -87,6 +87,7 @@
42263 #include <asm/page.h>
42264 #include <asm/segment.h>
42265 #include <asm/lguest.h>
42266+#include <asm/processor-flags.h>
42267
42268 // We mark the start of the code to copy
42269 // It's placed in .text tho it's never run here
42270@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
42271 // Changes type when we load it: damn Intel!
42272 // For after we switch over our page tables
42273 // That entry will be read-only: we'd crash.
42274+
42275+#ifdef CONFIG_PAX_KERNEXEC
42276+ mov %cr0, %edx
42277+ xor $X86_CR0_WP, %edx
42278+ mov %edx, %cr0
42279+#endif
42280+
42281 movl $(GDT_ENTRY_TSS*8), %edx
42282 ltr %dx
42283
42284@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
42285 // Let's clear it again for our return.
42286 // The GDT descriptor of the Host
42287 // Points to the table after two "size" bytes
42288- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
42289+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
42290 // Clear "used" from type field (byte 5, bit 2)
42291- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
42292+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
42293+
42294+#ifdef CONFIG_PAX_KERNEXEC
42295+ mov %cr0, %eax
42296+ xor $X86_CR0_WP, %eax
42297+ mov %eax, %cr0
42298+#endif
42299
42300 // Once our page table's switched, the Guest is live!
42301 // The Host fades as we run this final step.
42302@@ -295,13 +309,12 @@ deliver_to_host:
42303 // I consulted gcc, and it gave
42304 // These instructions, which I gladly credit:
42305 leal (%edx,%ebx,8), %eax
42306- movzwl (%eax),%edx
42307- movl 4(%eax), %eax
42308- xorw %ax, %ax
42309- orl %eax, %edx
42310+ movl 4(%eax), %edx
42311+ movw (%eax), %dx
42312 // Now the address of the handler's in %edx
42313 // We call it now: its "iret" drops us home.
42314- jmp *%edx
42315+ ljmp $__KERNEL_CS, $1f
42316+1: jmp *%edx
42317
42318 // Every interrupt can come to us here
42319 // But we must truly tell each apart.
42320diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
42321index 0003992..854bbce 100644
42322--- a/drivers/md/bcache/closure.h
42323+++ b/drivers/md/bcache/closure.h
42324@@ -622,7 +622,7 @@ static inline void closure_wake_up(struct closure_waitlist *list)
42325 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
42326 struct workqueue_struct *wq)
42327 {
42328- BUG_ON(object_is_on_stack(cl));
42329+ BUG_ON(object_starts_on_stack(cl));
42330 closure_set_ip(cl);
42331 cl->fn = fn;
42332 cl->wq = wq;
42333diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
42334index 547c4c5..5be1de4 100644
42335--- a/drivers/md/bcache/super.c
42336+++ b/drivers/md/bcache/super.c
42337@@ -1644,7 +1644,7 @@ err_unlock_gc:
42338 err:
42339 closure_sync(&op.cl);
42340 /* XXX: test this, it's broken */
42341- bch_cache_set_error(c, err);
42342+ bch_cache_set_error(c, "%s", err);
42343 }
42344
42345 static bool can_attach_cache(struct cache *ca, struct cache_set *c)
42346diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
42347index a7fd821..9dcf6c3 100644
42348--- a/drivers/md/bitmap.c
42349+++ b/drivers/md/bitmap.c
42350@@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
42351 chunk_kb ? "KB" : "B");
42352 if (bitmap->storage.file) {
42353 seq_printf(seq, ", file: ");
42354- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
42355+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
42356 }
42357
42358 seq_printf(seq, "\n");
42359diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
42360index f1b7586..a49c4bd 100644
42361--- a/drivers/md/dm-ioctl.c
42362+++ b/drivers/md/dm-ioctl.c
42363@@ -1739,7 +1739,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
42364 cmd == DM_LIST_VERSIONS_CMD)
42365 return 0;
42366
42367- if ((cmd == DM_DEV_CREATE_CMD)) {
42368+ if (cmd == DM_DEV_CREATE_CMD) {
42369 if (!*param->name) {
42370 DMWARN("name not supplied when creating device");
42371 return -EINVAL;
42372diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
42373index 699b5be..eac0a15 100644
42374--- a/drivers/md/dm-raid1.c
42375+++ b/drivers/md/dm-raid1.c
42376@@ -40,7 +40,7 @@ enum dm_raid1_error {
42377
42378 struct mirror {
42379 struct mirror_set *ms;
42380- atomic_t error_count;
42381+ atomic_unchecked_t error_count;
42382 unsigned long error_type;
42383 struct dm_dev *dev;
42384 sector_t offset;
42385@@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
42386 struct mirror *m;
42387
42388 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
42389- if (!atomic_read(&m->error_count))
42390+ if (!atomic_read_unchecked(&m->error_count))
42391 return m;
42392
42393 return NULL;
42394@@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
42395 * simple way to tell if a device has encountered
42396 * errors.
42397 */
42398- atomic_inc(&m->error_count);
42399+ atomic_inc_unchecked(&m->error_count);
42400
42401 if (test_and_set_bit(error_type, &m->error_type))
42402 return;
42403@@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
42404 struct mirror *m = get_default_mirror(ms);
42405
42406 do {
42407- if (likely(!atomic_read(&m->error_count)))
42408+ if (likely(!atomic_read_unchecked(&m->error_count)))
42409 return m;
42410
42411 if (m-- == ms->mirror)
42412@@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
42413 {
42414 struct mirror *default_mirror = get_default_mirror(m->ms);
42415
42416- return !atomic_read(&default_mirror->error_count);
42417+ return !atomic_read_unchecked(&default_mirror->error_count);
42418 }
42419
42420 static int mirror_available(struct mirror_set *ms, struct bio *bio)
42421@@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
42422 */
42423 if (likely(region_in_sync(ms, region, 1)))
42424 m = choose_mirror(ms, bio->bi_sector);
42425- else if (m && atomic_read(&m->error_count))
42426+ else if (m && atomic_read_unchecked(&m->error_count))
42427 m = NULL;
42428
42429 if (likely(m))
42430@@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
42431 }
42432
42433 ms->mirror[mirror].ms = ms;
42434- atomic_set(&(ms->mirror[mirror].error_count), 0);
42435+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
42436 ms->mirror[mirror].error_type = 0;
42437 ms->mirror[mirror].offset = offset;
42438
42439@@ -1340,7 +1340,7 @@ static void mirror_resume(struct dm_target *ti)
42440 */
42441 static char device_status_char(struct mirror *m)
42442 {
42443- if (!atomic_read(&(m->error_count)))
42444+ if (!atomic_read_unchecked(&(m->error_count)))
42445 return 'A';
42446
42447 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
42448diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
42449index d907ca6..cfb8384 100644
42450--- a/drivers/md/dm-stripe.c
42451+++ b/drivers/md/dm-stripe.c
42452@@ -20,7 +20,7 @@ struct stripe {
42453 struct dm_dev *dev;
42454 sector_t physical_start;
42455
42456- atomic_t error_count;
42457+ atomic_unchecked_t error_count;
42458 };
42459
42460 struct stripe_c {
42461@@ -185,7 +185,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
42462 kfree(sc);
42463 return r;
42464 }
42465- atomic_set(&(sc->stripe[i].error_count), 0);
42466+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
42467 }
42468
42469 ti->private = sc;
42470@@ -326,7 +326,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
42471 DMEMIT("%d ", sc->stripes);
42472 for (i = 0; i < sc->stripes; i++) {
42473 DMEMIT("%s ", sc->stripe[i].dev->name);
42474- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
42475+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
42476 'D' : 'A';
42477 }
42478 buffer[i] = '\0';
42479@@ -371,8 +371,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
42480 */
42481 for (i = 0; i < sc->stripes; i++)
42482 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
42483- atomic_inc(&(sc->stripe[i].error_count));
42484- if (atomic_read(&(sc->stripe[i].error_count)) <
42485+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
42486+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
42487 DM_IO_ERROR_THRESHOLD)
42488 schedule_work(&sc->trigger_event);
42489 }
42490diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
42491index f221812..aca962b 100644
42492--- a/drivers/md/dm-table.c
42493+++ b/drivers/md/dm-table.c
42494@@ -354,7 +354,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
42495 if (!dev_size)
42496 return 0;
42497
42498- if ((start >= dev_size) || (start + len > dev_size)) {
42499+ if ((start >= dev_size) || (len > dev_size - start)) {
42500 DMWARN("%s: %s too small for target: "
42501 "start=%llu, len=%llu, dev_size=%llu",
42502 dm_device_name(ti->table->md), bdevname(bdev, b),
42503diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
42504index 60bce43..9b997d0 100644
42505--- a/drivers/md/dm-thin-metadata.c
42506+++ b/drivers/md/dm-thin-metadata.c
42507@@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
42508 {
42509 pmd->info.tm = pmd->tm;
42510 pmd->info.levels = 2;
42511- pmd->info.value_type.context = pmd->data_sm;
42512+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
42513 pmd->info.value_type.size = sizeof(__le64);
42514 pmd->info.value_type.inc = data_block_inc;
42515 pmd->info.value_type.dec = data_block_dec;
42516@@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
42517
42518 pmd->bl_info.tm = pmd->tm;
42519 pmd->bl_info.levels = 1;
42520- pmd->bl_info.value_type.context = pmd->data_sm;
42521+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
42522 pmd->bl_info.value_type.size = sizeof(__le64);
42523 pmd->bl_info.value_type.inc = data_block_inc;
42524 pmd->bl_info.value_type.dec = data_block_dec;
42525diff --git a/drivers/md/dm.c b/drivers/md/dm.c
42526index 9e39d2b..fb879a7 100644
42527--- a/drivers/md/dm.c
42528+++ b/drivers/md/dm.c
42529@@ -178,9 +178,9 @@ struct mapped_device {
42530 /*
42531 * Event handling.
42532 */
42533- atomic_t event_nr;
42534+ atomic_unchecked_t event_nr;
42535 wait_queue_head_t eventq;
42536- atomic_t uevent_seq;
42537+ atomic_unchecked_t uevent_seq;
42538 struct list_head uevent_list;
42539 spinlock_t uevent_lock; /* Protect access to uevent_list */
42540
42541@@ -1916,8 +1916,8 @@ static struct mapped_device *alloc_dev(int minor)
42542 spin_lock_init(&md->deferred_lock);
42543 atomic_set(&md->holders, 1);
42544 atomic_set(&md->open_count, 0);
42545- atomic_set(&md->event_nr, 0);
42546- atomic_set(&md->uevent_seq, 0);
42547+ atomic_set_unchecked(&md->event_nr, 0);
42548+ atomic_set_unchecked(&md->uevent_seq, 0);
42549 INIT_LIST_HEAD(&md->uevent_list);
42550 spin_lock_init(&md->uevent_lock);
42551
42552@@ -2068,7 +2068,7 @@ static void event_callback(void *context)
42553
42554 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
42555
42556- atomic_inc(&md->event_nr);
42557+ atomic_inc_unchecked(&md->event_nr);
42558 wake_up(&md->eventq);
42559 }
42560
42561@@ -2716,18 +2716,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
42562
42563 uint32_t dm_next_uevent_seq(struct mapped_device *md)
42564 {
42565- return atomic_add_return(1, &md->uevent_seq);
42566+ return atomic_add_return_unchecked(1, &md->uevent_seq);
42567 }
42568
42569 uint32_t dm_get_event_nr(struct mapped_device *md)
42570 {
42571- return atomic_read(&md->event_nr);
42572+ return atomic_read_unchecked(&md->event_nr);
42573 }
42574
42575 int dm_wait_event(struct mapped_device *md, int event_nr)
42576 {
42577 return wait_event_interruptible(md->eventq,
42578- (event_nr != atomic_read(&md->event_nr)));
42579+ (event_nr != atomic_read_unchecked(&md->event_nr)));
42580 }
42581
42582 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
42583diff --git a/drivers/md/md.c b/drivers/md/md.c
42584index 9f13e13..411a5b8 100644
42585--- a/drivers/md/md.c
42586+++ b/drivers/md/md.c
42587@@ -234,10 +234,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
42588 * start build, activate spare
42589 */
42590 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
42591-static atomic_t md_event_count;
42592+static atomic_unchecked_t md_event_count;
42593 void md_new_event(struct mddev *mddev)
42594 {
42595- atomic_inc(&md_event_count);
42596+ atomic_inc_unchecked(&md_event_count);
42597 wake_up(&md_event_waiters);
42598 }
42599 EXPORT_SYMBOL_GPL(md_new_event);
42600@@ -247,7 +247,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
42601 */
42602 static void md_new_event_inintr(struct mddev *mddev)
42603 {
42604- atomic_inc(&md_event_count);
42605+ atomic_inc_unchecked(&md_event_count);
42606 wake_up(&md_event_waiters);
42607 }
42608
42609@@ -1502,7 +1502,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
42610 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
42611 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
42612 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
42613- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
42614+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
42615
42616 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
42617 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
42618@@ -1746,7 +1746,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
42619 else
42620 sb->resync_offset = cpu_to_le64(0);
42621
42622- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
42623+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
42624
42625 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
42626 sb->size = cpu_to_le64(mddev->dev_sectors);
42627@@ -2751,7 +2751,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
42628 static ssize_t
42629 errors_show(struct md_rdev *rdev, char *page)
42630 {
42631- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
42632+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
42633 }
42634
42635 static ssize_t
42636@@ -2760,7 +2760,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
42637 char *e;
42638 unsigned long n = simple_strtoul(buf, &e, 10);
42639 if (*buf && (*e == 0 || *e == '\n')) {
42640- atomic_set(&rdev->corrected_errors, n);
42641+ atomic_set_unchecked(&rdev->corrected_errors, n);
42642 return len;
42643 }
42644 return -EINVAL;
42645@@ -3208,8 +3208,8 @@ int md_rdev_init(struct md_rdev *rdev)
42646 rdev->sb_loaded = 0;
42647 rdev->bb_page = NULL;
42648 atomic_set(&rdev->nr_pending, 0);
42649- atomic_set(&rdev->read_errors, 0);
42650- atomic_set(&rdev->corrected_errors, 0);
42651+ atomic_set_unchecked(&rdev->read_errors, 0);
42652+ atomic_set_unchecked(&rdev->corrected_errors, 0);
42653
42654 INIT_LIST_HEAD(&rdev->same_set);
42655 init_waitqueue_head(&rdev->blocked_wait);
42656@@ -7024,7 +7024,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
42657
42658 spin_unlock(&pers_lock);
42659 seq_printf(seq, "\n");
42660- seq->poll_event = atomic_read(&md_event_count);
42661+ seq->poll_event = atomic_read_unchecked(&md_event_count);
42662 return 0;
42663 }
42664 if (v == (void*)2) {
42665@@ -7127,7 +7127,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
42666 return error;
42667
42668 seq = file->private_data;
42669- seq->poll_event = atomic_read(&md_event_count);
42670+ seq->poll_event = atomic_read_unchecked(&md_event_count);
42671 return error;
42672 }
42673
42674@@ -7141,7 +7141,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
42675 /* always allow read */
42676 mask = POLLIN | POLLRDNORM;
42677
42678- if (seq->poll_event != atomic_read(&md_event_count))
42679+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
42680 mask |= POLLERR | POLLPRI;
42681 return mask;
42682 }
42683@@ -7185,7 +7185,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
42684 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
42685 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
42686 (int)part_stat_read(&disk->part0, sectors[1]) -
42687- atomic_read(&disk->sync_io);
42688+ atomic_read_unchecked(&disk->sync_io);
42689 /* sync IO will cause sync_io to increase before the disk_stats
42690 * as sync_io is counted when a request starts, and
42691 * disk_stats is counted when it completes.
42692diff --git a/drivers/md/md.h b/drivers/md/md.h
42693index 20f02c0..fd8c821 100644
42694--- a/drivers/md/md.h
42695+++ b/drivers/md/md.h
42696@@ -94,13 +94,13 @@ struct md_rdev {
42697 * only maintained for arrays that
42698 * support hot removal
42699 */
42700- atomic_t read_errors; /* number of consecutive read errors that
42701+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
42702 * we have tried to ignore.
42703 */
42704 struct timespec last_read_error; /* monotonic time since our
42705 * last read error
42706 */
42707- atomic_t corrected_errors; /* number of corrected read errors,
42708+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
42709 * for reporting to userspace and storing
42710 * in superblock.
42711 */
42712@@ -442,7 +442,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
42713
42714 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
42715 {
42716- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
42717+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
42718 }
42719
42720 struct md_personality
42721diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
42722index 3e6d115..ffecdeb 100644
42723--- a/drivers/md/persistent-data/dm-space-map.h
42724+++ b/drivers/md/persistent-data/dm-space-map.h
42725@@ -71,6 +71,7 @@ struct dm_space_map {
42726 dm_sm_threshold_fn fn,
42727 void *context);
42728 };
42729+typedef struct dm_space_map __no_const dm_space_map_no_const;
42730
42731 /*----------------------------------------------------------------*/
42732
42733diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
42734index d60412c..8d4c982 100644
42735--- a/drivers/md/raid1.c
42736+++ b/drivers/md/raid1.c
42737@@ -1823,7 +1823,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
42738 if (r1_sync_page_io(rdev, sect, s,
42739 bio->bi_io_vec[idx].bv_page,
42740 READ) != 0)
42741- atomic_add(s, &rdev->corrected_errors);
42742+ atomic_add_unchecked(s, &rdev->corrected_errors);
42743 }
42744 sectors -= s;
42745 sect += s;
42746@@ -2050,7 +2050,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
42747 test_bit(In_sync, &rdev->flags)) {
42748 if (r1_sync_page_io(rdev, sect, s,
42749 conf->tmppage, READ)) {
42750- atomic_add(s, &rdev->corrected_errors);
42751+ atomic_add_unchecked(s, &rdev->corrected_errors);
42752 printk(KERN_INFO
42753 "md/raid1:%s: read error corrected "
42754 "(%d sectors at %llu on %s)\n",
42755diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
42756index df7b0a0..a257495 100644
42757--- a/drivers/md/raid10.c
42758+++ b/drivers/md/raid10.c
42759@@ -1962,7 +1962,7 @@ static void end_sync_read(struct bio *bio, int error)
42760 /* The write handler will notice the lack of
42761 * R10BIO_Uptodate and record any errors etc
42762 */
42763- atomic_add(r10_bio->sectors,
42764+ atomic_add_unchecked(r10_bio->sectors,
42765 &conf->mirrors[d].rdev->corrected_errors);
42766
42767 /* for reconstruct, we always reschedule after a read.
42768@@ -2320,7 +2320,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
42769 {
42770 struct timespec cur_time_mon;
42771 unsigned long hours_since_last;
42772- unsigned int read_errors = atomic_read(&rdev->read_errors);
42773+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
42774
42775 ktime_get_ts(&cur_time_mon);
42776
42777@@ -2342,9 +2342,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
42778 * overflowing the shift of read_errors by hours_since_last.
42779 */
42780 if (hours_since_last >= 8 * sizeof(read_errors))
42781- atomic_set(&rdev->read_errors, 0);
42782+ atomic_set_unchecked(&rdev->read_errors, 0);
42783 else
42784- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
42785+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
42786 }
42787
42788 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
42789@@ -2398,8 +2398,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
42790 return;
42791
42792 check_decay_read_errors(mddev, rdev);
42793- atomic_inc(&rdev->read_errors);
42794- if (atomic_read(&rdev->read_errors) > max_read_errors) {
42795+ atomic_inc_unchecked(&rdev->read_errors);
42796+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
42797 char b[BDEVNAME_SIZE];
42798 bdevname(rdev->bdev, b);
42799
42800@@ -2407,7 +2407,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
42801 "md/raid10:%s: %s: Raid device exceeded "
42802 "read_error threshold [cur %d:max %d]\n",
42803 mdname(mddev), b,
42804- atomic_read(&rdev->read_errors), max_read_errors);
42805+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
42806 printk(KERN_NOTICE
42807 "md/raid10:%s: %s: Failing raid device\n",
42808 mdname(mddev), b);
42809@@ -2562,7 +2562,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
42810 sect +
42811 choose_data_offset(r10_bio, rdev)),
42812 bdevname(rdev->bdev, b));
42813- atomic_add(s, &rdev->corrected_errors);
42814+ atomic_add_unchecked(s, &rdev->corrected_errors);
42815 }
42816
42817 rdev_dec_pending(rdev, mddev);
42818diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
42819index 78ea443..7d57513 100644
42820--- a/drivers/md/raid5.c
42821+++ b/drivers/md/raid5.c
42822@@ -1764,21 +1764,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
42823 mdname(conf->mddev), STRIPE_SECTORS,
42824 (unsigned long long)s,
42825 bdevname(rdev->bdev, b));
42826- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
42827+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
42828 clear_bit(R5_ReadError, &sh->dev[i].flags);
42829 clear_bit(R5_ReWrite, &sh->dev[i].flags);
42830 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
42831 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
42832
42833- if (atomic_read(&rdev->read_errors))
42834- atomic_set(&rdev->read_errors, 0);
42835+ if (atomic_read_unchecked(&rdev->read_errors))
42836+ atomic_set_unchecked(&rdev->read_errors, 0);
42837 } else {
42838 const char *bdn = bdevname(rdev->bdev, b);
42839 int retry = 0;
42840 int set_bad = 0;
42841
42842 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
42843- atomic_inc(&rdev->read_errors);
42844+ atomic_inc_unchecked(&rdev->read_errors);
42845 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
42846 printk_ratelimited(
42847 KERN_WARNING
42848@@ -1806,7 +1806,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
42849 mdname(conf->mddev),
42850 (unsigned long long)s,
42851 bdn);
42852- } else if (atomic_read(&rdev->read_errors)
42853+ } else if (atomic_read_unchecked(&rdev->read_errors)
42854 > conf->max_nr_stripes)
42855 printk(KERN_WARNING
42856 "md/raid:%s: Too many read errors, failing device %s.\n",
42857diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
42858index 401ef64..836e563 100644
42859--- a/drivers/media/dvb-core/dvbdev.c
42860+++ b/drivers/media/dvb-core/dvbdev.c
42861@@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
42862 const struct dvb_device *template, void *priv, int type)
42863 {
42864 struct dvb_device *dvbdev;
42865- struct file_operations *dvbdevfops;
42866+ file_operations_no_const *dvbdevfops;
42867 struct device *clsdev;
42868 int minor;
42869 int id;
42870diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
42871index 9b6c3bb..baeb5c7 100644
42872--- a/drivers/media/dvb-frontends/dib3000.h
42873+++ b/drivers/media/dvb-frontends/dib3000.h
42874@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
42875 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
42876 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
42877 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
42878-};
42879+} __no_const;
42880
42881 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
42882 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
42883diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
42884index ecf21d9..b992428d 100644
42885--- a/drivers/media/pci/cx88/cx88-video.c
42886+++ b/drivers/media/pci/cx88/cx88-video.c
42887@@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
42888
42889 /* ------------------------------------------------------------------ */
42890
42891-static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42892-static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42893-static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42894+static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42895+static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42896+static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42897
42898 module_param_array(video_nr, int, NULL, 0444);
42899 module_param_array(vbi_nr, int, NULL, 0444);
42900diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
42901index c08ae3e..eb59af1 100644
42902--- a/drivers/media/pci/ivtv/ivtv-driver.c
42903+++ b/drivers/media/pci/ivtv/ivtv-driver.c
42904@@ -83,7 +83,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
42905 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
42906
42907 /* ivtv instance counter */
42908-static atomic_t ivtv_instance = ATOMIC_INIT(0);
42909+static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
42910
42911 /* Parameter declarations */
42912 static int cardtype[IVTV_MAX_CARDS];
42913diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
42914index dfd0a21..6bbb465 100644
42915--- a/drivers/media/platform/omap/omap_vout.c
42916+++ b/drivers/media/platform/omap/omap_vout.c
42917@@ -63,7 +63,6 @@ enum omap_vout_channels {
42918 OMAP_VIDEO2,
42919 };
42920
42921-static struct videobuf_queue_ops video_vbq_ops;
42922 /* Variables configurable through module params*/
42923 static u32 video1_numbuffers = 3;
42924 static u32 video2_numbuffers = 3;
42925@@ -1014,6 +1013,12 @@ static int omap_vout_open(struct file *file)
42926 {
42927 struct videobuf_queue *q;
42928 struct omap_vout_device *vout = NULL;
42929+ static struct videobuf_queue_ops video_vbq_ops = {
42930+ .buf_setup = omap_vout_buffer_setup,
42931+ .buf_prepare = omap_vout_buffer_prepare,
42932+ .buf_release = omap_vout_buffer_release,
42933+ .buf_queue = omap_vout_buffer_queue,
42934+ };
42935
42936 vout = video_drvdata(file);
42937 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
42938@@ -1031,10 +1036,6 @@ static int omap_vout_open(struct file *file)
42939 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
42940
42941 q = &vout->vbq;
42942- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
42943- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
42944- video_vbq_ops.buf_release = omap_vout_buffer_release;
42945- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
42946 spin_lock_init(&vout->vbq_lock);
42947
42948 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
42949diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
42950index 04e6490..2df65bf 100644
42951--- a/drivers/media/platform/s5p-tv/mixer.h
42952+++ b/drivers/media/platform/s5p-tv/mixer.h
42953@@ -156,7 +156,7 @@ struct mxr_layer {
42954 /** layer index (unique identifier) */
42955 int idx;
42956 /** callbacks for layer methods */
42957- struct mxr_layer_ops ops;
42958+ struct mxr_layer_ops *ops;
42959 /** format array */
42960 const struct mxr_format **fmt_array;
42961 /** size of format array */
42962diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
42963index b93a21f..2535195 100644
42964--- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
42965+++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
42966@@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
42967 {
42968 struct mxr_layer *layer;
42969 int ret;
42970- struct mxr_layer_ops ops = {
42971+ static struct mxr_layer_ops ops = {
42972 .release = mxr_graph_layer_release,
42973 .buffer_set = mxr_graph_buffer_set,
42974 .stream_set = mxr_graph_stream_set,
42975diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
42976index b713403..53cb5ad 100644
42977--- a/drivers/media/platform/s5p-tv/mixer_reg.c
42978+++ b/drivers/media/platform/s5p-tv/mixer_reg.c
42979@@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
42980 layer->update_buf = next;
42981 }
42982
42983- layer->ops.buffer_set(layer, layer->update_buf);
42984+ layer->ops->buffer_set(layer, layer->update_buf);
42985
42986 if (done && done != layer->shadow_buf)
42987 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
42988diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
42989index 641b1f0..49cff30 100644
42990--- a/drivers/media/platform/s5p-tv/mixer_video.c
42991+++ b/drivers/media/platform/s5p-tv/mixer_video.c
42992@@ -210,7 +210,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
42993 layer->geo.src.height = layer->geo.src.full_height;
42994
42995 mxr_geometry_dump(mdev, &layer->geo);
42996- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
42997+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
42998 mxr_geometry_dump(mdev, &layer->geo);
42999 }
43000
43001@@ -228,7 +228,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
43002 layer->geo.dst.full_width = mbus_fmt.width;
43003 layer->geo.dst.full_height = mbus_fmt.height;
43004 layer->geo.dst.field = mbus_fmt.field;
43005- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
43006+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
43007
43008 mxr_geometry_dump(mdev, &layer->geo);
43009 }
43010@@ -334,7 +334,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
43011 /* set source size to highest accepted value */
43012 geo->src.full_width = max(geo->dst.full_width, pix->width);
43013 geo->src.full_height = max(geo->dst.full_height, pix->height);
43014- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
43015+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
43016 mxr_geometry_dump(mdev, &layer->geo);
43017 /* set cropping to total visible screen */
43018 geo->src.width = pix->width;
43019@@ -342,12 +342,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
43020 geo->src.x_offset = 0;
43021 geo->src.y_offset = 0;
43022 /* assure consistency of geometry */
43023- layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
43024+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
43025 mxr_geometry_dump(mdev, &layer->geo);
43026 /* set full size to lowest possible value */
43027 geo->src.full_width = 0;
43028 geo->src.full_height = 0;
43029- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
43030+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
43031 mxr_geometry_dump(mdev, &layer->geo);
43032
43033 /* returning results */
43034@@ -474,7 +474,7 @@ static int mxr_s_selection(struct file *file, void *fh,
43035 target->width = s->r.width;
43036 target->height = s->r.height;
43037
43038- layer->ops.fix_geometry(layer, stage, s->flags);
43039+ layer->ops->fix_geometry(layer, stage, s->flags);
43040
43041 /* retrieve update selection rectangle */
43042 res.left = target->x_offset;
43043@@ -955,13 +955,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
43044 mxr_output_get(mdev);
43045
43046 mxr_layer_update_output(layer);
43047- layer->ops.format_set(layer);
43048+ layer->ops->format_set(layer);
43049 /* enabling layer in hardware */
43050 spin_lock_irqsave(&layer->enq_slock, flags);
43051 layer->state = MXR_LAYER_STREAMING;
43052 spin_unlock_irqrestore(&layer->enq_slock, flags);
43053
43054- layer->ops.stream_set(layer, MXR_ENABLE);
43055+ layer->ops->stream_set(layer, MXR_ENABLE);
43056 mxr_streamer_get(mdev);
43057
43058 return 0;
43059@@ -1031,7 +1031,7 @@ static int stop_streaming(struct vb2_queue *vq)
43060 spin_unlock_irqrestore(&layer->enq_slock, flags);
43061
43062 /* disabling layer in hardware */
43063- layer->ops.stream_set(layer, MXR_DISABLE);
43064+ layer->ops->stream_set(layer, MXR_DISABLE);
43065 /* remove one streamer */
43066 mxr_streamer_put(mdev);
43067 /* allow changes in output configuration */
43068@@ -1070,8 +1070,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
43069
43070 void mxr_layer_release(struct mxr_layer *layer)
43071 {
43072- if (layer->ops.release)
43073- layer->ops.release(layer);
43074+ if (layer->ops->release)
43075+ layer->ops->release(layer);
43076 }
43077
43078 void mxr_base_layer_release(struct mxr_layer *layer)
43079@@ -1097,7 +1097,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
43080
43081 layer->mdev = mdev;
43082 layer->idx = idx;
43083- layer->ops = *ops;
43084+ layer->ops = ops;
43085
43086 spin_lock_init(&layer->enq_slock);
43087 INIT_LIST_HEAD(&layer->enq_list);
43088diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
43089index 3d13a63..da31bf1 100644
43090--- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
43091+++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
43092@@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
43093 {
43094 struct mxr_layer *layer;
43095 int ret;
43096- struct mxr_layer_ops ops = {
43097+ static struct mxr_layer_ops ops = {
43098 .release = mxr_vp_layer_release,
43099 .buffer_set = mxr_vp_buffer_set,
43100 .stream_set = mxr_vp_stream_set,
43101diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
43102index 545c04c..a14bded 100644
43103--- a/drivers/media/radio/radio-cadet.c
43104+++ b/drivers/media/radio/radio-cadet.c
43105@@ -324,6 +324,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
43106 unsigned char readbuf[RDS_BUFFER];
43107 int i = 0;
43108
43109+ if (count > RDS_BUFFER)
43110+ return -EFAULT;
43111 mutex_lock(&dev->lock);
43112 if (dev->rdsstat == 0)
43113 cadet_start_rds(dev);
43114@@ -339,7 +341,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
43115 while (i < count && dev->rdsin != dev->rdsout)
43116 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
43117
43118- if (i && copy_to_user(data, readbuf, i))
43119+ if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
43120 i = -EFAULT;
43121 unlock:
43122 mutex_unlock(&dev->lock);
43123diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
43124index bd4d3a7..ffc0b9d 100644
43125--- a/drivers/media/radio/radio-maxiradio.c
43126+++ b/drivers/media/radio/radio-maxiradio.c
43127@@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
43128 /* TEA5757 pin mappings */
43129 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
43130
43131-static atomic_t maxiradio_instance = ATOMIC_INIT(0);
43132+static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
43133
43134 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
43135 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
43136diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
43137index 8fa18ab..caee70f 100644
43138--- a/drivers/media/radio/radio-shark.c
43139+++ b/drivers/media/radio/radio-shark.c
43140@@ -79,7 +79,7 @@ struct shark_device {
43141 u32 last_val;
43142 };
43143
43144-static atomic_t shark_instance = ATOMIC_INIT(0);
43145+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
43146
43147 static void shark_write_val(struct snd_tea575x *tea, u32 val)
43148 {
43149diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
43150index 9fb6697..f167415 100644
43151--- a/drivers/media/radio/radio-shark2.c
43152+++ b/drivers/media/radio/radio-shark2.c
43153@@ -74,7 +74,7 @@ struct shark_device {
43154 u8 *transfer_buffer;
43155 };
43156
43157-static atomic_t shark_instance = ATOMIC_INIT(0);
43158+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
43159
43160 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
43161 {
43162diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
43163index 9c9084c..a9e8dfb 100644
43164--- a/drivers/media/radio/radio-si476x.c
43165+++ b/drivers/media/radio/radio-si476x.c
43166@@ -1445,7 +1445,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
43167 struct si476x_radio *radio;
43168 struct v4l2_ctrl *ctrl;
43169
43170- static atomic_t instance = ATOMIC_INIT(0);
43171+ static atomic_unchecked_t instance = ATOMIC_INIT(0);
43172
43173 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
43174 if (!radio)
43175diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
43176index 1cf382a..c22998c 100644
43177--- a/drivers/media/rc/rc-main.c
43178+++ b/drivers/media/rc/rc-main.c
43179@@ -1030,7 +1030,7 @@ EXPORT_SYMBOL_GPL(rc_free_device);
43180 int rc_register_device(struct rc_dev *dev)
43181 {
43182 static bool raw_init = false; /* raw decoders loaded? */
43183- static atomic_t devno = ATOMIC_INIT(0);
43184+ static atomic_unchecked_t devno = ATOMIC_INIT(0);
43185 struct rc_map *rc_map;
43186 const char *path;
43187 int rc;
43188@@ -1061,7 +1061,7 @@ int rc_register_device(struct rc_dev *dev)
43189 */
43190 mutex_lock(&dev->lock);
43191
43192- dev->devno = (unsigned long)(atomic_inc_return(&devno) - 1);
43193+ dev->devno = (unsigned long)(atomic_inc_return_unchecked(&devno) - 1);
43194 dev_set_name(&dev->dev, "rc%ld", dev->devno);
43195 dev_set_drvdata(&dev->dev, dev);
43196 rc = device_add(&dev->dev);
43197diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
43198index 3940bb0..fb3952a 100644
43199--- a/drivers/media/usb/dvb-usb/cxusb.c
43200+++ b/drivers/media/usb/dvb-usb/cxusb.c
43201@@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
43202
43203 struct dib0700_adapter_state {
43204 int (*set_param_save) (struct dvb_frontend *);
43205-};
43206+} __no_const;
43207
43208 static int dib7070_set_param_override(struct dvb_frontend *fe)
43209 {
43210diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
43211index 6e237b6..dc25556 100644
43212--- a/drivers/media/usb/dvb-usb/dw2102.c
43213+++ b/drivers/media/usb/dvb-usb/dw2102.c
43214@@ -118,7 +118,7 @@ struct su3000_state {
43215
43216 struct s6x0_state {
43217 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
43218-};
43219+} __no_const;
43220
43221 /* debug */
43222 static int dvb_usb_dw2102_debug;
43223diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
43224index 8f7a6a4..59502dd 100644
43225--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
43226+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
43227@@ -326,7 +326,7 @@ struct v4l2_buffer32 {
43228 __u32 reserved;
43229 };
43230
43231-static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
43232+static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
43233 enum v4l2_memory memory)
43234 {
43235 void __user *up_pln;
43236@@ -355,7 +355,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
43237 return 0;
43238 }
43239
43240-static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
43241+static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
43242 enum v4l2_memory memory)
43243 {
43244 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
43245@@ -772,7 +772,7 @@ static int put_v4l2_subdev_edid32(struct v4l2_subdev_edid *kp, struct v4l2_subde
43246 put_user(kp->start_block, &up->start_block) ||
43247 put_user(kp->blocks, &up->blocks) ||
43248 put_user(tmp, &up->edid) ||
43249- copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
43250+ copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
43251 return -EFAULT;
43252 return 0;
43253 }
43254diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
43255index 02d1b63..5fd6b16 100644
43256--- a/drivers/media/v4l2-core/v4l2-device.c
43257+++ b/drivers/media/v4l2-core/v4l2-device.c
43258@@ -75,9 +75,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
43259 EXPORT_SYMBOL_GPL(v4l2_device_put);
43260
43261 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
43262- atomic_t *instance)
43263+ atomic_unchecked_t *instance)
43264 {
43265- int num = atomic_inc_return(instance) - 1;
43266+ int num = atomic_inc_return_unchecked(instance) - 1;
43267 int len = strlen(basename);
43268
43269 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
43270diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
43271index 68e6b5e..d8b923e 100644
43272--- a/drivers/media/v4l2-core/v4l2-ioctl.c
43273+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
43274@@ -1939,7 +1939,8 @@ struct v4l2_ioctl_info {
43275 struct file *file, void *fh, void *p);
43276 } u;
43277 void (*debug)(const void *arg, bool write_only);
43278-};
43279+} __do_const;
43280+typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
43281
43282 /* This control needs a priority check */
43283 #define INFO_FL_PRIO (1 << 0)
43284@@ -2120,7 +2121,7 @@ static long __video_do_ioctl(struct file *file,
43285 struct video_device *vfd = video_devdata(file);
43286 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
43287 bool write_only = false;
43288- struct v4l2_ioctl_info default_info;
43289+ v4l2_ioctl_info_no_const default_info;
43290 const struct v4l2_ioctl_info *info;
43291 void *fh = file->private_data;
43292 struct v4l2_fh *vfh = NULL;
43293@@ -2194,7 +2195,7 @@ done:
43294 }
43295
43296 static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
43297- void * __user *user_ptr, void ***kernel_ptr)
43298+ void __user **user_ptr, void ***kernel_ptr)
43299 {
43300 int ret = 0;
43301
43302@@ -2210,7 +2211,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
43303 ret = -EINVAL;
43304 break;
43305 }
43306- *user_ptr = (void __user *)buf->m.planes;
43307+ *user_ptr = (void __force_user *)buf->m.planes;
43308 *kernel_ptr = (void *)&buf->m.planes;
43309 *array_size = sizeof(struct v4l2_plane) * buf->length;
43310 ret = 1;
43311@@ -2245,7 +2246,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
43312 ret = -EINVAL;
43313 break;
43314 }
43315- *user_ptr = (void __user *)ctrls->controls;
43316+ *user_ptr = (void __force_user *)ctrls->controls;
43317 *kernel_ptr = (void *)&ctrls->controls;
43318 *array_size = sizeof(struct v4l2_ext_control)
43319 * ctrls->count;
43320diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
43321index 767ff4d..c69d259 100644
43322--- a/drivers/message/fusion/mptbase.c
43323+++ b/drivers/message/fusion/mptbase.c
43324@@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
43325 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
43326 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
43327
43328+#ifdef CONFIG_GRKERNSEC_HIDESYM
43329+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
43330+#else
43331 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
43332 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
43333+#endif
43334+
43335 /*
43336 * Rounding UP to nearest 4-kB boundary here...
43337 */
43338@@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
43339 ioc->facts.GlobalCredits);
43340
43341 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
43342+#ifdef CONFIG_GRKERNSEC_HIDESYM
43343+ NULL, NULL);
43344+#else
43345 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
43346+#endif
43347 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
43348 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
43349 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
43350diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
43351index dd239bd..689c4f7 100644
43352--- a/drivers/message/fusion/mptsas.c
43353+++ b/drivers/message/fusion/mptsas.c
43354@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
43355 return 0;
43356 }
43357
43358+static inline void
43359+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
43360+{
43361+ if (phy_info->port_details) {
43362+ phy_info->port_details->rphy = rphy;
43363+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
43364+ ioc->name, rphy));
43365+ }
43366+
43367+ if (rphy) {
43368+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
43369+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
43370+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
43371+ ioc->name, rphy, rphy->dev.release));
43372+ }
43373+}
43374+
43375 /* no mutex */
43376 static void
43377 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
43378@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
43379 return NULL;
43380 }
43381
43382-static inline void
43383-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
43384-{
43385- if (phy_info->port_details) {
43386- phy_info->port_details->rphy = rphy;
43387- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
43388- ioc->name, rphy));
43389- }
43390-
43391- if (rphy) {
43392- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
43393- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
43394- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
43395- ioc->name, rphy, rphy->dev.release));
43396- }
43397-}
43398-
43399 static inline struct sas_port *
43400 mptsas_get_port(struct mptsas_phyinfo *phy_info)
43401 {
43402diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
43403index 727819c..ad74694 100644
43404--- a/drivers/message/fusion/mptscsih.c
43405+++ b/drivers/message/fusion/mptscsih.c
43406@@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
43407
43408 h = shost_priv(SChost);
43409
43410- if (h) {
43411- if (h->info_kbuf == NULL)
43412- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
43413- return h->info_kbuf;
43414- h->info_kbuf[0] = '\0';
43415+ if (!h)
43416+ return NULL;
43417
43418- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
43419- h->info_kbuf[size-1] = '\0';
43420- }
43421+ if (h->info_kbuf == NULL)
43422+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
43423+ return h->info_kbuf;
43424+ h->info_kbuf[0] = '\0';
43425+
43426+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
43427+ h->info_kbuf[size-1] = '\0';
43428
43429 return h->info_kbuf;
43430 }
43431diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
43432index b7d87cd..9890039 100644
43433--- a/drivers/message/i2o/i2o_proc.c
43434+++ b/drivers/message/i2o/i2o_proc.c
43435@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
43436 "Array Controller Device"
43437 };
43438
43439-static char *chtostr(char *tmp, u8 *chars, int n)
43440-{
43441- tmp[0] = 0;
43442- return strncat(tmp, (char *)chars, n);
43443-}
43444-
43445 static int i2o_report_query_status(struct seq_file *seq, int block_status,
43446 char *group)
43447 {
43448@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
43449 } *result;
43450
43451 i2o_exec_execute_ddm_table ddm_table;
43452- char tmp[28 + 1];
43453
43454 result = kmalloc(sizeof(*result), GFP_KERNEL);
43455 if (!result)
43456@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
43457
43458 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
43459 seq_printf(seq, "%-#8x", ddm_table.module_id);
43460- seq_printf(seq, "%-29s",
43461- chtostr(tmp, ddm_table.module_name_version, 28));
43462+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
43463 seq_printf(seq, "%9d ", ddm_table.data_size);
43464 seq_printf(seq, "%8d", ddm_table.code_size);
43465
43466@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
43467
43468 i2o_driver_result_table *result;
43469 i2o_driver_store_table *dst;
43470- char tmp[28 + 1];
43471
43472 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
43473 if (result == NULL)
43474@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
43475
43476 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
43477 seq_printf(seq, "%-#8x", dst->module_id);
43478- seq_printf(seq, "%-29s",
43479- chtostr(tmp, dst->module_name_version, 28));
43480- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
43481+ seq_printf(seq, "%-.28s", dst->module_name_version);
43482+ seq_printf(seq, "%-.8s", dst->date);
43483 seq_printf(seq, "%8d ", dst->module_size);
43484 seq_printf(seq, "%8d ", dst->mpb_size);
43485 seq_printf(seq, "0x%04x", dst->module_flags);
43486@@ -1250,7 +1240,6 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
43487 // == (allow) 512d bytes (max)
43488 static u16 *work16 = (u16 *) work32;
43489 int token;
43490- char tmp[16 + 1];
43491
43492 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
43493
43494@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
43495 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
43496 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
43497 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
43498- seq_printf(seq, "Vendor info : %s\n",
43499- chtostr(tmp, (u8 *) (work32 + 2), 16));
43500- seq_printf(seq, "Product info : %s\n",
43501- chtostr(tmp, (u8 *) (work32 + 6), 16));
43502- seq_printf(seq, "Description : %s\n",
43503- chtostr(tmp, (u8 *) (work32 + 10), 16));
43504- seq_printf(seq, "Product rev. : %s\n",
43505- chtostr(tmp, (u8 *) (work32 + 14), 8));
43506+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
43507+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
43508+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
43509+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
43510
43511 seq_printf(seq, "Serial number : ");
43512 print_serial_number(seq, (u8 *) (work32 + 16),
43513@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
43514 u8 pad[256]; // allow up to 256 byte (max) serial number
43515 } result;
43516
43517- char tmp[24 + 1];
43518-
43519 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
43520
43521 if (token < 0) {
43522@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
43523 }
43524
43525 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
43526- seq_printf(seq, "Module name : %s\n",
43527- chtostr(tmp, result.module_name, 24));
43528- seq_printf(seq, "Module revision : %s\n",
43529- chtostr(tmp, result.module_rev, 8));
43530+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
43531+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
43532
43533 seq_printf(seq, "Serial number : ");
43534 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
43535@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
43536 u8 instance_number[4];
43537 } result;
43538
43539- char tmp[64 + 1];
43540-
43541 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
43542
43543 if (token < 0) {
43544@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
43545 return 0;
43546 }
43547
43548- seq_printf(seq, "Device name : %s\n",
43549- chtostr(tmp, result.device_name, 64));
43550- seq_printf(seq, "Service name : %s\n",
43551- chtostr(tmp, result.service_name, 64));
43552- seq_printf(seq, "Physical name : %s\n",
43553- chtostr(tmp, result.physical_location, 64));
43554- seq_printf(seq, "Instance number : %s\n",
43555- chtostr(tmp, result.instance_number, 4));
43556+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
43557+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
43558+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
43559+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
43560
43561 return 0;
43562 }
43563diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
43564index a8c08f3..155fe3d 100644
43565--- a/drivers/message/i2o/iop.c
43566+++ b/drivers/message/i2o/iop.c
43567@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
43568
43569 spin_lock_irqsave(&c->context_list_lock, flags);
43570
43571- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
43572- atomic_inc(&c->context_list_counter);
43573+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
43574+ atomic_inc_unchecked(&c->context_list_counter);
43575
43576- entry->context = atomic_read(&c->context_list_counter);
43577+ entry->context = atomic_read_unchecked(&c->context_list_counter);
43578
43579 list_add(&entry->list, &c->context_list);
43580
43581@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
43582
43583 #if BITS_PER_LONG == 64
43584 spin_lock_init(&c->context_list_lock);
43585- atomic_set(&c->context_list_counter, 0);
43586+ atomic_set_unchecked(&c->context_list_counter, 0);
43587 INIT_LIST_HEAD(&c->context_list);
43588 #endif
43589
43590diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
43591index fcbb2e9..2635e11 100644
43592--- a/drivers/mfd/janz-cmodio.c
43593+++ b/drivers/mfd/janz-cmodio.c
43594@@ -13,6 +13,7 @@
43595
43596 #include <linux/kernel.h>
43597 #include <linux/module.h>
43598+#include <linux/slab.h>
43599 #include <linux/init.h>
43600 #include <linux/pci.h>
43601 #include <linux/interrupt.h>
43602diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
43603index 9aa6d1e..1631bfc 100644
43604--- a/drivers/mfd/twl4030-irq.c
43605+++ b/drivers/mfd/twl4030-irq.c
43606@@ -35,6 +35,7 @@
43607 #include <linux/of.h>
43608 #include <linux/irqdomain.h>
43609 #include <linux/i2c/twl.h>
43610+#include <asm/pgtable.h>
43611
43612 #include "twl-core.h"
43613
43614@@ -726,10 +727,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
43615 * Install an irq handler for each of the SIH modules;
43616 * clone dummy irq_chip since PIH can't *do* anything
43617 */
43618- twl4030_irq_chip = dummy_irq_chip;
43619- twl4030_irq_chip.name = "twl4030";
43620+ pax_open_kernel();
43621+ memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
43622+ *(const char **)&twl4030_irq_chip.name = "twl4030";
43623
43624- twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
43625+ *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
43626+ pax_close_kernel();
43627
43628 for (i = irq_base; i < irq_end; i++) {
43629 irq_set_chip_and_handler(i, &twl4030_irq_chip,
43630diff --git a/drivers/mfd/twl6030-irq.c b/drivers/mfd/twl6030-irq.c
43631index 277a8db..0e0b754 100644
43632--- a/drivers/mfd/twl6030-irq.c
43633+++ b/drivers/mfd/twl6030-irq.c
43634@@ -387,10 +387,12 @@ int twl6030_init_irq(struct device *dev, int irq_num)
43635 * install an irq handler for each of the modules;
43636 * clone dummy irq_chip since PIH can't *do* anything
43637 */
43638- twl6030_irq_chip = dummy_irq_chip;
43639- twl6030_irq_chip.name = "twl6030";
43640- twl6030_irq_chip.irq_set_type = NULL;
43641- twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake;
43642+ pax_open_kernel();
43643+ memcpy((void *)&twl6030_irq_chip, &dummy_irq_chip, sizeof twl6030_irq_chip);
43644+ *(const char **)&twl6030_irq_chip.name = "twl6030";
43645+ *(void **)&twl6030_irq_chip.irq_set_type = NULL;
43646+ *(void **)&twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake;
43647+ pax_close_kernel();
43648
43649 for (i = irq_base; i < irq_end; i++) {
43650 irq_set_chip_and_handler(i, &twl6030_irq_chip,
43651diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
43652index f32550a..e3e52a2 100644
43653--- a/drivers/misc/c2port/core.c
43654+++ b/drivers/misc/c2port/core.c
43655@@ -920,7 +920,9 @@ struct c2port_device *c2port_device_register(char *name,
43656 mutex_init(&c2dev->mutex);
43657
43658 /* Create binary file */
43659- c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
43660+ pax_open_kernel();
43661+ *(size_t *)&c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
43662+ pax_close_kernel();
43663 ret = device_create_bin_file(c2dev->dev, &c2port_bin_attrs);
43664 if (unlikely(ret))
43665 goto error_device_create_bin_file;
43666diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
43667index 36f5d52..32311c3 100644
43668--- a/drivers/misc/kgdbts.c
43669+++ b/drivers/misc/kgdbts.c
43670@@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
43671 char before[BREAK_INSTR_SIZE];
43672 char after[BREAK_INSTR_SIZE];
43673
43674- probe_kernel_read(before, (char *)kgdbts_break_test,
43675+ probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
43676 BREAK_INSTR_SIZE);
43677 init_simple_test();
43678 ts.tst = plant_and_detach_test;
43679@@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
43680 /* Activate test with initial breakpoint */
43681 if (!is_early)
43682 kgdb_breakpoint();
43683- probe_kernel_read(after, (char *)kgdbts_break_test,
43684+ probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
43685 BREAK_INSTR_SIZE);
43686 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
43687 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
43688diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
43689index 036effe..b3a6336 100644
43690--- a/drivers/misc/lis3lv02d/lis3lv02d.c
43691+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
43692@@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
43693 * the lid is closed. This leads to interrupts as soon as a little move
43694 * is done.
43695 */
43696- atomic_inc(&lis3->count);
43697+ atomic_inc_unchecked(&lis3->count);
43698
43699 wake_up_interruptible(&lis3->misc_wait);
43700 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
43701@@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
43702 if (lis3->pm_dev)
43703 pm_runtime_get_sync(lis3->pm_dev);
43704
43705- atomic_set(&lis3->count, 0);
43706+ atomic_set_unchecked(&lis3->count, 0);
43707 return 0;
43708 }
43709
43710@@ -616,7 +616,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
43711 add_wait_queue(&lis3->misc_wait, &wait);
43712 while (true) {
43713 set_current_state(TASK_INTERRUPTIBLE);
43714- data = atomic_xchg(&lis3->count, 0);
43715+ data = atomic_xchg_unchecked(&lis3->count, 0);
43716 if (data)
43717 break;
43718
43719@@ -657,7 +657,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
43720 struct lis3lv02d, miscdev);
43721
43722 poll_wait(file, &lis3->misc_wait, wait);
43723- if (atomic_read(&lis3->count))
43724+ if (atomic_read_unchecked(&lis3->count))
43725 return POLLIN | POLLRDNORM;
43726 return 0;
43727 }
43728diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
43729index c439c82..1f20f57 100644
43730--- a/drivers/misc/lis3lv02d/lis3lv02d.h
43731+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
43732@@ -297,7 +297,7 @@ struct lis3lv02d {
43733 struct input_polled_dev *idev; /* input device */
43734 struct platform_device *pdev; /* platform device */
43735 struct regulator_bulk_data regulators[2];
43736- atomic_t count; /* interrupt count after last read */
43737+ atomic_unchecked_t count; /* interrupt count after last read */
43738 union axis_conversion ac; /* hw -> logical axis */
43739 int mapped_btns[3];
43740
43741diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
43742index 2f30bad..c4c13d0 100644
43743--- a/drivers/misc/sgi-gru/gruhandles.c
43744+++ b/drivers/misc/sgi-gru/gruhandles.c
43745@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
43746 unsigned long nsec;
43747
43748 nsec = CLKS2NSEC(clks);
43749- atomic_long_inc(&mcs_op_statistics[op].count);
43750- atomic_long_add(nsec, &mcs_op_statistics[op].total);
43751+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
43752+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
43753 if (mcs_op_statistics[op].max < nsec)
43754 mcs_op_statistics[op].max = nsec;
43755 }
43756diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
43757index 4f76359..cdfcb2e 100644
43758--- a/drivers/misc/sgi-gru/gruprocfs.c
43759+++ b/drivers/misc/sgi-gru/gruprocfs.c
43760@@ -32,9 +32,9 @@
43761
43762 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
43763
43764-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
43765+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
43766 {
43767- unsigned long val = atomic_long_read(v);
43768+ unsigned long val = atomic_long_read_unchecked(v);
43769
43770 seq_printf(s, "%16lu %s\n", val, id);
43771 }
43772@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
43773
43774 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
43775 for (op = 0; op < mcsop_last; op++) {
43776- count = atomic_long_read(&mcs_op_statistics[op].count);
43777- total = atomic_long_read(&mcs_op_statistics[op].total);
43778+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
43779+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
43780 max = mcs_op_statistics[op].max;
43781 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
43782 count ? total / count : 0, max);
43783diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
43784index 5c3ce24..4915ccb 100644
43785--- a/drivers/misc/sgi-gru/grutables.h
43786+++ b/drivers/misc/sgi-gru/grutables.h
43787@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
43788 * GRU statistics.
43789 */
43790 struct gru_stats_s {
43791- atomic_long_t vdata_alloc;
43792- atomic_long_t vdata_free;
43793- atomic_long_t gts_alloc;
43794- atomic_long_t gts_free;
43795- atomic_long_t gms_alloc;
43796- atomic_long_t gms_free;
43797- atomic_long_t gts_double_allocate;
43798- atomic_long_t assign_context;
43799- atomic_long_t assign_context_failed;
43800- atomic_long_t free_context;
43801- atomic_long_t load_user_context;
43802- atomic_long_t load_kernel_context;
43803- atomic_long_t lock_kernel_context;
43804- atomic_long_t unlock_kernel_context;
43805- atomic_long_t steal_user_context;
43806- atomic_long_t steal_kernel_context;
43807- atomic_long_t steal_context_failed;
43808- atomic_long_t nopfn;
43809- atomic_long_t asid_new;
43810- atomic_long_t asid_next;
43811- atomic_long_t asid_wrap;
43812- atomic_long_t asid_reuse;
43813- atomic_long_t intr;
43814- atomic_long_t intr_cbr;
43815- atomic_long_t intr_tfh;
43816- atomic_long_t intr_spurious;
43817- atomic_long_t intr_mm_lock_failed;
43818- atomic_long_t call_os;
43819- atomic_long_t call_os_wait_queue;
43820- atomic_long_t user_flush_tlb;
43821- atomic_long_t user_unload_context;
43822- atomic_long_t user_exception;
43823- atomic_long_t set_context_option;
43824- atomic_long_t check_context_retarget_intr;
43825- atomic_long_t check_context_unload;
43826- atomic_long_t tlb_dropin;
43827- atomic_long_t tlb_preload_page;
43828- atomic_long_t tlb_dropin_fail_no_asid;
43829- atomic_long_t tlb_dropin_fail_upm;
43830- atomic_long_t tlb_dropin_fail_invalid;
43831- atomic_long_t tlb_dropin_fail_range_active;
43832- atomic_long_t tlb_dropin_fail_idle;
43833- atomic_long_t tlb_dropin_fail_fmm;
43834- atomic_long_t tlb_dropin_fail_no_exception;
43835- atomic_long_t tfh_stale_on_fault;
43836- atomic_long_t mmu_invalidate_range;
43837- atomic_long_t mmu_invalidate_page;
43838- atomic_long_t flush_tlb;
43839- atomic_long_t flush_tlb_gru;
43840- atomic_long_t flush_tlb_gru_tgh;
43841- atomic_long_t flush_tlb_gru_zero_asid;
43842+ atomic_long_unchecked_t vdata_alloc;
43843+ atomic_long_unchecked_t vdata_free;
43844+ atomic_long_unchecked_t gts_alloc;
43845+ atomic_long_unchecked_t gts_free;
43846+ atomic_long_unchecked_t gms_alloc;
43847+ atomic_long_unchecked_t gms_free;
43848+ atomic_long_unchecked_t gts_double_allocate;
43849+ atomic_long_unchecked_t assign_context;
43850+ atomic_long_unchecked_t assign_context_failed;
43851+ atomic_long_unchecked_t free_context;
43852+ atomic_long_unchecked_t load_user_context;
43853+ atomic_long_unchecked_t load_kernel_context;
43854+ atomic_long_unchecked_t lock_kernel_context;
43855+ atomic_long_unchecked_t unlock_kernel_context;
43856+ atomic_long_unchecked_t steal_user_context;
43857+ atomic_long_unchecked_t steal_kernel_context;
43858+ atomic_long_unchecked_t steal_context_failed;
43859+ atomic_long_unchecked_t nopfn;
43860+ atomic_long_unchecked_t asid_new;
43861+ atomic_long_unchecked_t asid_next;
43862+ atomic_long_unchecked_t asid_wrap;
43863+ atomic_long_unchecked_t asid_reuse;
43864+ atomic_long_unchecked_t intr;
43865+ atomic_long_unchecked_t intr_cbr;
43866+ atomic_long_unchecked_t intr_tfh;
43867+ atomic_long_unchecked_t intr_spurious;
43868+ atomic_long_unchecked_t intr_mm_lock_failed;
43869+ atomic_long_unchecked_t call_os;
43870+ atomic_long_unchecked_t call_os_wait_queue;
43871+ atomic_long_unchecked_t user_flush_tlb;
43872+ atomic_long_unchecked_t user_unload_context;
43873+ atomic_long_unchecked_t user_exception;
43874+ atomic_long_unchecked_t set_context_option;
43875+ atomic_long_unchecked_t check_context_retarget_intr;
43876+ atomic_long_unchecked_t check_context_unload;
43877+ atomic_long_unchecked_t tlb_dropin;
43878+ atomic_long_unchecked_t tlb_preload_page;
43879+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
43880+ atomic_long_unchecked_t tlb_dropin_fail_upm;
43881+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
43882+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
43883+ atomic_long_unchecked_t tlb_dropin_fail_idle;
43884+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
43885+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
43886+ atomic_long_unchecked_t tfh_stale_on_fault;
43887+ atomic_long_unchecked_t mmu_invalidate_range;
43888+ atomic_long_unchecked_t mmu_invalidate_page;
43889+ atomic_long_unchecked_t flush_tlb;
43890+ atomic_long_unchecked_t flush_tlb_gru;
43891+ atomic_long_unchecked_t flush_tlb_gru_tgh;
43892+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
43893
43894- atomic_long_t copy_gpa;
43895- atomic_long_t read_gpa;
43896+ atomic_long_unchecked_t copy_gpa;
43897+ atomic_long_unchecked_t read_gpa;
43898
43899- atomic_long_t mesq_receive;
43900- atomic_long_t mesq_receive_none;
43901- atomic_long_t mesq_send;
43902- atomic_long_t mesq_send_failed;
43903- atomic_long_t mesq_noop;
43904- atomic_long_t mesq_send_unexpected_error;
43905- atomic_long_t mesq_send_lb_overflow;
43906- atomic_long_t mesq_send_qlimit_reached;
43907- atomic_long_t mesq_send_amo_nacked;
43908- atomic_long_t mesq_send_put_nacked;
43909- atomic_long_t mesq_page_overflow;
43910- atomic_long_t mesq_qf_locked;
43911- atomic_long_t mesq_qf_noop_not_full;
43912- atomic_long_t mesq_qf_switch_head_failed;
43913- atomic_long_t mesq_qf_unexpected_error;
43914- atomic_long_t mesq_noop_unexpected_error;
43915- atomic_long_t mesq_noop_lb_overflow;
43916- atomic_long_t mesq_noop_qlimit_reached;
43917- atomic_long_t mesq_noop_amo_nacked;
43918- atomic_long_t mesq_noop_put_nacked;
43919- atomic_long_t mesq_noop_page_overflow;
43920+ atomic_long_unchecked_t mesq_receive;
43921+ atomic_long_unchecked_t mesq_receive_none;
43922+ atomic_long_unchecked_t mesq_send;
43923+ atomic_long_unchecked_t mesq_send_failed;
43924+ atomic_long_unchecked_t mesq_noop;
43925+ atomic_long_unchecked_t mesq_send_unexpected_error;
43926+ atomic_long_unchecked_t mesq_send_lb_overflow;
43927+ atomic_long_unchecked_t mesq_send_qlimit_reached;
43928+ atomic_long_unchecked_t mesq_send_amo_nacked;
43929+ atomic_long_unchecked_t mesq_send_put_nacked;
43930+ atomic_long_unchecked_t mesq_page_overflow;
43931+ atomic_long_unchecked_t mesq_qf_locked;
43932+ atomic_long_unchecked_t mesq_qf_noop_not_full;
43933+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
43934+ atomic_long_unchecked_t mesq_qf_unexpected_error;
43935+ atomic_long_unchecked_t mesq_noop_unexpected_error;
43936+ atomic_long_unchecked_t mesq_noop_lb_overflow;
43937+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
43938+ atomic_long_unchecked_t mesq_noop_amo_nacked;
43939+ atomic_long_unchecked_t mesq_noop_put_nacked;
43940+ atomic_long_unchecked_t mesq_noop_page_overflow;
43941
43942 };
43943
43944@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
43945 tghop_invalidate, mcsop_last};
43946
43947 struct mcs_op_statistic {
43948- atomic_long_t count;
43949- atomic_long_t total;
43950+ atomic_long_unchecked_t count;
43951+ atomic_long_unchecked_t total;
43952 unsigned long max;
43953 };
43954
43955@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
43956
43957 #define STAT(id) do { \
43958 if (gru_options & OPT_STATS) \
43959- atomic_long_inc(&gru_stats.id); \
43960+ atomic_long_inc_unchecked(&gru_stats.id); \
43961 } while (0)
43962
43963 #ifdef CONFIG_SGI_GRU_DEBUG
43964diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
43965index c862cd4..0d176fe 100644
43966--- a/drivers/misc/sgi-xp/xp.h
43967+++ b/drivers/misc/sgi-xp/xp.h
43968@@ -288,7 +288,7 @@ struct xpc_interface {
43969 xpc_notify_func, void *);
43970 void (*received) (short, int, void *);
43971 enum xp_retval (*partid_to_nasids) (short, void *);
43972-};
43973+} __no_const;
43974
43975 extern struct xpc_interface xpc_interface;
43976
43977diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
43978index b94d5f7..7f494c5 100644
43979--- a/drivers/misc/sgi-xp/xpc.h
43980+++ b/drivers/misc/sgi-xp/xpc.h
43981@@ -835,6 +835,7 @@ struct xpc_arch_operations {
43982 void (*received_payload) (struct xpc_channel *, void *);
43983 void (*notify_senders_of_disconnect) (struct xpc_channel *);
43984 };
43985+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
43986
43987 /* struct xpc_partition act_state values (for XPC HB) */
43988
43989@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
43990 /* found in xpc_main.c */
43991 extern struct device *xpc_part;
43992 extern struct device *xpc_chan;
43993-extern struct xpc_arch_operations xpc_arch_ops;
43994+extern xpc_arch_operations_no_const xpc_arch_ops;
43995 extern int xpc_disengage_timelimit;
43996 extern int xpc_disengage_timedout;
43997 extern int xpc_activate_IRQ_rcvd;
43998diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
43999index 82dc574..8539ab2 100644
44000--- a/drivers/misc/sgi-xp/xpc_main.c
44001+++ b/drivers/misc/sgi-xp/xpc_main.c
44002@@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
44003 .notifier_call = xpc_system_die,
44004 };
44005
44006-struct xpc_arch_operations xpc_arch_ops;
44007+xpc_arch_operations_no_const xpc_arch_ops;
44008
44009 /*
44010 * Timer function to enforce the timelimit on the partition disengage.
44011@@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
44012
44013 if (((die_args->trapnr == X86_TRAP_MF) ||
44014 (die_args->trapnr == X86_TRAP_XF)) &&
44015- !user_mode_vm(die_args->regs))
44016+ !user_mode(die_args->regs))
44017 xpc_die_deactivate();
44018
44019 break;
44020diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
44021index 837fc73..acb5862 100644
44022--- a/drivers/mmc/core/mmc_ops.c
44023+++ b/drivers/mmc/core/mmc_ops.c
44024@@ -213,7 +213,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
44025 void *data_buf;
44026 int is_on_stack;
44027
44028- is_on_stack = object_is_on_stack(buf);
44029+ is_on_stack = object_starts_on_stack(buf);
44030 if (is_on_stack) {
44031 /*
44032 * dma onto stack is unsafe/nonportable, but callers to this
44033diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
44034index 81b2994..dce857e 100644
44035--- a/drivers/mmc/host/dw_mmc.h
44036+++ b/drivers/mmc/host/dw_mmc.h
44037@@ -203,5 +203,5 @@ struct dw_mci_drv_data {
44038 void (*prepare_command)(struct dw_mci *host, u32 *cmdr);
44039 void (*set_ios)(struct dw_mci *host, struct mmc_ios *ios);
44040 int (*parse_dt)(struct dw_mci *host);
44041-};
44042+} __do_const;
44043 #endif /* _DW_MMC_H_ */
44044diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
44045index 926aaf6..8e153e2 100644
44046--- a/drivers/mmc/host/sdhci-s3c.c
44047+++ b/drivers/mmc/host/sdhci-s3c.c
44048@@ -664,9 +664,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
44049 * we can use overriding functions instead of default.
44050 */
44051 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
44052- sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
44053- sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
44054- sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
44055+ pax_open_kernel();
44056+ *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
44057+ *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
44058+ *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
44059+ pax_close_kernel();
44060 }
44061
44062 /* It supports additional host capabilities if needed */
44063diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
44064index 0c8bb6b..6f35deb 100644
44065--- a/drivers/mtd/nand/denali.c
44066+++ b/drivers/mtd/nand/denali.c
44067@@ -24,6 +24,7 @@
44068 #include <linux/slab.h>
44069 #include <linux/mtd/mtd.h>
44070 #include <linux/module.h>
44071+#include <linux/slab.h>
44072
44073 #include "denali.h"
44074
44075diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
44076index 51b9d6a..52af9a7 100644
44077--- a/drivers/mtd/nftlmount.c
44078+++ b/drivers/mtd/nftlmount.c
44079@@ -24,6 +24,7 @@
44080 #include <asm/errno.h>
44081 #include <linux/delay.h>
44082 #include <linux/slab.h>
44083+#include <linux/sched.h>
44084 #include <linux/mtd/mtd.h>
44085 #include <linux/mtd/nand.h>
44086 #include <linux/mtd/nftl.h>
44087diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
44088index f9d5615..99dd95f 100644
44089--- a/drivers/mtd/sm_ftl.c
44090+++ b/drivers/mtd/sm_ftl.c
44091@@ -56,7 +56,7 @@ ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
44092 #define SM_CIS_VENDOR_OFFSET 0x59
44093 struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
44094 {
44095- struct attribute_group *attr_group;
44096+ attribute_group_no_const *attr_group;
44097 struct attribute **attributes;
44098 struct sm_sysfs_attribute *vendor_attribute;
44099
44100diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
44101index e48cb33..72e73fc 100644
44102--- a/drivers/net/bonding/bond_main.c
44103+++ b/drivers/net/bonding/bond_main.c
44104@@ -4832,7 +4832,7 @@ static unsigned int bond_get_num_tx_queues(void)
44105 return tx_queues;
44106 }
44107
44108-static struct rtnl_link_ops bond_link_ops __read_mostly = {
44109+static struct rtnl_link_ops bond_link_ops = {
44110 .kind = "bond",
44111 .priv_size = sizeof(struct bonding),
44112 .setup = bond_setup,
44113@@ -4957,8 +4957,8 @@ static void __exit bonding_exit(void)
44114
44115 bond_destroy_debugfs();
44116
44117- rtnl_link_unregister(&bond_link_ops);
44118 unregister_pernet_subsys(&bond_net_ops);
44119+ rtnl_link_unregister(&bond_link_ops);
44120
44121 #ifdef CONFIG_NET_POLL_CONTROLLER
44122 /*
44123diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
44124index e1d2643..7f4133b 100644
44125--- a/drivers/net/ethernet/8390/ax88796.c
44126+++ b/drivers/net/ethernet/8390/ax88796.c
44127@@ -872,9 +872,11 @@ static int ax_probe(struct platform_device *pdev)
44128 if (ax->plat->reg_offsets)
44129 ei_local->reg_offset = ax->plat->reg_offsets;
44130 else {
44131+ resource_size_t _mem_size = mem_size;
44132+ do_div(_mem_size, 0x18);
44133 ei_local->reg_offset = ax->reg_offsets;
44134 for (ret = 0; ret < 0x18; ret++)
44135- ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
44136+ ax->reg_offsets[ret] = _mem_size * ret;
44137 }
44138
44139 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
44140diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
44141index c07a6d0..ca88c45 100644
44142--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
44143+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
44144@@ -1137,7 +1137,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
44145 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
44146 {
44147 /* RX_MODE controlling object */
44148- bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
44149+ bnx2x_init_rx_mode_obj(bp);
44150
44151 /* multicast configuration controlling object */
44152 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
44153diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
44154index 8f03c98..dd0ef10 100644
44155--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
44156+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
44157@@ -2345,15 +2345,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
44158 return rc;
44159 }
44160
44161-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
44162- struct bnx2x_rx_mode_obj *o)
44163+void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
44164 {
44165 if (CHIP_IS_E1x(bp)) {
44166- o->wait_comp = bnx2x_empty_rx_mode_wait;
44167- o->config_rx_mode = bnx2x_set_rx_mode_e1x;
44168+ bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
44169+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
44170 } else {
44171- o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
44172- o->config_rx_mode = bnx2x_set_rx_mode_e2;
44173+ bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
44174+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
44175 }
44176 }
44177
44178diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
44179index 798dfe9..05d0a44 100644
44180--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
44181+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
44182@@ -1311,8 +1311,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
44183
44184 /********************* RX MODE ****************/
44185
44186-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
44187- struct bnx2x_rx_mode_obj *o);
44188+void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
44189
44190 /**
44191 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
44192diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
44193index cd63d11..b67dd78 100644
44194--- a/drivers/net/ethernet/broadcom/tg3.h
44195+++ b/drivers/net/ethernet/broadcom/tg3.h
44196@@ -147,6 +147,7 @@
44197 #define CHIPREV_ID_5750_A0 0x4000
44198 #define CHIPREV_ID_5750_A1 0x4001
44199 #define CHIPREV_ID_5750_A3 0x4003
44200+#define CHIPREV_ID_5750_C1 0x4201
44201 #define CHIPREV_ID_5750_C2 0x4202
44202 #define CHIPREV_ID_5752_A0_HW 0x5000
44203 #define CHIPREV_ID_5752_A0 0x6000
44204diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
44205index 8cffcdf..aadf043 100644
44206--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
44207+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
44208@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
44209 */
44210 struct l2t_skb_cb {
44211 arp_failure_handler_func arp_failure_handler;
44212-};
44213+} __no_const;
44214
44215 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
44216
44217diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
44218index 4c83003..2a2a5b9 100644
44219--- a/drivers/net/ethernet/dec/tulip/de4x5.c
44220+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
44221@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
44222 for (i=0; i<ETH_ALEN; i++) {
44223 tmp.addr[i] = dev->dev_addr[i];
44224 }
44225- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
44226+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
44227 break;
44228
44229 case DE4X5_SET_HWADDR: /* Set the hardware address */
44230@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
44231 spin_lock_irqsave(&lp->lock, flags);
44232 memcpy(&statbuf, &lp->pktStats, ioc->len);
44233 spin_unlock_irqrestore(&lp->lock, flags);
44234- if (copy_to_user(ioc->data, &statbuf, ioc->len))
44235+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
44236 return -EFAULT;
44237 break;
44238 }
44239diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
44240index 3d91a5e..1014702 100644
44241--- a/drivers/net/ethernet/emulex/benet/be_main.c
44242+++ b/drivers/net/ethernet/emulex/benet/be_main.c
44243@@ -469,7 +469,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
44244
44245 if (wrapped)
44246 newacc += 65536;
44247- ACCESS_ONCE(*acc) = newacc;
44248+ ACCESS_ONCE_RW(*acc) = newacc;
44249 }
44250
44251 void populate_erx_stats(struct be_adapter *adapter,
44252diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
44253index 934e1ae..b262e6b 100644
44254--- a/drivers/net/ethernet/faraday/ftgmac100.c
44255+++ b/drivers/net/ethernet/faraday/ftgmac100.c
44256@@ -31,6 +31,8 @@
44257 #include <linux/netdevice.h>
44258 #include <linux/phy.h>
44259 #include <linux/platform_device.h>
44260+#include <linux/interrupt.h>
44261+#include <linux/irqreturn.h>
44262 #include <net/ip.h>
44263
44264 #include "ftgmac100.h"
44265diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
44266index 4658f4c..407d155 100644
44267--- a/drivers/net/ethernet/faraday/ftmac100.c
44268+++ b/drivers/net/ethernet/faraday/ftmac100.c
44269@@ -31,6 +31,8 @@
44270 #include <linux/module.h>
44271 #include <linux/netdevice.h>
44272 #include <linux/platform_device.h>
44273+#include <linux/interrupt.h>
44274+#include <linux/irqreturn.h>
44275
44276 #include "ftmac100.h"
44277
44278diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
44279index 331987d..3be1135 100644
44280--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
44281+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
44282@@ -776,7 +776,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
44283 }
44284
44285 /* update the base incval used to calculate frequency adjustment */
44286- ACCESS_ONCE(adapter->base_incval) = incval;
44287+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
44288 smp_mb();
44289
44290 /* need lock to prevent incorrect read while modifying cyclecounter */
44291diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
44292index fbe5363..266b4e3 100644
44293--- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
44294+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
44295@@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
44296 struct __vxge_hw_fifo *fifo;
44297 struct vxge_hw_fifo_config *config;
44298 u32 txdl_size, txdl_per_memblock;
44299- struct vxge_hw_mempool_cbs fifo_mp_callback;
44300+ static struct vxge_hw_mempool_cbs fifo_mp_callback = {
44301+ .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
44302+ };
44303+
44304 struct __vxge_hw_virtualpath *vpath;
44305
44306 if ((vp == NULL) || (attr == NULL)) {
44307@@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
44308 goto exit;
44309 }
44310
44311- fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
44312-
44313 fifo->mempool =
44314 __vxge_hw_mempool_create(vpath->hldev,
44315 fifo->config->memblock_size,
44316diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
44317index 345d987..af69721 100644
44318--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
44319+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
44320@@ -2011,7 +2011,9 @@ int qlcnic_83xx_config_default_opmode(struct qlcnic_adapter *adapter)
44321 op_mode = QLC_83XX_DEFAULT_OPMODE;
44322
44323 if (op_mode == QLC_83XX_DEFAULT_OPMODE) {
44324- adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
44325+ pax_open_kernel();
44326+ *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
44327+ pax_close_kernel();
44328 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
44329 } else {
44330 return -EIO;
44331diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
44332index 599d1fd..59868fe 100644
44333--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
44334+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
44335@@ -191,17 +191,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
44336 case QLCNIC_NON_PRIV_FUNC:
44337 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
44338 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
44339- nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
44340+ pax_open_kernel();
44341+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
44342+ pax_close_kernel();
44343 break;
44344 case QLCNIC_PRIV_FUNC:
44345 ahw->op_mode = QLCNIC_PRIV_FUNC;
44346 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
44347- nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
44348+ pax_open_kernel();
44349+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
44350+ pax_close_kernel();
44351 break;
44352 case QLCNIC_MGMT_FUNC:
44353 ahw->op_mode = QLCNIC_MGMT_FUNC;
44354 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
44355- nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
44356+ pax_open_kernel();
44357+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
44358+ pax_close_kernel();
44359 break;
44360 default:
44361 dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
44362diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
44363index 85e5c97..76f97ec 100644
44364--- a/drivers/net/ethernet/realtek/r8169.c
44365+++ b/drivers/net/ethernet/realtek/r8169.c
44366@@ -759,22 +759,22 @@ struct rtl8169_private {
44367 struct mdio_ops {
44368 void (*write)(struct rtl8169_private *, int, int);
44369 int (*read)(struct rtl8169_private *, int);
44370- } mdio_ops;
44371+ } __no_const mdio_ops;
44372
44373 struct pll_power_ops {
44374 void (*down)(struct rtl8169_private *);
44375 void (*up)(struct rtl8169_private *);
44376- } pll_power_ops;
44377+ } __no_const pll_power_ops;
44378
44379 struct jumbo_ops {
44380 void (*enable)(struct rtl8169_private *);
44381 void (*disable)(struct rtl8169_private *);
44382- } jumbo_ops;
44383+ } __no_const jumbo_ops;
44384
44385 struct csi_ops {
44386 void (*write)(struct rtl8169_private *, int, int);
44387 u32 (*read)(struct rtl8169_private *, int);
44388- } csi_ops;
44389+ } __no_const csi_ops;
44390
44391 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
44392 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
44393diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
44394index b495394..0748c54 100644
44395--- a/drivers/net/ethernet/sfc/ptp.c
44396+++ b/drivers/net/ethernet/sfc/ptp.c
44397@@ -535,7 +535,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
44398 (u32)((u64)ptp->start.dma_addr >> 32));
44399
44400 /* Clear flag that signals MC ready */
44401- ACCESS_ONCE(*start) = 0;
44402+ ACCESS_ONCE_RW(*start) = 0;
44403 efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
44404 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
44405
44406diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
44407index 50617c5..b13724c 100644
44408--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
44409+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
44410@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
44411
44412 writel(value, ioaddr + MMC_CNTRL);
44413
44414- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
44415- MMC_CNTRL, value);
44416+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
44417+// MMC_CNTRL, value);
44418 }
44419
44420 /* To mask all all interrupts.*/
44421diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
44422index e6fe0d8..2b7d752 100644
44423--- a/drivers/net/hyperv/hyperv_net.h
44424+++ b/drivers/net/hyperv/hyperv_net.h
44425@@ -101,7 +101,7 @@ struct rndis_device {
44426
44427 enum rndis_device_state state;
44428 bool link_state;
44429- atomic_t new_req_id;
44430+ atomic_unchecked_t new_req_id;
44431
44432 spinlock_t request_lock;
44433 struct list_head req_list;
44434diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
44435index 0775f0a..d4fb316 100644
44436--- a/drivers/net/hyperv/rndis_filter.c
44437+++ b/drivers/net/hyperv/rndis_filter.c
44438@@ -104,7 +104,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
44439 * template
44440 */
44441 set = &rndis_msg->msg.set_req;
44442- set->req_id = atomic_inc_return(&dev->new_req_id);
44443+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
44444
44445 /* Add to the request list */
44446 spin_lock_irqsave(&dev->request_lock, flags);
44447@@ -752,7 +752,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
44448
44449 /* Setup the rndis set */
44450 halt = &request->request_msg.msg.halt_req;
44451- halt->req_id = atomic_inc_return(&dev->new_req_id);
44452+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
44453
44454 /* Ignore return since this msg is optional. */
44455 rndis_filter_send_request(dev, request);
44456diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
44457index bf0d55e..82bcfbd1 100644
44458--- a/drivers/net/ieee802154/fakehard.c
44459+++ b/drivers/net/ieee802154/fakehard.c
44460@@ -364,7 +364,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
44461 phy->transmit_power = 0xbf;
44462
44463 dev->netdev_ops = &fake_ops;
44464- dev->ml_priv = &fake_mlme;
44465+ dev->ml_priv = (void *)&fake_mlme;
44466
44467 priv = netdev_priv(dev);
44468 priv->phy = phy;
44469diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
44470index 16b43bf..ead0c35 100644
44471--- a/drivers/net/macvlan.c
44472+++ b/drivers/net/macvlan.c
44473@@ -934,13 +934,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
44474 int macvlan_link_register(struct rtnl_link_ops *ops)
44475 {
44476 /* common fields */
44477- ops->priv_size = sizeof(struct macvlan_dev);
44478- ops->validate = macvlan_validate;
44479- ops->maxtype = IFLA_MACVLAN_MAX;
44480- ops->policy = macvlan_policy;
44481- ops->changelink = macvlan_changelink;
44482- ops->get_size = macvlan_get_size;
44483- ops->fill_info = macvlan_fill_info;
44484+ pax_open_kernel();
44485+ *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
44486+ *(void **)&ops->validate = macvlan_validate;
44487+ *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
44488+ *(const void **)&ops->policy = macvlan_policy;
44489+ *(void **)&ops->changelink = macvlan_changelink;
44490+ *(void **)&ops->get_size = macvlan_get_size;
44491+ *(void **)&ops->fill_info = macvlan_fill_info;
44492+ pax_close_kernel();
44493
44494 return rtnl_link_register(ops);
44495 };
44496@@ -996,7 +998,7 @@ static int macvlan_device_event(struct notifier_block *unused,
44497 return NOTIFY_DONE;
44498 }
44499
44500-static struct notifier_block macvlan_notifier_block __read_mostly = {
44501+static struct notifier_block macvlan_notifier_block = {
44502 .notifier_call = macvlan_device_event,
44503 };
44504
44505diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
44506index ea53abb..2e4d087 100644
44507--- a/drivers/net/macvtap.c
44508+++ b/drivers/net/macvtap.c
44509@@ -1286,7 +1286,7 @@ static int macvtap_device_event(struct notifier_block *unused,
44510 return NOTIFY_DONE;
44511 }
44512
44513-static struct notifier_block macvtap_notifier_block __read_mostly = {
44514+static struct notifier_block macvtap_notifier_block = {
44515 .notifier_call = macvtap_device_event,
44516 };
44517
44518diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
44519index daec9b0..6428fcb 100644
44520--- a/drivers/net/phy/mdio-bitbang.c
44521+++ b/drivers/net/phy/mdio-bitbang.c
44522@@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
44523 struct mdiobb_ctrl *ctrl = bus->priv;
44524
44525 module_put(ctrl->ops->owner);
44526+ mdiobus_unregister(bus);
44527 mdiobus_free(bus);
44528 }
44529 EXPORT_SYMBOL(free_mdio_bitbang);
44530diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
44531index 72ff14b..11d442d 100644
44532--- a/drivers/net/ppp/ppp_generic.c
44533+++ b/drivers/net/ppp/ppp_generic.c
44534@@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
44535 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
44536 struct ppp_stats stats;
44537 struct ppp_comp_stats cstats;
44538- char *vers;
44539
44540 switch (cmd) {
44541 case SIOCGPPPSTATS:
44542@@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
44543 break;
44544
44545 case SIOCGPPPVER:
44546- vers = PPP_VERSION;
44547- if (copy_to_user(addr, vers, strlen(vers) + 1))
44548+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
44549 break;
44550 err = 0;
44551 break;
44552diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
44553index 1252d9c..80e660b 100644
44554--- a/drivers/net/slip/slhc.c
44555+++ b/drivers/net/slip/slhc.c
44556@@ -488,7 +488,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
44557 register struct tcphdr *thp;
44558 register struct iphdr *ip;
44559 register struct cstate *cs;
44560- int len, hdrlen;
44561+ long len, hdrlen;
44562 unsigned char *cp = icp;
44563
44564 /* We've got a compressed packet; read the change byte */
44565diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
44566index bff7e0b..7315137 100644
44567--- a/drivers/net/team/team.c
44568+++ b/drivers/net/team/team.c
44569@@ -2702,7 +2702,7 @@ static int team_device_event(struct notifier_block *unused,
44570 return NOTIFY_DONE;
44571 }
44572
44573-static struct notifier_block team_notifier_block __read_mostly = {
44574+static struct notifier_block team_notifier_block = {
44575 .notifier_call = team_device_event,
44576 };
44577
44578diff --git a/drivers/net/tun.c b/drivers/net/tun.c
44579index 71af122..b3c20f3 100644
44580--- a/drivers/net/tun.c
44581+++ b/drivers/net/tun.c
44582@@ -1691,11 +1691,11 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
44583 INIT_LIST_HEAD(&tun->disabled);
44584 err = tun_attach(tun, file);
44585 if (err < 0)
44586- goto err_free_dev;
44587+ goto err_free_flow;
44588
44589 err = register_netdevice(tun->dev);
44590 if (err < 0)
44591- goto err_free_dev;
44592+ goto err_detach;
44593
44594 if (device_create_file(&tun->dev->dev, &dev_attr_tun_flags) ||
44595 device_create_file(&tun->dev->dev, &dev_attr_owner) ||
44596@@ -1739,7 +1739,12 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
44597 strcpy(ifr->ifr_name, tun->dev->name);
44598 return 0;
44599
44600- err_free_dev:
44601+err_detach:
44602+ tun_detach_all(dev);
44603+err_free_flow:
44604+ tun_flow_uninit(tun);
44605+ security_tun_dev_free_security(tun->security);
44606+err_free_dev:
44607 free_netdev(dev);
44608 return err;
44609 }
44610@@ -1869,7 +1874,7 @@ unlock:
44611 }
44612
44613 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
44614- unsigned long arg, int ifreq_len)
44615+ unsigned long arg, size_t ifreq_len)
44616 {
44617 struct tun_file *tfile = file->private_data;
44618 struct tun_struct *tun;
44619@@ -1881,6 +1886,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
44620 int vnet_hdr_sz;
44621 int ret;
44622
44623+ if (ifreq_len > sizeof ifr)
44624+ return -EFAULT;
44625+
44626 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
44627 if (copy_from_user(&ifr, argp, ifreq_len))
44628 return -EFAULT;
44629diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
44630index 86292e6..8d34433 100644
44631--- a/drivers/net/usb/hso.c
44632+++ b/drivers/net/usb/hso.c
44633@@ -71,7 +71,7 @@
44634 #include <asm/byteorder.h>
44635 #include <linux/serial_core.h>
44636 #include <linux/serial.h>
44637-
44638+#include <asm/local.h>
44639
44640 #define MOD_AUTHOR "Option Wireless"
44641 #define MOD_DESCRIPTION "USB High Speed Option driver"
44642@@ -1180,7 +1180,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
44643 struct urb *urb;
44644
44645 urb = serial->rx_urb[0];
44646- if (serial->port.count > 0) {
44647+ if (atomic_read(&serial->port.count) > 0) {
44648 count = put_rxbuf_data(urb, serial);
44649 if (count == -1)
44650 return;
44651@@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
44652 DUMP1(urb->transfer_buffer, urb->actual_length);
44653
44654 /* Anyone listening? */
44655- if (serial->port.count == 0)
44656+ if (atomic_read(&serial->port.count) == 0)
44657 return;
44658
44659 if (status == 0) {
44660@@ -1298,8 +1298,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
44661 tty_port_tty_set(&serial->port, tty);
44662
44663 /* check for port already opened, if not set the termios */
44664- serial->port.count++;
44665- if (serial->port.count == 1) {
44666+ if (atomic_inc_return(&serial->port.count) == 1) {
44667 serial->rx_state = RX_IDLE;
44668 /* Force default termio settings */
44669 _hso_serial_set_termios(tty, NULL);
44670@@ -1311,7 +1310,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
44671 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
44672 if (result) {
44673 hso_stop_serial_device(serial->parent);
44674- serial->port.count--;
44675+ atomic_dec(&serial->port.count);
44676 kref_put(&serial->parent->ref, hso_serial_ref_free);
44677 }
44678 } else {
44679@@ -1348,10 +1347,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
44680
44681 /* reset the rts and dtr */
44682 /* do the actual close */
44683- serial->port.count--;
44684+ atomic_dec(&serial->port.count);
44685
44686- if (serial->port.count <= 0) {
44687- serial->port.count = 0;
44688+ if (atomic_read(&serial->port.count) <= 0) {
44689+ atomic_set(&serial->port.count, 0);
44690 tty_port_tty_set(&serial->port, NULL);
44691 if (!usb_gone)
44692 hso_stop_serial_device(serial->parent);
44693@@ -1427,7 +1426,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
44694
44695 /* the actual setup */
44696 spin_lock_irqsave(&serial->serial_lock, flags);
44697- if (serial->port.count)
44698+ if (atomic_read(&serial->port.count))
44699 _hso_serial_set_termios(tty, old);
44700 else
44701 tty->termios = *old;
44702@@ -1886,7 +1885,7 @@ static void intr_callback(struct urb *urb)
44703 D1("Pending read interrupt on port %d\n", i);
44704 spin_lock(&serial->serial_lock);
44705 if (serial->rx_state == RX_IDLE &&
44706- serial->port.count > 0) {
44707+ atomic_read(&serial->port.count) > 0) {
44708 /* Setup and send a ctrl req read on
44709 * port i */
44710 if (!serial->rx_urb_filled[0]) {
44711@@ -3062,7 +3061,7 @@ static int hso_resume(struct usb_interface *iface)
44712 /* Start all serial ports */
44713 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
44714 if (serial_table[i] && (serial_table[i]->interface == iface)) {
44715- if (dev2ser(serial_table[i])->port.count) {
44716+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
44717 result =
44718 hso_start_serial_device(serial_table[i], GFP_NOIO);
44719 hso_kick_transmit(dev2ser(serial_table[i]));
44720diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
44721index a79e9d3..78cd4fa 100644
44722--- a/drivers/net/usb/sierra_net.c
44723+++ b/drivers/net/usb/sierra_net.c
44724@@ -52,7 +52,7 @@ static const char driver_name[] = "sierra_net";
44725 /* atomic counter partially included in MAC address to make sure 2 devices
44726 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
44727 */
44728-static atomic_t iface_counter = ATOMIC_INIT(0);
44729+static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
44730
44731 /*
44732 * SYNC Timer Delay definition used to set the expiry time
44733@@ -698,7 +698,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
44734 dev->net->netdev_ops = &sierra_net_device_ops;
44735
44736 /* change MAC addr to include, ifacenum, and to be unique */
44737- dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
44738+ dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
44739 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
44740
44741 /* we will have to manufacture ethernet headers, prepare template */
44742diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
44743index 767f7af..8162b9d 100644
44744--- a/drivers/net/vxlan.c
44745+++ b/drivers/net/vxlan.c
44746@@ -1868,7 +1868,7 @@ nla_put_failure:
44747 return -EMSGSIZE;
44748 }
44749
44750-static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
44751+static struct rtnl_link_ops vxlan_link_ops = {
44752 .kind = "vxlan",
44753 .maxtype = IFLA_VXLAN_MAX,
44754 .policy = vxlan_policy,
44755diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
44756index 0b60295..b8bfa5b 100644
44757--- a/drivers/net/wimax/i2400m/rx.c
44758+++ b/drivers/net/wimax/i2400m/rx.c
44759@@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
44760 if (i2400m->rx_roq == NULL)
44761 goto error_roq_alloc;
44762
44763- rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
44764+ rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
44765 GFP_KERNEL);
44766 if (rd == NULL) {
44767 result = -ENOMEM;
44768diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
44769index 34c8a33..3261fdc 100644
44770--- a/drivers/net/wireless/at76c50x-usb.c
44771+++ b/drivers/net/wireless/at76c50x-usb.c
44772@@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
44773 }
44774
44775 /* Convert timeout from the DFU status to jiffies */
44776-static inline unsigned long at76_get_timeout(struct dfu_status *s)
44777+static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
44778 {
44779 return msecs_to_jiffies((s->poll_timeout[2] << 16)
44780 | (s->poll_timeout[1] << 8)
44781diff --git a/drivers/net/wireless/ath/ath10k/core.c b/drivers/net/wireless/ath/ath10k/core.c
44782index 2b3426b..1f564be 100644
44783--- a/drivers/net/wireless/ath/ath10k/core.c
44784+++ b/drivers/net/wireless/ath/ath10k/core.c
44785@@ -507,7 +507,9 @@ EXPORT_SYMBOL(ath10k_core_destroy);
44786
44787 int ath10k_core_register(struct ath10k *ar)
44788 {
44789- struct ath10k_htc_ops htc_ops;
44790+ static struct ath10k_htc_ops htc_ops = {
44791+ .target_send_suspend_complete = ath10k_send_suspend_complete,
44792+ };
44793 struct bmi_target_info target_info;
44794 int status;
44795
44796@@ -536,8 +538,6 @@ int ath10k_core_register(struct ath10k *ar)
44797 if (status)
44798 goto err;
44799
44800- htc_ops.target_send_suspend_complete = ath10k_send_suspend_complete;
44801-
44802 ar->htc = ath10k_htc_create(ar, &htc_ops);
44803 if (IS_ERR(ar->htc)) {
44804 status = PTR_ERR(ar->htc);
44805diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
44806index 74363c9..237b926 100644
44807--- a/drivers/net/wireless/ath/ath10k/htc.c
44808+++ b/drivers/net/wireless/ath/ath10k/htc.c
44809@@ -963,7 +963,10 @@ void ath10k_htc_stop(struct ath10k_htc *htc)
44810 struct ath10k_htc *ath10k_htc_create(struct ath10k *ar,
44811 struct ath10k_htc_ops *htc_ops)
44812 {
44813- struct ath10k_hif_cb htc_callbacks;
44814+ static struct ath10k_hif_cb htc_callbacks = {
44815+ .rx_completion = ath10k_htc_rx_completion_handler,
44816+ .tx_completion = ath10k_htc_tx_completion_handler,
44817+ };
44818 struct ath10k_htc_ep *ep = NULL;
44819 struct ath10k_htc *htc = NULL;
44820
44821@@ -979,8 +982,6 @@ struct ath10k_htc *ath10k_htc_create(struct ath10k *ar,
44822 ath10k_htc_reset_endpoint_states(htc);
44823
44824 /* setup HIF layer callbacks */
44825- htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
44826- htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
44827 htc->ar = ar;
44828
44829 /* Get HIF default pipe for HTC message exchange */
44830diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
44831index 8d78253..bebbb68 100644
44832--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
44833+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
44834@@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44835 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
44836 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
44837
44838- ACCESS_ONCE(ads->ds_link) = i->link;
44839- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
44840+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
44841+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
44842
44843 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
44844 ctl6 = SM(i->keytype, AR_EncrType);
44845@@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44846
44847 if ((i->is_first || i->is_last) &&
44848 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
44849- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
44850+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
44851 | set11nTries(i->rates, 1)
44852 | set11nTries(i->rates, 2)
44853 | set11nTries(i->rates, 3)
44854 | (i->dur_update ? AR_DurUpdateEna : 0)
44855 | SM(0, AR_BurstDur);
44856
44857- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
44858+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
44859 | set11nRate(i->rates, 1)
44860 | set11nRate(i->rates, 2)
44861 | set11nRate(i->rates, 3);
44862 } else {
44863- ACCESS_ONCE(ads->ds_ctl2) = 0;
44864- ACCESS_ONCE(ads->ds_ctl3) = 0;
44865+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
44866+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
44867 }
44868
44869 if (!i->is_first) {
44870- ACCESS_ONCE(ads->ds_ctl0) = 0;
44871- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
44872- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
44873+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
44874+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
44875+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
44876 return;
44877 }
44878
44879@@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44880 break;
44881 }
44882
44883- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
44884+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
44885 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
44886 | SM(i->txpower, AR_XmitPower)
44887 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
44888@@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44889 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
44890 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
44891
44892- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
44893- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
44894+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
44895+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
44896
44897 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
44898 return;
44899
44900- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
44901+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
44902 | set11nPktDurRTSCTS(i->rates, 1);
44903
44904- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
44905+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
44906 | set11nPktDurRTSCTS(i->rates, 3);
44907
44908- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
44909+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
44910 | set11nRateFlags(i->rates, 1)
44911 | set11nRateFlags(i->rates, 2)
44912 | set11nRateFlags(i->rates, 3)
44913diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
44914index 5163abd..3ada4c2 100644
44915--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
44916+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
44917@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44918 (i->qcu << AR_TxQcuNum_S) | desc_len;
44919
44920 checksum += val;
44921- ACCESS_ONCE(ads->info) = val;
44922+ ACCESS_ONCE_RW(ads->info) = val;
44923
44924 checksum += i->link;
44925- ACCESS_ONCE(ads->link) = i->link;
44926+ ACCESS_ONCE_RW(ads->link) = i->link;
44927
44928 checksum += i->buf_addr[0];
44929- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
44930+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
44931 checksum += i->buf_addr[1];
44932- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
44933+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
44934 checksum += i->buf_addr[2];
44935- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
44936+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
44937 checksum += i->buf_addr[3];
44938- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
44939+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
44940
44941 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
44942- ACCESS_ONCE(ads->ctl3) = val;
44943+ ACCESS_ONCE_RW(ads->ctl3) = val;
44944 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
44945- ACCESS_ONCE(ads->ctl5) = val;
44946+ ACCESS_ONCE_RW(ads->ctl5) = val;
44947 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
44948- ACCESS_ONCE(ads->ctl7) = val;
44949+ ACCESS_ONCE_RW(ads->ctl7) = val;
44950 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
44951- ACCESS_ONCE(ads->ctl9) = val;
44952+ ACCESS_ONCE_RW(ads->ctl9) = val;
44953
44954 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
44955- ACCESS_ONCE(ads->ctl10) = checksum;
44956+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
44957
44958 if (i->is_first || i->is_last) {
44959- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
44960+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
44961 | set11nTries(i->rates, 1)
44962 | set11nTries(i->rates, 2)
44963 | set11nTries(i->rates, 3)
44964 | (i->dur_update ? AR_DurUpdateEna : 0)
44965 | SM(0, AR_BurstDur);
44966
44967- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
44968+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
44969 | set11nRate(i->rates, 1)
44970 | set11nRate(i->rates, 2)
44971 | set11nRate(i->rates, 3);
44972 } else {
44973- ACCESS_ONCE(ads->ctl13) = 0;
44974- ACCESS_ONCE(ads->ctl14) = 0;
44975+ ACCESS_ONCE_RW(ads->ctl13) = 0;
44976+ ACCESS_ONCE_RW(ads->ctl14) = 0;
44977 }
44978
44979 ads->ctl20 = 0;
44980@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44981
44982 ctl17 = SM(i->keytype, AR_EncrType);
44983 if (!i->is_first) {
44984- ACCESS_ONCE(ads->ctl11) = 0;
44985- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
44986- ACCESS_ONCE(ads->ctl15) = 0;
44987- ACCESS_ONCE(ads->ctl16) = 0;
44988- ACCESS_ONCE(ads->ctl17) = ctl17;
44989- ACCESS_ONCE(ads->ctl18) = 0;
44990- ACCESS_ONCE(ads->ctl19) = 0;
44991+ ACCESS_ONCE_RW(ads->ctl11) = 0;
44992+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
44993+ ACCESS_ONCE_RW(ads->ctl15) = 0;
44994+ ACCESS_ONCE_RW(ads->ctl16) = 0;
44995+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
44996+ ACCESS_ONCE_RW(ads->ctl18) = 0;
44997+ ACCESS_ONCE_RW(ads->ctl19) = 0;
44998 return;
44999 }
45000
45001- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
45002+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
45003 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
45004 | SM(i->txpower, AR_XmitPower)
45005 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
45006@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
45007 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
45008 ctl12 |= SM(val, AR_PAPRDChainMask);
45009
45010- ACCESS_ONCE(ads->ctl12) = ctl12;
45011- ACCESS_ONCE(ads->ctl17) = ctl17;
45012+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
45013+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
45014
45015- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
45016+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
45017 | set11nPktDurRTSCTS(i->rates, 1);
45018
45019- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
45020+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
45021 | set11nPktDurRTSCTS(i->rates, 3);
45022
45023- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
45024+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
45025 | set11nRateFlags(i->rates, 1)
45026 | set11nRateFlags(i->rates, 2)
45027 | set11nRateFlags(i->rates, 3)
45028 | SM(i->rtscts_rate, AR_RTSCTSRate);
45029
45030- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
45031+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
45032 }
45033
45034 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
45035diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
45036index cd74b3a..6a28d24 100644
45037--- a/drivers/net/wireless/ath/ath9k/hw.h
45038+++ b/drivers/net/wireless/ath/ath9k/hw.h
45039@@ -652,7 +652,7 @@ struct ath_hw_private_ops {
45040
45041 /* ANI */
45042 void (*ani_cache_ini_regs)(struct ath_hw *ah);
45043-};
45044+} __no_const;
45045
45046 /**
45047 * struct ath_spec_scan - parameters for Atheros spectral scan
45048@@ -721,7 +721,7 @@ struct ath_hw_ops {
45049 struct ath_spec_scan *param);
45050 void (*spectral_scan_trigger)(struct ath_hw *ah);
45051 void (*spectral_scan_wait)(struct ath_hw *ah);
45052-};
45053+} __no_const;
45054
45055 struct ath_nf_limits {
45056 s16 max;
45057diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
45058index 9581d07..84f6a76 100644
45059--- a/drivers/net/wireless/iwlegacy/3945-mac.c
45060+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
45061@@ -3639,7 +3639,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
45062 */
45063 if (il3945_mod_params.disable_hw_scan) {
45064 D_INFO("Disabling hw_scan\n");
45065- il3945_mac_ops.hw_scan = NULL;
45066+ pax_open_kernel();
45067+ *(void **)&il3945_mac_ops.hw_scan = NULL;
45068+ pax_close_kernel();
45069 }
45070
45071 D_INFO("*** LOAD DRIVER ***\n");
45072diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
45073index d532948..e0d8bb1 100644
45074--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
45075+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
45076@@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
45077 {
45078 struct iwl_priv *priv = file->private_data;
45079 char buf[64];
45080- int buf_size;
45081+ size_t buf_size;
45082 u32 offset, len;
45083
45084 memset(buf, 0, sizeof(buf));
45085@@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
45086 struct iwl_priv *priv = file->private_data;
45087
45088 char buf[8];
45089- int buf_size;
45090+ size_t buf_size;
45091 u32 reset_flag;
45092
45093 memset(buf, 0, sizeof(buf));
45094@@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
45095 {
45096 struct iwl_priv *priv = file->private_data;
45097 char buf[8];
45098- int buf_size;
45099+ size_t buf_size;
45100 int ht40;
45101
45102 memset(buf, 0, sizeof(buf));
45103@@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
45104 {
45105 struct iwl_priv *priv = file->private_data;
45106 char buf[8];
45107- int buf_size;
45108+ size_t buf_size;
45109 int value;
45110
45111 memset(buf, 0, sizeof(buf));
45112@@ -698,10 +698,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
45113 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
45114 DEBUGFS_READ_FILE_OPS(current_sleep_command);
45115
45116-static const char *fmt_value = " %-30s %10u\n";
45117-static const char *fmt_hex = " %-30s 0x%02X\n";
45118-static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
45119-static const char *fmt_header =
45120+static const char fmt_value[] = " %-30s %10u\n";
45121+static const char fmt_hex[] = " %-30s 0x%02X\n";
45122+static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
45123+static const char fmt_header[] =
45124 "%-32s current cumulative delta max\n";
45125
45126 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
45127@@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
45128 {
45129 struct iwl_priv *priv = file->private_data;
45130 char buf[8];
45131- int buf_size;
45132+ size_t buf_size;
45133 int clear;
45134
45135 memset(buf, 0, sizeof(buf));
45136@@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
45137 {
45138 struct iwl_priv *priv = file->private_data;
45139 char buf[8];
45140- int buf_size;
45141+ size_t buf_size;
45142 int trace;
45143
45144 memset(buf, 0, sizeof(buf));
45145@@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
45146 {
45147 struct iwl_priv *priv = file->private_data;
45148 char buf[8];
45149- int buf_size;
45150+ size_t buf_size;
45151 int missed;
45152
45153 memset(buf, 0, sizeof(buf));
45154@@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
45155
45156 struct iwl_priv *priv = file->private_data;
45157 char buf[8];
45158- int buf_size;
45159+ size_t buf_size;
45160 int plcp;
45161
45162 memset(buf, 0, sizeof(buf));
45163@@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
45164
45165 struct iwl_priv *priv = file->private_data;
45166 char buf[8];
45167- int buf_size;
45168+ size_t buf_size;
45169 int flush;
45170
45171 memset(buf, 0, sizeof(buf));
45172@@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
45173
45174 struct iwl_priv *priv = file->private_data;
45175 char buf[8];
45176- int buf_size;
45177+ size_t buf_size;
45178 int rts;
45179
45180 if (!priv->cfg->ht_params)
45181@@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
45182 {
45183 struct iwl_priv *priv = file->private_data;
45184 char buf[8];
45185- int buf_size;
45186+ size_t buf_size;
45187
45188 memset(buf, 0, sizeof(buf));
45189 buf_size = min(count, sizeof(buf) - 1);
45190@@ -2254,7 +2254,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
45191 struct iwl_priv *priv = file->private_data;
45192 u32 event_log_flag;
45193 char buf[8];
45194- int buf_size;
45195+ size_t buf_size;
45196
45197 /* check that the interface is up */
45198 if (!iwl_is_ready(priv))
45199@@ -2308,7 +2308,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
45200 struct iwl_priv *priv = file->private_data;
45201 char buf[8];
45202 u32 calib_disabled;
45203- int buf_size;
45204+ size_t buf_size;
45205
45206 memset(buf, 0, sizeof(buf));
45207 buf_size = min(count, sizeof(buf) - 1);
45208diff --git a/drivers/net/wireless/iwlwifi/dvm/main.c b/drivers/net/wireless/iwlwifi/dvm/main.c
45209index 1531a4f..21d2641 100644
45210--- a/drivers/net/wireless/iwlwifi/dvm/main.c
45211+++ b/drivers/net/wireless/iwlwifi/dvm/main.c
45212@@ -1180,7 +1180,7 @@ static void iwl_option_config(struct iwl_priv *priv)
45213 static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
45214 {
45215 struct iwl_nvm_data *data = priv->nvm_data;
45216- char *debug_msg;
45217+ static const char debug_msg[] = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
45218
45219 if (data->sku_cap_11n_enable &&
45220 !priv->cfg->ht_params) {
45221@@ -1194,7 +1194,6 @@ static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
45222 return -EINVAL;
45223 }
45224
45225- debug_msg = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
45226 IWL_DEBUG_INFO(priv, debug_msg,
45227 data->sku_cap_band_24GHz_enable ? "" : "NOT", "enabled",
45228 data->sku_cap_band_52GHz_enable ? "" : "NOT", "enabled",
45229diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
45230index 390e2f0..75cfbaf 100644
45231--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
45232+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
45233@@ -1350,7 +1350,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
45234 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
45235
45236 char buf[8];
45237- int buf_size;
45238+ size_t buf_size;
45239 u32 reset_flag;
45240
45241 memset(buf, 0, sizeof(buf));
45242@@ -1371,7 +1371,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
45243 {
45244 struct iwl_trans *trans = file->private_data;
45245 char buf[8];
45246- int buf_size;
45247+ size_t buf_size;
45248 int csr;
45249
45250 memset(buf, 0, sizeof(buf));
45251diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
45252index cb34c78..9fec0dc 100644
45253--- a/drivers/net/wireless/mac80211_hwsim.c
45254+++ b/drivers/net/wireless/mac80211_hwsim.c
45255@@ -2195,25 +2195,19 @@ static int __init init_mac80211_hwsim(void)
45256
45257 if (channels > 1) {
45258 hwsim_if_comb.num_different_channels = channels;
45259- mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
45260- mac80211_hwsim_ops.cancel_hw_scan =
45261- mac80211_hwsim_cancel_hw_scan;
45262- mac80211_hwsim_ops.sw_scan_start = NULL;
45263- mac80211_hwsim_ops.sw_scan_complete = NULL;
45264- mac80211_hwsim_ops.remain_on_channel =
45265- mac80211_hwsim_roc;
45266- mac80211_hwsim_ops.cancel_remain_on_channel =
45267- mac80211_hwsim_croc;
45268- mac80211_hwsim_ops.add_chanctx =
45269- mac80211_hwsim_add_chanctx;
45270- mac80211_hwsim_ops.remove_chanctx =
45271- mac80211_hwsim_remove_chanctx;
45272- mac80211_hwsim_ops.change_chanctx =
45273- mac80211_hwsim_change_chanctx;
45274- mac80211_hwsim_ops.assign_vif_chanctx =
45275- mac80211_hwsim_assign_vif_chanctx;
45276- mac80211_hwsim_ops.unassign_vif_chanctx =
45277- mac80211_hwsim_unassign_vif_chanctx;
45278+ pax_open_kernel();
45279+ *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
45280+ *(void **)&mac80211_hwsim_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
45281+ *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
45282+ *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
45283+ *(void **)&mac80211_hwsim_ops.remain_on_channel = mac80211_hwsim_roc;
45284+ *(void **)&mac80211_hwsim_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
45285+ *(void **)&mac80211_hwsim_ops.add_chanctx = mac80211_hwsim_add_chanctx;
45286+ *(void **)&mac80211_hwsim_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
45287+ *(void **)&mac80211_hwsim_ops.change_chanctx = mac80211_hwsim_change_chanctx;
45288+ *(void **)&mac80211_hwsim_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
45289+ *(void **)&mac80211_hwsim_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
45290+ pax_close_kernel();
45291 }
45292
45293 spin_lock_init(&hwsim_radio_lock);
45294diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
45295index 8169a85..7fa3b47 100644
45296--- a/drivers/net/wireless/rndis_wlan.c
45297+++ b/drivers/net/wireless/rndis_wlan.c
45298@@ -1238,7 +1238,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
45299
45300 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
45301
45302- if (rts_threshold < 0 || rts_threshold > 2347)
45303+ if (rts_threshold > 2347)
45304 rts_threshold = 2347;
45305
45306 tmp = cpu_to_le32(rts_threshold);
45307diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
45308index ee3fc57..ed5ddc9 100644
45309--- a/drivers/net/wireless/rt2x00/rt2x00.h
45310+++ b/drivers/net/wireless/rt2x00/rt2x00.h
45311@@ -386,7 +386,7 @@ struct rt2x00_intf {
45312 * for hardware which doesn't support hardware
45313 * sequence counting.
45314 */
45315- atomic_t seqno;
45316+ atomic_unchecked_t seqno;
45317 };
45318
45319 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
45320diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
45321index aa95c6c..a59dd67 100644
45322--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
45323+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
45324@@ -252,9 +252,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
45325 * sequence counter given by mac80211.
45326 */
45327 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
45328- seqno = atomic_add_return(0x10, &intf->seqno);
45329+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
45330 else
45331- seqno = atomic_read(&intf->seqno);
45332+ seqno = atomic_read_unchecked(&intf->seqno);
45333
45334 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
45335 hdr->seq_ctrl |= cpu_to_le16(seqno);
45336diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
45337index e2b3d9c..67a5184 100644
45338--- a/drivers/net/wireless/ti/wl1251/sdio.c
45339+++ b/drivers/net/wireless/ti/wl1251/sdio.c
45340@@ -271,13 +271,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
45341
45342 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
45343
45344- wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
45345- wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
45346+ pax_open_kernel();
45347+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
45348+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
45349+ pax_close_kernel();
45350
45351 wl1251_info("using dedicated interrupt line");
45352 } else {
45353- wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
45354- wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
45355+ pax_open_kernel();
45356+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
45357+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
45358+ pax_close_kernel();
45359
45360 wl1251_info("using SDIO interrupt");
45361 }
45362diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
45363index 1c627da..69f7d17 100644
45364--- a/drivers/net/wireless/ti/wl12xx/main.c
45365+++ b/drivers/net/wireless/ti/wl12xx/main.c
45366@@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
45367 sizeof(wl->conf.mem));
45368
45369 /* read data preparation is only needed by wl127x */
45370- wl->ops->prepare_read = wl127x_prepare_read;
45371+ pax_open_kernel();
45372+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
45373+ pax_close_kernel();
45374
45375 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
45376 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
45377@@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
45378 sizeof(wl->conf.mem));
45379
45380 /* read data preparation is only needed by wl127x */
45381- wl->ops->prepare_read = wl127x_prepare_read;
45382+ pax_open_kernel();
45383+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
45384+ pax_close_kernel();
45385
45386 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
45387 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
45388diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
45389index 7aa0eb8..5a9ef38 100644
45390--- a/drivers/net/wireless/ti/wl18xx/main.c
45391+++ b/drivers/net/wireless/ti/wl18xx/main.c
45392@@ -1730,8 +1730,10 @@ static int wl18xx_setup(struct wl1271 *wl)
45393 }
45394
45395 if (!checksum_param) {
45396- wl18xx_ops.set_rx_csum = NULL;
45397- wl18xx_ops.init_vif = NULL;
45398+ pax_open_kernel();
45399+ *(void **)&wl18xx_ops.set_rx_csum = NULL;
45400+ *(void **)&wl18xx_ops.init_vif = NULL;
45401+ pax_close_kernel();
45402 }
45403
45404 /* Enable 11a Band only if we have 5G antennas */
45405diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
45406index 7ef0b4a..ff65c28 100644
45407--- a/drivers/net/wireless/zd1211rw/zd_usb.c
45408+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
45409@@ -386,7 +386,7 @@ static inline void handle_regs_int(struct urb *urb)
45410 {
45411 struct zd_usb *usb = urb->context;
45412 struct zd_usb_interrupt *intr = &usb->intr;
45413- int len;
45414+ unsigned int len;
45415 u16 int_num;
45416
45417 ZD_ASSERT(in_interrupt());
45418diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
45419index d93b2b6..ae50401 100644
45420--- a/drivers/oprofile/buffer_sync.c
45421+++ b/drivers/oprofile/buffer_sync.c
45422@@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
45423 if (cookie == NO_COOKIE)
45424 offset = pc;
45425 if (cookie == INVALID_COOKIE) {
45426- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
45427+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
45428 offset = pc;
45429 }
45430 if (cookie != last_cookie) {
45431@@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
45432 /* add userspace sample */
45433
45434 if (!mm) {
45435- atomic_inc(&oprofile_stats.sample_lost_no_mm);
45436+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
45437 return 0;
45438 }
45439
45440 cookie = lookup_dcookie(mm, s->eip, &offset);
45441
45442 if (cookie == INVALID_COOKIE) {
45443- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
45444+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
45445 return 0;
45446 }
45447
45448@@ -552,7 +552,7 @@ void sync_buffer(int cpu)
45449 /* ignore backtraces if failed to add a sample */
45450 if (state == sb_bt_start) {
45451 state = sb_bt_ignore;
45452- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
45453+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
45454 }
45455 }
45456 release_mm(mm);
45457diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
45458index c0cc4e7..44d4e54 100644
45459--- a/drivers/oprofile/event_buffer.c
45460+++ b/drivers/oprofile/event_buffer.c
45461@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
45462 }
45463
45464 if (buffer_pos == buffer_size) {
45465- atomic_inc(&oprofile_stats.event_lost_overflow);
45466+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
45467 return;
45468 }
45469
45470diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
45471index ed2c3ec..deda85a 100644
45472--- a/drivers/oprofile/oprof.c
45473+++ b/drivers/oprofile/oprof.c
45474@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
45475 if (oprofile_ops.switch_events())
45476 return;
45477
45478- atomic_inc(&oprofile_stats.multiplex_counter);
45479+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
45480 start_switch_worker();
45481 }
45482
45483diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
45484index 84a208d..d61b0a1 100644
45485--- a/drivers/oprofile/oprofile_files.c
45486+++ b/drivers/oprofile/oprofile_files.c
45487@@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
45488
45489 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
45490
45491-static ssize_t timeout_read(struct file *file, char __user *buf,
45492+static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
45493 size_t count, loff_t *offset)
45494 {
45495 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
45496diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
45497index 917d28e..d62d981 100644
45498--- a/drivers/oprofile/oprofile_stats.c
45499+++ b/drivers/oprofile/oprofile_stats.c
45500@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
45501 cpu_buf->sample_invalid_eip = 0;
45502 }
45503
45504- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
45505- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
45506- atomic_set(&oprofile_stats.event_lost_overflow, 0);
45507- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
45508- atomic_set(&oprofile_stats.multiplex_counter, 0);
45509+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
45510+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
45511+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
45512+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
45513+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
45514 }
45515
45516
45517diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
45518index 38b6fc0..b5cbfce 100644
45519--- a/drivers/oprofile/oprofile_stats.h
45520+++ b/drivers/oprofile/oprofile_stats.h
45521@@ -13,11 +13,11 @@
45522 #include <linux/atomic.h>
45523
45524 struct oprofile_stat_struct {
45525- atomic_t sample_lost_no_mm;
45526- atomic_t sample_lost_no_mapping;
45527- atomic_t bt_lost_no_mapping;
45528- atomic_t event_lost_overflow;
45529- atomic_t multiplex_counter;
45530+ atomic_unchecked_t sample_lost_no_mm;
45531+ atomic_unchecked_t sample_lost_no_mapping;
45532+ atomic_unchecked_t bt_lost_no_mapping;
45533+ atomic_unchecked_t event_lost_overflow;
45534+ atomic_unchecked_t multiplex_counter;
45535 };
45536
45537 extern struct oprofile_stat_struct oprofile_stats;
45538diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
45539index 7c12d9c..558bf3bb 100644
45540--- a/drivers/oprofile/oprofilefs.c
45541+++ b/drivers/oprofile/oprofilefs.c
45542@@ -190,7 +190,7 @@ static const struct file_operations atomic_ro_fops = {
45543
45544
45545 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
45546- char const *name, atomic_t *val)
45547+ char const *name, atomic_unchecked_t *val)
45548 {
45549 return __oprofilefs_create_file(sb, root, name,
45550 &atomic_ro_fops, 0444, val);
45551diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
45552index 61be1d9..dec05d7 100644
45553--- a/drivers/oprofile/timer_int.c
45554+++ b/drivers/oprofile/timer_int.c
45555@@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
45556 return NOTIFY_OK;
45557 }
45558
45559-static struct notifier_block __refdata oprofile_cpu_notifier = {
45560+static struct notifier_block oprofile_cpu_notifier = {
45561 .notifier_call = oprofile_cpu_notify,
45562 };
45563
45564diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
45565index 92ed045..62d39bd7 100644
45566--- a/drivers/parport/procfs.c
45567+++ b/drivers/parport/procfs.c
45568@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
45569
45570 *ppos += len;
45571
45572- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
45573+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
45574 }
45575
45576 #ifdef CONFIG_PARPORT_1284
45577@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
45578
45579 *ppos += len;
45580
45581- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
45582+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
45583 }
45584 #endif /* IEEE1284.3 support. */
45585
45586diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
45587index c35e8ad..fc33beb 100644
45588--- a/drivers/pci/hotplug/acpiphp_ibm.c
45589+++ b/drivers/pci/hotplug/acpiphp_ibm.c
45590@@ -464,7 +464,9 @@ static int __init ibm_acpiphp_init(void)
45591 goto init_cleanup;
45592 }
45593
45594- ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
45595+ pax_open_kernel();
45596+ *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
45597+ pax_close_kernel();
45598 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
45599
45600 return retval;
45601diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
45602index a6a71c4..c91097b 100644
45603--- a/drivers/pci/hotplug/cpcihp_generic.c
45604+++ b/drivers/pci/hotplug/cpcihp_generic.c
45605@@ -73,7 +73,6 @@ static u16 port;
45606 static unsigned int enum_bit;
45607 static u8 enum_mask;
45608
45609-static struct cpci_hp_controller_ops generic_hpc_ops;
45610 static struct cpci_hp_controller generic_hpc;
45611
45612 static int __init validate_parameters(void)
45613@@ -139,6 +138,10 @@ static int query_enum(void)
45614 return ((value & enum_mask) == enum_mask);
45615 }
45616
45617+static struct cpci_hp_controller_ops generic_hpc_ops = {
45618+ .query_enum = query_enum,
45619+};
45620+
45621 static int __init cpcihp_generic_init(void)
45622 {
45623 int status;
45624@@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
45625 pci_dev_put(dev);
45626
45627 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
45628- generic_hpc_ops.query_enum = query_enum;
45629 generic_hpc.ops = &generic_hpc_ops;
45630
45631 status = cpci_hp_register_controller(&generic_hpc);
45632diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
45633index 449b4bb..257e2e8 100644
45634--- a/drivers/pci/hotplug/cpcihp_zt5550.c
45635+++ b/drivers/pci/hotplug/cpcihp_zt5550.c
45636@@ -59,7 +59,6 @@
45637 /* local variables */
45638 static bool debug;
45639 static bool poll;
45640-static struct cpci_hp_controller_ops zt5550_hpc_ops;
45641 static struct cpci_hp_controller zt5550_hpc;
45642
45643 /* Primary cPCI bus bridge device */
45644@@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
45645 return 0;
45646 }
45647
45648+static struct cpci_hp_controller_ops zt5550_hpc_ops = {
45649+ .query_enum = zt5550_hc_query_enum,
45650+};
45651+
45652 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
45653 {
45654 int status;
45655@@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
45656 dbg("returned from zt5550_hc_config");
45657
45658 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
45659- zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
45660 zt5550_hpc.ops = &zt5550_hpc_ops;
45661 if(!poll) {
45662 zt5550_hpc.irq = hc_dev->irq;
45663 zt5550_hpc.irq_flags = IRQF_SHARED;
45664 zt5550_hpc.dev_id = hc_dev;
45665
45666- zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
45667- zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
45668- zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
45669+ pax_open_kernel();
45670+ *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
45671+ *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
45672+ *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
45673+ pax_open_kernel();
45674 } else {
45675 info("using ENUM# polling mode");
45676 }
45677diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
45678index 76ba8a1..20ca857 100644
45679--- a/drivers/pci/hotplug/cpqphp_nvram.c
45680+++ b/drivers/pci/hotplug/cpqphp_nvram.c
45681@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
45682
45683 void compaq_nvram_init (void __iomem *rom_start)
45684 {
45685+
45686+#ifndef CONFIG_PAX_KERNEXEC
45687 if (rom_start) {
45688 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
45689 }
45690+#endif
45691+
45692 dbg("int15 entry = %p\n", compaq_int15_entry_point);
45693
45694 /* initialize our int15 lock */
45695diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
45696index ec20f74..c1d961e 100644
45697--- a/drivers/pci/hotplug/pci_hotplug_core.c
45698+++ b/drivers/pci/hotplug/pci_hotplug_core.c
45699@@ -441,8 +441,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
45700 return -EINVAL;
45701 }
45702
45703- slot->ops->owner = owner;
45704- slot->ops->mod_name = mod_name;
45705+ pax_open_kernel();
45706+ *(struct module **)&slot->ops->owner = owner;
45707+ *(const char **)&slot->ops->mod_name = mod_name;
45708+ pax_close_kernel();
45709
45710 mutex_lock(&pci_hp_mutex);
45711 /*
45712diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
45713index 7d72c5e..edce02c 100644
45714--- a/drivers/pci/hotplug/pciehp_core.c
45715+++ b/drivers/pci/hotplug/pciehp_core.c
45716@@ -91,7 +91,7 @@ static int init_slot(struct controller *ctrl)
45717 struct slot *slot = ctrl->slot;
45718 struct hotplug_slot *hotplug = NULL;
45719 struct hotplug_slot_info *info = NULL;
45720- struct hotplug_slot_ops *ops = NULL;
45721+ hotplug_slot_ops_no_const *ops = NULL;
45722 char name[SLOT_NAME_SIZE];
45723 int retval = -ENOMEM;
45724
45725diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
45726index c0dbe1f..94cf3d8 100644
45727--- a/drivers/pci/pci-sysfs.c
45728+++ b/drivers/pci/pci-sysfs.c
45729@@ -1073,7 +1073,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
45730 {
45731 /* allocate attribute structure, piggyback attribute name */
45732 int name_len = write_combine ? 13 : 10;
45733- struct bin_attribute *res_attr;
45734+ bin_attribute_no_const *res_attr;
45735 int retval;
45736
45737 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
45738@@ -1258,7 +1258,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
45739 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
45740 {
45741 int retval;
45742- struct bin_attribute *attr;
45743+ bin_attribute_no_const *attr;
45744
45745 /* If the device has VPD, try to expose it in sysfs. */
45746 if (dev->vpd) {
45747@@ -1305,7 +1305,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
45748 {
45749 int retval;
45750 int rom_size = 0;
45751- struct bin_attribute *attr;
45752+ bin_attribute_no_const *attr;
45753
45754 if (!sysfs_initialized)
45755 return -EACCES;
45756diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
45757index d1182c4..2a138ec 100644
45758--- a/drivers/pci/pci.h
45759+++ b/drivers/pci/pci.h
45760@@ -92,7 +92,7 @@ struct pci_vpd_ops {
45761 struct pci_vpd {
45762 unsigned int len;
45763 const struct pci_vpd_ops *ops;
45764- struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
45765+ bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
45766 };
45767
45768 int pci_vpd_pci22_init(struct pci_dev *dev);
45769diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
45770index 403a443..034e050 100644
45771--- a/drivers/pci/pcie/aspm.c
45772+++ b/drivers/pci/pcie/aspm.c
45773@@ -27,9 +27,9 @@
45774 #define MODULE_PARAM_PREFIX "pcie_aspm."
45775
45776 /* Note: those are not register definitions */
45777-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
45778-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
45779-#define ASPM_STATE_L1 (4) /* L1 state */
45780+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
45781+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
45782+#define ASPM_STATE_L1 (4U) /* L1 state */
45783 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
45784 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
45785
45786diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
45787index 46ada5c..20da716 100644
45788--- a/drivers/pci/probe.c
45789+++ b/drivers/pci/probe.c
45790@@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
45791 struct pci_bus_region region, inverted_region;
45792 bool bar_too_big = false, bar_disabled = false;
45793
45794- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
45795+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
45796
45797 /* No printks while decoding is disabled! */
45798 if (!dev->mmio_always_on) {
45799diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
45800index cdc7836..528635c 100644
45801--- a/drivers/pci/proc.c
45802+++ b/drivers/pci/proc.c
45803@@ -434,7 +434,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
45804 static int __init pci_proc_init(void)
45805 {
45806 struct pci_dev *dev = NULL;
45807+
45808+#ifdef CONFIG_GRKERNSEC_PROC_ADD
45809+#ifdef CONFIG_GRKERNSEC_PROC_USER
45810+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
45811+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
45812+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
45813+#endif
45814+#else
45815 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
45816+#endif
45817 proc_create("devices", 0, proc_bus_pci_dir,
45818 &proc_bus_pci_dev_operations);
45819 proc_initialized = 1;
45820diff --git a/drivers/platform/x86/chromeos_laptop.c b/drivers/platform/x86/chromeos_laptop.c
45821index 3e5b4497..dcdfb70 100644
45822--- a/drivers/platform/x86/chromeos_laptop.c
45823+++ b/drivers/platform/x86/chromeos_laptop.c
45824@@ -301,7 +301,7 @@ static int __init setup_tsl2563_als(const struct dmi_system_id *id)
45825 return 0;
45826 }
45827
45828-static struct dmi_system_id __initdata chromeos_laptop_dmi_table[] = {
45829+static struct dmi_system_id __initconst chromeos_laptop_dmi_table[] = {
45830 {
45831 .ident = "Samsung Series 5 550 - Touchpad",
45832 .matches = {
45833diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
45834index 62f8030..c7f2a45 100644
45835--- a/drivers/platform/x86/msi-laptop.c
45836+++ b/drivers/platform/x86/msi-laptop.c
45837@@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
45838
45839 if (!quirks->ec_read_only) {
45840 /* allow userland write sysfs file */
45841- dev_attr_bluetooth.store = store_bluetooth;
45842- dev_attr_wlan.store = store_wlan;
45843- dev_attr_threeg.store = store_threeg;
45844- dev_attr_bluetooth.attr.mode |= S_IWUSR;
45845- dev_attr_wlan.attr.mode |= S_IWUSR;
45846- dev_attr_threeg.attr.mode |= S_IWUSR;
45847+ pax_open_kernel();
45848+ *(void **)&dev_attr_bluetooth.store = store_bluetooth;
45849+ *(void **)&dev_attr_wlan.store = store_wlan;
45850+ *(void **)&dev_attr_threeg.store = store_threeg;
45851+ *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
45852+ *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
45853+ *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
45854+ pax_close_kernel();
45855 }
45856
45857 /* disable hardware control by fn key */
45858diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
45859index 3a1b6bf..b453930 100644
45860--- a/drivers/platform/x86/sony-laptop.c
45861+++ b/drivers/platform/x86/sony-laptop.c
45862@@ -2486,7 +2486,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
45863 }
45864
45865 /* High speed charging function */
45866-static struct device_attribute *hsc_handle;
45867+static device_attribute_no_const *hsc_handle;
45868
45869 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
45870 struct device_attribute *attr,
45871diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
45872index 54d31c0..3f896d3 100644
45873--- a/drivers/platform/x86/thinkpad_acpi.c
45874+++ b/drivers/platform/x86/thinkpad_acpi.c
45875@@ -2093,7 +2093,7 @@ static int hotkey_mask_get(void)
45876 return 0;
45877 }
45878
45879-void static hotkey_mask_warn_incomplete_mask(void)
45880+static void hotkey_mask_warn_incomplete_mask(void)
45881 {
45882 /* log only what the user can fix... */
45883 const u32 wantedmask = hotkey_driver_mask &
45884@@ -2324,11 +2324,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
45885 }
45886 }
45887
45888-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45889- struct tp_nvram_state *newn,
45890- const u32 event_mask)
45891-{
45892-
45893 #define TPACPI_COMPARE_KEY(__scancode, __member) \
45894 do { \
45895 if ((event_mask & (1 << __scancode)) && \
45896@@ -2342,36 +2337,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45897 tpacpi_hotkey_send_key(__scancode); \
45898 } while (0)
45899
45900- void issue_volchange(const unsigned int oldvol,
45901- const unsigned int newvol)
45902- {
45903- unsigned int i = oldvol;
45904+static void issue_volchange(const unsigned int oldvol,
45905+ const unsigned int newvol,
45906+ const u32 event_mask)
45907+{
45908+ unsigned int i = oldvol;
45909
45910- while (i > newvol) {
45911- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
45912- i--;
45913- }
45914- while (i < newvol) {
45915- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
45916- i++;
45917- }
45918+ while (i > newvol) {
45919+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
45920+ i--;
45921 }
45922+ while (i < newvol) {
45923+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
45924+ i++;
45925+ }
45926+}
45927
45928- void issue_brightnesschange(const unsigned int oldbrt,
45929- const unsigned int newbrt)
45930- {
45931- unsigned int i = oldbrt;
45932+static void issue_brightnesschange(const unsigned int oldbrt,
45933+ const unsigned int newbrt,
45934+ const u32 event_mask)
45935+{
45936+ unsigned int i = oldbrt;
45937
45938- while (i > newbrt) {
45939- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
45940- i--;
45941- }
45942- while (i < newbrt) {
45943- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
45944- i++;
45945- }
45946+ while (i > newbrt) {
45947+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
45948+ i--;
45949+ }
45950+ while (i < newbrt) {
45951+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
45952+ i++;
45953 }
45954+}
45955
45956+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45957+ struct tp_nvram_state *newn,
45958+ const u32 event_mask)
45959+{
45960 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
45961 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
45962 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
45963@@ -2405,7 +2406,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45964 oldn->volume_level != newn->volume_level) {
45965 /* recently muted, or repeated mute keypress, or
45966 * multiple presses ending in mute */
45967- issue_volchange(oldn->volume_level, newn->volume_level);
45968+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
45969 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
45970 }
45971 } else {
45972@@ -2415,7 +2416,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45973 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
45974 }
45975 if (oldn->volume_level != newn->volume_level) {
45976- issue_volchange(oldn->volume_level, newn->volume_level);
45977+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
45978 } else if (oldn->volume_toggle != newn->volume_toggle) {
45979 /* repeated vol up/down keypress at end of scale ? */
45980 if (newn->volume_level == 0)
45981@@ -2428,7 +2429,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45982 /* handle brightness */
45983 if (oldn->brightness_level != newn->brightness_level) {
45984 issue_brightnesschange(oldn->brightness_level,
45985- newn->brightness_level);
45986+ newn->brightness_level,
45987+ event_mask);
45988 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
45989 /* repeated key presses that didn't change state */
45990 if (newn->brightness_level == 0)
45991@@ -2437,10 +2439,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45992 && !tp_features.bright_unkfw)
45993 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
45994 }
45995+}
45996
45997 #undef TPACPI_COMPARE_KEY
45998 #undef TPACPI_MAY_SEND_KEY
45999-}
46000
46001 /*
46002 * Polling driver
46003diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
46004index 769d265..a3a05ca 100644
46005--- a/drivers/pnp/pnpbios/bioscalls.c
46006+++ b/drivers/pnp/pnpbios/bioscalls.c
46007@@ -58,7 +58,7 @@ do { \
46008 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
46009 } while(0)
46010
46011-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
46012+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
46013 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
46014
46015 /*
46016@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
46017
46018 cpu = get_cpu();
46019 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
46020+
46021+ pax_open_kernel();
46022 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
46023+ pax_close_kernel();
46024
46025 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
46026 spin_lock_irqsave(&pnp_bios_lock, flags);
46027@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
46028 :"memory");
46029 spin_unlock_irqrestore(&pnp_bios_lock, flags);
46030
46031+ pax_open_kernel();
46032 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
46033+ pax_close_kernel();
46034+
46035 put_cpu();
46036
46037 /* If we get here and this is set then the PnP BIOS faulted on us. */
46038@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
46039 return status;
46040 }
46041
46042-void pnpbios_calls_init(union pnp_bios_install_struct *header)
46043+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
46044 {
46045 int i;
46046
46047@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
46048 pnp_bios_callpoint.offset = header->fields.pm16offset;
46049 pnp_bios_callpoint.segment = PNP_CS16;
46050
46051+ pax_open_kernel();
46052+
46053 for_each_possible_cpu(i) {
46054 struct desc_struct *gdt = get_cpu_gdt_table(i);
46055 if (!gdt)
46056@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
46057 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
46058 (unsigned long)__va(header->fields.pm16dseg));
46059 }
46060+
46061+ pax_close_kernel();
46062 }
46063diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
46064index d95e101..67f0c3f 100644
46065--- a/drivers/pnp/resource.c
46066+++ b/drivers/pnp/resource.c
46067@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
46068 return 1;
46069
46070 /* check if the resource is valid */
46071- if (*irq < 0 || *irq > 15)
46072+ if (*irq > 15)
46073 return 0;
46074
46075 /* check if the resource is reserved */
46076@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
46077 return 1;
46078
46079 /* check if the resource is valid */
46080- if (*dma < 0 || *dma == 4 || *dma > 7)
46081+ if (*dma == 4 || *dma > 7)
46082 return 0;
46083
46084 /* check if the resource is reserved */
46085diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
46086index 0c52e2a..3421ab7 100644
46087--- a/drivers/power/pda_power.c
46088+++ b/drivers/power/pda_power.c
46089@@ -37,7 +37,11 @@ static int polling;
46090
46091 #if IS_ENABLED(CONFIG_USB_PHY)
46092 static struct usb_phy *transceiver;
46093-static struct notifier_block otg_nb;
46094+static int otg_handle_notification(struct notifier_block *nb,
46095+ unsigned long event, void *unused);
46096+static struct notifier_block otg_nb = {
46097+ .notifier_call = otg_handle_notification
46098+};
46099 #endif
46100
46101 static struct regulator *ac_draw;
46102@@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
46103
46104 #if IS_ENABLED(CONFIG_USB_PHY)
46105 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
46106- otg_nb.notifier_call = otg_handle_notification;
46107 ret = usb_register_notifier(transceiver, &otg_nb);
46108 if (ret) {
46109 dev_err(dev, "failure to register otg notifier\n");
46110diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
46111index cc439fd..8fa30df 100644
46112--- a/drivers/power/power_supply.h
46113+++ b/drivers/power/power_supply.h
46114@@ -16,12 +16,12 @@ struct power_supply;
46115
46116 #ifdef CONFIG_SYSFS
46117
46118-extern void power_supply_init_attrs(struct device_type *dev_type);
46119+extern void power_supply_init_attrs(void);
46120 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
46121
46122 #else
46123
46124-static inline void power_supply_init_attrs(struct device_type *dev_type) {}
46125+static inline void power_supply_init_attrs(void) {}
46126 #define power_supply_uevent NULL
46127
46128 #endif /* CONFIG_SYSFS */
46129diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
46130index 3b2d5df..3207114 100644
46131--- a/drivers/power/power_supply_core.c
46132+++ b/drivers/power/power_supply_core.c
46133@@ -24,7 +24,10 @@
46134 struct class *power_supply_class;
46135 EXPORT_SYMBOL_GPL(power_supply_class);
46136
46137-static struct device_type power_supply_dev_type;
46138+extern const struct attribute_group *power_supply_attr_groups[];
46139+static struct device_type power_supply_dev_type = {
46140+ .groups = power_supply_attr_groups,
46141+};
46142
46143 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
46144 struct power_supply *supply)
46145@@ -558,7 +561,7 @@ static int __init power_supply_class_init(void)
46146 return PTR_ERR(power_supply_class);
46147
46148 power_supply_class->dev_uevent = power_supply_uevent;
46149- power_supply_init_attrs(&power_supply_dev_type);
46150+ power_supply_init_attrs();
46151
46152 return 0;
46153 }
46154diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
46155index 29178f7..c65f324 100644
46156--- a/drivers/power/power_supply_sysfs.c
46157+++ b/drivers/power/power_supply_sysfs.c
46158@@ -230,17 +230,15 @@ static struct attribute_group power_supply_attr_group = {
46159 .is_visible = power_supply_attr_is_visible,
46160 };
46161
46162-static const struct attribute_group *power_supply_attr_groups[] = {
46163+const struct attribute_group *power_supply_attr_groups[] = {
46164 &power_supply_attr_group,
46165 NULL,
46166 };
46167
46168-void power_supply_init_attrs(struct device_type *dev_type)
46169+void power_supply_init_attrs(void)
46170 {
46171 int i;
46172
46173- dev_type->groups = power_supply_attr_groups;
46174-
46175 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
46176 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
46177 }
46178diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
46179index 288c75a..065bc84 100644
46180--- a/drivers/regulator/core.c
46181+++ b/drivers/regulator/core.c
46182@@ -3544,7 +3544,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
46183 {
46184 const struct regulation_constraints *constraints = NULL;
46185 const struct regulator_init_data *init_data;
46186- static atomic_t regulator_no = ATOMIC_INIT(0);
46187+ static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
46188 struct regulator_dev *rdev;
46189 struct device *dev;
46190 int ret, i;
46191@@ -3614,7 +3614,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
46192 rdev->dev.of_node = config->of_node;
46193 rdev->dev.parent = dev;
46194 dev_set_name(&rdev->dev, "regulator.%d",
46195- atomic_inc_return(&regulator_no) - 1);
46196+ atomic_inc_return_unchecked(&regulator_no) - 1);
46197 ret = device_register(&rdev->dev);
46198 if (ret != 0) {
46199 put_device(&rdev->dev);
46200diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
46201index d428ef9..fdc0357 100644
46202--- a/drivers/regulator/max8660.c
46203+++ b/drivers/regulator/max8660.c
46204@@ -333,8 +333,10 @@ static int max8660_probe(struct i2c_client *client,
46205 max8660->shadow_regs[MAX8660_OVER1] = 5;
46206 } else {
46207 /* Otherwise devices can be toggled via software */
46208- max8660_dcdc_ops.enable = max8660_dcdc_enable;
46209- max8660_dcdc_ops.disable = max8660_dcdc_disable;
46210+ pax_open_kernel();
46211+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
46212+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
46213+ pax_close_kernel();
46214 }
46215
46216 /*
46217diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
46218index 0c5195a..637a453d 100644
46219--- a/drivers/regulator/max8973-regulator.c
46220+++ b/drivers/regulator/max8973-regulator.c
46221@@ -406,9 +406,11 @@ static int max8973_probe(struct i2c_client *client,
46222 if (!pdata || !pdata->enable_ext_control) {
46223 max->desc.enable_reg = MAX8973_VOUT;
46224 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
46225- max->ops.enable = regulator_enable_regmap;
46226- max->ops.disable = regulator_disable_regmap;
46227- max->ops.is_enabled = regulator_is_enabled_regmap;
46228+ pax_open_kernel();
46229+ *(void **)&max->ops.enable = regulator_enable_regmap;
46230+ *(void **)&max->ops.disable = regulator_disable_regmap;
46231+ *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
46232+ pax_close_kernel();
46233 }
46234
46235 if (pdata) {
46236diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
46237index 1037e07..e64dea1 100644
46238--- a/drivers/regulator/mc13892-regulator.c
46239+++ b/drivers/regulator/mc13892-regulator.c
46240@@ -582,10 +582,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
46241 }
46242 mc13xxx_unlock(mc13892);
46243
46244- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
46245+ pax_open_kernel();
46246+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
46247 = mc13892_vcam_set_mode;
46248- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
46249+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
46250 = mc13892_vcam_get_mode;
46251+ pax_close_kernel();
46252
46253 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
46254 ARRAY_SIZE(mc13892_regulators));
46255diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
46256index be06d71..264aee9 100644
46257--- a/drivers/rtc/rtc-cmos.c
46258+++ b/drivers/rtc/rtc-cmos.c
46259@@ -731,7 +731,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
46260 hpet_rtc_timer_init();
46261
46262 /* export at least the first block of NVRAM */
46263- nvram.size = address_space - NVRAM_OFFSET;
46264+ pax_open_kernel();
46265+ *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
46266+ pax_close_kernel();
46267 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
46268 if (retval < 0) {
46269 dev_dbg(dev, "can't create nvram file? %d\n", retval);
46270diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
46271index d049393..bb20be0 100644
46272--- a/drivers/rtc/rtc-dev.c
46273+++ b/drivers/rtc/rtc-dev.c
46274@@ -16,6 +16,7 @@
46275 #include <linux/module.h>
46276 #include <linux/rtc.h>
46277 #include <linux/sched.h>
46278+#include <linux/grsecurity.h>
46279 #include "rtc-core.h"
46280
46281 static dev_t rtc_devt;
46282@@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
46283 if (copy_from_user(&tm, uarg, sizeof(tm)))
46284 return -EFAULT;
46285
46286+ gr_log_timechange();
46287+
46288 return rtc_set_time(rtc, &tm);
46289
46290 case RTC_PIE_ON:
46291diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
46292index ca18fd1..055e42d 100644
46293--- a/drivers/rtc/rtc-ds1307.c
46294+++ b/drivers/rtc/rtc-ds1307.c
46295@@ -107,7 +107,7 @@ struct ds1307 {
46296 u8 offset; /* register's offset */
46297 u8 regs[11];
46298 u16 nvram_offset;
46299- struct bin_attribute *nvram;
46300+ bin_attribute_no_const *nvram;
46301 enum ds_type type;
46302 unsigned long flags;
46303 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
46304diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
46305index fcb0329..d77b7f2 100644
46306--- a/drivers/rtc/rtc-m48t59.c
46307+++ b/drivers/rtc/rtc-m48t59.c
46308@@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
46309 if (IS_ERR(m48t59->rtc))
46310 return PTR_ERR(m48t59->rtc);
46311
46312- m48t59_nvram_attr.size = pdata->offset;
46313+ pax_open_kernel();
46314+ *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
46315+ pax_close_kernel();
46316
46317 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
46318 if (ret)
46319diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
46320index e693af6..2e525b6 100644
46321--- a/drivers/scsi/bfa/bfa_fcpim.h
46322+++ b/drivers/scsi/bfa/bfa_fcpim.h
46323@@ -36,7 +36,7 @@ struct bfa_iotag_s {
46324
46325 struct bfa_itn_s {
46326 bfa_isr_func_t isr;
46327-};
46328+} __no_const;
46329
46330 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
46331 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
46332diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
46333index 90814fe..4384138 100644
46334--- a/drivers/scsi/bfa/bfa_ioc.h
46335+++ b/drivers/scsi/bfa/bfa_ioc.h
46336@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
46337 bfa_ioc_disable_cbfn_t disable_cbfn;
46338 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
46339 bfa_ioc_reset_cbfn_t reset_cbfn;
46340-};
46341+} __no_const;
46342
46343 /*
46344 * IOC event notification mechanism.
46345@@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
46346 void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
46347 enum bfi_ioc_state fwstate);
46348 enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
46349-};
46350+} __no_const;
46351
46352 /*
46353 * Queue element to wait for room in request queue. FIFO order is
46354diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
46355index c9382d6..6619864 100644
46356--- a/drivers/scsi/fcoe/fcoe_sysfs.c
46357+++ b/drivers/scsi/fcoe/fcoe_sysfs.c
46358@@ -33,8 +33,8 @@
46359 */
46360 #include "libfcoe.h"
46361
46362-static atomic_t ctlr_num;
46363-static atomic_t fcf_num;
46364+static atomic_unchecked_t ctlr_num;
46365+static atomic_unchecked_t fcf_num;
46366
46367 /*
46368 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
46369@@ -681,7 +681,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
46370 if (!ctlr)
46371 goto out;
46372
46373- ctlr->id = atomic_inc_return(&ctlr_num) - 1;
46374+ ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
46375 ctlr->f = f;
46376 ctlr->mode = FIP_CONN_TYPE_FABRIC;
46377 INIT_LIST_HEAD(&ctlr->fcfs);
46378@@ -898,7 +898,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
46379 fcf->dev.parent = &ctlr->dev;
46380 fcf->dev.bus = &fcoe_bus_type;
46381 fcf->dev.type = &fcoe_fcf_device_type;
46382- fcf->id = atomic_inc_return(&fcf_num) - 1;
46383+ fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
46384 fcf->state = FCOE_FCF_STATE_UNKNOWN;
46385
46386 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
46387@@ -934,8 +934,8 @@ int __init fcoe_sysfs_setup(void)
46388 {
46389 int error;
46390
46391- atomic_set(&ctlr_num, 0);
46392- atomic_set(&fcf_num, 0);
46393+ atomic_set_unchecked(&ctlr_num, 0);
46394+ atomic_set_unchecked(&fcf_num, 0);
46395
46396 error = bus_register(&fcoe_bus_type);
46397 if (error)
46398diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
46399index df0c3c7..b00e1d0 100644
46400--- a/drivers/scsi/hosts.c
46401+++ b/drivers/scsi/hosts.c
46402@@ -42,7 +42,7 @@
46403 #include "scsi_logging.h"
46404
46405
46406-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
46407+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
46408
46409
46410 static void scsi_host_cls_release(struct device *dev)
46411@@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
46412 * subtract one because we increment first then return, but we need to
46413 * know what the next host number was before increment
46414 */
46415- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
46416+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
46417 shost->dma_channel = 0xff;
46418
46419 /* These three are default values which can be overridden */
46420diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
46421index 7f4f790..b75b92a 100644
46422--- a/drivers/scsi/hpsa.c
46423+++ b/drivers/scsi/hpsa.c
46424@@ -554,7 +554,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
46425 unsigned long flags;
46426
46427 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
46428- return h->access.command_completed(h, q);
46429+ return h->access->command_completed(h, q);
46430
46431 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
46432 a = rq->head[rq->current_entry];
46433@@ -3422,7 +3422,7 @@ static void start_io(struct ctlr_info *h)
46434 while (!list_empty(&h->reqQ)) {
46435 c = list_entry(h->reqQ.next, struct CommandList, list);
46436 /* can't do anything if fifo is full */
46437- if ((h->access.fifo_full(h))) {
46438+ if ((h->access->fifo_full(h))) {
46439 dev_warn(&h->pdev->dev, "fifo full\n");
46440 break;
46441 }
46442@@ -3444,7 +3444,7 @@ static void start_io(struct ctlr_info *h)
46443
46444 /* Tell the controller execute command */
46445 spin_unlock_irqrestore(&h->lock, flags);
46446- h->access.submit_command(h, c);
46447+ h->access->submit_command(h, c);
46448 spin_lock_irqsave(&h->lock, flags);
46449 }
46450 spin_unlock_irqrestore(&h->lock, flags);
46451@@ -3452,17 +3452,17 @@ static void start_io(struct ctlr_info *h)
46452
46453 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
46454 {
46455- return h->access.command_completed(h, q);
46456+ return h->access->command_completed(h, q);
46457 }
46458
46459 static inline bool interrupt_pending(struct ctlr_info *h)
46460 {
46461- return h->access.intr_pending(h);
46462+ return h->access->intr_pending(h);
46463 }
46464
46465 static inline long interrupt_not_for_us(struct ctlr_info *h)
46466 {
46467- return (h->access.intr_pending(h) == 0) ||
46468+ return (h->access->intr_pending(h) == 0) ||
46469 (h->interrupts_enabled == 0);
46470 }
46471
46472@@ -4364,7 +4364,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
46473 if (prod_index < 0)
46474 return -ENODEV;
46475 h->product_name = products[prod_index].product_name;
46476- h->access = *(products[prod_index].access);
46477+ h->access = products[prod_index].access;
46478
46479 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
46480 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
46481@@ -4646,7 +4646,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
46482
46483 assert_spin_locked(&lockup_detector_lock);
46484 remove_ctlr_from_lockup_detector_list(h);
46485- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46486+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46487 spin_lock_irqsave(&h->lock, flags);
46488 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
46489 spin_unlock_irqrestore(&h->lock, flags);
46490@@ -4823,7 +4823,7 @@ reinit_after_soft_reset:
46491 }
46492
46493 /* make sure the board interrupts are off */
46494- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46495+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46496
46497 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
46498 goto clean2;
46499@@ -4857,7 +4857,7 @@ reinit_after_soft_reset:
46500 * fake ones to scoop up any residual completions.
46501 */
46502 spin_lock_irqsave(&h->lock, flags);
46503- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46504+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46505 spin_unlock_irqrestore(&h->lock, flags);
46506 free_irqs(h);
46507 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
46508@@ -4876,9 +4876,9 @@ reinit_after_soft_reset:
46509 dev_info(&h->pdev->dev, "Board READY.\n");
46510 dev_info(&h->pdev->dev,
46511 "Waiting for stale completions to drain.\n");
46512- h->access.set_intr_mask(h, HPSA_INTR_ON);
46513+ h->access->set_intr_mask(h, HPSA_INTR_ON);
46514 msleep(10000);
46515- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46516+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46517
46518 rc = controller_reset_failed(h->cfgtable);
46519 if (rc)
46520@@ -4899,7 +4899,7 @@ reinit_after_soft_reset:
46521 }
46522
46523 /* Turn the interrupts on so we can service requests */
46524- h->access.set_intr_mask(h, HPSA_INTR_ON);
46525+ h->access->set_intr_mask(h, HPSA_INTR_ON);
46526
46527 hpsa_hba_inquiry(h);
46528 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
46529@@ -4954,7 +4954,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
46530 * To write all data in the battery backed cache to disks
46531 */
46532 hpsa_flush_cache(h);
46533- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46534+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46535 hpsa_free_irqs_and_disable_msix(h);
46536 }
46537
46538@@ -5122,7 +5122,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
46539 return;
46540 }
46541 /* Change the access methods to the performant access methods */
46542- h->access = SA5_performant_access;
46543+ h->access = &SA5_performant_access;
46544 h->transMethod = CFGTBL_Trans_Performant;
46545 }
46546
46547diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
46548index 9816479..c5d4e97 100644
46549--- a/drivers/scsi/hpsa.h
46550+++ b/drivers/scsi/hpsa.h
46551@@ -79,7 +79,7 @@ struct ctlr_info {
46552 unsigned int msix_vector;
46553 unsigned int msi_vector;
46554 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
46555- struct access_method access;
46556+ struct access_method *access;
46557
46558 /* queue and queue Info */
46559 struct list_head reqQ;
46560diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
46561index 5879929..32b241d 100644
46562--- a/drivers/scsi/libfc/fc_exch.c
46563+++ b/drivers/scsi/libfc/fc_exch.c
46564@@ -100,12 +100,12 @@ struct fc_exch_mgr {
46565 u16 pool_max_index;
46566
46567 struct {
46568- atomic_t no_free_exch;
46569- atomic_t no_free_exch_xid;
46570- atomic_t xid_not_found;
46571- atomic_t xid_busy;
46572- atomic_t seq_not_found;
46573- atomic_t non_bls_resp;
46574+ atomic_unchecked_t no_free_exch;
46575+ atomic_unchecked_t no_free_exch_xid;
46576+ atomic_unchecked_t xid_not_found;
46577+ atomic_unchecked_t xid_busy;
46578+ atomic_unchecked_t seq_not_found;
46579+ atomic_unchecked_t non_bls_resp;
46580 } stats;
46581 };
46582
46583@@ -736,7 +736,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
46584 /* allocate memory for exchange */
46585 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
46586 if (!ep) {
46587- atomic_inc(&mp->stats.no_free_exch);
46588+ atomic_inc_unchecked(&mp->stats.no_free_exch);
46589 goto out;
46590 }
46591 memset(ep, 0, sizeof(*ep));
46592@@ -797,7 +797,7 @@ out:
46593 return ep;
46594 err:
46595 spin_unlock_bh(&pool->lock);
46596- atomic_inc(&mp->stats.no_free_exch_xid);
46597+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
46598 mempool_free(ep, mp->ep_pool);
46599 return NULL;
46600 }
46601@@ -940,7 +940,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
46602 xid = ntohs(fh->fh_ox_id); /* we originated exch */
46603 ep = fc_exch_find(mp, xid);
46604 if (!ep) {
46605- atomic_inc(&mp->stats.xid_not_found);
46606+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46607 reject = FC_RJT_OX_ID;
46608 goto out;
46609 }
46610@@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
46611 ep = fc_exch_find(mp, xid);
46612 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
46613 if (ep) {
46614- atomic_inc(&mp->stats.xid_busy);
46615+ atomic_inc_unchecked(&mp->stats.xid_busy);
46616 reject = FC_RJT_RX_ID;
46617 goto rel;
46618 }
46619@@ -981,7 +981,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
46620 }
46621 xid = ep->xid; /* get our XID */
46622 } else if (!ep) {
46623- atomic_inc(&mp->stats.xid_not_found);
46624+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46625 reject = FC_RJT_RX_ID; /* XID not found */
46626 goto out;
46627 }
46628@@ -998,7 +998,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
46629 } else {
46630 sp = &ep->seq;
46631 if (sp->id != fh->fh_seq_id) {
46632- atomic_inc(&mp->stats.seq_not_found);
46633+ atomic_inc_unchecked(&mp->stats.seq_not_found);
46634 if (f_ctl & FC_FC_END_SEQ) {
46635 /*
46636 * Update sequence_id based on incoming last
46637@@ -1448,22 +1448,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
46638
46639 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
46640 if (!ep) {
46641- atomic_inc(&mp->stats.xid_not_found);
46642+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46643 goto out;
46644 }
46645 if (ep->esb_stat & ESB_ST_COMPLETE) {
46646- atomic_inc(&mp->stats.xid_not_found);
46647+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46648 goto rel;
46649 }
46650 if (ep->rxid == FC_XID_UNKNOWN)
46651 ep->rxid = ntohs(fh->fh_rx_id);
46652 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
46653- atomic_inc(&mp->stats.xid_not_found);
46654+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46655 goto rel;
46656 }
46657 if (ep->did != ntoh24(fh->fh_s_id) &&
46658 ep->did != FC_FID_FLOGI) {
46659- atomic_inc(&mp->stats.xid_not_found);
46660+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46661 goto rel;
46662 }
46663 sof = fr_sof(fp);
46664@@ -1472,7 +1472,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
46665 sp->ssb_stat |= SSB_ST_RESP;
46666 sp->id = fh->fh_seq_id;
46667 } else if (sp->id != fh->fh_seq_id) {
46668- atomic_inc(&mp->stats.seq_not_found);
46669+ atomic_inc_unchecked(&mp->stats.seq_not_found);
46670 goto rel;
46671 }
46672
46673@@ -1536,9 +1536,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
46674 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
46675
46676 if (!sp)
46677- atomic_inc(&mp->stats.xid_not_found);
46678+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46679 else
46680- atomic_inc(&mp->stats.non_bls_resp);
46681+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
46682
46683 fc_frame_free(fp);
46684 }
46685@@ -2185,13 +2185,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
46686
46687 list_for_each_entry(ema, &lport->ema_list, ema_list) {
46688 mp = ema->mp;
46689- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
46690+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
46691 st->fc_no_free_exch_xid +=
46692- atomic_read(&mp->stats.no_free_exch_xid);
46693- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
46694- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
46695- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
46696- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
46697+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
46698+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
46699+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
46700+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
46701+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
46702 }
46703 }
46704 EXPORT_SYMBOL(fc_exch_update_stats);
46705diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
46706index 161c98e..6d563b3 100644
46707--- a/drivers/scsi/libsas/sas_ata.c
46708+++ b/drivers/scsi/libsas/sas_ata.c
46709@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
46710 .postreset = ata_std_postreset,
46711 .error_handler = ata_std_error_handler,
46712 .post_internal_cmd = sas_ata_post_internal,
46713- .qc_defer = ata_std_qc_defer,
46714+ .qc_defer = ata_std_qc_defer,
46715 .qc_prep = ata_noop_qc_prep,
46716 .qc_issue = sas_ata_qc_issue,
46717 .qc_fill_rtf = sas_ata_qc_fill_rtf,
46718diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
46719index 93f222d..73e977b 100644
46720--- a/drivers/scsi/lpfc/lpfc.h
46721+++ b/drivers/scsi/lpfc/lpfc.h
46722@@ -431,7 +431,7 @@ struct lpfc_vport {
46723 struct dentry *debug_nodelist;
46724 struct dentry *vport_debugfs_root;
46725 struct lpfc_debugfs_trc *disc_trc;
46726- atomic_t disc_trc_cnt;
46727+ atomic_unchecked_t disc_trc_cnt;
46728 #endif
46729 uint8_t stat_data_enabled;
46730 uint8_t stat_data_blocked;
46731@@ -865,8 +865,8 @@ struct lpfc_hba {
46732 struct timer_list fabric_block_timer;
46733 unsigned long bit_flags;
46734 #define FABRIC_COMANDS_BLOCKED 0
46735- atomic_t num_rsrc_err;
46736- atomic_t num_cmd_success;
46737+ atomic_unchecked_t num_rsrc_err;
46738+ atomic_unchecked_t num_cmd_success;
46739 unsigned long last_rsrc_error_time;
46740 unsigned long last_ramp_down_time;
46741 unsigned long last_ramp_up_time;
46742@@ -902,7 +902,7 @@ struct lpfc_hba {
46743
46744 struct dentry *debug_slow_ring_trc;
46745 struct lpfc_debugfs_trc *slow_ring_trc;
46746- atomic_t slow_ring_trc_cnt;
46747+ atomic_unchecked_t slow_ring_trc_cnt;
46748 /* iDiag debugfs sub-directory */
46749 struct dentry *idiag_root;
46750 struct dentry *idiag_pci_cfg;
46751diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
46752index 60084e6..0e2e700 100644
46753--- a/drivers/scsi/lpfc/lpfc_debugfs.c
46754+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
46755@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
46756
46757 #include <linux/debugfs.h>
46758
46759-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
46760+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
46761 static unsigned long lpfc_debugfs_start_time = 0L;
46762
46763 /* iDiag */
46764@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
46765 lpfc_debugfs_enable = 0;
46766
46767 len = 0;
46768- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
46769+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
46770 (lpfc_debugfs_max_disc_trc - 1);
46771 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
46772 dtp = vport->disc_trc + i;
46773@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
46774 lpfc_debugfs_enable = 0;
46775
46776 len = 0;
46777- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
46778+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
46779 (lpfc_debugfs_max_slow_ring_trc - 1);
46780 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
46781 dtp = phba->slow_ring_trc + i;
46782@@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
46783 !vport || !vport->disc_trc)
46784 return;
46785
46786- index = atomic_inc_return(&vport->disc_trc_cnt) &
46787+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
46788 (lpfc_debugfs_max_disc_trc - 1);
46789 dtp = vport->disc_trc + index;
46790 dtp->fmt = fmt;
46791 dtp->data1 = data1;
46792 dtp->data2 = data2;
46793 dtp->data3 = data3;
46794- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
46795+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
46796 dtp->jif = jiffies;
46797 #endif
46798 return;
46799@@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
46800 !phba || !phba->slow_ring_trc)
46801 return;
46802
46803- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
46804+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
46805 (lpfc_debugfs_max_slow_ring_trc - 1);
46806 dtp = phba->slow_ring_trc + index;
46807 dtp->fmt = fmt;
46808 dtp->data1 = data1;
46809 dtp->data2 = data2;
46810 dtp->data3 = data3;
46811- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
46812+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
46813 dtp->jif = jiffies;
46814 #endif
46815 return;
46816@@ -4168,7 +4168,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
46817 "slow_ring buffer\n");
46818 goto debug_failed;
46819 }
46820- atomic_set(&phba->slow_ring_trc_cnt, 0);
46821+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
46822 memset(phba->slow_ring_trc, 0,
46823 (sizeof(struct lpfc_debugfs_trc) *
46824 lpfc_debugfs_max_slow_ring_trc));
46825@@ -4214,7 +4214,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
46826 "buffer\n");
46827 goto debug_failed;
46828 }
46829- atomic_set(&vport->disc_trc_cnt, 0);
46830+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
46831
46832 snprintf(name, sizeof(name), "discovery_trace");
46833 vport->debug_disc_trc =
46834diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
46835index e0b20fa..30c2c0d 100644
46836--- a/drivers/scsi/lpfc/lpfc_init.c
46837+++ b/drivers/scsi/lpfc/lpfc_init.c
46838@@ -10936,8 +10936,10 @@ lpfc_init(void)
46839 "misc_register returned with status %d", error);
46840
46841 if (lpfc_enable_npiv) {
46842- lpfc_transport_functions.vport_create = lpfc_vport_create;
46843- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
46844+ pax_open_kernel();
46845+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
46846+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
46847+ pax_close_kernel();
46848 }
46849 lpfc_transport_template =
46850 fc_attach_transport(&lpfc_transport_functions);
46851diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
46852index 243de1d..f40e3e5 100644
46853--- a/drivers/scsi/lpfc/lpfc_scsi.c
46854+++ b/drivers/scsi/lpfc/lpfc_scsi.c
46855@@ -353,7 +353,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
46856 uint32_t evt_posted;
46857
46858 spin_lock_irqsave(&phba->hbalock, flags);
46859- atomic_inc(&phba->num_rsrc_err);
46860+ atomic_inc_unchecked(&phba->num_rsrc_err);
46861 phba->last_rsrc_error_time = jiffies;
46862
46863 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
46864@@ -394,7 +394,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
46865 unsigned long flags;
46866 struct lpfc_hba *phba = vport->phba;
46867 uint32_t evt_posted;
46868- atomic_inc(&phba->num_cmd_success);
46869+ atomic_inc_unchecked(&phba->num_cmd_success);
46870
46871 if (vport->cfg_lun_queue_depth <= queue_depth)
46872 return;
46873@@ -438,8 +438,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
46874 unsigned long num_rsrc_err, num_cmd_success;
46875 int i;
46876
46877- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
46878- num_cmd_success = atomic_read(&phba->num_cmd_success);
46879+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
46880+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
46881
46882 /*
46883 * The error and success command counters are global per
46884@@ -467,8 +467,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
46885 }
46886 }
46887 lpfc_destroy_vport_work_array(phba, vports);
46888- atomic_set(&phba->num_rsrc_err, 0);
46889- atomic_set(&phba->num_cmd_success, 0);
46890+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
46891+ atomic_set_unchecked(&phba->num_cmd_success, 0);
46892 }
46893
46894 /**
46895@@ -502,8 +502,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
46896 }
46897 }
46898 lpfc_destroy_vport_work_array(phba, vports);
46899- atomic_set(&phba->num_rsrc_err, 0);
46900- atomic_set(&phba->num_cmd_success, 0);
46901+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
46902+ atomic_set_unchecked(&phba->num_cmd_success, 0);
46903 }
46904
46905 /**
46906diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
46907index 1eb7b028..b2a6080 100644
46908--- a/drivers/scsi/pmcraid.c
46909+++ b/drivers/scsi/pmcraid.c
46910@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
46911 res->scsi_dev = scsi_dev;
46912 scsi_dev->hostdata = res;
46913 res->change_detected = 0;
46914- atomic_set(&res->read_failures, 0);
46915- atomic_set(&res->write_failures, 0);
46916+ atomic_set_unchecked(&res->read_failures, 0);
46917+ atomic_set_unchecked(&res->write_failures, 0);
46918 rc = 0;
46919 }
46920 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
46921@@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
46922
46923 /* If this was a SCSI read/write command keep count of errors */
46924 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
46925- atomic_inc(&res->read_failures);
46926+ atomic_inc_unchecked(&res->read_failures);
46927 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
46928- atomic_inc(&res->write_failures);
46929+ atomic_inc_unchecked(&res->write_failures);
46930
46931 if (!RES_IS_GSCSI(res->cfg_entry) &&
46932 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
46933@@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
46934 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
46935 * hrrq_id assigned here in queuecommand
46936 */
46937- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
46938+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
46939 pinstance->num_hrrq;
46940 cmd->cmd_done = pmcraid_io_done;
46941
46942@@ -3846,7 +3846,7 @@ static long pmcraid_ioctl_passthrough(
46943 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
46944 * hrrq_id assigned here in queuecommand
46945 */
46946- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
46947+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
46948 pinstance->num_hrrq;
46949
46950 if (request_size) {
46951@@ -4483,7 +4483,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
46952
46953 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
46954 /* add resources only after host is added into system */
46955- if (!atomic_read(&pinstance->expose_resources))
46956+ if (!atomic_read_unchecked(&pinstance->expose_resources))
46957 return;
46958
46959 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
46960@@ -5310,8 +5310,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
46961 init_waitqueue_head(&pinstance->reset_wait_q);
46962
46963 atomic_set(&pinstance->outstanding_cmds, 0);
46964- atomic_set(&pinstance->last_message_id, 0);
46965- atomic_set(&pinstance->expose_resources, 0);
46966+ atomic_set_unchecked(&pinstance->last_message_id, 0);
46967+ atomic_set_unchecked(&pinstance->expose_resources, 0);
46968
46969 INIT_LIST_HEAD(&pinstance->free_res_q);
46970 INIT_LIST_HEAD(&pinstance->used_res_q);
46971@@ -6024,7 +6024,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
46972 /* Schedule worker thread to handle CCN and take care of adding and
46973 * removing devices to OS
46974 */
46975- atomic_set(&pinstance->expose_resources, 1);
46976+ atomic_set_unchecked(&pinstance->expose_resources, 1);
46977 schedule_work(&pinstance->worker_q);
46978 return rc;
46979
46980diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
46981index e1d150f..6c6df44 100644
46982--- a/drivers/scsi/pmcraid.h
46983+++ b/drivers/scsi/pmcraid.h
46984@@ -748,7 +748,7 @@ struct pmcraid_instance {
46985 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
46986
46987 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
46988- atomic_t last_message_id;
46989+ atomic_unchecked_t last_message_id;
46990
46991 /* configuration table */
46992 struct pmcraid_config_table *cfg_table;
46993@@ -777,7 +777,7 @@ struct pmcraid_instance {
46994 atomic_t outstanding_cmds;
46995
46996 /* should add/delete resources to mid-layer now ?*/
46997- atomic_t expose_resources;
46998+ atomic_unchecked_t expose_resources;
46999
47000
47001
47002@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
47003 struct pmcraid_config_table_entry_ext cfg_entry_ext;
47004 };
47005 struct scsi_device *scsi_dev; /* Link scsi_device structure */
47006- atomic_t read_failures; /* count of failed READ commands */
47007- atomic_t write_failures; /* count of failed WRITE commands */
47008+ atomic_unchecked_t read_failures; /* count of failed READ commands */
47009+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
47010
47011 /* To indicate add/delete/modify during CCN */
47012 u8 change_detected;
47013diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
47014index d7a99ae..801df70 100644
47015--- a/drivers/scsi/qla2xxx/qla_attr.c
47016+++ b/drivers/scsi/qla2xxx/qla_attr.c
47017@@ -2004,7 +2004,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
47018 return 0;
47019 }
47020
47021-struct fc_function_template qla2xxx_transport_functions = {
47022+fc_function_template_no_const qla2xxx_transport_functions = {
47023
47024 .show_host_node_name = 1,
47025 .show_host_port_name = 1,
47026@@ -2051,7 +2051,7 @@ struct fc_function_template qla2xxx_transport_functions = {
47027 .bsg_timeout = qla24xx_bsg_timeout,
47028 };
47029
47030-struct fc_function_template qla2xxx_transport_vport_functions = {
47031+fc_function_template_no_const qla2xxx_transport_vport_functions = {
47032
47033 .show_host_node_name = 1,
47034 .show_host_port_name = 1,
47035diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
47036index 2d98232..a84298e 100644
47037--- a/drivers/scsi/qla2xxx/qla_gbl.h
47038+++ b/drivers/scsi/qla2xxx/qla_gbl.h
47039@@ -528,8 +528,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
47040 struct device_attribute;
47041 extern struct device_attribute *qla2x00_host_attrs[];
47042 struct fc_function_template;
47043-extern struct fc_function_template qla2xxx_transport_functions;
47044-extern struct fc_function_template qla2xxx_transport_vport_functions;
47045+extern fc_function_template_no_const qla2xxx_transport_functions;
47046+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
47047 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
47048 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
47049 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
47050diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
47051index 3e21e9f..426ba79 100644
47052--- a/drivers/scsi/qla2xxx/qla_os.c
47053+++ b/drivers/scsi/qla2xxx/qla_os.c
47054@@ -1570,8 +1570,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
47055 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
47056 /* Ok, a 64bit DMA mask is applicable. */
47057 ha->flags.enable_64bit_addressing = 1;
47058- ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
47059- ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
47060+ pax_open_kernel();
47061+ *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
47062+ *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
47063+ pax_close_kernel();
47064 return;
47065 }
47066 }
47067diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
47068index ddf16a8..80f4dd0 100644
47069--- a/drivers/scsi/qla4xxx/ql4_def.h
47070+++ b/drivers/scsi/qla4xxx/ql4_def.h
47071@@ -291,7 +291,7 @@ struct ddb_entry {
47072 * (4000 only) */
47073 atomic_t relogin_timer; /* Max Time to wait for
47074 * relogin to complete */
47075- atomic_t relogin_retry_count; /* Num of times relogin has been
47076+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
47077 * retried */
47078 uint32_t default_time2wait; /* Default Min time between
47079 * relogins (+aens) */
47080diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
47081index b246b3c..897004d 100644
47082--- a/drivers/scsi/qla4xxx/ql4_os.c
47083+++ b/drivers/scsi/qla4xxx/ql4_os.c
47084@@ -2971,12 +2971,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
47085 */
47086 if (!iscsi_is_session_online(cls_sess)) {
47087 /* Reset retry relogin timer */
47088- atomic_inc(&ddb_entry->relogin_retry_count);
47089+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
47090 DEBUG2(ql4_printk(KERN_INFO, ha,
47091 "%s: index[%d] relogin timed out-retrying"
47092 " relogin (%d), retry (%d)\n", __func__,
47093 ddb_entry->fw_ddb_index,
47094- atomic_read(&ddb_entry->relogin_retry_count),
47095+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
47096 ddb_entry->default_time2wait + 4));
47097 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
47098 atomic_set(&ddb_entry->retry_relogin_timer,
47099@@ -5081,7 +5081,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
47100
47101 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
47102 atomic_set(&ddb_entry->relogin_timer, 0);
47103- atomic_set(&ddb_entry->relogin_retry_count, 0);
47104+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
47105 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
47106 ddb_entry->default_relogin_timeout =
47107 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
47108diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
47109index eaa808e..95f8841 100644
47110--- a/drivers/scsi/scsi.c
47111+++ b/drivers/scsi/scsi.c
47112@@ -661,7 +661,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
47113 unsigned long timeout;
47114 int rtn = 0;
47115
47116- atomic_inc(&cmd->device->iorequest_cnt);
47117+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
47118
47119 /* check if the device is still usable */
47120 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
47121diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
47122index 124392f..75eb43e 100644
47123--- a/drivers/scsi/scsi_lib.c
47124+++ b/drivers/scsi/scsi_lib.c
47125@@ -1474,7 +1474,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
47126 shost = sdev->host;
47127 scsi_init_cmd_errh(cmd);
47128 cmd->result = DID_NO_CONNECT << 16;
47129- atomic_inc(&cmd->device->iorequest_cnt);
47130+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
47131
47132 /*
47133 * SCSI request completion path will do scsi_device_unbusy(),
47134@@ -1500,9 +1500,9 @@ static void scsi_softirq_done(struct request *rq)
47135
47136 INIT_LIST_HEAD(&cmd->eh_entry);
47137
47138- atomic_inc(&cmd->device->iodone_cnt);
47139+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
47140 if (cmd->result)
47141- atomic_inc(&cmd->device->ioerr_cnt);
47142+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
47143
47144 disposition = scsi_decide_disposition(cmd);
47145 if (disposition != SUCCESS &&
47146diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
47147index 7e50061..71db7a6 100644
47148--- a/drivers/scsi/scsi_sysfs.c
47149+++ b/drivers/scsi/scsi_sysfs.c
47150@@ -687,7 +687,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
47151 char *buf) \
47152 { \
47153 struct scsi_device *sdev = to_scsi_device(dev); \
47154- unsigned long long count = atomic_read(&sdev->field); \
47155+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
47156 return snprintf(buf, 20, "0x%llx\n", count); \
47157 } \
47158 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
47159diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
47160index 84a1fdf..693b0d6 100644
47161--- a/drivers/scsi/scsi_tgt_lib.c
47162+++ b/drivers/scsi/scsi_tgt_lib.c
47163@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
47164 int err;
47165
47166 dprintk("%lx %u\n", uaddr, len);
47167- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
47168+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
47169 if (err) {
47170 /*
47171 * TODO: need to fixup sg_tablesize, max_segment_size,
47172diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
47173index 4628fd5..a94a1c2 100644
47174--- a/drivers/scsi/scsi_transport_fc.c
47175+++ b/drivers/scsi/scsi_transport_fc.c
47176@@ -497,7 +497,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
47177 * Netlink Infrastructure
47178 */
47179
47180-static atomic_t fc_event_seq;
47181+static atomic_unchecked_t fc_event_seq;
47182
47183 /**
47184 * fc_get_event_number - Obtain the next sequential FC event number
47185@@ -510,7 +510,7 @@ static atomic_t fc_event_seq;
47186 u32
47187 fc_get_event_number(void)
47188 {
47189- return atomic_add_return(1, &fc_event_seq);
47190+ return atomic_add_return_unchecked(1, &fc_event_seq);
47191 }
47192 EXPORT_SYMBOL(fc_get_event_number);
47193
47194@@ -654,7 +654,7 @@ static __init int fc_transport_init(void)
47195 {
47196 int error;
47197
47198- atomic_set(&fc_event_seq, 0);
47199+ atomic_set_unchecked(&fc_event_seq, 0);
47200
47201 error = transport_class_register(&fc_host_class);
47202 if (error)
47203@@ -844,7 +844,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
47204 char *cp;
47205
47206 *val = simple_strtoul(buf, &cp, 0);
47207- if ((*cp && (*cp != '\n')) || (*val < 0))
47208+ if (*cp && (*cp != '\n'))
47209 return -EINVAL;
47210 /*
47211 * Check for overflow; dev_loss_tmo is u32
47212diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
47213index abf7c40..c3240ed 100644
47214--- a/drivers/scsi/scsi_transport_iscsi.c
47215+++ b/drivers/scsi/scsi_transport_iscsi.c
47216@@ -80,7 +80,7 @@ struct iscsi_internal {
47217 struct transport_container session_cont;
47218 };
47219
47220-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
47221+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
47222 static struct workqueue_struct *iscsi_eh_timer_workq;
47223
47224 static DEFINE_IDA(iscsi_sess_ida);
47225@@ -1738,7 +1738,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
47226 int err;
47227
47228 ihost = shost->shost_data;
47229- session->sid = atomic_add_return(1, &iscsi_session_nr);
47230+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
47231
47232 if (target_id == ISCSI_MAX_TARGET) {
47233 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
47234@@ -3956,7 +3956,7 @@ static __init int iscsi_transport_init(void)
47235 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
47236 ISCSI_TRANSPORT_VERSION);
47237
47238- atomic_set(&iscsi_session_nr, 0);
47239+ atomic_set_unchecked(&iscsi_session_nr, 0);
47240
47241 err = class_register(&iscsi_transport_class);
47242 if (err)
47243diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
47244index f379c7f..e8fc69c 100644
47245--- a/drivers/scsi/scsi_transport_srp.c
47246+++ b/drivers/scsi/scsi_transport_srp.c
47247@@ -33,7 +33,7 @@
47248 #include "scsi_transport_srp_internal.h"
47249
47250 struct srp_host_attrs {
47251- atomic_t next_port_id;
47252+ atomic_unchecked_t next_port_id;
47253 };
47254 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
47255
47256@@ -61,7 +61,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
47257 struct Scsi_Host *shost = dev_to_shost(dev);
47258 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
47259
47260- atomic_set(&srp_host->next_port_id, 0);
47261+ atomic_set_unchecked(&srp_host->next_port_id, 0);
47262 return 0;
47263 }
47264
47265@@ -210,7 +210,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
47266 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
47267 rport->roles = ids->roles;
47268
47269- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
47270+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
47271 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
47272
47273 transport_setup_device(&rport->dev);
47274diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
47275index 86fcf2c..26d8594 100644
47276--- a/drivers/scsi/sd.c
47277+++ b/drivers/scsi/sd.c
47278@@ -2938,7 +2938,7 @@ static int sd_probe(struct device *dev)
47279 sdkp->disk = gd;
47280 sdkp->index = index;
47281 atomic_set(&sdkp->openers, 0);
47282- atomic_set(&sdkp->device->ioerr_cnt, 0);
47283+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
47284
47285 if (!sdp->request_queue->rq_timeout) {
47286 if (sdp->type != TYPE_MOD)
47287diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
47288index df5e961..df6b97f 100644
47289--- a/drivers/scsi/sg.c
47290+++ b/drivers/scsi/sg.c
47291@@ -1102,7 +1102,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
47292 sdp->disk->disk_name,
47293 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
47294 NULL,
47295- (char *)arg);
47296+ (char __user *)arg);
47297 case BLKTRACESTART:
47298 return blk_trace_startstop(sdp->device->request_queue, 1);
47299 case BLKTRACESTOP:
47300diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
47301index 978dda2..cb19aa0 100644
47302--- a/drivers/spi/spi.c
47303+++ b/drivers/spi/spi.c
47304@@ -1631,7 +1631,7 @@ int spi_bus_unlock(struct spi_master *master)
47305 EXPORT_SYMBOL_GPL(spi_bus_unlock);
47306
47307 /* portable code must never pass more than 32 bytes */
47308-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
47309+#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
47310
47311 static u8 *buf;
47312
47313diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
47314index ee3a57f..18368c1 100644
47315--- a/drivers/staging/android/timed_output.c
47316+++ b/drivers/staging/android/timed_output.c
47317@@ -25,7 +25,7 @@
47318 #include "timed_output.h"
47319
47320 static struct class *timed_output_class;
47321-static atomic_t device_count;
47322+static atomic_unchecked_t device_count;
47323
47324 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
47325 char *buf)
47326@@ -59,7 +59,7 @@ static int create_timed_output_class(void)
47327 timed_output_class = class_create(THIS_MODULE, "timed_output");
47328 if (IS_ERR(timed_output_class))
47329 return PTR_ERR(timed_output_class);
47330- atomic_set(&device_count, 0);
47331+ atomic_set_unchecked(&device_count, 0);
47332 }
47333
47334 return 0;
47335@@ -76,7 +76,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
47336 if (ret < 0)
47337 return ret;
47338
47339- tdev->index = atomic_inc_return(&device_count);
47340+ tdev->index = atomic_inc_return_unchecked(&device_count);
47341 tdev->dev = device_create(timed_output_class, NULL,
47342 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
47343 if (IS_ERR(tdev->dev))
47344diff --git a/drivers/staging/media/solo6x10/solo6x10-core.c b/drivers/staging/media/solo6x10/solo6x10-core.c
47345index 3675020..e80d92c 100644
47346--- a/drivers/staging/media/solo6x10/solo6x10-core.c
47347+++ b/drivers/staging/media/solo6x10/solo6x10-core.c
47348@@ -434,7 +434,7 @@ static void solo_device_release(struct device *dev)
47349
47350 static int solo_sysfs_init(struct solo_dev *solo_dev)
47351 {
47352- struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
47353+ bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
47354 struct device *dev = &solo_dev->dev;
47355 const char *driver;
47356 int i;
47357diff --git a/drivers/staging/media/solo6x10/solo6x10-p2m.c b/drivers/staging/media/solo6x10/solo6x10-p2m.c
47358index 3335941..2b26186 100644
47359--- a/drivers/staging/media/solo6x10/solo6x10-p2m.c
47360+++ b/drivers/staging/media/solo6x10/solo6x10-p2m.c
47361@@ -77,7 +77,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
47362
47363 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
47364 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
47365- p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
47366+ p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
47367 if (p2m_id < 0)
47368 p2m_id = -p2m_id;
47369 }
47370diff --git a/drivers/staging/media/solo6x10/solo6x10.h b/drivers/staging/media/solo6x10/solo6x10.h
47371index 6f91d2e..3f011d2 100644
47372--- a/drivers/staging/media/solo6x10/solo6x10.h
47373+++ b/drivers/staging/media/solo6x10/solo6x10.h
47374@@ -238,7 +238,7 @@ struct solo_dev {
47375
47376 /* P2M DMA Engine */
47377 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
47378- atomic_t p2m_count;
47379+ atomic_unchecked_t p2m_count;
47380 int p2m_jiffies;
47381 unsigned int p2m_timeouts;
47382
47383diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
47384index 34afc16..ffe44dd 100644
47385--- a/drivers/staging/octeon/ethernet-rx.c
47386+++ b/drivers/staging/octeon/ethernet-rx.c
47387@@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
47388 /* Increment RX stats for virtual ports */
47389 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
47390 #ifdef CONFIG_64BIT
47391- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
47392- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
47393+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
47394+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
47395 #else
47396- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
47397- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
47398+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
47399+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
47400 #endif
47401 }
47402 netif_receive_skb(skb);
47403@@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
47404 dev->name);
47405 */
47406 #ifdef CONFIG_64BIT
47407- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
47408+ atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
47409 #else
47410- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
47411+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
47412 #endif
47413 dev_kfree_skb_irq(skb);
47414 }
47415diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
47416index c3a90e7..023619a 100644
47417--- a/drivers/staging/octeon/ethernet.c
47418+++ b/drivers/staging/octeon/ethernet.c
47419@@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
47420 * since the RX tasklet also increments it.
47421 */
47422 #ifdef CONFIG_64BIT
47423- atomic64_add(rx_status.dropped_packets,
47424- (atomic64_t *)&priv->stats.rx_dropped);
47425+ atomic64_add_unchecked(rx_status.dropped_packets,
47426+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
47427 #else
47428- atomic_add(rx_status.dropped_packets,
47429- (atomic_t *)&priv->stats.rx_dropped);
47430+ atomic_add_unchecked(rx_status.dropped_packets,
47431+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
47432 #endif
47433 }
47434
47435diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
47436index dc23395..cf7e9b1 100644
47437--- a/drivers/staging/rtl8712/rtl871x_io.h
47438+++ b/drivers/staging/rtl8712/rtl871x_io.h
47439@@ -108,7 +108,7 @@ struct _io_ops {
47440 u8 *pmem);
47441 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
47442 u8 *pmem);
47443-};
47444+} __no_const;
47445
47446 struct io_req {
47447 struct list_head list;
47448diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
47449index 1f5088b..0e59820 100644
47450--- a/drivers/staging/sbe-2t3e3/netdev.c
47451+++ b/drivers/staging/sbe-2t3e3/netdev.c
47452@@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
47453 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
47454
47455 if (rlen)
47456- if (copy_to_user(data, &resp, rlen))
47457+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
47458 return -EFAULT;
47459
47460 return 0;
47461diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
47462index a863a98..d272795 100644
47463--- a/drivers/staging/usbip/vhci.h
47464+++ b/drivers/staging/usbip/vhci.h
47465@@ -83,7 +83,7 @@ struct vhci_hcd {
47466 unsigned resuming:1;
47467 unsigned long re_timeout;
47468
47469- atomic_t seqnum;
47470+ atomic_unchecked_t seqnum;
47471
47472 /*
47473 * NOTE:
47474diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
47475index d7974cb..d78076b 100644
47476--- a/drivers/staging/usbip/vhci_hcd.c
47477+++ b/drivers/staging/usbip/vhci_hcd.c
47478@@ -441,7 +441,7 @@ static void vhci_tx_urb(struct urb *urb)
47479
47480 spin_lock(&vdev->priv_lock);
47481
47482- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
47483+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
47484 if (priv->seqnum == 0xffff)
47485 dev_info(&urb->dev->dev, "seqnum max\n");
47486
47487@@ -687,7 +687,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
47488 return -ENOMEM;
47489 }
47490
47491- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
47492+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
47493 if (unlink->seqnum == 0xffff)
47494 pr_info("seqnum max\n");
47495
47496@@ -891,7 +891,7 @@ static int vhci_start(struct usb_hcd *hcd)
47497 vdev->rhport = rhport;
47498 }
47499
47500- atomic_set(&vhci->seqnum, 0);
47501+ atomic_set_unchecked(&vhci->seqnum, 0);
47502 spin_lock_init(&vhci->lock);
47503
47504 hcd->power_budget = 0; /* no limit */
47505diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
47506index d07fcb5..358e1e1 100644
47507--- a/drivers/staging/usbip/vhci_rx.c
47508+++ b/drivers/staging/usbip/vhci_rx.c
47509@@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
47510 if (!urb) {
47511 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
47512 pr_info("max seqnum %d\n",
47513- atomic_read(&the_controller->seqnum));
47514+ atomic_read_unchecked(&the_controller->seqnum));
47515 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
47516 return;
47517 }
47518diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
47519index 57a08c5..5b4bb7c 100644
47520--- a/drivers/staging/vt6655/hostap.c
47521+++ b/drivers/staging/vt6655/hostap.c
47522@@ -69,14 +69,13 @@ static int msglevel = MSG_LEVEL_INFO;
47523 *
47524 */
47525
47526+static net_device_ops_no_const apdev_netdev_ops;
47527+
47528 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
47529 {
47530 PSDevice apdev_priv;
47531 struct net_device *dev = pDevice->dev;
47532 int ret;
47533- const struct net_device_ops apdev_netdev_ops = {
47534- .ndo_start_xmit = pDevice->tx_80211,
47535- };
47536
47537 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
47538
47539@@ -88,6 +87,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
47540 *apdev_priv = *pDevice;
47541 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
47542
47543+ /* only half broken now */
47544+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
47545 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
47546
47547 pDevice->apdev->type = ARPHRD_IEEE80211;
47548diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
47549index c699a30..b90a5fd 100644
47550--- a/drivers/staging/vt6656/hostap.c
47551+++ b/drivers/staging/vt6656/hostap.c
47552@@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
47553 *
47554 */
47555
47556+static net_device_ops_no_const apdev_netdev_ops;
47557+
47558 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
47559 {
47560 struct vnt_private *apdev_priv;
47561 struct net_device *dev = pDevice->dev;
47562 int ret;
47563- const struct net_device_ops apdev_netdev_ops = {
47564- .ndo_start_xmit = pDevice->tx_80211,
47565- };
47566
47567 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
47568
47569@@ -79,6 +78,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
47570 *apdev_priv = *pDevice;
47571 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
47572
47573+ /* only half broken now */
47574+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
47575 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
47576
47577 pDevice->apdev->type = ARPHRD_IEEE80211;
47578diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
47579index d128ce2..fc1f9a1 100644
47580--- a/drivers/staging/zcache/tmem.h
47581+++ b/drivers/staging/zcache/tmem.h
47582@@ -225,7 +225,7 @@ struct tmem_pamops {
47583 bool (*is_remote)(void *);
47584 int (*replace_in_obj)(void *, struct tmem_obj *);
47585 #endif
47586-};
47587+} __no_const;
47588 extern void tmem_register_pamops(struct tmem_pamops *m);
47589
47590 /* memory allocation methods provided by the host implementation */
47591@@ -234,7 +234,7 @@ struct tmem_hostops {
47592 void (*obj_free)(struct tmem_obj *, struct tmem_pool *);
47593 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
47594 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
47595-};
47596+} __no_const;
47597 extern void tmem_register_hostops(struct tmem_hostops *m);
47598
47599 /* core tmem accessor functions */
47600diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
47601index e51b09a..5ebac31 100644
47602--- a/drivers/target/sbp/sbp_target.c
47603+++ b/drivers/target/sbp/sbp_target.c
47604@@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
47605
47606 #define SESSION_MAINTENANCE_INTERVAL HZ
47607
47608-static atomic_t login_id = ATOMIC_INIT(0);
47609+static atomic_unchecked_t login_id = ATOMIC_INIT(0);
47610
47611 static void session_maintenance_work(struct work_struct *);
47612 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
47613@@ -444,7 +444,7 @@ static void sbp_management_request_login(
47614 login->lun = se_lun;
47615 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
47616 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
47617- login->login_id = atomic_inc_return(&login_id);
47618+ login->login_id = atomic_inc_return_unchecked(&login_id);
47619
47620 login->tgt_agt = sbp_target_agent_register(login);
47621 if (IS_ERR(login->tgt_agt)) {
47622diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
47623index 8f4142f..b127f7d 100644
47624--- a/drivers/target/target_core_device.c
47625+++ b/drivers/target/target_core_device.c
47626@@ -1400,7 +1400,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
47627 spin_lock_init(&dev->se_port_lock);
47628 spin_lock_init(&dev->se_tmr_lock);
47629 spin_lock_init(&dev->qf_cmd_lock);
47630- atomic_set(&dev->dev_ordered_id, 0);
47631+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
47632 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
47633 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
47634 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
47635diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
47636index d8e49d7..6fcfdec 100644
47637--- a/drivers/target/target_core_transport.c
47638+++ b/drivers/target/target_core_transport.c
47639@@ -1080,7 +1080,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
47640 * Used to determine when ORDERED commands should go from
47641 * Dormant to Active status.
47642 */
47643- cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
47644+ cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
47645 smp_mb__after_atomic_inc();
47646 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
47647 cmd->se_ordered_id, cmd->sam_task_attr,
47648diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
47649index 33f83fe..d80f8e1 100644
47650--- a/drivers/tty/cyclades.c
47651+++ b/drivers/tty/cyclades.c
47652@@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
47653 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
47654 info->port.count);
47655 #endif
47656- info->port.count++;
47657+ atomic_inc(&info->port.count);
47658 #ifdef CY_DEBUG_COUNT
47659 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
47660- current->pid, info->port.count);
47661+ current->pid, atomic_read(&info->port.count));
47662 #endif
47663
47664 /*
47665@@ -3972,7 +3972,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
47666 for (j = 0; j < cy_card[i].nports; j++) {
47667 info = &cy_card[i].ports[j];
47668
47669- if (info->port.count) {
47670+ if (atomic_read(&info->port.count)) {
47671 /* XXX is the ldisc num worth this? */
47672 struct tty_struct *tty;
47673 struct tty_ldisc *ld;
47674diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
47675index eb255e8..f637a57 100644
47676--- a/drivers/tty/hvc/hvc_console.c
47677+++ b/drivers/tty/hvc/hvc_console.c
47678@@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
47679
47680 spin_lock_irqsave(&hp->port.lock, flags);
47681 /* Check and then increment for fast path open. */
47682- if (hp->port.count++ > 0) {
47683+ if (atomic_inc_return(&hp->port.count) > 1) {
47684 spin_unlock_irqrestore(&hp->port.lock, flags);
47685 hvc_kick();
47686 return 0;
47687@@ -388,7 +388,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
47688
47689 spin_lock_irqsave(&hp->port.lock, flags);
47690
47691- if (--hp->port.count == 0) {
47692+ if (atomic_dec_return(&hp->port.count) == 0) {
47693 spin_unlock_irqrestore(&hp->port.lock, flags);
47694 /* We are done with the tty pointer now. */
47695 tty_port_tty_set(&hp->port, NULL);
47696@@ -406,9 +406,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
47697 */
47698 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
47699 } else {
47700- if (hp->port.count < 0)
47701+ if (atomic_read(&hp->port.count) < 0)
47702 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
47703- hp->vtermno, hp->port.count);
47704+ hp->vtermno, atomic_read(&hp->port.count));
47705 spin_unlock_irqrestore(&hp->port.lock, flags);
47706 }
47707 }
47708@@ -438,12 +438,12 @@ static void hvc_hangup(struct tty_struct *tty)
47709 * open->hangup case this can be called after the final close so prevent
47710 * that from happening for now.
47711 */
47712- if (hp->port.count <= 0) {
47713+ if (atomic_read(&hp->port.count) <= 0) {
47714 spin_unlock_irqrestore(&hp->port.lock, flags);
47715 return;
47716 }
47717
47718- hp->port.count = 0;
47719+ atomic_set(&hp->port.count, 0);
47720 spin_unlock_irqrestore(&hp->port.lock, flags);
47721 tty_port_tty_set(&hp->port, NULL);
47722
47723@@ -491,7 +491,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
47724 return -EPIPE;
47725
47726 /* FIXME what's this (unprotected) check for? */
47727- if (hp->port.count <= 0)
47728+ if (atomic_read(&hp->port.count) <= 0)
47729 return -EIO;
47730
47731 spin_lock_irqsave(&hp->lock, flags);
47732diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
47733index 81e939e..95ead10 100644
47734--- a/drivers/tty/hvc/hvcs.c
47735+++ b/drivers/tty/hvc/hvcs.c
47736@@ -83,6 +83,7 @@
47737 #include <asm/hvcserver.h>
47738 #include <asm/uaccess.h>
47739 #include <asm/vio.h>
47740+#include <asm/local.h>
47741
47742 /*
47743 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
47744@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
47745
47746 spin_lock_irqsave(&hvcsd->lock, flags);
47747
47748- if (hvcsd->port.count > 0) {
47749+ if (atomic_read(&hvcsd->port.count) > 0) {
47750 spin_unlock_irqrestore(&hvcsd->lock, flags);
47751 printk(KERN_INFO "HVCS: vterm state unchanged. "
47752 "The hvcs device node is still in use.\n");
47753@@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
47754 }
47755 }
47756
47757- hvcsd->port.count = 0;
47758+ atomic_set(&hvcsd->port.count, 0);
47759 hvcsd->port.tty = tty;
47760 tty->driver_data = hvcsd;
47761
47762@@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
47763 unsigned long flags;
47764
47765 spin_lock_irqsave(&hvcsd->lock, flags);
47766- hvcsd->port.count++;
47767+ atomic_inc(&hvcsd->port.count);
47768 hvcsd->todo_mask |= HVCS_SCHED_READ;
47769 spin_unlock_irqrestore(&hvcsd->lock, flags);
47770
47771@@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
47772 hvcsd = tty->driver_data;
47773
47774 spin_lock_irqsave(&hvcsd->lock, flags);
47775- if (--hvcsd->port.count == 0) {
47776+ if (atomic_dec_and_test(&hvcsd->port.count)) {
47777
47778 vio_disable_interrupts(hvcsd->vdev);
47779
47780@@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
47781
47782 free_irq(irq, hvcsd);
47783 return;
47784- } else if (hvcsd->port.count < 0) {
47785+ } else if (atomic_read(&hvcsd->port.count) < 0) {
47786 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
47787 " is missmanaged.\n",
47788- hvcsd->vdev->unit_address, hvcsd->port.count);
47789+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
47790 }
47791
47792 spin_unlock_irqrestore(&hvcsd->lock, flags);
47793@@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
47794
47795 spin_lock_irqsave(&hvcsd->lock, flags);
47796 /* Preserve this so that we know how many kref refs to put */
47797- temp_open_count = hvcsd->port.count;
47798+ temp_open_count = atomic_read(&hvcsd->port.count);
47799
47800 /*
47801 * Don't kref put inside the spinlock because the destruction
47802@@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
47803 tty->driver_data = NULL;
47804 hvcsd->port.tty = NULL;
47805
47806- hvcsd->port.count = 0;
47807+ atomic_set(&hvcsd->port.count, 0);
47808
47809 /* This will drop any buffered data on the floor which is OK in a hangup
47810 * scenario. */
47811@@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
47812 * the middle of a write operation? This is a crummy place to do this
47813 * but we want to keep it all in the spinlock.
47814 */
47815- if (hvcsd->port.count <= 0) {
47816+ if (atomic_read(&hvcsd->port.count) <= 0) {
47817 spin_unlock_irqrestore(&hvcsd->lock, flags);
47818 return -ENODEV;
47819 }
47820@@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
47821 {
47822 struct hvcs_struct *hvcsd = tty->driver_data;
47823
47824- if (!hvcsd || hvcsd->port.count <= 0)
47825+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
47826 return 0;
47827
47828 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
47829diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
47830index 4190199..48f2920 100644
47831--- a/drivers/tty/hvc/hvsi.c
47832+++ b/drivers/tty/hvc/hvsi.c
47833@@ -85,7 +85,7 @@ struct hvsi_struct {
47834 int n_outbuf;
47835 uint32_t vtermno;
47836 uint32_t virq;
47837- atomic_t seqno; /* HVSI packet sequence number */
47838+ atomic_unchecked_t seqno; /* HVSI packet sequence number */
47839 uint16_t mctrl;
47840 uint8_t state; /* HVSI protocol state */
47841 uint8_t flags;
47842@@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
47843
47844 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
47845 packet.hdr.len = sizeof(struct hvsi_query_response);
47846- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47847+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47848 packet.verb = VSV_SEND_VERSION_NUMBER;
47849 packet.u.version = HVSI_VERSION;
47850 packet.query_seqno = query_seqno+1;
47851@@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
47852
47853 packet.hdr.type = VS_QUERY_PACKET_HEADER;
47854 packet.hdr.len = sizeof(struct hvsi_query);
47855- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47856+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47857 packet.verb = verb;
47858
47859 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
47860@@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
47861 int wrote;
47862
47863 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
47864- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47865+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47866 packet.hdr.len = sizeof(struct hvsi_control);
47867 packet.verb = VSV_SET_MODEM_CTL;
47868 packet.mask = HVSI_TSDTR;
47869@@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
47870 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
47871
47872 packet.hdr.type = VS_DATA_PACKET_HEADER;
47873- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47874+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47875 packet.hdr.len = count + sizeof(struct hvsi_header);
47876 memcpy(&packet.data, buf, count);
47877
47878@@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
47879 struct hvsi_control packet __ALIGNED__;
47880
47881 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
47882- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47883+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47884 packet.hdr.len = 6;
47885 packet.verb = VSV_CLOSE_PROTOCOL;
47886
47887diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
47888index ac27671..0f627ee 100644
47889--- a/drivers/tty/hvc/hvsi_lib.c
47890+++ b/drivers/tty/hvc/hvsi_lib.c
47891@@ -9,7 +9,7 @@
47892
47893 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
47894 {
47895- packet->seqno = atomic_inc_return(&pv->seqno);
47896+ packet->seqno = atomic_inc_return_unchecked(&pv->seqno);
47897
47898 /* Assumes that always succeeds, works in practice */
47899 return pv->put_chars(pv->termno, (char *)packet, packet->len);
47900@@ -21,7 +21,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
47901
47902 /* Reset state */
47903 pv->established = 0;
47904- atomic_set(&pv->seqno, 0);
47905+ atomic_set_unchecked(&pv->seqno, 0);
47906
47907 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
47908
47909@@ -265,7 +265,7 @@ int hvsilib_read_mctrl(struct hvsi_priv *pv)
47910 pv->mctrl_update = 0;
47911 q.hdr.type = VS_QUERY_PACKET_HEADER;
47912 q.hdr.len = sizeof(struct hvsi_query);
47913- q.hdr.seqno = atomic_inc_return(&pv->seqno);
47914+ q.hdr.seqno = atomic_inc_return_unchecked(&pv->seqno);
47915 q.verb = VSV_SEND_MODEM_CTL_STATUS;
47916 rc = hvsi_send_packet(pv, &q.hdr);
47917 if (rc <= 0) {
47918diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
47919index 8fd72ff..34a0bed 100644
47920--- a/drivers/tty/ipwireless/tty.c
47921+++ b/drivers/tty/ipwireless/tty.c
47922@@ -29,6 +29,7 @@
47923 #include <linux/tty_driver.h>
47924 #include <linux/tty_flip.h>
47925 #include <linux/uaccess.h>
47926+#include <asm/local.h>
47927
47928 #include "tty.h"
47929 #include "network.h"
47930@@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
47931 mutex_unlock(&tty->ipw_tty_mutex);
47932 return -ENODEV;
47933 }
47934- if (tty->port.count == 0)
47935+ if (atomic_read(&tty->port.count) == 0)
47936 tty->tx_bytes_queued = 0;
47937
47938- tty->port.count++;
47939+ atomic_inc(&tty->port.count);
47940
47941 tty->port.tty = linux_tty;
47942 linux_tty->driver_data = tty;
47943@@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
47944
47945 static void do_ipw_close(struct ipw_tty *tty)
47946 {
47947- tty->port.count--;
47948-
47949- if (tty->port.count == 0) {
47950+ if (atomic_dec_return(&tty->port.count) == 0) {
47951 struct tty_struct *linux_tty = tty->port.tty;
47952
47953 if (linux_tty != NULL) {
47954@@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
47955 return;
47956
47957 mutex_lock(&tty->ipw_tty_mutex);
47958- if (tty->port.count == 0) {
47959+ if (atomic_read(&tty->port.count) == 0) {
47960 mutex_unlock(&tty->ipw_tty_mutex);
47961 return;
47962 }
47963@@ -164,7 +163,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
47964
47965 mutex_lock(&tty->ipw_tty_mutex);
47966
47967- if (!tty->port.count) {
47968+ if (!atomic_read(&tty->port.count)) {
47969 mutex_unlock(&tty->ipw_tty_mutex);
47970 return;
47971 }
47972@@ -206,7 +205,7 @@ static int ipw_write(struct tty_struct *linux_tty,
47973 return -ENODEV;
47974
47975 mutex_lock(&tty->ipw_tty_mutex);
47976- if (!tty->port.count) {
47977+ if (!atomic_read(&tty->port.count)) {
47978 mutex_unlock(&tty->ipw_tty_mutex);
47979 return -EINVAL;
47980 }
47981@@ -246,7 +245,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
47982 if (!tty)
47983 return -ENODEV;
47984
47985- if (!tty->port.count)
47986+ if (!atomic_read(&tty->port.count))
47987 return -EINVAL;
47988
47989 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
47990@@ -288,7 +287,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
47991 if (!tty)
47992 return 0;
47993
47994- if (!tty->port.count)
47995+ if (!atomic_read(&tty->port.count))
47996 return 0;
47997
47998 return tty->tx_bytes_queued;
47999@@ -369,7 +368,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
48000 if (!tty)
48001 return -ENODEV;
48002
48003- if (!tty->port.count)
48004+ if (!atomic_read(&tty->port.count))
48005 return -EINVAL;
48006
48007 return get_control_lines(tty);
48008@@ -385,7 +384,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
48009 if (!tty)
48010 return -ENODEV;
48011
48012- if (!tty->port.count)
48013+ if (!atomic_read(&tty->port.count))
48014 return -EINVAL;
48015
48016 return set_control_lines(tty, set, clear);
48017@@ -399,7 +398,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
48018 if (!tty)
48019 return -ENODEV;
48020
48021- if (!tty->port.count)
48022+ if (!atomic_read(&tty->port.count))
48023 return -EINVAL;
48024
48025 /* FIXME: Exactly how is the tty object locked here .. */
48026@@ -555,7 +554,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
48027 * are gone */
48028 mutex_lock(&ttyj->ipw_tty_mutex);
48029 }
48030- while (ttyj->port.count)
48031+ while (atomic_read(&ttyj->port.count))
48032 do_ipw_close(ttyj);
48033 ipwireless_disassociate_network_ttys(network,
48034 ttyj->channel_idx);
48035diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
48036index 1deaca4..c8582d4 100644
48037--- a/drivers/tty/moxa.c
48038+++ b/drivers/tty/moxa.c
48039@@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
48040 }
48041
48042 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
48043- ch->port.count++;
48044+ atomic_inc(&ch->port.count);
48045 tty->driver_data = ch;
48046 tty_port_tty_set(&ch->port, tty);
48047 mutex_lock(&ch->port.mutex);
48048diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
48049index 6422390..49003ac8 100644
48050--- a/drivers/tty/n_gsm.c
48051+++ b/drivers/tty/n_gsm.c
48052@@ -1632,7 +1632,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
48053 spin_lock_init(&dlci->lock);
48054 mutex_init(&dlci->mutex);
48055 dlci->fifo = &dlci->_fifo;
48056- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
48057+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
48058 kfree(dlci);
48059 return NULL;
48060 }
48061@@ -2932,7 +2932,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
48062 struct gsm_dlci *dlci = tty->driver_data;
48063 struct tty_port *port = &dlci->port;
48064
48065- port->count++;
48066+ atomic_inc(&port->count);
48067 dlci_get(dlci);
48068 dlci_get(dlci->gsm->dlci[0]);
48069 mux_get(dlci->gsm);
48070diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
48071index 4bf0fc0..433bd58 100644
48072--- a/drivers/tty/n_tty.c
48073+++ b/drivers/tty/n_tty.c
48074@@ -2217,6 +2217,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
48075 {
48076 *ops = tty_ldisc_N_TTY;
48077 ops->owner = NULL;
48078- ops->refcount = ops->flags = 0;
48079+ atomic_set(&ops->refcount, 0);
48080+ ops->flags = 0;
48081 }
48082 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
48083diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
48084index abfd990..5ab5da9 100644
48085--- a/drivers/tty/pty.c
48086+++ b/drivers/tty/pty.c
48087@@ -796,8 +796,10 @@ static void __init unix98_pty_init(void)
48088 panic("Couldn't register Unix98 pts driver");
48089
48090 /* Now create the /dev/ptmx special device */
48091+ pax_open_kernel();
48092 tty_default_fops(&ptmx_fops);
48093- ptmx_fops.open = ptmx_open;
48094+ *(void **)&ptmx_fops.open = ptmx_open;
48095+ pax_close_kernel();
48096
48097 cdev_init(&ptmx_cdev, &ptmx_fops);
48098 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
48099diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
48100index 354564e..fe50d9a 100644
48101--- a/drivers/tty/rocket.c
48102+++ b/drivers/tty/rocket.c
48103@@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
48104 tty->driver_data = info;
48105 tty_port_tty_set(port, tty);
48106
48107- if (port->count++ == 0) {
48108+ if (atomic_inc_return(&port->count) == 1) {
48109 atomic_inc(&rp_num_ports_open);
48110
48111 #ifdef ROCKET_DEBUG_OPEN
48112@@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
48113 #endif
48114 }
48115 #ifdef ROCKET_DEBUG_OPEN
48116- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
48117+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
48118 #endif
48119
48120 /*
48121@@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
48122 spin_unlock_irqrestore(&info->port.lock, flags);
48123 return;
48124 }
48125- if (info->port.count)
48126+ if (atomic_read(&info->port.count))
48127 atomic_dec(&rp_num_ports_open);
48128 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
48129 spin_unlock_irqrestore(&info->port.lock, flags);
48130diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
48131index e2520ab..034e20b 100644
48132--- a/drivers/tty/serial/ioc4_serial.c
48133+++ b/drivers/tty/serial/ioc4_serial.c
48134@@ -437,7 +437,7 @@ struct ioc4_soft {
48135 } is_intr_info[MAX_IOC4_INTR_ENTS];
48136
48137 /* Number of entries active in the above array */
48138- atomic_t is_num_intrs;
48139+ atomic_unchecked_t is_num_intrs;
48140 } is_intr_type[IOC4_NUM_INTR_TYPES];
48141
48142 /* is_ir_lock must be held while
48143@@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
48144 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
48145 || (type == IOC4_OTHER_INTR_TYPE)));
48146
48147- i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
48148+ i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
48149 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
48150
48151 /* Save off the lower level interrupt handler */
48152@@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
48153
48154 soft = arg;
48155 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
48156- num_intrs = (int)atomic_read(
48157+ num_intrs = (int)atomic_read_unchecked(
48158 &soft->is_intr_type[intr_type].is_num_intrs);
48159
48160 this_mir = this_ir = pending_intrs(soft, intr_type);
48161diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
48162index 1002054..dd644a8 100644
48163--- a/drivers/tty/serial/kgdboc.c
48164+++ b/drivers/tty/serial/kgdboc.c
48165@@ -24,8 +24,9 @@
48166 #define MAX_CONFIG_LEN 40
48167
48168 static struct kgdb_io kgdboc_io_ops;
48169+static struct kgdb_io kgdboc_io_ops_console;
48170
48171-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
48172+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
48173 static int configured = -1;
48174
48175 static char config[MAX_CONFIG_LEN];
48176@@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
48177 kgdboc_unregister_kbd();
48178 if (configured == 1)
48179 kgdb_unregister_io_module(&kgdboc_io_ops);
48180+ else if (configured == 2)
48181+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
48182 }
48183
48184 static int configure_kgdboc(void)
48185@@ -160,13 +163,13 @@ static int configure_kgdboc(void)
48186 int err;
48187 char *cptr = config;
48188 struct console *cons;
48189+ int is_console = 0;
48190
48191 err = kgdboc_option_setup(config);
48192 if (err || !strlen(config) || isspace(config[0]))
48193 goto noconfig;
48194
48195 err = -ENODEV;
48196- kgdboc_io_ops.is_console = 0;
48197 kgdb_tty_driver = NULL;
48198
48199 kgdboc_use_kms = 0;
48200@@ -187,7 +190,7 @@ static int configure_kgdboc(void)
48201 int idx;
48202 if (cons->device && cons->device(cons, &idx) == p &&
48203 idx == tty_line) {
48204- kgdboc_io_ops.is_console = 1;
48205+ is_console = 1;
48206 break;
48207 }
48208 cons = cons->next;
48209@@ -197,7 +200,13 @@ static int configure_kgdboc(void)
48210 kgdb_tty_line = tty_line;
48211
48212 do_register:
48213- err = kgdb_register_io_module(&kgdboc_io_ops);
48214+ if (is_console) {
48215+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
48216+ configured = 2;
48217+ } else {
48218+ err = kgdb_register_io_module(&kgdboc_io_ops);
48219+ configured = 1;
48220+ }
48221 if (err)
48222 goto noconfig;
48223
48224@@ -205,8 +214,6 @@ do_register:
48225 if (err)
48226 goto nmi_con_failed;
48227
48228- configured = 1;
48229-
48230 return 0;
48231
48232 nmi_con_failed:
48233@@ -223,7 +230,7 @@ noconfig:
48234 static int __init init_kgdboc(void)
48235 {
48236 /* Already configured? */
48237- if (configured == 1)
48238+ if (configured >= 1)
48239 return 0;
48240
48241 return configure_kgdboc();
48242@@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
48243 if (config[len - 1] == '\n')
48244 config[len - 1] = '\0';
48245
48246- if (configured == 1)
48247+ if (configured >= 1)
48248 cleanup_kgdboc();
48249
48250 /* Go and configure with the new params. */
48251@@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
48252 .post_exception = kgdboc_post_exp_handler,
48253 };
48254
48255+static struct kgdb_io kgdboc_io_ops_console = {
48256+ .name = "kgdboc",
48257+ .read_char = kgdboc_get_char,
48258+ .write_char = kgdboc_put_char,
48259+ .pre_exception = kgdboc_pre_exp_handler,
48260+ .post_exception = kgdboc_post_exp_handler,
48261+ .is_console = 1
48262+};
48263+
48264 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
48265 /* This is only available if kgdboc is a built in for early debugging */
48266 static int __init kgdboc_early_init(char *opt)
48267diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
48268index 2c6cfb3..048274e 100644
48269--- a/drivers/tty/serial/msm_serial.c
48270+++ b/drivers/tty/serial/msm_serial.c
48271@@ -857,7 +857,7 @@ static struct uart_driver msm_uart_driver = {
48272 .cons = MSM_CONSOLE,
48273 };
48274
48275-static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
48276+static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
48277
48278 static int __init msm_serial_probe(struct platform_device *pdev)
48279 {
48280@@ -867,7 +867,7 @@ static int __init msm_serial_probe(struct platform_device *pdev)
48281 int irq;
48282
48283 if (pdev->id == -1)
48284- pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
48285+ pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
48286
48287 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
48288 return -ENXIO;
48289diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
48290index 376079b..d8de7aa 100644
48291--- a/drivers/tty/serial/samsung.c
48292+++ b/drivers/tty/serial/samsung.c
48293@@ -453,11 +453,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
48294 }
48295 }
48296
48297+static int s3c64xx_serial_startup(struct uart_port *port);
48298 static int s3c24xx_serial_startup(struct uart_port *port)
48299 {
48300 struct s3c24xx_uart_port *ourport = to_ourport(port);
48301 int ret;
48302
48303+ /* Startup sequence is different for s3c64xx and higher SoC's */
48304+ if (s3c24xx_serial_has_interrupt_mask(port))
48305+ return s3c64xx_serial_startup(port);
48306+
48307 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
48308 port->mapbase, port->membase);
48309
48310@@ -1124,10 +1129,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
48311 /* setup info for port */
48312 port->dev = &platdev->dev;
48313
48314- /* Startup sequence is different for s3c64xx and higher SoC's */
48315- if (s3c24xx_serial_has_interrupt_mask(port))
48316- s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
48317-
48318 port->uartclk = 1;
48319
48320 if (cfg->uart_flags & UPF_CONS_FLOW) {
48321diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
48322index 28cdd28..56f1d60 100644
48323--- a/drivers/tty/serial/serial_core.c
48324+++ b/drivers/tty/serial/serial_core.c
48325@@ -1448,7 +1448,7 @@ static void uart_hangup(struct tty_struct *tty)
48326 uart_flush_buffer(tty);
48327 uart_shutdown(tty, state);
48328 spin_lock_irqsave(&port->lock, flags);
48329- port->count = 0;
48330+ atomic_set(&port->count, 0);
48331 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
48332 spin_unlock_irqrestore(&port->lock, flags);
48333 tty_port_tty_set(port, NULL);
48334@@ -1544,7 +1544,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
48335 goto end;
48336 }
48337
48338- port->count++;
48339+ atomic_inc(&port->count);
48340 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
48341 retval = -ENXIO;
48342 goto err_dec_count;
48343@@ -1572,7 +1572,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
48344 /*
48345 * Make sure the device is in D0 state.
48346 */
48347- if (port->count == 1)
48348+ if (atomic_read(&port->count) == 1)
48349 uart_change_pm(state, UART_PM_STATE_ON);
48350
48351 /*
48352@@ -1590,7 +1590,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
48353 end:
48354 return retval;
48355 err_dec_count:
48356- port->count--;
48357+ atomic_inc(&port->count);
48358 mutex_unlock(&port->mutex);
48359 goto end;
48360 }
48361diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
48362index 8eaf1ab..85c030d 100644
48363--- a/drivers/tty/synclink.c
48364+++ b/drivers/tty/synclink.c
48365@@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
48366
48367 if (debug_level >= DEBUG_LEVEL_INFO)
48368 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
48369- __FILE__,__LINE__, info->device_name, info->port.count);
48370+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
48371
48372 if (tty_port_close_start(&info->port, tty, filp) == 0)
48373 goto cleanup;
48374@@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
48375 cleanup:
48376 if (debug_level >= DEBUG_LEVEL_INFO)
48377 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
48378- tty->driver->name, info->port.count);
48379+ tty->driver->name, atomic_read(&info->port.count));
48380
48381 } /* end of mgsl_close() */
48382
48383@@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
48384
48385 mgsl_flush_buffer(tty);
48386 shutdown(info);
48387-
48388- info->port.count = 0;
48389+
48390+ atomic_set(&info->port.count, 0);
48391 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
48392 info->port.tty = NULL;
48393
48394@@ -3297,12 +3297,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
48395
48396 if (debug_level >= DEBUG_LEVEL_INFO)
48397 printk("%s(%d):block_til_ready before block on %s count=%d\n",
48398- __FILE__,__LINE__, tty->driver->name, port->count );
48399+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48400
48401 spin_lock_irqsave(&info->irq_spinlock, flags);
48402 if (!tty_hung_up_p(filp)) {
48403 extra_count = true;
48404- port->count--;
48405+ atomic_dec(&port->count);
48406 }
48407 spin_unlock_irqrestore(&info->irq_spinlock, flags);
48408 port->blocked_open++;
48409@@ -3331,7 +3331,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
48410
48411 if (debug_level >= DEBUG_LEVEL_INFO)
48412 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
48413- __FILE__,__LINE__, tty->driver->name, port->count );
48414+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48415
48416 tty_unlock(tty);
48417 schedule();
48418@@ -3343,12 +3343,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
48419
48420 /* FIXME: Racy on hangup during close wait */
48421 if (extra_count)
48422- port->count++;
48423+ atomic_inc(&port->count);
48424 port->blocked_open--;
48425
48426 if (debug_level >= DEBUG_LEVEL_INFO)
48427 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
48428- __FILE__,__LINE__, tty->driver->name, port->count );
48429+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48430
48431 if (!retval)
48432 port->flags |= ASYNC_NORMAL_ACTIVE;
48433@@ -3400,7 +3400,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
48434
48435 if (debug_level >= DEBUG_LEVEL_INFO)
48436 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
48437- __FILE__,__LINE__,tty->driver->name, info->port.count);
48438+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
48439
48440 /* If port is closing, signal caller to try again */
48441 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
48442@@ -3419,10 +3419,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
48443 spin_unlock_irqrestore(&info->netlock, flags);
48444 goto cleanup;
48445 }
48446- info->port.count++;
48447+ atomic_inc(&info->port.count);
48448 spin_unlock_irqrestore(&info->netlock, flags);
48449
48450- if (info->port.count == 1) {
48451+ if (atomic_read(&info->port.count) == 1) {
48452 /* 1st open on this device, init hardware */
48453 retval = startup(info);
48454 if (retval < 0)
48455@@ -3446,8 +3446,8 @@ cleanup:
48456 if (retval) {
48457 if (tty->count == 1)
48458 info->port.tty = NULL; /* tty layer will release tty struct */
48459- if(info->port.count)
48460- info->port.count--;
48461+ if (atomic_read(&info->port.count))
48462+ atomic_dec(&info->port.count);
48463 }
48464
48465 return retval;
48466@@ -7665,7 +7665,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
48467 unsigned short new_crctype;
48468
48469 /* return error if TTY interface open */
48470- if (info->port.count)
48471+ if (atomic_read(&info->port.count))
48472 return -EBUSY;
48473
48474 switch (encoding)
48475@@ -7760,7 +7760,7 @@ static int hdlcdev_open(struct net_device *dev)
48476
48477 /* arbitrate between network and tty opens */
48478 spin_lock_irqsave(&info->netlock, flags);
48479- if (info->port.count != 0 || info->netcount != 0) {
48480+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
48481 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
48482 spin_unlock_irqrestore(&info->netlock, flags);
48483 return -EBUSY;
48484@@ -7846,7 +7846,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48485 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
48486
48487 /* return error if TTY interface open */
48488- if (info->port.count)
48489+ if (atomic_read(&info->port.count))
48490 return -EBUSY;
48491
48492 if (cmd != SIOCWANDEV)
48493diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
48494index 1abf946..1ee34fc 100644
48495--- a/drivers/tty/synclink_gt.c
48496+++ b/drivers/tty/synclink_gt.c
48497@@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
48498 tty->driver_data = info;
48499 info->port.tty = tty;
48500
48501- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
48502+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
48503
48504 /* If port is closing, signal caller to try again */
48505 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
48506@@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
48507 mutex_unlock(&info->port.mutex);
48508 goto cleanup;
48509 }
48510- info->port.count++;
48511+ atomic_inc(&info->port.count);
48512 spin_unlock_irqrestore(&info->netlock, flags);
48513
48514- if (info->port.count == 1) {
48515+ if (atomic_read(&info->port.count) == 1) {
48516 /* 1st open on this device, init hardware */
48517 retval = startup(info);
48518 if (retval < 0) {
48519@@ -715,8 +715,8 @@ cleanup:
48520 if (retval) {
48521 if (tty->count == 1)
48522 info->port.tty = NULL; /* tty layer will release tty struct */
48523- if(info->port.count)
48524- info->port.count--;
48525+ if(atomic_read(&info->port.count))
48526+ atomic_dec(&info->port.count);
48527 }
48528
48529 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
48530@@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
48531
48532 if (sanity_check(info, tty->name, "close"))
48533 return;
48534- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
48535+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
48536
48537 if (tty_port_close_start(&info->port, tty, filp) == 0)
48538 goto cleanup;
48539@@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
48540 tty_port_close_end(&info->port, tty);
48541 info->port.tty = NULL;
48542 cleanup:
48543- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
48544+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
48545 }
48546
48547 static void hangup(struct tty_struct *tty)
48548@@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
48549 shutdown(info);
48550
48551 spin_lock_irqsave(&info->port.lock, flags);
48552- info->port.count = 0;
48553+ atomic_set(&info->port.count, 0);
48554 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
48555 info->port.tty = NULL;
48556 spin_unlock_irqrestore(&info->port.lock, flags);
48557@@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
48558 unsigned short new_crctype;
48559
48560 /* return error if TTY interface open */
48561- if (info->port.count)
48562+ if (atomic_read(&info->port.count))
48563 return -EBUSY;
48564
48565 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
48566@@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
48567
48568 /* arbitrate between network and tty opens */
48569 spin_lock_irqsave(&info->netlock, flags);
48570- if (info->port.count != 0 || info->netcount != 0) {
48571+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
48572 DBGINFO(("%s hdlc_open busy\n", dev->name));
48573 spin_unlock_irqrestore(&info->netlock, flags);
48574 return -EBUSY;
48575@@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48576 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
48577
48578 /* return error if TTY interface open */
48579- if (info->port.count)
48580+ if (atomic_read(&info->port.count))
48581 return -EBUSY;
48582
48583 if (cmd != SIOCWANDEV)
48584@@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
48585 if (port == NULL)
48586 continue;
48587 spin_lock(&port->lock);
48588- if ((port->port.count || port->netcount) &&
48589+ if ((atomic_read(&port->port.count) || port->netcount) &&
48590 port->pending_bh && !port->bh_running &&
48591 !port->bh_requested) {
48592 DBGISR(("%s bh queued\n", port->device_name));
48593@@ -3302,7 +3302,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48594 spin_lock_irqsave(&info->lock, flags);
48595 if (!tty_hung_up_p(filp)) {
48596 extra_count = true;
48597- port->count--;
48598+ atomic_dec(&port->count);
48599 }
48600 spin_unlock_irqrestore(&info->lock, flags);
48601 port->blocked_open++;
48602@@ -3339,7 +3339,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48603 remove_wait_queue(&port->open_wait, &wait);
48604
48605 if (extra_count)
48606- port->count++;
48607+ atomic_inc(&port->count);
48608 port->blocked_open--;
48609
48610 if (!retval)
48611diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
48612index dc6e969..5dc8786 100644
48613--- a/drivers/tty/synclinkmp.c
48614+++ b/drivers/tty/synclinkmp.c
48615@@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
48616
48617 if (debug_level >= DEBUG_LEVEL_INFO)
48618 printk("%s(%d):%s open(), old ref count = %d\n",
48619- __FILE__,__LINE__,tty->driver->name, info->port.count);
48620+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
48621
48622 /* If port is closing, signal caller to try again */
48623 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
48624@@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
48625 spin_unlock_irqrestore(&info->netlock, flags);
48626 goto cleanup;
48627 }
48628- info->port.count++;
48629+ atomic_inc(&info->port.count);
48630 spin_unlock_irqrestore(&info->netlock, flags);
48631
48632- if (info->port.count == 1) {
48633+ if (atomic_read(&info->port.count) == 1) {
48634 /* 1st open on this device, init hardware */
48635 retval = startup(info);
48636 if (retval < 0)
48637@@ -796,8 +796,8 @@ cleanup:
48638 if (retval) {
48639 if (tty->count == 1)
48640 info->port.tty = NULL; /* tty layer will release tty struct */
48641- if(info->port.count)
48642- info->port.count--;
48643+ if(atomic_read(&info->port.count))
48644+ atomic_dec(&info->port.count);
48645 }
48646
48647 return retval;
48648@@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
48649
48650 if (debug_level >= DEBUG_LEVEL_INFO)
48651 printk("%s(%d):%s close() entry, count=%d\n",
48652- __FILE__,__LINE__, info->device_name, info->port.count);
48653+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
48654
48655 if (tty_port_close_start(&info->port, tty, filp) == 0)
48656 goto cleanup;
48657@@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
48658 cleanup:
48659 if (debug_level >= DEBUG_LEVEL_INFO)
48660 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
48661- tty->driver->name, info->port.count);
48662+ tty->driver->name, atomic_read(&info->port.count));
48663 }
48664
48665 /* Called by tty_hangup() when a hangup is signaled.
48666@@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
48667 shutdown(info);
48668
48669 spin_lock_irqsave(&info->port.lock, flags);
48670- info->port.count = 0;
48671+ atomic_set(&info->port.count, 0);
48672 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
48673 info->port.tty = NULL;
48674 spin_unlock_irqrestore(&info->port.lock, flags);
48675@@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
48676 unsigned short new_crctype;
48677
48678 /* return error if TTY interface open */
48679- if (info->port.count)
48680+ if (atomic_read(&info->port.count))
48681 return -EBUSY;
48682
48683 switch (encoding)
48684@@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
48685
48686 /* arbitrate between network and tty opens */
48687 spin_lock_irqsave(&info->netlock, flags);
48688- if (info->port.count != 0 || info->netcount != 0) {
48689+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
48690 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
48691 spin_unlock_irqrestore(&info->netlock, flags);
48692 return -EBUSY;
48693@@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48694 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
48695
48696 /* return error if TTY interface open */
48697- if (info->port.count)
48698+ if (atomic_read(&info->port.count))
48699 return -EBUSY;
48700
48701 if (cmd != SIOCWANDEV)
48702@@ -2620,7 +2620,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
48703 * do not request bottom half processing if the
48704 * device is not open in a normal mode.
48705 */
48706- if ( port && (port->port.count || port->netcount) &&
48707+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
48708 port->pending_bh && !port->bh_running &&
48709 !port->bh_requested ) {
48710 if ( debug_level >= DEBUG_LEVEL_ISR )
48711@@ -3318,12 +3318,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48712
48713 if (debug_level >= DEBUG_LEVEL_INFO)
48714 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
48715- __FILE__,__LINE__, tty->driver->name, port->count );
48716+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48717
48718 spin_lock_irqsave(&info->lock, flags);
48719 if (!tty_hung_up_p(filp)) {
48720 extra_count = true;
48721- port->count--;
48722+ atomic_dec(&port->count);
48723 }
48724 spin_unlock_irqrestore(&info->lock, flags);
48725 port->blocked_open++;
48726@@ -3352,7 +3352,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48727
48728 if (debug_level >= DEBUG_LEVEL_INFO)
48729 printk("%s(%d):%s block_til_ready() count=%d\n",
48730- __FILE__,__LINE__, tty->driver->name, port->count );
48731+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48732
48733 tty_unlock(tty);
48734 schedule();
48735@@ -3363,12 +3363,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48736 remove_wait_queue(&port->open_wait, &wait);
48737
48738 if (extra_count)
48739- port->count++;
48740+ atomic_inc(&port->count);
48741 port->blocked_open--;
48742
48743 if (debug_level >= DEBUG_LEVEL_INFO)
48744 printk("%s(%d):%s block_til_ready() after, count=%d\n",
48745- __FILE__,__LINE__, tty->driver->name, port->count );
48746+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48747
48748 if (!retval)
48749 port->flags |= ASYNC_NORMAL_ACTIVE;
48750diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
48751index d5cc3ac..3263411 100644
48752--- a/drivers/tty/sysrq.c
48753+++ b/drivers/tty/sysrq.c
48754@@ -1033,7 +1033,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
48755 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
48756 size_t count, loff_t *ppos)
48757 {
48758- if (count) {
48759+ if (count && capable(CAP_SYS_ADMIN)) {
48760 char c;
48761
48762 if (get_user(c, buf))
48763diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
48764index 366af83..6db51c3 100644
48765--- a/drivers/tty/tty_io.c
48766+++ b/drivers/tty/tty_io.c
48767@@ -3467,7 +3467,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
48768
48769 void tty_default_fops(struct file_operations *fops)
48770 {
48771- *fops = tty_fops;
48772+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
48773 }
48774
48775 /*
48776diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
48777index 1afe192..73d2c20 100644
48778--- a/drivers/tty/tty_ldisc.c
48779+++ b/drivers/tty/tty_ldisc.c
48780@@ -66,7 +66,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
48781 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
48782 tty_ldiscs[disc] = new_ldisc;
48783 new_ldisc->num = disc;
48784- new_ldisc->refcount = 0;
48785+ atomic_set(&new_ldisc->refcount, 0);
48786 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
48787
48788 return ret;
48789@@ -94,7 +94,7 @@ int tty_unregister_ldisc(int disc)
48790 return -EINVAL;
48791
48792 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
48793- if (tty_ldiscs[disc]->refcount)
48794+ if (atomic_read(&tty_ldiscs[disc]->refcount))
48795 ret = -EBUSY;
48796 else
48797 tty_ldiscs[disc] = NULL;
48798@@ -115,7 +115,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
48799 if (ldops) {
48800 ret = ERR_PTR(-EAGAIN);
48801 if (try_module_get(ldops->owner)) {
48802- ldops->refcount++;
48803+ atomic_inc(&ldops->refcount);
48804 ret = ldops;
48805 }
48806 }
48807@@ -128,7 +128,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
48808 unsigned long flags;
48809
48810 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
48811- ldops->refcount--;
48812+ atomic_dec(&ldops->refcount);
48813 module_put(ldops->owner);
48814 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
48815 }
48816@@ -196,7 +196,7 @@ static inline void tty_ldisc_put(struct tty_ldisc *ld)
48817 /* unreleased reader reference(s) will cause this WARN */
48818 WARN_ON(!atomic_dec_and_test(&ld->users));
48819
48820- ld->ops->refcount--;
48821+ atomic_dec(&ld->ops->refcount);
48822 module_put(ld->ops->owner);
48823 kfree(ld);
48824 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
48825diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
48826index f597e88..b7f68ed 100644
48827--- a/drivers/tty/tty_port.c
48828+++ b/drivers/tty/tty_port.c
48829@@ -232,7 +232,7 @@ void tty_port_hangup(struct tty_port *port)
48830 unsigned long flags;
48831
48832 spin_lock_irqsave(&port->lock, flags);
48833- port->count = 0;
48834+ atomic_set(&port->count, 0);
48835 port->flags &= ~ASYNC_NORMAL_ACTIVE;
48836 tty = port->tty;
48837 if (tty)
48838@@ -390,7 +390,7 @@ int tty_port_block_til_ready(struct tty_port *port,
48839 /* The port lock protects the port counts */
48840 spin_lock_irqsave(&port->lock, flags);
48841 if (!tty_hung_up_p(filp))
48842- port->count--;
48843+ atomic_dec(&port->count);
48844 port->blocked_open++;
48845 spin_unlock_irqrestore(&port->lock, flags);
48846
48847@@ -432,7 +432,7 @@ int tty_port_block_til_ready(struct tty_port *port,
48848 we must not mess that up further */
48849 spin_lock_irqsave(&port->lock, flags);
48850 if (!tty_hung_up_p(filp))
48851- port->count++;
48852+ atomic_inc(&port->count);
48853 port->blocked_open--;
48854 if (retval == 0)
48855 port->flags |= ASYNC_NORMAL_ACTIVE;
48856@@ -466,19 +466,19 @@ int tty_port_close_start(struct tty_port *port,
48857 return 0;
48858 }
48859
48860- if (tty->count == 1 && port->count != 1) {
48861+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
48862 printk(KERN_WARNING
48863 "tty_port_close_start: tty->count = 1 port count = %d.\n",
48864- port->count);
48865- port->count = 1;
48866+ atomic_read(&port->count));
48867+ atomic_set(&port->count, 1);
48868 }
48869- if (--port->count < 0) {
48870+ if (atomic_dec_return(&port->count) < 0) {
48871 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
48872- port->count);
48873- port->count = 0;
48874+ atomic_read(&port->count));
48875+ atomic_set(&port->count, 0);
48876 }
48877
48878- if (port->count) {
48879+ if (atomic_read(&port->count)) {
48880 spin_unlock_irqrestore(&port->lock, flags);
48881 if (port->ops->drop)
48882 port->ops->drop(port);
48883@@ -564,7 +564,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
48884 {
48885 spin_lock_irq(&port->lock);
48886 if (!tty_hung_up_p(filp))
48887- ++port->count;
48888+ atomic_inc(&port->count);
48889 spin_unlock_irq(&port->lock);
48890 tty_port_tty_set(port, tty);
48891
48892diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
48893index a9af1b9a..1e08e7f 100644
48894--- a/drivers/tty/vt/keyboard.c
48895+++ b/drivers/tty/vt/keyboard.c
48896@@ -647,6 +647,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
48897 kbd->kbdmode == VC_OFF) &&
48898 value != KVAL(K_SAK))
48899 return; /* SAK is allowed even in raw mode */
48900+
48901+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48902+ {
48903+ void *func = fn_handler[value];
48904+ if (func == fn_show_state || func == fn_show_ptregs ||
48905+ func == fn_show_mem)
48906+ return;
48907+ }
48908+#endif
48909+
48910 fn_handler[value](vc);
48911 }
48912
48913@@ -1795,9 +1805,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
48914 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
48915 return -EFAULT;
48916
48917- if (!capable(CAP_SYS_TTY_CONFIG))
48918- perm = 0;
48919-
48920 switch (cmd) {
48921 case KDGKBENT:
48922 /* Ensure another thread doesn't free it under us */
48923@@ -1812,6 +1819,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
48924 spin_unlock_irqrestore(&kbd_event_lock, flags);
48925 return put_user(val, &user_kbe->kb_value);
48926 case KDSKBENT:
48927+ if (!capable(CAP_SYS_TTY_CONFIG))
48928+ perm = 0;
48929+
48930 if (!perm)
48931 return -EPERM;
48932 if (!i && v == K_NOSUCHMAP) {
48933@@ -1902,9 +1912,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
48934 int i, j, k;
48935 int ret;
48936
48937- if (!capable(CAP_SYS_TTY_CONFIG))
48938- perm = 0;
48939-
48940 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
48941 if (!kbs) {
48942 ret = -ENOMEM;
48943@@ -1938,6 +1945,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
48944 kfree(kbs);
48945 return ((p && *p) ? -EOVERFLOW : 0);
48946 case KDSKBSENT:
48947+ if (!capable(CAP_SYS_TTY_CONFIG))
48948+ perm = 0;
48949+
48950 if (!perm) {
48951 ret = -EPERM;
48952 goto reterr;
48953diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
48954index 3b96f18..026a9bf 100644
48955--- a/drivers/uio/uio.c
48956+++ b/drivers/uio/uio.c
48957@@ -25,6 +25,7 @@
48958 #include <linux/kobject.h>
48959 #include <linux/cdev.h>
48960 #include <linux/uio_driver.h>
48961+#include <asm/local.h>
48962
48963 #define UIO_MAX_DEVICES (1U << MINORBITS)
48964
48965@@ -32,10 +33,10 @@ struct uio_device {
48966 struct module *owner;
48967 struct device *dev;
48968 int minor;
48969- atomic_t event;
48970+ atomic_unchecked_t event;
48971 struct fasync_struct *async_queue;
48972 wait_queue_head_t wait;
48973- int vma_count;
48974+ local_t vma_count;
48975 struct uio_info *info;
48976 struct kobject *map_dir;
48977 struct kobject *portio_dir;
48978@@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
48979 struct device_attribute *attr, char *buf)
48980 {
48981 struct uio_device *idev = dev_get_drvdata(dev);
48982- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
48983+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
48984 }
48985
48986 static struct device_attribute uio_class_attributes[] = {
48987@@ -398,7 +399,7 @@ void uio_event_notify(struct uio_info *info)
48988 {
48989 struct uio_device *idev = info->uio_dev;
48990
48991- atomic_inc(&idev->event);
48992+ atomic_inc_unchecked(&idev->event);
48993 wake_up_interruptible(&idev->wait);
48994 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
48995 }
48996@@ -451,7 +452,7 @@ static int uio_open(struct inode *inode, struct file *filep)
48997 }
48998
48999 listener->dev = idev;
49000- listener->event_count = atomic_read(&idev->event);
49001+ listener->event_count = atomic_read_unchecked(&idev->event);
49002 filep->private_data = listener;
49003
49004 if (idev->info->open) {
49005@@ -502,7 +503,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
49006 return -EIO;
49007
49008 poll_wait(filep, &idev->wait, wait);
49009- if (listener->event_count != atomic_read(&idev->event))
49010+ if (listener->event_count != atomic_read_unchecked(&idev->event))
49011 return POLLIN | POLLRDNORM;
49012 return 0;
49013 }
49014@@ -527,7 +528,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
49015 do {
49016 set_current_state(TASK_INTERRUPTIBLE);
49017
49018- event_count = atomic_read(&idev->event);
49019+ event_count = atomic_read_unchecked(&idev->event);
49020 if (event_count != listener->event_count) {
49021 if (copy_to_user(buf, &event_count, count))
49022 retval = -EFAULT;
49023@@ -596,13 +597,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
49024 static void uio_vma_open(struct vm_area_struct *vma)
49025 {
49026 struct uio_device *idev = vma->vm_private_data;
49027- idev->vma_count++;
49028+ local_inc(&idev->vma_count);
49029 }
49030
49031 static void uio_vma_close(struct vm_area_struct *vma)
49032 {
49033 struct uio_device *idev = vma->vm_private_data;
49034- idev->vma_count--;
49035+ local_dec(&idev->vma_count);
49036 }
49037
49038 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
49039@@ -809,7 +810,7 @@ int __uio_register_device(struct module *owner,
49040 idev->owner = owner;
49041 idev->info = info;
49042 init_waitqueue_head(&idev->wait);
49043- atomic_set(&idev->event, 0);
49044+ atomic_set_unchecked(&idev->event, 0);
49045
49046 ret = uio_get_minor(idev);
49047 if (ret)
49048diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
49049index 8a7eb77..c00402f 100644
49050--- a/drivers/usb/atm/cxacru.c
49051+++ b/drivers/usb/atm/cxacru.c
49052@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
49053 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
49054 if (ret < 2)
49055 return -EINVAL;
49056- if (index < 0 || index > 0x7f)
49057+ if (index > 0x7f)
49058 return -EINVAL;
49059 pos += tmp;
49060
49061diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
49062index 5e0d33a..cc10579 100644
49063--- a/drivers/usb/atm/usbatm.c
49064+++ b/drivers/usb/atm/usbatm.c
49065@@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
49066 if (printk_ratelimit())
49067 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
49068 __func__, vpi, vci);
49069- atomic_inc(&vcc->stats->rx_err);
49070+ atomic_inc_unchecked(&vcc->stats->rx_err);
49071 return;
49072 }
49073
49074@@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
49075 if (length > ATM_MAX_AAL5_PDU) {
49076 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
49077 __func__, length, vcc);
49078- atomic_inc(&vcc->stats->rx_err);
49079+ atomic_inc_unchecked(&vcc->stats->rx_err);
49080 goto out;
49081 }
49082
49083@@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
49084 if (sarb->len < pdu_length) {
49085 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
49086 __func__, pdu_length, sarb->len, vcc);
49087- atomic_inc(&vcc->stats->rx_err);
49088+ atomic_inc_unchecked(&vcc->stats->rx_err);
49089 goto out;
49090 }
49091
49092 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
49093 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
49094 __func__, vcc);
49095- atomic_inc(&vcc->stats->rx_err);
49096+ atomic_inc_unchecked(&vcc->stats->rx_err);
49097 goto out;
49098 }
49099
49100@@ -389,7 +389,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
49101 if (printk_ratelimit())
49102 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
49103 __func__, length);
49104- atomic_inc(&vcc->stats->rx_drop);
49105+ atomic_inc_unchecked(&vcc->stats->rx_drop);
49106 goto out;
49107 }
49108
49109@@ -417,7 +417,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
49110
49111 vcc->push(vcc, skb);
49112
49113- atomic_inc(&vcc->stats->rx);
49114+ atomic_inc_unchecked(&vcc->stats->rx);
49115 out:
49116 skb_trim(sarb, 0);
49117 }
49118@@ -623,7 +623,7 @@ static void usbatm_tx_process(unsigned long data)
49119 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
49120
49121 usbatm_pop(vcc, skb);
49122- atomic_inc(&vcc->stats->tx);
49123+ atomic_inc_unchecked(&vcc->stats->tx);
49124
49125 skb = skb_dequeue(&instance->sndqueue);
49126 }
49127@@ -779,11 +779,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
49128 if (!left--)
49129 return sprintf(page,
49130 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
49131- atomic_read(&atm_dev->stats.aal5.tx),
49132- atomic_read(&atm_dev->stats.aal5.tx_err),
49133- atomic_read(&atm_dev->stats.aal5.rx),
49134- atomic_read(&atm_dev->stats.aal5.rx_err),
49135- atomic_read(&atm_dev->stats.aal5.rx_drop));
49136+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
49137+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
49138+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
49139+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
49140+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
49141
49142 if (!left--) {
49143 if (instance->disconnected)
49144diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
49145index 2a3bbdf..91d72cf 100644
49146--- a/drivers/usb/core/devices.c
49147+++ b/drivers/usb/core/devices.c
49148@@ -126,7 +126,7 @@ static const char format_endpt[] =
49149 * time it gets called.
49150 */
49151 static struct device_connect_event {
49152- atomic_t count;
49153+ atomic_unchecked_t count;
49154 wait_queue_head_t wait;
49155 } device_event = {
49156 .count = ATOMIC_INIT(1),
49157@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
49158
49159 void usbfs_conn_disc_event(void)
49160 {
49161- atomic_add(2, &device_event.count);
49162+ atomic_add_unchecked(2, &device_event.count);
49163 wake_up(&device_event.wait);
49164 }
49165
49166@@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
49167
49168 poll_wait(file, &device_event.wait, wait);
49169
49170- event_count = atomic_read(&device_event.count);
49171+ event_count = atomic_read_unchecked(&device_event.count);
49172 if (file->f_version != event_count) {
49173 file->f_version = event_count;
49174 return POLLIN | POLLRDNORM;
49175diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
49176index 014dc99..4d25fd7 100644
49177--- a/drivers/usb/core/hcd.c
49178+++ b/drivers/usb/core/hcd.c
49179@@ -1551,7 +1551,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
49180 */
49181 usb_get_urb(urb);
49182 atomic_inc(&urb->use_count);
49183- atomic_inc(&urb->dev->urbnum);
49184+ atomic_inc_unchecked(&urb->dev->urbnum);
49185 usbmon_urb_submit(&hcd->self, urb);
49186
49187 /* NOTE requirements on root-hub callers (usbfs and the hub
49188@@ -1578,7 +1578,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
49189 urb->hcpriv = NULL;
49190 INIT_LIST_HEAD(&urb->urb_list);
49191 atomic_dec(&urb->use_count);
49192- atomic_dec(&urb->dev->urbnum);
49193+ atomic_dec_unchecked(&urb->dev->urbnum);
49194 if (atomic_read(&urb->reject))
49195 wake_up(&usb_kill_urb_queue);
49196 usb_put_urb(urb);
49197diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
49198index 558313d..8cadfa5 100644
49199--- a/drivers/usb/core/hub.c
49200+++ b/drivers/usb/core/hub.c
49201@@ -27,6 +27,7 @@
49202 #include <linux/freezer.h>
49203 #include <linux/random.h>
49204 #include <linux/pm_qos.h>
49205+#include <linux/grsecurity.h>
49206
49207 #include <asm/uaccess.h>
49208 #include <asm/byteorder.h>
49209@@ -4426,6 +4427,10 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
49210 goto done;
49211 return;
49212 }
49213+
49214+ if (gr_handle_new_usb())
49215+ goto done;
49216+
49217 if (hub_is_superspeed(hub->hdev))
49218 unit_load = 150;
49219 else
49220diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
49221index e7ee1e4..1dfc9ea4 100644
49222--- a/drivers/usb/core/message.c
49223+++ b/drivers/usb/core/message.c
49224@@ -129,7 +129,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
49225 * method can wait for it to complete. Since you don't have a handle on the
49226 * URB used, you can't cancel the request.
49227 */
49228-int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
49229+int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
49230 __u8 requesttype, __u16 value, __u16 index, void *data,
49231 __u16 size, int timeout)
49232 {
49233diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
49234index d9284b9..17023c7 100644
49235--- a/drivers/usb/core/sysfs.c
49236+++ b/drivers/usb/core/sysfs.c
49237@@ -239,7 +239,7 @@ show_urbnum(struct device *dev, struct device_attribute *attr, char *buf)
49238 struct usb_device *udev;
49239
49240 udev = to_usb_device(dev);
49241- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
49242+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
49243 }
49244 static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL);
49245
49246diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
49247index 7dad603..350f7a9 100644
49248--- a/drivers/usb/core/usb.c
49249+++ b/drivers/usb/core/usb.c
49250@@ -422,7 +422,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
49251 set_dev_node(&dev->dev, dev_to_node(bus->controller));
49252 dev->state = USB_STATE_ATTACHED;
49253 dev->lpm_disable_count = 1;
49254- atomic_set(&dev->urbnum, 0);
49255+ atomic_set_unchecked(&dev->urbnum, 0);
49256
49257 INIT_LIST_HEAD(&dev->ep0.urb_list);
49258 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
49259diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
49260index f77083f..f3e2e34 100644
49261--- a/drivers/usb/dwc3/gadget.c
49262+++ b/drivers/usb/dwc3/gadget.c
49263@@ -550,8 +550,6 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
49264 if (!usb_endpoint_xfer_isoc(desc))
49265 return 0;
49266
49267- memset(&trb_link, 0, sizeof(trb_link));
49268-
49269 /* Link TRB for ISOC. The HWO bit is never reset */
49270 trb_st_hw = &dep->trb_pool[0];
49271
49272diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
49273index 5e29dde..eca992f 100644
49274--- a/drivers/usb/early/ehci-dbgp.c
49275+++ b/drivers/usb/early/ehci-dbgp.c
49276@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
49277
49278 #ifdef CONFIG_KGDB
49279 static struct kgdb_io kgdbdbgp_io_ops;
49280-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
49281+static struct kgdb_io kgdbdbgp_io_ops_console;
49282+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
49283 #else
49284 #define dbgp_kgdb_mode (0)
49285 #endif
49286@@ -1047,6 +1048,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
49287 .write_char = kgdbdbgp_write_char,
49288 };
49289
49290+static struct kgdb_io kgdbdbgp_io_ops_console = {
49291+ .name = "kgdbdbgp",
49292+ .read_char = kgdbdbgp_read_char,
49293+ .write_char = kgdbdbgp_write_char,
49294+ .is_console = 1
49295+};
49296+
49297 static int kgdbdbgp_wait_time;
49298
49299 static int __init kgdbdbgp_parse_config(char *str)
49300@@ -1062,8 +1070,10 @@ static int __init kgdbdbgp_parse_config(char *str)
49301 ptr++;
49302 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
49303 }
49304- kgdb_register_io_module(&kgdbdbgp_io_ops);
49305- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
49306+ if (early_dbgp_console.index != -1)
49307+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
49308+ else
49309+ kgdb_register_io_module(&kgdbdbgp_io_ops);
49310
49311 return 0;
49312 }
49313diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
49314index b369292..9f3ba40 100644
49315--- a/drivers/usb/gadget/u_serial.c
49316+++ b/drivers/usb/gadget/u_serial.c
49317@@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
49318 spin_lock_irq(&port->port_lock);
49319
49320 /* already open? Great. */
49321- if (port->port.count) {
49322+ if (atomic_read(&port->port.count)) {
49323 status = 0;
49324- port->port.count++;
49325+ atomic_inc(&port->port.count);
49326
49327 /* currently opening/closing? wait ... */
49328 } else if (port->openclose) {
49329@@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
49330 tty->driver_data = port;
49331 port->port.tty = tty;
49332
49333- port->port.count = 1;
49334+ atomic_set(&port->port.count, 1);
49335 port->openclose = false;
49336
49337 /* if connected, start the I/O stream */
49338@@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
49339
49340 spin_lock_irq(&port->port_lock);
49341
49342- if (port->port.count != 1) {
49343- if (port->port.count == 0)
49344+ if (atomic_read(&port->port.count) != 1) {
49345+ if (atomic_read(&port->port.count) == 0)
49346 WARN_ON(1);
49347 else
49348- --port->port.count;
49349+ atomic_dec(&port->port.count);
49350 goto exit;
49351 }
49352
49353@@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
49354 * and sleep if necessary
49355 */
49356 port->openclose = true;
49357- port->port.count = 0;
49358+ atomic_set(&port->port.count, 0);
49359
49360 gser = port->port_usb;
49361 if (gser && gser->disconnect)
49362@@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
49363 int cond;
49364
49365 spin_lock_irq(&port->port_lock);
49366- cond = (port->port.count == 0) && !port->openclose;
49367+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
49368 spin_unlock_irq(&port->port_lock);
49369 return cond;
49370 }
49371@@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
49372 /* if it's already open, start I/O ... and notify the serial
49373 * protocol about open/close status (connect/disconnect).
49374 */
49375- if (port->port.count) {
49376+ if (atomic_read(&port->port.count)) {
49377 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
49378 gs_start_io(port);
49379 if (gser->connect)
49380@@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
49381
49382 port->port_usb = NULL;
49383 gser->ioport = NULL;
49384- if (port->port.count > 0 || port->openclose) {
49385+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
49386 wake_up_interruptible(&port->drain_wait);
49387 if (port->port.tty)
49388 tty_hangup(port->port.tty);
49389@@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
49390
49391 /* finally, free any unused/unusable I/O buffers */
49392 spin_lock_irqsave(&port->port_lock, flags);
49393- if (port->port.count == 0 && !port->openclose)
49394+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
49395 gs_buf_free(&port->port_write_buf);
49396 gs_free_requests(gser->out, &port->read_pool, NULL);
49397 gs_free_requests(gser->out, &port->read_queue, NULL);
49398diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
49399index ba6a5d6..f88f7f3 100644
49400--- a/drivers/usb/misc/appledisplay.c
49401+++ b/drivers/usb/misc/appledisplay.c
49402@@ -83,7 +83,7 @@ struct appledisplay {
49403 spinlock_t lock;
49404 };
49405
49406-static atomic_t count_displays = ATOMIC_INIT(0);
49407+static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
49408 static struct workqueue_struct *wq;
49409
49410 static void appledisplay_complete(struct urb *urb)
49411@@ -281,7 +281,7 @@ static int appledisplay_probe(struct usb_interface *iface,
49412
49413 /* Register backlight device */
49414 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
49415- atomic_inc_return(&count_displays) - 1);
49416+ atomic_inc_return_unchecked(&count_displays) - 1);
49417 memset(&props, 0, sizeof(struct backlight_properties));
49418 props.type = BACKLIGHT_RAW;
49419 props.max_brightness = 0xff;
49420diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
49421index afb50ea..7b0b1cf 100644
49422--- a/drivers/usb/serial/console.c
49423+++ b/drivers/usb/serial/console.c
49424@@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
49425
49426 info->port = port;
49427
49428- ++port->port.count;
49429+ atomic_inc(&port->port.count);
49430 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
49431 if (serial->type->set_termios) {
49432 /*
49433@@ -174,7 +174,7 @@ static int usb_console_setup(struct console *co, char *options)
49434 }
49435 /* Now that any required fake tty operations are completed restore
49436 * the tty port count */
49437- --port->port.count;
49438+ atomic_dec(&port->port.count);
49439 /* The console is special in terms of closing the device so
49440 * indicate this port is now acting as a system console. */
49441 port->port.console = 1;
49442@@ -187,7 +187,7 @@ static int usb_console_setup(struct console *co, char *options)
49443 free_tty:
49444 kfree(tty);
49445 reset_open_count:
49446- port->port.count = 0;
49447+ atomic_set(&port->port.count, 0);
49448 usb_autopm_put_interface(serial->interface);
49449 error_get_interface:
49450 usb_serial_put(serial);
49451diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
49452index 75f70f0..d467e1a 100644
49453--- a/drivers/usb/storage/usb.h
49454+++ b/drivers/usb/storage/usb.h
49455@@ -63,7 +63,7 @@ struct us_unusual_dev {
49456 __u8 useProtocol;
49457 __u8 useTransport;
49458 int (*initFunction)(struct us_data *);
49459-};
49460+} __do_const;
49461
49462
49463 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
49464diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
49465index d6bea3e..60b250e 100644
49466--- a/drivers/usb/wusbcore/wa-hc.h
49467+++ b/drivers/usb/wusbcore/wa-hc.h
49468@@ -192,7 +192,7 @@ struct wahc {
49469 struct list_head xfer_delayed_list;
49470 spinlock_t xfer_list_lock;
49471 struct work_struct xfer_work;
49472- atomic_t xfer_id_count;
49473+ atomic_unchecked_t xfer_id_count;
49474 };
49475
49476
49477@@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
49478 INIT_LIST_HEAD(&wa->xfer_delayed_list);
49479 spin_lock_init(&wa->xfer_list_lock);
49480 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
49481- atomic_set(&wa->xfer_id_count, 1);
49482+ atomic_set_unchecked(&wa->xfer_id_count, 1);
49483 }
49484
49485 /**
49486diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
49487index d3493ca..0c33b7e 100644
49488--- a/drivers/usb/wusbcore/wa-xfer.c
49489+++ b/drivers/usb/wusbcore/wa-xfer.c
49490@@ -297,7 +297,7 @@ out:
49491 */
49492 static void wa_xfer_id_init(struct wa_xfer *xfer)
49493 {
49494- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
49495+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
49496 }
49497
49498 /*
49499diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
49500index 842f450..d1d7409 100644
49501--- a/drivers/vfio/vfio.c
49502+++ b/drivers/vfio/vfio.c
49503@@ -488,7 +488,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
49504 return 0;
49505
49506 /* TODO Prevent device auto probing */
49507- WARN("Device %s added to live group %d!\n", dev_name(dev),
49508+ WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
49509 iommu_group_id(group->iommu_group));
49510
49511 return 0;
49512diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
49513index 5174eba..86e764a 100644
49514--- a/drivers/vhost/vringh.c
49515+++ b/drivers/vhost/vringh.c
49516@@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
49517
49518 static inline int putu16_kern(u16 *p, u16 val)
49519 {
49520- ACCESS_ONCE(*p) = val;
49521+ ACCESS_ONCE_RW(*p) = val;
49522 return 0;
49523 }
49524
49525diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
49526index a4dfe8c..297ddd9 100644
49527--- a/drivers/video/aty/aty128fb.c
49528+++ b/drivers/video/aty/aty128fb.c
49529@@ -149,7 +149,7 @@ enum {
49530 };
49531
49532 /* Must match above enum */
49533-static char * const r128_family[] = {
49534+static const char * const r128_family[] = {
49535 "AGP",
49536 "PCI",
49537 "PRO AGP",
49538diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
49539index 9b0f12c..024673d 100644
49540--- a/drivers/video/aty/atyfb_base.c
49541+++ b/drivers/video/aty/atyfb_base.c
49542@@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
49543 par->accel_flags = var->accel_flags; /* hack */
49544
49545 if (var->accel_flags) {
49546- info->fbops->fb_sync = atyfb_sync;
49547+ pax_open_kernel();
49548+ *(void **)&info->fbops->fb_sync = atyfb_sync;
49549+ pax_close_kernel();
49550 info->flags &= ~FBINFO_HWACCEL_DISABLED;
49551 } else {
49552- info->fbops->fb_sync = NULL;
49553+ pax_open_kernel();
49554+ *(void **)&info->fbops->fb_sync = NULL;
49555+ pax_close_kernel();
49556 info->flags |= FBINFO_HWACCEL_DISABLED;
49557 }
49558
49559diff --git a/drivers/video/aty/mach64_cursor.c b/drivers/video/aty/mach64_cursor.c
49560index 95ec042..e6affdd 100644
49561--- a/drivers/video/aty/mach64_cursor.c
49562+++ b/drivers/video/aty/mach64_cursor.c
49563@@ -7,6 +7,7 @@
49564 #include <linux/string.h>
49565
49566 #include <asm/io.h>
49567+#include <asm/pgtable.h>
49568
49569 #ifdef __sparc__
49570 #include <asm/fbio.h>
49571@@ -208,7 +209,9 @@ int aty_init_cursor(struct fb_info *info)
49572 info->sprite.buf_align = 16; /* and 64 lines tall. */
49573 info->sprite.flags = FB_PIXMAP_IO;
49574
49575- info->fbops->fb_cursor = atyfb_cursor;
49576+ pax_open_kernel();
49577+ *(void **)&info->fbops->fb_cursor = atyfb_cursor;
49578+ pax_close_kernel();
49579
49580 return 0;
49581 }
49582diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
49583index bca6ccc..252107e 100644
49584--- a/drivers/video/backlight/kb3886_bl.c
49585+++ b/drivers/video/backlight/kb3886_bl.c
49586@@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
49587 static unsigned long kb3886bl_flags;
49588 #define KB3886BL_SUSPENDED 0x01
49589
49590-static struct dmi_system_id __initdata kb3886bl_device_table[] = {
49591+static const struct dmi_system_id __initconst kb3886bl_device_table[] = {
49592 {
49593 .ident = "Sahara Touch-iT",
49594 .matches = {
49595diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c
49596index 900aa4e..6d49418 100644
49597--- a/drivers/video/fb_defio.c
49598+++ b/drivers/video/fb_defio.c
49599@@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
49600
49601 BUG_ON(!fbdefio);
49602 mutex_init(&fbdefio->lock);
49603- info->fbops->fb_mmap = fb_deferred_io_mmap;
49604+ pax_open_kernel();
49605+ *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
49606+ pax_close_kernel();
49607 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
49608 INIT_LIST_HEAD(&fbdefio->pagelist);
49609 if (fbdefio->delay == 0) /* set a default of 1 s */
49610@@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
49611 page->mapping = NULL;
49612 }
49613
49614- info->fbops->fb_mmap = NULL;
49615+ *(void **)&info->fbops->fb_mmap = NULL;
49616 mutex_destroy(&fbdefio->lock);
49617 }
49618 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
49619diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
49620index 5c3960d..15cf8fc 100644
49621--- a/drivers/video/fbcmap.c
49622+++ b/drivers/video/fbcmap.c
49623@@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
49624 rc = -ENODEV;
49625 goto out;
49626 }
49627- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
49628- !info->fbops->fb_setcmap)) {
49629+ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
49630 rc = -EINVAL;
49631 goto out1;
49632 }
49633diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
49634index 36e1fe2..c744820 100644
49635--- a/drivers/video/fbmem.c
49636+++ b/drivers/video/fbmem.c
49637@@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
49638 image->dx += image->width + 8;
49639 }
49640 } else if (rotate == FB_ROTATE_UD) {
49641- for (x = 0; x < num && image->dx >= 0; x++) {
49642+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
49643 info->fbops->fb_imageblit(info, image);
49644 image->dx -= image->width + 8;
49645 }
49646@@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
49647 image->dy += image->height + 8;
49648 }
49649 } else if (rotate == FB_ROTATE_CCW) {
49650- for (x = 0; x < num && image->dy >= 0; x++) {
49651+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
49652 info->fbops->fb_imageblit(info, image);
49653 image->dy -= image->height + 8;
49654 }
49655@@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
49656 return -EFAULT;
49657 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
49658 return -EINVAL;
49659- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
49660+ if (con2fb.framebuffer >= FB_MAX)
49661 return -EINVAL;
49662 if (!registered_fb[con2fb.framebuffer])
49663 request_module("fb%d", con2fb.framebuffer);
49664diff --git a/drivers/video/hyperv_fb.c b/drivers/video/hyperv_fb.c
49665index d4d2c5f..ebbd113 100644
49666--- a/drivers/video/hyperv_fb.c
49667+++ b/drivers/video/hyperv_fb.c
49668@@ -233,7 +233,7 @@ static uint screen_fb_size;
49669 static inline int synthvid_send(struct hv_device *hdev,
49670 struct synthvid_msg *msg)
49671 {
49672- static atomic64_t request_id = ATOMIC64_INIT(0);
49673+ static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
49674 int ret;
49675
49676 msg->pipe_hdr.type = PIPE_MSG_DATA;
49677@@ -241,7 +241,7 @@ static inline int synthvid_send(struct hv_device *hdev,
49678
49679 ret = vmbus_sendpacket(hdev->channel, msg,
49680 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
49681- atomic64_inc_return(&request_id),
49682+ atomic64_inc_return_unchecked(&request_id),
49683 VM_PKT_DATA_INBAND, 0);
49684
49685 if (ret)
49686diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
49687index 7672d2e..b56437f 100644
49688--- a/drivers/video/i810/i810_accel.c
49689+++ b/drivers/video/i810/i810_accel.c
49690@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
49691 }
49692 }
49693 printk("ringbuffer lockup!!!\n");
49694+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
49695 i810_report_error(mmio);
49696 par->dev_flags |= LOCKUP;
49697 info->pixmap.scan_align = 1;
49698diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
49699index 285d552..eafa544 100644
49700--- a/drivers/video/logo/logo_linux_clut224.ppm
49701+++ b/drivers/video/logo/logo_linux_clut224.ppm
49702@@ -1,883 +1,1123 @@
49703 P3
49704 80 80
49705 255
49706-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49707-0 0 0 0 0 0 0 0 0 0 0 0 11 15 17 33 49 54 59 85 92 73 97 106
49708-83 116 129 105 131 142 115 114 122 74 88 93 20 29 31 0 0 0 0 0 0 0 0 0
49709-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49710-0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 6 6 6 10 10 10 10 10 10
49711-10 10 10 6 6 6 6 6 6 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0
49712-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49713-0 0 0 0 0 0 0 0 0 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-
49717-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49718-0 0 0 0 0 0 2 3 3 17 23 26 50 67 72 73 97 106 59 85 92 73 97 106
49719-105 131 142 124 127 131 105 131 142 105 131 142 53 75 83 6 8 8 0 0 0 0 0 0
49720-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49721-0 0 0 6 6 6 10 10 10 14 14 14 22 22 22 26 26 26 30 30 30 34 34 34
49722-30 30 30 30 30 30 26 26 26 18 18 18 14 14 14 10 10 10 6 6 6 0 0 0
49723-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49724-0 0 0 0 0 0 0 0 0 0 0 0 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-
49728-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0
49729-0 0 0 1 1 1 26 35 39 59 85 92 59 85 92 59 85 92 29 43 47 53 75 83
49730-108 122 132 132 98 104 108 122 132 105 131 142 101 101 101 43 45 48 6 8 8 0 0 0
49731-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49732-6 6 6 14 14 14 26 26 26 42 42 42 54 54 54 66 66 66 78 78 78 78 78 78
49733-78 78 78 74 74 74 66 66 66 54 54 54 42 42 42 26 26 26 18 18 18 10 10 10
49734-6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49735-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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-
49739-0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0
49740-11 15 17 27 40 45 59 85 92 59 85 92 27 40 45 31 45 49 73 97 106 93 121 133
49741-108 122 132 108 122 132 105 131 142 108 122 132 105 131 142 73 97 106 26 35 39 0 0 0
49742-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
49743-22 22 22 42 42 42 66 66 66 86 86 86 66 66 66 38 38 38 38 38 38 22 22 22
49744-26 26 26 34 34 34 54 54 54 66 66 66 86 86 86 70 70 70 46 46 46 26 26 26
49745-14 14 14 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49746-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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-
49750-0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 7 12 13 21 31 35 42 59 64
49751-53 75 83 53 75 83 50 67 72 42 59 64 32 40 45 42 59 64 73 97 106 116 116 116
49752-132 98 104 116 116 116 108 122 132 117 104 110 105 131 142 83 116 129 50 67 72 7 12 13
49753-1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10 26 26 26
49754-50 50 50 82 82 82 58 58 58 6 6 6 2 2 6 2 2 6 2 2 6 2 2 6
49755-2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 54 54 54 86 86 86 66 66 66
49756-38 38 38 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49757-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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-
49761-0 0 0 1 1 1 6 8 8 15 22 25 26 35 39 36 54 60 53 75 83 59 85 92
49762-59 85 92 48 63 69 15 22 25 12 17 20 52 67 79 94 94 94 132 98 104 132 98 104
49763-117 104 110 108 122 132 108 122 132 115 114 122 105 131 142 77 105 114 59 85 92 36 54 60
49764-7 12 13 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 22 22 22 50 50 50
49765-78 78 78 34 34 34 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49766-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 70 70 70
49767-78 78 78 46 46 46 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0
49768-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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-
49772-0 0 0 15 22 25 29 43 47 36 54 60 42 59 64 42 59 64 48 63 69 21 31 35
49773-6 8 8 29 43 47 36 50 56 43 45 48 79 78 84 132 98 104 165 78 79 132 98 104
49774-108 122 132 117 104 110 117 104 110 108 122 132 77 105 114 73 97 106 95 131 149 78 102 129
49775-36 50 56 0 0 0 0 0 0 0 0 0 6 6 6 18 18 18 42 42 42 82 82 82
49776-26 26 26 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49777-2 2 6 2 2 6 2 2 6 14 14 14 46 46 46 34 34 34 6 6 6 2 2 6
49778-42 42 42 78 78 78 42 42 42 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0
49779-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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-
49783-27 40 45 53 75 83 48 63 69 24 31 37 6 8 12 0 0 0 18 25 28 26 35 39
49784-12 17 20 26 35 39 65 78 84 112 81 86 152 81 83 137 83 86 132 98 104 117 104 110
49785-117 104 110 132 98 104 132 98 104 115 114 122 73 97 106 53 75 83 95 131 149 93 124 152
49786-68 78 128 15 22 25 0 0 0 0 0 0 10 10 10 30 30 30 66 66 66 58 58 58
49787-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49788-2 2 6 2 2 6 2 2 6 26 26 26 86 86 86 101 101 101 46 46 46 10 10 10
49789-2 2 6 58 58 58 70 70 70 34 34 34 10 10 10 0 0 0 0 0 0 0 0 0
49790-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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-
49794-36 50 56 21 30 33 4 7 7 0 0 0 1 1 1 17 12 12 69 31 31 68 59 64
49795-57 59 63 21 31 35 32 40 45 86 73 69 152 81 83 152 81 83 117 104 110 132 98 104
49796-152 81 83 132 98 104 108 122 132 77 105 114 77 105 114 93 121 133 95 131 149 93 124 152
49797-95 131 149 53 75 83 11 15 17 0 0 0 14 14 14 42 42 42 86 86 86 10 10 10
49798-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49799-2 2 6 2 2 6 2 2 6 30 30 30 94 94 94 94 94 94 58 58 58 26 26 26
49800-2 2 6 6 6 6 78 78 78 54 54 54 22 22 22 6 6 6 0 0 0 0 0 0
49801-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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-
49805-17 23 26 2 3 3 0 0 0 17 12 12 69 31 31 123 55 55 123 55 55 152 81 83
49806-86 73 69 17 23 26 7 12 13 45 54 57 101 101 101 137 83 86 132 98 104 132 98 104
49807-137 83 86 117 104 110 77 105 114 42 59 64 50 67 72 78 102 129 91 117 157 91 117 157
49808-95 131 149 83 116 129 40 48 73 6 6 6 22 22 22 62 62 62 62 62 62 2 2 6
49809-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49810-2 2 6 2 2 6 2 2 6 26 26 26 54 54 54 38 38 38 18 18 18 10 10 10
49811-2 2 6 2 2 6 34 34 34 82 82 82 38 38 38 14 14 14 0 0 0 0 0 0
49812-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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-
49816-1 1 1 1 2 2 2 3 3 28 12 12 123 55 55 174 79 79 174 79 79 174 79 79
49817-152 81 83 68 59 64 26 35 39 27 40 45 79 78 84 137 83 86 165 78 79 137 83 86
49818-94 94 94 48 63 69 36 50 56 50 67 72 73 97 106 93 121 133 93 124 152 93 124 152
49819-95 131 149 91 118 149 78 102 129 27 40 45 30 30 30 78 78 78 30 30 30 2 2 6
49820-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49821-2 2 6 2 2 6 2 2 6 10 10 10 10 10 10 2 2 6 2 2 6 2 2 6
49822-2 2 6 2 2 6 2 2 6 78 78 78 50 50 50 18 18 18 6 6 6 0 0 0
49823-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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-
49827-4 5 3 24 53 24 19 31 15 8 7 3 90 61 47 165 78 79 174 79 79 174 79 79
49828-174 79 79 137 83 86 60 52 57 7 12 13 17 23 26 70 70 70 132 98 104 112 81 86
49829-79 78 84 31 45 49 15 22 25 53 75 83 91 118 149 86 106 160 91 117 157 93 124 152
49830-91 117 157 93 124 152 95 131 149 53 75 83 50 50 50 86 86 86 14 14 14 2 2 6
49831-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49832-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49833-2 2 6 2 2 6 2 2 6 54 54 54 66 66 66 26 26 26 6 6 6 0 0 0
49834-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
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-
49838-19 31 15 34 76 34 34 76 34 19 31 15 28 12 12 123 55 55 174 79 79 174 79 79
49839-174 79 79 165 78 79 112 81 86 32 40 45 15 22 25 38 53 58 65 78 84 29 31 32
49840-21 30 33 42 59 64 60 80 103 78 102 129 87 112 149 84 96 162 91 117 157 93 124 152
49841-91 117 157 93 124 152 93 121 133 59 85 92 57 68 71 82 85 86 2 2 6 2 2 6
49842-2 2 6 6 6 6 10 10 10 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49843-2 2 6 2 2 6 2 2 6 6 6 6 14 14 14 10 10 10 2 2 6 2 2 6
49844-2 2 6 2 2 6 2 2 6 18 18 18 82 82 82 34 34 34 10 10 10 0 0 0
49845-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
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-
49849-34 76 34 40 89 40 40 89 40 34 76 34 8 15 6 48 26 18 123 55 55 174 79 79
49850-174 79 79 174 79 79 137 83 86 68 59 64 32 40 45 21 30 33 31 45 49 21 31 35
49851-12 17 20 48 63 69 78 102 129 81 88 166 84 96 162 91 117 157 93 124 152 91 117 157
49852-93 124 152 95 131 149 83 116 129 59 85 92 57 68 71 86 86 86 2 2 6 2 2 6
49853-6 6 6 6 6 6 22 22 22 34 34 34 6 6 6 2 2 6 2 2 6 2 2 6
49854-2 2 6 2 2 6 18 18 18 34 34 34 10 10 10 50 50 50 22 22 22 2 2 6
49855-2 2 6 2 2 6 2 2 6 10 10 10 86 86 86 42 42 42 14 14 14 0 0 0
49856-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
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-
49860-40 89 40 40 89 40 40 89 40 40 89 40 24 53 24 6 6 6 69 31 31 123 55 55
49861-123 55 55 90 61 47 69 31 31 36 32 33 21 31 35 7 12 13 18 25 28 48 63 69
49862-60 80 103 68 78 128 84 101 153 84 96 162 84 96 162 91 117 157 91 117 157 84 96 162
49863-91 117 157 73 97 106 48 63 69 50 67 72 57 59 63 86 86 86 2 2 6 2 2 6
49864-38 38 38 116 116 116 94 94 94 22 22 22 22 22 22 2 2 6 2 2 6 2 2 6
49865-14 14 14 86 86 86 124 131 137 170 170 170 151 151 151 38 38 38 26 26 26 6 6 6
49866-2 2 6 2 2 6 2 2 6 2 2 6 86 86 86 46 46 46 14 14 14 0 0 0
49867-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
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-
49871-34 76 34 40 89 40 40 89 40 40 89 40 34 76 34 19 31 15 17 12 12 48 26 18
49872-48 26 18 8 7 3 10 10 22 23 29 47 51 61 92 42 59 64 21 30 33 34 45 54
49873-68 78 128 81 88 166 81 82 173 86 106 160 86 106 160 84 96 162 86 106 160 87 112 149
49874-91 118 149 77 105 114 52 67 79 32 40 45 50 50 50 86 86 86 2 2 6 14 14 14
49875-124 131 137 198 198 198 195 195 195 116 116 116 10 10 10 2 2 6 2 2 6 6 6 6
49876-101 98 89 187 187 187 210 210 210 218 218 218 214 214 214 124 131 137 14 14 14 6 6 6
49877-2 2 6 2 2 6 2 2 6 2 2 6 86 86 86 50 50 50 18 18 18 6 6 6
49878-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
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-
49882-19 31 15 34 76 34 40 89 40 40 89 40 40 89 40 24 53 24 8 7 3 0 0 0
49883-6 8 12 28 32 52 51 61 92 54 54 122 74 77 160 68 78 128 26 35 39 6 8 8
49884-34 45 54 68 78 128 84 96 162 86 106 160 86 106 160 81 88 166 84 96 162 87 112 149
49885-73 97 106 36 50 56 33 49 54 18 18 18 46 46 46 86 86 86 2 2 6 54 54 54
49886-218 218 218 195 195 195 226 226 226 246 246 246 58 58 58 2 2 6 2 2 6 30 30 30
49887-210 210 210 253 253 253 170 170 170 124 127 131 221 221 221 234 234 234 74 74 74 2 2 6
49888-2 2 6 2 2 6 2 2 6 2 2 6 70 70 70 58 58 58 22 22 22 6 6 6
49889-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
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-
49893-4 5 3 24 53 24 40 89 40 40 89 40 34 76 34 12 22 15 4 5 3 4 5 3
49894-13 17 26 54 54 122 78 78 174 78 78 174 78 78 174 74 77 160 51 61 92 21 31 35
49895-26 35 39 53 75 83 84 101 153 81 82 173 81 88 166 84 101 153 60 80 103 60 80 103
49896-53 75 83 38 53 58 42 59 64 22 22 22 46 46 46 82 82 82 2 2 6 106 106 106
49897-170 170 170 26 26 26 86 86 86 226 226 226 124 127 131 10 10 10 14 14 14 46 46 46
49898-231 231 231 190 190 190 6 6 6 70 70 70 90 90 90 238 238 238 151 151 151 2 2 6
49899-2 2 6 2 2 6 2 2 6 2 2 6 70 70 70 58 58 58 22 22 22 6 6 6
49900-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
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-
49904-1 2 2 8 15 6 24 53 24 34 76 34 19 31 15 8 15 6 63 55 20 63 55 20
49905-18 18 18 40 48 73 74 77 160 78 78 174 78 78 174 81 82 173 74 77 160 52 67 79
49906-17 23 26 21 31 35 60 80 103 81 88 166 74 77 160 78 102 129 36 54 60 12 17 20
49907-42 59 64 48 63 69 21 31 35 18 18 18 42 42 42 86 86 86 6 6 6 116 116 116
49908-106 106 106 6 6 6 70 70 70 151 151 151 124 127 131 18 18 18 38 38 38 54 54 54
49909-221 221 221 106 106 106 2 2 6 14 14 14 46 46 46 190 190 190 198 198 198 2 2 6
49910-2 2 6 2 2 6 2 2 6 2 2 6 74 74 74 62 62 62 22 22 22 6 6 6
49911-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
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-
49915-11 15 17 0 0 0 12 22 15 19 31 15 8 15 6 63 55 20 149 139 69 149 139 69
49916-63 55 20 10 10 22 54 54 122 78 78 174 78 78 174 78 78 174 81 82 173 68 78 128
49917-24 31 37 6 6 6 36 50 56 60 80 103 51 61 92 42 59 64 36 50 56 31 45 49
49918-29 43 47 27 40 45 6 8 8 14 14 14 42 42 42 94 94 94 14 14 14 101 101 101
49919-124 127 131 2 2 6 18 18 18 116 116 116 106 107 48 121 92 8 121 92 8 98 70 6
49920-170 170 170 106 106 106 2 2 6 2 2 6 2 2 6 195 195 195 195 195 195 6 6 6
49921-2 2 6 2 2 6 2 2 6 2 2 6 74 74 74 62 62 62 22 22 22 6 6 6
49922-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
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-
49926-26 35 39 3 5 6 1 1 1 2 3 3 35 31 12 133 118 54 175 176 80 175 176 80
49927-133 118 54 35 31 12 23 29 47 54 54 122 78 78 174 78 78 174 74 77 160 68 78 128
49928-51 61 92 31 45 49 26 35 39 36 50 56 29 43 47 7 12 13 21 30 33 42 59 64
49929-18 25 28 7 12 13 1 1 1 10 10 10 38 38 38 90 90 90 14 14 14 58 58 58
49930-210 210 210 26 26 26 62 42 6 154 114 10 226 170 11 237 188 10 220 174 15 184 138 11
49931-220 174 15 174 140 55 35 31 12 2 2 6 70 70 70 246 246 246 124 131 137 2 2 6
49932-2 2 6 2 2 6 2 2 6 2 2 6 70 70 70 66 66 66 26 26 26 6 6 6
49933-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49934-0 0 0 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-
49937-27 40 45 17 23 26 2 3 3 1 1 1 56 77 35 165 152 80 175 176 80 175 176 80
49938-175 176 80 106 107 48 22 22 22 28 32 52 54 54 122 54 54 122 51 61 92 28 32 52
49939-20 27 34 31 45 49 11 15 17 7 12 13 36 50 56 31 45 49 29 43 47 36 50 56
49940-6 8 8 0 0 0 0 0 0 10 10 10 38 38 38 86 86 86 14 14 14 10 10 10
49941-195 195 195 198 179 130 192 133 9 220 174 15 239 182 13 237 188 10 232 195 16 239 207 25
49942-237 201 50 241 208 19 232 195 16 184 138 11 198 179 130 208 206 196 42 42 42 2 2 6
49943-2 2 6 2 2 6 2 2 6 2 2 6 50 50 50 74 74 74 30 30 30 6 6 6
49944-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49945-0 0 0 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-
49948-15 22 25 26 35 39 15 22 25 0 0 0 35 31 12 133 118 54 175 176 80 175 176 80
49949-175 176 80 165 152 80 56 77 35 6 8 12 23 29 47 13 17 26 2 2 6 0 0 0
49950-1 2 2 26 35 39 26 35 39 26 35 39 42 59 64 42 59 64 20 29 31 6 8 8
49951-0 0 0 0 0 0 0 0 0 10 10 10 34 34 34 86 86 86 14 14 14 2 2 6
49952-121 92 8 192 133 9 219 162 10 239 182 13 237 188 10 232 195 16 241 208 19 237 201 50
49953-237 201 50 239 207 25 241 208 19 241 208 19 241 208 19 230 187 11 121 92 8 2 2 6
49954-2 2 6 2 2 6 2 2 6 2 2 6 50 50 50 82 82 82 34 34 34 10 10 10
49955-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49956-0 0 0 0 0 0 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-
49959-1 2 2 15 22 25 31 45 49 6 8 12 4 5 3 63 55 20 149 139 69 175 176 80
49960-175 176 80 175 176 80 106 107 48 20 16 6 1 1 1 0 0 0 2 3 3 11 15 17
49961-21 30 33 36 50 56 36 50 56 24 31 37 15 22 25 6 8 8 0 0 0 0 0 0
49962-0 0 0 0 0 0 0 0 0 10 10 10 34 34 34 82 82 82 30 30 30 62 42 6
49963-180 123 7 206 145 10 230 174 11 239 182 13 237 188 10 238 202 15 241 208 19 237 201 50
49964-239 207 25 241 208 19 241 208 19 241 208 19 230 187 11 220 174 15 184 138 11 6 6 6
49965-2 2 6 2 2 6 2 2 6 2 2 6 26 26 26 94 94 94 42 42 42 14 14 14
49966-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49967-0 0 0 0 0 0 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-
49970-0 0 0 1 2 2 29 43 47 26 35 39 3 5 6 8 7 3 106 107 48 165 152 80
49971-175 176 80 149 139 69 63 55 20 4 5 3 2 3 3 12 17 20 26 35 39 26 35 39
49972-17 23 26 7 12 13 6 8 8 3 5 6 1 2 2 0 0 0 0 0 0 0 0 0
49973-0 0 0 0 0 0 0 0 0 10 10 10 30 30 30 78 78 78 50 50 50 104 69 6
49974-192 133 9 216 158 10 236 178 12 237 188 10 232 195 16 241 208 19 237 201 50 237 201 50
49975-241 208 19 241 208 19 241 208 19 204 160 10 200 144 11 216 158 10 156 118 10 2 2 6
49976-2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 90 90 90 54 54 54 18 18 18
49977-6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49978-0 0 0 0 0 0 0 0 0 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-
49981-0 0 0 0 0 0 12 17 20 27 40 45 18 25 28 1 1 1 35 31 12 106 107 48
49982-149 139 69 56 77 35 8 7 3 1 2 2 12 17 20 26 35 39 21 31 35 11 15 17
49983-3 5 6 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49984-0 0 0 0 0 0 0 0 0 10 10 10 30 30 30 78 78 78 46 46 46 22 22 22
49985-137 92 6 204 160 10 239 182 13 237 188 10 238 202 15 241 208 19 241 208 19 241 208 19
49986-241 208 19 204 160 10 184 138 11 210 150 10 216 158 10 210 150 10 98 70 6 2 2 6
49987-6 6 6 54 54 54 14 14 14 2 2 6 2 2 6 62 62 62 74 74 74 30 30 30
49988-10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49989-0 0 0 0 0 0 0 0 0 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-
49992-0 0 0 0 0 0 1 1 1 15 22 25 33 49 54 12 17 20 2 3 3 35 31 12
49993-56 77 35 20 16 6 1 1 1 18 25 28 21 31 35 11 15 17 1 1 1 0 0 0
49994-0 0 0 0 0 0 0 0 0 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 10 10 10 34 34 34 78 78 78 50 50 50 6 6 6
49996-88 55 22 139 102 15 190 146 13 230 187 11 239 207 25 232 195 16 220 174 15 190 146 13
49997-171 120 8 192 133 9 210 150 10 213 154 11 185 146 40 165 152 80 101 98 89 2 2 6
49998-2 2 6 78 78 78 116 116 116 58 58 58 2 2 6 22 22 22 90 90 90 46 46 46
49999-18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50000-0 0 0 0 0 0 0 0 0 0 0 0 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-
50003-0 0 0 0 0 0 0 0 0 1 1 1 27 40 45 29 43 47 3 5 6 2 3 3
50004-8 7 3 1 1 1 17 23 26 31 45 49 15 22 25 0 0 0 0 0 0 0 0 0
50005-0 0 0 0 0 0 0 0 0 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 10 10 10 38 38 38 86 86 86 50 50 50 6 6 6
50007-124 127 131 168 158 138 156 107 11 171 120 8 204 160 10 184 138 11 197 138 11 200 144 11
50008-206 145 10 206 145 10 197 138 11 198 179 130 195 195 195 198 198 198 170 170 170 14 14 14
50009-2 2 6 22 22 22 116 116 116 116 116 116 22 22 22 2 2 6 74 74 74 70 70 70
50010-30 30 30 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50011-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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-
50014-0 0 0 0 0 0 0 0 0 0 0 0 11 15 17 31 45 49 26 35 39 3 5 6
50015-0 0 0 7 12 13 27 40 45 18 25 28 0 0 0 0 0 0 0 0 0 0 0 0
50016-0 0 0 0 0 0 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 6 6 6 18 18 18 50 50 50 101 101 101 26 26 26 10 10 10
50018-124 131 137 190 190 190 168 158 138 156 107 11 197 138 11 200 144 11 197 138 11 192 133 9
50019-180 123 7 185 146 40 198 179 130 187 187 187 202 202 202 221 221 221 214 214 214 66 66 66
50020-2 2 6 2 2 6 50 50 50 62 62 62 6 6 6 2 2 6 10 10 10 90 90 90
50021-50 50 50 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50022-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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-
50025-0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 15 22 25 36 54 60 18 25 28
50026-0 0 0 21 30 33 27 40 45 2 3 3 0 0 0 0 0 0 0 0 0 0 0 0
50027-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50028-0 0 0 0 0 0 10 10 10 34 34 34 74 74 74 74 74 74 2 2 6 6 6 6
50029-151 151 151 198 198 198 190 190 190 168 158 138 148 132 55 156 107 11 156 107 11 169 125 40
50030-168 158 138 187 187 187 190 190 190 210 210 210 246 246 246 253 253 253 253 253 253 180 180 180
50031-6 6 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 62 62 62
50032-74 74 74 34 34 34 14 14 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50033-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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-
50036-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 27 40 45 35 52 58
50037-18 25 28 35 52 58 17 23 26 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50038-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50039-0 0 0 10 10 10 22 22 22 54 54 54 94 94 94 18 18 18 2 2 6 46 46 46
50040-234 234 234 221 221 221 190 190 190 190 190 190 190 190 190 187 187 187 187 187 187 190 190 190
50041-190 190 190 195 195 195 214 214 214 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
50042-82 82 82 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 14 14 14
50043-86 86 86 54 54 54 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0
50044-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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-
50047-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7 12 13 33 49 54
50048-52 72 81 36 54 60 6 8 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50049-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50050-6 6 6 18 18 18 46 46 46 90 90 90 46 46 46 18 18 18 6 6 6 180 180 180
50051-253 253 253 246 246 246 202 202 202 190 190 190 190 190 190 190 190 190 190 190 190 190 190 190
50052-202 202 202 231 231 231 250 250 250 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50053-202 202 202 14 14 14 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50054-42 42 42 86 86 86 42 42 42 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0
50055-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
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-
50058-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 12 17 20
50059-36 54 60 29 43 47 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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50061-14 14 14 38 38 38 74 74 74 66 66 66 2 2 6 6 6 6 90 90 90 250 250 250
50062-253 253 253 253 253 253 238 238 238 198 198 198 190 190 190 190 190 190 195 195 195 221 221 221
50063-246 246 246 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50064-253 253 253 82 82 82 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50065-2 2 6 78 78 78 70 70 70 34 34 34 14 14 14 6 6 6 0 0 0 0 0 0
50066-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50067-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50068-
50069-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50070-21 30 33 35 52 58 6 8 12 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 0 0 0 0 0 0 0 0 0 0 0 0 14 14 14
50072-34 34 34 66 66 66 78 78 78 6 6 6 2 2 6 18 18 18 218 218 218 253 253 253
50073-253 253 253 253 253 253 253 253 253 246 246 246 226 226 226 231 231 231 246 246 246 253 253 253
50074-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50075-253 253 253 180 180 180 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50076-2 2 6 18 18 18 90 90 90 62 62 62 30 30 30 10 10 10 0 0 0 0 0 0
50077-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50078-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50079-
50080-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50081-12 17 20 36 54 60 29 43 47 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 0 0 0 0 0 0 0 0 0 10 10 10 26 26 26
50083-58 58 58 90 90 90 18 18 18 2 2 6 2 2 6 106 106 106 253 253 253 253 253 253
50084-253 253 253 253 253 253 253 253 253 253 253 253 250 250 250 253 253 253 253 253 253 253 253 253
50085-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50086-253 253 253 231 231 231 18 18 18 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50087-2 2 6 2 2 6 18 18 18 94 94 94 54 54 54 26 26 26 10 10 10 0 0 0
50088-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50089-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50090-
50091-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50092-0 0 0 21 30 33 35 52 58 6 8 12 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 0 0 0 6 6 6 22 22 22 50 50 50
50094-90 90 90 26 26 26 2 2 6 2 2 6 14 14 14 195 195 195 250 250 250 253 253 253
50095-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50096-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50097-250 250 250 242 242 242 54 54 54 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50098-2 2 6 2 2 6 2 2 6 38 38 38 86 86 86 50 50 50 22 22 22 6 6 6
50099-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50100-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50101-
50102-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50103-0 0 0 0 0 0 12 17 20 36 54 60 29 43 47 0 0 0 0 0 0 0 0 0
50104-0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 14 14 14 38 38 38 82 82 82
50105-34 34 34 2 2 6 2 2 6 2 2 6 42 42 42 195 195 195 246 246 246 253 253 253
50106-253 253 253 253 253 253 253 253 253 250 250 250 242 242 242 242 242 242 250 250 250 253 253 253
50107-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 250 250 250 246 246 246 238 238 238
50108-226 226 226 231 231 231 101 101 101 6 6 6 2 2 6 2 2 6 2 2 6 2 2 6
50109-2 2 6 2 2 6 2 2 6 2 2 6 38 38 38 82 82 82 42 42 42 14 14 14
50110-6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50111-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50112-
50113-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50114-0 0 0 0 0 0 0 0 0 21 30 33 35 52 58 6 8 12 0 0 0 0 0 0
50115-0 0 0 0 0 0 0 0 0 0 0 0 10 10 10 26 26 26 62 62 62 66 66 66
50116-2 2 6 2 2 6 2 2 6 6 6 6 70 70 70 170 170 170 202 202 202 234 234 234
50117-246 246 246 250 250 250 250 250 250 238 238 238 226 226 226 231 231 231 238 238 238 250 250 250
50118-250 250 250 250 250 250 246 246 246 231 231 231 214 214 214 202 202 202 202 202 202 202 202 202
50119-198 198 198 202 202 202 180 180 180 18 18 18 2 2 6 2 2 6 2 2 6 2 2 6
50120-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 62 62 62 66 66 66 30 30 30
50121-10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50122-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50123-
50124-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50125-0 0 0 0 0 0 0 0 0 12 17 20 36 54 60 29 43 47 0 0 0 0 0 0
50126-0 0 0 0 0 0 0 0 0 0 0 0 14 14 14 42 42 42 82 82 82 18 18 18
50127-2 2 6 2 2 6 2 2 6 10 10 10 94 94 94 180 180 180 218 218 218 242 242 242
50128-250 250 250 253 253 253 253 253 253 250 250 250 234 234 234 253 253 253 253 253 253 253 253 253
50129-253 253 253 253 253 253 253 253 253 246 246 246 238 238 238 226 226 226 210 210 210 202 202 202
50130-195 195 195 195 195 195 210 210 210 151 151 151 6 6 6 14 14 14 50 50 50 14 14 14
50131-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 86 86 86 46 46 46
50132-18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50133-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50134-
50135-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50136-0 0 0 0 0 0 0 0 0 0 0 0 21 30 33 35 52 58 6 8 12 0 0 0
50137-0 0 0 0 0 0 0 0 0 6 6 6 22 22 22 54 54 54 70 70 70 2 2 6
50138-2 2 6 10 10 10 2 2 6 22 22 22 170 170 170 231 231 231 250 250 250 253 253 253
50139-253 253 253 253 253 253 253 253 253 250 250 250 242 242 242 253 253 253 253 253 253 253 253 253
50140-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 246 246 246
50141-231 231 231 202 202 202 198 198 198 226 226 226 94 94 94 2 2 6 6 6 6 38 38 38
50142-30 30 30 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 62 62 62 66 66 66
50143-26 26 26 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50144-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50145-
50146-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50147-0 0 0 0 0 0 0 0 0 0 0 0 6 8 8 33 49 54 29 43 47 6 8 12
50148-0 0 0 0 0 0 0 0 0 10 10 10 30 30 30 74 74 74 50 50 50 2 2 6
50149-26 26 26 26 26 26 2 2 6 106 106 106 238 238 238 253 253 253 253 253 253 253 253 253
50150-253 253 253 253 253 253 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 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50152-253 253 253 246 246 246 218 218 218 202 202 202 210 210 210 14 14 14 2 2 6 2 2 6
50153-30 30 30 22 22 22 2 2 6 2 2 6 2 2 6 2 2 6 18 18 18 86 86 86
50154-42 42 42 14 14 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50155-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50156-
50157-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50158-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 12 17 20 33 49 54 17 23 26
50159-0 0 0 0 0 0 0 0 0 14 14 14 42 42 42 90 90 90 22 22 22 2 2 6
50160-42 42 42 2 2 6 18 18 18 218 218 218 253 253 253 253 253 253 253 253 253 253 253 253
50161-253 253 253 253 253 253 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 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50163-253 253 253 253 253 253 250 250 250 221 221 221 218 218 218 101 101 101 2 2 6 14 14 14
50164-18 18 18 38 38 38 10 10 10 2 2 6 2 2 6 2 2 6 2 2 6 78 78 78
50165-58 58 58 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50166-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50167-
50168-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50169-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 15 22 25 36 54 60
50170-0 0 0 0 0 0 0 0 0 18 18 18 54 54 54 82 82 82 2 2 6 26 26 26
50171-22 22 22 2 2 6 124 127 131 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50172-253 253 253 253 253 253 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 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50174-253 253 253 253 253 253 253 253 253 250 250 250 238 238 238 198 198 198 6 6 6 38 38 38
50175-58 58 58 26 26 26 38 38 38 2 2 6 2 2 6 2 2 6 2 2 6 46 46 46
50176-78 78 78 30 30 30 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50177-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50178-
50179-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50180-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 21 30 33
50181-36 54 60 0 0 0 0 0 0 30 30 30 74 74 74 58 58 58 2 2 6 42 42 42
50182-2 2 6 22 22 22 231 231 231 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50183-253 253 253 253 253 253 253 253 253 250 250 250 253 253 253 253 253 253 253 253 253 253 253 253
50184-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50185-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 246 246 246 46 46 46 38 38 38
50186-42 42 42 14 14 14 38 38 38 14 14 14 2 2 6 2 2 6 2 2 6 6 6 6
50187-86 86 86 46 46 46 14 14 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50188-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50189-
50190-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50191-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-36 54 60 0 0 0 0 0 0 42 42 42 90 90 90 18 18 18 18 18 18 26 26 26
50193-2 2 6 116 116 116 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50194-253 253 253 253 253 253 250 250 250 238 238 238 253 253 253 253 253 253 253 253 253 253 253 253
50195-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50196-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 94 94 94 6 6 6
50197-2 2 6 2 2 6 10 10 10 34 34 34 2 2 6 2 2 6 2 2 6 2 2 6
50198-74 74 74 58 58 58 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0
50199-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50200-
50201-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50202-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 36 54 60 26 26 26 66 66 66 82 82 82 2 2 6 38 38 38 6 6 6
50204-14 14 14 210 210 210 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50205-253 253 253 253 253 253 246 246 246 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
50206-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50207-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 151 151 151 2 2 6
50208-2 2 6 2 2 6 2 2 6 46 46 46 2 2 6 2 2 6 2 2 6 2 2 6
50209-42 42 42 74 74 74 30 30 30 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0
50210-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50211-
50212-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50213-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-6 6 6 36 54 60 21 30 33 90 90 90 26 26 26 6 6 6 42 42 42 2 2 6
50215-74 74 74 250 250 250 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50216-253 253 253 253 253 253 242 242 242 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
50217-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50218-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 180 180 180 2 2 6
50219-2 2 6 2 2 6 2 2 6 46 46 46 2 2 6 2 2 6 2 2 6 2 2 6
50220-10 10 10 86 86 86 38 38 38 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0
50221-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50222-
50223-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50224-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-10 10 10 26 26 26 36 54 60 82 82 82 2 2 6 22 22 22 18 18 18 2 2 6
50226-151 151 151 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50227-253 253 253 253 253 253 234 234 234 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
50228-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50229-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 202 202 202 2 2 6
50230-2 2 6 2 2 6 2 2 6 38 38 38 2 2 6 2 2 6 2 2 6 2 2 6
50231-6 6 6 86 86 86 46 46 46 14 14 14 0 0 0 0 0 0 0 0 0 0 0 0
50232-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50233-
50234-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50235-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50236-18 18 18 46 46 46 86 86 86 36 54 60 2 2 6 34 34 34 10 10 10 6 6 6
50237-210 210 210 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50238-253 253 253 253 253 253 234 234 234 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
50239-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50240-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 221 221 221 6 6 6
50241-2 2 6 2 2 6 6 6 6 30 30 30 2 2 6 2 2 6 2 2 6 2 2 6
50242-2 2 6 82 82 82 54 54 54 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0
50243-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50244-
50245-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50246-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
50247-26 26 26 66 66 66 62 62 62 2 2 6 2 2 6 38 38 38 10 10 10 26 26 26
50248-238 238 238 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50249-253 253 253 253 253 253 231 231 231 238 238 238 253 253 253 253 253 253 253 253 253 253 253 253
50250-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50251-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 231 231 231 6 6 6
50252-2 2 6 2 2 6 10 10 10 30 30 30 2 2 6 2 2 6 2 2 6 2 2 6
50253-2 2 6 66 66 66 58 58 58 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0
50254-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50255-
50256-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50257-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
50258-38 38 38 78 78 78 6 6 6 2 2 6 2 2 6 46 46 46 14 14 14 42 42 42
50259-246 246 246 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50260-253 253 253 253 253 253 231 231 231 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
50261-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50262-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 234 234 234 10 10 10
50263-2 2 6 2 2 6 22 22 22 14 14 14 2 2 6 2 2 6 2 2 6 2 2 6
50264-2 2 6 66 66 66 62 62 62 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0
50265-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50266-
50267-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50268-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 18 18 18
50269-50 50 50 74 74 74 2 2 6 2 2 6 14 14 14 70 70 70 34 34 34 62 62 62
50270-250 250 250 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50271-253 253 253 253 253 253 231 231 231 246 246 246 253 253 253 253 253 253 253 253 253 253 253 253
50272-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50273-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 234 234 234 14 14 14
50274-2 2 6 2 2 6 30 30 30 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50275-2 2 6 66 66 66 62 62 62 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0
50276-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50277-
50278-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50279-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 18 18 18
50280-54 54 54 62 62 62 2 2 6 2 2 6 2 2 6 30 30 30 46 46 46 70 70 70
50281-250 250 250 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50282-253 253 253 253 253 253 231 231 231 246 246 246 253 253 253 253 253 253 253 253 253 253 253 253
50283-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50284-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 226 226 226 10 10 10
50285-2 2 6 6 6 6 30 30 30 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50286-2 2 6 66 66 66 58 58 58 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0
50287-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50288-
50289-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50290-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 22 22 22
50291-58 58 58 62 62 62 2 2 6 2 2 6 2 2 6 2 2 6 30 30 30 78 78 78
50292-250 250 250 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50293-253 253 253 253 253 253 231 231 231 246 246 246 253 253 253 253 253 253 253 253 253 253 253 253
50294-253 253 253 253 253 253 253 253 253 253 253 253 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 202 202 202 2 2 6
50296-22 22 22 34 34 34 20 16 6 22 22 22 26 26 26 18 18 18 6 6 6 2 2 6
50297-2 2 6 82 82 82 54 54 54 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0
50298-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50299-
50300-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50301-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 26 26 26
50302-62 62 62 106 106 106 63 55 20 184 138 11 204 160 10 121 92 8 6 6 6 62 62 62
50303-238 238 238 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50304-253 253 253 253 253 253 231 231 231 246 246 246 253 253 253 253 253 253 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 151 151 151 18 18 18
50307-14 14 14 2 2 6 2 2 6 2 2 6 6 6 6 18 18 18 66 66 66 38 38 38
50308-6 6 6 94 94 94 50 50 50 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0
50309-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50310-
50311-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50312-0 0 0 0 0 0 0 0 0 6 6 6 10 10 10 10 10 10 18 18 18 38 38 38
50313-78 78 78 138 132 106 216 158 10 242 186 14 246 190 14 246 190 14 156 118 10 10 10 10
50314-90 90 90 238 238 238 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50315-253 253 253 253 253 253 231 231 231 250 250 250 253 253 253 253 253 253 253 253 253 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 246 230 190 214 187 87 214 187 87 185 146 40 35 31 12
50318-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 38 38 38 46 46 46
50319-26 26 26 106 106 106 54 54 54 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0
50320-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50321-
50322-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50323-0 0 0 6 6 6 14 14 14 22 22 22 30 30 30 38 38 38 50 50 50 70 70 70
50324-106 106 106 185 146 40 226 170 11 242 186 14 246 190 14 246 190 14 246 190 14 154 114 10
50325-6 6 6 74 74 74 226 226 226 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50326-253 253 253 253 253 253 231 231 231 250 250 250 253 253 253 253 253 253 253 253 253 253 253 253
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 237 201 50 241 196 14 241 208 19 232 195 16 35 31 12
50329-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 30 30 30 26 26 26
50330-204 160 10 165 152 80 66 66 66 26 26 26 6 6 6 0 0 0 0 0 0 0 0 0
50331-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50332-
50333-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50334-6 6 6 18 18 18 38 38 38 58 58 58 78 78 78 86 86 86 101 101 101 124 127 131
50335-174 140 55 210 150 10 234 174 13 246 186 14 246 190 14 246 190 14 246 190 14 237 188 10
50336-98 70 6 2 2 6 46 46 46 198 198 198 253 253 253 253 253 253 253 253 253 253 253 253
50337-253 253 253 253 253 253 234 234 234 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
50338-253 253 253 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 214 187 87 242 186 14 241 196 14 204 160 10 20 16 6
50340-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 121 92 8
50341-238 202 15 232 195 16 82 82 82 34 34 34 10 10 10 0 0 0 0 0 0 0 0 0
50342-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50343-
50344-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50345-14 14 14 38 38 38 70 70 70 148 132 55 185 146 40 200 144 11 197 138 11 197 138 11
50346-213 154 11 226 170 11 242 186 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50347-220 174 15 35 31 12 2 2 6 22 22 22 151 151 151 250 250 250 253 253 253 253 253 253
50348-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50349-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50350-253 253 253 250 250 250 242 242 242 214 187 87 239 182 13 237 188 10 213 154 11 35 31 12
50351-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 62 42 6 220 174 15
50352-237 188 10 237 188 10 113 101 86 42 42 42 14 14 14 0 0 0 0 0 0 0 0 0
50353-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50354-
50355-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50356-22 22 22 54 54 54 148 132 55 213 154 11 226 170 11 230 174 11 226 170 11 226 170 11
50357-236 178 12 242 186 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50358-241 196 14 184 138 11 10 10 10 2 2 6 6 6 6 116 116 116 242 242 242 253 253 253
50359-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50360-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50361-253 253 253 231 231 231 198 198 198 213 164 39 236 178 12 236 178 12 210 150 10 137 92 6
50362-20 16 6 2 2 6 2 2 6 2 2 6 6 6 6 62 42 6 200 144 11 236 178 12
50363-239 182 13 239 182 13 124 112 88 58 58 58 22 22 22 6 6 6 0 0 0 0 0 0
50364-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50365-
50366-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
50367-30 30 30 70 70 70 169 125 40 226 170 11 239 182 13 242 186 14 242 186 14 246 186 14
50368-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50369-246 190 14 232 195 16 98 70 6 2 2 6 2 2 6 2 2 6 66 66 66 221 221 221
50370-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50371-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50372-253 253 253 202 202 202 198 198 198 213 164 39 230 174 11 230 174 11 216 158 10 192 133 9
50373-163 110 8 120 80 7 98 70 6 120 80 7 167 114 7 197 138 11 226 170 11 239 182 13
50374-242 186 14 242 186 14 165 152 80 78 78 78 34 34 34 14 14 14 6 6 6 0 0 0
50375-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50376-
50377-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50378-30 30 30 78 78 78 185 146 40 226 170 11 239 182 13 246 190 14 246 190 14 246 190 14
50379-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50380-246 190 14 241 196 14 204 160 10 20 16 6 2 2 6 2 2 6 2 2 6 38 38 38
50381-218 218 218 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50382-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50383-250 250 250 202 202 202 198 198 198 213 164 39 226 170 11 236 178 12 224 166 10 210 150 10
50384-200 144 11 197 138 11 192 133 9 197 138 11 210 150 10 226 170 11 242 186 14 246 190 14
50385-246 190 14 246 186 14 220 174 15 124 112 88 62 62 62 30 30 30 14 14 14 6 6 6
50386-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50387-
50388-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
50389-30 30 30 78 78 78 174 140 55 224 166 10 239 182 13 246 190 14 246 190 14 246 190 14
50390-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50391-246 190 14 246 190 14 241 196 14 139 102 15 2 2 6 2 2 6 2 2 6 2 2 6
50392-78 78 78 250 250 250 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 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-250 250 250 214 214 214 198 198 198 185 146 40 219 162 10 236 178 12 234 174 13 224 166 10
50395-216 158 10 213 154 11 213 154 11 216 158 10 226 170 11 239 182 13 246 190 14 246 190 14
50396-246 190 14 246 190 14 242 186 14 213 164 39 101 101 101 58 58 58 30 30 30 14 14 14
50397-6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50398-
50399-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
50400-30 30 30 74 74 74 174 140 55 216 158 10 236 178 12 246 190 14 246 190 14 246 190 14
50401-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50402-246 190 14 246 190 14 241 196 14 230 187 11 62 42 6 2 2 6 2 2 6 2 2 6
50403-22 22 22 238 238 238 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
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 226 226 226 187 187 187 169 125 40 216 158 10 236 178 12 239 182 13 236 178 12
50406-230 174 11 226 170 11 226 170 11 230 174 11 236 178 12 242 186 14 246 190 14 246 190 14
50407-246 190 14 246 190 14 246 186 14 239 182 13 213 164 39 106 106 106 66 66 66 34 34 34
50408-14 14 14 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50409-
50410-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50411-26 26 26 70 70 70 149 139 69 213 154 11 236 178 12 246 190 14 246 190 14 246 190 14
50412-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50413-246 190 14 246 190 14 246 190 14 241 196 14 190 146 13 20 16 6 2 2 6 2 2 6
50414-46 46 46 246 246 246 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50415-253 253 253 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 221 221 221 86 86 86 156 107 11 216 158 10 236 178 12 242 186 14 246 186 14
50417-242 186 14 239 182 13 239 182 13 242 186 14 242 186 14 246 186 14 246 190 14 246 190 14
50418-246 190 14 246 190 14 246 190 14 246 190 14 242 186 14 220 174 15 149 139 69 66 66 66
50419-30 30 30 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50420-
50421-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50422-26 26 26 70 70 70 149 139 69 210 150 10 236 178 12 246 190 14 246 190 14 246 190 14
50423-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50424-246 190 14 246 190 14 246 190 14 246 190 14 232 195 16 121 92 8 34 34 34 106 106 106
50425-221 221 221 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50426-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50427-242 242 242 82 82 82 20 16 6 163 110 8 216 158 10 236 178 12 242 186 14 246 190 14
50428-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 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 242 186 14 149 139 69
50430-46 46 46 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50431-
50432-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
50433-30 30 30 78 78 78 149 139 69 210 150 10 236 178 12 246 186 14 246 190 14 246 190 14
50434-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50435-246 190 14 246 190 14 246 190 14 246 190 14 241 196 14 220 174 15 198 179 130 253 253 253
50436-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50437-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 218 218 218
50438-58 58 58 2 2 6 20 16 6 167 114 7 216 158 10 236 178 12 246 186 14 246 190 14
50439-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50440-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 186 14 242 186 14 185 146 40
50441-54 54 54 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50442-
50443-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 14 14 14
50444-38 38 38 86 86 86 169 125 40 213 154 11 236 178 12 246 186 14 246 190 14 246 190 14
50445-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50446-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 232 195 16 190 146 13 214 214 214
50447-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50448-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 250 250 250 170 170 170 26 26 26
50449-2 2 6 2 2 6 35 31 12 163 110 8 219 162 10 239 182 13 246 186 14 246 190 14
50450-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50451-246 190 14 246 190 14 246 190 14 246 190 14 246 186 14 236 178 12 224 166 10 149 139 69
50452-46 46 46 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50453-
50454-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 18 18 18
50455-50 50 50 113 101 86 192 133 9 224 166 10 242 186 14 246 190 14 246 190 14 246 190 14
50456-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50457-246 190 14 246 190 14 246 190 14 246 190 14 242 186 14 230 187 11 204 160 10 133 118 54
50458-226 226 226 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50459-253 253 253 253 253 253 253 253 253 253 253 253 198 198 198 66 66 66 2 2 6 2 2 6
50460-2 2 6 2 2 6 62 42 6 156 107 11 219 162 10 239 182 13 246 186 14 246 190 14
50461-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50462-246 190 14 246 190 14 246 190 14 242 186 14 234 174 13 213 154 11 148 132 55 66 66 66
50463-30 30 30 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50464-
50465-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 22 22 22
50466-58 58 58 148 132 55 206 145 10 234 174 13 242 186 14 246 186 14 246 190 14 246 190 14
50467-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50468-246 190 14 246 190 14 246 190 14 246 190 14 246 186 14 236 178 12 204 160 10 163 110 8
50469-62 42 6 124 131 137 218 218 218 250 250 250 253 253 253 253 253 253 253 253 253 250 250 250
50470-242 242 242 210 210 210 151 151 151 66 66 66 6 6 6 2 2 6 2 2 6 2 2 6
50471-2 2 6 2 2 6 62 42 6 163 110 8 216 158 10 236 178 12 246 190 14 246 190 14
50472-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50473-246 190 14 239 182 13 230 174 11 216 158 10 185 146 40 124 112 88 70 70 70 38 38 38
50474-18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50475-
50476-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 22 22 22
50477-62 62 62 169 125 40 206 145 10 224 166 10 236 178 12 239 182 13 242 186 14 242 186 14
50478-246 186 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50479-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 236 178 12 216 158 10 171 120 8
50480-85 57 6 2 2 6 6 6 6 30 30 30 54 54 54 62 62 62 50 50 50 38 38 38
50481-14 14 14 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50482-2 2 6 6 6 6 85 57 6 167 114 7 213 154 11 236 178 12 246 190 14 246 190 14
50483-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 242 186 14 239 182 13 239 182 13
50484-230 174 11 210 150 10 174 140 55 124 112 88 82 82 82 54 54 54 34 34 34 18 18 18
50485-6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50486-
50487-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 18 18 18
50488-50 50 50 169 125 40 192 133 9 200 144 11 216 158 10 219 162 10 224 166 10 226 170 11
50489-230 174 11 236 178 12 239 182 13 239 182 13 242 186 14 246 186 14 246 190 14 246 190 14
50490-246 190 14 246 190 14 246 190 14 246 190 14 246 186 14 230 174 11 210 150 10 163 110 8
50491-104 69 6 10 10 10 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50492-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50493-2 2 6 6 6 6 85 57 6 167 114 7 206 145 10 230 174 11 242 186 14 246 190 14
50494-246 190 14 246 190 14 246 186 14 242 186 14 239 182 13 230 174 11 224 166 10 213 154 11
50495-169 125 40 124 112 88 86 86 86 58 58 58 38 38 38 22 22 22 10 10 10 6 6 6
50496-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50497-
50498-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 14 14 14
50499-34 34 34 70 70 70 133 118 54 169 125 40 167 114 7 180 123 7 192 133 9 197 138 11
50500-200 144 11 206 145 10 213 154 11 219 162 10 224 166 10 230 174 11 239 182 13 242 186 14
50501-246 186 14 246 186 14 246 186 14 246 186 14 239 182 13 216 158 10 184 138 11 152 99 6
50502-104 69 6 20 16 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50503-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50504-2 2 6 6 6 6 85 57 6 152 99 6 192 133 9 219 162 10 236 178 12 239 182 13
50505-246 186 14 242 186 14 239 182 13 236 178 12 224 166 10 206 145 10 192 133 9 148 132 55
50506-94 94 94 62 62 62 42 42 42 22 22 22 14 14 14 6 6 6 0 0 0 0 0 0
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-
50509-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50510-18 18 18 34 34 34 58 58 58 78 78 78 101 98 89 124 112 88 133 118 54 156 107 11
50511-163 110 8 167 114 7 171 120 8 180 123 7 184 138 11 197 138 11 210 150 10 219 162 10
50512-226 170 11 236 178 12 236 178 12 234 174 13 219 162 10 197 138 11 163 110 8 134 84 6
50513-85 57 6 10 10 10 2 2 6 2 2 6 18 18 18 38 38 38 38 38 38 38 38 38
50514-38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 26 26 26 2 2 6
50515-2 2 6 6 6 6 62 42 6 137 92 6 171 120 8 200 144 11 219 162 10 230 174 11
50516-234 174 13 230 174 11 219 162 10 210 150 10 192 133 9 163 110 8 124 112 88 82 82 82
50517-50 50 50 30 30 30 14 14 14 6 6 6 0 0 0 0 0 0 0 0 0 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-
50520-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50521-6 6 6 14 14 14 22 22 22 34 34 34 42 42 42 58 58 58 74 74 74 86 86 86
50522-101 98 89 113 101 86 133 118 54 121 92 8 137 92 6 152 99 6 163 110 8 180 123 7
50523-184 138 11 197 138 11 206 145 10 200 144 11 180 123 7 156 107 11 134 84 6 104 69 6
50524-62 42 6 54 54 54 106 106 106 101 98 89 86 86 86 82 82 82 78 78 78 78 78 78
50525-78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 82 82 82 86 86 86 94 94 94
50526-106 106 106 101 101 101 90 61 47 120 80 7 156 107 11 180 123 7 192 133 9 200 144 11
50527-206 145 10 200 144 11 192 133 9 171 120 8 139 102 15 113 101 86 70 70 70 42 42 42
50528-22 22 22 10 10 10 0 0 0 0 0 0 0 0 0 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-
50531-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50532-0 0 0 0 0 0 6 6 6 10 10 10 14 14 14 22 22 22 30 30 30 38 38 38
50533-50 50 50 62 62 62 74 74 74 90 90 90 101 98 89 113 101 86 121 92 8 120 80 7
50534-137 92 6 152 99 6 152 99 6 152 99 6 134 84 6 120 80 7 98 70 6 88 55 22
50535-101 98 89 82 82 82 58 58 58 46 46 46 38 38 38 34 34 34 34 34 34 34 34 34
50536-34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 38 38 38 42 42 42
50537-54 54 54 82 82 82 94 86 71 85 57 6 134 84 6 156 107 11 167 114 7 171 120 8
50538-171 120 8 167 114 7 152 99 6 121 92 8 101 98 89 62 62 62 34 34 34 18 18 18
50539-6 6 6 0 0 0 0 0 0 0 0 0 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-
50542-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50543-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 6 6 6 10 10 10
50544-18 18 18 22 22 22 30 30 30 42 42 42 50 50 50 66 66 66 86 86 86 101 98 89
50545-94 86 71 98 70 6 104 69 6 104 69 6 104 69 6 85 57 6 88 55 22 90 90 90
50546-62 62 62 38 38 38 22 22 22 14 14 14 10 10 10 10 10 10 10 10 10 10 10 10
50547-10 10 10 10 10 10 6 6 6 10 10 10 10 10 10 10 10 10 10 10 10 14 14 14
50548-22 22 22 42 42 42 70 70 70 94 86 71 85 57 6 104 69 6 120 80 7 137 92 6
50549-134 84 6 120 80 7 94 86 71 86 86 86 58 58 58 30 30 30 14 14 14 6 6 6
50550-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50551-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50552-
50553-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50554-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50555-0 0 0 6 6 6 10 10 10 14 14 14 18 18 18 26 26 26 38 38 38 54 54 54
50556-70 70 70 86 86 86 94 86 71 94 86 71 94 86 71 86 86 86 74 74 74 50 50 50
50557-30 30 30 14 14 14 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50558-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50559-6 6 6 18 18 18 34 34 34 58 58 58 82 82 82 94 86 71 94 86 71 94 86 71
50560-94 86 71 94 86 71 74 74 74 50 50 50 26 26 26 14 14 14 6 6 6 0 0 0
50561-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50562-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50563-
50564-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50565-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50566-0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 6 6 6 14 14 14 18 18 18
50567-30 30 30 38 38 38 46 46 46 54 54 54 50 50 50 42 42 42 30 30 30 18 18 18
50568-10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50569-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50570-0 0 0 6 6 6 14 14 14 26 26 26 38 38 38 50 50 50 58 58 58 58 58 58
50571-54 54 54 42 42 42 30 30 30 18 18 18 10 10 10 0 0 0 0 0 0 0 0 0
50572-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50573-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50574-
50575-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50576-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50577-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50578-6 6 6 10 10 10 14 14 14 18 18 18 18 18 18 14 14 14 10 10 10 6 6 6
50579-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50580-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50581-0 0 0 0 0 0 0 0 0 6 6 6 14 14 14 18 18 18 22 22 22 22 22 22
50582-18 18 18 14 14 14 10 10 10 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0
50583-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50584-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50585-
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 4 4 4 4 4 4 4 4 4 4 4 4
50599+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 4 4 4 4 4 4 4 4 4 4 4 4
50613+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 4 4 4 4 4 4 4 4 4 4 4 4
50627+4 4 4 4 4 4
50628+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50629+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50630+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50631+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50632+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50633+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50634+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50635+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50636+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50637+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50638+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50639+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50640+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50641+4 4 4 4 4 4
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 4 4 4 4 4 4 4 4 4 4 4 4
50646+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50647+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50648+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
50651+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50652+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50653+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50654+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50655+4 4 4 4 4 4
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+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50660+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50661+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50662+4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
50665+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50666+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50667+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50668+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50669+4 4 4 4 4 4
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 4 4 4 4 4 4 4 4 4 4 4 4
50673+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50674+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
50675+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 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 4 4 4 4 4 4
50678+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50679+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
50680+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
50681+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
50682+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50683+4 4 4 4 4 4
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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50687+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50688+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
50689+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
50690+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50691+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50692+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50693+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
50694+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
50695+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
50696+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50697+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 4 4 4
50700+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50701+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50702+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
50703+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
50704+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
50705+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50706+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50707+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
50708+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
50709+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
50710+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
50711+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 4 4 4 4 4 4
50714+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50715+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
50716+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
50717+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
50718+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
50719+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50720+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
50721+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
50722+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
50723+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
50724+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
50725+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 4 4 4 4 4 4 4 4 4
50728+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50729+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
50730+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
50731+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
50732+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
50733+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
50734+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
50735+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
50736+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
50737+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
50738+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
50739+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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50742+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
50743+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
50744+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
50745+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
50746+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
50747+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
50748+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
50749+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
50750+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
50751+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
50752+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
50753+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+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50756+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
50757+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
50758+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
50759+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
50760+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
50761+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
50762+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
50763+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
50764+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
50765+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
50766+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
50767+4 4 4 4 4 4
50768+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50769+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50770+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
50771+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
50772+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
50773+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
50774+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
50775+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
50776+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
50777+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
50778+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
50779+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
50780+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
50781+4 4 4 4 4 4
50782+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50783+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50784+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
50785+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
50786+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
50787+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
50788+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
50789+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
50790+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
50791+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
50792+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
50793+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
50794+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
50795+4 4 4 4 4 4
50796+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50797+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50798+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
50799+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
50800+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
50801+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
50802+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
50803+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
50804+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
50805+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
50806+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
50807+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
50808+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
50809+4 4 4 4 4 4
50810+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50811+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
50812+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
50813+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
50814+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
50815+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
50816+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
50817+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
50818+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
50819+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
50820+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
50821+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
50822+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
50823+4 4 4 4 4 4
50824+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50825+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
50826+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
50827+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
50828+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
50829+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
50830+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
50831+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
50832+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
50833+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
50834+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
50835+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
50836+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
50837+0 0 0 4 4 4
50838+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
50839+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
50840+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
50841+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
50842+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
50843+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
50844+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
50845+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
50846+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
50847+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
50848+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
50849+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
50850+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
50851+2 0 0 0 0 0
50852+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
50853+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
50854+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
50855+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
50856+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
50857+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
50858+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
50859+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
50860+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
50861+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
50862+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
50863+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
50864+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
50865+37 38 37 0 0 0
50866+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
50867+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
50868+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
50869+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
50870+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
50871+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
50872+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
50873+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
50874+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
50875+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
50876+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
50877+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
50878+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
50879+85 115 134 4 0 0
50880+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
50881+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
50882+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
50883+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
50884+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
50885+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
50886+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
50887+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
50888+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
50889+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
50890+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
50891+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
50892+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
50893+60 73 81 4 0 0
50894+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
50895+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
50896+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
50897+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
50898+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
50899+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
50900+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
50901+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
50902+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
50903+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
50904+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
50905+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
50906+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
50907+16 19 21 4 0 0
50908+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
50909+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
50910+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
50911+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
50912+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
50913+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
50914+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
50915+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
50916+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
50917+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
50918+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
50919+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
50920+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
50921+4 0 0 4 3 3
50922+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
50923+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
50924+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
50925+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
50926+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
50927+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
50928+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
50929+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
50930+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
50931+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
50932+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
50933+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
50934+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
50935+3 2 2 4 4 4
50936+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
50937+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
50938+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
50939+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
50940+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
50941+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
50942+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50943+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
50944+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
50945+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
50946+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
50947+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
50948+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
50949+4 4 4 4 4 4
50950+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
50951+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
50952+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
50953+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
50954+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
50955+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
50956+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
50957+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
50958+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
50959+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
50960+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
50961+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
50962+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
50963+4 4 4 4 4 4
50964+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
50965+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
50966+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
50967+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
50968+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
50969+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
50970+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
50971+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
50972+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
50973+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
50974+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
50975+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
50976+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
50977+5 5 5 5 5 5
50978+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
50979+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
50980+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
50981+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
50982+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
50983+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
50984+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
50985+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
50986+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
50987+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
50988+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
50989+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
50990+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
50991+5 5 5 4 4 4
50992+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
50993+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
50994+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
50995+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
50996+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
50997+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
50998+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
50999+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
51000+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
51001+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
51002+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
51003+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
51004+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51005+4 4 4 4 4 4
51006+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
51007+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
51008+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
51009+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
51010+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
51011+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
51012+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
51013+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
51014+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
51015+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
51016+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
51017+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
51018+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51019+4 4 4 4 4 4
51020+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
51021+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
51022+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
51023+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
51024+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
51025+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
51026+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
51027+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
51028+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
51029+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
51030+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 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 4 4 4 4 4 4 4 4 4 4 4 4
51033+4 4 4 4 4 4
51034+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
51035+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
51036+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
51037+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
51038+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
51039+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
51040+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
51041+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
51042+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
51043+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
51044+6 6 6 4 0 0 4 0 0 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 4 4 4 4 4 4 4 4 4 4 4 4
51047+4 4 4 4 4 4
51048+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
51049+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
51050+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
51051+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
51052+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
51053+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
51054+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
51055+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
51056+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
51057+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
51058+4 0 0 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
51061+4 4 4 4 4 4
51062+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
51063+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
51064+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
51065+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
51066+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
51067+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
51068+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
51069+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
51070+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
51071+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
51072+6 6 6 4 0 0 6 6 6 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 4 4 4 4 4 4 4 4 4 4 4 4
51075+4 4 4 4 4 4
51076+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
51077+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
51078+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
51079+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
51080+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
51081+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
51082+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
51083+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
51084+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
51085+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
51086+4 0 0 3 2 2 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
51089+4 4 4 4 4 4
51090+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
51091+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
51092+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
51093+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
51094+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
51095+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
51096+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
51097+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
51098+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
51099+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
51100+4 0 0 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
51103+4 4 4 4 4 4
51104+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
51105+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
51106+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
51107+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
51108+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
51109+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
51110+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
51111+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
51112+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
51113+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
51114+4 0 0 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
51117+4 4 4 4 4 4
51118+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
51119+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
51120+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
51121+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
51122+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
51123+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
51124+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
51125+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
51126+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
51127+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
51128+4 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
51131+4 4 4 4 4 4
51132+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
51133+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
51134+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
51135+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
51136+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
51137+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
51138+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
51139+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
51140+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
51141+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51142+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
51145+4 4 4 4 4 4
51146+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
51147+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
51148+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
51149+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
51150+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
51151+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
51152+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
51153+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
51154+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
51155+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51156+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
51159+4 4 4 4 4 4
51160+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
51161+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
51162+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
51163+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
51164+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
51165+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
51166+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
51167+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
51168+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
51169+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51170+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
51173+4 4 4 4 4 4
51174+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
51175+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
51176+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
51177+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
51178+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
51179+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
51180+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
51181+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
51182+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
51183+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51184+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
51187+4 4 4 4 4 4
51188+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
51189+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
51190+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
51191+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
51192+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
51193+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
51194+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
51195+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
51196+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
51197+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51198+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
51201+4 4 4 4 4 4
51202+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
51203+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
51204+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
51205+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
51206+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
51207+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
51208+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
51209+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
51210+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
51211+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51212+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
51215+4 4 4 4 4 4
51216+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
51217+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
51218+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
51219+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
51220+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
51221+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
51222+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
51223+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
51224+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
51225+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51226+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
51229+4 4 4 4 4 4
51230+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
51231+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
51232+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
51233+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
51234+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
51235+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
51236+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
51237+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
51238+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
51239+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51240+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
51243+4 4 4 4 4 4
51244+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
51245+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
51246+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
51247+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
51248+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
51249+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
51250+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
51251+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
51252+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
51253+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51254+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
51257+4 4 4 4 4 4
51258+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
51259+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
51260+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
51261+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
51262+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
51263+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
51264+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
51265+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
51266+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
51267+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51268+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
51271+4 4 4 4 4 4
51272+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
51273+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
51274+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
51275+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
51276+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
51277+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
51278+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
51279+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
51280+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
51281+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51282+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
51285+4 4 4 4 4 4
51286+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
51287+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
51288+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
51289+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
51290+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
51291+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
51292+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
51293+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
51294+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
51295+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51296+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
51299+4 4 4 4 4 4
51300+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
51301+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
51302+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
51303+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
51304+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
51305+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
51306+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
51307+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
51308+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
51309+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51310+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
51313+4 4 4 4 4 4
51314+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
51315+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
51316+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
51317+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
51318+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
51319+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
51320+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
51321+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
51322+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
51323+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51324+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
51327+4 4 4 4 4 4
51328+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
51329+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
51330+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
51331+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
51332+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
51333+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
51334+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
51335+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
51336+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
51337+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51338+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
51341+4 4 4 4 4 4
51342+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
51343+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
51344+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
51345+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
51346+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
51347+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
51348+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
51349+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
51350+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
51351+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
51352+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
51355+4 4 4 4 4 4
51356+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
51357+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
51358+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
51359+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
51360+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
51361+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
51362+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
51363+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
51364+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
51365+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
51366+0 0 0 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 4 4 4 4 4 4 4 4 4 4 4 4
51369+4 4 4 4 4 4
51370+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
51371+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
51372+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
51373+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
51374+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
51375+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
51376+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51377+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
51378+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
51379+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
51380+4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
51383+4 4 4 4 4 4
51384+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
51385+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
51386+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
51387+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
51388+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
51389+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
51390+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
51391+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
51392+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
51393+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
51394+5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
51397+4 4 4 4 4 4
51398+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
51399+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
51400+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
51401+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
51402+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
51403+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
51404+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
51405+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
51406+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
51407+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
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 4 4 4 4 4 4 4 4 4 4 4 4
51411+4 4 4 4 4 4
51412+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
51413+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
51414+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
51415+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
51416+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
51417+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
51418+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
51419+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
51420+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
51421+13 16 17 4 0 0 4 0 0 4 3 3 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 4 4 4 4 4 4 4 4 4 4 4 4
51425+4 4 4 4 4 4
51426+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
51427+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
51428+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
51429+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
51430+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
51431+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
51432+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
51433+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
51434+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
51435+4 0 0 4 0 0 5 5 5 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
51439+4 4 4 4 4 4
51440+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
51441+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
51442+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
51443+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
51444+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
51445+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
51446+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
51447+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
51448+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
51449+4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
51453+4 4 4 4 4 4
51454+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
51455+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
51456+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
51457+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
51458+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
51459+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
51460+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
51461+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
51462+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
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 4 4 4 4 4 4 4 4 4 4 4 4
51467+4 4 4 4 4 4
51468+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
51469+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
51470+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
51471+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
51472+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
51473+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
51474+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
51475+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
51476+4 0 0 4 0 0 4 0 0 6 6 6 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 4 4 4 4 4 4 4 4 4 4 4 4
51481+4 4 4 4 4 4
51482+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
51483+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
51484+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
51485+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
51486+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
51487+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
51488+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
51489+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
51490+4 0 0 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 4 4 4 4 4 4 4 4 4 4 4 4
51495+4 4 4 4 4 4
51496+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
51497+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
51498+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
51499+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
51500+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
51501+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
51502+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
51503+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
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 4 4 4 4 4 4 4 4 4 4 4 4
51509+4 4 4 4 4 4
51510+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
51511+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
51512+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
51513+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
51514+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
51515+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
51516+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
51517+6 6 6 4 0 0 4 0 0 4 3 3 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 4 4 4 4 4 4 4 4 4 4 4 4
51523+4 4 4 4 4 4
51524+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
51525+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
51526+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
51527+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
51528+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
51529+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
51530+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
51531+4 0 0 4 3 3 6 6 6 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 4 4 4 4 4 4 4 4 4 4 4 4
51537+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 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
51540+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
51541+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
51542+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
51543+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
51544+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
51545+6 6 6 6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
51551+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 5 5 5 5 5 5 5 5 5
51554+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
51555+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
51556+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
51557+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
51558+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
51559+5 5 5 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
51565+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 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
51569+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
51570+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
51571+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
51572+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
51573+4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
51579+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 4 4 4 4 4 4 5 5 5
51583+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
51584+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
51585+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
51586+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
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 4 4 4 4 4 4 4 4 4 4 4 4
51593+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 4 4 4
51597+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
51598+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
51599+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
51600+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
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 4 4 4 4 4 4 4 4 4 4 4 4
51607+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 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
51612+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
51613+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
51614+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
51621+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 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
51626+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
51627+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
51628+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
51635+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 4 4 4 4 4 4 5 5 5
51640+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
51641+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
51642+6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
51649+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 4 4 4 4 4 4
51654+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
51655+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
51656+4 3 3 5 5 5 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
51663+4 4 4 4 4 4
51664+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51665+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51666+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51667+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51668+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
51669+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
51670+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51671+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51672+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51673+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51674+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51675+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51676+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51677+4 4 4 4 4 4
51678+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51679+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51680+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51681+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51682+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
51683+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
51684+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51685+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51686+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51687+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51688+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51689+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51690+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51691+4 4 4 4 4 4
51692+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51693+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51694+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51695+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51696+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
51697+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
51698+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51699+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51700+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51701+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51702+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51703+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51704+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51705+4 4 4 4 4 4
51706diff --git a/drivers/video/mb862xx/mb862xxfb_accel.c b/drivers/video/mb862xx/mb862xxfb_accel.c
51707index fe92eed..106e085 100644
51708--- a/drivers/video/mb862xx/mb862xxfb_accel.c
51709+++ b/drivers/video/mb862xx/mb862xxfb_accel.c
51710@@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
51711 struct mb862xxfb_par *par = info->par;
51712
51713 if (info->var.bits_per_pixel == 32) {
51714- info->fbops->fb_fillrect = cfb_fillrect;
51715- info->fbops->fb_copyarea = cfb_copyarea;
51716- info->fbops->fb_imageblit = cfb_imageblit;
51717+ pax_open_kernel();
51718+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
51719+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
51720+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
51721+ pax_close_kernel();
51722 } else {
51723 outreg(disp, GC_L0EM, 3);
51724- info->fbops->fb_fillrect = mb86290fb_fillrect;
51725- info->fbops->fb_copyarea = mb86290fb_copyarea;
51726- info->fbops->fb_imageblit = mb86290fb_imageblit;
51727+ pax_open_kernel();
51728+ *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
51729+ *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
51730+ *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
51731+ pax_close_kernel();
51732 }
51733 outreg(draw, GDC_REG_DRAW_BASE, 0);
51734 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
51735diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
51736index ff22871..b129bed 100644
51737--- a/drivers/video/nvidia/nvidia.c
51738+++ b/drivers/video/nvidia/nvidia.c
51739@@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
51740 info->fix.line_length = (info->var.xres_virtual *
51741 info->var.bits_per_pixel) >> 3;
51742 if (info->var.accel_flags) {
51743- info->fbops->fb_imageblit = nvidiafb_imageblit;
51744- info->fbops->fb_fillrect = nvidiafb_fillrect;
51745- info->fbops->fb_copyarea = nvidiafb_copyarea;
51746- info->fbops->fb_sync = nvidiafb_sync;
51747+ pax_open_kernel();
51748+ *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
51749+ *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
51750+ *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
51751+ *(void **)&info->fbops->fb_sync = nvidiafb_sync;
51752+ pax_close_kernel();
51753 info->pixmap.scan_align = 4;
51754 info->flags &= ~FBINFO_HWACCEL_DISABLED;
51755 info->flags |= FBINFO_READS_FAST;
51756 NVResetGraphics(info);
51757 } else {
51758- info->fbops->fb_imageblit = cfb_imageblit;
51759- info->fbops->fb_fillrect = cfb_fillrect;
51760- info->fbops->fb_copyarea = cfb_copyarea;
51761- info->fbops->fb_sync = NULL;
51762+ pax_open_kernel();
51763+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
51764+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
51765+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
51766+ *(void **)&info->fbops->fb_sync = NULL;
51767+ pax_close_kernel();
51768 info->pixmap.scan_align = 1;
51769 info->flags |= FBINFO_HWACCEL_DISABLED;
51770 info->flags &= ~FBINFO_READS_FAST;
51771@@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
51772 info->pixmap.size = 8 * 1024;
51773 info->pixmap.flags = FB_PIXMAP_SYSTEM;
51774
51775- if (!hwcur)
51776- info->fbops->fb_cursor = NULL;
51777+ if (!hwcur) {
51778+ pax_open_kernel();
51779+ *(void **)&info->fbops->fb_cursor = NULL;
51780+ pax_close_kernel();
51781+ }
51782
51783 info->var.accel_flags = (!noaccel);
51784
51785diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
51786index 05c2dc3..ea1f391 100644
51787--- a/drivers/video/s1d13xxxfb.c
51788+++ b/drivers/video/s1d13xxxfb.c
51789@@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
51790
51791 switch(prod_id) {
51792 case S1D13506_PROD_ID: /* activate acceleration */
51793- s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
51794- s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
51795+ pax_open_kernel();
51796+ *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
51797+ *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
51798+ pax_close_kernel();
51799 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
51800 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
51801 break;
51802diff --git a/drivers/video/smscufx.c b/drivers/video/smscufx.c
51803index e188ada..aac63c8 100644
51804--- a/drivers/video/smscufx.c
51805+++ b/drivers/video/smscufx.c
51806@@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
51807 fb_deferred_io_cleanup(info);
51808 kfree(info->fbdefio);
51809 info->fbdefio = NULL;
51810- info->fbops->fb_mmap = ufx_ops_mmap;
51811+ pax_open_kernel();
51812+ *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
51813+ pax_close_kernel();
51814 }
51815
51816 pr_debug("released /dev/fb%d user=%d count=%d",
51817diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
51818index d2e5bc3..4cb05d1 100644
51819--- a/drivers/video/udlfb.c
51820+++ b/drivers/video/udlfb.c
51821@@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
51822 dlfb_urb_completion(urb);
51823
51824 error:
51825- atomic_add(bytes_sent, &dev->bytes_sent);
51826- atomic_add(bytes_identical, &dev->bytes_identical);
51827- atomic_add(width*height*2, &dev->bytes_rendered);
51828+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
51829+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
51830+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
51831 end_cycles = get_cycles();
51832- atomic_add(((unsigned int) ((end_cycles - start_cycles)
51833+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
51834 >> 10)), /* Kcycles */
51835 &dev->cpu_kcycles_used);
51836
51837@@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
51838 dlfb_urb_completion(urb);
51839
51840 error:
51841- atomic_add(bytes_sent, &dev->bytes_sent);
51842- atomic_add(bytes_identical, &dev->bytes_identical);
51843- atomic_add(bytes_rendered, &dev->bytes_rendered);
51844+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
51845+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
51846+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
51847 end_cycles = get_cycles();
51848- atomic_add(((unsigned int) ((end_cycles - start_cycles)
51849+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
51850 >> 10)), /* Kcycles */
51851 &dev->cpu_kcycles_used);
51852 }
51853@@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
51854 fb_deferred_io_cleanup(info);
51855 kfree(info->fbdefio);
51856 info->fbdefio = NULL;
51857- info->fbops->fb_mmap = dlfb_ops_mmap;
51858+ pax_open_kernel();
51859+ *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
51860+ pax_close_kernel();
51861 }
51862
51863 pr_warn("released /dev/fb%d user=%d count=%d\n",
51864@@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
51865 struct fb_info *fb_info = dev_get_drvdata(fbdev);
51866 struct dlfb_data *dev = fb_info->par;
51867 return snprintf(buf, PAGE_SIZE, "%u\n",
51868- atomic_read(&dev->bytes_rendered));
51869+ atomic_read_unchecked(&dev->bytes_rendered));
51870 }
51871
51872 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
51873@@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
51874 struct fb_info *fb_info = dev_get_drvdata(fbdev);
51875 struct dlfb_data *dev = fb_info->par;
51876 return snprintf(buf, PAGE_SIZE, "%u\n",
51877- atomic_read(&dev->bytes_identical));
51878+ atomic_read_unchecked(&dev->bytes_identical));
51879 }
51880
51881 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
51882@@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
51883 struct fb_info *fb_info = dev_get_drvdata(fbdev);
51884 struct dlfb_data *dev = fb_info->par;
51885 return snprintf(buf, PAGE_SIZE, "%u\n",
51886- atomic_read(&dev->bytes_sent));
51887+ atomic_read_unchecked(&dev->bytes_sent));
51888 }
51889
51890 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
51891@@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
51892 struct fb_info *fb_info = dev_get_drvdata(fbdev);
51893 struct dlfb_data *dev = fb_info->par;
51894 return snprintf(buf, PAGE_SIZE, "%u\n",
51895- atomic_read(&dev->cpu_kcycles_used));
51896+ atomic_read_unchecked(&dev->cpu_kcycles_used));
51897 }
51898
51899 static ssize_t edid_show(
51900@@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
51901 struct fb_info *fb_info = dev_get_drvdata(fbdev);
51902 struct dlfb_data *dev = fb_info->par;
51903
51904- atomic_set(&dev->bytes_rendered, 0);
51905- atomic_set(&dev->bytes_identical, 0);
51906- atomic_set(&dev->bytes_sent, 0);
51907- atomic_set(&dev->cpu_kcycles_used, 0);
51908+ atomic_set_unchecked(&dev->bytes_rendered, 0);
51909+ atomic_set_unchecked(&dev->bytes_identical, 0);
51910+ atomic_set_unchecked(&dev->bytes_sent, 0);
51911+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
51912
51913 return count;
51914 }
51915diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
51916index 7aec6f3..e3b2d55 100644
51917--- a/drivers/video/uvesafb.c
51918+++ b/drivers/video/uvesafb.c
51919@@ -19,6 +19,7 @@
51920 #include <linux/io.h>
51921 #include <linux/mutex.h>
51922 #include <linux/slab.h>
51923+#include <linux/moduleloader.h>
51924 #include <video/edid.h>
51925 #include <video/uvesafb.h>
51926 #ifdef CONFIG_X86
51927@@ -566,10 +567,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
51928 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
51929 par->pmi_setpal = par->ypan = 0;
51930 } else {
51931+
51932+#ifdef CONFIG_PAX_KERNEXEC
51933+#ifdef CONFIG_MODULES
51934+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
51935+#endif
51936+ if (!par->pmi_code) {
51937+ par->pmi_setpal = par->ypan = 0;
51938+ return 0;
51939+ }
51940+#endif
51941+
51942 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
51943 + task->t.regs.edi);
51944+
51945+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
51946+ pax_open_kernel();
51947+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
51948+ pax_close_kernel();
51949+
51950+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
51951+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
51952+#else
51953 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
51954 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
51955+#endif
51956+
51957 printk(KERN_INFO "uvesafb: protected mode interface info at "
51958 "%04x:%04x\n",
51959 (u16)task->t.regs.es, (u16)task->t.regs.edi);
51960@@ -814,13 +837,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
51961 par->ypan = ypan;
51962
51963 if (par->pmi_setpal || par->ypan) {
51964+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
51965 if (__supported_pte_mask & _PAGE_NX) {
51966 par->pmi_setpal = par->ypan = 0;
51967 printk(KERN_WARNING "uvesafb: NX protection is active, "
51968 "better not use the PMI.\n");
51969- } else {
51970+ } else
51971+#endif
51972 uvesafb_vbe_getpmi(task, par);
51973- }
51974 }
51975 #else
51976 /* The protected mode interface is not available on non-x86. */
51977@@ -1454,8 +1478,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
51978 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
51979
51980 /* Disable blanking if the user requested so. */
51981- if (!blank)
51982- info->fbops->fb_blank = NULL;
51983+ if (!blank) {
51984+ pax_open_kernel();
51985+ *(void **)&info->fbops->fb_blank = NULL;
51986+ pax_close_kernel();
51987+ }
51988
51989 /*
51990 * Find out how much IO memory is required for the mode with
51991@@ -1531,8 +1558,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
51992 info->flags = FBINFO_FLAG_DEFAULT |
51993 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
51994
51995- if (!par->ypan)
51996- info->fbops->fb_pan_display = NULL;
51997+ if (!par->ypan) {
51998+ pax_open_kernel();
51999+ *(void **)&info->fbops->fb_pan_display = NULL;
52000+ pax_close_kernel();
52001+ }
52002 }
52003
52004 static void uvesafb_init_mtrr(struct fb_info *info)
52005@@ -1796,6 +1826,11 @@ out:
52006 if (par->vbe_modes)
52007 kfree(par->vbe_modes);
52008
52009+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
52010+ if (par->pmi_code)
52011+ module_free_exec(NULL, par->pmi_code);
52012+#endif
52013+
52014 framebuffer_release(info);
52015 return err;
52016 }
52017@@ -1823,6 +1858,12 @@ static int uvesafb_remove(struct platform_device *dev)
52018 kfree(par->vbe_state_orig);
52019 if (par->vbe_state_saved)
52020 kfree(par->vbe_state_saved);
52021+
52022+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
52023+ if (par->pmi_code)
52024+ module_free_exec(NULL, par->pmi_code);
52025+#endif
52026+
52027 }
52028
52029 framebuffer_release(info);
52030diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
52031index 501b340..d80aa17 100644
52032--- a/drivers/video/vesafb.c
52033+++ b/drivers/video/vesafb.c
52034@@ -9,6 +9,7 @@
52035 */
52036
52037 #include <linux/module.h>
52038+#include <linux/moduleloader.h>
52039 #include <linux/kernel.h>
52040 #include <linux/errno.h>
52041 #include <linux/string.h>
52042@@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
52043 static int vram_total __initdata; /* Set total amount of memory */
52044 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
52045 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
52046-static void (*pmi_start)(void) __read_mostly;
52047-static void (*pmi_pal) (void) __read_mostly;
52048+static void (*pmi_start)(void) __read_only;
52049+static void (*pmi_pal) (void) __read_only;
52050 static int depth __read_mostly;
52051 static int vga_compat __read_mostly;
52052 /* --------------------------------------------------------------------- */
52053@@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
52054 unsigned int size_vmode;
52055 unsigned int size_remap;
52056 unsigned int size_total;
52057+ void *pmi_code = NULL;
52058
52059 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
52060 return -ENODEV;
52061@@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
52062 size_remap = size_total;
52063 vesafb_fix.smem_len = size_remap;
52064
52065-#ifndef __i386__
52066- screen_info.vesapm_seg = 0;
52067-#endif
52068-
52069 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
52070 printk(KERN_WARNING
52071 "vesafb: cannot reserve video memory at 0x%lx\n",
52072@@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
52073 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
52074 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
52075
52076+#ifdef __i386__
52077+
52078+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
52079+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
52080+ if (!pmi_code)
52081+#elif !defined(CONFIG_PAX_KERNEXEC)
52082+ if (0)
52083+#endif
52084+
52085+#endif
52086+ screen_info.vesapm_seg = 0;
52087+
52088 if (screen_info.vesapm_seg) {
52089- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
52090- screen_info.vesapm_seg,screen_info.vesapm_off);
52091+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
52092+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
52093 }
52094
52095 if (screen_info.vesapm_seg < 0xc000)
52096@@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
52097
52098 if (ypan || pmi_setpal) {
52099 unsigned short *pmi_base;
52100+
52101 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
52102- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
52103- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
52104+
52105+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
52106+ pax_open_kernel();
52107+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
52108+#else
52109+ pmi_code = pmi_base;
52110+#endif
52111+
52112+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
52113+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
52114+
52115+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
52116+ pmi_start = ktva_ktla(pmi_start);
52117+ pmi_pal = ktva_ktla(pmi_pal);
52118+ pax_close_kernel();
52119+#endif
52120+
52121 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
52122 if (pmi_base[3]) {
52123 printk(KERN_INFO "vesafb: pmi: ports = ");
52124@@ -472,8 +498,11 @@ static int __init vesafb_probe(struct platform_device *dev)
52125 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
52126 (ypan ? FBINFO_HWACCEL_YPAN : 0);
52127
52128- if (!ypan)
52129- info->fbops->fb_pan_display = NULL;
52130+ if (!ypan) {
52131+ pax_open_kernel();
52132+ *(void **)&info->fbops->fb_pan_display = NULL;
52133+ pax_close_kernel();
52134+ }
52135
52136 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
52137 err = -ENOMEM;
52138@@ -488,6 +517,11 @@ static int __init vesafb_probe(struct platform_device *dev)
52139 info->node, info->fix.id);
52140 return 0;
52141 err:
52142+
52143+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
52144+ module_free_exec(NULL, pmi_code);
52145+#endif
52146+
52147 if (info->screen_base)
52148 iounmap(info->screen_base);
52149 framebuffer_release(info);
52150diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
52151index 88714ae..16c2e11 100644
52152--- a/drivers/video/via/via_clock.h
52153+++ b/drivers/video/via/via_clock.h
52154@@ -56,7 +56,7 @@ struct via_clock {
52155
52156 void (*set_engine_pll_state)(u8 state);
52157 void (*set_engine_pll)(struct via_pll_config config);
52158-};
52159+} __no_const;
52160
52161
52162 static inline u32 get_pll_internal_frequency(u32 ref_freq,
52163diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
52164index fef20db..d28b1ab 100644
52165--- a/drivers/xen/xenfs/xenstored.c
52166+++ b/drivers/xen/xenfs/xenstored.c
52167@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
52168 static int xsd_kva_open(struct inode *inode, struct file *file)
52169 {
52170 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
52171+#ifdef CONFIG_GRKERNSEC_HIDESYM
52172+ NULL);
52173+#else
52174 xen_store_interface);
52175+#endif
52176+
52177 if (!file->private_data)
52178 return -ENOMEM;
52179 return 0;
52180diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
52181index 9ff073f..05cef23 100644
52182--- a/fs/9p/vfs_addr.c
52183+++ b/fs/9p/vfs_addr.c
52184@@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
52185
52186 retval = v9fs_file_write_internal(inode,
52187 v9inode->writeback_fid,
52188- (__force const char __user *)buffer,
52189+ (const char __force_user *)buffer,
52190 len, &offset, 0);
52191 if (retval > 0)
52192 retval = 0;
52193diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
52194index 25b018e..b941525 100644
52195--- a/fs/9p/vfs_inode.c
52196+++ b/fs/9p/vfs_inode.c
52197@@ -1312,7 +1312,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
52198 void
52199 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
52200 {
52201- char *s = nd_get_link(nd);
52202+ const char *s = nd_get_link(nd);
52203
52204 p9_debug(P9_DEBUG_VFS, " %s %s\n",
52205 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
52206diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
52207index 370b24c..ff0be7b 100644
52208--- a/fs/Kconfig.binfmt
52209+++ b/fs/Kconfig.binfmt
52210@@ -103,7 +103,7 @@ config HAVE_AOUT
52211
52212 config BINFMT_AOUT
52213 tristate "Kernel support for a.out and ECOFF binaries"
52214- depends on HAVE_AOUT
52215+ depends on HAVE_AOUT && BROKEN
52216 ---help---
52217 A.out (Assembler.OUTput) is a set of formats for libraries and
52218 executables used in the earliest versions of UNIX. Linux used
52219diff --git a/fs/afs/inode.c b/fs/afs/inode.c
52220index 789bc25..fafaeea 100644
52221--- a/fs/afs/inode.c
52222+++ b/fs/afs/inode.c
52223@@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
52224 struct afs_vnode *vnode;
52225 struct super_block *sb;
52226 struct inode *inode;
52227- static atomic_t afs_autocell_ino;
52228+ static atomic_unchecked_t afs_autocell_ino;
52229
52230 _enter("{%x:%u},%*.*s,",
52231 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
52232@@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
52233 data.fid.unique = 0;
52234 data.fid.vnode = 0;
52235
52236- inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
52237+ inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
52238 afs_iget5_autocell_test, afs_iget5_set,
52239 &data);
52240 if (!inode) {
52241diff --git a/fs/aio.c b/fs/aio.c
52242index 9b5ca11..c530886 100644
52243--- a/fs/aio.c
52244+++ b/fs/aio.c
52245@@ -162,7 +162,7 @@ static int aio_setup_ring(struct kioctx *ctx)
52246 size += sizeof(struct io_event) * nr_events;
52247 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
52248
52249- if (nr_pages < 0)
52250+ if (nr_pages <= 0)
52251 return -EINVAL;
52252
52253 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
52254@@ -952,6 +952,7 @@ static ssize_t aio_rw_vect_retry(struct kiocb *iocb, int rw, aio_rw_op *rw_op)
52255 static ssize_t aio_setup_vectored_rw(int rw, struct kiocb *kiocb, bool compat)
52256 {
52257 ssize_t ret;
52258+ struct iovec iovstack;
52259
52260 kiocb->ki_nr_segs = kiocb->ki_nbytes;
52261
52262@@ -959,17 +960,22 @@ static ssize_t aio_setup_vectored_rw(int rw, struct kiocb *kiocb, bool compat)
52263 if (compat)
52264 ret = compat_rw_copy_check_uvector(rw,
52265 (struct compat_iovec __user *)kiocb->ki_buf,
52266- kiocb->ki_nr_segs, 1, &kiocb->ki_inline_vec,
52267+ kiocb->ki_nr_segs, 1, &iovstack,
52268 &kiocb->ki_iovec);
52269 else
52270 #endif
52271 ret = rw_copy_check_uvector(rw,
52272 (struct iovec __user *)kiocb->ki_buf,
52273- kiocb->ki_nr_segs, 1, &kiocb->ki_inline_vec,
52274+ kiocb->ki_nr_segs, 1, &iovstack,
52275 &kiocb->ki_iovec);
52276 if (ret < 0)
52277 return ret;
52278
52279+ if (kiocb->ki_iovec == &iovstack) {
52280+ kiocb->ki_inline_vec = iovstack;
52281+ kiocb->ki_iovec = &kiocb->ki_inline_vec;
52282+ }
52283+
52284 /* ki_nbytes now reflect bytes instead of segs */
52285 kiocb->ki_nbytes = ret;
52286 return 0;
52287diff --git a/fs/attr.c b/fs/attr.c
52288index 1449adb..a2038c2 100644
52289--- a/fs/attr.c
52290+++ b/fs/attr.c
52291@@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
52292 unsigned long limit;
52293
52294 limit = rlimit(RLIMIT_FSIZE);
52295+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
52296 if (limit != RLIM_INFINITY && offset > limit)
52297 goto out_sig;
52298 if (offset > inode->i_sb->s_maxbytes)
52299diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
52300index 3db70da..7aeec5b 100644
52301--- a/fs/autofs4/waitq.c
52302+++ b/fs/autofs4/waitq.c
52303@@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
52304 {
52305 unsigned long sigpipe, flags;
52306 mm_segment_t fs;
52307- const char *data = (const char *)addr;
52308+ const char __user *data = (const char __force_user *)addr;
52309 ssize_t wr = 0;
52310
52311 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
52312@@ -346,6 +346,10 @@ static int validate_request(struct autofs_wait_queue **wait,
52313 return 1;
52314 }
52315
52316+#ifdef CONFIG_GRKERNSEC_HIDESYM
52317+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
52318+#endif
52319+
52320 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
52321 enum autofs_notify notify)
52322 {
52323@@ -379,7 +383,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
52324
52325 /* If this is a direct mount request create a dummy name */
52326 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
52327+#ifdef CONFIG_GRKERNSEC_HIDESYM
52328+ /* this name does get written to userland via autofs4_write() */
52329+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
52330+#else
52331 qstr.len = sprintf(name, "%p", dentry);
52332+#endif
52333 else {
52334 qstr.len = autofs4_getpath(sbi, dentry, &name);
52335 if (!qstr.len) {
52336diff --git a/fs/befs/endian.h b/fs/befs/endian.h
52337index 2722387..c8dd2a7 100644
52338--- a/fs/befs/endian.h
52339+++ b/fs/befs/endian.h
52340@@ -11,7 +11,7 @@
52341
52342 #include <asm/byteorder.h>
52343
52344-static inline u64
52345+static inline u64 __intentional_overflow(-1)
52346 fs64_to_cpu(const struct super_block *sb, fs64 n)
52347 {
52348 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
52349@@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
52350 return (__force fs64)cpu_to_be64(n);
52351 }
52352
52353-static inline u32
52354+static inline u32 __intentional_overflow(-1)
52355 fs32_to_cpu(const struct super_block *sb, fs32 n)
52356 {
52357 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
52358diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
52359index e9c75e2..1baece1 100644
52360--- a/fs/befs/linuxvfs.c
52361+++ b/fs/befs/linuxvfs.c
52362@@ -514,7 +514,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
52363 {
52364 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
52365 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
52366- char *link = nd_get_link(nd);
52367+ const char *link = nd_get_link(nd);
52368 if (!IS_ERR(link))
52369 kfree(link);
52370 }
52371diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
52372index 89dec7f..361b0d75 100644
52373--- a/fs/binfmt_aout.c
52374+++ b/fs/binfmt_aout.c
52375@@ -16,6 +16,7 @@
52376 #include <linux/string.h>
52377 #include <linux/fs.h>
52378 #include <linux/file.h>
52379+#include <linux/security.h>
52380 #include <linux/stat.h>
52381 #include <linux/fcntl.h>
52382 #include <linux/ptrace.h>
52383@@ -59,6 +60,8 @@ static int aout_core_dump(struct coredump_params *cprm)
52384 #endif
52385 # define START_STACK(u) ((void __user *)u.start_stack)
52386
52387+ memset(&dump, 0, sizeof(dump));
52388+
52389 fs = get_fs();
52390 set_fs(KERNEL_DS);
52391 has_dumped = 1;
52392@@ -69,10 +72,12 @@ static int aout_core_dump(struct coredump_params *cprm)
52393
52394 /* If the size of the dump file exceeds the rlimit, then see what would happen
52395 if we wrote the stack, but not the data area. */
52396+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
52397 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
52398 dump.u_dsize = 0;
52399
52400 /* Make sure we have enough room to write the stack and data areas. */
52401+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
52402 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
52403 dump.u_ssize = 0;
52404
52405@@ -233,6 +238,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
52406 rlim = rlimit(RLIMIT_DATA);
52407 if (rlim >= RLIM_INFINITY)
52408 rlim = ~0;
52409+
52410+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
52411 if (ex.a_data + ex.a_bss > rlim)
52412 return -ENOMEM;
52413
52414@@ -265,6 +272,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
52415
52416 install_exec_creds(bprm);
52417
52418+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
52419+ current->mm->pax_flags = 0UL;
52420+#endif
52421+
52422+#ifdef CONFIG_PAX_PAGEEXEC
52423+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
52424+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
52425+
52426+#ifdef CONFIG_PAX_EMUTRAMP
52427+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
52428+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
52429+#endif
52430+
52431+#ifdef CONFIG_PAX_MPROTECT
52432+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
52433+ current->mm->pax_flags |= MF_PAX_MPROTECT;
52434+#endif
52435+
52436+ }
52437+#endif
52438+
52439 if (N_MAGIC(ex) == OMAGIC) {
52440 unsigned long text_addr, map_size;
52441 loff_t pos;
52442@@ -322,7 +350,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
52443 }
52444
52445 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
52446- PROT_READ | PROT_WRITE | PROT_EXEC,
52447+ PROT_READ | PROT_WRITE,
52448 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
52449 fd_offset + ex.a_text);
52450 if (error != N_DATADDR(ex)) {
52451diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
52452index 100edcc..ed95731 100644
52453--- a/fs/binfmt_elf.c
52454+++ b/fs/binfmt_elf.c
52455@@ -34,6 +34,7 @@
52456 #include <linux/utsname.h>
52457 #include <linux/coredump.h>
52458 #include <linux/sched.h>
52459+#include <linux/xattr.h>
52460 #include <asm/uaccess.h>
52461 #include <asm/param.h>
52462 #include <asm/page.h>
52463@@ -60,6 +61,14 @@ static int elf_core_dump(struct coredump_params *cprm);
52464 #define elf_core_dump NULL
52465 #endif
52466
52467+#ifdef CONFIG_PAX_MPROTECT
52468+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
52469+#endif
52470+
52471+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
52472+static void elf_handle_mmap(struct file *file);
52473+#endif
52474+
52475 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
52476 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
52477 #else
52478@@ -79,6 +88,15 @@ static struct linux_binfmt elf_format = {
52479 .load_binary = load_elf_binary,
52480 .load_shlib = load_elf_library,
52481 .core_dump = elf_core_dump,
52482+
52483+#ifdef CONFIG_PAX_MPROTECT
52484+ .handle_mprotect= elf_handle_mprotect,
52485+#endif
52486+
52487+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
52488+ .handle_mmap = elf_handle_mmap,
52489+#endif
52490+
52491 .min_coredump = ELF_EXEC_PAGESIZE,
52492 };
52493
52494@@ -86,6 +104,8 @@ static struct linux_binfmt elf_format = {
52495
52496 static int set_brk(unsigned long start, unsigned long end)
52497 {
52498+ unsigned long e = end;
52499+
52500 start = ELF_PAGEALIGN(start);
52501 end = ELF_PAGEALIGN(end);
52502 if (end > start) {
52503@@ -94,7 +114,7 @@ static int set_brk(unsigned long start, unsigned long end)
52504 if (BAD_ADDR(addr))
52505 return addr;
52506 }
52507- current->mm->start_brk = current->mm->brk = end;
52508+ current->mm->start_brk = current->mm->brk = e;
52509 return 0;
52510 }
52511
52512@@ -155,12 +175,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
52513 elf_addr_t __user *u_rand_bytes;
52514 const char *k_platform = ELF_PLATFORM;
52515 const char *k_base_platform = ELF_BASE_PLATFORM;
52516- unsigned char k_rand_bytes[16];
52517+ u32 k_rand_bytes[4];
52518 int items;
52519 elf_addr_t *elf_info;
52520 int ei_index = 0;
52521 const struct cred *cred = current_cred();
52522 struct vm_area_struct *vma;
52523+ unsigned long saved_auxv[AT_VECTOR_SIZE];
52524
52525 /*
52526 * In some cases (e.g. Hyper-Threading), we want to avoid L1
52527@@ -202,8 +223,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
52528 * Generate 16 random bytes for userspace PRNG seeding.
52529 */
52530 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
52531- u_rand_bytes = (elf_addr_t __user *)
52532- STACK_ALLOC(p, sizeof(k_rand_bytes));
52533+ prandom_seed(k_rand_bytes[0] ^ prandom_u32());
52534+ prandom_seed(k_rand_bytes[1] ^ prandom_u32());
52535+ prandom_seed(k_rand_bytes[2] ^ prandom_u32());
52536+ prandom_seed(k_rand_bytes[3] ^ prandom_u32());
52537+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
52538+ u_rand_bytes = (elf_addr_t __user *) p;
52539 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
52540 return -EFAULT;
52541
52542@@ -318,9 +343,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
52543 return -EFAULT;
52544 current->mm->env_end = p;
52545
52546+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
52547+
52548 /* Put the elf_info on the stack in the right place. */
52549 sp = (elf_addr_t __user *)envp + 1;
52550- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
52551+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
52552 return -EFAULT;
52553 return 0;
52554 }
52555@@ -388,15 +415,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
52556 an ELF header */
52557
52558 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
52559- struct file *interpreter, unsigned long *interp_map_addr,
52560- unsigned long no_base)
52561+ struct file *interpreter, unsigned long no_base)
52562 {
52563 struct elf_phdr *elf_phdata;
52564 struct elf_phdr *eppnt;
52565- unsigned long load_addr = 0;
52566+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
52567 int load_addr_set = 0;
52568 unsigned long last_bss = 0, elf_bss = 0;
52569- unsigned long error = ~0UL;
52570+ unsigned long error = -EINVAL;
52571 unsigned long total_size;
52572 int retval, i, size;
52573
52574@@ -442,6 +468,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
52575 goto out_close;
52576 }
52577
52578+#ifdef CONFIG_PAX_SEGMEXEC
52579+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
52580+ pax_task_size = SEGMEXEC_TASK_SIZE;
52581+#endif
52582+
52583 eppnt = elf_phdata;
52584 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
52585 if (eppnt->p_type == PT_LOAD) {
52586@@ -465,8 +496,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
52587 map_addr = elf_map(interpreter, load_addr + vaddr,
52588 eppnt, elf_prot, elf_type, total_size);
52589 total_size = 0;
52590- if (!*interp_map_addr)
52591- *interp_map_addr = map_addr;
52592 error = map_addr;
52593 if (BAD_ADDR(map_addr))
52594 goto out_close;
52595@@ -485,8 +514,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
52596 k = load_addr + eppnt->p_vaddr;
52597 if (BAD_ADDR(k) ||
52598 eppnt->p_filesz > eppnt->p_memsz ||
52599- eppnt->p_memsz > TASK_SIZE ||
52600- TASK_SIZE - eppnt->p_memsz < k) {
52601+ eppnt->p_memsz > pax_task_size ||
52602+ pax_task_size - eppnt->p_memsz < k) {
52603 error = -ENOMEM;
52604 goto out_close;
52605 }
52606@@ -538,6 +567,315 @@ out:
52607 return error;
52608 }
52609
52610+#ifdef CONFIG_PAX_PT_PAX_FLAGS
52611+#ifdef CONFIG_PAX_SOFTMODE
52612+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
52613+{
52614+ unsigned long pax_flags = 0UL;
52615+
52616+#ifdef CONFIG_PAX_PAGEEXEC
52617+ if (elf_phdata->p_flags & PF_PAGEEXEC)
52618+ pax_flags |= MF_PAX_PAGEEXEC;
52619+#endif
52620+
52621+#ifdef CONFIG_PAX_SEGMEXEC
52622+ if (elf_phdata->p_flags & PF_SEGMEXEC)
52623+ pax_flags |= MF_PAX_SEGMEXEC;
52624+#endif
52625+
52626+#ifdef CONFIG_PAX_EMUTRAMP
52627+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
52628+ pax_flags |= MF_PAX_EMUTRAMP;
52629+#endif
52630+
52631+#ifdef CONFIG_PAX_MPROTECT
52632+ if (elf_phdata->p_flags & PF_MPROTECT)
52633+ pax_flags |= MF_PAX_MPROTECT;
52634+#endif
52635+
52636+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
52637+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
52638+ pax_flags |= MF_PAX_RANDMMAP;
52639+#endif
52640+
52641+ return pax_flags;
52642+}
52643+#endif
52644+
52645+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
52646+{
52647+ unsigned long pax_flags = 0UL;
52648+
52649+#ifdef CONFIG_PAX_PAGEEXEC
52650+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
52651+ pax_flags |= MF_PAX_PAGEEXEC;
52652+#endif
52653+
52654+#ifdef CONFIG_PAX_SEGMEXEC
52655+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
52656+ pax_flags |= MF_PAX_SEGMEXEC;
52657+#endif
52658+
52659+#ifdef CONFIG_PAX_EMUTRAMP
52660+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
52661+ pax_flags |= MF_PAX_EMUTRAMP;
52662+#endif
52663+
52664+#ifdef CONFIG_PAX_MPROTECT
52665+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
52666+ pax_flags |= MF_PAX_MPROTECT;
52667+#endif
52668+
52669+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
52670+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
52671+ pax_flags |= MF_PAX_RANDMMAP;
52672+#endif
52673+
52674+ return pax_flags;
52675+}
52676+#endif
52677+
52678+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
52679+#ifdef CONFIG_PAX_SOFTMODE
52680+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
52681+{
52682+ unsigned long pax_flags = 0UL;
52683+
52684+#ifdef CONFIG_PAX_PAGEEXEC
52685+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
52686+ pax_flags |= MF_PAX_PAGEEXEC;
52687+#endif
52688+
52689+#ifdef CONFIG_PAX_SEGMEXEC
52690+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
52691+ pax_flags |= MF_PAX_SEGMEXEC;
52692+#endif
52693+
52694+#ifdef CONFIG_PAX_EMUTRAMP
52695+ if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
52696+ pax_flags |= MF_PAX_EMUTRAMP;
52697+#endif
52698+
52699+#ifdef CONFIG_PAX_MPROTECT
52700+ if (pax_flags_softmode & MF_PAX_MPROTECT)
52701+ pax_flags |= MF_PAX_MPROTECT;
52702+#endif
52703+
52704+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
52705+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
52706+ pax_flags |= MF_PAX_RANDMMAP;
52707+#endif
52708+
52709+ return pax_flags;
52710+}
52711+#endif
52712+
52713+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
52714+{
52715+ unsigned long pax_flags = 0UL;
52716+
52717+#ifdef CONFIG_PAX_PAGEEXEC
52718+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
52719+ pax_flags |= MF_PAX_PAGEEXEC;
52720+#endif
52721+
52722+#ifdef CONFIG_PAX_SEGMEXEC
52723+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
52724+ pax_flags |= MF_PAX_SEGMEXEC;
52725+#endif
52726+
52727+#ifdef CONFIG_PAX_EMUTRAMP
52728+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
52729+ pax_flags |= MF_PAX_EMUTRAMP;
52730+#endif
52731+
52732+#ifdef CONFIG_PAX_MPROTECT
52733+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
52734+ pax_flags |= MF_PAX_MPROTECT;
52735+#endif
52736+
52737+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
52738+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
52739+ pax_flags |= MF_PAX_RANDMMAP;
52740+#endif
52741+
52742+ return pax_flags;
52743+}
52744+#endif
52745+
52746+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
52747+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
52748+{
52749+ unsigned long pax_flags = 0UL;
52750+
52751+#ifdef CONFIG_PAX_EI_PAX
52752+
52753+#ifdef CONFIG_PAX_PAGEEXEC
52754+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
52755+ pax_flags |= MF_PAX_PAGEEXEC;
52756+#endif
52757+
52758+#ifdef CONFIG_PAX_SEGMEXEC
52759+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
52760+ pax_flags |= MF_PAX_SEGMEXEC;
52761+#endif
52762+
52763+#ifdef CONFIG_PAX_EMUTRAMP
52764+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
52765+ pax_flags |= MF_PAX_EMUTRAMP;
52766+#endif
52767+
52768+#ifdef CONFIG_PAX_MPROTECT
52769+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
52770+ pax_flags |= MF_PAX_MPROTECT;
52771+#endif
52772+
52773+#ifdef CONFIG_PAX_ASLR
52774+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
52775+ pax_flags |= MF_PAX_RANDMMAP;
52776+#endif
52777+
52778+#else
52779+
52780+#ifdef CONFIG_PAX_PAGEEXEC
52781+ pax_flags |= MF_PAX_PAGEEXEC;
52782+#endif
52783+
52784+#ifdef CONFIG_PAX_SEGMEXEC
52785+ pax_flags |= MF_PAX_SEGMEXEC;
52786+#endif
52787+
52788+#ifdef CONFIG_PAX_MPROTECT
52789+ pax_flags |= MF_PAX_MPROTECT;
52790+#endif
52791+
52792+#ifdef CONFIG_PAX_RANDMMAP
52793+ if (randomize_va_space)
52794+ pax_flags |= MF_PAX_RANDMMAP;
52795+#endif
52796+
52797+#endif
52798+
52799+ return pax_flags;
52800+}
52801+
52802+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
52803+{
52804+
52805+#ifdef CONFIG_PAX_PT_PAX_FLAGS
52806+ unsigned long i;
52807+
52808+ for (i = 0UL; i < elf_ex->e_phnum; i++)
52809+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
52810+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
52811+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
52812+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
52813+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
52814+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
52815+ return ~0UL;
52816+
52817+#ifdef CONFIG_PAX_SOFTMODE
52818+ if (pax_softmode)
52819+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
52820+ else
52821+#endif
52822+
52823+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
52824+ break;
52825+ }
52826+#endif
52827+
52828+ return ~0UL;
52829+}
52830+
52831+static unsigned long pax_parse_xattr_pax(struct file * const file)
52832+{
52833+
52834+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
52835+ ssize_t xattr_size, i;
52836+ unsigned char xattr_value[sizeof("pemrs") - 1];
52837+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
52838+
52839+ xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
52840+ if (xattr_size <= 0 || xattr_size > sizeof xattr_value)
52841+ return ~0UL;
52842+
52843+ for (i = 0; i < xattr_size; i++)
52844+ switch (xattr_value[i]) {
52845+ default:
52846+ return ~0UL;
52847+
52848+#define parse_flag(option1, option2, flag) \
52849+ case option1: \
52850+ if (pax_flags_hardmode & MF_PAX_##flag) \
52851+ return ~0UL; \
52852+ pax_flags_hardmode |= MF_PAX_##flag; \
52853+ break; \
52854+ case option2: \
52855+ if (pax_flags_softmode & MF_PAX_##flag) \
52856+ return ~0UL; \
52857+ pax_flags_softmode |= MF_PAX_##flag; \
52858+ break;
52859+
52860+ parse_flag('p', 'P', PAGEEXEC);
52861+ parse_flag('e', 'E', EMUTRAMP);
52862+ parse_flag('m', 'M', MPROTECT);
52863+ parse_flag('r', 'R', RANDMMAP);
52864+ parse_flag('s', 'S', SEGMEXEC);
52865+
52866+#undef parse_flag
52867+ }
52868+
52869+ if (pax_flags_hardmode & pax_flags_softmode)
52870+ return ~0UL;
52871+
52872+#ifdef CONFIG_PAX_SOFTMODE
52873+ if (pax_softmode)
52874+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
52875+ else
52876+#endif
52877+
52878+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
52879+#else
52880+ return ~0UL;
52881+#endif
52882+
52883+}
52884+
52885+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
52886+{
52887+ unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
52888+
52889+ pax_flags = pax_parse_ei_pax(elf_ex);
52890+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
52891+ xattr_pax_flags = pax_parse_xattr_pax(file);
52892+
52893+ if (pt_pax_flags == ~0UL)
52894+ pt_pax_flags = xattr_pax_flags;
52895+ else if (xattr_pax_flags == ~0UL)
52896+ xattr_pax_flags = pt_pax_flags;
52897+ if (pt_pax_flags != xattr_pax_flags)
52898+ return -EINVAL;
52899+ if (pt_pax_flags != ~0UL)
52900+ pax_flags = pt_pax_flags;
52901+
52902+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
52903+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
52904+ if ((__supported_pte_mask & _PAGE_NX))
52905+ pax_flags &= ~MF_PAX_SEGMEXEC;
52906+ else
52907+ pax_flags &= ~MF_PAX_PAGEEXEC;
52908+ }
52909+#endif
52910+
52911+ if (0 > pax_check_flags(&pax_flags))
52912+ return -EINVAL;
52913+
52914+ current->mm->pax_flags = pax_flags;
52915+ return 0;
52916+}
52917+#endif
52918+
52919 /*
52920 * These are the functions used to load ELF style executables and shared
52921 * libraries. There is no binary dependent code anywhere else.
52922@@ -554,6 +892,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
52923 {
52924 unsigned int random_variable = 0;
52925
52926+#ifdef CONFIG_PAX_RANDUSTACK
52927+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
52928+ return stack_top - current->mm->delta_stack;
52929+#endif
52930+
52931 if ((current->flags & PF_RANDOMIZE) &&
52932 !(current->personality & ADDR_NO_RANDOMIZE)) {
52933 random_variable = get_random_int() & STACK_RND_MASK;
52934@@ -572,7 +915,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
52935 unsigned long load_addr = 0, load_bias = 0;
52936 int load_addr_set = 0;
52937 char * elf_interpreter = NULL;
52938- unsigned long error;
52939+ unsigned long error = 0;
52940 struct elf_phdr *elf_ppnt, *elf_phdata;
52941 unsigned long elf_bss, elf_brk;
52942 int retval, i;
52943@@ -582,12 +925,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
52944 unsigned long start_code, end_code, start_data, end_data;
52945 unsigned long reloc_func_desc __maybe_unused = 0;
52946 int executable_stack = EXSTACK_DEFAULT;
52947- unsigned long def_flags = 0;
52948 struct pt_regs *regs = current_pt_regs();
52949 struct {
52950 struct elfhdr elf_ex;
52951 struct elfhdr interp_elf_ex;
52952 } *loc;
52953+ unsigned long pax_task_size = TASK_SIZE;
52954
52955 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
52956 if (!loc) {
52957@@ -723,11 +1066,81 @@ static int load_elf_binary(struct linux_binprm *bprm)
52958 goto out_free_dentry;
52959
52960 /* OK, This is the point of no return */
52961- current->mm->def_flags = def_flags;
52962+
52963+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
52964+ current->mm->pax_flags = 0UL;
52965+#endif
52966+
52967+#ifdef CONFIG_PAX_DLRESOLVE
52968+ current->mm->call_dl_resolve = 0UL;
52969+#endif
52970+
52971+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
52972+ current->mm->call_syscall = 0UL;
52973+#endif
52974+
52975+#ifdef CONFIG_PAX_ASLR
52976+ current->mm->delta_mmap = 0UL;
52977+ current->mm->delta_stack = 0UL;
52978+#endif
52979+
52980+ current->mm->def_flags = 0;
52981+
52982+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
52983+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
52984+ send_sig(SIGKILL, current, 0);
52985+ goto out_free_dentry;
52986+ }
52987+#endif
52988+
52989+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
52990+ pax_set_initial_flags(bprm);
52991+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
52992+ if (pax_set_initial_flags_func)
52993+ (pax_set_initial_flags_func)(bprm);
52994+#endif
52995+
52996+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
52997+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
52998+ current->mm->context.user_cs_limit = PAGE_SIZE;
52999+ current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
53000+ }
53001+#endif
53002+
53003+#ifdef CONFIG_PAX_SEGMEXEC
53004+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
53005+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
53006+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
53007+ pax_task_size = SEGMEXEC_TASK_SIZE;
53008+ current->mm->def_flags |= VM_NOHUGEPAGE;
53009+ }
53010+#endif
53011+
53012+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
53013+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
53014+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
53015+ put_cpu();
53016+ }
53017+#endif
53018
53019 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
53020 may depend on the personality. */
53021 SET_PERSONALITY(loc->elf_ex);
53022+
53023+#ifdef CONFIG_PAX_ASLR
53024+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
53025+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
53026+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
53027+ }
53028+#endif
53029+
53030+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
53031+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
53032+ executable_stack = EXSTACK_DISABLE_X;
53033+ current->personality &= ~READ_IMPLIES_EXEC;
53034+ } else
53035+#endif
53036+
53037 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
53038 current->personality |= READ_IMPLIES_EXEC;
53039
53040@@ -817,6 +1230,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
53041 #else
53042 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
53043 #endif
53044+
53045+#ifdef CONFIG_PAX_RANDMMAP
53046+ /* PaX: randomize base address at the default exe base if requested */
53047+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
53048+#ifdef CONFIG_SPARC64
53049+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
53050+#else
53051+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
53052+#endif
53053+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
53054+ elf_flags |= MAP_FIXED;
53055+ }
53056+#endif
53057+
53058 }
53059
53060 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
53061@@ -849,9 +1276,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
53062 * allowed task size. Note that p_filesz must always be
53063 * <= p_memsz so it is only necessary to check p_memsz.
53064 */
53065- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
53066- elf_ppnt->p_memsz > TASK_SIZE ||
53067- TASK_SIZE - elf_ppnt->p_memsz < k) {
53068+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
53069+ elf_ppnt->p_memsz > pax_task_size ||
53070+ pax_task_size - elf_ppnt->p_memsz < k) {
53071 /* set_brk can never work. Avoid overflows. */
53072 send_sig(SIGKILL, current, 0);
53073 retval = -EINVAL;
53074@@ -890,17 +1317,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
53075 goto out_free_dentry;
53076 }
53077 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
53078- send_sig(SIGSEGV, current, 0);
53079- retval = -EFAULT; /* Nobody gets to see this, but.. */
53080- goto out_free_dentry;
53081+ /*
53082+ * This bss-zeroing can fail if the ELF
53083+ * file specifies odd protections. So
53084+ * we don't check the return value
53085+ */
53086 }
53087
53088+#ifdef CONFIG_PAX_RANDMMAP
53089+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
53090+ unsigned long start, size, flags;
53091+ vm_flags_t vm_flags;
53092+
53093+ start = ELF_PAGEALIGN(elf_brk);
53094+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
53095+ flags = MAP_FIXED | MAP_PRIVATE;
53096+ vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
53097+
53098+ down_write(&current->mm->mmap_sem);
53099+ start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
53100+ retval = -ENOMEM;
53101+ if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
53102+// if (current->personality & ADDR_NO_RANDOMIZE)
53103+// vm_flags |= VM_READ | VM_MAYREAD;
53104+ start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
53105+ retval = IS_ERR_VALUE(start) ? start : 0;
53106+ }
53107+ up_write(&current->mm->mmap_sem);
53108+ if (retval == 0)
53109+ retval = set_brk(start + size, start + size + PAGE_SIZE);
53110+ if (retval < 0) {
53111+ send_sig(SIGKILL, current, 0);
53112+ goto out_free_dentry;
53113+ }
53114+ }
53115+#endif
53116+
53117 if (elf_interpreter) {
53118- unsigned long interp_map_addr = 0;
53119-
53120 elf_entry = load_elf_interp(&loc->interp_elf_ex,
53121 interpreter,
53122- &interp_map_addr,
53123 load_bias);
53124 if (!IS_ERR((void *)elf_entry)) {
53125 /*
53126@@ -1122,7 +1577,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
53127 * Decide what to dump of a segment, part, all or none.
53128 */
53129 static unsigned long vma_dump_size(struct vm_area_struct *vma,
53130- unsigned long mm_flags)
53131+ unsigned long mm_flags, long signr)
53132 {
53133 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
53134
53135@@ -1160,7 +1615,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
53136 if (vma->vm_file == NULL)
53137 return 0;
53138
53139- if (FILTER(MAPPED_PRIVATE))
53140+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
53141 goto whole;
53142
53143 /*
53144@@ -1385,9 +1840,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
53145 {
53146 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
53147 int i = 0;
53148- do
53149+ do {
53150 i += 2;
53151- while (auxv[i - 2] != AT_NULL);
53152+ } while (auxv[i - 2] != AT_NULL);
53153 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
53154 }
53155
53156@@ -1396,7 +1851,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
53157 {
53158 mm_segment_t old_fs = get_fs();
53159 set_fs(KERNEL_DS);
53160- copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
53161+ copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
53162 set_fs(old_fs);
53163 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
53164 }
53165@@ -2017,14 +2472,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
53166 }
53167
53168 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
53169- unsigned long mm_flags)
53170+ struct coredump_params *cprm)
53171 {
53172 struct vm_area_struct *vma;
53173 size_t size = 0;
53174
53175 for (vma = first_vma(current, gate_vma); vma != NULL;
53176 vma = next_vma(vma, gate_vma))
53177- size += vma_dump_size(vma, mm_flags);
53178+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
53179 return size;
53180 }
53181
53182@@ -2117,7 +2572,7 @@ static int elf_core_dump(struct coredump_params *cprm)
53183
53184 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
53185
53186- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
53187+ offset += elf_core_vma_data_size(gate_vma, cprm);
53188 offset += elf_core_extra_data_size();
53189 e_shoff = offset;
53190
53191@@ -2131,10 +2586,12 @@ static int elf_core_dump(struct coredump_params *cprm)
53192 offset = dataoff;
53193
53194 size += sizeof(*elf);
53195+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
53196 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
53197 goto end_coredump;
53198
53199 size += sizeof(*phdr4note);
53200+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
53201 if (size > cprm->limit
53202 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
53203 goto end_coredump;
53204@@ -2148,7 +2605,7 @@ static int elf_core_dump(struct coredump_params *cprm)
53205 phdr.p_offset = offset;
53206 phdr.p_vaddr = vma->vm_start;
53207 phdr.p_paddr = 0;
53208- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
53209+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
53210 phdr.p_memsz = vma->vm_end - vma->vm_start;
53211 offset += phdr.p_filesz;
53212 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
53213@@ -2159,6 +2616,7 @@ static int elf_core_dump(struct coredump_params *cprm)
53214 phdr.p_align = ELF_EXEC_PAGESIZE;
53215
53216 size += sizeof(phdr);
53217+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
53218 if (size > cprm->limit
53219 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
53220 goto end_coredump;
53221@@ -2183,7 +2641,7 @@ static int elf_core_dump(struct coredump_params *cprm)
53222 unsigned long addr;
53223 unsigned long end;
53224
53225- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
53226+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
53227
53228 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
53229 struct page *page;
53230@@ -2192,6 +2650,7 @@ static int elf_core_dump(struct coredump_params *cprm)
53231 page = get_dump_page(addr);
53232 if (page) {
53233 void *kaddr = kmap(page);
53234+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
53235 stop = ((size += PAGE_SIZE) > cprm->limit) ||
53236 !dump_write(cprm->file, kaddr,
53237 PAGE_SIZE);
53238@@ -2209,6 +2668,7 @@ static int elf_core_dump(struct coredump_params *cprm)
53239
53240 if (e_phnum == PN_XNUM) {
53241 size += sizeof(*shdr4extnum);
53242+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
53243 if (size > cprm->limit
53244 || !dump_write(cprm->file, shdr4extnum,
53245 sizeof(*shdr4extnum)))
53246@@ -2229,6 +2689,167 @@ out:
53247
53248 #endif /* CONFIG_ELF_CORE */
53249
53250+#ifdef CONFIG_PAX_MPROTECT
53251+/* PaX: non-PIC ELF libraries need relocations on their executable segments
53252+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
53253+ * we'll remove VM_MAYWRITE for good on RELRO segments.
53254+ *
53255+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
53256+ * basis because we want to allow the common case and not the special ones.
53257+ */
53258+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
53259+{
53260+ struct elfhdr elf_h;
53261+ struct elf_phdr elf_p;
53262+ unsigned long i;
53263+ unsigned long oldflags;
53264+ bool is_textrel_rw, is_textrel_rx, is_relro;
53265+
53266+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
53267+ return;
53268+
53269+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
53270+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
53271+
53272+#ifdef CONFIG_PAX_ELFRELOCS
53273+ /* possible TEXTREL */
53274+ is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
53275+ is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
53276+#else
53277+ is_textrel_rw = false;
53278+ is_textrel_rx = false;
53279+#endif
53280+
53281+ /* possible RELRO */
53282+ is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
53283+
53284+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
53285+ return;
53286+
53287+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
53288+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
53289+
53290+#ifdef CONFIG_PAX_ETEXECRELOCS
53291+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
53292+#else
53293+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
53294+#endif
53295+
53296+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
53297+ !elf_check_arch(&elf_h) ||
53298+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
53299+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
53300+ return;
53301+
53302+ for (i = 0UL; i < elf_h.e_phnum; i++) {
53303+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
53304+ return;
53305+ switch (elf_p.p_type) {
53306+ case PT_DYNAMIC:
53307+ if (!is_textrel_rw && !is_textrel_rx)
53308+ continue;
53309+ i = 0UL;
53310+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
53311+ elf_dyn dyn;
53312+
53313+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
53314+ break;
53315+ if (dyn.d_tag == DT_NULL)
53316+ break;
53317+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
53318+ gr_log_textrel(vma);
53319+ if (is_textrel_rw)
53320+ vma->vm_flags |= VM_MAYWRITE;
53321+ else
53322+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
53323+ vma->vm_flags &= ~VM_MAYWRITE;
53324+ break;
53325+ }
53326+ i++;
53327+ }
53328+ is_textrel_rw = false;
53329+ is_textrel_rx = false;
53330+ continue;
53331+
53332+ case PT_GNU_RELRO:
53333+ if (!is_relro)
53334+ continue;
53335+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
53336+ vma->vm_flags &= ~VM_MAYWRITE;
53337+ is_relro = false;
53338+ continue;
53339+
53340+#ifdef CONFIG_PAX_PT_PAX_FLAGS
53341+ case PT_PAX_FLAGS: {
53342+ const char *msg_mprotect = "", *msg_emutramp = "";
53343+ char *buffer_lib, *buffer_exe;
53344+
53345+ if (elf_p.p_flags & PF_NOMPROTECT)
53346+ msg_mprotect = "MPROTECT disabled";
53347+
53348+#ifdef CONFIG_PAX_EMUTRAMP
53349+ if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
53350+ msg_emutramp = "EMUTRAMP enabled";
53351+#endif
53352+
53353+ if (!msg_mprotect[0] && !msg_emutramp[0])
53354+ continue;
53355+
53356+ if (!printk_ratelimit())
53357+ continue;
53358+
53359+ buffer_lib = (char *)__get_free_page(GFP_KERNEL);
53360+ buffer_exe = (char *)__get_free_page(GFP_KERNEL);
53361+ if (buffer_lib && buffer_exe) {
53362+ char *path_lib, *path_exe;
53363+
53364+ path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
53365+ path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
53366+
53367+ pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
53368+ (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
53369+
53370+ }
53371+ free_page((unsigned long)buffer_exe);
53372+ free_page((unsigned long)buffer_lib);
53373+ continue;
53374+ }
53375+#endif
53376+
53377+ }
53378+ }
53379+}
53380+#endif
53381+
53382+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
53383+
53384+extern int grsec_enable_log_rwxmaps;
53385+
53386+static void elf_handle_mmap(struct file *file)
53387+{
53388+ struct elfhdr elf_h;
53389+ struct elf_phdr elf_p;
53390+ unsigned long i;
53391+
53392+ if (!grsec_enable_log_rwxmaps)
53393+ return;
53394+
53395+ if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
53396+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
53397+ (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
53398+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
53399+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
53400+ return;
53401+
53402+ for (i = 0UL; i < elf_h.e_phnum; i++) {
53403+ if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
53404+ return;
53405+ if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
53406+ gr_log_ptgnustack(file);
53407+ }
53408+}
53409+#endif
53410+
53411 static int __init init_elf_binfmt(void)
53412 {
53413 register_binfmt(&elf_format);
53414diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
53415index d50bbe5..af3b649 100644
53416--- a/fs/binfmt_flat.c
53417+++ b/fs/binfmt_flat.c
53418@@ -566,7 +566,9 @@ static int load_flat_file(struct linux_binprm * bprm,
53419 realdatastart = (unsigned long) -ENOMEM;
53420 printk("Unable to allocate RAM for process data, errno %d\n",
53421 (int)-realdatastart);
53422+ down_write(&current->mm->mmap_sem);
53423 vm_munmap(textpos, text_len);
53424+ up_write(&current->mm->mmap_sem);
53425 ret = realdatastart;
53426 goto err;
53427 }
53428@@ -590,8 +592,10 @@ static int load_flat_file(struct linux_binprm * bprm,
53429 }
53430 if (IS_ERR_VALUE(result)) {
53431 printk("Unable to read data+bss, errno %d\n", (int)-result);
53432+ down_write(&current->mm->mmap_sem);
53433 vm_munmap(textpos, text_len);
53434 vm_munmap(realdatastart, len);
53435+ up_write(&current->mm->mmap_sem);
53436 ret = result;
53437 goto err;
53438 }
53439@@ -653,8 +657,10 @@ static int load_flat_file(struct linux_binprm * bprm,
53440 }
53441 if (IS_ERR_VALUE(result)) {
53442 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
53443+ down_write(&current->mm->mmap_sem);
53444 vm_munmap(textpos, text_len + data_len + extra +
53445 MAX_SHARED_LIBS * sizeof(unsigned long));
53446+ up_write(&current->mm->mmap_sem);
53447 ret = result;
53448 goto err;
53449 }
53450diff --git a/fs/bio.c b/fs/bio.c
53451index c5eae72..599e3cf 100644
53452--- a/fs/bio.c
53453+++ b/fs/bio.c
53454@@ -1106,7 +1106,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
53455 /*
53456 * Overflow, abort
53457 */
53458- if (end < start)
53459+ if (end < start || end - start > INT_MAX - nr_pages)
53460 return ERR_PTR(-EINVAL);
53461
53462 nr_pages += end - start;
53463@@ -1240,7 +1240,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
53464 /*
53465 * Overflow, abort
53466 */
53467- if (end < start)
53468+ if (end < start || end - start > INT_MAX - nr_pages)
53469 return ERR_PTR(-EINVAL);
53470
53471 nr_pages += end - start;
53472@@ -1502,7 +1502,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
53473 const int read = bio_data_dir(bio) == READ;
53474 struct bio_map_data *bmd = bio->bi_private;
53475 int i;
53476- char *p = bmd->sgvecs[0].iov_base;
53477+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
53478
53479 bio_for_each_segment_all(bvec, bio, i) {
53480 char *addr = page_address(bvec->bv_page);
53481diff --git a/fs/block_dev.c b/fs/block_dev.c
53482index c7bda5c..2121e94 100644
53483--- a/fs/block_dev.c
53484+++ b/fs/block_dev.c
53485@@ -637,7 +637,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
53486 else if (bdev->bd_contains == bdev)
53487 return true; /* is a whole device which isn't held */
53488
53489- else if (whole->bd_holder == bd_may_claim)
53490+ else if (whole->bd_holder == (void *)bd_may_claim)
53491 return true; /* is a partition of a device that is being partitioned */
53492 else if (whole->bd_holder != NULL)
53493 return false; /* is a partition of a held device */
53494diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
53495index ed50460..fe84385 100644
53496--- a/fs/btrfs/ctree.c
53497+++ b/fs/btrfs/ctree.c
53498@@ -1076,9 +1076,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
53499 free_extent_buffer(buf);
53500 add_root_to_dirty_list(root);
53501 } else {
53502- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
53503- parent_start = parent->start;
53504- else
53505+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
53506+ if (parent)
53507+ parent_start = parent->start;
53508+ else
53509+ parent_start = 0;
53510+ } else
53511 parent_start = 0;
53512
53513 WARN_ON(trans->transid != btrfs_header_generation(parent));
53514diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
53515index 3755109..e3d457f 100644
53516--- a/fs/btrfs/delayed-inode.c
53517+++ b/fs/btrfs/delayed-inode.c
53518@@ -458,7 +458,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
53519
53520 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
53521 {
53522- int seq = atomic_inc_return(&delayed_root->items_seq);
53523+ int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
53524 if ((atomic_dec_return(&delayed_root->items) <
53525 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
53526 waitqueue_active(&delayed_root->wait))
53527@@ -1377,7 +1377,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
53528 static int refs_newer(struct btrfs_delayed_root *delayed_root,
53529 int seq, int count)
53530 {
53531- int val = atomic_read(&delayed_root->items_seq);
53532+ int val = atomic_read_unchecked(&delayed_root->items_seq);
53533
53534 if (val < seq || val >= seq + count)
53535 return 1;
53536@@ -1394,7 +1394,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
53537 if (atomic_read(&delayed_root->items) < BTRFS_DELAYED_BACKGROUND)
53538 return;
53539
53540- seq = atomic_read(&delayed_root->items_seq);
53541+ seq = atomic_read_unchecked(&delayed_root->items_seq);
53542
53543 if (atomic_read(&delayed_root->items) >= BTRFS_DELAYED_WRITEBACK) {
53544 int ret;
53545diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
53546index a4b38f9..f86a509 100644
53547--- a/fs/btrfs/delayed-inode.h
53548+++ b/fs/btrfs/delayed-inode.h
53549@@ -43,7 +43,7 @@ struct btrfs_delayed_root {
53550 */
53551 struct list_head prepare_list;
53552 atomic_t items; /* for delayed items */
53553- atomic_t items_seq; /* for delayed items */
53554+ atomic_unchecked_t items_seq; /* for delayed items */
53555 int nodes; /* for delayed nodes */
53556 wait_queue_head_t wait;
53557 };
53558@@ -87,7 +87,7 @@ static inline void btrfs_init_delayed_root(
53559 struct btrfs_delayed_root *delayed_root)
53560 {
53561 atomic_set(&delayed_root->items, 0);
53562- atomic_set(&delayed_root->items_seq, 0);
53563+ atomic_set_unchecked(&delayed_root->items_seq, 0);
53564 delayed_root->nodes = 0;
53565 spin_lock_init(&delayed_root->lock);
53566 init_waitqueue_head(&delayed_root->wait);
53567diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
53568index 238a055..1e33cd5 100644
53569--- a/fs/btrfs/ioctl.c
53570+++ b/fs/btrfs/ioctl.c
53571@@ -3097,9 +3097,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
53572 for (i = 0; i < num_types; i++) {
53573 struct btrfs_space_info *tmp;
53574
53575+ /* Don't copy in more than we allocated */
53576 if (!slot_count)
53577 break;
53578
53579+ slot_count--;
53580+
53581 info = NULL;
53582 rcu_read_lock();
53583 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
53584@@ -3121,10 +3124,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
53585 memcpy(dest, &space, sizeof(space));
53586 dest++;
53587 space_args.total_spaces++;
53588- slot_count--;
53589 }
53590- if (!slot_count)
53591- break;
53592 }
53593 up_read(&info->groups_sem);
53594 }
53595diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
53596index 8eb6191..eda91e2 100644
53597--- a/fs/btrfs/super.c
53598+++ b/fs/btrfs/super.c
53599@@ -264,7 +264,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
53600 function, line, errstr);
53601 return;
53602 }
53603- ACCESS_ONCE(trans->transaction->aborted) = errno;
53604+ ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
53605 /* Wake up anybody who may be waiting on this transaction */
53606 wake_up(&root->fs_info->transaction_wait);
53607 wake_up(&root->fs_info->transaction_blocked_wait);
53608diff --git a/fs/buffer.c b/fs/buffer.c
53609index 4d74335..b0df7f9 100644
53610--- a/fs/buffer.c
53611+++ b/fs/buffer.c
53612@@ -3416,7 +3416,7 @@ void __init buffer_init(void)
53613 bh_cachep = kmem_cache_create("buffer_head",
53614 sizeof(struct buffer_head), 0,
53615 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
53616- SLAB_MEM_SPREAD),
53617+ SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
53618 NULL);
53619
53620 /*
53621diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
53622index 622f469..e8d2d55 100644
53623--- a/fs/cachefiles/bind.c
53624+++ b/fs/cachefiles/bind.c
53625@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
53626 args);
53627
53628 /* start by checking things over */
53629- ASSERT(cache->fstop_percent >= 0 &&
53630- cache->fstop_percent < cache->fcull_percent &&
53631+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
53632 cache->fcull_percent < cache->frun_percent &&
53633 cache->frun_percent < 100);
53634
53635- ASSERT(cache->bstop_percent >= 0 &&
53636- cache->bstop_percent < cache->bcull_percent &&
53637+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
53638 cache->bcull_percent < cache->brun_percent &&
53639 cache->brun_percent < 100);
53640
53641diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
53642index 0a1467b..6a53245 100644
53643--- a/fs/cachefiles/daemon.c
53644+++ b/fs/cachefiles/daemon.c
53645@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
53646 if (n > buflen)
53647 return -EMSGSIZE;
53648
53649- if (copy_to_user(_buffer, buffer, n) != 0)
53650+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
53651 return -EFAULT;
53652
53653 return n;
53654@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
53655 if (test_bit(CACHEFILES_DEAD, &cache->flags))
53656 return -EIO;
53657
53658- if (datalen < 0 || datalen > PAGE_SIZE - 1)
53659+ if (datalen > PAGE_SIZE - 1)
53660 return -EOPNOTSUPP;
53661
53662 /* drag the command string into the kernel so we can parse it */
53663@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
53664 if (args[0] != '%' || args[1] != '\0')
53665 return -EINVAL;
53666
53667- if (fstop < 0 || fstop >= cache->fcull_percent)
53668+ if (fstop >= cache->fcull_percent)
53669 return cachefiles_daemon_range_error(cache, args);
53670
53671 cache->fstop_percent = fstop;
53672@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
53673 if (args[0] != '%' || args[1] != '\0')
53674 return -EINVAL;
53675
53676- if (bstop < 0 || bstop >= cache->bcull_percent)
53677+ if (bstop >= cache->bcull_percent)
53678 return cachefiles_daemon_range_error(cache, args);
53679
53680 cache->bstop_percent = bstop;
53681diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
53682index 4938251..7e01445 100644
53683--- a/fs/cachefiles/internal.h
53684+++ b/fs/cachefiles/internal.h
53685@@ -59,7 +59,7 @@ struct cachefiles_cache {
53686 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
53687 struct rb_root active_nodes; /* active nodes (can't be culled) */
53688 rwlock_t active_lock; /* lock for active_nodes */
53689- atomic_t gravecounter; /* graveyard uniquifier */
53690+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
53691 unsigned frun_percent; /* when to stop culling (% files) */
53692 unsigned fcull_percent; /* when to start culling (% files) */
53693 unsigned fstop_percent; /* when to stop allocating (% files) */
53694@@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
53695 * proc.c
53696 */
53697 #ifdef CONFIG_CACHEFILES_HISTOGRAM
53698-extern atomic_t cachefiles_lookup_histogram[HZ];
53699-extern atomic_t cachefiles_mkdir_histogram[HZ];
53700-extern atomic_t cachefiles_create_histogram[HZ];
53701+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
53702+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
53703+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
53704
53705 extern int __init cachefiles_proc_init(void);
53706 extern void cachefiles_proc_cleanup(void);
53707 static inline
53708-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
53709+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
53710 {
53711 unsigned long jif = jiffies - start_jif;
53712 if (jif >= HZ)
53713 jif = HZ - 1;
53714- atomic_inc(&histogram[jif]);
53715+ atomic_inc_unchecked(&histogram[jif]);
53716 }
53717
53718 #else
53719diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
53720index 25badd1..d70d918 100644
53721--- a/fs/cachefiles/namei.c
53722+++ b/fs/cachefiles/namei.c
53723@@ -317,7 +317,7 @@ try_again:
53724 /* first step is to make up a grave dentry in the graveyard */
53725 sprintf(nbuffer, "%08x%08x",
53726 (uint32_t) get_seconds(),
53727- (uint32_t) atomic_inc_return(&cache->gravecounter));
53728+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
53729
53730 /* do the multiway lock magic */
53731 trap = lock_rename(cache->graveyard, dir);
53732diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
53733index eccd339..4c1d995 100644
53734--- a/fs/cachefiles/proc.c
53735+++ b/fs/cachefiles/proc.c
53736@@ -14,9 +14,9 @@
53737 #include <linux/seq_file.h>
53738 #include "internal.h"
53739
53740-atomic_t cachefiles_lookup_histogram[HZ];
53741-atomic_t cachefiles_mkdir_histogram[HZ];
53742-atomic_t cachefiles_create_histogram[HZ];
53743+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
53744+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
53745+atomic_unchecked_t cachefiles_create_histogram[HZ];
53746
53747 /*
53748 * display the latency histogram
53749@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
53750 return 0;
53751 default:
53752 index = (unsigned long) v - 3;
53753- x = atomic_read(&cachefiles_lookup_histogram[index]);
53754- y = atomic_read(&cachefiles_mkdir_histogram[index]);
53755- z = atomic_read(&cachefiles_create_histogram[index]);
53756+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
53757+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
53758+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
53759 if (x == 0 && y == 0 && z == 0)
53760 return 0;
53761
53762diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
53763index ebaff36..7e3ea26 100644
53764--- a/fs/cachefiles/rdwr.c
53765+++ b/fs/cachefiles/rdwr.c
53766@@ -950,7 +950,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
53767 old_fs = get_fs();
53768 set_fs(KERNEL_DS);
53769 ret = file->f_op->write(
53770- file, (const void __user *) data, len, &pos);
53771+ file, (const void __force_user *) data, len, &pos);
53772 set_fs(old_fs);
53773 kunmap(page);
53774 file_end_write(file);
53775diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
53776index a40ceda..f43d17c 100644
53777--- a/fs/ceph/dir.c
53778+++ b/fs/ceph/dir.c
53779@@ -240,7 +240,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
53780 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
53781 struct ceph_mds_client *mdsc = fsc->mdsc;
53782 unsigned frag = fpos_frag(ctx->pos);
53783- int off = fpos_off(ctx->pos);
53784+ unsigned int off = fpos_off(ctx->pos);
53785 int err;
53786 u32 ftype;
53787 struct ceph_mds_reply_info_parsed *rinfo;
53788diff --git a/fs/ceph/super.c b/fs/ceph/super.c
53789index 6627b26..634ec4b 100644
53790--- a/fs/ceph/super.c
53791+++ b/fs/ceph/super.c
53792@@ -839,7 +839,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
53793 /*
53794 * construct our own bdi so we can control readahead, etc.
53795 */
53796-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
53797+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
53798
53799 static int ceph_register_bdi(struct super_block *sb,
53800 struct ceph_fs_client *fsc)
53801@@ -856,7 +856,7 @@ static int ceph_register_bdi(struct super_block *sb,
53802 default_backing_dev_info.ra_pages;
53803
53804 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
53805- atomic_long_inc_return(&bdi_seq));
53806+ atomic_long_inc_return_unchecked(&bdi_seq));
53807 if (!err)
53808 sb->s_bdi = &fsc->backing_dev_info;
53809 return err;
53810diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
53811index f3ac415..3d2420c 100644
53812--- a/fs/cifs/cifs_debug.c
53813+++ b/fs/cifs/cifs_debug.c
53814@@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
53815
53816 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
53817 #ifdef CONFIG_CIFS_STATS2
53818- atomic_set(&totBufAllocCount, 0);
53819- atomic_set(&totSmBufAllocCount, 0);
53820+ atomic_set_unchecked(&totBufAllocCount, 0);
53821+ atomic_set_unchecked(&totSmBufAllocCount, 0);
53822 #endif /* CONFIG_CIFS_STATS2 */
53823 spin_lock(&cifs_tcp_ses_lock);
53824 list_for_each(tmp1, &cifs_tcp_ses_list) {
53825@@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
53826 tcon = list_entry(tmp3,
53827 struct cifs_tcon,
53828 tcon_list);
53829- atomic_set(&tcon->num_smbs_sent, 0);
53830+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
53831 if (server->ops->clear_stats)
53832 server->ops->clear_stats(tcon);
53833 }
53834@@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
53835 smBufAllocCount.counter, cifs_min_small);
53836 #ifdef CONFIG_CIFS_STATS2
53837 seq_printf(m, "Total Large %d Small %d Allocations\n",
53838- atomic_read(&totBufAllocCount),
53839- atomic_read(&totSmBufAllocCount));
53840+ atomic_read_unchecked(&totBufAllocCount),
53841+ atomic_read_unchecked(&totSmBufAllocCount));
53842 #endif /* CONFIG_CIFS_STATS2 */
53843
53844 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
53845@@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
53846 if (tcon->need_reconnect)
53847 seq_puts(m, "\tDISCONNECTED ");
53848 seq_printf(m, "\nSMBs: %d",
53849- atomic_read(&tcon->num_smbs_sent));
53850+ atomic_read_unchecked(&tcon->num_smbs_sent));
53851 if (server->ops->print_stats)
53852 server->ops->print_stats(m, tcon);
53853 }
53854diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
53855index 85ea98d..b3ed4d6 100644
53856--- a/fs/cifs/cifsfs.c
53857+++ b/fs/cifs/cifsfs.c
53858@@ -1037,7 +1037,7 @@ cifs_init_request_bufs(void)
53859 */
53860 cifs_req_cachep = kmem_cache_create("cifs_request",
53861 CIFSMaxBufSize + max_hdr_size, 0,
53862- SLAB_HWCACHE_ALIGN, NULL);
53863+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
53864 if (cifs_req_cachep == NULL)
53865 return -ENOMEM;
53866
53867@@ -1064,7 +1064,7 @@ cifs_init_request_bufs(void)
53868 efficient to alloc 1 per page off the slab compared to 17K (5page)
53869 alloc of large cifs buffers even when page debugging is on */
53870 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
53871- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
53872+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
53873 NULL);
53874 if (cifs_sm_req_cachep == NULL) {
53875 mempool_destroy(cifs_req_poolp);
53876@@ -1149,8 +1149,8 @@ init_cifs(void)
53877 atomic_set(&bufAllocCount, 0);
53878 atomic_set(&smBufAllocCount, 0);
53879 #ifdef CONFIG_CIFS_STATS2
53880- atomic_set(&totBufAllocCount, 0);
53881- atomic_set(&totSmBufAllocCount, 0);
53882+ atomic_set_unchecked(&totBufAllocCount, 0);
53883+ atomic_set_unchecked(&totSmBufAllocCount, 0);
53884 #endif /* CONFIG_CIFS_STATS2 */
53885
53886 atomic_set(&midCount, 0);
53887diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
53888index 52ca861..47f309c 100644
53889--- a/fs/cifs/cifsglob.h
53890+++ b/fs/cifs/cifsglob.h
53891@@ -756,35 +756,35 @@ struct cifs_tcon {
53892 __u16 Flags; /* optional support bits */
53893 enum statusEnum tidStatus;
53894 #ifdef CONFIG_CIFS_STATS
53895- atomic_t num_smbs_sent;
53896+ atomic_unchecked_t num_smbs_sent;
53897 union {
53898 struct {
53899- atomic_t num_writes;
53900- atomic_t num_reads;
53901- atomic_t num_flushes;
53902- atomic_t num_oplock_brks;
53903- atomic_t num_opens;
53904- atomic_t num_closes;
53905- atomic_t num_deletes;
53906- atomic_t num_mkdirs;
53907- atomic_t num_posixopens;
53908- atomic_t num_posixmkdirs;
53909- atomic_t num_rmdirs;
53910- atomic_t num_renames;
53911- atomic_t num_t2renames;
53912- atomic_t num_ffirst;
53913- atomic_t num_fnext;
53914- atomic_t num_fclose;
53915- atomic_t num_hardlinks;
53916- atomic_t num_symlinks;
53917- atomic_t num_locks;
53918- atomic_t num_acl_get;
53919- atomic_t num_acl_set;
53920+ atomic_unchecked_t num_writes;
53921+ atomic_unchecked_t num_reads;
53922+ atomic_unchecked_t num_flushes;
53923+ atomic_unchecked_t num_oplock_brks;
53924+ atomic_unchecked_t num_opens;
53925+ atomic_unchecked_t num_closes;
53926+ atomic_unchecked_t num_deletes;
53927+ atomic_unchecked_t num_mkdirs;
53928+ atomic_unchecked_t num_posixopens;
53929+ atomic_unchecked_t num_posixmkdirs;
53930+ atomic_unchecked_t num_rmdirs;
53931+ atomic_unchecked_t num_renames;
53932+ atomic_unchecked_t num_t2renames;
53933+ atomic_unchecked_t num_ffirst;
53934+ atomic_unchecked_t num_fnext;
53935+ atomic_unchecked_t num_fclose;
53936+ atomic_unchecked_t num_hardlinks;
53937+ atomic_unchecked_t num_symlinks;
53938+ atomic_unchecked_t num_locks;
53939+ atomic_unchecked_t num_acl_get;
53940+ atomic_unchecked_t num_acl_set;
53941 } cifs_stats;
53942 #ifdef CONFIG_CIFS_SMB2
53943 struct {
53944- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
53945- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
53946+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
53947+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
53948 } smb2_stats;
53949 #endif /* CONFIG_CIFS_SMB2 */
53950 } stats;
53951@@ -1096,7 +1096,7 @@ convert_delimiter(char *path, char delim)
53952 }
53953
53954 #ifdef CONFIG_CIFS_STATS
53955-#define cifs_stats_inc atomic_inc
53956+#define cifs_stats_inc atomic_inc_unchecked
53957
53958 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
53959 unsigned int bytes)
53960@@ -1461,8 +1461,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
53961 /* Various Debug counters */
53962 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
53963 #ifdef CONFIG_CIFS_STATS2
53964-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
53965-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
53966+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
53967+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
53968 #endif
53969 GLOBAL_EXTERN atomic_t smBufAllocCount;
53970 GLOBAL_EXTERN atomic_t midCount;
53971diff --git a/fs/cifs/link.c b/fs/cifs/link.c
53972index 562044f..4af6a17 100644
53973--- a/fs/cifs/link.c
53974+++ b/fs/cifs/link.c
53975@@ -638,7 +638,7 @@ symlink_exit:
53976
53977 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
53978 {
53979- char *p = nd_get_link(nd);
53980+ const char *p = nd_get_link(nd);
53981 if (!IS_ERR(p))
53982 kfree(p);
53983 }
53984diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
53985index f7d4b22..1254377 100644
53986--- a/fs/cifs/misc.c
53987+++ b/fs/cifs/misc.c
53988@@ -169,7 +169,7 @@ cifs_buf_get(void)
53989 memset(ret_buf, 0, buf_size + 3);
53990 atomic_inc(&bufAllocCount);
53991 #ifdef CONFIG_CIFS_STATS2
53992- atomic_inc(&totBufAllocCount);
53993+ atomic_inc_unchecked(&totBufAllocCount);
53994 #endif /* CONFIG_CIFS_STATS2 */
53995 }
53996
53997@@ -204,7 +204,7 @@ cifs_small_buf_get(void)
53998 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
53999 atomic_inc(&smBufAllocCount);
54000 #ifdef CONFIG_CIFS_STATS2
54001- atomic_inc(&totSmBufAllocCount);
54002+ atomic_inc_unchecked(&totSmBufAllocCount);
54003 #endif /* CONFIG_CIFS_STATS2 */
54004
54005 }
54006diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
54007index 6094397..51e576f 100644
54008--- a/fs/cifs/smb1ops.c
54009+++ b/fs/cifs/smb1ops.c
54010@@ -590,27 +590,27 @@ static void
54011 cifs_clear_stats(struct cifs_tcon *tcon)
54012 {
54013 #ifdef CONFIG_CIFS_STATS
54014- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
54015- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
54016- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
54017- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
54018- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
54019- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
54020- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
54021- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
54022- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
54023- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
54024- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
54025- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
54026- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
54027- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
54028- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
54029- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
54030- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
54031- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
54032- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
54033- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
54034- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
54035+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
54036+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
54037+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
54038+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
54039+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
54040+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
54041+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
54042+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
54043+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
54044+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
54045+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
54046+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
54047+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
54048+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
54049+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
54050+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
54051+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
54052+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
54053+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
54054+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
54055+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
54056 #endif
54057 }
54058
54059@@ -619,36 +619,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
54060 {
54061 #ifdef CONFIG_CIFS_STATS
54062 seq_printf(m, " Oplocks breaks: %d",
54063- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
54064+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
54065 seq_printf(m, "\nReads: %d Bytes: %llu",
54066- atomic_read(&tcon->stats.cifs_stats.num_reads),
54067+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
54068 (long long)(tcon->bytes_read));
54069 seq_printf(m, "\nWrites: %d Bytes: %llu",
54070- atomic_read(&tcon->stats.cifs_stats.num_writes),
54071+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
54072 (long long)(tcon->bytes_written));
54073 seq_printf(m, "\nFlushes: %d",
54074- atomic_read(&tcon->stats.cifs_stats.num_flushes));
54075+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
54076 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
54077- atomic_read(&tcon->stats.cifs_stats.num_locks),
54078- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
54079- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
54080+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
54081+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
54082+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
54083 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
54084- atomic_read(&tcon->stats.cifs_stats.num_opens),
54085- atomic_read(&tcon->stats.cifs_stats.num_closes),
54086- atomic_read(&tcon->stats.cifs_stats.num_deletes));
54087+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
54088+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
54089+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
54090 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
54091- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
54092- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
54093+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
54094+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
54095 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
54096- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
54097- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
54098+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
54099+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
54100 seq_printf(m, "\nRenames: %d T2 Renames %d",
54101- atomic_read(&tcon->stats.cifs_stats.num_renames),
54102- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
54103+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
54104+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
54105 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
54106- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
54107- atomic_read(&tcon->stats.cifs_stats.num_fnext),
54108- atomic_read(&tcon->stats.cifs_stats.num_fclose));
54109+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
54110+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
54111+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
54112 #endif
54113 }
54114
54115diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
54116index f259e6c..ca948ff 100644
54117--- a/fs/cifs/smb2ops.c
54118+++ b/fs/cifs/smb2ops.c
54119@@ -281,8 +281,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
54120 #ifdef CONFIG_CIFS_STATS
54121 int i;
54122 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
54123- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
54124- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
54125+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
54126+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
54127 }
54128 #endif
54129 }
54130@@ -310,65 +310,65 @@ static void
54131 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
54132 {
54133 #ifdef CONFIG_CIFS_STATS
54134- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
54135- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
54136+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
54137+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
54138 seq_printf(m, "\nNegotiates: %d sent %d failed",
54139- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
54140- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
54141+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
54142+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
54143 seq_printf(m, "\nSessionSetups: %d sent %d failed",
54144- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
54145- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
54146+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
54147+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
54148 seq_printf(m, "\nLogoffs: %d sent %d failed",
54149- atomic_read(&sent[SMB2_LOGOFF_HE]),
54150- atomic_read(&failed[SMB2_LOGOFF_HE]));
54151+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
54152+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
54153 seq_printf(m, "\nTreeConnects: %d sent %d failed",
54154- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
54155- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
54156+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
54157+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
54158 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
54159- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
54160- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
54161+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
54162+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
54163 seq_printf(m, "\nCreates: %d sent %d failed",
54164- atomic_read(&sent[SMB2_CREATE_HE]),
54165- atomic_read(&failed[SMB2_CREATE_HE]));
54166+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
54167+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
54168 seq_printf(m, "\nCloses: %d sent %d failed",
54169- atomic_read(&sent[SMB2_CLOSE_HE]),
54170- atomic_read(&failed[SMB2_CLOSE_HE]));
54171+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
54172+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
54173 seq_printf(m, "\nFlushes: %d sent %d failed",
54174- atomic_read(&sent[SMB2_FLUSH_HE]),
54175- atomic_read(&failed[SMB2_FLUSH_HE]));
54176+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
54177+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
54178 seq_printf(m, "\nReads: %d sent %d failed",
54179- atomic_read(&sent[SMB2_READ_HE]),
54180- atomic_read(&failed[SMB2_READ_HE]));
54181+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
54182+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
54183 seq_printf(m, "\nWrites: %d sent %d failed",
54184- atomic_read(&sent[SMB2_WRITE_HE]),
54185- atomic_read(&failed[SMB2_WRITE_HE]));
54186+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
54187+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
54188 seq_printf(m, "\nLocks: %d sent %d failed",
54189- atomic_read(&sent[SMB2_LOCK_HE]),
54190- atomic_read(&failed[SMB2_LOCK_HE]));
54191+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
54192+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
54193 seq_printf(m, "\nIOCTLs: %d sent %d failed",
54194- atomic_read(&sent[SMB2_IOCTL_HE]),
54195- atomic_read(&failed[SMB2_IOCTL_HE]));
54196+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
54197+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
54198 seq_printf(m, "\nCancels: %d sent %d failed",
54199- atomic_read(&sent[SMB2_CANCEL_HE]),
54200- atomic_read(&failed[SMB2_CANCEL_HE]));
54201+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
54202+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
54203 seq_printf(m, "\nEchos: %d sent %d failed",
54204- atomic_read(&sent[SMB2_ECHO_HE]),
54205- atomic_read(&failed[SMB2_ECHO_HE]));
54206+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
54207+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
54208 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
54209- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
54210- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
54211+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
54212+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
54213 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
54214- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
54215- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
54216+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
54217+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
54218 seq_printf(m, "\nQueryInfos: %d sent %d failed",
54219- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
54220- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
54221+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
54222+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
54223 seq_printf(m, "\nSetInfos: %d sent %d failed",
54224- atomic_read(&sent[SMB2_SET_INFO_HE]),
54225- atomic_read(&failed[SMB2_SET_INFO_HE]));
54226+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
54227+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
54228 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
54229- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
54230- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
54231+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
54232+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
54233 #endif
54234 }
54235
54236diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
54237index abc9c28..3fdae28 100644
54238--- a/fs/cifs/smb2pdu.c
54239+++ b/fs/cifs/smb2pdu.c
54240@@ -1946,8 +1946,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
54241 default:
54242 cifs_dbg(VFS, "info level %u isn't supported\n",
54243 srch_inf->info_level);
54244- rc = -EINVAL;
54245- goto qdir_exit;
54246+ return -EINVAL;
54247 }
54248
54249 req->FileIndex = cpu_to_le32(index);
54250diff --git a/fs/coda/cache.c b/fs/coda/cache.c
54251index 1da168c..8bc7ff6 100644
54252--- a/fs/coda/cache.c
54253+++ b/fs/coda/cache.c
54254@@ -24,7 +24,7 @@
54255 #include "coda_linux.h"
54256 #include "coda_cache.h"
54257
54258-static atomic_t permission_epoch = ATOMIC_INIT(0);
54259+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
54260
54261 /* replace or extend an acl cache hit */
54262 void coda_cache_enter(struct inode *inode, int mask)
54263@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
54264 struct coda_inode_info *cii = ITOC(inode);
54265
54266 spin_lock(&cii->c_lock);
54267- cii->c_cached_epoch = atomic_read(&permission_epoch);
54268+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
54269 if (!uid_eq(cii->c_uid, current_fsuid())) {
54270 cii->c_uid = current_fsuid();
54271 cii->c_cached_perm = mask;
54272@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
54273 {
54274 struct coda_inode_info *cii = ITOC(inode);
54275 spin_lock(&cii->c_lock);
54276- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
54277+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
54278 spin_unlock(&cii->c_lock);
54279 }
54280
54281 /* remove all acl caches */
54282 void coda_cache_clear_all(struct super_block *sb)
54283 {
54284- atomic_inc(&permission_epoch);
54285+ atomic_inc_unchecked(&permission_epoch);
54286 }
54287
54288
54289@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
54290 spin_lock(&cii->c_lock);
54291 hit = (mask & cii->c_cached_perm) == mask &&
54292 uid_eq(cii->c_uid, current_fsuid()) &&
54293- cii->c_cached_epoch == atomic_read(&permission_epoch);
54294+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
54295 spin_unlock(&cii->c_lock);
54296
54297 return hit;
54298diff --git a/fs/compat.c b/fs/compat.c
54299index 6af20de..fec3fbb 100644
54300--- a/fs/compat.c
54301+++ b/fs/compat.c
54302@@ -54,7 +54,7 @@
54303 #include <asm/ioctls.h>
54304 #include "internal.h"
54305
54306-int compat_log = 1;
54307+int compat_log = 0;
54308
54309 int compat_printk(const char *fmt, ...)
54310 {
54311@@ -488,7 +488,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
54312
54313 set_fs(KERNEL_DS);
54314 /* The __user pointer cast is valid because of the set_fs() */
54315- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
54316+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
54317 set_fs(oldfs);
54318 /* truncating is ok because it's a user address */
54319 if (!ret)
54320@@ -546,7 +546,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
54321 goto out;
54322
54323 ret = -EINVAL;
54324- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
54325+ if (nr_segs > UIO_MAXIOV)
54326 goto out;
54327 if (nr_segs > fast_segs) {
54328 ret = -ENOMEM;
54329@@ -834,6 +834,7 @@ struct compat_old_linux_dirent {
54330 struct compat_readdir_callback {
54331 struct dir_context ctx;
54332 struct compat_old_linux_dirent __user *dirent;
54333+ struct file * file;
54334 int result;
54335 };
54336
54337@@ -851,6 +852,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
54338 buf->result = -EOVERFLOW;
54339 return -EOVERFLOW;
54340 }
54341+
54342+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
54343+ return 0;
54344+
54345 buf->result++;
54346 dirent = buf->dirent;
54347 if (!access_ok(VERIFY_WRITE, dirent,
54348@@ -882,6 +887,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
54349 if (!f.file)
54350 return -EBADF;
54351
54352+ buf.file = f.file;
54353 error = iterate_dir(f.file, &buf.ctx);
54354 if (buf.result)
54355 error = buf.result;
54356@@ -901,6 +907,7 @@ struct compat_getdents_callback {
54357 struct dir_context ctx;
54358 struct compat_linux_dirent __user *current_dir;
54359 struct compat_linux_dirent __user *previous;
54360+ struct file * file;
54361 int count;
54362 int error;
54363 };
54364@@ -922,6 +929,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
54365 buf->error = -EOVERFLOW;
54366 return -EOVERFLOW;
54367 }
54368+
54369+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
54370+ return 0;
54371+
54372 dirent = buf->previous;
54373 if (dirent) {
54374 if (__put_user(offset, &dirent->d_off))
54375@@ -967,6 +978,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
54376 if (!f.file)
54377 return -EBADF;
54378
54379+ buf.file = f.file;
54380 error = iterate_dir(f.file, &buf.ctx);
54381 if (error >= 0)
54382 error = buf.error;
54383@@ -987,6 +999,7 @@ struct compat_getdents_callback64 {
54384 struct dir_context ctx;
54385 struct linux_dirent64 __user *current_dir;
54386 struct linux_dirent64 __user *previous;
54387+ struct file * file;
54388 int count;
54389 int error;
54390 };
54391@@ -1003,6 +1016,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
54392 buf->error = -EINVAL; /* only used if we fail.. */
54393 if (reclen > buf->count)
54394 return -EINVAL;
54395+
54396+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
54397+ return 0;
54398+
54399 dirent = buf->previous;
54400
54401 if (dirent) {
54402@@ -1052,6 +1069,7 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
54403 if (!f.file)
54404 return -EBADF;
54405
54406+ buf.file = f.file;
54407 error = iterate_dir(f.file, &buf.ctx);
54408 if (error >= 0)
54409 error = buf.error;
54410diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
54411index a81147e..20bf2b5 100644
54412--- a/fs/compat_binfmt_elf.c
54413+++ b/fs/compat_binfmt_elf.c
54414@@ -30,11 +30,13 @@
54415 #undef elf_phdr
54416 #undef elf_shdr
54417 #undef elf_note
54418+#undef elf_dyn
54419 #undef elf_addr_t
54420 #define elfhdr elf32_hdr
54421 #define elf_phdr elf32_phdr
54422 #define elf_shdr elf32_shdr
54423 #define elf_note elf32_note
54424+#define elf_dyn Elf32_Dyn
54425 #define elf_addr_t Elf32_Addr
54426
54427 /*
54428diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
54429index 5d19acf..9ab093b 100644
54430--- a/fs/compat_ioctl.c
54431+++ b/fs/compat_ioctl.c
54432@@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
54433 return -EFAULT;
54434 if (__get_user(udata, &ss32->iomem_base))
54435 return -EFAULT;
54436- ss.iomem_base = compat_ptr(udata);
54437+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
54438 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
54439 __get_user(ss.port_high, &ss32->port_high))
54440 return -EFAULT;
54441@@ -702,8 +702,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
54442 for (i = 0; i < nmsgs; i++) {
54443 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
54444 return -EFAULT;
54445- if (get_user(datap, &umsgs[i].buf) ||
54446- put_user(compat_ptr(datap), &tmsgs[i].buf))
54447+ if (get_user(datap, (u8 __user * __user *)&umsgs[i].buf) ||
54448+ put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
54449 return -EFAULT;
54450 }
54451 return sys_ioctl(fd, cmd, (unsigned long)tdata);
54452@@ -796,7 +796,7 @@ static int compat_ioctl_preallocate(struct file *file,
54453 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
54454 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
54455 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
54456- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
54457+ copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
54458 return -EFAULT;
54459
54460 return ioctl_preallocate(file, p);
54461@@ -1616,8 +1616,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
54462 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
54463 {
54464 unsigned int a, b;
54465- a = *(unsigned int *)p;
54466- b = *(unsigned int *)q;
54467+ a = *(const unsigned int *)p;
54468+ b = *(const unsigned int *)q;
54469 if (a > b)
54470 return 1;
54471 if (a < b)
54472diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
54473index 277bd1b..f312c9e 100644
54474--- a/fs/configfs/dir.c
54475+++ b/fs/configfs/dir.c
54476@@ -1546,7 +1546,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
54477 }
54478 for (p = q->next; p != &parent_sd->s_children; p = p->next) {
54479 struct configfs_dirent *next;
54480- const char *name;
54481+ const unsigned char * name;
54482+ char d_name[sizeof(next->s_dentry->d_iname)];
54483 int len;
54484 struct inode *inode = NULL;
54485
54486@@ -1555,7 +1556,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
54487 continue;
54488
54489 name = configfs_get_name(next);
54490- len = strlen(name);
54491+ if (next->s_dentry && name == next->s_dentry->d_iname) {
54492+ len = next->s_dentry->d_name.len;
54493+ memcpy(d_name, name, len);
54494+ name = d_name;
54495+ } else
54496+ len = strlen(name);
54497
54498 /*
54499 * We'll have a dentry and an inode for
54500diff --git a/fs/coredump.c b/fs/coredump.c
54501index 72f816d..1ba8eff 100644
54502--- a/fs/coredump.c
54503+++ b/fs/coredump.c
54504@@ -433,8 +433,8 @@ static void wait_for_dump_helpers(struct file *file)
54505 struct pipe_inode_info *pipe = file->private_data;
54506
54507 pipe_lock(pipe);
54508- pipe->readers++;
54509- pipe->writers--;
54510+ atomic_inc(&pipe->readers);
54511+ atomic_dec(&pipe->writers);
54512 wake_up_interruptible_sync(&pipe->wait);
54513 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
54514 pipe_unlock(pipe);
54515@@ -443,11 +443,11 @@ static void wait_for_dump_helpers(struct file *file)
54516 * We actually want wait_event_freezable() but then we need
54517 * to clear TIF_SIGPENDING and improve dump_interrupted().
54518 */
54519- wait_event_interruptible(pipe->wait, pipe->readers == 1);
54520+ wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
54521
54522 pipe_lock(pipe);
54523- pipe->readers--;
54524- pipe->writers++;
54525+ atomic_dec(&pipe->readers);
54526+ atomic_inc(&pipe->writers);
54527 pipe_unlock(pipe);
54528 }
54529
54530@@ -494,7 +494,8 @@ void do_coredump(siginfo_t *siginfo)
54531 struct files_struct *displaced;
54532 bool need_nonrelative = false;
54533 bool core_dumped = false;
54534- static atomic_t core_dump_count = ATOMIC_INIT(0);
54535+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
54536+ long signr = siginfo->si_signo;
54537 struct coredump_params cprm = {
54538 .siginfo = siginfo,
54539 .regs = signal_pt_regs(),
54540@@ -507,7 +508,10 @@ void do_coredump(siginfo_t *siginfo)
54541 .mm_flags = mm->flags,
54542 };
54543
54544- audit_core_dumps(siginfo->si_signo);
54545+ audit_core_dumps(signr);
54546+
54547+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
54548+ gr_handle_brute_attach(cprm.mm_flags);
54549
54550 binfmt = mm->binfmt;
54551 if (!binfmt || !binfmt->core_dump)
54552@@ -531,7 +535,7 @@ void do_coredump(siginfo_t *siginfo)
54553 need_nonrelative = true;
54554 }
54555
54556- retval = coredump_wait(siginfo->si_signo, &core_state);
54557+ retval = coredump_wait(signr, &core_state);
54558 if (retval < 0)
54559 goto fail_creds;
54560
54561@@ -574,7 +578,7 @@ void do_coredump(siginfo_t *siginfo)
54562 }
54563 cprm.limit = RLIM_INFINITY;
54564
54565- dump_count = atomic_inc_return(&core_dump_count);
54566+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
54567 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
54568 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
54569 task_tgid_vnr(current), current->comm);
54570@@ -606,6 +610,8 @@ void do_coredump(siginfo_t *siginfo)
54571 } else {
54572 struct inode *inode;
54573
54574+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
54575+
54576 if (cprm.limit < binfmt->min_coredump)
54577 goto fail_unlock;
54578
54579@@ -664,7 +670,7 @@ close_fail:
54580 filp_close(cprm.file, NULL);
54581 fail_dropcount:
54582 if (ispipe)
54583- atomic_dec(&core_dump_count);
54584+ atomic_dec_unchecked(&core_dump_count);
54585 fail_unlock:
54586 kfree(cn.corename);
54587 coredump_finish(mm, core_dumped);
54588@@ -684,7 +690,7 @@ int dump_write(struct file *file, const void *addr, int nr)
54589 {
54590 return !dump_interrupted() &&
54591 access_ok(VERIFY_READ, addr, nr) &&
54592- file->f_op->write(file, addr, nr, &file->f_pos) == nr;
54593+ file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
54594 }
54595 EXPORT_SYMBOL(dump_write);
54596
54597diff --git a/fs/dcache.c b/fs/dcache.c
54598index b949af8..5978926 100644
54599--- a/fs/dcache.c
54600+++ b/fs/dcache.c
54601@@ -3073,7 +3073,8 @@ void __init vfs_caches_init(unsigned long mempages)
54602 mempages -= reserve;
54603
54604 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
54605- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
54606+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
54607+ SLAB_NO_SANITIZE, NULL);
54608
54609 dcache_init();
54610 inode_init();
54611diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
54612index c7c83ff..bda9461 100644
54613--- a/fs/debugfs/inode.c
54614+++ b/fs/debugfs/inode.c
54615@@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
54616 */
54617 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
54618 {
54619+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
54620+ return __create_file(name, S_IFDIR | S_IRWXU,
54621+#else
54622 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
54623+#endif
54624 parent, NULL, NULL);
54625 }
54626 EXPORT_SYMBOL_GPL(debugfs_create_dir);
54627diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
54628index 67e9b63..a9adb68 100644
54629--- a/fs/ecryptfs/inode.c
54630+++ b/fs/ecryptfs/inode.c
54631@@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
54632 old_fs = get_fs();
54633 set_fs(get_ds());
54634 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
54635- (char __user *)lower_buf,
54636+ (char __force_user *)lower_buf,
54637 PATH_MAX);
54638 set_fs(old_fs);
54639 if (rc < 0)
54640@@ -706,7 +706,7 @@ out:
54641 static void
54642 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
54643 {
54644- char *buf = nd_get_link(nd);
54645+ const char *buf = nd_get_link(nd);
54646 if (!IS_ERR(buf)) {
54647 /* Free the char* */
54648 kfree(buf);
54649diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
54650index e4141f2..d8263e8 100644
54651--- a/fs/ecryptfs/miscdev.c
54652+++ b/fs/ecryptfs/miscdev.c
54653@@ -304,7 +304,7 @@ check_list:
54654 goto out_unlock_msg_ctx;
54655 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
54656 if (msg_ctx->msg) {
54657- if (copy_to_user(&buf[i], packet_length, packet_length_size))
54658+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
54659 goto out_unlock_msg_ctx;
54660 i += packet_length_size;
54661 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
54662diff --git a/fs/exec.c b/fs/exec.c
54663index fd774c7..1c6a7bf 100644
54664--- a/fs/exec.c
54665+++ b/fs/exec.c
54666@@ -55,8 +55,20 @@
54667 #include <linux/pipe_fs_i.h>
54668 #include <linux/oom.h>
54669 #include <linux/compat.h>
54670+#include <linux/random.h>
54671+#include <linux/seq_file.h>
54672+#include <linux/coredump.h>
54673+#include <linux/mman.h>
54674+
54675+#ifdef CONFIG_PAX_REFCOUNT
54676+#include <linux/kallsyms.h>
54677+#include <linux/kdebug.h>
54678+#endif
54679+
54680+#include <trace/events/fs.h>
54681
54682 #include <asm/uaccess.h>
54683+#include <asm/sections.h>
54684 #include <asm/mmu_context.h>
54685 #include <asm/tlb.h>
54686
54687@@ -66,17 +78,32 @@
54688
54689 #include <trace/events/sched.h>
54690
54691+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
54692+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
54693+{
54694+ 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");
54695+}
54696+#endif
54697+
54698+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
54699+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
54700+EXPORT_SYMBOL(pax_set_initial_flags_func);
54701+#endif
54702+
54703 int suid_dumpable = 0;
54704
54705 static LIST_HEAD(formats);
54706 static DEFINE_RWLOCK(binfmt_lock);
54707
54708+extern int gr_process_kernel_exec_ban(void);
54709+extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
54710+
54711 void __register_binfmt(struct linux_binfmt * fmt, int insert)
54712 {
54713 BUG_ON(!fmt);
54714 write_lock(&binfmt_lock);
54715- insert ? list_add(&fmt->lh, &formats) :
54716- list_add_tail(&fmt->lh, &formats);
54717+ insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
54718+ pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
54719 write_unlock(&binfmt_lock);
54720 }
54721
54722@@ -85,7 +112,7 @@ EXPORT_SYMBOL(__register_binfmt);
54723 void unregister_binfmt(struct linux_binfmt * fmt)
54724 {
54725 write_lock(&binfmt_lock);
54726- list_del(&fmt->lh);
54727+ pax_list_del((struct list_head *)&fmt->lh);
54728 write_unlock(&binfmt_lock);
54729 }
54730
54731@@ -181,18 +208,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
54732 int write)
54733 {
54734 struct page *page;
54735- int ret;
54736
54737-#ifdef CONFIG_STACK_GROWSUP
54738- if (write) {
54739- ret = expand_downwards(bprm->vma, pos);
54740- if (ret < 0)
54741- return NULL;
54742- }
54743-#endif
54744- ret = get_user_pages(current, bprm->mm, pos,
54745- 1, write, 1, &page, NULL);
54746- if (ret <= 0)
54747+ if (0 > expand_downwards(bprm->vma, pos))
54748+ return NULL;
54749+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
54750 return NULL;
54751
54752 if (write) {
54753@@ -208,6 +227,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
54754 if (size <= ARG_MAX)
54755 return page;
54756
54757+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54758+ // only allow 512KB for argv+env on suid/sgid binaries
54759+ // to prevent easy ASLR exhaustion
54760+ if (((!uid_eq(bprm->cred->euid, current_euid())) ||
54761+ (!gid_eq(bprm->cred->egid, current_egid()))) &&
54762+ (size > (512 * 1024))) {
54763+ put_page(page);
54764+ return NULL;
54765+ }
54766+#endif
54767+
54768 /*
54769 * Limit to 1/4-th the stack size for the argv+env strings.
54770 * This ensures that:
54771@@ -267,6 +297,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
54772 vma->vm_end = STACK_TOP_MAX;
54773 vma->vm_start = vma->vm_end - PAGE_SIZE;
54774 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
54775+
54776+#ifdef CONFIG_PAX_SEGMEXEC
54777+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
54778+#endif
54779+
54780 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
54781 INIT_LIST_HEAD(&vma->anon_vma_chain);
54782
54783@@ -277,6 +312,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
54784 mm->stack_vm = mm->total_vm = 1;
54785 up_write(&mm->mmap_sem);
54786 bprm->p = vma->vm_end - sizeof(void *);
54787+
54788+#ifdef CONFIG_PAX_RANDUSTACK
54789+ if (randomize_va_space)
54790+ bprm->p ^= prandom_u32() & ~PAGE_MASK;
54791+#endif
54792+
54793 return 0;
54794 err:
54795 up_write(&mm->mmap_sem);
54796@@ -397,7 +438,7 @@ struct user_arg_ptr {
54797 } ptr;
54798 };
54799
54800-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
54801+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
54802 {
54803 const char __user *native;
54804
54805@@ -406,14 +447,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
54806 compat_uptr_t compat;
54807
54808 if (get_user(compat, argv.ptr.compat + nr))
54809- return ERR_PTR(-EFAULT);
54810+ return (const char __force_user *)ERR_PTR(-EFAULT);
54811
54812 return compat_ptr(compat);
54813 }
54814 #endif
54815
54816 if (get_user(native, argv.ptr.native + nr))
54817- return ERR_PTR(-EFAULT);
54818+ return (const char __force_user *)ERR_PTR(-EFAULT);
54819
54820 return native;
54821 }
54822@@ -432,7 +473,7 @@ static int count(struct user_arg_ptr argv, int max)
54823 if (!p)
54824 break;
54825
54826- if (IS_ERR(p))
54827+ if (IS_ERR((const char __force_kernel *)p))
54828 return -EFAULT;
54829
54830 if (i >= max)
54831@@ -467,7 +508,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
54832
54833 ret = -EFAULT;
54834 str = get_user_arg_ptr(argv, argc);
54835- if (IS_ERR(str))
54836+ if (IS_ERR((const char __force_kernel *)str))
54837 goto out;
54838
54839 len = strnlen_user(str, MAX_ARG_STRLEN);
54840@@ -549,7 +590,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
54841 int r;
54842 mm_segment_t oldfs = get_fs();
54843 struct user_arg_ptr argv = {
54844- .ptr.native = (const char __user *const __user *)__argv,
54845+ .ptr.native = (const char __force_user * const __force_user *)__argv,
54846 };
54847
54848 set_fs(KERNEL_DS);
54849@@ -584,7 +625,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
54850 unsigned long new_end = old_end - shift;
54851 struct mmu_gather tlb;
54852
54853- BUG_ON(new_start > new_end);
54854+ if (new_start >= new_end || new_start < mmap_min_addr)
54855+ return -ENOMEM;
54856
54857 /*
54858 * ensure there are no vmas between where we want to go
54859@@ -593,6 +635,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
54860 if (vma != find_vma(mm, new_start))
54861 return -EFAULT;
54862
54863+#ifdef CONFIG_PAX_SEGMEXEC
54864+ BUG_ON(pax_find_mirror_vma(vma));
54865+#endif
54866+
54867 /*
54868 * cover the whole range: [new_start, old_end)
54869 */
54870@@ -673,10 +719,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
54871 stack_top = arch_align_stack(stack_top);
54872 stack_top = PAGE_ALIGN(stack_top);
54873
54874- if (unlikely(stack_top < mmap_min_addr) ||
54875- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
54876- return -ENOMEM;
54877-
54878 stack_shift = vma->vm_end - stack_top;
54879
54880 bprm->p -= stack_shift;
54881@@ -688,8 +730,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
54882 bprm->exec -= stack_shift;
54883
54884 down_write(&mm->mmap_sem);
54885+
54886+ /* Move stack pages down in memory. */
54887+ if (stack_shift) {
54888+ ret = shift_arg_pages(vma, stack_shift);
54889+ if (ret)
54890+ goto out_unlock;
54891+ }
54892+
54893 vm_flags = VM_STACK_FLAGS;
54894
54895+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
54896+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
54897+ vm_flags &= ~VM_EXEC;
54898+
54899+#ifdef CONFIG_PAX_MPROTECT
54900+ if (mm->pax_flags & MF_PAX_MPROTECT)
54901+ vm_flags &= ~VM_MAYEXEC;
54902+#endif
54903+
54904+ }
54905+#endif
54906+
54907 /*
54908 * Adjust stack execute permissions; explicitly enable for
54909 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
54910@@ -708,13 +770,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
54911 goto out_unlock;
54912 BUG_ON(prev != vma);
54913
54914- /* Move stack pages down in memory. */
54915- if (stack_shift) {
54916- ret = shift_arg_pages(vma, stack_shift);
54917- if (ret)
54918- goto out_unlock;
54919- }
54920-
54921 /* mprotect_fixup is overkill to remove the temporary stack flags */
54922 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
54923
54924@@ -738,6 +793,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
54925 #endif
54926 current->mm->start_stack = bprm->p;
54927 ret = expand_stack(vma, stack_base);
54928+
54929+#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
54930+ if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
54931+ unsigned long size;
54932+ vm_flags_t vm_flags;
54933+
54934+ size = STACK_TOP - vma->vm_end;
54935+ vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
54936+
54937+ ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
54938+
54939+#ifdef CONFIG_X86
54940+ if (!ret) {
54941+ size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
54942+ ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
54943+ }
54944+#endif
54945+
54946+ }
54947+#endif
54948+
54949 if (ret)
54950 ret = -EFAULT;
54951
54952@@ -774,6 +850,8 @@ struct file *open_exec(const char *name)
54953
54954 fsnotify_open(file);
54955
54956+ trace_open_exec(name);
54957+
54958 err = deny_write_access(file);
54959 if (err)
54960 goto exit;
54961@@ -797,7 +875,7 @@ int kernel_read(struct file *file, loff_t offset,
54962 old_fs = get_fs();
54963 set_fs(get_ds());
54964 /* The cast to a user pointer is valid due to the set_fs() */
54965- result = vfs_read(file, (void __user *)addr, count, &pos);
54966+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
54967 set_fs(old_fs);
54968 return result;
54969 }
54970@@ -1253,7 +1331,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
54971 }
54972 rcu_read_unlock();
54973
54974- if (p->fs->users > n_fs) {
54975+ if (atomic_read(&p->fs->users) > n_fs) {
54976 bprm->unsafe |= LSM_UNSAFE_SHARE;
54977 } else {
54978 res = -EAGAIN;
54979@@ -1453,6 +1531,31 @@ int search_binary_handler(struct linux_binprm *bprm)
54980
54981 EXPORT_SYMBOL(search_binary_handler);
54982
54983+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54984+static DEFINE_PER_CPU(u64, exec_counter);
54985+static int __init init_exec_counters(void)
54986+{
54987+ unsigned int cpu;
54988+
54989+ for_each_possible_cpu(cpu) {
54990+ per_cpu(exec_counter, cpu) = (u64)cpu;
54991+ }
54992+
54993+ return 0;
54994+}
54995+early_initcall(init_exec_counters);
54996+static inline void increment_exec_counter(void)
54997+{
54998+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
54999+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
55000+}
55001+#else
55002+static inline void increment_exec_counter(void) {}
55003+#endif
55004+
55005+extern void gr_handle_exec_args(struct linux_binprm *bprm,
55006+ struct user_arg_ptr argv);
55007+
55008 /*
55009 * sys_execve() executes a new program.
55010 */
55011@@ -1460,12 +1563,19 @@ static int do_execve_common(const char *filename,
55012 struct user_arg_ptr argv,
55013 struct user_arg_ptr envp)
55014 {
55015+#ifdef CONFIG_GRKERNSEC
55016+ struct file *old_exec_file;
55017+ struct acl_subject_label *old_acl;
55018+ struct rlimit old_rlim[RLIM_NLIMITS];
55019+#endif
55020 struct linux_binprm *bprm;
55021 struct file *file;
55022 struct files_struct *displaced;
55023 bool clear_in_exec;
55024 int retval;
55025
55026+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
55027+
55028 /*
55029 * We move the actual failure in case of RLIMIT_NPROC excess from
55030 * set*uid() to execve() because too many poorly written programs
55031@@ -1506,12 +1616,22 @@ static int do_execve_common(const char *filename,
55032 if (IS_ERR(file))
55033 goto out_unmark;
55034
55035+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
55036+ retval = -EPERM;
55037+ goto out_file;
55038+ }
55039+
55040 sched_exec();
55041
55042 bprm->file = file;
55043 bprm->filename = filename;
55044 bprm->interp = filename;
55045
55046+ if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
55047+ retval = -EACCES;
55048+ goto out_file;
55049+ }
55050+
55051 retval = bprm_mm_init(bprm);
55052 if (retval)
55053 goto out_file;
55054@@ -1528,24 +1648,70 @@ static int do_execve_common(const char *filename,
55055 if (retval < 0)
55056 goto out;
55057
55058+#ifdef CONFIG_GRKERNSEC
55059+ old_acl = current->acl;
55060+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
55061+ old_exec_file = current->exec_file;
55062+ get_file(file);
55063+ current->exec_file = file;
55064+#endif
55065+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55066+ /* limit suid stack to 8MB
55067+ * we saved the old limits above and will restore them if this exec fails
55068+ */
55069+ if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
55070+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
55071+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
55072+#endif
55073+
55074+ if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
55075+ retval = -EPERM;
55076+ goto out_fail;
55077+ }
55078+
55079+ if (!gr_tpe_allow(file)) {
55080+ retval = -EACCES;
55081+ goto out_fail;
55082+ }
55083+
55084+ if (gr_check_crash_exec(file)) {
55085+ retval = -EACCES;
55086+ goto out_fail;
55087+ }
55088+
55089+ retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
55090+ bprm->unsafe);
55091+ if (retval < 0)
55092+ goto out_fail;
55093+
55094 retval = copy_strings_kernel(1, &bprm->filename, bprm);
55095 if (retval < 0)
55096- goto out;
55097+ goto out_fail;
55098
55099 bprm->exec = bprm->p;
55100 retval = copy_strings(bprm->envc, envp, bprm);
55101 if (retval < 0)
55102- goto out;
55103+ goto out_fail;
55104
55105 retval = copy_strings(bprm->argc, argv, bprm);
55106 if (retval < 0)
55107- goto out;
55108+ goto out_fail;
55109+
55110+ gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
55111+
55112+ gr_handle_exec_args(bprm, argv);
55113
55114 retval = search_binary_handler(bprm);
55115 if (retval < 0)
55116- goto out;
55117+ goto out_fail;
55118+#ifdef CONFIG_GRKERNSEC
55119+ if (old_exec_file)
55120+ fput(old_exec_file);
55121+#endif
55122
55123 /* execve succeeded */
55124+
55125+ increment_exec_counter();
55126 current->fs->in_exec = 0;
55127 current->in_execve = 0;
55128 acct_update_integrals(current);
55129@@ -1554,6 +1720,14 @@ static int do_execve_common(const char *filename,
55130 put_files_struct(displaced);
55131 return retval;
55132
55133+out_fail:
55134+#ifdef CONFIG_GRKERNSEC
55135+ current->acl = old_acl;
55136+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
55137+ fput(current->exec_file);
55138+ current->exec_file = old_exec_file;
55139+#endif
55140+
55141 out:
55142 if (bprm->mm) {
55143 acct_arg_size(bprm, 0);
55144@@ -1702,3 +1876,287 @@ asmlinkage long compat_sys_execve(const char __user * filename,
55145 return error;
55146 }
55147 #endif
55148+
55149+int pax_check_flags(unsigned long *flags)
55150+{
55151+ int retval = 0;
55152+
55153+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
55154+ if (*flags & MF_PAX_SEGMEXEC)
55155+ {
55156+ *flags &= ~MF_PAX_SEGMEXEC;
55157+ retval = -EINVAL;
55158+ }
55159+#endif
55160+
55161+ if ((*flags & MF_PAX_PAGEEXEC)
55162+
55163+#ifdef CONFIG_PAX_PAGEEXEC
55164+ && (*flags & MF_PAX_SEGMEXEC)
55165+#endif
55166+
55167+ )
55168+ {
55169+ *flags &= ~MF_PAX_PAGEEXEC;
55170+ retval = -EINVAL;
55171+ }
55172+
55173+ if ((*flags & MF_PAX_MPROTECT)
55174+
55175+#ifdef CONFIG_PAX_MPROTECT
55176+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
55177+#endif
55178+
55179+ )
55180+ {
55181+ *flags &= ~MF_PAX_MPROTECT;
55182+ retval = -EINVAL;
55183+ }
55184+
55185+ if ((*flags & MF_PAX_EMUTRAMP)
55186+
55187+#ifdef CONFIG_PAX_EMUTRAMP
55188+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
55189+#endif
55190+
55191+ )
55192+ {
55193+ *flags &= ~MF_PAX_EMUTRAMP;
55194+ retval = -EINVAL;
55195+ }
55196+
55197+ return retval;
55198+}
55199+
55200+EXPORT_SYMBOL(pax_check_flags);
55201+
55202+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
55203+char *pax_get_path(const struct path *path, char *buf, int buflen)
55204+{
55205+ char *pathname = d_path(path, buf, buflen);
55206+
55207+ if (IS_ERR(pathname))
55208+ goto toolong;
55209+
55210+ pathname = mangle_path(buf, pathname, "\t\n\\");
55211+ if (!pathname)
55212+ goto toolong;
55213+
55214+ *pathname = 0;
55215+ return buf;
55216+
55217+toolong:
55218+ return "<path too long>";
55219+}
55220+EXPORT_SYMBOL(pax_get_path);
55221+
55222+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
55223+{
55224+ struct task_struct *tsk = current;
55225+ struct mm_struct *mm = current->mm;
55226+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
55227+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
55228+ char *path_exec = NULL;
55229+ char *path_fault = NULL;
55230+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
55231+ siginfo_t info = { };
55232+
55233+ if (buffer_exec && buffer_fault) {
55234+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
55235+
55236+ down_read(&mm->mmap_sem);
55237+ vma = mm->mmap;
55238+ while (vma && (!vma_exec || !vma_fault)) {
55239+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
55240+ vma_exec = vma;
55241+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
55242+ vma_fault = vma;
55243+ vma = vma->vm_next;
55244+ }
55245+ if (vma_exec)
55246+ path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
55247+ if (vma_fault) {
55248+ start = vma_fault->vm_start;
55249+ end = vma_fault->vm_end;
55250+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
55251+ if (vma_fault->vm_file)
55252+ path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
55253+ else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
55254+ path_fault = "<heap>";
55255+ else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
55256+ path_fault = "<stack>";
55257+ else
55258+ path_fault = "<anonymous mapping>";
55259+ }
55260+ up_read(&mm->mmap_sem);
55261+ }
55262+ if (tsk->signal->curr_ip)
55263+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
55264+ else
55265+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
55266+ 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),
55267+ from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
55268+ free_page((unsigned long)buffer_exec);
55269+ free_page((unsigned long)buffer_fault);
55270+ pax_report_insns(regs, pc, sp);
55271+ info.si_signo = SIGKILL;
55272+ info.si_errno = 0;
55273+ info.si_code = SI_KERNEL;
55274+ info.si_pid = 0;
55275+ info.si_uid = 0;
55276+ do_coredump(&info);
55277+}
55278+#endif
55279+
55280+#ifdef CONFIG_PAX_REFCOUNT
55281+void pax_report_refcount_overflow(struct pt_regs *regs)
55282+{
55283+ if (current->signal->curr_ip)
55284+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
55285+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
55286+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
55287+ else
55288+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
55289+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
55290+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
55291+ preempt_disable();
55292+ show_regs(regs);
55293+ preempt_enable();
55294+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
55295+}
55296+#endif
55297+
55298+#ifdef CONFIG_PAX_USERCOPY
55299+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
55300+static noinline int check_stack_object(const void *obj, unsigned long len)
55301+{
55302+ const void * const stack = task_stack_page(current);
55303+ const void * const stackend = stack + THREAD_SIZE;
55304+
55305+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
55306+ const void *frame = NULL;
55307+ const void *oldframe;
55308+#endif
55309+
55310+ if (obj + len < obj)
55311+ return -1;
55312+
55313+ if (obj + len <= stack || stackend <= obj)
55314+ return 0;
55315+
55316+ if (obj < stack || stackend < obj + len)
55317+ return -1;
55318+
55319+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
55320+ oldframe = __builtin_frame_address(1);
55321+ if (oldframe)
55322+ frame = __builtin_frame_address(2);
55323+ /*
55324+ low ----------------------------------------------> high
55325+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
55326+ ^----------------^
55327+ allow copies only within here
55328+ */
55329+ while (stack <= frame && frame < stackend) {
55330+ /* if obj + len extends past the last frame, this
55331+ check won't pass and the next frame will be 0,
55332+ causing us to bail out and correctly report
55333+ the copy as invalid
55334+ */
55335+ if (obj + len <= frame)
55336+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
55337+ oldframe = frame;
55338+ frame = *(const void * const *)frame;
55339+ }
55340+ return -1;
55341+#else
55342+ return 1;
55343+#endif
55344+}
55345+
55346+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
55347+{
55348+ if (current->signal->curr_ip)
55349+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
55350+ &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
55351+ else
55352+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
55353+ to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
55354+ dump_stack();
55355+ gr_handle_kernel_exploit();
55356+ do_group_exit(SIGKILL);
55357+}
55358+#endif
55359+
55360+#ifdef CONFIG_PAX_USERCOPY
55361+static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
55362+{
55363+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
55364+ unsigned long textlow = ktla_ktva((unsigned long)_stext);
55365+#ifdef CONFIG_MODULES
55366+ unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
55367+#else
55368+ unsigned long texthigh = ktla_ktva((unsigned long)_etext);
55369+#endif
55370+
55371+#else
55372+ unsigned long textlow = (unsigned long)_stext;
55373+ unsigned long texthigh = (unsigned long)_etext;
55374+#endif
55375+
55376+ if (high <= textlow || low > texthigh)
55377+ return false;
55378+ else
55379+ return true;
55380+}
55381+#endif
55382+
55383+void __check_object_size(const void *ptr, unsigned long n, bool to_user)
55384+{
55385+
55386+#ifdef CONFIG_PAX_USERCOPY
55387+ const char *type;
55388+
55389+ if (!n)
55390+ return;
55391+
55392+ type = check_heap_object(ptr, n);
55393+ if (!type) {
55394+ int ret = check_stack_object(ptr, n);
55395+ if (ret == 1 || ret == 2)
55396+ return;
55397+ if (ret == 0) {
55398+ if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
55399+ type = "<kernel text>";
55400+ else
55401+ return;
55402+ } else
55403+ type = "<process stack>";
55404+ }
55405+
55406+ pax_report_usercopy(ptr, n, to_user, type);
55407+#endif
55408+
55409+}
55410+EXPORT_SYMBOL(__check_object_size);
55411+
55412+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
55413+void pax_track_stack(void)
55414+{
55415+ unsigned long sp = (unsigned long)&sp;
55416+ if (sp < current_thread_info()->lowest_stack &&
55417+ sp > (unsigned long)task_stack_page(current))
55418+ current_thread_info()->lowest_stack = sp;
55419+}
55420+EXPORT_SYMBOL(pax_track_stack);
55421+#endif
55422+
55423+#ifdef CONFIG_PAX_SIZE_OVERFLOW
55424+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
55425+{
55426+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
55427+ dump_stack();
55428+ do_group_exit(SIGKILL);
55429+}
55430+EXPORT_SYMBOL(report_size_overflow);
55431+#endif
55432diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
55433index 9f9992b..8b59411 100644
55434--- a/fs/ext2/balloc.c
55435+++ b/fs/ext2/balloc.c
55436@@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
55437
55438 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
55439 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
55440- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
55441+ if (free_blocks < root_blocks + 1 &&
55442 !uid_eq(sbi->s_resuid, current_fsuid()) &&
55443 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
55444- !in_group_p (sbi->s_resgid))) {
55445+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
55446 return 0;
55447 }
55448 return 1;
55449diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
55450index 22548f5..41521d8 100644
55451--- a/fs/ext3/balloc.c
55452+++ b/fs/ext3/balloc.c
55453@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
55454
55455 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
55456 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
55457- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
55458+ if (free_blocks < root_blocks + 1 &&
55459 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
55460 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
55461- !in_group_p (sbi->s_resgid))) {
55462+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
55463 return 0;
55464 }
55465 return 1;
55466diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
55467index ddd715e..c772f88 100644
55468--- a/fs/ext4/balloc.c
55469+++ b/fs/ext4/balloc.c
55470@@ -528,8 +528,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
55471 /* Hm, nope. Are (enough) root reserved clusters available? */
55472 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
55473 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
55474- capable(CAP_SYS_RESOURCE) ||
55475- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
55476+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
55477+ capable_nolog(CAP_SYS_RESOURCE)) {
55478
55479 if (free_clusters >= (nclusters + dirty_clusters +
55480 resv_clusters))
55481diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
55482index 0ab26fb..b6ecb39 100644
55483--- a/fs/ext4/ext4.h
55484+++ b/fs/ext4/ext4.h
55485@@ -1247,19 +1247,19 @@ struct ext4_sb_info {
55486 unsigned long s_mb_last_start;
55487
55488 /* stats for buddy allocator */
55489- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
55490- atomic_t s_bal_success; /* we found long enough chunks */
55491- atomic_t s_bal_allocated; /* in blocks */
55492- atomic_t s_bal_ex_scanned; /* total extents scanned */
55493- atomic_t s_bal_goals; /* goal hits */
55494- atomic_t s_bal_breaks; /* too long searches */
55495- atomic_t s_bal_2orders; /* 2^order hits */
55496+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
55497+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
55498+ atomic_unchecked_t s_bal_allocated; /* in blocks */
55499+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
55500+ atomic_unchecked_t s_bal_goals; /* goal hits */
55501+ atomic_unchecked_t s_bal_breaks; /* too long searches */
55502+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
55503 spinlock_t s_bal_lock;
55504 unsigned long s_mb_buddies_generated;
55505 unsigned long long s_mb_generation_time;
55506- atomic_t s_mb_lost_chunks;
55507- atomic_t s_mb_preallocated;
55508- atomic_t s_mb_discarded;
55509+ atomic_unchecked_t s_mb_lost_chunks;
55510+ atomic_unchecked_t s_mb_preallocated;
55511+ atomic_unchecked_t s_mb_discarded;
55512 atomic_t s_lock_busy;
55513
55514 /* locality groups */
55515diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
55516index 4bbbf13b..dcceaeb 100644
55517--- a/fs/ext4/mballoc.c
55518+++ b/fs/ext4/mballoc.c
55519@@ -1865,7 +1865,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
55520 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
55521
55522 if (EXT4_SB(sb)->s_mb_stats)
55523- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
55524+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
55525
55526 break;
55527 }
55528@@ -2171,7 +2171,7 @@ repeat:
55529 ac->ac_status = AC_STATUS_CONTINUE;
55530 ac->ac_flags |= EXT4_MB_HINT_FIRST;
55531 cr = 3;
55532- atomic_inc(&sbi->s_mb_lost_chunks);
55533+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
55534 goto repeat;
55535 }
55536 }
55537@@ -2679,25 +2679,25 @@ int ext4_mb_release(struct super_block *sb)
55538 if (sbi->s_mb_stats) {
55539 ext4_msg(sb, KERN_INFO,
55540 "mballoc: %u blocks %u reqs (%u success)",
55541- atomic_read(&sbi->s_bal_allocated),
55542- atomic_read(&sbi->s_bal_reqs),
55543- atomic_read(&sbi->s_bal_success));
55544+ atomic_read_unchecked(&sbi->s_bal_allocated),
55545+ atomic_read_unchecked(&sbi->s_bal_reqs),
55546+ atomic_read_unchecked(&sbi->s_bal_success));
55547 ext4_msg(sb, KERN_INFO,
55548 "mballoc: %u extents scanned, %u goal hits, "
55549 "%u 2^N hits, %u breaks, %u lost",
55550- atomic_read(&sbi->s_bal_ex_scanned),
55551- atomic_read(&sbi->s_bal_goals),
55552- atomic_read(&sbi->s_bal_2orders),
55553- atomic_read(&sbi->s_bal_breaks),
55554- atomic_read(&sbi->s_mb_lost_chunks));
55555+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
55556+ atomic_read_unchecked(&sbi->s_bal_goals),
55557+ atomic_read_unchecked(&sbi->s_bal_2orders),
55558+ atomic_read_unchecked(&sbi->s_bal_breaks),
55559+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
55560 ext4_msg(sb, KERN_INFO,
55561 "mballoc: %lu generated and it took %Lu",
55562 sbi->s_mb_buddies_generated,
55563 sbi->s_mb_generation_time);
55564 ext4_msg(sb, KERN_INFO,
55565 "mballoc: %u preallocated, %u discarded",
55566- atomic_read(&sbi->s_mb_preallocated),
55567- atomic_read(&sbi->s_mb_discarded));
55568+ atomic_read_unchecked(&sbi->s_mb_preallocated),
55569+ atomic_read_unchecked(&sbi->s_mb_discarded));
55570 }
55571
55572 free_percpu(sbi->s_locality_groups);
55573@@ -3151,16 +3151,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
55574 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
55575
55576 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
55577- atomic_inc(&sbi->s_bal_reqs);
55578- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
55579+ atomic_inc_unchecked(&sbi->s_bal_reqs);
55580+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
55581 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
55582- atomic_inc(&sbi->s_bal_success);
55583- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
55584+ atomic_inc_unchecked(&sbi->s_bal_success);
55585+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
55586 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
55587 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
55588- atomic_inc(&sbi->s_bal_goals);
55589+ atomic_inc_unchecked(&sbi->s_bal_goals);
55590 if (ac->ac_found > sbi->s_mb_max_to_scan)
55591- atomic_inc(&sbi->s_bal_breaks);
55592+ atomic_inc_unchecked(&sbi->s_bal_breaks);
55593 }
55594
55595 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
55596@@ -3560,7 +3560,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
55597 trace_ext4_mb_new_inode_pa(ac, pa);
55598
55599 ext4_mb_use_inode_pa(ac, pa);
55600- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
55601+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
55602
55603 ei = EXT4_I(ac->ac_inode);
55604 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
55605@@ -3620,7 +3620,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
55606 trace_ext4_mb_new_group_pa(ac, pa);
55607
55608 ext4_mb_use_group_pa(ac, pa);
55609- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
55610+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
55611
55612 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
55613 lg = ac->ac_lg;
55614@@ -3709,7 +3709,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
55615 * from the bitmap and continue.
55616 */
55617 }
55618- atomic_add(free, &sbi->s_mb_discarded);
55619+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
55620
55621 return err;
55622 }
55623@@ -3727,7 +3727,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
55624 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
55625 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
55626 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
55627- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
55628+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
55629 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
55630
55631 return 0;
55632diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
55633index 214461e..3614c89 100644
55634--- a/fs/ext4/mmp.c
55635+++ b/fs/ext4/mmp.c
55636@@ -113,7 +113,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
55637 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
55638 const char *function, unsigned int line, const char *msg)
55639 {
55640- __ext4_warning(sb, function, line, msg);
55641+ __ext4_warning(sb, function, line, "%s", msg);
55642 __ext4_warning(sb, function, line,
55643 "MMP failure info: last update time: %llu, last update "
55644 "node: %s, last update device: %s\n",
55645diff --git a/fs/ext4/super.c b/fs/ext4/super.c
55646index b59373b..f41c2b5 100644
55647--- a/fs/ext4/super.c
55648+++ b/fs/ext4/super.c
55649@@ -1254,7 +1254,7 @@ static ext4_fsblk_t get_sb_block(void **data)
55650 }
55651
55652 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
55653-static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
55654+static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
55655 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
55656
55657 #ifdef CONFIG_QUOTA
55658@@ -2394,7 +2394,7 @@ struct ext4_attr {
55659 int offset;
55660 int deprecated_val;
55661 } u;
55662-};
55663+} __do_const;
55664
55665 static int parse_strtoull(const char *buf,
55666 unsigned long long max, unsigned long long *value)
55667diff --git a/fs/fcntl.c b/fs/fcntl.c
55668index 65343c3..9969dcf 100644
55669--- a/fs/fcntl.c
55670+++ b/fs/fcntl.c
55671@@ -107,6 +107,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
55672 if (err)
55673 return err;
55674
55675+ if (gr_handle_chroot_fowner(pid, type))
55676+ return -ENOENT;
55677+ if (gr_check_protected_task_fowner(pid, type))
55678+ return -EACCES;
55679+
55680 f_modown(filp, pid, type, force);
55681 return 0;
55682 }
55683diff --git a/fs/fhandle.c b/fs/fhandle.c
55684index 999ff5c..41f4109 100644
55685--- a/fs/fhandle.c
55686+++ b/fs/fhandle.c
55687@@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
55688 } else
55689 retval = 0;
55690 /* copy the mount id */
55691- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
55692- sizeof(*mnt_id)) ||
55693+ if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
55694 copy_to_user(ufh, handle,
55695 sizeof(struct file_handle) + handle_bytes))
55696 retval = -EFAULT;
55697diff --git a/fs/file.c b/fs/file.c
55698index 4a78f98..9447397 100644
55699--- a/fs/file.c
55700+++ b/fs/file.c
55701@@ -16,6 +16,7 @@
55702 #include <linux/slab.h>
55703 #include <linux/vmalloc.h>
55704 #include <linux/file.h>
55705+#include <linux/security.h>
55706 #include <linux/fdtable.h>
55707 #include <linux/bitops.h>
55708 #include <linux/interrupt.h>
55709@@ -828,6 +829,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
55710 if (!file)
55711 return __close_fd(files, fd);
55712
55713+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
55714 if (fd >= rlimit(RLIMIT_NOFILE))
55715 return -EBADF;
55716
55717@@ -854,6 +856,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
55718 if (unlikely(oldfd == newfd))
55719 return -EINVAL;
55720
55721+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
55722 if (newfd >= rlimit(RLIMIT_NOFILE))
55723 return -EBADF;
55724
55725@@ -909,6 +912,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
55726 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
55727 {
55728 int err;
55729+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
55730 if (from >= rlimit(RLIMIT_NOFILE))
55731 return -EINVAL;
55732 err = alloc_fd(from, flags);
55733diff --git a/fs/filesystems.c b/fs/filesystems.c
55734index 92567d9..fcd8cbf 100644
55735--- a/fs/filesystems.c
55736+++ b/fs/filesystems.c
55737@@ -273,7 +273,11 @@ struct file_system_type *get_fs_type(const char *name)
55738 int len = dot ? dot - name : strlen(name);
55739
55740 fs = __get_fs_type(name, len);
55741+#ifdef CONFIG_GRKERNSEC_MODHARDEN
55742+ if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
55743+#else
55744 if (!fs && (request_module("fs-%.*s", len, name) == 0))
55745+#endif
55746 fs = __get_fs_type(name, len);
55747
55748 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
55749diff --git a/fs/fs_struct.c b/fs/fs_struct.c
55750index d8ac61d..79a36f0 100644
55751--- a/fs/fs_struct.c
55752+++ b/fs/fs_struct.c
55753@@ -4,6 +4,7 @@
55754 #include <linux/path.h>
55755 #include <linux/slab.h>
55756 #include <linux/fs_struct.h>
55757+#include <linux/grsecurity.h>
55758 #include "internal.h"
55759
55760 /*
55761@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
55762 write_seqcount_begin(&fs->seq);
55763 old_root = fs->root;
55764 fs->root = *path;
55765+ gr_set_chroot_entries(current, path);
55766 write_seqcount_end(&fs->seq);
55767 spin_unlock(&fs->lock);
55768 if (old_root.dentry)
55769@@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
55770 int hits = 0;
55771 spin_lock(&fs->lock);
55772 write_seqcount_begin(&fs->seq);
55773+ /* this root replacement is only done by pivot_root,
55774+ leave grsec's chroot tagging alone for this task
55775+ so that a pivoted root isn't treated as a chroot
55776+ */
55777 hits += replace_path(&fs->root, old_root, new_root);
55778 hits += replace_path(&fs->pwd, old_root, new_root);
55779 write_seqcount_end(&fs->seq);
55780@@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
55781 task_lock(tsk);
55782 spin_lock(&fs->lock);
55783 tsk->fs = NULL;
55784- kill = !--fs->users;
55785+ gr_clear_chroot_entries(tsk);
55786+ kill = !atomic_dec_return(&fs->users);
55787 spin_unlock(&fs->lock);
55788 task_unlock(tsk);
55789 if (kill)
55790@@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
55791 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
55792 /* We don't need to lock fs - think why ;-) */
55793 if (fs) {
55794- fs->users = 1;
55795+ atomic_set(&fs->users, 1);
55796 fs->in_exec = 0;
55797 spin_lock_init(&fs->lock);
55798 seqcount_init(&fs->seq);
55799@@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
55800 spin_lock(&old->lock);
55801 fs->root = old->root;
55802 path_get(&fs->root);
55803+ /* instead of calling gr_set_chroot_entries here,
55804+ we call it from every caller of this function
55805+ */
55806 fs->pwd = old->pwd;
55807 path_get(&fs->pwd);
55808 spin_unlock(&old->lock);
55809@@ -139,8 +149,9 @@ int unshare_fs_struct(void)
55810
55811 task_lock(current);
55812 spin_lock(&fs->lock);
55813- kill = !--fs->users;
55814+ kill = !atomic_dec_return(&fs->users);
55815 current->fs = new_fs;
55816+ gr_set_chroot_entries(current, &new_fs->root);
55817 spin_unlock(&fs->lock);
55818 task_unlock(current);
55819
55820@@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
55821
55822 int current_umask(void)
55823 {
55824- return current->fs->umask;
55825+ return current->fs->umask | gr_acl_umask();
55826 }
55827 EXPORT_SYMBOL(current_umask);
55828
55829 /* to be mentioned only in INIT_TASK */
55830 struct fs_struct init_fs = {
55831- .users = 1,
55832+ .users = ATOMIC_INIT(1),
55833 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
55834 .seq = SEQCNT_ZERO,
55835 .umask = 0022,
55836diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
55837index 0e91a3c..6c6d2e0 100644
55838--- a/fs/fscache/cookie.c
55839+++ b/fs/fscache/cookie.c
55840@@ -19,7 +19,7 @@
55841
55842 struct kmem_cache *fscache_cookie_jar;
55843
55844-static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
55845+static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
55846
55847 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
55848 static int fscache_alloc_object(struct fscache_cache *cache,
55849@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
55850 parent ? (char *) parent->def->name : "<no-parent>",
55851 def->name, netfs_data);
55852
55853- fscache_stat(&fscache_n_acquires);
55854+ fscache_stat_unchecked(&fscache_n_acquires);
55855
55856 /* if there's no parent cookie, then we don't create one here either */
55857 if (!parent) {
55858- fscache_stat(&fscache_n_acquires_null);
55859+ fscache_stat_unchecked(&fscache_n_acquires_null);
55860 _leave(" [no parent]");
55861 return NULL;
55862 }
55863@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
55864 /* allocate and initialise a cookie */
55865 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
55866 if (!cookie) {
55867- fscache_stat(&fscache_n_acquires_oom);
55868+ fscache_stat_unchecked(&fscache_n_acquires_oom);
55869 _leave(" [ENOMEM]");
55870 return NULL;
55871 }
55872@@ -114,13 +114,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
55873
55874 switch (cookie->def->type) {
55875 case FSCACHE_COOKIE_TYPE_INDEX:
55876- fscache_stat(&fscache_n_cookie_index);
55877+ fscache_stat_unchecked(&fscache_n_cookie_index);
55878 break;
55879 case FSCACHE_COOKIE_TYPE_DATAFILE:
55880- fscache_stat(&fscache_n_cookie_data);
55881+ fscache_stat_unchecked(&fscache_n_cookie_data);
55882 break;
55883 default:
55884- fscache_stat(&fscache_n_cookie_special);
55885+ fscache_stat_unchecked(&fscache_n_cookie_special);
55886 break;
55887 }
55888
55889@@ -131,13 +131,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
55890 if (fscache_acquire_non_index_cookie(cookie) < 0) {
55891 atomic_dec(&parent->n_children);
55892 __fscache_cookie_put(cookie);
55893- fscache_stat(&fscache_n_acquires_nobufs);
55894+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
55895 _leave(" = NULL");
55896 return NULL;
55897 }
55898 }
55899
55900- fscache_stat(&fscache_n_acquires_ok);
55901+ fscache_stat_unchecked(&fscache_n_acquires_ok);
55902 _leave(" = %p", cookie);
55903 return cookie;
55904 }
55905@@ -173,7 +173,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
55906 cache = fscache_select_cache_for_object(cookie->parent);
55907 if (!cache) {
55908 up_read(&fscache_addremove_sem);
55909- fscache_stat(&fscache_n_acquires_no_cache);
55910+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
55911 _leave(" = -ENOMEDIUM [no cache]");
55912 return -ENOMEDIUM;
55913 }
55914@@ -259,14 +259,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
55915 object = cache->ops->alloc_object(cache, cookie);
55916 fscache_stat_d(&fscache_n_cop_alloc_object);
55917 if (IS_ERR(object)) {
55918- fscache_stat(&fscache_n_object_no_alloc);
55919+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
55920 ret = PTR_ERR(object);
55921 goto error;
55922 }
55923
55924- fscache_stat(&fscache_n_object_alloc);
55925+ fscache_stat_unchecked(&fscache_n_object_alloc);
55926
55927- object->debug_id = atomic_inc_return(&fscache_object_debug_id);
55928+ object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
55929
55930 _debug("ALLOC OBJ%x: %s {%lx}",
55931 object->debug_id, cookie->def->name, object->events);
55932@@ -380,7 +380,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
55933
55934 _enter("{%s}", cookie->def->name);
55935
55936- fscache_stat(&fscache_n_invalidates);
55937+ fscache_stat_unchecked(&fscache_n_invalidates);
55938
55939 /* Only permit invalidation of data files. Invalidating an index will
55940 * require the caller to release all its attachments to the tree rooted
55941@@ -438,10 +438,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
55942 {
55943 struct fscache_object *object;
55944
55945- fscache_stat(&fscache_n_updates);
55946+ fscache_stat_unchecked(&fscache_n_updates);
55947
55948 if (!cookie) {
55949- fscache_stat(&fscache_n_updates_null);
55950+ fscache_stat_unchecked(&fscache_n_updates_null);
55951 _leave(" [no cookie]");
55952 return;
55953 }
55954@@ -473,12 +473,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
55955 {
55956 struct fscache_object *object;
55957
55958- fscache_stat(&fscache_n_relinquishes);
55959+ fscache_stat_unchecked(&fscache_n_relinquishes);
55960 if (retire)
55961- fscache_stat(&fscache_n_relinquishes_retire);
55962+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
55963
55964 if (!cookie) {
55965- fscache_stat(&fscache_n_relinquishes_null);
55966+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
55967 _leave(" [no cookie]");
55968 return;
55969 }
55970diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
55971index 12d505b..86473a3 100644
55972--- a/fs/fscache/internal.h
55973+++ b/fs/fscache/internal.h
55974@@ -147,101 +147,101 @@ extern void fscache_proc_cleanup(void);
55975 * stats.c
55976 */
55977 #ifdef CONFIG_FSCACHE_STATS
55978-extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
55979-extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
55980+extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
55981+extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
55982
55983-extern atomic_t fscache_n_op_pend;
55984-extern atomic_t fscache_n_op_run;
55985-extern atomic_t fscache_n_op_enqueue;
55986-extern atomic_t fscache_n_op_deferred_release;
55987-extern atomic_t fscache_n_op_release;
55988-extern atomic_t fscache_n_op_gc;
55989-extern atomic_t fscache_n_op_cancelled;
55990-extern atomic_t fscache_n_op_rejected;
55991+extern atomic_unchecked_t fscache_n_op_pend;
55992+extern atomic_unchecked_t fscache_n_op_run;
55993+extern atomic_unchecked_t fscache_n_op_enqueue;
55994+extern atomic_unchecked_t fscache_n_op_deferred_release;
55995+extern atomic_unchecked_t fscache_n_op_release;
55996+extern atomic_unchecked_t fscache_n_op_gc;
55997+extern atomic_unchecked_t fscache_n_op_cancelled;
55998+extern atomic_unchecked_t fscache_n_op_rejected;
55999
56000-extern atomic_t fscache_n_attr_changed;
56001-extern atomic_t fscache_n_attr_changed_ok;
56002-extern atomic_t fscache_n_attr_changed_nobufs;
56003-extern atomic_t fscache_n_attr_changed_nomem;
56004-extern atomic_t fscache_n_attr_changed_calls;
56005+extern atomic_unchecked_t fscache_n_attr_changed;
56006+extern atomic_unchecked_t fscache_n_attr_changed_ok;
56007+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
56008+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
56009+extern atomic_unchecked_t fscache_n_attr_changed_calls;
56010
56011-extern atomic_t fscache_n_allocs;
56012-extern atomic_t fscache_n_allocs_ok;
56013-extern atomic_t fscache_n_allocs_wait;
56014-extern atomic_t fscache_n_allocs_nobufs;
56015-extern atomic_t fscache_n_allocs_intr;
56016-extern atomic_t fscache_n_allocs_object_dead;
56017-extern atomic_t fscache_n_alloc_ops;
56018-extern atomic_t fscache_n_alloc_op_waits;
56019+extern atomic_unchecked_t fscache_n_allocs;
56020+extern atomic_unchecked_t fscache_n_allocs_ok;
56021+extern atomic_unchecked_t fscache_n_allocs_wait;
56022+extern atomic_unchecked_t fscache_n_allocs_nobufs;
56023+extern atomic_unchecked_t fscache_n_allocs_intr;
56024+extern atomic_unchecked_t fscache_n_allocs_object_dead;
56025+extern atomic_unchecked_t fscache_n_alloc_ops;
56026+extern atomic_unchecked_t fscache_n_alloc_op_waits;
56027
56028-extern atomic_t fscache_n_retrievals;
56029-extern atomic_t fscache_n_retrievals_ok;
56030-extern atomic_t fscache_n_retrievals_wait;
56031-extern atomic_t fscache_n_retrievals_nodata;
56032-extern atomic_t fscache_n_retrievals_nobufs;
56033-extern atomic_t fscache_n_retrievals_intr;
56034-extern atomic_t fscache_n_retrievals_nomem;
56035-extern atomic_t fscache_n_retrievals_object_dead;
56036-extern atomic_t fscache_n_retrieval_ops;
56037-extern atomic_t fscache_n_retrieval_op_waits;
56038+extern atomic_unchecked_t fscache_n_retrievals;
56039+extern atomic_unchecked_t fscache_n_retrievals_ok;
56040+extern atomic_unchecked_t fscache_n_retrievals_wait;
56041+extern atomic_unchecked_t fscache_n_retrievals_nodata;
56042+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
56043+extern atomic_unchecked_t fscache_n_retrievals_intr;
56044+extern atomic_unchecked_t fscache_n_retrievals_nomem;
56045+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
56046+extern atomic_unchecked_t fscache_n_retrieval_ops;
56047+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
56048
56049-extern atomic_t fscache_n_stores;
56050-extern atomic_t fscache_n_stores_ok;
56051-extern atomic_t fscache_n_stores_again;
56052-extern atomic_t fscache_n_stores_nobufs;
56053-extern atomic_t fscache_n_stores_oom;
56054-extern atomic_t fscache_n_store_ops;
56055-extern atomic_t fscache_n_store_calls;
56056-extern atomic_t fscache_n_store_pages;
56057-extern atomic_t fscache_n_store_radix_deletes;
56058-extern atomic_t fscache_n_store_pages_over_limit;
56059+extern atomic_unchecked_t fscache_n_stores;
56060+extern atomic_unchecked_t fscache_n_stores_ok;
56061+extern atomic_unchecked_t fscache_n_stores_again;
56062+extern atomic_unchecked_t fscache_n_stores_nobufs;
56063+extern atomic_unchecked_t fscache_n_stores_oom;
56064+extern atomic_unchecked_t fscache_n_store_ops;
56065+extern atomic_unchecked_t fscache_n_store_calls;
56066+extern atomic_unchecked_t fscache_n_store_pages;
56067+extern atomic_unchecked_t fscache_n_store_radix_deletes;
56068+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
56069
56070-extern atomic_t fscache_n_store_vmscan_not_storing;
56071-extern atomic_t fscache_n_store_vmscan_gone;
56072-extern atomic_t fscache_n_store_vmscan_busy;
56073-extern atomic_t fscache_n_store_vmscan_cancelled;
56074-extern atomic_t fscache_n_store_vmscan_wait;
56075+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
56076+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
56077+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
56078+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
56079+extern atomic_unchecked_t fscache_n_store_vmscan_wait;
56080
56081-extern atomic_t fscache_n_marks;
56082-extern atomic_t fscache_n_uncaches;
56083+extern atomic_unchecked_t fscache_n_marks;
56084+extern atomic_unchecked_t fscache_n_uncaches;
56085
56086-extern atomic_t fscache_n_acquires;
56087-extern atomic_t fscache_n_acquires_null;
56088-extern atomic_t fscache_n_acquires_no_cache;
56089-extern atomic_t fscache_n_acquires_ok;
56090-extern atomic_t fscache_n_acquires_nobufs;
56091-extern atomic_t fscache_n_acquires_oom;
56092+extern atomic_unchecked_t fscache_n_acquires;
56093+extern atomic_unchecked_t fscache_n_acquires_null;
56094+extern atomic_unchecked_t fscache_n_acquires_no_cache;
56095+extern atomic_unchecked_t fscache_n_acquires_ok;
56096+extern atomic_unchecked_t fscache_n_acquires_nobufs;
56097+extern atomic_unchecked_t fscache_n_acquires_oom;
56098
56099-extern atomic_t fscache_n_invalidates;
56100-extern atomic_t fscache_n_invalidates_run;
56101+extern atomic_unchecked_t fscache_n_invalidates;
56102+extern atomic_unchecked_t fscache_n_invalidates_run;
56103
56104-extern atomic_t fscache_n_updates;
56105-extern atomic_t fscache_n_updates_null;
56106-extern atomic_t fscache_n_updates_run;
56107+extern atomic_unchecked_t fscache_n_updates;
56108+extern atomic_unchecked_t fscache_n_updates_null;
56109+extern atomic_unchecked_t fscache_n_updates_run;
56110
56111-extern atomic_t fscache_n_relinquishes;
56112-extern atomic_t fscache_n_relinquishes_null;
56113-extern atomic_t fscache_n_relinquishes_waitcrt;
56114-extern atomic_t fscache_n_relinquishes_retire;
56115+extern atomic_unchecked_t fscache_n_relinquishes;
56116+extern atomic_unchecked_t fscache_n_relinquishes_null;
56117+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
56118+extern atomic_unchecked_t fscache_n_relinquishes_retire;
56119
56120-extern atomic_t fscache_n_cookie_index;
56121-extern atomic_t fscache_n_cookie_data;
56122-extern atomic_t fscache_n_cookie_special;
56123+extern atomic_unchecked_t fscache_n_cookie_index;
56124+extern atomic_unchecked_t fscache_n_cookie_data;
56125+extern atomic_unchecked_t fscache_n_cookie_special;
56126
56127-extern atomic_t fscache_n_object_alloc;
56128-extern atomic_t fscache_n_object_no_alloc;
56129-extern atomic_t fscache_n_object_lookups;
56130-extern atomic_t fscache_n_object_lookups_negative;
56131-extern atomic_t fscache_n_object_lookups_positive;
56132-extern atomic_t fscache_n_object_lookups_timed_out;
56133-extern atomic_t fscache_n_object_created;
56134-extern atomic_t fscache_n_object_avail;
56135-extern atomic_t fscache_n_object_dead;
56136+extern atomic_unchecked_t fscache_n_object_alloc;
56137+extern atomic_unchecked_t fscache_n_object_no_alloc;
56138+extern atomic_unchecked_t fscache_n_object_lookups;
56139+extern atomic_unchecked_t fscache_n_object_lookups_negative;
56140+extern atomic_unchecked_t fscache_n_object_lookups_positive;
56141+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
56142+extern atomic_unchecked_t fscache_n_object_created;
56143+extern atomic_unchecked_t fscache_n_object_avail;
56144+extern atomic_unchecked_t fscache_n_object_dead;
56145
56146-extern atomic_t fscache_n_checkaux_none;
56147-extern atomic_t fscache_n_checkaux_okay;
56148-extern atomic_t fscache_n_checkaux_update;
56149-extern atomic_t fscache_n_checkaux_obsolete;
56150+extern atomic_unchecked_t fscache_n_checkaux_none;
56151+extern atomic_unchecked_t fscache_n_checkaux_okay;
56152+extern atomic_unchecked_t fscache_n_checkaux_update;
56153+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
56154
56155 extern atomic_t fscache_n_cop_alloc_object;
56156 extern atomic_t fscache_n_cop_lookup_object;
56157@@ -266,6 +266,11 @@ static inline void fscache_stat(atomic_t *stat)
56158 atomic_inc(stat);
56159 }
56160
56161+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
56162+{
56163+ atomic_inc_unchecked(stat);
56164+}
56165+
56166 static inline void fscache_stat_d(atomic_t *stat)
56167 {
56168 atomic_dec(stat);
56169@@ -278,6 +283,7 @@ extern const struct file_operations fscache_stats_fops;
56170
56171 #define __fscache_stat(stat) (NULL)
56172 #define fscache_stat(stat) do {} while (0)
56173+#define fscache_stat_unchecked(stat) do {} while (0)
56174 #define fscache_stat_d(stat) do {} while (0)
56175 #endif
56176
56177diff --git a/fs/fscache/object.c b/fs/fscache/object.c
56178index 86d75a6..5f3d7a0 100644
56179--- a/fs/fscache/object.c
56180+++ b/fs/fscache/object.c
56181@@ -451,7 +451,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
56182 _debug("LOOKUP \"%s\" in \"%s\"",
56183 cookie->def->name, object->cache->tag->name);
56184
56185- fscache_stat(&fscache_n_object_lookups);
56186+ fscache_stat_unchecked(&fscache_n_object_lookups);
56187 fscache_stat(&fscache_n_cop_lookup_object);
56188 ret = object->cache->ops->lookup_object(object);
56189 fscache_stat_d(&fscache_n_cop_lookup_object);
56190@@ -461,7 +461,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
56191 if (ret == -ETIMEDOUT) {
56192 /* probably stuck behind another object, so move this one to
56193 * the back of the queue */
56194- fscache_stat(&fscache_n_object_lookups_timed_out);
56195+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
56196 _leave(" [timeout]");
56197 return NO_TRANSIT;
56198 }
56199@@ -489,7 +489,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
56200 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
56201
56202 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
56203- fscache_stat(&fscache_n_object_lookups_negative);
56204+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
56205
56206 /* Allow write requests to begin stacking up and read requests to begin
56207 * returning ENODATA.
56208@@ -523,7 +523,7 @@ void fscache_obtained_object(struct fscache_object *object)
56209 /* if we were still looking up, then we must have a positive lookup
56210 * result, in which case there may be data available */
56211 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
56212- fscache_stat(&fscache_n_object_lookups_positive);
56213+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
56214
56215 /* We do (presumably) have data */
56216 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
56217@@ -534,7 +534,7 @@ void fscache_obtained_object(struct fscache_object *object)
56218 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
56219 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
56220 } else {
56221- fscache_stat(&fscache_n_object_created);
56222+ fscache_stat_unchecked(&fscache_n_object_created);
56223 }
56224
56225 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
56226@@ -570,7 +570,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
56227 fscache_stat_d(&fscache_n_cop_lookup_complete);
56228
56229 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
56230- fscache_stat(&fscache_n_object_avail);
56231+ fscache_stat_unchecked(&fscache_n_object_avail);
56232
56233 _leave("");
56234 return transit_to(JUMPSTART_DEPS);
56235@@ -716,7 +716,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
56236
56237 /* this just shifts the object release to the work processor */
56238 fscache_put_object(object);
56239- fscache_stat(&fscache_n_object_dead);
56240+ fscache_stat_unchecked(&fscache_n_object_dead);
56241
56242 _leave("");
56243 return transit_to(OBJECT_DEAD);
56244@@ -881,7 +881,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
56245 enum fscache_checkaux result;
56246
56247 if (!object->cookie->def->check_aux) {
56248- fscache_stat(&fscache_n_checkaux_none);
56249+ fscache_stat_unchecked(&fscache_n_checkaux_none);
56250 return FSCACHE_CHECKAUX_OKAY;
56251 }
56252
56253@@ -890,17 +890,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
56254 switch (result) {
56255 /* entry okay as is */
56256 case FSCACHE_CHECKAUX_OKAY:
56257- fscache_stat(&fscache_n_checkaux_okay);
56258+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
56259 break;
56260
56261 /* entry requires update */
56262 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
56263- fscache_stat(&fscache_n_checkaux_update);
56264+ fscache_stat_unchecked(&fscache_n_checkaux_update);
56265 break;
56266
56267 /* entry requires deletion */
56268 case FSCACHE_CHECKAUX_OBSOLETE:
56269- fscache_stat(&fscache_n_checkaux_obsolete);
56270+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
56271 break;
56272
56273 default:
56274@@ -986,7 +986,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
56275 {
56276 const struct fscache_state *s;
56277
56278- fscache_stat(&fscache_n_invalidates_run);
56279+ fscache_stat_unchecked(&fscache_n_invalidates_run);
56280 fscache_stat(&fscache_n_cop_invalidate_object);
56281 s = _fscache_invalidate_object(object, event);
56282 fscache_stat_d(&fscache_n_cop_invalidate_object);
56283@@ -1001,7 +1001,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
56284 {
56285 _enter("{OBJ%x},%d", object->debug_id, event);
56286
56287- fscache_stat(&fscache_n_updates_run);
56288+ fscache_stat_unchecked(&fscache_n_updates_run);
56289 fscache_stat(&fscache_n_cop_update_object);
56290 object->cache->ops->update_object(object);
56291 fscache_stat_d(&fscache_n_cop_update_object);
56292diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
56293index 318071a..379938b 100644
56294--- a/fs/fscache/operation.c
56295+++ b/fs/fscache/operation.c
56296@@ -17,7 +17,7 @@
56297 #include <linux/slab.h>
56298 #include "internal.h"
56299
56300-atomic_t fscache_op_debug_id;
56301+atomic_unchecked_t fscache_op_debug_id;
56302 EXPORT_SYMBOL(fscache_op_debug_id);
56303
56304 /**
56305@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
56306 ASSERTCMP(atomic_read(&op->usage), >, 0);
56307 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
56308
56309- fscache_stat(&fscache_n_op_enqueue);
56310+ fscache_stat_unchecked(&fscache_n_op_enqueue);
56311 switch (op->flags & FSCACHE_OP_TYPE) {
56312 case FSCACHE_OP_ASYNC:
56313 _debug("queue async");
56314@@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
56315 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
56316 if (op->processor)
56317 fscache_enqueue_operation(op);
56318- fscache_stat(&fscache_n_op_run);
56319+ fscache_stat_unchecked(&fscache_n_op_run);
56320 }
56321
56322 /*
56323@@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
56324 if (object->n_in_progress > 0) {
56325 atomic_inc(&op->usage);
56326 list_add_tail(&op->pend_link, &object->pending_ops);
56327- fscache_stat(&fscache_n_op_pend);
56328+ fscache_stat_unchecked(&fscache_n_op_pend);
56329 } else if (!list_empty(&object->pending_ops)) {
56330 atomic_inc(&op->usage);
56331 list_add_tail(&op->pend_link, &object->pending_ops);
56332- fscache_stat(&fscache_n_op_pend);
56333+ fscache_stat_unchecked(&fscache_n_op_pend);
56334 fscache_start_operations(object);
56335 } else {
56336 ASSERTCMP(object->n_in_progress, ==, 0);
56337@@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
56338 object->n_exclusive++; /* reads and writes must wait */
56339 atomic_inc(&op->usage);
56340 list_add_tail(&op->pend_link, &object->pending_ops);
56341- fscache_stat(&fscache_n_op_pend);
56342+ fscache_stat_unchecked(&fscache_n_op_pend);
56343 ret = 0;
56344 } else {
56345 /* If we're in any other state, there must have been an I/O
56346@@ -212,11 +212,11 @@ int fscache_submit_op(struct fscache_object *object,
56347 if (object->n_exclusive > 0) {
56348 atomic_inc(&op->usage);
56349 list_add_tail(&op->pend_link, &object->pending_ops);
56350- fscache_stat(&fscache_n_op_pend);
56351+ fscache_stat_unchecked(&fscache_n_op_pend);
56352 } else if (!list_empty(&object->pending_ops)) {
56353 atomic_inc(&op->usage);
56354 list_add_tail(&op->pend_link, &object->pending_ops);
56355- fscache_stat(&fscache_n_op_pend);
56356+ fscache_stat_unchecked(&fscache_n_op_pend);
56357 fscache_start_operations(object);
56358 } else {
56359 ASSERTCMP(object->n_exclusive, ==, 0);
56360@@ -228,10 +228,10 @@ int fscache_submit_op(struct fscache_object *object,
56361 object->n_ops++;
56362 atomic_inc(&op->usage);
56363 list_add_tail(&op->pend_link, &object->pending_ops);
56364- fscache_stat(&fscache_n_op_pend);
56365+ fscache_stat_unchecked(&fscache_n_op_pend);
56366 ret = 0;
56367 } else if (fscache_object_is_dying(object)) {
56368- fscache_stat(&fscache_n_op_rejected);
56369+ fscache_stat_unchecked(&fscache_n_op_rejected);
56370 op->state = FSCACHE_OP_ST_CANCELLED;
56371 ret = -ENOBUFS;
56372 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
56373@@ -310,7 +310,7 @@ int fscache_cancel_op(struct fscache_operation *op,
56374 ret = -EBUSY;
56375 if (op->state == FSCACHE_OP_ST_PENDING) {
56376 ASSERT(!list_empty(&op->pend_link));
56377- fscache_stat(&fscache_n_op_cancelled);
56378+ fscache_stat_unchecked(&fscache_n_op_cancelled);
56379 list_del_init(&op->pend_link);
56380 if (do_cancel)
56381 do_cancel(op);
56382@@ -342,7 +342,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
56383 while (!list_empty(&object->pending_ops)) {
56384 op = list_entry(object->pending_ops.next,
56385 struct fscache_operation, pend_link);
56386- fscache_stat(&fscache_n_op_cancelled);
56387+ fscache_stat_unchecked(&fscache_n_op_cancelled);
56388 list_del_init(&op->pend_link);
56389
56390 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
56391@@ -414,7 +414,7 @@ void fscache_put_operation(struct fscache_operation *op)
56392 op->state, ==, FSCACHE_OP_ST_CANCELLED);
56393 op->state = FSCACHE_OP_ST_DEAD;
56394
56395- fscache_stat(&fscache_n_op_release);
56396+ fscache_stat_unchecked(&fscache_n_op_release);
56397
56398 if (op->release) {
56399 op->release(op);
56400@@ -433,7 +433,7 @@ void fscache_put_operation(struct fscache_operation *op)
56401 * lock, and defer it otherwise */
56402 if (!spin_trylock(&object->lock)) {
56403 _debug("defer put");
56404- fscache_stat(&fscache_n_op_deferred_release);
56405+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
56406
56407 cache = object->cache;
56408 spin_lock(&cache->op_gc_list_lock);
56409@@ -486,7 +486,7 @@ void fscache_operation_gc(struct work_struct *work)
56410
56411 _debug("GC DEFERRED REL OBJ%x OP%x",
56412 object->debug_id, op->debug_id);
56413- fscache_stat(&fscache_n_op_gc);
56414+ fscache_stat_unchecked(&fscache_n_op_gc);
56415
56416 ASSERTCMP(atomic_read(&op->usage), ==, 0);
56417 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
56418diff --git a/fs/fscache/page.c b/fs/fscache/page.c
56419index d479ab3..727a7f2 100644
56420--- a/fs/fscache/page.c
56421+++ b/fs/fscache/page.c
56422@@ -61,7 +61,7 @@ try_again:
56423 val = radix_tree_lookup(&cookie->stores, page->index);
56424 if (!val) {
56425 rcu_read_unlock();
56426- fscache_stat(&fscache_n_store_vmscan_not_storing);
56427+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
56428 __fscache_uncache_page(cookie, page);
56429 return true;
56430 }
56431@@ -91,11 +91,11 @@ try_again:
56432 spin_unlock(&cookie->stores_lock);
56433
56434 if (xpage) {
56435- fscache_stat(&fscache_n_store_vmscan_cancelled);
56436- fscache_stat(&fscache_n_store_radix_deletes);
56437+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
56438+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
56439 ASSERTCMP(xpage, ==, page);
56440 } else {
56441- fscache_stat(&fscache_n_store_vmscan_gone);
56442+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
56443 }
56444
56445 wake_up_bit(&cookie->flags, 0);
56446@@ -110,11 +110,11 @@ page_busy:
56447 * sleeping on memory allocation, so we may need to impose a timeout
56448 * too. */
56449 if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
56450- fscache_stat(&fscache_n_store_vmscan_busy);
56451+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
56452 return false;
56453 }
56454
56455- fscache_stat(&fscache_n_store_vmscan_wait);
56456+ fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
56457 __fscache_wait_on_page_write(cookie, page);
56458 gfp &= ~__GFP_WAIT;
56459 goto try_again;
56460@@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
56461 FSCACHE_COOKIE_STORING_TAG);
56462 if (!radix_tree_tag_get(&cookie->stores, page->index,
56463 FSCACHE_COOKIE_PENDING_TAG)) {
56464- fscache_stat(&fscache_n_store_radix_deletes);
56465+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
56466 xpage = radix_tree_delete(&cookie->stores, page->index);
56467 }
56468 spin_unlock(&cookie->stores_lock);
56469@@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
56470
56471 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
56472
56473- fscache_stat(&fscache_n_attr_changed_calls);
56474+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
56475
56476 if (fscache_object_is_active(object) &&
56477 fscache_use_cookie(object)) {
56478@@ -189,11 +189,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
56479
56480 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
56481
56482- fscache_stat(&fscache_n_attr_changed);
56483+ fscache_stat_unchecked(&fscache_n_attr_changed);
56484
56485 op = kzalloc(sizeof(*op), GFP_KERNEL);
56486 if (!op) {
56487- fscache_stat(&fscache_n_attr_changed_nomem);
56488+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
56489 _leave(" = -ENOMEM");
56490 return -ENOMEM;
56491 }
56492@@ -211,7 +211,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
56493 if (fscache_submit_exclusive_op(object, op) < 0)
56494 goto nobufs;
56495 spin_unlock(&cookie->lock);
56496- fscache_stat(&fscache_n_attr_changed_ok);
56497+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
56498 fscache_put_operation(op);
56499 _leave(" = 0");
56500 return 0;
56501@@ -219,7 +219,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
56502 nobufs:
56503 spin_unlock(&cookie->lock);
56504 kfree(op);
56505- fscache_stat(&fscache_n_attr_changed_nobufs);
56506+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
56507 _leave(" = %d", -ENOBUFS);
56508 return -ENOBUFS;
56509 }
56510@@ -258,7 +258,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
56511 /* allocate a retrieval operation and attempt to submit it */
56512 op = kzalloc(sizeof(*op), GFP_NOIO);
56513 if (!op) {
56514- fscache_stat(&fscache_n_retrievals_nomem);
56515+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
56516 return NULL;
56517 }
56518
56519@@ -289,13 +289,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
56520 return 0;
56521 }
56522
56523- fscache_stat(&fscache_n_retrievals_wait);
56524+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
56525
56526 jif = jiffies;
56527 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
56528 fscache_wait_bit_interruptible,
56529 TASK_INTERRUPTIBLE) != 0) {
56530- fscache_stat(&fscache_n_retrievals_intr);
56531+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
56532 _leave(" = -ERESTARTSYS");
56533 return -ERESTARTSYS;
56534 }
56535@@ -324,8 +324,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
56536 */
56537 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
56538 struct fscache_retrieval *op,
56539- atomic_t *stat_op_waits,
56540- atomic_t *stat_object_dead)
56541+ atomic_unchecked_t *stat_op_waits,
56542+ atomic_unchecked_t *stat_object_dead)
56543 {
56544 int ret;
56545
56546@@ -333,7 +333,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
56547 goto check_if_dead;
56548
56549 _debug(">>> WT");
56550- fscache_stat(stat_op_waits);
56551+ fscache_stat_unchecked(stat_op_waits);
56552 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
56553 fscache_wait_bit_interruptible,
56554 TASK_INTERRUPTIBLE) != 0) {
56555@@ -350,14 +350,14 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
56556
56557 check_if_dead:
56558 if (op->op.state == FSCACHE_OP_ST_CANCELLED) {
56559- fscache_stat(stat_object_dead);
56560+ fscache_stat_unchecked(stat_object_dead);
56561 _leave(" = -ENOBUFS [cancelled]");
56562 return -ENOBUFS;
56563 }
56564 if (unlikely(fscache_object_is_dead(object))) {
56565 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->op.state);
56566 fscache_cancel_op(&op->op, fscache_do_cancel_retrieval);
56567- fscache_stat(stat_object_dead);
56568+ fscache_stat_unchecked(stat_object_dead);
56569 return -ENOBUFS;
56570 }
56571 return 0;
56572@@ -384,7 +384,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
56573
56574 _enter("%p,%p,,,", cookie, page);
56575
56576- fscache_stat(&fscache_n_retrievals);
56577+ fscache_stat_unchecked(&fscache_n_retrievals);
56578
56579 if (hlist_empty(&cookie->backing_objects))
56580 goto nobufs;
56581@@ -424,7 +424,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
56582 goto nobufs_unlock_dec;
56583 spin_unlock(&cookie->lock);
56584
56585- fscache_stat(&fscache_n_retrieval_ops);
56586+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
56587
56588 /* pin the netfs read context in case we need to do the actual netfs
56589 * read because we've encountered a cache read failure */
56590@@ -454,15 +454,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
56591
56592 error:
56593 if (ret == -ENOMEM)
56594- fscache_stat(&fscache_n_retrievals_nomem);
56595+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
56596 else if (ret == -ERESTARTSYS)
56597- fscache_stat(&fscache_n_retrievals_intr);
56598+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
56599 else if (ret == -ENODATA)
56600- fscache_stat(&fscache_n_retrievals_nodata);
56601+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
56602 else if (ret < 0)
56603- fscache_stat(&fscache_n_retrievals_nobufs);
56604+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
56605 else
56606- fscache_stat(&fscache_n_retrievals_ok);
56607+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
56608
56609 fscache_put_retrieval(op);
56610 _leave(" = %d", ret);
56611@@ -475,7 +475,7 @@ nobufs_unlock:
56612 atomic_dec(&cookie->n_active);
56613 kfree(op);
56614 nobufs:
56615- fscache_stat(&fscache_n_retrievals_nobufs);
56616+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
56617 _leave(" = -ENOBUFS");
56618 return -ENOBUFS;
56619 }
56620@@ -513,7 +513,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
56621
56622 _enter("%p,,%d,,,", cookie, *nr_pages);
56623
56624- fscache_stat(&fscache_n_retrievals);
56625+ fscache_stat_unchecked(&fscache_n_retrievals);
56626
56627 if (hlist_empty(&cookie->backing_objects))
56628 goto nobufs;
56629@@ -549,7 +549,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
56630 goto nobufs_unlock_dec;
56631 spin_unlock(&cookie->lock);
56632
56633- fscache_stat(&fscache_n_retrieval_ops);
56634+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
56635
56636 /* pin the netfs read context in case we need to do the actual netfs
56637 * read because we've encountered a cache read failure */
56638@@ -579,15 +579,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
56639
56640 error:
56641 if (ret == -ENOMEM)
56642- fscache_stat(&fscache_n_retrievals_nomem);
56643+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
56644 else if (ret == -ERESTARTSYS)
56645- fscache_stat(&fscache_n_retrievals_intr);
56646+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
56647 else if (ret == -ENODATA)
56648- fscache_stat(&fscache_n_retrievals_nodata);
56649+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
56650 else if (ret < 0)
56651- fscache_stat(&fscache_n_retrievals_nobufs);
56652+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
56653 else
56654- fscache_stat(&fscache_n_retrievals_ok);
56655+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
56656
56657 fscache_put_retrieval(op);
56658 _leave(" = %d", ret);
56659@@ -600,7 +600,7 @@ nobufs_unlock:
56660 atomic_dec(&cookie->n_active);
56661 kfree(op);
56662 nobufs:
56663- fscache_stat(&fscache_n_retrievals_nobufs);
56664+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
56665 _leave(" = -ENOBUFS");
56666 return -ENOBUFS;
56667 }
56668@@ -624,7 +624,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
56669
56670 _enter("%p,%p,,,", cookie, page);
56671
56672- fscache_stat(&fscache_n_allocs);
56673+ fscache_stat_unchecked(&fscache_n_allocs);
56674
56675 if (hlist_empty(&cookie->backing_objects))
56676 goto nobufs;
56677@@ -656,7 +656,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
56678 goto nobufs_unlock;
56679 spin_unlock(&cookie->lock);
56680
56681- fscache_stat(&fscache_n_alloc_ops);
56682+ fscache_stat_unchecked(&fscache_n_alloc_ops);
56683
56684 ret = fscache_wait_for_retrieval_activation(
56685 object, op,
56686@@ -672,11 +672,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
56687
56688 error:
56689 if (ret == -ERESTARTSYS)
56690- fscache_stat(&fscache_n_allocs_intr);
56691+ fscache_stat_unchecked(&fscache_n_allocs_intr);
56692 else if (ret < 0)
56693- fscache_stat(&fscache_n_allocs_nobufs);
56694+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
56695 else
56696- fscache_stat(&fscache_n_allocs_ok);
56697+ fscache_stat_unchecked(&fscache_n_allocs_ok);
56698
56699 fscache_put_retrieval(op);
56700 _leave(" = %d", ret);
56701@@ -687,7 +687,7 @@ nobufs_unlock:
56702 atomic_dec(&cookie->n_active);
56703 kfree(op);
56704 nobufs:
56705- fscache_stat(&fscache_n_allocs_nobufs);
56706+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
56707 _leave(" = -ENOBUFS");
56708 return -ENOBUFS;
56709 }
56710@@ -747,7 +747,7 @@ static void fscache_write_op(struct fscache_operation *_op)
56711
56712 spin_lock(&cookie->stores_lock);
56713
56714- fscache_stat(&fscache_n_store_calls);
56715+ fscache_stat_unchecked(&fscache_n_store_calls);
56716
56717 /* find a page to store */
56718 page = NULL;
56719@@ -758,7 +758,7 @@ static void fscache_write_op(struct fscache_operation *_op)
56720 page = results[0];
56721 _debug("gang %d [%lx]", n, page->index);
56722 if (page->index > op->store_limit) {
56723- fscache_stat(&fscache_n_store_pages_over_limit);
56724+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
56725 goto superseded;
56726 }
56727
56728@@ -770,7 +770,7 @@ static void fscache_write_op(struct fscache_operation *_op)
56729 spin_unlock(&cookie->stores_lock);
56730 spin_unlock(&object->lock);
56731
56732- fscache_stat(&fscache_n_store_pages);
56733+ fscache_stat_unchecked(&fscache_n_store_pages);
56734 fscache_stat(&fscache_n_cop_write_page);
56735 ret = object->cache->ops->write_page(op, page);
56736 fscache_stat_d(&fscache_n_cop_write_page);
56737@@ -873,7 +873,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
56738 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
56739 ASSERT(PageFsCache(page));
56740
56741- fscache_stat(&fscache_n_stores);
56742+ fscache_stat_unchecked(&fscache_n_stores);
56743
56744 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
56745 _leave(" = -ENOBUFS [invalidating]");
56746@@ -931,7 +931,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
56747 spin_unlock(&cookie->stores_lock);
56748 spin_unlock(&object->lock);
56749
56750- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
56751+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
56752 op->store_limit = object->store_limit;
56753
56754 atomic_inc(&cookie->n_active);
56755@@ -940,8 +940,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
56756
56757 spin_unlock(&cookie->lock);
56758 radix_tree_preload_end();
56759- fscache_stat(&fscache_n_store_ops);
56760- fscache_stat(&fscache_n_stores_ok);
56761+ fscache_stat_unchecked(&fscache_n_store_ops);
56762+ fscache_stat_unchecked(&fscache_n_stores_ok);
56763
56764 /* the work queue now carries its own ref on the object */
56765 fscache_put_operation(&op->op);
56766@@ -949,14 +949,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
56767 return 0;
56768
56769 already_queued:
56770- fscache_stat(&fscache_n_stores_again);
56771+ fscache_stat_unchecked(&fscache_n_stores_again);
56772 already_pending:
56773 spin_unlock(&cookie->stores_lock);
56774 spin_unlock(&object->lock);
56775 spin_unlock(&cookie->lock);
56776 radix_tree_preload_end();
56777 kfree(op);
56778- fscache_stat(&fscache_n_stores_ok);
56779+ fscache_stat_unchecked(&fscache_n_stores_ok);
56780 _leave(" = 0");
56781 return 0;
56782
56783@@ -976,14 +976,14 @@ nobufs:
56784 spin_unlock(&cookie->lock);
56785 radix_tree_preload_end();
56786 kfree(op);
56787- fscache_stat(&fscache_n_stores_nobufs);
56788+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
56789 _leave(" = -ENOBUFS");
56790 return -ENOBUFS;
56791
56792 nomem_free:
56793 kfree(op);
56794 nomem:
56795- fscache_stat(&fscache_n_stores_oom);
56796+ fscache_stat_unchecked(&fscache_n_stores_oom);
56797 _leave(" = -ENOMEM");
56798 return -ENOMEM;
56799 }
56800@@ -1001,7 +1001,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
56801 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
56802 ASSERTCMP(page, !=, NULL);
56803
56804- fscache_stat(&fscache_n_uncaches);
56805+ fscache_stat_unchecked(&fscache_n_uncaches);
56806
56807 /* cache withdrawal may beat us to it */
56808 if (!PageFsCache(page))
56809@@ -1052,7 +1052,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
56810 struct fscache_cookie *cookie = op->op.object->cookie;
56811
56812 #ifdef CONFIG_FSCACHE_STATS
56813- atomic_inc(&fscache_n_marks);
56814+ atomic_inc_unchecked(&fscache_n_marks);
56815 #endif
56816
56817 _debug("- mark %p{%lx}", page, page->index);
56818diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
56819index 40d13c7..ddf52b9 100644
56820--- a/fs/fscache/stats.c
56821+++ b/fs/fscache/stats.c
56822@@ -18,99 +18,99 @@
56823 /*
56824 * operation counters
56825 */
56826-atomic_t fscache_n_op_pend;
56827-atomic_t fscache_n_op_run;
56828-atomic_t fscache_n_op_enqueue;
56829-atomic_t fscache_n_op_requeue;
56830-atomic_t fscache_n_op_deferred_release;
56831-atomic_t fscache_n_op_release;
56832-atomic_t fscache_n_op_gc;
56833-atomic_t fscache_n_op_cancelled;
56834-atomic_t fscache_n_op_rejected;
56835+atomic_unchecked_t fscache_n_op_pend;
56836+atomic_unchecked_t fscache_n_op_run;
56837+atomic_unchecked_t fscache_n_op_enqueue;
56838+atomic_unchecked_t fscache_n_op_requeue;
56839+atomic_unchecked_t fscache_n_op_deferred_release;
56840+atomic_unchecked_t fscache_n_op_release;
56841+atomic_unchecked_t fscache_n_op_gc;
56842+atomic_unchecked_t fscache_n_op_cancelled;
56843+atomic_unchecked_t fscache_n_op_rejected;
56844
56845-atomic_t fscache_n_attr_changed;
56846-atomic_t fscache_n_attr_changed_ok;
56847-atomic_t fscache_n_attr_changed_nobufs;
56848-atomic_t fscache_n_attr_changed_nomem;
56849-atomic_t fscache_n_attr_changed_calls;
56850+atomic_unchecked_t fscache_n_attr_changed;
56851+atomic_unchecked_t fscache_n_attr_changed_ok;
56852+atomic_unchecked_t fscache_n_attr_changed_nobufs;
56853+atomic_unchecked_t fscache_n_attr_changed_nomem;
56854+atomic_unchecked_t fscache_n_attr_changed_calls;
56855
56856-atomic_t fscache_n_allocs;
56857-atomic_t fscache_n_allocs_ok;
56858-atomic_t fscache_n_allocs_wait;
56859-atomic_t fscache_n_allocs_nobufs;
56860-atomic_t fscache_n_allocs_intr;
56861-atomic_t fscache_n_allocs_object_dead;
56862-atomic_t fscache_n_alloc_ops;
56863-atomic_t fscache_n_alloc_op_waits;
56864+atomic_unchecked_t fscache_n_allocs;
56865+atomic_unchecked_t fscache_n_allocs_ok;
56866+atomic_unchecked_t fscache_n_allocs_wait;
56867+atomic_unchecked_t fscache_n_allocs_nobufs;
56868+atomic_unchecked_t fscache_n_allocs_intr;
56869+atomic_unchecked_t fscache_n_allocs_object_dead;
56870+atomic_unchecked_t fscache_n_alloc_ops;
56871+atomic_unchecked_t fscache_n_alloc_op_waits;
56872
56873-atomic_t fscache_n_retrievals;
56874-atomic_t fscache_n_retrievals_ok;
56875-atomic_t fscache_n_retrievals_wait;
56876-atomic_t fscache_n_retrievals_nodata;
56877-atomic_t fscache_n_retrievals_nobufs;
56878-atomic_t fscache_n_retrievals_intr;
56879-atomic_t fscache_n_retrievals_nomem;
56880-atomic_t fscache_n_retrievals_object_dead;
56881-atomic_t fscache_n_retrieval_ops;
56882-atomic_t fscache_n_retrieval_op_waits;
56883+atomic_unchecked_t fscache_n_retrievals;
56884+atomic_unchecked_t fscache_n_retrievals_ok;
56885+atomic_unchecked_t fscache_n_retrievals_wait;
56886+atomic_unchecked_t fscache_n_retrievals_nodata;
56887+atomic_unchecked_t fscache_n_retrievals_nobufs;
56888+atomic_unchecked_t fscache_n_retrievals_intr;
56889+atomic_unchecked_t fscache_n_retrievals_nomem;
56890+atomic_unchecked_t fscache_n_retrievals_object_dead;
56891+atomic_unchecked_t fscache_n_retrieval_ops;
56892+atomic_unchecked_t fscache_n_retrieval_op_waits;
56893
56894-atomic_t fscache_n_stores;
56895-atomic_t fscache_n_stores_ok;
56896-atomic_t fscache_n_stores_again;
56897-atomic_t fscache_n_stores_nobufs;
56898-atomic_t fscache_n_stores_oom;
56899-atomic_t fscache_n_store_ops;
56900-atomic_t fscache_n_store_calls;
56901-atomic_t fscache_n_store_pages;
56902-atomic_t fscache_n_store_radix_deletes;
56903-atomic_t fscache_n_store_pages_over_limit;
56904+atomic_unchecked_t fscache_n_stores;
56905+atomic_unchecked_t fscache_n_stores_ok;
56906+atomic_unchecked_t fscache_n_stores_again;
56907+atomic_unchecked_t fscache_n_stores_nobufs;
56908+atomic_unchecked_t fscache_n_stores_oom;
56909+atomic_unchecked_t fscache_n_store_ops;
56910+atomic_unchecked_t fscache_n_store_calls;
56911+atomic_unchecked_t fscache_n_store_pages;
56912+atomic_unchecked_t fscache_n_store_radix_deletes;
56913+atomic_unchecked_t fscache_n_store_pages_over_limit;
56914
56915-atomic_t fscache_n_store_vmscan_not_storing;
56916-atomic_t fscache_n_store_vmscan_gone;
56917-atomic_t fscache_n_store_vmscan_busy;
56918-atomic_t fscache_n_store_vmscan_cancelled;
56919-atomic_t fscache_n_store_vmscan_wait;
56920+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
56921+atomic_unchecked_t fscache_n_store_vmscan_gone;
56922+atomic_unchecked_t fscache_n_store_vmscan_busy;
56923+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
56924+atomic_unchecked_t fscache_n_store_vmscan_wait;
56925
56926-atomic_t fscache_n_marks;
56927-atomic_t fscache_n_uncaches;
56928+atomic_unchecked_t fscache_n_marks;
56929+atomic_unchecked_t fscache_n_uncaches;
56930
56931-atomic_t fscache_n_acquires;
56932-atomic_t fscache_n_acquires_null;
56933-atomic_t fscache_n_acquires_no_cache;
56934-atomic_t fscache_n_acquires_ok;
56935-atomic_t fscache_n_acquires_nobufs;
56936-atomic_t fscache_n_acquires_oom;
56937+atomic_unchecked_t fscache_n_acquires;
56938+atomic_unchecked_t fscache_n_acquires_null;
56939+atomic_unchecked_t fscache_n_acquires_no_cache;
56940+atomic_unchecked_t fscache_n_acquires_ok;
56941+atomic_unchecked_t fscache_n_acquires_nobufs;
56942+atomic_unchecked_t fscache_n_acquires_oom;
56943
56944-atomic_t fscache_n_invalidates;
56945-atomic_t fscache_n_invalidates_run;
56946+atomic_unchecked_t fscache_n_invalidates;
56947+atomic_unchecked_t fscache_n_invalidates_run;
56948
56949-atomic_t fscache_n_updates;
56950-atomic_t fscache_n_updates_null;
56951-atomic_t fscache_n_updates_run;
56952+atomic_unchecked_t fscache_n_updates;
56953+atomic_unchecked_t fscache_n_updates_null;
56954+atomic_unchecked_t fscache_n_updates_run;
56955
56956-atomic_t fscache_n_relinquishes;
56957-atomic_t fscache_n_relinquishes_null;
56958-atomic_t fscache_n_relinquishes_waitcrt;
56959-atomic_t fscache_n_relinquishes_retire;
56960+atomic_unchecked_t fscache_n_relinquishes;
56961+atomic_unchecked_t fscache_n_relinquishes_null;
56962+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
56963+atomic_unchecked_t fscache_n_relinquishes_retire;
56964
56965-atomic_t fscache_n_cookie_index;
56966-atomic_t fscache_n_cookie_data;
56967-atomic_t fscache_n_cookie_special;
56968+atomic_unchecked_t fscache_n_cookie_index;
56969+atomic_unchecked_t fscache_n_cookie_data;
56970+atomic_unchecked_t fscache_n_cookie_special;
56971
56972-atomic_t fscache_n_object_alloc;
56973-atomic_t fscache_n_object_no_alloc;
56974-atomic_t fscache_n_object_lookups;
56975-atomic_t fscache_n_object_lookups_negative;
56976-atomic_t fscache_n_object_lookups_positive;
56977-atomic_t fscache_n_object_lookups_timed_out;
56978-atomic_t fscache_n_object_created;
56979-atomic_t fscache_n_object_avail;
56980-atomic_t fscache_n_object_dead;
56981+atomic_unchecked_t fscache_n_object_alloc;
56982+atomic_unchecked_t fscache_n_object_no_alloc;
56983+atomic_unchecked_t fscache_n_object_lookups;
56984+atomic_unchecked_t fscache_n_object_lookups_negative;
56985+atomic_unchecked_t fscache_n_object_lookups_positive;
56986+atomic_unchecked_t fscache_n_object_lookups_timed_out;
56987+atomic_unchecked_t fscache_n_object_created;
56988+atomic_unchecked_t fscache_n_object_avail;
56989+atomic_unchecked_t fscache_n_object_dead;
56990
56991-atomic_t fscache_n_checkaux_none;
56992-atomic_t fscache_n_checkaux_okay;
56993-atomic_t fscache_n_checkaux_update;
56994-atomic_t fscache_n_checkaux_obsolete;
56995+atomic_unchecked_t fscache_n_checkaux_none;
56996+atomic_unchecked_t fscache_n_checkaux_okay;
56997+atomic_unchecked_t fscache_n_checkaux_update;
56998+atomic_unchecked_t fscache_n_checkaux_obsolete;
56999
57000 atomic_t fscache_n_cop_alloc_object;
57001 atomic_t fscache_n_cop_lookup_object;
57002@@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
57003 seq_puts(m, "FS-Cache statistics\n");
57004
57005 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
57006- atomic_read(&fscache_n_cookie_index),
57007- atomic_read(&fscache_n_cookie_data),
57008- atomic_read(&fscache_n_cookie_special));
57009+ atomic_read_unchecked(&fscache_n_cookie_index),
57010+ atomic_read_unchecked(&fscache_n_cookie_data),
57011+ atomic_read_unchecked(&fscache_n_cookie_special));
57012
57013 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
57014- atomic_read(&fscache_n_object_alloc),
57015- atomic_read(&fscache_n_object_no_alloc),
57016- atomic_read(&fscache_n_object_avail),
57017- atomic_read(&fscache_n_object_dead));
57018+ atomic_read_unchecked(&fscache_n_object_alloc),
57019+ atomic_read_unchecked(&fscache_n_object_no_alloc),
57020+ atomic_read_unchecked(&fscache_n_object_avail),
57021+ atomic_read_unchecked(&fscache_n_object_dead));
57022 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
57023- atomic_read(&fscache_n_checkaux_none),
57024- atomic_read(&fscache_n_checkaux_okay),
57025- atomic_read(&fscache_n_checkaux_update),
57026- atomic_read(&fscache_n_checkaux_obsolete));
57027+ atomic_read_unchecked(&fscache_n_checkaux_none),
57028+ atomic_read_unchecked(&fscache_n_checkaux_okay),
57029+ atomic_read_unchecked(&fscache_n_checkaux_update),
57030+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
57031
57032 seq_printf(m, "Pages : mrk=%u unc=%u\n",
57033- atomic_read(&fscache_n_marks),
57034- atomic_read(&fscache_n_uncaches));
57035+ atomic_read_unchecked(&fscache_n_marks),
57036+ atomic_read_unchecked(&fscache_n_uncaches));
57037
57038 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
57039 " oom=%u\n",
57040- atomic_read(&fscache_n_acquires),
57041- atomic_read(&fscache_n_acquires_null),
57042- atomic_read(&fscache_n_acquires_no_cache),
57043- atomic_read(&fscache_n_acquires_ok),
57044- atomic_read(&fscache_n_acquires_nobufs),
57045- atomic_read(&fscache_n_acquires_oom));
57046+ atomic_read_unchecked(&fscache_n_acquires),
57047+ atomic_read_unchecked(&fscache_n_acquires_null),
57048+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
57049+ atomic_read_unchecked(&fscache_n_acquires_ok),
57050+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
57051+ atomic_read_unchecked(&fscache_n_acquires_oom));
57052
57053 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
57054- atomic_read(&fscache_n_object_lookups),
57055- atomic_read(&fscache_n_object_lookups_negative),
57056- atomic_read(&fscache_n_object_lookups_positive),
57057- atomic_read(&fscache_n_object_created),
57058- atomic_read(&fscache_n_object_lookups_timed_out));
57059+ atomic_read_unchecked(&fscache_n_object_lookups),
57060+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
57061+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
57062+ atomic_read_unchecked(&fscache_n_object_created),
57063+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
57064
57065 seq_printf(m, "Invals : n=%u run=%u\n",
57066- atomic_read(&fscache_n_invalidates),
57067- atomic_read(&fscache_n_invalidates_run));
57068+ atomic_read_unchecked(&fscache_n_invalidates),
57069+ atomic_read_unchecked(&fscache_n_invalidates_run));
57070
57071 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
57072- atomic_read(&fscache_n_updates),
57073- atomic_read(&fscache_n_updates_null),
57074- atomic_read(&fscache_n_updates_run));
57075+ atomic_read_unchecked(&fscache_n_updates),
57076+ atomic_read_unchecked(&fscache_n_updates_null),
57077+ atomic_read_unchecked(&fscache_n_updates_run));
57078
57079 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
57080- atomic_read(&fscache_n_relinquishes),
57081- atomic_read(&fscache_n_relinquishes_null),
57082- atomic_read(&fscache_n_relinquishes_waitcrt),
57083- atomic_read(&fscache_n_relinquishes_retire));
57084+ atomic_read_unchecked(&fscache_n_relinquishes),
57085+ atomic_read_unchecked(&fscache_n_relinquishes_null),
57086+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
57087+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
57088
57089 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
57090- atomic_read(&fscache_n_attr_changed),
57091- atomic_read(&fscache_n_attr_changed_ok),
57092- atomic_read(&fscache_n_attr_changed_nobufs),
57093- atomic_read(&fscache_n_attr_changed_nomem),
57094- atomic_read(&fscache_n_attr_changed_calls));
57095+ atomic_read_unchecked(&fscache_n_attr_changed),
57096+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
57097+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
57098+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
57099+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
57100
57101 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
57102- atomic_read(&fscache_n_allocs),
57103- atomic_read(&fscache_n_allocs_ok),
57104- atomic_read(&fscache_n_allocs_wait),
57105- atomic_read(&fscache_n_allocs_nobufs),
57106- atomic_read(&fscache_n_allocs_intr));
57107+ atomic_read_unchecked(&fscache_n_allocs),
57108+ atomic_read_unchecked(&fscache_n_allocs_ok),
57109+ atomic_read_unchecked(&fscache_n_allocs_wait),
57110+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
57111+ atomic_read_unchecked(&fscache_n_allocs_intr));
57112 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
57113- atomic_read(&fscache_n_alloc_ops),
57114- atomic_read(&fscache_n_alloc_op_waits),
57115- atomic_read(&fscache_n_allocs_object_dead));
57116+ atomic_read_unchecked(&fscache_n_alloc_ops),
57117+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
57118+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
57119
57120 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
57121 " int=%u oom=%u\n",
57122- atomic_read(&fscache_n_retrievals),
57123- atomic_read(&fscache_n_retrievals_ok),
57124- atomic_read(&fscache_n_retrievals_wait),
57125- atomic_read(&fscache_n_retrievals_nodata),
57126- atomic_read(&fscache_n_retrievals_nobufs),
57127- atomic_read(&fscache_n_retrievals_intr),
57128- atomic_read(&fscache_n_retrievals_nomem));
57129+ atomic_read_unchecked(&fscache_n_retrievals),
57130+ atomic_read_unchecked(&fscache_n_retrievals_ok),
57131+ atomic_read_unchecked(&fscache_n_retrievals_wait),
57132+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
57133+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
57134+ atomic_read_unchecked(&fscache_n_retrievals_intr),
57135+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
57136 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
57137- atomic_read(&fscache_n_retrieval_ops),
57138- atomic_read(&fscache_n_retrieval_op_waits),
57139- atomic_read(&fscache_n_retrievals_object_dead));
57140+ atomic_read_unchecked(&fscache_n_retrieval_ops),
57141+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
57142+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
57143
57144 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
57145- atomic_read(&fscache_n_stores),
57146- atomic_read(&fscache_n_stores_ok),
57147- atomic_read(&fscache_n_stores_again),
57148- atomic_read(&fscache_n_stores_nobufs),
57149- atomic_read(&fscache_n_stores_oom));
57150+ atomic_read_unchecked(&fscache_n_stores),
57151+ atomic_read_unchecked(&fscache_n_stores_ok),
57152+ atomic_read_unchecked(&fscache_n_stores_again),
57153+ atomic_read_unchecked(&fscache_n_stores_nobufs),
57154+ atomic_read_unchecked(&fscache_n_stores_oom));
57155 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
57156- atomic_read(&fscache_n_store_ops),
57157- atomic_read(&fscache_n_store_calls),
57158- atomic_read(&fscache_n_store_pages),
57159- atomic_read(&fscache_n_store_radix_deletes),
57160- atomic_read(&fscache_n_store_pages_over_limit));
57161+ atomic_read_unchecked(&fscache_n_store_ops),
57162+ atomic_read_unchecked(&fscache_n_store_calls),
57163+ atomic_read_unchecked(&fscache_n_store_pages),
57164+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
57165+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
57166
57167 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
57168- atomic_read(&fscache_n_store_vmscan_not_storing),
57169- atomic_read(&fscache_n_store_vmscan_gone),
57170- atomic_read(&fscache_n_store_vmscan_busy),
57171- atomic_read(&fscache_n_store_vmscan_cancelled),
57172- atomic_read(&fscache_n_store_vmscan_wait));
57173+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
57174+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
57175+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
57176+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
57177+ atomic_read_unchecked(&fscache_n_store_vmscan_wait));
57178
57179 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
57180- atomic_read(&fscache_n_op_pend),
57181- atomic_read(&fscache_n_op_run),
57182- atomic_read(&fscache_n_op_enqueue),
57183- atomic_read(&fscache_n_op_cancelled),
57184- atomic_read(&fscache_n_op_rejected));
57185+ atomic_read_unchecked(&fscache_n_op_pend),
57186+ atomic_read_unchecked(&fscache_n_op_run),
57187+ atomic_read_unchecked(&fscache_n_op_enqueue),
57188+ atomic_read_unchecked(&fscache_n_op_cancelled),
57189+ atomic_read_unchecked(&fscache_n_op_rejected));
57190 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
57191- atomic_read(&fscache_n_op_deferred_release),
57192- atomic_read(&fscache_n_op_release),
57193- atomic_read(&fscache_n_op_gc));
57194+ atomic_read_unchecked(&fscache_n_op_deferred_release),
57195+ atomic_read_unchecked(&fscache_n_op_release),
57196+ atomic_read_unchecked(&fscache_n_op_gc));
57197
57198 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
57199 atomic_read(&fscache_n_cop_alloc_object),
57200diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
57201index aef34b1..59bfd7b 100644
57202--- a/fs/fuse/cuse.c
57203+++ b/fs/fuse/cuse.c
57204@@ -600,10 +600,12 @@ static int __init cuse_init(void)
57205 INIT_LIST_HEAD(&cuse_conntbl[i]);
57206
57207 /* inherit and extend fuse_dev_operations */
57208- cuse_channel_fops = fuse_dev_operations;
57209- cuse_channel_fops.owner = THIS_MODULE;
57210- cuse_channel_fops.open = cuse_channel_open;
57211- cuse_channel_fops.release = cuse_channel_release;
57212+ pax_open_kernel();
57213+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
57214+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
57215+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
57216+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
57217+ pax_close_kernel();
57218
57219 cuse_class = class_create(THIS_MODULE, "cuse");
57220 if (IS_ERR(cuse_class))
57221diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
57222index 1d55f94..088da65 100644
57223--- a/fs/fuse/dev.c
57224+++ b/fs/fuse/dev.c
57225@@ -1339,7 +1339,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
57226 ret = 0;
57227 pipe_lock(pipe);
57228
57229- if (!pipe->readers) {
57230+ if (!atomic_read(&pipe->readers)) {
57231 send_sig(SIGPIPE, current, 0);
57232 if (!ret)
57233 ret = -EPIPE;
57234@@ -1364,7 +1364,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
57235 page_nr++;
57236 ret += buf->len;
57237
57238- if (pipe->files)
57239+ if (atomic_read(&pipe->files))
57240 do_wakeup = 1;
57241 }
57242
57243diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
57244index 72a5d5b..c991011 100644
57245--- a/fs/fuse/dir.c
57246+++ b/fs/fuse/dir.c
57247@@ -1433,7 +1433,7 @@ static char *read_link(struct dentry *dentry)
57248 return link;
57249 }
57250
57251-static void free_link(char *link)
57252+static void free_link(const char *link)
57253 {
57254 if (!IS_ERR(link))
57255 free_page((unsigned long) link);
57256diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
57257index 64915ee..6bed500 100644
57258--- a/fs/gfs2/inode.c
57259+++ b/fs/gfs2/inode.c
57260@@ -1506,7 +1506,7 @@ out:
57261
57262 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
57263 {
57264- char *s = nd_get_link(nd);
57265+ const char *s = nd_get_link(nd);
57266 if (!IS_ERR(s))
57267 kfree(s);
57268 }
57269diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
57270index d19b30a..ef89c36 100644
57271--- a/fs/hugetlbfs/inode.c
57272+++ b/fs/hugetlbfs/inode.c
57273@@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
57274 struct mm_struct *mm = current->mm;
57275 struct vm_area_struct *vma;
57276 struct hstate *h = hstate_file(file);
57277+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
57278 struct vm_unmapped_area_info info;
57279
57280 if (len & ~huge_page_mask(h))
57281@@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
57282 return addr;
57283 }
57284
57285+#ifdef CONFIG_PAX_RANDMMAP
57286+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
57287+#endif
57288+
57289 if (addr) {
57290 addr = ALIGN(addr, huge_page_size(h));
57291 vma = find_vma(mm, addr);
57292- if (TASK_SIZE - len >= addr &&
57293- (!vma || addr + len <= vma->vm_start))
57294+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
57295 return addr;
57296 }
57297
57298 info.flags = 0;
57299 info.length = len;
57300 info.low_limit = TASK_UNMAPPED_BASE;
57301+
57302+#ifdef CONFIG_PAX_RANDMMAP
57303+ if (mm->pax_flags & MF_PAX_RANDMMAP)
57304+ info.low_limit += mm->delta_mmap;
57305+#endif
57306+
57307 info.high_limit = TASK_SIZE;
57308 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
57309 info.align_offset = 0;
57310@@ -908,7 +918,7 @@ static struct file_system_type hugetlbfs_fs_type = {
57311 };
57312 MODULE_ALIAS_FS("hugetlbfs");
57313
57314-static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
57315+struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
57316
57317 static int can_do_hugetlb_shm(void)
57318 {
57319diff --git a/fs/inode.c b/fs/inode.c
57320index d6dfb09..602e77e 100644
57321--- a/fs/inode.c
57322+++ b/fs/inode.c
57323@@ -880,8 +880,8 @@ unsigned int get_next_ino(void)
57324
57325 #ifdef CONFIG_SMP
57326 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
57327- static atomic_t shared_last_ino;
57328- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
57329+ static atomic_unchecked_t shared_last_ino;
57330+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
57331
57332 res = next - LAST_INO_BATCH;
57333 }
57334diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
57335index 4a6cf28..d3a29d3 100644
57336--- a/fs/jffs2/erase.c
57337+++ b/fs/jffs2/erase.c
57338@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
57339 struct jffs2_unknown_node marker = {
57340 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
57341 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
57342- .totlen = cpu_to_je32(c->cleanmarker_size)
57343+ .totlen = cpu_to_je32(c->cleanmarker_size),
57344+ .hdr_crc = cpu_to_je32(0)
57345 };
57346
57347 jffs2_prealloc_raw_node_refs(c, jeb, 1);
57348diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
57349index a6597d6..41b30ec 100644
57350--- a/fs/jffs2/wbuf.c
57351+++ b/fs/jffs2/wbuf.c
57352@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
57353 {
57354 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
57355 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
57356- .totlen = constant_cpu_to_je32(8)
57357+ .totlen = constant_cpu_to_je32(8),
57358+ .hdr_crc = constant_cpu_to_je32(0)
57359 };
57360
57361 /*
57362diff --git a/fs/jfs/super.c b/fs/jfs/super.c
57363index 6669aa2..36b033d 100644
57364--- a/fs/jfs/super.c
57365+++ b/fs/jfs/super.c
57366@@ -882,7 +882,7 @@ static int __init init_jfs_fs(void)
57367
57368 jfs_inode_cachep =
57369 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
57370- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
57371+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
57372 init_once);
57373 if (jfs_inode_cachep == NULL)
57374 return -ENOMEM;
57375diff --git a/fs/libfs.c b/fs/libfs.c
57376index 3a3a9b5..3a9b074 100644
57377--- a/fs/libfs.c
57378+++ b/fs/libfs.c
57379@@ -150,6 +150,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
57380
57381 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
57382 struct dentry *next = list_entry(p, struct dentry, d_u.d_child);
57383+ char d_name[sizeof(next->d_iname)];
57384+ const unsigned char *name;
57385+
57386 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
57387 if (!simple_positive(next)) {
57388 spin_unlock(&next->d_lock);
57389@@ -158,7 +161,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
57390
57391 spin_unlock(&next->d_lock);
57392 spin_unlock(&dentry->d_lock);
57393- if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
57394+ name = next->d_name.name;
57395+ if (name == next->d_iname) {
57396+ memcpy(d_name, name, next->d_name.len);
57397+ name = d_name;
57398+ }
57399+ if (!dir_emit(ctx, name, next->d_name.len,
57400 next->d_inode->i_ino, dt_type(next->d_inode)))
57401 return 0;
57402 spin_lock(&dentry->d_lock);
57403diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
57404index acd3947..1f896e2 100644
57405--- a/fs/lockd/clntproc.c
57406+++ b/fs/lockd/clntproc.c
57407@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
57408 /*
57409 * Cookie counter for NLM requests
57410 */
57411-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
57412+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
57413
57414 void nlmclnt_next_cookie(struct nlm_cookie *c)
57415 {
57416- u32 cookie = atomic_inc_return(&nlm_cookie);
57417+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
57418
57419 memcpy(c->data, &cookie, 4);
57420 c->len=4;
57421diff --git a/fs/locks.c b/fs/locks.c
57422index b27a300..4156d0b 100644
57423--- a/fs/locks.c
57424+++ b/fs/locks.c
57425@@ -2183,16 +2183,16 @@ void locks_remove_flock(struct file *filp)
57426 return;
57427
57428 if (filp->f_op && filp->f_op->flock) {
57429- struct file_lock fl = {
57430+ struct file_lock flock = {
57431 .fl_pid = current->tgid,
57432 .fl_file = filp,
57433 .fl_flags = FL_FLOCK,
57434 .fl_type = F_UNLCK,
57435 .fl_end = OFFSET_MAX,
57436 };
57437- filp->f_op->flock(filp, F_SETLKW, &fl);
57438- if (fl.fl_ops && fl.fl_ops->fl_release_private)
57439- fl.fl_ops->fl_release_private(&fl);
57440+ filp->f_op->flock(filp, F_SETLKW, &flock);
57441+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
57442+ flock.fl_ops->fl_release_private(&flock);
57443 }
57444
57445 spin_lock(&inode->i_lock);
57446diff --git a/fs/namei.c b/fs/namei.c
57447index 7720fbd..7934bb2 100644
57448--- a/fs/namei.c
57449+++ b/fs/namei.c
57450@@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
57451 if (ret != -EACCES)
57452 return ret;
57453
57454+#ifdef CONFIG_GRKERNSEC
57455+ /* we'll block if we have to log due to a denied capability use */
57456+ if (mask & MAY_NOT_BLOCK)
57457+ return -ECHILD;
57458+#endif
57459+
57460 if (S_ISDIR(inode->i_mode)) {
57461 /* DACs are overridable for directories */
57462- if (inode_capable(inode, CAP_DAC_OVERRIDE))
57463- return 0;
57464 if (!(mask & MAY_WRITE))
57465- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
57466+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
57467+ inode_capable(inode, CAP_DAC_READ_SEARCH))
57468 return 0;
57469+ if (inode_capable(inode, CAP_DAC_OVERRIDE))
57470+ return 0;
57471 return -EACCES;
57472 }
57473 /*
57474+ * Searching includes executable on directories, else just read.
57475+ */
57476+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
57477+ if (mask == MAY_READ)
57478+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
57479+ inode_capable(inode, CAP_DAC_READ_SEARCH))
57480+ return 0;
57481+
57482+ /*
57483 * Read/write DACs are always overridable.
57484 * Executable DACs are overridable when there is
57485 * at least one exec bit set.
57486@@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
57487 if (inode_capable(inode, CAP_DAC_OVERRIDE))
57488 return 0;
57489
57490- /*
57491- * Searching includes executable on directories, else just read.
57492- */
57493- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
57494- if (mask == MAY_READ)
57495- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
57496- return 0;
57497-
57498 return -EACCES;
57499 }
57500
57501@@ -820,7 +828,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
57502 {
57503 struct dentry *dentry = link->dentry;
57504 int error;
57505- char *s;
57506+ const char *s;
57507
57508 BUG_ON(nd->flags & LOOKUP_RCU);
57509
57510@@ -841,6 +849,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
57511 if (error)
57512 goto out_put_nd_path;
57513
57514+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
57515+ dentry->d_inode, dentry, nd->path.mnt)) {
57516+ error = -EACCES;
57517+ goto out_put_nd_path;
57518+ }
57519+
57520 nd->last_type = LAST_BIND;
57521 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
57522 error = PTR_ERR(*p);
57523@@ -1588,6 +1602,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
57524 if (res)
57525 break;
57526 res = walk_component(nd, path, LOOKUP_FOLLOW);
57527+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
57528+ res = -EACCES;
57529 put_link(nd, &link, cookie);
57530 } while (res > 0);
57531
57532@@ -1686,7 +1702,7 @@ EXPORT_SYMBOL(full_name_hash);
57533 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
57534 {
57535 unsigned long a, b, adata, bdata, mask, hash, len;
57536- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
57537+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
57538
57539 hash = a = 0;
57540 len = -sizeof(unsigned long);
57541@@ -1967,6 +1983,8 @@ static int path_lookupat(int dfd, const char *name,
57542 if (err)
57543 break;
57544 err = lookup_last(nd, &path);
57545+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
57546+ err = -EACCES;
57547 put_link(nd, &link, cookie);
57548 }
57549 }
57550@@ -1974,6 +1992,13 @@ static int path_lookupat(int dfd, const char *name,
57551 if (!err)
57552 err = complete_walk(nd);
57553
57554+ if (!err && !(nd->flags & LOOKUP_PARENT)) {
57555+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
57556+ path_put(&nd->path);
57557+ err = -ENOENT;
57558+ }
57559+ }
57560+
57561 if (!err && nd->flags & LOOKUP_DIRECTORY) {
57562 if (!can_lookup(nd->inode)) {
57563 path_put(&nd->path);
57564@@ -2001,8 +2026,15 @@ static int filename_lookup(int dfd, struct filename *name,
57565 retval = path_lookupat(dfd, name->name,
57566 flags | LOOKUP_REVAL, nd);
57567
57568- if (likely(!retval))
57569+ if (likely(!retval)) {
57570 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
57571+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
57572+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
57573+ path_put(&nd->path);
57574+ return -ENOENT;
57575+ }
57576+ }
57577+ }
57578 return retval;
57579 }
57580
57581@@ -2380,6 +2412,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
57582 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
57583 return -EPERM;
57584
57585+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
57586+ return -EPERM;
57587+ if (gr_handle_rawio(inode))
57588+ return -EPERM;
57589+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
57590+ return -EACCES;
57591+
57592 return 0;
57593 }
57594
57595@@ -2601,7 +2640,7 @@ looked_up:
57596 * cleared otherwise prior to returning.
57597 */
57598 static int lookup_open(struct nameidata *nd, struct path *path,
57599- struct file *file,
57600+ struct path *link, struct file *file,
57601 const struct open_flags *op,
57602 bool got_write, int *opened)
57603 {
57604@@ -2636,6 +2675,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
57605 /* Negative dentry, just create the file */
57606 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
57607 umode_t mode = op->mode;
57608+
57609+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
57610+ error = -EACCES;
57611+ goto out_dput;
57612+ }
57613+
57614+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
57615+ error = -EACCES;
57616+ goto out_dput;
57617+ }
57618+
57619 if (!IS_POSIXACL(dir->d_inode))
57620 mode &= ~current_umask();
57621 /*
57622@@ -2657,6 +2707,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
57623 nd->flags & LOOKUP_EXCL);
57624 if (error)
57625 goto out_dput;
57626+ else
57627+ gr_handle_create(dentry, nd->path.mnt);
57628 }
57629 out_no_open:
57630 path->dentry = dentry;
57631@@ -2671,7 +2723,7 @@ out_dput:
57632 /*
57633 * Handle the last step of open()
57634 */
57635-static int do_last(struct nameidata *nd, struct path *path,
57636+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
57637 struct file *file, const struct open_flags *op,
57638 int *opened, struct filename *name)
57639 {
57640@@ -2721,6 +2773,15 @@ static int do_last(struct nameidata *nd, struct path *path,
57641 if (error)
57642 return error;
57643
57644+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
57645+ error = -ENOENT;
57646+ goto out;
57647+ }
57648+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
57649+ error = -EACCES;
57650+ goto out;
57651+ }
57652+
57653 audit_inode(name, dir, LOOKUP_PARENT);
57654 error = -EISDIR;
57655 /* trailing slashes? */
57656@@ -2740,7 +2801,7 @@ retry_lookup:
57657 */
57658 }
57659 mutex_lock(&dir->d_inode->i_mutex);
57660- error = lookup_open(nd, path, file, op, got_write, opened);
57661+ error = lookup_open(nd, path, link, file, op, got_write, opened);
57662 mutex_unlock(&dir->d_inode->i_mutex);
57663
57664 if (error <= 0) {
57665@@ -2764,11 +2825,28 @@ retry_lookup:
57666 goto finish_open_created;
57667 }
57668
57669+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
57670+ error = -ENOENT;
57671+ goto exit_dput;
57672+ }
57673+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
57674+ error = -EACCES;
57675+ goto exit_dput;
57676+ }
57677+
57678 /*
57679 * create/update audit record if it already exists.
57680 */
57681- if (path->dentry->d_inode)
57682+ if (path->dentry->d_inode) {
57683+ /* only check if O_CREAT is specified, all other checks need to go
57684+ into may_open */
57685+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
57686+ error = -EACCES;
57687+ goto exit_dput;
57688+ }
57689+
57690 audit_inode(name, path->dentry, 0);
57691+ }
57692
57693 /*
57694 * If atomic_open() acquired write access it is dropped now due to
57695@@ -2809,6 +2887,11 @@ finish_lookup:
57696 }
57697 }
57698 BUG_ON(inode != path->dentry->d_inode);
57699+ /* if we're resolving a symlink to another symlink */
57700+ if (link && gr_handle_symlink_owner(link, inode)) {
57701+ error = -EACCES;
57702+ goto out;
57703+ }
57704 return 1;
57705 }
57706
57707@@ -2818,7 +2901,6 @@ finish_lookup:
57708 save_parent.dentry = nd->path.dentry;
57709 save_parent.mnt = mntget(path->mnt);
57710 nd->path.dentry = path->dentry;
57711-
57712 }
57713 nd->inode = inode;
57714 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
57715@@ -2828,7 +2910,18 @@ finish_open:
57716 path_put(&save_parent);
57717 return error;
57718 }
57719+
57720+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
57721+ error = -ENOENT;
57722+ goto out;
57723+ }
57724+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
57725+ error = -EACCES;
57726+ goto out;
57727+ }
57728+
57729 audit_inode(name, nd->path.dentry, 0);
57730+
57731 error = -EISDIR;
57732 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
57733 goto out;
57734@@ -2991,7 +3084,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
57735 if (unlikely(error))
57736 goto out;
57737
57738- error = do_last(nd, &path, file, op, &opened, pathname);
57739+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
57740 while (unlikely(error > 0)) { /* trailing symlink */
57741 struct path link = path;
57742 void *cookie;
57743@@ -3009,7 +3102,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
57744 error = follow_link(&link, nd, &cookie);
57745 if (unlikely(error))
57746 break;
57747- error = do_last(nd, &path, file, op, &opened, pathname);
57748+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
57749 put_link(nd, &link, cookie);
57750 }
57751 out:
57752@@ -3109,8 +3202,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
57753 goto unlock;
57754
57755 error = -EEXIST;
57756- if (dentry->d_inode)
57757+ if (dentry->d_inode) {
57758+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
57759+ error = -ENOENT;
57760+ }
57761 goto fail;
57762+ }
57763 /*
57764 * Special case - lookup gave negative, but... we had foo/bar/
57765 * From the vfs_mknod() POV we just have a negative dentry -
57766@@ -3162,6 +3259,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
57767 }
57768 EXPORT_SYMBOL(user_path_create);
57769
57770+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
57771+{
57772+ struct filename *tmp = getname(pathname);
57773+ struct dentry *res;
57774+ if (IS_ERR(tmp))
57775+ return ERR_CAST(tmp);
57776+ res = kern_path_create(dfd, tmp->name, path, lookup_flags);
57777+ if (IS_ERR(res))
57778+ putname(tmp);
57779+ else
57780+ *to = tmp;
57781+ return res;
57782+}
57783+
57784 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
57785 {
57786 int error = may_create(dir, dentry);
57787@@ -3224,6 +3335,17 @@ retry:
57788
57789 if (!IS_POSIXACL(path.dentry->d_inode))
57790 mode &= ~current_umask();
57791+
57792+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
57793+ error = -EPERM;
57794+ goto out;
57795+ }
57796+
57797+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
57798+ error = -EACCES;
57799+ goto out;
57800+ }
57801+
57802 error = security_path_mknod(&path, dentry, mode, dev);
57803 if (error)
57804 goto out;
57805@@ -3240,6 +3362,8 @@ retry:
57806 break;
57807 }
57808 out:
57809+ if (!error)
57810+ gr_handle_create(dentry, path.mnt);
57811 done_path_create(&path, dentry);
57812 if (retry_estale(error, lookup_flags)) {
57813 lookup_flags |= LOOKUP_REVAL;
57814@@ -3292,9 +3416,16 @@ retry:
57815
57816 if (!IS_POSIXACL(path.dentry->d_inode))
57817 mode &= ~current_umask();
57818+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
57819+ error = -EACCES;
57820+ goto out;
57821+ }
57822 error = security_path_mkdir(&path, dentry, mode);
57823 if (!error)
57824 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
57825+ if (!error)
57826+ gr_handle_create(dentry, path.mnt);
57827+out:
57828 done_path_create(&path, dentry);
57829 if (retry_estale(error, lookup_flags)) {
57830 lookup_flags |= LOOKUP_REVAL;
57831@@ -3375,6 +3506,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
57832 struct filename *name;
57833 struct dentry *dentry;
57834 struct nameidata nd;
57835+ ino_t saved_ino = 0;
57836+ dev_t saved_dev = 0;
57837 unsigned int lookup_flags = 0;
57838 retry:
57839 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
57840@@ -3407,10 +3540,21 @@ retry:
57841 error = -ENOENT;
57842 goto exit3;
57843 }
57844+
57845+ saved_ino = dentry->d_inode->i_ino;
57846+ saved_dev = gr_get_dev_from_dentry(dentry);
57847+
57848+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
57849+ error = -EACCES;
57850+ goto exit3;
57851+ }
57852+
57853 error = security_path_rmdir(&nd.path, dentry);
57854 if (error)
57855 goto exit3;
57856 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
57857+ if (!error && (saved_dev || saved_ino))
57858+ gr_handle_delete(saved_ino, saved_dev);
57859 exit3:
57860 dput(dentry);
57861 exit2:
57862@@ -3476,6 +3620,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
57863 struct dentry *dentry;
57864 struct nameidata nd;
57865 struct inode *inode = NULL;
57866+ ino_t saved_ino = 0;
57867+ dev_t saved_dev = 0;
57868 unsigned int lookup_flags = 0;
57869 retry:
57870 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
57871@@ -3502,10 +3648,22 @@ retry:
57872 if (!inode)
57873 goto slashes;
57874 ihold(inode);
57875+
57876+ if (inode->i_nlink <= 1) {
57877+ saved_ino = inode->i_ino;
57878+ saved_dev = gr_get_dev_from_dentry(dentry);
57879+ }
57880+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
57881+ error = -EACCES;
57882+ goto exit2;
57883+ }
57884+
57885 error = security_path_unlink(&nd.path, dentry);
57886 if (error)
57887 goto exit2;
57888 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
57889+ if (!error && (saved_ino || saved_dev))
57890+ gr_handle_delete(saved_ino, saved_dev);
57891 exit2:
57892 dput(dentry);
57893 }
57894@@ -3583,9 +3741,17 @@ retry:
57895 if (IS_ERR(dentry))
57896 goto out_putname;
57897
57898+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
57899+ error = -EACCES;
57900+ goto out;
57901+ }
57902+
57903 error = security_path_symlink(&path, dentry, from->name);
57904 if (!error)
57905 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
57906+ if (!error)
57907+ gr_handle_create(dentry, path.mnt);
57908+out:
57909 done_path_create(&path, dentry);
57910 if (retry_estale(error, lookup_flags)) {
57911 lookup_flags |= LOOKUP_REVAL;
57912@@ -3665,6 +3831,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
57913 {
57914 struct dentry *new_dentry;
57915 struct path old_path, new_path;
57916+ struct filename *to = NULL;
57917 int how = 0;
57918 int error;
57919
57920@@ -3688,7 +3855,7 @@ retry:
57921 if (error)
57922 return error;
57923
57924- new_dentry = user_path_create(newdfd, newname, &new_path,
57925+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
57926 (how & LOOKUP_REVAL));
57927 error = PTR_ERR(new_dentry);
57928 if (IS_ERR(new_dentry))
57929@@ -3700,11 +3867,28 @@ retry:
57930 error = may_linkat(&old_path);
57931 if (unlikely(error))
57932 goto out_dput;
57933+
57934+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
57935+ old_path.dentry->d_inode,
57936+ old_path.dentry->d_inode->i_mode, to)) {
57937+ error = -EACCES;
57938+ goto out_dput;
57939+ }
57940+
57941+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
57942+ old_path.dentry, old_path.mnt, to)) {
57943+ error = -EACCES;
57944+ goto out_dput;
57945+ }
57946+
57947 error = security_path_link(old_path.dentry, &new_path, new_dentry);
57948 if (error)
57949 goto out_dput;
57950 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
57951+ if (!error)
57952+ gr_handle_create(new_dentry, new_path.mnt);
57953 out_dput:
57954+ putname(to);
57955 done_path_create(&new_path, new_dentry);
57956 if (retry_estale(error, how)) {
57957 how |= LOOKUP_REVAL;
57958@@ -3950,12 +4134,21 @@ retry:
57959 if (new_dentry == trap)
57960 goto exit5;
57961
57962+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
57963+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
57964+ to);
57965+ if (error)
57966+ goto exit5;
57967+
57968 error = security_path_rename(&oldnd.path, old_dentry,
57969 &newnd.path, new_dentry);
57970 if (error)
57971 goto exit5;
57972 error = vfs_rename(old_dir->d_inode, old_dentry,
57973 new_dir->d_inode, new_dentry);
57974+ if (!error)
57975+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
57976+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
57977 exit5:
57978 dput(new_dentry);
57979 exit4:
57980@@ -3987,6 +4180,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
57981
57982 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
57983 {
57984+ char tmpbuf[64];
57985+ const char *newlink;
57986 int len;
57987
57988 len = PTR_ERR(link);
57989@@ -3996,7 +4191,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
57990 len = strlen(link);
57991 if (len > (unsigned) buflen)
57992 len = buflen;
57993- if (copy_to_user(buffer, link, len))
57994+
57995+ if (len < sizeof(tmpbuf)) {
57996+ memcpy(tmpbuf, link, len);
57997+ newlink = tmpbuf;
57998+ } else
57999+ newlink = link;
58000+
58001+ if (copy_to_user(buffer, newlink, len))
58002 len = -EFAULT;
58003 out:
58004 return len;
58005diff --git a/fs/namespace.c b/fs/namespace.c
58006index a45ba4f..b4c7d07 100644
58007--- a/fs/namespace.c
58008+++ b/fs/namespace.c
58009@@ -1265,6 +1265,9 @@ static int do_umount(struct mount *mnt, int flags)
58010 if (!(sb->s_flags & MS_RDONLY))
58011 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
58012 up_write(&sb->s_umount);
58013+
58014+ gr_log_remount(mnt->mnt_devname, retval);
58015+
58016 return retval;
58017 }
58018
58019@@ -1283,6 +1286,9 @@ static int do_umount(struct mount *mnt, int flags)
58020 }
58021 br_write_unlock(&vfsmount_lock);
58022 namespace_unlock();
58023+
58024+ gr_log_unmount(mnt->mnt_devname, retval);
58025+
58026 return retval;
58027 }
58028
58029@@ -1302,7 +1308,7 @@ static inline bool may_mount(void)
58030 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
58031 */
58032
58033-SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
58034+SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
58035 {
58036 struct path path;
58037 struct mount *mnt;
58038@@ -1342,7 +1348,7 @@ out:
58039 /*
58040 * The 2.0 compatible umount. No flags.
58041 */
58042-SYSCALL_DEFINE1(oldumount, char __user *, name)
58043+SYSCALL_DEFINE1(oldumount, const char __user *, name)
58044 {
58045 return sys_umount(name, 0);
58046 }
58047@@ -2313,6 +2319,16 @@ long do_mount(const char *dev_name, const char *dir_name,
58048 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
58049 MS_STRICTATIME);
58050
58051+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
58052+ retval = -EPERM;
58053+ goto dput_out;
58054+ }
58055+
58056+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
58057+ retval = -EPERM;
58058+ goto dput_out;
58059+ }
58060+
58061 if (flags & MS_REMOUNT)
58062 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
58063 data_page);
58064@@ -2327,6 +2343,9 @@ long do_mount(const char *dev_name, const char *dir_name,
58065 dev_name, data_page);
58066 dput_out:
58067 path_put(&path);
58068+
58069+ gr_log_mount(dev_name, dir_name, retval);
58070+
58071 return retval;
58072 }
58073
58074@@ -2344,7 +2363,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
58075 * number incrementing at 10Ghz will take 12,427 years to wrap which
58076 * is effectively never, so we can ignore the possibility.
58077 */
58078-static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
58079+static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
58080
58081 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
58082 {
58083@@ -2359,7 +2378,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
58084 kfree(new_ns);
58085 return ERR_PTR(ret);
58086 }
58087- new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
58088+ new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
58089 atomic_set(&new_ns->count, 1);
58090 new_ns->root = NULL;
58091 INIT_LIST_HEAD(&new_ns->list);
58092@@ -2373,7 +2392,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
58093 * Allocate a new namespace structure and populate it with contents
58094 * copied from the namespace of the passed in task structure.
58095 */
58096-static struct mnt_namespace *dup_mnt_ns(struct mnt_namespace *mnt_ns,
58097+static __latent_entropy struct mnt_namespace *dup_mnt_ns(struct mnt_namespace *mnt_ns,
58098 struct user_namespace *user_ns, struct fs_struct *fs)
58099 {
58100 struct mnt_namespace *new_ns;
58101@@ -2500,8 +2519,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
58102 }
58103 EXPORT_SYMBOL(mount_subtree);
58104
58105-SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
58106- char __user *, type, unsigned long, flags, void __user *, data)
58107+SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
58108+ const char __user *, type, unsigned long, flags, void __user *, data)
58109 {
58110 int ret;
58111 char *kernel_type;
58112@@ -2614,6 +2633,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
58113 if (error)
58114 goto out2;
58115
58116+ if (gr_handle_chroot_pivot()) {
58117+ error = -EPERM;
58118+ goto out2;
58119+ }
58120+
58121 get_fs_root(current->fs, &root);
58122 old_mp = lock_mount(&old);
58123 error = PTR_ERR(old_mp);
58124@@ -2864,7 +2888,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
58125 !nsown_capable(CAP_SYS_ADMIN))
58126 return -EPERM;
58127
58128- if (fs->users != 1)
58129+ if (atomic_read(&fs->users) != 1)
58130 return -EINVAL;
58131
58132 get_mnt_ns(mnt_ns);
58133diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
58134index f4ccfe6..a5cf064 100644
58135--- a/fs/nfs/callback_xdr.c
58136+++ b/fs/nfs/callback_xdr.c
58137@@ -51,7 +51,7 @@ struct callback_op {
58138 callback_decode_arg_t decode_args;
58139 callback_encode_res_t encode_res;
58140 long res_maxsize;
58141-};
58142+} __do_const;
58143
58144 static struct callback_op callback_ops[];
58145
58146diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
58147index 941246f..17d8724 100644
58148--- a/fs/nfs/inode.c
58149+++ b/fs/nfs/inode.c
58150@@ -1138,16 +1138,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
58151 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
58152 }
58153
58154-static atomic_long_t nfs_attr_generation_counter;
58155+static atomic_long_unchecked_t nfs_attr_generation_counter;
58156
58157 static unsigned long nfs_read_attr_generation_counter(void)
58158 {
58159- return atomic_long_read(&nfs_attr_generation_counter);
58160+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
58161 }
58162
58163 unsigned long nfs_inc_attr_generation_counter(void)
58164 {
58165- return atomic_long_inc_return(&nfs_attr_generation_counter);
58166+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
58167 }
58168
58169 void nfs_fattr_init(struct nfs_fattr *fattr)
58170diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
58171index 419572f..5414a23 100644
58172--- a/fs/nfsd/nfs4proc.c
58173+++ b/fs/nfsd/nfs4proc.c
58174@@ -1168,7 +1168,7 @@ struct nfsd4_operation {
58175 nfsd4op_rsize op_rsize_bop;
58176 stateid_getter op_get_currentstateid;
58177 stateid_setter op_set_currentstateid;
58178-};
58179+} __do_const;
58180
58181 static struct nfsd4_operation nfsd4_ops[];
58182
58183diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
58184index c2a4701..fd80e29 100644
58185--- a/fs/nfsd/nfs4xdr.c
58186+++ b/fs/nfsd/nfs4xdr.c
58187@@ -1498,7 +1498,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
58188
58189 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
58190
58191-static nfsd4_dec nfsd4_dec_ops[] = {
58192+static const nfsd4_dec nfsd4_dec_ops[] = {
58193 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
58194 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
58195 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
58196@@ -1538,7 +1538,7 @@ static nfsd4_dec nfsd4_dec_ops[] = {
58197 [OP_RELEASE_LOCKOWNER] = (nfsd4_dec)nfsd4_decode_release_lockowner,
58198 };
58199
58200-static nfsd4_dec nfsd41_dec_ops[] = {
58201+static const nfsd4_dec nfsd41_dec_ops[] = {
58202 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
58203 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
58204 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
58205@@ -1600,7 +1600,7 @@ static nfsd4_dec nfsd41_dec_ops[] = {
58206 };
58207
58208 struct nfsd4_minorversion_ops {
58209- nfsd4_dec *decoders;
58210+ const nfsd4_dec *decoders;
58211 int nops;
58212 };
58213
58214diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
58215index e76244e..9fe8f2f1 100644
58216--- a/fs/nfsd/nfscache.c
58217+++ b/fs/nfsd/nfscache.c
58218@@ -526,14 +526,17 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
58219 {
58220 struct svc_cacherep *rp = rqstp->rq_cacherep;
58221 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
58222- int len;
58223+ long len;
58224 size_t bufsize = 0;
58225
58226 if (!rp)
58227 return;
58228
58229- len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
58230- len >>= 2;
58231+ if (statp) {
58232+ len = (char*)statp - (char*)resv->iov_base;
58233+ len = resv->iov_len - len;
58234+ len >>= 2;
58235+ }
58236
58237 /* Don't cache excessive amounts of data and XDR failures */
58238 if (!statp || len > (256 >> 2)) {
58239diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
58240index c827acb..b253b77 100644
58241--- a/fs/nfsd/vfs.c
58242+++ b/fs/nfsd/vfs.c
58243@@ -968,7 +968,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
58244 } else {
58245 oldfs = get_fs();
58246 set_fs(KERNEL_DS);
58247- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
58248+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
58249 set_fs(oldfs);
58250 }
58251
58252@@ -1055,7 +1055,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
58253
58254 /* Write the data. */
58255 oldfs = get_fs(); set_fs(KERNEL_DS);
58256- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
58257+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
58258 set_fs(oldfs);
58259 if (host_err < 0)
58260 goto out_nfserr;
58261@@ -1601,7 +1601,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
58262 */
58263
58264 oldfs = get_fs(); set_fs(KERNEL_DS);
58265- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
58266+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
58267 set_fs(oldfs);
58268
58269 if (host_err < 0)
58270diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
58271index fea6bd5..8ee9d81 100644
58272--- a/fs/nls/nls_base.c
58273+++ b/fs/nls/nls_base.c
58274@@ -234,20 +234,22 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
58275
58276 int register_nls(struct nls_table * nls)
58277 {
58278- struct nls_table ** tmp = &tables;
58279+ struct nls_table *tmp = tables;
58280
58281 if (nls->next)
58282 return -EBUSY;
58283
58284 spin_lock(&nls_lock);
58285- while (*tmp) {
58286- if (nls == *tmp) {
58287+ while (tmp) {
58288+ if (nls == tmp) {
58289 spin_unlock(&nls_lock);
58290 return -EBUSY;
58291 }
58292- tmp = &(*tmp)->next;
58293+ tmp = tmp->next;
58294 }
58295- nls->next = tables;
58296+ pax_open_kernel();
58297+ *(struct nls_table **)&nls->next = tables;
58298+ pax_close_kernel();
58299 tables = nls;
58300 spin_unlock(&nls_lock);
58301 return 0;
58302@@ -255,12 +257,14 @@ int register_nls(struct nls_table * nls)
58303
58304 int unregister_nls(struct nls_table * nls)
58305 {
58306- struct nls_table ** tmp = &tables;
58307+ struct nls_table * const * tmp = &tables;
58308
58309 spin_lock(&nls_lock);
58310 while (*tmp) {
58311 if (nls == *tmp) {
58312- *tmp = nls->next;
58313+ pax_open_kernel();
58314+ *(struct nls_table **)tmp = nls->next;
58315+ pax_close_kernel();
58316 spin_unlock(&nls_lock);
58317 return 0;
58318 }
58319diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
58320index 7424929..35f6be5 100644
58321--- a/fs/nls/nls_euc-jp.c
58322+++ b/fs/nls/nls_euc-jp.c
58323@@ -561,8 +561,10 @@ static int __init init_nls_euc_jp(void)
58324 p_nls = load_nls("cp932");
58325
58326 if (p_nls) {
58327- table.charset2upper = p_nls->charset2upper;
58328- table.charset2lower = p_nls->charset2lower;
58329+ pax_open_kernel();
58330+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
58331+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
58332+ pax_close_kernel();
58333 return register_nls(&table);
58334 }
58335
58336diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
58337index e7bc1d7..06bd4bb 100644
58338--- a/fs/nls/nls_koi8-ru.c
58339+++ b/fs/nls/nls_koi8-ru.c
58340@@ -63,8 +63,10 @@ static int __init init_nls_koi8_ru(void)
58341 p_nls = load_nls("koi8-u");
58342
58343 if (p_nls) {
58344- table.charset2upper = p_nls->charset2upper;
58345- table.charset2lower = p_nls->charset2lower;
58346+ pax_open_kernel();
58347+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
58348+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
58349+ pax_close_kernel();
58350 return register_nls(&table);
58351 }
58352
58353diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
58354index e44cb64..4807084 100644
58355--- a/fs/notify/fanotify/fanotify_user.c
58356+++ b/fs/notify/fanotify/fanotify_user.c
58357@@ -253,8 +253,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
58358
58359 fd = fanotify_event_metadata.fd;
58360 ret = -EFAULT;
58361- if (copy_to_user(buf, &fanotify_event_metadata,
58362- fanotify_event_metadata.event_len))
58363+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
58364+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
58365 goto out_close_fd;
58366
58367 ret = prepare_for_access_response(group, event, fd);
58368diff --git a/fs/notify/notification.c b/fs/notify/notification.c
58369index 7b51b05..5ea5ef6 100644
58370--- a/fs/notify/notification.c
58371+++ b/fs/notify/notification.c
58372@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
58373 * get set to 0 so it will never get 'freed'
58374 */
58375 static struct fsnotify_event *q_overflow_event;
58376-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
58377+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
58378
58379 /**
58380 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
58381@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
58382 */
58383 u32 fsnotify_get_cookie(void)
58384 {
58385- return atomic_inc_return(&fsnotify_sync_cookie);
58386+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
58387 }
58388 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
58389
58390diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
58391index 9e38daf..5727cae 100644
58392--- a/fs/ntfs/dir.c
58393+++ b/fs/ntfs/dir.c
58394@@ -1310,7 +1310,7 @@ find_next_index_buffer:
58395 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
58396 ~(s64)(ndir->itype.index.block_size - 1)));
58397 /* Bounds checks. */
58398- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
58399+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
58400 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
58401 "inode 0x%lx or driver bug.", vdir->i_ino);
58402 goto err_out;
58403diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
58404index c5670b8..d590213 100644
58405--- a/fs/ntfs/file.c
58406+++ b/fs/ntfs/file.c
58407@@ -1282,7 +1282,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
58408 char *addr;
58409 size_t total = 0;
58410 unsigned len;
58411- int left;
58412+ unsigned left;
58413
58414 do {
58415 len = PAGE_CACHE_SIZE - ofs;
58416diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
58417index 82650d5..db37dcf 100644
58418--- a/fs/ntfs/super.c
58419+++ b/fs/ntfs/super.c
58420@@ -685,7 +685,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
58421 if (!silent)
58422 ntfs_error(sb, "Primary boot sector is invalid.");
58423 } else if (!silent)
58424- ntfs_error(sb, read_err_str, "primary");
58425+ ntfs_error(sb, read_err_str, "%s", "primary");
58426 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
58427 if (bh_primary)
58428 brelse(bh_primary);
58429@@ -701,7 +701,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
58430 goto hotfix_primary_boot_sector;
58431 brelse(bh_backup);
58432 } else if (!silent)
58433- ntfs_error(sb, read_err_str, "backup");
58434+ ntfs_error(sb, read_err_str, "%s", "backup");
58435 /* Try to read NT3.51- backup boot sector. */
58436 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
58437 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
58438@@ -712,7 +712,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
58439 "sector.");
58440 brelse(bh_backup);
58441 } else if (!silent)
58442- ntfs_error(sb, read_err_str, "backup");
58443+ ntfs_error(sb, read_err_str, "%s", "backup");
58444 /* We failed. Cleanup and return. */
58445 if (bh_primary)
58446 brelse(bh_primary);
58447diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
58448index aebeacd..0dcdd26 100644
58449--- a/fs/ocfs2/localalloc.c
58450+++ b/fs/ocfs2/localalloc.c
58451@@ -1278,7 +1278,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
58452 goto bail;
58453 }
58454
58455- atomic_inc(&osb->alloc_stats.moves);
58456+ atomic_inc_unchecked(&osb->alloc_stats.moves);
58457
58458 bail:
58459 if (handle)
58460diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
58461index 3a90347..c40bef8 100644
58462--- a/fs/ocfs2/ocfs2.h
58463+++ b/fs/ocfs2/ocfs2.h
58464@@ -235,11 +235,11 @@ enum ocfs2_vol_state
58465
58466 struct ocfs2_alloc_stats
58467 {
58468- atomic_t moves;
58469- atomic_t local_data;
58470- atomic_t bitmap_data;
58471- atomic_t bg_allocs;
58472- atomic_t bg_extends;
58473+ atomic_unchecked_t moves;
58474+ atomic_unchecked_t local_data;
58475+ atomic_unchecked_t bitmap_data;
58476+ atomic_unchecked_t bg_allocs;
58477+ atomic_unchecked_t bg_extends;
58478 };
58479
58480 enum ocfs2_local_alloc_state
58481diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
58482index 5397c07..54afc55 100644
58483--- a/fs/ocfs2/suballoc.c
58484+++ b/fs/ocfs2/suballoc.c
58485@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
58486 mlog_errno(status);
58487 goto bail;
58488 }
58489- atomic_inc(&osb->alloc_stats.bg_extends);
58490+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
58491
58492 /* You should never ask for this much metadata */
58493 BUG_ON(bits_wanted >
58494@@ -2000,7 +2000,7 @@ int ocfs2_claim_metadata(handle_t *handle,
58495 mlog_errno(status);
58496 goto bail;
58497 }
58498- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
58499+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
58500
58501 *suballoc_loc = res.sr_bg_blkno;
58502 *suballoc_bit_start = res.sr_bit_offset;
58503@@ -2164,7 +2164,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
58504 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
58505 res->sr_bits);
58506
58507- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
58508+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
58509
58510 BUG_ON(res->sr_bits != 1);
58511
58512@@ -2206,7 +2206,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
58513 mlog_errno(status);
58514 goto bail;
58515 }
58516- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
58517+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
58518
58519 BUG_ON(res.sr_bits != 1);
58520
58521@@ -2310,7 +2310,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
58522 cluster_start,
58523 num_clusters);
58524 if (!status)
58525- atomic_inc(&osb->alloc_stats.local_data);
58526+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
58527 } else {
58528 if (min_clusters > (osb->bitmap_cpg - 1)) {
58529 /* The only paths asking for contiguousness
58530@@ -2336,7 +2336,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
58531 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
58532 res.sr_bg_blkno,
58533 res.sr_bit_offset);
58534- atomic_inc(&osb->alloc_stats.bitmap_data);
58535+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
58536 *num_clusters = res.sr_bits;
58537 }
58538 }
58539diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
58540index 121da2d..a0232bc 100644
58541--- a/fs/ocfs2/super.c
58542+++ b/fs/ocfs2/super.c
58543@@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
58544 "%10s => GlobalAllocs: %d LocalAllocs: %d "
58545 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
58546 "Stats",
58547- atomic_read(&osb->alloc_stats.bitmap_data),
58548- atomic_read(&osb->alloc_stats.local_data),
58549- atomic_read(&osb->alloc_stats.bg_allocs),
58550- atomic_read(&osb->alloc_stats.moves),
58551- atomic_read(&osb->alloc_stats.bg_extends));
58552+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
58553+ atomic_read_unchecked(&osb->alloc_stats.local_data),
58554+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
58555+ atomic_read_unchecked(&osb->alloc_stats.moves),
58556+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
58557
58558 out += snprintf(buf + out, len - out,
58559 "%10s => State: %u Descriptor: %llu Size: %u bits "
58560@@ -2121,11 +2121,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
58561 spin_lock_init(&osb->osb_xattr_lock);
58562 ocfs2_init_steal_slots(osb);
58563
58564- atomic_set(&osb->alloc_stats.moves, 0);
58565- atomic_set(&osb->alloc_stats.local_data, 0);
58566- atomic_set(&osb->alloc_stats.bitmap_data, 0);
58567- atomic_set(&osb->alloc_stats.bg_allocs, 0);
58568- atomic_set(&osb->alloc_stats.bg_extends, 0);
58569+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
58570+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
58571+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
58572+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
58573+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
58574
58575 /* Copy the blockcheck stats from the superblock probe */
58576 osb->osb_ecc_stats = *stats;
58577diff --git a/fs/open.c b/fs/open.c
58578index 7931f76..7b03f3b 100644
58579--- a/fs/open.c
58580+++ b/fs/open.c
58581@@ -32,6 +32,8 @@
58582 #include <linux/dnotify.h>
58583 #include <linux/compat.h>
58584
58585+#define CREATE_TRACE_POINTS
58586+#include <trace/events/fs.h>
58587 #include "internal.h"
58588
58589 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
58590@@ -102,6 +104,8 @@ long vfs_truncate(struct path *path, loff_t length)
58591 error = locks_verify_truncate(inode, NULL, length);
58592 if (!error)
58593 error = security_path_truncate(path);
58594+ if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
58595+ error = -EACCES;
58596 if (!error)
58597 error = do_truncate(path->dentry, length, 0, NULL);
58598
58599@@ -186,6 +190,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
58600 error = locks_verify_truncate(inode, f.file, length);
58601 if (!error)
58602 error = security_path_truncate(&f.file->f_path);
58603+ if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
58604+ error = -EACCES;
58605 if (!error)
58606 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
58607 sb_end_write(inode->i_sb);
58608@@ -360,6 +366,9 @@ retry:
58609 if (__mnt_is_readonly(path.mnt))
58610 res = -EROFS;
58611
58612+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
58613+ res = -EACCES;
58614+
58615 out_path_release:
58616 path_put(&path);
58617 if (retry_estale(res, lookup_flags)) {
58618@@ -391,6 +400,8 @@ retry:
58619 if (error)
58620 goto dput_and_out;
58621
58622+ gr_log_chdir(path.dentry, path.mnt);
58623+
58624 set_fs_pwd(current->fs, &path);
58625
58626 dput_and_out:
58627@@ -420,6 +431,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
58628 goto out_putf;
58629
58630 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
58631+
58632+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
58633+ error = -EPERM;
58634+
58635+ if (!error)
58636+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
58637+
58638 if (!error)
58639 set_fs_pwd(current->fs, &f.file->f_path);
58640 out_putf:
58641@@ -449,7 +467,13 @@ retry:
58642 if (error)
58643 goto dput_and_out;
58644
58645+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
58646+ goto dput_and_out;
58647+
58648 set_fs_root(current->fs, &path);
58649+
58650+ gr_handle_chroot_chdir(&path);
58651+
58652 error = 0;
58653 dput_and_out:
58654 path_put(&path);
58655@@ -471,6 +495,16 @@ static int chmod_common(struct path *path, umode_t mode)
58656 if (error)
58657 return error;
58658 mutex_lock(&inode->i_mutex);
58659+
58660+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
58661+ error = -EACCES;
58662+ goto out_unlock;
58663+ }
58664+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
58665+ error = -EACCES;
58666+ goto out_unlock;
58667+ }
58668+
58669 error = security_path_chmod(path, mode);
58670 if (error)
58671 goto out_unlock;
58672@@ -531,6 +565,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
58673 uid = make_kuid(current_user_ns(), user);
58674 gid = make_kgid(current_user_ns(), group);
58675
58676+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
58677+ return -EACCES;
58678+
58679 newattrs.ia_valid = ATTR_CTIME;
58680 if (user != (uid_t) -1) {
58681 if (!uid_valid(uid))
58682@@ -960,6 +997,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
58683 } else {
58684 fsnotify_open(f);
58685 fd_install(fd, f);
58686+ trace_do_sys_open(tmp->name, flags, mode);
58687 }
58688 }
58689 putname(tmp);
58690diff --git a/fs/pipe.c b/fs/pipe.c
58691index d2c45e1..009fe1c 100644
58692--- a/fs/pipe.c
58693+++ b/fs/pipe.c
58694@@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
58695
58696 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
58697 {
58698- if (pipe->files)
58699+ if (atomic_read(&pipe->files))
58700 mutex_lock_nested(&pipe->mutex, subclass);
58701 }
58702
58703@@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
58704
58705 void pipe_unlock(struct pipe_inode_info *pipe)
58706 {
58707- if (pipe->files)
58708+ if (atomic_read(&pipe->files))
58709 mutex_unlock(&pipe->mutex);
58710 }
58711 EXPORT_SYMBOL(pipe_unlock);
58712@@ -449,9 +449,9 @@ redo:
58713 }
58714 if (bufs) /* More to do? */
58715 continue;
58716- if (!pipe->writers)
58717+ if (!atomic_read(&pipe->writers))
58718 break;
58719- if (!pipe->waiting_writers) {
58720+ if (!atomic_read(&pipe->waiting_writers)) {
58721 /* syscall merging: Usually we must not sleep
58722 * if O_NONBLOCK is set, or if we got some data.
58723 * But if a writer sleeps in kernel space, then
58724@@ -513,7 +513,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
58725 ret = 0;
58726 __pipe_lock(pipe);
58727
58728- if (!pipe->readers) {
58729+ if (!atomic_read(&pipe->readers)) {
58730 send_sig(SIGPIPE, current, 0);
58731 ret = -EPIPE;
58732 goto out;
58733@@ -562,7 +562,7 @@ redo1:
58734 for (;;) {
58735 int bufs;
58736
58737- if (!pipe->readers) {
58738+ if (!atomic_read(&pipe->readers)) {
58739 send_sig(SIGPIPE, current, 0);
58740 if (!ret)
58741 ret = -EPIPE;
58742@@ -653,9 +653,9 @@ redo2:
58743 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
58744 do_wakeup = 0;
58745 }
58746- pipe->waiting_writers++;
58747+ atomic_inc(&pipe->waiting_writers);
58748 pipe_wait(pipe);
58749- pipe->waiting_writers--;
58750+ atomic_dec(&pipe->waiting_writers);
58751 }
58752 out:
58753 __pipe_unlock(pipe);
58754@@ -709,7 +709,7 @@ pipe_poll(struct file *filp, poll_table *wait)
58755 mask = 0;
58756 if (filp->f_mode & FMODE_READ) {
58757 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
58758- if (!pipe->writers && filp->f_version != pipe->w_counter)
58759+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
58760 mask |= POLLHUP;
58761 }
58762
58763@@ -719,7 +719,7 @@ pipe_poll(struct file *filp, poll_table *wait)
58764 * Most Unices do not set POLLERR for FIFOs but on Linux they
58765 * behave exactly like pipes for poll().
58766 */
58767- if (!pipe->readers)
58768+ if (!atomic_read(&pipe->readers))
58769 mask |= POLLERR;
58770 }
58771
58772@@ -734,17 +734,17 @@ pipe_release(struct inode *inode, struct file *file)
58773
58774 __pipe_lock(pipe);
58775 if (file->f_mode & FMODE_READ)
58776- pipe->readers--;
58777+ atomic_dec(&pipe->readers);
58778 if (file->f_mode & FMODE_WRITE)
58779- pipe->writers--;
58780+ atomic_dec(&pipe->writers);
58781
58782- if (pipe->readers || pipe->writers) {
58783+ if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
58784 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
58785 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
58786 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
58787 }
58788 spin_lock(&inode->i_lock);
58789- if (!--pipe->files) {
58790+ if (atomic_dec_and_test(&pipe->files)) {
58791 inode->i_pipe = NULL;
58792 kill = 1;
58793 }
58794@@ -811,7 +811,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
58795 kfree(pipe);
58796 }
58797
58798-static struct vfsmount *pipe_mnt __read_mostly;
58799+struct vfsmount *pipe_mnt __read_mostly;
58800
58801 /*
58802 * pipefs_dname() is called from d_path().
58803@@ -841,8 +841,9 @@ static struct inode * get_pipe_inode(void)
58804 goto fail_iput;
58805
58806 inode->i_pipe = pipe;
58807- pipe->files = 2;
58808- pipe->readers = pipe->writers = 1;
58809+ atomic_set(&pipe->files, 2);
58810+ atomic_set(&pipe->readers, 1);
58811+ atomic_set(&pipe->writers, 1);
58812 inode->i_fop = &pipefifo_fops;
58813
58814 /*
58815@@ -1022,17 +1023,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
58816 spin_lock(&inode->i_lock);
58817 if (inode->i_pipe) {
58818 pipe = inode->i_pipe;
58819- pipe->files++;
58820+ atomic_inc(&pipe->files);
58821 spin_unlock(&inode->i_lock);
58822 } else {
58823 spin_unlock(&inode->i_lock);
58824 pipe = alloc_pipe_info();
58825 if (!pipe)
58826 return -ENOMEM;
58827- pipe->files = 1;
58828+ atomic_set(&pipe->files, 1);
58829 spin_lock(&inode->i_lock);
58830 if (unlikely(inode->i_pipe)) {
58831- inode->i_pipe->files++;
58832+ atomic_inc(&inode->i_pipe->files);
58833 spin_unlock(&inode->i_lock);
58834 free_pipe_info(pipe);
58835 pipe = inode->i_pipe;
58836@@ -1057,10 +1058,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
58837 * opened, even when there is no process writing the FIFO.
58838 */
58839 pipe->r_counter++;
58840- if (pipe->readers++ == 0)
58841+ if (atomic_inc_return(&pipe->readers) == 1)
58842 wake_up_partner(pipe);
58843
58844- if (!is_pipe && !pipe->writers) {
58845+ if (!is_pipe && !atomic_read(&pipe->writers)) {
58846 if ((filp->f_flags & O_NONBLOCK)) {
58847 /* suppress POLLHUP until we have
58848 * seen a writer */
58849@@ -1079,14 +1080,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
58850 * errno=ENXIO when there is no process reading the FIFO.
58851 */
58852 ret = -ENXIO;
58853- if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
58854+ if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
58855 goto err;
58856
58857 pipe->w_counter++;
58858- if (!pipe->writers++)
58859+ if (atomic_inc_return(&pipe->writers) == 1)
58860 wake_up_partner(pipe);
58861
58862- if (!is_pipe && !pipe->readers) {
58863+ if (!is_pipe && !atomic_read(&pipe->readers)) {
58864 if (wait_for_partner(pipe, &pipe->r_counter))
58865 goto err_wr;
58866 }
58867@@ -1100,11 +1101,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
58868 * the process can at least talk to itself.
58869 */
58870
58871- pipe->readers++;
58872- pipe->writers++;
58873+ atomic_inc(&pipe->readers);
58874+ atomic_inc(&pipe->writers);
58875 pipe->r_counter++;
58876 pipe->w_counter++;
58877- if (pipe->readers == 1 || pipe->writers == 1)
58878+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
58879 wake_up_partner(pipe);
58880 break;
58881
58882@@ -1118,20 +1119,20 @@ static int fifo_open(struct inode *inode, struct file *filp)
58883 return 0;
58884
58885 err_rd:
58886- if (!--pipe->readers)
58887+ if (atomic_dec_and_test(&pipe->readers))
58888 wake_up_interruptible(&pipe->wait);
58889 ret = -ERESTARTSYS;
58890 goto err;
58891
58892 err_wr:
58893- if (!--pipe->writers)
58894+ if (atomic_dec_and_test(&pipe->writers))
58895 wake_up_interruptible(&pipe->wait);
58896 ret = -ERESTARTSYS;
58897 goto err;
58898
58899 err:
58900 spin_lock(&inode->i_lock);
58901- if (!--pipe->files) {
58902+ if (atomic_dec_and_test(&pipe->files)) {
58903 inode->i_pipe = NULL;
58904 kill = 1;
58905 }
58906diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
58907index 15af622..0e9f4467 100644
58908--- a/fs/proc/Kconfig
58909+++ b/fs/proc/Kconfig
58910@@ -30,12 +30,12 @@ config PROC_FS
58911
58912 config PROC_KCORE
58913 bool "/proc/kcore support" if !ARM
58914- depends on PROC_FS && MMU
58915+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
58916
58917 config PROC_VMCORE
58918 bool "/proc/vmcore support"
58919- depends on PROC_FS && CRASH_DUMP
58920- default y
58921+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
58922+ default n
58923 help
58924 Exports the dump image of crashed kernel in ELF format.
58925
58926@@ -59,8 +59,8 @@ config PROC_SYSCTL
58927 limited in memory.
58928
58929 config PROC_PAGE_MONITOR
58930- default y
58931- depends on PROC_FS && MMU
58932+ default n
58933+ depends on PROC_FS && MMU && !GRKERNSEC
58934 bool "Enable /proc page monitoring" if EXPERT
58935 help
58936 Various /proc files exist to monitor process memory utilization:
58937diff --git a/fs/proc/array.c b/fs/proc/array.c
58938index cbd0f1b..adec3f0 100644
58939--- a/fs/proc/array.c
58940+++ b/fs/proc/array.c
58941@@ -60,6 +60,7 @@
58942 #include <linux/tty.h>
58943 #include <linux/string.h>
58944 #include <linux/mman.h>
58945+#include <linux/grsecurity.h>
58946 #include <linux/proc_fs.h>
58947 #include <linux/ioport.h>
58948 #include <linux/uaccess.h>
58949@@ -363,6 +364,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
58950 seq_putc(m, '\n');
58951 }
58952
58953+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
58954+static inline void task_pax(struct seq_file *m, struct task_struct *p)
58955+{
58956+ if (p->mm)
58957+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
58958+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
58959+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
58960+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
58961+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
58962+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
58963+ else
58964+ seq_printf(m, "PaX:\t-----\n");
58965+}
58966+#endif
58967+
58968 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
58969 struct pid *pid, struct task_struct *task)
58970 {
58971@@ -381,9 +397,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
58972 task_cpus_allowed(m, task);
58973 cpuset_task_status_allowed(m, task);
58974 task_context_switch_counts(m, task);
58975+
58976+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
58977+ task_pax(m, task);
58978+#endif
58979+
58980+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
58981+ task_grsec_rbac(m, task);
58982+#endif
58983+
58984 return 0;
58985 }
58986
58987+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58988+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
58989+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
58990+ _mm->pax_flags & MF_PAX_SEGMEXEC))
58991+#endif
58992+
58993 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
58994 struct pid *pid, struct task_struct *task, int whole)
58995 {
58996@@ -405,6 +436,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
58997 char tcomm[sizeof(task->comm)];
58998 unsigned long flags;
58999
59000+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59001+ if (current->exec_id != m->exec_id) {
59002+ gr_log_badprocpid("stat");
59003+ return 0;
59004+ }
59005+#endif
59006+
59007 state = *get_task_state(task);
59008 vsize = eip = esp = 0;
59009 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
59010@@ -476,6 +514,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
59011 gtime = task_gtime(task);
59012 }
59013
59014+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59015+ if (PAX_RAND_FLAGS(mm)) {
59016+ eip = 0;
59017+ esp = 0;
59018+ wchan = 0;
59019+ }
59020+#endif
59021+#ifdef CONFIG_GRKERNSEC_HIDESYM
59022+ wchan = 0;
59023+ eip =0;
59024+ esp =0;
59025+#endif
59026+
59027 /* scale priority and nice values from timeslices to -20..20 */
59028 /* to make it look like a "normal" Unix priority/nice value */
59029 priority = task_prio(task);
59030@@ -512,9 +563,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
59031 seq_put_decimal_ull(m, ' ', vsize);
59032 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
59033 seq_put_decimal_ull(m, ' ', rsslim);
59034+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59035+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
59036+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
59037+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
59038+#else
59039 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
59040 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
59041 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
59042+#endif
59043 seq_put_decimal_ull(m, ' ', esp);
59044 seq_put_decimal_ull(m, ' ', eip);
59045 /* The signal information here is obsolete.
59046@@ -536,7 +593,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
59047 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
59048 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
59049
59050- if (mm && permitted) {
59051+ if (mm && permitted
59052+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59053+ && !PAX_RAND_FLAGS(mm)
59054+#endif
59055+ ) {
59056 seq_put_decimal_ull(m, ' ', mm->start_data);
59057 seq_put_decimal_ull(m, ' ', mm->end_data);
59058 seq_put_decimal_ull(m, ' ', mm->start_brk);
59059@@ -574,8 +635,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
59060 struct pid *pid, struct task_struct *task)
59061 {
59062 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
59063- struct mm_struct *mm = get_task_mm(task);
59064+ struct mm_struct *mm;
59065
59066+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59067+ if (current->exec_id != m->exec_id) {
59068+ gr_log_badprocpid("statm");
59069+ return 0;
59070+ }
59071+#endif
59072+ mm = get_task_mm(task);
59073 if (mm) {
59074 size = task_statm(mm, &shared, &text, &data, &resident);
59075 mmput(mm);
59076@@ -598,6 +666,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
59077 return 0;
59078 }
59079
59080+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
59081+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
59082+{
59083+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
59084+}
59085+#endif
59086+
59087 #ifdef CONFIG_CHECKPOINT_RESTORE
59088 static struct pid *
59089 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
59090diff --git a/fs/proc/base.c b/fs/proc/base.c
59091index 1485e38..8ad4236 100644
59092--- a/fs/proc/base.c
59093+++ b/fs/proc/base.c
59094@@ -113,6 +113,14 @@ struct pid_entry {
59095 union proc_op op;
59096 };
59097
59098+struct getdents_callback {
59099+ struct linux_dirent __user * current_dir;
59100+ struct linux_dirent __user * previous;
59101+ struct file * file;
59102+ int count;
59103+ int error;
59104+};
59105+
59106 #define NOD(NAME, MODE, IOP, FOP, OP) { \
59107 .name = (NAME), \
59108 .len = sizeof(NAME) - 1, \
59109@@ -210,6 +218,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
59110 if (!mm->arg_end)
59111 goto out_mm; /* Shh! No looking before we're done */
59112
59113+ if (gr_acl_handle_procpidmem(task))
59114+ goto out_mm;
59115+
59116 len = mm->arg_end - mm->arg_start;
59117
59118 if (len > PAGE_SIZE)
59119@@ -237,12 +248,28 @@ out:
59120 return res;
59121 }
59122
59123+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59124+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
59125+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
59126+ _mm->pax_flags & MF_PAX_SEGMEXEC))
59127+#endif
59128+
59129 static int proc_pid_auxv(struct task_struct *task, char *buffer)
59130 {
59131 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
59132 int res = PTR_ERR(mm);
59133 if (mm && !IS_ERR(mm)) {
59134 unsigned int nwords = 0;
59135+
59136+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59137+ /* allow if we're currently ptracing this task */
59138+ if (PAX_RAND_FLAGS(mm) &&
59139+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
59140+ mmput(mm);
59141+ return 0;
59142+ }
59143+#endif
59144+
59145 do {
59146 nwords += 2;
59147 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
59148@@ -256,7 +283,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
59149 }
59150
59151
59152-#ifdef CONFIG_KALLSYMS
59153+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59154 /*
59155 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
59156 * Returns the resolved symbol. If that fails, simply return the address.
59157@@ -295,7 +322,7 @@ static void unlock_trace(struct task_struct *task)
59158 mutex_unlock(&task->signal->cred_guard_mutex);
59159 }
59160
59161-#ifdef CONFIG_STACKTRACE
59162+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59163
59164 #define MAX_STACK_TRACE_DEPTH 64
59165
59166@@ -518,7 +545,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
59167 return count;
59168 }
59169
59170-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
59171+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
59172 static int proc_pid_syscall(struct task_struct *task, char *buffer)
59173 {
59174 long nr;
59175@@ -547,7 +574,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
59176 /************************************************************************/
59177
59178 /* permission checks */
59179-static int proc_fd_access_allowed(struct inode *inode)
59180+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
59181 {
59182 struct task_struct *task;
59183 int allowed = 0;
59184@@ -557,7 +584,10 @@ static int proc_fd_access_allowed(struct inode *inode)
59185 */
59186 task = get_proc_task(inode);
59187 if (task) {
59188- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
59189+ if (log)
59190+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
59191+ else
59192+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
59193 put_task_struct(task);
59194 }
59195 return allowed;
59196@@ -588,10 +618,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
59197 struct task_struct *task,
59198 int hide_pid_min)
59199 {
59200+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
59201+ return false;
59202+
59203+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59204+ rcu_read_lock();
59205+ {
59206+ const struct cred *tmpcred = current_cred();
59207+ const struct cred *cred = __task_cred(task);
59208+
59209+ if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
59210+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
59211+ || in_group_p(grsec_proc_gid)
59212+#endif
59213+ ) {
59214+ rcu_read_unlock();
59215+ return true;
59216+ }
59217+ }
59218+ rcu_read_unlock();
59219+
59220+ if (!pid->hide_pid)
59221+ return false;
59222+#endif
59223+
59224 if (pid->hide_pid < hide_pid_min)
59225 return true;
59226 if (in_group_p(pid->pid_gid))
59227 return true;
59228+
59229 return ptrace_may_access(task, PTRACE_MODE_READ);
59230 }
59231
59232@@ -609,7 +664,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
59233 put_task_struct(task);
59234
59235 if (!has_perms) {
59236+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59237+ {
59238+#else
59239 if (pid->hide_pid == 2) {
59240+#endif
59241 /*
59242 * Let's make getdents(), stat(), and open()
59243 * consistent with each other. If a process
59244@@ -707,6 +766,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
59245 if (!task)
59246 return -ESRCH;
59247
59248+ if (gr_acl_handle_procpidmem(task)) {
59249+ put_task_struct(task);
59250+ return -EPERM;
59251+ }
59252+
59253 mm = mm_access(task, mode);
59254 put_task_struct(task);
59255
59256@@ -722,6 +786,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
59257
59258 file->private_data = mm;
59259
59260+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59261+ file->f_version = current->exec_id;
59262+#endif
59263+
59264 return 0;
59265 }
59266
59267@@ -743,6 +811,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
59268 ssize_t copied;
59269 char *page;
59270
59271+#ifdef CONFIG_GRKERNSEC
59272+ if (write)
59273+ return -EPERM;
59274+#endif
59275+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59276+ if (file->f_version != current->exec_id) {
59277+ gr_log_badprocpid("mem");
59278+ return 0;
59279+ }
59280+#endif
59281+
59282 if (!mm)
59283 return 0;
59284
59285@@ -755,7 +834,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
59286 goto free;
59287
59288 while (count > 0) {
59289- int this_len = min_t(int, count, PAGE_SIZE);
59290+ ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
59291
59292 if (write && copy_from_user(page, buf, this_len)) {
59293 copied = -EFAULT;
59294@@ -847,6 +926,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
59295 if (!mm)
59296 return 0;
59297
59298+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59299+ if (file->f_version != current->exec_id) {
59300+ gr_log_badprocpid("environ");
59301+ return 0;
59302+ }
59303+#endif
59304+
59305 page = (char *)__get_free_page(GFP_TEMPORARY);
59306 if (!page)
59307 return -ENOMEM;
59308@@ -856,7 +942,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
59309 goto free;
59310 while (count > 0) {
59311 size_t this_len, max_len;
59312- int retval;
59313+ ssize_t retval;
59314
59315 if (src >= (mm->env_end - mm->env_start))
59316 break;
59317@@ -1461,7 +1547,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
59318 int error = -EACCES;
59319
59320 /* Are we allowed to snoop on the tasks file descriptors? */
59321- if (!proc_fd_access_allowed(inode))
59322+ if (!proc_fd_access_allowed(inode, 0))
59323 goto out;
59324
59325 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
59326@@ -1505,8 +1591,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
59327 struct path path;
59328
59329 /* Are we allowed to snoop on the tasks file descriptors? */
59330- if (!proc_fd_access_allowed(inode))
59331- goto out;
59332+ /* logging this is needed for learning on chromium to work properly,
59333+ but we don't want to flood the logs from 'ps' which does a readlink
59334+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
59335+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
59336+ */
59337+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
59338+ if (!proc_fd_access_allowed(inode,0))
59339+ goto out;
59340+ } else {
59341+ if (!proc_fd_access_allowed(inode,1))
59342+ goto out;
59343+ }
59344
59345 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
59346 if (error)
59347@@ -1556,7 +1652,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
59348 rcu_read_lock();
59349 cred = __task_cred(task);
59350 inode->i_uid = cred->euid;
59351+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
59352+ inode->i_gid = grsec_proc_gid;
59353+#else
59354 inode->i_gid = cred->egid;
59355+#endif
59356 rcu_read_unlock();
59357 }
59358 security_task_to_inode(task, inode);
59359@@ -1592,10 +1692,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
59360 return -ENOENT;
59361 }
59362 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
59363+#ifdef CONFIG_GRKERNSEC_PROC_USER
59364+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
59365+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59366+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
59367+#endif
59368 task_dumpable(task)) {
59369 cred = __task_cred(task);
59370 stat->uid = cred->euid;
59371+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
59372+ stat->gid = grsec_proc_gid;
59373+#else
59374 stat->gid = cred->egid;
59375+#endif
59376 }
59377 }
59378 rcu_read_unlock();
59379@@ -1633,11 +1742,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
59380
59381 if (task) {
59382 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
59383+#ifdef CONFIG_GRKERNSEC_PROC_USER
59384+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
59385+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59386+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
59387+#endif
59388 task_dumpable(task)) {
59389 rcu_read_lock();
59390 cred = __task_cred(task);
59391 inode->i_uid = cred->euid;
59392+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
59393+ inode->i_gid = grsec_proc_gid;
59394+#else
59395 inode->i_gid = cred->egid;
59396+#endif
59397 rcu_read_unlock();
59398 } else {
59399 inode->i_uid = GLOBAL_ROOT_UID;
59400@@ -2166,6 +2284,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
59401 if (!task)
59402 goto out_no_task;
59403
59404+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
59405+ goto out;
59406+
59407 /*
59408 * Yes, it does not scale. And it should not. Don't add
59409 * new entries into /proc/<tgid>/ without very good reasons.
59410@@ -2196,6 +2317,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
59411 if (!task)
59412 return -ENOENT;
59413
59414+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
59415+ goto out;
59416+
59417 if (!dir_emit_dots(file, ctx))
59418 goto out;
59419
59420@@ -2585,7 +2709,7 @@ static const struct pid_entry tgid_base_stuff[] = {
59421 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
59422 #endif
59423 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
59424-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
59425+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
59426 INF("syscall", S_IRUGO, proc_pid_syscall),
59427 #endif
59428 INF("cmdline", S_IRUGO, proc_pid_cmdline),
59429@@ -2610,10 +2734,10 @@ static const struct pid_entry tgid_base_stuff[] = {
59430 #ifdef CONFIG_SECURITY
59431 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
59432 #endif
59433-#ifdef CONFIG_KALLSYMS
59434+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59435 INF("wchan", S_IRUGO, proc_pid_wchan),
59436 #endif
59437-#ifdef CONFIG_STACKTRACE
59438+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59439 ONE("stack", S_IRUGO, proc_pid_stack),
59440 #endif
59441 #ifdef CONFIG_SCHEDSTATS
59442@@ -2647,6 +2771,9 @@ static const struct pid_entry tgid_base_stuff[] = {
59443 #ifdef CONFIG_HARDWALL
59444 INF("hardwall", S_IRUGO, proc_pid_hardwall),
59445 #endif
59446+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
59447+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
59448+#endif
59449 #ifdef CONFIG_USER_NS
59450 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
59451 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
59452@@ -2777,7 +2904,14 @@ static int proc_pid_instantiate(struct inode *dir,
59453 if (!inode)
59454 goto out;
59455
59456+#ifdef CONFIG_GRKERNSEC_PROC_USER
59457+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
59458+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59459+ inode->i_gid = grsec_proc_gid;
59460+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
59461+#else
59462 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
59463+#endif
59464 inode->i_op = &proc_tgid_base_inode_operations;
59465 inode->i_fop = &proc_tgid_base_operations;
59466 inode->i_flags|=S_IMMUTABLE;
59467@@ -2815,7 +2949,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
59468 if (!task)
59469 goto out;
59470
59471+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
59472+ goto out_put_task;
59473+
59474 result = proc_pid_instantiate(dir, dentry, task, NULL);
59475+out_put_task:
59476 put_task_struct(task);
59477 out:
59478 return ERR_PTR(result);
59479@@ -2921,7 +3059,7 @@ static const struct pid_entry tid_base_stuff[] = {
59480 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
59481 #endif
59482 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
59483-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
59484+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
59485 INF("syscall", S_IRUGO, proc_pid_syscall),
59486 #endif
59487 INF("cmdline", S_IRUGO, proc_pid_cmdline),
59488@@ -2948,10 +3086,10 @@ static const struct pid_entry tid_base_stuff[] = {
59489 #ifdef CONFIG_SECURITY
59490 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
59491 #endif
59492-#ifdef CONFIG_KALLSYMS
59493+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59494 INF("wchan", S_IRUGO, proc_pid_wchan),
59495 #endif
59496-#ifdef CONFIG_STACKTRACE
59497+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59498 ONE("stack", S_IRUGO, proc_pid_stack),
59499 #endif
59500 #ifdef CONFIG_SCHEDSTATS
59501diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
59502index 82676e3..5f8518a 100644
59503--- a/fs/proc/cmdline.c
59504+++ b/fs/proc/cmdline.c
59505@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
59506
59507 static int __init proc_cmdline_init(void)
59508 {
59509+#ifdef CONFIG_GRKERNSEC_PROC_ADD
59510+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
59511+#else
59512 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
59513+#endif
59514 return 0;
59515 }
59516 module_init(proc_cmdline_init);
59517diff --git a/fs/proc/devices.c b/fs/proc/devices.c
59518index b143471..bb105e5 100644
59519--- a/fs/proc/devices.c
59520+++ b/fs/proc/devices.c
59521@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
59522
59523 static int __init proc_devices_init(void)
59524 {
59525+#ifdef CONFIG_GRKERNSEC_PROC_ADD
59526+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
59527+#else
59528 proc_create("devices", 0, NULL, &proc_devinfo_operations);
59529+#endif
59530 return 0;
59531 }
59532 module_init(proc_devices_init);
59533diff --git a/fs/proc/fd.c b/fs/proc/fd.c
59534index 0ff80f9..a1d7500 100644
59535--- a/fs/proc/fd.c
59536+++ b/fs/proc/fd.c
59537@@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
59538 if (!task)
59539 return -ENOENT;
59540
59541- files = get_files_struct(task);
59542+ if (!gr_acl_handle_procpidmem(task))
59543+ files = get_files_struct(task);
59544 put_task_struct(task);
59545
59546 if (files) {
59547@@ -283,11 +284,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
59548 */
59549 int proc_fd_permission(struct inode *inode, int mask)
59550 {
59551+ struct task_struct *task;
59552 int rv = generic_permission(inode, mask);
59553- if (rv == 0)
59554- return 0;
59555+
59556 if (task_pid(current) == proc_pid(inode))
59557 rv = 0;
59558+
59559+ task = get_proc_task(inode);
59560+ if (task == NULL)
59561+ return rv;
59562+
59563+ if (gr_acl_handle_procpidmem(task))
59564+ rv = -EACCES;
59565+
59566+ put_task_struct(task);
59567+
59568 return rv;
59569 }
59570
59571diff --git a/fs/proc/inode.c b/fs/proc/inode.c
59572index 073aea6..0630370 100644
59573--- a/fs/proc/inode.c
59574+++ b/fs/proc/inode.c
59575@@ -23,11 +23,17 @@
59576 #include <linux/slab.h>
59577 #include <linux/mount.h>
59578 #include <linux/magic.h>
59579+#include <linux/grsecurity.h>
59580
59581 #include <asm/uaccess.h>
59582
59583 #include "internal.h"
59584
59585+#ifdef CONFIG_PROC_SYSCTL
59586+extern const struct inode_operations proc_sys_inode_operations;
59587+extern const struct inode_operations proc_sys_dir_operations;
59588+#endif
59589+
59590 static void proc_evict_inode(struct inode *inode)
59591 {
59592 struct proc_dir_entry *de;
59593@@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
59594 ns = PROC_I(inode)->ns.ns;
59595 if (ns_ops && ns)
59596 ns_ops->put(ns);
59597+
59598+#ifdef CONFIG_PROC_SYSCTL
59599+ if (inode->i_op == &proc_sys_inode_operations ||
59600+ inode->i_op == &proc_sys_dir_operations)
59601+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
59602+#endif
59603+
59604 }
59605
59606 static struct kmem_cache * proc_inode_cachep;
59607@@ -385,7 +398,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
59608 if (de->mode) {
59609 inode->i_mode = de->mode;
59610 inode->i_uid = de->uid;
59611+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
59612+ inode->i_gid = grsec_proc_gid;
59613+#else
59614 inode->i_gid = de->gid;
59615+#endif
59616 }
59617 if (de->size)
59618 inode->i_size = de->size;
59619diff --git a/fs/proc/internal.h b/fs/proc/internal.h
59620index 651d09a..60c73ae 100644
59621--- a/fs/proc/internal.h
59622+++ b/fs/proc/internal.h
59623@@ -155,6 +155,9 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
59624 struct pid *, struct task_struct *);
59625 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
59626 struct pid *, struct task_struct *);
59627+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
59628+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
59629+#endif
59630
59631 /*
59632 * base.c
59633diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
59634index 06ea155..9a798c7 100644
59635--- a/fs/proc/kcore.c
59636+++ b/fs/proc/kcore.c
59637@@ -484,9 +484,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
59638 * the addresses in the elf_phdr on our list.
59639 */
59640 start = kc_offset_to_vaddr(*fpos - elf_buflen);
59641- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
59642+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
59643+ if (tsz > buflen)
59644 tsz = buflen;
59645-
59646+
59647 while (buflen) {
59648 struct kcore_list *m;
59649
59650@@ -515,20 +516,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
59651 kfree(elf_buf);
59652 } else {
59653 if (kern_addr_valid(start)) {
59654- unsigned long n;
59655+ char *elf_buf;
59656+ mm_segment_t oldfs;
59657
59658- n = copy_to_user(buffer, (char *)start, tsz);
59659- /*
59660- * We cannot distinguish between fault on source
59661- * and fault on destination. When this happens
59662- * we clear too and hope it will trigger the
59663- * EFAULT again.
59664- */
59665- if (n) {
59666- if (clear_user(buffer + tsz - n,
59667- n))
59668+ elf_buf = kmalloc(tsz, GFP_KERNEL);
59669+ if (!elf_buf)
59670+ return -ENOMEM;
59671+ oldfs = get_fs();
59672+ set_fs(KERNEL_DS);
59673+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
59674+ set_fs(oldfs);
59675+ if (copy_to_user(buffer, elf_buf, tsz)) {
59676+ kfree(elf_buf);
59677 return -EFAULT;
59678+ }
59679 }
59680+ set_fs(oldfs);
59681+ kfree(elf_buf);
59682 } else {
59683 if (clear_user(buffer, tsz))
59684 return -EFAULT;
59685@@ -548,6 +552,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
59686
59687 static int open_kcore(struct inode *inode, struct file *filp)
59688 {
59689+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
59690+ return -EPERM;
59691+#endif
59692 if (!capable(CAP_SYS_RAWIO))
59693 return -EPERM;
59694 if (kcore_need_update)
59695diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
59696index 5aa847a..f77c8d4 100644
59697--- a/fs/proc/meminfo.c
59698+++ b/fs/proc/meminfo.c
59699@@ -159,7 +159,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
59700 vmi.used >> 10,
59701 vmi.largest_chunk >> 10
59702 #ifdef CONFIG_MEMORY_FAILURE
59703- ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
59704+ ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
59705 #endif
59706 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
59707 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
59708diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
59709index ccfd99b..1b7e255 100644
59710--- a/fs/proc/nommu.c
59711+++ b/fs/proc/nommu.c
59712@@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
59713 if (len < 1)
59714 len = 1;
59715 seq_printf(m, "%*c", len, ' ');
59716- seq_path(m, &file->f_path, "");
59717+ seq_path(m, &file->f_path, "\n\\");
59718 }
59719
59720 seq_putc(m, '\n');
59721diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
59722index 4677bb7..408e936 100644
59723--- a/fs/proc/proc_net.c
59724+++ b/fs/proc/proc_net.c
59725@@ -23,6 +23,7 @@
59726 #include <linux/nsproxy.h>
59727 #include <net/net_namespace.h>
59728 #include <linux/seq_file.h>
59729+#include <linux/grsecurity.h>
59730
59731 #include "internal.h"
59732
59733@@ -109,6 +110,17 @@ static struct net *get_proc_task_net(struct inode *dir)
59734 struct task_struct *task;
59735 struct nsproxy *ns;
59736 struct net *net = NULL;
59737+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59738+ const struct cred *cred = current_cred();
59739+#endif
59740+
59741+#ifdef CONFIG_GRKERNSEC_PROC_USER
59742+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
59743+ return net;
59744+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59745+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
59746+ return net;
59747+#endif
59748
59749 rcu_read_lock();
59750 task = pid_task(proc_pid(dir), PIDTYPE_PID);
59751diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
59752index 7129046..f2779c6 100644
59753--- a/fs/proc/proc_sysctl.c
59754+++ b/fs/proc/proc_sysctl.c
59755@@ -13,11 +13,15 @@
59756 #include <linux/module.h>
59757 #include "internal.h"
59758
59759+extern int gr_handle_chroot_sysctl(const int op);
59760+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
59761+ const int op);
59762+
59763 static const struct dentry_operations proc_sys_dentry_operations;
59764 static const struct file_operations proc_sys_file_operations;
59765-static const struct inode_operations proc_sys_inode_operations;
59766+const struct inode_operations proc_sys_inode_operations;
59767 static const struct file_operations proc_sys_dir_file_operations;
59768-static const struct inode_operations proc_sys_dir_operations;
59769+const struct inode_operations proc_sys_dir_operations;
59770
59771 void proc_sys_poll_notify(struct ctl_table_poll *poll)
59772 {
59773@@ -467,6 +471,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
59774
59775 err = NULL;
59776 d_set_d_op(dentry, &proc_sys_dentry_operations);
59777+
59778+ gr_handle_proc_create(dentry, inode);
59779+
59780 d_add(dentry, inode);
59781
59782 out:
59783@@ -482,6 +489,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
59784 struct inode *inode = file_inode(filp);
59785 struct ctl_table_header *head = grab_header(inode);
59786 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
59787+ int op = write ? MAY_WRITE : MAY_READ;
59788 ssize_t error;
59789 size_t res;
59790
59791@@ -493,7 +501,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
59792 * and won't be until we finish.
59793 */
59794 error = -EPERM;
59795- if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
59796+ if (sysctl_perm(head, table, op))
59797 goto out;
59798
59799 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
59800@@ -501,6 +509,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
59801 if (!table->proc_handler)
59802 goto out;
59803
59804+#ifdef CONFIG_GRKERNSEC
59805+ error = -EPERM;
59806+ if (gr_handle_chroot_sysctl(op))
59807+ goto out;
59808+ dget(filp->f_path.dentry);
59809+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
59810+ dput(filp->f_path.dentry);
59811+ goto out;
59812+ }
59813+ dput(filp->f_path.dentry);
59814+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
59815+ goto out;
59816+ if (write && !capable(CAP_SYS_ADMIN))
59817+ goto out;
59818+#endif
59819+
59820 /* careful: calling conventions are nasty here */
59821 res = count;
59822 error = table->proc_handler(table, write, buf, &res, ppos);
59823@@ -598,6 +622,9 @@ static bool proc_sys_fill_cache(struct file *file,
59824 return false;
59825 } else {
59826 d_set_d_op(child, &proc_sys_dentry_operations);
59827+
59828+ gr_handle_proc_create(child, inode);
59829+
59830 d_add(child, inode);
59831 }
59832 } else {
59833@@ -641,6 +668,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
59834 if ((*pos)++ < ctx->pos)
59835 return true;
59836
59837+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
59838+ return 0;
59839+
59840 if (unlikely(S_ISLNK(table->mode)))
59841 res = proc_sys_link_fill_cache(file, ctx, head, table);
59842 else
59843@@ -734,6 +764,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
59844 if (IS_ERR(head))
59845 return PTR_ERR(head);
59846
59847+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
59848+ return -ENOENT;
59849+
59850 generic_fillattr(inode, stat);
59851 if (table)
59852 stat->mode = (stat->mode & S_IFMT) | table->mode;
59853@@ -756,13 +789,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
59854 .llseek = generic_file_llseek,
59855 };
59856
59857-static const struct inode_operations proc_sys_inode_operations = {
59858+const struct inode_operations proc_sys_inode_operations = {
59859 .permission = proc_sys_permission,
59860 .setattr = proc_sys_setattr,
59861 .getattr = proc_sys_getattr,
59862 };
59863
59864-static const struct inode_operations proc_sys_dir_operations = {
59865+const struct inode_operations proc_sys_dir_operations = {
59866 .lookup = proc_sys_lookup,
59867 .permission = proc_sys_permission,
59868 .setattr = proc_sys_setattr,
59869@@ -839,7 +872,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
59870 static struct ctl_dir *new_dir(struct ctl_table_set *set,
59871 const char *name, int namelen)
59872 {
59873- struct ctl_table *table;
59874+ ctl_table_no_const *table;
59875 struct ctl_dir *new;
59876 struct ctl_node *node;
59877 char *new_name;
59878@@ -851,7 +884,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
59879 return NULL;
59880
59881 node = (struct ctl_node *)(new + 1);
59882- table = (struct ctl_table *)(node + 1);
59883+ table = (ctl_table_no_const *)(node + 1);
59884 new_name = (char *)(table + 2);
59885 memcpy(new_name, name, namelen);
59886 new_name[namelen] = '\0';
59887@@ -1020,7 +1053,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
59888 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
59889 struct ctl_table_root *link_root)
59890 {
59891- struct ctl_table *link_table, *entry, *link;
59892+ ctl_table_no_const *link_table, *link;
59893+ struct ctl_table *entry;
59894 struct ctl_table_header *links;
59895 struct ctl_node *node;
59896 char *link_name;
59897@@ -1043,7 +1077,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
59898 return NULL;
59899
59900 node = (struct ctl_node *)(links + 1);
59901- link_table = (struct ctl_table *)(node + nr_entries);
59902+ link_table = (ctl_table_no_const *)(node + nr_entries);
59903 link_name = (char *)&link_table[nr_entries + 1];
59904
59905 for (link = link_table, entry = table; entry->procname; link++, entry++) {
59906@@ -1291,8 +1325,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
59907 struct ctl_table_header ***subheader, struct ctl_table_set *set,
59908 struct ctl_table *table)
59909 {
59910- struct ctl_table *ctl_table_arg = NULL;
59911- struct ctl_table *entry, *files;
59912+ ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
59913+ struct ctl_table *entry;
59914 int nr_files = 0;
59915 int nr_dirs = 0;
59916 int err = -ENOMEM;
59917@@ -1304,10 +1338,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
59918 nr_files++;
59919 }
59920
59921- files = table;
59922 /* If there are mixed files and directories we need a new table */
59923 if (nr_dirs && nr_files) {
59924- struct ctl_table *new;
59925+ ctl_table_no_const *new;
59926 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
59927 GFP_KERNEL);
59928 if (!files)
59929@@ -1325,7 +1358,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
59930 /* Register everything except a directory full of subdirectories */
59931 if (nr_files || !nr_dirs) {
59932 struct ctl_table_header *header;
59933- header = __register_sysctl_table(set, path, files);
59934+ header = __register_sysctl_table(set, path, files ? files : table);
59935 if (!header) {
59936 kfree(ctl_table_arg);
59937 goto out;
59938diff --git a/fs/proc/root.c b/fs/proc/root.c
59939index e0a790d..21e095e 100644
59940--- a/fs/proc/root.c
59941+++ b/fs/proc/root.c
59942@@ -182,7 +182,15 @@ void __init proc_root_init(void)
59943 #ifdef CONFIG_PROC_DEVICETREE
59944 proc_device_tree_init();
59945 #endif
59946+#ifdef CONFIG_GRKERNSEC_PROC_ADD
59947+#ifdef CONFIG_GRKERNSEC_PROC_USER
59948+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
59949+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59950+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
59951+#endif
59952+#else
59953 proc_mkdir("bus", NULL);
59954+#endif
59955 proc_sys_init();
59956 }
59957
59958diff --git a/fs/proc/self.c b/fs/proc/self.c
59959index 6b6a993..807cccc 100644
59960--- a/fs/proc/self.c
59961+++ b/fs/proc/self.c
59962@@ -39,7 +39,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
59963 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
59964 void *cookie)
59965 {
59966- char *s = nd_get_link(nd);
59967+ const char *s = nd_get_link(nd);
59968 if (!IS_ERR(s))
59969 kfree(s);
59970 }
59971diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
59972index 107d026..c715aeb 100644
59973--- a/fs/proc/task_mmu.c
59974+++ b/fs/proc/task_mmu.c
59975@@ -12,12 +12,19 @@
59976 #include <linux/swap.h>
59977 #include <linux/swapops.h>
59978 #include <linux/mmu_notifier.h>
59979+#include <linux/grsecurity.h>
59980
59981 #include <asm/elf.h>
59982 #include <asm/uaccess.h>
59983 #include <asm/tlbflush.h>
59984 #include "internal.h"
59985
59986+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59987+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
59988+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
59989+ _mm->pax_flags & MF_PAX_SEGMEXEC))
59990+#endif
59991+
59992 void task_mem(struct seq_file *m, struct mm_struct *mm)
59993 {
59994 unsigned long data, text, lib, swap;
59995@@ -53,8 +60,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
59996 "VmExe:\t%8lu kB\n"
59997 "VmLib:\t%8lu kB\n"
59998 "VmPTE:\t%8lu kB\n"
59999- "VmSwap:\t%8lu kB\n",
60000- hiwater_vm << (PAGE_SHIFT-10),
60001+ "VmSwap:\t%8lu kB\n"
60002+
60003+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
60004+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
60005+#endif
60006+
60007+ ,hiwater_vm << (PAGE_SHIFT-10),
60008 total_vm << (PAGE_SHIFT-10),
60009 mm->locked_vm << (PAGE_SHIFT-10),
60010 mm->pinned_vm << (PAGE_SHIFT-10),
60011@@ -63,7 +75,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
60012 data << (PAGE_SHIFT-10),
60013 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
60014 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
60015- swap << (PAGE_SHIFT-10));
60016+ swap << (PAGE_SHIFT-10)
60017+
60018+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
60019+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60020+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
60021+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
60022+#else
60023+ , mm->context.user_cs_base
60024+ , mm->context.user_cs_limit
60025+#endif
60026+#endif
60027+
60028+ );
60029 }
60030
60031 unsigned long task_vsize(struct mm_struct *mm)
60032@@ -278,13 +302,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
60033 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
60034 }
60035
60036- /* We don't show the stack guard page in /proc/maps */
60037+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60038+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
60039+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
60040+#else
60041 start = vma->vm_start;
60042- if (stack_guard_page_start(vma, start))
60043- start += PAGE_SIZE;
60044 end = vma->vm_end;
60045- if (stack_guard_page_end(vma, end))
60046- end -= PAGE_SIZE;
60047+#endif
60048
60049 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
60050 start,
60051@@ -293,7 +317,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
60052 flags & VM_WRITE ? 'w' : '-',
60053 flags & VM_EXEC ? 'x' : '-',
60054 flags & VM_MAYSHARE ? 's' : 'p',
60055+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60056+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
60057+#else
60058 pgoff,
60059+#endif
60060 MAJOR(dev), MINOR(dev), ino, &len);
60061
60062 /*
60063@@ -302,7 +330,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
60064 */
60065 if (file) {
60066 pad_len_spaces(m, len);
60067- seq_path(m, &file->f_path, "\n");
60068+ seq_path(m, &file->f_path, "\n\\");
60069 goto done;
60070 }
60071
60072@@ -328,8 +356,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
60073 * Thread stack in /proc/PID/task/TID/maps or
60074 * the main process stack.
60075 */
60076- if (!is_pid || (vma->vm_start <= mm->start_stack &&
60077- vma->vm_end >= mm->start_stack)) {
60078+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
60079+ (vma->vm_start <= mm->start_stack &&
60080+ vma->vm_end >= mm->start_stack)) {
60081 name = "[stack]";
60082 } else {
60083 /* Thread stack in /proc/PID/maps */
60084@@ -353,6 +382,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
60085 struct proc_maps_private *priv = m->private;
60086 struct task_struct *task = priv->task;
60087
60088+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60089+ if (current->exec_id != m->exec_id) {
60090+ gr_log_badprocpid("maps");
60091+ return 0;
60092+ }
60093+#endif
60094+
60095 show_map_vma(m, vma, is_pid);
60096
60097 if (m->count < m->size) /* vma is copied successfully */
60098@@ -590,12 +626,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
60099 .private = &mss,
60100 };
60101
60102+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60103+ if (current->exec_id != m->exec_id) {
60104+ gr_log_badprocpid("smaps");
60105+ return 0;
60106+ }
60107+#endif
60108 memset(&mss, 0, sizeof mss);
60109- mss.vma = vma;
60110- /* mmap_sem is held in m_start */
60111- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
60112- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
60113-
60114+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60115+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
60116+#endif
60117+ mss.vma = vma;
60118+ /* mmap_sem is held in m_start */
60119+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
60120+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
60121+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60122+ }
60123+#endif
60124 show_map_vma(m, vma, is_pid);
60125
60126 seq_printf(m,
60127@@ -613,7 +660,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
60128 "KernelPageSize: %8lu kB\n"
60129 "MMUPageSize: %8lu kB\n"
60130 "Locked: %8lu kB\n",
60131+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60132+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
60133+#else
60134 (vma->vm_end - vma->vm_start) >> 10,
60135+#endif
60136 mss.resident >> 10,
60137 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
60138 mss.shared_clean >> 10,
60139@@ -1362,6 +1413,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
60140 int n;
60141 char buffer[50];
60142
60143+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60144+ if (current->exec_id != m->exec_id) {
60145+ gr_log_badprocpid("numa_maps");
60146+ return 0;
60147+ }
60148+#endif
60149+
60150 if (!mm)
60151 return 0;
60152
60153@@ -1379,11 +1437,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
60154 mpol_to_str(buffer, sizeof(buffer), pol);
60155 mpol_cond_put(pol);
60156
60157+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60158+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
60159+#else
60160 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
60161+#endif
60162
60163 if (file) {
60164 seq_printf(m, " file=");
60165- seq_path(m, &file->f_path, "\n\t= ");
60166+ seq_path(m, &file->f_path, "\n\t\\= ");
60167 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
60168 seq_printf(m, " heap");
60169 } else {
60170diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
60171index 56123a6..5a2f6ec 100644
60172--- a/fs/proc/task_nommu.c
60173+++ b/fs/proc/task_nommu.c
60174@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
60175 else
60176 bytes += kobjsize(mm);
60177
60178- if (current->fs && current->fs->users > 1)
60179+ if (current->fs && atomic_read(&current->fs->users) > 1)
60180 sbytes += kobjsize(current->fs);
60181 else
60182 bytes += kobjsize(current->fs);
60183@@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
60184
60185 if (file) {
60186 pad_len_spaces(m, len);
60187- seq_path(m, &file->f_path, "");
60188+ seq_path(m, &file->f_path, "\n\\");
60189 } else if (mm) {
60190 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
60191
60192diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
60193index a1a16eb..6be46ed 100644
60194--- a/fs/proc/vmcore.c
60195+++ b/fs/proc/vmcore.c
60196@@ -104,9 +104,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
60197 nr_bytes = count;
60198
60199 /* If pfn is not ram, return zeros for sparse dump files */
60200- if (pfn_is_ram(pfn) == 0)
60201- memset(buf, 0, nr_bytes);
60202- else {
60203+ if (pfn_is_ram(pfn) == 0) {
60204+ if (userbuf) {
60205+ if (clear_user((char __force_user *)buf, nr_bytes))
60206+ return -EFAULT;
60207+ } else
60208+ memset(buf, 0, nr_bytes);
60209+ } else {
60210 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
60211 offset, userbuf);
60212 if (tmp < 0)
60213@@ -178,7 +182,7 @@ static ssize_t read_vmcore(struct file *file, char __user *buffer,
60214 if (*fpos < m->offset + m->size) {
60215 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
60216 start = m->paddr + *fpos - m->offset;
60217- tmp = read_from_oldmem(buffer, tsz, &start, 1);
60218+ tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, 1);
60219 if (tmp < 0)
60220 return tmp;
60221 buflen -= tsz;
60222diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
60223index b00fcc9..e0c6381 100644
60224--- a/fs/qnx6/qnx6.h
60225+++ b/fs/qnx6/qnx6.h
60226@@ -74,7 +74,7 @@ enum {
60227 BYTESEX_BE,
60228 };
60229
60230-static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
60231+static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
60232 {
60233 if (sbi->s_bytesex == BYTESEX_LE)
60234 return le64_to_cpu((__force __le64)n);
60235@@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
60236 return (__force __fs64)cpu_to_be64(n);
60237 }
60238
60239-static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
60240+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
60241 {
60242 if (sbi->s_bytesex == BYTESEX_LE)
60243 return le32_to_cpu((__force __le32)n);
60244diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
60245index 16e8abb..2dcf914 100644
60246--- a/fs/quota/netlink.c
60247+++ b/fs/quota/netlink.c
60248@@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
60249 void quota_send_warning(struct kqid qid, dev_t dev,
60250 const char warntype)
60251 {
60252- static atomic_t seq;
60253+ static atomic_unchecked_t seq;
60254 struct sk_buff *skb;
60255 void *msg_head;
60256 int ret;
60257@@ -49,7 +49,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
60258 "VFS: Not enough memory to send quota warning.\n");
60259 return;
60260 }
60261- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
60262+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
60263 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
60264 if (!msg_head) {
60265 printk(KERN_ERR
60266diff --git a/fs/read_write.c b/fs/read_write.c
60267index 122a384..0b7ecf2 100644
60268--- a/fs/read_write.c
60269+++ b/fs/read_write.c
60270@@ -440,7 +440,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
60271
60272 old_fs = get_fs();
60273 set_fs(get_ds());
60274- p = (__force const char __user *)buf;
60275+ p = (const char __force_user *)buf;
60276 if (count > MAX_RW_COUNT)
60277 count = MAX_RW_COUNT;
60278 if (file->f_op->write)
60279diff --git a/fs/readdir.c b/fs/readdir.c
60280index 93d71e5..6a14be8 100644
60281--- a/fs/readdir.c
60282+++ b/fs/readdir.c
60283@@ -17,6 +17,7 @@
60284 #include <linux/security.h>
60285 #include <linux/syscalls.h>
60286 #include <linux/unistd.h>
60287+#include <linux/namei.h>
60288
60289 #include <asm/uaccess.h>
60290
60291@@ -69,6 +70,7 @@ struct old_linux_dirent {
60292 struct readdir_callback {
60293 struct dir_context ctx;
60294 struct old_linux_dirent __user * dirent;
60295+ struct file * file;
60296 int result;
60297 };
60298
60299@@ -86,6 +88,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
60300 buf->result = -EOVERFLOW;
60301 return -EOVERFLOW;
60302 }
60303+
60304+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60305+ return 0;
60306+
60307 buf->result++;
60308 dirent = buf->dirent;
60309 if (!access_ok(VERIFY_WRITE, dirent,
60310@@ -117,6 +123,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
60311 if (!f.file)
60312 return -EBADF;
60313
60314+ buf.file = f.file;
60315 error = iterate_dir(f.file, &buf.ctx);
60316 if (buf.result)
60317 error = buf.result;
60318@@ -142,6 +149,7 @@ struct getdents_callback {
60319 struct dir_context ctx;
60320 struct linux_dirent __user * current_dir;
60321 struct linux_dirent __user * previous;
60322+ struct file * file;
60323 int count;
60324 int error;
60325 };
60326@@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
60327 buf->error = -EOVERFLOW;
60328 return -EOVERFLOW;
60329 }
60330+
60331+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60332+ return 0;
60333+
60334 dirent = buf->previous;
60335 if (dirent) {
60336 if (__put_user(offset, &dirent->d_off))
60337@@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
60338 if (!f.file)
60339 return -EBADF;
60340
60341+ buf.file = f.file;
60342 error = iterate_dir(f.file, &buf.ctx);
60343 if (error >= 0)
60344 error = buf.error;
60345@@ -226,6 +239,7 @@ struct getdents_callback64 {
60346 struct dir_context ctx;
60347 struct linux_dirent64 __user * current_dir;
60348 struct linux_dirent64 __user * previous;
60349+ struct file *file;
60350 int count;
60351 int error;
60352 };
60353@@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
60354 buf->error = -EINVAL; /* only used if we fail.. */
60355 if (reclen > buf->count)
60356 return -EINVAL;
60357+
60358+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60359+ return 0;
60360+
60361 dirent = buf->previous;
60362 if (dirent) {
60363 if (__put_user(offset, &dirent->d_off))
60364@@ -288,6 +306,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
60365 if (!f.file)
60366 return -EBADF;
60367
60368+ buf.file = f.file;
60369 error = iterate_dir(f.file, &buf.ctx);
60370 if (error >= 0)
60371 error = buf.error;
60372diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
60373index 2b7882b..1c5ef48 100644
60374--- a/fs/reiserfs/do_balan.c
60375+++ b/fs/reiserfs/do_balan.c
60376@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
60377 return;
60378 }
60379
60380- atomic_inc(&(fs_generation(tb->tb_sb)));
60381+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
60382 do_balance_starts(tb);
60383
60384 /* balance leaf returns 0 except if combining L R and S into
60385diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
60386index a958444..42b2323 100644
60387--- a/fs/reiserfs/procfs.c
60388+++ b/fs/reiserfs/procfs.c
60389@@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
60390 "SMALL_TAILS " : "NO_TAILS ",
60391 replay_only(sb) ? "REPLAY_ONLY " : "",
60392 convert_reiserfs(sb) ? "CONV " : "",
60393- atomic_read(&r->s_generation_counter),
60394+ atomic_read_unchecked(&r->s_generation_counter),
60395 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
60396 SF(s_do_balance), SF(s_unneeded_left_neighbor),
60397 SF(s_good_search_by_key_reada), SF(s_bmaps),
60398diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
60399index 3df5ce6..8c0f4b0 100644
60400--- a/fs/reiserfs/reiserfs.h
60401+++ b/fs/reiserfs/reiserfs.h
60402@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
60403 /* Comment? -Hans */
60404 wait_queue_head_t s_wait;
60405 /* To be obsoleted soon by per buffer seals.. -Hans */
60406- atomic_t s_generation_counter; // increased by one every time the
60407+ atomic_unchecked_t s_generation_counter; // increased by one every time the
60408 // tree gets re-balanced
60409 unsigned long s_properties; /* File system properties. Currently holds
60410 on-disk FS format */
60411@@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
60412 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
60413
60414 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
60415-#define get_generation(s) atomic_read (&fs_generation(s))
60416+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
60417 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
60418 #define __fs_changed(gen,s) (gen != get_generation (s))
60419 #define fs_changed(gen,s) \
60420diff --git a/fs/select.c b/fs/select.c
60421index 35d4adc7..d6c60db 100644
60422--- a/fs/select.c
60423+++ b/fs/select.c
60424@@ -20,6 +20,7 @@
60425 #include <linux/export.h>
60426 #include <linux/slab.h>
60427 #include <linux/poll.h>
60428+#include <linux/security.h>
60429 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
60430 #include <linux/file.h>
60431 #include <linux/fdtable.h>
60432@@ -881,6 +882,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
60433 struct poll_list *walk = head;
60434 unsigned long todo = nfds;
60435
60436+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
60437 if (nfds > rlimit(RLIMIT_NOFILE))
60438 return -EINVAL;
60439
60440diff --git a/fs/seq_file.c b/fs/seq_file.c
60441index 3135c25..d0395dd 100644
60442--- a/fs/seq_file.c
60443+++ b/fs/seq_file.c
60444@@ -10,6 +10,7 @@
60445 #include <linux/seq_file.h>
60446 #include <linux/slab.h>
60447 #include <linux/cred.h>
60448+#include <linux/sched.h>
60449
60450 #include <asm/uaccess.h>
60451 #include <asm/page.h>
60452@@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
60453 #ifdef CONFIG_USER_NS
60454 p->user_ns = file->f_cred->user_ns;
60455 #endif
60456+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60457+ p->exec_id = current->exec_id;
60458+#endif
60459
60460 /*
60461 * Wrappers around seq_open(e.g. swaps_open) need to be
60462@@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
60463 return 0;
60464 }
60465 if (!m->buf) {
60466- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
60467+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
60468 if (!m->buf)
60469 return -ENOMEM;
60470 }
60471@@ -136,7 +140,7 @@ static int traverse(struct seq_file *m, loff_t offset)
60472 Eoverflow:
60473 m->op->stop(m, p);
60474 kfree(m->buf);
60475- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
60476+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
60477 return !m->buf ? -ENOMEM : -EAGAIN;
60478 }
60479
60480@@ -191,7 +195,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
60481
60482 /* grab buffer if we didn't have one */
60483 if (!m->buf) {
60484- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
60485+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
60486 if (!m->buf)
60487 goto Enomem;
60488 }
60489@@ -232,7 +236,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
60490 goto Fill;
60491 m->op->stop(m, p);
60492 kfree(m->buf);
60493- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
60494+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
60495 if (!m->buf)
60496 goto Enomem;
60497 m->count = 0;
60498@@ -581,7 +585,7 @@ static void single_stop(struct seq_file *p, void *v)
60499 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
60500 void *data)
60501 {
60502- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
60503+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
60504 int res = -ENOMEM;
60505
60506 if (op) {
60507diff --git a/fs/splice.c b/fs/splice.c
60508index 3b7ee65..87fc2e4 100644
60509--- a/fs/splice.c
60510+++ b/fs/splice.c
60511@@ -196,7 +196,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
60512 pipe_lock(pipe);
60513
60514 for (;;) {
60515- if (!pipe->readers) {
60516+ if (!atomic_read(&pipe->readers)) {
60517 send_sig(SIGPIPE, current, 0);
60518 if (!ret)
60519 ret = -EPIPE;
60520@@ -219,7 +219,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
60521 page_nr++;
60522 ret += buf->len;
60523
60524- if (pipe->files)
60525+ if (atomic_read(&pipe->files))
60526 do_wakeup = 1;
60527
60528 if (!--spd->nr_pages)
60529@@ -250,9 +250,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
60530 do_wakeup = 0;
60531 }
60532
60533- pipe->waiting_writers++;
60534+ atomic_inc(&pipe->waiting_writers);
60535 pipe_wait(pipe);
60536- pipe->waiting_writers--;
60537+ atomic_dec(&pipe->waiting_writers);
60538 }
60539
60540 pipe_unlock(pipe);
60541@@ -565,7 +565,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
60542 old_fs = get_fs();
60543 set_fs(get_ds());
60544 /* The cast to a user pointer is valid due to the set_fs() */
60545- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
60546+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
60547 set_fs(old_fs);
60548
60549 return res;
60550@@ -580,7 +580,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
60551 old_fs = get_fs();
60552 set_fs(get_ds());
60553 /* The cast to a user pointer is valid due to the set_fs() */
60554- res = vfs_write(file, (__force const char __user *)buf, count, &pos);
60555+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
60556 set_fs(old_fs);
60557
60558 return res;
60559@@ -633,7 +633,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
60560 goto err;
60561
60562 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
60563- vec[i].iov_base = (void __user *) page_address(page);
60564+ vec[i].iov_base = (void __force_user *) page_address(page);
60565 vec[i].iov_len = this_len;
60566 spd.pages[i] = page;
60567 spd.nr_pages++;
60568@@ -829,7 +829,7 @@ int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_desc *sd,
60569 ops->release(pipe, buf);
60570 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
60571 pipe->nrbufs--;
60572- if (pipe->files)
60573+ if (atomic_read(&pipe->files))
60574 sd->need_wakeup = true;
60575 }
60576
60577@@ -854,10 +854,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
60578 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
60579 {
60580 while (!pipe->nrbufs) {
60581- if (!pipe->writers)
60582+ if (!atomic_read(&pipe->writers))
60583 return 0;
60584
60585- if (!pipe->waiting_writers && sd->num_spliced)
60586+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
60587 return 0;
60588
60589 if (sd->flags & SPLICE_F_NONBLOCK)
60590@@ -1179,7 +1179,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
60591 * out of the pipe right after the splice_to_pipe(). So set
60592 * PIPE_READERS appropriately.
60593 */
60594- pipe->readers = 1;
60595+ atomic_set(&pipe->readers, 1);
60596
60597 current->splice_pipe = pipe;
60598 }
60599@@ -1475,6 +1475,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
60600
60601 partial[buffers].offset = off;
60602 partial[buffers].len = plen;
60603+ partial[buffers].private = 0;
60604
60605 off = 0;
60606 len -= plen;
60607@@ -1777,9 +1778,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
60608 ret = -ERESTARTSYS;
60609 break;
60610 }
60611- if (!pipe->writers)
60612+ if (!atomic_read(&pipe->writers))
60613 break;
60614- if (!pipe->waiting_writers) {
60615+ if (!atomic_read(&pipe->waiting_writers)) {
60616 if (flags & SPLICE_F_NONBLOCK) {
60617 ret = -EAGAIN;
60618 break;
60619@@ -1811,7 +1812,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
60620 pipe_lock(pipe);
60621
60622 while (pipe->nrbufs >= pipe->buffers) {
60623- if (!pipe->readers) {
60624+ if (!atomic_read(&pipe->readers)) {
60625 send_sig(SIGPIPE, current, 0);
60626 ret = -EPIPE;
60627 break;
60628@@ -1824,9 +1825,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
60629 ret = -ERESTARTSYS;
60630 break;
60631 }
60632- pipe->waiting_writers++;
60633+ atomic_inc(&pipe->waiting_writers);
60634 pipe_wait(pipe);
60635- pipe->waiting_writers--;
60636+ atomic_dec(&pipe->waiting_writers);
60637 }
60638
60639 pipe_unlock(pipe);
60640@@ -1862,14 +1863,14 @@ retry:
60641 pipe_double_lock(ipipe, opipe);
60642
60643 do {
60644- if (!opipe->readers) {
60645+ if (!atomic_read(&opipe->readers)) {
60646 send_sig(SIGPIPE, current, 0);
60647 if (!ret)
60648 ret = -EPIPE;
60649 break;
60650 }
60651
60652- if (!ipipe->nrbufs && !ipipe->writers)
60653+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
60654 break;
60655
60656 /*
60657@@ -1966,7 +1967,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
60658 pipe_double_lock(ipipe, opipe);
60659
60660 do {
60661- if (!opipe->readers) {
60662+ if (!atomic_read(&opipe->readers)) {
60663 send_sig(SIGPIPE, current, 0);
60664 if (!ret)
60665 ret = -EPIPE;
60666@@ -2011,7 +2012,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
60667 * return EAGAIN if we have the potential of some data in the
60668 * future, otherwise just return 0
60669 */
60670- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
60671+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
60672 ret = -EAGAIN;
60673
60674 pipe_unlock(ipipe);
60675diff --git a/fs/stat.c b/fs/stat.c
60676index 04ce1ac..a13dd1e 100644
60677--- a/fs/stat.c
60678+++ b/fs/stat.c
60679@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
60680 stat->gid = inode->i_gid;
60681 stat->rdev = inode->i_rdev;
60682 stat->size = i_size_read(inode);
60683- stat->atime = inode->i_atime;
60684- stat->mtime = inode->i_mtime;
60685+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
60686+ stat->atime = inode->i_ctime;
60687+ stat->mtime = inode->i_ctime;
60688+ } else {
60689+ stat->atime = inode->i_atime;
60690+ stat->mtime = inode->i_mtime;
60691+ }
60692 stat->ctime = inode->i_ctime;
60693 stat->blksize = (1 << inode->i_blkbits);
60694 stat->blocks = inode->i_blocks;
60695@@ -46,8 +51,14 @@ int vfs_getattr(struct path *path, struct kstat *stat)
60696 if (retval)
60697 return retval;
60698
60699- if (inode->i_op->getattr)
60700- return inode->i_op->getattr(path->mnt, path->dentry, stat);
60701+ if (inode->i_op->getattr) {
60702+ retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
60703+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
60704+ stat->atime = stat->ctime;
60705+ stat->mtime = stat->ctime;
60706+ }
60707+ return retval;
60708+ }
60709
60710 generic_fillattr(inode, stat);
60711 return 0;
60712diff --git a/fs/sysfs/bin.c b/fs/sysfs/bin.c
60713index 15c68f9..36a8b3e 100644
60714--- a/fs/sysfs/bin.c
60715+++ b/fs/sysfs/bin.c
60716@@ -235,13 +235,13 @@ static int bin_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
60717 return ret;
60718 }
60719
60720-static int bin_access(struct vm_area_struct *vma, unsigned long addr,
60721- void *buf, int len, int write)
60722+static ssize_t bin_access(struct vm_area_struct *vma, unsigned long addr,
60723+ void *buf, size_t len, int write)
60724 {
60725 struct file *file = vma->vm_file;
60726 struct bin_buffer *bb = file->private_data;
60727 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
60728- int ret;
60729+ ssize_t ret;
60730
60731 if (!bb->vm_ops)
60732 return -EINVAL;
60733diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
60734index e068e74..92edeb8 100644
60735--- a/fs/sysfs/dir.c
60736+++ b/fs/sysfs/dir.c
60737@@ -40,7 +40,7 @@ static DEFINE_IDA(sysfs_ino_ida);
60738 *
60739 * Returns 31 bit hash of ns + name (so it fits in an off_t )
60740 */
60741-static unsigned int sysfs_name_hash(const void *ns, const char *name)
60742+static unsigned int sysfs_name_hash(const void *ns, const unsigned char *name)
60743 {
60744 unsigned long hash = init_name_hash();
60745 unsigned int len = strlen(name);
60746@@ -679,6 +679,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
60747 struct sysfs_dirent *sd;
60748 int rc;
60749
60750+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
60751+ const char *parent_name = parent_sd->s_name;
60752+
60753+ mode = S_IFDIR | S_IRWXU;
60754+
60755+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
60756+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
60757+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
60758+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
60759+ mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
60760+#endif
60761+
60762 /* allocate */
60763 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
60764 if (!sd)
60765diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
60766index d2bb7ed..fe8c331 100644
60767--- a/fs/sysfs/file.c
60768+++ b/fs/sysfs/file.c
60769@@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
60770
60771 struct sysfs_open_dirent {
60772 atomic_t refcnt;
60773- atomic_t event;
60774+ atomic_unchecked_t event;
60775 wait_queue_head_t poll;
60776 struct list_head buffers; /* goes through sysfs_buffer.list */
60777 };
60778@@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
60779 if (!sysfs_get_active(attr_sd))
60780 return -ENODEV;
60781
60782- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
60783+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
60784 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
60785
60786 sysfs_put_active(attr_sd);
60787@@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
60788 return -ENOMEM;
60789
60790 atomic_set(&new_od->refcnt, 0);
60791- atomic_set(&new_od->event, 1);
60792+ atomic_set_unchecked(&new_od->event, 1);
60793 init_waitqueue_head(&new_od->poll);
60794 INIT_LIST_HEAD(&new_od->buffers);
60795 goto retry;
60796@@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
60797
60798 sysfs_put_active(attr_sd);
60799
60800- if (buffer->event != atomic_read(&od->event))
60801+ if (buffer->event != atomic_read_unchecked(&od->event))
60802 goto trigger;
60803
60804 return DEFAULT_POLLMASK;
60805@@ -452,7 +452,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
60806 if (!WARN_ON(sysfs_type(sd) != SYSFS_KOBJ_ATTR)) {
60807 od = sd->s_attr.open;
60808 if (od) {
60809- atomic_inc(&od->event);
60810+ atomic_inc_unchecked(&od->event);
60811 wake_up_interruptible(&od->poll);
60812 }
60813 }
60814diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
60815index 8c940df..25b733e 100644
60816--- a/fs/sysfs/symlink.c
60817+++ b/fs/sysfs/symlink.c
60818@@ -305,7 +305,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
60819
60820 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
60821 {
60822- char *page = nd_get_link(nd);
60823+ const char *page = nd_get_link(nd);
60824 if (!IS_ERR(page))
60825 free_page((unsigned long)page);
60826 }
60827diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
60828index 69d4889..a810bd4 100644
60829--- a/fs/sysv/sysv.h
60830+++ b/fs/sysv/sysv.h
60831@@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
60832 #endif
60833 }
60834
60835-static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
60836+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
60837 {
60838 if (sbi->s_bytesex == BYTESEX_PDP)
60839 return PDP_swab((__force __u32)n);
60840diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
60841index e18b988..f1d4ad0f 100644
60842--- a/fs/ubifs/io.c
60843+++ b/fs/ubifs/io.c
60844@@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
60845 return err;
60846 }
60847
60848-int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
60849+int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
60850 {
60851 int err;
60852
60853diff --git a/fs/udf/misc.c b/fs/udf/misc.c
60854index c175b4d..8f36a16 100644
60855--- a/fs/udf/misc.c
60856+++ b/fs/udf/misc.c
60857@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
60858
60859 u8 udf_tag_checksum(const struct tag *t)
60860 {
60861- u8 *data = (u8 *)t;
60862+ const u8 *data = (const u8 *)t;
60863 u8 checksum = 0;
60864 int i;
60865 for (i = 0; i < sizeof(struct tag); ++i)
60866diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
60867index 8d974c4..b82f6ec 100644
60868--- a/fs/ufs/swab.h
60869+++ b/fs/ufs/swab.h
60870@@ -22,7 +22,7 @@ enum {
60871 BYTESEX_BE
60872 };
60873
60874-static inline u64
60875+static inline u64 __intentional_overflow(-1)
60876 fs64_to_cpu(struct super_block *sbp, __fs64 n)
60877 {
60878 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
60879@@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
60880 return (__force __fs64)cpu_to_be64(n);
60881 }
60882
60883-static inline u32
60884+static inline u32 __intentional_overflow(-1)
60885 fs32_to_cpu(struct super_block *sbp, __fs32 n)
60886 {
60887 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
60888diff --git a/fs/utimes.c b/fs/utimes.c
60889index f4fb7ec..3fe03c0 100644
60890--- a/fs/utimes.c
60891+++ b/fs/utimes.c
60892@@ -1,6 +1,7 @@
60893 #include <linux/compiler.h>
60894 #include <linux/file.h>
60895 #include <linux/fs.h>
60896+#include <linux/security.h>
60897 #include <linux/linkage.h>
60898 #include <linux/mount.h>
60899 #include <linux/namei.h>
60900@@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
60901 goto mnt_drop_write_and_out;
60902 }
60903 }
60904+
60905+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
60906+ error = -EACCES;
60907+ goto mnt_drop_write_and_out;
60908+ }
60909+
60910 mutex_lock(&inode->i_mutex);
60911 error = notify_change(path->dentry, &newattrs);
60912 mutex_unlock(&inode->i_mutex);
60913diff --git a/fs/xattr.c b/fs/xattr.c
60914index 3377dff..4d074d9 100644
60915--- a/fs/xattr.c
60916+++ b/fs/xattr.c
60917@@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
60918 return rc;
60919 }
60920
60921+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
60922+ssize_t
60923+pax_getxattr(struct dentry *dentry, void *value, size_t size)
60924+{
60925+ struct inode *inode = dentry->d_inode;
60926+ ssize_t error;
60927+
60928+ error = inode_permission(inode, MAY_EXEC);
60929+ if (error)
60930+ return error;
60931+
60932+ if (inode->i_op->getxattr)
60933+ error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
60934+ else
60935+ error = -EOPNOTSUPP;
60936+
60937+ return error;
60938+}
60939+EXPORT_SYMBOL(pax_getxattr);
60940+#endif
60941+
60942 ssize_t
60943 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
60944 {
60945@@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
60946 * Extended attribute SET operations
60947 */
60948 static long
60949-setxattr(struct dentry *d, const char __user *name, const void __user *value,
60950+setxattr(struct path *path, const char __user *name, const void __user *value,
60951 size_t size, int flags)
60952 {
60953 int error;
60954@@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
60955 posix_acl_fix_xattr_from_user(kvalue, size);
60956 }
60957
60958- error = vfs_setxattr(d, kname, kvalue, size, flags);
60959+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
60960+ error = -EACCES;
60961+ goto out;
60962+ }
60963+
60964+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
60965 out:
60966 if (vvalue)
60967 vfree(vvalue);
60968@@ -377,7 +403,7 @@ retry:
60969 return error;
60970 error = mnt_want_write(path.mnt);
60971 if (!error) {
60972- error = setxattr(path.dentry, name, value, size, flags);
60973+ error = setxattr(&path, name, value, size, flags);
60974 mnt_drop_write(path.mnt);
60975 }
60976 path_put(&path);
60977@@ -401,7 +427,7 @@ retry:
60978 return error;
60979 error = mnt_want_write(path.mnt);
60980 if (!error) {
60981- error = setxattr(path.dentry, name, value, size, flags);
60982+ error = setxattr(&path, name, value, size, flags);
60983 mnt_drop_write(path.mnt);
60984 }
60985 path_put(&path);
60986@@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
60987 const void __user *,value, size_t, size, int, flags)
60988 {
60989 struct fd f = fdget(fd);
60990- struct dentry *dentry;
60991 int error = -EBADF;
60992
60993 if (!f.file)
60994 return error;
60995- dentry = f.file->f_path.dentry;
60996- audit_inode(NULL, dentry, 0);
60997+ audit_inode(NULL, f.file->f_path.dentry, 0);
60998 error = mnt_want_write_file(f.file);
60999 if (!error) {
61000- error = setxattr(dentry, name, value, size, flags);
61001+ error = setxattr(&f.file->f_path, name, value, size, flags);
61002 mnt_drop_write_file(f.file);
61003 }
61004 fdput(f);
61005diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
61006index 9fbea87..6b19972 100644
61007--- a/fs/xattr_acl.c
61008+++ b/fs/xattr_acl.c
61009@@ -76,8 +76,8 @@ struct posix_acl *
61010 posix_acl_from_xattr(struct user_namespace *user_ns,
61011 const void *value, size_t size)
61012 {
61013- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
61014- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
61015+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
61016+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
61017 int count;
61018 struct posix_acl *acl;
61019 struct posix_acl_entry *acl_e;
61020diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
61021index 05c698c..6b918af 100644
61022--- a/fs/xfs/xfs_bmap.c
61023+++ b/fs/xfs/xfs_bmap.c
61024@@ -765,7 +765,7 @@ xfs_bmap_validate_ret(
61025
61026 #else
61027 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
61028-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
61029+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
61030 #endif /* DEBUG */
61031
61032 /*
61033diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
61034index 97676a3..399a75d 100644
61035--- a/fs/xfs/xfs_dir2_sf.c
61036+++ b/fs/xfs/xfs_dir2_sf.c
61037@@ -848,7 +848,12 @@ xfs_dir2_sf_getdents(
61038
61039 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
61040 ctx->pos = off & 0x7fffffff;
61041- if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen,
61042+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
61043+ char name[sfep->namelen];
61044+ memcpy(name, sfep->name, sfep->namelen);
61045+ if (!dir_emit(ctx, name, sfep->namelen, ino, DT_UNKNOWN))
61046+ return 0;
61047+ } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen,
61048 ino, DT_UNKNOWN))
61049 return 0;
61050 sfep = xfs_dir2_sf_nextentry(sfp, sfep);
61051diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
61052index 6e2bca5..6ce80d3 100644
61053--- a/fs/xfs/xfs_ioctl.c
61054+++ b/fs/xfs/xfs_ioctl.c
61055@@ -127,7 +127,7 @@ xfs_find_handle(
61056 }
61057
61058 error = -EFAULT;
61059- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
61060+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
61061 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
61062 goto out_put;
61063
61064diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
61065index 96dda62..d6c6a52 100644
61066--- a/fs/xfs/xfs_iops.c
61067+++ b/fs/xfs/xfs_iops.c
61068@@ -395,7 +395,7 @@ xfs_vn_put_link(
61069 struct nameidata *nd,
61070 void *p)
61071 {
61072- char *s = nd_get_link(nd);
61073+ const char *s = nd_get_link(nd);
61074
61075 if (!IS_ERR(s))
61076 kfree(s);
61077diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
61078new file mode 100644
61079index 0000000..0fd7c82
61080--- /dev/null
61081+++ b/grsecurity/Kconfig
61082@@ -0,0 +1,1080 @@
61083+#
61084+# grecurity configuration
61085+#
61086+menu "Memory Protections"
61087+depends on GRKERNSEC
61088+
61089+config GRKERNSEC_KMEM
61090+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
61091+ default y if GRKERNSEC_CONFIG_AUTO
61092+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
61093+ help
61094+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
61095+ be written to or read from to modify or leak the contents of the running
61096+ kernel. /dev/port will also not be allowed to be opened and support
61097+ for /dev/cpu/*/msr will be removed. If you have module
61098+ support disabled, enabling this will close up five ways that are
61099+ currently used to insert malicious code into the running kernel.
61100+
61101+ Even with all these features enabled, we still highly recommend that
61102+ you use the RBAC system, as it is still possible for an attacker to
61103+ modify the running kernel through privileged I/O granted by ioperm/iopl.
61104+
61105+ If you are not using XFree86, you may be able to stop this additional
61106+ case by enabling the 'Disable privileged I/O' option. Though nothing
61107+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
61108+ but only to video memory, which is the only writing we allow in this
61109+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
61110+ not be allowed to mprotect it with PROT_WRITE later.
61111+ Enabling this feature will prevent the "cpupower" and "powertop" tools
61112+ from working.
61113+
61114+ It is highly recommended that you say Y here if you meet all the
61115+ conditions above.
61116+
61117+config GRKERNSEC_VM86
61118+ bool "Restrict VM86 mode"
61119+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
61120+ depends on X86_32
61121+
61122+ help
61123+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
61124+ make use of a special execution mode on 32bit x86 processors called
61125+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
61126+ video cards and will still work with this option enabled. The purpose
61127+ of the option is to prevent exploitation of emulation errors in
61128+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
61129+ Nearly all users should be able to enable this option.
61130+
61131+config GRKERNSEC_IO
61132+ bool "Disable privileged I/O"
61133+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
61134+ depends on X86
61135+ select RTC_CLASS
61136+ select RTC_INTF_DEV
61137+ select RTC_DRV_CMOS
61138+
61139+ help
61140+ If you say Y here, all ioperm and iopl calls will return an error.
61141+ Ioperm and iopl can be used to modify the running kernel.
61142+ Unfortunately, some programs need this access to operate properly,
61143+ the most notable of which are XFree86 and hwclock. hwclock can be
61144+ remedied by having RTC support in the kernel, so real-time
61145+ clock support is enabled if this option is enabled, to ensure
61146+ that hwclock operates correctly. XFree86 still will not
61147+ operate correctly with this option enabled, so DO NOT CHOOSE Y
61148+ IF YOU USE XFree86. If you use XFree86 and you still want to
61149+ protect your kernel against modification, use the RBAC system.
61150+
61151+config GRKERNSEC_JIT_HARDEN
61152+ bool "Harden BPF JIT against spray attacks"
61153+ default y if GRKERNSEC_CONFIG_AUTO
61154+ depends on BPF_JIT
61155+ help
61156+ If you say Y here, the native code generated by the kernel's Berkeley
61157+ Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
61158+ attacks that attempt to fit attacker-beneficial instructions in
61159+ 32bit immediate fields of JIT-generated native instructions. The
61160+ attacker will generally aim to cause an unintended instruction sequence
61161+ of JIT-generated native code to execute by jumping into the middle of
61162+ a generated instruction. This feature effectively randomizes the 32bit
61163+ immediate constants present in the generated code to thwart such attacks.
61164+
61165+ If you're using KERNEXEC, it's recommended that you enable this option
61166+ to supplement the hardening of the kernel.
61167+
61168+config GRKERNSEC_PERF_HARDEN
61169+ bool "Disable unprivileged PERF_EVENTS usage by default"
61170+ default y if GRKERNSEC_CONFIG_AUTO
61171+ depends on PERF_EVENTS
61172+ help
61173+ If you say Y here, the range of acceptable values for the
61174+ /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
61175+ default to a new value: 3. When the sysctl is set to this value, no
61176+ unprivileged use of the PERF_EVENTS syscall interface will be permitted.
61177+
61178+ Though PERF_EVENTS can be used legitimately for performance monitoring
61179+ and low-level application profiling, it is forced on regardless of
61180+ configuration, has been at fault for several vulnerabilities, and
61181+ creates new opportunities for side channels and other information leaks.
61182+
61183+ This feature puts PERF_EVENTS into a secure default state and permits
61184+ the administrator to change out of it temporarily if unprivileged
61185+ application profiling is needed.
61186+
61187+config GRKERNSEC_RAND_THREADSTACK
61188+ bool "Insert random gaps between thread stacks"
61189+ default y if GRKERNSEC_CONFIG_AUTO
61190+ depends on PAX_RANDMMAP && !PPC
61191+ help
61192+ If you say Y here, a random-sized gap will be enforced between allocated
61193+ thread stacks. Glibc's NPTL and other threading libraries that
61194+ pass MAP_STACK to the kernel for thread stack allocation are supported.
61195+ The implementation currently provides 8 bits of entropy for the gap.
61196+
61197+ Many distributions do not compile threaded remote services with the
61198+ -fstack-check argument to GCC, causing the variable-sized stack-based
61199+ allocator, alloca(), to not probe the stack on allocation. This
61200+ permits an unbounded alloca() to skip over any guard page and potentially
61201+ modify another thread's stack reliably. An enforced random gap
61202+ reduces the reliability of such an attack and increases the chance
61203+ that such a read/write to another thread's stack instead lands in
61204+ an unmapped area, causing a crash and triggering grsecurity's
61205+ anti-bruteforcing logic.
61206+
61207+config GRKERNSEC_PROC_MEMMAP
61208+ bool "Harden ASLR against information leaks and entropy reduction"
61209+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
61210+ depends on PAX_NOEXEC || PAX_ASLR
61211+ help
61212+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
61213+ give no information about the addresses of its mappings if
61214+ PaX features that rely on random addresses are enabled on the task.
61215+ In addition to sanitizing this information and disabling other
61216+ dangerous sources of information, this option causes reads of sensitive
61217+ /proc/<pid> entries where the file descriptor was opened in a different
61218+ task than the one performing the read. Such attempts are logged.
61219+ This option also limits argv/env strings for suid/sgid binaries
61220+ to 512KB to prevent a complete exhaustion of the stack entropy provided
61221+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
61222+ binaries to prevent alternative mmap layouts from being abused.
61223+
61224+ If you use PaX it is essential that you say Y here as it closes up
61225+ several holes that make full ASLR useless locally.
61226+
61227+config GRKERNSEC_BRUTE
61228+ bool "Deter exploit bruteforcing"
61229+ default y if GRKERNSEC_CONFIG_AUTO
61230+ help
61231+ If you say Y here, attempts to bruteforce exploits against forking
61232+ daemons such as apache or sshd, as well as against suid/sgid binaries
61233+ will be deterred. When a child of a forking daemon is killed by PaX
61234+ or crashes due to an illegal instruction or other suspicious signal,
61235+ the parent process will be delayed 30 seconds upon every subsequent
61236+ fork until the administrator is able to assess the situation and
61237+ restart the daemon.
61238+ In the suid/sgid case, the attempt is logged, the user has all their
61239+ existing instances of the suid/sgid binary terminated and will
61240+ be unable to execute any suid/sgid binaries for 15 minutes.
61241+
61242+ It is recommended that you also enable signal logging in the auditing
61243+ section so that logs are generated when a process triggers a suspicious
61244+ signal.
61245+ If the sysctl option is enabled, a sysctl option with name
61246+ "deter_bruteforce" is created.
61247+
61248+
61249+config GRKERNSEC_MODHARDEN
61250+ bool "Harden module auto-loading"
61251+ default y if GRKERNSEC_CONFIG_AUTO
61252+ depends on MODULES
61253+ help
61254+ If you say Y here, module auto-loading in response to use of some
61255+ feature implemented by an unloaded module will be restricted to
61256+ root users. Enabling this option helps defend against attacks
61257+ by unprivileged users who abuse the auto-loading behavior to
61258+ cause a vulnerable module to load that is then exploited.
61259+
61260+ If this option prevents a legitimate use of auto-loading for a
61261+ non-root user, the administrator can execute modprobe manually
61262+ with the exact name of the module mentioned in the alert log.
61263+ Alternatively, the administrator can add the module to the list
61264+ of modules loaded at boot by modifying init scripts.
61265+
61266+ Modification of init scripts will most likely be needed on
61267+ Ubuntu servers with encrypted home directory support enabled,
61268+ as the first non-root user logging in will cause the ecb(aes),
61269+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
61270+
61271+config GRKERNSEC_HIDESYM
61272+ bool "Hide kernel symbols"
61273+ default y if GRKERNSEC_CONFIG_AUTO
61274+ select PAX_USERCOPY_SLABS
61275+ help
61276+ If you say Y here, getting information on loaded modules, and
61277+ displaying all kernel symbols through a syscall will be restricted
61278+ to users with CAP_SYS_MODULE. For software compatibility reasons,
61279+ /proc/kallsyms will be restricted to the root user. The RBAC
61280+ system can hide that entry even from root.
61281+
61282+ This option also prevents leaking of kernel addresses through
61283+ several /proc entries.
61284+
61285+ Note that this option is only effective provided the following
61286+ conditions are met:
61287+ 1) The kernel using grsecurity is not precompiled by some distribution
61288+ 2) You have also enabled GRKERNSEC_DMESG
61289+ 3) You are using the RBAC system and hiding other files such as your
61290+ kernel image and System.map. Alternatively, enabling this option
61291+ causes the permissions on /boot, /lib/modules, and the kernel
61292+ source directory to change at compile time to prevent
61293+ reading by non-root users.
61294+ If the above conditions are met, this option will aid in providing a
61295+ useful protection against local kernel exploitation of overflows
61296+ and arbitrary read/write vulnerabilities.
61297+
61298+ It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
61299+ in addition to this feature.
61300+
61301+config GRKERNSEC_KERN_LOCKOUT
61302+ bool "Active kernel exploit response"
61303+ default y if GRKERNSEC_CONFIG_AUTO
61304+ depends on X86 || ARM || PPC || SPARC
61305+ help
61306+ If you say Y here, when a PaX alert is triggered due to suspicious
61307+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
61308+ or an OOPS occurs due to bad memory accesses, instead of just
61309+ terminating the offending process (and potentially allowing
61310+ a subsequent exploit from the same user), we will take one of two
61311+ actions:
61312+ If the user was root, we will panic the system
61313+ If the user was non-root, we will log the attempt, terminate
61314+ all processes owned by the user, then prevent them from creating
61315+ any new processes until the system is restarted
61316+ This deters repeated kernel exploitation/bruteforcing attempts
61317+ and is useful for later forensics.
61318+
61319+endmenu
61320+menu "Role Based Access Control Options"
61321+depends on GRKERNSEC
61322+
61323+config GRKERNSEC_RBAC_DEBUG
61324+ bool
61325+
61326+config GRKERNSEC_NO_RBAC
61327+ bool "Disable RBAC system"
61328+ help
61329+ If you say Y here, the /dev/grsec device will be removed from the kernel,
61330+ preventing the RBAC system from being enabled. You should only say Y
61331+ here if you have no intention of using the RBAC system, so as to prevent
61332+ an attacker with root access from misusing the RBAC system to hide files
61333+ and processes when loadable module support and /dev/[k]mem have been
61334+ locked down.
61335+
61336+config GRKERNSEC_ACL_HIDEKERN
61337+ bool "Hide kernel processes"
61338+ help
61339+ If you say Y here, all kernel threads will be hidden to all
61340+ processes but those whose subject has the "view hidden processes"
61341+ flag.
61342+
61343+config GRKERNSEC_ACL_MAXTRIES
61344+ int "Maximum tries before password lockout"
61345+ default 3
61346+ help
61347+ This option enforces the maximum number of times a user can attempt
61348+ to authorize themselves with the grsecurity RBAC system before being
61349+ denied the ability to attempt authorization again for a specified time.
61350+ The lower the number, the harder it will be to brute-force a password.
61351+
61352+config GRKERNSEC_ACL_TIMEOUT
61353+ int "Time to wait after max password tries, in seconds"
61354+ default 30
61355+ help
61356+ This option specifies the time the user must wait after attempting to
61357+ authorize to the RBAC system with the maximum number of invalid
61358+ passwords. The higher the number, the harder it will be to brute-force
61359+ a password.
61360+
61361+endmenu
61362+menu "Filesystem Protections"
61363+depends on GRKERNSEC
61364+
61365+config GRKERNSEC_PROC
61366+ bool "Proc restrictions"
61367+ default y if GRKERNSEC_CONFIG_AUTO
61368+ help
61369+ If you say Y here, the permissions of the /proc filesystem
61370+ will be altered to enhance system security and privacy. You MUST
61371+ choose either a user only restriction or a user and group restriction.
61372+ Depending upon the option you choose, you can either restrict users to
61373+ see only the processes they themselves run, or choose a group that can
61374+ view all processes and files normally restricted to root if you choose
61375+ the "restrict to user only" option. NOTE: If you're running identd or
61376+ ntpd as a non-root user, you will have to run it as the group you
61377+ specify here.
61378+
61379+config GRKERNSEC_PROC_USER
61380+ bool "Restrict /proc to user only"
61381+ depends on GRKERNSEC_PROC
61382+ help
61383+ If you say Y here, non-root users will only be able to view their own
61384+ processes, and restricts them from viewing network-related information,
61385+ and viewing kernel symbol and module information.
61386+
61387+config GRKERNSEC_PROC_USERGROUP
61388+ bool "Allow special group"
61389+ default y if GRKERNSEC_CONFIG_AUTO
61390+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
61391+ help
61392+ If you say Y here, you will be able to select a group that will be
61393+ able to view all processes and network-related information. If you've
61394+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
61395+ remain hidden. This option is useful if you want to run identd as
61396+ a non-root user. The group you select may also be chosen at boot time
61397+ via "grsec_proc_gid=" on the kernel commandline.
61398+
61399+config GRKERNSEC_PROC_GID
61400+ int "GID for special group"
61401+ depends on GRKERNSEC_PROC_USERGROUP
61402+ default 1001
61403+
61404+config GRKERNSEC_PROC_ADD
61405+ bool "Additional restrictions"
61406+ default y if GRKERNSEC_CONFIG_AUTO
61407+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
61408+ help
61409+ If you say Y here, additional restrictions will be placed on
61410+ /proc that keep normal users from viewing device information and
61411+ slabinfo information that could be useful for exploits.
61412+
61413+config GRKERNSEC_LINK
61414+ bool "Linking restrictions"
61415+ default y if GRKERNSEC_CONFIG_AUTO
61416+ help
61417+ If you say Y here, /tmp race exploits will be prevented, since users
61418+ will no longer be able to follow symlinks owned by other users in
61419+ world-writable +t directories (e.g. /tmp), unless the owner of the
61420+ symlink is the owner of the directory. users will also not be
61421+ able to hardlink to files they do not own. If the sysctl option is
61422+ enabled, a sysctl option with name "linking_restrictions" is created.
61423+
61424+config GRKERNSEC_SYMLINKOWN
61425+ bool "Kernel-enforced SymlinksIfOwnerMatch"
61426+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
61427+ help
61428+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
61429+ that prevents it from being used as a security feature. As Apache
61430+ verifies the symlink by performing a stat() against the target of
61431+ the symlink before it is followed, an attacker can setup a symlink
61432+ to point to a same-owned file, then replace the symlink with one
61433+ that targets another user's file just after Apache "validates" the
61434+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
61435+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
61436+ will be in place for the group you specify. If the sysctl option
61437+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
61438+ created.
61439+
61440+config GRKERNSEC_SYMLINKOWN_GID
61441+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
61442+ depends on GRKERNSEC_SYMLINKOWN
61443+ default 1006
61444+ help
61445+ Setting this GID determines what group kernel-enforced
61446+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
61447+ is enabled, a sysctl option with name "symlinkown_gid" is created.
61448+
61449+config GRKERNSEC_FIFO
61450+ bool "FIFO restrictions"
61451+ default y if GRKERNSEC_CONFIG_AUTO
61452+ help
61453+ If you say Y here, users will not be able to write to FIFOs they don't
61454+ own in world-writable +t directories (e.g. /tmp), unless the owner of
61455+ the FIFO is the same owner of the directory it's held in. If the sysctl
61456+ option is enabled, a sysctl option with name "fifo_restrictions" is
61457+ created.
61458+
61459+config GRKERNSEC_SYSFS_RESTRICT
61460+ bool "Sysfs/debugfs restriction"
61461+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
61462+ depends on SYSFS
61463+ help
61464+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
61465+ any filesystem normally mounted under it (e.g. debugfs) will be
61466+ mostly accessible only by root. These filesystems generally provide access
61467+ to hardware and debug information that isn't appropriate for unprivileged
61468+ users of the system. Sysfs and debugfs have also become a large source
61469+ of new vulnerabilities, ranging from infoleaks to local compromise.
61470+ There has been very little oversight with an eye toward security involved
61471+ in adding new exporters of information to these filesystems, so their
61472+ use is discouraged.
61473+ For reasons of compatibility, a few directories have been whitelisted
61474+ for access by non-root users:
61475+ /sys/fs/selinux
61476+ /sys/fs/fuse
61477+ /sys/devices/system/cpu
61478+
61479+config GRKERNSEC_ROFS
61480+ bool "Runtime read-only mount protection"
61481+ depends on SYSCTL
61482+ help
61483+ If you say Y here, a sysctl option with name "romount_protect" will
61484+ be created. By setting this option to 1 at runtime, filesystems
61485+ will be protected in the following ways:
61486+ * No new writable mounts will be allowed
61487+ * Existing read-only mounts won't be able to be remounted read/write
61488+ * Write operations will be denied on all block devices
61489+ This option acts independently of grsec_lock: once it is set to 1,
61490+ it cannot be turned off. Therefore, please be mindful of the resulting
61491+ behavior if this option is enabled in an init script on a read-only
61492+ filesystem. This feature is mainly intended for secure embedded systems.
61493+
61494+config GRKERNSEC_DEVICE_SIDECHANNEL
61495+ bool "Eliminate stat/notify-based device sidechannels"
61496+ default y if GRKERNSEC_CONFIG_AUTO
61497+ help
61498+ If you say Y here, timing analyses on block or character
61499+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
61500+ will be thwarted for unprivileged users. If a process without
61501+ CAP_MKNOD stats such a device, the last access and last modify times
61502+ will match the device's create time. No access or modify events
61503+ will be triggered through inotify/dnotify/fanotify for such devices.
61504+ This feature will prevent attacks that may at a minimum
61505+ allow an attacker to determine the administrator's password length.
61506+
61507+config GRKERNSEC_CHROOT
61508+ bool "Chroot jail restrictions"
61509+ default y if GRKERNSEC_CONFIG_AUTO
61510+ help
61511+ If you say Y here, you will be able to choose several options that will
61512+ make breaking out of a chrooted jail much more difficult. If you
61513+ encounter no software incompatibilities with the following options, it
61514+ is recommended that you enable each one.
61515+
61516+config GRKERNSEC_CHROOT_MOUNT
61517+ bool "Deny mounts"
61518+ default y if GRKERNSEC_CONFIG_AUTO
61519+ depends on GRKERNSEC_CHROOT
61520+ help
61521+ If you say Y here, processes inside a chroot will not be able to
61522+ mount or remount filesystems. If the sysctl option is enabled, a
61523+ sysctl option with name "chroot_deny_mount" is created.
61524+
61525+config GRKERNSEC_CHROOT_DOUBLE
61526+ bool "Deny double-chroots"
61527+ default y if GRKERNSEC_CONFIG_AUTO
61528+ depends on GRKERNSEC_CHROOT
61529+ help
61530+ If you say Y here, processes inside a chroot will not be able to chroot
61531+ again outside the chroot. This is a widely used method of breaking
61532+ out of a chroot jail and should not be allowed. If the sysctl
61533+ option is enabled, a sysctl option with name
61534+ "chroot_deny_chroot" is created.
61535+
61536+config GRKERNSEC_CHROOT_PIVOT
61537+ bool "Deny pivot_root in chroot"
61538+ default y if GRKERNSEC_CONFIG_AUTO
61539+ depends on GRKERNSEC_CHROOT
61540+ help
61541+ If you say Y here, processes inside a chroot will not be able to use
61542+ a function called pivot_root() that was introduced in Linux 2.3.41. It
61543+ works similar to chroot in that it changes the root filesystem. This
61544+ function could be misused in a chrooted process to attempt to break out
61545+ of the chroot, and therefore should not be allowed. If the sysctl
61546+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
61547+ created.
61548+
61549+config GRKERNSEC_CHROOT_CHDIR
61550+ bool "Enforce chdir(\"/\") on all chroots"
61551+ default y if GRKERNSEC_CONFIG_AUTO
61552+ depends on GRKERNSEC_CHROOT
61553+ help
61554+ If you say Y here, the current working directory of all newly-chrooted
61555+ applications will be set to the the root directory of the chroot.
61556+ The man page on chroot(2) states:
61557+ Note that this call does not change the current working
61558+ directory, so that `.' can be outside the tree rooted at
61559+ `/'. In particular, the super-user can escape from a
61560+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
61561+
61562+ It is recommended that you say Y here, since it's not known to break
61563+ any software. If the sysctl option is enabled, a sysctl option with
61564+ name "chroot_enforce_chdir" is created.
61565+
61566+config GRKERNSEC_CHROOT_CHMOD
61567+ bool "Deny (f)chmod +s"
61568+ default y if GRKERNSEC_CONFIG_AUTO
61569+ depends on GRKERNSEC_CHROOT
61570+ help
61571+ If you say Y here, processes inside a chroot will not be able to chmod
61572+ or fchmod files to make them have suid or sgid bits. This protects
61573+ against another published method of breaking a chroot. If the sysctl
61574+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
61575+ created.
61576+
61577+config GRKERNSEC_CHROOT_FCHDIR
61578+ bool "Deny fchdir out of chroot"
61579+ default y if GRKERNSEC_CONFIG_AUTO
61580+ depends on GRKERNSEC_CHROOT
61581+ help
61582+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
61583+ to a file descriptor of the chrooting process that points to a directory
61584+ outside the filesystem will be stopped. If the sysctl option
61585+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
61586+
61587+config GRKERNSEC_CHROOT_MKNOD
61588+ bool "Deny mknod"
61589+ default y if GRKERNSEC_CONFIG_AUTO
61590+ depends on GRKERNSEC_CHROOT
61591+ help
61592+ If you say Y here, processes inside a chroot will not be allowed to
61593+ mknod. The problem with using mknod inside a chroot is that it
61594+ would allow an attacker to create a device entry that is the same
61595+ as one on the physical root of your system, which could range from
61596+ anything from the console device to a device for your harddrive (which
61597+ they could then use to wipe the drive or steal data). It is recommended
61598+ that you say Y here, unless you run into software incompatibilities.
61599+ If the sysctl option is enabled, a sysctl option with name
61600+ "chroot_deny_mknod" is created.
61601+
61602+config GRKERNSEC_CHROOT_SHMAT
61603+ bool "Deny shmat() out of chroot"
61604+ default y if GRKERNSEC_CONFIG_AUTO
61605+ depends on GRKERNSEC_CHROOT
61606+ help
61607+ If you say Y here, processes inside a chroot will not be able to attach
61608+ to shared memory segments that were created outside of the chroot jail.
61609+ It is recommended that you say Y here. If the sysctl option is enabled,
61610+ a sysctl option with name "chroot_deny_shmat" is created.
61611+
61612+config GRKERNSEC_CHROOT_UNIX
61613+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
61614+ default y if GRKERNSEC_CONFIG_AUTO
61615+ depends on GRKERNSEC_CHROOT
61616+ help
61617+ If you say Y here, processes inside a chroot will not be able to
61618+ connect to abstract (meaning not belonging to a filesystem) Unix
61619+ domain sockets that were bound outside of a chroot. It is recommended
61620+ that you say Y here. If the sysctl option is enabled, a sysctl option
61621+ with name "chroot_deny_unix" is created.
61622+
61623+config GRKERNSEC_CHROOT_FINDTASK
61624+ bool "Protect outside processes"
61625+ default y if GRKERNSEC_CONFIG_AUTO
61626+ depends on GRKERNSEC_CHROOT
61627+ help
61628+ If you say Y here, processes inside a chroot will not be able to
61629+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
61630+ getsid, or view any process outside of the chroot. If the sysctl
61631+ option is enabled, a sysctl option with name "chroot_findtask" is
61632+ created.
61633+
61634+config GRKERNSEC_CHROOT_NICE
61635+ bool "Restrict priority changes"
61636+ default y if GRKERNSEC_CONFIG_AUTO
61637+ depends on GRKERNSEC_CHROOT
61638+ help
61639+ If you say Y here, processes inside a chroot will not be able to raise
61640+ the priority of processes in the chroot, or alter the priority of
61641+ processes outside the chroot. This provides more security than simply
61642+ removing CAP_SYS_NICE from the process' capability set. If the
61643+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
61644+ is created.
61645+
61646+config GRKERNSEC_CHROOT_SYSCTL
61647+ bool "Deny sysctl writes"
61648+ default y if GRKERNSEC_CONFIG_AUTO
61649+ depends on GRKERNSEC_CHROOT
61650+ help
61651+ If you say Y here, an attacker in a chroot will not be able to
61652+ write to sysctl entries, either by sysctl(2) or through a /proc
61653+ interface. It is strongly recommended that you say Y here. If the
61654+ sysctl option is enabled, a sysctl option with name
61655+ "chroot_deny_sysctl" is created.
61656+
61657+config GRKERNSEC_CHROOT_CAPS
61658+ bool "Capability restrictions"
61659+ default y if GRKERNSEC_CONFIG_AUTO
61660+ depends on GRKERNSEC_CHROOT
61661+ help
61662+ If you say Y here, the capabilities on all processes within a
61663+ chroot jail will be lowered to stop module insertion, raw i/o,
61664+ system and net admin tasks, rebooting the system, modifying immutable
61665+ files, modifying IPC owned by another, and changing the system time.
61666+ This is left an option because it can break some apps. Disable this
61667+ if your chrooted apps are having problems performing those kinds of
61668+ tasks. If the sysctl option is enabled, a sysctl option with
61669+ name "chroot_caps" is created.
61670+
61671+config GRKERNSEC_CHROOT_INITRD
61672+ bool "Exempt initrd tasks from restrictions"
61673+ default y if GRKERNSEC_CONFIG_AUTO
61674+ depends on GRKERNSEC_CHROOT && BLK_DEV_RAM
61675+ help
61676+ If you say Y here, tasks started prior to init will be exempted from
61677+ grsecurity's chroot restrictions. This option is mainly meant to
61678+ resolve Plymouth's performing privileged operations unnecessarily
61679+ in a chroot.
61680+
61681+endmenu
61682+menu "Kernel Auditing"
61683+depends on GRKERNSEC
61684+
61685+config GRKERNSEC_AUDIT_GROUP
61686+ bool "Single group for auditing"
61687+ help
61688+ If you say Y here, the exec and chdir logging features will only operate
61689+ on a group you specify. This option is recommended if you only want to
61690+ watch certain users instead of having a large amount of logs from the
61691+ entire system. If the sysctl option is enabled, a sysctl option with
61692+ name "audit_group" is created.
61693+
61694+config GRKERNSEC_AUDIT_GID
61695+ int "GID for auditing"
61696+ depends on GRKERNSEC_AUDIT_GROUP
61697+ default 1007
61698+
61699+config GRKERNSEC_EXECLOG
61700+ bool "Exec logging"
61701+ help
61702+ If you say Y here, all execve() calls will be logged (since the
61703+ other exec*() calls are frontends to execve(), all execution
61704+ will be logged). Useful for shell-servers that like to keep track
61705+ of their users. If the sysctl option is enabled, a sysctl option with
61706+ name "exec_logging" is created.
61707+ WARNING: This option when enabled will produce a LOT of logs, especially
61708+ on an active system.
61709+
61710+config GRKERNSEC_RESLOG
61711+ bool "Resource logging"
61712+ default y if GRKERNSEC_CONFIG_AUTO
61713+ help
61714+ If you say Y here, all attempts to overstep resource limits will
61715+ be logged with the resource name, the requested size, and the current
61716+ limit. It is highly recommended that you say Y here. If the sysctl
61717+ option is enabled, a sysctl option with name "resource_logging" is
61718+ created. If the RBAC system is enabled, the sysctl value is ignored.
61719+
61720+config GRKERNSEC_CHROOT_EXECLOG
61721+ bool "Log execs within chroot"
61722+ help
61723+ If you say Y here, all executions inside a chroot jail will be logged
61724+ to syslog. This can cause a large amount of logs if certain
61725+ applications (eg. djb's daemontools) are installed on the system, and
61726+ is therefore left as an option. If the sysctl option is enabled, a
61727+ sysctl option with name "chroot_execlog" is created.
61728+
61729+config GRKERNSEC_AUDIT_PTRACE
61730+ bool "Ptrace logging"
61731+ help
61732+ If you say Y here, all attempts to attach to a process via ptrace
61733+ will be logged. If the sysctl option is enabled, a sysctl option
61734+ with name "audit_ptrace" is created.
61735+
61736+config GRKERNSEC_AUDIT_CHDIR
61737+ bool "Chdir logging"
61738+ help
61739+ If you say Y here, all chdir() calls will be logged. If the sysctl
61740+ option is enabled, a sysctl option with name "audit_chdir" is created.
61741+
61742+config GRKERNSEC_AUDIT_MOUNT
61743+ bool "(Un)Mount logging"
61744+ help
61745+ If you say Y here, all mounts and unmounts will be logged. If the
61746+ sysctl option is enabled, a sysctl option with name "audit_mount" is
61747+ created.
61748+
61749+config GRKERNSEC_SIGNAL
61750+ bool "Signal logging"
61751+ default y if GRKERNSEC_CONFIG_AUTO
61752+ help
61753+ If you say Y here, certain important signals will be logged, such as
61754+ SIGSEGV, which will as a result inform you of when a error in a program
61755+ occurred, which in some cases could mean a possible exploit attempt.
61756+ If the sysctl option is enabled, a sysctl option with name
61757+ "signal_logging" is created.
61758+
61759+config GRKERNSEC_FORKFAIL
61760+ bool "Fork failure logging"
61761+ help
61762+ If you say Y here, all failed fork() attempts will be logged.
61763+ This could suggest a fork bomb, or someone attempting to overstep
61764+ their process limit. If the sysctl option is enabled, a sysctl option
61765+ with name "forkfail_logging" is created.
61766+
61767+config GRKERNSEC_TIME
61768+ bool "Time change logging"
61769+ default y if GRKERNSEC_CONFIG_AUTO
61770+ help
61771+ If you say Y here, any changes of the system clock will be logged.
61772+ If the sysctl option is enabled, a sysctl option with name
61773+ "timechange_logging" is created.
61774+
61775+config GRKERNSEC_PROC_IPADDR
61776+ bool "/proc/<pid>/ipaddr support"
61777+ default y if GRKERNSEC_CONFIG_AUTO
61778+ help
61779+ If you say Y here, a new entry will be added to each /proc/<pid>
61780+ directory that contains the IP address of the person using the task.
61781+ The IP is carried across local TCP and AF_UNIX stream sockets.
61782+ This information can be useful for IDS/IPSes to perform remote response
61783+ to a local attack. The entry is readable by only the owner of the
61784+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
61785+ the RBAC system), and thus does not create privacy concerns.
61786+
61787+config GRKERNSEC_RWXMAP_LOG
61788+ bool 'Denied RWX mmap/mprotect logging'
61789+ default y if GRKERNSEC_CONFIG_AUTO
61790+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
61791+ help
61792+ If you say Y here, calls to mmap() and mprotect() with explicit
61793+ usage of PROT_WRITE and PROT_EXEC together will be logged when
61794+ denied by the PAX_MPROTECT feature. This feature will also
61795+ log other problematic scenarios that can occur when PAX_MPROTECT
61796+ is enabled on a binary, like textrels and PT_GNU_STACK. If the
61797+ sysctl option is enabled, a sysctl option with name "rwxmap_logging"
61798+ is created.
61799+
61800+endmenu
61801+
61802+menu "Executable Protections"
61803+depends on GRKERNSEC
61804+
61805+config GRKERNSEC_DMESG
61806+ bool "Dmesg(8) restriction"
61807+ default y if GRKERNSEC_CONFIG_AUTO
61808+ help
61809+ If you say Y here, non-root users will not be able to use dmesg(8)
61810+ to view the contents of the kernel's circular log buffer.
61811+ The kernel's log buffer often contains kernel addresses and other
61812+ identifying information useful to an attacker in fingerprinting a
61813+ system for a targeted exploit.
61814+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
61815+ created.
61816+
61817+config GRKERNSEC_HARDEN_PTRACE
61818+ bool "Deter ptrace-based process snooping"
61819+ default y if GRKERNSEC_CONFIG_AUTO
61820+ help
61821+ If you say Y here, TTY sniffers and other malicious monitoring
61822+ programs implemented through ptrace will be defeated. If you
61823+ have been using the RBAC system, this option has already been
61824+ enabled for several years for all users, with the ability to make
61825+ fine-grained exceptions.
61826+
61827+ This option only affects the ability of non-root users to ptrace
61828+ processes that are not a descendent of the ptracing process.
61829+ This means that strace ./binary and gdb ./binary will still work,
61830+ but attaching to arbitrary processes will not. If the sysctl
61831+ option is enabled, a sysctl option with name "harden_ptrace" is
61832+ created.
61833+
61834+config GRKERNSEC_PTRACE_READEXEC
61835+ bool "Require read access to ptrace sensitive binaries"
61836+ default y if GRKERNSEC_CONFIG_AUTO
61837+ help
61838+ If you say Y here, unprivileged users will not be able to ptrace unreadable
61839+ binaries. This option is useful in environments that
61840+ remove the read bits (e.g. file mode 4711) from suid binaries to
61841+ prevent infoleaking of their contents. This option adds
61842+ consistency to the use of that file mode, as the binary could normally
61843+ be read out when run without privileges while ptracing.
61844+
61845+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
61846+ is created.
61847+
61848+config GRKERNSEC_SETXID
61849+ bool "Enforce consistent multithreaded privileges"
61850+ default y if GRKERNSEC_CONFIG_AUTO
61851+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
61852+ help
61853+ If you say Y here, a change from a root uid to a non-root uid
61854+ in a multithreaded application will cause the resulting uids,
61855+ gids, supplementary groups, and capabilities in that thread
61856+ to be propagated to the other threads of the process. In most
61857+ cases this is unnecessary, as glibc will emulate this behavior
61858+ on behalf of the application. Other libcs do not act in the
61859+ same way, allowing the other threads of the process to continue
61860+ running with root privileges. If the sysctl option is enabled,
61861+ a sysctl option with name "consistent_setxid" is created.
61862+
61863+config GRKERNSEC_TPE
61864+ bool "Trusted Path Execution (TPE)"
61865+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
61866+ help
61867+ If you say Y here, you will be able to choose a gid to add to the
61868+ supplementary groups of users you want to mark as "untrusted."
61869+ These users will not be able to execute any files that are not in
61870+ root-owned directories writable only by root. If the sysctl option
61871+ is enabled, a sysctl option with name "tpe" is created.
61872+
61873+config GRKERNSEC_TPE_ALL
61874+ bool "Partially restrict all non-root users"
61875+ depends on GRKERNSEC_TPE
61876+ help
61877+ If you say Y here, all non-root users will be covered under
61878+ a weaker TPE restriction. This is separate from, and in addition to,
61879+ the main TPE options that you have selected elsewhere. Thus, if a
61880+ "trusted" GID is chosen, this restriction applies to even that GID.
61881+ Under this restriction, all non-root users will only be allowed to
61882+ execute files in directories they own that are not group or
61883+ world-writable, or in directories owned by root and writable only by
61884+ root. If the sysctl option is enabled, a sysctl option with name
61885+ "tpe_restrict_all" is created.
61886+
61887+config GRKERNSEC_TPE_INVERT
61888+ bool "Invert GID option"
61889+ depends on GRKERNSEC_TPE
61890+ help
61891+ If you say Y here, the group you specify in the TPE configuration will
61892+ decide what group TPE restrictions will be *disabled* for. This
61893+ option is useful if you want TPE restrictions to be applied to most
61894+ users on the system. If the sysctl option is enabled, a sysctl option
61895+ with name "tpe_invert" is created. Unlike other sysctl options, this
61896+ entry will default to on for backward-compatibility.
61897+
61898+config GRKERNSEC_TPE_GID
61899+ int
61900+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
61901+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
61902+
61903+config GRKERNSEC_TPE_UNTRUSTED_GID
61904+ int "GID for TPE-untrusted users"
61905+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
61906+ default 1005
61907+ help
61908+ Setting this GID determines what group TPE restrictions will be
61909+ *enabled* for. If the sysctl option is enabled, a sysctl option
61910+ with name "tpe_gid" is created.
61911+
61912+config GRKERNSEC_TPE_TRUSTED_GID
61913+ int "GID for TPE-trusted users"
61914+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
61915+ default 1005
61916+ help
61917+ Setting this GID determines what group TPE restrictions will be
61918+ *disabled* for. If the sysctl option is enabled, a sysctl option
61919+ with name "tpe_gid" is created.
61920+
61921+endmenu
61922+menu "Network Protections"
61923+depends on GRKERNSEC
61924+
61925+config GRKERNSEC_RANDNET
61926+ bool "Larger entropy pools"
61927+ default y if GRKERNSEC_CONFIG_AUTO
61928+ help
61929+ If you say Y here, the entropy pools used for many features of Linux
61930+ and grsecurity will be doubled in size. Since several grsecurity
61931+ features use additional randomness, it is recommended that you say Y
61932+ here. Saying Y here has a similar effect as modifying
61933+ /proc/sys/kernel/random/poolsize.
61934+
61935+config GRKERNSEC_BLACKHOLE
61936+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
61937+ default y if GRKERNSEC_CONFIG_AUTO
61938+ depends on NET
61939+ help
61940+ If you say Y here, neither TCP resets nor ICMP
61941+ destination-unreachable packets will be sent in response to packets
61942+ sent to ports for which no associated listening process exists.
61943+ This feature supports both IPV4 and IPV6 and exempts the
61944+ loopback interface from blackholing. Enabling this feature
61945+ makes a host more resilient to DoS attacks and reduces network
61946+ visibility against scanners.
61947+
61948+ The blackhole feature as-implemented is equivalent to the FreeBSD
61949+ blackhole feature, as it prevents RST responses to all packets, not
61950+ just SYNs. Under most application behavior this causes no
61951+ problems, but applications (like haproxy) may not close certain
61952+ connections in a way that cleanly terminates them on the remote
61953+ end, leaving the remote host in LAST_ACK state. Because of this
61954+ side-effect and to prevent intentional LAST_ACK DoSes, this
61955+ feature also adds automatic mitigation against such attacks.
61956+ The mitigation drastically reduces the amount of time a socket
61957+ can spend in LAST_ACK state. If you're using haproxy and not
61958+ all servers it connects to have this option enabled, consider
61959+ disabling this feature on the haproxy host.
61960+
61961+ If the sysctl option is enabled, two sysctl options with names
61962+ "ip_blackhole" and "lastack_retries" will be created.
61963+ While "ip_blackhole" takes the standard zero/non-zero on/off
61964+ toggle, "lastack_retries" uses the same kinds of values as
61965+ "tcp_retries1" and "tcp_retries2". The default value of 4
61966+ prevents a socket from lasting more than 45 seconds in LAST_ACK
61967+ state.
61968+
61969+config GRKERNSEC_NO_SIMULT_CONNECT
61970+ bool "Disable TCP Simultaneous Connect"
61971+ default y if GRKERNSEC_CONFIG_AUTO
61972+ depends on NET
61973+ help
61974+ If you say Y here, a feature by Willy Tarreau will be enabled that
61975+ removes a weakness in Linux's strict implementation of TCP that
61976+ allows two clients to connect to each other without either entering
61977+ a listening state. The weakness allows an attacker to easily prevent
61978+ a client from connecting to a known server provided the source port
61979+ for the connection is guessed correctly.
61980+
61981+ As the weakness could be used to prevent an antivirus or IPS from
61982+ fetching updates, or prevent an SSL gateway from fetching a CRL,
61983+ it should be eliminated by enabling this option. Though Linux is
61984+ one of few operating systems supporting simultaneous connect, it
61985+ has no legitimate use in practice and is rarely supported by firewalls.
61986+
61987+config GRKERNSEC_SOCKET
61988+ bool "Socket restrictions"
61989+ depends on NET
61990+ help
61991+ If you say Y here, you will be able to choose from several options.
61992+ If you assign a GID on your system and add it to the supplementary
61993+ groups of users you want to restrict socket access to, this patch
61994+ will perform up to three things, based on the option(s) you choose.
61995+
61996+config GRKERNSEC_SOCKET_ALL
61997+ bool "Deny any sockets to group"
61998+ depends on GRKERNSEC_SOCKET
61999+ help
62000+ If you say Y here, you will be able to choose a GID of whose users will
62001+ be unable to connect to other hosts from your machine or run server
62002+ applications from your machine. If the sysctl option is enabled, a
62003+ sysctl option with name "socket_all" is created.
62004+
62005+config GRKERNSEC_SOCKET_ALL_GID
62006+ int "GID to deny all sockets for"
62007+ depends on GRKERNSEC_SOCKET_ALL
62008+ default 1004
62009+ help
62010+ Here you can choose the GID to disable socket access for. Remember to
62011+ add the users you want socket access disabled for to the GID
62012+ specified here. If the sysctl option is enabled, a sysctl option
62013+ with name "socket_all_gid" is created.
62014+
62015+config GRKERNSEC_SOCKET_CLIENT
62016+ bool "Deny client sockets to group"
62017+ depends on GRKERNSEC_SOCKET
62018+ help
62019+ If you say Y here, you will be able to choose a GID of whose users will
62020+ be unable to connect to other hosts from your machine, but will be
62021+ able to run servers. If this option is enabled, all users in the group
62022+ you specify will have to use passive mode when initiating ftp transfers
62023+ from the shell on your machine. If the sysctl option is enabled, a
62024+ sysctl option with name "socket_client" is created.
62025+
62026+config GRKERNSEC_SOCKET_CLIENT_GID
62027+ int "GID to deny client sockets for"
62028+ depends on GRKERNSEC_SOCKET_CLIENT
62029+ default 1003
62030+ help
62031+ Here you can choose the GID to disable client socket access for.
62032+ Remember to add the users you want client socket access disabled for to
62033+ the GID specified here. If the sysctl option is enabled, a sysctl
62034+ option with name "socket_client_gid" is created.
62035+
62036+config GRKERNSEC_SOCKET_SERVER
62037+ bool "Deny server sockets to group"
62038+ depends on GRKERNSEC_SOCKET
62039+ help
62040+ If you say Y here, you will be able to choose a GID of whose users will
62041+ be unable to run server applications from your machine. If the sysctl
62042+ option is enabled, a sysctl option with name "socket_server" is created.
62043+
62044+config GRKERNSEC_SOCKET_SERVER_GID
62045+ int "GID to deny server sockets for"
62046+ depends on GRKERNSEC_SOCKET_SERVER
62047+ default 1002
62048+ help
62049+ Here you can choose the GID to disable server socket access for.
62050+ Remember to add the users you want server socket access disabled for to
62051+ the GID specified here. If the sysctl option is enabled, a sysctl
62052+ option with name "socket_server_gid" is created.
62053+
62054+endmenu
62055+
62056+menu "Physical Protections"
62057+depends on GRKERNSEC
62058+
62059+config GRKERNSEC_DENYUSB
62060+ bool "Deny new USB connections after toggle"
62061+ default y if GRKERNSEC_CONFIG_AUTO
62062+ depends on SYSCTL && USB_SUPPORT
62063+ help
62064+ If you say Y here, a new sysctl option with name "deny_new_usb"
62065+ will be created. Setting its value to 1 will prevent any new
62066+ USB devices from being recognized by the OS. Any attempted USB
62067+ device insertion will be logged. This option is intended to be
62068+ used against custom USB devices designed to exploit vulnerabilities
62069+ in various USB device drivers.
62070+
62071+ For greatest effectiveness, this sysctl should be set after any
62072+ relevant init scripts. This option is safe to enable in distros
62073+ as each user can choose whether or not to toggle the sysctl.
62074+
62075+config GRKERNSEC_DENYUSB_FORCE
62076+ bool "Reject all USB devices not connected at boot"
62077+ select USB
62078+ depends on GRKERNSEC_DENYUSB
62079+ help
62080+ If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
62081+ that doesn't involve a sysctl entry. This option should only be
62082+ enabled if you're sure you want to deny all new USB connections
62083+ at runtime and don't want to modify init scripts. This should not
62084+ be enabled by distros. It forces the core USB code to be built
62085+ into the kernel image so that all devices connected at boot time
62086+ can be recognized and new USB device connections can be prevented
62087+ prior to init running.
62088+
62089+endmenu
62090+
62091+menu "Sysctl Support"
62092+depends on GRKERNSEC && SYSCTL
62093+
62094+config GRKERNSEC_SYSCTL
62095+ bool "Sysctl support"
62096+ default y if GRKERNSEC_CONFIG_AUTO
62097+ help
62098+ If you say Y here, you will be able to change the options that
62099+ grsecurity runs with at bootup, without having to recompile your
62100+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
62101+ to enable (1) or disable (0) various features. All the sysctl entries
62102+ are mutable until the "grsec_lock" entry is set to a non-zero value.
62103+ All features enabled in the kernel configuration are disabled at boot
62104+ if you do not say Y to the "Turn on features by default" option.
62105+ All options should be set at startup, and the grsec_lock entry should
62106+ be set to a non-zero value after all the options are set.
62107+ *THIS IS EXTREMELY IMPORTANT*
62108+
62109+config GRKERNSEC_SYSCTL_DISTRO
62110+ bool "Extra sysctl support for distro makers (READ HELP)"
62111+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
62112+ help
62113+ If you say Y here, additional sysctl options will be created
62114+ for features that affect processes running as root. Therefore,
62115+ it is critical when using this option that the grsec_lock entry be
62116+ enabled after boot. Only distros with prebuilt kernel packages
62117+ with this option enabled that can ensure grsec_lock is enabled
62118+ after boot should use this option.
62119+ *Failure to set grsec_lock after boot makes all grsec features
62120+ this option covers useless*
62121+
62122+ Currently this option creates the following sysctl entries:
62123+ "Disable Privileged I/O": "disable_priv_io"
62124+
62125+config GRKERNSEC_SYSCTL_ON
62126+ bool "Turn on features by default"
62127+ default y if GRKERNSEC_CONFIG_AUTO
62128+ depends on GRKERNSEC_SYSCTL
62129+ help
62130+ If you say Y here, instead of having all features enabled in the
62131+ kernel configuration disabled at boot time, the features will be
62132+ enabled at boot time. It is recommended you say Y here unless
62133+ there is some reason you would want all sysctl-tunable features to
62134+ be disabled by default. As mentioned elsewhere, it is important
62135+ to enable the grsec_lock entry once you have finished modifying
62136+ the sysctl entries.
62137+
62138+endmenu
62139+menu "Logging Options"
62140+depends on GRKERNSEC
62141+
62142+config GRKERNSEC_FLOODTIME
62143+ int "Seconds in between log messages (minimum)"
62144+ default 10
62145+ help
62146+ This option allows you to enforce the number of seconds between
62147+ grsecurity log messages. The default should be suitable for most
62148+ people, however, if you choose to change it, choose a value small enough
62149+ to allow informative logs to be produced, but large enough to
62150+ prevent flooding.
62151+
62152+config GRKERNSEC_FLOODBURST
62153+ int "Number of messages in a burst (maximum)"
62154+ default 6
62155+ help
62156+ This option allows you to choose the maximum number of messages allowed
62157+ within the flood time interval you chose in a separate option. The
62158+ default should be suitable for most people, however if you find that
62159+ many of your logs are being interpreted as flooding, you may want to
62160+ raise this value.
62161+
62162+endmenu
62163diff --git a/grsecurity/Makefile b/grsecurity/Makefile
62164new file mode 100644
62165index 0000000..b0b77d5
62166--- /dev/null
62167+++ b/grsecurity/Makefile
62168@@ -0,0 +1,43 @@
62169+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
62170+# during 2001-2009 it has been completely redesigned by Brad Spengler
62171+# into an RBAC system
62172+#
62173+# All code in this directory and various hooks inserted throughout the kernel
62174+# are copyright Brad Spengler - Open Source Security, Inc., and released
62175+# under the GPL v2 or higher
62176+
62177+KBUILD_CFLAGS += -Werror
62178+
62179+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
62180+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
62181+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
62182+ grsec_usb.o
62183+
62184+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
62185+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
62186+ gracl_learn.o grsec_log.o
62187+ifdef CONFIG_COMPAT
62188+obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
62189+endif
62190+
62191+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
62192+
62193+ifdef CONFIG_NET
62194+obj-y += grsec_sock.o
62195+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
62196+endif
62197+
62198+ifndef CONFIG_GRKERNSEC
62199+obj-y += grsec_disabled.o
62200+endif
62201+
62202+ifdef CONFIG_GRKERNSEC_HIDESYM
62203+extra-y := grsec_hidesym.o
62204+$(obj)/grsec_hidesym.o:
62205+ @-chmod -f 500 /boot
62206+ @-chmod -f 500 /lib/modules
62207+ @-chmod -f 500 /lib64/modules
62208+ @-chmod -f 500 /lib32/modules
62209+ @-chmod -f 700 .
62210+ @echo ' grsec: protected kernel image paths'
62211+endif
62212diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
62213new file mode 100644
62214index 0000000..c0793fd
62215--- /dev/null
62216+++ b/grsecurity/gracl.c
62217@@ -0,0 +1,4178 @@
62218+#include <linux/kernel.h>
62219+#include <linux/module.h>
62220+#include <linux/sched.h>
62221+#include <linux/mm.h>
62222+#include <linux/file.h>
62223+#include <linux/fs.h>
62224+#include <linux/namei.h>
62225+#include <linux/mount.h>
62226+#include <linux/tty.h>
62227+#include <linux/proc_fs.h>
62228+#include <linux/lglock.h>
62229+#include <linux/slab.h>
62230+#include <linux/vmalloc.h>
62231+#include <linux/types.h>
62232+#include <linux/sysctl.h>
62233+#include <linux/netdevice.h>
62234+#include <linux/ptrace.h>
62235+#include <linux/gracl.h>
62236+#include <linux/gralloc.h>
62237+#include <linux/security.h>
62238+#include <linux/grinternal.h>
62239+#include <linux/pid_namespace.h>
62240+#include <linux/stop_machine.h>
62241+#include <linux/fdtable.h>
62242+#include <linux/percpu.h>
62243+#include <linux/lglock.h>
62244+#include <linux/hugetlb.h>
62245+#include <linux/posix-timers.h>
62246+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
62247+#include <linux/magic.h>
62248+#include <linux/pagemap.h>
62249+#include "../fs/btrfs/async-thread.h"
62250+#include "../fs/btrfs/ctree.h"
62251+#include "../fs/btrfs/btrfs_inode.h"
62252+#endif
62253+#include "../fs/mount.h"
62254+
62255+#include <asm/uaccess.h>
62256+#include <asm/errno.h>
62257+#include <asm/mman.h>
62258+
62259+extern struct lglock vfsmount_lock;
62260+
62261+static struct acl_role_db acl_role_set;
62262+static struct name_db name_set;
62263+static struct inodev_db inodev_set;
62264+
62265+/* for keeping track of userspace pointers used for subjects, so we
62266+ can share references in the kernel as well
62267+*/
62268+
62269+static struct path real_root;
62270+
62271+static struct acl_subj_map_db subj_map_set;
62272+
62273+static struct acl_role_label *default_role;
62274+
62275+static struct acl_role_label *role_list;
62276+
62277+static u16 acl_sp_role_value;
62278+
62279+extern char *gr_shared_page[4];
62280+static DEFINE_MUTEX(gr_dev_mutex);
62281+DEFINE_RWLOCK(gr_inode_lock);
62282+
62283+struct gr_arg *gr_usermode;
62284+
62285+static unsigned int gr_status __read_only = GR_STATUS_INIT;
62286+
62287+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
62288+extern void gr_clear_learn_entries(void);
62289+
62290+unsigned char *gr_system_salt;
62291+unsigned char *gr_system_sum;
62292+
62293+static struct sprole_pw **acl_special_roles = NULL;
62294+static __u16 num_sprole_pws = 0;
62295+
62296+static struct acl_role_label *kernel_role = NULL;
62297+
62298+static unsigned int gr_auth_attempts = 0;
62299+static unsigned long gr_auth_expires = 0UL;
62300+
62301+#ifdef CONFIG_NET
62302+extern struct vfsmount *sock_mnt;
62303+#endif
62304+
62305+extern struct vfsmount *pipe_mnt;
62306+extern struct vfsmount *shm_mnt;
62307+
62308+#ifdef CONFIG_HUGETLBFS
62309+extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
62310+#endif
62311+
62312+static struct acl_object_label *fakefs_obj_rw;
62313+static struct acl_object_label *fakefs_obj_rwx;
62314+
62315+extern int gr_init_uidset(void);
62316+extern void gr_free_uidset(void);
62317+extern void gr_remove_uid(uid_t uid);
62318+extern int gr_find_uid(uid_t uid);
62319+
62320+static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
62321+{
62322+ if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
62323+ return -EFAULT;
62324+
62325+ return 0;
62326+}
62327+
62328+static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
62329+{
62330+ if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
62331+ return -EFAULT;
62332+
62333+ return 0;
62334+}
62335+
62336+static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
62337+{
62338+ if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
62339+ return -EFAULT;
62340+
62341+ return 0;
62342+}
62343+
62344+static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
62345+{
62346+ if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
62347+ return -EFAULT;
62348+
62349+ return 0;
62350+}
62351+
62352+static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
62353+{
62354+ if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
62355+ return -EFAULT;
62356+
62357+ return 0;
62358+}
62359+
62360+static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
62361+{
62362+ if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
62363+ return -EFAULT;
62364+
62365+ return 0;
62366+}
62367+
62368+static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
62369+{
62370+ if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
62371+ return -EFAULT;
62372+
62373+ return 0;
62374+}
62375+
62376+static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
62377+{
62378+ if (copy_from_user(trans, userp, sizeof(struct role_transition)))
62379+ return -EFAULT;
62380+
62381+ return 0;
62382+}
62383+
62384+int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
62385+{
62386+ if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
62387+ return -EFAULT;
62388+
62389+ return 0;
62390+}
62391+
62392+static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
62393+{
62394+ if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
62395+ return -EFAULT;
62396+
62397+ if ((uwrap->version != GRSECURITY_VERSION) || (uwrap->size != sizeof(struct gr_arg)))
62398+ return -EINVAL;
62399+
62400+ return 0;
62401+}
62402+
62403+static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
62404+{
62405+ if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
62406+ return -EFAULT;
62407+
62408+ return 0;
62409+}
62410+
62411+static size_t get_gr_arg_wrapper_size_normal(void)
62412+{
62413+ return sizeof(struct gr_arg_wrapper);
62414+}
62415+
62416+#ifdef CONFIG_COMPAT
62417+extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
62418+extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
62419+extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
62420+extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
62421+extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
62422+extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
62423+extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
62424+extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
62425+extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
62426+extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
62427+extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
62428+extern size_t get_gr_arg_wrapper_size_compat(void);
62429+
62430+int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
62431+int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
62432+int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
62433+int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
62434+int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
62435+int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
62436+int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
62437+int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
62438+int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
62439+int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
62440+int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
62441+size_t (* get_gr_arg_wrapper_size)(void) __read_only;
62442+
62443+#else
62444+#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
62445+#define copy_gr_arg copy_gr_arg_normal
62446+#define copy_gr_hash_struct copy_gr_hash_struct_normal
62447+#define copy_acl_object_label copy_acl_object_label_normal
62448+#define copy_acl_subject_label copy_acl_subject_label_normal
62449+#define copy_acl_role_label copy_acl_role_label_normal
62450+#define copy_acl_ip_label copy_acl_ip_label_normal
62451+#define copy_pointer_from_array copy_pointer_from_array_normal
62452+#define copy_sprole_pw copy_sprole_pw_normal
62453+#define copy_role_transition copy_role_transition_normal
62454+#define copy_role_allowed_ip copy_role_allowed_ip_normal
62455+#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
62456+#endif
62457+
62458+__inline__ int
62459+gr_acl_is_enabled(void)
62460+{
62461+ return (gr_status & GR_READY);
62462+}
62463+
62464+static inline dev_t __get_dev(const struct dentry *dentry)
62465+{
62466+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
62467+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
62468+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
62469+ else
62470+#endif
62471+ return dentry->d_sb->s_dev;
62472+}
62473+
62474+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
62475+{
62476+ return __get_dev(dentry);
62477+}
62478+
62479+static char gr_task_roletype_to_char(struct task_struct *task)
62480+{
62481+ switch (task->role->roletype &
62482+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
62483+ GR_ROLE_SPECIAL)) {
62484+ case GR_ROLE_DEFAULT:
62485+ return 'D';
62486+ case GR_ROLE_USER:
62487+ return 'U';
62488+ case GR_ROLE_GROUP:
62489+ return 'G';
62490+ case GR_ROLE_SPECIAL:
62491+ return 'S';
62492+ }
62493+
62494+ return 'X';
62495+}
62496+
62497+char gr_roletype_to_char(void)
62498+{
62499+ return gr_task_roletype_to_char(current);
62500+}
62501+
62502+__inline__ int
62503+gr_acl_tpe_check(void)
62504+{
62505+ if (unlikely(!(gr_status & GR_READY)))
62506+ return 0;
62507+ if (current->role->roletype & GR_ROLE_TPE)
62508+ return 1;
62509+ else
62510+ return 0;
62511+}
62512+
62513+int
62514+gr_handle_rawio(const struct inode *inode)
62515+{
62516+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
62517+ if (inode && S_ISBLK(inode->i_mode) &&
62518+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
62519+ !capable(CAP_SYS_RAWIO))
62520+ return 1;
62521+#endif
62522+ return 0;
62523+}
62524+
62525+static int
62526+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
62527+{
62528+ if (likely(lena != lenb))
62529+ return 0;
62530+
62531+ return !memcmp(a, b, lena);
62532+}
62533+
62534+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
62535+{
62536+ *buflen -= namelen;
62537+ if (*buflen < 0)
62538+ return -ENAMETOOLONG;
62539+ *buffer -= namelen;
62540+ memcpy(*buffer, str, namelen);
62541+ return 0;
62542+}
62543+
62544+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
62545+{
62546+ return prepend(buffer, buflen, name->name, name->len);
62547+}
62548+
62549+static int prepend_path(const struct path *path, struct path *root,
62550+ char **buffer, int *buflen)
62551+{
62552+ struct dentry *dentry = path->dentry;
62553+ struct vfsmount *vfsmnt = path->mnt;
62554+ struct mount *mnt = real_mount(vfsmnt);
62555+ bool slash = false;
62556+ int error = 0;
62557+
62558+ while (dentry != root->dentry || vfsmnt != root->mnt) {
62559+ struct dentry * parent;
62560+
62561+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
62562+ /* Global root? */
62563+ if (!mnt_has_parent(mnt)) {
62564+ goto out;
62565+ }
62566+ dentry = mnt->mnt_mountpoint;
62567+ mnt = mnt->mnt_parent;
62568+ vfsmnt = &mnt->mnt;
62569+ continue;
62570+ }
62571+ parent = dentry->d_parent;
62572+ prefetch(parent);
62573+ spin_lock(&dentry->d_lock);
62574+ error = prepend_name(buffer, buflen, &dentry->d_name);
62575+ spin_unlock(&dentry->d_lock);
62576+ if (!error)
62577+ error = prepend(buffer, buflen, "/", 1);
62578+ if (error)
62579+ break;
62580+
62581+ slash = true;
62582+ dentry = parent;
62583+ }
62584+
62585+out:
62586+ if (!error && !slash)
62587+ error = prepend(buffer, buflen, "/", 1);
62588+
62589+ return error;
62590+}
62591+
62592+/* this must be called with vfsmount_lock and rename_lock held */
62593+
62594+static char *__our_d_path(const struct path *path, struct path *root,
62595+ char *buf, int buflen)
62596+{
62597+ char *res = buf + buflen;
62598+ int error;
62599+
62600+ prepend(&res, &buflen, "\0", 1);
62601+ error = prepend_path(path, root, &res, &buflen);
62602+ if (error)
62603+ return ERR_PTR(error);
62604+
62605+ return res;
62606+}
62607+
62608+static char *
62609+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
62610+{
62611+ char *retval;
62612+
62613+ retval = __our_d_path(path, root, buf, buflen);
62614+ if (unlikely(IS_ERR(retval)))
62615+ retval = strcpy(buf, "<path too long>");
62616+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
62617+ retval[1] = '\0';
62618+
62619+ return retval;
62620+}
62621+
62622+static char *
62623+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
62624+ char *buf, int buflen)
62625+{
62626+ struct path path;
62627+ char *res;
62628+
62629+ path.dentry = (struct dentry *)dentry;
62630+ path.mnt = (struct vfsmount *)vfsmnt;
62631+
62632+ /* we can use real_root.dentry, real_root.mnt, because this is only called
62633+ by the RBAC system */
62634+ res = gen_full_path(&path, &real_root, buf, buflen);
62635+
62636+ return res;
62637+}
62638+
62639+static char *
62640+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
62641+ char *buf, int buflen)
62642+{
62643+ char *res;
62644+ struct path path;
62645+ struct path root;
62646+ struct task_struct *reaper = init_pid_ns.child_reaper;
62647+
62648+ path.dentry = (struct dentry *)dentry;
62649+ path.mnt = (struct vfsmount *)vfsmnt;
62650+
62651+ /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
62652+ get_fs_root(reaper->fs, &root);
62653+
62654+ br_read_lock(&vfsmount_lock);
62655+ write_seqlock(&rename_lock);
62656+ res = gen_full_path(&path, &root, buf, buflen);
62657+ write_sequnlock(&rename_lock);
62658+ br_read_unlock(&vfsmount_lock);
62659+
62660+ path_put(&root);
62661+ return res;
62662+}
62663+
62664+static char *
62665+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
62666+{
62667+ char *ret;
62668+ br_read_lock(&vfsmount_lock);
62669+ write_seqlock(&rename_lock);
62670+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
62671+ PAGE_SIZE);
62672+ write_sequnlock(&rename_lock);
62673+ br_read_unlock(&vfsmount_lock);
62674+ return ret;
62675+}
62676+
62677+static char *
62678+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
62679+{
62680+ char *ret;
62681+ char *buf;
62682+ int buflen;
62683+
62684+ br_read_lock(&vfsmount_lock);
62685+ write_seqlock(&rename_lock);
62686+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
62687+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
62688+ buflen = (int)(ret - buf);
62689+ if (buflen >= 5)
62690+ prepend(&ret, &buflen, "/proc", 5);
62691+ else
62692+ ret = strcpy(buf, "<path too long>");
62693+ write_sequnlock(&rename_lock);
62694+ br_read_unlock(&vfsmount_lock);
62695+ return ret;
62696+}
62697+
62698+char *
62699+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
62700+{
62701+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
62702+ PAGE_SIZE);
62703+}
62704+
62705+char *
62706+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
62707+{
62708+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
62709+ PAGE_SIZE);
62710+}
62711+
62712+char *
62713+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
62714+{
62715+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
62716+ PAGE_SIZE);
62717+}
62718+
62719+char *
62720+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
62721+{
62722+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
62723+ PAGE_SIZE);
62724+}
62725+
62726+char *
62727+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
62728+{
62729+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
62730+ PAGE_SIZE);
62731+}
62732+
62733+__inline__ __u32
62734+to_gr_audit(const __u32 reqmode)
62735+{
62736+ /* masks off auditable permission flags, then shifts them to create
62737+ auditing flags, and adds the special case of append auditing if
62738+ we're requesting write */
62739+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
62740+}
62741+
62742+struct acl_subject_label *
62743+lookup_subject_map(const struct acl_subject_label *userp)
62744+{
62745+ unsigned int index = gr_shash(userp, subj_map_set.s_size);
62746+ struct subject_map *match;
62747+
62748+ match = subj_map_set.s_hash[index];
62749+
62750+ while (match && match->user != userp)
62751+ match = match->next;
62752+
62753+ if (match != NULL)
62754+ return match->kernel;
62755+ else
62756+ return NULL;
62757+}
62758+
62759+static void
62760+insert_subj_map_entry(struct subject_map *subjmap)
62761+{
62762+ unsigned int index = gr_shash(subjmap->user, subj_map_set.s_size);
62763+ struct subject_map **curr;
62764+
62765+ subjmap->prev = NULL;
62766+
62767+ curr = &subj_map_set.s_hash[index];
62768+ if (*curr != NULL)
62769+ (*curr)->prev = subjmap;
62770+
62771+ subjmap->next = *curr;
62772+ *curr = subjmap;
62773+
62774+ return;
62775+}
62776+
62777+static struct acl_role_label *
62778+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
62779+ const gid_t gid)
62780+{
62781+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
62782+ struct acl_role_label *match;
62783+ struct role_allowed_ip *ipp;
62784+ unsigned int x;
62785+ u32 curr_ip = task->signal->curr_ip;
62786+
62787+ task->signal->saved_ip = curr_ip;
62788+
62789+ match = acl_role_set.r_hash[index];
62790+
62791+ while (match) {
62792+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
62793+ for (x = 0; x < match->domain_child_num; x++) {
62794+ if (match->domain_children[x] == uid)
62795+ goto found;
62796+ }
62797+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
62798+ break;
62799+ match = match->next;
62800+ }
62801+found:
62802+ if (match == NULL) {
62803+ try_group:
62804+ index = gr_rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
62805+ match = acl_role_set.r_hash[index];
62806+
62807+ while (match) {
62808+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
62809+ for (x = 0; x < match->domain_child_num; x++) {
62810+ if (match->domain_children[x] == gid)
62811+ goto found2;
62812+ }
62813+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
62814+ break;
62815+ match = match->next;
62816+ }
62817+found2:
62818+ if (match == NULL)
62819+ match = default_role;
62820+ if (match->allowed_ips == NULL)
62821+ return match;
62822+ else {
62823+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
62824+ if (likely
62825+ ((ntohl(curr_ip) & ipp->netmask) ==
62826+ (ntohl(ipp->addr) & ipp->netmask)))
62827+ return match;
62828+ }
62829+ match = default_role;
62830+ }
62831+ } else if (match->allowed_ips == NULL) {
62832+ return match;
62833+ } else {
62834+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
62835+ if (likely
62836+ ((ntohl(curr_ip) & ipp->netmask) ==
62837+ (ntohl(ipp->addr) & ipp->netmask)))
62838+ return match;
62839+ }
62840+ goto try_group;
62841+ }
62842+
62843+ return match;
62844+}
62845+
62846+struct acl_subject_label *
62847+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
62848+ const struct acl_role_label *role)
62849+{
62850+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
62851+ struct acl_subject_label *match;
62852+
62853+ match = role->subj_hash[index];
62854+
62855+ while (match && (match->inode != ino || match->device != dev ||
62856+ (match->mode & GR_DELETED))) {
62857+ match = match->next;
62858+ }
62859+
62860+ if (match && !(match->mode & GR_DELETED))
62861+ return match;
62862+ else
62863+ return NULL;
62864+}
62865+
62866+struct acl_subject_label *
62867+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
62868+ const struct acl_role_label *role)
62869+{
62870+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
62871+ struct acl_subject_label *match;
62872+
62873+ match = role->subj_hash[index];
62874+
62875+ while (match && (match->inode != ino || match->device != dev ||
62876+ !(match->mode & GR_DELETED))) {
62877+ match = match->next;
62878+ }
62879+
62880+ if (match && (match->mode & GR_DELETED))
62881+ return match;
62882+ else
62883+ return NULL;
62884+}
62885+
62886+static struct acl_object_label *
62887+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
62888+ const struct acl_subject_label *subj)
62889+{
62890+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
62891+ struct acl_object_label *match;
62892+
62893+ match = subj->obj_hash[index];
62894+
62895+ while (match && (match->inode != ino || match->device != dev ||
62896+ (match->mode & GR_DELETED))) {
62897+ match = match->next;
62898+ }
62899+
62900+ if (match && !(match->mode & GR_DELETED))
62901+ return match;
62902+ else
62903+ return NULL;
62904+}
62905+
62906+static struct acl_object_label *
62907+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
62908+ const struct acl_subject_label *subj)
62909+{
62910+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
62911+ struct acl_object_label *match;
62912+
62913+ match = subj->obj_hash[index];
62914+
62915+ while (match && (match->inode != ino || match->device != dev ||
62916+ !(match->mode & GR_DELETED))) {
62917+ match = match->next;
62918+ }
62919+
62920+ if (match && (match->mode & GR_DELETED))
62921+ return match;
62922+
62923+ match = subj->obj_hash[index];
62924+
62925+ while (match && (match->inode != ino || match->device != dev ||
62926+ (match->mode & GR_DELETED))) {
62927+ match = match->next;
62928+ }
62929+
62930+ if (match && !(match->mode & GR_DELETED))
62931+ return match;
62932+ else
62933+ return NULL;
62934+}
62935+
62936+static struct name_entry *
62937+lookup_name_entry(const char *name)
62938+{
62939+ unsigned int len = strlen(name);
62940+ unsigned int key = full_name_hash(name, len);
62941+ unsigned int index = key % name_set.n_size;
62942+ struct name_entry *match;
62943+
62944+ match = name_set.n_hash[index];
62945+
62946+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
62947+ match = match->next;
62948+
62949+ return match;
62950+}
62951+
62952+static struct name_entry *
62953+lookup_name_entry_create(const char *name)
62954+{
62955+ unsigned int len = strlen(name);
62956+ unsigned int key = full_name_hash(name, len);
62957+ unsigned int index = key % name_set.n_size;
62958+ struct name_entry *match;
62959+
62960+ match = name_set.n_hash[index];
62961+
62962+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
62963+ !match->deleted))
62964+ match = match->next;
62965+
62966+ if (match && match->deleted)
62967+ return match;
62968+
62969+ match = name_set.n_hash[index];
62970+
62971+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
62972+ match->deleted))
62973+ match = match->next;
62974+
62975+ if (match && !match->deleted)
62976+ return match;
62977+ else
62978+ return NULL;
62979+}
62980+
62981+static struct inodev_entry *
62982+lookup_inodev_entry(const ino_t ino, const dev_t dev)
62983+{
62984+ unsigned int index = gr_fhash(ino, dev, inodev_set.i_size);
62985+ struct inodev_entry *match;
62986+
62987+ match = inodev_set.i_hash[index];
62988+
62989+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
62990+ match = match->next;
62991+
62992+ return match;
62993+}
62994+
62995+static void
62996+insert_inodev_entry(struct inodev_entry *entry)
62997+{
62998+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
62999+ inodev_set.i_size);
63000+ struct inodev_entry **curr;
63001+
63002+ entry->prev = NULL;
63003+
63004+ curr = &inodev_set.i_hash[index];
63005+ if (*curr != NULL)
63006+ (*curr)->prev = entry;
63007+
63008+ entry->next = *curr;
63009+ *curr = entry;
63010+
63011+ return;
63012+}
63013+
63014+static void
63015+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
63016+{
63017+ unsigned int index =
63018+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
63019+ struct acl_role_label **curr;
63020+ struct acl_role_label *tmp, *tmp2;
63021+
63022+ curr = &acl_role_set.r_hash[index];
63023+
63024+ /* simple case, slot is empty, just set it to our role */
63025+ if (*curr == NULL) {
63026+ *curr = role;
63027+ } else {
63028+ /* example:
63029+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
63030+ 2 -> 3
63031+ */
63032+ /* first check to see if we can already be reached via this slot */
63033+ tmp = *curr;
63034+ while (tmp && tmp != role)
63035+ tmp = tmp->next;
63036+ if (tmp == role) {
63037+ /* we don't need to add ourselves to this slot's chain */
63038+ return;
63039+ }
63040+ /* we need to add ourselves to this chain, two cases */
63041+ if (role->next == NULL) {
63042+ /* simple case, append the current chain to our role */
63043+ role->next = *curr;
63044+ *curr = role;
63045+ } else {
63046+ /* 1 -> 2 -> 3 -> 4
63047+ 2 -> 3 -> 4
63048+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
63049+ */
63050+ /* trickier case: walk our role's chain until we find
63051+ the role for the start of the current slot's chain */
63052+ tmp = role;
63053+ tmp2 = *curr;
63054+ while (tmp->next && tmp->next != tmp2)
63055+ tmp = tmp->next;
63056+ if (tmp->next == tmp2) {
63057+ /* from example above, we found 3, so just
63058+ replace this slot's chain with ours */
63059+ *curr = role;
63060+ } else {
63061+ /* we didn't find a subset of our role's chain
63062+ in the current slot's chain, so append their
63063+ chain to ours, and set us as the first role in
63064+ the slot's chain
63065+
63066+ we could fold this case with the case above,
63067+ but making it explicit for clarity
63068+ */
63069+ tmp->next = tmp2;
63070+ *curr = role;
63071+ }
63072+ }
63073+ }
63074+
63075+ return;
63076+}
63077+
63078+static void
63079+insert_acl_role_label(struct acl_role_label *role)
63080+{
63081+ int i;
63082+
63083+ if (role_list == NULL) {
63084+ role_list = role;
63085+ role->prev = NULL;
63086+ } else {
63087+ role->prev = role_list;
63088+ role_list = role;
63089+ }
63090+
63091+ /* used for hash chains */
63092+ role->next = NULL;
63093+
63094+ if (role->roletype & GR_ROLE_DOMAIN) {
63095+ for (i = 0; i < role->domain_child_num; i++)
63096+ __insert_acl_role_label(role, role->domain_children[i]);
63097+ } else
63098+ __insert_acl_role_label(role, role->uidgid);
63099+}
63100+
63101+static int
63102+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
63103+{
63104+ struct name_entry **curr, *nentry;
63105+ struct inodev_entry *ientry;
63106+ unsigned int len = strlen(name);
63107+ unsigned int key = full_name_hash(name, len);
63108+ unsigned int index = key % name_set.n_size;
63109+
63110+ curr = &name_set.n_hash[index];
63111+
63112+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
63113+ curr = &((*curr)->next);
63114+
63115+ if (*curr != NULL)
63116+ return 1;
63117+
63118+ nentry = acl_alloc(sizeof (struct name_entry));
63119+ if (nentry == NULL)
63120+ return 0;
63121+ ientry = acl_alloc(sizeof (struct inodev_entry));
63122+ if (ientry == NULL)
63123+ return 0;
63124+ ientry->nentry = nentry;
63125+
63126+ nentry->key = key;
63127+ nentry->name = name;
63128+ nentry->inode = inode;
63129+ nentry->device = device;
63130+ nentry->len = len;
63131+ nentry->deleted = deleted;
63132+
63133+ nentry->prev = NULL;
63134+ curr = &name_set.n_hash[index];
63135+ if (*curr != NULL)
63136+ (*curr)->prev = nentry;
63137+ nentry->next = *curr;
63138+ *curr = nentry;
63139+
63140+ /* insert us into the table searchable by inode/dev */
63141+ insert_inodev_entry(ientry);
63142+
63143+ return 1;
63144+}
63145+
63146+static void
63147+insert_acl_obj_label(struct acl_object_label *obj,
63148+ struct acl_subject_label *subj)
63149+{
63150+ unsigned int index =
63151+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
63152+ struct acl_object_label **curr;
63153+
63154+
63155+ obj->prev = NULL;
63156+
63157+ curr = &subj->obj_hash[index];
63158+ if (*curr != NULL)
63159+ (*curr)->prev = obj;
63160+
63161+ obj->next = *curr;
63162+ *curr = obj;
63163+
63164+ return;
63165+}
63166+
63167+static void
63168+insert_acl_subj_label(struct acl_subject_label *obj,
63169+ struct acl_role_label *role)
63170+{
63171+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
63172+ struct acl_subject_label **curr;
63173+
63174+ obj->prev = NULL;
63175+
63176+ curr = &role->subj_hash[index];
63177+ if (*curr != NULL)
63178+ (*curr)->prev = obj;
63179+
63180+ obj->next = *curr;
63181+ *curr = obj;
63182+
63183+ return;
63184+}
63185+
63186+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
63187+
63188+static void *
63189+create_table(__u32 * len, int elementsize)
63190+{
63191+ unsigned int table_sizes[] = {
63192+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
63193+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
63194+ 4194301, 8388593, 16777213, 33554393, 67108859
63195+ };
63196+ void *newtable = NULL;
63197+ unsigned int pwr = 0;
63198+
63199+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
63200+ table_sizes[pwr] <= *len)
63201+ pwr++;
63202+
63203+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
63204+ return newtable;
63205+
63206+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
63207+ newtable =
63208+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
63209+ else
63210+ newtable = vmalloc(table_sizes[pwr] * elementsize);
63211+
63212+ *len = table_sizes[pwr];
63213+
63214+ return newtable;
63215+}
63216+
63217+static int
63218+init_variables(const struct gr_arg *arg)
63219+{
63220+ struct task_struct *reaper = init_pid_ns.child_reaper;
63221+ unsigned int stacksize;
63222+
63223+ subj_map_set.s_size = arg->role_db.num_subjects;
63224+ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
63225+ name_set.n_size = arg->role_db.num_objects;
63226+ inodev_set.i_size = arg->role_db.num_objects;
63227+
63228+ if (!subj_map_set.s_size || !acl_role_set.r_size ||
63229+ !name_set.n_size || !inodev_set.i_size)
63230+ return 1;
63231+
63232+ if (!gr_init_uidset())
63233+ return 1;
63234+
63235+ /* set up the stack that holds allocation info */
63236+
63237+ stacksize = arg->role_db.num_pointers + 5;
63238+
63239+ if (!acl_alloc_stack_init(stacksize))
63240+ return 1;
63241+
63242+ /* grab reference for the real root dentry and vfsmount */
63243+ get_fs_root(reaper->fs, &real_root);
63244+
63245+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
63246+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
63247+#endif
63248+
63249+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
63250+ if (fakefs_obj_rw == NULL)
63251+ return 1;
63252+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
63253+
63254+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
63255+ if (fakefs_obj_rwx == NULL)
63256+ return 1;
63257+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
63258+
63259+ subj_map_set.s_hash =
63260+ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
63261+ acl_role_set.r_hash =
63262+ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
63263+ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
63264+ inodev_set.i_hash =
63265+ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
63266+
63267+ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
63268+ !name_set.n_hash || !inodev_set.i_hash)
63269+ return 1;
63270+
63271+ memset(subj_map_set.s_hash, 0,
63272+ sizeof(struct subject_map *) * subj_map_set.s_size);
63273+ memset(acl_role_set.r_hash, 0,
63274+ sizeof (struct acl_role_label *) * acl_role_set.r_size);
63275+ memset(name_set.n_hash, 0,
63276+ sizeof (struct name_entry *) * name_set.n_size);
63277+ memset(inodev_set.i_hash, 0,
63278+ sizeof (struct inodev_entry *) * inodev_set.i_size);
63279+
63280+ return 0;
63281+}
63282+
63283+/* free information not needed after startup
63284+ currently contains user->kernel pointer mappings for subjects
63285+*/
63286+
63287+static void
63288+free_init_variables(void)
63289+{
63290+ __u32 i;
63291+
63292+ if (subj_map_set.s_hash) {
63293+ for (i = 0; i < subj_map_set.s_size; i++) {
63294+ if (subj_map_set.s_hash[i]) {
63295+ kfree(subj_map_set.s_hash[i]);
63296+ subj_map_set.s_hash[i] = NULL;
63297+ }
63298+ }
63299+
63300+ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
63301+ PAGE_SIZE)
63302+ kfree(subj_map_set.s_hash);
63303+ else
63304+ vfree(subj_map_set.s_hash);
63305+ }
63306+
63307+ return;
63308+}
63309+
63310+static void
63311+free_variables(void)
63312+{
63313+ struct acl_subject_label *s;
63314+ struct acl_role_label *r;
63315+ struct task_struct *task, *task2;
63316+ unsigned int x;
63317+
63318+ gr_clear_learn_entries();
63319+
63320+ read_lock(&tasklist_lock);
63321+ do_each_thread(task2, task) {
63322+ task->acl_sp_role = 0;
63323+ task->acl_role_id = 0;
63324+ task->acl = NULL;
63325+ task->role = NULL;
63326+ } while_each_thread(task2, task);
63327+ read_unlock(&tasklist_lock);
63328+
63329+ /* release the reference to the real root dentry and vfsmount */
63330+ path_put(&real_root);
63331+ memset(&real_root, 0, sizeof(real_root));
63332+
63333+ /* free all object hash tables */
63334+
63335+ FOR_EACH_ROLE_START(r)
63336+ if (r->subj_hash == NULL)
63337+ goto next_role;
63338+ FOR_EACH_SUBJECT_START(r, s, x)
63339+ if (s->obj_hash == NULL)
63340+ break;
63341+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
63342+ kfree(s->obj_hash);
63343+ else
63344+ vfree(s->obj_hash);
63345+ FOR_EACH_SUBJECT_END(s, x)
63346+ FOR_EACH_NESTED_SUBJECT_START(r, s)
63347+ if (s->obj_hash == NULL)
63348+ break;
63349+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
63350+ kfree(s->obj_hash);
63351+ else
63352+ vfree(s->obj_hash);
63353+ FOR_EACH_NESTED_SUBJECT_END(s)
63354+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
63355+ kfree(r->subj_hash);
63356+ else
63357+ vfree(r->subj_hash);
63358+ r->subj_hash = NULL;
63359+next_role:
63360+ FOR_EACH_ROLE_END(r)
63361+
63362+ acl_free_all();
63363+
63364+ if (acl_role_set.r_hash) {
63365+ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
63366+ PAGE_SIZE)
63367+ kfree(acl_role_set.r_hash);
63368+ else
63369+ vfree(acl_role_set.r_hash);
63370+ }
63371+ if (name_set.n_hash) {
63372+ if ((name_set.n_size * sizeof (struct name_entry *)) <=
63373+ PAGE_SIZE)
63374+ kfree(name_set.n_hash);
63375+ else
63376+ vfree(name_set.n_hash);
63377+ }
63378+
63379+ if (inodev_set.i_hash) {
63380+ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
63381+ PAGE_SIZE)
63382+ kfree(inodev_set.i_hash);
63383+ else
63384+ vfree(inodev_set.i_hash);
63385+ }
63386+
63387+ gr_free_uidset();
63388+
63389+ memset(&name_set, 0, sizeof (struct name_db));
63390+ memset(&inodev_set, 0, sizeof (struct inodev_db));
63391+ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
63392+ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
63393+
63394+ default_role = NULL;
63395+ kernel_role = NULL;
63396+ role_list = NULL;
63397+
63398+ return;
63399+}
63400+
63401+static struct acl_subject_label *
63402+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
63403+
63404+static int alloc_and_copy_string(char **name, unsigned int maxlen)
63405+{
63406+ unsigned int len = strnlen_user(*name, maxlen);
63407+ char *tmp;
63408+
63409+ if (!len || len >= maxlen)
63410+ return -EINVAL;
63411+
63412+ if ((tmp = (char *) acl_alloc(len)) == NULL)
63413+ return -ENOMEM;
63414+
63415+ if (copy_from_user(tmp, *name, len))
63416+ return -EFAULT;
63417+
63418+ tmp[len-1] = '\0';
63419+ *name = tmp;
63420+
63421+ return 0;
63422+}
63423+
63424+static int
63425+copy_user_glob(struct acl_object_label *obj)
63426+{
63427+ struct acl_object_label *g_tmp, **guser;
63428+ int error;
63429+
63430+ if (obj->globbed == NULL)
63431+ return 0;
63432+
63433+ guser = &obj->globbed;
63434+ while (*guser) {
63435+ g_tmp = (struct acl_object_label *)
63436+ acl_alloc(sizeof (struct acl_object_label));
63437+ if (g_tmp == NULL)
63438+ return -ENOMEM;
63439+
63440+ if (copy_acl_object_label(g_tmp, *guser))
63441+ return -EFAULT;
63442+
63443+ error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
63444+ if (error)
63445+ return error;
63446+
63447+ *guser = g_tmp;
63448+ guser = &(g_tmp->next);
63449+ }
63450+
63451+ return 0;
63452+}
63453+
63454+static int
63455+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
63456+ struct acl_role_label *role)
63457+{
63458+ struct acl_object_label *o_tmp;
63459+ int ret;
63460+
63461+ while (userp) {
63462+ if ((o_tmp = (struct acl_object_label *)
63463+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
63464+ return -ENOMEM;
63465+
63466+ if (copy_acl_object_label(o_tmp, userp))
63467+ return -EFAULT;
63468+
63469+ userp = o_tmp->prev;
63470+
63471+ ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
63472+ if (ret)
63473+ return ret;
63474+
63475+ insert_acl_obj_label(o_tmp, subj);
63476+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
63477+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
63478+ return -ENOMEM;
63479+
63480+ ret = copy_user_glob(o_tmp);
63481+ if (ret)
63482+ return ret;
63483+
63484+ if (o_tmp->nested) {
63485+ int already_copied;
63486+
63487+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
63488+ if (IS_ERR(o_tmp->nested))
63489+ return PTR_ERR(o_tmp->nested);
63490+
63491+ /* insert into nested subject list if we haven't copied this one yet
63492+ to prevent duplicate entries */
63493+ if (!already_copied) {
63494+ o_tmp->nested->next = role->hash->first;
63495+ role->hash->first = o_tmp->nested;
63496+ }
63497+ }
63498+ }
63499+
63500+ return 0;
63501+}
63502+
63503+static __u32
63504+count_user_subjs(struct acl_subject_label *userp)
63505+{
63506+ struct acl_subject_label s_tmp;
63507+ __u32 num = 0;
63508+
63509+ while (userp) {
63510+ if (copy_acl_subject_label(&s_tmp, userp))
63511+ break;
63512+
63513+ userp = s_tmp.prev;
63514+ }
63515+
63516+ return num;
63517+}
63518+
63519+static int
63520+copy_user_allowedips(struct acl_role_label *rolep)
63521+{
63522+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
63523+
63524+ ruserip = rolep->allowed_ips;
63525+
63526+ while (ruserip) {
63527+ rlast = rtmp;
63528+
63529+ if ((rtmp = (struct role_allowed_ip *)
63530+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
63531+ return -ENOMEM;
63532+
63533+ if (copy_role_allowed_ip(rtmp, ruserip))
63534+ return -EFAULT;
63535+
63536+ ruserip = rtmp->prev;
63537+
63538+ if (!rlast) {
63539+ rtmp->prev = NULL;
63540+ rolep->allowed_ips = rtmp;
63541+ } else {
63542+ rlast->next = rtmp;
63543+ rtmp->prev = rlast;
63544+ }
63545+
63546+ if (!ruserip)
63547+ rtmp->next = NULL;
63548+ }
63549+
63550+ return 0;
63551+}
63552+
63553+static int
63554+copy_user_transitions(struct acl_role_label *rolep)
63555+{
63556+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
63557+ int error;
63558+
63559+ rusertp = rolep->transitions;
63560+
63561+ while (rusertp) {
63562+ rlast = rtmp;
63563+
63564+ if ((rtmp = (struct role_transition *)
63565+ acl_alloc(sizeof (struct role_transition))) == NULL)
63566+ return -ENOMEM;
63567+
63568+ if (copy_role_transition(rtmp, rusertp))
63569+ return -EFAULT;
63570+
63571+ rusertp = rtmp->prev;
63572+
63573+ error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
63574+ if (error)
63575+ return error;
63576+
63577+ if (!rlast) {
63578+ rtmp->prev = NULL;
63579+ rolep->transitions = rtmp;
63580+ } else {
63581+ rlast->next = rtmp;
63582+ rtmp->prev = rlast;
63583+ }
63584+
63585+ if (!rusertp)
63586+ rtmp->next = NULL;
63587+ }
63588+
63589+ return 0;
63590+}
63591+
63592+static __u32 count_user_objs(const struct acl_object_label __user *userp)
63593+{
63594+ struct acl_object_label o_tmp;
63595+ __u32 num = 0;
63596+
63597+ while (userp) {
63598+ if (copy_acl_object_label(&o_tmp, userp))
63599+ break;
63600+
63601+ userp = o_tmp.prev;
63602+ num++;
63603+ }
63604+
63605+ return num;
63606+}
63607+
63608+static struct acl_subject_label *
63609+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
63610+{
63611+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
63612+ __u32 num_objs;
63613+ struct acl_ip_label **i_tmp, *i_utmp2;
63614+ struct gr_hash_struct ghash;
63615+ struct subject_map *subjmap;
63616+ unsigned int i_num;
63617+ int err;
63618+
63619+ if (already_copied != NULL)
63620+ *already_copied = 0;
63621+
63622+ s_tmp = lookup_subject_map(userp);
63623+
63624+ /* we've already copied this subject into the kernel, just return
63625+ the reference to it, and don't copy it over again
63626+ */
63627+ if (s_tmp) {
63628+ if (already_copied != NULL)
63629+ *already_copied = 1;
63630+ return(s_tmp);
63631+ }
63632+
63633+ if ((s_tmp = (struct acl_subject_label *)
63634+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
63635+ return ERR_PTR(-ENOMEM);
63636+
63637+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
63638+ if (subjmap == NULL)
63639+ return ERR_PTR(-ENOMEM);
63640+
63641+ subjmap->user = userp;
63642+ subjmap->kernel = s_tmp;
63643+ insert_subj_map_entry(subjmap);
63644+
63645+ if (copy_acl_subject_label(s_tmp, userp))
63646+ return ERR_PTR(-EFAULT);
63647+
63648+ err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
63649+ if (err)
63650+ return ERR_PTR(err);
63651+
63652+ if (!strcmp(s_tmp->filename, "/"))
63653+ role->root_label = s_tmp;
63654+
63655+ if (copy_gr_hash_struct(&ghash, s_tmp->hash))
63656+ return ERR_PTR(-EFAULT);
63657+
63658+ /* copy user and group transition tables */
63659+
63660+ if (s_tmp->user_trans_num) {
63661+ uid_t *uidlist;
63662+
63663+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
63664+ if (uidlist == NULL)
63665+ return ERR_PTR(-ENOMEM);
63666+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
63667+ return ERR_PTR(-EFAULT);
63668+
63669+ s_tmp->user_transitions = uidlist;
63670+ }
63671+
63672+ if (s_tmp->group_trans_num) {
63673+ gid_t *gidlist;
63674+
63675+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
63676+ if (gidlist == NULL)
63677+ return ERR_PTR(-ENOMEM);
63678+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
63679+ return ERR_PTR(-EFAULT);
63680+
63681+ s_tmp->group_transitions = gidlist;
63682+ }
63683+
63684+ /* set up object hash table */
63685+ num_objs = count_user_objs(ghash.first);
63686+
63687+ s_tmp->obj_hash_size = num_objs;
63688+ s_tmp->obj_hash =
63689+ (struct acl_object_label **)
63690+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
63691+
63692+ if (!s_tmp->obj_hash)
63693+ return ERR_PTR(-ENOMEM);
63694+
63695+ memset(s_tmp->obj_hash, 0,
63696+ s_tmp->obj_hash_size *
63697+ sizeof (struct acl_object_label *));
63698+
63699+ /* add in objects */
63700+ err = copy_user_objs(ghash.first, s_tmp, role);
63701+
63702+ if (err)
63703+ return ERR_PTR(err);
63704+
63705+ /* set pointer for parent subject */
63706+ if (s_tmp->parent_subject) {
63707+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
63708+
63709+ if (IS_ERR(s_tmp2))
63710+ return s_tmp2;
63711+
63712+ s_tmp->parent_subject = s_tmp2;
63713+ }
63714+
63715+ /* add in ip acls */
63716+
63717+ if (!s_tmp->ip_num) {
63718+ s_tmp->ips = NULL;
63719+ goto insert;
63720+ }
63721+
63722+ i_tmp =
63723+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
63724+ sizeof (struct acl_ip_label *));
63725+
63726+ if (!i_tmp)
63727+ return ERR_PTR(-ENOMEM);
63728+
63729+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
63730+ *(i_tmp + i_num) =
63731+ (struct acl_ip_label *)
63732+ acl_alloc(sizeof (struct acl_ip_label));
63733+ if (!*(i_tmp + i_num))
63734+ return ERR_PTR(-ENOMEM);
63735+
63736+ if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
63737+ return ERR_PTR(-EFAULT);
63738+
63739+ if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
63740+ return ERR_PTR(-EFAULT);
63741+
63742+ if ((*(i_tmp + i_num))->iface == NULL)
63743+ continue;
63744+
63745+ err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
63746+ if (err)
63747+ return ERR_PTR(err);
63748+ }
63749+
63750+ s_tmp->ips = i_tmp;
63751+
63752+insert:
63753+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
63754+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
63755+ return ERR_PTR(-ENOMEM);
63756+
63757+ return s_tmp;
63758+}
63759+
63760+static int
63761+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
63762+{
63763+ struct acl_subject_label s_pre;
63764+ struct acl_subject_label * ret;
63765+ int err;
63766+
63767+ while (userp) {
63768+ if (copy_acl_subject_label(&s_pre, userp))
63769+ return -EFAULT;
63770+
63771+ ret = do_copy_user_subj(userp, role, NULL);
63772+
63773+ err = PTR_ERR(ret);
63774+ if (IS_ERR(ret))
63775+ return err;
63776+
63777+ insert_acl_subj_label(ret, role);
63778+
63779+ userp = s_pre.prev;
63780+ }
63781+
63782+ return 0;
63783+}
63784+
63785+static int
63786+copy_user_acl(struct gr_arg *arg)
63787+{
63788+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
63789+ struct acl_subject_label *subj_list;
63790+ struct sprole_pw *sptmp;
63791+ struct gr_hash_struct *ghash;
63792+ uid_t *domainlist;
63793+ unsigned int r_num;
63794+ int err = 0;
63795+ __u16 i;
63796+ __u32 num_subjs;
63797+
63798+ /* we need a default and kernel role */
63799+ if (arg->role_db.num_roles < 2)
63800+ return -EINVAL;
63801+
63802+ /* copy special role authentication info from userspace */
63803+
63804+ num_sprole_pws = arg->num_sprole_pws;
63805+ acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
63806+
63807+ if (!acl_special_roles && num_sprole_pws)
63808+ return -ENOMEM;
63809+
63810+ for (i = 0; i < num_sprole_pws; i++) {
63811+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
63812+ if (!sptmp)
63813+ return -ENOMEM;
63814+ if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
63815+ return -EFAULT;
63816+
63817+ err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
63818+ if (err)
63819+ return err;
63820+
63821+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
63822+ printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
63823+#endif
63824+
63825+ acl_special_roles[i] = sptmp;
63826+ }
63827+
63828+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
63829+
63830+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
63831+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
63832+
63833+ if (!r_tmp)
63834+ return -ENOMEM;
63835+
63836+ if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
63837+ return -EFAULT;
63838+
63839+ if (copy_acl_role_label(r_tmp, r_utmp2))
63840+ return -EFAULT;
63841+
63842+ err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
63843+ if (err)
63844+ return err;
63845+
63846+ if (!strcmp(r_tmp->rolename, "default")
63847+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
63848+ default_role = r_tmp;
63849+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
63850+ kernel_role = r_tmp;
63851+ }
63852+
63853+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
63854+ return -ENOMEM;
63855+
63856+ if (copy_gr_hash_struct(ghash, r_tmp->hash))
63857+ return -EFAULT;
63858+
63859+ r_tmp->hash = ghash;
63860+
63861+ num_subjs = count_user_subjs(r_tmp->hash->first);
63862+
63863+ r_tmp->subj_hash_size = num_subjs;
63864+ r_tmp->subj_hash =
63865+ (struct acl_subject_label **)
63866+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
63867+
63868+ if (!r_tmp->subj_hash)
63869+ return -ENOMEM;
63870+
63871+ err = copy_user_allowedips(r_tmp);
63872+ if (err)
63873+ return err;
63874+
63875+ /* copy domain info */
63876+ if (r_tmp->domain_children != NULL) {
63877+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
63878+ if (domainlist == NULL)
63879+ return -ENOMEM;
63880+
63881+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
63882+ return -EFAULT;
63883+
63884+ r_tmp->domain_children = domainlist;
63885+ }
63886+
63887+ err = copy_user_transitions(r_tmp);
63888+ if (err)
63889+ return err;
63890+
63891+ memset(r_tmp->subj_hash, 0,
63892+ r_tmp->subj_hash_size *
63893+ sizeof (struct acl_subject_label *));
63894+
63895+ /* acquire the list of subjects, then NULL out
63896+ the list prior to parsing the subjects for this role,
63897+ as during this parsing the list is replaced with a list
63898+ of *nested* subjects for the role
63899+ */
63900+ subj_list = r_tmp->hash->first;
63901+
63902+ /* set nested subject list to null */
63903+ r_tmp->hash->first = NULL;
63904+
63905+ err = copy_user_subjs(subj_list, r_tmp);
63906+
63907+ if (err)
63908+ return err;
63909+
63910+ insert_acl_role_label(r_tmp);
63911+ }
63912+
63913+ if (default_role == NULL || kernel_role == NULL)
63914+ return -EINVAL;
63915+
63916+ return err;
63917+}
63918+
63919+static int
63920+gracl_init(struct gr_arg *args)
63921+{
63922+ int error = 0;
63923+
63924+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
63925+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
63926+
63927+ if (init_variables(args)) {
63928+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
63929+ error = -ENOMEM;
63930+ free_variables();
63931+ goto out;
63932+ }
63933+
63934+ error = copy_user_acl(args);
63935+ free_init_variables();
63936+ if (error) {
63937+ free_variables();
63938+ goto out;
63939+ }
63940+
63941+ if ((error = gr_set_acls(0))) {
63942+ free_variables();
63943+ goto out;
63944+ }
63945+
63946+ pax_open_kernel();
63947+ gr_status |= GR_READY;
63948+ pax_close_kernel();
63949+
63950+ out:
63951+ return error;
63952+}
63953+
63954+/* derived from glibc fnmatch() 0: match, 1: no match*/
63955+
63956+static int
63957+glob_match(const char *p, const char *n)
63958+{
63959+ char c;
63960+
63961+ while ((c = *p++) != '\0') {
63962+ switch (c) {
63963+ case '?':
63964+ if (*n == '\0')
63965+ return 1;
63966+ else if (*n == '/')
63967+ return 1;
63968+ break;
63969+ case '\\':
63970+ if (*n != c)
63971+ return 1;
63972+ break;
63973+ case '*':
63974+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
63975+ if (*n == '/')
63976+ return 1;
63977+ else if (c == '?') {
63978+ if (*n == '\0')
63979+ return 1;
63980+ else
63981+ ++n;
63982+ }
63983+ }
63984+ if (c == '\0') {
63985+ return 0;
63986+ } else {
63987+ const char *endp;
63988+
63989+ if ((endp = strchr(n, '/')) == NULL)
63990+ endp = n + strlen(n);
63991+
63992+ if (c == '[') {
63993+ for (--p; n < endp; ++n)
63994+ if (!glob_match(p, n))
63995+ return 0;
63996+ } else if (c == '/') {
63997+ while (*n != '\0' && *n != '/')
63998+ ++n;
63999+ if (*n == '/' && !glob_match(p, n + 1))
64000+ return 0;
64001+ } else {
64002+ for (--p; n < endp; ++n)
64003+ if (*n == c && !glob_match(p, n))
64004+ return 0;
64005+ }
64006+
64007+ return 1;
64008+ }
64009+ case '[':
64010+ {
64011+ int not;
64012+ char cold;
64013+
64014+ if (*n == '\0' || *n == '/')
64015+ return 1;
64016+
64017+ not = (*p == '!' || *p == '^');
64018+ if (not)
64019+ ++p;
64020+
64021+ c = *p++;
64022+ for (;;) {
64023+ unsigned char fn = (unsigned char)*n;
64024+
64025+ if (c == '\0')
64026+ return 1;
64027+ else {
64028+ if (c == fn)
64029+ goto matched;
64030+ cold = c;
64031+ c = *p++;
64032+
64033+ if (c == '-' && *p != ']') {
64034+ unsigned char cend = *p++;
64035+
64036+ if (cend == '\0')
64037+ return 1;
64038+
64039+ if (cold <= fn && fn <= cend)
64040+ goto matched;
64041+
64042+ c = *p++;
64043+ }
64044+ }
64045+
64046+ if (c == ']')
64047+ break;
64048+ }
64049+ if (!not)
64050+ return 1;
64051+ break;
64052+ matched:
64053+ while (c != ']') {
64054+ if (c == '\0')
64055+ return 1;
64056+
64057+ c = *p++;
64058+ }
64059+ if (not)
64060+ return 1;
64061+ }
64062+ break;
64063+ default:
64064+ if (c != *n)
64065+ return 1;
64066+ }
64067+
64068+ ++n;
64069+ }
64070+
64071+ if (*n == '\0')
64072+ return 0;
64073+
64074+ if (*n == '/')
64075+ return 0;
64076+
64077+ return 1;
64078+}
64079+
64080+static struct acl_object_label *
64081+chk_glob_label(struct acl_object_label *globbed,
64082+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
64083+{
64084+ struct acl_object_label *tmp;
64085+
64086+ if (*path == NULL)
64087+ *path = gr_to_filename_nolock(dentry, mnt);
64088+
64089+ tmp = globbed;
64090+
64091+ while (tmp) {
64092+ if (!glob_match(tmp->filename, *path))
64093+ return tmp;
64094+ tmp = tmp->next;
64095+ }
64096+
64097+ return NULL;
64098+}
64099+
64100+static struct acl_object_label *
64101+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
64102+ const ino_t curr_ino, const dev_t curr_dev,
64103+ const struct acl_subject_label *subj, char **path, const int checkglob)
64104+{
64105+ struct acl_subject_label *tmpsubj;
64106+ struct acl_object_label *retval;
64107+ struct acl_object_label *retval2;
64108+
64109+ tmpsubj = (struct acl_subject_label *) subj;
64110+ read_lock(&gr_inode_lock);
64111+ do {
64112+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
64113+ if (retval) {
64114+ if (checkglob && retval->globbed) {
64115+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
64116+ if (retval2)
64117+ retval = retval2;
64118+ }
64119+ break;
64120+ }
64121+ } while ((tmpsubj = tmpsubj->parent_subject));
64122+ read_unlock(&gr_inode_lock);
64123+
64124+ return retval;
64125+}
64126+
64127+static __inline__ struct acl_object_label *
64128+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
64129+ struct dentry *curr_dentry,
64130+ const struct acl_subject_label *subj, char **path, const int checkglob)
64131+{
64132+ int newglob = checkglob;
64133+ ino_t inode;
64134+ dev_t device;
64135+
64136+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
64137+ as we don't want a / * rule to match instead of the / object
64138+ don't do this for create lookups that call this function though, since they're looking up
64139+ on the parent and thus need globbing checks on all paths
64140+ */
64141+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
64142+ newglob = GR_NO_GLOB;
64143+
64144+ spin_lock(&curr_dentry->d_lock);
64145+ inode = curr_dentry->d_inode->i_ino;
64146+ device = __get_dev(curr_dentry);
64147+ spin_unlock(&curr_dentry->d_lock);
64148+
64149+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
64150+}
64151+
64152+#ifdef CONFIG_HUGETLBFS
64153+static inline bool
64154+is_hugetlbfs_mnt(const struct vfsmount *mnt)
64155+{
64156+ int i;
64157+ for (i = 0; i < HUGE_MAX_HSTATE; i++) {
64158+ if (unlikely(hugetlbfs_vfsmount[i] == mnt))
64159+ return true;
64160+ }
64161+
64162+ return false;
64163+}
64164+#endif
64165+
64166+static struct acl_object_label *
64167+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
64168+ const struct acl_subject_label *subj, char *path, const int checkglob)
64169+{
64170+ struct dentry *dentry = (struct dentry *) l_dentry;
64171+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
64172+ struct mount *real_mnt = real_mount(mnt);
64173+ struct acl_object_label *retval;
64174+ struct dentry *parent;
64175+
64176+ br_read_lock(&vfsmount_lock);
64177+ write_seqlock(&rename_lock);
64178+
64179+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
64180+#ifdef CONFIG_NET
64181+ mnt == sock_mnt ||
64182+#endif
64183+#ifdef CONFIG_HUGETLBFS
64184+ (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
64185+#endif
64186+ /* ignore Eric Biederman */
64187+ IS_PRIVATE(l_dentry->d_inode))) {
64188+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
64189+ goto out;
64190+ }
64191+
64192+ for (;;) {
64193+ if (dentry == real_root.dentry && mnt == real_root.mnt)
64194+ break;
64195+
64196+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
64197+ if (!mnt_has_parent(real_mnt))
64198+ break;
64199+
64200+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
64201+ if (retval != NULL)
64202+ goto out;
64203+
64204+ dentry = real_mnt->mnt_mountpoint;
64205+ real_mnt = real_mnt->mnt_parent;
64206+ mnt = &real_mnt->mnt;
64207+ continue;
64208+ }
64209+
64210+ parent = dentry->d_parent;
64211+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
64212+ if (retval != NULL)
64213+ goto out;
64214+
64215+ dentry = parent;
64216+ }
64217+
64218+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
64219+
64220+ /* real_root is pinned so we don't have to hold a reference */
64221+ if (retval == NULL)
64222+ retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
64223+out:
64224+ write_sequnlock(&rename_lock);
64225+ br_read_unlock(&vfsmount_lock);
64226+
64227+ BUG_ON(retval == NULL);
64228+
64229+ return retval;
64230+}
64231+
64232+static __inline__ struct acl_object_label *
64233+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
64234+ const struct acl_subject_label *subj)
64235+{
64236+ char *path = NULL;
64237+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
64238+}
64239+
64240+static __inline__ struct acl_object_label *
64241+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
64242+ const struct acl_subject_label *subj)
64243+{
64244+ char *path = NULL;
64245+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
64246+}
64247+
64248+static __inline__ struct acl_object_label *
64249+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
64250+ const struct acl_subject_label *subj, char *path)
64251+{
64252+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
64253+}
64254+
64255+static struct acl_subject_label *
64256+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
64257+ const struct acl_role_label *role)
64258+{
64259+ struct dentry *dentry = (struct dentry *) l_dentry;
64260+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
64261+ struct mount *real_mnt = real_mount(mnt);
64262+ struct acl_subject_label *retval;
64263+ struct dentry *parent;
64264+
64265+ br_read_lock(&vfsmount_lock);
64266+ write_seqlock(&rename_lock);
64267+
64268+ for (;;) {
64269+ if (dentry == real_root.dentry && mnt == real_root.mnt)
64270+ break;
64271+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
64272+ if (!mnt_has_parent(real_mnt))
64273+ break;
64274+
64275+ spin_lock(&dentry->d_lock);
64276+ read_lock(&gr_inode_lock);
64277+ retval =
64278+ lookup_acl_subj_label(dentry->d_inode->i_ino,
64279+ __get_dev(dentry), role);
64280+ read_unlock(&gr_inode_lock);
64281+ spin_unlock(&dentry->d_lock);
64282+ if (retval != NULL)
64283+ goto out;
64284+
64285+ dentry = real_mnt->mnt_mountpoint;
64286+ real_mnt = real_mnt->mnt_parent;
64287+ mnt = &real_mnt->mnt;
64288+ continue;
64289+ }
64290+
64291+ spin_lock(&dentry->d_lock);
64292+ read_lock(&gr_inode_lock);
64293+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
64294+ __get_dev(dentry), role);
64295+ read_unlock(&gr_inode_lock);
64296+ parent = dentry->d_parent;
64297+ spin_unlock(&dentry->d_lock);
64298+
64299+ if (retval != NULL)
64300+ goto out;
64301+
64302+ dentry = parent;
64303+ }
64304+
64305+ spin_lock(&dentry->d_lock);
64306+ read_lock(&gr_inode_lock);
64307+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
64308+ __get_dev(dentry), role);
64309+ read_unlock(&gr_inode_lock);
64310+ spin_unlock(&dentry->d_lock);
64311+
64312+ if (unlikely(retval == NULL)) {
64313+ /* real_root is pinned, we don't need to hold a reference */
64314+ read_lock(&gr_inode_lock);
64315+ retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
64316+ __get_dev(real_root.dentry), role);
64317+ read_unlock(&gr_inode_lock);
64318+ }
64319+out:
64320+ write_sequnlock(&rename_lock);
64321+ br_read_unlock(&vfsmount_lock);
64322+
64323+ BUG_ON(retval == NULL);
64324+
64325+ return retval;
64326+}
64327+
64328+static void
64329+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
64330+{
64331+ struct task_struct *task = current;
64332+ const struct cred *cred = current_cred();
64333+
64334+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
64335+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
64336+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
64337+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
64338+
64339+ return;
64340+}
64341+
64342+static void
64343+gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
64344+{
64345+ struct task_struct *task = current;
64346+ const struct cred *cred = current_cred();
64347+
64348+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
64349+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
64350+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
64351+ 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
64352+
64353+ return;
64354+}
64355+
64356+static void
64357+gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
64358+{
64359+ struct task_struct *task = current;
64360+ const struct cred *cred = current_cred();
64361+
64362+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
64363+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
64364+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
64365+ 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
64366+
64367+ return;
64368+}
64369+
64370+__u32
64371+gr_search_file(const struct dentry * dentry, const __u32 mode,
64372+ const struct vfsmount * mnt)
64373+{
64374+ __u32 retval = mode;
64375+ struct acl_subject_label *curracl;
64376+ struct acl_object_label *currobj;
64377+
64378+ if (unlikely(!(gr_status & GR_READY)))
64379+ return (mode & ~GR_AUDITS);
64380+
64381+ curracl = current->acl;
64382+
64383+ currobj = chk_obj_label(dentry, mnt, curracl);
64384+ retval = currobj->mode & mode;
64385+
64386+ /* if we're opening a specified transfer file for writing
64387+ (e.g. /dev/initctl), then transfer our role to init
64388+ */
64389+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
64390+ current->role->roletype & GR_ROLE_PERSIST)) {
64391+ struct task_struct *task = init_pid_ns.child_reaper;
64392+
64393+ if (task->role != current->role) {
64394+ task->acl_sp_role = 0;
64395+ task->acl_role_id = current->acl_role_id;
64396+ task->role = current->role;
64397+ rcu_read_lock();
64398+ read_lock(&grsec_exec_file_lock);
64399+ gr_apply_subject_to_task(task);
64400+ read_unlock(&grsec_exec_file_lock);
64401+ rcu_read_unlock();
64402+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
64403+ }
64404+ }
64405+
64406+ if (unlikely
64407+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
64408+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
64409+ __u32 new_mode = mode;
64410+
64411+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
64412+
64413+ retval = new_mode;
64414+
64415+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
64416+ new_mode |= GR_INHERIT;
64417+
64418+ if (!(mode & GR_NOLEARN))
64419+ gr_log_learn(dentry, mnt, new_mode);
64420+ }
64421+
64422+ return retval;
64423+}
64424+
64425+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
64426+ const struct dentry *parent,
64427+ const struct vfsmount *mnt)
64428+{
64429+ struct name_entry *match;
64430+ struct acl_object_label *matchpo;
64431+ struct acl_subject_label *curracl;
64432+ char *path;
64433+
64434+ if (unlikely(!(gr_status & GR_READY)))
64435+ return NULL;
64436+
64437+ preempt_disable();
64438+ path = gr_to_filename_rbac(new_dentry, mnt);
64439+ match = lookup_name_entry_create(path);
64440+
64441+ curracl = current->acl;
64442+
64443+ if (match) {
64444+ read_lock(&gr_inode_lock);
64445+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
64446+ read_unlock(&gr_inode_lock);
64447+
64448+ if (matchpo) {
64449+ preempt_enable();
64450+ return matchpo;
64451+ }
64452+ }
64453+
64454+ // lookup parent
64455+
64456+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
64457+
64458+ preempt_enable();
64459+ return matchpo;
64460+}
64461+
64462+__u32
64463+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
64464+ const struct vfsmount * mnt, const __u32 mode)
64465+{
64466+ struct acl_object_label *matchpo;
64467+ __u32 retval;
64468+
64469+ if (unlikely(!(gr_status & GR_READY)))
64470+ return (mode & ~GR_AUDITS);
64471+
64472+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
64473+
64474+ retval = matchpo->mode & mode;
64475+
64476+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
64477+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
64478+ __u32 new_mode = mode;
64479+
64480+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
64481+
64482+ gr_log_learn(new_dentry, mnt, new_mode);
64483+ return new_mode;
64484+ }
64485+
64486+ return retval;
64487+}
64488+
64489+__u32
64490+gr_check_link(const struct dentry * new_dentry,
64491+ const struct dentry * parent_dentry,
64492+ const struct vfsmount * parent_mnt,
64493+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
64494+{
64495+ struct acl_object_label *obj;
64496+ __u32 oldmode, newmode;
64497+ __u32 needmode;
64498+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
64499+ GR_DELETE | GR_INHERIT;
64500+
64501+ if (unlikely(!(gr_status & GR_READY)))
64502+ return (GR_CREATE | GR_LINK);
64503+
64504+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
64505+ oldmode = obj->mode;
64506+
64507+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
64508+ newmode = obj->mode;
64509+
64510+ needmode = newmode & checkmodes;
64511+
64512+ // old name for hardlink must have at least the permissions of the new name
64513+ if ((oldmode & needmode) != needmode)
64514+ goto bad;
64515+
64516+ // if old name had restrictions/auditing, make sure the new name does as well
64517+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
64518+
64519+ // don't allow hardlinking of suid/sgid/fcapped files without permission
64520+ if (is_privileged_binary(old_dentry))
64521+ needmode |= GR_SETID;
64522+
64523+ if ((newmode & needmode) != needmode)
64524+ goto bad;
64525+
64526+ // enforce minimum permissions
64527+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
64528+ return newmode;
64529+bad:
64530+ needmode = oldmode;
64531+ if (is_privileged_binary(old_dentry))
64532+ needmode |= GR_SETID;
64533+
64534+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
64535+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
64536+ return (GR_CREATE | GR_LINK);
64537+ } else if (newmode & GR_SUPPRESS)
64538+ return GR_SUPPRESS;
64539+ else
64540+ return 0;
64541+}
64542+
64543+int
64544+gr_check_hidden_task(const struct task_struct *task)
64545+{
64546+ if (unlikely(!(gr_status & GR_READY)))
64547+ return 0;
64548+
64549+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
64550+ return 1;
64551+
64552+ return 0;
64553+}
64554+
64555+int
64556+gr_check_protected_task(const struct task_struct *task)
64557+{
64558+ if (unlikely(!(gr_status & GR_READY) || !task))
64559+ return 0;
64560+
64561+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
64562+ task->acl != current->acl)
64563+ return 1;
64564+
64565+ return 0;
64566+}
64567+
64568+int
64569+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
64570+{
64571+ struct task_struct *p;
64572+ int ret = 0;
64573+
64574+ if (unlikely(!(gr_status & GR_READY) || !pid))
64575+ return ret;
64576+
64577+ read_lock(&tasklist_lock);
64578+ do_each_pid_task(pid, type, p) {
64579+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
64580+ p->acl != current->acl) {
64581+ ret = 1;
64582+ goto out;
64583+ }
64584+ } while_each_pid_task(pid, type, p);
64585+out:
64586+ read_unlock(&tasklist_lock);
64587+
64588+ return ret;
64589+}
64590+
64591+void
64592+gr_copy_label(struct task_struct *tsk)
64593+{
64594+ tsk->signal->used_accept = 0;
64595+ tsk->acl_sp_role = 0;
64596+ tsk->acl_role_id = current->acl_role_id;
64597+ tsk->acl = current->acl;
64598+ tsk->role = current->role;
64599+ tsk->signal->curr_ip = current->signal->curr_ip;
64600+ tsk->signal->saved_ip = current->signal->saved_ip;
64601+ if (current->exec_file)
64602+ get_file(current->exec_file);
64603+ tsk->exec_file = current->exec_file;
64604+ tsk->is_writable = current->is_writable;
64605+ if (unlikely(current->signal->used_accept)) {
64606+ current->signal->curr_ip = 0;
64607+ current->signal->saved_ip = 0;
64608+ }
64609+
64610+ return;
64611+}
64612+
64613+static void
64614+gr_set_proc_res(struct task_struct *task)
64615+{
64616+ struct acl_subject_label *proc;
64617+ unsigned short i;
64618+
64619+ proc = task->acl;
64620+
64621+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
64622+ return;
64623+
64624+ for (i = 0; i < RLIM_NLIMITS; i++) {
64625+ if (!(proc->resmask & (1U << i)))
64626+ continue;
64627+
64628+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
64629+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
64630+
64631+ if (i == RLIMIT_CPU)
64632+ update_rlimit_cpu(task, proc->res[i].rlim_cur);
64633+ }
64634+
64635+ return;
64636+}
64637+
64638+extern int gr_process_kernel_setuid_ban(struct user_struct *user);
64639+
64640+int
64641+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
64642+{
64643+ unsigned int i;
64644+ __u16 num;
64645+ uid_t *uidlist;
64646+ uid_t curuid;
64647+ int realok = 0;
64648+ int effectiveok = 0;
64649+ int fsok = 0;
64650+ uid_t globalreal, globaleffective, globalfs;
64651+
64652+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
64653+ struct user_struct *user;
64654+
64655+ if (!uid_valid(real))
64656+ goto skipit;
64657+
64658+ /* find user based on global namespace */
64659+
64660+ globalreal = GR_GLOBAL_UID(real);
64661+
64662+ user = find_user(make_kuid(&init_user_ns, globalreal));
64663+ if (user == NULL)
64664+ goto skipit;
64665+
64666+ if (gr_process_kernel_setuid_ban(user)) {
64667+ /* for find_user */
64668+ free_uid(user);
64669+ return 1;
64670+ }
64671+
64672+ /* for find_user */
64673+ free_uid(user);
64674+
64675+skipit:
64676+#endif
64677+
64678+ if (unlikely(!(gr_status & GR_READY)))
64679+ return 0;
64680+
64681+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
64682+ gr_log_learn_uid_change(real, effective, fs);
64683+
64684+ num = current->acl->user_trans_num;
64685+ uidlist = current->acl->user_transitions;
64686+
64687+ if (uidlist == NULL)
64688+ return 0;
64689+
64690+ if (!uid_valid(real)) {
64691+ realok = 1;
64692+ globalreal = (uid_t)-1;
64693+ } else {
64694+ globalreal = GR_GLOBAL_UID(real);
64695+ }
64696+ if (!uid_valid(effective)) {
64697+ effectiveok = 1;
64698+ globaleffective = (uid_t)-1;
64699+ } else {
64700+ globaleffective = GR_GLOBAL_UID(effective);
64701+ }
64702+ if (!uid_valid(fs)) {
64703+ fsok = 1;
64704+ globalfs = (uid_t)-1;
64705+ } else {
64706+ globalfs = GR_GLOBAL_UID(fs);
64707+ }
64708+
64709+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
64710+ for (i = 0; i < num; i++) {
64711+ curuid = uidlist[i];
64712+ if (globalreal == curuid)
64713+ realok = 1;
64714+ if (globaleffective == curuid)
64715+ effectiveok = 1;
64716+ if (globalfs == curuid)
64717+ fsok = 1;
64718+ }
64719+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
64720+ for (i = 0; i < num; i++) {
64721+ curuid = uidlist[i];
64722+ if (globalreal == curuid)
64723+ break;
64724+ if (globaleffective == curuid)
64725+ break;
64726+ if (globalfs == curuid)
64727+ break;
64728+ }
64729+ /* not in deny list */
64730+ if (i == num) {
64731+ realok = 1;
64732+ effectiveok = 1;
64733+ fsok = 1;
64734+ }
64735+ }
64736+
64737+ if (realok && effectiveok && fsok)
64738+ return 0;
64739+ else {
64740+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
64741+ return 1;
64742+ }
64743+}
64744+
64745+int
64746+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
64747+{
64748+ unsigned int i;
64749+ __u16 num;
64750+ gid_t *gidlist;
64751+ gid_t curgid;
64752+ int realok = 0;
64753+ int effectiveok = 0;
64754+ int fsok = 0;
64755+ gid_t globalreal, globaleffective, globalfs;
64756+
64757+ if (unlikely(!(gr_status & GR_READY)))
64758+ return 0;
64759+
64760+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
64761+ gr_log_learn_gid_change(real, effective, fs);
64762+
64763+ num = current->acl->group_trans_num;
64764+ gidlist = current->acl->group_transitions;
64765+
64766+ if (gidlist == NULL)
64767+ return 0;
64768+
64769+ if (!gid_valid(real)) {
64770+ realok = 1;
64771+ globalreal = (gid_t)-1;
64772+ } else {
64773+ globalreal = GR_GLOBAL_GID(real);
64774+ }
64775+ if (!gid_valid(effective)) {
64776+ effectiveok = 1;
64777+ globaleffective = (gid_t)-1;
64778+ } else {
64779+ globaleffective = GR_GLOBAL_GID(effective);
64780+ }
64781+ if (!gid_valid(fs)) {
64782+ fsok = 1;
64783+ globalfs = (gid_t)-1;
64784+ } else {
64785+ globalfs = GR_GLOBAL_GID(fs);
64786+ }
64787+
64788+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
64789+ for (i = 0; i < num; i++) {
64790+ curgid = gidlist[i];
64791+ if (globalreal == curgid)
64792+ realok = 1;
64793+ if (globaleffective == curgid)
64794+ effectiveok = 1;
64795+ if (globalfs == curgid)
64796+ fsok = 1;
64797+ }
64798+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
64799+ for (i = 0; i < num; i++) {
64800+ curgid = gidlist[i];
64801+ if (globalreal == curgid)
64802+ break;
64803+ if (globaleffective == curgid)
64804+ break;
64805+ if (globalfs == curgid)
64806+ break;
64807+ }
64808+ /* not in deny list */
64809+ if (i == num) {
64810+ realok = 1;
64811+ effectiveok = 1;
64812+ fsok = 1;
64813+ }
64814+ }
64815+
64816+ if (realok && effectiveok && fsok)
64817+ return 0;
64818+ else {
64819+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
64820+ return 1;
64821+ }
64822+}
64823+
64824+extern int gr_acl_is_capable(const int cap);
64825+
64826+void
64827+gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
64828+{
64829+ struct acl_role_label *role = task->role;
64830+ struct acl_subject_label *subj = NULL;
64831+ struct acl_object_label *obj;
64832+ struct file *filp;
64833+ uid_t uid;
64834+ gid_t gid;
64835+
64836+ if (unlikely(!(gr_status & GR_READY)))
64837+ return;
64838+
64839+ uid = GR_GLOBAL_UID(kuid);
64840+ gid = GR_GLOBAL_GID(kgid);
64841+
64842+ filp = task->exec_file;
64843+
64844+ /* kernel process, we'll give them the kernel role */
64845+ if (unlikely(!filp)) {
64846+ task->role = kernel_role;
64847+ task->acl = kernel_role->root_label;
64848+ return;
64849+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
64850+ role = lookup_acl_role_label(task, uid, gid);
64851+
64852+ /* don't change the role if we're not a privileged process */
64853+ if (role && task->role != role &&
64854+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
64855+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
64856+ return;
64857+
64858+ /* perform subject lookup in possibly new role
64859+ we can use this result below in the case where role == task->role
64860+ */
64861+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
64862+
64863+ /* if we changed uid/gid, but result in the same role
64864+ and are using inheritance, don't lose the inherited subject
64865+ if current subject is other than what normal lookup
64866+ would result in, we arrived via inheritance, don't
64867+ lose subject
64868+ */
64869+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
64870+ (subj == task->acl)))
64871+ task->acl = subj;
64872+
64873+ task->role = role;
64874+
64875+ task->is_writable = 0;
64876+
64877+ /* ignore additional mmap checks for processes that are writable
64878+ by the default ACL */
64879+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
64880+ if (unlikely(obj->mode & GR_WRITE))
64881+ task->is_writable = 1;
64882+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
64883+ if (unlikely(obj->mode & GR_WRITE))
64884+ task->is_writable = 1;
64885+
64886+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
64887+ 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);
64888+#endif
64889+
64890+ gr_set_proc_res(task);
64891+
64892+ return;
64893+}
64894+
64895+int
64896+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
64897+ const int unsafe_flags)
64898+{
64899+ struct task_struct *task = current;
64900+ struct acl_subject_label *newacl;
64901+ struct acl_object_label *obj;
64902+ __u32 retmode;
64903+
64904+ if (unlikely(!(gr_status & GR_READY)))
64905+ return 0;
64906+
64907+ newacl = chk_subj_label(dentry, mnt, task->role);
64908+
64909+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
64910+ did an exec
64911+ */
64912+ rcu_read_lock();
64913+ read_lock(&tasklist_lock);
64914+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
64915+ (task->parent->acl->mode & GR_POVERRIDE))) {
64916+ read_unlock(&tasklist_lock);
64917+ rcu_read_unlock();
64918+ goto skip_check;
64919+ }
64920+ read_unlock(&tasklist_lock);
64921+ rcu_read_unlock();
64922+
64923+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
64924+ !(task->role->roletype & GR_ROLE_GOD) &&
64925+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
64926+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
64927+ if (unsafe_flags & LSM_UNSAFE_SHARE)
64928+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
64929+ else
64930+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
64931+ return -EACCES;
64932+ }
64933+
64934+skip_check:
64935+
64936+ obj = chk_obj_label(dentry, mnt, task->acl);
64937+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
64938+
64939+ if (!(task->acl->mode & GR_INHERITLEARN) &&
64940+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
64941+ if (obj->nested)
64942+ task->acl = obj->nested;
64943+ else
64944+ task->acl = newacl;
64945+ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
64946+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
64947+
64948+ task->is_writable = 0;
64949+
64950+ /* ignore additional mmap checks for processes that are writable
64951+ by the default ACL */
64952+ obj = chk_obj_label(dentry, mnt, default_role->root_label);
64953+ if (unlikely(obj->mode & GR_WRITE))
64954+ task->is_writable = 1;
64955+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
64956+ if (unlikely(obj->mode & GR_WRITE))
64957+ task->is_writable = 1;
64958+
64959+ gr_set_proc_res(task);
64960+
64961+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
64962+ 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);
64963+#endif
64964+ return 0;
64965+}
64966+
64967+/* always called with valid inodev ptr */
64968+static void
64969+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
64970+{
64971+ struct acl_object_label *matchpo;
64972+ struct acl_subject_label *matchps;
64973+ struct acl_subject_label *subj;
64974+ struct acl_role_label *role;
64975+ unsigned int x;
64976+
64977+ FOR_EACH_ROLE_START(role)
64978+ FOR_EACH_SUBJECT_START(role, subj, x)
64979+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
64980+ matchpo->mode |= GR_DELETED;
64981+ FOR_EACH_SUBJECT_END(subj,x)
64982+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
64983+ /* nested subjects aren't in the role's subj_hash table */
64984+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
64985+ matchpo->mode |= GR_DELETED;
64986+ FOR_EACH_NESTED_SUBJECT_END(subj)
64987+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
64988+ matchps->mode |= GR_DELETED;
64989+ FOR_EACH_ROLE_END(role)
64990+
64991+ inodev->nentry->deleted = 1;
64992+
64993+ return;
64994+}
64995+
64996+void
64997+gr_handle_delete(const ino_t ino, const dev_t dev)
64998+{
64999+ struct inodev_entry *inodev;
65000+
65001+ if (unlikely(!(gr_status & GR_READY)))
65002+ return;
65003+
65004+ write_lock(&gr_inode_lock);
65005+ inodev = lookup_inodev_entry(ino, dev);
65006+ if (inodev != NULL)
65007+ do_handle_delete(inodev, ino, dev);
65008+ write_unlock(&gr_inode_lock);
65009+
65010+ return;
65011+}
65012+
65013+static void
65014+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
65015+ const ino_t newinode, const dev_t newdevice,
65016+ struct acl_subject_label *subj)
65017+{
65018+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
65019+ struct acl_object_label *match;
65020+
65021+ match = subj->obj_hash[index];
65022+
65023+ while (match && (match->inode != oldinode ||
65024+ match->device != olddevice ||
65025+ !(match->mode & GR_DELETED)))
65026+ match = match->next;
65027+
65028+ if (match && (match->inode == oldinode)
65029+ && (match->device == olddevice)
65030+ && (match->mode & GR_DELETED)) {
65031+ if (match->prev == NULL) {
65032+ subj->obj_hash[index] = match->next;
65033+ if (match->next != NULL)
65034+ match->next->prev = NULL;
65035+ } else {
65036+ match->prev->next = match->next;
65037+ if (match->next != NULL)
65038+ match->next->prev = match->prev;
65039+ }
65040+ match->prev = NULL;
65041+ match->next = NULL;
65042+ match->inode = newinode;
65043+ match->device = newdevice;
65044+ match->mode &= ~GR_DELETED;
65045+
65046+ insert_acl_obj_label(match, subj);
65047+ }
65048+
65049+ return;
65050+}
65051+
65052+static void
65053+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
65054+ const ino_t newinode, const dev_t newdevice,
65055+ struct acl_role_label *role)
65056+{
65057+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
65058+ struct acl_subject_label *match;
65059+
65060+ match = role->subj_hash[index];
65061+
65062+ while (match && (match->inode != oldinode ||
65063+ match->device != olddevice ||
65064+ !(match->mode & GR_DELETED)))
65065+ match = match->next;
65066+
65067+ if (match && (match->inode == oldinode)
65068+ && (match->device == olddevice)
65069+ && (match->mode & GR_DELETED)) {
65070+ if (match->prev == NULL) {
65071+ role->subj_hash[index] = match->next;
65072+ if (match->next != NULL)
65073+ match->next->prev = NULL;
65074+ } else {
65075+ match->prev->next = match->next;
65076+ if (match->next != NULL)
65077+ match->next->prev = match->prev;
65078+ }
65079+ match->prev = NULL;
65080+ match->next = NULL;
65081+ match->inode = newinode;
65082+ match->device = newdevice;
65083+ match->mode &= ~GR_DELETED;
65084+
65085+ insert_acl_subj_label(match, role);
65086+ }
65087+
65088+ return;
65089+}
65090+
65091+static void
65092+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
65093+ const ino_t newinode, const dev_t newdevice)
65094+{
65095+ unsigned int index = gr_fhash(oldinode, olddevice, inodev_set.i_size);
65096+ struct inodev_entry *match;
65097+
65098+ match = inodev_set.i_hash[index];
65099+
65100+ while (match && (match->nentry->inode != oldinode ||
65101+ match->nentry->device != olddevice || !match->nentry->deleted))
65102+ match = match->next;
65103+
65104+ if (match && (match->nentry->inode == oldinode)
65105+ && (match->nentry->device == olddevice) &&
65106+ match->nentry->deleted) {
65107+ if (match->prev == NULL) {
65108+ inodev_set.i_hash[index] = match->next;
65109+ if (match->next != NULL)
65110+ match->next->prev = NULL;
65111+ } else {
65112+ match->prev->next = match->next;
65113+ if (match->next != NULL)
65114+ match->next->prev = match->prev;
65115+ }
65116+ match->prev = NULL;
65117+ match->next = NULL;
65118+ match->nentry->inode = newinode;
65119+ match->nentry->device = newdevice;
65120+ match->nentry->deleted = 0;
65121+
65122+ insert_inodev_entry(match);
65123+ }
65124+
65125+ return;
65126+}
65127+
65128+static void
65129+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
65130+{
65131+ struct acl_subject_label *subj;
65132+ struct acl_role_label *role;
65133+ unsigned int x;
65134+
65135+ FOR_EACH_ROLE_START(role)
65136+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
65137+
65138+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
65139+ if ((subj->inode == ino) && (subj->device == dev)) {
65140+ subj->inode = ino;
65141+ subj->device = dev;
65142+ }
65143+ /* nested subjects aren't in the role's subj_hash table */
65144+ update_acl_obj_label(matchn->inode, matchn->device,
65145+ ino, dev, subj);
65146+ FOR_EACH_NESTED_SUBJECT_END(subj)
65147+ FOR_EACH_SUBJECT_START(role, subj, x)
65148+ update_acl_obj_label(matchn->inode, matchn->device,
65149+ ino, dev, subj);
65150+ FOR_EACH_SUBJECT_END(subj,x)
65151+ FOR_EACH_ROLE_END(role)
65152+
65153+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
65154+
65155+ return;
65156+}
65157+
65158+static void
65159+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
65160+ const struct vfsmount *mnt)
65161+{
65162+ ino_t ino = dentry->d_inode->i_ino;
65163+ dev_t dev = __get_dev(dentry);
65164+
65165+ __do_handle_create(matchn, ino, dev);
65166+
65167+ return;
65168+}
65169+
65170+void
65171+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
65172+{
65173+ struct name_entry *matchn;
65174+
65175+ if (unlikely(!(gr_status & GR_READY)))
65176+ return;
65177+
65178+ preempt_disable();
65179+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
65180+
65181+ if (unlikely((unsigned long)matchn)) {
65182+ write_lock(&gr_inode_lock);
65183+ do_handle_create(matchn, dentry, mnt);
65184+ write_unlock(&gr_inode_lock);
65185+ }
65186+ preempt_enable();
65187+
65188+ return;
65189+}
65190+
65191+void
65192+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
65193+{
65194+ struct name_entry *matchn;
65195+
65196+ if (unlikely(!(gr_status & GR_READY)))
65197+ return;
65198+
65199+ preempt_disable();
65200+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
65201+
65202+ if (unlikely((unsigned long)matchn)) {
65203+ write_lock(&gr_inode_lock);
65204+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
65205+ write_unlock(&gr_inode_lock);
65206+ }
65207+ preempt_enable();
65208+
65209+ return;
65210+}
65211+
65212+void
65213+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
65214+ struct dentry *old_dentry,
65215+ struct dentry *new_dentry,
65216+ struct vfsmount *mnt, const __u8 replace)
65217+{
65218+ struct name_entry *matchn;
65219+ struct inodev_entry *inodev;
65220+ struct inode *inode = new_dentry->d_inode;
65221+ ino_t old_ino = old_dentry->d_inode->i_ino;
65222+ dev_t old_dev = __get_dev(old_dentry);
65223+
65224+ /* vfs_rename swaps the name and parent link for old_dentry and
65225+ new_dentry
65226+ at this point, old_dentry has the new name, parent link, and inode
65227+ for the renamed file
65228+ if a file is being replaced by a rename, new_dentry has the inode
65229+ and name for the replaced file
65230+ */
65231+
65232+ if (unlikely(!(gr_status & GR_READY)))
65233+ return;
65234+
65235+ preempt_disable();
65236+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
65237+
65238+ /* we wouldn't have to check d_inode if it weren't for
65239+ NFS silly-renaming
65240+ */
65241+
65242+ write_lock(&gr_inode_lock);
65243+ if (unlikely(replace && inode)) {
65244+ ino_t new_ino = inode->i_ino;
65245+ dev_t new_dev = __get_dev(new_dentry);
65246+
65247+ inodev = lookup_inodev_entry(new_ino, new_dev);
65248+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
65249+ do_handle_delete(inodev, new_ino, new_dev);
65250+ }
65251+
65252+ inodev = lookup_inodev_entry(old_ino, old_dev);
65253+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
65254+ do_handle_delete(inodev, old_ino, old_dev);
65255+
65256+ if (unlikely((unsigned long)matchn))
65257+ do_handle_create(matchn, old_dentry, mnt);
65258+
65259+ write_unlock(&gr_inode_lock);
65260+ preempt_enable();
65261+
65262+ return;
65263+}
65264+
65265+static int
65266+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
65267+ unsigned char **sum)
65268+{
65269+ struct acl_role_label *r;
65270+ struct role_allowed_ip *ipp;
65271+ struct role_transition *trans;
65272+ unsigned int i;
65273+ int found = 0;
65274+ u32 curr_ip = current->signal->curr_ip;
65275+
65276+ current->signal->saved_ip = curr_ip;
65277+
65278+ /* check transition table */
65279+
65280+ for (trans = current->role->transitions; trans; trans = trans->next) {
65281+ if (!strcmp(rolename, trans->rolename)) {
65282+ found = 1;
65283+ break;
65284+ }
65285+ }
65286+
65287+ if (!found)
65288+ return 0;
65289+
65290+ /* handle special roles that do not require authentication
65291+ and check ip */
65292+
65293+ FOR_EACH_ROLE_START(r)
65294+ if (!strcmp(rolename, r->rolename) &&
65295+ (r->roletype & GR_ROLE_SPECIAL)) {
65296+ found = 0;
65297+ if (r->allowed_ips != NULL) {
65298+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
65299+ if ((ntohl(curr_ip) & ipp->netmask) ==
65300+ (ntohl(ipp->addr) & ipp->netmask))
65301+ found = 1;
65302+ }
65303+ } else
65304+ found = 2;
65305+ if (!found)
65306+ return 0;
65307+
65308+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
65309+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
65310+ *salt = NULL;
65311+ *sum = NULL;
65312+ return 1;
65313+ }
65314+ }
65315+ FOR_EACH_ROLE_END(r)
65316+
65317+ for (i = 0; i < num_sprole_pws; i++) {
65318+ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
65319+ *salt = acl_special_roles[i]->salt;
65320+ *sum = acl_special_roles[i]->sum;
65321+ return 1;
65322+ }
65323+ }
65324+
65325+ return 0;
65326+}
65327+
65328+static void
65329+assign_special_role(char *rolename)
65330+{
65331+ struct acl_object_label *obj;
65332+ struct acl_role_label *r;
65333+ struct acl_role_label *assigned = NULL;
65334+ struct task_struct *tsk;
65335+ struct file *filp;
65336+
65337+ FOR_EACH_ROLE_START(r)
65338+ if (!strcmp(rolename, r->rolename) &&
65339+ (r->roletype & GR_ROLE_SPECIAL)) {
65340+ assigned = r;
65341+ break;
65342+ }
65343+ FOR_EACH_ROLE_END(r)
65344+
65345+ if (!assigned)
65346+ return;
65347+
65348+ read_lock(&tasklist_lock);
65349+ read_lock(&grsec_exec_file_lock);
65350+
65351+ tsk = current->real_parent;
65352+ if (tsk == NULL)
65353+ goto out_unlock;
65354+
65355+ filp = tsk->exec_file;
65356+ if (filp == NULL)
65357+ goto out_unlock;
65358+
65359+ tsk->is_writable = 0;
65360+
65361+ tsk->acl_sp_role = 1;
65362+ tsk->acl_role_id = ++acl_sp_role_value;
65363+ tsk->role = assigned;
65364+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
65365+
65366+ /* ignore additional mmap checks for processes that are writable
65367+ by the default ACL */
65368+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
65369+ if (unlikely(obj->mode & GR_WRITE))
65370+ tsk->is_writable = 1;
65371+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
65372+ if (unlikely(obj->mode & GR_WRITE))
65373+ tsk->is_writable = 1;
65374+
65375+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
65376+ 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));
65377+#endif
65378+
65379+out_unlock:
65380+ read_unlock(&grsec_exec_file_lock);
65381+ read_unlock(&tasklist_lock);
65382+ return;
65383+}
65384+
65385+int gr_check_secure_terminal(struct task_struct *task)
65386+{
65387+ struct task_struct *p, *p2, *p3;
65388+ struct files_struct *files;
65389+ struct fdtable *fdt;
65390+ struct file *our_file = NULL, *file;
65391+ int i;
65392+
65393+ if (task->signal->tty == NULL)
65394+ return 1;
65395+
65396+ files = get_files_struct(task);
65397+ if (files != NULL) {
65398+ rcu_read_lock();
65399+ fdt = files_fdtable(files);
65400+ for (i=0; i < fdt->max_fds; i++) {
65401+ file = fcheck_files(files, i);
65402+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
65403+ get_file(file);
65404+ our_file = file;
65405+ }
65406+ }
65407+ rcu_read_unlock();
65408+ put_files_struct(files);
65409+ }
65410+
65411+ if (our_file == NULL)
65412+ return 1;
65413+
65414+ read_lock(&tasklist_lock);
65415+ do_each_thread(p2, p) {
65416+ files = get_files_struct(p);
65417+ if (files == NULL ||
65418+ (p->signal && p->signal->tty == task->signal->tty)) {
65419+ if (files != NULL)
65420+ put_files_struct(files);
65421+ continue;
65422+ }
65423+ rcu_read_lock();
65424+ fdt = files_fdtable(files);
65425+ for (i=0; i < fdt->max_fds; i++) {
65426+ file = fcheck_files(files, i);
65427+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
65428+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
65429+ p3 = task;
65430+ while (task_pid_nr(p3) > 0) {
65431+ if (p3 == p)
65432+ break;
65433+ p3 = p3->real_parent;
65434+ }
65435+ if (p3 == p)
65436+ break;
65437+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
65438+ gr_handle_alertkill(p);
65439+ rcu_read_unlock();
65440+ put_files_struct(files);
65441+ read_unlock(&tasklist_lock);
65442+ fput(our_file);
65443+ return 0;
65444+ }
65445+ }
65446+ rcu_read_unlock();
65447+ put_files_struct(files);
65448+ } while_each_thread(p2, p);
65449+ read_unlock(&tasklist_lock);
65450+
65451+ fput(our_file);
65452+ return 1;
65453+}
65454+
65455+static int gr_rbac_disable(void *unused)
65456+{
65457+ pax_open_kernel();
65458+ gr_status &= ~GR_READY;
65459+ pax_close_kernel();
65460+
65461+ return 0;
65462+}
65463+
65464+ssize_t
65465+write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
65466+{
65467+ struct gr_arg_wrapper uwrap;
65468+ unsigned char *sprole_salt = NULL;
65469+ unsigned char *sprole_sum = NULL;
65470+ int error = 0;
65471+ int error2 = 0;
65472+ size_t req_count = 0;
65473+
65474+ mutex_lock(&gr_dev_mutex);
65475+
65476+ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
65477+ error = -EPERM;
65478+ goto out;
65479+ }
65480+
65481+#ifdef CONFIG_COMPAT
65482+ pax_open_kernel();
65483+ if (is_compat_task()) {
65484+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
65485+ copy_gr_arg = &copy_gr_arg_compat;
65486+ copy_acl_object_label = &copy_acl_object_label_compat;
65487+ copy_acl_subject_label = &copy_acl_subject_label_compat;
65488+ copy_acl_role_label = &copy_acl_role_label_compat;
65489+ copy_acl_ip_label = &copy_acl_ip_label_compat;
65490+ copy_role_allowed_ip = &copy_role_allowed_ip_compat;
65491+ copy_role_transition = &copy_role_transition_compat;
65492+ copy_sprole_pw = &copy_sprole_pw_compat;
65493+ copy_gr_hash_struct = &copy_gr_hash_struct_compat;
65494+ copy_pointer_from_array = &copy_pointer_from_array_compat;
65495+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
65496+ } else {
65497+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
65498+ copy_gr_arg = &copy_gr_arg_normal;
65499+ copy_acl_object_label = &copy_acl_object_label_normal;
65500+ copy_acl_subject_label = &copy_acl_subject_label_normal;
65501+ copy_acl_role_label = &copy_acl_role_label_normal;
65502+ copy_acl_ip_label = &copy_acl_ip_label_normal;
65503+ copy_role_allowed_ip = &copy_role_allowed_ip_normal;
65504+ copy_role_transition = &copy_role_transition_normal;
65505+ copy_sprole_pw = &copy_sprole_pw_normal;
65506+ copy_gr_hash_struct = &copy_gr_hash_struct_normal;
65507+ copy_pointer_from_array = &copy_pointer_from_array_normal;
65508+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
65509+ }
65510+ pax_close_kernel();
65511+#endif
65512+
65513+ req_count = get_gr_arg_wrapper_size();
65514+
65515+ if (count != req_count) {
65516+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
65517+ error = -EINVAL;
65518+ goto out;
65519+ }
65520+
65521+
65522+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
65523+ gr_auth_expires = 0;
65524+ gr_auth_attempts = 0;
65525+ }
65526+
65527+ error = copy_gr_arg_wrapper(buf, &uwrap);
65528+ if (error)
65529+ goto out;
65530+
65531+ error = copy_gr_arg(uwrap.arg, gr_usermode);
65532+ if (error)
65533+ goto out;
65534+
65535+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
65536+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
65537+ time_after(gr_auth_expires, get_seconds())) {
65538+ error = -EBUSY;
65539+ goto out;
65540+ }
65541+
65542+ /* if non-root trying to do anything other than use a special role,
65543+ do not attempt authentication, do not count towards authentication
65544+ locking
65545+ */
65546+
65547+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
65548+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
65549+ gr_is_global_nonroot(current_uid())) {
65550+ error = -EPERM;
65551+ goto out;
65552+ }
65553+
65554+ /* ensure pw and special role name are null terminated */
65555+
65556+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
65557+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
65558+
65559+ /* Okay.
65560+ * We have our enough of the argument structure..(we have yet
65561+ * to copy_from_user the tables themselves) . Copy the tables
65562+ * only if we need them, i.e. for loading operations. */
65563+
65564+ switch (gr_usermode->mode) {
65565+ case GR_STATUS:
65566+ if (gr_status & GR_READY) {
65567+ error = 1;
65568+ if (!gr_check_secure_terminal(current))
65569+ error = 3;
65570+ } else
65571+ error = 2;
65572+ goto out;
65573+ case GR_SHUTDOWN:
65574+ if ((gr_status & GR_READY)
65575+ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
65576+ stop_machine(gr_rbac_disable, NULL, NULL);
65577+ free_variables();
65578+ memset(gr_usermode, 0, sizeof (struct gr_arg));
65579+ memset(gr_system_salt, 0, GR_SALT_LEN);
65580+ memset(gr_system_sum, 0, GR_SHA_LEN);
65581+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
65582+ } else if (gr_status & GR_READY) {
65583+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
65584+ error = -EPERM;
65585+ } else {
65586+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
65587+ error = -EAGAIN;
65588+ }
65589+ break;
65590+ case GR_ENABLE:
65591+ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
65592+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
65593+ else {
65594+ if (gr_status & GR_READY)
65595+ error = -EAGAIN;
65596+ else
65597+ error = error2;
65598+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
65599+ }
65600+ break;
65601+ case GR_RELOAD:
65602+ if (!(gr_status & GR_READY)) {
65603+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
65604+ error = -EAGAIN;
65605+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
65606+ stop_machine(gr_rbac_disable, NULL, NULL);
65607+ free_variables();
65608+ error2 = gracl_init(gr_usermode);
65609+ if (!error2)
65610+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
65611+ else {
65612+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
65613+ error = error2;
65614+ }
65615+ } else {
65616+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
65617+ error = -EPERM;
65618+ }
65619+ break;
65620+ case GR_SEGVMOD:
65621+ if (unlikely(!(gr_status & GR_READY))) {
65622+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
65623+ error = -EAGAIN;
65624+ break;
65625+ }
65626+
65627+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
65628+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
65629+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
65630+ struct acl_subject_label *segvacl;
65631+ segvacl =
65632+ lookup_acl_subj_label(gr_usermode->segv_inode,
65633+ gr_usermode->segv_device,
65634+ current->role);
65635+ if (segvacl) {
65636+ segvacl->crashes = 0;
65637+ segvacl->expires = 0;
65638+ }
65639+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
65640+ gr_remove_uid(gr_usermode->segv_uid);
65641+ }
65642+ } else {
65643+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
65644+ error = -EPERM;
65645+ }
65646+ break;
65647+ case GR_SPROLE:
65648+ case GR_SPROLEPAM:
65649+ if (unlikely(!(gr_status & GR_READY))) {
65650+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
65651+ error = -EAGAIN;
65652+ break;
65653+ }
65654+
65655+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
65656+ current->role->expires = 0;
65657+ current->role->auth_attempts = 0;
65658+ }
65659+
65660+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
65661+ time_after(current->role->expires, get_seconds())) {
65662+ error = -EBUSY;
65663+ goto out;
65664+ }
65665+
65666+ if (lookup_special_role_auth
65667+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
65668+ && ((!sprole_salt && !sprole_sum)
65669+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
65670+ char *p = "";
65671+ assign_special_role(gr_usermode->sp_role);
65672+ read_lock(&tasklist_lock);
65673+ if (current->real_parent)
65674+ p = current->real_parent->role->rolename;
65675+ read_unlock(&tasklist_lock);
65676+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
65677+ p, acl_sp_role_value);
65678+ } else {
65679+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
65680+ error = -EPERM;
65681+ if(!(current->role->auth_attempts++))
65682+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
65683+
65684+ goto out;
65685+ }
65686+ break;
65687+ case GR_UNSPROLE:
65688+ if (unlikely(!(gr_status & GR_READY))) {
65689+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
65690+ error = -EAGAIN;
65691+ break;
65692+ }
65693+
65694+ if (current->role->roletype & GR_ROLE_SPECIAL) {
65695+ char *p = "";
65696+ int i = 0;
65697+
65698+ read_lock(&tasklist_lock);
65699+ if (current->real_parent) {
65700+ p = current->real_parent->role->rolename;
65701+ i = current->real_parent->acl_role_id;
65702+ }
65703+ read_unlock(&tasklist_lock);
65704+
65705+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
65706+ gr_set_acls(1);
65707+ } else {
65708+ error = -EPERM;
65709+ goto out;
65710+ }
65711+ break;
65712+ default:
65713+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
65714+ error = -EINVAL;
65715+ break;
65716+ }
65717+
65718+ if (error != -EPERM)
65719+ goto out;
65720+
65721+ if(!(gr_auth_attempts++))
65722+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
65723+
65724+ out:
65725+ mutex_unlock(&gr_dev_mutex);
65726+
65727+ if (!error)
65728+ error = req_count;
65729+
65730+ return error;
65731+}
65732+
65733+/* must be called with
65734+ rcu_read_lock();
65735+ read_lock(&tasklist_lock);
65736+ read_lock(&grsec_exec_file_lock);
65737+*/
65738+int gr_apply_subject_to_task(struct task_struct *task)
65739+{
65740+ struct acl_object_label *obj;
65741+ char *tmpname;
65742+ struct acl_subject_label *tmpsubj;
65743+ struct file *filp;
65744+ struct name_entry *nmatch;
65745+
65746+ filp = task->exec_file;
65747+ if (filp == NULL)
65748+ return 0;
65749+
65750+ /* the following is to apply the correct subject
65751+ on binaries running when the RBAC system
65752+ is enabled, when the binaries have been
65753+ replaced or deleted since their execution
65754+ -----
65755+ when the RBAC system starts, the inode/dev
65756+ from exec_file will be one the RBAC system
65757+ is unaware of. It only knows the inode/dev
65758+ of the present file on disk, or the absence
65759+ of it.
65760+ */
65761+ preempt_disable();
65762+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
65763+
65764+ nmatch = lookup_name_entry(tmpname);
65765+ preempt_enable();
65766+ tmpsubj = NULL;
65767+ if (nmatch) {
65768+ if (nmatch->deleted)
65769+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
65770+ else
65771+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
65772+ if (tmpsubj != NULL)
65773+ task->acl = tmpsubj;
65774+ }
65775+ if (tmpsubj == NULL)
65776+ task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
65777+ task->role);
65778+ if (task->acl) {
65779+ task->is_writable = 0;
65780+ /* ignore additional mmap checks for processes that are writable
65781+ by the default ACL */
65782+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
65783+ if (unlikely(obj->mode & GR_WRITE))
65784+ task->is_writable = 1;
65785+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
65786+ if (unlikely(obj->mode & GR_WRITE))
65787+ task->is_writable = 1;
65788+
65789+ gr_set_proc_res(task);
65790+
65791+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
65792+ 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);
65793+#endif
65794+ } else {
65795+ return 1;
65796+ }
65797+
65798+ return 0;
65799+}
65800+
65801+int
65802+gr_set_acls(const int type)
65803+{
65804+ struct task_struct *task, *task2;
65805+ struct acl_role_label *role = current->role;
65806+ __u16 acl_role_id = current->acl_role_id;
65807+ const struct cred *cred;
65808+ int ret;
65809+
65810+ rcu_read_lock();
65811+ read_lock(&tasklist_lock);
65812+ read_lock(&grsec_exec_file_lock);
65813+ do_each_thread(task2, task) {
65814+ /* check to see if we're called from the exit handler,
65815+ if so, only replace ACLs that have inherited the admin
65816+ ACL */
65817+
65818+ if (type && (task->role != role ||
65819+ task->acl_role_id != acl_role_id))
65820+ continue;
65821+
65822+ task->acl_role_id = 0;
65823+ task->acl_sp_role = 0;
65824+
65825+ if (task->exec_file) {
65826+ cred = __task_cred(task);
65827+ task->role = lookup_acl_role_label(task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
65828+ ret = gr_apply_subject_to_task(task);
65829+ if (ret) {
65830+ read_unlock(&grsec_exec_file_lock);
65831+ read_unlock(&tasklist_lock);
65832+ rcu_read_unlock();
65833+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
65834+ return ret;
65835+ }
65836+ } else {
65837+ // it's a kernel process
65838+ task->role = kernel_role;
65839+ task->acl = kernel_role->root_label;
65840+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
65841+ task->acl->mode &= ~GR_PROCFIND;
65842+#endif
65843+ }
65844+ } while_each_thread(task2, task);
65845+ read_unlock(&grsec_exec_file_lock);
65846+ read_unlock(&tasklist_lock);
65847+ rcu_read_unlock();
65848+
65849+ return 0;
65850+}
65851+
65852+#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
65853+static const unsigned long res_learn_bumps[GR_NLIMITS] = {
65854+ [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
65855+ [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
65856+ [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
65857+ [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
65858+ [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
65859+ [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
65860+ [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
65861+ [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
65862+ [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
65863+ [RLIMIT_AS] = GR_RLIM_AS_BUMP,
65864+ [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
65865+ [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
65866+ [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
65867+ [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
65868+ [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
65869+ [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
65870+};
65871+
65872+void
65873+gr_learn_resource(const struct task_struct *task,
65874+ const int res, const unsigned long wanted, const int gt)
65875+{
65876+ struct acl_subject_label *acl;
65877+ const struct cred *cred;
65878+
65879+ if (unlikely((gr_status & GR_READY) &&
65880+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
65881+ goto skip_reslog;
65882+
65883+ gr_log_resource(task, res, wanted, gt);
65884+skip_reslog:
65885+
65886+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
65887+ return;
65888+
65889+ acl = task->acl;
65890+
65891+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
65892+ !(acl->resmask & (1U << (unsigned short) res))))
65893+ return;
65894+
65895+ if (wanted >= acl->res[res].rlim_cur) {
65896+ unsigned long res_add;
65897+
65898+ res_add = wanted + res_learn_bumps[res];
65899+
65900+ acl->res[res].rlim_cur = res_add;
65901+
65902+ if (wanted > acl->res[res].rlim_max)
65903+ acl->res[res].rlim_max = res_add;
65904+
65905+ /* only log the subject filename, since resource logging is supported for
65906+ single-subject learning only */
65907+ rcu_read_lock();
65908+ cred = __task_cred(task);
65909+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
65910+ task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
65911+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
65912+ "", (unsigned long) res, &task->signal->saved_ip);
65913+ rcu_read_unlock();
65914+ }
65915+
65916+ return;
65917+}
65918+EXPORT_SYMBOL(gr_learn_resource);
65919+#endif
65920+
65921+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
65922+void
65923+pax_set_initial_flags(struct linux_binprm *bprm)
65924+{
65925+ struct task_struct *task = current;
65926+ struct acl_subject_label *proc;
65927+ unsigned long flags;
65928+
65929+ if (unlikely(!(gr_status & GR_READY)))
65930+ return;
65931+
65932+ flags = pax_get_flags(task);
65933+
65934+ proc = task->acl;
65935+
65936+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
65937+ flags &= ~MF_PAX_PAGEEXEC;
65938+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
65939+ flags &= ~MF_PAX_SEGMEXEC;
65940+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
65941+ flags &= ~MF_PAX_RANDMMAP;
65942+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
65943+ flags &= ~MF_PAX_EMUTRAMP;
65944+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
65945+ flags &= ~MF_PAX_MPROTECT;
65946+
65947+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
65948+ flags |= MF_PAX_PAGEEXEC;
65949+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
65950+ flags |= MF_PAX_SEGMEXEC;
65951+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
65952+ flags |= MF_PAX_RANDMMAP;
65953+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
65954+ flags |= MF_PAX_EMUTRAMP;
65955+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
65956+ flags |= MF_PAX_MPROTECT;
65957+
65958+ pax_set_flags(task, flags);
65959+
65960+ return;
65961+}
65962+#endif
65963+
65964+int
65965+gr_handle_proc_ptrace(struct task_struct *task)
65966+{
65967+ struct file *filp;
65968+ struct task_struct *tmp = task;
65969+ struct task_struct *curtemp = current;
65970+ __u32 retmode;
65971+
65972+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
65973+ if (unlikely(!(gr_status & GR_READY)))
65974+ return 0;
65975+#endif
65976+
65977+ read_lock(&tasklist_lock);
65978+ read_lock(&grsec_exec_file_lock);
65979+ filp = task->exec_file;
65980+
65981+ while (task_pid_nr(tmp) > 0) {
65982+ if (tmp == curtemp)
65983+ break;
65984+ tmp = tmp->real_parent;
65985+ }
65986+
65987+ if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
65988+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
65989+ read_unlock(&grsec_exec_file_lock);
65990+ read_unlock(&tasklist_lock);
65991+ return 1;
65992+ }
65993+
65994+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
65995+ if (!(gr_status & GR_READY)) {
65996+ read_unlock(&grsec_exec_file_lock);
65997+ read_unlock(&tasklist_lock);
65998+ return 0;
65999+ }
66000+#endif
66001+
66002+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
66003+ read_unlock(&grsec_exec_file_lock);
66004+ read_unlock(&tasklist_lock);
66005+
66006+ if (retmode & GR_NOPTRACE)
66007+ return 1;
66008+
66009+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
66010+ && (current->acl != task->acl || (current->acl != current->role->root_label
66011+ && task_pid_nr(current) != task_pid_nr(task))))
66012+ return 1;
66013+
66014+ return 0;
66015+}
66016+
66017+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
66018+{
66019+ if (unlikely(!(gr_status & GR_READY)))
66020+ return;
66021+
66022+ if (!(current->role->roletype & GR_ROLE_GOD))
66023+ return;
66024+
66025+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
66026+ p->role->rolename, gr_task_roletype_to_char(p),
66027+ p->acl->filename);
66028+}
66029+
66030+int
66031+gr_handle_ptrace(struct task_struct *task, const long request)
66032+{
66033+ struct task_struct *tmp = task;
66034+ struct task_struct *curtemp = current;
66035+ __u32 retmode;
66036+
66037+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
66038+ if (unlikely(!(gr_status & GR_READY)))
66039+ return 0;
66040+#endif
66041+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
66042+ read_lock(&tasklist_lock);
66043+ while (task_pid_nr(tmp) > 0) {
66044+ if (tmp == curtemp)
66045+ break;
66046+ tmp = tmp->real_parent;
66047+ }
66048+
66049+ if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
66050+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
66051+ read_unlock(&tasklist_lock);
66052+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
66053+ return 1;
66054+ }
66055+ read_unlock(&tasklist_lock);
66056+ }
66057+
66058+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
66059+ if (!(gr_status & GR_READY))
66060+ return 0;
66061+#endif
66062+
66063+ read_lock(&grsec_exec_file_lock);
66064+ if (unlikely(!task->exec_file)) {
66065+ read_unlock(&grsec_exec_file_lock);
66066+ return 0;
66067+ }
66068+
66069+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
66070+ read_unlock(&grsec_exec_file_lock);
66071+
66072+ if (retmode & GR_NOPTRACE) {
66073+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
66074+ return 1;
66075+ }
66076+
66077+ if (retmode & GR_PTRACERD) {
66078+ switch (request) {
66079+ case PTRACE_SEIZE:
66080+ case PTRACE_POKETEXT:
66081+ case PTRACE_POKEDATA:
66082+ case PTRACE_POKEUSR:
66083+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
66084+ case PTRACE_SETREGS:
66085+ case PTRACE_SETFPREGS:
66086+#endif
66087+#ifdef CONFIG_X86
66088+ case PTRACE_SETFPXREGS:
66089+#endif
66090+#ifdef CONFIG_ALTIVEC
66091+ case PTRACE_SETVRREGS:
66092+#endif
66093+ return 1;
66094+ default:
66095+ return 0;
66096+ }
66097+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
66098+ !(current->role->roletype & GR_ROLE_GOD) &&
66099+ (current->acl != task->acl)) {
66100+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
66101+ return 1;
66102+ }
66103+
66104+ return 0;
66105+}
66106+
66107+static int is_writable_mmap(const struct file *filp)
66108+{
66109+ struct task_struct *task = current;
66110+ struct acl_object_label *obj, *obj2;
66111+
66112+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
66113+ !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))) {
66114+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
66115+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
66116+ task->role->root_label);
66117+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
66118+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
66119+ return 1;
66120+ }
66121+ }
66122+ return 0;
66123+}
66124+
66125+int
66126+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
66127+{
66128+ __u32 mode;
66129+
66130+ if (unlikely(!file || !(prot & PROT_EXEC)))
66131+ return 1;
66132+
66133+ if (is_writable_mmap(file))
66134+ return 0;
66135+
66136+ mode =
66137+ gr_search_file(file->f_path.dentry,
66138+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
66139+ file->f_path.mnt);
66140+
66141+ if (!gr_tpe_allow(file))
66142+ return 0;
66143+
66144+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
66145+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
66146+ return 0;
66147+ } else if (unlikely(!(mode & GR_EXEC))) {
66148+ return 0;
66149+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
66150+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
66151+ return 1;
66152+ }
66153+
66154+ return 1;
66155+}
66156+
66157+int
66158+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
66159+{
66160+ __u32 mode;
66161+
66162+ if (unlikely(!file || !(prot & PROT_EXEC)))
66163+ return 1;
66164+
66165+ if (is_writable_mmap(file))
66166+ return 0;
66167+
66168+ mode =
66169+ gr_search_file(file->f_path.dentry,
66170+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
66171+ file->f_path.mnt);
66172+
66173+ if (!gr_tpe_allow(file))
66174+ return 0;
66175+
66176+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
66177+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
66178+ return 0;
66179+ } else if (unlikely(!(mode & GR_EXEC))) {
66180+ return 0;
66181+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
66182+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
66183+ return 1;
66184+ }
66185+
66186+ return 1;
66187+}
66188+
66189+void
66190+gr_acl_handle_psacct(struct task_struct *task, const long code)
66191+{
66192+ unsigned long runtime;
66193+ unsigned long cputime;
66194+ unsigned int wday, cday;
66195+ __u8 whr, chr;
66196+ __u8 wmin, cmin;
66197+ __u8 wsec, csec;
66198+ struct timespec timeval;
66199+
66200+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
66201+ !(task->acl->mode & GR_PROCACCT)))
66202+ return;
66203+
66204+ do_posix_clock_monotonic_gettime(&timeval);
66205+ runtime = timeval.tv_sec - task->start_time.tv_sec;
66206+ wday = runtime / (3600 * 24);
66207+ runtime -= wday * (3600 * 24);
66208+ whr = runtime / 3600;
66209+ runtime -= whr * 3600;
66210+ wmin = runtime / 60;
66211+ runtime -= wmin * 60;
66212+ wsec = runtime;
66213+
66214+ cputime = (task->utime + task->stime) / HZ;
66215+ cday = cputime / (3600 * 24);
66216+ cputime -= cday * (3600 * 24);
66217+ chr = cputime / 3600;
66218+ cputime -= chr * 3600;
66219+ cmin = cputime / 60;
66220+ cputime -= cmin * 60;
66221+ csec = cputime;
66222+
66223+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
66224+
66225+ return;
66226+}
66227+
66228+void gr_set_kernel_label(struct task_struct *task)
66229+{
66230+ if (gr_status & GR_READY) {
66231+ task->role = kernel_role;
66232+ task->acl = kernel_role->root_label;
66233+ }
66234+ return;
66235+}
66236+
66237+#ifdef CONFIG_TASKSTATS
66238+int gr_is_taskstats_denied(int pid)
66239+{
66240+ struct task_struct *task;
66241+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66242+ const struct cred *cred;
66243+#endif
66244+ int ret = 0;
66245+
66246+ /* restrict taskstats viewing to un-chrooted root users
66247+ who have the 'view' subject flag if the RBAC system is enabled
66248+ */
66249+
66250+ rcu_read_lock();
66251+ read_lock(&tasklist_lock);
66252+ task = find_task_by_vpid(pid);
66253+ if (task) {
66254+#ifdef CONFIG_GRKERNSEC_CHROOT
66255+ if (proc_is_chrooted(task))
66256+ ret = -EACCES;
66257+#endif
66258+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66259+ cred = __task_cred(task);
66260+#ifdef CONFIG_GRKERNSEC_PROC_USER
66261+ if (gr_is_global_nonroot(cred->uid))
66262+ ret = -EACCES;
66263+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66264+ if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
66265+ ret = -EACCES;
66266+#endif
66267+#endif
66268+ if (gr_status & GR_READY) {
66269+ if (!(task->acl->mode & GR_VIEW))
66270+ ret = -EACCES;
66271+ }
66272+ } else
66273+ ret = -ENOENT;
66274+
66275+ read_unlock(&tasklist_lock);
66276+ rcu_read_unlock();
66277+
66278+ return ret;
66279+}
66280+#endif
66281+
66282+/* AUXV entries are filled via a descendant of search_binary_handler
66283+ after we've already applied the subject for the target
66284+*/
66285+int gr_acl_enable_at_secure(void)
66286+{
66287+ if (unlikely(!(gr_status & GR_READY)))
66288+ return 0;
66289+
66290+ if (current->acl->mode & GR_ATSECURE)
66291+ return 1;
66292+
66293+ return 0;
66294+}
66295+
66296+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
66297+{
66298+ struct task_struct *task = current;
66299+ struct dentry *dentry = file->f_path.dentry;
66300+ struct vfsmount *mnt = file->f_path.mnt;
66301+ struct acl_object_label *obj, *tmp;
66302+ struct acl_subject_label *subj;
66303+ unsigned int bufsize;
66304+ int is_not_root;
66305+ char *path;
66306+ dev_t dev = __get_dev(dentry);
66307+
66308+ if (unlikely(!(gr_status & GR_READY)))
66309+ return 1;
66310+
66311+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
66312+ return 1;
66313+
66314+ /* ignore Eric Biederman */
66315+ if (IS_PRIVATE(dentry->d_inode))
66316+ return 1;
66317+
66318+ subj = task->acl;
66319+ read_lock(&gr_inode_lock);
66320+ do {
66321+ obj = lookup_acl_obj_label(ino, dev, subj);
66322+ if (obj != NULL) {
66323+ read_unlock(&gr_inode_lock);
66324+ return (obj->mode & GR_FIND) ? 1 : 0;
66325+ }
66326+ } while ((subj = subj->parent_subject));
66327+ read_unlock(&gr_inode_lock);
66328+
66329+ /* this is purely an optimization since we're looking for an object
66330+ for the directory we're doing a readdir on
66331+ if it's possible for any globbed object to match the entry we're
66332+ filling into the directory, then the object we find here will be
66333+ an anchor point with attached globbed objects
66334+ */
66335+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
66336+ if (obj->globbed == NULL)
66337+ return (obj->mode & GR_FIND) ? 1 : 0;
66338+
66339+ is_not_root = ((obj->filename[0] == '/') &&
66340+ (obj->filename[1] == '\0')) ? 0 : 1;
66341+ bufsize = PAGE_SIZE - namelen - is_not_root;
66342+
66343+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
66344+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
66345+ return 1;
66346+
66347+ preempt_disable();
66348+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
66349+ bufsize);
66350+
66351+ bufsize = strlen(path);
66352+
66353+ /* if base is "/", don't append an additional slash */
66354+ if (is_not_root)
66355+ *(path + bufsize) = '/';
66356+ memcpy(path + bufsize + is_not_root, name, namelen);
66357+ *(path + bufsize + namelen + is_not_root) = '\0';
66358+
66359+ tmp = obj->globbed;
66360+ while (tmp) {
66361+ if (!glob_match(tmp->filename, path)) {
66362+ preempt_enable();
66363+ return (tmp->mode & GR_FIND) ? 1 : 0;
66364+ }
66365+ tmp = tmp->next;
66366+ }
66367+ preempt_enable();
66368+ return (obj->mode & GR_FIND) ? 1 : 0;
66369+}
66370+
66371+void gr_put_exec_file(struct task_struct *task)
66372+{
66373+ struct file *filp;
66374+
66375+ write_lock(&grsec_exec_file_lock);
66376+ filp = task->exec_file;
66377+ task->exec_file = NULL;
66378+ write_unlock(&grsec_exec_file_lock);
66379+
66380+ if (filp)
66381+ fput(filp);
66382+
66383+ return;
66384+}
66385+
66386+
66387+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
66388+EXPORT_SYMBOL(gr_acl_is_enabled);
66389+#endif
66390+EXPORT_SYMBOL(gr_set_kernel_label);
66391+#ifdef CONFIG_SECURITY
66392+EXPORT_SYMBOL(gr_check_user_change);
66393+EXPORT_SYMBOL(gr_check_group_change);
66394+#endif
66395+
66396diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
66397new file mode 100644
66398index 0000000..34fefda
66399--- /dev/null
66400+++ b/grsecurity/gracl_alloc.c
66401@@ -0,0 +1,105 @@
66402+#include <linux/kernel.h>
66403+#include <linux/mm.h>
66404+#include <linux/slab.h>
66405+#include <linux/vmalloc.h>
66406+#include <linux/gracl.h>
66407+#include <linux/grsecurity.h>
66408+
66409+static unsigned long alloc_stack_next = 1;
66410+static unsigned long alloc_stack_size = 1;
66411+static void **alloc_stack;
66412+
66413+static __inline__ int
66414+alloc_pop(void)
66415+{
66416+ if (alloc_stack_next == 1)
66417+ return 0;
66418+
66419+ kfree(alloc_stack[alloc_stack_next - 2]);
66420+
66421+ alloc_stack_next--;
66422+
66423+ return 1;
66424+}
66425+
66426+static __inline__ int
66427+alloc_push(void *buf)
66428+{
66429+ if (alloc_stack_next >= alloc_stack_size)
66430+ return 1;
66431+
66432+ alloc_stack[alloc_stack_next - 1] = buf;
66433+
66434+ alloc_stack_next++;
66435+
66436+ return 0;
66437+}
66438+
66439+void *
66440+acl_alloc(unsigned long len)
66441+{
66442+ void *ret = NULL;
66443+
66444+ if (!len || len > PAGE_SIZE)
66445+ goto out;
66446+
66447+ ret = kmalloc(len, GFP_KERNEL);
66448+
66449+ if (ret) {
66450+ if (alloc_push(ret)) {
66451+ kfree(ret);
66452+ ret = NULL;
66453+ }
66454+ }
66455+
66456+out:
66457+ return ret;
66458+}
66459+
66460+void *
66461+acl_alloc_num(unsigned long num, unsigned long len)
66462+{
66463+ if (!len || (num > (PAGE_SIZE / len)))
66464+ return NULL;
66465+
66466+ return acl_alloc(num * len);
66467+}
66468+
66469+void
66470+acl_free_all(void)
66471+{
66472+ if (gr_acl_is_enabled() || !alloc_stack)
66473+ return;
66474+
66475+ while (alloc_pop()) ;
66476+
66477+ if (alloc_stack) {
66478+ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
66479+ kfree(alloc_stack);
66480+ else
66481+ vfree(alloc_stack);
66482+ }
66483+
66484+ alloc_stack = NULL;
66485+ alloc_stack_size = 1;
66486+ alloc_stack_next = 1;
66487+
66488+ return;
66489+}
66490+
66491+int
66492+acl_alloc_stack_init(unsigned long size)
66493+{
66494+ if ((size * sizeof (void *)) <= PAGE_SIZE)
66495+ alloc_stack =
66496+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
66497+ else
66498+ alloc_stack = (void **) vmalloc(size * sizeof (void *));
66499+
66500+ alloc_stack_size = size;
66501+
66502+ if (!alloc_stack)
66503+ return 0;
66504+ else
66505+ return 1;
66506+}
66507diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
66508new file mode 100644
66509index 0000000..bdd51ea
66510--- /dev/null
66511+++ b/grsecurity/gracl_cap.c
66512@@ -0,0 +1,110 @@
66513+#include <linux/kernel.h>
66514+#include <linux/module.h>
66515+#include <linux/sched.h>
66516+#include <linux/gracl.h>
66517+#include <linux/grsecurity.h>
66518+#include <linux/grinternal.h>
66519+
66520+extern const char *captab_log[];
66521+extern int captab_log_entries;
66522+
66523+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
66524+{
66525+ struct acl_subject_label *curracl;
66526+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
66527+ kernel_cap_t cap_audit = __cap_empty_set;
66528+
66529+ if (!gr_acl_is_enabled())
66530+ return 1;
66531+
66532+ curracl = task->acl;
66533+
66534+ cap_drop = curracl->cap_lower;
66535+ cap_mask = curracl->cap_mask;
66536+ cap_audit = curracl->cap_invert_audit;
66537+
66538+ while ((curracl = curracl->parent_subject)) {
66539+ /* if the cap isn't specified in the current computed mask but is specified in the
66540+ current level subject, and is lowered in the current level subject, then add
66541+ it to the set of dropped capabilities
66542+ otherwise, add the current level subject's mask to the current computed mask
66543+ */
66544+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
66545+ cap_raise(cap_mask, cap);
66546+ if (cap_raised(curracl->cap_lower, cap))
66547+ cap_raise(cap_drop, cap);
66548+ if (cap_raised(curracl->cap_invert_audit, cap))
66549+ cap_raise(cap_audit, cap);
66550+ }
66551+ }
66552+
66553+ if (!cap_raised(cap_drop, cap)) {
66554+ if (cap_raised(cap_audit, cap))
66555+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
66556+ return 1;
66557+ }
66558+
66559+ curracl = task->acl;
66560+
66561+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
66562+ && cap_raised(cred->cap_effective, cap)) {
66563+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
66564+ task->role->roletype, GR_GLOBAL_UID(cred->uid),
66565+ GR_GLOBAL_GID(cred->gid), task->exec_file ?
66566+ gr_to_filename(task->exec_file->f_path.dentry,
66567+ task->exec_file->f_path.mnt) : curracl->filename,
66568+ curracl->filename, 0UL,
66569+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
66570+ return 1;
66571+ }
66572+
66573+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
66574+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
66575+
66576+ return 0;
66577+}
66578+
66579+int
66580+gr_acl_is_capable(const int cap)
66581+{
66582+ return gr_task_acl_is_capable(current, current_cred(), cap);
66583+}
66584+
66585+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
66586+{
66587+ struct acl_subject_label *curracl;
66588+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
66589+
66590+ if (!gr_acl_is_enabled())
66591+ return 1;
66592+
66593+ curracl = task->acl;
66594+
66595+ cap_drop = curracl->cap_lower;
66596+ cap_mask = curracl->cap_mask;
66597+
66598+ while ((curracl = curracl->parent_subject)) {
66599+ /* if the cap isn't specified in the current computed mask but is specified in the
66600+ current level subject, and is lowered in the current level subject, then add
66601+ it to the set of dropped capabilities
66602+ otherwise, add the current level subject's mask to the current computed mask
66603+ */
66604+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
66605+ cap_raise(cap_mask, cap);
66606+ if (cap_raised(curracl->cap_lower, cap))
66607+ cap_raise(cap_drop, cap);
66608+ }
66609+ }
66610+
66611+ if (!cap_raised(cap_drop, cap))
66612+ return 1;
66613+
66614+ return 0;
66615+}
66616+
66617+int
66618+gr_acl_is_capable_nolog(const int cap)
66619+{
66620+ return gr_task_acl_is_capable_nolog(current, cap);
66621+}
66622+
66623diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
66624new file mode 100644
66625index 0000000..a43dd06
66626--- /dev/null
66627+++ b/grsecurity/gracl_compat.c
66628@@ -0,0 +1,269 @@
66629+#include <linux/kernel.h>
66630+#include <linux/gracl.h>
66631+#include <linux/compat.h>
66632+#include <linux/gracl_compat.h>
66633+
66634+#include <asm/uaccess.h>
66635+
66636+int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
66637+{
66638+ struct gr_arg_wrapper_compat uwrapcompat;
66639+
66640+ if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
66641+ return -EFAULT;
66642+
66643+ if ((uwrapcompat.version != GRSECURITY_VERSION) ||
66644+ (uwrapcompat.size != sizeof(struct gr_arg_compat)))
66645+ return -EINVAL;
66646+
66647+ uwrap->arg = compat_ptr(uwrapcompat.arg);
66648+ uwrap->version = uwrapcompat.version;
66649+ uwrap->size = sizeof(struct gr_arg);
66650+
66651+ return 0;
66652+}
66653+
66654+int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
66655+{
66656+ struct gr_arg_compat argcompat;
66657+
66658+ if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
66659+ return -EFAULT;
66660+
66661+ arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
66662+ arg->role_db.num_pointers = argcompat.role_db.num_pointers;
66663+ arg->role_db.num_roles = argcompat.role_db.num_roles;
66664+ arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
66665+ arg->role_db.num_subjects = argcompat.role_db.num_subjects;
66666+ arg->role_db.num_objects = argcompat.role_db.num_objects;
66667+
66668+ memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
66669+ memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
66670+ memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
66671+ memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
66672+ arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
66673+ arg->segv_device = argcompat.segv_device;
66674+ arg->segv_inode = argcompat.segv_inode;
66675+ arg->segv_uid = argcompat.segv_uid;
66676+ arg->num_sprole_pws = argcompat.num_sprole_pws;
66677+ arg->mode = argcompat.mode;
66678+
66679+ return 0;
66680+}
66681+
66682+int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
66683+{
66684+ struct acl_object_label_compat objcompat;
66685+
66686+ if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
66687+ return -EFAULT;
66688+
66689+ obj->filename = compat_ptr(objcompat.filename);
66690+ obj->inode = objcompat.inode;
66691+ obj->device = objcompat.device;
66692+ obj->mode = objcompat.mode;
66693+
66694+ obj->nested = compat_ptr(objcompat.nested);
66695+ obj->globbed = compat_ptr(objcompat.globbed);
66696+
66697+ obj->prev = compat_ptr(objcompat.prev);
66698+ obj->next = compat_ptr(objcompat.next);
66699+
66700+ return 0;
66701+}
66702+
66703+int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
66704+{
66705+ unsigned int i;
66706+ struct acl_subject_label_compat subjcompat;
66707+
66708+ if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
66709+ return -EFAULT;
66710+
66711+ subj->filename = compat_ptr(subjcompat.filename);
66712+ subj->inode = subjcompat.inode;
66713+ subj->device = subjcompat.device;
66714+ subj->mode = subjcompat.mode;
66715+ subj->cap_mask = subjcompat.cap_mask;
66716+ subj->cap_lower = subjcompat.cap_lower;
66717+ subj->cap_invert_audit = subjcompat.cap_invert_audit;
66718+
66719+ for (i = 0; i < GR_NLIMITS; i++) {
66720+ if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
66721+ subj->res[i].rlim_cur = RLIM_INFINITY;
66722+ else
66723+ subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
66724+ if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
66725+ subj->res[i].rlim_max = RLIM_INFINITY;
66726+ else
66727+ subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
66728+ }
66729+ subj->resmask = subjcompat.resmask;
66730+
66731+ subj->user_trans_type = subjcompat.user_trans_type;
66732+ subj->group_trans_type = subjcompat.group_trans_type;
66733+ subj->user_transitions = compat_ptr(subjcompat.user_transitions);
66734+ subj->group_transitions = compat_ptr(subjcompat.group_transitions);
66735+ subj->user_trans_num = subjcompat.user_trans_num;
66736+ subj->group_trans_num = subjcompat.group_trans_num;
66737+
66738+ memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
66739+ memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
66740+ subj->ip_type = subjcompat.ip_type;
66741+ subj->ips = compat_ptr(subjcompat.ips);
66742+ subj->ip_num = subjcompat.ip_num;
66743+ subj->inaddr_any_override = subjcompat.inaddr_any_override;
66744+
66745+ subj->crashes = subjcompat.crashes;
66746+ subj->expires = subjcompat.expires;
66747+
66748+ subj->parent_subject = compat_ptr(subjcompat.parent_subject);
66749+ subj->hash = compat_ptr(subjcompat.hash);
66750+ subj->prev = compat_ptr(subjcompat.prev);
66751+ subj->next = compat_ptr(subjcompat.next);
66752+
66753+ subj->obj_hash = compat_ptr(subjcompat.obj_hash);
66754+ subj->obj_hash_size = subjcompat.obj_hash_size;
66755+ subj->pax_flags = subjcompat.pax_flags;
66756+
66757+ return 0;
66758+}
66759+
66760+int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
66761+{
66762+ struct acl_role_label_compat rolecompat;
66763+
66764+ if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
66765+ return -EFAULT;
66766+
66767+ role->rolename = compat_ptr(rolecompat.rolename);
66768+ role->uidgid = rolecompat.uidgid;
66769+ role->roletype = rolecompat.roletype;
66770+
66771+ role->auth_attempts = rolecompat.auth_attempts;
66772+ role->expires = rolecompat.expires;
66773+
66774+ role->root_label = compat_ptr(rolecompat.root_label);
66775+ role->hash = compat_ptr(rolecompat.hash);
66776+
66777+ role->prev = compat_ptr(rolecompat.prev);
66778+ role->next = compat_ptr(rolecompat.next);
66779+
66780+ role->transitions = compat_ptr(rolecompat.transitions);
66781+ role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
66782+ role->domain_children = compat_ptr(rolecompat.domain_children);
66783+ role->domain_child_num = rolecompat.domain_child_num;
66784+
66785+ role->umask = rolecompat.umask;
66786+
66787+ role->subj_hash = compat_ptr(rolecompat.subj_hash);
66788+ role->subj_hash_size = rolecompat.subj_hash_size;
66789+
66790+ return 0;
66791+}
66792+
66793+int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
66794+{
66795+ struct role_allowed_ip_compat roleip_compat;
66796+
66797+ if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
66798+ return -EFAULT;
66799+
66800+ roleip->addr = roleip_compat.addr;
66801+ roleip->netmask = roleip_compat.netmask;
66802+
66803+ roleip->prev = compat_ptr(roleip_compat.prev);
66804+ roleip->next = compat_ptr(roleip_compat.next);
66805+
66806+ return 0;
66807+}
66808+
66809+int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
66810+{
66811+ struct role_transition_compat trans_compat;
66812+
66813+ if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
66814+ return -EFAULT;
66815+
66816+ trans->rolename = compat_ptr(trans_compat.rolename);
66817+
66818+ trans->prev = compat_ptr(trans_compat.prev);
66819+ trans->next = compat_ptr(trans_compat.next);
66820+
66821+ return 0;
66822+
66823+}
66824+
66825+int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
66826+{
66827+ struct gr_hash_struct_compat hash_compat;
66828+
66829+ if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
66830+ return -EFAULT;
66831+
66832+ hash->table = compat_ptr(hash_compat.table);
66833+ hash->nametable = compat_ptr(hash_compat.nametable);
66834+ hash->first = compat_ptr(hash_compat.first);
66835+
66836+ hash->table_size = hash_compat.table_size;
66837+ hash->used_size = hash_compat.used_size;
66838+
66839+ hash->type = hash_compat.type;
66840+
66841+ return 0;
66842+}
66843+
66844+int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
66845+{
66846+ compat_uptr_t ptrcompat;
66847+
66848+ if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
66849+ return -EFAULT;
66850+
66851+ *(void **)ptr = compat_ptr(ptrcompat);
66852+
66853+ return 0;
66854+}
66855+
66856+int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
66857+{
66858+ struct acl_ip_label_compat ip_compat;
66859+
66860+ if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
66861+ return -EFAULT;
66862+
66863+ ip->iface = compat_ptr(ip_compat.iface);
66864+ ip->addr = ip_compat.addr;
66865+ ip->netmask = ip_compat.netmask;
66866+ ip->low = ip_compat.low;
66867+ ip->high = ip_compat.high;
66868+ ip->mode = ip_compat.mode;
66869+ ip->type = ip_compat.type;
66870+
66871+ memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
66872+
66873+ ip->prev = compat_ptr(ip_compat.prev);
66874+ ip->next = compat_ptr(ip_compat.next);
66875+
66876+ return 0;
66877+}
66878+
66879+int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
66880+{
66881+ struct sprole_pw_compat pw_compat;
66882+
66883+ if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
66884+ return -EFAULT;
66885+
66886+ pw->rolename = compat_ptr(pw_compat.rolename);
66887+ memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
66888+ memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
66889+
66890+ return 0;
66891+}
66892+
66893+size_t get_gr_arg_wrapper_size_compat(void)
66894+{
66895+ return sizeof(struct gr_arg_wrapper_compat);
66896+}
66897+
66898diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
66899new file mode 100644
66900index 0000000..a340c17
66901--- /dev/null
66902+++ b/grsecurity/gracl_fs.c
66903@@ -0,0 +1,431 @@
66904+#include <linux/kernel.h>
66905+#include <linux/sched.h>
66906+#include <linux/types.h>
66907+#include <linux/fs.h>
66908+#include <linux/file.h>
66909+#include <linux/stat.h>
66910+#include <linux/grsecurity.h>
66911+#include <linux/grinternal.h>
66912+#include <linux/gracl.h>
66913+
66914+umode_t
66915+gr_acl_umask(void)
66916+{
66917+ if (unlikely(!gr_acl_is_enabled()))
66918+ return 0;
66919+
66920+ return current->role->umask;
66921+}
66922+
66923+__u32
66924+gr_acl_handle_hidden_file(const struct dentry * dentry,
66925+ const struct vfsmount * mnt)
66926+{
66927+ __u32 mode;
66928+
66929+ if (unlikely(!dentry->d_inode))
66930+ return GR_FIND;
66931+
66932+ mode =
66933+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
66934+
66935+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
66936+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
66937+ return mode;
66938+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
66939+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
66940+ return 0;
66941+ } else if (unlikely(!(mode & GR_FIND)))
66942+ return 0;
66943+
66944+ return GR_FIND;
66945+}
66946+
66947+__u32
66948+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
66949+ int acc_mode)
66950+{
66951+ __u32 reqmode = GR_FIND;
66952+ __u32 mode;
66953+
66954+ if (unlikely(!dentry->d_inode))
66955+ return reqmode;
66956+
66957+ if (acc_mode & MAY_APPEND)
66958+ reqmode |= GR_APPEND;
66959+ else if (acc_mode & MAY_WRITE)
66960+ reqmode |= GR_WRITE;
66961+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
66962+ reqmode |= GR_READ;
66963+
66964+ mode =
66965+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
66966+ mnt);
66967+
66968+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
66969+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
66970+ reqmode & GR_READ ? " reading" : "",
66971+ reqmode & GR_WRITE ? " writing" : reqmode &
66972+ GR_APPEND ? " appending" : "");
66973+ return reqmode;
66974+ } else
66975+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
66976+ {
66977+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
66978+ reqmode & GR_READ ? " reading" : "",
66979+ reqmode & GR_WRITE ? " writing" : reqmode &
66980+ GR_APPEND ? " appending" : "");
66981+ return 0;
66982+ } else if (unlikely((mode & reqmode) != reqmode))
66983+ return 0;
66984+
66985+ return reqmode;
66986+}
66987+
66988+__u32
66989+gr_acl_handle_creat(const struct dentry * dentry,
66990+ const struct dentry * p_dentry,
66991+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
66992+ const int imode)
66993+{
66994+ __u32 reqmode = GR_WRITE | GR_CREATE;
66995+ __u32 mode;
66996+
66997+ if (acc_mode & MAY_APPEND)
66998+ reqmode |= GR_APPEND;
66999+ // if a directory was required or the directory already exists, then
67000+ // don't count this open as a read
67001+ if ((acc_mode & MAY_READ) &&
67002+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
67003+ reqmode |= GR_READ;
67004+ if ((open_flags & O_CREAT) &&
67005+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
67006+ reqmode |= GR_SETID;
67007+
67008+ mode =
67009+ gr_check_create(dentry, p_dentry, p_mnt,
67010+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
67011+
67012+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
67013+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
67014+ reqmode & GR_READ ? " reading" : "",
67015+ reqmode & GR_WRITE ? " writing" : reqmode &
67016+ GR_APPEND ? " appending" : "");
67017+ return reqmode;
67018+ } else
67019+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
67020+ {
67021+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
67022+ reqmode & GR_READ ? " reading" : "",
67023+ reqmode & GR_WRITE ? " writing" : reqmode &
67024+ GR_APPEND ? " appending" : "");
67025+ return 0;
67026+ } else if (unlikely((mode & reqmode) != reqmode))
67027+ return 0;
67028+
67029+ return reqmode;
67030+}
67031+
67032+__u32
67033+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
67034+ const int fmode)
67035+{
67036+ __u32 mode, reqmode = GR_FIND;
67037+
67038+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
67039+ reqmode |= GR_EXEC;
67040+ if (fmode & S_IWOTH)
67041+ reqmode |= GR_WRITE;
67042+ if (fmode & S_IROTH)
67043+ reqmode |= GR_READ;
67044+
67045+ mode =
67046+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
67047+ mnt);
67048+
67049+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
67050+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
67051+ reqmode & GR_READ ? " reading" : "",
67052+ reqmode & GR_WRITE ? " writing" : "",
67053+ reqmode & GR_EXEC ? " executing" : "");
67054+ return reqmode;
67055+ } else
67056+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
67057+ {
67058+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
67059+ reqmode & GR_READ ? " reading" : "",
67060+ reqmode & GR_WRITE ? " writing" : "",
67061+ reqmode & GR_EXEC ? " executing" : "");
67062+ return 0;
67063+ } else if (unlikely((mode & reqmode) != reqmode))
67064+ return 0;
67065+
67066+ return reqmode;
67067+}
67068+
67069+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
67070+{
67071+ __u32 mode;
67072+
67073+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
67074+
67075+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
67076+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
67077+ return mode;
67078+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
67079+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
67080+ return 0;
67081+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
67082+ return 0;
67083+
67084+ return (reqmode);
67085+}
67086+
67087+__u32
67088+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
67089+{
67090+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
67091+}
67092+
67093+__u32
67094+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
67095+{
67096+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
67097+}
67098+
67099+__u32
67100+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
67101+{
67102+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
67103+}
67104+
67105+__u32
67106+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
67107+{
67108+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
67109+}
67110+
67111+__u32
67112+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
67113+ umode_t *modeptr)
67114+{
67115+ umode_t mode;
67116+
67117+ *modeptr &= ~gr_acl_umask();
67118+ mode = *modeptr;
67119+
67120+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
67121+ return 1;
67122+
67123+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
67124+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
67125+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
67126+ GR_CHMOD_ACL_MSG);
67127+ } else {
67128+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
67129+ }
67130+}
67131+
67132+__u32
67133+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
67134+{
67135+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
67136+}
67137+
67138+__u32
67139+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
67140+{
67141+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
67142+}
67143+
67144+__u32
67145+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
67146+{
67147+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
67148+}
67149+
67150+__u32
67151+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
67152+{
67153+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
67154+ GR_UNIXCONNECT_ACL_MSG);
67155+}
67156+
67157+/* hardlinks require at minimum create and link permission,
67158+ any additional privilege required is based on the
67159+ privilege of the file being linked to
67160+*/
67161+__u32
67162+gr_acl_handle_link(const struct dentry * new_dentry,
67163+ const struct dentry * parent_dentry,
67164+ const struct vfsmount * parent_mnt,
67165+ const struct dentry * old_dentry,
67166+ const struct vfsmount * old_mnt, const struct filename *to)
67167+{
67168+ __u32 mode;
67169+ __u32 needmode = GR_CREATE | GR_LINK;
67170+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
67171+
67172+ mode =
67173+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
67174+ old_mnt);
67175+
67176+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
67177+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
67178+ return mode;
67179+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
67180+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
67181+ return 0;
67182+ } else if (unlikely((mode & needmode) != needmode))
67183+ return 0;
67184+
67185+ return 1;
67186+}
67187+
67188+__u32
67189+gr_acl_handle_symlink(const struct dentry * new_dentry,
67190+ const struct dentry * parent_dentry,
67191+ const struct vfsmount * parent_mnt, const struct filename *from)
67192+{
67193+ __u32 needmode = GR_WRITE | GR_CREATE;
67194+ __u32 mode;
67195+
67196+ mode =
67197+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
67198+ GR_CREATE | GR_AUDIT_CREATE |
67199+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
67200+
67201+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
67202+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
67203+ return mode;
67204+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
67205+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
67206+ return 0;
67207+ } else if (unlikely((mode & needmode) != needmode))
67208+ return 0;
67209+
67210+ return (GR_WRITE | GR_CREATE);
67211+}
67212+
67213+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)
67214+{
67215+ __u32 mode;
67216+
67217+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
67218+
67219+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
67220+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
67221+ return mode;
67222+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
67223+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
67224+ return 0;
67225+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
67226+ return 0;
67227+
67228+ return (reqmode);
67229+}
67230+
67231+__u32
67232+gr_acl_handle_mknod(const struct dentry * new_dentry,
67233+ const struct dentry * parent_dentry,
67234+ const struct vfsmount * parent_mnt,
67235+ const int mode)
67236+{
67237+ __u32 reqmode = GR_WRITE | GR_CREATE;
67238+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
67239+ reqmode |= GR_SETID;
67240+
67241+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
67242+ reqmode, GR_MKNOD_ACL_MSG);
67243+}
67244+
67245+__u32
67246+gr_acl_handle_mkdir(const struct dentry *new_dentry,
67247+ const struct dentry *parent_dentry,
67248+ const struct vfsmount *parent_mnt)
67249+{
67250+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
67251+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
67252+}
67253+
67254+#define RENAME_CHECK_SUCCESS(old, new) \
67255+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
67256+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
67257+
67258+int
67259+gr_acl_handle_rename(struct dentry *new_dentry,
67260+ struct dentry *parent_dentry,
67261+ const struct vfsmount *parent_mnt,
67262+ struct dentry *old_dentry,
67263+ struct inode *old_parent_inode,
67264+ struct vfsmount *old_mnt, const struct filename *newname)
67265+{
67266+ __u32 comp1, comp2;
67267+ int error = 0;
67268+
67269+ if (unlikely(!gr_acl_is_enabled()))
67270+ return 0;
67271+
67272+ if (!new_dentry->d_inode) {
67273+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
67274+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
67275+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
67276+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
67277+ GR_DELETE | GR_AUDIT_DELETE |
67278+ GR_AUDIT_READ | GR_AUDIT_WRITE |
67279+ GR_SUPPRESS, old_mnt);
67280+ } else {
67281+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
67282+ GR_CREATE | GR_DELETE |
67283+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
67284+ GR_AUDIT_READ | GR_AUDIT_WRITE |
67285+ GR_SUPPRESS, parent_mnt);
67286+ comp2 =
67287+ gr_search_file(old_dentry,
67288+ GR_READ | GR_WRITE | GR_AUDIT_READ |
67289+ GR_DELETE | GR_AUDIT_DELETE |
67290+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
67291+ }
67292+
67293+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
67294+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
67295+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
67296+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
67297+ && !(comp2 & GR_SUPPRESS)) {
67298+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
67299+ error = -EACCES;
67300+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
67301+ error = -EACCES;
67302+
67303+ return error;
67304+}
67305+
67306+void
67307+gr_acl_handle_exit(void)
67308+{
67309+ u16 id;
67310+ char *rolename;
67311+
67312+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
67313+ !(current->role->roletype & GR_ROLE_PERSIST))) {
67314+ id = current->acl_role_id;
67315+ rolename = current->role->rolename;
67316+ gr_set_acls(1);
67317+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
67318+ }
67319+
67320+ gr_put_exec_file(current);
67321+ return;
67322+}
67323+
67324+int
67325+gr_acl_handle_procpidmem(const struct task_struct *task)
67326+{
67327+ if (unlikely(!gr_acl_is_enabled()))
67328+ return 0;
67329+
67330+ if (task != current && task->acl->mode & GR_PROTPROCFD)
67331+ return -EACCES;
67332+
67333+ return 0;
67334+}
67335diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
67336new file mode 100644
67337index 0000000..8132048
67338--- /dev/null
67339+++ b/grsecurity/gracl_ip.c
67340@@ -0,0 +1,387 @@
67341+#include <linux/kernel.h>
67342+#include <asm/uaccess.h>
67343+#include <asm/errno.h>
67344+#include <net/sock.h>
67345+#include <linux/file.h>
67346+#include <linux/fs.h>
67347+#include <linux/net.h>
67348+#include <linux/in.h>
67349+#include <linux/skbuff.h>
67350+#include <linux/ip.h>
67351+#include <linux/udp.h>
67352+#include <linux/types.h>
67353+#include <linux/sched.h>
67354+#include <linux/netdevice.h>
67355+#include <linux/inetdevice.h>
67356+#include <linux/gracl.h>
67357+#include <linux/grsecurity.h>
67358+#include <linux/grinternal.h>
67359+
67360+#define GR_BIND 0x01
67361+#define GR_CONNECT 0x02
67362+#define GR_INVERT 0x04
67363+#define GR_BINDOVERRIDE 0x08
67364+#define GR_CONNECTOVERRIDE 0x10
67365+#define GR_SOCK_FAMILY 0x20
67366+
67367+static const char * gr_protocols[IPPROTO_MAX] = {
67368+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
67369+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
67370+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
67371+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
67372+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
67373+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
67374+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
67375+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
67376+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
67377+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
67378+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
67379+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
67380+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
67381+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
67382+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
67383+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
67384+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
67385+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
67386+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
67387+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
67388+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
67389+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
67390+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
67391+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
67392+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
67393+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
67394+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
67395+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
67396+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
67397+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
67398+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
67399+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
67400+ };
67401+
67402+static const char * gr_socktypes[SOCK_MAX] = {
67403+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
67404+ "unknown:7", "unknown:8", "unknown:9", "packet"
67405+ };
67406+
67407+static const char * gr_sockfamilies[AF_MAX+1] = {
67408+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
67409+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
67410+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
67411+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
67412+ };
67413+
67414+const char *
67415+gr_proto_to_name(unsigned char proto)
67416+{
67417+ return gr_protocols[proto];
67418+}
67419+
67420+const char *
67421+gr_socktype_to_name(unsigned char type)
67422+{
67423+ return gr_socktypes[type];
67424+}
67425+
67426+const char *
67427+gr_sockfamily_to_name(unsigned char family)
67428+{
67429+ return gr_sockfamilies[family];
67430+}
67431+
67432+int
67433+gr_search_socket(const int domain, const int type, const int protocol)
67434+{
67435+ struct acl_subject_label *curr;
67436+ const struct cred *cred = current_cred();
67437+
67438+ if (unlikely(!gr_acl_is_enabled()))
67439+ goto exit;
67440+
67441+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
67442+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
67443+ goto exit; // let the kernel handle it
67444+
67445+ curr = current->acl;
67446+
67447+ if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
67448+ /* the family is allowed, if this is PF_INET allow it only if
67449+ the extra sock type/protocol checks pass */
67450+ if (domain == PF_INET)
67451+ goto inet_check;
67452+ goto exit;
67453+ } else {
67454+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
67455+ __u32 fakeip = 0;
67456+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
67457+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
67458+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
67459+ gr_to_filename(current->exec_file->f_path.dentry,
67460+ current->exec_file->f_path.mnt) :
67461+ curr->filename, curr->filename,
67462+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
67463+ &current->signal->saved_ip);
67464+ goto exit;
67465+ }
67466+ goto exit_fail;
67467+ }
67468+
67469+inet_check:
67470+ /* the rest of this checking is for IPv4 only */
67471+ if (!curr->ips)
67472+ goto exit;
67473+
67474+ if ((curr->ip_type & (1U << type)) &&
67475+ (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
67476+ goto exit;
67477+
67478+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
67479+ /* we don't place acls on raw sockets , and sometimes
67480+ dgram/ip sockets are opened for ioctl and not
67481+ bind/connect, so we'll fake a bind learn log */
67482+ if (type == SOCK_RAW || type == SOCK_PACKET) {
67483+ __u32 fakeip = 0;
67484+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
67485+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
67486+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
67487+ gr_to_filename(current->exec_file->f_path.dentry,
67488+ current->exec_file->f_path.mnt) :
67489+ curr->filename, curr->filename,
67490+ &fakeip, 0, type,
67491+ protocol, GR_CONNECT, &current->signal->saved_ip);
67492+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
67493+ __u32 fakeip = 0;
67494+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
67495+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
67496+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
67497+ gr_to_filename(current->exec_file->f_path.dentry,
67498+ current->exec_file->f_path.mnt) :
67499+ curr->filename, curr->filename,
67500+ &fakeip, 0, type,
67501+ protocol, GR_BIND, &current->signal->saved_ip);
67502+ }
67503+ /* we'll log when they use connect or bind */
67504+ goto exit;
67505+ }
67506+
67507+exit_fail:
67508+ if (domain == PF_INET)
67509+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
67510+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
67511+ else
67512+#ifndef CONFIG_IPV6
67513+ if (domain != PF_INET6)
67514+#endif
67515+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
67516+ gr_socktype_to_name(type), protocol);
67517+
67518+ return 0;
67519+exit:
67520+ return 1;
67521+}
67522+
67523+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)
67524+{
67525+ if ((ip->mode & mode) &&
67526+ (ip_port >= ip->low) &&
67527+ (ip_port <= ip->high) &&
67528+ ((ntohl(ip_addr) & our_netmask) ==
67529+ (ntohl(our_addr) & our_netmask))
67530+ && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
67531+ && (ip->type & (1U << type))) {
67532+ if (ip->mode & GR_INVERT)
67533+ return 2; // specifically denied
67534+ else
67535+ return 1; // allowed
67536+ }
67537+
67538+ return 0; // not specifically allowed, may continue parsing
67539+}
67540+
67541+static int
67542+gr_search_connectbind(const int full_mode, struct sock *sk,
67543+ struct sockaddr_in *addr, const int type)
67544+{
67545+ char iface[IFNAMSIZ] = {0};
67546+ struct acl_subject_label *curr;
67547+ struct acl_ip_label *ip;
67548+ struct inet_sock *isk;
67549+ struct net_device *dev;
67550+ struct in_device *idev;
67551+ unsigned long i;
67552+ int ret;
67553+ int mode = full_mode & (GR_BIND | GR_CONNECT);
67554+ __u32 ip_addr = 0;
67555+ __u32 our_addr;
67556+ __u32 our_netmask;
67557+ char *p;
67558+ __u16 ip_port = 0;
67559+ const struct cred *cred = current_cred();
67560+
67561+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
67562+ return 0;
67563+
67564+ curr = current->acl;
67565+ isk = inet_sk(sk);
67566+
67567+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
67568+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
67569+ addr->sin_addr.s_addr = curr->inaddr_any_override;
67570+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
67571+ struct sockaddr_in saddr;
67572+ int err;
67573+
67574+ saddr.sin_family = AF_INET;
67575+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
67576+ saddr.sin_port = isk->inet_sport;
67577+
67578+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
67579+ if (err)
67580+ return err;
67581+
67582+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
67583+ if (err)
67584+ return err;
67585+ }
67586+
67587+ if (!curr->ips)
67588+ return 0;
67589+
67590+ ip_addr = addr->sin_addr.s_addr;
67591+ ip_port = ntohs(addr->sin_port);
67592+
67593+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
67594+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
67595+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
67596+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
67597+ gr_to_filename(current->exec_file->f_path.dentry,
67598+ current->exec_file->f_path.mnt) :
67599+ curr->filename, curr->filename,
67600+ &ip_addr, ip_port, type,
67601+ sk->sk_protocol, mode, &current->signal->saved_ip);
67602+ return 0;
67603+ }
67604+
67605+ for (i = 0; i < curr->ip_num; i++) {
67606+ ip = *(curr->ips + i);
67607+ if (ip->iface != NULL) {
67608+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
67609+ p = strchr(iface, ':');
67610+ if (p != NULL)
67611+ *p = '\0';
67612+ dev = dev_get_by_name(sock_net(sk), iface);
67613+ if (dev == NULL)
67614+ continue;
67615+ idev = in_dev_get(dev);
67616+ if (idev == NULL) {
67617+ dev_put(dev);
67618+ continue;
67619+ }
67620+ rcu_read_lock();
67621+ for_ifa(idev) {
67622+ if (!strcmp(ip->iface, ifa->ifa_label)) {
67623+ our_addr = ifa->ifa_address;
67624+ our_netmask = 0xffffffff;
67625+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
67626+ if (ret == 1) {
67627+ rcu_read_unlock();
67628+ in_dev_put(idev);
67629+ dev_put(dev);
67630+ return 0;
67631+ } else if (ret == 2) {
67632+ rcu_read_unlock();
67633+ in_dev_put(idev);
67634+ dev_put(dev);
67635+ goto denied;
67636+ }
67637+ }
67638+ } endfor_ifa(idev);
67639+ rcu_read_unlock();
67640+ in_dev_put(idev);
67641+ dev_put(dev);
67642+ } else {
67643+ our_addr = ip->addr;
67644+ our_netmask = ip->netmask;
67645+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
67646+ if (ret == 1)
67647+ return 0;
67648+ else if (ret == 2)
67649+ goto denied;
67650+ }
67651+ }
67652+
67653+denied:
67654+ if (mode == GR_BIND)
67655+ 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));
67656+ else if (mode == GR_CONNECT)
67657+ 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));
67658+
67659+ return -EACCES;
67660+}
67661+
67662+int
67663+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
67664+{
67665+ /* always allow disconnection of dgram sockets with connect */
67666+ if (addr->sin_family == AF_UNSPEC)
67667+ return 0;
67668+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
67669+}
67670+
67671+int
67672+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
67673+{
67674+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
67675+}
67676+
67677+int gr_search_listen(struct socket *sock)
67678+{
67679+ struct sock *sk = sock->sk;
67680+ struct sockaddr_in addr;
67681+
67682+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
67683+ addr.sin_port = inet_sk(sk)->inet_sport;
67684+
67685+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
67686+}
67687+
67688+int gr_search_accept(struct socket *sock)
67689+{
67690+ struct sock *sk = sock->sk;
67691+ struct sockaddr_in addr;
67692+
67693+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
67694+ addr.sin_port = inet_sk(sk)->inet_sport;
67695+
67696+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
67697+}
67698+
67699+int
67700+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
67701+{
67702+ if (addr)
67703+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
67704+ else {
67705+ struct sockaddr_in sin;
67706+ const struct inet_sock *inet = inet_sk(sk);
67707+
67708+ sin.sin_addr.s_addr = inet->inet_daddr;
67709+ sin.sin_port = inet->inet_dport;
67710+
67711+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
67712+ }
67713+}
67714+
67715+int
67716+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
67717+{
67718+ struct sockaddr_in sin;
67719+
67720+ if (unlikely(skb->len < sizeof (struct udphdr)))
67721+ return 0; // skip this packet
67722+
67723+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
67724+ sin.sin_port = udp_hdr(skb)->source;
67725+
67726+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
67727+}
67728diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
67729new file mode 100644
67730index 0000000..25f54ef
67731--- /dev/null
67732+++ b/grsecurity/gracl_learn.c
67733@@ -0,0 +1,207 @@
67734+#include <linux/kernel.h>
67735+#include <linux/mm.h>
67736+#include <linux/sched.h>
67737+#include <linux/poll.h>
67738+#include <linux/string.h>
67739+#include <linux/file.h>
67740+#include <linux/types.h>
67741+#include <linux/vmalloc.h>
67742+#include <linux/grinternal.h>
67743+
67744+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
67745+ size_t count, loff_t *ppos);
67746+extern int gr_acl_is_enabled(void);
67747+
67748+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
67749+static int gr_learn_attached;
67750+
67751+/* use a 512k buffer */
67752+#define LEARN_BUFFER_SIZE (512 * 1024)
67753+
67754+static DEFINE_SPINLOCK(gr_learn_lock);
67755+static DEFINE_MUTEX(gr_learn_user_mutex);
67756+
67757+/* we need to maintain two buffers, so that the kernel context of grlearn
67758+ uses a semaphore around the userspace copying, and the other kernel contexts
67759+ use a spinlock when copying into the buffer, since they cannot sleep
67760+*/
67761+static char *learn_buffer;
67762+static char *learn_buffer_user;
67763+static int learn_buffer_len;
67764+static int learn_buffer_user_len;
67765+
67766+static ssize_t
67767+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
67768+{
67769+ DECLARE_WAITQUEUE(wait, current);
67770+ ssize_t retval = 0;
67771+
67772+ add_wait_queue(&learn_wait, &wait);
67773+ set_current_state(TASK_INTERRUPTIBLE);
67774+ do {
67775+ mutex_lock(&gr_learn_user_mutex);
67776+ spin_lock(&gr_learn_lock);
67777+ if (learn_buffer_len)
67778+ break;
67779+ spin_unlock(&gr_learn_lock);
67780+ mutex_unlock(&gr_learn_user_mutex);
67781+ if (file->f_flags & O_NONBLOCK) {
67782+ retval = -EAGAIN;
67783+ goto out;
67784+ }
67785+ if (signal_pending(current)) {
67786+ retval = -ERESTARTSYS;
67787+ goto out;
67788+ }
67789+
67790+ schedule();
67791+ } while (1);
67792+
67793+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
67794+ learn_buffer_user_len = learn_buffer_len;
67795+ retval = learn_buffer_len;
67796+ learn_buffer_len = 0;
67797+
67798+ spin_unlock(&gr_learn_lock);
67799+
67800+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
67801+ retval = -EFAULT;
67802+
67803+ mutex_unlock(&gr_learn_user_mutex);
67804+out:
67805+ set_current_state(TASK_RUNNING);
67806+ remove_wait_queue(&learn_wait, &wait);
67807+ return retval;
67808+}
67809+
67810+static unsigned int
67811+poll_learn(struct file * file, poll_table * wait)
67812+{
67813+ poll_wait(file, &learn_wait, wait);
67814+
67815+ if (learn_buffer_len)
67816+ return (POLLIN | POLLRDNORM);
67817+
67818+ return 0;
67819+}
67820+
67821+void
67822+gr_clear_learn_entries(void)
67823+{
67824+ char *tmp;
67825+
67826+ mutex_lock(&gr_learn_user_mutex);
67827+ spin_lock(&gr_learn_lock);
67828+ tmp = learn_buffer;
67829+ learn_buffer = NULL;
67830+ spin_unlock(&gr_learn_lock);
67831+ if (tmp)
67832+ vfree(tmp);
67833+ if (learn_buffer_user != NULL) {
67834+ vfree(learn_buffer_user);
67835+ learn_buffer_user = NULL;
67836+ }
67837+ learn_buffer_len = 0;
67838+ mutex_unlock(&gr_learn_user_mutex);
67839+
67840+ return;
67841+}
67842+
67843+void
67844+gr_add_learn_entry(const char *fmt, ...)
67845+{
67846+ va_list args;
67847+ unsigned int len;
67848+
67849+ if (!gr_learn_attached)
67850+ return;
67851+
67852+ spin_lock(&gr_learn_lock);
67853+
67854+ /* leave a gap at the end so we know when it's "full" but don't have to
67855+ compute the exact length of the string we're trying to append
67856+ */
67857+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
67858+ spin_unlock(&gr_learn_lock);
67859+ wake_up_interruptible(&learn_wait);
67860+ return;
67861+ }
67862+ if (learn_buffer == NULL) {
67863+ spin_unlock(&gr_learn_lock);
67864+ return;
67865+ }
67866+
67867+ va_start(args, fmt);
67868+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
67869+ va_end(args);
67870+
67871+ learn_buffer_len += len + 1;
67872+
67873+ spin_unlock(&gr_learn_lock);
67874+ wake_up_interruptible(&learn_wait);
67875+
67876+ return;
67877+}
67878+
67879+static int
67880+open_learn(struct inode *inode, struct file *file)
67881+{
67882+ if (file->f_mode & FMODE_READ && gr_learn_attached)
67883+ return -EBUSY;
67884+ if (file->f_mode & FMODE_READ) {
67885+ int retval = 0;
67886+ mutex_lock(&gr_learn_user_mutex);
67887+ if (learn_buffer == NULL)
67888+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
67889+ if (learn_buffer_user == NULL)
67890+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
67891+ if (learn_buffer == NULL) {
67892+ retval = -ENOMEM;
67893+ goto out_error;
67894+ }
67895+ if (learn_buffer_user == NULL) {
67896+ retval = -ENOMEM;
67897+ goto out_error;
67898+ }
67899+ learn_buffer_len = 0;
67900+ learn_buffer_user_len = 0;
67901+ gr_learn_attached = 1;
67902+out_error:
67903+ mutex_unlock(&gr_learn_user_mutex);
67904+ return retval;
67905+ }
67906+ return 0;
67907+}
67908+
67909+static int
67910+close_learn(struct inode *inode, struct file *file)
67911+{
67912+ if (file->f_mode & FMODE_READ) {
67913+ char *tmp = NULL;
67914+ mutex_lock(&gr_learn_user_mutex);
67915+ spin_lock(&gr_learn_lock);
67916+ tmp = learn_buffer;
67917+ learn_buffer = NULL;
67918+ spin_unlock(&gr_learn_lock);
67919+ if (tmp)
67920+ vfree(tmp);
67921+ if (learn_buffer_user != NULL) {
67922+ vfree(learn_buffer_user);
67923+ learn_buffer_user = NULL;
67924+ }
67925+ learn_buffer_len = 0;
67926+ learn_buffer_user_len = 0;
67927+ gr_learn_attached = 0;
67928+ mutex_unlock(&gr_learn_user_mutex);
67929+ }
67930+
67931+ return 0;
67932+}
67933+
67934+const struct file_operations grsec_fops = {
67935+ .read = read_learn,
67936+ .write = write_grsec_handler,
67937+ .open = open_learn,
67938+ .release = close_learn,
67939+ .poll = poll_learn,
67940+};
67941diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
67942new file mode 100644
67943index 0000000..39645c9
67944--- /dev/null
67945+++ b/grsecurity/gracl_res.c
67946@@ -0,0 +1,68 @@
67947+#include <linux/kernel.h>
67948+#include <linux/sched.h>
67949+#include <linux/gracl.h>
67950+#include <linux/grinternal.h>
67951+
67952+static const char *restab_log[] = {
67953+ [RLIMIT_CPU] = "RLIMIT_CPU",
67954+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
67955+ [RLIMIT_DATA] = "RLIMIT_DATA",
67956+ [RLIMIT_STACK] = "RLIMIT_STACK",
67957+ [RLIMIT_CORE] = "RLIMIT_CORE",
67958+ [RLIMIT_RSS] = "RLIMIT_RSS",
67959+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
67960+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
67961+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
67962+ [RLIMIT_AS] = "RLIMIT_AS",
67963+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
67964+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
67965+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
67966+ [RLIMIT_NICE] = "RLIMIT_NICE",
67967+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
67968+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
67969+ [GR_CRASH_RES] = "RLIMIT_CRASH"
67970+};
67971+
67972+void
67973+gr_log_resource(const struct task_struct *task,
67974+ const int res, const unsigned long wanted, const int gt)
67975+{
67976+ const struct cred *cred;
67977+ unsigned long rlim;
67978+
67979+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
67980+ return;
67981+
67982+ // not yet supported resource
67983+ if (unlikely(!restab_log[res]))
67984+ return;
67985+
67986+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
67987+ rlim = task_rlimit_max(task, res);
67988+ else
67989+ rlim = task_rlimit(task, res);
67990+
67991+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
67992+ return;
67993+
67994+ rcu_read_lock();
67995+ cred = __task_cred(task);
67996+
67997+ if (res == RLIMIT_NPROC &&
67998+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
67999+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
68000+ goto out_rcu_unlock;
68001+ else if (res == RLIMIT_MEMLOCK &&
68002+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
68003+ goto out_rcu_unlock;
68004+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
68005+ goto out_rcu_unlock;
68006+ rcu_read_unlock();
68007+
68008+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
68009+
68010+ return;
68011+out_rcu_unlock:
68012+ rcu_read_unlock();
68013+ return;
68014+}
68015diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
68016new file mode 100644
68017index 0000000..3c38bfe
68018--- /dev/null
68019+++ b/grsecurity/gracl_segv.c
68020@@ -0,0 +1,305 @@
68021+#include <linux/kernel.h>
68022+#include <linux/mm.h>
68023+#include <asm/uaccess.h>
68024+#include <asm/errno.h>
68025+#include <asm/mman.h>
68026+#include <net/sock.h>
68027+#include <linux/file.h>
68028+#include <linux/fs.h>
68029+#include <linux/net.h>
68030+#include <linux/in.h>
68031+#include <linux/slab.h>
68032+#include <linux/types.h>
68033+#include <linux/sched.h>
68034+#include <linux/timer.h>
68035+#include <linux/gracl.h>
68036+#include <linux/grsecurity.h>
68037+#include <linux/grinternal.h>
68038+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
68039+#include <linux/magic.h>
68040+#include <linux/pagemap.h>
68041+#include "../fs/btrfs/async-thread.h"
68042+#include "../fs/btrfs/ctree.h"
68043+#include "../fs/btrfs/btrfs_inode.h"
68044+#endif
68045+
68046+static struct crash_uid *uid_set;
68047+static unsigned short uid_used;
68048+static DEFINE_SPINLOCK(gr_uid_lock);
68049+extern rwlock_t gr_inode_lock;
68050+extern struct acl_subject_label *
68051+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
68052+ struct acl_role_label *role);
68053+
68054+static inline dev_t __get_dev(const struct dentry *dentry)
68055+{
68056+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
68057+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
68058+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
68059+ else
68060+#endif
68061+ return dentry->d_sb->s_dev;
68062+}
68063+
68064+int
68065+gr_init_uidset(void)
68066+{
68067+ uid_set =
68068+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
68069+ uid_used = 0;
68070+
68071+ return uid_set ? 1 : 0;
68072+}
68073+
68074+void
68075+gr_free_uidset(void)
68076+{
68077+ if (uid_set)
68078+ kfree(uid_set);
68079+
68080+ return;
68081+}
68082+
68083+int
68084+gr_find_uid(const uid_t uid)
68085+{
68086+ struct crash_uid *tmp = uid_set;
68087+ uid_t buid;
68088+ int low = 0, high = uid_used - 1, mid;
68089+
68090+ while (high >= low) {
68091+ mid = (low + high) >> 1;
68092+ buid = tmp[mid].uid;
68093+ if (buid == uid)
68094+ return mid;
68095+ if (buid > uid)
68096+ high = mid - 1;
68097+ if (buid < uid)
68098+ low = mid + 1;
68099+ }
68100+
68101+ return -1;
68102+}
68103+
68104+static __inline__ void
68105+gr_insertsort(void)
68106+{
68107+ unsigned short i, j;
68108+ struct crash_uid index;
68109+
68110+ for (i = 1; i < uid_used; i++) {
68111+ index = uid_set[i];
68112+ j = i;
68113+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
68114+ uid_set[j] = uid_set[j - 1];
68115+ j--;
68116+ }
68117+ uid_set[j] = index;
68118+ }
68119+
68120+ return;
68121+}
68122+
68123+static __inline__ void
68124+gr_insert_uid(const kuid_t kuid, const unsigned long expires)
68125+{
68126+ int loc;
68127+ uid_t uid = GR_GLOBAL_UID(kuid);
68128+
68129+ if (uid_used == GR_UIDTABLE_MAX)
68130+ return;
68131+
68132+ loc = gr_find_uid(uid);
68133+
68134+ if (loc >= 0) {
68135+ uid_set[loc].expires = expires;
68136+ return;
68137+ }
68138+
68139+ uid_set[uid_used].uid = uid;
68140+ uid_set[uid_used].expires = expires;
68141+ uid_used++;
68142+
68143+ gr_insertsort();
68144+
68145+ return;
68146+}
68147+
68148+void
68149+gr_remove_uid(const unsigned short loc)
68150+{
68151+ unsigned short i;
68152+
68153+ for (i = loc + 1; i < uid_used; i++)
68154+ uid_set[i - 1] = uid_set[i];
68155+
68156+ uid_used--;
68157+
68158+ return;
68159+}
68160+
68161+int
68162+gr_check_crash_uid(const kuid_t kuid)
68163+{
68164+ int loc;
68165+ int ret = 0;
68166+ uid_t uid;
68167+
68168+ if (unlikely(!gr_acl_is_enabled()))
68169+ return 0;
68170+
68171+ uid = GR_GLOBAL_UID(kuid);
68172+
68173+ spin_lock(&gr_uid_lock);
68174+ loc = gr_find_uid(uid);
68175+
68176+ if (loc < 0)
68177+ goto out_unlock;
68178+
68179+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
68180+ gr_remove_uid(loc);
68181+ else
68182+ ret = 1;
68183+
68184+out_unlock:
68185+ spin_unlock(&gr_uid_lock);
68186+ return ret;
68187+}
68188+
68189+static __inline__ int
68190+proc_is_setxid(const struct cred *cred)
68191+{
68192+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
68193+ !uid_eq(cred->uid, cred->fsuid))
68194+ return 1;
68195+ if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
68196+ !gid_eq(cred->gid, cred->fsgid))
68197+ return 1;
68198+
68199+ return 0;
68200+}
68201+
68202+extern int gr_fake_force_sig(int sig, struct task_struct *t);
68203+
68204+void
68205+gr_handle_crash(struct task_struct *task, const int sig)
68206+{
68207+ struct acl_subject_label *curr;
68208+ struct task_struct *tsk, *tsk2;
68209+ const struct cred *cred;
68210+ const struct cred *cred2;
68211+
68212+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
68213+ return;
68214+
68215+ if (unlikely(!gr_acl_is_enabled()))
68216+ return;
68217+
68218+ curr = task->acl;
68219+
68220+ if (!(curr->resmask & (1U << GR_CRASH_RES)))
68221+ return;
68222+
68223+ if (time_before_eq(curr->expires, get_seconds())) {
68224+ curr->expires = 0;
68225+ curr->crashes = 0;
68226+ }
68227+
68228+ curr->crashes++;
68229+
68230+ if (!curr->expires)
68231+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
68232+
68233+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
68234+ time_after(curr->expires, get_seconds())) {
68235+ rcu_read_lock();
68236+ cred = __task_cred(task);
68237+ if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
68238+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
68239+ spin_lock(&gr_uid_lock);
68240+ gr_insert_uid(cred->uid, curr->expires);
68241+ spin_unlock(&gr_uid_lock);
68242+ curr->expires = 0;
68243+ curr->crashes = 0;
68244+ read_lock(&tasklist_lock);
68245+ do_each_thread(tsk2, tsk) {
68246+ cred2 = __task_cred(tsk);
68247+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
68248+ gr_fake_force_sig(SIGKILL, tsk);
68249+ } while_each_thread(tsk2, tsk);
68250+ read_unlock(&tasklist_lock);
68251+ } else {
68252+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
68253+ read_lock(&tasklist_lock);
68254+ read_lock(&grsec_exec_file_lock);
68255+ do_each_thread(tsk2, tsk) {
68256+ if (likely(tsk != task)) {
68257+ // if this thread has the same subject as the one that triggered
68258+ // RES_CRASH and it's the same binary, kill it
68259+ if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
68260+ gr_fake_force_sig(SIGKILL, tsk);
68261+ }
68262+ } while_each_thread(tsk2, tsk);
68263+ read_unlock(&grsec_exec_file_lock);
68264+ read_unlock(&tasklist_lock);
68265+ }
68266+ rcu_read_unlock();
68267+ }
68268+
68269+ return;
68270+}
68271+
68272+int
68273+gr_check_crash_exec(const struct file *filp)
68274+{
68275+ struct acl_subject_label *curr;
68276+
68277+ if (unlikely(!gr_acl_is_enabled()))
68278+ return 0;
68279+
68280+ read_lock(&gr_inode_lock);
68281+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
68282+ __get_dev(filp->f_path.dentry),
68283+ current->role);
68284+ read_unlock(&gr_inode_lock);
68285+
68286+ if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
68287+ (!curr->crashes && !curr->expires))
68288+ return 0;
68289+
68290+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
68291+ time_after(curr->expires, get_seconds()))
68292+ return 1;
68293+ else if (time_before_eq(curr->expires, get_seconds())) {
68294+ curr->crashes = 0;
68295+ curr->expires = 0;
68296+ }
68297+
68298+ return 0;
68299+}
68300+
68301+void
68302+gr_handle_alertkill(struct task_struct *task)
68303+{
68304+ struct acl_subject_label *curracl;
68305+ __u32 curr_ip;
68306+ struct task_struct *p, *p2;
68307+
68308+ if (unlikely(!gr_acl_is_enabled()))
68309+ return;
68310+
68311+ curracl = task->acl;
68312+ curr_ip = task->signal->curr_ip;
68313+
68314+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
68315+ read_lock(&tasklist_lock);
68316+ do_each_thread(p2, p) {
68317+ if (p->signal->curr_ip == curr_ip)
68318+ gr_fake_force_sig(SIGKILL, p);
68319+ } while_each_thread(p2, p);
68320+ read_unlock(&tasklist_lock);
68321+ } else if (curracl->mode & GR_KILLPROC)
68322+ gr_fake_force_sig(SIGKILL, task);
68323+
68324+ return;
68325+}
68326diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
68327new file mode 100644
68328index 0000000..98011b0
68329--- /dev/null
68330+++ b/grsecurity/gracl_shm.c
68331@@ -0,0 +1,40 @@
68332+#include <linux/kernel.h>
68333+#include <linux/mm.h>
68334+#include <linux/sched.h>
68335+#include <linux/file.h>
68336+#include <linux/ipc.h>
68337+#include <linux/gracl.h>
68338+#include <linux/grsecurity.h>
68339+#include <linux/grinternal.h>
68340+
68341+int
68342+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
68343+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
68344+{
68345+ struct task_struct *task;
68346+
68347+ if (!gr_acl_is_enabled())
68348+ return 1;
68349+
68350+ rcu_read_lock();
68351+ read_lock(&tasklist_lock);
68352+
68353+ task = find_task_by_vpid(shm_cprid);
68354+
68355+ if (unlikely(!task))
68356+ task = find_task_by_vpid(shm_lapid);
68357+
68358+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
68359+ (task_pid_nr(task) == shm_lapid)) &&
68360+ (task->acl->mode & GR_PROTSHM) &&
68361+ (task->acl != current->acl))) {
68362+ read_unlock(&tasklist_lock);
68363+ rcu_read_unlock();
68364+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
68365+ return 0;
68366+ }
68367+ read_unlock(&tasklist_lock);
68368+ rcu_read_unlock();
68369+
68370+ return 1;
68371+}
68372diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
68373new file mode 100644
68374index 0000000..bc0be01
68375--- /dev/null
68376+++ b/grsecurity/grsec_chdir.c
68377@@ -0,0 +1,19 @@
68378+#include <linux/kernel.h>
68379+#include <linux/sched.h>
68380+#include <linux/fs.h>
68381+#include <linux/file.h>
68382+#include <linux/grsecurity.h>
68383+#include <linux/grinternal.h>
68384+
68385+void
68386+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
68387+{
68388+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
68389+ if ((grsec_enable_chdir && grsec_enable_group &&
68390+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
68391+ !grsec_enable_group)) {
68392+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
68393+ }
68394+#endif
68395+ return;
68396+}
68397diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
68398new file mode 100644
68399index 0000000..bd6e105
68400--- /dev/null
68401+++ b/grsecurity/grsec_chroot.c
68402@@ -0,0 +1,370 @@
68403+#include <linux/kernel.h>
68404+#include <linux/module.h>
68405+#include <linux/sched.h>
68406+#include <linux/file.h>
68407+#include <linux/fs.h>
68408+#include <linux/mount.h>
68409+#include <linux/types.h>
68410+#include "../fs/mount.h"
68411+#include <linux/grsecurity.h>
68412+#include <linux/grinternal.h>
68413+
68414+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
68415+static int gr_init_ran;
68416+#endif
68417+
68418+void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
68419+{
68420+#ifdef CONFIG_GRKERNSEC
68421+ if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
68422+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
68423+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
68424+ && gr_init_ran
68425+#endif
68426+ )
68427+ task->gr_is_chrooted = 1;
68428+ else {
68429+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
68430+ if (task_pid_nr(task) == 1 && !gr_init_ran)
68431+ gr_init_ran = 1;
68432+#endif
68433+ task->gr_is_chrooted = 0;
68434+ }
68435+
68436+ task->gr_chroot_dentry = path->dentry;
68437+#endif
68438+ return;
68439+}
68440+
68441+void gr_clear_chroot_entries(struct task_struct *task)
68442+{
68443+#ifdef CONFIG_GRKERNSEC
68444+ task->gr_is_chrooted = 0;
68445+ task->gr_chroot_dentry = NULL;
68446+#endif
68447+ return;
68448+}
68449+
68450+int
68451+gr_handle_chroot_unix(const pid_t pid)
68452+{
68453+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
68454+ struct task_struct *p;
68455+
68456+ if (unlikely(!grsec_enable_chroot_unix))
68457+ return 1;
68458+
68459+ if (likely(!proc_is_chrooted(current)))
68460+ return 1;
68461+
68462+ rcu_read_lock();
68463+ read_lock(&tasklist_lock);
68464+ p = find_task_by_vpid_unrestricted(pid);
68465+ if (unlikely(p && !have_same_root(current, p))) {
68466+ read_unlock(&tasklist_lock);
68467+ rcu_read_unlock();
68468+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
68469+ return 0;
68470+ }
68471+ read_unlock(&tasklist_lock);
68472+ rcu_read_unlock();
68473+#endif
68474+ return 1;
68475+}
68476+
68477+int
68478+gr_handle_chroot_nice(void)
68479+{
68480+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
68481+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
68482+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
68483+ return -EPERM;
68484+ }
68485+#endif
68486+ return 0;
68487+}
68488+
68489+int
68490+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
68491+{
68492+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
68493+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
68494+ && proc_is_chrooted(current)) {
68495+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
68496+ return -EACCES;
68497+ }
68498+#endif
68499+ return 0;
68500+}
68501+
68502+int
68503+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
68504+{
68505+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
68506+ struct task_struct *p;
68507+ int ret = 0;
68508+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
68509+ return ret;
68510+
68511+ read_lock(&tasklist_lock);
68512+ do_each_pid_task(pid, type, p) {
68513+ if (!have_same_root(current, p)) {
68514+ ret = 1;
68515+ goto out;
68516+ }
68517+ } while_each_pid_task(pid, type, p);
68518+out:
68519+ read_unlock(&tasklist_lock);
68520+ return ret;
68521+#endif
68522+ return 0;
68523+}
68524+
68525+int
68526+gr_pid_is_chrooted(struct task_struct *p)
68527+{
68528+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
68529+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
68530+ return 0;
68531+
68532+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
68533+ !have_same_root(current, p)) {
68534+ return 1;
68535+ }
68536+#endif
68537+ return 0;
68538+}
68539+
68540+EXPORT_SYMBOL(gr_pid_is_chrooted);
68541+
68542+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
68543+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
68544+{
68545+ struct path path, currentroot;
68546+ int ret = 0;
68547+
68548+ path.dentry = (struct dentry *)u_dentry;
68549+ path.mnt = (struct vfsmount *)u_mnt;
68550+ get_fs_root(current->fs, &currentroot);
68551+ if (path_is_under(&path, &currentroot))
68552+ ret = 1;
68553+ path_put(&currentroot);
68554+
68555+ return ret;
68556+}
68557+#endif
68558+
68559+int
68560+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
68561+{
68562+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
68563+ if (!grsec_enable_chroot_fchdir)
68564+ return 1;
68565+
68566+ if (!proc_is_chrooted(current))
68567+ return 1;
68568+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
68569+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
68570+ return 0;
68571+ }
68572+#endif
68573+ return 1;
68574+}
68575+
68576+int
68577+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
68578+ const time_t shm_createtime)
68579+{
68580+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
68581+ struct task_struct *p;
68582+ time_t starttime;
68583+
68584+ if (unlikely(!grsec_enable_chroot_shmat))
68585+ return 1;
68586+
68587+ if (likely(!proc_is_chrooted(current)))
68588+ return 1;
68589+
68590+ rcu_read_lock();
68591+ read_lock(&tasklist_lock);
68592+
68593+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
68594+ starttime = p->start_time.tv_sec;
68595+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
68596+ if (have_same_root(current, p)) {
68597+ goto allow;
68598+ } else {
68599+ read_unlock(&tasklist_lock);
68600+ rcu_read_unlock();
68601+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
68602+ return 0;
68603+ }
68604+ }
68605+ /* creator exited, pid reuse, fall through to next check */
68606+ }
68607+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
68608+ if (unlikely(!have_same_root(current, p))) {
68609+ read_unlock(&tasklist_lock);
68610+ rcu_read_unlock();
68611+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
68612+ return 0;
68613+ }
68614+ }
68615+
68616+allow:
68617+ read_unlock(&tasklist_lock);
68618+ rcu_read_unlock();
68619+#endif
68620+ return 1;
68621+}
68622+
68623+void
68624+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
68625+{
68626+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
68627+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
68628+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
68629+#endif
68630+ return;
68631+}
68632+
68633+int
68634+gr_handle_chroot_mknod(const struct dentry *dentry,
68635+ const struct vfsmount *mnt, const int mode)
68636+{
68637+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
68638+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
68639+ proc_is_chrooted(current)) {
68640+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
68641+ return -EPERM;
68642+ }
68643+#endif
68644+ return 0;
68645+}
68646+
68647+int
68648+gr_handle_chroot_mount(const struct dentry *dentry,
68649+ const struct vfsmount *mnt, const char *dev_name)
68650+{
68651+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
68652+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
68653+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
68654+ return -EPERM;
68655+ }
68656+#endif
68657+ return 0;
68658+}
68659+
68660+int
68661+gr_handle_chroot_pivot(void)
68662+{
68663+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
68664+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
68665+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
68666+ return -EPERM;
68667+ }
68668+#endif
68669+ return 0;
68670+}
68671+
68672+int
68673+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
68674+{
68675+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
68676+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
68677+ !gr_is_outside_chroot(dentry, mnt)) {
68678+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
68679+ return -EPERM;
68680+ }
68681+#endif
68682+ return 0;
68683+}
68684+
68685+extern const char *captab_log[];
68686+extern int captab_log_entries;
68687+
68688+int
68689+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
68690+{
68691+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
68692+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
68693+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
68694+ if (cap_raised(chroot_caps, cap)) {
68695+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
68696+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
68697+ }
68698+ return 0;
68699+ }
68700+ }
68701+#endif
68702+ return 1;
68703+}
68704+
68705+int
68706+gr_chroot_is_capable(const int cap)
68707+{
68708+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
68709+ return gr_task_chroot_is_capable(current, current_cred(), cap);
68710+#endif
68711+ return 1;
68712+}
68713+
68714+int
68715+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
68716+{
68717+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
68718+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
68719+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
68720+ if (cap_raised(chroot_caps, cap)) {
68721+ return 0;
68722+ }
68723+ }
68724+#endif
68725+ return 1;
68726+}
68727+
68728+int
68729+gr_chroot_is_capable_nolog(const int cap)
68730+{
68731+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
68732+ return gr_task_chroot_is_capable_nolog(current, cap);
68733+#endif
68734+ return 1;
68735+}
68736+
68737+int
68738+gr_handle_chroot_sysctl(const int op)
68739+{
68740+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
68741+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
68742+ proc_is_chrooted(current))
68743+ return -EACCES;
68744+#endif
68745+ return 0;
68746+}
68747+
68748+void
68749+gr_handle_chroot_chdir(const struct path *path)
68750+{
68751+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
68752+ if (grsec_enable_chroot_chdir)
68753+ set_fs_pwd(current->fs, path);
68754+#endif
68755+ return;
68756+}
68757+
68758+int
68759+gr_handle_chroot_chmod(const struct dentry *dentry,
68760+ const struct vfsmount *mnt, const int mode)
68761+{
68762+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
68763+ /* allow chmod +s on directories, but not files */
68764+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
68765+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
68766+ proc_is_chrooted(current)) {
68767+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
68768+ return -EPERM;
68769+ }
68770+#endif
68771+ return 0;
68772+}
68773diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
68774new file mode 100644
68775index 0000000..ce65ceb
68776--- /dev/null
68777+++ b/grsecurity/grsec_disabled.c
68778@@ -0,0 +1,434 @@
68779+#include <linux/kernel.h>
68780+#include <linux/module.h>
68781+#include <linux/sched.h>
68782+#include <linux/file.h>
68783+#include <linux/fs.h>
68784+#include <linux/kdev_t.h>
68785+#include <linux/net.h>
68786+#include <linux/in.h>
68787+#include <linux/ip.h>
68788+#include <linux/skbuff.h>
68789+#include <linux/sysctl.h>
68790+
68791+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
68792+void
68793+pax_set_initial_flags(struct linux_binprm *bprm)
68794+{
68795+ return;
68796+}
68797+#endif
68798+
68799+#ifdef CONFIG_SYSCTL
68800+__u32
68801+gr_handle_sysctl(const struct ctl_table * table, const int op)
68802+{
68803+ return 0;
68804+}
68805+#endif
68806+
68807+#ifdef CONFIG_TASKSTATS
68808+int gr_is_taskstats_denied(int pid)
68809+{
68810+ return 0;
68811+}
68812+#endif
68813+
68814+int
68815+gr_acl_is_enabled(void)
68816+{
68817+ return 0;
68818+}
68819+
68820+void
68821+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
68822+{
68823+ return;
68824+}
68825+
68826+int
68827+gr_handle_rawio(const struct inode *inode)
68828+{
68829+ return 0;
68830+}
68831+
68832+void
68833+gr_acl_handle_psacct(struct task_struct *task, const long code)
68834+{
68835+ return;
68836+}
68837+
68838+int
68839+gr_handle_ptrace(struct task_struct *task, const long request)
68840+{
68841+ return 0;
68842+}
68843+
68844+int
68845+gr_handle_proc_ptrace(struct task_struct *task)
68846+{
68847+ return 0;
68848+}
68849+
68850+int
68851+gr_set_acls(const int type)
68852+{
68853+ return 0;
68854+}
68855+
68856+int
68857+gr_check_hidden_task(const struct task_struct *tsk)
68858+{
68859+ return 0;
68860+}
68861+
68862+int
68863+gr_check_protected_task(const struct task_struct *task)
68864+{
68865+ return 0;
68866+}
68867+
68868+int
68869+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
68870+{
68871+ return 0;
68872+}
68873+
68874+void
68875+gr_copy_label(struct task_struct *tsk)
68876+{
68877+ return;
68878+}
68879+
68880+void
68881+gr_set_pax_flags(struct task_struct *task)
68882+{
68883+ return;
68884+}
68885+
68886+int
68887+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
68888+ const int unsafe_share)
68889+{
68890+ return 0;
68891+}
68892+
68893+void
68894+gr_handle_delete(const ino_t ino, const dev_t dev)
68895+{
68896+ return;
68897+}
68898+
68899+void
68900+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
68901+{
68902+ return;
68903+}
68904+
68905+void
68906+gr_handle_crash(struct task_struct *task, const int sig)
68907+{
68908+ return;
68909+}
68910+
68911+int
68912+gr_check_crash_exec(const struct file *filp)
68913+{
68914+ return 0;
68915+}
68916+
68917+int
68918+gr_check_crash_uid(const kuid_t uid)
68919+{
68920+ return 0;
68921+}
68922+
68923+void
68924+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
68925+ struct dentry *old_dentry,
68926+ struct dentry *new_dentry,
68927+ struct vfsmount *mnt, const __u8 replace)
68928+{
68929+ return;
68930+}
68931+
68932+int
68933+gr_search_socket(const int family, const int type, const int protocol)
68934+{
68935+ return 1;
68936+}
68937+
68938+int
68939+gr_search_connectbind(const int mode, const struct socket *sock,
68940+ const struct sockaddr_in *addr)
68941+{
68942+ return 0;
68943+}
68944+
68945+void
68946+gr_handle_alertkill(struct task_struct *task)
68947+{
68948+ return;
68949+}
68950+
68951+__u32
68952+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
68953+{
68954+ return 1;
68955+}
68956+
68957+__u32
68958+gr_acl_handle_hidden_file(const struct dentry * dentry,
68959+ const struct vfsmount * mnt)
68960+{
68961+ return 1;
68962+}
68963+
68964+__u32
68965+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
68966+ int acc_mode)
68967+{
68968+ return 1;
68969+}
68970+
68971+__u32
68972+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
68973+{
68974+ return 1;
68975+}
68976+
68977+__u32
68978+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
68979+{
68980+ return 1;
68981+}
68982+
68983+int
68984+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
68985+ unsigned int *vm_flags)
68986+{
68987+ return 1;
68988+}
68989+
68990+__u32
68991+gr_acl_handle_truncate(const struct dentry * dentry,
68992+ const struct vfsmount * mnt)
68993+{
68994+ return 1;
68995+}
68996+
68997+__u32
68998+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
68999+{
69000+ return 1;
69001+}
69002+
69003+__u32
69004+gr_acl_handle_access(const struct dentry * dentry,
69005+ const struct vfsmount * mnt, const int fmode)
69006+{
69007+ return 1;
69008+}
69009+
69010+__u32
69011+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
69012+ umode_t *mode)
69013+{
69014+ return 1;
69015+}
69016+
69017+__u32
69018+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
69019+{
69020+ return 1;
69021+}
69022+
69023+__u32
69024+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
69025+{
69026+ return 1;
69027+}
69028+
69029+void
69030+grsecurity_init(void)
69031+{
69032+ return;
69033+}
69034+
69035+umode_t gr_acl_umask(void)
69036+{
69037+ return 0;
69038+}
69039+
69040+__u32
69041+gr_acl_handle_mknod(const struct dentry * new_dentry,
69042+ const struct dentry * parent_dentry,
69043+ const struct vfsmount * parent_mnt,
69044+ const int mode)
69045+{
69046+ return 1;
69047+}
69048+
69049+__u32
69050+gr_acl_handle_mkdir(const struct dentry * new_dentry,
69051+ const struct dentry * parent_dentry,
69052+ const struct vfsmount * parent_mnt)
69053+{
69054+ return 1;
69055+}
69056+
69057+__u32
69058+gr_acl_handle_symlink(const struct dentry * new_dentry,
69059+ const struct dentry * parent_dentry,
69060+ const struct vfsmount * parent_mnt, const struct filename *from)
69061+{
69062+ return 1;
69063+}
69064+
69065+__u32
69066+gr_acl_handle_link(const struct dentry * new_dentry,
69067+ const struct dentry * parent_dentry,
69068+ const struct vfsmount * parent_mnt,
69069+ const struct dentry * old_dentry,
69070+ const struct vfsmount * old_mnt, const struct filename *to)
69071+{
69072+ return 1;
69073+}
69074+
69075+int
69076+gr_acl_handle_rename(const struct dentry *new_dentry,
69077+ const struct dentry *parent_dentry,
69078+ const struct vfsmount *parent_mnt,
69079+ const struct dentry *old_dentry,
69080+ const struct inode *old_parent_inode,
69081+ const struct vfsmount *old_mnt, const struct filename *newname)
69082+{
69083+ return 0;
69084+}
69085+
69086+int
69087+gr_acl_handle_filldir(const struct file *file, const char *name,
69088+ const int namelen, const ino_t ino)
69089+{
69090+ return 1;
69091+}
69092+
69093+int
69094+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
69095+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
69096+{
69097+ return 1;
69098+}
69099+
69100+int
69101+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
69102+{
69103+ return 0;
69104+}
69105+
69106+int
69107+gr_search_accept(const struct socket *sock)
69108+{
69109+ return 0;
69110+}
69111+
69112+int
69113+gr_search_listen(const struct socket *sock)
69114+{
69115+ return 0;
69116+}
69117+
69118+int
69119+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
69120+{
69121+ return 0;
69122+}
69123+
69124+__u32
69125+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
69126+{
69127+ return 1;
69128+}
69129+
69130+__u32
69131+gr_acl_handle_creat(const struct dentry * dentry,
69132+ const struct dentry * p_dentry,
69133+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
69134+ const int imode)
69135+{
69136+ return 1;
69137+}
69138+
69139+void
69140+gr_acl_handle_exit(void)
69141+{
69142+ return;
69143+}
69144+
69145+int
69146+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
69147+{
69148+ return 1;
69149+}
69150+
69151+void
69152+gr_set_role_label(const kuid_t uid, const kgid_t gid)
69153+{
69154+ return;
69155+}
69156+
69157+int
69158+gr_acl_handle_procpidmem(const struct task_struct *task)
69159+{
69160+ return 0;
69161+}
69162+
69163+int
69164+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
69165+{
69166+ return 0;
69167+}
69168+
69169+int
69170+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
69171+{
69172+ return 0;
69173+}
69174+
69175+void
69176+gr_set_kernel_label(struct task_struct *task)
69177+{
69178+ return;
69179+}
69180+
69181+int
69182+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
69183+{
69184+ return 0;
69185+}
69186+
69187+int
69188+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
69189+{
69190+ return 0;
69191+}
69192+
69193+int gr_acl_enable_at_secure(void)
69194+{
69195+ return 0;
69196+}
69197+
69198+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
69199+{
69200+ return dentry->d_sb->s_dev;
69201+}
69202+
69203+void gr_put_exec_file(struct task_struct *task)
69204+{
69205+ return;
69206+}
69207+
69208+EXPORT_SYMBOL(gr_set_kernel_label);
69209+#ifdef CONFIG_SECURITY
69210+EXPORT_SYMBOL(gr_check_user_change);
69211+EXPORT_SYMBOL(gr_check_group_change);
69212+#endif
69213diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
69214new file mode 100644
69215index 0000000..387032b
69216--- /dev/null
69217+++ b/grsecurity/grsec_exec.c
69218@@ -0,0 +1,187 @@
69219+#include <linux/kernel.h>
69220+#include <linux/sched.h>
69221+#include <linux/file.h>
69222+#include <linux/binfmts.h>
69223+#include <linux/fs.h>
69224+#include <linux/types.h>
69225+#include <linux/grdefs.h>
69226+#include <linux/grsecurity.h>
69227+#include <linux/grinternal.h>
69228+#include <linux/capability.h>
69229+#include <linux/module.h>
69230+#include <linux/compat.h>
69231+
69232+#include <asm/uaccess.h>
69233+
69234+#ifdef CONFIG_GRKERNSEC_EXECLOG
69235+static char gr_exec_arg_buf[132];
69236+static DEFINE_MUTEX(gr_exec_arg_mutex);
69237+#endif
69238+
69239+struct user_arg_ptr {
69240+#ifdef CONFIG_COMPAT
69241+ bool is_compat;
69242+#endif
69243+ union {
69244+ const char __user *const __user *native;
69245+#ifdef CONFIG_COMPAT
69246+ const compat_uptr_t __user *compat;
69247+#endif
69248+ } ptr;
69249+};
69250+
69251+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
69252+
69253+void
69254+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
69255+{
69256+#ifdef CONFIG_GRKERNSEC_EXECLOG
69257+ char *grarg = gr_exec_arg_buf;
69258+ unsigned int i, x, execlen = 0;
69259+ char c;
69260+
69261+ if (!((grsec_enable_execlog && grsec_enable_group &&
69262+ in_group_p(grsec_audit_gid))
69263+ || (grsec_enable_execlog && !grsec_enable_group)))
69264+ return;
69265+
69266+ mutex_lock(&gr_exec_arg_mutex);
69267+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
69268+
69269+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
69270+ const char __user *p;
69271+ unsigned int len;
69272+
69273+ p = get_user_arg_ptr(argv, i);
69274+ if (IS_ERR(p))
69275+ goto log;
69276+
69277+ len = strnlen_user(p, 128 - execlen);
69278+ if (len > 128 - execlen)
69279+ len = 128 - execlen;
69280+ else if (len > 0)
69281+ len--;
69282+ if (copy_from_user(grarg + execlen, p, len))
69283+ goto log;
69284+
69285+ /* rewrite unprintable characters */
69286+ for (x = 0; x < len; x++) {
69287+ c = *(grarg + execlen + x);
69288+ if (c < 32 || c > 126)
69289+ *(grarg + execlen + x) = ' ';
69290+ }
69291+
69292+ execlen += len;
69293+ *(grarg + execlen) = ' ';
69294+ *(grarg + execlen + 1) = '\0';
69295+ execlen++;
69296+ }
69297+
69298+ log:
69299+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
69300+ bprm->file->f_path.mnt, grarg);
69301+ mutex_unlock(&gr_exec_arg_mutex);
69302+#endif
69303+ return;
69304+}
69305+
69306+#ifdef CONFIG_GRKERNSEC
69307+extern int gr_acl_is_capable(const int cap);
69308+extern int gr_acl_is_capable_nolog(const int cap);
69309+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
69310+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
69311+extern int gr_chroot_is_capable(const int cap);
69312+extern int gr_chroot_is_capable_nolog(const int cap);
69313+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
69314+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
69315+#endif
69316+
69317+const char *captab_log[] = {
69318+ "CAP_CHOWN",
69319+ "CAP_DAC_OVERRIDE",
69320+ "CAP_DAC_READ_SEARCH",
69321+ "CAP_FOWNER",
69322+ "CAP_FSETID",
69323+ "CAP_KILL",
69324+ "CAP_SETGID",
69325+ "CAP_SETUID",
69326+ "CAP_SETPCAP",
69327+ "CAP_LINUX_IMMUTABLE",
69328+ "CAP_NET_BIND_SERVICE",
69329+ "CAP_NET_BROADCAST",
69330+ "CAP_NET_ADMIN",
69331+ "CAP_NET_RAW",
69332+ "CAP_IPC_LOCK",
69333+ "CAP_IPC_OWNER",
69334+ "CAP_SYS_MODULE",
69335+ "CAP_SYS_RAWIO",
69336+ "CAP_SYS_CHROOT",
69337+ "CAP_SYS_PTRACE",
69338+ "CAP_SYS_PACCT",
69339+ "CAP_SYS_ADMIN",
69340+ "CAP_SYS_BOOT",
69341+ "CAP_SYS_NICE",
69342+ "CAP_SYS_RESOURCE",
69343+ "CAP_SYS_TIME",
69344+ "CAP_SYS_TTY_CONFIG",
69345+ "CAP_MKNOD",
69346+ "CAP_LEASE",
69347+ "CAP_AUDIT_WRITE",
69348+ "CAP_AUDIT_CONTROL",
69349+ "CAP_SETFCAP",
69350+ "CAP_MAC_OVERRIDE",
69351+ "CAP_MAC_ADMIN",
69352+ "CAP_SYSLOG",
69353+ "CAP_WAKE_ALARM"
69354+};
69355+
69356+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
69357+
69358+int gr_is_capable(const int cap)
69359+{
69360+#ifdef CONFIG_GRKERNSEC
69361+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
69362+ return 1;
69363+ return 0;
69364+#else
69365+ return 1;
69366+#endif
69367+}
69368+
69369+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
69370+{
69371+#ifdef CONFIG_GRKERNSEC
69372+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
69373+ return 1;
69374+ return 0;
69375+#else
69376+ return 1;
69377+#endif
69378+}
69379+
69380+int gr_is_capable_nolog(const int cap)
69381+{
69382+#ifdef CONFIG_GRKERNSEC
69383+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
69384+ return 1;
69385+ return 0;
69386+#else
69387+ return 1;
69388+#endif
69389+}
69390+
69391+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
69392+{
69393+#ifdef CONFIG_GRKERNSEC
69394+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
69395+ return 1;
69396+ return 0;
69397+#else
69398+ return 1;
69399+#endif
69400+}
69401+
69402+EXPORT_SYMBOL(gr_is_capable);
69403+EXPORT_SYMBOL(gr_is_capable_nolog);
69404+EXPORT_SYMBOL(gr_task_is_capable);
69405+EXPORT_SYMBOL(gr_task_is_capable_nolog);
69406diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
69407new file mode 100644
69408index 0000000..06cc6ea
69409--- /dev/null
69410+++ b/grsecurity/grsec_fifo.c
69411@@ -0,0 +1,24 @@
69412+#include <linux/kernel.h>
69413+#include <linux/sched.h>
69414+#include <linux/fs.h>
69415+#include <linux/file.h>
69416+#include <linux/grinternal.h>
69417+
69418+int
69419+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
69420+ const struct dentry *dir, const int flag, const int acc_mode)
69421+{
69422+#ifdef CONFIG_GRKERNSEC_FIFO
69423+ const struct cred *cred = current_cred();
69424+
69425+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
69426+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
69427+ !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
69428+ !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
69429+ if (!inode_permission(dentry->d_inode, acc_mode))
69430+ 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));
69431+ return -EACCES;
69432+ }
69433+#endif
69434+ return 0;
69435+}
69436diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
69437new file mode 100644
69438index 0000000..8ca18bf
69439--- /dev/null
69440+++ b/grsecurity/grsec_fork.c
69441@@ -0,0 +1,23 @@
69442+#include <linux/kernel.h>
69443+#include <linux/sched.h>
69444+#include <linux/grsecurity.h>
69445+#include <linux/grinternal.h>
69446+#include <linux/errno.h>
69447+
69448+void
69449+gr_log_forkfail(const int retval)
69450+{
69451+#ifdef CONFIG_GRKERNSEC_FORKFAIL
69452+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
69453+ switch (retval) {
69454+ case -EAGAIN:
69455+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
69456+ break;
69457+ case -ENOMEM:
69458+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
69459+ break;
69460+ }
69461+ }
69462+#endif
69463+ return;
69464+}
69465diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
69466new file mode 100644
69467index 0000000..99a0cb9
69468--- /dev/null
69469+++ b/grsecurity/grsec_init.c
69470@@ -0,0 +1,283 @@
69471+#include <linux/kernel.h>
69472+#include <linux/sched.h>
69473+#include <linux/mm.h>
69474+#include <linux/gracl.h>
69475+#include <linux/slab.h>
69476+#include <linux/vmalloc.h>
69477+#include <linux/percpu.h>
69478+#include <linux/module.h>
69479+
69480+int grsec_enable_ptrace_readexec;
69481+int grsec_enable_setxid;
69482+int grsec_enable_symlinkown;
69483+kgid_t grsec_symlinkown_gid;
69484+int grsec_enable_brute;
69485+int grsec_enable_link;
69486+int grsec_enable_dmesg;
69487+int grsec_enable_harden_ptrace;
69488+int grsec_enable_fifo;
69489+int grsec_enable_execlog;
69490+int grsec_enable_signal;
69491+int grsec_enable_forkfail;
69492+int grsec_enable_audit_ptrace;
69493+int grsec_enable_time;
69494+int grsec_enable_group;
69495+kgid_t grsec_audit_gid;
69496+int grsec_enable_chdir;
69497+int grsec_enable_mount;
69498+int grsec_enable_rofs;
69499+int grsec_deny_new_usb;
69500+int grsec_enable_chroot_findtask;
69501+int grsec_enable_chroot_mount;
69502+int grsec_enable_chroot_shmat;
69503+int grsec_enable_chroot_fchdir;
69504+int grsec_enable_chroot_double;
69505+int grsec_enable_chroot_pivot;
69506+int grsec_enable_chroot_chdir;
69507+int grsec_enable_chroot_chmod;
69508+int grsec_enable_chroot_mknod;
69509+int grsec_enable_chroot_nice;
69510+int grsec_enable_chroot_execlog;
69511+int grsec_enable_chroot_caps;
69512+int grsec_enable_chroot_sysctl;
69513+int grsec_enable_chroot_unix;
69514+int grsec_enable_tpe;
69515+kgid_t grsec_tpe_gid;
69516+int grsec_enable_blackhole;
69517+#ifdef CONFIG_IPV6_MODULE
69518+EXPORT_SYMBOL(grsec_enable_blackhole);
69519+#endif
69520+int grsec_lastack_retries;
69521+int grsec_enable_tpe_all;
69522+int grsec_enable_tpe_invert;
69523+int grsec_enable_socket_all;
69524+kgid_t grsec_socket_all_gid;
69525+int grsec_enable_socket_client;
69526+kgid_t grsec_socket_client_gid;
69527+int grsec_enable_socket_server;
69528+kgid_t grsec_socket_server_gid;
69529+int grsec_resource_logging;
69530+int grsec_disable_privio;
69531+int grsec_enable_log_rwxmaps;
69532+int grsec_lock;
69533+
69534+DEFINE_SPINLOCK(grsec_alert_lock);
69535+unsigned long grsec_alert_wtime = 0;
69536+unsigned long grsec_alert_fyet = 0;
69537+
69538+DEFINE_SPINLOCK(grsec_audit_lock);
69539+
69540+DEFINE_RWLOCK(grsec_exec_file_lock);
69541+
69542+char *gr_shared_page[4];
69543+
69544+char *gr_alert_log_fmt;
69545+char *gr_audit_log_fmt;
69546+char *gr_alert_log_buf;
69547+char *gr_audit_log_buf;
69548+
69549+extern struct gr_arg *gr_usermode;
69550+extern unsigned char *gr_system_salt;
69551+extern unsigned char *gr_system_sum;
69552+
69553+void __init
69554+grsecurity_init(void)
69555+{
69556+ int j;
69557+ /* create the per-cpu shared pages */
69558+
69559+#ifdef CONFIG_X86
69560+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
69561+#endif
69562+
69563+ for (j = 0; j < 4; j++) {
69564+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
69565+ if (gr_shared_page[j] == NULL) {
69566+ panic("Unable to allocate grsecurity shared page");
69567+ return;
69568+ }
69569+ }
69570+
69571+ /* allocate log buffers */
69572+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
69573+ if (!gr_alert_log_fmt) {
69574+ panic("Unable to allocate grsecurity alert log format buffer");
69575+ return;
69576+ }
69577+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
69578+ if (!gr_audit_log_fmt) {
69579+ panic("Unable to allocate grsecurity audit log format buffer");
69580+ return;
69581+ }
69582+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
69583+ if (!gr_alert_log_buf) {
69584+ panic("Unable to allocate grsecurity alert log buffer");
69585+ return;
69586+ }
69587+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
69588+ if (!gr_audit_log_buf) {
69589+ panic("Unable to allocate grsecurity audit log buffer");
69590+ return;
69591+ }
69592+
69593+ /* allocate memory for authentication structure */
69594+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
69595+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
69596+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
69597+
69598+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
69599+ panic("Unable to allocate grsecurity authentication structure");
69600+ return;
69601+ }
69602+
69603+
69604+#ifdef CONFIG_GRKERNSEC_IO
69605+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
69606+ grsec_disable_privio = 1;
69607+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
69608+ grsec_disable_privio = 1;
69609+#else
69610+ grsec_disable_privio = 0;
69611+#endif
69612+#endif
69613+
69614+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
69615+ /* for backward compatibility, tpe_invert always defaults to on if
69616+ enabled in the kernel
69617+ */
69618+ grsec_enable_tpe_invert = 1;
69619+#endif
69620+
69621+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
69622+#ifndef CONFIG_GRKERNSEC_SYSCTL
69623+ grsec_lock = 1;
69624+#endif
69625+
69626+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
69627+ grsec_enable_log_rwxmaps = 1;
69628+#endif
69629+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
69630+ grsec_enable_group = 1;
69631+ grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
69632+#endif
69633+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
69634+ grsec_enable_ptrace_readexec = 1;
69635+#endif
69636+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
69637+ grsec_enable_chdir = 1;
69638+#endif
69639+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
69640+ grsec_enable_harden_ptrace = 1;
69641+#endif
69642+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
69643+ grsec_enable_mount = 1;
69644+#endif
69645+#ifdef CONFIG_GRKERNSEC_LINK
69646+ grsec_enable_link = 1;
69647+#endif
69648+#ifdef CONFIG_GRKERNSEC_BRUTE
69649+ grsec_enable_brute = 1;
69650+#endif
69651+#ifdef CONFIG_GRKERNSEC_DMESG
69652+ grsec_enable_dmesg = 1;
69653+#endif
69654+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
69655+ grsec_enable_blackhole = 1;
69656+ grsec_lastack_retries = 4;
69657+#endif
69658+#ifdef CONFIG_GRKERNSEC_FIFO
69659+ grsec_enable_fifo = 1;
69660+#endif
69661+#ifdef CONFIG_GRKERNSEC_EXECLOG
69662+ grsec_enable_execlog = 1;
69663+#endif
69664+#ifdef CONFIG_GRKERNSEC_SETXID
69665+ grsec_enable_setxid = 1;
69666+#endif
69667+#ifdef CONFIG_GRKERNSEC_SIGNAL
69668+ grsec_enable_signal = 1;
69669+#endif
69670+#ifdef CONFIG_GRKERNSEC_FORKFAIL
69671+ grsec_enable_forkfail = 1;
69672+#endif
69673+#ifdef CONFIG_GRKERNSEC_TIME
69674+ grsec_enable_time = 1;
69675+#endif
69676+#ifdef CONFIG_GRKERNSEC_RESLOG
69677+ grsec_resource_logging = 1;
69678+#endif
69679+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
69680+ grsec_enable_chroot_findtask = 1;
69681+#endif
69682+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
69683+ grsec_enable_chroot_unix = 1;
69684+#endif
69685+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
69686+ grsec_enable_chroot_mount = 1;
69687+#endif
69688+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
69689+ grsec_enable_chroot_fchdir = 1;
69690+#endif
69691+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
69692+ grsec_enable_chroot_shmat = 1;
69693+#endif
69694+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
69695+ grsec_enable_audit_ptrace = 1;
69696+#endif
69697+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
69698+ grsec_enable_chroot_double = 1;
69699+#endif
69700+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
69701+ grsec_enable_chroot_pivot = 1;
69702+#endif
69703+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
69704+ grsec_enable_chroot_chdir = 1;
69705+#endif
69706+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
69707+ grsec_enable_chroot_chmod = 1;
69708+#endif
69709+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
69710+ grsec_enable_chroot_mknod = 1;
69711+#endif
69712+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
69713+ grsec_enable_chroot_nice = 1;
69714+#endif
69715+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
69716+ grsec_enable_chroot_execlog = 1;
69717+#endif
69718+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
69719+ grsec_enable_chroot_caps = 1;
69720+#endif
69721+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
69722+ grsec_enable_chroot_sysctl = 1;
69723+#endif
69724+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
69725+ grsec_enable_symlinkown = 1;
69726+ grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
69727+#endif
69728+#ifdef CONFIG_GRKERNSEC_TPE
69729+ grsec_enable_tpe = 1;
69730+ grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
69731+#ifdef CONFIG_GRKERNSEC_TPE_ALL
69732+ grsec_enable_tpe_all = 1;
69733+#endif
69734+#endif
69735+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
69736+ grsec_enable_socket_all = 1;
69737+ grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
69738+#endif
69739+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
69740+ grsec_enable_socket_client = 1;
69741+ grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
69742+#endif
69743+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
69744+ grsec_enable_socket_server = 1;
69745+ grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
69746+#endif
69747+#endif
69748+#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
69749+ grsec_deny_new_usb = 1;
69750+#endif
69751+
69752+ return;
69753+}
69754diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
69755new file mode 100644
69756index 0000000..5e05e20
69757--- /dev/null
69758+++ b/grsecurity/grsec_link.c
69759@@ -0,0 +1,58 @@
69760+#include <linux/kernel.h>
69761+#include <linux/sched.h>
69762+#include <linux/fs.h>
69763+#include <linux/file.h>
69764+#include <linux/grinternal.h>
69765+
69766+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
69767+{
69768+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
69769+ const struct inode *link_inode = link->dentry->d_inode;
69770+
69771+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
69772+ /* ignore root-owned links, e.g. /proc/self */
69773+ gr_is_global_nonroot(link_inode->i_uid) && target &&
69774+ !uid_eq(link_inode->i_uid, target->i_uid)) {
69775+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
69776+ return 1;
69777+ }
69778+#endif
69779+ return 0;
69780+}
69781+
69782+int
69783+gr_handle_follow_link(const struct inode *parent,
69784+ const struct inode *inode,
69785+ const struct dentry *dentry, const struct vfsmount *mnt)
69786+{
69787+#ifdef CONFIG_GRKERNSEC_LINK
69788+ const struct cred *cred = current_cred();
69789+
69790+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
69791+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
69792+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
69793+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
69794+ return -EACCES;
69795+ }
69796+#endif
69797+ return 0;
69798+}
69799+
69800+int
69801+gr_handle_hardlink(const struct dentry *dentry,
69802+ const struct vfsmount *mnt,
69803+ struct inode *inode, const int mode, const struct filename *to)
69804+{
69805+#ifdef CONFIG_GRKERNSEC_LINK
69806+ const struct cred *cred = current_cred();
69807+
69808+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
69809+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
69810+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
69811+ !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
69812+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
69813+ return -EPERM;
69814+ }
69815+#endif
69816+ return 0;
69817+}
69818diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
69819new file mode 100644
69820index 0000000..dbe0a6b
69821--- /dev/null
69822+++ b/grsecurity/grsec_log.c
69823@@ -0,0 +1,341 @@
69824+#include <linux/kernel.h>
69825+#include <linux/sched.h>
69826+#include <linux/file.h>
69827+#include <linux/tty.h>
69828+#include <linux/fs.h>
69829+#include <linux/mm.h>
69830+#include <linux/grinternal.h>
69831+
69832+#ifdef CONFIG_TREE_PREEMPT_RCU
69833+#define DISABLE_PREEMPT() preempt_disable()
69834+#define ENABLE_PREEMPT() preempt_enable()
69835+#else
69836+#define DISABLE_PREEMPT()
69837+#define ENABLE_PREEMPT()
69838+#endif
69839+
69840+#define BEGIN_LOCKS(x) \
69841+ DISABLE_PREEMPT(); \
69842+ rcu_read_lock(); \
69843+ read_lock(&tasklist_lock); \
69844+ read_lock(&grsec_exec_file_lock); \
69845+ if (x != GR_DO_AUDIT) \
69846+ spin_lock(&grsec_alert_lock); \
69847+ else \
69848+ spin_lock(&grsec_audit_lock)
69849+
69850+#define END_LOCKS(x) \
69851+ if (x != GR_DO_AUDIT) \
69852+ spin_unlock(&grsec_alert_lock); \
69853+ else \
69854+ spin_unlock(&grsec_audit_lock); \
69855+ read_unlock(&grsec_exec_file_lock); \
69856+ read_unlock(&tasklist_lock); \
69857+ rcu_read_unlock(); \
69858+ ENABLE_PREEMPT(); \
69859+ if (x == GR_DONT_AUDIT) \
69860+ gr_handle_alertkill(current)
69861+
69862+enum {
69863+ FLOODING,
69864+ NO_FLOODING
69865+};
69866+
69867+extern char *gr_alert_log_fmt;
69868+extern char *gr_audit_log_fmt;
69869+extern char *gr_alert_log_buf;
69870+extern char *gr_audit_log_buf;
69871+
69872+static int gr_log_start(int audit)
69873+{
69874+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
69875+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
69876+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
69877+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
69878+ unsigned long curr_secs = get_seconds();
69879+
69880+ if (audit == GR_DO_AUDIT)
69881+ goto set_fmt;
69882+
69883+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
69884+ grsec_alert_wtime = curr_secs;
69885+ grsec_alert_fyet = 0;
69886+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
69887+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
69888+ grsec_alert_fyet++;
69889+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
69890+ grsec_alert_wtime = curr_secs;
69891+ grsec_alert_fyet++;
69892+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
69893+ return FLOODING;
69894+ }
69895+ else return FLOODING;
69896+
69897+set_fmt:
69898+#endif
69899+ memset(buf, 0, PAGE_SIZE);
69900+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
69901+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
69902+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
69903+ } else if (current->signal->curr_ip) {
69904+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
69905+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
69906+ } else if (gr_acl_is_enabled()) {
69907+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
69908+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
69909+ } else {
69910+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
69911+ strcpy(buf, fmt);
69912+ }
69913+
69914+ return NO_FLOODING;
69915+}
69916+
69917+static void gr_log_middle(int audit, const char *msg, va_list ap)
69918+ __attribute__ ((format (printf, 2, 0)));
69919+
69920+static void gr_log_middle(int audit, const char *msg, va_list ap)
69921+{
69922+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
69923+ unsigned int len = strlen(buf);
69924+
69925+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
69926+
69927+ return;
69928+}
69929+
69930+static void gr_log_middle_varargs(int audit, const char *msg, ...)
69931+ __attribute__ ((format (printf, 2, 3)));
69932+
69933+static void gr_log_middle_varargs(int audit, const char *msg, ...)
69934+{
69935+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
69936+ unsigned int len = strlen(buf);
69937+ va_list ap;
69938+
69939+ va_start(ap, msg);
69940+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
69941+ va_end(ap);
69942+
69943+ return;
69944+}
69945+
69946+static void gr_log_end(int audit, int append_default)
69947+{
69948+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
69949+ if (append_default) {
69950+ struct task_struct *task = current;
69951+ struct task_struct *parent = task->real_parent;
69952+ const struct cred *cred = __task_cred(task);
69953+ const struct cred *pcred = __task_cred(parent);
69954+ unsigned int len = strlen(buf);
69955+
69956+ 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));
69957+ }
69958+
69959+ printk("%s\n", buf);
69960+
69961+ return;
69962+}
69963+
69964+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
69965+{
69966+ int logtype;
69967+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
69968+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
69969+ void *voidptr = NULL;
69970+ int num1 = 0, num2 = 0;
69971+ unsigned long ulong1 = 0, ulong2 = 0;
69972+ struct dentry *dentry = NULL;
69973+ struct vfsmount *mnt = NULL;
69974+ struct file *file = NULL;
69975+ struct task_struct *task = NULL;
69976+ struct vm_area_struct *vma = NULL;
69977+ const struct cred *cred, *pcred;
69978+ va_list ap;
69979+
69980+ BEGIN_LOCKS(audit);
69981+ logtype = gr_log_start(audit);
69982+ if (logtype == FLOODING) {
69983+ END_LOCKS(audit);
69984+ return;
69985+ }
69986+ va_start(ap, argtypes);
69987+ switch (argtypes) {
69988+ case GR_TTYSNIFF:
69989+ task = va_arg(ap, struct task_struct *);
69990+ 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));
69991+ break;
69992+ case GR_SYSCTL_HIDDEN:
69993+ str1 = va_arg(ap, char *);
69994+ gr_log_middle_varargs(audit, msg, result, str1);
69995+ break;
69996+ case GR_RBAC:
69997+ dentry = va_arg(ap, struct dentry *);
69998+ mnt = va_arg(ap, struct vfsmount *);
69999+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
70000+ break;
70001+ case GR_RBAC_STR:
70002+ dentry = va_arg(ap, struct dentry *);
70003+ mnt = va_arg(ap, struct vfsmount *);
70004+ str1 = va_arg(ap, char *);
70005+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
70006+ break;
70007+ case GR_STR_RBAC:
70008+ str1 = va_arg(ap, char *);
70009+ dentry = va_arg(ap, struct dentry *);
70010+ mnt = va_arg(ap, struct vfsmount *);
70011+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
70012+ break;
70013+ case GR_RBAC_MODE2:
70014+ dentry = va_arg(ap, struct dentry *);
70015+ mnt = va_arg(ap, struct vfsmount *);
70016+ str1 = va_arg(ap, char *);
70017+ str2 = va_arg(ap, char *);
70018+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
70019+ break;
70020+ case GR_RBAC_MODE3:
70021+ dentry = va_arg(ap, struct dentry *);
70022+ mnt = va_arg(ap, struct vfsmount *);
70023+ str1 = va_arg(ap, char *);
70024+ str2 = va_arg(ap, char *);
70025+ str3 = va_arg(ap, char *);
70026+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
70027+ break;
70028+ case GR_FILENAME:
70029+ dentry = va_arg(ap, struct dentry *);
70030+ mnt = va_arg(ap, struct vfsmount *);
70031+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
70032+ break;
70033+ case GR_STR_FILENAME:
70034+ str1 = va_arg(ap, char *);
70035+ dentry = va_arg(ap, struct dentry *);
70036+ mnt = va_arg(ap, struct vfsmount *);
70037+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
70038+ break;
70039+ case GR_FILENAME_STR:
70040+ dentry = va_arg(ap, struct dentry *);
70041+ mnt = va_arg(ap, struct vfsmount *);
70042+ str1 = va_arg(ap, char *);
70043+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
70044+ break;
70045+ case GR_FILENAME_TWO_INT:
70046+ dentry = va_arg(ap, struct dentry *);
70047+ mnt = va_arg(ap, struct vfsmount *);
70048+ num1 = va_arg(ap, int);
70049+ num2 = va_arg(ap, int);
70050+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
70051+ break;
70052+ case GR_FILENAME_TWO_INT_STR:
70053+ dentry = va_arg(ap, struct dentry *);
70054+ mnt = va_arg(ap, struct vfsmount *);
70055+ num1 = va_arg(ap, int);
70056+ num2 = va_arg(ap, int);
70057+ str1 = va_arg(ap, char *);
70058+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
70059+ break;
70060+ case GR_TEXTREL:
70061+ file = va_arg(ap, struct file *);
70062+ ulong1 = va_arg(ap, unsigned long);
70063+ ulong2 = va_arg(ap, unsigned long);
70064+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
70065+ break;
70066+ case GR_PTRACE:
70067+ task = va_arg(ap, struct task_struct *);
70068+ 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));
70069+ break;
70070+ case GR_RESOURCE:
70071+ task = va_arg(ap, struct task_struct *);
70072+ cred = __task_cred(task);
70073+ pcred = __task_cred(task->real_parent);
70074+ ulong1 = va_arg(ap, unsigned long);
70075+ str1 = va_arg(ap, char *);
70076+ ulong2 = va_arg(ap, unsigned long);
70077+ 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));
70078+ break;
70079+ case GR_CAP:
70080+ task = va_arg(ap, struct task_struct *);
70081+ cred = __task_cred(task);
70082+ pcred = __task_cred(task->real_parent);
70083+ str1 = va_arg(ap, char *);
70084+ 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));
70085+ break;
70086+ case GR_SIG:
70087+ str1 = va_arg(ap, char *);
70088+ voidptr = va_arg(ap, void *);
70089+ gr_log_middle_varargs(audit, msg, str1, voidptr);
70090+ break;
70091+ case GR_SIG2:
70092+ task = va_arg(ap, struct task_struct *);
70093+ cred = __task_cred(task);
70094+ pcred = __task_cred(task->real_parent);
70095+ num1 = va_arg(ap, int);
70096+ 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));
70097+ break;
70098+ case GR_CRASH1:
70099+ task = va_arg(ap, struct task_struct *);
70100+ cred = __task_cred(task);
70101+ pcred = __task_cred(task->real_parent);
70102+ ulong1 = va_arg(ap, unsigned long);
70103+ 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);
70104+ break;
70105+ case GR_CRASH2:
70106+ task = va_arg(ap, struct task_struct *);
70107+ cred = __task_cred(task);
70108+ pcred = __task_cred(task->real_parent);
70109+ ulong1 = va_arg(ap, unsigned long);
70110+ 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);
70111+ break;
70112+ case GR_RWXMAP:
70113+ file = va_arg(ap, struct file *);
70114+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
70115+ break;
70116+ case GR_RWXMAPVMA:
70117+ vma = va_arg(ap, struct vm_area_struct *);
70118+ if (vma->vm_file)
70119+ str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
70120+ else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
70121+ str1 = "<stack>";
70122+ else if (vma->vm_start <= current->mm->brk &&
70123+ vma->vm_end >= current->mm->start_brk)
70124+ str1 = "<heap>";
70125+ else
70126+ str1 = "<anonymous mapping>";
70127+ gr_log_middle_varargs(audit, msg, str1);
70128+ break;
70129+ case GR_PSACCT:
70130+ {
70131+ unsigned int wday, cday;
70132+ __u8 whr, chr;
70133+ __u8 wmin, cmin;
70134+ __u8 wsec, csec;
70135+ char cur_tty[64] = { 0 };
70136+ char parent_tty[64] = { 0 };
70137+
70138+ task = va_arg(ap, struct task_struct *);
70139+ wday = va_arg(ap, unsigned int);
70140+ cday = va_arg(ap, unsigned int);
70141+ whr = va_arg(ap, int);
70142+ chr = va_arg(ap, int);
70143+ wmin = va_arg(ap, int);
70144+ cmin = va_arg(ap, int);
70145+ wsec = va_arg(ap, int);
70146+ csec = va_arg(ap, int);
70147+ ulong1 = va_arg(ap, unsigned long);
70148+ cred = __task_cred(task);
70149+ pcred = __task_cred(task->real_parent);
70150+
70151+ 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));
70152+ }
70153+ break;
70154+ default:
70155+ gr_log_middle(audit, msg, ap);
70156+ }
70157+ va_end(ap);
70158+ // these don't need DEFAULTSECARGS printed on the end
70159+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
70160+ gr_log_end(audit, 0);
70161+ else
70162+ gr_log_end(audit, 1);
70163+ END_LOCKS(audit);
70164+}
70165diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
70166new file mode 100644
70167index 0000000..f536303
70168--- /dev/null
70169+++ b/grsecurity/grsec_mem.c
70170@@ -0,0 +1,40 @@
70171+#include <linux/kernel.h>
70172+#include <linux/sched.h>
70173+#include <linux/mm.h>
70174+#include <linux/mman.h>
70175+#include <linux/grinternal.h>
70176+
70177+void
70178+gr_handle_ioperm(void)
70179+{
70180+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
70181+ return;
70182+}
70183+
70184+void
70185+gr_handle_iopl(void)
70186+{
70187+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
70188+ return;
70189+}
70190+
70191+void
70192+gr_handle_mem_readwrite(u64 from, u64 to)
70193+{
70194+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
70195+ return;
70196+}
70197+
70198+void
70199+gr_handle_vm86(void)
70200+{
70201+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
70202+ return;
70203+}
70204+
70205+void
70206+gr_log_badprocpid(const char *entry)
70207+{
70208+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
70209+ return;
70210+}
70211diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
70212new file mode 100644
70213index 0000000..2131422
70214--- /dev/null
70215+++ b/grsecurity/grsec_mount.c
70216@@ -0,0 +1,62 @@
70217+#include <linux/kernel.h>
70218+#include <linux/sched.h>
70219+#include <linux/mount.h>
70220+#include <linux/grsecurity.h>
70221+#include <linux/grinternal.h>
70222+
70223+void
70224+gr_log_remount(const char *devname, const int retval)
70225+{
70226+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
70227+ if (grsec_enable_mount && (retval >= 0))
70228+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
70229+#endif
70230+ return;
70231+}
70232+
70233+void
70234+gr_log_unmount(const char *devname, const int retval)
70235+{
70236+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
70237+ if (grsec_enable_mount && (retval >= 0))
70238+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
70239+#endif
70240+ return;
70241+}
70242+
70243+void
70244+gr_log_mount(const char *from, const char *to, const int retval)
70245+{
70246+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
70247+ if (grsec_enable_mount && (retval >= 0))
70248+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
70249+#endif
70250+ return;
70251+}
70252+
70253+int
70254+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
70255+{
70256+#ifdef CONFIG_GRKERNSEC_ROFS
70257+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
70258+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
70259+ return -EPERM;
70260+ } else
70261+ return 0;
70262+#endif
70263+ return 0;
70264+}
70265+
70266+int
70267+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
70268+{
70269+#ifdef CONFIG_GRKERNSEC_ROFS
70270+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
70271+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
70272+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
70273+ return -EPERM;
70274+ } else
70275+ return 0;
70276+#endif
70277+ return 0;
70278+}
70279diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
70280new file mode 100644
70281index 0000000..6ee9d50
70282--- /dev/null
70283+++ b/grsecurity/grsec_pax.c
70284@@ -0,0 +1,45 @@
70285+#include <linux/kernel.h>
70286+#include <linux/sched.h>
70287+#include <linux/mm.h>
70288+#include <linux/file.h>
70289+#include <linux/grinternal.h>
70290+#include <linux/grsecurity.h>
70291+
70292+void
70293+gr_log_textrel(struct vm_area_struct * vma)
70294+{
70295+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
70296+ if (grsec_enable_log_rwxmaps)
70297+ gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
70298+#endif
70299+ return;
70300+}
70301+
70302+void gr_log_ptgnustack(struct file *file)
70303+{
70304+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
70305+ if (grsec_enable_log_rwxmaps)
70306+ gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
70307+#endif
70308+ return;
70309+}
70310+
70311+void
70312+gr_log_rwxmmap(struct file *file)
70313+{
70314+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
70315+ if (grsec_enable_log_rwxmaps)
70316+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
70317+#endif
70318+ return;
70319+}
70320+
70321+void
70322+gr_log_rwxmprotect(struct vm_area_struct *vma)
70323+{
70324+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
70325+ if (grsec_enable_log_rwxmaps)
70326+ gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
70327+#endif
70328+ return;
70329+}
70330diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
70331new file mode 100644
70332index 0000000..f7f29aa
70333--- /dev/null
70334+++ b/grsecurity/grsec_ptrace.c
70335@@ -0,0 +1,30 @@
70336+#include <linux/kernel.h>
70337+#include <linux/sched.h>
70338+#include <linux/grinternal.h>
70339+#include <linux/security.h>
70340+
70341+void
70342+gr_audit_ptrace(struct task_struct *task)
70343+{
70344+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
70345+ if (grsec_enable_audit_ptrace)
70346+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
70347+#endif
70348+ return;
70349+}
70350+
70351+int
70352+gr_ptrace_readexec(struct file *file, int unsafe_flags)
70353+{
70354+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
70355+ const struct dentry *dentry = file->f_path.dentry;
70356+ const struct vfsmount *mnt = file->f_path.mnt;
70357+
70358+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
70359+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
70360+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
70361+ return -EACCES;
70362+ }
70363+#endif
70364+ return 0;
70365+}
70366diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
70367new file mode 100644
70368index 0000000..4e29cc7
70369--- /dev/null
70370+++ b/grsecurity/grsec_sig.c
70371@@ -0,0 +1,246 @@
70372+#include <linux/kernel.h>
70373+#include <linux/sched.h>
70374+#include <linux/fs.h>
70375+#include <linux/delay.h>
70376+#include <linux/grsecurity.h>
70377+#include <linux/grinternal.h>
70378+#include <linux/hardirq.h>
70379+
70380+char *signames[] = {
70381+ [SIGSEGV] = "Segmentation fault",
70382+ [SIGILL] = "Illegal instruction",
70383+ [SIGABRT] = "Abort",
70384+ [SIGBUS] = "Invalid alignment/Bus error"
70385+};
70386+
70387+void
70388+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
70389+{
70390+#ifdef CONFIG_GRKERNSEC_SIGNAL
70391+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
70392+ (sig == SIGABRT) || (sig == SIGBUS))) {
70393+ if (task_pid_nr(t) == task_pid_nr(current)) {
70394+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
70395+ } else {
70396+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
70397+ }
70398+ }
70399+#endif
70400+ return;
70401+}
70402+
70403+int
70404+gr_handle_signal(const struct task_struct *p, const int sig)
70405+{
70406+#ifdef CONFIG_GRKERNSEC
70407+ /* ignore the 0 signal for protected task checks */
70408+ if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
70409+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
70410+ return -EPERM;
70411+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
70412+ return -EPERM;
70413+ }
70414+#endif
70415+ return 0;
70416+}
70417+
70418+#ifdef CONFIG_GRKERNSEC
70419+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
70420+
70421+int gr_fake_force_sig(int sig, struct task_struct *t)
70422+{
70423+ unsigned long int flags;
70424+ int ret, blocked, ignored;
70425+ struct k_sigaction *action;
70426+
70427+ spin_lock_irqsave(&t->sighand->siglock, flags);
70428+ action = &t->sighand->action[sig-1];
70429+ ignored = action->sa.sa_handler == SIG_IGN;
70430+ blocked = sigismember(&t->blocked, sig);
70431+ if (blocked || ignored) {
70432+ action->sa.sa_handler = SIG_DFL;
70433+ if (blocked) {
70434+ sigdelset(&t->blocked, sig);
70435+ recalc_sigpending_and_wake(t);
70436+ }
70437+ }
70438+ if (action->sa.sa_handler == SIG_DFL)
70439+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
70440+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
70441+
70442+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
70443+
70444+ return ret;
70445+}
70446+#endif
70447+
70448+#ifdef CONFIG_GRKERNSEC_BRUTE
70449+#define GR_USER_BAN_TIME (15 * 60)
70450+#define GR_DAEMON_BRUTE_TIME (30 * 60)
70451+
70452+static int __get_dumpable(unsigned long mm_flags)
70453+{
70454+ int ret;
70455+
70456+ ret = mm_flags & MMF_DUMPABLE_MASK;
70457+ return (ret >= 2) ? 2 : ret;
70458+}
70459+#endif
70460+
70461+void gr_handle_brute_attach(unsigned long mm_flags)
70462+{
70463+#ifdef CONFIG_GRKERNSEC_BRUTE
70464+ struct task_struct *p = current;
70465+ kuid_t uid = GLOBAL_ROOT_UID;
70466+ int daemon = 0;
70467+
70468+ if (!grsec_enable_brute)
70469+ return;
70470+
70471+ rcu_read_lock();
70472+ read_lock(&tasklist_lock);
70473+ read_lock(&grsec_exec_file_lock);
70474+ if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
70475+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
70476+ p->real_parent->brute = 1;
70477+ daemon = 1;
70478+ } else {
70479+ const struct cred *cred = __task_cred(p), *cred2;
70480+ struct task_struct *tsk, *tsk2;
70481+
70482+ if (!__get_dumpable(mm_flags) && gr_is_global_nonroot(cred->uid)) {
70483+ struct user_struct *user;
70484+
70485+ uid = cred->uid;
70486+
70487+ /* this is put upon execution past expiration */
70488+ user = find_user(uid);
70489+ if (user == NULL)
70490+ goto unlock;
70491+ user->suid_banned = 1;
70492+ user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
70493+ if (user->suid_ban_expires == ~0UL)
70494+ user->suid_ban_expires--;
70495+
70496+ /* only kill other threads of the same binary, from the same user */
70497+ do_each_thread(tsk2, tsk) {
70498+ cred2 = __task_cred(tsk);
70499+ if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
70500+ gr_fake_force_sig(SIGKILL, tsk);
70501+ } while_each_thread(tsk2, tsk);
70502+ }
70503+ }
70504+unlock:
70505+ read_unlock(&grsec_exec_file_lock);
70506+ read_unlock(&tasklist_lock);
70507+ rcu_read_unlock();
70508+
70509+ if (gr_is_global_nonroot(uid))
70510+ 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);
70511+ else if (daemon)
70512+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
70513+
70514+#endif
70515+ return;
70516+}
70517+
70518+void gr_handle_brute_check(void)
70519+{
70520+#ifdef CONFIG_GRKERNSEC_BRUTE
70521+ struct task_struct *p = current;
70522+
70523+ if (unlikely(p->brute)) {
70524+ if (!grsec_enable_brute)
70525+ p->brute = 0;
70526+ else if (time_before(get_seconds(), p->brute_expires))
70527+ msleep(30 * 1000);
70528+ }
70529+#endif
70530+ return;
70531+}
70532+
70533+void gr_handle_kernel_exploit(void)
70534+{
70535+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
70536+ const struct cred *cred;
70537+ struct task_struct *tsk, *tsk2;
70538+ struct user_struct *user;
70539+ kuid_t uid;
70540+
70541+ if (in_irq() || in_serving_softirq() || in_nmi())
70542+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
70543+
70544+ uid = current_uid();
70545+
70546+ if (gr_is_global_root(uid))
70547+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
70548+ else {
70549+ /* kill all the processes of this user, hold a reference
70550+ to their creds struct, and prevent them from creating
70551+ another process until system reset
70552+ */
70553+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
70554+ GR_GLOBAL_UID(uid));
70555+ /* we intentionally leak this ref */
70556+ user = get_uid(current->cred->user);
70557+ if (user)
70558+ user->kernel_banned = 1;
70559+
70560+ /* kill all processes of this user */
70561+ read_lock(&tasklist_lock);
70562+ do_each_thread(tsk2, tsk) {
70563+ cred = __task_cred(tsk);
70564+ if (uid_eq(cred->uid, uid))
70565+ gr_fake_force_sig(SIGKILL, tsk);
70566+ } while_each_thread(tsk2, tsk);
70567+ read_unlock(&tasklist_lock);
70568+ }
70569+#endif
70570+}
70571+
70572+#ifdef CONFIG_GRKERNSEC_BRUTE
70573+static bool suid_ban_expired(struct user_struct *user)
70574+{
70575+ if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
70576+ user->suid_banned = 0;
70577+ user->suid_ban_expires = 0;
70578+ free_uid(user);
70579+ return true;
70580+ }
70581+
70582+ return false;
70583+}
70584+#endif
70585+
70586+int gr_process_kernel_exec_ban(void)
70587+{
70588+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
70589+ if (unlikely(current->cred->user->kernel_banned))
70590+ return -EPERM;
70591+#endif
70592+ return 0;
70593+}
70594+
70595+int gr_process_kernel_setuid_ban(struct user_struct *user)
70596+{
70597+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
70598+ if (unlikely(user->kernel_banned))
70599+ gr_fake_force_sig(SIGKILL, current);
70600+#endif
70601+ return 0;
70602+}
70603+
70604+int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
70605+{
70606+#ifdef CONFIG_GRKERNSEC_BRUTE
70607+ struct user_struct *user = current->cred->user;
70608+ if (unlikely(user->suid_banned)) {
70609+ if (suid_ban_expired(user))
70610+ return 0;
70611+ /* disallow execution of suid binaries only */
70612+ else if (!uid_eq(bprm->cred->euid, current->cred->uid))
70613+ return -EPERM;
70614+ }
70615+#endif
70616+ return 0;
70617+}
70618diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
70619new file mode 100644
70620index 0000000..4030d57
70621--- /dev/null
70622+++ b/grsecurity/grsec_sock.c
70623@@ -0,0 +1,244 @@
70624+#include <linux/kernel.h>
70625+#include <linux/module.h>
70626+#include <linux/sched.h>
70627+#include <linux/file.h>
70628+#include <linux/net.h>
70629+#include <linux/in.h>
70630+#include <linux/ip.h>
70631+#include <net/sock.h>
70632+#include <net/inet_sock.h>
70633+#include <linux/grsecurity.h>
70634+#include <linux/grinternal.h>
70635+#include <linux/gracl.h>
70636+
70637+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
70638+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
70639+
70640+EXPORT_SYMBOL(gr_search_udp_recvmsg);
70641+EXPORT_SYMBOL(gr_search_udp_sendmsg);
70642+
70643+#ifdef CONFIG_UNIX_MODULE
70644+EXPORT_SYMBOL(gr_acl_handle_unix);
70645+EXPORT_SYMBOL(gr_acl_handle_mknod);
70646+EXPORT_SYMBOL(gr_handle_chroot_unix);
70647+EXPORT_SYMBOL(gr_handle_create);
70648+#endif
70649+
70650+#ifdef CONFIG_GRKERNSEC
70651+#define gr_conn_table_size 32749
70652+struct conn_table_entry {
70653+ struct conn_table_entry *next;
70654+ struct signal_struct *sig;
70655+};
70656+
70657+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
70658+DEFINE_SPINLOCK(gr_conn_table_lock);
70659+
70660+extern const char * gr_socktype_to_name(unsigned char type);
70661+extern const char * gr_proto_to_name(unsigned char proto);
70662+extern const char * gr_sockfamily_to_name(unsigned char family);
70663+
70664+static __inline__ int
70665+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
70666+{
70667+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
70668+}
70669+
70670+static __inline__ int
70671+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
70672+ __u16 sport, __u16 dport)
70673+{
70674+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
70675+ sig->gr_sport == sport && sig->gr_dport == dport))
70676+ return 1;
70677+ else
70678+ return 0;
70679+}
70680+
70681+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
70682+{
70683+ struct conn_table_entry **match;
70684+ unsigned int index;
70685+
70686+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
70687+ sig->gr_sport, sig->gr_dport,
70688+ gr_conn_table_size);
70689+
70690+ newent->sig = sig;
70691+
70692+ match = &gr_conn_table[index];
70693+ newent->next = *match;
70694+ *match = newent;
70695+
70696+ return;
70697+}
70698+
70699+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
70700+{
70701+ struct conn_table_entry *match, *last = NULL;
70702+ unsigned int index;
70703+
70704+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
70705+ sig->gr_sport, sig->gr_dport,
70706+ gr_conn_table_size);
70707+
70708+ match = gr_conn_table[index];
70709+ while (match && !conn_match(match->sig,
70710+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
70711+ sig->gr_dport)) {
70712+ last = match;
70713+ match = match->next;
70714+ }
70715+
70716+ if (match) {
70717+ if (last)
70718+ last->next = match->next;
70719+ else
70720+ gr_conn_table[index] = NULL;
70721+ kfree(match);
70722+ }
70723+
70724+ return;
70725+}
70726+
70727+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
70728+ __u16 sport, __u16 dport)
70729+{
70730+ struct conn_table_entry *match;
70731+ unsigned int index;
70732+
70733+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
70734+
70735+ match = gr_conn_table[index];
70736+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
70737+ match = match->next;
70738+
70739+ if (match)
70740+ return match->sig;
70741+ else
70742+ return NULL;
70743+}
70744+
70745+#endif
70746+
70747+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
70748+{
70749+#ifdef CONFIG_GRKERNSEC
70750+ struct signal_struct *sig = task->signal;
70751+ struct conn_table_entry *newent;
70752+
70753+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
70754+ if (newent == NULL)
70755+ return;
70756+ /* no bh lock needed since we are called with bh disabled */
70757+ spin_lock(&gr_conn_table_lock);
70758+ gr_del_task_from_ip_table_nolock(sig);
70759+ sig->gr_saddr = inet->inet_rcv_saddr;
70760+ sig->gr_daddr = inet->inet_daddr;
70761+ sig->gr_sport = inet->inet_sport;
70762+ sig->gr_dport = inet->inet_dport;
70763+ gr_add_to_task_ip_table_nolock(sig, newent);
70764+ spin_unlock(&gr_conn_table_lock);
70765+#endif
70766+ return;
70767+}
70768+
70769+void gr_del_task_from_ip_table(struct task_struct *task)
70770+{
70771+#ifdef CONFIG_GRKERNSEC
70772+ spin_lock_bh(&gr_conn_table_lock);
70773+ gr_del_task_from_ip_table_nolock(task->signal);
70774+ spin_unlock_bh(&gr_conn_table_lock);
70775+#endif
70776+ return;
70777+}
70778+
70779+void
70780+gr_attach_curr_ip(const struct sock *sk)
70781+{
70782+#ifdef CONFIG_GRKERNSEC
70783+ struct signal_struct *p, *set;
70784+ const struct inet_sock *inet = inet_sk(sk);
70785+
70786+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
70787+ return;
70788+
70789+ set = current->signal;
70790+
70791+ spin_lock_bh(&gr_conn_table_lock);
70792+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
70793+ inet->inet_dport, inet->inet_sport);
70794+ if (unlikely(p != NULL)) {
70795+ set->curr_ip = p->curr_ip;
70796+ set->used_accept = 1;
70797+ gr_del_task_from_ip_table_nolock(p);
70798+ spin_unlock_bh(&gr_conn_table_lock);
70799+ return;
70800+ }
70801+ spin_unlock_bh(&gr_conn_table_lock);
70802+
70803+ set->curr_ip = inet->inet_daddr;
70804+ set->used_accept = 1;
70805+#endif
70806+ return;
70807+}
70808+
70809+int
70810+gr_handle_sock_all(const int family, const int type, const int protocol)
70811+{
70812+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
70813+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
70814+ (family != AF_UNIX)) {
70815+ if (family == AF_INET)
70816+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
70817+ else
70818+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
70819+ return -EACCES;
70820+ }
70821+#endif
70822+ return 0;
70823+}
70824+
70825+int
70826+gr_handle_sock_server(const struct sockaddr *sck)
70827+{
70828+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
70829+ if (grsec_enable_socket_server &&
70830+ in_group_p(grsec_socket_server_gid) &&
70831+ sck && (sck->sa_family != AF_UNIX) &&
70832+ (sck->sa_family != AF_LOCAL)) {
70833+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
70834+ return -EACCES;
70835+ }
70836+#endif
70837+ return 0;
70838+}
70839+
70840+int
70841+gr_handle_sock_server_other(const struct sock *sck)
70842+{
70843+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
70844+ if (grsec_enable_socket_server &&
70845+ in_group_p(grsec_socket_server_gid) &&
70846+ sck && (sck->sk_family != AF_UNIX) &&
70847+ (sck->sk_family != AF_LOCAL)) {
70848+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
70849+ return -EACCES;
70850+ }
70851+#endif
70852+ return 0;
70853+}
70854+
70855+int
70856+gr_handle_sock_client(const struct sockaddr *sck)
70857+{
70858+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
70859+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
70860+ sck && (sck->sa_family != AF_UNIX) &&
70861+ (sck->sa_family != AF_LOCAL)) {
70862+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
70863+ return -EACCES;
70864+ }
70865+#endif
70866+ return 0;
70867+}
70868diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
70869new file mode 100644
70870index 0000000..a147ae7
70871--- /dev/null
70872+++ b/grsecurity/grsec_sysctl.c
70873@@ -0,0 +1,470 @@
70874+#include <linux/kernel.h>
70875+#include <linux/sched.h>
70876+#include <linux/sysctl.h>
70877+#include <linux/grsecurity.h>
70878+#include <linux/grinternal.h>
70879+
70880+int
70881+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
70882+{
70883+#ifdef CONFIG_GRKERNSEC_SYSCTL
70884+ if (dirname == NULL || name == NULL)
70885+ return 0;
70886+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
70887+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
70888+ return -EACCES;
70889+ }
70890+#endif
70891+ return 0;
70892+}
70893+
70894+#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
70895+static int __maybe_unused __read_only one = 1;
70896+#endif
70897+
70898+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
70899+ defined(CONFIG_GRKERNSEC_DENYUSB)
70900+struct ctl_table grsecurity_table[] = {
70901+#ifdef CONFIG_GRKERNSEC_SYSCTL
70902+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
70903+#ifdef CONFIG_GRKERNSEC_IO
70904+ {
70905+ .procname = "disable_priv_io",
70906+ .data = &grsec_disable_privio,
70907+ .maxlen = sizeof(int),
70908+ .mode = 0600,
70909+ .proc_handler = &proc_dointvec,
70910+ },
70911+#endif
70912+#endif
70913+#ifdef CONFIG_GRKERNSEC_LINK
70914+ {
70915+ .procname = "linking_restrictions",
70916+ .data = &grsec_enable_link,
70917+ .maxlen = sizeof(int),
70918+ .mode = 0600,
70919+ .proc_handler = &proc_dointvec,
70920+ },
70921+#endif
70922+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
70923+ {
70924+ .procname = "enforce_symlinksifowner",
70925+ .data = &grsec_enable_symlinkown,
70926+ .maxlen = sizeof(int),
70927+ .mode = 0600,
70928+ .proc_handler = &proc_dointvec,
70929+ },
70930+ {
70931+ .procname = "symlinkown_gid",
70932+ .data = &grsec_symlinkown_gid,
70933+ .maxlen = sizeof(int),
70934+ .mode = 0600,
70935+ .proc_handler = &proc_dointvec,
70936+ },
70937+#endif
70938+#ifdef CONFIG_GRKERNSEC_BRUTE
70939+ {
70940+ .procname = "deter_bruteforce",
70941+ .data = &grsec_enable_brute,
70942+ .maxlen = sizeof(int),
70943+ .mode = 0600,
70944+ .proc_handler = &proc_dointvec,
70945+ },
70946+#endif
70947+#ifdef CONFIG_GRKERNSEC_FIFO
70948+ {
70949+ .procname = "fifo_restrictions",
70950+ .data = &grsec_enable_fifo,
70951+ .maxlen = sizeof(int),
70952+ .mode = 0600,
70953+ .proc_handler = &proc_dointvec,
70954+ },
70955+#endif
70956+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
70957+ {
70958+ .procname = "ptrace_readexec",
70959+ .data = &grsec_enable_ptrace_readexec,
70960+ .maxlen = sizeof(int),
70961+ .mode = 0600,
70962+ .proc_handler = &proc_dointvec,
70963+ },
70964+#endif
70965+#ifdef CONFIG_GRKERNSEC_SETXID
70966+ {
70967+ .procname = "consistent_setxid",
70968+ .data = &grsec_enable_setxid,
70969+ .maxlen = sizeof(int),
70970+ .mode = 0600,
70971+ .proc_handler = &proc_dointvec,
70972+ },
70973+#endif
70974+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
70975+ {
70976+ .procname = "ip_blackhole",
70977+ .data = &grsec_enable_blackhole,
70978+ .maxlen = sizeof(int),
70979+ .mode = 0600,
70980+ .proc_handler = &proc_dointvec,
70981+ },
70982+ {
70983+ .procname = "lastack_retries",
70984+ .data = &grsec_lastack_retries,
70985+ .maxlen = sizeof(int),
70986+ .mode = 0600,
70987+ .proc_handler = &proc_dointvec,
70988+ },
70989+#endif
70990+#ifdef CONFIG_GRKERNSEC_EXECLOG
70991+ {
70992+ .procname = "exec_logging",
70993+ .data = &grsec_enable_execlog,
70994+ .maxlen = sizeof(int),
70995+ .mode = 0600,
70996+ .proc_handler = &proc_dointvec,
70997+ },
70998+#endif
70999+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
71000+ {
71001+ .procname = "rwxmap_logging",
71002+ .data = &grsec_enable_log_rwxmaps,
71003+ .maxlen = sizeof(int),
71004+ .mode = 0600,
71005+ .proc_handler = &proc_dointvec,
71006+ },
71007+#endif
71008+#ifdef CONFIG_GRKERNSEC_SIGNAL
71009+ {
71010+ .procname = "signal_logging",
71011+ .data = &grsec_enable_signal,
71012+ .maxlen = sizeof(int),
71013+ .mode = 0600,
71014+ .proc_handler = &proc_dointvec,
71015+ },
71016+#endif
71017+#ifdef CONFIG_GRKERNSEC_FORKFAIL
71018+ {
71019+ .procname = "forkfail_logging",
71020+ .data = &grsec_enable_forkfail,
71021+ .maxlen = sizeof(int),
71022+ .mode = 0600,
71023+ .proc_handler = &proc_dointvec,
71024+ },
71025+#endif
71026+#ifdef CONFIG_GRKERNSEC_TIME
71027+ {
71028+ .procname = "timechange_logging",
71029+ .data = &grsec_enable_time,
71030+ .maxlen = sizeof(int),
71031+ .mode = 0600,
71032+ .proc_handler = &proc_dointvec,
71033+ },
71034+#endif
71035+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
71036+ {
71037+ .procname = "chroot_deny_shmat",
71038+ .data = &grsec_enable_chroot_shmat,
71039+ .maxlen = sizeof(int),
71040+ .mode = 0600,
71041+ .proc_handler = &proc_dointvec,
71042+ },
71043+#endif
71044+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
71045+ {
71046+ .procname = "chroot_deny_unix",
71047+ .data = &grsec_enable_chroot_unix,
71048+ .maxlen = sizeof(int),
71049+ .mode = 0600,
71050+ .proc_handler = &proc_dointvec,
71051+ },
71052+#endif
71053+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
71054+ {
71055+ .procname = "chroot_deny_mount",
71056+ .data = &grsec_enable_chroot_mount,
71057+ .maxlen = sizeof(int),
71058+ .mode = 0600,
71059+ .proc_handler = &proc_dointvec,
71060+ },
71061+#endif
71062+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
71063+ {
71064+ .procname = "chroot_deny_fchdir",
71065+ .data = &grsec_enable_chroot_fchdir,
71066+ .maxlen = sizeof(int),
71067+ .mode = 0600,
71068+ .proc_handler = &proc_dointvec,
71069+ },
71070+#endif
71071+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
71072+ {
71073+ .procname = "chroot_deny_chroot",
71074+ .data = &grsec_enable_chroot_double,
71075+ .maxlen = sizeof(int),
71076+ .mode = 0600,
71077+ .proc_handler = &proc_dointvec,
71078+ },
71079+#endif
71080+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
71081+ {
71082+ .procname = "chroot_deny_pivot",
71083+ .data = &grsec_enable_chroot_pivot,
71084+ .maxlen = sizeof(int),
71085+ .mode = 0600,
71086+ .proc_handler = &proc_dointvec,
71087+ },
71088+#endif
71089+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
71090+ {
71091+ .procname = "chroot_enforce_chdir",
71092+ .data = &grsec_enable_chroot_chdir,
71093+ .maxlen = sizeof(int),
71094+ .mode = 0600,
71095+ .proc_handler = &proc_dointvec,
71096+ },
71097+#endif
71098+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
71099+ {
71100+ .procname = "chroot_deny_chmod",
71101+ .data = &grsec_enable_chroot_chmod,
71102+ .maxlen = sizeof(int),
71103+ .mode = 0600,
71104+ .proc_handler = &proc_dointvec,
71105+ },
71106+#endif
71107+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
71108+ {
71109+ .procname = "chroot_deny_mknod",
71110+ .data = &grsec_enable_chroot_mknod,
71111+ .maxlen = sizeof(int),
71112+ .mode = 0600,
71113+ .proc_handler = &proc_dointvec,
71114+ },
71115+#endif
71116+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
71117+ {
71118+ .procname = "chroot_restrict_nice",
71119+ .data = &grsec_enable_chroot_nice,
71120+ .maxlen = sizeof(int),
71121+ .mode = 0600,
71122+ .proc_handler = &proc_dointvec,
71123+ },
71124+#endif
71125+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
71126+ {
71127+ .procname = "chroot_execlog",
71128+ .data = &grsec_enable_chroot_execlog,
71129+ .maxlen = sizeof(int),
71130+ .mode = 0600,
71131+ .proc_handler = &proc_dointvec,
71132+ },
71133+#endif
71134+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
71135+ {
71136+ .procname = "chroot_caps",
71137+ .data = &grsec_enable_chroot_caps,
71138+ .maxlen = sizeof(int),
71139+ .mode = 0600,
71140+ .proc_handler = &proc_dointvec,
71141+ },
71142+#endif
71143+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
71144+ {
71145+ .procname = "chroot_deny_sysctl",
71146+ .data = &grsec_enable_chroot_sysctl,
71147+ .maxlen = sizeof(int),
71148+ .mode = 0600,
71149+ .proc_handler = &proc_dointvec,
71150+ },
71151+#endif
71152+#ifdef CONFIG_GRKERNSEC_TPE
71153+ {
71154+ .procname = "tpe",
71155+ .data = &grsec_enable_tpe,
71156+ .maxlen = sizeof(int),
71157+ .mode = 0600,
71158+ .proc_handler = &proc_dointvec,
71159+ },
71160+ {
71161+ .procname = "tpe_gid",
71162+ .data = &grsec_tpe_gid,
71163+ .maxlen = sizeof(int),
71164+ .mode = 0600,
71165+ .proc_handler = &proc_dointvec,
71166+ },
71167+#endif
71168+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
71169+ {
71170+ .procname = "tpe_invert",
71171+ .data = &grsec_enable_tpe_invert,
71172+ .maxlen = sizeof(int),
71173+ .mode = 0600,
71174+ .proc_handler = &proc_dointvec,
71175+ },
71176+#endif
71177+#ifdef CONFIG_GRKERNSEC_TPE_ALL
71178+ {
71179+ .procname = "tpe_restrict_all",
71180+ .data = &grsec_enable_tpe_all,
71181+ .maxlen = sizeof(int),
71182+ .mode = 0600,
71183+ .proc_handler = &proc_dointvec,
71184+ },
71185+#endif
71186+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
71187+ {
71188+ .procname = "socket_all",
71189+ .data = &grsec_enable_socket_all,
71190+ .maxlen = sizeof(int),
71191+ .mode = 0600,
71192+ .proc_handler = &proc_dointvec,
71193+ },
71194+ {
71195+ .procname = "socket_all_gid",
71196+ .data = &grsec_socket_all_gid,
71197+ .maxlen = sizeof(int),
71198+ .mode = 0600,
71199+ .proc_handler = &proc_dointvec,
71200+ },
71201+#endif
71202+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
71203+ {
71204+ .procname = "socket_client",
71205+ .data = &grsec_enable_socket_client,
71206+ .maxlen = sizeof(int),
71207+ .mode = 0600,
71208+ .proc_handler = &proc_dointvec,
71209+ },
71210+ {
71211+ .procname = "socket_client_gid",
71212+ .data = &grsec_socket_client_gid,
71213+ .maxlen = sizeof(int),
71214+ .mode = 0600,
71215+ .proc_handler = &proc_dointvec,
71216+ },
71217+#endif
71218+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
71219+ {
71220+ .procname = "socket_server",
71221+ .data = &grsec_enable_socket_server,
71222+ .maxlen = sizeof(int),
71223+ .mode = 0600,
71224+ .proc_handler = &proc_dointvec,
71225+ },
71226+ {
71227+ .procname = "socket_server_gid",
71228+ .data = &grsec_socket_server_gid,
71229+ .maxlen = sizeof(int),
71230+ .mode = 0600,
71231+ .proc_handler = &proc_dointvec,
71232+ },
71233+#endif
71234+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
71235+ {
71236+ .procname = "audit_group",
71237+ .data = &grsec_enable_group,
71238+ .maxlen = sizeof(int),
71239+ .mode = 0600,
71240+ .proc_handler = &proc_dointvec,
71241+ },
71242+ {
71243+ .procname = "audit_gid",
71244+ .data = &grsec_audit_gid,
71245+ .maxlen = sizeof(int),
71246+ .mode = 0600,
71247+ .proc_handler = &proc_dointvec,
71248+ },
71249+#endif
71250+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
71251+ {
71252+ .procname = "audit_chdir",
71253+ .data = &grsec_enable_chdir,
71254+ .maxlen = sizeof(int),
71255+ .mode = 0600,
71256+ .proc_handler = &proc_dointvec,
71257+ },
71258+#endif
71259+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
71260+ {
71261+ .procname = "audit_mount",
71262+ .data = &grsec_enable_mount,
71263+ .maxlen = sizeof(int),
71264+ .mode = 0600,
71265+ .proc_handler = &proc_dointvec,
71266+ },
71267+#endif
71268+#ifdef CONFIG_GRKERNSEC_DMESG
71269+ {
71270+ .procname = "dmesg",
71271+ .data = &grsec_enable_dmesg,
71272+ .maxlen = sizeof(int),
71273+ .mode = 0600,
71274+ .proc_handler = &proc_dointvec,
71275+ },
71276+#endif
71277+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
71278+ {
71279+ .procname = "chroot_findtask",
71280+ .data = &grsec_enable_chroot_findtask,
71281+ .maxlen = sizeof(int),
71282+ .mode = 0600,
71283+ .proc_handler = &proc_dointvec,
71284+ },
71285+#endif
71286+#ifdef CONFIG_GRKERNSEC_RESLOG
71287+ {
71288+ .procname = "resource_logging",
71289+ .data = &grsec_resource_logging,
71290+ .maxlen = sizeof(int),
71291+ .mode = 0600,
71292+ .proc_handler = &proc_dointvec,
71293+ },
71294+#endif
71295+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
71296+ {
71297+ .procname = "audit_ptrace",
71298+ .data = &grsec_enable_audit_ptrace,
71299+ .maxlen = sizeof(int),
71300+ .mode = 0600,
71301+ .proc_handler = &proc_dointvec,
71302+ },
71303+#endif
71304+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
71305+ {
71306+ .procname = "harden_ptrace",
71307+ .data = &grsec_enable_harden_ptrace,
71308+ .maxlen = sizeof(int),
71309+ .mode = 0600,
71310+ .proc_handler = &proc_dointvec,
71311+ },
71312+#endif
71313+ {
71314+ .procname = "grsec_lock",
71315+ .data = &grsec_lock,
71316+ .maxlen = sizeof(int),
71317+ .mode = 0600,
71318+ .proc_handler = &proc_dointvec,
71319+ },
71320+#endif
71321+#ifdef CONFIG_GRKERNSEC_ROFS
71322+ {
71323+ .procname = "romount_protect",
71324+ .data = &grsec_enable_rofs,
71325+ .maxlen = sizeof(int),
71326+ .mode = 0600,
71327+ .proc_handler = &proc_dointvec_minmax,
71328+ .extra1 = &one,
71329+ .extra2 = &one,
71330+ },
71331+#endif
71332+#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
71333+ {
71334+ .procname = "deny_new_usb",
71335+ .data = &grsec_deny_new_usb,
71336+ .maxlen = sizeof(int),
71337+ .mode = 0600,
71338+ .proc_handler = &proc_dointvec,
71339+ },
71340+#endif
71341+ { }
71342+};
71343+#endif
71344diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
71345new file mode 100644
71346index 0000000..0dc13c3
71347--- /dev/null
71348+++ b/grsecurity/grsec_time.c
71349@@ -0,0 +1,16 @@
71350+#include <linux/kernel.h>
71351+#include <linux/sched.h>
71352+#include <linux/grinternal.h>
71353+#include <linux/module.h>
71354+
71355+void
71356+gr_log_timechange(void)
71357+{
71358+#ifdef CONFIG_GRKERNSEC_TIME
71359+ if (grsec_enable_time)
71360+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
71361+#endif
71362+ return;
71363+}
71364+
71365+EXPORT_SYMBOL(gr_log_timechange);
71366diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
71367new file mode 100644
71368index 0000000..ee57dcf
71369--- /dev/null
71370+++ b/grsecurity/grsec_tpe.c
71371@@ -0,0 +1,73 @@
71372+#include <linux/kernel.h>
71373+#include <linux/sched.h>
71374+#include <linux/file.h>
71375+#include <linux/fs.h>
71376+#include <linux/grinternal.h>
71377+
71378+extern int gr_acl_tpe_check(void);
71379+
71380+int
71381+gr_tpe_allow(const struct file *file)
71382+{
71383+#ifdef CONFIG_GRKERNSEC
71384+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
71385+ const struct cred *cred = current_cred();
71386+ char *msg = NULL;
71387+ char *msg2 = NULL;
71388+
71389+ // never restrict root
71390+ if (gr_is_global_root(cred->uid))
71391+ return 1;
71392+
71393+ if (grsec_enable_tpe) {
71394+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
71395+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
71396+ msg = "not being in trusted group";
71397+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
71398+ msg = "being in untrusted group";
71399+#else
71400+ if (in_group_p(grsec_tpe_gid))
71401+ msg = "being in untrusted group";
71402+#endif
71403+ }
71404+ if (!msg && gr_acl_tpe_check())
71405+ msg = "being in untrusted role";
71406+
71407+ // not in any affected group/role
71408+ if (!msg)
71409+ goto next_check;
71410+
71411+ if (gr_is_global_nonroot(inode->i_uid))
71412+ msg2 = "file in non-root-owned directory";
71413+ else if (inode->i_mode & S_IWOTH)
71414+ msg2 = "file in world-writable directory";
71415+ else if (inode->i_mode & S_IWGRP)
71416+ msg2 = "file in group-writable directory";
71417+
71418+ if (msg && msg2) {
71419+ char fullmsg[70] = {0};
71420+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
71421+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
71422+ return 0;
71423+ }
71424+ msg = NULL;
71425+next_check:
71426+#ifdef CONFIG_GRKERNSEC_TPE_ALL
71427+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
71428+ return 1;
71429+
71430+ if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
71431+ msg = "directory not owned by user";
71432+ else if (inode->i_mode & S_IWOTH)
71433+ msg = "file in world-writable directory";
71434+ else if (inode->i_mode & S_IWGRP)
71435+ msg = "file in group-writable directory";
71436+
71437+ if (msg) {
71438+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
71439+ return 0;
71440+ }
71441+#endif
71442+#endif
71443+ return 1;
71444+}
71445diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
71446new file mode 100644
71447index 0000000..ae02d8e
71448--- /dev/null
71449+++ b/grsecurity/grsec_usb.c
71450@@ -0,0 +1,15 @@
71451+#include <linux/kernel.h>
71452+#include <linux/grinternal.h>
71453+#include <linux/module.h>
71454+
71455+int gr_handle_new_usb(void)
71456+{
71457+#ifdef CONFIG_GRKERNSEC_DENYUSB
71458+ if (grsec_deny_new_usb) {
71459+ printk(KERN_ALERT "grsec: denied insert of new USB device\n");
71460+ return 1;
71461+ }
71462+#endif
71463+ return 0;
71464+}
71465+EXPORT_SYMBOL_GPL(gr_handle_new_usb);
71466diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
71467new file mode 100644
71468index 0000000..9f7b1ac
71469--- /dev/null
71470+++ b/grsecurity/grsum.c
71471@@ -0,0 +1,61 @@
71472+#include <linux/err.h>
71473+#include <linux/kernel.h>
71474+#include <linux/sched.h>
71475+#include <linux/mm.h>
71476+#include <linux/scatterlist.h>
71477+#include <linux/crypto.h>
71478+#include <linux/gracl.h>
71479+
71480+
71481+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
71482+#error "crypto and sha256 must be built into the kernel"
71483+#endif
71484+
71485+int
71486+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
71487+{
71488+ char *p;
71489+ struct crypto_hash *tfm;
71490+ struct hash_desc desc;
71491+ struct scatterlist sg;
71492+ unsigned char temp_sum[GR_SHA_LEN];
71493+ volatile int retval = 0;
71494+ volatile int dummy = 0;
71495+ unsigned int i;
71496+
71497+ sg_init_table(&sg, 1);
71498+
71499+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
71500+ if (IS_ERR(tfm)) {
71501+ /* should never happen, since sha256 should be built in */
71502+ return 1;
71503+ }
71504+
71505+ desc.tfm = tfm;
71506+ desc.flags = 0;
71507+
71508+ crypto_hash_init(&desc);
71509+
71510+ p = salt;
71511+ sg_set_buf(&sg, p, GR_SALT_LEN);
71512+ crypto_hash_update(&desc, &sg, sg.length);
71513+
71514+ p = entry->pw;
71515+ sg_set_buf(&sg, p, strlen(p));
71516+
71517+ crypto_hash_update(&desc, &sg, sg.length);
71518+
71519+ crypto_hash_final(&desc, temp_sum);
71520+
71521+ memset(entry->pw, 0, GR_PW_LEN);
71522+
71523+ for (i = 0; i < GR_SHA_LEN; i++)
71524+ if (sum[i] != temp_sum[i])
71525+ retval = 1;
71526+ else
71527+ dummy = 1; // waste a cycle
71528+
71529+ crypto_free_hash(tfm);
71530+
71531+ return retval;
71532+}
71533diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
71534index 77ff547..181834f 100644
71535--- a/include/asm-generic/4level-fixup.h
71536+++ b/include/asm-generic/4level-fixup.h
71537@@ -13,8 +13,10 @@
71538 #define pmd_alloc(mm, pud, address) \
71539 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
71540 NULL: pmd_offset(pud, address))
71541+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
71542
71543 #define pud_alloc(mm, pgd, address) (pgd)
71544+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
71545 #define pud_offset(pgd, start) (pgd)
71546 #define pud_none(pud) 0
71547 #define pud_bad(pud) 0
71548diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
71549index b7babf0..04ad282 100644
71550--- a/include/asm-generic/atomic-long.h
71551+++ b/include/asm-generic/atomic-long.h
71552@@ -22,6 +22,12 @@
71553
71554 typedef atomic64_t atomic_long_t;
71555
71556+#ifdef CONFIG_PAX_REFCOUNT
71557+typedef atomic64_unchecked_t atomic_long_unchecked_t;
71558+#else
71559+typedef atomic64_t atomic_long_unchecked_t;
71560+#endif
71561+
71562 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
71563
71564 static inline long atomic_long_read(atomic_long_t *l)
71565@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
71566 return (long)atomic64_read(v);
71567 }
71568
71569+#ifdef CONFIG_PAX_REFCOUNT
71570+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
71571+{
71572+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71573+
71574+ return (long)atomic64_read_unchecked(v);
71575+}
71576+#endif
71577+
71578 static inline void atomic_long_set(atomic_long_t *l, long i)
71579 {
71580 atomic64_t *v = (atomic64_t *)l;
71581@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
71582 atomic64_set(v, i);
71583 }
71584
71585+#ifdef CONFIG_PAX_REFCOUNT
71586+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
71587+{
71588+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71589+
71590+ atomic64_set_unchecked(v, i);
71591+}
71592+#endif
71593+
71594 static inline void atomic_long_inc(atomic_long_t *l)
71595 {
71596 atomic64_t *v = (atomic64_t *)l;
71597@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
71598 atomic64_inc(v);
71599 }
71600
71601+#ifdef CONFIG_PAX_REFCOUNT
71602+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
71603+{
71604+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71605+
71606+ atomic64_inc_unchecked(v);
71607+}
71608+#endif
71609+
71610 static inline void atomic_long_dec(atomic_long_t *l)
71611 {
71612 atomic64_t *v = (atomic64_t *)l;
71613@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
71614 atomic64_dec(v);
71615 }
71616
71617+#ifdef CONFIG_PAX_REFCOUNT
71618+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
71619+{
71620+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71621+
71622+ atomic64_dec_unchecked(v);
71623+}
71624+#endif
71625+
71626 static inline void atomic_long_add(long i, atomic_long_t *l)
71627 {
71628 atomic64_t *v = (atomic64_t *)l;
71629@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
71630 atomic64_add(i, v);
71631 }
71632
71633+#ifdef CONFIG_PAX_REFCOUNT
71634+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
71635+{
71636+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71637+
71638+ atomic64_add_unchecked(i, v);
71639+}
71640+#endif
71641+
71642 static inline void atomic_long_sub(long i, atomic_long_t *l)
71643 {
71644 atomic64_t *v = (atomic64_t *)l;
71645@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
71646 atomic64_sub(i, v);
71647 }
71648
71649+#ifdef CONFIG_PAX_REFCOUNT
71650+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
71651+{
71652+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71653+
71654+ atomic64_sub_unchecked(i, v);
71655+}
71656+#endif
71657+
71658 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
71659 {
71660 atomic64_t *v = (atomic64_t *)l;
71661@@ -101,6 +161,15 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
71662 return (long)atomic64_add_return(i, v);
71663 }
71664
71665+#ifdef CONFIG_PAX_REFCOUNT
71666+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
71667+{
71668+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71669+
71670+ return (long)atomic64_add_return_unchecked(i, v);
71671+}
71672+#endif
71673+
71674 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
71675 {
71676 atomic64_t *v = (atomic64_t *)l;
71677@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
71678 return (long)atomic64_inc_return(v);
71679 }
71680
71681+#ifdef CONFIG_PAX_REFCOUNT
71682+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
71683+{
71684+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71685+
71686+ return (long)atomic64_inc_return_unchecked(v);
71687+}
71688+#endif
71689+
71690 static inline long atomic_long_dec_return(atomic_long_t *l)
71691 {
71692 atomic64_t *v = (atomic64_t *)l;
71693@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
71694
71695 typedef atomic_t atomic_long_t;
71696
71697+#ifdef CONFIG_PAX_REFCOUNT
71698+typedef atomic_unchecked_t atomic_long_unchecked_t;
71699+#else
71700+typedef atomic_t atomic_long_unchecked_t;
71701+#endif
71702+
71703 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
71704 static inline long atomic_long_read(atomic_long_t *l)
71705 {
71706@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
71707 return (long)atomic_read(v);
71708 }
71709
71710+#ifdef CONFIG_PAX_REFCOUNT
71711+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
71712+{
71713+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71714+
71715+ return (long)atomic_read_unchecked(v);
71716+}
71717+#endif
71718+
71719 static inline void atomic_long_set(atomic_long_t *l, long i)
71720 {
71721 atomic_t *v = (atomic_t *)l;
71722@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
71723 atomic_set(v, i);
71724 }
71725
71726+#ifdef CONFIG_PAX_REFCOUNT
71727+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
71728+{
71729+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71730+
71731+ atomic_set_unchecked(v, i);
71732+}
71733+#endif
71734+
71735 static inline void atomic_long_inc(atomic_long_t *l)
71736 {
71737 atomic_t *v = (atomic_t *)l;
71738@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
71739 atomic_inc(v);
71740 }
71741
71742+#ifdef CONFIG_PAX_REFCOUNT
71743+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
71744+{
71745+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71746+
71747+ atomic_inc_unchecked(v);
71748+}
71749+#endif
71750+
71751 static inline void atomic_long_dec(atomic_long_t *l)
71752 {
71753 atomic_t *v = (atomic_t *)l;
71754@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
71755 atomic_dec(v);
71756 }
71757
71758+#ifdef CONFIG_PAX_REFCOUNT
71759+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
71760+{
71761+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71762+
71763+ atomic_dec_unchecked(v);
71764+}
71765+#endif
71766+
71767 static inline void atomic_long_add(long i, atomic_long_t *l)
71768 {
71769 atomic_t *v = (atomic_t *)l;
71770@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
71771 atomic_add(i, v);
71772 }
71773
71774+#ifdef CONFIG_PAX_REFCOUNT
71775+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
71776+{
71777+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71778+
71779+ atomic_add_unchecked(i, v);
71780+}
71781+#endif
71782+
71783 static inline void atomic_long_sub(long i, atomic_long_t *l)
71784 {
71785 atomic_t *v = (atomic_t *)l;
71786@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
71787 atomic_sub(i, v);
71788 }
71789
71790+#ifdef CONFIG_PAX_REFCOUNT
71791+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
71792+{
71793+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71794+
71795+ atomic_sub_unchecked(i, v);
71796+}
71797+#endif
71798+
71799 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
71800 {
71801 atomic_t *v = (atomic_t *)l;
71802@@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
71803 return (long)atomic_add_return(i, v);
71804 }
71805
71806+#ifdef CONFIG_PAX_REFCOUNT
71807+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
71808+{
71809+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71810+
71811+ return (long)atomic_add_return_unchecked(i, v);
71812+}
71813+
71814+#endif
71815+
71816 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
71817 {
71818 atomic_t *v = (atomic_t *)l;
71819@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
71820 return (long)atomic_inc_return(v);
71821 }
71822
71823+#ifdef CONFIG_PAX_REFCOUNT
71824+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
71825+{
71826+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71827+
71828+ return (long)atomic_inc_return_unchecked(v);
71829+}
71830+#endif
71831+
71832 static inline long atomic_long_dec_return(atomic_long_t *l)
71833 {
71834 atomic_t *v = (atomic_t *)l;
71835@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
71836
71837 #endif /* BITS_PER_LONG == 64 */
71838
71839+#ifdef CONFIG_PAX_REFCOUNT
71840+static inline void pax_refcount_needs_these_functions(void)
71841+{
71842+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
71843+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
71844+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
71845+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
71846+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
71847+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
71848+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
71849+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
71850+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
71851+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
71852+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
71853+#ifdef CONFIG_X86
71854+ atomic_clear_mask_unchecked(0, NULL);
71855+ atomic_set_mask_unchecked(0, NULL);
71856+#endif
71857+
71858+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
71859+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
71860+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
71861+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
71862+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
71863+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
71864+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
71865+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
71866+}
71867+#else
71868+#define atomic_read_unchecked(v) atomic_read(v)
71869+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
71870+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
71871+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
71872+#define atomic_inc_unchecked(v) atomic_inc(v)
71873+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
71874+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
71875+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
71876+#define atomic_dec_unchecked(v) atomic_dec(v)
71877+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
71878+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
71879+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
71880+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
71881+
71882+#define atomic_long_read_unchecked(v) atomic_long_read(v)
71883+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
71884+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
71885+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
71886+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
71887+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
71888+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
71889+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
71890+#endif
71891+
71892 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
71893diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
71894index 33bd2de..f31bff97 100644
71895--- a/include/asm-generic/atomic.h
71896+++ b/include/asm-generic/atomic.h
71897@@ -153,7 +153,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
71898 * Atomically clears the bits set in @mask from @v
71899 */
71900 #ifndef atomic_clear_mask
71901-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
71902+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
71903 {
71904 unsigned long flags;
71905
71906diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
71907index b18ce4f..2ee2843 100644
71908--- a/include/asm-generic/atomic64.h
71909+++ b/include/asm-generic/atomic64.h
71910@@ -16,6 +16,8 @@ typedef struct {
71911 long long counter;
71912 } atomic64_t;
71913
71914+typedef atomic64_t atomic64_unchecked_t;
71915+
71916 #define ATOMIC64_INIT(i) { (i) }
71917
71918 extern long long atomic64_read(const atomic64_t *v);
71919@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
71920 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
71921 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
71922
71923+#define atomic64_read_unchecked(v) atomic64_read(v)
71924+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
71925+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
71926+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
71927+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
71928+#define atomic64_inc_unchecked(v) atomic64_inc(v)
71929+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
71930+#define atomic64_dec_unchecked(v) atomic64_dec(v)
71931+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
71932+
71933 #endif /* _ASM_GENERIC_ATOMIC64_H */
71934diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
71935index 1bfcfe5..e04c5c9 100644
71936--- a/include/asm-generic/cache.h
71937+++ b/include/asm-generic/cache.h
71938@@ -6,7 +6,7 @@
71939 * cache lines need to provide their own cache.h.
71940 */
71941
71942-#define L1_CACHE_SHIFT 5
71943-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
71944+#define L1_CACHE_SHIFT 5UL
71945+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
71946
71947 #endif /* __ASM_GENERIC_CACHE_H */
71948diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
71949index 0d68a1e..b74a761 100644
71950--- a/include/asm-generic/emergency-restart.h
71951+++ b/include/asm-generic/emergency-restart.h
71952@@ -1,7 +1,7 @@
71953 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
71954 #define _ASM_GENERIC_EMERGENCY_RESTART_H
71955
71956-static inline void machine_emergency_restart(void)
71957+static inline __noreturn void machine_emergency_restart(void)
71958 {
71959 machine_restart(NULL);
71960 }
71961diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
71962index 90f99c7..00ce236 100644
71963--- a/include/asm-generic/kmap_types.h
71964+++ b/include/asm-generic/kmap_types.h
71965@@ -2,9 +2,9 @@
71966 #define _ASM_GENERIC_KMAP_TYPES_H
71967
71968 #ifdef __WITH_KM_FENCE
71969-# define KM_TYPE_NR 41
71970+# define KM_TYPE_NR 42
71971 #else
71972-# define KM_TYPE_NR 20
71973+# define KM_TYPE_NR 21
71974 #endif
71975
71976 #endif
71977diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
71978index 9ceb03b..62b0b8f 100644
71979--- a/include/asm-generic/local.h
71980+++ b/include/asm-generic/local.h
71981@@ -23,24 +23,37 @@ typedef struct
71982 atomic_long_t a;
71983 } local_t;
71984
71985+typedef struct {
71986+ atomic_long_unchecked_t a;
71987+} local_unchecked_t;
71988+
71989 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
71990
71991 #define local_read(l) atomic_long_read(&(l)->a)
71992+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
71993 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
71994+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
71995 #define local_inc(l) atomic_long_inc(&(l)->a)
71996+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
71997 #define local_dec(l) atomic_long_dec(&(l)->a)
71998+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
71999 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
72000+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
72001 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
72002+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
72003
72004 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
72005 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
72006 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
72007 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
72008 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
72009+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
72010 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
72011 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
72012+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
72013
72014 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
72015+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
72016 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
72017 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
72018 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
72019diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
72020index 725612b..9cc513a 100644
72021--- a/include/asm-generic/pgtable-nopmd.h
72022+++ b/include/asm-generic/pgtable-nopmd.h
72023@@ -1,14 +1,19 @@
72024 #ifndef _PGTABLE_NOPMD_H
72025 #define _PGTABLE_NOPMD_H
72026
72027-#ifndef __ASSEMBLY__
72028-
72029 #include <asm-generic/pgtable-nopud.h>
72030
72031-struct mm_struct;
72032-
72033 #define __PAGETABLE_PMD_FOLDED
72034
72035+#define PMD_SHIFT PUD_SHIFT
72036+#define PTRS_PER_PMD 1
72037+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
72038+#define PMD_MASK (~(PMD_SIZE-1))
72039+
72040+#ifndef __ASSEMBLY__
72041+
72042+struct mm_struct;
72043+
72044 /*
72045 * Having the pmd type consist of a pud gets the size right, and allows
72046 * us to conceptually access the pud entry that this pmd is folded into
72047@@ -16,11 +21,6 @@ struct mm_struct;
72048 */
72049 typedef struct { pud_t pud; } pmd_t;
72050
72051-#define PMD_SHIFT PUD_SHIFT
72052-#define PTRS_PER_PMD 1
72053-#define PMD_SIZE (1UL << PMD_SHIFT)
72054-#define PMD_MASK (~(PMD_SIZE-1))
72055-
72056 /*
72057 * The "pud_xxx()" functions here are trivial for a folded two-level
72058 * setup: the pmd is never bad, and a pmd always exists (as it's folded
72059diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
72060index 810431d..0ec4804f 100644
72061--- a/include/asm-generic/pgtable-nopud.h
72062+++ b/include/asm-generic/pgtable-nopud.h
72063@@ -1,10 +1,15 @@
72064 #ifndef _PGTABLE_NOPUD_H
72065 #define _PGTABLE_NOPUD_H
72066
72067-#ifndef __ASSEMBLY__
72068-
72069 #define __PAGETABLE_PUD_FOLDED
72070
72071+#define PUD_SHIFT PGDIR_SHIFT
72072+#define PTRS_PER_PUD 1
72073+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
72074+#define PUD_MASK (~(PUD_SIZE-1))
72075+
72076+#ifndef __ASSEMBLY__
72077+
72078 /*
72079 * Having the pud type consist of a pgd gets the size right, and allows
72080 * us to conceptually access the pgd entry that this pud is folded into
72081@@ -12,11 +17,6 @@
72082 */
72083 typedef struct { pgd_t pgd; } pud_t;
72084
72085-#define PUD_SHIFT PGDIR_SHIFT
72086-#define PTRS_PER_PUD 1
72087-#define PUD_SIZE (1UL << PUD_SHIFT)
72088-#define PUD_MASK (~(PUD_SIZE-1))
72089-
72090 /*
72091 * The "pgd_xxx()" functions here are trivial for a folded two-level
72092 * setup: the pud is never bad, and a pud always exists (as it's folded
72093@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
72094 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
72095
72096 #define pgd_populate(mm, pgd, pud) do { } while (0)
72097+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
72098 /*
72099 * (puds are folded into pgds so this doesn't get actually called,
72100 * but the define is needed for a generic inline function.)
72101diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
72102index 0807ddf..cd67747 100644
72103--- a/include/asm-generic/pgtable.h
72104+++ b/include/asm-generic/pgtable.h
72105@@ -741,6 +741,22 @@ static inline pmd_t pmd_mknuma(pmd_t pmd)
72106 }
72107 #endif /* CONFIG_NUMA_BALANCING */
72108
72109+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
72110+#ifdef CONFIG_PAX_KERNEXEC
72111+#error KERNEXEC requires pax_open_kernel
72112+#else
72113+static inline unsigned long pax_open_kernel(void) { return 0; }
72114+#endif
72115+#endif
72116+
72117+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
72118+#ifdef CONFIG_PAX_KERNEXEC
72119+#error KERNEXEC requires pax_close_kernel
72120+#else
72121+static inline unsigned long pax_close_kernel(void) { return 0; }
72122+#endif
72123+#endif
72124+
72125 #endif /* CONFIG_MMU */
72126
72127 #endif /* !__ASSEMBLY__ */
72128diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
72129index dc1269c..48a4f51 100644
72130--- a/include/asm-generic/uaccess.h
72131+++ b/include/asm-generic/uaccess.h
72132@@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
72133 return __clear_user(to, n);
72134 }
72135
72136+#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
72137+#ifdef CONFIG_PAX_MEMORY_UDEREF
72138+#error UDEREF requires pax_open_userland
72139+#else
72140+static inline unsigned long pax_open_userland(void) { return 0; }
72141+#endif
72142+#endif
72143+
72144+#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
72145+#ifdef CONFIG_PAX_MEMORY_UDEREF
72146+#error UDEREF requires pax_close_userland
72147+#else
72148+static inline unsigned long pax_close_userland(void) { return 0; }
72149+#endif
72150+#endif
72151+
72152 #endif /* __ASM_GENERIC_UACCESS_H */
72153diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
72154index 69732d2..cbe16d9 100644
72155--- a/include/asm-generic/vmlinux.lds.h
72156+++ b/include/asm-generic/vmlinux.lds.h
72157@@ -227,6 +227,7 @@
72158 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
72159 VMLINUX_SYMBOL(__start_rodata) = .; \
72160 *(.rodata) *(.rodata.*) \
72161+ *(.data..read_only) \
72162 *(__vermagic) /* Kernel version magic */ \
72163 . = ALIGN(8); \
72164 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
72165@@ -710,17 +711,18 @@
72166 * section in the linker script will go there too. @phdr should have
72167 * a leading colon.
72168 *
72169- * Note that this macros defines __per_cpu_load as an absolute symbol.
72170+ * Note that this macros defines per_cpu_load as an absolute symbol.
72171 * If there is no need to put the percpu section at a predetermined
72172 * address, use PERCPU_SECTION.
72173 */
72174 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
72175- VMLINUX_SYMBOL(__per_cpu_load) = .; \
72176- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
72177+ per_cpu_load = .; \
72178+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
72179 - LOAD_OFFSET) { \
72180+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
72181 PERCPU_INPUT(cacheline) \
72182 } phdr \
72183- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
72184+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
72185
72186 /**
72187 * PERCPU_SECTION - define output section for percpu area, simple version
72188diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
72189index 418d270..bfd2794 100644
72190--- a/include/crypto/algapi.h
72191+++ b/include/crypto/algapi.h
72192@@ -34,7 +34,7 @@ struct crypto_type {
72193 unsigned int maskclear;
72194 unsigned int maskset;
72195 unsigned int tfmsize;
72196-};
72197+} __do_const;
72198
72199 struct crypto_instance {
72200 struct crypto_alg alg;
72201diff --git a/include/drm/drmP.h b/include/drm/drmP.h
72202index 12083dc..39740ec 100644
72203--- a/include/drm/drmP.h
72204+++ b/include/drm/drmP.h
72205@@ -69,6 +69,7 @@
72206 #include <linux/workqueue.h>
72207 #include <linux/poll.h>
72208 #include <asm/pgalloc.h>
72209+#include <asm/local.h>
72210 #include <drm/drm.h>
72211 #include <drm/drm_sarea.h>
72212
72213@@ -293,10 +294,12 @@ do { \
72214 * \param cmd command.
72215 * \param arg argument.
72216 */
72217-typedef int drm_ioctl_t(struct drm_device *dev, void *data,
72218+typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
72219+ struct drm_file *file_priv);
72220+typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
72221 struct drm_file *file_priv);
72222
72223-typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
72224+typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
72225 unsigned long arg);
72226
72227 #define DRM_IOCTL_NR(n) _IOC_NR(n)
72228@@ -311,10 +314,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
72229 struct drm_ioctl_desc {
72230 unsigned int cmd;
72231 int flags;
72232- drm_ioctl_t *func;
72233+ drm_ioctl_t func;
72234 unsigned int cmd_drv;
72235 const char *name;
72236-};
72237+} __do_const;
72238
72239 /**
72240 * Creates a driver or general drm_ioctl_desc array entry for the given
72241@@ -1015,7 +1018,7 @@ struct drm_info_list {
72242 int (*show)(struct seq_file*, void*); /** show callback */
72243 u32 driver_features; /**< Required driver features for this entry */
72244 void *data;
72245-};
72246+} __do_const;
72247
72248 /**
72249 * debugfs node structure. This structure represents a debugfs file.
72250@@ -1088,7 +1091,7 @@ struct drm_device {
72251
72252 /** \name Usage Counters */
72253 /*@{ */
72254- int open_count; /**< Outstanding files open */
72255+ local_t open_count; /**< Outstanding files open */
72256 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
72257 atomic_t vma_count; /**< Outstanding vma areas open */
72258 int buf_use; /**< Buffers in use -- cannot alloc */
72259@@ -1099,7 +1102,7 @@ struct drm_device {
72260 /*@{ */
72261 unsigned long counters;
72262 enum drm_stat_type types[15];
72263- atomic_t counts[15];
72264+ atomic_unchecked_t counts[15];
72265 /*@} */
72266
72267 struct list_head filelist;
72268diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
72269index f43d556..94d9343 100644
72270--- a/include/drm/drm_crtc_helper.h
72271+++ b/include/drm/drm_crtc_helper.h
72272@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
72273 struct drm_connector *connector);
72274 /* disable encoder when not in use - more explicit than dpms off */
72275 void (*disable)(struct drm_encoder *encoder);
72276-};
72277+} __no_const;
72278
72279 /**
72280 * drm_connector_helper_funcs - helper operations for connectors
72281diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
72282index 72dcbe8..8db58d7 100644
72283--- a/include/drm/ttm/ttm_memory.h
72284+++ b/include/drm/ttm/ttm_memory.h
72285@@ -48,7 +48,7 @@
72286
72287 struct ttm_mem_shrink {
72288 int (*do_shrink) (struct ttm_mem_shrink *);
72289-};
72290+} __no_const;
72291
72292 /**
72293 * struct ttm_mem_global - Global memory accounting structure.
72294diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
72295index 4b840e8..155d235 100644
72296--- a/include/keys/asymmetric-subtype.h
72297+++ b/include/keys/asymmetric-subtype.h
72298@@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
72299 /* Verify the signature on a key of this subtype (optional) */
72300 int (*verify_signature)(const struct key *key,
72301 const struct public_key_signature *sig);
72302-};
72303+} __do_const;
72304
72305 /**
72306 * asymmetric_key_subtype - Get the subtype from an asymmetric key
72307diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
72308index c1da539..1dcec55 100644
72309--- a/include/linux/atmdev.h
72310+++ b/include/linux/atmdev.h
72311@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
72312 #endif
72313
72314 struct k_atm_aal_stats {
72315-#define __HANDLE_ITEM(i) atomic_t i
72316+#define __HANDLE_ITEM(i) atomic_unchecked_t i
72317 __AAL_STAT_ITEMS
72318 #undef __HANDLE_ITEM
72319 };
72320@@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
72321 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
72322 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
72323 struct module *owner;
72324-};
72325+} __do_const ;
72326
72327 struct atmphy_ops {
72328 int (*start)(struct atm_dev *dev);
72329diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
72330index 70cf138..0418ee2 100644
72331--- a/include/linux/binfmts.h
72332+++ b/include/linux/binfmts.h
72333@@ -73,8 +73,10 @@ struct linux_binfmt {
72334 int (*load_binary)(struct linux_binprm *);
72335 int (*load_shlib)(struct file *);
72336 int (*core_dump)(struct coredump_params *cprm);
72337+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
72338+ void (*handle_mmap)(struct file *);
72339 unsigned long min_coredump; /* minimal dump size */
72340-};
72341+} __do_const;
72342
72343 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
72344
72345diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
72346index 2fdb4a4..54aad7e 100644
72347--- a/include/linux/blkdev.h
72348+++ b/include/linux/blkdev.h
72349@@ -1526,7 +1526,7 @@ struct block_device_operations {
72350 /* this callback is with swap_lock and sometimes page table lock held */
72351 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
72352 struct module *owner;
72353-};
72354+} __do_const;
72355
72356 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
72357 unsigned long);
72358diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
72359index 7c2e030..b72475d 100644
72360--- a/include/linux/blktrace_api.h
72361+++ b/include/linux/blktrace_api.h
72362@@ -23,7 +23,7 @@ struct blk_trace {
72363 struct dentry *dir;
72364 struct dentry *dropped_file;
72365 struct dentry *msg_file;
72366- atomic_t dropped;
72367+ atomic_unchecked_t dropped;
72368 };
72369
72370 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
72371diff --git a/include/linux/cache.h b/include/linux/cache.h
72372index 4c57065..4307975 100644
72373--- a/include/linux/cache.h
72374+++ b/include/linux/cache.h
72375@@ -16,6 +16,10 @@
72376 #define __read_mostly
72377 #endif
72378
72379+#ifndef __read_only
72380+#define __read_only __read_mostly
72381+#endif
72382+
72383 #ifndef ____cacheline_aligned
72384 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
72385 #endif
72386diff --git a/include/linux/capability.h b/include/linux/capability.h
72387index d9a4f7f4..19f77d6 100644
72388--- a/include/linux/capability.h
72389+++ b/include/linux/capability.h
72390@@ -213,8 +213,13 @@ extern bool ns_capable(struct user_namespace *ns, int cap);
72391 extern bool nsown_capable(int cap);
72392 extern bool inode_capable(const struct inode *inode, int cap);
72393 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
72394+extern bool capable_nolog(int cap);
72395+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
72396+extern bool inode_capable_nolog(const struct inode *inode, int cap);
72397
72398 /* audit system wants to get cap info from files as well */
72399 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
72400
72401+extern int is_privileged_binary(const struct dentry *dentry);
72402+
72403 #endif /* !_LINUX_CAPABILITY_H */
72404diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
72405index 8609d57..86e4d79 100644
72406--- a/include/linux/cdrom.h
72407+++ b/include/linux/cdrom.h
72408@@ -87,7 +87,6 @@ struct cdrom_device_ops {
72409
72410 /* driver specifications */
72411 const int capability; /* capability flags */
72412- int n_minors; /* number of active minor devices */
72413 /* handle uniform packets for scsi type devices (scsi,atapi) */
72414 int (*generic_packet) (struct cdrom_device_info *,
72415 struct packet_command *);
72416diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
72417index 4ce9056..86caac6 100644
72418--- a/include/linux/cleancache.h
72419+++ b/include/linux/cleancache.h
72420@@ -31,7 +31,7 @@ struct cleancache_ops {
72421 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
72422 void (*invalidate_inode)(int, struct cleancache_filekey);
72423 void (*invalidate_fs)(int);
72424-};
72425+} __no_const;
72426
72427 extern struct cleancache_ops *
72428 cleancache_register_ops(struct cleancache_ops *ops);
72429diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
72430index 1ec14a7..d0654a2 100644
72431--- a/include/linux/clk-provider.h
72432+++ b/include/linux/clk-provider.h
72433@@ -132,6 +132,7 @@ struct clk_ops {
72434 unsigned long);
72435 void (*init)(struct clk_hw *hw);
72436 };
72437+typedef struct clk_ops __no_const clk_ops_no_const;
72438
72439 /**
72440 * struct clk_init_data - holds init data that's common to all clocks and is
72441diff --git a/include/linux/compat.h b/include/linux/compat.h
72442index 7f0c1dd..206ac34 100644
72443--- a/include/linux/compat.h
72444+++ b/include/linux/compat.h
72445@@ -312,7 +312,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
72446 compat_size_t __user *len_ptr);
72447
72448 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
72449-asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
72450+asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
72451 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
72452 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
72453 compat_ssize_t msgsz, int msgflg);
72454@@ -419,7 +419,7 @@ extern int compat_ptrace_request(struct task_struct *child,
72455 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
72456 compat_ulong_t addr, compat_ulong_t data);
72457 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
72458- compat_long_t addr, compat_long_t data);
72459+ compat_ulong_t addr, compat_ulong_t data);
72460
72461 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, size_t);
72462 /*
72463@@ -669,6 +669,7 @@ asmlinkage long compat_sys_sigaltstack(const compat_stack_t __user *uss_ptr,
72464
72465 int compat_restore_altstack(const compat_stack_t __user *uss);
72466 int __compat_save_altstack(compat_stack_t __user *, unsigned long);
72467+void __compat_save_altstack_ex(compat_stack_t __user *, unsigned long);
72468
72469 asmlinkage long compat_sys_sched_rr_get_interval(compat_pid_t pid,
72470 struct compat_timespec __user *interval);
72471diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
72472index 842de22..7f3a41f 100644
72473--- a/include/linux/compiler-gcc4.h
72474+++ b/include/linux/compiler-gcc4.h
72475@@ -39,9 +39,29 @@
72476 # define __compiletime_warning(message) __attribute__((warning(message)))
72477 # define __compiletime_error(message) __attribute__((error(message)))
72478 #endif /* __CHECKER__ */
72479+
72480+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
72481+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
72482+#define __bos0(ptr) __bos((ptr), 0)
72483+#define __bos1(ptr) __bos((ptr), 1)
72484 #endif /* GCC_VERSION >= 40300 */
72485
72486 #if GCC_VERSION >= 40500
72487+
72488+#ifdef CONSTIFY_PLUGIN
72489+#define __no_const __attribute__((no_const))
72490+#define __do_const __attribute__((do_const))
72491+#endif
72492+
72493+#ifdef SIZE_OVERFLOW_PLUGIN
72494+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
72495+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
72496+#endif
72497+
72498+#ifdef LATENT_ENTROPY_PLUGIN
72499+#define __latent_entropy __attribute__((latent_entropy))
72500+#endif
72501+
72502 /*
72503 * Mark a position in code as unreachable. This can be used to
72504 * suppress control flow warnings after asm blocks that transfer
72505diff --git a/include/linux/compiler.h b/include/linux/compiler.h
72506index 92669cd..1771a15 100644
72507--- a/include/linux/compiler.h
72508+++ b/include/linux/compiler.h
72509@@ -5,11 +5,14 @@
72510
72511 #ifdef __CHECKER__
72512 # define __user __attribute__((noderef, address_space(1)))
72513+# define __force_user __force __user
72514 # define __kernel __attribute__((address_space(0)))
72515+# define __force_kernel __force __kernel
72516 # define __safe __attribute__((safe))
72517 # define __force __attribute__((force))
72518 # define __nocast __attribute__((nocast))
72519 # define __iomem __attribute__((noderef, address_space(2)))
72520+# define __force_iomem __force __iomem
72521 # define __must_hold(x) __attribute__((context(x,1,1)))
72522 # define __acquires(x) __attribute__((context(x,0,1)))
72523 # define __releases(x) __attribute__((context(x,1,0)))
72524@@ -17,20 +20,37 @@
72525 # define __release(x) __context__(x,-1)
72526 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
72527 # define __percpu __attribute__((noderef, address_space(3)))
72528+# define __force_percpu __force __percpu
72529 #ifdef CONFIG_SPARSE_RCU_POINTER
72530 # define __rcu __attribute__((noderef, address_space(4)))
72531+# define __force_rcu __force __rcu
72532 #else
72533 # define __rcu
72534+# define __force_rcu
72535 #endif
72536 extern void __chk_user_ptr(const volatile void __user *);
72537 extern void __chk_io_ptr(const volatile void __iomem *);
72538 #else
72539-# define __user
72540-# define __kernel
72541+# ifdef CHECKER_PLUGIN
72542+//# define __user
72543+//# define __force_user
72544+//# define __kernel
72545+//# define __force_kernel
72546+# else
72547+# ifdef STRUCTLEAK_PLUGIN
72548+# define __user __attribute__((user))
72549+# else
72550+# define __user
72551+# endif
72552+# define __force_user
72553+# define __kernel
72554+# define __force_kernel
72555+# endif
72556 # define __safe
72557 # define __force
72558 # define __nocast
72559 # define __iomem
72560+# define __force_iomem
72561 # define __chk_user_ptr(x) (void)0
72562 # define __chk_io_ptr(x) (void)0
72563 # define __builtin_warning(x, y...) (1)
72564@@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
72565 # define __release(x) (void)0
72566 # define __cond_lock(x,c) (c)
72567 # define __percpu
72568+# define __force_percpu
72569 # define __rcu
72570+# define __force_rcu
72571 #endif
72572
72573 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
72574@@ -275,6 +297,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
72575 # define __attribute_const__ /* unimplemented */
72576 #endif
72577
72578+#ifndef __no_const
72579+# define __no_const
72580+#endif
72581+
72582+#ifndef __do_const
72583+# define __do_const
72584+#endif
72585+
72586+#ifndef __size_overflow
72587+# define __size_overflow(...)
72588+#endif
72589+
72590+#ifndef __intentional_overflow
72591+# define __intentional_overflow(...)
72592+#endif
72593+
72594+#ifndef __latent_entropy
72595+# define __latent_entropy
72596+#endif
72597+
72598 /*
72599 * Tell gcc if a function is cold. The compiler will assume any path
72600 * directly leading to the call is unlikely.
72601@@ -284,6 +326,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
72602 #define __cold
72603 #endif
72604
72605+#ifndef __alloc_size
72606+#define __alloc_size(...)
72607+#endif
72608+
72609+#ifndef __bos
72610+#define __bos(ptr, arg)
72611+#endif
72612+
72613+#ifndef __bos0
72614+#define __bos0(ptr)
72615+#endif
72616+
72617+#ifndef __bos1
72618+#define __bos1(ptr)
72619+#endif
72620+
72621 /* Simple shorthand for a section definition */
72622 #ifndef __section
72623 # define __section(S) __attribute__ ((__section__(#S)))
72624@@ -349,7 +407,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
72625 * use is to mediate communication between process-level code and irq/NMI
72626 * handlers, all running on the same CPU.
72627 */
72628-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
72629+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
72630+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
72631
72632 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
72633 #ifdef CONFIG_KPROBES
72634diff --git a/include/linux/completion.h b/include/linux/completion.h
72635index 3cd574d..adce5fa 100644
72636--- a/include/linux/completion.h
72637+++ b/include/linux/completion.h
72638@@ -79,15 +79,15 @@ static inline void init_completion(struct completion *x)
72639 extern void wait_for_completion(struct completion *);
72640 extern void wait_for_completion_io(struct completion *);
72641 extern int wait_for_completion_interruptible(struct completion *x);
72642-extern int wait_for_completion_killable(struct completion *x);
72643+extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
72644 extern unsigned long wait_for_completion_timeout(struct completion *x,
72645 unsigned long timeout);
72646 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
72647 unsigned long timeout);
72648 extern long wait_for_completion_interruptible_timeout(
72649- struct completion *x, unsigned long timeout);
72650+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
72651 extern long wait_for_completion_killable_timeout(
72652- struct completion *x, unsigned long timeout);
72653+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
72654 extern bool try_wait_for_completion(struct completion *x);
72655 extern bool completion_done(struct completion *x);
72656
72657diff --git a/include/linux/configfs.h b/include/linux/configfs.h
72658index 34025df..d94bbbc 100644
72659--- a/include/linux/configfs.h
72660+++ b/include/linux/configfs.h
72661@@ -125,7 +125,7 @@ struct configfs_attribute {
72662 const char *ca_name;
72663 struct module *ca_owner;
72664 umode_t ca_mode;
72665-};
72666+} __do_const;
72667
72668 /*
72669 * Users often need to create attribute structures for their configurable
72670diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
72671index 90d5a15..950cb80 100644
72672--- a/include/linux/cpufreq.h
72673+++ b/include/linux/cpufreq.h
72674@@ -266,7 +266,7 @@ struct cpufreq_driver {
72675 int (*suspend) (struct cpufreq_policy *policy);
72676 int (*resume) (struct cpufreq_policy *policy);
72677 struct freq_attr **attr;
72678-};
72679+} __do_const;
72680
72681 /* flags */
72682
72683@@ -325,6 +325,7 @@ struct global_attr {
72684 ssize_t (*store)(struct kobject *a, struct attribute *b,
72685 const char *c, size_t count);
72686 };
72687+typedef struct global_attr __no_const global_attr_no_const;
72688
72689 #define define_one_global_ro(_name) \
72690 static struct global_attr _name = \
72691diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
72692index 0bc4b74..973b368 100644
72693--- a/include/linux/cpuidle.h
72694+++ b/include/linux/cpuidle.h
72695@@ -52,7 +52,8 @@ struct cpuidle_state {
72696 int index);
72697
72698 int (*enter_dead) (struct cpuidle_device *dev, int index);
72699-};
72700+} __do_const;
72701+typedef struct cpuidle_state __no_const cpuidle_state_no_const;
72702
72703 /* Idle State Flags */
72704 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
72705@@ -191,7 +192,7 @@ struct cpuidle_governor {
72706 void (*reflect) (struct cpuidle_device *dev, int index);
72707
72708 struct module *owner;
72709-};
72710+} __do_const;
72711
72712 #ifdef CONFIG_CPU_IDLE
72713
72714diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
72715index d08e4d2..95fad61 100644
72716--- a/include/linux/cpumask.h
72717+++ b/include/linux/cpumask.h
72718@@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
72719 }
72720
72721 /* Valid inputs for n are -1 and 0. */
72722-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
72723+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
72724 {
72725 return n+1;
72726 }
72727
72728-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
72729+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
72730 {
72731 return n+1;
72732 }
72733
72734-static inline unsigned int cpumask_next_and(int n,
72735+static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
72736 const struct cpumask *srcp,
72737 const struct cpumask *andp)
72738 {
72739@@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
72740 *
72741 * Returns >= nr_cpu_ids if no further cpus set.
72742 */
72743-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
72744+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
72745 {
72746 /* -1 is a legal arg here. */
72747 if (n != -1)
72748@@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
72749 *
72750 * Returns >= nr_cpu_ids if no further cpus unset.
72751 */
72752-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
72753+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
72754 {
72755 /* -1 is a legal arg here. */
72756 if (n != -1)
72757@@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
72758 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
72759 }
72760
72761-int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
72762+int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
72763 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
72764
72765 /**
72766diff --git a/include/linux/cred.h b/include/linux/cred.h
72767index 04421e8..6bce4ef 100644
72768--- a/include/linux/cred.h
72769+++ b/include/linux/cred.h
72770@@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
72771 static inline void validate_process_creds(void)
72772 {
72773 }
72774+static inline void validate_task_creds(struct task_struct *task)
72775+{
72776+}
72777 #endif
72778
72779 /**
72780diff --git a/include/linux/crypto.h b/include/linux/crypto.h
72781index b92eadf..b4ecdc1 100644
72782--- a/include/linux/crypto.h
72783+++ b/include/linux/crypto.h
72784@@ -373,7 +373,7 @@ struct cipher_tfm {
72785 const u8 *key, unsigned int keylen);
72786 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
72787 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
72788-};
72789+} __no_const;
72790
72791 struct hash_tfm {
72792 int (*init)(struct hash_desc *desc);
72793@@ -394,13 +394,13 @@ struct compress_tfm {
72794 int (*cot_decompress)(struct crypto_tfm *tfm,
72795 const u8 *src, unsigned int slen,
72796 u8 *dst, unsigned int *dlen);
72797-};
72798+} __no_const;
72799
72800 struct rng_tfm {
72801 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
72802 unsigned int dlen);
72803 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
72804-};
72805+} __no_const;
72806
72807 #define crt_ablkcipher crt_u.ablkcipher
72808 #define crt_aead crt_u.aead
72809diff --git a/include/linux/ctype.h b/include/linux/ctype.h
72810index 653589e..4ef254a 100644
72811--- a/include/linux/ctype.h
72812+++ b/include/linux/ctype.h
72813@@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
72814 * Fast implementation of tolower() for internal usage. Do not use in your
72815 * code.
72816 */
72817-static inline char _tolower(const char c)
72818+static inline unsigned char _tolower(const unsigned char c)
72819 {
72820 return c | 0x20;
72821 }
72822diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
72823index 7925bf0..d5143d2 100644
72824--- a/include/linux/decompress/mm.h
72825+++ b/include/linux/decompress/mm.h
72826@@ -77,7 +77,7 @@ static void free(void *where)
72827 * warnings when not needed (indeed large_malloc / large_free are not
72828 * needed by inflate */
72829
72830-#define malloc(a) kmalloc(a, GFP_KERNEL)
72831+#define malloc(a) kmalloc((a), GFP_KERNEL)
72832 #define free(a) kfree(a)
72833
72834 #define large_malloc(a) vmalloc(a)
72835diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
72836index 5f1ab92..39c35ae 100644
72837--- a/include/linux/devfreq.h
72838+++ b/include/linux/devfreq.h
72839@@ -114,7 +114,7 @@ struct devfreq_governor {
72840 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
72841 int (*event_handler)(struct devfreq *devfreq,
72842 unsigned int event, void *data);
72843-};
72844+} __do_const;
72845
72846 /**
72847 * struct devfreq - Device devfreq structure
72848diff --git a/include/linux/device.h b/include/linux/device.h
72849index 22b546a..a573dc9 100644
72850--- a/include/linux/device.h
72851+++ b/include/linux/device.h
72852@@ -305,7 +305,7 @@ struct subsys_interface {
72853 struct list_head node;
72854 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
72855 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
72856-};
72857+} __do_const;
72858
72859 int subsys_interface_register(struct subsys_interface *sif);
72860 void subsys_interface_unregister(struct subsys_interface *sif);
72861@@ -493,7 +493,7 @@ struct device_type {
72862 void (*release)(struct device *dev);
72863
72864 const struct dev_pm_ops *pm;
72865-};
72866+} __do_const;
72867
72868 /* interface for exporting device attributes */
72869 struct device_attribute {
72870@@ -503,11 +503,12 @@ struct device_attribute {
72871 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
72872 const char *buf, size_t count);
72873 };
72874+typedef struct device_attribute __no_const device_attribute_no_const;
72875
72876 struct dev_ext_attribute {
72877 struct device_attribute attr;
72878 void *var;
72879-};
72880+} __do_const;
72881
72882 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
72883 char *buf);
72884diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
72885index 94af418..b1ca7a2 100644
72886--- a/include/linux/dma-mapping.h
72887+++ b/include/linux/dma-mapping.h
72888@@ -54,7 +54,7 @@ struct dma_map_ops {
72889 u64 (*get_required_mask)(struct device *dev);
72890 #endif
72891 int is_phys;
72892-};
72893+} __do_const;
72894
72895 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
72896
72897diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
72898index cb286b1..923d066 100644
72899--- a/include/linux/dmaengine.h
72900+++ b/include/linux/dmaengine.h
72901@@ -1030,9 +1030,9 @@ struct dma_pinned_list {
72902 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
72903 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
72904
72905-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
72906+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
72907 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
72908-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
72909+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
72910 struct dma_pinned_list *pinned_list, struct page *page,
72911 unsigned int offset, size_t len);
72912
72913diff --git a/include/linux/efi.h b/include/linux/efi.h
72914index 5f8f176..62a0556 100644
72915--- a/include/linux/efi.h
72916+++ b/include/linux/efi.h
72917@@ -745,6 +745,7 @@ struct efivar_operations {
72918 efi_set_variable_t *set_variable;
72919 efi_query_variable_store_t *query_variable_store;
72920 };
72921+typedef struct efivar_operations __no_const efivar_operations_no_const;
72922
72923 struct efivars {
72924 /*
72925diff --git a/include/linux/elf.h b/include/linux/elf.h
72926index 40a3c0e..4c45a38 100644
72927--- a/include/linux/elf.h
72928+++ b/include/linux/elf.h
72929@@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
72930 #define elf_note elf32_note
72931 #define elf_addr_t Elf32_Off
72932 #define Elf_Half Elf32_Half
72933+#define elf_dyn Elf32_Dyn
72934
72935 #else
72936
72937@@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
72938 #define elf_note elf64_note
72939 #define elf_addr_t Elf64_Off
72940 #define Elf_Half Elf64_Half
72941+#define elf_dyn Elf64_Dyn
72942
72943 #endif
72944
72945diff --git a/include/linux/err.h b/include/linux/err.h
72946index 221fcfb..f29e5e2 100644
72947--- a/include/linux/err.h
72948+++ b/include/linux/err.h
72949@@ -19,12 +19,12 @@
72950
72951 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
72952
72953-static inline void * __must_check ERR_PTR(long error)
72954+static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
72955 {
72956 return (void *) error;
72957 }
72958
72959-static inline long __must_check PTR_ERR(__force const void *ptr)
72960+static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
72961 {
72962 return (long) ptr;
72963 }
72964diff --git a/include/linux/extcon.h b/include/linux/extcon.h
72965index fcb51c8..bdafcf6 100644
72966--- a/include/linux/extcon.h
72967+++ b/include/linux/extcon.h
72968@@ -134,7 +134,7 @@ struct extcon_dev {
72969 /* /sys/class/extcon/.../mutually_exclusive/... */
72970 struct attribute_group attr_g_muex;
72971 struct attribute **attrs_muex;
72972- struct device_attribute *d_attrs_muex;
72973+ device_attribute_no_const *d_attrs_muex;
72974 };
72975
72976 /**
72977diff --git a/include/linux/fb.h b/include/linux/fb.h
72978index ffac70a..ca3e711 100644
72979--- a/include/linux/fb.h
72980+++ b/include/linux/fb.h
72981@@ -304,7 +304,7 @@ struct fb_ops {
72982 /* called at KDB enter and leave time to prepare the console */
72983 int (*fb_debug_enter)(struct fb_info *info);
72984 int (*fb_debug_leave)(struct fb_info *info);
72985-};
72986+} __do_const;
72987
72988 #ifdef CONFIG_FB_TILEBLITTING
72989 #define FB_TILE_CURSOR_NONE 0
72990diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
72991index 085197b..0fa6f0b 100644
72992--- a/include/linux/fdtable.h
72993+++ b/include/linux/fdtable.h
72994@@ -95,7 +95,7 @@ struct files_struct *get_files_struct(struct task_struct *);
72995 void put_files_struct(struct files_struct *fs);
72996 void reset_files_struct(struct files_struct *);
72997 int unshare_files(struct files_struct **);
72998-struct files_struct *dup_fd(struct files_struct *, int *);
72999+struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
73000 void do_close_on_exec(struct files_struct *);
73001 int iterate_fd(struct files_struct *, unsigned,
73002 int (*)(const void *, struct file *, unsigned),
73003diff --git a/include/linux/filter.h b/include/linux/filter.h
73004index a6ac848..a104a76 100644
73005--- a/include/linux/filter.h
73006+++ b/include/linux/filter.h
73007@@ -20,6 +20,7 @@ struct compat_sock_fprog {
73008
73009 struct sk_buff;
73010 struct sock;
73011+struct bpf_jit_work;
73012
73013 struct sk_filter
73014 {
73015@@ -27,6 +28,9 @@ struct sk_filter
73016 unsigned int len; /* Number of filter blocks */
73017 unsigned int (*bpf_func)(const struct sk_buff *skb,
73018 const struct sock_filter *filter);
73019+#ifdef CONFIG_BPF_JIT
73020+ struct bpf_jit_work *work;
73021+#endif
73022 struct rcu_head rcu;
73023 struct sock_filter insns[0];
73024 };
73025diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
73026index 8293262..2b3b8bd 100644
73027--- a/include/linux/frontswap.h
73028+++ b/include/linux/frontswap.h
73029@@ -11,7 +11,7 @@ struct frontswap_ops {
73030 int (*load)(unsigned, pgoff_t, struct page *);
73031 void (*invalidate_page)(unsigned, pgoff_t);
73032 void (*invalidate_area)(unsigned);
73033-};
73034+} __no_const;
73035
73036 extern bool frontswap_enabled;
73037 extern struct frontswap_ops *
73038diff --git a/include/linux/fs.h b/include/linux/fs.h
73039index 9818747..788bfbd 100644
73040--- a/include/linux/fs.h
73041+++ b/include/linux/fs.h
73042@@ -1554,7 +1554,8 @@ struct file_operations {
73043 long (*fallocate)(struct file *file, int mode, loff_t offset,
73044 loff_t len);
73045 int (*show_fdinfo)(struct seq_file *m, struct file *f);
73046-};
73047+} __do_const;
73048+typedef struct file_operations __no_const file_operations_no_const;
73049
73050 struct inode_operations {
73051 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
73052@@ -2740,4 +2741,14 @@ static inline bool dir_relax(struct inode *inode)
73053 return !IS_DEADDIR(inode);
73054 }
73055
73056+static inline bool is_sidechannel_device(const struct inode *inode)
73057+{
73058+#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
73059+ umode_t mode = inode->i_mode;
73060+ return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
73061+#else
73062+ return false;
73063+#endif
73064+}
73065+
73066 #endif /* _LINUX_FS_H */
73067diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
73068index 2b93a9a..855d94a 100644
73069--- a/include/linux/fs_struct.h
73070+++ b/include/linux/fs_struct.h
73071@@ -6,7 +6,7 @@
73072 #include <linux/seqlock.h>
73073
73074 struct fs_struct {
73075- int users;
73076+ atomic_t users;
73077 spinlock_t lock;
73078 seqcount_t seq;
73079 int umask;
73080diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
73081index a9ff9a3..1ba1788 100644
73082--- a/include/linux/fscache-cache.h
73083+++ b/include/linux/fscache-cache.h
73084@@ -113,7 +113,7 @@ struct fscache_operation {
73085 fscache_operation_release_t release;
73086 };
73087
73088-extern atomic_t fscache_op_debug_id;
73089+extern atomic_unchecked_t fscache_op_debug_id;
73090 extern void fscache_op_work_func(struct work_struct *work);
73091
73092 extern void fscache_enqueue_operation(struct fscache_operation *);
73093@@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
73094 INIT_WORK(&op->work, fscache_op_work_func);
73095 atomic_set(&op->usage, 1);
73096 op->state = FSCACHE_OP_ST_INITIALISED;
73097- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
73098+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
73099 op->processor = processor;
73100 op->release = release;
73101 INIT_LIST_HEAD(&op->pend_link);
73102diff --git a/include/linux/fscache.h b/include/linux/fscache.h
73103index 7a08623..4c07b0f 100644
73104--- a/include/linux/fscache.h
73105+++ b/include/linux/fscache.h
73106@@ -152,7 +152,7 @@ struct fscache_cookie_def {
73107 * - this is mandatory for any object that may have data
73108 */
73109 void (*now_uncached)(void *cookie_netfs_data);
73110-};
73111+} __do_const;
73112
73113 /*
73114 * fscache cached network filesystem type
73115diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
73116index 1c804b0..1432c2b 100644
73117--- a/include/linux/fsnotify.h
73118+++ b/include/linux/fsnotify.h
73119@@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
73120 struct inode *inode = file_inode(file);
73121 __u32 mask = FS_ACCESS;
73122
73123+ if (is_sidechannel_device(inode))
73124+ return;
73125+
73126 if (S_ISDIR(inode->i_mode))
73127 mask |= FS_ISDIR;
73128
73129@@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
73130 struct inode *inode = file_inode(file);
73131 __u32 mask = FS_MODIFY;
73132
73133+ if (is_sidechannel_device(inode))
73134+ return;
73135+
73136 if (S_ISDIR(inode->i_mode))
73137 mask |= FS_ISDIR;
73138
73139@@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
73140 */
73141 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
73142 {
73143- return kstrdup(name, GFP_KERNEL);
73144+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
73145 }
73146
73147 /*
73148diff --git a/include/linux/genhd.h b/include/linux/genhd.h
73149index 9f3c275..911b591 100644
73150--- a/include/linux/genhd.h
73151+++ b/include/linux/genhd.h
73152@@ -194,7 +194,7 @@ struct gendisk {
73153 struct kobject *slave_dir;
73154
73155 struct timer_rand_state *random;
73156- atomic_t sync_io; /* RAID */
73157+ atomic_unchecked_t sync_io; /* RAID */
73158 struct disk_events *ev;
73159 #ifdef CONFIG_BLK_DEV_INTEGRITY
73160 struct blk_integrity *integrity;
73161diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
73162index 023bc34..b02b46a 100644
73163--- a/include/linux/genl_magic_func.h
73164+++ b/include/linux/genl_magic_func.h
73165@@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
73166 },
73167
73168 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
73169-static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
73170+static struct genl_ops ZZZ_genl_ops[] = {
73171 #include GENL_MAGIC_INCLUDE_FILE
73172 };
73173
73174diff --git a/include/linux/gfp.h b/include/linux/gfp.h
73175index 9b4dd49..61fd41d 100644
73176--- a/include/linux/gfp.h
73177+++ b/include/linux/gfp.h
73178@@ -35,6 +35,13 @@ struct vm_area_struct;
73179 #define ___GFP_NO_KSWAPD 0x400000u
73180 #define ___GFP_OTHER_NODE 0x800000u
73181 #define ___GFP_WRITE 0x1000000u
73182+
73183+#ifdef CONFIG_PAX_USERCOPY_SLABS
73184+#define ___GFP_USERCOPY 0x2000000u
73185+#else
73186+#define ___GFP_USERCOPY 0
73187+#endif
73188+
73189 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
73190
73191 /*
73192@@ -92,6 +99,7 @@ struct vm_area_struct;
73193 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
73194 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
73195 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
73196+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
73197
73198 /*
73199 * This may seem redundant, but it's a way of annotating false positives vs.
73200@@ -99,7 +107,7 @@ struct vm_area_struct;
73201 */
73202 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
73203
73204-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
73205+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
73206 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
73207
73208 /* This equals 0, but use constants in case they ever change */
73209@@ -153,6 +161,8 @@ struct vm_area_struct;
73210 /* 4GB DMA on some platforms */
73211 #define GFP_DMA32 __GFP_DMA32
73212
73213+#define GFP_USERCOPY __GFP_USERCOPY
73214+
73215 /* Convert GFP flags to their corresponding migrate type */
73216 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
73217 {
73218diff --git a/include/linux/gracl.h b/include/linux/gracl.h
73219new file mode 100644
73220index 0000000..ebe6d72
73221--- /dev/null
73222+++ b/include/linux/gracl.h
73223@@ -0,0 +1,319 @@
73224+#ifndef GR_ACL_H
73225+#define GR_ACL_H
73226+
73227+#include <linux/grdefs.h>
73228+#include <linux/resource.h>
73229+#include <linux/capability.h>
73230+#include <linux/dcache.h>
73231+#include <asm/resource.h>
73232+
73233+/* Major status information */
73234+
73235+#define GR_VERSION "grsecurity 2.9.1"
73236+#define GRSECURITY_VERSION 0x2901
73237+
73238+enum {
73239+ GR_SHUTDOWN = 0,
73240+ GR_ENABLE = 1,
73241+ GR_SPROLE = 2,
73242+ GR_RELOAD = 3,
73243+ GR_SEGVMOD = 4,
73244+ GR_STATUS = 5,
73245+ GR_UNSPROLE = 6,
73246+ GR_PASSSET = 7,
73247+ GR_SPROLEPAM = 8,
73248+};
73249+
73250+/* Password setup definitions
73251+ * kernel/grhash.c */
73252+enum {
73253+ GR_PW_LEN = 128,
73254+ GR_SALT_LEN = 16,
73255+ GR_SHA_LEN = 32,
73256+};
73257+
73258+enum {
73259+ GR_SPROLE_LEN = 64,
73260+};
73261+
73262+enum {
73263+ GR_NO_GLOB = 0,
73264+ GR_REG_GLOB,
73265+ GR_CREATE_GLOB
73266+};
73267+
73268+#define GR_NLIMITS 32
73269+
73270+/* Begin Data Structures */
73271+
73272+struct sprole_pw {
73273+ unsigned char *rolename;
73274+ unsigned char salt[GR_SALT_LEN];
73275+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
73276+};
73277+
73278+struct name_entry {
73279+ __u32 key;
73280+ ino_t inode;
73281+ dev_t device;
73282+ char *name;
73283+ __u16 len;
73284+ __u8 deleted;
73285+ struct name_entry *prev;
73286+ struct name_entry *next;
73287+};
73288+
73289+struct inodev_entry {
73290+ struct name_entry *nentry;
73291+ struct inodev_entry *prev;
73292+ struct inodev_entry *next;
73293+};
73294+
73295+struct acl_role_db {
73296+ struct acl_role_label **r_hash;
73297+ __u32 r_size;
73298+};
73299+
73300+struct inodev_db {
73301+ struct inodev_entry **i_hash;
73302+ __u32 i_size;
73303+};
73304+
73305+struct name_db {
73306+ struct name_entry **n_hash;
73307+ __u32 n_size;
73308+};
73309+
73310+struct crash_uid {
73311+ uid_t uid;
73312+ unsigned long expires;
73313+};
73314+
73315+struct gr_hash_struct {
73316+ void **table;
73317+ void **nametable;
73318+ void *first;
73319+ __u32 table_size;
73320+ __u32 used_size;
73321+ int type;
73322+};
73323+
73324+/* Userspace Grsecurity ACL data structures */
73325+
73326+struct acl_subject_label {
73327+ char *filename;
73328+ ino_t inode;
73329+ dev_t device;
73330+ __u32 mode;
73331+ kernel_cap_t cap_mask;
73332+ kernel_cap_t cap_lower;
73333+ kernel_cap_t cap_invert_audit;
73334+
73335+ struct rlimit res[GR_NLIMITS];
73336+ __u32 resmask;
73337+
73338+ __u8 user_trans_type;
73339+ __u8 group_trans_type;
73340+ uid_t *user_transitions;
73341+ gid_t *group_transitions;
73342+ __u16 user_trans_num;
73343+ __u16 group_trans_num;
73344+
73345+ __u32 sock_families[2];
73346+ __u32 ip_proto[8];
73347+ __u32 ip_type;
73348+ struct acl_ip_label **ips;
73349+ __u32 ip_num;
73350+ __u32 inaddr_any_override;
73351+
73352+ __u32 crashes;
73353+ unsigned long expires;
73354+
73355+ struct acl_subject_label *parent_subject;
73356+ struct gr_hash_struct *hash;
73357+ struct acl_subject_label *prev;
73358+ struct acl_subject_label *next;
73359+
73360+ struct acl_object_label **obj_hash;
73361+ __u32 obj_hash_size;
73362+ __u16 pax_flags;
73363+};
73364+
73365+struct role_allowed_ip {
73366+ __u32 addr;
73367+ __u32 netmask;
73368+
73369+ struct role_allowed_ip *prev;
73370+ struct role_allowed_ip *next;
73371+};
73372+
73373+struct role_transition {
73374+ char *rolename;
73375+
73376+ struct role_transition *prev;
73377+ struct role_transition *next;
73378+};
73379+
73380+struct acl_role_label {
73381+ char *rolename;
73382+ uid_t uidgid;
73383+ __u16 roletype;
73384+
73385+ __u16 auth_attempts;
73386+ unsigned long expires;
73387+
73388+ struct acl_subject_label *root_label;
73389+ struct gr_hash_struct *hash;
73390+
73391+ struct acl_role_label *prev;
73392+ struct acl_role_label *next;
73393+
73394+ struct role_transition *transitions;
73395+ struct role_allowed_ip *allowed_ips;
73396+ uid_t *domain_children;
73397+ __u16 domain_child_num;
73398+
73399+ umode_t umask;
73400+
73401+ struct acl_subject_label **subj_hash;
73402+ __u32 subj_hash_size;
73403+};
73404+
73405+struct user_acl_role_db {
73406+ struct acl_role_label **r_table;
73407+ __u32 num_pointers; /* Number of allocations to track */
73408+ __u32 num_roles; /* Number of roles */
73409+ __u32 num_domain_children; /* Number of domain children */
73410+ __u32 num_subjects; /* Number of subjects */
73411+ __u32 num_objects; /* Number of objects */
73412+};
73413+
73414+struct acl_object_label {
73415+ char *filename;
73416+ ino_t inode;
73417+ dev_t device;
73418+ __u32 mode;
73419+
73420+ struct acl_subject_label *nested;
73421+ struct acl_object_label *globbed;
73422+
73423+ /* next two structures not used */
73424+
73425+ struct acl_object_label *prev;
73426+ struct acl_object_label *next;
73427+};
73428+
73429+struct acl_ip_label {
73430+ char *iface;
73431+ __u32 addr;
73432+ __u32 netmask;
73433+ __u16 low, high;
73434+ __u8 mode;
73435+ __u32 type;
73436+ __u32 proto[8];
73437+
73438+ /* next two structures not used */
73439+
73440+ struct acl_ip_label *prev;
73441+ struct acl_ip_label *next;
73442+};
73443+
73444+struct gr_arg {
73445+ struct user_acl_role_db role_db;
73446+ unsigned char pw[GR_PW_LEN];
73447+ unsigned char salt[GR_SALT_LEN];
73448+ unsigned char sum[GR_SHA_LEN];
73449+ unsigned char sp_role[GR_SPROLE_LEN];
73450+ struct sprole_pw *sprole_pws;
73451+ dev_t segv_device;
73452+ ino_t segv_inode;
73453+ uid_t segv_uid;
73454+ __u16 num_sprole_pws;
73455+ __u16 mode;
73456+};
73457+
73458+struct gr_arg_wrapper {
73459+ struct gr_arg *arg;
73460+ __u32 version;
73461+ __u32 size;
73462+};
73463+
73464+struct subject_map {
73465+ struct acl_subject_label *user;
73466+ struct acl_subject_label *kernel;
73467+ struct subject_map *prev;
73468+ struct subject_map *next;
73469+};
73470+
73471+struct acl_subj_map_db {
73472+ struct subject_map **s_hash;
73473+ __u32 s_size;
73474+};
73475+
73476+/* End Data Structures Section */
73477+
73478+/* Hash functions generated by empirical testing by Brad Spengler
73479+ Makes good use of the low bits of the inode. Generally 0-1 times
73480+ in loop for successful match. 0-3 for unsuccessful match.
73481+ Shift/add algorithm with modulus of table size and an XOR*/
73482+
73483+static __inline__ unsigned int
73484+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
73485+{
73486+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
73487+}
73488+
73489+ static __inline__ unsigned int
73490+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
73491+{
73492+ return ((const unsigned long)userp % sz);
73493+}
73494+
73495+static __inline__ unsigned int
73496+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
73497+{
73498+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
73499+}
73500+
73501+static __inline__ unsigned int
73502+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
73503+{
73504+ return full_name_hash((const unsigned char *)name, len) % sz;
73505+}
73506+
73507+#define FOR_EACH_ROLE_START(role) \
73508+ role = role_list; \
73509+ while (role) {
73510+
73511+#define FOR_EACH_ROLE_END(role) \
73512+ role = role->prev; \
73513+ }
73514+
73515+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
73516+ subj = NULL; \
73517+ iter = 0; \
73518+ while (iter < role->subj_hash_size) { \
73519+ if (subj == NULL) \
73520+ subj = role->subj_hash[iter]; \
73521+ if (subj == NULL) { \
73522+ iter++; \
73523+ continue; \
73524+ }
73525+
73526+#define FOR_EACH_SUBJECT_END(subj,iter) \
73527+ subj = subj->next; \
73528+ if (subj == NULL) \
73529+ iter++; \
73530+ }
73531+
73532+
73533+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
73534+ subj = role->hash->first; \
73535+ while (subj != NULL) {
73536+
73537+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
73538+ subj = subj->next; \
73539+ }
73540+
73541+#endif
73542+
73543diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
73544new file mode 100644
73545index 0000000..33ebd1f
73546--- /dev/null
73547+++ b/include/linux/gracl_compat.h
73548@@ -0,0 +1,156 @@
73549+#ifndef GR_ACL_COMPAT_H
73550+#define GR_ACL_COMPAT_H
73551+
73552+#include <linux/resource.h>
73553+#include <asm/resource.h>
73554+
73555+struct sprole_pw_compat {
73556+ compat_uptr_t rolename;
73557+ unsigned char salt[GR_SALT_LEN];
73558+ unsigned char sum[GR_SHA_LEN];
73559+};
73560+
73561+struct gr_hash_struct_compat {
73562+ compat_uptr_t table;
73563+ compat_uptr_t nametable;
73564+ compat_uptr_t first;
73565+ __u32 table_size;
73566+ __u32 used_size;
73567+ int type;
73568+};
73569+
73570+struct acl_subject_label_compat {
73571+ compat_uptr_t filename;
73572+ compat_ino_t inode;
73573+ __u32 device;
73574+ __u32 mode;
73575+ kernel_cap_t cap_mask;
73576+ kernel_cap_t cap_lower;
73577+ kernel_cap_t cap_invert_audit;
73578+
73579+ struct compat_rlimit res[GR_NLIMITS];
73580+ __u32 resmask;
73581+
73582+ __u8 user_trans_type;
73583+ __u8 group_trans_type;
73584+ compat_uptr_t user_transitions;
73585+ compat_uptr_t group_transitions;
73586+ __u16 user_trans_num;
73587+ __u16 group_trans_num;
73588+
73589+ __u32 sock_families[2];
73590+ __u32 ip_proto[8];
73591+ __u32 ip_type;
73592+ compat_uptr_t ips;
73593+ __u32 ip_num;
73594+ __u32 inaddr_any_override;
73595+
73596+ __u32 crashes;
73597+ compat_ulong_t expires;
73598+
73599+ compat_uptr_t parent_subject;
73600+ compat_uptr_t hash;
73601+ compat_uptr_t prev;
73602+ compat_uptr_t next;
73603+
73604+ compat_uptr_t obj_hash;
73605+ __u32 obj_hash_size;
73606+ __u16 pax_flags;
73607+};
73608+
73609+struct role_allowed_ip_compat {
73610+ __u32 addr;
73611+ __u32 netmask;
73612+
73613+ compat_uptr_t prev;
73614+ compat_uptr_t next;
73615+};
73616+
73617+struct role_transition_compat {
73618+ compat_uptr_t rolename;
73619+
73620+ compat_uptr_t prev;
73621+ compat_uptr_t next;
73622+};
73623+
73624+struct acl_role_label_compat {
73625+ compat_uptr_t rolename;
73626+ uid_t uidgid;
73627+ __u16 roletype;
73628+
73629+ __u16 auth_attempts;
73630+ compat_ulong_t expires;
73631+
73632+ compat_uptr_t root_label;
73633+ compat_uptr_t hash;
73634+
73635+ compat_uptr_t prev;
73636+ compat_uptr_t next;
73637+
73638+ compat_uptr_t transitions;
73639+ compat_uptr_t allowed_ips;
73640+ compat_uptr_t domain_children;
73641+ __u16 domain_child_num;
73642+
73643+ umode_t umask;
73644+
73645+ compat_uptr_t subj_hash;
73646+ __u32 subj_hash_size;
73647+};
73648+
73649+struct user_acl_role_db_compat {
73650+ compat_uptr_t r_table;
73651+ __u32 num_pointers;
73652+ __u32 num_roles;
73653+ __u32 num_domain_children;
73654+ __u32 num_subjects;
73655+ __u32 num_objects;
73656+};
73657+
73658+struct acl_object_label_compat {
73659+ compat_uptr_t filename;
73660+ compat_ino_t inode;
73661+ __u32 device;
73662+ __u32 mode;
73663+
73664+ compat_uptr_t nested;
73665+ compat_uptr_t globbed;
73666+
73667+ compat_uptr_t prev;
73668+ compat_uptr_t next;
73669+};
73670+
73671+struct acl_ip_label_compat {
73672+ compat_uptr_t iface;
73673+ __u32 addr;
73674+ __u32 netmask;
73675+ __u16 low, high;
73676+ __u8 mode;
73677+ __u32 type;
73678+ __u32 proto[8];
73679+
73680+ compat_uptr_t prev;
73681+ compat_uptr_t next;
73682+};
73683+
73684+struct gr_arg_compat {
73685+ struct user_acl_role_db_compat role_db;
73686+ unsigned char pw[GR_PW_LEN];
73687+ unsigned char salt[GR_SALT_LEN];
73688+ unsigned char sum[GR_SHA_LEN];
73689+ unsigned char sp_role[GR_SPROLE_LEN];
73690+ compat_uptr_t sprole_pws;
73691+ __u32 segv_device;
73692+ compat_ino_t segv_inode;
73693+ uid_t segv_uid;
73694+ __u16 num_sprole_pws;
73695+ __u16 mode;
73696+};
73697+
73698+struct gr_arg_wrapper_compat {
73699+ compat_uptr_t arg;
73700+ __u32 version;
73701+ __u32 size;
73702+};
73703+
73704+#endif
73705diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
73706new file mode 100644
73707index 0000000..323ecf2
73708--- /dev/null
73709+++ b/include/linux/gralloc.h
73710@@ -0,0 +1,9 @@
73711+#ifndef __GRALLOC_H
73712+#define __GRALLOC_H
73713+
73714+void acl_free_all(void);
73715+int acl_alloc_stack_init(unsigned long size);
73716+void *acl_alloc(unsigned long len);
73717+void *acl_alloc_num(unsigned long num, unsigned long len);
73718+
73719+#endif
73720diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
73721new file mode 100644
73722index 0000000..be66033
73723--- /dev/null
73724+++ b/include/linux/grdefs.h
73725@@ -0,0 +1,140 @@
73726+#ifndef GRDEFS_H
73727+#define GRDEFS_H
73728+
73729+/* Begin grsecurity status declarations */
73730+
73731+enum {
73732+ GR_READY = 0x01,
73733+ GR_STATUS_INIT = 0x00 // disabled state
73734+};
73735+
73736+/* Begin ACL declarations */
73737+
73738+/* Role flags */
73739+
73740+enum {
73741+ GR_ROLE_USER = 0x0001,
73742+ GR_ROLE_GROUP = 0x0002,
73743+ GR_ROLE_DEFAULT = 0x0004,
73744+ GR_ROLE_SPECIAL = 0x0008,
73745+ GR_ROLE_AUTH = 0x0010,
73746+ GR_ROLE_NOPW = 0x0020,
73747+ GR_ROLE_GOD = 0x0040,
73748+ GR_ROLE_LEARN = 0x0080,
73749+ GR_ROLE_TPE = 0x0100,
73750+ GR_ROLE_DOMAIN = 0x0200,
73751+ GR_ROLE_PAM = 0x0400,
73752+ GR_ROLE_PERSIST = 0x0800
73753+};
73754+
73755+/* ACL Subject and Object mode flags */
73756+enum {
73757+ GR_DELETED = 0x80000000
73758+};
73759+
73760+/* ACL Object-only mode flags */
73761+enum {
73762+ GR_READ = 0x00000001,
73763+ GR_APPEND = 0x00000002,
73764+ GR_WRITE = 0x00000004,
73765+ GR_EXEC = 0x00000008,
73766+ GR_FIND = 0x00000010,
73767+ GR_INHERIT = 0x00000020,
73768+ GR_SETID = 0x00000040,
73769+ GR_CREATE = 0x00000080,
73770+ GR_DELETE = 0x00000100,
73771+ GR_LINK = 0x00000200,
73772+ GR_AUDIT_READ = 0x00000400,
73773+ GR_AUDIT_APPEND = 0x00000800,
73774+ GR_AUDIT_WRITE = 0x00001000,
73775+ GR_AUDIT_EXEC = 0x00002000,
73776+ GR_AUDIT_FIND = 0x00004000,
73777+ GR_AUDIT_INHERIT= 0x00008000,
73778+ GR_AUDIT_SETID = 0x00010000,
73779+ GR_AUDIT_CREATE = 0x00020000,
73780+ GR_AUDIT_DELETE = 0x00040000,
73781+ GR_AUDIT_LINK = 0x00080000,
73782+ GR_PTRACERD = 0x00100000,
73783+ GR_NOPTRACE = 0x00200000,
73784+ GR_SUPPRESS = 0x00400000,
73785+ GR_NOLEARN = 0x00800000,
73786+ GR_INIT_TRANSFER= 0x01000000
73787+};
73788+
73789+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
73790+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
73791+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
73792+
73793+/* ACL subject-only mode flags */
73794+enum {
73795+ GR_KILL = 0x00000001,
73796+ GR_VIEW = 0x00000002,
73797+ GR_PROTECTED = 0x00000004,
73798+ GR_LEARN = 0x00000008,
73799+ GR_OVERRIDE = 0x00000010,
73800+ /* just a placeholder, this mode is only used in userspace */
73801+ GR_DUMMY = 0x00000020,
73802+ GR_PROTSHM = 0x00000040,
73803+ GR_KILLPROC = 0x00000080,
73804+ GR_KILLIPPROC = 0x00000100,
73805+ /* just a placeholder, this mode is only used in userspace */
73806+ GR_NOTROJAN = 0x00000200,
73807+ GR_PROTPROCFD = 0x00000400,
73808+ GR_PROCACCT = 0x00000800,
73809+ GR_RELAXPTRACE = 0x00001000,
73810+ //GR_NESTED = 0x00002000,
73811+ GR_INHERITLEARN = 0x00004000,
73812+ GR_PROCFIND = 0x00008000,
73813+ GR_POVERRIDE = 0x00010000,
73814+ GR_KERNELAUTH = 0x00020000,
73815+ GR_ATSECURE = 0x00040000,
73816+ GR_SHMEXEC = 0x00080000
73817+};
73818+
73819+enum {
73820+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
73821+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
73822+ GR_PAX_ENABLE_MPROTECT = 0x0004,
73823+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
73824+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
73825+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
73826+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
73827+ GR_PAX_DISABLE_MPROTECT = 0x0400,
73828+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
73829+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
73830+};
73831+
73832+enum {
73833+ GR_ID_USER = 0x01,
73834+ GR_ID_GROUP = 0x02,
73835+};
73836+
73837+enum {
73838+ GR_ID_ALLOW = 0x01,
73839+ GR_ID_DENY = 0x02,
73840+};
73841+
73842+#define GR_CRASH_RES 31
73843+#define GR_UIDTABLE_MAX 500
73844+
73845+/* begin resource learning section */
73846+enum {
73847+ GR_RLIM_CPU_BUMP = 60,
73848+ GR_RLIM_FSIZE_BUMP = 50000,
73849+ GR_RLIM_DATA_BUMP = 10000,
73850+ GR_RLIM_STACK_BUMP = 1000,
73851+ GR_RLIM_CORE_BUMP = 10000,
73852+ GR_RLIM_RSS_BUMP = 500000,
73853+ GR_RLIM_NPROC_BUMP = 1,
73854+ GR_RLIM_NOFILE_BUMP = 5,
73855+ GR_RLIM_MEMLOCK_BUMP = 50000,
73856+ GR_RLIM_AS_BUMP = 500000,
73857+ GR_RLIM_LOCKS_BUMP = 2,
73858+ GR_RLIM_SIGPENDING_BUMP = 5,
73859+ GR_RLIM_MSGQUEUE_BUMP = 10000,
73860+ GR_RLIM_NICE_BUMP = 1,
73861+ GR_RLIM_RTPRIO_BUMP = 1,
73862+ GR_RLIM_RTTIME_BUMP = 1000000
73863+};
73864+
73865+#endif
73866diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
73867new file mode 100644
73868index 0000000..e337683
73869--- /dev/null
73870+++ b/include/linux/grinternal.h
73871@@ -0,0 +1,229 @@
73872+#ifndef __GRINTERNAL_H
73873+#define __GRINTERNAL_H
73874+
73875+#ifdef CONFIG_GRKERNSEC
73876+
73877+#include <linux/fs.h>
73878+#include <linux/mnt_namespace.h>
73879+#include <linux/nsproxy.h>
73880+#include <linux/gracl.h>
73881+#include <linux/grdefs.h>
73882+#include <linux/grmsg.h>
73883+
73884+void gr_add_learn_entry(const char *fmt, ...)
73885+ __attribute__ ((format (printf, 1, 2)));
73886+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
73887+ const struct vfsmount *mnt);
73888+__u32 gr_check_create(const struct dentry *new_dentry,
73889+ const struct dentry *parent,
73890+ const struct vfsmount *mnt, const __u32 mode);
73891+int gr_check_protected_task(const struct task_struct *task);
73892+__u32 to_gr_audit(const __u32 reqmode);
73893+int gr_set_acls(const int type);
73894+int gr_apply_subject_to_task(struct task_struct *task);
73895+int gr_acl_is_enabled(void);
73896+char gr_roletype_to_char(void);
73897+
73898+void gr_handle_alertkill(struct task_struct *task);
73899+char *gr_to_filename(const struct dentry *dentry,
73900+ const struct vfsmount *mnt);
73901+char *gr_to_filename1(const struct dentry *dentry,
73902+ const struct vfsmount *mnt);
73903+char *gr_to_filename2(const struct dentry *dentry,
73904+ const struct vfsmount *mnt);
73905+char *gr_to_filename3(const struct dentry *dentry,
73906+ const struct vfsmount *mnt);
73907+
73908+extern int grsec_enable_ptrace_readexec;
73909+extern int grsec_enable_harden_ptrace;
73910+extern int grsec_enable_link;
73911+extern int grsec_enable_fifo;
73912+extern int grsec_enable_execve;
73913+extern int grsec_enable_shm;
73914+extern int grsec_enable_execlog;
73915+extern int grsec_enable_signal;
73916+extern int grsec_enable_audit_ptrace;
73917+extern int grsec_enable_forkfail;
73918+extern int grsec_enable_time;
73919+extern int grsec_enable_rofs;
73920+extern int grsec_deny_new_usb;
73921+extern int grsec_enable_chroot_shmat;
73922+extern int grsec_enable_chroot_mount;
73923+extern int grsec_enable_chroot_double;
73924+extern int grsec_enable_chroot_pivot;
73925+extern int grsec_enable_chroot_chdir;
73926+extern int grsec_enable_chroot_chmod;
73927+extern int grsec_enable_chroot_mknod;
73928+extern int grsec_enable_chroot_fchdir;
73929+extern int grsec_enable_chroot_nice;
73930+extern int grsec_enable_chroot_execlog;
73931+extern int grsec_enable_chroot_caps;
73932+extern int grsec_enable_chroot_sysctl;
73933+extern int grsec_enable_chroot_unix;
73934+extern int grsec_enable_symlinkown;
73935+extern kgid_t grsec_symlinkown_gid;
73936+extern int grsec_enable_tpe;
73937+extern kgid_t grsec_tpe_gid;
73938+extern int grsec_enable_tpe_all;
73939+extern int grsec_enable_tpe_invert;
73940+extern int grsec_enable_socket_all;
73941+extern kgid_t grsec_socket_all_gid;
73942+extern int grsec_enable_socket_client;
73943+extern kgid_t grsec_socket_client_gid;
73944+extern int grsec_enable_socket_server;
73945+extern kgid_t grsec_socket_server_gid;
73946+extern kgid_t grsec_audit_gid;
73947+extern int grsec_enable_group;
73948+extern int grsec_enable_log_rwxmaps;
73949+extern int grsec_enable_mount;
73950+extern int grsec_enable_chdir;
73951+extern int grsec_resource_logging;
73952+extern int grsec_enable_blackhole;
73953+extern int grsec_lastack_retries;
73954+extern int grsec_enable_brute;
73955+extern int grsec_lock;
73956+
73957+extern spinlock_t grsec_alert_lock;
73958+extern unsigned long grsec_alert_wtime;
73959+extern unsigned long grsec_alert_fyet;
73960+
73961+extern spinlock_t grsec_audit_lock;
73962+
73963+extern rwlock_t grsec_exec_file_lock;
73964+
73965+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
73966+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
73967+ (tsk)->exec_file->f_path.mnt) : "/")
73968+
73969+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
73970+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
73971+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
73972+
73973+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
73974+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
73975+ (tsk)->exec_file->f_path.mnt) : "/")
73976+
73977+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
73978+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
73979+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
73980+
73981+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
73982+
73983+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
73984+
73985+static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
73986+{
73987+ if (file1 && file2) {
73988+ const struct inode *inode1 = file1->f_path.dentry->d_inode;
73989+ const struct inode *inode2 = file2->f_path.dentry->d_inode;
73990+ if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
73991+ return true;
73992+ }
73993+
73994+ return false;
73995+}
73996+
73997+#define GR_CHROOT_CAPS {{ \
73998+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
73999+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
74000+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
74001+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
74002+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
74003+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
74004+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
74005+
74006+#define security_learn(normal_msg,args...) \
74007+({ \
74008+ read_lock(&grsec_exec_file_lock); \
74009+ gr_add_learn_entry(normal_msg "\n", ## args); \
74010+ read_unlock(&grsec_exec_file_lock); \
74011+})
74012+
74013+enum {
74014+ GR_DO_AUDIT,
74015+ GR_DONT_AUDIT,
74016+ /* used for non-audit messages that we shouldn't kill the task on */
74017+ GR_DONT_AUDIT_GOOD
74018+};
74019+
74020+enum {
74021+ GR_TTYSNIFF,
74022+ GR_RBAC,
74023+ GR_RBAC_STR,
74024+ GR_STR_RBAC,
74025+ GR_RBAC_MODE2,
74026+ GR_RBAC_MODE3,
74027+ GR_FILENAME,
74028+ GR_SYSCTL_HIDDEN,
74029+ GR_NOARGS,
74030+ GR_ONE_INT,
74031+ GR_ONE_INT_TWO_STR,
74032+ GR_ONE_STR,
74033+ GR_STR_INT,
74034+ GR_TWO_STR_INT,
74035+ GR_TWO_INT,
74036+ GR_TWO_U64,
74037+ GR_THREE_INT,
74038+ GR_FIVE_INT_TWO_STR,
74039+ GR_TWO_STR,
74040+ GR_THREE_STR,
74041+ GR_FOUR_STR,
74042+ GR_STR_FILENAME,
74043+ GR_FILENAME_STR,
74044+ GR_FILENAME_TWO_INT,
74045+ GR_FILENAME_TWO_INT_STR,
74046+ GR_TEXTREL,
74047+ GR_PTRACE,
74048+ GR_RESOURCE,
74049+ GR_CAP,
74050+ GR_SIG,
74051+ GR_SIG2,
74052+ GR_CRASH1,
74053+ GR_CRASH2,
74054+ GR_PSACCT,
74055+ GR_RWXMAP,
74056+ GR_RWXMAPVMA
74057+};
74058+
74059+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
74060+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
74061+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
74062+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
74063+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
74064+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
74065+#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)
74066+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
74067+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
74068+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
74069+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
74070+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
74071+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
74072+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
74073+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
74074+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
74075+#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)
74076+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
74077+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
74078+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
74079+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
74080+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
74081+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
74082+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
74083+#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)
74084+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
74085+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
74086+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
74087+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
74088+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
74089+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
74090+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
74091+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
74092+#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)
74093+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
74094+#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
74095+
74096+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
74097+
74098+#endif
74099+
74100+#endif
74101diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
74102new file mode 100644
74103index 0000000..a4396b5
74104--- /dev/null
74105+++ b/include/linux/grmsg.h
74106@@ -0,0 +1,113 @@
74107+#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"
74108+#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"
74109+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
74110+#define GR_STOPMOD_MSG "denied modification of module state by "
74111+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
74112+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
74113+#define GR_IOPERM_MSG "denied use of ioperm() by "
74114+#define GR_IOPL_MSG "denied use of iopl() by "
74115+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
74116+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
74117+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
74118+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
74119+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
74120+#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"
74121+#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"
74122+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
74123+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
74124+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
74125+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
74126+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
74127+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
74128+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
74129+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
74130+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
74131+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
74132+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
74133+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
74134+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
74135+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
74136+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
74137+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
74138+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
74139+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
74140+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
74141+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
74142+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
74143+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
74144+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
74145+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
74146+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
74147+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
74148+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
74149+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
74150+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
74151+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
74152+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
74153+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
74154+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
74155+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
74156+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
74157+#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"
74158+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
74159+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
74160+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
74161+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
74162+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
74163+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
74164+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
74165+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
74166+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
74167+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
74168+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
74169+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
74170+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
74171+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
74172+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
74173+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
74174+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
74175+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
74176+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
74177+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
74178+#define GR_FAILFORK_MSG "failed fork with errno %s by "
74179+#define GR_NICE_CHROOT_MSG "denied priority change by "
74180+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
74181+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
74182+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
74183+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
74184+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
74185+#define GR_TIME_MSG "time set by "
74186+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
74187+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
74188+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
74189+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
74190+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
74191+#define GR_BIND_MSG "denied bind() by "
74192+#define GR_CONNECT_MSG "denied connect() by "
74193+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
74194+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
74195+#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"
74196+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
74197+#define GR_CAP_ACL_MSG "use of %s denied for "
74198+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
74199+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
74200+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
74201+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
74202+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
74203+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
74204+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
74205+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
74206+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
74207+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
74208+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
74209+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
74210+#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
74211+#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
74212+#define GR_VM86_MSG "denied use of vm86 by "
74213+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
74214+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
74215+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
74216+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
74217+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
74218+#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 "
74219+#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 "
74220diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
74221new file mode 100644
74222index 0000000..d6f5a21
74223--- /dev/null
74224+++ b/include/linux/grsecurity.h
74225@@ -0,0 +1,244 @@
74226+#ifndef GR_SECURITY_H
74227+#define GR_SECURITY_H
74228+#include <linux/fs.h>
74229+#include <linux/fs_struct.h>
74230+#include <linux/binfmts.h>
74231+#include <linux/gracl.h>
74232+
74233+/* notify of brain-dead configs */
74234+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
74235+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
74236+#endif
74237+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
74238+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
74239+#endif
74240+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
74241+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
74242+#endif
74243+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
74244+#error "CONFIG_PAX enabled, but no PaX options are enabled."
74245+#endif
74246+
74247+int gr_handle_new_usb(void);
74248+
74249+void gr_handle_brute_attach(unsigned long mm_flags);
74250+void gr_handle_brute_check(void);
74251+void gr_handle_kernel_exploit(void);
74252+
74253+char gr_roletype_to_char(void);
74254+
74255+int gr_acl_enable_at_secure(void);
74256+
74257+int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
74258+int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
74259+
74260+void gr_del_task_from_ip_table(struct task_struct *p);
74261+
74262+int gr_pid_is_chrooted(struct task_struct *p);
74263+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
74264+int gr_handle_chroot_nice(void);
74265+int gr_handle_chroot_sysctl(const int op);
74266+int gr_handle_chroot_setpriority(struct task_struct *p,
74267+ const int niceval);
74268+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
74269+int gr_handle_chroot_chroot(const struct dentry *dentry,
74270+ const struct vfsmount *mnt);
74271+void gr_handle_chroot_chdir(const struct path *path);
74272+int gr_handle_chroot_chmod(const struct dentry *dentry,
74273+ const struct vfsmount *mnt, const int mode);
74274+int gr_handle_chroot_mknod(const struct dentry *dentry,
74275+ const struct vfsmount *mnt, const int mode);
74276+int gr_handle_chroot_mount(const struct dentry *dentry,
74277+ const struct vfsmount *mnt,
74278+ const char *dev_name);
74279+int gr_handle_chroot_pivot(void);
74280+int gr_handle_chroot_unix(const pid_t pid);
74281+
74282+int gr_handle_rawio(const struct inode *inode);
74283+
74284+void gr_handle_ioperm(void);
74285+void gr_handle_iopl(void);
74286+
74287+umode_t gr_acl_umask(void);
74288+
74289+int gr_tpe_allow(const struct file *file);
74290+
74291+void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
74292+void gr_clear_chroot_entries(struct task_struct *task);
74293+
74294+void gr_log_forkfail(const int retval);
74295+void gr_log_timechange(void);
74296+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
74297+void gr_log_chdir(const struct dentry *dentry,
74298+ const struct vfsmount *mnt);
74299+void gr_log_chroot_exec(const struct dentry *dentry,
74300+ const struct vfsmount *mnt);
74301+void gr_log_remount(const char *devname, const int retval);
74302+void gr_log_unmount(const char *devname, const int retval);
74303+void gr_log_mount(const char *from, const char *to, const int retval);
74304+void gr_log_textrel(struct vm_area_struct *vma);
74305+void gr_log_ptgnustack(struct file *file);
74306+void gr_log_rwxmmap(struct file *file);
74307+void gr_log_rwxmprotect(struct vm_area_struct *vma);
74308+
74309+int gr_handle_follow_link(const struct inode *parent,
74310+ const struct inode *inode,
74311+ const struct dentry *dentry,
74312+ const struct vfsmount *mnt);
74313+int gr_handle_fifo(const struct dentry *dentry,
74314+ const struct vfsmount *mnt,
74315+ const struct dentry *dir, const int flag,
74316+ const int acc_mode);
74317+int gr_handle_hardlink(const struct dentry *dentry,
74318+ const struct vfsmount *mnt,
74319+ struct inode *inode,
74320+ const int mode, const struct filename *to);
74321+
74322+int gr_is_capable(const int cap);
74323+int gr_is_capable_nolog(const int cap);
74324+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
74325+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
74326+
74327+void gr_copy_label(struct task_struct *tsk);
74328+void gr_handle_crash(struct task_struct *task, const int sig);
74329+int gr_handle_signal(const struct task_struct *p, const int sig);
74330+int gr_check_crash_uid(const kuid_t uid);
74331+int gr_check_protected_task(const struct task_struct *task);
74332+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
74333+int gr_acl_handle_mmap(const struct file *file,
74334+ const unsigned long prot);
74335+int gr_acl_handle_mprotect(const struct file *file,
74336+ const unsigned long prot);
74337+int gr_check_hidden_task(const struct task_struct *tsk);
74338+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
74339+ const struct vfsmount *mnt);
74340+__u32 gr_acl_handle_utime(const struct dentry *dentry,
74341+ const struct vfsmount *mnt);
74342+__u32 gr_acl_handle_access(const struct dentry *dentry,
74343+ const struct vfsmount *mnt, const int fmode);
74344+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
74345+ const struct vfsmount *mnt, umode_t *mode);
74346+__u32 gr_acl_handle_chown(const struct dentry *dentry,
74347+ const struct vfsmount *mnt);
74348+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
74349+ const struct vfsmount *mnt);
74350+int gr_handle_ptrace(struct task_struct *task, const long request);
74351+int gr_handle_proc_ptrace(struct task_struct *task);
74352+__u32 gr_acl_handle_execve(const struct dentry *dentry,
74353+ const struct vfsmount *mnt);
74354+int gr_check_crash_exec(const struct file *filp);
74355+int gr_acl_is_enabled(void);
74356+void gr_set_kernel_label(struct task_struct *task);
74357+void gr_set_role_label(struct task_struct *task, const kuid_t uid,
74358+ const kgid_t gid);
74359+int gr_set_proc_label(const struct dentry *dentry,
74360+ const struct vfsmount *mnt,
74361+ const int unsafe_flags);
74362+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
74363+ const struct vfsmount *mnt);
74364+__u32 gr_acl_handle_open(const struct dentry *dentry,
74365+ const struct vfsmount *mnt, int acc_mode);
74366+__u32 gr_acl_handle_creat(const struct dentry *dentry,
74367+ const struct dentry *p_dentry,
74368+ const struct vfsmount *p_mnt,
74369+ int open_flags, int acc_mode, const int imode);
74370+void gr_handle_create(const struct dentry *dentry,
74371+ const struct vfsmount *mnt);
74372+void gr_handle_proc_create(const struct dentry *dentry,
74373+ const struct inode *inode);
74374+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
74375+ const struct dentry *parent_dentry,
74376+ const struct vfsmount *parent_mnt,
74377+ const int mode);
74378+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
74379+ const struct dentry *parent_dentry,
74380+ const struct vfsmount *parent_mnt);
74381+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
74382+ const struct vfsmount *mnt);
74383+void gr_handle_delete(const ino_t ino, const dev_t dev);
74384+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
74385+ const struct vfsmount *mnt);
74386+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
74387+ const struct dentry *parent_dentry,
74388+ const struct vfsmount *parent_mnt,
74389+ const struct filename *from);
74390+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
74391+ const struct dentry *parent_dentry,
74392+ const struct vfsmount *parent_mnt,
74393+ const struct dentry *old_dentry,
74394+ const struct vfsmount *old_mnt, const struct filename *to);
74395+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
74396+int gr_acl_handle_rename(struct dentry *new_dentry,
74397+ struct dentry *parent_dentry,
74398+ const struct vfsmount *parent_mnt,
74399+ struct dentry *old_dentry,
74400+ struct inode *old_parent_inode,
74401+ struct vfsmount *old_mnt, const struct filename *newname);
74402+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
74403+ struct dentry *old_dentry,
74404+ struct dentry *new_dentry,
74405+ struct vfsmount *mnt, const __u8 replace);
74406+__u32 gr_check_link(const struct dentry *new_dentry,
74407+ const struct dentry *parent_dentry,
74408+ const struct vfsmount *parent_mnt,
74409+ const struct dentry *old_dentry,
74410+ const struct vfsmount *old_mnt);
74411+int gr_acl_handle_filldir(const struct file *file, const char *name,
74412+ const unsigned int namelen, const ino_t ino);
74413+
74414+__u32 gr_acl_handle_unix(const struct dentry *dentry,
74415+ const struct vfsmount *mnt);
74416+void gr_acl_handle_exit(void);
74417+void gr_acl_handle_psacct(struct task_struct *task, const long code);
74418+int gr_acl_handle_procpidmem(const struct task_struct *task);
74419+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
74420+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
74421+void gr_audit_ptrace(struct task_struct *task);
74422+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
74423+void gr_put_exec_file(struct task_struct *task);
74424+
74425+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
74426+
74427+#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
74428+extern void gr_learn_resource(const struct task_struct *task, const int res,
74429+ const unsigned long wanted, const int gt);
74430+#else
74431+static inline void gr_learn_resource(const struct task_struct *task, const int res,
74432+ const unsigned long wanted, const int gt)
74433+{
74434+}
74435+#endif
74436+
74437+#ifdef CONFIG_GRKERNSEC_RESLOG
74438+extern void gr_log_resource(const struct task_struct *task, const int res,
74439+ const unsigned long wanted, const int gt);
74440+#else
74441+static inline void gr_log_resource(const struct task_struct *task, const int res,
74442+ const unsigned long wanted, const int gt)
74443+{
74444+}
74445+#endif
74446+
74447+#ifdef CONFIG_GRKERNSEC
74448+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
74449+void gr_handle_vm86(void);
74450+void gr_handle_mem_readwrite(u64 from, u64 to);
74451+
74452+void gr_log_badprocpid(const char *entry);
74453+
74454+extern int grsec_enable_dmesg;
74455+extern int grsec_disable_privio;
74456+
74457+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
74458+extern kgid_t grsec_proc_gid;
74459+#endif
74460+
74461+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
74462+extern int grsec_enable_chroot_findtask;
74463+#endif
74464+#ifdef CONFIG_GRKERNSEC_SETXID
74465+extern int grsec_enable_setxid;
74466+#endif
74467+#endif
74468+
74469+#endif
74470diff --git a/include/linux/grsock.h b/include/linux/grsock.h
74471new file mode 100644
74472index 0000000..e7ffaaf
74473--- /dev/null
74474+++ b/include/linux/grsock.h
74475@@ -0,0 +1,19 @@
74476+#ifndef __GRSOCK_H
74477+#define __GRSOCK_H
74478+
74479+extern void gr_attach_curr_ip(const struct sock *sk);
74480+extern int gr_handle_sock_all(const int family, const int type,
74481+ const int protocol);
74482+extern int gr_handle_sock_server(const struct sockaddr *sck);
74483+extern int gr_handle_sock_server_other(const struct sock *sck);
74484+extern int gr_handle_sock_client(const struct sockaddr *sck);
74485+extern int gr_search_connect(struct socket * sock,
74486+ struct sockaddr_in * addr);
74487+extern int gr_search_bind(struct socket * sock,
74488+ struct sockaddr_in * addr);
74489+extern int gr_search_listen(struct socket * sock);
74490+extern int gr_search_accept(struct socket * sock);
74491+extern int gr_search_socket(const int domain, const int type,
74492+ const int protocol);
74493+
74494+#endif
74495diff --git a/include/linux/hid.h b/include/linux/hid.h
74496index 0c48991..76e41d8 100644
74497--- a/include/linux/hid.h
74498+++ b/include/linux/hid.h
74499@@ -393,10 +393,12 @@ struct hid_report {
74500 struct hid_device *device; /* associated device */
74501 };
74502
74503+#define HID_MAX_IDS 256
74504+
74505 struct hid_report_enum {
74506 unsigned numbered;
74507 struct list_head report_list;
74508- struct hid_report *report_id_hash[256];
74509+ struct hid_report *report_id_hash[HID_MAX_IDS];
74510 };
74511
74512 #define HID_REPORT_TYPES 3
74513@@ -747,6 +749,10 @@ void hid_output_report(struct hid_report *report, __u8 *data);
74514 struct hid_device *hid_allocate_device(void);
74515 struct hid_report *hid_register_report(struct hid_device *device, unsigned type, unsigned id);
74516 int hid_parse_report(struct hid_device *hid, __u8 *start, unsigned size);
74517+struct hid_report *hid_validate_report(struct hid_device *hid,
74518+ unsigned int type, unsigned int id,
74519+ unsigned int fields,
74520+ unsigned int report_counts);
74521 int hid_open_report(struct hid_device *device);
74522 int hid_check_keys_pressed(struct hid_device *hid);
74523 int hid_connect(struct hid_device *hid, unsigned int connect_mask);
74524diff --git a/include/linux/highmem.h b/include/linux/highmem.h
74525index 7fb31da..08b5114 100644
74526--- a/include/linux/highmem.h
74527+++ b/include/linux/highmem.h
74528@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
74529 kunmap_atomic(kaddr);
74530 }
74531
74532+static inline void sanitize_highpage(struct page *page)
74533+{
74534+ void *kaddr;
74535+ unsigned long flags;
74536+
74537+ local_irq_save(flags);
74538+ kaddr = kmap_atomic(page);
74539+ clear_page(kaddr);
74540+ kunmap_atomic(kaddr);
74541+ local_irq_restore(flags);
74542+}
74543+
74544 static inline void zero_user_segments(struct page *page,
74545 unsigned start1, unsigned end1,
74546 unsigned start2, unsigned end2)
74547diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
74548index 1c7b89a..7f52502 100644
74549--- a/include/linux/hwmon-sysfs.h
74550+++ b/include/linux/hwmon-sysfs.h
74551@@ -25,7 +25,8 @@
74552 struct sensor_device_attribute{
74553 struct device_attribute dev_attr;
74554 int index;
74555-};
74556+} __do_const;
74557+typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
74558 #define to_sensor_dev_attr(_dev_attr) \
74559 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
74560
74561@@ -41,7 +42,7 @@ struct sensor_device_attribute_2 {
74562 struct device_attribute dev_attr;
74563 u8 index;
74564 u8 nr;
74565-};
74566+} __do_const;
74567 #define to_sensor_dev_attr_2(_dev_attr) \
74568 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
74569
74570diff --git a/include/linux/i2c.h b/include/linux/i2c.h
74571index e988fa9..ff9f17e 100644
74572--- a/include/linux/i2c.h
74573+++ b/include/linux/i2c.h
74574@@ -366,6 +366,7 @@ struct i2c_algorithm {
74575 /* To determine what the adapter supports */
74576 u32 (*functionality) (struct i2c_adapter *);
74577 };
74578+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
74579
74580 /**
74581 * struct i2c_bus_recovery_info - I2C bus recovery information
74582diff --git a/include/linux/i2o.h b/include/linux/i2o.h
74583index d23c3c2..eb63c81 100644
74584--- a/include/linux/i2o.h
74585+++ b/include/linux/i2o.h
74586@@ -565,7 +565,7 @@ struct i2o_controller {
74587 struct i2o_device *exec; /* Executive */
74588 #if BITS_PER_LONG == 64
74589 spinlock_t context_list_lock; /* lock for context_list */
74590- atomic_t context_list_counter; /* needed for unique contexts */
74591+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
74592 struct list_head context_list; /* list of context id's
74593 and pointers */
74594 #endif
74595diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
74596index aff7ad8..3942bbd 100644
74597--- a/include/linux/if_pppox.h
74598+++ b/include/linux/if_pppox.h
74599@@ -76,7 +76,7 @@ struct pppox_proto {
74600 int (*ioctl)(struct socket *sock, unsigned int cmd,
74601 unsigned long arg);
74602 struct module *owner;
74603-};
74604+} __do_const;
74605
74606 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
74607 extern void unregister_pppox_proto(int proto_num);
74608diff --git a/include/linux/init.h b/include/linux/init.h
74609index e73f2b7..cc996e0 100644
74610--- a/include/linux/init.h
74611+++ b/include/linux/init.h
74612@@ -39,9 +39,17 @@
74613 * Also note, that this data cannot be "const".
74614 */
74615
74616+#define add_init_latent_entropy __latent_entropy
74617+
74618+#ifdef CONFIG_MEMORY_HOTPLUG
74619+#define add_meminit_latent_entropy
74620+#else
74621+#define add_meminit_latent_entropy __latent_entropy
74622+#endif
74623+
74624 /* These are for everybody (although not all archs will actually
74625 discard it in modules) */
74626-#define __init __section(.init.text) __cold notrace
74627+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
74628 #define __initdata __section(.init.data)
74629 #define __initconst __constsection(.init.rodata)
74630 #define __exitdata __section(.exit.data)
74631@@ -102,7 +110,7 @@
74632 #define __cpuexitconst
74633
74634 /* Used for MEMORY_HOTPLUG */
74635-#define __meminit __section(.meminit.text) __cold notrace
74636+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
74637 #define __meminitdata __section(.meminit.data)
74638 #define __meminitconst __constsection(.meminit.rodata)
74639 #define __memexit __section(.memexit.text) __exitused __cold notrace
74640diff --git a/include/linux/init_task.h b/include/linux/init_task.h
74641index 5cd0f09..c9f67cc 100644
74642--- a/include/linux/init_task.h
74643+++ b/include/linux/init_task.h
74644@@ -154,6 +154,12 @@ extern struct task_group root_task_group;
74645
74646 #define INIT_TASK_COMM "swapper"
74647
74648+#ifdef CONFIG_X86
74649+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
74650+#else
74651+#define INIT_TASK_THREAD_INFO
74652+#endif
74653+
74654 /*
74655 * INIT_TASK is used to set up the first task table, touch at
74656 * your own risk!. Base=0, limit=0x1fffff (=2MB)
74657@@ -193,6 +199,7 @@ extern struct task_group root_task_group;
74658 RCU_POINTER_INITIALIZER(cred, &init_cred), \
74659 .comm = INIT_TASK_COMM, \
74660 .thread = INIT_THREAD, \
74661+ INIT_TASK_THREAD_INFO \
74662 .fs = &init_fs, \
74663 .files = &init_files, \
74664 .signal = &init_signals, \
74665diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
74666index 5fa5afe..ac55b25 100644
74667--- a/include/linux/interrupt.h
74668+++ b/include/linux/interrupt.h
74669@@ -430,7 +430,7 @@ enum
74670 /* map softirq index to softirq name. update 'softirq_to_name' in
74671 * kernel/softirq.c when adding a new softirq.
74672 */
74673-extern char *softirq_to_name[NR_SOFTIRQS];
74674+extern const char * const softirq_to_name[NR_SOFTIRQS];
74675
74676 /* softirq mask and active fields moved to irq_cpustat_t in
74677 * asm/hardirq.h to get better cache usage. KAO
74678@@ -438,12 +438,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
74679
74680 struct softirq_action
74681 {
74682- void (*action)(struct softirq_action *);
74683-};
74684+ void (*action)(void);
74685+} __no_const;
74686
74687 asmlinkage void do_softirq(void);
74688 asmlinkage void __do_softirq(void);
74689-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
74690+extern void open_softirq(int nr, void (*action)(void));
74691 extern void softirq_init(void);
74692 extern void __raise_softirq_irqoff(unsigned int nr);
74693
74694diff --git a/include/linux/iommu.h b/include/linux/iommu.h
74695index 3aeb730..2177f39 100644
74696--- a/include/linux/iommu.h
74697+++ b/include/linux/iommu.h
74698@@ -113,7 +113,7 @@ struct iommu_ops {
74699 u32 (*domain_get_windows)(struct iommu_domain *domain);
74700
74701 unsigned long pgsize_bitmap;
74702-};
74703+} __do_const;
74704
74705 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
74706 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
74707diff --git a/include/linux/ioport.h b/include/linux/ioport.h
74708index 89b7c24..382af74 100644
74709--- a/include/linux/ioport.h
74710+++ b/include/linux/ioport.h
74711@@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
74712 int adjust_resource(struct resource *res, resource_size_t start,
74713 resource_size_t size);
74714 resource_size_t resource_alignment(struct resource *res);
74715-static inline resource_size_t resource_size(const struct resource *res)
74716+static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
74717 {
74718 return res->end - res->start + 1;
74719 }
74720diff --git a/include/linux/irq.h b/include/linux/irq.h
74721index f04d3ba..bcf2cfb 100644
74722--- a/include/linux/irq.h
74723+++ b/include/linux/irq.h
74724@@ -333,7 +333,8 @@ struct irq_chip {
74725 void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
74726
74727 unsigned long flags;
74728-};
74729+} __do_const;
74730+typedef struct irq_chip __no_const irq_chip_no_const;
74731
74732 /*
74733 * irq_chip specific flags
74734diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
74735index 3e203eb..3fe68d0 100644
74736--- a/include/linux/irqchip/arm-gic.h
74737+++ b/include/linux/irqchip/arm-gic.h
74738@@ -59,9 +59,11 @@
74739
74740 #ifndef __ASSEMBLY__
74741
74742+#include <linux/irq.h>
74743+
74744 struct device_node;
74745
74746-extern struct irq_chip gic_arch_extn;
74747+extern irq_chip_no_const gic_arch_extn;
74748
74749 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
74750 u32 offset, struct device_node *);
74751diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
74752index 6883e19..e854fcb 100644
74753--- a/include/linux/kallsyms.h
74754+++ b/include/linux/kallsyms.h
74755@@ -15,7 +15,8 @@
74756
74757 struct module;
74758
74759-#ifdef CONFIG_KALLSYMS
74760+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
74761+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
74762 /* Lookup the address for a symbol. Returns 0 if not found. */
74763 unsigned long kallsyms_lookup_name(const char *name);
74764
74765@@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
74766 /* Stupid that this does nothing, but I didn't create this mess. */
74767 #define __print_symbol(fmt, addr)
74768 #endif /*CONFIG_KALLSYMS*/
74769+#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
74770+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
74771+extern unsigned long kallsyms_lookup_name(const char *name);
74772+extern void __print_symbol(const char *fmt, unsigned long address);
74773+extern int sprint_backtrace(char *buffer, unsigned long address);
74774+extern int sprint_symbol(char *buffer, unsigned long address);
74775+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
74776+const char *kallsyms_lookup(unsigned long addr,
74777+ unsigned long *symbolsize,
74778+ unsigned long *offset,
74779+ char **modname, char *namebuf);
74780+extern int kallsyms_lookup_size_offset(unsigned long addr,
74781+ unsigned long *symbolsize,
74782+ unsigned long *offset);
74783+#endif
74784
74785 /* This macro allows us to keep printk typechecking */
74786 static __printf(1, 2)
74787diff --git a/include/linux/key-type.h b/include/linux/key-type.h
74788index 518a53a..5e28358 100644
74789--- a/include/linux/key-type.h
74790+++ b/include/linux/key-type.h
74791@@ -125,7 +125,7 @@ struct key_type {
74792 /* internal fields */
74793 struct list_head link; /* link in types list */
74794 struct lock_class_key lock_class; /* key->sem lock class */
74795-};
74796+} __do_const;
74797
74798 extern struct key_type key_type_keyring;
74799
74800diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
74801index c6e091b..a940adf 100644
74802--- a/include/linux/kgdb.h
74803+++ b/include/linux/kgdb.h
74804@@ -52,7 +52,7 @@ extern int kgdb_connected;
74805 extern int kgdb_io_module_registered;
74806
74807 extern atomic_t kgdb_setting_breakpoint;
74808-extern atomic_t kgdb_cpu_doing_single_step;
74809+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
74810
74811 extern struct task_struct *kgdb_usethread;
74812 extern struct task_struct *kgdb_contthread;
74813@@ -254,7 +254,7 @@ struct kgdb_arch {
74814 void (*correct_hw_break)(void);
74815
74816 void (*enable_nmi)(bool on);
74817-};
74818+} __do_const;
74819
74820 /**
74821 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
74822@@ -279,7 +279,7 @@ struct kgdb_io {
74823 void (*pre_exception) (void);
74824 void (*post_exception) (void);
74825 int is_console;
74826-};
74827+} __do_const;
74828
74829 extern struct kgdb_arch arch_kgdb_ops;
74830
74831diff --git a/include/linux/kmod.h b/include/linux/kmod.h
74832index 0555cc6..b16a7a4 100644
74833--- a/include/linux/kmod.h
74834+++ b/include/linux/kmod.h
74835@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
74836 * usually useless though. */
74837 extern __printf(2, 3)
74838 int __request_module(bool wait, const char *name, ...);
74839+extern __printf(3, 4)
74840+int ___request_module(bool wait, char *param_name, const char *name, ...);
74841 #define request_module(mod...) __request_module(true, mod)
74842 #define request_module_nowait(mod...) __request_module(false, mod)
74843 #define try_then_request_module(x, mod...) \
74844diff --git a/include/linux/kobject.h b/include/linux/kobject.h
74845index 939b112..ed6ed51 100644
74846--- a/include/linux/kobject.h
74847+++ b/include/linux/kobject.h
74848@@ -111,7 +111,7 @@ struct kobj_type {
74849 struct attribute **default_attrs;
74850 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
74851 const void *(*namespace)(struct kobject *kobj);
74852-};
74853+} __do_const;
74854
74855 struct kobj_uevent_env {
74856 char *envp[UEVENT_NUM_ENVP];
74857@@ -134,6 +134,7 @@ struct kobj_attribute {
74858 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
74859 const char *buf, size_t count);
74860 };
74861+typedef struct kobj_attribute __no_const kobj_attribute_no_const;
74862
74863 extern const struct sysfs_ops kobj_sysfs_ops;
74864
74865diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
74866index f66b065..c2c29b4 100644
74867--- a/include/linux/kobject_ns.h
74868+++ b/include/linux/kobject_ns.h
74869@@ -43,7 +43,7 @@ struct kobj_ns_type_operations {
74870 const void *(*netlink_ns)(struct sock *sk);
74871 const void *(*initial_ns)(void);
74872 void (*drop_ns)(void *);
74873-};
74874+} __do_const;
74875
74876 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
74877 int kobj_ns_type_registered(enum kobj_ns_type type);
74878diff --git a/include/linux/kref.h b/include/linux/kref.h
74879index 484604d..0f6c5b6 100644
74880--- a/include/linux/kref.h
74881+++ b/include/linux/kref.h
74882@@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
74883 static inline int kref_sub(struct kref *kref, unsigned int count,
74884 void (*release)(struct kref *kref))
74885 {
74886- WARN_ON(release == NULL);
74887+ BUG_ON(release == NULL);
74888
74889 if (atomic_sub_and_test((int) count, &kref->refcount)) {
74890 release(kref);
74891diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
74892index a63d83e..77fd685 100644
74893--- a/include/linux/kvm_host.h
74894+++ b/include/linux/kvm_host.h
74895@@ -446,7 +446,7 @@ static inline void kvm_irqfd_exit(void)
74896 {
74897 }
74898 #endif
74899-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
74900+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
74901 struct module *module);
74902 void kvm_exit(void);
74903
74904@@ -618,7 +618,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
74905 struct kvm_guest_debug *dbg);
74906 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
74907
74908-int kvm_arch_init(void *opaque);
74909+int kvm_arch_init(const void *opaque);
74910 void kvm_arch_exit(void);
74911
74912 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
74913diff --git a/include/linux/libata.h b/include/linux/libata.h
74914index 4ea55bb..dcd2601 100644
74915--- a/include/linux/libata.h
74916+++ b/include/linux/libata.h
74917@@ -924,7 +924,7 @@ struct ata_port_operations {
74918 * fields must be pointers.
74919 */
74920 const struct ata_port_operations *inherits;
74921-};
74922+} __do_const;
74923
74924 struct ata_port_info {
74925 unsigned long flags;
74926diff --git a/include/linux/linkage.h b/include/linux/linkage.h
74927index d3e8ad2..a949f68 100644
74928--- a/include/linux/linkage.h
74929+++ b/include/linux/linkage.h
74930@@ -31,6 +31,7 @@
74931 #endif
74932
74933 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
74934+#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
74935 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
74936
74937 /*
74938diff --git a/include/linux/list.h b/include/linux/list.h
74939index f4d8a2f..38e6e46 100644
74940--- a/include/linux/list.h
74941+++ b/include/linux/list.h
74942@@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
74943 extern void list_del(struct list_head *entry);
74944 #endif
74945
74946+extern void __pax_list_add(struct list_head *new,
74947+ struct list_head *prev,
74948+ struct list_head *next);
74949+static inline void pax_list_add(struct list_head *new, struct list_head *head)
74950+{
74951+ __pax_list_add(new, head, head->next);
74952+}
74953+static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
74954+{
74955+ __pax_list_add(new, head->prev, head);
74956+}
74957+extern void pax_list_del(struct list_head *entry);
74958+
74959 /**
74960 * list_replace - replace old entry by new one
74961 * @old : the element to be replaced
74962@@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
74963 INIT_LIST_HEAD(entry);
74964 }
74965
74966+extern void pax_list_del_init(struct list_head *entry);
74967+
74968 /**
74969 * list_move - delete from one list and add as another's head
74970 * @list: the entry to move
74971diff --git a/include/linux/math64.h b/include/linux/math64.h
74972index 2913b86..8dcbb1e 100644
74973--- a/include/linux/math64.h
74974+++ b/include/linux/math64.h
74975@@ -15,7 +15,7 @@
74976 * This is commonly provided by 32bit archs to provide an optimized 64bit
74977 * divide.
74978 */
74979-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
74980+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
74981 {
74982 *remainder = dividend % divisor;
74983 return dividend / divisor;
74984@@ -33,7 +33,7 @@ static inline s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
74985 /**
74986 * div64_u64 - unsigned 64bit divide with 64bit divisor
74987 */
74988-static inline u64 div64_u64(u64 dividend, u64 divisor)
74989+static inline u64 __intentional_overflow(0) div64_u64(u64 dividend, u64 divisor)
74990 {
74991 return dividend / divisor;
74992 }
74993@@ -52,7 +52,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
74994 #define div64_ul(x, y) div_u64((x), (y))
74995
74996 #ifndef div_u64_rem
74997-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
74998+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
74999 {
75000 *remainder = do_div(dividend, divisor);
75001 return dividend;
75002@@ -81,7 +81,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
75003 * divide.
75004 */
75005 #ifndef div_u64
75006-static inline u64 div_u64(u64 dividend, u32 divisor)
75007+static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
75008 {
75009 u32 remainder;
75010 return div_u64_rem(dividend, divisor, &remainder);
75011diff --git a/include/linux/mm.h b/include/linux/mm.h
75012index f022460..6ecf4f9 100644
75013--- a/include/linux/mm.h
75014+++ b/include/linux/mm.h
75015@@ -113,6 +113,11 @@ extern unsigned int kobjsize(const void *objp);
75016 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
75017 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
75018 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
75019+
75020+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
75021+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
75022+#endif
75023+
75024 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
75025
75026 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
75027@@ -208,8 +213,8 @@ struct vm_operations_struct {
75028 /* called by access_process_vm when get_user_pages() fails, typically
75029 * for use by special VMAs that can switch between memory and hardware
75030 */
75031- int (*access)(struct vm_area_struct *vma, unsigned long addr,
75032- void *buf, int len, int write);
75033+ ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
75034+ void *buf, size_t len, int write);
75035 #ifdef CONFIG_NUMA
75036 /*
75037 * set_policy() op must add a reference to any non-NULL @new mempolicy
75038@@ -239,6 +244,7 @@ struct vm_operations_struct {
75039 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
75040 unsigned long size, pgoff_t pgoff);
75041 };
75042+typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
75043
75044 struct mmu_gather;
75045 struct inode;
75046@@ -983,8 +989,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
75047 unsigned long *pfn);
75048 int follow_phys(struct vm_area_struct *vma, unsigned long address,
75049 unsigned int flags, unsigned long *prot, resource_size_t *phys);
75050-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
75051- void *buf, int len, int write);
75052+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
75053+ void *buf, size_t len, int write);
75054
75055 static inline void unmap_shared_mapping_range(struct address_space *mapping,
75056 loff_t const holebegin, loff_t const holelen)
75057@@ -1023,9 +1029,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
75058 }
75059 #endif
75060
75061-extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
75062-extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
75063- void *buf, int len, int write);
75064+extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
75065+extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
75066+ void *buf, size_t len, int write);
75067
75068 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
75069 unsigned long start, unsigned long nr_pages,
75070@@ -1057,34 +1063,6 @@ int set_page_dirty(struct page *page);
75071 int set_page_dirty_lock(struct page *page);
75072 int clear_page_dirty_for_io(struct page *page);
75073
75074-/* Is the vma a continuation of the stack vma above it? */
75075-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
75076-{
75077- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
75078-}
75079-
75080-static inline int stack_guard_page_start(struct vm_area_struct *vma,
75081- unsigned long addr)
75082-{
75083- return (vma->vm_flags & VM_GROWSDOWN) &&
75084- (vma->vm_start == addr) &&
75085- !vma_growsdown(vma->vm_prev, addr);
75086-}
75087-
75088-/* Is the vma a continuation of the stack vma below it? */
75089-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
75090-{
75091- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
75092-}
75093-
75094-static inline int stack_guard_page_end(struct vm_area_struct *vma,
75095- unsigned long addr)
75096-{
75097- return (vma->vm_flags & VM_GROWSUP) &&
75098- (vma->vm_end == addr) &&
75099- !vma_growsup(vma->vm_next, addr);
75100-}
75101-
75102 extern pid_t
75103 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
75104
75105@@ -1184,6 +1162,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
75106 }
75107 #endif
75108
75109+#ifdef CONFIG_MMU
75110+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
75111+#else
75112+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
75113+{
75114+ return __pgprot(0);
75115+}
75116+#endif
75117+
75118 int vma_wants_writenotify(struct vm_area_struct *vma);
75119
75120 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
75121@@ -1202,8 +1189,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
75122 {
75123 return 0;
75124 }
75125+
75126+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
75127+ unsigned long address)
75128+{
75129+ return 0;
75130+}
75131 #else
75132 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
75133+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
75134 #endif
75135
75136 #ifdef __PAGETABLE_PMD_FOLDED
75137@@ -1212,8 +1206,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
75138 {
75139 return 0;
75140 }
75141+
75142+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
75143+ unsigned long address)
75144+{
75145+ return 0;
75146+}
75147 #else
75148 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
75149+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
75150 #endif
75151
75152 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
75153@@ -1231,11 +1232,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
75154 NULL: pud_offset(pgd, address);
75155 }
75156
75157+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
75158+{
75159+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
75160+ NULL: pud_offset(pgd, address);
75161+}
75162+
75163 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
75164 {
75165 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
75166 NULL: pmd_offset(pud, address);
75167 }
75168+
75169+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
75170+{
75171+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
75172+ NULL: pmd_offset(pud, address);
75173+}
75174 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
75175
75176 #if USE_SPLIT_PTLOCKS
75177@@ -1531,6 +1544,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
75178 unsigned long len, unsigned long prot, unsigned long flags,
75179 unsigned long pgoff, unsigned long *populate);
75180 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
75181+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
75182
75183 #ifdef CONFIG_MMU
75184 extern int __mm_populate(unsigned long addr, unsigned long len,
75185@@ -1559,10 +1573,11 @@ struct vm_unmapped_area_info {
75186 unsigned long high_limit;
75187 unsigned long align_mask;
75188 unsigned long align_offset;
75189+ unsigned long threadstack_offset;
75190 };
75191
75192-extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
75193-extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
75194+extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
75195+extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
75196
75197 /*
75198 * Search for an unmapped address range.
75199@@ -1574,7 +1589,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
75200 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
75201 */
75202 static inline unsigned long
75203-vm_unmapped_area(struct vm_unmapped_area_info *info)
75204+vm_unmapped_area(const struct vm_unmapped_area_info *info)
75205 {
75206 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
75207 return unmapped_area(info);
75208@@ -1637,6 +1652,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
75209 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
75210 struct vm_area_struct **pprev);
75211
75212+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
75213+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
75214+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
75215+
75216 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
75217 NULL if none. Assume start_addr < end_addr. */
75218 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
75219@@ -1665,15 +1684,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
75220 return vma;
75221 }
75222
75223-#ifdef CONFIG_MMU
75224-pgprot_t vm_get_page_prot(unsigned long vm_flags);
75225-#else
75226-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
75227-{
75228- return __pgprot(0);
75229-}
75230-#endif
75231-
75232 #ifdef CONFIG_ARCH_USES_NUMA_PROT_NONE
75233 unsigned long change_prot_numa(struct vm_area_struct *vma,
75234 unsigned long start, unsigned long end);
75235@@ -1725,6 +1735,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
75236 static inline void vm_stat_account(struct mm_struct *mm,
75237 unsigned long flags, struct file *file, long pages)
75238 {
75239+
75240+#ifdef CONFIG_PAX_RANDMMAP
75241+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
75242+#endif
75243+
75244 mm->total_vm += pages;
75245 }
75246 #endif /* CONFIG_PROC_FS */
75247@@ -1805,7 +1820,7 @@ extern int unpoison_memory(unsigned long pfn);
75248 extern int sysctl_memory_failure_early_kill;
75249 extern int sysctl_memory_failure_recovery;
75250 extern void shake_page(struct page *p, int access);
75251-extern atomic_long_t num_poisoned_pages;
75252+extern atomic_long_unchecked_t num_poisoned_pages;
75253 extern int soft_offline_page(struct page *page, int flags);
75254
75255 extern void dump_page(struct page *page);
75256@@ -1842,5 +1857,11 @@ void __init setup_nr_node_ids(void);
75257 static inline void setup_nr_node_ids(void) {}
75258 #endif
75259
75260+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
75261+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
75262+#else
75263+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
75264+#endif
75265+
75266 #endif /* __KERNEL__ */
75267 #endif /* _LINUX_MM_H */
75268diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
75269index faf4b7c..1e70c6e 100644
75270--- a/include/linux/mm_types.h
75271+++ b/include/linux/mm_types.h
75272@@ -289,6 +289,8 @@ struct vm_area_struct {
75273 #ifdef CONFIG_NUMA
75274 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
75275 #endif
75276+
75277+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
75278 };
75279
75280 struct core_thread {
75281@@ -435,6 +437,24 @@ struct mm_struct {
75282 int first_nid;
75283 #endif
75284 struct uprobes_state uprobes_state;
75285+
75286+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
75287+ unsigned long pax_flags;
75288+#endif
75289+
75290+#ifdef CONFIG_PAX_DLRESOLVE
75291+ unsigned long call_dl_resolve;
75292+#endif
75293+
75294+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
75295+ unsigned long call_syscall;
75296+#endif
75297+
75298+#ifdef CONFIG_PAX_ASLR
75299+ unsigned long delta_mmap; /* randomized offset */
75300+ unsigned long delta_stack; /* randomized offset */
75301+#endif
75302+
75303 };
75304
75305 /* first nid will either be a valid NID or one of these values */
75306diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
75307index c5d5278..f0b68c8 100644
75308--- a/include/linux/mmiotrace.h
75309+++ b/include/linux/mmiotrace.h
75310@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
75311 /* Called from ioremap.c */
75312 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
75313 void __iomem *addr);
75314-extern void mmiotrace_iounmap(volatile void __iomem *addr);
75315+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
75316
75317 /* For anyone to insert markers. Remember trailing newline. */
75318 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
75319@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
75320 {
75321 }
75322
75323-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
75324+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
75325 {
75326 }
75327
75328diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
75329index af4a3b7..9ad8889 100644
75330--- a/include/linux/mmzone.h
75331+++ b/include/linux/mmzone.h
75332@@ -396,7 +396,7 @@ struct zone {
75333 unsigned long flags; /* zone flags, see below */
75334
75335 /* Zone statistics */
75336- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
75337+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
75338
75339 /*
75340 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
75341diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
75342index 45e9214..a7227d6 100644
75343--- a/include/linux/mod_devicetable.h
75344+++ b/include/linux/mod_devicetable.h
75345@@ -13,7 +13,7 @@
75346 typedef unsigned long kernel_ulong_t;
75347 #endif
75348
75349-#define PCI_ANY_ID (~0)
75350+#define PCI_ANY_ID ((__u16)~0)
75351
75352 struct pci_device_id {
75353 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
75354@@ -139,7 +139,7 @@ struct usb_device_id {
75355 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
75356 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
75357
75358-#define HID_ANY_ID (~0)
75359+#define HID_ANY_ID (~0U)
75360 #define HID_BUS_ANY 0xffff
75361 #define HID_GROUP_ANY 0x0000
75362
75363@@ -467,7 +467,7 @@ struct dmi_system_id {
75364 const char *ident;
75365 struct dmi_strmatch matches[4];
75366 void *driver_data;
75367-};
75368+} __do_const;
75369 /*
75370 * struct dmi_device_id appears during expansion of
75371 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
75372diff --git a/include/linux/module.h b/include/linux/module.h
75373index 46f1ea0..a34ca37 100644
75374--- a/include/linux/module.h
75375+++ b/include/linux/module.h
75376@@ -17,9 +17,11 @@
75377 #include <linux/moduleparam.h>
75378 #include <linux/tracepoint.h>
75379 #include <linux/export.h>
75380+#include <linux/fs.h>
75381
75382 #include <linux/percpu.h>
75383 #include <asm/module.h>
75384+#include <asm/pgtable.h>
75385
75386 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
75387 #define MODULE_SIG_STRING "~Module signature appended~\n"
75388@@ -54,12 +56,13 @@ struct module_attribute {
75389 int (*test)(struct module *);
75390 void (*free)(struct module *);
75391 };
75392+typedef struct module_attribute __no_const module_attribute_no_const;
75393
75394 struct module_version_attribute {
75395 struct module_attribute mattr;
75396 const char *module_name;
75397 const char *version;
75398-} __attribute__ ((__aligned__(sizeof(void *))));
75399+} __do_const __attribute__ ((__aligned__(sizeof(void *))));
75400
75401 extern ssize_t __modver_version_show(struct module_attribute *,
75402 struct module_kobject *, char *);
75403@@ -232,7 +235,7 @@ struct module
75404
75405 /* Sysfs stuff. */
75406 struct module_kobject mkobj;
75407- struct module_attribute *modinfo_attrs;
75408+ module_attribute_no_const *modinfo_attrs;
75409 const char *version;
75410 const char *srcversion;
75411 struct kobject *holders_dir;
75412@@ -281,19 +284,16 @@ struct module
75413 int (*init)(void);
75414
75415 /* If this is non-NULL, vfree after init() returns */
75416- void *module_init;
75417+ void *module_init_rx, *module_init_rw;
75418
75419 /* Here is the actual code + data, vfree'd on unload. */
75420- void *module_core;
75421+ void *module_core_rx, *module_core_rw;
75422
75423 /* Here are the sizes of the init and core sections */
75424- unsigned int init_size, core_size;
75425+ unsigned int init_size_rw, core_size_rw;
75426
75427 /* The size of the executable code in each section. */
75428- unsigned int init_text_size, core_text_size;
75429-
75430- /* Size of RO sections of the module (text+rodata) */
75431- unsigned int init_ro_size, core_ro_size;
75432+ unsigned int init_size_rx, core_size_rx;
75433
75434 /* Arch-specific module values */
75435 struct mod_arch_specific arch;
75436@@ -349,6 +349,10 @@ struct module
75437 #ifdef CONFIG_EVENT_TRACING
75438 struct ftrace_event_call **trace_events;
75439 unsigned int num_trace_events;
75440+ struct file_operations trace_id;
75441+ struct file_operations trace_enable;
75442+ struct file_operations trace_format;
75443+ struct file_operations trace_filter;
75444 #endif
75445 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
75446 unsigned int num_ftrace_callsites;
75447@@ -396,16 +400,46 @@ bool is_module_address(unsigned long addr);
75448 bool is_module_percpu_address(unsigned long addr);
75449 bool is_module_text_address(unsigned long addr);
75450
75451+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
75452+{
75453+
75454+#ifdef CONFIG_PAX_KERNEXEC
75455+ if (ktla_ktva(addr) >= (unsigned long)start &&
75456+ ktla_ktva(addr) < (unsigned long)start + size)
75457+ return 1;
75458+#endif
75459+
75460+ return ((void *)addr >= start && (void *)addr < start + size);
75461+}
75462+
75463+static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
75464+{
75465+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
75466+}
75467+
75468+static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
75469+{
75470+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
75471+}
75472+
75473+static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
75474+{
75475+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
75476+}
75477+
75478+static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
75479+{
75480+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
75481+}
75482+
75483 static inline int within_module_core(unsigned long addr, const struct module *mod)
75484 {
75485- return (unsigned long)mod->module_core <= addr &&
75486- addr < (unsigned long)mod->module_core + mod->core_size;
75487+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
75488 }
75489
75490 static inline int within_module_init(unsigned long addr, const struct module *mod)
75491 {
75492- return (unsigned long)mod->module_init <= addr &&
75493- addr < (unsigned long)mod->module_init + mod->init_size;
75494+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
75495 }
75496
75497 /* Search for module by name: must hold module_mutex. */
75498diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
75499index 560ca53..ef621ef 100644
75500--- a/include/linux/moduleloader.h
75501+++ b/include/linux/moduleloader.h
75502@@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
75503 sections. Returns NULL on failure. */
75504 void *module_alloc(unsigned long size);
75505
75506+#ifdef CONFIG_PAX_KERNEXEC
75507+void *module_alloc_exec(unsigned long size);
75508+#else
75509+#define module_alloc_exec(x) module_alloc(x)
75510+#endif
75511+
75512 /* Free memory returned from module_alloc. */
75513 void module_free(struct module *mod, void *module_region);
75514
75515+#ifdef CONFIG_PAX_KERNEXEC
75516+void module_free_exec(struct module *mod, void *module_region);
75517+#else
75518+#define module_free_exec(x, y) module_free((x), (y))
75519+#endif
75520+
75521 /*
75522 * Apply the given relocation to the (simplified) ELF. Return -error
75523 * or 0.
75524@@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
75525 unsigned int relsec,
75526 struct module *me)
75527 {
75528+#ifdef CONFIG_MODULES
75529 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
75530+#endif
75531 return -ENOEXEC;
75532 }
75533 #endif
75534@@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
75535 unsigned int relsec,
75536 struct module *me)
75537 {
75538+#ifdef CONFIG_MODULES
75539 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
75540+#endif
75541 return -ENOEXEC;
75542 }
75543 #endif
75544diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
75545index 27d9da3..5d94aa3 100644
75546--- a/include/linux/moduleparam.h
75547+++ b/include/linux/moduleparam.h
75548@@ -284,7 +284,7 @@ static inline void __kernel_param_unlock(void)
75549 * @len is usually just sizeof(string).
75550 */
75551 #define module_param_string(name, string, len, perm) \
75552- static const struct kparam_string __param_string_##name \
75553+ static const struct kparam_string __param_string_##name __used \
75554 = { len, string }; \
75555 __module_param_call(MODULE_PARAM_PREFIX, name, \
75556 &param_ops_string, \
75557@@ -423,7 +423,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
75558 */
75559 #define module_param_array_named(name, array, type, nump, perm) \
75560 param_check_##type(name, &(array)[0]); \
75561- static const struct kparam_array __param_arr_##name \
75562+ static const struct kparam_array __param_arr_##name __used \
75563 = { .max = ARRAY_SIZE(array), .num = nump, \
75564 .ops = &param_ops_##type, \
75565 .elemsize = sizeof(array[0]), .elem = array }; \
75566diff --git a/include/linux/namei.h b/include/linux/namei.h
75567index 5a5ff57..5ae5070 100644
75568--- a/include/linux/namei.h
75569+++ b/include/linux/namei.h
75570@@ -19,7 +19,7 @@ struct nameidata {
75571 unsigned seq;
75572 int last_type;
75573 unsigned depth;
75574- char *saved_names[MAX_NESTED_LINKS + 1];
75575+ const char *saved_names[MAX_NESTED_LINKS + 1];
75576 };
75577
75578 /*
75579@@ -84,12 +84,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
75580
75581 extern void nd_jump_link(struct nameidata *nd, struct path *path);
75582
75583-static inline void nd_set_link(struct nameidata *nd, char *path)
75584+static inline void nd_set_link(struct nameidata *nd, const char *path)
75585 {
75586 nd->saved_names[nd->depth] = path;
75587 }
75588
75589-static inline char *nd_get_link(struct nameidata *nd)
75590+static inline const char *nd_get_link(const struct nameidata *nd)
75591 {
75592 return nd->saved_names[nd->depth];
75593 }
75594diff --git a/include/linux/net.h b/include/linux/net.h
75595index 4f27575..fc8a65f 100644
75596--- a/include/linux/net.h
75597+++ b/include/linux/net.h
75598@@ -183,7 +183,7 @@ struct net_proto_family {
75599 int (*create)(struct net *net, struct socket *sock,
75600 int protocol, int kern);
75601 struct module *owner;
75602-};
75603+} __do_const;
75604
75605 struct iovec;
75606 struct kvec;
75607diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
75608index 9a41568..203d903 100644
75609--- a/include/linux/netdevice.h
75610+++ b/include/linux/netdevice.h
75611@@ -1061,6 +1061,7 @@ struct net_device_ops {
75612 int (*ndo_change_carrier)(struct net_device *dev,
75613 bool new_carrier);
75614 };
75615+typedef struct net_device_ops __no_const net_device_ops_no_const;
75616
75617 /*
75618 * The DEVICE structure.
75619@@ -1131,7 +1132,7 @@ struct net_device {
75620 int iflink;
75621
75622 struct net_device_stats stats;
75623- atomic_long_t rx_dropped; /* dropped packets by core network
75624+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
75625 * Do not use this in drivers.
75626 */
75627
75628diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
75629index de70f7b..2675e91 100644
75630--- a/include/linux/netfilter.h
75631+++ b/include/linux/netfilter.h
75632@@ -82,7 +82,7 @@ struct nf_sockopt_ops {
75633 #endif
75634 /* Use the module struct to lock set/get code in place */
75635 struct module *owner;
75636-};
75637+} __do_const;
75638
75639 /* Function to register/unregister hook points. */
75640 int nf_register_hook(struct nf_hook_ops *reg);
75641diff --git a/include/linux/netfilter/ipset/ip_set.h b/include/linux/netfilter/ipset/ip_set.h
75642index d80e275..c3510b8 100644
75643--- a/include/linux/netfilter/ipset/ip_set.h
75644+++ b/include/linux/netfilter/ipset/ip_set.h
75645@@ -124,7 +124,7 @@ struct ip_set_type_variant {
75646 /* Return true if "b" set is the same as "a"
75647 * according to the create set parameters */
75648 bool (*same_set)(const struct ip_set *a, const struct ip_set *b);
75649-};
75650+} __do_const;
75651
75652 /* The core set type structure */
75653 struct ip_set_type {
75654diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
75655index cadb740..d7c37c0 100644
75656--- a/include/linux/netfilter/nfnetlink.h
75657+++ b/include/linux/netfilter/nfnetlink.h
75658@@ -16,7 +16,7 @@ struct nfnl_callback {
75659 const struct nlattr * const cda[]);
75660 const struct nla_policy *policy; /* netlink attribute policy */
75661 const u_int16_t attr_count; /* number of nlattr's */
75662-};
75663+} __do_const;
75664
75665 struct nfnetlink_subsystem {
75666 const char *name;
75667diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
75668new file mode 100644
75669index 0000000..33f4af8
75670--- /dev/null
75671+++ b/include/linux/netfilter/xt_gradm.h
75672@@ -0,0 +1,9 @@
75673+#ifndef _LINUX_NETFILTER_XT_GRADM_H
75674+#define _LINUX_NETFILTER_XT_GRADM_H 1
75675+
75676+struct xt_gradm_mtinfo {
75677+ __u16 flags;
75678+ __u16 invflags;
75679+};
75680+
75681+#endif
75682diff --git a/include/linux/nls.h b/include/linux/nls.h
75683index 5dc635f..35f5e11 100644
75684--- a/include/linux/nls.h
75685+++ b/include/linux/nls.h
75686@@ -31,7 +31,7 @@ struct nls_table {
75687 const unsigned char *charset2upper;
75688 struct module *owner;
75689 struct nls_table *next;
75690-};
75691+} __do_const;
75692
75693 /* this value hold the maximum octet of charset */
75694 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
75695diff --git a/include/linux/notifier.h b/include/linux/notifier.h
75696index d14a4c3..a078786 100644
75697--- a/include/linux/notifier.h
75698+++ b/include/linux/notifier.h
75699@@ -54,7 +54,8 @@ struct notifier_block {
75700 notifier_fn_t notifier_call;
75701 struct notifier_block __rcu *next;
75702 int priority;
75703-};
75704+} __do_const;
75705+typedef struct notifier_block __no_const notifier_block_no_const;
75706
75707 struct atomic_notifier_head {
75708 spinlock_t lock;
75709diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
75710index a4c5624..79d6d88 100644
75711--- a/include/linux/oprofile.h
75712+++ b/include/linux/oprofile.h
75713@@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
75714 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
75715 char const * name, ulong * val);
75716
75717-/** Create a file for read-only access to an atomic_t. */
75718+/** Create a file for read-only access to an atomic_unchecked_t. */
75719 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
75720- char const * name, atomic_t * val);
75721+ char const * name, atomic_unchecked_t * val);
75722
75723 /** create a directory */
75724 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
75725diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
75726index 8db71dc..a76bf2c 100644
75727--- a/include/linux/pci_hotplug.h
75728+++ b/include/linux/pci_hotplug.h
75729@@ -80,7 +80,8 @@ struct hotplug_slot_ops {
75730 int (*get_attention_status) (struct hotplug_slot *slot, u8 *value);
75731 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
75732 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
75733-};
75734+} __do_const;
75735+typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
75736
75737 /**
75738 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
75739diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
75740index c43f6ea..2d4416f 100644
75741--- a/include/linux/perf_event.h
75742+++ b/include/linux/perf_event.h
75743@@ -328,8 +328,8 @@ struct perf_event {
75744
75745 enum perf_event_active_state state;
75746 unsigned int attach_state;
75747- local64_t count;
75748- atomic64_t child_count;
75749+ local64_t count; /* PaX: fix it one day */
75750+ atomic64_unchecked_t child_count;
75751
75752 /*
75753 * These are the total time in nanoseconds that the event
75754@@ -380,8 +380,8 @@ struct perf_event {
75755 * These accumulate total time (in nanoseconds) that children
75756 * events have been enabled and running, respectively.
75757 */
75758- atomic64_t child_total_time_enabled;
75759- atomic64_t child_total_time_running;
75760+ atomic64_unchecked_t child_total_time_enabled;
75761+ atomic64_unchecked_t child_total_time_running;
75762
75763 /*
75764 * Protect attach/detach and child_list:
75765@@ -703,7 +703,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
75766 entry->ip[entry->nr++] = ip;
75767 }
75768
75769-extern int sysctl_perf_event_paranoid;
75770+extern int sysctl_perf_event_legitimately_concerned;
75771 extern int sysctl_perf_event_mlock;
75772 extern int sysctl_perf_event_sample_rate;
75773 extern int sysctl_perf_cpu_time_max_percent;
75774@@ -718,19 +718,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
75775 loff_t *ppos);
75776
75777
75778+static inline bool perf_paranoid_any(void)
75779+{
75780+ return sysctl_perf_event_legitimately_concerned > 2;
75781+}
75782+
75783 static inline bool perf_paranoid_tracepoint_raw(void)
75784 {
75785- return sysctl_perf_event_paranoid > -1;
75786+ return sysctl_perf_event_legitimately_concerned > -1;
75787 }
75788
75789 static inline bool perf_paranoid_cpu(void)
75790 {
75791- return sysctl_perf_event_paranoid > 0;
75792+ return sysctl_perf_event_legitimately_concerned > 0;
75793 }
75794
75795 static inline bool perf_paranoid_kernel(void)
75796 {
75797- return sysctl_perf_event_paranoid > 1;
75798+ return sysctl_perf_event_legitimately_concerned > 1;
75799 }
75800
75801 extern void perf_event_init(void);
75802@@ -846,7 +851,7 @@ struct perf_pmu_events_attr {
75803 struct device_attribute attr;
75804 u64 id;
75805 const char *event_str;
75806-};
75807+} __do_const;
75808
75809 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
75810 static struct perf_pmu_events_attr _var = { \
75811diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
75812index b8809fe..ae4ccd0 100644
75813--- a/include/linux/pipe_fs_i.h
75814+++ b/include/linux/pipe_fs_i.h
75815@@ -47,10 +47,10 @@ struct pipe_inode_info {
75816 struct mutex mutex;
75817 wait_queue_head_t wait;
75818 unsigned int nrbufs, curbuf, buffers;
75819- unsigned int readers;
75820- unsigned int writers;
75821- unsigned int files;
75822- unsigned int waiting_writers;
75823+ atomic_t readers;
75824+ atomic_t writers;
75825+ atomic_t files;
75826+ atomic_t waiting_writers;
75827 unsigned int r_counter;
75828 unsigned int w_counter;
75829 struct page *tmp_page;
75830diff --git a/include/linux/platform_data/usb-ehci-s5p.h b/include/linux/platform_data/usb-ehci-s5p.h
75831index 5f28cae..3d23723 100644
75832--- a/include/linux/platform_data/usb-ehci-s5p.h
75833+++ b/include/linux/platform_data/usb-ehci-s5p.h
75834@@ -14,7 +14,7 @@
75835 struct s5p_ehci_platdata {
75836 int (*phy_init)(struct platform_device *pdev, int type);
75837 int (*phy_exit)(struct platform_device *pdev, int type);
75838-};
75839+} __no_const;
75840
75841 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
75842
75843diff --git a/include/linux/platform_data/usb-ohci-exynos.h b/include/linux/platform_data/usb-ohci-exynos.h
75844index c256c59..8ea94c7 100644
75845--- a/include/linux/platform_data/usb-ohci-exynos.h
75846+++ b/include/linux/platform_data/usb-ohci-exynos.h
75847@@ -14,7 +14,7 @@
75848 struct exynos4_ohci_platdata {
75849 int (*phy_init)(struct platform_device *pdev, int type);
75850 int (*phy_exit)(struct platform_device *pdev, int type);
75851-};
75852+} __no_const;
75853
75854 extern void exynos4_ohci_set_platdata(struct exynos4_ohci_platdata *pd);
75855
75856diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
75857index 7c1d252..c5c773e 100644
75858--- a/include/linux/pm_domain.h
75859+++ b/include/linux/pm_domain.h
75860@@ -48,7 +48,7 @@ struct gpd_dev_ops {
75861
75862 struct gpd_cpu_data {
75863 unsigned int saved_exit_latency;
75864- struct cpuidle_state *idle_state;
75865+ cpuidle_state_no_const *idle_state;
75866 };
75867
75868 struct generic_pm_domain {
75869diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
75870index 6fa7cea..7bf6415 100644
75871--- a/include/linux/pm_runtime.h
75872+++ b/include/linux/pm_runtime.h
75873@@ -103,7 +103,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
75874
75875 static inline void pm_runtime_mark_last_busy(struct device *dev)
75876 {
75877- ACCESS_ONCE(dev->power.last_busy) = jiffies;
75878+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
75879 }
75880
75881 #else /* !CONFIG_PM_RUNTIME */
75882diff --git a/include/linux/pnp.h b/include/linux/pnp.h
75883index 195aafc..49a7bc2 100644
75884--- a/include/linux/pnp.h
75885+++ b/include/linux/pnp.h
75886@@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
75887 struct pnp_fixup {
75888 char id[7];
75889 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
75890-};
75891+} __do_const;
75892
75893 /* config parameters */
75894 #define PNP_CONFIG_NORMAL 0x0001
75895diff --git a/include/linux/poison.h b/include/linux/poison.h
75896index 2110a81..13a11bb 100644
75897--- a/include/linux/poison.h
75898+++ b/include/linux/poison.h
75899@@ -19,8 +19,8 @@
75900 * under normal circumstances, used to verify that nobody uses
75901 * non-initialized list entries.
75902 */
75903-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
75904-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
75905+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
75906+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
75907
75908 /********** include/linux/timer.h **********/
75909 /*
75910diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
75911index d8b187c3..9a9257a 100644
75912--- a/include/linux/power/smartreflex.h
75913+++ b/include/linux/power/smartreflex.h
75914@@ -238,7 +238,7 @@ struct omap_sr_class_data {
75915 int (*notify)(struct omap_sr *sr, u32 status);
75916 u8 notify_flags;
75917 u8 class_type;
75918-};
75919+} __do_const;
75920
75921 /**
75922 * struct omap_sr_nvalue_table - Smartreflex n-target value info
75923diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
75924index 4ea1d37..80f4b33 100644
75925--- a/include/linux/ppp-comp.h
75926+++ b/include/linux/ppp-comp.h
75927@@ -84,7 +84,7 @@ struct compressor {
75928 struct module *owner;
75929 /* Extra skb space needed by the compressor algorithm */
75930 unsigned int comp_extra;
75931-};
75932+} __do_const;
75933
75934 /*
75935 * The return value from decompress routine is the length of the
75936diff --git a/include/linux/preempt.h b/include/linux/preempt.h
75937index f5d4723..a6ea2fa 100644
75938--- a/include/linux/preempt.h
75939+++ b/include/linux/preempt.h
75940@@ -18,8 +18,13 @@
75941 # define sub_preempt_count(val) do { preempt_count() -= (val); } while (0)
75942 #endif
75943
75944+#define raw_add_preempt_count(val) do { preempt_count() += (val); } while (0)
75945+#define raw_sub_preempt_count(val) do { preempt_count() -= (val); } while (0)
75946+
75947 #define inc_preempt_count() add_preempt_count(1)
75948+#define raw_inc_preempt_count() raw_add_preempt_count(1)
75949 #define dec_preempt_count() sub_preempt_count(1)
75950+#define raw_dec_preempt_count() raw_sub_preempt_count(1)
75951
75952 #define preempt_count() (current_thread_info()->preempt_count)
75953
75954@@ -64,6 +69,12 @@ do { \
75955 barrier(); \
75956 } while (0)
75957
75958+#define raw_preempt_disable() \
75959+do { \
75960+ raw_inc_preempt_count(); \
75961+ barrier(); \
75962+} while (0)
75963+
75964 #define sched_preempt_enable_no_resched() \
75965 do { \
75966 barrier(); \
75967@@ -72,6 +83,12 @@ do { \
75968
75969 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
75970
75971+#define raw_preempt_enable_no_resched() \
75972+do { \
75973+ barrier(); \
75974+ raw_dec_preempt_count(); \
75975+} while (0)
75976+
75977 #define preempt_enable() \
75978 do { \
75979 preempt_enable_no_resched(); \
75980@@ -116,8 +133,10 @@ do { \
75981 * region.
75982 */
75983 #define preempt_disable() barrier()
75984+#define raw_preempt_disable() barrier()
75985 #define sched_preempt_enable_no_resched() barrier()
75986 #define preempt_enable_no_resched() barrier()
75987+#define raw_preempt_enable_no_resched() barrier()
75988 #define preempt_enable() barrier()
75989
75990 #define preempt_disable_notrace() barrier()
75991diff --git a/include/linux/printk.h b/include/linux/printk.h
75992index 22c7052..ad3fa0a 100644
75993--- a/include/linux/printk.h
75994+++ b/include/linux/printk.h
75995@@ -106,6 +106,8 @@ static inline __printf(1, 2) __cold
75996 void early_printk(const char *s, ...) { }
75997 #endif
75998
75999+extern int kptr_restrict;
76000+
76001 #ifdef CONFIG_PRINTK
76002 asmlinkage __printf(5, 0)
76003 int vprintk_emit(int facility, int level,
76004@@ -140,7 +142,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
76005
76006 extern int printk_delay_msec;
76007 extern int dmesg_restrict;
76008-extern int kptr_restrict;
76009
76010 extern void wake_up_klogd(void);
76011
76012diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
76013index 608e60a..c26f864 100644
76014--- a/include/linux/proc_fs.h
76015+++ b/include/linux/proc_fs.h
76016@@ -34,6 +34,19 @@ static inline struct proc_dir_entry *proc_create(
76017 return proc_create_data(name, mode, parent, proc_fops, NULL);
76018 }
76019
76020+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
76021+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
76022+{
76023+#ifdef CONFIG_GRKERNSEC_PROC_USER
76024+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
76025+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
76026+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
76027+#else
76028+ return proc_create_data(name, mode, parent, proc_fops, NULL);
76029+#endif
76030+}
76031+
76032+
76033 extern void proc_set_size(struct proc_dir_entry *, loff_t);
76034 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
76035 extern void *PDE_DATA(const struct inode *);
76036diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
76037index 34a1e10..03a6d03 100644
76038--- a/include/linux/proc_ns.h
76039+++ b/include/linux/proc_ns.h
76040@@ -14,7 +14,7 @@ struct proc_ns_operations {
76041 void (*put)(void *ns);
76042 int (*install)(struct nsproxy *nsproxy, void *ns);
76043 unsigned int (*inum)(void *ns);
76044-};
76045+} __do_const;
76046
76047 struct proc_ns {
76048 void *ns;
76049diff --git a/include/linux/random.h b/include/linux/random.h
76050index 3b9377d..943ad4a 100644
76051--- a/include/linux/random.h
76052+++ b/include/linux/random.h
76053@@ -10,6 +10,16 @@
76054
76055
76056 extern void add_device_randomness(const void *, unsigned int);
76057+
76058+static inline void add_latent_entropy(void)
76059+{
76060+
76061+#ifdef LATENT_ENTROPY_PLUGIN
76062+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
76063+#endif
76064+
76065+}
76066+
76067 extern void add_input_randomness(unsigned int type, unsigned int code,
76068 unsigned int value);
76069 extern void add_interrupt_randomness(int irq, int irq_flags);
76070@@ -32,6 +42,11 @@ void prandom_seed(u32 seed);
76071 u32 prandom_u32_state(struct rnd_state *);
76072 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
76073
76074+static inline unsigned long pax_get_random_long(void)
76075+{
76076+ return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
76077+}
76078+
76079 /*
76080 * Handle minimum values for seeds
76081 */
76082diff --git a/include/linux/rculist.h b/include/linux/rculist.h
76083index f4b1001..8ddb2b6 100644
76084--- a/include/linux/rculist.h
76085+++ b/include/linux/rculist.h
76086@@ -44,6 +44,9 @@ extern void __list_add_rcu(struct list_head *new,
76087 struct list_head *prev, struct list_head *next);
76088 #endif
76089
76090+extern void __pax_list_add_rcu(struct list_head *new,
76091+ struct list_head *prev, struct list_head *next);
76092+
76093 /**
76094 * list_add_rcu - add a new entry to rcu-protected list
76095 * @new: new entry to be added
76096@@ -65,6 +68,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
76097 __list_add_rcu(new, head, head->next);
76098 }
76099
76100+static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
76101+{
76102+ __pax_list_add_rcu(new, head, head->next);
76103+}
76104+
76105 /**
76106 * list_add_tail_rcu - add a new entry to rcu-protected list
76107 * @new: new entry to be added
76108@@ -87,6 +95,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
76109 __list_add_rcu(new, head->prev, head);
76110 }
76111
76112+static inline void pax_list_add_tail_rcu(struct list_head *new,
76113+ struct list_head *head)
76114+{
76115+ __pax_list_add_rcu(new, head->prev, head);
76116+}
76117+
76118 /**
76119 * list_del_rcu - deletes entry from list without re-initialization
76120 * @entry: the element to delete from the list.
76121@@ -117,6 +131,8 @@ static inline void list_del_rcu(struct list_head *entry)
76122 entry->prev = LIST_POISON2;
76123 }
76124
76125+extern void pax_list_del_rcu(struct list_head *entry);
76126+
76127 /**
76128 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
76129 * @n: the element to delete from the hash list.
76130diff --git a/include/linux/reboot.h b/include/linux/reboot.h
76131index 8e00f9f..9449b55 100644
76132--- a/include/linux/reboot.h
76133+++ b/include/linux/reboot.h
76134@@ -43,9 +43,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
76135 * Architecture-specific implementations of sys_reboot commands.
76136 */
76137
76138-extern void machine_restart(char *cmd);
76139-extern void machine_halt(void);
76140-extern void machine_power_off(void);
76141+extern void machine_restart(char *cmd) __noreturn;
76142+extern void machine_halt(void) __noreturn;
76143+extern void machine_power_off(void) __noreturn;
76144
76145 extern void machine_shutdown(void);
76146 struct pt_regs;
76147@@ -56,9 +56,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
76148 */
76149
76150 extern void kernel_restart_prepare(char *cmd);
76151-extern void kernel_restart(char *cmd);
76152-extern void kernel_halt(void);
76153-extern void kernel_power_off(void);
76154+extern void kernel_restart(char *cmd) __noreturn;
76155+extern void kernel_halt(void) __noreturn;
76156+extern void kernel_power_off(void) __noreturn;
76157
76158 extern int C_A_D; /* for sysctl */
76159 void ctrl_alt_del(void);
76160@@ -72,7 +72,7 @@ extern int orderly_poweroff(bool force);
76161 * Emergency restart, callable from an interrupt handler.
76162 */
76163
76164-extern void emergency_restart(void);
76165+extern void emergency_restart(void) __noreturn;
76166 #include <asm/emergency-restart.h>
76167
76168 #endif /* _LINUX_REBOOT_H */
76169diff --git a/include/linux/regset.h b/include/linux/regset.h
76170index 8e0c9fe..ac4d221 100644
76171--- a/include/linux/regset.h
76172+++ b/include/linux/regset.h
76173@@ -161,7 +161,8 @@ struct user_regset {
76174 unsigned int align;
76175 unsigned int bias;
76176 unsigned int core_note_type;
76177-};
76178+} __do_const;
76179+typedef struct user_regset __no_const user_regset_no_const;
76180
76181 /**
76182 * struct user_regset_view - available regsets
76183diff --git a/include/linux/relay.h b/include/linux/relay.h
76184index d7c8359..818daf5 100644
76185--- a/include/linux/relay.h
76186+++ b/include/linux/relay.h
76187@@ -157,7 +157,7 @@ struct rchan_callbacks
76188 * The callback should return 0 if successful, negative if not.
76189 */
76190 int (*remove_buf_file)(struct dentry *dentry);
76191-};
76192+} __no_const;
76193
76194 /*
76195 * CONFIG_RELAY kernel API, kernel/relay.c
76196diff --git a/include/linux/rio.h b/include/linux/rio.h
76197index b71d573..2f940bd 100644
76198--- a/include/linux/rio.h
76199+++ b/include/linux/rio.h
76200@@ -355,7 +355,7 @@ struct rio_ops {
76201 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
76202 u64 rstart, u32 size, u32 flags);
76203 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
76204-};
76205+} __no_const;
76206
76207 #define RIO_RESOURCE_MEM 0x00000100
76208 #define RIO_RESOURCE_DOORBELL 0x00000200
76209diff --git a/include/linux/rmap.h b/include/linux/rmap.h
76210index 6dacb93..6174423 100644
76211--- a/include/linux/rmap.h
76212+++ b/include/linux/rmap.h
76213@@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
76214 void anon_vma_init(void); /* create anon_vma_cachep */
76215 int anon_vma_prepare(struct vm_area_struct *);
76216 void unlink_anon_vmas(struct vm_area_struct *);
76217-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
76218-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
76219+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
76220+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
76221
76222 static inline void anon_vma_merge(struct vm_area_struct *vma,
76223 struct vm_area_struct *next)
76224diff --git a/include/linux/sched.h b/include/linux/sched.h
76225index 078066d..4090b3b 100644
76226--- a/include/linux/sched.h
76227+++ b/include/linux/sched.h
76228@@ -62,6 +62,7 @@ struct bio_list;
76229 struct fs_struct;
76230 struct perf_event_context;
76231 struct blk_plug;
76232+struct linux_binprm;
76233
76234 /*
76235 * List of flags we want to share for kernel threads,
76236@@ -303,7 +304,7 @@ extern char __sched_text_start[], __sched_text_end[];
76237 extern int in_sched_functions(unsigned long addr);
76238
76239 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
76240-extern signed long schedule_timeout(signed long timeout);
76241+extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
76242 extern signed long schedule_timeout_interruptible(signed long timeout);
76243 extern signed long schedule_timeout_killable(signed long timeout);
76244 extern signed long schedule_timeout_uninterruptible(signed long timeout);
76245@@ -314,6 +315,19 @@ struct nsproxy;
76246 struct user_namespace;
76247
76248 #ifdef CONFIG_MMU
76249+
76250+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
76251+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
76252+#else
76253+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
76254+{
76255+ return 0;
76256+}
76257+#endif
76258+
76259+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
76260+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
76261+
76262 extern void arch_pick_mmap_layout(struct mm_struct *mm);
76263 extern unsigned long
76264 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
76265@@ -589,6 +603,17 @@ struct signal_struct {
76266 #ifdef CONFIG_TASKSTATS
76267 struct taskstats *stats;
76268 #endif
76269+
76270+#ifdef CONFIG_GRKERNSEC
76271+ u32 curr_ip;
76272+ u32 saved_ip;
76273+ u32 gr_saddr;
76274+ u32 gr_daddr;
76275+ u16 gr_sport;
76276+ u16 gr_dport;
76277+ u8 used_accept:1;
76278+#endif
76279+
76280 #ifdef CONFIG_AUDIT
76281 unsigned audit_tty;
76282 unsigned audit_tty_log_passwd;
76283@@ -669,6 +694,14 @@ struct user_struct {
76284 struct key *session_keyring; /* UID's default session keyring */
76285 #endif
76286
76287+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
76288+ unsigned char kernel_banned;
76289+#endif
76290+#ifdef CONFIG_GRKERNSEC_BRUTE
76291+ unsigned char suid_banned;
76292+ unsigned long suid_ban_expires;
76293+#endif
76294+
76295 /* Hash table maintenance information */
76296 struct hlist_node uidhash_node;
76297 kuid_t uid;
76298@@ -1151,8 +1184,8 @@ struct task_struct {
76299 struct list_head thread_group;
76300
76301 struct completion *vfork_done; /* for vfork() */
76302- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
76303- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
76304+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
76305+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
76306
76307 cputime_t utime, stime, utimescaled, stimescaled;
76308 cputime_t gtime;
76309@@ -1177,11 +1210,6 @@ struct task_struct {
76310 struct task_cputime cputime_expires;
76311 struct list_head cpu_timers[3];
76312
76313-/* process credentials */
76314- const struct cred __rcu *real_cred; /* objective and real subjective task
76315- * credentials (COW) */
76316- const struct cred __rcu *cred; /* effective (overridable) subjective task
76317- * credentials (COW) */
76318 char comm[TASK_COMM_LEN]; /* executable name excluding path
76319 - access with [gs]et_task_comm (which lock
76320 it with task_lock())
76321@@ -1198,6 +1226,10 @@ struct task_struct {
76322 #endif
76323 /* CPU-specific state of this task */
76324 struct thread_struct thread;
76325+/* thread_info moved to task_struct */
76326+#ifdef CONFIG_X86
76327+ struct thread_info tinfo;
76328+#endif
76329 /* filesystem information */
76330 struct fs_struct *fs;
76331 /* open file information */
76332@@ -1271,6 +1303,10 @@ struct task_struct {
76333 gfp_t lockdep_reclaim_gfp;
76334 #endif
76335
76336+/* process credentials */
76337+ const struct cred __rcu *real_cred; /* objective and real subjective task
76338+ * credentials (COW) */
76339+
76340 /* journalling filesystem info */
76341 void *journal_info;
76342
76343@@ -1309,6 +1345,10 @@ struct task_struct {
76344 /* cg_list protected by css_set_lock and tsk->alloc_lock */
76345 struct list_head cg_list;
76346 #endif
76347+
76348+ const struct cred __rcu *cred; /* effective (overridable) subjective task
76349+ * credentials (COW) */
76350+
76351 #ifdef CONFIG_FUTEX
76352 struct robust_list_head __user *robust_list;
76353 #ifdef CONFIG_COMPAT
76354@@ -1406,8 +1446,76 @@ struct task_struct {
76355 unsigned int sequential_io;
76356 unsigned int sequential_io_avg;
76357 #endif
76358+
76359+#ifdef CONFIG_GRKERNSEC
76360+ /* grsecurity */
76361+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
76362+ u64 exec_id;
76363+#endif
76364+#ifdef CONFIG_GRKERNSEC_SETXID
76365+ const struct cred *delayed_cred;
76366+#endif
76367+ struct dentry *gr_chroot_dentry;
76368+ struct acl_subject_label *acl;
76369+ struct acl_role_label *role;
76370+ struct file *exec_file;
76371+ unsigned long brute_expires;
76372+ u16 acl_role_id;
76373+ /* is this the task that authenticated to the special role */
76374+ u8 acl_sp_role;
76375+ u8 is_writable;
76376+ u8 brute;
76377+ u8 gr_is_chrooted;
76378+#endif
76379+
76380 };
76381
76382+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
76383+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
76384+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
76385+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
76386+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
76387+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
76388+
76389+#ifdef CONFIG_PAX_SOFTMODE
76390+extern int pax_softmode;
76391+#endif
76392+
76393+extern int pax_check_flags(unsigned long *);
76394+
76395+/* if tsk != current then task_lock must be held on it */
76396+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
76397+static inline unsigned long pax_get_flags(struct task_struct *tsk)
76398+{
76399+ if (likely(tsk->mm))
76400+ return tsk->mm->pax_flags;
76401+ else
76402+ return 0UL;
76403+}
76404+
76405+/* if tsk != current then task_lock must be held on it */
76406+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
76407+{
76408+ if (likely(tsk->mm)) {
76409+ tsk->mm->pax_flags = flags;
76410+ return 0;
76411+ }
76412+ return -EINVAL;
76413+}
76414+#endif
76415+
76416+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
76417+extern void pax_set_initial_flags(struct linux_binprm *bprm);
76418+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
76419+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
76420+#endif
76421+
76422+struct path;
76423+extern char *pax_get_path(const struct path *path, char *buf, int buflen);
76424+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
76425+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
76426+extern void pax_report_refcount_overflow(struct pt_regs *regs);
76427+
76428 /* Future-safe accessor for struct task_struct's cpus_allowed. */
76429 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
76430
76431@@ -1466,7 +1574,7 @@ struct pid_namespace;
76432 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
76433 struct pid_namespace *ns);
76434
76435-static inline pid_t task_pid_nr(struct task_struct *tsk)
76436+static inline pid_t task_pid_nr(const struct task_struct *tsk)
76437 {
76438 return tsk->pid;
76439 }
76440@@ -1916,7 +2024,9 @@ void yield(void);
76441 extern struct exec_domain default_exec_domain;
76442
76443 union thread_union {
76444+#ifndef CONFIG_X86
76445 struct thread_info thread_info;
76446+#endif
76447 unsigned long stack[THREAD_SIZE/sizeof(long)];
76448 };
76449
76450@@ -1949,6 +2059,7 @@ extern struct pid_namespace init_pid_ns;
76451 */
76452
76453 extern struct task_struct *find_task_by_vpid(pid_t nr);
76454+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
76455 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
76456 struct pid_namespace *ns);
76457
76458@@ -2113,7 +2224,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
76459 extern void exit_itimers(struct signal_struct *);
76460 extern void flush_itimer_signals(void);
76461
76462-extern void do_group_exit(int);
76463+extern __noreturn void do_group_exit(int);
76464
76465 extern int allow_signal(int);
76466 extern int disallow_signal(int);
76467@@ -2304,9 +2415,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
76468
76469 #endif
76470
76471-static inline int object_is_on_stack(void *obj)
76472+static inline int object_starts_on_stack(void *obj)
76473 {
76474- void *stack = task_stack_page(current);
76475+ const void *stack = task_stack_page(current);
76476
76477 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
76478 }
76479diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
76480index bf8086b..962b035 100644
76481--- a/include/linux/sched/sysctl.h
76482+++ b/include/linux/sched/sysctl.h
76483@@ -30,6 +30,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
76484 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
76485
76486 extern int sysctl_max_map_count;
76487+extern unsigned long sysctl_heap_stack_gap;
76488
76489 extern unsigned int sysctl_sched_latency;
76490 extern unsigned int sysctl_sched_min_granularity;
76491diff --git a/include/linux/security.h b/include/linux/security.h
76492index 7ce53ae..8ee24a5 100644
76493--- a/include/linux/security.h
76494+++ b/include/linux/security.h
76495@@ -27,6 +27,7 @@
76496 #include <linux/slab.h>
76497 #include <linux/err.h>
76498 #include <linux/string.h>
76499+#include <linux/grsecurity.h>
76500
76501 struct linux_binprm;
76502 struct cred;
76503@@ -116,8 +117,6 @@ struct seq_file;
76504
76505 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
76506
76507-void reset_security_ops(void);
76508-
76509 #ifdef CONFIG_MMU
76510 extern unsigned long mmap_min_addr;
76511 extern unsigned long dac_mmap_min_addr;
76512diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
76513index 4e32edc..f8f2d18 100644
76514--- a/include/linux/seq_file.h
76515+++ b/include/linux/seq_file.h
76516@@ -26,6 +26,9 @@ struct seq_file {
76517 struct mutex lock;
76518 const struct seq_operations *op;
76519 int poll_event;
76520+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
76521+ u64 exec_id;
76522+#endif
76523 #ifdef CONFIG_USER_NS
76524 struct user_namespace *user_ns;
76525 #endif
76526@@ -38,6 +41,7 @@ struct seq_operations {
76527 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
76528 int (*show) (struct seq_file *m, void *v);
76529 };
76530+typedef struct seq_operations __no_const seq_operations_no_const;
76531
76532 #define SEQ_SKIP 1
76533
76534diff --git a/include/linux/shm.h b/include/linux/shm.h
76535index 429c199..4d42e38 100644
76536--- a/include/linux/shm.h
76537+++ b/include/linux/shm.h
76538@@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
76539
76540 /* The task created the shm object. NULL if the task is dead. */
76541 struct task_struct *shm_creator;
76542+#ifdef CONFIG_GRKERNSEC
76543+ time_t shm_createtime;
76544+ pid_t shm_lapid;
76545+#endif
76546 };
76547
76548 /* shm_mode upper byte flags */
76549diff --git a/include/linux/signal.h b/include/linux/signal.h
76550index d897484..323ba98 100644
76551--- a/include/linux/signal.h
76552+++ b/include/linux/signal.h
76553@@ -433,6 +433,7 @@ void signals_init(void);
76554
76555 int restore_altstack(const stack_t __user *);
76556 int __save_altstack(stack_t __user *, unsigned long);
76557+void __save_altstack_ex(stack_t __user *, unsigned long);
76558
76559 #ifdef CONFIG_PROC_FS
76560 struct seq_file;
76561diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
76562index 3b71a4e..5c9f309 100644
76563--- a/include/linux/skbuff.h
76564+++ b/include/linux/skbuff.h
76565@@ -648,7 +648,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
76566 extern struct sk_buff *__alloc_skb(unsigned int size,
76567 gfp_t priority, int flags, int node);
76568 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
76569-static inline struct sk_buff *alloc_skb(unsigned int size,
76570+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
76571 gfp_t priority)
76572 {
76573 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
76574@@ -764,7 +764,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
76575 */
76576 static inline int skb_queue_empty(const struct sk_buff_head *list)
76577 {
76578- return list->next == (struct sk_buff *)list;
76579+ return list->next == (const struct sk_buff *)list;
76580 }
76581
76582 /**
76583@@ -777,7 +777,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
76584 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
76585 const struct sk_buff *skb)
76586 {
76587- return skb->next == (struct sk_buff *)list;
76588+ return skb->next == (const struct sk_buff *)list;
76589 }
76590
76591 /**
76592@@ -790,7 +790,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
76593 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
76594 const struct sk_buff *skb)
76595 {
76596- return skb->prev == (struct sk_buff *)list;
76597+ return skb->prev == (const struct sk_buff *)list;
76598 }
76599
76600 /**
76601@@ -1750,7 +1750,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
76602 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
76603 */
76604 #ifndef NET_SKB_PAD
76605-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
76606+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
76607 #endif
76608
76609 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
76610@@ -2345,7 +2345,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
76611 int noblock, int *err);
76612 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
76613 struct poll_table_struct *wait);
76614-extern int skb_copy_datagram_iovec(const struct sk_buff *from,
76615+extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
76616 int offset, struct iovec *to,
76617 int size);
76618 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
76619@@ -2636,6 +2636,9 @@ static inline void nf_reset(struct sk_buff *skb)
76620 nf_bridge_put(skb->nf_bridge);
76621 skb->nf_bridge = NULL;
76622 #endif
76623+#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
76624+ skb->nf_trace = 0;
76625+#endif
76626 }
76627
76628 static inline void nf_reset_trace(struct sk_buff *skb)
76629diff --git a/include/linux/slab.h b/include/linux/slab.h
76630index 6c5cc0e..9ca0fd6 100644
76631--- a/include/linux/slab.h
76632+++ b/include/linux/slab.h
76633@@ -12,15 +12,29 @@
76634 #include <linux/gfp.h>
76635 #include <linux/types.h>
76636 #include <linux/workqueue.h>
76637-
76638+#include <linux/err.h>
76639
76640 /*
76641 * Flags to pass to kmem_cache_create().
76642 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
76643 */
76644 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
76645+
76646+#ifdef CONFIG_PAX_USERCOPY_SLABS
76647+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
76648+#else
76649+#define SLAB_USERCOPY 0x00000000UL
76650+#endif
76651+
76652 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
76653 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
76654+
76655+#ifdef CONFIG_PAX_MEMORY_SANITIZE
76656+#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
76657+#else
76658+#define SLAB_NO_SANITIZE 0x00000000UL
76659+#endif
76660+
76661 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
76662 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
76663 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
76664@@ -89,10 +103,13 @@
76665 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
76666 * Both make kfree a no-op.
76667 */
76668-#define ZERO_SIZE_PTR ((void *)16)
76669+#define ZERO_SIZE_PTR \
76670+({ \
76671+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
76672+ (void *)(-MAX_ERRNO-1L); \
76673+})
76674
76675-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
76676- (unsigned long)ZERO_SIZE_PTR)
76677+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
76678
76679
76680 struct mem_cgroup;
76681@@ -132,6 +149,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
76682 void kfree(const void *);
76683 void kzfree(const void *);
76684 size_t ksize(const void *);
76685+const char *check_heap_object(const void *ptr, unsigned long n);
76686+bool is_usercopy_object(const void *ptr);
76687
76688 /*
76689 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
76690@@ -164,7 +183,7 @@ struct kmem_cache {
76691 unsigned int align; /* Alignment as calculated */
76692 unsigned long flags; /* Active flags on the slab */
76693 const char *name; /* Slab name for sysfs */
76694- int refcount; /* Use counter */
76695+ atomic_t refcount; /* Use counter */
76696 void (*ctor)(void *); /* Called on object slot creation */
76697 struct list_head list; /* List of all slab caches on the system */
76698 };
76699@@ -238,6 +257,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
76700 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
76701 #endif
76702
76703+#ifdef CONFIG_PAX_USERCOPY_SLABS
76704+extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
76705+#endif
76706+
76707 /*
76708 * Figure out which kmalloc slab an allocation of a certain size
76709 * belongs to.
76710@@ -246,7 +269,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
76711 * 2 = 120 .. 192 bytes
76712 * n = 2^(n-1) .. 2^n -1
76713 */
76714-static __always_inline int kmalloc_index(size_t size)
76715+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
76716 {
76717 if (!size)
76718 return 0;
76719@@ -492,7 +515,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
76720 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
76721 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
76722 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
76723-extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
76724+extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
76725 #define kmalloc_track_caller(size, flags) \
76726 __kmalloc_track_caller(size, flags, _RET_IP_)
76727 #else
76728@@ -512,7 +535,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
76729 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
76730 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
76731 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
76732-extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
76733+extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
76734 #define kmalloc_node_track_caller(size, flags, node) \
76735 __kmalloc_node_track_caller(size, flags, node, \
76736 _RET_IP_)
76737diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
76738index cd40158..4e2f7af 100644
76739--- a/include/linux/slab_def.h
76740+++ b/include/linux/slab_def.h
76741@@ -50,7 +50,7 @@ struct kmem_cache {
76742 /* 4) cache creation/removal */
76743 const char *name;
76744 struct list_head list;
76745- int refcount;
76746+ atomic_t refcount;
76747 int object_size;
76748 int align;
76749
76750@@ -66,10 +66,14 @@ struct kmem_cache {
76751 unsigned long node_allocs;
76752 unsigned long node_frees;
76753 unsigned long node_overflow;
76754- atomic_t allochit;
76755- atomic_t allocmiss;
76756- atomic_t freehit;
76757- atomic_t freemiss;
76758+ atomic_unchecked_t allochit;
76759+ atomic_unchecked_t allocmiss;
76760+ atomic_unchecked_t freehit;
76761+ atomic_unchecked_t freemiss;
76762+#ifdef CONFIG_PAX_MEMORY_SANITIZE
76763+ atomic_unchecked_t sanitized;
76764+ atomic_unchecked_t not_sanitized;
76765+#endif
76766
76767 /*
76768 * If debugging is enabled, then the allocator can add additional
76769@@ -103,7 +107,7 @@ struct kmem_cache {
76770 };
76771
76772 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
76773-void *__kmalloc(size_t size, gfp_t flags);
76774+void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
76775
76776 #ifdef CONFIG_TRACING
76777 extern void *kmem_cache_alloc_trace(struct kmem_cache *, gfp_t, size_t);
76778@@ -136,6 +140,13 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
76779 cachep = kmalloc_dma_caches[i];
76780 else
76781 #endif
76782+
76783+#ifdef CONFIG_PAX_USERCOPY_SLABS
76784+ if (flags & GFP_USERCOPY)
76785+ cachep = kmalloc_usercopy_caches[i];
76786+ else
76787+#endif
76788+
76789 cachep = kmalloc_caches[i];
76790
76791 ret = kmem_cache_alloc_trace(cachep, flags, size);
76792@@ -146,7 +157,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
76793 }
76794
76795 #ifdef CONFIG_NUMA
76796-extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
76797+extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
76798 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
76799
76800 #ifdef CONFIG_TRACING
76801@@ -185,6 +196,13 @@ static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
76802 cachep = kmalloc_dma_caches[i];
76803 else
76804 #endif
76805+
76806+#ifdef CONFIG_PAX_USERCOPY_SLABS
76807+ if (flags & GFP_USERCOPY)
76808+ cachep = kmalloc_usercopy_caches[i];
76809+ else
76810+#endif
76811+
76812 cachep = kmalloc_caches[i];
76813
76814 return kmem_cache_alloc_node_trace(cachep, flags, node, size);
76815diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
76816index 095a5a4..4b82027 100644
76817--- a/include/linux/slob_def.h
76818+++ b/include/linux/slob_def.h
76819@@ -11,7 +11,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
76820 return kmem_cache_alloc_node(cachep, flags, NUMA_NO_NODE);
76821 }
76822
76823-void *__kmalloc_node(size_t size, gfp_t flags, int node);
76824+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
76825
76826 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
76827 {
76828@@ -23,7 +23,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
76829 return __kmalloc_node(size, flags, NUMA_NO_NODE);
76830 }
76831
76832-static __always_inline void *__kmalloc(size_t size, gfp_t flags)
76833+static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
76834 {
76835 return kmalloc(size, flags);
76836 }
76837diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
76838index 027276f..092bfe8 100644
76839--- a/include/linux/slub_def.h
76840+++ b/include/linux/slub_def.h
76841@@ -80,7 +80,7 @@ struct kmem_cache {
76842 struct kmem_cache_order_objects max;
76843 struct kmem_cache_order_objects min;
76844 gfp_t allocflags; /* gfp flags to use on each alloc */
76845- int refcount; /* Refcount for slab cache destroy */
76846+ atomic_t refcount; /* Refcount for slab cache destroy */
76847 void (*ctor)(void *);
76848 int inuse; /* Offset to metadata */
76849 int align; /* Alignment */
76850@@ -105,7 +105,7 @@ struct kmem_cache {
76851 };
76852
76853 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
76854-void *__kmalloc(size_t size, gfp_t flags);
76855+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
76856
76857 static __always_inline void *
76858 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
76859@@ -149,7 +149,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
76860 }
76861 #endif
76862
76863-static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
76864+static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
76865 {
76866 unsigned int order = get_order(size);
76867 return kmalloc_order_trace(size, flags, order);
76868@@ -175,7 +175,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
76869 }
76870
76871 #ifdef CONFIG_NUMA
76872-void *__kmalloc_node(size_t size, gfp_t flags, int node);
76873+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
76874 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
76875
76876 #ifdef CONFIG_TRACING
76877diff --git a/include/linux/smp.h b/include/linux/smp.h
76878index c181399..09d7b92 100644
76879--- a/include/linux/smp.h
76880+++ b/include/linux/smp.h
76881@@ -217,7 +217,9 @@ static inline void kick_all_cpus_sync(void) { }
76882 #endif
76883
76884 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
76885+#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
76886 #define put_cpu() preempt_enable()
76887+#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
76888
76889 /*
76890 * Callback to arch code if there's nosmp or maxcpus=0 on the
76891diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
76892index 54f91d3..be2c379 100644
76893--- a/include/linux/sock_diag.h
76894+++ b/include/linux/sock_diag.h
76895@@ -11,7 +11,7 @@ struct sock;
76896 struct sock_diag_handler {
76897 __u8 family;
76898 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
76899-};
76900+} __do_const;
76901
76902 int sock_diag_register(const struct sock_diag_handler *h);
76903 void sock_diag_unregister(const struct sock_diag_handler *h);
76904diff --git a/include/linux/sonet.h b/include/linux/sonet.h
76905index 680f9a3..f13aeb0 100644
76906--- a/include/linux/sonet.h
76907+++ b/include/linux/sonet.h
76908@@ -7,7 +7,7 @@
76909 #include <uapi/linux/sonet.h>
76910
76911 struct k_sonet_stats {
76912-#define __HANDLE_ITEM(i) atomic_t i
76913+#define __HANDLE_ITEM(i) atomic_unchecked_t i
76914 __SONET_ITEMS
76915 #undef __HANDLE_ITEM
76916 };
76917diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
76918index 07d8e53..dc934c9 100644
76919--- a/include/linux/sunrpc/addr.h
76920+++ b/include/linux/sunrpc/addr.h
76921@@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
76922 {
76923 switch (sap->sa_family) {
76924 case AF_INET:
76925- return ntohs(((struct sockaddr_in *)sap)->sin_port);
76926+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
76927 case AF_INET6:
76928- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
76929+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
76930 }
76931 return 0;
76932 }
76933@@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
76934 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
76935 const struct sockaddr *src)
76936 {
76937- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
76938+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
76939 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
76940
76941 dsin->sin_family = ssin->sin_family;
76942@@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
76943 if (sa->sa_family != AF_INET6)
76944 return 0;
76945
76946- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
76947+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
76948 }
76949
76950 #endif /* _LINUX_SUNRPC_ADDR_H */
76951diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
76952index bfe11be..12bc8c4 100644
76953--- a/include/linux/sunrpc/clnt.h
76954+++ b/include/linux/sunrpc/clnt.h
76955@@ -96,7 +96,7 @@ struct rpc_procinfo {
76956 unsigned int p_timer; /* Which RTT timer to use */
76957 u32 p_statidx; /* Which procedure to account */
76958 const char * p_name; /* name of procedure */
76959-};
76960+} __do_const;
76961
76962 #ifdef __KERNEL__
76963
76964diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
76965index 1f0216b..6a4fa50 100644
76966--- a/include/linux/sunrpc/svc.h
76967+++ b/include/linux/sunrpc/svc.h
76968@@ -411,7 +411,7 @@ struct svc_procedure {
76969 unsigned int pc_count; /* call count */
76970 unsigned int pc_cachetype; /* cache info (NFS) */
76971 unsigned int pc_xdrressize; /* maximum size of XDR reply */
76972-};
76973+} __do_const;
76974
76975 /*
76976 * Function prototypes.
76977diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
76978index 0b8e3e6..33e0a01 100644
76979--- a/include/linux/sunrpc/svc_rdma.h
76980+++ b/include/linux/sunrpc/svc_rdma.h
76981@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
76982 extern unsigned int svcrdma_max_requests;
76983 extern unsigned int svcrdma_max_req_size;
76984
76985-extern atomic_t rdma_stat_recv;
76986-extern atomic_t rdma_stat_read;
76987-extern atomic_t rdma_stat_write;
76988-extern atomic_t rdma_stat_sq_starve;
76989-extern atomic_t rdma_stat_rq_starve;
76990-extern atomic_t rdma_stat_rq_poll;
76991-extern atomic_t rdma_stat_rq_prod;
76992-extern atomic_t rdma_stat_sq_poll;
76993-extern atomic_t rdma_stat_sq_prod;
76994+extern atomic_unchecked_t rdma_stat_recv;
76995+extern atomic_unchecked_t rdma_stat_read;
76996+extern atomic_unchecked_t rdma_stat_write;
76997+extern atomic_unchecked_t rdma_stat_sq_starve;
76998+extern atomic_unchecked_t rdma_stat_rq_starve;
76999+extern atomic_unchecked_t rdma_stat_rq_poll;
77000+extern atomic_unchecked_t rdma_stat_rq_prod;
77001+extern atomic_unchecked_t rdma_stat_sq_poll;
77002+extern atomic_unchecked_t rdma_stat_sq_prod;
77003
77004 #define RPCRDMA_VERSION 1
77005
77006diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
77007index 8d71d65..f79586e 100644
77008--- a/include/linux/sunrpc/svcauth.h
77009+++ b/include/linux/sunrpc/svcauth.h
77010@@ -120,7 +120,7 @@ struct auth_ops {
77011 int (*release)(struct svc_rqst *rq);
77012 void (*domain_release)(struct auth_domain *);
77013 int (*set_client)(struct svc_rqst *rq);
77014-};
77015+} __do_const;
77016
77017 #define SVC_GARBAGE 1
77018 #define SVC_SYSERR 2
77019diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
77020index a5ffd32..0935dea 100644
77021--- a/include/linux/swiotlb.h
77022+++ b/include/linux/swiotlb.h
77023@@ -60,7 +60,8 @@ extern void
77024
77025 extern void
77026 swiotlb_free_coherent(struct device *hwdev, size_t size,
77027- void *vaddr, dma_addr_t dma_handle);
77028+ void *vaddr, dma_addr_t dma_handle,
77029+ struct dma_attrs *attrs);
77030
77031 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
77032 unsigned long offset, size_t size,
77033diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
77034index 84662ec..5271947 100644
77035--- a/include/linux/syscalls.h
77036+++ b/include/linux/syscalls.h
77037@@ -97,8 +97,14 @@ struct sigaltstack;
77038 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
77039
77040 #define __SC_DECL(t, a) t a
77041+#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))
77042 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
77043-#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
77044+#define __SC_LONG(t, a) __typeof( \
77045+ __builtin_choose_expr( \
77046+ sizeof(t) > sizeof(int), \
77047+ (t) 0, \
77048+ __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
77049+ )) a
77050 #define __SC_CAST(t, a) (t) a
77051 #define __SC_ARGS(t, a) a
77052 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
77053@@ -362,11 +368,11 @@ asmlinkage long sys_sync(void);
77054 asmlinkage long sys_fsync(unsigned int fd);
77055 asmlinkage long sys_fdatasync(unsigned int fd);
77056 asmlinkage long sys_bdflush(int func, long data);
77057-asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
77058- char __user *type, unsigned long flags,
77059+asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
77060+ const char __user *type, unsigned long flags,
77061 void __user *data);
77062-asmlinkage long sys_umount(char __user *name, int flags);
77063-asmlinkage long sys_oldumount(char __user *name);
77064+asmlinkage long sys_umount(const char __user *name, int flags);
77065+asmlinkage long sys_oldumount(const char __user *name);
77066 asmlinkage long sys_truncate(const char __user *path, long length);
77067 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
77068 asmlinkage long sys_stat(const char __user *filename,
77069@@ -578,7 +584,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
77070 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
77071 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
77072 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
77073- struct sockaddr __user *, int);
77074+ struct sockaddr __user *, int) __intentional_overflow(0);
77075 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
77076 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
77077 unsigned int vlen, unsigned flags);
77078diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
77079index 27b3b0b..e093dd9 100644
77080--- a/include/linux/syscore_ops.h
77081+++ b/include/linux/syscore_ops.h
77082@@ -16,7 +16,7 @@ struct syscore_ops {
77083 int (*suspend)(void);
77084 void (*resume)(void);
77085 void (*shutdown)(void);
77086-};
77087+} __do_const;
77088
77089 extern void register_syscore_ops(struct syscore_ops *ops);
77090 extern void unregister_syscore_ops(struct syscore_ops *ops);
77091diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
77092index 14a8ff2..af52bad 100644
77093--- a/include/linux/sysctl.h
77094+++ b/include/linux/sysctl.h
77095@@ -34,13 +34,13 @@ struct ctl_table_root;
77096 struct ctl_table_header;
77097 struct ctl_dir;
77098
77099-typedef struct ctl_table ctl_table;
77100-
77101 typedef int proc_handler (struct ctl_table *ctl, int write,
77102 void __user *buffer, size_t *lenp, loff_t *ppos);
77103
77104 extern int proc_dostring(struct ctl_table *, int,
77105 void __user *, size_t *, loff_t *);
77106+extern int proc_dostring_modpriv(struct ctl_table *, int,
77107+ void __user *, size_t *, loff_t *);
77108 extern int proc_dointvec(struct ctl_table *, int,
77109 void __user *, size_t *, loff_t *);
77110 extern int proc_dointvec_minmax(struct ctl_table *, int,
77111@@ -115,7 +115,9 @@ struct ctl_table
77112 struct ctl_table_poll *poll;
77113 void *extra1;
77114 void *extra2;
77115-};
77116+} __do_const;
77117+typedef struct ctl_table __no_const ctl_table_no_const;
77118+typedef struct ctl_table ctl_table;
77119
77120 struct ctl_node {
77121 struct rb_node node;
77122diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
77123index 9e8a9b5..753de68 100644
77124--- a/include/linux/sysfs.h
77125+++ b/include/linux/sysfs.h
77126@@ -33,7 +33,8 @@ struct attribute {
77127 struct lock_class_key *key;
77128 struct lock_class_key skey;
77129 #endif
77130-};
77131+} __do_const;
77132+typedef struct attribute __no_const attribute_no_const;
77133
77134 /**
77135 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
77136@@ -62,7 +63,8 @@ struct attribute_group {
77137 struct attribute *, int);
77138 struct attribute **attrs;
77139 struct bin_attribute **bin_attrs;
77140-};
77141+} __do_const;
77142+typedef struct attribute_group __no_const attribute_group_no_const;
77143
77144 /**
77145 * Use these macros to make defining attributes easier. See include/linux/device.h
77146@@ -123,7 +125,8 @@ struct bin_attribute {
77147 char *, loff_t, size_t);
77148 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
77149 struct vm_area_struct *vma);
77150-};
77151+} __do_const;
77152+typedef struct bin_attribute __no_const bin_attribute_no_const;
77153
77154 /**
77155 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
77156diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
77157index 7faf933..9b85a0c 100644
77158--- a/include/linux/sysrq.h
77159+++ b/include/linux/sysrq.h
77160@@ -16,6 +16,7 @@
77161
77162 #include <linux/errno.h>
77163 #include <linux/types.h>
77164+#include <linux/compiler.h>
77165
77166 /* Enable/disable SYSRQ support by default (0==no, 1==yes). */
77167 #define SYSRQ_DEFAULT_ENABLE 1
77168@@ -36,7 +37,7 @@ struct sysrq_key_op {
77169 char *help_msg;
77170 char *action_msg;
77171 int enable_mask;
77172-};
77173+} __do_const;
77174
77175 #ifdef CONFIG_MAGIC_SYSRQ
77176
77177diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
77178index e7e0473..7989295 100644
77179--- a/include/linux/thread_info.h
77180+++ b/include/linux/thread_info.h
77181@@ -148,6 +148,15 @@ static inline bool test_and_clear_restore_sigmask(void)
77182 #error "no set_restore_sigmask() provided and default one won't work"
77183 #endif
77184
77185+extern void __check_object_size(const void *ptr, unsigned long n, bool to_user);
77186+static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
77187+{
77188+#ifndef CONFIG_PAX_USERCOPY_DEBUG
77189+ if (!__builtin_constant_p(n))
77190+#endif
77191+ __check_object_size(ptr, n, to_user);
77192+}
77193+
77194 #endif /* __KERNEL__ */
77195
77196 #endif /* _LINUX_THREAD_INFO_H */
77197diff --git a/include/linux/tty.h b/include/linux/tty.h
77198index 01ac30e..bf18a71 100644
77199--- a/include/linux/tty.h
77200+++ b/include/linux/tty.h
77201@@ -194,7 +194,7 @@ struct tty_port {
77202 const struct tty_port_operations *ops; /* Port operations */
77203 spinlock_t lock; /* Lock protecting tty field */
77204 int blocked_open; /* Waiting to open */
77205- int count; /* Usage count */
77206+ atomic_t count; /* Usage count */
77207 wait_queue_head_t open_wait; /* Open waiters */
77208 wait_queue_head_t close_wait; /* Close waiters */
77209 wait_queue_head_t delta_msr_wait; /* Modem status change */
77210@@ -547,7 +547,7 @@ extern int tty_port_open(struct tty_port *port,
77211 struct tty_struct *tty, struct file *filp);
77212 static inline int tty_port_users(struct tty_port *port)
77213 {
77214- return port->count + port->blocked_open;
77215+ return atomic_read(&port->count) + port->blocked_open;
77216 }
77217
77218 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
77219diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
77220index 756a609..b302dd6 100644
77221--- a/include/linux/tty_driver.h
77222+++ b/include/linux/tty_driver.h
77223@@ -285,7 +285,7 @@ struct tty_operations {
77224 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
77225 #endif
77226 const struct file_operations *proc_fops;
77227-};
77228+} __do_const;
77229
77230 struct tty_driver {
77231 int magic; /* magic number for this structure */
77232diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
77233index a1b0489..f02e17c 100644
77234--- a/include/linux/tty_ldisc.h
77235+++ b/include/linux/tty_ldisc.h
77236@@ -198,7 +198,7 @@ struct tty_ldisc_ops {
77237
77238 struct module *owner;
77239
77240- int refcount;
77241+ atomic_t refcount;
77242 };
77243
77244 struct tty_ldisc {
77245diff --git a/include/linux/types.h b/include/linux/types.h
77246index 4d118ba..c3ee9bf 100644
77247--- a/include/linux/types.h
77248+++ b/include/linux/types.h
77249@@ -176,10 +176,26 @@ typedef struct {
77250 int counter;
77251 } atomic_t;
77252
77253+#ifdef CONFIG_PAX_REFCOUNT
77254+typedef struct {
77255+ int counter;
77256+} atomic_unchecked_t;
77257+#else
77258+typedef atomic_t atomic_unchecked_t;
77259+#endif
77260+
77261 #ifdef CONFIG_64BIT
77262 typedef struct {
77263 long counter;
77264 } atomic64_t;
77265+
77266+#ifdef CONFIG_PAX_REFCOUNT
77267+typedef struct {
77268+ long counter;
77269+} atomic64_unchecked_t;
77270+#else
77271+typedef atomic64_t atomic64_unchecked_t;
77272+#endif
77273 #endif
77274
77275 struct list_head {
77276diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
77277index 5ca0951..ab496a5 100644
77278--- a/include/linux/uaccess.h
77279+++ b/include/linux/uaccess.h
77280@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
77281 long ret; \
77282 mm_segment_t old_fs = get_fs(); \
77283 \
77284- set_fs(KERNEL_DS); \
77285 pagefault_disable(); \
77286- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
77287- pagefault_enable(); \
77288+ set_fs(KERNEL_DS); \
77289+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
77290 set_fs(old_fs); \
77291+ pagefault_enable(); \
77292 ret; \
77293 })
77294
77295diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
77296index 8e522cbc..aa8572d 100644
77297--- a/include/linux/uidgid.h
77298+++ b/include/linux/uidgid.h
77299@@ -197,4 +197,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
77300
77301 #endif /* CONFIG_USER_NS */
77302
77303+#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
77304+#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
77305+#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
77306+#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
77307+
77308 #endif /* _LINUX_UIDGID_H */
77309diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
77310index 99c1b4d..562e6f3 100644
77311--- a/include/linux/unaligned/access_ok.h
77312+++ b/include/linux/unaligned/access_ok.h
77313@@ -4,34 +4,34 @@
77314 #include <linux/kernel.h>
77315 #include <asm/byteorder.h>
77316
77317-static inline u16 get_unaligned_le16(const void *p)
77318+static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
77319 {
77320- return le16_to_cpup((__le16 *)p);
77321+ return le16_to_cpup((const __le16 *)p);
77322 }
77323
77324-static inline u32 get_unaligned_le32(const void *p)
77325+static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
77326 {
77327- return le32_to_cpup((__le32 *)p);
77328+ return le32_to_cpup((const __le32 *)p);
77329 }
77330
77331-static inline u64 get_unaligned_le64(const void *p)
77332+static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
77333 {
77334- return le64_to_cpup((__le64 *)p);
77335+ return le64_to_cpup((const __le64 *)p);
77336 }
77337
77338-static inline u16 get_unaligned_be16(const void *p)
77339+static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
77340 {
77341- return be16_to_cpup((__be16 *)p);
77342+ return be16_to_cpup((const __be16 *)p);
77343 }
77344
77345-static inline u32 get_unaligned_be32(const void *p)
77346+static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
77347 {
77348- return be32_to_cpup((__be32 *)p);
77349+ return be32_to_cpup((const __be32 *)p);
77350 }
77351
77352-static inline u64 get_unaligned_be64(const void *p)
77353+static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
77354 {
77355- return be64_to_cpup((__be64 *)p);
77356+ return be64_to_cpup((const __be64 *)p);
77357 }
77358
77359 static inline void put_unaligned_le16(u16 val, void *p)
77360diff --git a/include/linux/usb.h b/include/linux/usb.h
77361index 0eec268..4496526 100644
77362--- a/include/linux/usb.h
77363+++ b/include/linux/usb.h
77364@@ -560,7 +560,7 @@ struct usb_device {
77365 int maxchild;
77366
77367 u32 quirks;
77368- atomic_t urbnum;
77369+ atomic_unchecked_t urbnum;
77370
77371 unsigned long active_duration;
77372
77373@@ -1617,7 +1617,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
77374
77375 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
77376 __u8 request, __u8 requesttype, __u16 value, __u16 index,
77377- void *data, __u16 size, int timeout);
77378+ void *data, __u16 size, int timeout) __intentional_overflow(-1);
77379 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
77380 void *data, int len, int *actual_length, int timeout);
77381 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
77382diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
77383index e452ba6..78f8e80 100644
77384--- a/include/linux/usb/renesas_usbhs.h
77385+++ b/include/linux/usb/renesas_usbhs.h
77386@@ -39,7 +39,7 @@ enum {
77387 */
77388 struct renesas_usbhs_driver_callback {
77389 int (*notify_hotplug)(struct platform_device *pdev);
77390-};
77391+} __no_const;
77392
77393 /*
77394 * callback functions for platform
77395diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
77396index 6f8fbcf..8259001 100644
77397--- a/include/linux/vermagic.h
77398+++ b/include/linux/vermagic.h
77399@@ -25,9 +25,35 @@
77400 #define MODULE_ARCH_VERMAGIC ""
77401 #endif
77402
77403+#ifdef CONFIG_PAX_REFCOUNT
77404+#define MODULE_PAX_REFCOUNT "REFCOUNT "
77405+#else
77406+#define MODULE_PAX_REFCOUNT ""
77407+#endif
77408+
77409+#ifdef CONSTIFY_PLUGIN
77410+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
77411+#else
77412+#define MODULE_CONSTIFY_PLUGIN ""
77413+#endif
77414+
77415+#ifdef STACKLEAK_PLUGIN
77416+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
77417+#else
77418+#define MODULE_STACKLEAK_PLUGIN ""
77419+#endif
77420+
77421+#ifdef CONFIG_GRKERNSEC
77422+#define MODULE_GRSEC "GRSEC "
77423+#else
77424+#define MODULE_GRSEC ""
77425+#endif
77426+
77427 #define VERMAGIC_STRING \
77428 UTS_RELEASE " " \
77429 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
77430 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
77431- MODULE_ARCH_VERMAGIC
77432+ MODULE_ARCH_VERMAGIC \
77433+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
77434+ MODULE_GRSEC
77435
77436diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
77437index 4b8a891..c20e936 100644
77438--- a/include/linux/vmalloc.h
77439+++ b/include/linux/vmalloc.h
77440@@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
77441 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
77442 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
77443 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
77444+
77445+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
77446+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
77447+#endif
77448+
77449 /* bits [20..32] reserved for arch specific ioremap internals */
77450
77451 /*
77452@@ -75,7 +80,7 @@ extern void *vmalloc_32_user(unsigned long size);
77453 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
77454 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
77455 unsigned long start, unsigned long end, gfp_t gfp_mask,
77456- pgprot_t prot, int node, const void *caller);
77457+ pgprot_t prot, int node, const void *caller) __size_overflow(1);
77458 extern void vfree(const void *addr);
77459
77460 extern void *vmap(struct page **pages, unsigned int count,
77461@@ -141,8 +146,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
77462 extern void free_vm_area(struct vm_struct *area);
77463
77464 /* for /dev/kmem */
77465-extern long vread(char *buf, char *addr, unsigned long count);
77466-extern long vwrite(char *buf, char *addr, unsigned long count);
77467+extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
77468+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
77469
77470 /*
77471 * Internals. Dont't use..
77472diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
77473index c586679..f06b389 100644
77474--- a/include/linux/vmstat.h
77475+++ b/include/linux/vmstat.h
77476@@ -90,18 +90,18 @@ static inline void vm_events_fold_cpu(int cpu)
77477 /*
77478 * Zone based page accounting with per cpu differentials.
77479 */
77480-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
77481+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
77482
77483 static inline void zone_page_state_add(long x, struct zone *zone,
77484 enum zone_stat_item item)
77485 {
77486- atomic_long_add(x, &zone->vm_stat[item]);
77487- atomic_long_add(x, &vm_stat[item]);
77488+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
77489+ atomic_long_add_unchecked(x, &vm_stat[item]);
77490 }
77491
77492 static inline unsigned long global_page_state(enum zone_stat_item item)
77493 {
77494- long x = atomic_long_read(&vm_stat[item]);
77495+ long x = atomic_long_read_unchecked(&vm_stat[item]);
77496 #ifdef CONFIG_SMP
77497 if (x < 0)
77498 x = 0;
77499@@ -112,7 +112,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
77500 static inline unsigned long zone_page_state(struct zone *zone,
77501 enum zone_stat_item item)
77502 {
77503- long x = atomic_long_read(&zone->vm_stat[item]);
77504+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
77505 #ifdef CONFIG_SMP
77506 if (x < 0)
77507 x = 0;
77508@@ -129,7 +129,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
77509 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
77510 enum zone_stat_item item)
77511 {
77512- long x = atomic_long_read(&zone->vm_stat[item]);
77513+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
77514
77515 #ifdef CONFIG_SMP
77516 int cpu;
77517@@ -221,8 +221,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
77518
77519 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
77520 {
77521- atomic_long_inc(&zone->vm_stat[item]);
77522- atomic_long_inc(&vm_stat[item]);
77523+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
77524+ atomic_long_inc_unchecked(&vm_stat[item]);
77525 }
77526
77527 static inline void __inc_zone_page_state(struct page *page,
77528@@ -233,8 +233,8 @@ static inline void __inc_zone_page_state(struct page *page,
77529
77530 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
77531 {
77532- atomic_long_dec(&zone->vm_stat[item]);
77533- atomic_long_dec(&vm_stat[item]);
77534+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
77535+ atomic_long_dec_unchecked(&vm_stat[item]);
77536 }
77537
77538 static inline void __dec_zone_page_state(struct page *page,
77539diff --git a/include/linux/xattr.h b/include/linux/xattr.h
77540index fdbafc6..49dfe4f 100644
77541--- a/include/linux/xattr.h
77542+++ b/include/linux/xattr.h
77543@@ -28,7 +28,7 @@ struct xattr_handler {
77544 size_t size, int handler_flags);
77545 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
77546 size_t size, int flags, int handler_flags);
77547-};
77548+} __do_const;
77549
77550 struct xattr {
77551 char *name;
77552@@ -37,6 +37,9 @@ struct xattr {
77553 };
77554
77555 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
77556+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
77557+ssize_t pax_getxattr(struct dentry *, void *, size_t);
77558+#endif
77559 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
77560 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
77561 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
77562diff --git a/include/linux/zlib.h b/include/linux/zlib.h
77563index 9c5a6b4..09c9438 100644
77564--- a/include/linux/zlib.h
77565+++ b/include/linux/zlib.h
77566@@ -31,6 +31,7 @@
77567 #define _ZLIB_H
77568
77569 #include <linux/zconf.h>
77570+#include <linux/compiler.h>
77571
77572 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
77573 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
77574@@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
77575
77576 /* basic functions */
77577
77578-extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
77579+extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
77580 /*
77581 Returns the number of bytes that needs to be allocated for a per-
77582 stream workspace with the specified parameters. A pointer to this
77583diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
77584index c768c9f..bdcaa5a 100644
77585--- a/include/media/v4l2-dev.h
77586+++ b/include/media/v4l2-dev.h
77587@@ -76,7 +76,7 @@ struct v4l2_file_operations {
77588 int (*mmap) (struct file *, struct vm_area_struct *);
77589 int (*open) (struct file *);
77590 int (*release) (struct file *);
77591-};
77592+} __do_const;
77593
77594 /*
77595 * Newer version of video_device, handled by videodev2.c
77596diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
77597index c9b1593..a572459 100644
77598--- a/include/media/v4l2-device.h
77599+++ b/include/media/v4l2-device.h
77600@@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
77601 this function returns 0. If the name ends with a digit (e.g. cx18),
77602 then the name will be set to cx18-0 since cx180 looks really odd. */
77603 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
77604- atomic_t *instance);
77605+ atomic_unchecked_t *instance);
77606
77607 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
77608 Since the parent disappears this ensures that v4l2_dev doesn't have an
77609diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
77610index d9fa68f..45c88d1 100644
77611--- a/include/net/9p/transport.h
77612+++ b/include/net/9p/transport.h
77613@@ -63,7 +63,7 @@ struct p9_trans_module {
77614 int (*cancelled)(struct p9_client *, struct p9_req_t *req);
77615 int (*zc_request)(struct p9_client *, struct p9_req_t *,
77616 char *, char *, int , int, int, int);
77617-};
77618+} __do_const;
77619
77620 void v9fs_register_trans(struct p9_trans_module *m);
77621 void v9fs_unregister_trans(struct p9_trans_module *m);
77622diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
77623index 1a966af..2767cf6 100644
77624--- a/include/net/bluetooth/l2cap.h
77625+++ b/include/net/bluetooth/l2cap.h
77626@@ -551,7 +551,7 @@ struct l2cap_ops {
77627 void (*defer) (struct l2cap_chan *chan);
77628 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
77629 unsigned long len, int nb);
77630-};
77631+} __do_const;
77632
77633 struct l2cap_conn {
77634 struct hci_conn *hcon;
77635diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
77636index f2ae33d..c457cf0 100644
77637--- a/include/net/caif/cfctrl.h
77638+++ b/include/net/caif/cfctrl.h
77639@@ -52,7 +52,7 @@ struct cfctrl_rsp {
77640 void (*radioset_rsp)(void);
77641 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
77642 struct cflayer *client_layer);
77643-};
77644+} __no_const;
77645
77646 /* Link Setup Parameters for CAIF-Links. */
77647 struct cfctrl_link_param {
77648@@ -101,8 +101,8 @@ struct cfctrl_request_info {
77649 struct cfctrl {
77650 struct cfsrvl serv;
77651 struct cfctrl_rsp res;
77652- atomic_t req_seq_no;
77653- atomic_t rsp_seq_no;
77654+ atomic_unchecked_t req_seq_no;
77655+ atomic_unchecked_t rsp_seq_no;
77656 struct list_head list;
77657 /* Protects from simultaneous access to first_req list */
77658 spinlock_t info_list_lock;
77659diff --git a/include/net/flow.h b/include/net/flow.h
77660index 628e11b..4c475df 100644
77661--- a/include/net/flow.h
77662+++ b/include/net/flow.h
77663@@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
77664
77665 extern void flow_cache_flush(void);
77666 extern void flow_cache_flush_deferred(void);
77667-extern atomic_t flow_cache_genid;
77668+extern atomic_unchecked_t flow_cache_genid;
77669
77670 #endif
77671diff --git a/include/net/genetlink.h b/include/net/genetlink.h
77672index 8e0b6c8..73cf605 100644
77673--- a/include/net/genetlink.h
77674+++ b/include/net/genetlink.h
77675@@ -120,7 +120,7 @@ struct genl_ops {
77676 struct netlink_callback *cb);
77677 int (*done)(struct netlink_callback *cb);
77678 struct list_head ops_list;
77679-};
77680+} __do_const;
77681
77682 extern int __genl_register_family(struct genl_family *family);
77683
77684diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
77685index 734d9b5..48a9a4b 100644
77686--- a/include/net/gro_cells.h
77687+++ b/include/net/gro_cells.h
77688@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
77689 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
77690
77691 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
77692- atomic_long_inc(&dev->rx_dropped);
77693+ atomic_long_inc_unchecked(&dev->rx_dropped);
77694 kfree_skb(skb);
77695 return;
77696 }
77697diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
77698index de2c785..0588a6b 100644
77699--- a/include/net/inet_connection_sock.h
77700+++ b/include/net/inet_connection_sock.h
77701@@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
77702 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
77703 int (*bind_conflict)(const struct sock *sk,
77704 const struct inet_bind_bucket *tb, bool relax);
77705-};
77706+} __do_const;
77707
77708 /** inet_connection_sock - INET connection oriented sock
77709 *
77710diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
77711index 53f464d..0bd0b49 100644
77712--- a/include/net/inetpeer.h
77713+++ b/include/net/inetpeer.h
77714@@ -47,8 +47,8 @@ struct inet_peer {
77715 */
77716 union {
77717 struct {
77718- atomic_t rid; /* Frag reception counter */
77719- atomic_t ip_id_count; /* IP ID for the next packet */
77720+ atomic_unchecked_t rid; /* Frag reception counter */
77721+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
77722 };
77723 struct rcu_head rcu;
77724 struct inet_peer *gc_next;
77725@@ -178,16 +178,13 @@ static inline void inet_peer_refcheck(const struct inet_peer *p)
77726 /* can be called with or without local BH being disabled */
77727 static inline int inet_getid(struct inet_peer *p, int more)
77728 {
77729- int old, new;
77730+ int id;
77731 more++;
77732 inet_peer_refcheck(p);
77733- do {
77734- old = atomic_read(&p->ip_id_count);
77735- new = old + more;
77736- if (!new)
77737- new = 1;
77738- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
77739- return new;
77740+ id = atomic_add_return_unchecked(more, &p->ip_id_count);
77741+ if (!id)
77742+ id = atomic_inc_return_unchecked(&p->ip_id_count);
77743+ return id;
77744 }
77745
77746 #endif /* _NET_INETPEER_H */
77747diff --git a/include/net/ip.h b/include/net/ip.h
77748index a68f838..74518ab 100644
77749--- a/include/net/ip.h
77750+++ b/include/net/ip.h
77751@@ -202,7 +202,7 @@ extern struct local_ports {
77752 } sysctl_local_ports;
77753 extern void inet_get_local_port_range(int *low, int *high);
77754
77755-extern unsigned long *sysctl_local_reserved_ports;
77756+extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
77757 static inline int inet_is_reserved_local_port(int port)
77758 {
77759 return test_bit(port, sysctl_local_reserved_ports);
77760diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
77761index cbf2be3..3683f6d 100644
77762--- a/include/net/ip_fib.h
77763+++ b/include/net/ip_fib.h
77764@@ -169,7 +169,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
77765
77766 #define FIB_RES_SADDR(net, res) \
77767 ((FIB_RES_NH(res).nh_saddr_genid == \
77768- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
77769+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
77770 FIB_RES_NH(res).nh_saddr : \
77771 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
77772 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
77773diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
77774index f0d70f0..185f15b 100644
77775--- a/include/net/ip_vs.h
77776+++ b/include/net/ip_vs.h
77777@@ -588,7 +588,7 @@ struct ip_vs_conn {
77778 struct ip_vs_conn *control; /* Master control connection */
77779 atomic_t n_control; /* Number of controlled ones */
77780 struct ip_vs_dest *dest; /* real server */
77781- atomic_t in_pkts; /* incoming packet counter */
77782+ atomic_unchecked_t in_pkts; /* incoming packet counter */
77783
77784 /* packet transmitter for different forwarding methods. If it
77785 mangles the packet, it must return NF_DROP or better NF_STOLEN,
77786@@ -737,7 +737,7 @@ struct ip_vs_dest {
77787 __be16 port; /* port number of the server */
77788 union nf_inet_addr addr; /* IP address of the server */
77789 volatile unsigned int flags; /* dest status flags */
77790- atomic_t conn_flags; /* flags to copy to conn */
77791+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
77792 atomic_t weight; /* server weight */
77793
77794 atomic_t refcnt; /* reference counter */
77795@@ -993,11 +993,11 @@ struct netns_ipvs {
77796 /* ip_vs_lblc */
77797 int sysctl_lblc_expiration;
77798 struct ctl_table_header *lblc_ctl_header;
77799- struct ctl_table *lblc_ctl_table;
77800+ ctl_table_no_const *lblc_ctl_table;
77801 /* ip_vs_lblcr */
77802 int sysctl_lblcr_expiration;
77803 struct ctl_table_header *lblcr_ctl_header;
77804- struct ctl_table *lblcr_ctl_table;
77805+ ctl_table_no_const *lblcr_ctl_table;
77806 /* ip_vs_est */
77807 struct list_head est_list; /* estimator list */
77808 spinlock_t est_lock;
77809diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
77810index 80ffde3..968b0f4 100644
77811--- a/include/net/irda/ircomm_tty.h
77812+++ b/include/net/irda/ircomm_tty.h
77813@@ -35,6 +35,7 @@
77814 #include <linux/termios.h>
77815 #include <linux/timer.h>
77816 #include <linux/tty.h> /* struct tty_struct */
77817+#include <asm/local.h>
77818
77819 #include <net/irda/irias_object.h>
77820 #include <net/irda/ircomm_core.h>
77821diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
77822index 714cc9a..ea05f3e 100644
77823--- a/include/net/iucv/af_iucv.h
77824+++ b/include/net/iucv/af_iucv.h
77825@@ -149,7 +149,7 @@ struct iucv_skb_cb {
77826 struct iucv_sock_list {
77827 struct hlist_head head;
77828 rwlock_t lock;
77829- atomic_t autobind_name;
77830+ atomic_unchecked_t autobind_name;
77831 };
77832
77833 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
77834diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
77835index df83f69..9b640b8 100644
77836--- a/include/net/llc_c_ac.h
77837+++ b/include/net/llc_c_ac.h
77838@@ -87,7 +87,7 @@
77839 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
77840 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
77841
77842-typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
77843+typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
77844
77845 extern int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
77846 extern int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
77847diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
77848index 6ca3113..f8026dd 100644
77849--- a/include/net/llc_c_ev.h
77850+++ b/include/net/llc_c_ev.h
77851@@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
77852 return (struct llc_conn_state_ev *)skb->cb;
77853 }
77854
77855-typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
77856-typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
77857+typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
77858+typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
77859
77860 extern int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
77861 extern int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
77862diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
77863index 0e79cfb..f46db31 100644
77864--- a/include/net/llc_c_st.h
77865+++ b/include/net/llc_c_st.h
77866@@ -37,7 +37,7 @@ struct llc_conn_state_trans {
77867 u8 next_state;
77868 llc_conn_ev_qfyr_t *ev_qualifiers;
77869 llc_conn_action_t *ev_actions;
77870-};
77871+} __do_const;
77872
77873 struct llc_conn_state {
77874 u8 current_state;
77875diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
77876index 37a3bbd..55a4241 100644
77877--- a/include/net/llc_s_ac.h
77878+++ b/include/net/llc_s_ac.h
77879@@ -23,7 +23,7 @@
77880 #define SAP_ACT_TEST_IND 9
77881
77882 /* All action functions must look like this */
77883-typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
77884+typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
77885
77886 extern int llc_sap_action_unitdata_ind(struct llc_sap *sap,
77887 struct sk_buff *skb);
77888diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
77889index 567c681..cd73ac0 100644
77890--- a/include/net/llc_s_st.h
77891+++ b/include/net/llc_s_st.h
77892@@ -20,7 +20,7 @@ struct llc_sap_state_trans {
77893 llc_sap_ev_t ev;
77894 u8 next_state;
77895 llc_sap_action_t *ev_actions;
77896-};
77897+} __do_const;
77898
77899 struct llc_sap_state {
77900 u8 curr_state;
77901diff --git a/include/net/mac80211.h b/include/net/mac80211.h
77902index 551ba6a..11c99c1 100644
77903--- a/include/net/mac80211.h
77904+++ b/include/net/mac80211.h
77905@@ -4221,7 +4221,7 @@ struct rate_control_ops {
77906 void (*add_sta_debugfs)(void *priv, void *priv_sta,
77907 struct dentry *dir);
77908 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
77909-};
77910+} __do_const;
77911
77912 static inline int rate_supported(struct ieee80211_sta *sta,
77913 enum ieee80211_band band,
77914diff --git a/include/net/neighbour.h b/include/net/neighbour.h
77915index 7e748ad..5c6229b 100644
77916--- a/include/net/neighbour.h
77917+++ b/include/net/neighbour.h
77918@@ -123,7 +123,7 @@ struct neigh_ops {
77919 void (*error_report)(struct neighbour *, struct sk_buff *);
77920 int (*output)(struct neighbour *, struct sk_buff *);
77921 int (*connected_output)(struct neighbour *, struct sk_buff *);
77922-};
77923+} __do_const;
77924
77925 struct pneigh_entry {
77926 struct pneigh_entry *next;
77927diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
77928index 84e37b1..8eba19a 100644
77929--- a/include/net/net_namespace.h
77930+++ b/include/net/net_namespace.h
77931@@ -119,8 +119,8 @@ struct net {
77932 struct netns_ipvs *ipvs;
77933 #endif
77934 struct sock *diag_nlsk;
77935- atomic_t rt_genid;
77936- atomic_t fnhe_genid;
77937+ atomic_unchecked_t rt_genid;
77938+ atomic_unchecked_t fnhe_genid;
77939 };
77940
77941 /*
77942@@ -277,7 +277,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
77943 #define __net_init __init
77944 #define __net_exit __exit_refok
77945 #define __net_initdata __initdata
77946+#ifdef CONSTIFY_PLUGIN
77947 #define __net_initconst __initconst
77948+#else
77949+#define __net_initconst __initdata
77950+#endif
77951 #endif
77952
77953 struct pernet_operations {
77954@@ -287,7 +291,7 @@ struct pernet_operations {
77955 void (*exit_batch)(struct list_head *net_exit_list);
77956 int *id;
77957 size_t size;
77958-};
77959+} __do_const;
77960
77961 /*
77962 * Use these carefully. If you implement a network device and it
77963@@ -335,22 +339,22 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
77964
77965 static inline int rt_genid(struct net *net)
77966 {
77967- return atomic_read(&net->rt_genid);
77968+ return atomic_read_unchecked(&net->rt_genid);
77969 }
77970
77971 static inline void rt_genid_bump(struct net *net)
77972 {
77973- atomic_inc(&net->rt_genid);
77974+ atomic_inc_unchecked(&net->rt_genid);
77975 }
77976
77977 static inline int fnhe_genid(struct net *net)
77978 {
77979- return atomic_read(&net->fnhe_genid);
77980+ return atomic_read_unchecked(&net->fnhe_genid);
77981 }
77982
77983 static inline void fnhe_genid_bump(struct net *net)
77984 {
77985- atomic_inc(&net->fnhe_genid);
77986+ atomic_inc_unchecked(&net->fnhe_genid);
77987 }
77988
77989 #endif /* __NET_NET_NAMESPACE_H */
77990diff --git a/include/net/netdma.h b/include/net/netdma.h
77991index 8ba8ce2..99b7fff 100644
77992--- a/include/net/netdma.h
77993+++ b/include/net/netdma.h
77994@@ -24,7 +24,7 @@
77995 #include <linux/dmaengine.h>
77996 #include <linux/skbuff.h>
77997
77998-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
77999+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
78000 struct sk_buff *skb, int offset, struct iovec *to,
78001 size_t len, struct dma_pinned_list *pinned_list);
78002
78003diff --git a/include/net/netlink.h b/include/net/netlink.h
78004index 9690b0f..87aded7 100644
78005--- a/include/net/netlink.h
78006+++ b/include/net/netlink.h
78007@@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
78008 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
78009 {
78010 if (mark)
78011- skb_trim(skb, (unsigned char *) mark - skb->data);
78012+ skb_trim(skb, (const unsigned char *) mark - skb->data);
78013 }
78014
78015 /**
78016diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
78017index c9c0c53..53f24c3 100644
78018--- a/include/net/netns/conntrack.h
78019+++ b/include/net/netns/conntrack.h
78020@@ -12,10 +12,10 @@ struct nf_conntrack_ecache;
78021 struct nf_proto_net {
78022 #ifdef CONFIG_SYSCTL
78023 struct ctl_table_header *ctl_table_header;
78024- struct ctl_table *ctl_table;
78025+ ctl_table_no_const *ctl_table;
78026 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
78027 struct ctl_table_header *ctl_compat_header;
78028- struct ctl_table *ctl_compat_table;
78029+ ctl_table_no_const *ctl_compat_table;
78030 #endif
78031 #endif
78032 unsigned int users;
78033@@ -58,7 +58,7 @@ struct nf_ip_net {
78034 struct nf_icmp_net icmpv6;
78035 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
78036 struct ctl_table_header *ctl_table_header;
78037- struct ctl_table *ctl_table;
78038+ ctl_table_no_const *ctl_table;
78039 #endif
78040 };
78041
78042diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
78043index 2ba9de8..47bd6c7 100644
78044--- a/include/net/netns/ipv4.h
78045+++ b/include/net/netns/ipv4.h
78046@@ -67,7 +67,7 @@ struct netns_ipv4 {
78047 kgid_t sysctl_ping_group_range[2];
78048 long sysctl_tcp_mem[3];
78049
78050- atomic_t dev_addr_genid;
78051+ atomic_unchecked_t dev_addr_genid;
78052
78053 #ifdef CONFIG_IP_MROUTE
78054 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
78055diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
78056index 005e2c2..023d340 100644
78057--- a/include/net/netns/ipv6.h
78058+++ b/include/net/netns/ipv6.h
78059@@ -71,7 +71,7 @@ struct netns_ipv6 {
78060 struct fib_rules_ops *mr6_rules_ops;
78061 #endif
78062 #endif
78063- atomic_t dev_addr_genid;
78064+ atomic_unchecked_t dev_addr_genid;
78065 };
78066
78067 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
78068diff --git a/include/net/ping.h b/include/net/ping.h
78069index 5db0224..0d65365 100644
78070--- a/include/net/ping.h
78071+++ b/include/net/ping.h
78072@@ -55,7 +55,7 @@ struct ping_iter_state {
78073 extern struct proto ping_prot;
78074 extern struct ping_table ping_table;
78075 #if IS_ENABLED(CONFIG_IPV6)
78076-extern struct pingv6_ops pingv6_ops;
78077+extern struct pingv6_ops *pingv6_ops;
78078 #endif
78079
78080 struct pingfakehdr {
78081diff --git a/include/net/protocol.h b/include/net/protocol.h
78082index 047c047..b9dad15 100644
78083--- a/include/net/protocol.h
78084+++ b/include/net/protocol.h
78085@@ -44,7 +44,7 @@ struct net_protocol {
78086 void (*err_handler)(struct sk_buff *skb, u32 info);
78087 unsigned int no_policy:1,
78088 netns_ok:1;
78089-};
78090+} __do_const;
78091
78092 #if IS_ENABLED(CONFIG_IPV6)
78093 struct inet6_protocol {
78094@@ -57,7 +57,7 @@ struct inet6_protocol {
78095 u8 type, u8 code, int offset,
78096 __be32 info);
78097 unsigned int flags; /* INET6_PROTO_xxx */
78098-};
78099+} __do_const;
78100
78101 #define INET6_PROTO_NOPOLICY 0x1
78102 #define INET6_PROTO_FINAL 0x2
78103diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
78104index 7026648..584cc8c 100644
78105--- a/include/net/rtnetlink.h
78106+++ b/include/net/rtnetlink.h
78107@@ -81,7 +81,7 @@ struct rtnl_link_ops {
78108 const struct net_device *dev);
78109 unsigned int (*get_num_tx_queues)(void);
78110 unsigned int (*get_num_rx_queues)(void);
78111-};
78112+} __do_const;
78113
78114 extern int __rtnl_link_register(struct rtnl_link_ops *ops);
78115 extern void __rtnl_link_unregister(struct rtnl_link_ops *ops);
78116diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
78117index 2a82d13..62a31c2 100644
78118--- a/include/net/sctp/sm.h
78119+++ b/include/net/sctp/sm.h
78120@@ -87,7 +87,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
78121 typedef struct {
78122 sctp_state_fn_t *fn;
78123 const char *name;
78124-} sctp_sm_table_entry_t;
78125+} __do_const sctp_sm_table_entry_t;
78126
78127 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
78128 * currently in use.
78129@@ -299,7 +299,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
78130 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
78131
78132 /* Extern declarations for major data structures. */
78133-extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
78134+extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
78135
78136
78137 /* Get the size of a DATA chunk payload. */
78138diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
78139index e745c92..3641448 100644
78140--- a/include/net/sctp/structs.h
78141+++ b/include/net/sctp/structs.h
78142@@ -516,7 +516,7 @@ struct sctp_pf {
78143 struct sctp_association *asoc);
78144 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
78145 struct sctp_af *af;
78146-};
78147+} __do_const;
78148
78149
78150 /* Structure to track chunk fragments that have been acked, but peer
78151diff --git a/include/net/sock.h b/include/net/sock.h
78152index 31d5cfb..9ee0602 100644
78153--- a/include/net/sock.h
78154+++ b/include/net/sock.h
78155@@ -331,7 +331,7 @@ struct sock {
78156 unsigned int sk_napi_id;
78157 unsigned int sk_ll_usec;
78158 #endif
78159- atomic_t sk_drops;
78160+ atomic_unchecked_t sk_drops;
78161 int sk_rcvbuf;
78162
78163 struct sk_filter __rcu *sk_filter;
78164@@ -1803,7 +1803,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
78165 }
78166
78167 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
78168- char __user *from, char *to,
78169+ char __user *from, unsigned char *to,
78170 int copy, int offset)
78171 {
78172 if (skb->ip_summed == CHECKSUM_NONE) {
78173@@ -2065,7 +2065,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
78174 }
78175 }
78176
78177-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
78178+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
78179
78180 /**
78181 * sk_page_frag - return an appropriate page_frag
78182diff --git a/include/net/tcp.h b/include/net/tcp.h
78183index d198005..c974a393 100644
78184--- a/include/net/tcp.h
78185+++ b/include/net/tcp.h
78186@@ -521,7 +521,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
78187 extern void tcp_xmit_retransmit_queue(struct sock *);
78188 extern void tcp_simple_retransmit(struct sock *);
78189 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
78190-extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
78191+extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
78192
78193 extern void tcp_send_probe0(struct sock *);
78194 extern void tcp_send_partial(struct sock *);
78195@@ -694,8 +694,8 @@ struct tcp_skb_cb {
78196 struct inet6_skb_parm h6;
78197 #endif
78198 } header; /* For incoming frames */
78199- __u32 seq; /* Starting sequence number */
78200- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
78201+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
78202+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
78203 __u32 when; /* used to compute rtt's */
78204 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
78205
78206@@ -709,7 +709,7 @@ struct tcp_skb_cb {
78207
78208 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
78209 /* 1 byte hole */
78210- __u32 ack_seq; /* Sequence number ACK'd */
78211+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
78212 };
78213
78214 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
78215diff --git a/include/net/xfrm.h b/include/net/xfrm.h
78216index e823786..53b0608 100644
78217--- a/include/net/xfrm.h
78218+++ b/include/net/xfrm.h
78219@@ -287,7 +287,6 @@ struct xfrm_dst;
78220 struct xfrm_policy_afinfo {
78221 unsigned short family;
78222 struct dst_ops *dst_ops;
78223- void (*garbage_collect)(struct net *net);
78224 struct dst_entry *(*dst_lookup)(struct net *net, int tos,
78225 const xfrm_address_t *saddr,
78226 const xfrm_address_t *daddr);
78227@@ -305,7 +304,7 @@ struct xfrm_policy_afinfo {
78228 struct net_device *dev,
78229 const struct flowi *fl);
78230 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
78231-};
78232+} __do_const;
78233
78234 extern int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
78235 extern int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
78236@@ -342,7 +341,7 @@ struct xfrm_state_afinfo {
78237 int (*transport_finish)(struct sk_buff *skb,
78238 int async);
78239 void (*local_error)(struct sk_buff *skb, u32 mtu);
78240-};
78241+} __do_const;
78242
78243 extern int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
78244 extern int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
78245@@ -427,7 +426,7 @@ struct xfrm_mode {
78246 struct module *owner;
78247 unsigned int encap;
78248 int flags;
78249-};
78250+} __do_const;
78251
78252 /* Flags for xfrm_mode. */
78253 enum {
78254@@ -524,7 +523,7 @@ struct xfrm_policy {
78255 struct timer_list timer;
78256
78257 struct flow_cache_object flo;
78258- atomic_t genid;
78259+ atomic_unchecked_t genid;
78260 u32 priority;
78261 u32 index;
78262 struct xfrm_mark mark;
78263@@ -1164,6 +1163,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
78264 }
78265
78266 extern void xfrm_garbage_collect(struct net *net);
78267+extern void xfrm_garbage_collect_deferred(struct net *net);
78268
78269 #else
78270
78271@@ -1202,6 +1202,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
78272 static inline void xfrm_garbage_collect(struct net *net)
78273 {
78274 }
78275+static inline void xfrm_garbage_collect_deferred(struct net *net)
78276+{
78277+}
78278 #endif
78279
78280 static __inline__
78281diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
78282index 1a046b1..ee0bef0 100644
78283--- a/include/rdma/iw_cm.h
78284+++ b/include/rdma/iw_cm.h
78285@@ -122,7 +122,7 @@ struct iw_cm_verbs {
78286 int backlog);
78287
78288 int (*destroy_listen)(struct iw_cm_id *cm_id);
78289-};
78290+} __no_const;
78291
78292 /**
78293 * iw_create_cm_id - Create an IW CM identifier.
78294diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
78295index e1379b4..67eafbe 100644
78296--- a/include/scsi/libfc.h
78297+++ b/include/scsi/libfc.h
78298@@ -762,6 +762,7 @@ struct libfc_function_template {
78299 */
78300 void (*disc_stop_final) (struct fc_lport *);
78301 };
78302+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
78303
78304 /**
78305 * struct fc_disc - Discovery context
78306@@ -866,7 +867,7 @@ struct fc_lport {
78307 struct fc_vport *vport;
78308
78309 /* Operational Information */
78310- struct libfc_function_template tt;
78311+ libfc_function_template_no_const tt;
78312 u8 link_up;
78313 u8 qfull;
78314 enum fc_lport_state state;
78315diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
78316index a44954c..5da04b2 100644
78317--- a/include/scsi/scsi_device.h
78318+++ b/include/scsi/scsi_device.h
78319@@ -172,9 +172,9 @@ struct scsi_device {
78320 unsigned int max_device_blocked; /* what device_blocked counts down from */
78321 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
78322
78323- atomic_t iorequest_cnt;
78324- atomic_t iodone_cnt;
78325- atomic_t ioerr_cnt;
78326+ atomic_unchecked_t iorequest_cnt;
78327+ atomic_unchecked_t iodone_cnt;
78328+ atomic_unchecked_t ioerr_cnt;
78329
78330 struct device sdev_gendev,
78331 sdev_dev;
78332diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
78333index b797e8f..8e2c3aa 100644
78334--- a/include/scsi/scsi_transport_fc.h
78335+++ b/include/scsi/scsi_transport_fc.h
78336@@ -751,7 +751,8 @@ struct fc_function_template {
78337 unsigned long show_host_system_hostname:1;
78338
78339 unsigned long disable_target_scan:1;
78340-};
78341+} __do_const;
78342+typedef struct fc_function_template __no_const fc_function_template_no_const;
78343
78344
78345 /**
78346diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
78347index 9031a26..750d592 100644
78348--- a/include/sound/compress_driver.h
78349+++ b/include/sound/compress_driver.h
78350@@ -128,7 +128,7 @@ struct snd_compr_ops {
78351 struct snd_compr_caps *caps);
78352 int (*get_codec_caps) (struct snd_compr_stream *stream,
78353 struct snd_compr_codec_caps *codec);
78354-};
78355+} __no_const;
78356
78357 /**
78358 * struct snd_compr: Compressed device
78359diff --git a/include/sound/soc.h b/include/sound/soc.h
78360index 6eabee7..58afb50 100644
78361--- a/include/sound/soc.h
78362+++ b/include/sound/soc.h
78363@@ -783,7 +783,7 @@ struct snd_soc_codec_driver {
78364 /* probe ordering - for components with runtime dependencies */
78365 int probe_order;
78366 int remove_order;
78367-};
78368+} __do_const;
78369
78370 /* SoC platform interface */
78371 struct snd_soc_platform_driver {
78372@@ -829,7 +829,7 @@ struct snd_soc_platform_driver {
78373 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
78374 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
78375 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
78376-};
78377+} __do_const;
78378
78379 struct snd_soc_platform {
78380 const char *name;
78381diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
78382index e34fc90..ecefa2c 100644
78383--- a/include/target/target_core_base.h
78384+++ b/include/target/target_core_base.h
78385@@ -643,7 +643,7 @@ struct se_device {
78386 spinlock_t stats_lock;
78387 /* Active commands on this virtual SE device */
78388 atomic_t simple_cmds;
78389- atomic_t dev_ordered_id;
78390+ atomic_unchecked_t dev_ordered_id;
78391 atomic_t dev_ordered_sync;
78392 atomic_t dev_qf_count;
78393 int export_count;
78394diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
78395new file mode 100644
78396index 0000000..fb634b7
78397--- /dev/null
78398+++ b/include/trace/events/fs.h
78399@@ -0,0 +1,53 @@
78400+#undef TRACE_SYSTEM
78401+#define TRACE_SYSTEM fs
78402+
78403+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
78404+#define _TRACE_FS_H
78405+
78406+#include <linux/fs.h>
78407+#include <linux/tracepoint.h>
78408+
78409+TRACE_EVENT(do_sys_open,
78410+
78411+ TP_PROTO(const char *filename, int flags, int mode),
78412+
78413+ TP_ARGS(filename, flags, mode),
78414+
78415+ TP_STRUCT__entry(
78416+ __string( filename, filename )
78417+ __field( int, flags )
78418+ __field( int, mode )
78419+ ),
78420+
78421+ TP_fast_assign(
78422+ __assign_str(filename, filename);
78423+ __entry->flags = flags;
78424+ __entry->mode = mode;
78425+ ),
78426+
78427+ TP_printk("\"%s\" %x %o",
78428+ __get_str(filename), __entry->flags, __entry->mode)
78429+);
78430+
78431+TRACE_EVENT(open_exec,
78432+
78433+ TP_PROTO(const char *filename),
78434+
78435+ TP_ARGS(filename),
78436+
78437+ TP_STRUCT__entry(
78438+ __string( filename, filename )
78439+ ),
78440+
78441+ TP_fast_assign(
78442+ __assign_str(filename, filename);
78443+ ),
78444+
78445+ TP_printk("\"%s\"",
78446+ __get_str(filename))
78447+);
78448+
78449+#endif /* _TRACE_FS_H */
78450+
78451+/* This part must be outside protection */
78452+#include <trace/define_trace.h>
78453diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
78454index 1c09820..7f5ec79 100644
78455--- a/include/trace/events/irq.h
78456+++ b/include/trace/events/irq.h
78457@@ -36,7 +36,7 @@ struct softirq_action;
78458 */
78459 TRACE_EVENT(irq_handler_entry,
78460
78461- TP_PROTO(int irq, struct irqaction *action),
78462+ TP_PROTO(int irq, const struct irqaction *action),
78463
78464 TP_ARGS(irq, action),
78465
78466@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
78467 */
78468 TRACE_EVENT(irq_handler_exit,
78469
78470- TP_PROTO(int irq, struct irqaction *action, int ret),
78471+ TP_PROTO(int irq, const struct irqaction *action, int ret),
78472
78473 TP_ARGS(irq, action, ret),
78474
78475diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
78476index 7caf44c..23c6f27 100644
78477--- a/include/uapi/linux/a.out.h
78478+++ b/include/uapi/linux/a.out.h
78479@@ -39,6 +39,14 @@ enum machine_type {
78480 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
78481 };
78482
78483+/* Constants for the N_FLAGS field */
78484+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
78485+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
78486+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
78487+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
78488+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
78489+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
78490+
78491 #if !defined (N_MAGIC)
78492 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
78493 #endif
78494diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
78495index d876736..ccce5c0 100644
78496--- a/include/uapi/linux/byteorder/little_endian.h
78497+++ b/include/uapi/linux/byteorder/little_endian.h
78498@@ -42,51 +42,51 @@
78499
78500 static inline __le64 __cpu_to_le64p(const __u64 *p)
78501 {
78502- return (__force __le64)*p;
78503+ return (__force const __le64)*p;
78504 }
78505-static inline __u64 __le64_to_cpup(const __le64 *p)
78506+static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
78507 {
78508- return (__force __u64)*p;
78509+ return (__force const __u64)*p;
78510 }
78511 static inline __le32 __cpu_to_le32p(const __u32 *p)
78512 {
78513- return (__force __le32)*p;
78514+ return (__force const __le32)*p;
78515 }
78516 static inline __u32 __le32_to_cpup(const __le32 *p)
78517 {
78518- return (__force __u32)*p;
78519+ return (__force const __u32)*p;
78520 }
78521 static inline __le16 __cpu_to_le16p(const __u16 *p)
78522 {
78523- return (__force __le16)*p;
78524+ return (__force const __le16)*p;
78525 }
78526 static inline __u16 __le16_to_cpup(const __le16 *p)
78527 {
78528- return (__force __u16)*p;
78529+ return (__force const __u16)*p;
78530 }
78531 static inline __be64 __cpu_to_be64p(const __u64 *p)
78532 {
78533- return (__force __be64)__swab64p(p);
78534+ return (__force const __be64)__swab64p(p);
78535 }
78536 static inline __u64 __be64_to_cpup(const __be64 *p)
78537 {
78538- return __swab64p((__u64 *)p);
78539+ return __swab64p((const __u64 *)p);
78540 }
78541 static inline __be32 __cpu_to_be32p(const __u32 *p)
78542 {
78543- return (__force __be32)__swab32p(p);
78544+ return (__force const __be32)__swab32p(p);
78545 }
78546-static inline __u32 __be32_to_cpup(const __be32 *p)
78547+static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
78548 {
78549- return __swab32p((__u32 *)p);
78550+ return __swab32p((const __u32 *)p);
78551 }
78552 static inline __be16 __cpu_to_be16p(const __u16 *p)
78553 {
78554- return (__force __be16)__swab16p(p);
78555+ return (__force const __be16)__swab16p(p);
78556 }
78557 static inline __u16 __be16_to_cpup(const __be16 *p)
78558 {
78559- return __swab16p((__u16 *)p);
78560+ return __swab16p((const __u16 *)p);
78561 }
78562 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
78563 #define __le64_to_cpus(x) do { (void)(x); } while (0)
78564diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
78565index ef6103b..d4e65dd 100644
78566--- a/include/uapi/linux/elf.h
78567+++ b/include/uapi/linux/elf.h
78568@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
78569 #define PT_GNU_EH_FRAME 0x6474e550
78570
78571 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
78572+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
78573+
78574+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
78575+
78576+/* Constants for the e_flags field */
78577+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
78578+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
78579+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
78580+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
78581+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
78582+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
78583
78584 /*
78585 * Extended Numbering
78586@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
78587 #define DT_DEBUG 21
78588 #define DT_TEXTREL 22
78589 #define DT_JMPREL 23
78590+#define DT_FLAGS 30
78591+ #define DF_TEXTREL 0x00000004
78592 #define DT_ENCODING 32
78593 #define OLD_DT_LOOS 0x60000000
78594 #define DT_LOOS 0x6000000d
78595@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
78596 #define PF_W 0x2
78597 #define PF_X 0x1
78598
78599+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
78600+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
78601+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
78602+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
78603+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
78604+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
78605+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
78606+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
78607+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
78608+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
78609+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
78610+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
78611+
78612 typedef struct elf32_phdr{
78613 Elf32_Word p_type;
78614 Elf32_Off p_offset;
78615@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
78616 #define EI_OSABI 7
78617 #define EI_PAD 8
78618
78619+#define EI_PAX 14
78620+
78621 #define ELFMAG0 0x7f /* EI_MAG */
78622 #define ELFMAG1 'E'
78623 #define ELFMAG2 'L'
78624diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
78625index aa169c4..6a2771d 100644
78626--- a/include/uapi/linux/personality.h
78627+++ b/include/uapi/linux/personality.h
78628@@ -30,6 +30,7 @@ enum {
78629 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
78630 ADDR_NO_RANDOMIZE | \
78631 ADDR_COMPAT_LAYOUT | \
78632+ ADDR_LIMIT_3GB | \
78633 MMAP_PAGE_ZERO)
78634
78635 /*
78636diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
78637index 7530e74..e714828 100644
78638--- a/include/uapi/linux/screen_info.h
78639+++ b/include/uapi/linux/screen_info.h
78640@@ -43,7 +43,8 @@ struct screen_info {
78641 __u16 pages; /* 0x32 */
78642 __u16 vesa_attributes; /* 0x34 */
78643 __u32 capabilities; /* 0x36 */
78644- __u8 _reserved[6]; /* 0x3a */
78645+ __u16 vesapm_size; /* 0x3a */
78646+ __u8 _reserved[4]; /* 0x3c */
78647 } __attribute__((packed));
78648
78649 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
78650diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
78651index 0e011eb..82681b1 100644
78652--- a/include/uapi/linux/swab.h
78653+++ b/include/uapi/linux/swab.h
78654@@ -43,7 +43,7 @@
78655 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
78656 */
78657
78658-static inline __attribute_const__ __u16 __fswab16(__u16 val)
78659+static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
78660 {
78661 #ifdef __HAVE_BUILTIN_BSWAP16__
78662 return __builtin_bswap16(val);
78663@@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
78664 #endif
78665 }
78666
78667-static inline __attribute_const__ __u32 __fswab32(__u32 val)
78668+static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
78669 {
78670 #ifdef __HAVE_BUILTIN_BSWAP32__
78671 return __builtin_bswap32(val);
78672@@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
78673 #endif
78674 }
78675
78676-static inline __attribute_const__ __u64 __fswab64(__u64 val)
78677+static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
78678 {
78679 #ifdef __HAVE_BUILTIN_BSWAP64__
78680 return __builtin_bswap64(val);
78681diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
78682index 6d67213..8dab561 100644
78683--- a/include/uapi/linux/sysctl.h
78684+++ b/include/uapi/linux/sysctl.h
78685@@ -155,7 +155,11 @@ enum
78686 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
78687 };
78688
78689-
78690+#ifdef CONFIG_PAX_SOFTMODE
78691+enum {
78692+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
78693+};
78694+#endif
78695
78696 /* CTL_VM names: */
78697 enum
78698diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
78699index e4629b9..6958086 100644
78700--- a/include/uapi/linux/xattr.h
78701+++ b/include/uapi/linux/xattr.h
78702@@ -63,5 +63,9 @@
78703 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
78704 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
78705
78706+/* User namespace */
78707+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
78708+#define XATTR_PAX_FLAGS_SUFFIX "flags"
78709+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
78710
78711 #endif /* _UAPI_LINUX_XATTR_H */
78712diff --git a/include/video/udlfb.h b/include/video/udlfb.h
78713index f9466fa..f4e2b81 100644
78714--- a/include/video/udlfb.h
78715+++ b/include/video/udlfb.h
78716@@ -53,10 +53,10 @@ struct dlfb_data {
78717 u32 pseudo_palette[256];
78718 int blank_mode; /*one of FB_BLANK_ */
78719 /* blit-only rendering path metrics, exposed through sysfs */
78720- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
78721- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
78722- atomic_t bytes_sent; /* to usb, after compression including overhead */
78723- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
78724+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
78725+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
78726+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
78727+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
78728 };
78729
78730 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
78731diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
78732index 30f5362..8ed8ac9 100644
78733--- a/include/video/uvesafb.h
78734+++ b/include/video/uvesafb.h
78735@@ -122,6 +122,7 @@ struct uvesafb_par {
78736 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
78737 u8 pmi_setpal; /* PMI for palette changes */
78738 u16 *pmi_base; /* protected mode interface location */
78739+ u8 *pmi_code; /* protected mode code location */
78740 void *pmi_start;
78741 void *pmi_pal;
78742 u8 *vbe_state_orig; /*
78743diff --git a/init/Kconfig b/init/Kconfig
78744index fed81b5..0d3b964 100644
78745--- a/init/Kconfig
78746+++ b/init/Kconfig
78747@@ -1069,6 +1069,7 @@ endif # CGROUPS
78748
78749 config CHECKPOINT_RESTORE
78750 bool "Checkpoint/restore support" if EXPERT
78751+ depends on !GRKERNSEC
78752 default n
78753 help
78754 Enables additional kernel features in a sake of checkpoint/restore.
78755@@ -1553,7 +1554,7 @@ config SLUB_DEBUG
78756
78757 config COMPAT_BRK
78758 bool "Disable heap randomization"
78759- default y
78760+ default n
78761 help
78762 Randomizing heap placement makes heap exploits harder, but it
78763 also breaks ancient binaries (including anything libc5 based).
78764@@ -1827,7 +1828,7 @@ config INIT_ALL_POSSIBLE
78765 config STOP_MACHINE
78766 bool
78767 default y
78768- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
78769+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
78770 help
78771 Need stop_machine() primitive.
78772
78773diff --git a/init/Makefile b/init/Makefile
78774index 7bc47ee..6da2dc7 100644
78775--- a/init/Makefile
78776+++ b/init/Makefile
78777@@ -2,6 +2,9 @@
78778 # Makefile for the linux kernel.
78779 #
78780
78781+ccflags-y := $(GCC_PLUGINS_CFLAGS)
78782+asflags-y := $(GCC_PLUGINS_AFLAGS)
78783+
78784 obj-y := main.o version.o mounts.o
78785 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
78786 obj-y += noinitramfs.o
78787diff --git a/init/do_mounts.c b/init/do_mounts.c
78788index 816014c..c2054db 100644
78789--- a/init/do_mounts.c
78790+++ b/init/do_mounts.c
78791@@ -355,11 +355,11 @@ static void __init get_fs_names(char *page)
78792 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
78793 {
78794 struct super_block *s;
78795- int err = sys_mount(name, "/root", fs, flags, data);
78796+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
78797 if (err)
78798 return err;
78799
78800- sys_chdir("/root");
78801+ sys_chdir((const char __force_user *)"/root");
78802 s = current->fs->pwd.dentry->d_sb;
78803 ROOT_DEV = s->s_dev;
78804 printk(KERN_INFO
78805@@ -480,18 +480,18 @@ void __init change_floppy(char *fmt, ...)
78806 va_start(args, fmt);
78807 vsprintf(buf, fmt, args);
78808 va_end(args);
78809- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
78810+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
78811 if (fd >= 0) {
78812 sys_ioctl(fd, FDEJECT, 0);
78813 sys_close(fd);
78814 }
78815 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
78816- fd = sys_open("/dev/console", O_RDWR, 0);
78817+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
78818 if (fd >= 0) {
78819 sys_ioctl(fd, TCGETS, (long)&termios);
78820 termios.c_lflag &= ~ICANON;
78821 sys_ioctl(fd, TCSETSF, (long)&termios);
78822- sys_read(fd, &c, 1);
78823+ sys_read(fd, (char __user *)&c, 1);
78824 termios.c_lflag |= ICANON;
78825 sys_ioctl(fd, TCSETSF, (long)&termios);
78826 sys_close(fd);
78827@@ -585,6 +585,6 @@ void __init prepare_namespace(void)
78828 mount_root();
78829 out:
78830 devtmpfs_mount("dev");
78831- sys_mount(".", "/", NULL, MS_MOVE, NULL);
78832- sys_chroot(".");
78833+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
78834+ sys_chroot((const char __force_user *)".");
78835 }
78836diff --git a/init/do_mounts.h b/init/do_mounts.h
78837index f5b978a..69dbfe8 100644
78838--- a/init/do_mounts.h
78839+++ b/init/do_mounts.h
78840@@ -15,15 +15,15 @@ extern int root_mountflags;
78841
78842 static inline int create_dev(char *name, dev_t dev)
78843 {
78844- sys_unlink(name);
78845- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
78846+ sys_unlink((char __force_user *)name);
78847+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
78848 }
78849
78850 #if BITS_PER_LONG == 32
78851 static inline u32 bstat(char *name)
78852 {
78853 struct stat64 stat;
78854- if (sys_stat64(name, &stat) != 0)
78855+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
78856 return 0;
78857 if (!S_ISBLK(stat.st_mode))
78858 return 0;
78859@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
78860 static inline u32 bstat(char *name)
78861 {
78862 struct stat stat;
78863- if (sys_newstat(name, &stat) != 0)
78864+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
78865 return 0;
78866 if (!S_ISBLK(stat.st_mode))
78867 return 0;
78868diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
78869index 3e0878e..8a9d7a0 100644
78870--- a/init/do_mounts_initrd.c
78871+++ b/init/do_mounts_initrd.c
78872@@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
78873 {
78874 sys_unshare(CLONE_FS | CLONE_FILES);
78875 /* stdin/stdout/stderr for /linuxrc */
78876- sys_open("/dev/console", O_RDWR, 0);
78877+ sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
78878 sys_dup(0);
78879 sys_dup(0);
78880 /* move initrd over / and chdir/chroot in initrd root */
78881- sys_chdir("/root");
78882- sys_mount(".", "/", NULL, MS_MOVE, NULL);
78883- sys_chroot(".");
78884+ sys_chdir((const char __force_user *)"/root");
78885+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
78886+ sys_chroot((const char __force_user *)".");
78887 sys_setsid();
78888 return 0;
78889 }
78890@@ -59,8 +59,8 @@ static void __init handle_initrd(void)
78891 create_dev("/dev/root.old", Root_RAM0);
78892 /* mount initrd on rootfs' /root */
78893 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
78894- sys_mkdir("/old", 0700);
78895- sys_chdir("/old");
78896+ sys_mkdir((const char __force_user *)"/old", 0700);
78897+ sys_chdir((const char __force_user *)"/old");
78898
78899 /* try loading default modules from initrd */
78900 load_default_modules();
78901@@ -80,31 +80,31 @@ static void __init handle_initrd(void)
78902 current->flags &= ~PF_FREEZER_SKIP;
78903
78904 /* move initrd to rootfs' /old */
78905- sys_mount("..", ".", NULL, MS_MOVE, NULL);
78906+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
78907 /* switch root and cwd back to / of rootfs */
78908- sys_chroot("..");
78909+ sys_chroot((const char __force_user *)"..");
78910
78911 if (new_decode_dev(real_root_dev) == Root_RAM0) {
78912- sys_chdir("/old");
78913+ sys_chdir((const char __force_user *)"/old");
78914 return;
78915 }
78916
78917- sys_chdir("/");
78918+ sys_chdir((const char __force_user *)"/");
78919 ROOT_DEV = new_decode_dev(real_root_dev);
78920 mount_root();
78921
78922 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
78923- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
78924+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
78925 if (!error)
78926 printk("okay\n");
78927 else {
78928- int fd = sys_open("/dev/root.old", O_RDWR, 0);
78929+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
78930 if (error == -ENOENT)
78931 printk("/initrd does not exist. Ignored.\n");
78932 else
78933 printk("failed\n");
78934 printk(KERN_NOTICE "Unmounting old root\n");
78935- sys_umount("/old", MNT_DETACH);
78936+ sys_umount((char __force_user *)"/old", MNT_DETACH);
78937 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
78938 if (fd < 0) {
78939 error = fd;
78940@@ -127,11 +127,11 @@ int __init initrd_load(void)
78941 * mounted in the normal path.
78942 */
78943 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
78944- sys_unlink("/initrd.image");
78945+ sys_unlink((const char __force_user *)"/initrd.image");
78946 handle_initrd();
78947 return 1;
78948 }
78949 }
78950- sys_unlink("/initrd.image");
78951+ sys_unlink((const char __force_user *)"/initrd.image");
78952 return 0;
78953 }
78954diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
78955index 8cb6db5..d729f50 100644
78956--- a/init/do_mounts_md.c
78957+++ b/init/do_mounts_md.c
78958@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
78959 partitioned ? "_d" : "", minor,
78960 md_setup_args[ent].device_names);
78961
78962- fd = sys_open(name, 0, 0);
78963+ fd = sys_open((char __force_user *)name, 0, 0);
78964 if (fd < 0) {
78965 printk(KERN_ERR "md: open failed - cannot start "
78966 "array %s\n", name);
78967@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
78968 * array without it
78969 */
78970 sys_close(fd);
78971- fd = sys_open(name, 0, 0);
78972+ fd = sys_open((char __force_user *)name, 0, 0);
78973 sys_ioctl(fd, BLKRRPART, 0);
78974 }
78975 sys_close(fd);
78976@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
78977
78978 wait_for_device_probe();
78979
78980- fd = sys_open("/dev/md0", 0, 0);
78981+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
78982 if (fd >= 0) {
78983 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
78984 sys_close(fd);
78985diff --git a/init/init_task.c b/init/init_task.c
78986index ba0a7f36..2bcf1d5 100644
78987--- a/init/init_task.c
78988+++ b/init/init_task.c
78989@@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
78990 * Initial thread structure. Alignment of this is handled by a special
78991 * linker map entry.
78992 */
78993+#ifdef CONFIG_X86
78994+union thread_union init_thread_union __init_task_data;
78995+#else
78996 union thread_union init_thread_union __init_task_data =
78997 { INIT_THREAD_INFO(init_task) };
78998+#endif
78999diff --git a/init/initramfs.c b/init/initramfs.c
79000index a67ef9d..2d17ed9 100644
79001--- a/init/initramfs.c
79002+++ b/init/initramfs.c
79003@@ -84,7 +84,7 @@ static void __init free_hash(void)
79004 }
79005 }
79006
79007-static long __init do_utime(char *filename, time_t mtime)
79008+static long __init do_utime(char __force_user *filename, time_t mtime)
79009 {
79010 struct timespec t[2];
79011
79012@@ -119,7 +119,7 @@ static void __init dir_utime(void)
79013 struct dir_entry *de, *tmp;
79014 list_for_each_entry_safe(de, tmp, &dir_list, list) {
79015 list_del(&de->list);
79016- do_utime(de->name, de->mtime);
79017+ do_utime((char __force_user *)de->name, de->mtime);
79018 kfree(de->name);
79019 kfree(de);
79020 }
79021@@ -281,7 +281,7 @@ static int __init maybe_link(void)
79022 if (nlink >= 2) {
79023 char *old = find_link(major, minor, ino, mode, collected);
79024 if (old)
79025- return (sys_link(old, collected) < 0) ? -1 : 1;
79026+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
79027 }
79028 return 0;
79029 }
79030@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
79031 {
79032 struct stat st;
79033
79034- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
79035+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
79036 if (S_ISDIR(st.st_mode))
79037- sys_rmdir(path);
79038+ sys_rmdir((char __force_user *)path);
79039 else
79040- sys_unlink(path);
79041+ sys_unlink((char __force_user *)path);
79042 }
79043 }
79044
79045@@ -315,7 +315,7 @@ static int __init do_name(void)
79046 int openflags = O_WRONLY|O_CREAT;
79047 if (ml != 1)
79048 openflags |= O_TRUNC;
79049- wfd = sys_open(collected, openflags, mode);
79050+ wfd = sys_open((char __force_user *)collected, openflags, mode);
79051
79052 if (wfd >= 0) {
79053 sys_fchown(wfd, uid, gid);
79054@@ -327,17 +327,17 @@ static int __init do_name(void)
79055 }
79056 }
79057 } else if (S_ISDIR(mode)) {
79058- sys_mkdir(collected, mode);
79059- sys_chown(collected, uid, gid);
79060- sys_chmod(collected, mode);
79061+ sys_mkdir((char __force_user *)collected, mode);
79062+ sys_chown((char __force_user *)collected, uid, gid);
79063+ sys_chmod((char __force_user *)collected, mode);
79064 dir_add(collected, mtime);
79065 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
79066 S_ISFIFO(mode) || S_ISSOCK(mode)) {
79067 if (maybe_link() == 0) {
79068- sys_mknod(collected, mode, rdev);
79069- sys_chown(collected, uid, gid);
79070- sys_chmod(collected, mode);
79071- do_utime(collected, mtime);
79072+ sys_mknod((char __force_user *)collected, mode, rdev);
79073+ sys_chown((char __force_user *)collected, uid, gid);
79074+ sys_chmod((char __force_user *)collected, mode);
79075+ do_utime((char __force_user *)collected, mtime);
79076 }
79077 }
79078 return 0;
79079@@ -346,15 +346,15 @@ static int __init do_name(void)
79080 static int __init do_copy(void)
79081 {
79082 if (count >= body_len) {
79083- sys_write(wfd, victim, body_len);
79084+ sys_write(wfd, (char __force_user *)victim, body_len);
79085 sys_close(wfd);
79086- do_utime(vcollected, mtime);
79087+ do_utime((char __force_user *)vcollected, mtime);
79088 kfree(vcollected);
79089 eat(body_len);
79090 state = SkipIt;
79091 return 0;
79092 } else {
79093- sys_write(wfd, victim, count);
79094+ sys_write(wfd, (char __force_user *)victim, count);
79095 body_len -= count;
79096 eat(count);
79097 return 1;
79098@@ -365,9 +365,9 @@ static int __init do_symlink(void)
79099 {
79100 collected[N_ALIGN(name_len) + body_len] = '\0';
79101 clean_path(collected, 0);
79102- sys_symlink(collected + N_ALIGN(name_len), collected);
79103- sys_lchown(collected, uid, gid);
79104- do_utime(collected, mtime);
79105+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
79106+ sys_lchown((char __force_user *)collected, uid, gid);
79107+ do_utime((char __force_user *)collected, mtime);
79108 state = SkipIt;
79109 next_state = Reset;
79110 return 0;
79111@@ -583,7 +583,7 @@ static int __init populate_rootfs(void)
79112 {
79113 char *err = unpack_to_rootfs(__initramfs_start, __initramfs_size);
79114 if (err)
79115- panic(err); /* Failed to decompress INTERNAL initramfs */
79116+ panic("%s", err); /* Failed to decompress INTERNAL initramfs */
79117 if (initrd_start) {
79118 #ifdef CONFIG_BLK_DEV_RAM
79119 int fd;
79120diff --git a/init/main.c b/init/main.c
79121index d03d2ec..9fc4737 100644
79122--- a/init/main.c
79123+++ b/init/main.c
79124@@ -101,6 +101,8 @@ static inline void mark_rodata_ro(void) { }
79125 extern void tc_init(void);
79126 #endif
79127
79128+extern void grsecurity_init(void);
79129+
79130 /*
79131 * Debug helper: via this flag we know that we are in 'early bootup code'
79132 * where only the boot processor is running with IRQ disabled. This means
79133@@ -154,6 +156,74 @@ static int __init set_reset_devices(char *str)
79134
79135 __setup("reset_devices", set_reset_devices);
79136
79137+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
79138+kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
79139+static int __init setup_grsec_proc_gid(char *str)
79140+{
79141+ grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
79142+ return 1;
79143+}
79144+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
79145+#endif
79146+
79147+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
79148+unsigned long pax_user_shadow_base __read_only;
79149+EXPORT_SYMBOL(pax_user_shadow_base);
79150+extern char pax_enter_kernel_user[];
79151+extern char pax_exit_kernel_user[];
79152+#endif
79153+
79154+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
79155+static int __init setup_pax_nouderef(char *str)
79156+{
79157+#ifdef CONFIG_X86_32
79158+ unsigned int cpu;
79159+ struct desc_struct *gdt;
79160+
79161+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
79162+ gdt = get_cpu_gdt_table(cpu);
79163+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
79164+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
79165+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
79166+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
79167+ }
79168+ loadsegment(ds, __KERNEL_DS);
79169+ loadsegment(es, __KERNEL_DS);
79170+ loadsegment(ss, __KERNEL_DS);
79171+#else
79172+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
79173+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
79174+ clone_pgd_mask = ~(pgdval_t)0UL;
79175+ pax_user_shadow_base = 0UL;
79176+ setup_clear_cpu_cap(X86_FEATURE_PCID);
79177+#endif
79178+
79179+ return 0;
79180+}
79181+early_param("pax_nouderef", setup_pax_nouderef);
79182+
79183+#ifdef CONFIG_X86_64
79184+static int __init setup_pax_weakuderef(char *str)
79185+{
79186+ if (clone_pgd_mask != ~(pgdval_t)0UL)
79187+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
79188+ return 1;
79189+}
79190+__setup("pax_weakuderef", setup_pax_weakuderef);
79191+#endif
79192+#endif
79193+
79194+#ifdef CONFIG_PAX_SOFTMODE
79195+int pax_softmode;
79196+
79197+static int __init setup_pax_softmode(char *str)
79198+{
79199+ get_option(&str, &pax_softmode);
79200+ return 1;
79201+}
79202+__setup("pax_softmode=", setup_pax_softmode);
79203+#endif
79204+
79205 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
79206 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
79207 static const char *panic_later, *panic_param;
79208@@ -679,25 +749,24 @@ int __init_or_module do_one_initcall(initcall_t fn)
79209 {
79210 int count = preempt_count();
79211 int ret;
79212- char msgbuf[64];
79213+ const char *msg1 = "", *msg2 = "";
79214
79215 if (initcall_debug)
79216 ret = do_one_initcall_debug(fn);
79217 else
79218 ret = fn();
79219
79220- msgbuf[0] = 0;
79221-
79222 if (preempt_count() != count) {
79223- sprintf(msgbuf, "preemption imbalance ");
79224+ msg1 = " preemption imbalance";
79225 preempt_count() = count;
79226 }
79227 if (irqs_disabled()) {
79228- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
79229+ msg2 = " disabled interrupts";
79230 local_irq_enable();
79231 }
79232- WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
79233+ WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
79234
79235+ add_latent_entropy();
79236 return ret;
79237 }
79238
79239@@ -803,8 +872,8 @@ static int run_init_process(const char *init_filename)
79240 {
79241 argv_init[0] = init_filename;
79242 return do_execve(init_filename,
79243- (const char __user *const __user *)argv_init,
79244- (const char __user *const __user *)envp_init);
79245+ (const char __user *const __force_user *)argv_init,
79246+ (const char __user *const __force_user *)envp_init);
79247 }
79248
79249 static noinline void __init kernel_init_freeable(void);
79250@@ -881,7 +950,7 @@ static noinline void __init kernel_init_freeable(void)
79251 do_basic_setup();
79252
79253 /* Open the /dev/console on the rootfs, this should never fail */
79254- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
79255+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
79256 pr_err("Warning: unable to open an initial console.\n");
79257
79258 (void) sys_dup(0);
79259@@ -894,11 +963,13 @@ static noinline void __init kernel_init_freeable(void)
79260 if (!ramdisk_execute_command)
79261 ramdisk_execute_command = "/init";
79262
79263- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
79264+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
79265 ramdisk_execute_command = NULL;
79266 prepare_namespace();
79267 }
79268
79269+ grsecurity_init();
79270+
79271 /*
79272 * Ok, we have completed the initial bootup, and
79273 * we're essentially up and running. Get rid of the
79274diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
79275index 130dfec..cc88451 100644
79276--- a/ipc/ipc_sysctl.c
79277+++ b/ipc/ipc_sysctl.c
79278@@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
79279 static int proc_ipc_dointvec(ctl_table *table, int write,
79280 void __user *buffer, size_t *lenp, loff_t *ppos)
79281 {
79282- struct ctl_table ipc_table;
79283+ ctl_table_no_const ipc_table;
79284
79285 memcpy(&ipc_table, table, sizeof(ipc_table));
79286 ipc_table.data = get_ipc(table);
79287@@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
79288 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
79289 void __user *buffer, size_t *lenp, loff_t *ppos)
79290 {
79291- struct ctl_table ipc_table;
79292+ ctl_table_no_const ipc_table;
79293
79294 memcpy(&ipc_table, table, sizeof(ipc_table));
79295 ipc_table.data = get_ipc(table);
79296@@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
79297 static int proc_ipc_callback_dointvec(ctl_table *table, int write,
79298 void __user *buffer, size_t *lenp, loff_t *ppos)
79299 {
79300- struct ctl_table ipc_table;
79301+ ctl_table_no_const ipc_table;
79302 size_t lenp_bef = *lenp;
79303 int rc;
79304
79305@@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec(ctl_table *table, int write,
79306 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
79307 void __user *buffer, size_t *lenp, loff_t *ppos)
79308 {
79309- struct ctl_table ipc_table;
79310+ ctl_table_no_const ipc_table;
79311 memcpy(&ipc_table, table, sizeof(ipc_table));
79312 ipc_table.data = get_ipc(table);
79313
79314@@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
79315 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
79316 void __user *buffer, size_t *lenp, loff_t *ppos)
79317 {
79318- struct ctl_table ipc_table;
79319+ ctl_table_no_const ipc_table;
79320 size_t lenp_bef = *lenp;
79321 int oldval;
79322 int rc;
79323diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
79324index 383d638..943fdbb 100644
79325--- a/ipc/mq_sysctl.c
79326+++ b/ipc/mq_sysctl.c
79327@@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
79328 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
79329 void __user *buffer, size_t *lenp, loff_t *ppos)
79330 {
79331- struct ctl_table mq_table;
79332+ ctl_table_no_const mq_table;
79333 memcpy(&mq_table, table, sizeof(mq_table));
79334 mq_table.data = get_mq(table);
79335
79336diff --git a/ipc/mqueue.c b/ipc/mqueue.c
79337index ae1996d..a35f2cc 100644
79338--- a/ipc/mqueue.c
79339+++ b/ipc/mqueue.c
79340@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
79341 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
79342 info->attr.mq_msgsize);
79343
79344+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
79345 spin_lock(&mq_lock);
79346 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
79347 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
79348diff --git a/ipc/msg.c b/ipc/msg.c
79349index 9f29d9e..8f284e0 100644
79350--- a/ipc/msg.c
79351+++ b/ipc/msg.c
79352@@ -291,18 +291,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
79353 return security_msg_queue_associate(msq, msgflg);
79354 }
79355
79356+static struct ipc_ops msg_ops = {
79357+ .getnew = newque,
79358+ .associate = msg_security,
79359+ .more_checks = NULL
79360+};
79361+
79362 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
79363 {
79364 struct ipc_namespace *ns;
79365- struct ipc_ops msg_ops;
79366 struct ipc_params msg_params;
79367
79368 ns = current->nsproxy->ipc_ns;
79369
79370- msg_ops.getnew = newque;
79371- msg_ops.associate = msg_security;
79372- msg_ops.more_checks = NULL;
79373-
79374 msg_params.key = key;
79375 msg_params.flg = msgflg;
79376
79377diff --git a/ipc/sem.c b/ipc/sem.c
79378index 4108889..511ada1 100644
79379--- a/ipc/sem.c
79380+++ b/ipc/sem.c
79381@@ -517,10 +517,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
79382 return 0;
79383 }
79384
79385+static struct ipc_ops sem_ops = {
79386+ .getnew = newary,
79387+ .associate = sem_security,
79388+ .more_checks = sem_more_checks
79389+};
79390+
79391 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
79392 {
79393 struct ipc_namespace *ns;
79394- struct ipc_ops sem_ops;
79395 struct ipc_params sem_params;
79396
79397 ns = current->nsproxy->ipc_ns;
79398@@ -528,10 +533,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
79399 if (nsems < 0 || nsems > ns->sc_semmsl)
79400 return -EINVAL;
79401
79402- sem_ops.getnew = newary;
79403- sem_ops.associate = sem_security;
79404- sem_ops.more_checks = sem_more_checks;
79405-
79406 sem_params.key = key;
79407 sem_params.flg = semflg;
79408 sem_params.u.nsems = nsems;
79409diff --git a/ipc/shm.c b/ipc/shm.c
79410index c6b4ad5..3ec3254 100644
79411--- a/ipc/shm.c
79412+++ b/ipc/shm.c
79413@@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
79414 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
79415 #endif
79416
79417+#ifdef CONFIG_GRKERNSEC
79418+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
79419+ const time_t shm_createtime, const kuid_t cuid,
79420+ const int shmid);
79421+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
79422+ const time_t shm_createtime);
79423+#endif
79424+
79425 void shm_init_ns(struct ipc_namespace *ns)
79426 {
79427 ns->shm_ctlmax = SHMMAX;
79428@@ -531,6 +539,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
79429 shp->shm_lprid = 0;
79430 shp->shm_atim = shp->shm_dtim = 0;
79431 shp->shm_ctim = get_seconds();
79432+#ifdef CONFIG_GRKERNSEC
79433+ {
79434+ struct timespec timeval;
79435+ do_posix_clock_monotonic_gettime(&timeval);
79436+
79437+ shp->shm_createtime = timeval.tv_sec;
79438+ }
79439+#endif
79440 shp->shm_segsz = size;
79441 shp->shm_nattch = 0;
79442 shp->shm_file = file;
79443@@ -585,18 +601,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
79444 return 0;
79445 }
79446
79447+static struct ipc_ops shm_ops = {
79448+ .getnew = newseg,
79449+ .associate = shm_security,
79450+ .more_checks = shm_more_checks
79451+};
79452+
79453 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
79454 {
79455 struct ipc_namespace *ns;
79456- struct ipc_ops shm_ops;
79457 struct ipc_params shm_params;
79458
79459 ns = current->nsproxy->ipc_ns;
79460
79461- shm_ops.getnew = newseg;
79462- shm_ops.associate = shm_security;
79463- shm_ops.more_checks = shm_more_checks;
79464-
79465 shm_params.key = key;
79466 shm_params.flg = shmflg;
79467 shm_params.u.size = size;
79468@@ -1028,6 +1045,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
79469 f_mode = FMODE_READ | FMODE_WRITE;
79470 }
79471 if (shmflg & SHM_EXEC) {
79472+
79473+#ifdef CONFIG_PAX_MPROTECT
79474+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
79475+ goto out;
79476+#endif
79477+
79478 prot |= PROT_EXEC;
79479 acc_mode |= S_IXUGO;
79480 }
79481@@ -1051,9 +1074,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
79482 if (err)
79483 goto out_unlock;
79484
79485+#ifdef CONFIG_GRKERNSEC
79486+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
79487+ shp->shm_perm.cuid, shmid) ||
79488+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
79489+ err = -EACCES;
79490+ goto out_unlock;
79491+ }
79492+#endif
79493+
79494 path = shp->shm_file->f_path;
79495 path_get(&path);
79496 shp->shm_nattch++;
79497+#ifdef CONFIG_GRKERNSEC
79498+ shp->shm_lapid = current->pid;
79499+#endif
79500 size = i_size_read(path.dentry->d_inode);
79501 shm_unlock(shp);
79502
79503diff --git a/kernel/acct.c b/kernel/acct.c
79504index 8d6e145..33e0b1e 100644
79505--- a/kernel/acct.c
79506+++ b/kernel/acct.c
79507@@ -556,7 +556,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
79508 */
79509 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
79510 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
79511- file->f_op->write(file, (char *)&ac,
79512+ file->f_op->write(file, (char __force_user *)&ac,
79513 sizeof(acct_t), &file->f_pos);
79514 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
79515 set_fs(fs);
79516diff --git a/kernel/audit.c b/kernel/audit.c
79517index 91e53d0..d9e3ec4 100644
79518--- a/kernel/audit.c
79519+++ b/kernel/audit.c
79520@@ -118,7 +118,7 @@ u32 audit_sig_sid = 0;
79521 3) suppressed due to audit_rate_limit
79522 4) suppressed due to audit_backlog_limit
79523 */
79524-static atomic_t audit_lost = ATOMIC_INIT(0);
79525+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
79526
79527 /* The netlink socket. */
79528 static struct sock *audit_sock;
79529@@ -240,7 +240,7 @@ void audit_log_lost(const char *message)
79530 unsigned long now;
79531 int print;
79532
79533- atomic_inc(&audit_lost);
79534+ atomic_inc_unchecked(&audit_lost);
79535
79536 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
79537
79538@@ -259,7 +259,7 @@ void audit_log_lost(const char *message)
79539 printk(KERN_WARNING
79540 "audit: audit_lost=%d audit_rate_limit=%d "
79541 "audit_backlog_limit=%d\n",
79542- atomic_read(&audit_lost),
79543+ atomic_read_unchecked(&audit_lost),
79544 audit_rate_limit,
79545 audit_backlog_limit);
79546 audit_panic(message);
79547@@ -664,7 +664,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
79548 status_set.pid = audit_pid;
79549 status_set.rate_limit = audit_rate_limit;
79550 status_set.backlog_limit = audit_backlog_limit;
79551- status_set.lost = atomic_read(&audit_lost);
79552+ status_set.lost = atomic_read_unchecked(&audit_lost);
79553 status_set.backlog = skb_queue_len(&audit_skb_queue);
79554 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
79555 &status_set, sizeof(status_set));
79556diff --git a/kernel/auditsc.c b/kernel/auditsc.c
79557index 9845cb3..3ec9369 100644
79558--- a/kernel/auditsc.c
79559+++ b/kernel/auditsc.c
79560@@ -1962,7 +1962,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
79561 }
79562
79563 /* global counter which is incremented every time something logs in */
79564-static atomic_t session_id = ATOMIC_INIT(0);
79565+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
79566
79567 /**
79568 * audit_set_loginuid - set current task's audit_context loginuid
79569@@ -1986,7 +1986,7 @@ int audit_set_loginuid(kuid_t loginuid)
79570 return -EPERM;
79571 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
79572
79573- sessionid = atomic_inc_return(&session_id);
79574+ sessionid = atomic_inc_return_unchecked(&session_id);
79575 if (context && context->in_syscall) {
79576 struct audit_buffer *ab;
79577
79578diff --git a/kernel/capability.c b/kernel/capability.c
79579index f6c2ce5..982c0f9 100644
79580--- a/kernel/capability.c
79581+++ b/kernel/capability.c
79582@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
79583 * before modification is attempted and the application
79584 * fails.
79585 */
79586+ if (tocopy > ARRAY_SIZE(kdata))
79587+ return -EFAULT;
79588+
79589 if (copy_to_user(dataptr, kdata, tocopy
79590 * sizeof(struct __user_cap_data_struct))) {
79591 return -EFAULT;
79592@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
79593 int ret;
79594
79595 rcu_read_lock();
79596- ret = security_capable(__task_cred(t), ns, cap);
79597+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
79598+ gr_task_is_capable(t, __task_cred(t), cap);
79599 rcu_read_unlock();
79600
79601- return (ret == 0);
79602+ return ret;
79603 }
79604
79605 /**
79606@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
79607 int ret;
79608
79609 rcu_read_lock();
79610- ret = security_capable_noaudit(__task_cred(t), ns, cap);
79611+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
79612 rcu_read_unlock();
79613
79614- return (ret == 0);
79615+ return ret;
79616 }
79617
79618 /**
79619@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
79620 BUG();
79621 }
79622
79623- if (security_capable(current_cred(), ns, cap) == 0) {
79624+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
79625 current->flags |= PF_SUPERPRIV;
79626 return true;
79627 }
79628@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
79629 }
79630 EXPORT_SYMBOL(ns_capable);
79631
79632+bool ns_capable_nolog(struct user_namespace *ns, int cap)
79633+{
79634+ if (unlikely(!cap_valid(cap))) {
79635+ printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
79636+ BUG();
79637+ }
79638+
79639+ if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
79640+ current->flags |= PF_SUPERPRIV;
79641+ return true;
79642+ }
79643+ return false;
79644+}
79645+EXPORT_SYMBOL(ns_capable_nolog);
79646+
79647 /**
79648 * file_ns_capable - Determine if the file's opener had a capability in effect
79649 * @file: The file we want to check
79650@@ -432,6 +451,12 @@ bool capable(int cap)
79651 }
79652 EXPORT_SYMBOL(capable);
79653
79654+bool capable_nolog(int cap)
79655+{
79656+ return ns_capable_nolog(&init_user_ns, cap);
79657+}
79658+EXPORT_SYMBOL(capable_nolog);
79659+
79660 /**
79661 * nsown_capable - Check superior capability to one's own user_ns
79662 * @cap: The capability in question
79663@@ -464,3 +489,10 @@ bool inode_capable(const struct inode *inode, int cap)
79664
79665 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
79666 }
79667+
79668+bool inode_capable_nolog(const struct inode *inode, int cap)
79669+{
79670+ struct user_namespace *ns = current_user_ns();
79671+
79672+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
79673+}
79674diff --git a/kernel/cgroup.c b/kernel/cgroup.c
79675index e919633..f46b08f 100644
79676--- a/kernel/cgroup.c
79677+++ b/kernel/cgroup.c
79678@@ -5623,7 +5623,7 @@ static int cgroup_css_links_read(struct cgroup *cgrp,
79679 struct css_set *cset = link->cset;
79680 struct task_struct *task;
79681 int count = 0;
79682- seq_printf(seq, "css_set %p\n", cset);
79683+ seq_printf(seq, "css_set %pK\n", cset);
79684 list_for_each_entry(task, &cset->tasks, cg_list) {
79685 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
79686 seq_puts(seq, " ...\n");
79687diff --git a/kernel/compat.c b/kernel/compat.c
79688index 0a09e48..f44f3f0 100644
79689--- a/kernel/compat.c
79690+++ b/kernel/compat.c
79691@@ -13,6 +13,7 @@
79692
79693 #include <linux/linkage.h>
79694 #include <linux/compat.h>
79695+#include <linux/module.h>
79696 #include <linux/errno.h>
79697 #include <linux/time.h>
79698 #include <linux/signal.h>
79699@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
79700 mm_segment_t oldfs;
79701 long ret;
79702
79703- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
79704+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
79705 oldfs = get_fs();
79706 set_fs(KERNEL_DS);
79707 ret = hrtimer_nanosleep_restart(restart);
79708@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
79709 oldfs = get_fs();
79710 set_fs(KERNEL_DS);
79711 ret = hrtimer_nanosleep(&tu,
79712- rmtp ? (struct timespec __user *)&rmt : NULL,
79713+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
79714 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
79715 set_fs(oldfs);
79716
79717@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
79718 mm_segment_t old_fs = get_fs();
79719
79720 set_fs(KERNEL_DS);
79721- ret = sys_sigpending((old_sigset_t __user *) &s);
79722+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
79723 set_fs(old_fs);
79724 if (ret == 0)
79725 ret = put_user(s, set);
79726@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
79727 mm_segment_t old_fs = get_fs();
79728
79729 set_fs(KERNEL_DS);
79730- ret = sys_old_getrlimit(resource, &r);
79731+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
79732 set_fs(old_fs);
79733
79734 if (!ret) {
79735@@ -533,8 +534,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
79736 set_fs (KERNEL_DS);
79737 ret = sys_wait4(pid,
79738 (stat_addr ?
79739- (unsigned int __user *) &status : NULL),
79740- options, (struct rusage __user *) &r);
79741+ (unsigned int __force_user *) &status : NULL),
79742+ options, (struct rusage __force_user *) &r);
79743 set_fs (old_fs);
79744
79745 if (ret > 0) {
79746@@ -560,8 +561,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
79747 memset(&info, 0, sizeof(info));
79748
79749 set_fs(KERNEL_DS);
79750- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
79751- uru ? (struct rusage __user *)&ru : NULL);
79752+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
79753+ uru ? (struct rusage __force_user *)&ru : NULL);
79754 set_fs(old_fs);
79755
79756 if ((ret < 0) || (info.si_signo == 0))
79757@@ -695,8 +696,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
79758 oldfs = get_fs();
79759 set_fs(KERNEL_DS);
79760 err = sys_timer_settime(timer_id, flags,
79761- (struct itimerspec __user *) &newts,
79762- (struct itimerspec __user *) &oldts);
79763+ (struct itimerspec __force_user *) &newts,
79764+ (struct itimerspec __force_user *) &oldts);
79765 set_fs(oldfs);
79766 if (!err && old && put_compat_itimerspec(old, &oldts))
79767 return -EFAULT;
79768@@ -713,7 +714,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
79769 oldfs = get_fs();
79770 set_fs(KERNEL_DS);
79771 err = sys_timer_gettime(timer_id,
79772- (struct itimerspec __user *) &ts);
79773+ (struct itimerspec __force_user *) &ts);
79774 set_fs(oldfs);
79775 if (!err && put_compat_itimerspec(setting, &ts))
79776 return -EFAULT;
79777@@ -732,7 +733,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
79778 oldfs = get_fs();
79779 set_fs(KERNEL_DS);
79780 err = sys_clock_settime(which_clock,
79781- (struct timespec __user *) &ts);
79782+ (struct timespec __force_user *) &ts);
79783 set_fs(oldfs);
79784 return err;
79785 }
79786@@ -747,7 +748,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
79787 oldfs = get_fs();
79788 set_fs(KERNEL_DS);
79789 err = sys_clock_gettime(which_clock,
79790- (struct timespec __user *) &ts);
79791+ (struct timespec __force_user *) &ts);
79792 set_fs(oldfs);
79793 if (!err && put_compat_timespec(&ts, tp))
79794 return -EFAULT;
79795@@ -767,7 +768,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
79796
79797 oldfs = get_fs();
79798 set_fs(KERNEL_DS);
79799- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
79800+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
79801 set_fs(oldfs);
79802
79803 err = compat_put_timex(utp, &txc);
79804@@ -787,7 +788,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
79805 oldfs = get_fs();
79806 set_fs(KERNEL_DS);
79807 err = sys_clock_getres(which_clock,
79808- (struct timespec __user *) &ts);
79809+ (struct timespec __force_user *) &ts);
79810 set_fs(oldfs);
79811 if (!err && tp && put_compat_timespec(&ts, tp))
79812 return -EFAULT;
79813@@ -799,9 +800,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
79814 long err;
79815 mm_segment_t oldfs;
79816 struct timespec tu;
79817- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
79818+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
79819
79820- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
79821+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
79822 oldfs = get_fs();
79823 set_fs(KERNEL_DS);
79824 err = clock_nanosleep_restart(restart);
79825@@ -833,8 +834,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
79826 oldfs = get_fs();
79827 set_fs(KERNEL_DS);
79828 err = sys_clock_nanosleep(which_clock, flags,
79829- (struct timespec __user *) &in,
79830- (struct timespec __user *) &out);
79831+ (struct timespec __force_user *) &in,
79832+ (struct timespec __force_user *) &out);
79833 set_fs(oldfs);
79834
79835 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
79836diff --git a/kernel/configs.c b/kernel/configs.c
79837index c18b1f1..b9a0132 100644
79838--- a/kernel/configs.c
79839+++ b/kernel/configs.c
79840@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
79841 struct proc_dir_entry *entry;
79842
79843 /* create the current config file */
79844+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
79845+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
79846+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
79847+ &ikconfig_file_ops);
79848+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
79849+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
79850+ &ikconfig_file_ops);
79851+#endif
79852+#else
79853 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
79854 &ikconfig_file_ops);
79855+#endif
79856+
79857 if (!entry)
79858 return -ENOMEM;
79859
79860diff --git a/kernel/cred.c b/kernel/cred.c
79861index e0573a4..3874e41 100644
79862--- a/kernel/cred.c
79863+++ b/kernel/cred.c
79864@@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
79865 validate_creds(cred);
79866 alter_cred_subscribers(cred, -1);
79867 put_cred(cred);
79868+
79869+#ifdef CONFIG_GRKERNSEC_SETXID
79870+ cred = (struct cred *) tsk->delayed_cred;
79871+ if (cred != NULL) {
79872+ tsk->delayed_cred = NULL;
79873+ validate_creds(cred);
79874+ alter_cred_subscribers(cred, -1);
79875+ put_cred(cred);
79876+ }
79877+#endif
79878 }
79879
79880 /**
79881@@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
79882 * Always returns 0 thus allowing this function to be tail-called at the end
79883 * of, say, sys_setgid().
79884 */
79885-int commit_creds(struct cred *new)
79886+static int __commit_creds(struct cred *new)
79887 {
79888 struct task_struct *task = current;
79889 const struct cred *old = task->real_cred;
79890@@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
79891
79892 get_cred(new); /* we will require a ref for the subj creds too */
79893
79894+ gr_set_role_label(task, new->uid, new->gid);
79895+
79896 /* dumpability changes */
79897 if (!uid_eq(old->euid, new->euid) ||
79898 !gid_eq(old->egid, new->egid) ||
79899@@ -479,6 +491,102 @@ int commit_creds(struct cred *new)
79900 put_cred(old);
79901 return 0;
79902 }
79903+#ifdef CONFIG_GRKERNSEC_SETXID
79904+extern int set_user(struct cred *new);
79905+
79906+void gr_delayed_cred_worker(void)
79907+{
79908+ const struct cred *new = current->delayed_cred;
79909+ struct cred *ncred;
79910+
79911+ current->delayed_cred = NULL;
79912+
79913+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
79914+ // from doing get_cred on it when queueing this
79915+ put_cred(new);
79916+ return;
79917+ } else if (new == NULL)
79918+ return;
79919+
79920+ ncred = prepare_creds();
79921+ if (!ncred)
79922+ goto die;
79923+ // uids
79924+ ncred->uid = new->uid;
79925+ ncred->euid = new->euid;
79926+ ncred->suid = new->suid;
79927+ ncred->fsuid = new->fsuid;
79928+ // gids
79929+ ncred->gid = new->gid;
79930+ ncred->egid = new->egid;
79931+ ncred->sgid = new->sgid;
79932+ ncred->fsgid = new->fsgid;
79933+ // groups
79934+ if (set_groups(ncred, new->group_info) < 0) {
79935+ abort_creds(ncred);
79936+ goto die;
79937+ }
79938+ // caps
79939+ ncred->securebits = new->securebits;
79940+ ncred->cap_inheritable = new->cap_inheritable;
79941+ ncred->cap_permitted = new->cap_permitted;
79942+ ncred->cap_effective = new->cap_effective;
79943+ ncred->cap_bset = new->cap_bset;
79944+
79945+ if (set_user(ncred)) {
79946+ abort_creds(ncred);
79947+ goto die;
79948+ }
79949+
79950+ // from doing get_cred on it when queueing this
79951+ put_cred(new);
79952+
79953+ __commit_creds(ncred);
79954+ return;
79955+die:
79956+ // from doing get_cred on it when queueing this
79957+ put_cred(new);
79958+ do_group_exit(SIGKILL);
79959+}
79960+#endif
79961+
79962+int commit_creds(struct cred *new)
79963+{
79964+#ifdef CONFIG_GRKERNSEC_SETXID
79965+ int ret;
79966+ int schedule_it = 0;
79967+ struct task_struct *t;
79968+
79969+ /* we won't get called with tasklist_lock held for writing
79970+ and interrupts disabled as the cred struct in that case is
79971+ init_cred
79972+ */
79973+ if (grsec_enable_setxid && !current_is_single_threaded() &&
79974+ uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
79975+ !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
79976+ schedule_it = 1;
79977+ }
79978+ ret = __commit_creds(new);
79979+ if (schedule_it) {
79980+ rcu_read_lock();
79981+ read_lock(&tasklist_lock);
79982+ for (t = next_thread(current); t != current;
79983+ t = next_thread(t)) {
79984+ if (t->delayed_cred == NULL) {
79985+ t->delayed_cred = get_cred(new);
79986+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
79987+ set_tsk_need_resched(t);
79988+ }
79989+ }
79990+ read_unlock(&tasklist_lock);
79991+ rcu_read_unlock();
79992+ }
79993+ return ret;
79994+#else
79995+ return __commit_creds(new);
79996+#endif
79997+}
79998+
79999 EXPORT_SYMBOL(commit_creds);
80000
80001 /**
80002diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
80003index 0506d44..2c20034 100644
80004--- a/kernel/debug/debug_core.c
80005+++ b/kernel/debug/debug_core.c
80006@@ -123,7 +123,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
80007 */
80008 static atomic_t masters_in_kgdb;
80009 static atomic_t slaves_in_kgdb;
80010-static atomic_t kgdb_break_tasklet_var;
80011+static atomic_unchecked_t kgdb_break_tasklet_var;
80012 atomic_t kgdb_setting_breakpoint;
80013
80014 struct task_struct *kgdb_usethread;
80015@@ -133,7 +133,7 @@ int kgdb_single_step;
80016 static pid_t kgdb_sstep_pid;
80017
80018 /* to keep track of the CPU which is doing the single stepping*/
80019-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
80020+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
80021
80022 /*
80023 * If you are debugging a problem where roundup (the collection of
80024@@ -541,7 +541,7 @@ return_normal:
80025 * kernel will only try for the value of sstep_tries before
80026 * giving up and continuing on.
80027 */
80028- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
80029+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
80030 (kgdb_info[cpu].task &&
80031 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
80032 atomic_set(&kgdb_active, -1);
80033@@ -635,8 +635,8 @@ cpu_master_loop:
80034 }
80035
80036 kgdb_restore:
80037- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
80038- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
80039+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
80040+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
80041 if (kgdb_info[sstep_cpu].task)
80042 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
80043 else
80044@@ -888,18 +888,18 @@ static void kgdb_unregister_callbacks(void)
80045 static void kgdb_tasklet_bpt(unsigned long ing)
80046 {
80047 kgdb_breakpoint();
80048- atomic_set(&kgdb_break_tasklet_var, 0);
80049+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
80050 }
80051
80052 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
80053
80054 void kgdb_schedule_breakpoint(void)
80055 {
80056- if (atomic_read(&kgdb_break_tasklet_var) ||
80057+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
80058 atomic_read(&kgdb_active) != -1 ||
80059 atomic_read(&kgdb_setting_breakpoint))
80060 return;
80061- atomic_inc(&kgdb_break_tasklet_var);
80062+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
80063 tasklet_schedule(&kgdb_tasklet_breakpoint);
80064 }
80065 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
80066diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
80067index 00eb8f7..d7e3244 100644
80068--- a/kernel/debug/kdb/kdb_main.c
80069+++ b/kernel/debug/kdb/kdb_main.c
80070@@ -1974,7 +1974,7 @@ static int kdb_lsmod(int argc, const char **argv)
80071 continue;
80072
80073 kdb_printf("%-20s%8u 0x%p ", mod->name,
80074- mod->core_size, (void *)mod);
80075+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
80076 #ifdef CONFIG_MODULE_UNLOAD
80077 kdb_printf("%4ld ", module_refcount(mod));
80078 #endif
80079@@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
80080 kdb_printf(" (Loading)");
80081 else
80082 kdb_printf(" (Live)");
80083- kdb_printf(" 0x%p", mod->module_core);
80084+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
80085
80086 #ifdef CONFIG_MODULE_UNLOAD
80087 {
80088diff --git a/kernel/events/core.c b/kernel/events/core.c
80089index f86599e..b18b180 100644
80090--- a/kernel/events/core.c
80091+++ b/kernel/events/core.c
80092@@ -156,8 +156,15 @@ static struct srcu_struct pmus_srcu;
80093 * 0 - disallow raw tracepoint access for unpriv
80094 * 1 - disallow cpu events for unpriv
80095 * 2 - disallow kernel profiling for unpriv
80096+ * 3 - disallow all unpriv perf event use
80097 */
80098-int sysctl_perf_event_paranoid __read_mostly = 1;
80099+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
80100+int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
80101+#elif defined(CONFIG_GRKERNSEC_HIDESYM)
80102+int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
80103+#else
80104+int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
80105+#endif
80106
80107 /* Minimum for 512 kiB + 1 user control page */
80108 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
80109@@ -270,7 +277,7 @@ void perf_sample_event_took(u64 sample_len_ns)
80110 update_perf_cpu_limits();
80111 }
80112
80113-static atomic64_t perf_event_id;
80114+static atomic64_unchecked_t perf_event_id;
80115
80116 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
80117 enum event_type_t event_type);
80118@@ -2936,7 +2943,7 @@ static void __perf_event_read(void *info)
80119
80120 static inline u64 perf_event_count(struct perf_event *event)
80121 {
80122- return local64_read(&event->count) + atomic64_read(&event->child_count);
80123+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
80124 }
80125
80126 static u64 perf_event_read(struct perf_event *event)
80127@@ -3282,9 +3289,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
80128 mutex_lock(&event->child_mutex);
80129 total += perf_event_read(event);
80130 *enabled += event->total_time_enabled +
80131- atomic64_read(&event->child_total_time_enabled);
80132+ atomic64_read_unchecked(&event->child_total_time_enabled);
80133 *running += event->total_time_running +
80134- atomic64_read(&event->child_total_time_running);
80135+ atomic64_read_unchecked(&event->child_total_time_running);
80136
80137 list_for_each_entry(child, &event->child_list, child_list) {
80138 total += perf_event_read(child);
80139@@ -3670,10 +3677,10 @@ void perf_event_update_userpage(struct perf_event *event)
80140 userpg->offset -= local64_read(&event->hw.prev_count);
80141
80142 userpg->time_enabled = enabled +
80143- atomic64_read(&event->child_total_time_enabled);
80144+ atomic64_read_unchecked(&event->child_total_time_enabled);
80145
80146 userpg->time_running = running +
80147- atomic64_read(&event->child_total_time_running);
80148+ atomic64_read_unchecked(&event->child_total_time_running);
80149
80150 arch_perf_update_userpage(userpg, now);
80151
80152@@ -4223,7 +4230,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
80153
80154 /* Data. */
80155 sp = perf_user_stack_pointer(regs);
80156- rem = __output_copy_user(handle, (void *) sp, dump_size);
80157+ rem = __output_copy_user(handle, (void __user *) sp, dump_size);
80158 dyn_size = dump_size - rem;
80159
80160 perf_output_skip(handle, rem);
80161@@ -4311,11 +4318,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
80162 values[n++] = perf_event_count(event);
80163 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
80164 values[n++] = enabled +
80165- atomic64_read(&event->child_total_time_enabled);
80166+ atomic64_read_unchecked(&event->child_total_time_enabled);
80167 }
80168 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
80169 values[n++] = running +
80170- atomic64_read(&event->child_total_time_running);
80171+ atomic64_read_unchecked(&event->child_total_time_running);
80172 }
80173 if (read_format & PERF_FORMAT_ID)
80174 values[n++] = primary_event_id(event);
80175@@ -5024,12 +5031,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
80176 * need to add enough zero bytes after the string to handle
80177 * the 64bit alignment we do later.
80178 */
80179- buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
80180+ buf = kzalloc(PATH_MAX, GFP_KERNEL);
80181 if (!buf) {
80182 name = strncpy(tmp, "//enomem", sizeof(tmp));
80183 goto got_name;
80184 }
80185- name = d_path(&file->f_path, buf, PATH_MAX);
80186+ name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
80187 if (IS_ERR(name)) {
80188 name = strncpy(tmp, "//toolong", sizeof(tmp));
80189 goto got_name;
80190@@ -6498,7 +6505,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
80191 event->parent = parent_event;
80192
80193 event->ns = get_pid_ns(task_active_pid_ns(current));
80194- event->id = atomic64_inc_return(&perf_event_id);
80195+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
80196
80197 event->state = PERF_EVENT_STATE_INACTIVE;
80198
80199@@ -6807,6 +6814,11 @@ SYSCALL_DEFINE5(perf_event_open,
80200 if (flags & ~PERF_FLAG_ALL)
80201 return -EINVAL;
80202
80203+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
80204+ if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
80205+ return -EACCES;
80206+#endif
80207+
80208 err = perf_copy_attr(attr_uptr, &attr);
80209 if (err)
80210 return err;
80211@@ -7139,10 +7151,10 @@ static void sync_child_event(struct perf_event *child_event,
80212 /*
80213 * Add back the child's count to the parent's count:
80214 */
80215- atomic64_add(child_val, &parent_event->child_count);
80216- atomic64_add(child_event->total_time_enabled,
80217+ atomic64_add_unchecked(child_val, &parent_event->child_count);
80218+ atomic64_add_unchecked(child_event->total_time_enabled,
80219 &parent_event->child_total_time_enabled);
80220- atomic64_add(child_event->total_time_running,
80221+ atomic64_add_unchecked(child_event->total_time_running,
80222 &parent_event->child_total_time_running);
80223
80224 /*
80225diff --git a/kernel/events/internal.h b/kernel/events/internal.h
80226index ca65997..60df03d 100644
80227--- a/kernel/events/internal.h
80228+++ b/kernel/events/internal.h
80229@@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
80230 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
80231 }
80232
80233-#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
80234-static inline unsigned int \
80235+#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
80236+static inline unsigned long \
80237 func_name(struct perf_output_handle *handle, \
80238- const void *buf, unsigned int len) \
80239+ const void user *buf, unsigned long len) \
80240 { \
80241 unsigned long size, written; \
80242 \
80243@@ -116,17 +116,17 @@ static inline int memcpy_common(void *dst, const void *src, size_t n)
80244 return n;
80245 }
80246
80247-DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
80248+DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
80249
80250 #define MEMCPY_SKIP(dst, src, n) (n)
80251
80252-DEFINE_OUTPUT_COPY(__output_skip, MEMCPY_SKIP)
80253+DEFINE_OUTPUT_COPY(__output_skip, MEMCPY_SKIP, )
80254
80255 #ifndef arch_perf_out_copy_user
80256 #define arch_perf_out_copy_user __copy_from_user_inatomic
80257 #endif
80258
80259-DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
80260+DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
80261
80262 /* Callchain handling */
80263 extern struct perf_callchain_entry *
80264diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
80265index f356974..cb8c570 100644
80266--- a/kernel/events/uprobes.c
80267+++ b/kernel/events/uprobes.c
80268@@ -1556,7 +1556,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
80269 {
80270 struct page *page;
80271 uprobe_opcode_t opcode;
80272- int result;
80273+ long result;
80274
80275 pagefault_disable();
80276 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
80277diff --git a/kernel/exit.c b/kernel/exit.c
80278index a949819..a5f127d 100644
80279--- a/kernel/exit.c
80280+++ b/kernel/exit.c
80281@@ -172,6 +172,10 @@ void release_task(struct task_struct * p)
80282 struct task_struct *leader;
80283 int zap_leader;
80284 repeat:
80285+#ifdef CONFIG_NET
80286+ gr_del_task_from_ip_table(p);
80287+#endif
80288+
80289 /* don't need to get the RCU readlock here - the process is dead and
80290 * can't be modifying its own credentials. But shut RCU-lockdep up */
80291 rcu_read_lock();
80292@@ -329,7 +333,7 @@ int allow_signal(int sig)
80293 * know it'll be handled, so that they don't get converted to
80294 * SIGKILL or just silently dropped.
80295 */
80296- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
80297+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
80298 recalc_sigpending();
80299 spin_unlock_irq(&current->sighand->siglock);
80300 return 0;
80301@@ -698,6 +702,8 @@ void do_exit(long code)
80302 struct task_struct *tsk = current;
80303 int group_dead;
80304
80305+ set_fs(USER_DS);
80306+
80307 profile_task_exit(tsk);
80308
80309 WARN_ON(blk_needs_flush_plug(tsk));
80310@@ -714,7 +720,6 @@ void do_exit(long code)
80311 * mm_release()->clear_child_tid() from writing to a user-controlled
80312 * kernel address.
80313 */
80314- set_fs(USER_DS);
80315
80316 ptrace_event(PTRACE_EVENT_EXIT, code);
80317
80318@@ -773,6 +778,9 @@ void do_exit(long code)
80319 tsk->exit_code = code;
80320 taskstats_exit(tsk, group_dead);
80321
80322+ gr_acl_handle_psacct(tsk, code);
80323+ gr_acl_handle_exit();
80324+
80325 exit_mm(tsk);
80326
80327 if (group_dead)
80328@@ -894,7 +902,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
80329 * Take down every thread in the group. This is called by fatal signals
80330 * as well as by sys_exit_group (below).
80331 */
80332-void
80333+__noreturn void
80334 do_group_exit(int exit_code)
80335 {
80336 struct signal_struct *sig = current->signal;
80337diff --git a/kernel/fork.c b/kernel/fork.c
80338index bf46287..2af185d 100644
80339--- a/kernel/fork.c
80340+++ b/kernel/fork.c
80341@@ -319,7 +319,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
80342 *stackend = STACK_END_MAGIC; /* for overflow detection */
80343
80344 #ifdef CONFIG_CC_STACKPROTECTOR
80345- tsk->stack_canary = get_random_int();
80346+ tsk->stack_canary = pax_get_random_long();
80347 #endif
80348
80349 /*
80350@@ -345,13 +345,81 @@ free_tsk:
80351 }
80352
80353 #ifdef CONFIG_MMU
80354-static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
80355+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
80356 {
80357- struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
80358- struct rb_node **rb_link, *rb_parent;
80359- int retval;
80360+ struct vm_area_struct *tmp;
80361 unsigned long charge;
80362 struct mempolicy *pol;
80363+ struct file *file;
80364+
80365+ charge = 0;
80366+ if (mpnt->vm_flags & VM_ACCOUNT) {
80367+ unsigned long len = vma_pages(mpnt);
80368+
80369+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
80370+ goto fail_nomem;
80371+ charge = len;
80372+ }
80373+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
80374+ if (!tmp)
80375+ goto fail_nomem;
80376+ *tmp = *mpnt;
80377+ tmp->vm_mm = mm;
80378+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
80379+ pol = mpol_dup(vma_policy(mpnt));
80380+ if (IS_ERR(pol))
80381+ goto fail_nomem_policy;
80382+ vma_set_policy(tmp, pol);
80383+ if (anon_vma_fork(tmp, mpnt))
80384+ goto fail_nomem_anon_vma_fork;
80385+ tmp->vm_flags &= ~VM_LOCKED;
80386+ tmp->vm_next = tmp->vm_prev = NULL;
80387+ tmp->vm_mirror = NULL;
80388+ file = tmp->vm_file;
80389+ if (file) {
80390+ struct inode *inode = file_inode(file);
80391+ struct address_space *mapping = file->f_mapping;
80392+
80393+ get_file(file);
80394+ if (tmp->vm_flags & VM_DENYWRITE)
80395+ atomic_dec(&inode->i_writecount);
80396+ mutex_lock(&mapping->i_mmap_mutex);
80397+ if (tmp->vm_flags & VM_SHARED)
80398+ mapping->i_mmap_writable++;
80399+ flush_dcache_mmap_lock(mapping);
80400+ /* insert tmp into the share list, just after mpnt */
80401+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
80402+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
80403+ else
80404+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
80405+ flush_dcache_mmap_unlock(mapping);
80406+ mutex_unlock(&mapping->i_mmap_mutex);
80407+ }
80408+
80409+ /*
80410+ * Clear hugetlb-related page reserves for children. This only
80411+ * affects MAP_PRIVATE mappings. Faults generated by the child
80412+ * are not guaranteed to succeed, even if read-only
80413+ */
80414+ if (is_vm_hugetlb_page(tmp))
80415+ reset_vma_resv_huge_pages(tmp);
80416+
80417+ return tmp;
80418+
80419+fail_nomem_anon_vma_fork:
80420+ mpol_put(pol);
80421+fail_nomem_policy:
80422+ kmem_cache_free(vm_area_cachep, tmp);
80423+fail_nomem:
80424+ vm_unacct_memory(charge);
80425+ return NULL;
80426+}
80427+
80428+static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
80429+{
80430+ struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
80431+ struct rb_node **rb_link, *rb_parent;
80432+ int retval;
80433
80434 uprobe_start_dup_mmap();
80435 down_write(&oldmm->mmap_sem);
80436@@ -380,57 +448,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
80437
80438 prev = NULL;
80439 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
80440- struct file *file;
80441-
80442 if (mpnt->vm_flags & VM_DONTCOPY) {
80443 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
80444 -vma_pages(mpnt));
80445 continue;
80446 }
80447- charge = 0;
80448- if (mpnt->vm_flags & VM_ACCOUNT) {
80449- unsigned long len = vma_pages(mpnt);
80450-
80451- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
80452- goto fail_nomem;
80453- charge = len;
80454- }
80455- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
80456- if (!tmp)
80457- goto fail_nomem;
80458- *tmp = *mpnt;
80459- INIT_LIST_HEAD(&tmp->anon_vma_chain);
80460- pol = mpol_dup(vma_policy(mpnt));
80461- retval = PTR_ERR(pol);
80462- if (IS_ERR(pol))
80463- goto fail_nomem_policy;
80464- vma_set_policy(tmp, pol);
80465- tmp->vm_mm = mm;
80466- if (anon_vma_fork(tmp, mpnt))
80467- goto fail_nomem_anon_vma_fork;
80468- tmp->vm_flags &= ~VM_LOCKED;
80469- tmp->vm_next = tmp->vm_prev = NULL;
80470- file = tmp->vm_file;
80471- if (file) {
80472- struct inode *inode = file_inode(file);
80473- struct address_space *mapping = file->f_mapping;
80474-
80475- get_file(file);
80476- if (tmp->vm_flags & VM_DENYWRITE)
80477- atomic_dec(&inode->i_writecount);
80478- mutex_lock(&mapping->i_mmap_mutex);
80479- if (tmp->vm_flags & VM_SHARED)
80480- mapping->i_mmap_writable++;
80481- flush_dcache_mmap_lock(mapping);
80482- /* insert tmp into the share list, just after mpnt */
80483- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
80484- vma_nonlinear_insert(tmp,
80485- &mapping->i_mmap_nonlinear);
80486- else
80487- vma_interval_tree_insert_after(tmp, mpnt,
80488- &mapping->i_mmap);
80489- flush_dcache_mmap_unlock(mapping);
80490- mutex_unlock(&mapping->i_mmap_mutex);
80491+ tmp = dup_vma(mm, oldmm, mpnt);
80492+ if (!tmp) {
80493+ retval = -ENOMEM;
80494+ goto out;
80495 }
80496
80497 /*
80498@@ -462,6 +488,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
80499 if (retval)
80500 goto out;
80501 }
80502+
80503+#ifdef CONFIG_PAX_SEGMEXEC
80504+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
80505+ struct vm_area_struct *mpnt_m;
80506+
80507+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
80508+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
80509+
80510+ if (!mpnt->vm_mirror)
80511+ continue;
80512+
80513+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
80514+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
80515+ mpnt->vm_mirror = mpnt_m;
80516+ } else {
80517+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
80518+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
80519+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
80520+ mpnt->vm_mirror->vm_mirror = mpnt;
80521+ }
80522+ }
80523+ BUG_ON(mpnt_m);
80524+ }
80525+#endif
80526+
80527 /* a new mm has just been created */
80528 arch_dup_mmap(oldmm, mm);
80529 retval = 0;
80530@@ -471,14 +522,6 @@ out:
80531 up_write(&oldmm->mmap_sem);
80532 uprobe_end_dup_mmap();
80533 return retval;
80534-fail_nomem_anon_vma_fork:
80535- mpol_put(pol);
80536-fail_nomem_policy:
80537- kmem_cache_free(vm_area_cachep, tmp);
80538-fail_nomem:
80539- retval = -ENOMEM;
80540- vm_unacct_memory(charge);
80541- goto out;
80542 }
80543
80544 static inline int mm_alloc_pgd(struct mm_struct *mm)
80545@@ -691,8 +734,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
80546 return ERR_PTR(err);
80547
80548 mm = get_task_mm(task);
80549- if (mm && mm != current->mm &&
80550- !ptrace_may_access(task, mode)) {
80551+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
80552+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
80553 mmput(mm);
80554 mm = ERR_PTR(-EACCES);
80555 }
80556@@ -914,13 +957,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
80557 spin_unlock(&fs->lock);
80558 return -EAGAIN;
80559 }
80560- fs->users++;
80561+ atomic_inc(&fs->users);
80562 spin_unlock(&fs->lock);
80563 return 0;
80564 }
80565 tsk->fs = copy_fs_struct(fs);
80566 if (!tsk->fs)
80567 return -ENOMEM;
80568+ /* Carry through gr_chroot_dentry and is_chrooted instead
80569+ of recomputing it here. Already copied when the task struct
80570+ is duplicated. This allows pivot_root to not be treated as
80571+ a chroot
80572+ */
80573+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
80574+
80575 return 0;
80576 }
80577
80578@@ -1131,7 +1181,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
80579 * parts of the process environment (as per the clone
80580 * flags). The actual kick-off is left to the caller.
80581 */
80582-static struct task_struct *copy_process(unsigned long clone_flags,
80583+static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
80584 unsigned long stack_start,
80585 unsigned long stack_size,
80586 int __user *child_tidptr,
80587@@ -1200,6 +1250,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
80588 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
80589 #endif
80590 retval = -EAGAIN;
80591+
80592+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
80593+
80594 if (atomic_read(&p->real_cred->user->processes) >=
80595 task_rlimit(p, RLIMIT_NPROC)) {
80596 if (p->real_cred->user != INIT_USER &&
80597@@ -1449,6 +1502,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
80598 goto bad_fork_free_pid;
80599 }
80600
80601+ /* synchronizes with gr_set_acls()
80602+ we need to call this past the point of no return for fork()
80603+ */
80604+ gr_copy_label(p);
80605+
80606 if (likely(p->pid)) {
80607 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
80608
80609@@ -1534,6 +1592,8 @@ bad_fork_cleanup_count:
80610 bad_fork_free:
80611 free_task(p);
80612 fork_out:
80613+ gr_log_forkfail(retval);
80614+
80615 return ERR_PTR(retval);
80616 }
80617
80618@@ -1604,6 +1664,7 @@ long do_fork(unsigned long clone_flags,
80619
80620 p = copy_process(clone_flags, stack_start, stack_size,
80621 child_tidptr, NULL, trace);
80622+ add_latent_entropy();
80623 /*
80624 * Do this prior waking up the new thread - the thread pointer
80625 * might get invalid after that point, if the thread exits quickly.
80626@@ -1618,6 +1679,8 @@ long do_fork(unsigned long clone_flags,
80627 if (clone_flags & CLONE_PARENT_SETTID)
80628 put_user(nr, parent_tidptr);
80629
80630+ gr_handle_brute_check();
80631+
80632 if (clone_flags & CLONE_VFORK) {
80633 p->vfork_done = &vfork;
80634 init_completion(&vfork);
80635@@ -1734,7 +1797,7 @@ void __init proc_caches_init(void)
80636 mm_cachep = kmem_cache_create("mm_struct",
80637 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
80638 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
80639- vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
80640+ vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
80641 mmap_init();
80642 nsproxy_cache_init();
80643 }
80644@@ -1774,7 +1837,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
80645 return 0;
80646
80647 /* don't need lock here; in the worst case we'll do useless copy */
80648- if (fs->users == 1)
80649+ if (atomic_read(&fs->users) == 1)
80650 return 0;
80651
80652 *new_fsp = copy_fs_struct(fs);
80653@@ -1886,7 +1949,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
80654 fs = current->fs;
80655 spin_lock(&fs->lock);
80656 current->fs = new_fs;
80657- if (--fs->users)
80658+ gr_set_chroot_entries(current, &current->fs->root);
80659+ if (atomic_dec_return(&fs->users))
80660 new_fs = NULL;
80661 else
80662 new_fs = fs;
80663diff --git a/kernel/futex.c b/kernel/futex.c
80664index c3a1a55..e32b4a98 100644
80665--- a/kernel/futex.c
80666+++ b/kernel/futex.c
80667@@ -54,6 +54,7 @@
80668 #include <linux/mount.h>
80669 #include <linux/pagemap.h>
80670 #include <linux/syscalls.h>
80671+#include <linux/ptrace.h>
80672 #include <linux/signal.h>
80673 #include <linux/export.h>
80674 #include <linux/magic.h>
80675@@ -243,6 +244,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
80676 struct page *page, *page_head;
80677 int err, ro = 0;
80678
80679+#ifdef CONFIG_PAX_SEGMEXEC
80680+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
80681+ return -EFAULT;
80682+#endif
80683+
80684 /*
80685 * The futex address must be "naturally" aligned.
80686 */
80687@@ -441,7 +447,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
80688
80689 static int get_futex_value_locked(u32 *dest, u32 __user *from)
80690 {
80691- int ret;
80692+ unsigned long ret;
80693
80694 pagefault_disable();
80695 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
80696@@ -2734,6 +2740,7 @@ static int __init futex_init(void)
80697 {
80698 u32 curval;
80699 int i;
80700+ mm_segment_t oldfs;
80701
80702 /*
80703 * This will fail and we want it. Some arch implementations do
80704@@ -2745,8 +2752,11 @@ static int __init futex_init(void)
80705 * implementation, the non-functional ones will return
80706 * -ENOSYS.
80707 */
80708+ oldfs = get_fs();
80709+ set_fs(USER_DS);
80710 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
80711 futex_cmpxchg_enabled = 1;
80712+ set_fs(oldfs);
80713
80714 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
80715 plist_head_init(&futex_queues[i].chain);
80716diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
80717index f9f44fd..29885e4 100644
80718--- a/kernel/futex_compat.c
80719+++ b/kernel/futex_compat.c
80720@@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
80721 return 0;
80722 }
80723
80724-static void __user *futex_uaddr(struct robust_list __user *entry,
80725+static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
80726 compat_long_t futex_offset)
80727 {
80728 compat_uptr_t base = ptr_to_compat(entry);
80729diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
80730index 9b22d03..6295b62 100644
80731--- a/kernel/gcov/base.c
80732+++ b/kernel/gcov/base.c
80733@@ -102,11 +102,6 @@ void gcov_enable_events(void)
80734 }
80735
80736 #ifdef CONFIG_MODULES
80737-static inline int within(void *addr, void *start, unsigned long size)
80738-{
80739- return ((addr >= start) && (addr < start + size));
80740-}
80741-
80742 /* Update list and generate events when modules are unloaded. */
80743 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
80744 void *data)
80745@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
80746 prev = NULL;
80747 /* Remove entries located in module from linked list. */
80748 for (info = gcov_info_head; info; info = info->next) {
80749- if (within(info, mod->module_core, mod->core_size)) {
80750+ if (within_module_core_rw((unsigned long)info, mod)) {
80751 if (prev)
80752 prev->next = info->next;
80753 else
80754diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
80755index 383319b..cd2b391 100644
80756--- a/kernel/hrtimer.c
80757+++ b/kernel/hrtimer.c
80758@@ -1438,7 +1438,7 @@ void hrtimer_peek_ahead_timers(void)
80759 local_irq_restore(flags);
80760 }
80761
80762-static void run_hrtimer_softirq(struct softirq_action *h)
80763+static void run_hrtimer_softirq(void)
80764 {
80765 hrtimer_peek_ahead_timers();
80766 }
80767diff --git a/kernel/irq_work.c b/kernel/irq_work.c
80768index 55fcce6..0e4cf34 100644
80769--- a/kernel/irq_work.c
80770+++ b/kernel/irq_work.c
80771@@ -189,12 +189,13 @@ static int irq_work_cpu_notify(struct notifier_block *self,
80772 return NOTIFY_OK;
80773 }
80774
80775-static struct notifier_block cpu_notify;
80776+static struct notifier_block cpu_notify = {
80777+ .notifier_call = irq_work_cpu_notify,
80778+ .priority = 0,
80779+};
80780
80781 static __init int irq_work_init_cpu_notifier(void)
80782 {
80783- cpu_notify.notifier_call = irq_work_cpu_notify;
80784- cpu_notify.priority = 0;
80785 register_cpu_notifier(&cpu_notify);
80786 return 0;
80787 }
80788diff --git a/kernel/jump_label.c b/kernel/jump_label.c
80789index 60f48fa..7f3a770 100644
80790--- a/kernel/jump_label.c
80791+++ b/kernel/jump_label.c
80792@@ -13,6 +13,7 @@
80793 #include <linux/sort.h>
80794 #include <linux/err.h>
80795 #include <linux/static_key.h>
80796+#include <linux/mm.h>
80797
80798 #ifdef HAVE_JUMP_LABEL
80799
80800@@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
80801
80802 size = (((unsigned long)stop - (unsigned long)start)
80803 / sizeof(struct jump_entry));
80804+ pax_open_kernel();
80805 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
80806+ pax_close_kernel();
80807 }
80808
80809 static void jump_label_update(struct static_key *key, int enable);
80810@@ -357,10 +360,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
80811 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
80812 struct jump_entry *iter;
80813
80814+ pax_open_kernel();
80815 for (iter = iter_start; iter < iter_stop; iter++) {
80816 if (within_module_init(iter->code, mod))
80817 iter->code = 0;
80818 }
80819+ pax_close_kernel();
80820 }
80821
80822 static int
80823diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
80824index 3127ad5..159d880 100644
80825--- a/kernel/kallsyms.c
80826+++ b/kernel/kallsyms.c
80827@@ -11,6 +11,9 @@
80828 * Changed the compression method from stem compression to "table lookup"
80829 * compression (see scripts/kallsyms.c for a more complete description)
80830 */
80831+#ifdef CONFIG_GRKERNSEC_HIDESYM
80832+#define __INCLUDED_BY_HIDESYM 1
80833+#endif
80834 #include <linux/kallsyms.h>
80835 #include <linux/module.h>
80836 #include <linux/init.h>
80837@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
80838
80839 static inline int is_kernel_inittext(unsigned long addr)
80840 {
80841+ if (system_state != SYSTEM_BOOTING)
80842+ return 0;
80843+
80844 if (addr >= (unsigned long)_sinittext
80845 && addr <= (unsigned long)_einittext)
80846 return 1;
80847 return 0;
80848 }
80849
80850+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
80851+#ifdef CONFIG_MODULES
80852+static inline int is_module_text(unsigned long addr)
80853+{
80854+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
80855+ return 1;
80856+
80857+ addr = ktla_ktva(addr);
80858+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
80859+}
80860+#else
80861+static inline int is_module_text(unsigned long addr)
80862+{
80863+ return 0;
80864+}
80865+#endif
80866+#endif
80867+
80868 static inline int is_kernel_text(unsigned long addr)
80869 {
80870 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
80871@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
80872
80873 static inline int is_kernel(unsigned long addr)
80874 {
80875+
80876+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
80877+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
80878+ return 1;
80879+
80880+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
80881+#else
80882 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
80883+#endif
80884+
80885 return 1;
80886 return in_gate_area_no_mm(addr);
80887 }
80888
80889 static int is_ksym_addr(unsigned long addr)
80890 {
80891+
80892+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
80893+ if (is_module_text(addr))
80894+ return 0;
80895+#endif
80896+
80897 if (all_var)
80898 return is_kernel(addr);
80899
80900@@ -480,7 +519,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
80901
80902 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
80903 {
80904- iter->name[0] = '\0';
80905 iter->nameoff = get_symbol_offset(new_pos);
80906 iter->pos = new_pos;
80907 }
80908@@ -528,6 +566,11 @@ static int s_show(struct seq_file *m, void *p)
80909 {
80910 struct kallsym_iter *iter = m->private;
80911
80912+#ifdef CONFIG_GRKERNSEC_HIDESYM
80913+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
80914+ return 0;
80915+#endif
80916+
80917 /* Some debugging symbols have no name. Ignore them. */
80918 if (!iter->name[0])
80919 return 0;
80920@@ -541,6 +584,7 @@ static int s_show(struct seq_file *m, void *p)
80921 */
80922 type = iter->exported ? toupper(iter->type) :
80923 tolower(iter->type);
80924+
80925 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
80926 type, iter->name, iter->module_name);
80927 } else
80928@@ -566,7 +610,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
80929 struct kallsym_iter *iter;
80930 int ret;
80931
80932- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
80933+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
80934 if (!iter)
80935 return -ENOMEM;
80936 reset_iter(iter, 0);
80937diff --git a/kernel/kcmp.c b/kernel/kcmp.c
80938index e30ac0f..3528cac 100644
80939--- a/kernel/kcmp.c
80940+++ b/kernel/kcmp.c
80941@@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
80942 struct task_struct *task1, *task2;
80943 int ret;
80944
80945+#ifdef CONFIG_GRKERNSEC
80946+ return -ENOSYS;
80947+#endif
80948+
80949 rcu_read_lock();
80950
80951 /*
80952diff --git a/kernel/kexec.c b/kernel/kexec.c
80953index 59f7b55..4022f65 100644
80954--- a/kernel/kexec.c
80955+++ b/kernel/kexec.c
80956@@ -1041,7 +1041,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
80957 unsigned long flags)
80958 {
80959 struct compat_kexec_segment in;
80960- struct kexec_segment out, __user *ksegments;
80961+ struct kexec_segment out;
80962+ struct kexec_segment __user *ksegments;
80963 unsigned long i, result;
80964
80965 /* Don't allow clients that don't understand the native
80966diff --git a/kernel/kmod.c b/kernel/kmod.c
80967index fb32636..2fe8775 100644
80968--- a/kernel/kmod.c
80969+++ b/kernel/kmod.c
80970@@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
80971 kfree(info->argv);
80972 }
80973
80974-static int call_modprobe(char *module_name, int wait)
80975+static int call_modprobe(char *module_name, char *module_param, int wait)
80976 {
80977 struct subprocess_info *info;
80978 static char *envp[] = {
80979@@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
80980 NULL
80981 };
80982
80983- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
80984+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
80985 if (!argv)
80986 goto out;
80987
80988@@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
80989 argv[1] = "-q";
80990 argv[2] = "--";
80991 argv[3] = module_name; /* check free_modprobe_argv() */
80992- argv[4] = NULL;
80993+ argv[4] = module_param;
80994+ argv[5] = NULL;
80995
80996 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
80997 NULL, free_modprobe_argv, NULL);
80998@@ -129,9 +130,8 @@ out:
80999 * If module auto-loading support is disabled then this function
81000 * becomes a no-operation.
81001 */
81002-int __request_module(bool wait, const char *fmt, ...)
81003+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
81004 {
81005- va_list args;
81006 char module_name[MODULE_NAME_LEN];
81007 unsigned int max_modprobes;
81008 int ret;
81009@@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
81010 if (!modprobe_path[0])
81011 return 0;
81012
81013- va_start(args, fmt);
81014- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
81015- va_end(args);
81016+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
81017 if (ret >= MODULE_NAME_LEN)
81018 return -ENAMETOOLONG;
81019
81020@@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
81021 if (ret)
81022 return ret;
81023
81024+#ifdef CONFIG_GRKERNSEC_MODHARDEN
81025+ if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
81026+ /* hack to workaround consolekit/udisks stupidity */
81027+ read_lock(&tasklist_lock);
81028+ if (!strcmp(current->comm, "mount") &&
81029+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
81030+ read_unlock(&tasklist_lock);
81031+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
81032+ return -EPERM;
81033+ }
81034+ read_unlock(&tasklist_lock);
81035+ }
81036+#endif
81037+
81038 /* If modprobe needs a service that is in a module, we get a recursive
81039 * loop. Limit the number of running kmod threads to max_threads/2 or
81040 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
81041@@ -188,11 +200,52 @@ int __request_module(bool wait, const char *fmt, ...)
81042
81043 trace_module_request(module_name, wait, _RET_IP_);
81044
81045- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
81046+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
81047
81048 atomic_dec(&kmod_concurrent);
81049 return ret;
81050 }
81051+
81052+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
81053+{
81054+ va_list args;
81055+ int ret;
81056+
81057+ va_start(args, fmt);
81058+ ret = ____request_module(wait, module_param, fmt, args);
81059+ va_end(args);
81060+
81061+ return ret;
81062+}
81063+
81064+int __request_module(bool wait, const char *fmt, ...)
81065+{
81066+ va_list args;
81067+ int ret;
81068+
81069+#ifdef CONFIG_GRKERNSEC_MODHARDEN
81070+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
81071+ char module_param[MODULE_NAME_LEN];
81072+
81073+ memset(module_param, 0, sizeof(module_param));
81074+
81075+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
81076+
81077+ va_start(args, fmt);
81078+ ret = ____request_module(wait, module_param, fmt, args);
81079+ va_end(args);
81080+
81081+ return ret;
81082+ }
81083+#endif
81084+
81085+ va_start(args, fmt);
81086+ ret = ____request_module(wait, NULL, fmt, args);
81087+ va_end(args);
81088+
81089+ return ret;
81090+}
81091+
81092 EXPORT_SYMBOL(__request_module);
81093 #endif /* CONFIG_MODULES */
81094
81095@@ -303,7 +356,7 @@ static int wait_for_helper(void *data)
81096 *
81097 * Thus the __user pointer cast is valid here.
81098 */
81099- sys_wait4(pid, (int __user *)&ret, 0, NULL);
81100+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
81101
81102 /*
81103 * If ret is 0, either ____call_usermodehelper failed and the
81104@@ -646,7 +699,7 @@ EXPORT_SYMBOL(call_usermodehelper);
81105 static int proc_cap_handler(struct ctl_table *table, int write,
81106 void __user *buffer, size_t *lenp, loff_t *ppos)
81107 {
81108- struct ctl_table t;
81109+ ctl_table_no_const t;
81110 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
81111 kernel_cap_t new_cap;
81112 int err, i;
81113diff --git a/kernel/kprobes.c b/kernel/kprobes.c
81114index 6e33498..3133bd3 100644
81115--- a/kernel/kprobes.c
81116+++ b/kernel/kprobes.c
81117@@ -31,6 +31,9 @@
81118 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
81119 * <prasanna@in.ibm.com> added function-return probes.
81120 */
81121+#ifdef CONFIG_GRKERNSEC_HIDESYM
81122+#define __INCLUDED_BY_HIDESYM 1
81123+#endif
81124 #include <linux/kprobes.h>
81125 #include <linux/hash.h>
81126 #include <linux/init.h>
81127@@ -185,7 +188,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
81128 * kernel image and loaded module images reside. This is required
81129 * so x86_64 can correctly handle the %rip-relative fixups.
81130 */
81131- kip->insns = module_alloc(PAGE_SIZE);
81132+ kip->insns = module_alloc_exec(PAGE_SIZE);
81133 if (!kip->insns) {
81134 kfree(kip);
81135 return NULL;
81136@@ -225,7 +228,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
81137 */
81138 if (!list_is_singular(&kip->list)) {
81139 list_del(&kip->list);
81140- module_free(NULL, kip->insns);
81141+ module_free_exec(NULL, kip->insns);
81142 kfree(kip);
81143 }
81144 return 1;
81145@@ -2083,7 +2086,7 @@ static int __init init_kprobes(void)
81146 {
81147 int i, err = 0;
81148 unsigned long offset = 0, size = 0;
81149- char *modname, namebuf[128];
81150+ char *modname, namebuf[KSYM_NAME_LEN];
81151 const char *symbol_name;
81152 void *addr;
81153 struct kprobe_blackpoint *kb;
81154@@ -2168,11 +2171,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
81155 kprobe_type = "k";
81156
81157 if (sym)
81158- seq_printf(pi, "%p %s %s+0x%x %s ",
81159+ seq_printf(pi, "%pK %s %s+0x%x %s ",
81160 p->addr, kprobe_type, sym, offset,
81161 (modname ? modname : " "));
81162 else
81163- seq_printf(pi, "%p %s %p ",
81164+ seq_printf(pi, "%pK %s %pK ",
81165 p->addr, kprobe_type, p->addr);
81166
81167 if (!pp)
81168@@ -2209,7 +2212,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
81169 const char *sym = NULL;
81170 unsigned int i = *(loff_t *) v;
81171 unsigned long offset = 0;
81172- char *modname, namebuf[128];
81173+ char *modname, namebuf[KSYM_NAME_LEN];
81174
81175 head = &kprobe_table[i];
81176 preempt_disable();
81177diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
81178index 6ada93c..dce7d5d 100644
81179--- a/kernel/ksysfs.c
81180+++ b/kernel/ksysfs.c
81181@@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
81182 {
81183 if (count+1 > UEVENT_HELPER_PATH_LEN)
81184 return -ENOENT;
81185+ if (!capable(CAP_SYS_ADMIN))
81186+ return -EPERM;
81187 memcpy(uevent_helper, buf, count);
81188 uevent_helper[count] = '\0';
81189 if (count && uevent_helper[count-1] == '\n')
81190@@ -172,7 +174,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
81191 return count;
81192 }
81193
81194-static struct bin_attribute notes_attr = {
81195+static bin_attribute_no_const notes_attr __read_only = {
81196 .attr = {
81197 .name = "notes",
81198 .mode = S_IRUGO,
81199diff --git a/kernel/lockdep.c b/kernel/lockdep.c
81200index e16c45b..6f49c48 100644
81201--- a/kernel/lockdep.c
81202+++ b/kernel/lockdep.c
81203@@ -596,6 +596,10 @@ static int static_obj(void *obj)
81204 end = (unsigned long) &_end,
81205 addr = (unsigned long) obj;
81206
81207+#ifdef CONFIG_PAX_KERNEXEC
81208+ start = ktla_ktva(start);
81209+#endif
81210+
81211 /*
81212 * static variable?
81213 */
81214@@ -736,6 +740,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
81215 if (!static_obj(lock->key)) {
81216 debug_locks_off();
81217 printk("INFO: trying to register non-static key.\n");
81218+ printk("lock:%pS key:%pS.\n", lock, lock->key);
81219 printk("the code is fine but needs lockdep annotation.\n");
81220 printk("turning off the locking correctness validator.\n");
81221 dump_stack();
81222@@ -3080,7 +3085,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
81223 if (!class)
81224 return 0;
81225 }
81226- atomic_inc((atomic_t *)&class->ops);
81227+ atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
81228 if (very_verbose(class)) {
81229 printk("\nacquire class [%p] %s", class->key, class->name);
81230 if (class->name_version > 1)
81231diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
81232index b2c71c5..7b88d63 100644
81233--- a/kernel/lockdep_proc.c
81234+++ b/kernel/lockdep_proc.c
81235@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
81236 return 0;
81237 }
81238
81239- seq_printf(m, "%p", class->key);
81240+ seq_printf(m, "%pK", class->key);
81241 #ifdef CONFIG_DEBUG_LOCKDEP
81242 seq_printf(m, " OPS:%8ld", class->ops);
81243 #endif
81244@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
81245
81246 list_for_each_entry(entry, &class->locks_after, entry) {
81247 if (entry->distance == 1) {
81248- seq_printf(m, " -> [%p] ", entry->class->key);
81249+ seq_printf(m, " -> [%pK] ", entry->class->key);
81250 print_name(m, entry->class);
81251 seq_puts(m, "\n");
81252 }
81253@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
81254 if (!class->key)
81255 continue;
81256
81257- seq_printf(m, "[%p] ", class->key);
81258+ seq_printf(m, "[%pK] ", class->key);
81259 print_name(m, class);
81260 seq_puts(m, "\n");
81261 }
81262@@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
81263 if (!i)
81264 seq_line(m, '-', 40-namelen, namelen);
81265
81266- snprintf(ip, sizeof(ip), "[<%p>]",
81267+ snprintf(ip, sizeof(ip), "[<%pK>]",
81268 (void *)class->contention_point[i]);
81269 seq_printf(m, "%40s %14lu %29s %pS\n",
81270 name, stats->contention_point[i],
81271@@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
81272 if (!i)
81273 seq_line(m, '-', 40-namelen, namelen);
81274
81275- snprintf(ip, sizeof(ip), "[<%p>]",
81276+ snprintf(ip, sizeof(ip), "[<%pK>]",
81277 (void *)class->contending_point[i]);
81278 seq_printf(m, "%40s %14lu %29s %pS\n",
81279 name, stats->contending_point[i],
81280diff --git a/kernel/module.c b/kernel/module.c
81281index 2069158..71101bb 100644
81282--- a/kernel/module.c
81283+++ b/kernel/module.c
81284@@ -61,6 +61,7 @@
81285 #include <linux/pfn.h>
81286 #include <linux/bsearch.h>
81287 #include <linux/fips.h>
81288+#include <linux/grsecurity.h>
81289 #include <uapi/linux/module.h>
81290 #include "module-internal.h"
81291
81292@@ -156,7 +157,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
81293
81294 /* Bounds of module allocation, for speeding __module_address.
81295 * Protected by module_mutex. */
81296-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
81297+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
81298+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
81299
81300 int register_module_notifier(struct notifier_block * nb)
81301 {
81302@@ -323,7 +325,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
81303 return true;
81304
81305 list_for_each_entry_rcu(mod, &modules, list) {
81306- struct symsearch arr[] = {
81307+ struct symsearch modarr[] = {
81308 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
81309 NOT_GPL_ONLY, false },
81310 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
81311@@ -348,7 +350,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
81312 if (mod->state == MODULE_STATE_UNFORMED)
81313 continue;
81314
81315- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
81316+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
81317 return true;
81318 }
81319 return false;
81320@@ -490,7 +492,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
81321 if (!pcpusec->sh_size)
81322 return 0;
81323
81324- if (align > PAGE_SIZE) {
81325+ if (align-1 >= PAGE_SIZE) {
81326 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
81327 mod->name, align, PAGE_SIZE);
81328 align = PAGE_SIZE;
81329@@ -1096,7 +1098,7 @@ struct module_attribute module_uevent =
81330 static ssize_t show_coresize(struct module_attribute *mattr,
81331 struct module_kobject *mk, char *buffer)
81332 {
81333- return sprintf(buffer, "%u\n", mk->mod->core_size);
81334+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
81335 }
81336
81337 static struct module_attribute modinfo_coresize =
81338@@ -1105,7 +1107,7 @@ static struct module_attribute modinfo_coresize =
81339 static ssize_t show_initsize(struct module_attribute *mattr,
81340 struct module_kobject *mk, char *buffer)
81341 {
81342- return sprintf(buffer, "%u\n", mk->mod->init_size);
81343+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
81344 }
81345
81346 static struct module_attribute modinfo_initsize =
81347@@ -1320,7 +1322,7 @@ resolve_symbol_wait(struct module *mod,
81348 */
81349 #ifdef CONFIG_SYSFS
81350
81351-#ifdef CONFIG_KALLSYMS
81352+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
81353 static inline bool sect_empty(const Elf_Shdr *sect)
81354 {
81355 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
81356@@ -1460,7 +1462,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
81357 {
81358 unsigned int notes, loaded, i;
81359 struct module_notes_attrs *notes_attrs;
81360- struct bin_attribute *nattr;
81361+ bin_attribute_no_const *nattr;
81362
81363 /* failed to create section attributes, so can't create notes */
81364 if (!mod->sect_attrs)
81365@@ -1572,7 +1574,7 @@ static void del_usage_links(struct module *mod)
81366 static int module_add_modinfo_attrs(struct module *mod)
81367 {
81368 struct module_attribute *attr;
81369- struct module_attribute *temp_attr;
81370+ module_attribute_no_const *temp_attr;
81371 int error = 0;
81372 int i;
81373
81374@@ -1786,21 +1788,21 @@ static void set_section_ro_nx(void *base,
81375
81376 static void unset_module_core_ro_nx(struct module *mod)
81377 {
81378- set_page_attributes(mod->module_core + mod->core_text_size,
81379- mod->module_core + mod->core_size,
81380+ set_page_attributes(mod->module_core_rw,
81381+ mod->module_core_rw + mod->core_size_rw,
81382 set_memory_x);
81383- set_page_attributes(mod->module_core,
81384- mod->module_core + mod->core_ro_size,
81385+ set_page_attributes(mod->module_core_rx,
81386+ mod->module_core_rx + mod->core_size_rx,
81387 set_memory_rw);
81388 }
81389
81390 static void unset_module_init_ro_nx(struct module *mod)
81391 {
81392- set_page_attributes(mod->module_init + mod->init_text_size,
81393- mod->module_init + mod->init_size,
81394+ set_page_attributes(mod->module_init_rw,
81395+ mod->module_init_rw + mod->init_size_rw,
81396 set_memory_x);
81397- set_page_attributes(mod->module_init,
81398- mod->module_init + mod->init_ro_size,
81399+ set_page_attributes(mod->module_init_rx,
81400+ mod->module_init_rx + mod->init_size_rx,
81401 set_memory_rw);
81402 }
81403
81404@@ -1813,14 +1815,14 @@ void set_all_modules_text_rw(void)
81405 list_for_each_entry_rcu(mod, &modules, list) {
81406 if (mod->state == MODULE_STATE_UNFORMED)
81407 continue;
81408- if ((mod->module_core) && (mod->core_text_size)) {
81409- set_page_attributes(mod->module_core,
81410- mod->module_core + mod->core_text_size,
81411+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
81412+ set_page_attributes(mod->module_core_rx,
81413+ mod->module_core_rx + mod->core_size_rx,
81414 set_memory_rw);
81415 }
81416- if ((mod->module_init) && (mod->init_text_size)) {
81417- set_page_attributes(mod->module_init,
81418- mod->module_init + mod->init_text_size,
81419+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
81420+ set_page_attributes(mod->module_init_rx,
81421+ mod->module_init_rx + mod->init_size_rx,
81422 set_memory_rw);
81423 }
81424 }
81425@@ -1836,14 +1838,14 @@ void set_all_modules_text_ro(void)
81426 list_for_each_entry_rcu(mod, &modules, list) {
81427 if (mod->state == MODULE_STATE_UNFORMED)
81428 continue;
81429- if ((mod->module_core) && (mod->core_text_size)) {
81430- set_page_attributes(mod->module_core,
81431- mod->module_core + mod->core_text_size,
81432+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
81433+ set_page_attributes(mod->module_core_rx,
81434+ mod->module_core_rx + mod->core_size_rx,
81435 set_memory_ro);
81436 }
81437- if ((mod->module_init) && (mod->init_text_size)) {
81438- set_page_attributes(mod->module_init,
81439- mod->module_init + mod->init_text_size,
81440+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
81441+ set_page_attributes(mod->module_init_rx,
81442+ mod->module_init_rx + mod->init_size_rx,
81443 set_memory_ro);
81444 }
81445 }
81446@@ -1894,16 +1896,19 @@ static void free_module(struct module *mod)
81447
81448 /* This may be NULL, but that's OK */
81449 unset_module_init_ro_nx(mod);
81450- module_free(mod, mod->module_init);
81451+ module_free(mod, mod->module_init_rw);
81452+ module_free_exec(mod, mod->module_init_rx);
81453 kfree(mod->args);
81454 percpu_modfree(mod);
81455
81456 /* Free lock-classes: */
81457- lockdep_free_key_range(mod->module_core, mod->core_size);
81458+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
81459+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
81460
81461 /* Finally, free the core (containing the module structure) */
81462 unset_module_core_ro_nx(mod);
81463- module_free(mod, mod->module_core);
81464+ module_free_exec(mod, mod->module_core_rx);
81465+ module_free(mod, mod->module_core_rw);
81466
81467 #ifdef CONFIG_MPU
81468 update_protections(current->mm);
81469@@ -1973,9 +1978,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
81470 int ret = 0;
81471 const struct kernel_symbol *ksym;
81472
81473+#ifdef CONFIG_GRKERNSEC_MODHARDEN
81474+ int is_fs_load = 0;
81475+ int register_filesystem_found = 0;
81476+ char *p;
81477+
81478+ p = strstr(mod->args, "grsec_modharden_fs");
81479+ if (p) {
81480+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
81481+ /* copy \0 as well */
81482+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
81483+ is_fs_load = 1;
81484+ }
81485+#endif
81486+
81487 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
81488 const char *name = info->strtab + sym[i].st_name;
81489
81490+#ifdef CONFIG_GRKERNSEC_MODHARDEN
81491+ /* it's a real shame this will never get ripped and copied
81492+ upstream! ;(
81493+ */
81494+ if (is_fs_load && !strcmp(name, "register_filesystem"))
81495+ register_filesystem_found = 1;
81496+#endif
81497+
81498 switch (sym[i].st_shndx) {
81499 case SHN_COMMON:
81500 /* We compiled with -fno-common. These are not
81501@@ -1996,7 +2023,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
81502 ksym = resolve_symbol_wait(mod, info, name);
81503 /* Ok if resolved. */
81504 if (ksym && !IS_ERR(ksym)) {
81505+ pax_open_kernel();
81506 sym[i].st_value = ksym->value;
81507+ pax_close_kernel();
81508 break;
81509 }
81510
81511@@ -2015,11 +2044,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
81512 secbase = (unsigned long)mod_percpu(mod);
81513 else
81514 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
81515+ pax_open_kernel();
81516 sym[i].st_value += secbase;
81517+ pax_close_kernel();
81518 break;
81519 }
81520 }
81521
81522+#ifdef CONFIG_GRKERNSEC_MODHARDEN
81523+ if (is_fs_load && !register_filesystem_found) {
81524+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
81525+ ret = -EPERM;
81526+ }
81527+#endif
81528+
81529 return ret;
81530 }
81531
81532@@ -2103,22 +2141,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
81533 || s->sh_entsize != ~0UL
81534 || strstarts(sname, ".init"))
81535 continue;
81536- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
81537+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
81538+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
81539+ else
81540+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
81541 pr_debug("\t%s\n", sname);
81542 }
81543- switch (m) {
81544- case 0: /* executable */
81545- mod->core_size = debug_align(mod->core_size);
81546- mod->core_text_size = mod->core_size;
81547- break;
81548- case 1: /* RO: text and ro-data */
81549- mod->core_size = debug_align(mod->core_size);
81550- mod->core_ro_size = mod->core_size;
81551- break;
81552- case 3: /* whole core */
81553- mod->core_size = debug_align(mod->core_size);
81554- break;
81555- }
81556 }
81557
81558 pr_debug("Init section allocation order:\n");
81559@@ -2132,23 +2160,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
81560 || s->sh_entsize != ~0UL
81561 || !strstarts(sname, ".init"))
81562 continue;
81563- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
81564- | INIT_OFFSET_MASK);
81565+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
81566+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
81567+ else
81568+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
81569+ s->sh_entsize |= INIT_OFFSET_MASK;
81570 pr_debug("\t%s\n", sname);
81571 }
81572- switch (m) {
81573- case 0: /* executable */
81574- mod->init_size = debug_align(mod->init_size);
81575- mod->init_text_size = mod->init_size;
81576- break;
81577- case 1: /* RO: text and ro-data */
81578- mod->init_size = debug_align(mod->init_size);
81579- mod->init_ro_size = mod->init_size;
81580- break;
81581- case 3: /* whole init */
81582- mod->init_size = debug_align(mod->init_size);
81583- break;
81584- }
81585 }
81586 }
81587
81588@@ -2321,7 +2339,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
81589
81590 /* Put symbol section at end of init part of module. */
81591 symsect->sh_flags |= SHF_ALLOC;
81592- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
81593+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
81594 info->index.sym) | INIT_OFFSET_MASK;
81595 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
81596
81597@@ -2338,13 +2356,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
81598 }
81599
81600 /* Append room for core symbols at end of core part. */
81601- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
81602- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
81603- mod->core_size += strtab_size;
81604+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
81605+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
81606+ mod->core_size_rx += strtab_size;
81607
81608 /* Put string table section at end of init part of module. */
81609 strsect->sh_flags |= SHF_ALLOC;
81610- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
81611+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
81612 info->index.str) | INIT_OFFSET_MASK;
81613 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
81614 }
81615@@ -2362,12 +2380,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
81616 /* Make sure we get permanent strtab: don't use info->strtab. */
81617 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
81618
81619+ pax_open_kernel();
81620+
81621 /* Set types up while we still have access to sections. */
81622 for (i = 0; i < mod->num_symtab; i++)
81623 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
81624
81625- mod->core_symtab = dst = mod->module_core + info->symoffs;
81626- mod->core_strtab = s = mod->module_core + info->stroffs;
81627+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
81628+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
81629 src = mod->symtab;
81630 for (ndst = i = 0; i < mod->num_symtab; i++) {
81631 if (i == 0 ||
81632@@ -2379,6 +2399,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
81633 }
81634 }
81635 mod->core_num_syms = ndst;
81636+
81637+ pax_close_kernel();
81638 }
81639 #else
81640 static inline void layout_symtab(struct module *mod, struct load_info *info)
81641@@ -2412,17 +2434,33 @@ void * __weak module_alloc(unsigned long size)
81642 return vmalloc_exec(size);
81643 }
81644
81645-static void *module_alloc_update_bounds(unsigned long size)
81646+static void *module_alloc_update_bounds_rw(unsigned long size)
81647 {
81648 void *ret = module_alloc(size);
81649
81650 if (ret) {
81651 mutex_lock(&module_mutex);
81652 /* Update module bounds. */
81653- if ((unsigned long)ret < module_addr_min)
81654- module_addr_min = (unsigned long)ret;
81655- if ((unsigned long)ret + size > module_addr_max)
81656- module_addr_max = (unsigned long)ret + size;
81657+ if ((unsigned long)ret < module_addr_min_rw)
81658+ module_addr_min_rw = (unsigned long)ret;
81659+ if ((unsigned long)ret + size > module_addr_max_rw)
81660+ module_addr_max_rw = (unsigned long)ret + size;
81661+ mutex_unlock(&module_mutex);
81662+ }
81663+ return ret;
81664+}
81665+
81666+static void *module_alloc_update_bounds_rx(unsigned long size)
81667+{
81668+ void *ret = module_alloc_exec(size);
81669+
81670+ if (ret) {
81671+ mutex_lock(&module_mutex);
81672+ /* Update module bounds. */
81673+ if ((unsigned long)ret < module_addr_min_rx)
81674+ module_addr_min_rx = (unsigned long)ret;
81675+ if ((unsigned long)ret + size > module_addr_max_rx)
81676+ module_addr_max_rx = (unsigned long)ret + size;
81677 mutex_unlock(&module_mutex);
81678 }
81679 return ret;
81680@@ -2698,8 +2736,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
81681 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
81682 {
81683 const char *modmagic = get_modinfo(info, "vermagic");
81684+ const char *license = get_modinfo(info, "license");
81685 int err;
81686
81687+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
81688+ if (!license || !license_is_gpl_compatible(license))
81689+ return -ENOEXEC;
81690+#endif
81691+
81692 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
81693 modmagic = NULL;
81694
81695@@ -2725,7 +2769,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
81696 }
81697
81698 /* Set up license info based on the info section */
81699- set_license(mod, get_modinfo(info, "license"));
81700+ set_license(mod, license);
81701
81702 return 0;
81703 }
81704@@ -2806,7 +2850,7 @@ static int move_module(struct module *mod, struct load_info *info)
81705 void *ptr;
81706
81707 /* Do the allocs. */
81708- ptr = module_alloc_update_bounds(mod->core_size);
81709+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
81710 /*
81711 * The pointer to this block is stored in the module structure
81712 * which is inside the block. Just mark it as not being a
81713@@ -2816,11 +2860,11 @@ static int move_module(struct module *mod, struct load_info *info)
81714 if (!ptr)
81715 return -ENOMEM;
81716
81717- memset(ptr, 0, mod->core_size);
81718- mod->module_core = ptr;
81719+ memset(ptr, 0, mod->core_size_rw);
81720+ mod->module_core_rw = ptr;
81721
81722- if (mod->init_size) {
81723- ptr = module_alloc_update_bounds(mod->init_size);
81724+ if (mod->init_size_rw) {
81725+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
81726 /*
81727 * The pointer to this block is stored in the module structure
81728 * which is inside the block. This block doesn't need to be
81729@@ -2829,13 +2873,45 @@ static int move_module(struct module *mod, struct load_info *info)
81730 */
81731 kmemleak_ignore(ptr);
81732 if (!ptr) {
81733- module_free(mod, mod->module_core);
81734+ module_free(mod, mod->module_core_rw);
81735 return -ENOMEM;
81736 }
81737- memset(ptr, 0, mod->init_size);
81738- mod->module_init = ptr;
81739+ memset(ptr, 0, mod->init_size_rw);
81740+ mod->module_init_rw = ptr;
81741 } else
81742- mod->module_init = NULL;
81743+ mod->module_init_rw = NULL;
81744+
81745+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
81746+ kmemleak_not_leak(ptr);
81747+ if (!ptr) {
81748+ if (mod->module_init_rw)
81749+ module_free(mod, mod->module_init_rw);
81750+ module_free(mod, mod->module_core_rw);
81751+ return -ENOMEM;
81752+ }
81753+
81754+ pax_open_kernel();
81755+ memset(ptr, 0, mod->core_size_rx);
81756+ pax_close_kernel();
81757+ mod->module_core_rx = ptr;
81758+
81759+ if (mod->init_size_rx) {
81760+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
81761+ kmemleak_ignore(ptr);
81762+ if (!ptr && mod->init_size_rx) {
81763+ module_free_exec(mod, mod->module_core_rx);
81764+ if (mod->module_init_rw)
81765+ module_free(mod, mod->module_init_rw);
81766+ module_free(mod, mod->module_core_rw);
81767+ return -ENOMEM;
81768+ }
81769+
81770+ pax_open_kernel();
81771+ memset(ptr, 0, mod->init_size_rx);
81772+ pax_close_kernel();
81773+ mod->module_init_rx = ptr;
81774+ } else
81775+ mod->module_init_rx = NULL;
81776
81777 /* Transfer each section which specifies SHF_ALLOC */
81778 pr_debug("final section addresses:\n");
81779@@ -2846,16 +2922,45 @@ static int move_module(struct module *mod, struct load_info *info)
81780 if (!(shdr->sh_flags & SHF_ALLOC))
81781 continue;
81782
81783- if (shdr->sh_entsize & INIT_OFFSET_MASK)
81784- dest = mod->module_init
81785- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
81786- else
81787- dest = mod->module_core + shdr->sh_entsize;
81788+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
81789+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
81790+ dest = mod->module_init_rw
81791+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
81792+ else
81793+ dest = mod->module_init_rx
81794+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
81795+ } else {
81796+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
81797+ dest = mod->module_core_rw + shdr->sh_entsize;
81798+ else
81799+ dest = mod->module_core_rx + shdr->sh_entsize;
81800+ }
81801+
81802+ if (shdr->sh_type != SHT_NOBITS) {
81803+
81804+#ifdef CONFIG_PAX_KERNEXEC
81805+#ifdef CONFIG_X86_64
81806+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
81807+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
81808+#endif
81809+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
81810+ pax_open_kernel();
81811+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
81812+ pax_close_kernel();
81813+ } else
81814+#endif
81815
81816- if (shdr->sh_type != SHT_NOBITS)
81817 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
81818+ }
81819 /* Update sh_addr to point to copy in image. */
81820- shdr->sh_addr = (unsigned long)dest;
81821+
81822+#ifdef CONFIG_PAX_KERNEXEC
81823+ if (shdr->sh_flags & SHF_EXECINSTR)
81824+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
81825+ else
81826+#endif
81827+
81828+ shdr->sh_addr = (unsigned long)dest;
81829 pr_debug("\t0x%lx %s\n",
81830 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
81831 }
81832@@ -2912,12 +3017,12 @@ static void flush_module_icache(const struct module *mod)
81833 * Do it before processing of module parameters, so the module
81834 * can provide parameter accessor functions of its own.
81835 */
81836- if (mod->module_init)
81837- flush_icache_range((unsigned long)mod->module_init,
81838- (unsigned long)mod->module_init
81839- + mod->init_size);
81840- flush_icache_range((unsigned long)mod->module_core,
81841- (unsigned long)mod->module_core + mod->core_size);
81842+ if (mod->module_init_rx)
81843+ flush_icache_range((unsigned long)mod->module_init_rx,
81844+ (unsigned long)mod->module_init_rx
81845+ + mod->init_size_rx);
81846+ flush_icache_range((unsigned long)mod->module_core_rx,
81847+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
81848
81849 set_fs(old_fs);
81850 }
81851@@ -2974,8 +3079,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
81852 static void module_deallocate(struct module *mod, struct load_info *info)
81853 {
81854 percpu_modfree(mod);
81855- module_free(mod, mod->module_init);
81856- module_free(mod, mod->module_core);
81857+ module_free_exec(mod, mod->module_init_rx);
81858+ module_free_exec(mod, mod->module_core_rx);
81859+ module_free(mod, mod->module_init_rw);
81860+ module_free(mod, mod->module_core_rw);
81861 }
81862
81863 int __weak module_finalize(const Elf_Ehdr *hdr,
81864@@ -2988,7 +3095,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
81865 static int post_relocation(struct module *mod, const struct load_info *info)
81866 {
81867 /* Sort exception table now relocations are done. */
81868+ pax_open_kernel();
81869 sort_extable(mod->extable, mod->extable + mod->num_exentries);
81870+ pax_close_kernel();
81871
81872 /* Copy relocated percpu area over. */
81873 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
81874@@ -3042,16 +3151,16 @@ static int do_init_module(struct module *mod)
81875 MODULE_STATE_COMING, mod);
81876
81877 /* Set RO and NX regions for core */
81878- set_section_ro_nx(mod->module_core,
81879- mod->core_text_size,
81880- mod->core_ro_size,
81881- mod->core_size);
81882+ set_section_ro_nx(mod->module_core_rx,
81883+ mod->core_size_rx,
81884+ mod->core_size_rx,
81885+ mod->core_size_rx);
81886
81887 /* Set RO and NX regions for init */
81888- set_section_ro_nx(mod->module_init,
81889- mod->init_text_size,
81890- mod->init_ro_size,
81891- mod->init_size);
81892+ set_section_ro_nx(mod->module_init_rx,
81893+ mod->init_size_rx,
81894+ mod->init_size_rx,
81895+ mod->init_size_rx);
81896
81897 do_mod_ctors(mod);
81898 /* Start the module */
81899@@ -3113,11 +3222,12 @@ static int do_init_module(struct module *mod)
81900 mod->strtab = mod->core_strtab;
81901 #endif
81902 unset_module_init_ro_nx(mod);
81903- module_free(mod, mod->module_init);
81904- mod->module_init = NULL;
81905- mod->init_size = 0;
81906- mod->init_ro_size = 0;
81907- mod->init_text_size = 0;
81908+ module_free(mod, mod->module_init_rw);
81909+ module_free_exec(mod, mod->module_init_rx);
81910+ mod->module_init_rw = NULL;
81911+ mod->module_init_rx = NULL;
81912+ mod->init_size_rw = 0;
81913+ mod->init_size_rx = 0;
81914 mutex_unlock(&module_mutex);
81915 wake_up_all(&module_wq);
81916
81917@@ -3261,9 +3371,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
81918 if (err)
81919 goto free_unload;
81920
81921+ /* Now copy in args */
81922+ mod->args = strndup_user(uargs, ~0UL >> 1);
81923+ if (IS_ERR(mod->args)) {
81924+ err = PTR_ERR(mod->args);
81925+ goto free_unload;
81926+ }
81927+
81928 /* Set up MODINFO_ATTR fields */
81929 setup_modinfo(mod, info);
81930
81931+#ifdef CONFIG_GRKERNSEC_MODHARDEN
81932+ {
81933+ char *p, *p2;
81934+
81935+ if (strstr(mod->args, "grsec_modharden_netdev")) {
81936+ 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);
81937+ err = -EPERM;
81938+ goto free_modinfo;
81939+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
81940+ p += sizeof("grsec_modharden_normal") - 1;
81941+ p2 = strstr(p, "_");
81942+ if (p2) {
81943+ *p2 = '\0';
81944+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
81945+ *p2 = '_';
81946+ }
81947+ err = -EPERM;
81948+ goto free_modinfo;
81949+ }
81950+ }
81951+#endif
81952+
81953 /* Fix up syms, so that st_value is a pointer to location. */
81954 err = simplify_symbols(mod, info);
81955 if (err < 0)
81956@@ -3279,13 +3418,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
81957
81958 flush_module_icache(mod);
81959
81960- /* Now copy in args */
81961- mod->args = strndup_user(uargs, ~0UL >> 1);
81962- if (IS_ERR(mod->args)) {
81963- err = PTR_ERR(mod->args);
81964- goto free_arch_cleanup;
81965- }
81966-
81967 dynamic_debug_setup(info->debug, info->num_debug);
81968
81969 /* Finally it's fully formed, ready to start executing. */
81970@@ -3320,11 +3452,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
81971 ddebug_cleanup:
81972 dynamic_debug_remove(info->debug);
81973 synchronize_sched();
81974- kfree(mod->args);
81975- free_arch_cleanup:
81976 module_arch_cleanup(mod);
81977 free_modinfo:
81978 free_modinfo(mod);
81979+ kfree(mod->args);
81980 free_unload:
81981 module_unload_free(mod);
81982 unlink_mod:
81983@@ -3407,10 +3538,16 @@ static const char *get_ksymbol(struct module *mod,
81984 unsigned long nextval;
81985
81986 /* At worse, next value is at end of module */
81987- if (within_module_init(addr, mod))
81988- nextval = (unsigned long)mod->module_init+mod->init_text_size;
81989+ if (within_module_init_rx(addr, mod))
81990+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
81991+ else if (within_module_init_rw(addr, mod))
81992+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
81993+ else if (within_module_core_rx(addr, mod))
81994+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
81995+ else if (within_module_core_rw(addr, mod))
81996+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
81997 else
81998- nextval = (unsigned long)mod->module_core+mod->core_text_size;
81999+ return NULL;
82000
82001 /* Scan for closest preceding symbol, and next symbol. (ELF
82002 starts real symbols at 1). */
82003@@ -3661,7 +3798,7 @@ static int m_show(struct seq_file *m, void *p)
82004 return 0;
82005
82006 seq_printf(m, "%s %u",
82007- mod->name, mod->init_size + mod->core_size);
82008+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
82009 print_unload_info(m, mod);
82010
82011 /* Informative for users. */
82012@@ -3670,7 +3807,7 @@ static int m_show(struct seq_file *m, void *p)
82013 mod->state == MODULE_STATE_COMING ? "Loading":
82014 "Live");
82015 /* Used by oprofile and other similar tools. */
82016- seq_printf(m, " 0x%pK", mod->module_core);
82017+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
82018
82019 /* Taints info */
82020 if (mod->taints)
82021@@ -3706,7 +3843,17 @@ static const struct file_operations proc_modules_operations = {
82022
82023 static int __init proc_modules_init(void)
82024 {
82025+#ifndef CONFIG_GRKERNSEC_HIDESYM
82026+#ifdef CONFIG_GRKERNSEC_PROC_USER
82027+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
82028+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
82029+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
82030+#else
82031 proc_create("modules", 0, NULL, &proc_modules_operations);
82032+#endif
82033+#else
82034+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
82035+#endif
82036 return 0;
82037 }
82038 module_init(proc_modules_init);
82039@@ -3767,14 +3914,14 @@ struct module *__module_address(unsigned long addr)
82040 {
82041 struct module *mod;
82042
82043- if (addr < module_addr_min || addr > module_addr_max)
82044+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
82045+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
82046 return NULL;
82047
82048 list_for_each_entry_rcu(mod, &modules, list) {
82049 if (mod->state == MODULE_STATE_UNFORMED)
82050 continue;
82051- if (within_module_core(addr, mod)
82052- || within_module_init(addr, mod))
82053+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
82054 return mod;
82055 }
82056 return NULL;
82057@@ -3809,11 +3956,20 @@ bool is_module_text_address(unsigned long addr)
82058 */
82059 struct module *__module_text_address(unsigned long addr)
82060 {
82061- struct module *mod = __module_address(addr);
82062+ struct module *mod;
82063+
82064+#ifdef CONFIG_X86_32
82065+ addr = ktla_ktva(addr);
82066+#endif
82067+
82068+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
82069+ return NULL;
82070+
82071+ mod = __module_address(addr);
82072+
82073 if (mod) {
82074 /* Make sure it's within the text section. */
82075- if (!within(addr, mod->module_init, mod->init_text_size)
82076- && !within(addr, mod->module_core, mod->core_text_size))
82077+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
82078 mod = NULL;
82079 }
82080 return mod;
82081diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
82082index 7e3443f..b2a1e6b 100644
82083--- a/kernel/mutex-debug.c
82084+++ b/kernel/mutex-debug.c
82085@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
82086 }
82087
82088 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
82089- struct thread_info *ti)
82090+ struct task_struct *task)
82091 {
82092 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
82093
82094 /* Mark the current thread as blocked on the lock: */
82095- ti->task->blocked_on = waiter;
82096+ task->blocked_on = waiter;
82097 }
82098
82099 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
82100- struct thread_info *ti)
82101+ struct task_struct *task)
82102 {
82103 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
82104- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
82105- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
82106- ti->task->blocked_on = NULL;
82107+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
82108+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
82109+ task->blocked_on = NULL;
82110
82111 list_del_init(&waiter->list);
82112 waiter->task = NULL;
82113diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
82114index 0799fd3..d06ae3b 100644
82115--- a/kernel/mutex-debug.h
82116+++ b/kernel/mutex-debug.h
82117@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
82118 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
82119 extern void debug_mutex_add_waiter(struct mutex *lock,
82120 struct mutex_waiter *waiter,
82121- struct thread_info *ti);
82122+ struct task_struct *task);
82123 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
82124- struct thread_info *ti);
82125+ struct task_struct *task);
82126 extern void debug_mutex_unlock(struct mutex *lock);
82127 extern void debug_mutex_init(struct mutex *lock, const char *name,
82128 struct lock_class_key *key);
82129diff --git a/kernel/mutex.c b/kernel/mutex.c
82130index a52ee7bb..f361f16 100644
82131--- a/kernel/mutex.c
82132+++ b/kernel/mutex.c
82133@@ -135,7 +135,7 @@ void mspin_lock(struct mspin_node **lock, struct mspin_node *node)
82134 node->locked = 1;
82135 return;
82136 }
82137- ACCESS_ONCE(prev->next) = node;
82138+ ACCESS_ONCE_RW(prev->next) = node;
82139 smp_wmb();
82140 /* Wait until the lock holder passes the lock down */
82141 while (!ACCESS_ONCE(node->locked))
82142@@ -156,7 +156,7 @@ static void mspin_unlock(struct mspin_node **lock, struct mspin_node *node)
82143 while (!(next = ACCESS_ONCE(node->next)))
82144 arch_mutex_cpu_relax();
82145 }
82146- ACCESS_ONCE(next->locked) = 1;
82147+ ACCESS_ONCE_RW(next->locked) = 1;
82148 smp_wmb();
82149 }
82150
82151@@ -514,7 +514,7 @@ slowpath:
82152 spin_lock_mutex(&lock->wait_lock, flags);
82153
82154 debug_mutex_lock_common(lock, &waiter);
82155- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
82156+ debug_mutex_add_waiter(lock, &waiter, task);
82157
82158 /* add waiting tasks to the end of the waitqueue (FIFO): */
82159 list_add_tail(&waiter.list, &lock->wait_list);
82160@@ -565,7 +565,7 @@ slowpath:
82161 done:
82162 lock_acquired(&lock->dep_map, ip);
82163 /* got the lock - rejoice! */
82164- mutex_remove_waiter(lock, &waiter, current_thread_info());
82165+ mutex_remove_waiter(lock, &waiter, task);
82166 mutex_set_owner(lock);
82167
82168 if (!__builtin_constant_p(ww_ctx == NULL)) {
82169@@ -604,7 +604,7 @@ done:
82170 return 0;
82171
82172 err:
82173- mutex_remove_waiter(lock, &waiter, task_thread_info(task));
82174+ mutex_remove_waiter(lock, &waiter, task);
82175 spin_unlock_mutex(&lock->wait_lock, flags);
82176 debug_mutex_free_waiter(&waiter);
82177 mutex_release(&lock->dep_map, 1, ip);
82178diff --git a/kernel/notifier.c b/kernel/notifier.c
82179index 2d5cc4c..d9ea600 100644
82180--- a/kernel/notifier.c
82181+++ b/kernel/notifier.c
82182@@ -5,6 +5,7 @@
82183 #include <linux/rcupdate.h>
82184 #include <linux/vmalloc.h>
82185 #include <linux/reboot.h>
82186+#include <linux/mm.h>
82187
82188 /*
82189 * Notifier list for kernel code which wants to be called
82190@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
82191 while ((*nl) != NULL) {
82192 if (n->priority > (*nl)->priority)
82193 break;
82194- nl = &((*nl)->next);
82195+ nl = (struct notifier_block **)&((*nl)->next);
82196 }
82197- n->next = *nl;
82198+ pax_open_kernel();
82199+ *(const void **)&n->next = *nl;
82200 rcu_assign_pointer(*nl, n);
82201+ pax_close_kernel();
82202 return 0;
82203 }
82204
82205@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
82206 return 0;
82207 if (n->priority > (*nl)->priority)
82208 break;
82209- nl = &((*nl)->next);
82210+ nl = (struct notifier_block **)&((*nl)->next);
82211 }
82212- n->next = *nl;
82213+ pax_open_kernel();
82214+ *(const void **)&n->next = *nl;
82215 rcu_assign_pointer(*nl, n);
82216+ pax_close_kernel();
82217 return 0;
82218 }
82219
82220@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
82221 {
82222 while ((*nl) != NULL) {
82223 if ((*nl) == n) {
82224+ pax_open_kernel();
82225 rcu_assign_pointer(*nl, n->next);
82226+ pax_close_kernel();
82227 return 0;
82228 }
82229- nl = &((*nl)->next);
82230+ nl = (struct notifier_block **)&((*nl)->next);
82231 }
82232 return -ENOENT;
82233 }
82234diff --git a/kernel/panic.c b/kernel/panic.c
82235index 8018646..b6a5b4f 100644
82236--- a/kernel/panic.c
82237+++ b/kernel/panic.c
82238@@ -403,7 +403,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
82239 disable_trace_on_warning();
82240
82241 pr_warn("------------[ cut here ]------------\n");
82242- pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
82243+ pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
82244 raw_smp_processor_id(), current->pid, file, line, caller);
82245
82246 if (args)
82247@@ -457,7 +457,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
82248 */
82249 void __stack_chk_fail(void)
82250 {
82251- panic("stack-protector: Kernel stack is corrupted in: %p\n",
82252+ dump_stack();
82253+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
82254 __builtin_return_address(0));
82255 }
82256 EXPORT_SYMBOL(__stack_chk_fail);
82257diff --git a/kernel/pid.c b/kernel/pid.c
82258index 66505c1..87af12c 100644
82259--- a/kernel/pid.c
82260+++ b/kernel/pid.c
82261@@ -33,6 +33,7 @@
82262 #include <linux/rculist.h>
82263 #include <linux/bootmem.h>
82264 #include <linux/hash.h>
82265+#include <linux/security.h>
82266 #include <linux/pid_namespace.h>
82267 #include <linux/init_task.h>
82268 #include <linux/syscalls.h>
82269@@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
82270
82271 int pid_max = PID_MAX_DEFAULT;
82272
82273-#define RESERVED_PIDS 300
82274+#define RESERVED_PIDS 500
82275
82276 int pid_max_min = RESERVED_PIDS + 1;
82277 int pid_max_max = PID_MAX_LIMIT;
82278@@ -439,10 +440,18 @@ EXPORT_SYMBOL(pid_task);
82279 */
82280 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
82281 {
82282+ struct task_struct *task;
82283+
82284 rcu_lockdep_assert(rcu_read_lock_held(),
82285 "find_task_by_pid_ns() needs rcu_read_lock()"
82286 " protection");
82287- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
82288+
82289+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
82290+
82291+ if (gr_pid_is_chrooted(task))
82292+ return NULL;
82293+
82294+ return task;
82295 }
82296
82297 struct task_struct *find_task_by_vpid(pid_t vnr)
82298@@ -450,6 +459,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
82299 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
82300 }
82301
82302+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
82303+{
82304+ rcu_lockdep_assert(rcu_read_lock_held(),
82305+ "find_task_by_pid_ns() needs rcu_read_lock()"
82306+ " protection");
82307+ return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
82308+}
82309+
82310 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
82311 {
82312 struct pid *pid;
82313diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
82314index 601bb36..f7e6f34 100644
82315--- a/kernel/pid_namespace.c
82316+++ b/kernel/pid_namespace.c
82317@@ -247,7 +247,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
82318 void __user *buffer, size_t *lenp, loff_t *ppos)
82319 {
82320 struct pid_namespace *pid_ns = task_active_pid_ns(current);
82321- struct ctl_table tmp = *table;
82322+ ctl_table_no_const tmp = *table;
82323
82324 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
82325 return -EPERM;
82326diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
82327index c7f31aa..2b44977 100644
82328--- a/kernel/posix-cpu-timers.c
82329+++ b/kernel/posix-cpu-timers.c
82330@@ -1521,14 +1521,14 @@ struct k_clock clock_posix_cpu = {
82331
82332 static __init int init_posix_cpu_timers(void)
82333 {
82334- struct k_clock process = {
82335+ static struct k_clock process = {
82336 .clock_getres = process_cpu_clock_getres,
82337 .clock_get = process_cpu_clock_get,
82338 .timer_create = process_cpu_timer_create,
82339 .nsleep = process_cpu_nsleep,
82340 .nsleep_restart = process_cpu_nsleep_restart,
82341 };
82342- struct k_clock thread = {
82343+ static struct k_clock thread = {
82344 .clock_getres = thread_cpu_clock_getres,
82345 .clock_get = thread_cpu_clock_get,
82346 .timer_create = thread_cpu_timer_create,
82347diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
82348index 424c2d4..679242f 100644
82349--- a/kernel/posix-timers.c
82350+++ b/kernel/posix-timers.c
82351@@ -43,6 +43,7 @@
82352 #include <linux/hash.h>
82353 #include <linux/posix-clock.h>
82354 #include <linux/posix-timers.h>
82355+#include <linux/grsecurity.h>
82356 #include <linux/syscalls.h>
82357 #include <linux/wait.h>
82358 #include <linux/workqueue.h>
82359@@ -122,7 +123,7 @@ static DEFINE_SPINLOCK(hash_lock);
82360 * which we beg off on and pass to do_sys_settimeofday().
82361 */
82362
82363-static struct k_clock posix_clocks[MAX_CLOCKS];
82364+static struct k_clock *posix_clocks[MAX_CLOCKS];
82365
82366 /*
82367 * These ones are defined below.
82368@@ -275,7 +276,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
82369 */
82370 static __init int init_posix_timers(void)
82371 {
82372- struct k_clock clock_realtime = {
82373+ static struct k_clock clock_realtime = {
82374 .clock_getres = hrtimer_get_res,
82375 .clock_get = posix_clock_realtime_get,
82376 .clock_set = posix_clock_realtime_set,
82377@@ -287,7 +288,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_monotonic = {
82382+ static struct k_clock clock_monotonic = {
82383 .clock_getres = hrtimer_get_res,
82384 .clock_get = posix_ktime_get_ts,
82385 .nsleep = common_nsleep,
82386@@ -297,19 +298,19 @@ static __init int init_posix_timers(void)
82387 .timer_get = common_timer_get,
82388 .timer_del = common_timer_del,
82389 };
82390- struct k_clock clock_monotonic_raw = {
82391+ static struct k_clock clock_monotonic_raw = {
82392 .clock_getres = hrtimer_get_res,
82393 .clock_get = posix_get_monotonic_raw,
82394 };
82395- struct k_clock clock_realtime_coarse = {
82396+ static struct k_clock clock_realtime_coarse = {
82397 .clock_getres = posix_get_coarse_res,
82398 .clock_get = posix_get_realtime_coarse,
82399 };
82400- struct k_clock clock_monotonic_coarse = {
82401+ static struct k_clock clock_monotonic_coarse = {
82402 .clock_getres = posix_get_coarse_res,
82403 .clock_get = posix_get_monotonic_coarse,
82404 };
82405- struct k_clock clock_tai = {
82406+ static struct k_clock clock_tai = {
82407 .clock_getres = hrtimer_get_res,
82408 .clock_get = posix_get_tai,
82409 .nsleep = common_nsleep,
82410@@ -319,7 +320,7 @@ static __init int init_posix_timers(void)
82411 .timer_get = common_timer_get,
82412 .timer_del = common_timer_del,
82413 };
82414- struct k_clock clock_boottime = {
82415+ static struct k_clock clock_boottime = {
82416 .clock_getres = hrtimer_get_res,
82417 .clock_get = posix_get_boottime,
82418 .nsleep = common_nsleep,
82419@@ -531,7 +532,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
82420 return;
82421 }
82422
82423- posix_clocks[clock_id] = *new_clock;
82424+ posix_clocks[clock_id] = new_clock;
82425 }
82426 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
82427
82428@@ -577,9 +578,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
82429 return (id & CLOCKFD_MASK) == CLOCKFD ?
82430 &clock_posix_dynamic : &clock_posix_cpu;
82431
82432- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
82433+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
82434 return NULL;
82435- return &posix_clocks[id];
82436+ return posix_clocks[id];
82437 }
82438
82439 static int common_timer_create(struct k_itimer *new_timer)
82440@@ -597,7 +598,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
82441 struct k_clock *kc = clockid_to_kclock(which_clock);
82442 struct k_itimer *new_timer;
82443 int error, new_timer_id;
82444- sigevent_t event;
82445+ sigevent_t event = { };
82446 int it_id_set = IT_ID_NOT_SET;
82447
82448 if (!kc)
82449@@ -1011,6 +1012,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
82450 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
82451 return -EFAULT;
82452
82453+ /* only the CLOCK_REALTIME clock can be set, all other clocks
82454+ have their clock_set fptr set to a nosettime dummy function
82455+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
82456+ call common_clock_set, which calls do_sys_settimeofday, which
82457+ we hook
82458+ */
82459+
82460 return kc->clock_set(which_clock, &new_tp);
82461 }
82462
82463diff --git a/kernel/power/process.c b/kernel/power/process.c
82464index 06ec886..9dba35e 100644
82465--- a/kernel/power/process.c
82466+++ b/kernel/power/process.c
82467@@ -34,6 +34,7 @@ static int try_to_freeze_tasks(bool user_only)
82468 unsigned int elapsed_msecs;
82469 bool wakeup = false;
82470 int sleep_usecs = USEC_PER_MSEC;
82471+ bool timedout = false;
82472
82473 do_gettimeofday(&start);
82474
82475@@ -44,13 +45,20 @@ static int try_to_freeze_tasks(bool user_only)
82476
82477 while (true) {
82478 todo = 0;
82479+ if (time_after(jiffies, end_time))
82480+ timedout = true;
82481 read_lock(&tasklist_lock);
82482 do_each_thread(g, p) {
82483 if (p == current || !freeze_task(p))
82484 continue;
82485
82486- if (!freezer_should_skip(p))
82487+ if (!freezer_should_skip(p)) {
82488 todo++;
82489+ if (timedout) {
82490+ printk(KERN_ERR "Task refusing to freeze:\n");
82491+ sched_show_task(p);
82492+ }
82493+ }
82494 } while_each_thread(g, p);
82495 read_unlock(&tasklist_lock);
82496
82497@@ -59,7 +67,7 @@ static int try_to_freeze_tasks(bool user_only)
82498 todo += wq_busy;
82499 }
82500
82501- if (!todo || time_after(jiffies, end_time))
82502+ if (!todo || timedout)
82503 break;
82504
82505 if (pm_wakeup_pending()) {
82506diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
82507index 5b5a708..ec7637e 100644
82508--- a/kernel/printk/printk.c
82509+++ b/kernel/printk/printk.c
82510@@ -385,6 +385,11 @@ static int check_syslog_permissions(int type, bool from_file)
82511 if (from_file && type != SYSLOG_ACTION_OPEN)
82512 return 0;
82513
82514+#ifdef CONFIG_GRKERNSEC_DMESG
82515+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
82516+ return -EPERM;
82517+#endif
82518+
82519 if (syslog_action_restricted(type)) {
82520 if (capable(CAP_SYSLOG))
82521 return 0;
82522diff --git a/kernel/profile.c b/kernel/profile.c
82523index 6631e1e..310c266 100644
82524--- a/kernel/profile.c
82525+++ b/kernel/profile.c
82526@@ -37,7 +37,7 @@ struct profile_hit {
82527 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
82528 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
82529
82530-static atomic_t *prof_buffer;
82531+static atomic_unchecked_t *prof_buffer;
82532 static unsigned long prof_len, prof_shift;
82533
82534 int prof_on __read_mostly;
82535@@ -260,7 +260,7 @@ static void profile_flip_buffers(void)
82536 hits[i].pc = 0;
82537 continue;
82538 }
82539- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
82540+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
82541 hits[i].hits = hits[i].pc = 0;
82542 }
82543 }
82544@@ -321,9 +321,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
82545 * Add the current hit(s) and flush the write-queue out
82546 * to the global buffer:
82547 */
82548- atomic_add(nr_hits, &prof_buffer[pc]);
82549+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
82550 for (i = 0; i < NR_PROFILE_HIT; ++i) {
82551- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
82552+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
82553 hits[i].pc = hits[i].hits = 0;
82554 }
82555 out:
82556@@ -398,7 +398,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
82557 {
82558 unsigned long pc;
82559 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
82560- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
82561+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
82562 }
82563 #endif /* !CONFIG_SMP */
82564
82565@@ -494,7 +494,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
82566 return -EFAULT;
82567 buf++; p++; count--; read++;
82568 }
82569- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
82570+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
82571 if (copy_to_user(buf, (void *)pnt, count))
82572 return -EFAULT;
82573 read += count;
82574@@ -525,7 +525,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
82575 }
82576 #endif
82577 profile_discard_flip_buffers();
82578- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
82579+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
82580 return count;
82581 }
82582
82583diff --git a/kernel/ptrace.c b/kernel/ptrace.c
82584index a146ee3..ffed4c3 100644
82585--- a/kernel/ptrace.c
82586+++ b/kernel/ptrace.c
82587@@ -326,7 +326,7 @@ static int ptrace_attach(struct task_struct *task, long request,
82588 if (seize)
82589 flags |= PT_SEIZED;
82590 rcu_read_lock();
82591- if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
82592+ if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
82593 flags |= PT_PTRACE_CAP;
82594 rcu_read_unlock();
82595 task->ptrace = flags;
82596@@ -537,7 +537,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
82597 break;
82598 return -EIO;
82599 }
82600- if (copy_to_user(dst, buf, retval))
82601+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
82602 return -EFAULT;
82603 copied += retval;
82604 src += retval;
82605@@ -805,7 +805,7 @@ int ptrace_request(struct task_struct *child, long request,
82606 bool seized = child->ptrace & PT_SEIZED;
82607 int ret = -EIO;
82608 siginfo_t siginfo, *si;
82609- void __user *datavp = (void __user *) data;
82610+ void __user *datavp = (__force void __user *) data;
82611 unsigned long __user *datalp = datavp;
82612 unsigned long flags;
82613
82614@@ -1051,14 +1051,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
82615 goto out;
82616 }
82617
82618+ if (gr_handle_ptrace(child, request)) {
82619+ ret = -EPERM;
82620+ goto out_put_task_struct;
82621+ }
82622+
82623 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
82624 ret = ptrace_attach(child, request, addr, data);
82625 /*
82626 * Some architectures need to do book-keeping after
82627 * a ptrace attach.
82628 */
82629- if (!ret)
82630+ if (!ret) {
82631 arch_ptrace_attach(child);
82632+ gr_audit_ptrace(child);
82633+ }
82634 goto out_put_task_struct;
82635 }
82636
82637@@ -1086,7 +1093,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
82638 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
82639 if (copied != sizeof(tmp))
82640 return -EIO;
82641- return put_user(tmp, (unsigned long __user *)data);
82642+ return put_user(tmp, (__force unsigned long __user *)data);
82643 }
82644
82645 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
82646@@ -1180,7 +1187,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
82647 }
82648
82649 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
82650- compat_long_t addr, compat_long_t data)
82651+ compat_ulong_t addr, compat_ulong_t data)
82652 {
82653 struct task_struct *child;
82654 long ret;
82655@@ -1196,14 +1203,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
82656 goto out;
82657 }
82658
82659+ if (gr_handle_ptrace(child, request)) {
82660+ ret = -EPERM;
82661+ goto out_put_task_struct;
82662+ }
82663+
82664 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
82665 ret = ptrace_attach(child, request, addr, data);
82666 /*
82667 * Some architectures need to do book-keeping after
82668 * a ptrace attach.
82669 */
82670- if (!ret)
82671+ if (!ret) {
82672 arch_ptrace_attach(child);
82673+ gr_audit_ptrace(child);
82674+ }
82675 goto out_put_task_struct;
82676 }
82677
82678diff --git a/kernel/rcupdate.c b/kernel/rcupdate.c
82679index cce6ba8..7c758b1f 100644
82680--- a/kernel/rcupdate.c
82681+++ b/kernel/rcupdate.c
82682@@ -412,10 +412,10 @@ int rcu_jiffies_till_stall_check(void)
82683 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
82684 */
82685 if (till_stall_check < 3) {
82686- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
82687+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
82688 till_stall_check = 3;
82689 } else if (till_stall_check > 300) {
82690- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
82691+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
82692 till_stall_check = 300;
82693 }
82694 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
82695diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
82696index aa34411..78e5ccb 100644
82697--- a/kernel/rcutiny.c
82698+++ b/kernel/rcutiny.c
82699@@ -45,7 +45,7 @@
82700 /* Forward declarations for rcutiny_plugin.h. */
82701 struct rcu_ctrlblk;
82702 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
82703-static void rcu_process_callbacks(struct softirq_action *unused);
82704+static void rcu_process_callbacks(void);
82705 static void __call_rcu(struct rcu_head *head,
82706 void (*func)(struct rcu_head *rcu),
82707 struct rcu_ctrlblk *rcp);
82708@@ -309,7 +309,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
82709 false));
82710 }
82711
82712-static void rcu_process_callbacks(struct softirq_action *unused)
82713+static void rcu_process_callbacks(void)
82714 {
82715 __rcu_process_callbacks(&rcu_sched_ctrlblk);
82716 __rcu_process_callbacks(&rcu_bh_ctrlblk);
82717diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
82718index f4871e5..8ef5741 100644
82719--- a/kernel/rcutorture.c
82720+++ b/kernel/rcutorture.c
82721@@ -164,12 +164,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
82722 { 0 };
82723 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
82724 { 0 };
82725-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
82726-static atomic_t n_rcu_torture_alloc;
82727-static atomic_t n_rcu_torture_alloc_fail;
82728-static atomic_t n_rcu_torture_free;
82729-static atomic_t n_rcu_torture_mberror;
82730-static atomic_t n_rcu_torture_error;
82731+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
82732+static atomic_unchecked_t n_rcu_torture_alloc;
82733+static atomic_unchecked_t n_rcu_torture_alloc_fail;
82734+static atomic_unchecked_t n_rcu_torture_free;
82735+static atomic_unchecked_t n_rcu_torture_mberror;
82736+static atomic_unchecked_t n_rcu_torture_error;
82737 static long n_rcu_torture_barrier_error;
82738 static long n_rcu_torture_boost_ktrerror;
82739 static long n_rcu_torture_boost_rterror;
82740@@ -287,11 +287,11 @@ rcu_torture_alloc(void)
82741
82742 spin_lock_bh(&rcu_torture_lock);
82743 if (list_empty(&rcu_torture_freelist)) {
82744- atomic_inc(&n_rcu_torture_alloc_fail);
82745+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
82746 spin_unlock_bh(&rcu_torture_lock);
82747 return NULL;
82748 }
82749- atomic_inc(&n_rcu_torture_alloc);
82750+ atomic_inc_unchecked(&n_rcu_torture_alloc);
82751 p = rcu_torture_freelist.next;
82752 list_del_init(p);
82753 spin_unlock_bh(&rcu_torture_lock);
82754@@ -304,7 +304,7 @@ rcu_torture_alloc(void)
82755 static void
82756 rcu_torture_free(struct rcu_torture *p)
82757 {
82758- atomic_inc(&n_rcu_torture_free);
82759+ atomic_inc_unchecked(&n_rcu_torture_free);
82760 spin_lock_bh(&rcu_torture_lock);
82761 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
82762 spin_unlock_bh(&rcu_torture_lock);
82763@@ -424,7 +424,7 @@ rcu_torture_cb(struct rcu_head *p)
82764 i = rp->rtort_pipe_count;
82765 if (i > RCU_TORTURE_PIPE_LEN)
82766 i = RCU_TORTURE_PIPE_LEN;
82767- atomic_inc(&rcu_torture_wcount[i]);
82768+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
82769 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
82770 rp->rtort_mbtest = 0;
82771 rcu_torture_free(rp);
82772@@ -472,7 +472,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
82773 i = rp->rtort_pipe_count;
82774 if (i > RCU_TORTURE_PIPE_LEN)
82775 i = RCU_TORTURE_PIPE_LEN;
82776- atomic_inc(&rcu_torture_wcount[i]);
82777+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
82778 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
82779 rp->rtort_mbtest = 0;
82780 list_del(&rp->rtort_free);
82781@@ -952,7 +952,7 @@ rcu_torture_writer(void *arg)
82782 i = old_rp->rtort_pipe_count;
82783 if (i > RCU_TORTURE_PIPE_LEN)
82784 i = RCU_TORTURE_PIPE_LEN;
82785- atomic_inc(&rcu_torture_wcount[i]);
82786+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
82787 old_rp->rtort_pipe_count++;
82788 cur_ops->deferred_free(old_rp);
82789 }
82790@@ -1038,7 +1038,7 @@ static void rcu_torture_timer(unsigned long unused)
82791 return;
82792 }
82793 if (p->rtort_mbtest == 0)
82794- atomic_inc(&n_rcu_torture_mberror);
82795+ atomic_inc_unchecked(&n_rcu_torture_mberror);
82796 spin_lock(&rand_lock);
82797 cur_ops->read_delay(&rand);
82798 n_rcu_torture_timers++;
82799@@ -1108,7 +1108,7 @@ rcu_torture_reader(void *arg)
82800 continue;
82801 }
82802 if (p->rtort_mbtest == 0)
82803- atomic_inc(&n_rcu_torture_mberror);
82804+ atomic_inc_unchecked(&n_rcu_torture_mberror);
82805 cur_ops->read_delay(&rand);
82806 preempt_disable();
82807 pipe_count = p->rtort_pipe_count;
82808@@ -1171,11 +1171,11 @@ rcu_torture_printk(char *page)
82809 rcu_torture_current,
82810 rcu_torture_current_version,
82811 list_empty(&rcu_torture_freelist),
82812- atomic_read(&n_rcu_torture_alloc),
82813- atomic_read(&n_rcu_torture_alloc_fail),
82814- atomic_read(&n_rcu_torture_free));
82815+ atomic_read_unchecked(&n_rcu_torture_alloc),
82816+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
82817+ atomic_read_unchecked(&n_rcu_torture_free));
82818 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
82819- atomic_read(&n_rcu_torture_mberror),
82820+ atomic_read_unchecked(&n_rcu_torture_mberror),
82821 n_rcu_torture_boost_ktrerror,
82822 n_rcu_torture_boost_rterror);
82823 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
82824@@ -1194,14 +1194,14 @@ rcu_torture_printk(char *page)
82825 n_barrier_attempts,
82826 n_rcu_torture_barrier_error);
82827 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
82828- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
82829+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
82830 n_rcu_torture_barrier_error != 0 ||
82831 n_rcu_torture_boost_ktrerror != 0 ||
82832 n_rcu_torture_boost_rterror != 0 ||
82833 n_rcu_torture_boost_failure != 0 ||
82834 i > 1) {
82835 cnt += sprintf(&page[cnt], "!!! ");
82836- atomic_inc(&n_rcu_torture_error);
82837+ atomic_inc_unchecked(&n_rcu_torture_error);
82838 WARN_ON_ONCE(1);
82839 }
82840 cnt += sprintf(&page[cnt], "Reader Pipe: ");
82841@@ -1215,7 +1215,7 @@ rcu_torture_printk(char *page)
82842 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
82843 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
82844 cnt += sprintf(&page[cnt], " %d",
82845- atomic_read(&rcu_torture_wcount[i]));
82846+ atomic_read_unchecked(&rcu_torture_wcount[i]));
82847 }
82848 cnt += sprintf(&page[cnt], "\n");
82849 if (cur_ops->stats)
82850@@ -1924,7 +1924,7 @@ rcu_torture_cleanup(void)
82851
82852 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
82853
82854- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
82855+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
82856 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
82857 else if (n_online_successes != n_online_attempts ||
82858 n_offline_successes != n_offline_attempts)
82859@@ -1992,18 +1992,18 @@ rcu_torture_init(void)
82860
82861 rcu_torture_current = NULL;
82862 rcu_torture_current_version = 0;
82863- atomic_set(&n_rcu_torture_alloc, 0);
82864- atomic_set(&n_rcu_torture_alloc_fail, 0);
82865- atomic_set(&n_rcu_torture_free, 0);
82866- atomic_set(&n_rcu_torture_mberror, 0);
82867- atomic_set(&n_rcu_torture_error, 0);
82868+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
82869+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
82870+ atomic_set_unchecked(&n_rcu_torture_free, 0);
82871+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
82872+ atomic_set_unchecked(&n_rcu_torture_error, 0);
82873 n_rcu_torture_barrier_error = 0;
82874 n_rcu_torture_boost_ktrerror = 0;
82875 n_rcu_torture_boost_rterror = 0;
82876 n_rcu_torture_boost_failure = 0;
82877 n_rcu_torture_boosts = 0;
82878 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
82879- atomic_set(&rcu_torture_wcount[i], 0);
82880+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
82881 for_each_possible_cpu(cpu) {
82882 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
82883 per_cpu(rcu_torture_count, cpu)[i] = 0;
82884diff --git a/kernel/rcutree.c b/kernel/rcutree.c
82885index 068de3a..df7da65 100644
82886--- a/kernel/rcutree.c
82887+++ b/kernel/rcutree.c
82888@@ -358,9 +358,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
82889 rcu_prepare_for_idle(smp_processor_id());
82890 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
82891 smp_mb__before_atomic_inc(); /* See above. */
82892- atomic_inc(&rdtp->dynticks);
82893+ atomic_inc_unchecked(&rdtp->dynticks);
82894 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
82895- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
82896+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
82897
82898 /*
82899 * It is illegal to enter an extended quiescent state while
82900@@ -496,10 +496,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
82901 int user)
82902 {
82903 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
82904- atomic_inc(&rdtp->dynticks);
82905+ atomic_inc_unchecked(&rdtp->dynticks);
82906 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
82907 smp_mb__after_atomic_inc(); /* See above. */
82908- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
82909+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
82910 rcu_cleanup_after_idle(smp_processor_id());
82911 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
82912 if (!user && !is_idle_task(current)) {
82913@@ -638,14 +638,14 @@ void rcu_nmi_enter(void)
82914 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
82915
82916 if (rdtp->dynticks_nmi_nesting == 0 &&
82917- (atomic_read(&rdtp->dynticks) & 0x1))
82918+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
82919 return;
82920 rdtp->dynticks_nmi_nesting++;
82921 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
82922- atomic_inc(&rdtp->dynticks);
82923+ atomic_inc_unchecked(&rdtp->dynticks);
82924 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
82925 smp_mb__after_atomic_inc(); /* See above. */
82926- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
82927+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
82928 }
82929
82930 /**
82931@@ -664,9 +664,9 @@ void rcu_nmi_exit(void)
82932 return;
82933 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
82934 smp_mb__before_atomic_inc(); /* See above. */
82935- atomic_inc(&rdtp->dynticks);
82936+ atomic_inc_unchecked(&rdtp->dynticks);
82937 smp_mb__after_atomic_inc(); /* Force delay to next write. */
82938- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
82939+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
82940 }
82941
82942 /**
82943@@ -680,7 +680,7 @@ int rcu_is_cpu_idle(void)
82944 int ret;
82945
82946 preempt_disable();
82947- ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
82948+ ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
82949 preempt_enable();
82950 return ret;
82951 }
82952@@ -748,7 +748,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
82953 */
82954 static int dyntick_save_progress_counter(struct rcu_data *rdp)
82955 {
82956- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
82957+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
82958 return (rdp->dynticks_snap & 0x1) == 0;
82959 }
82960
82961@@ -763,7 +763,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
82962 unsigned int curr;
82963 unsigned int snap;
82964
82965- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
82966+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
82967 snap = (unsigned int)rdp->dynticks_snap;
82968
82969 /*
82970@@ -1351,9 +1351,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
82971 rdp = this_cpu_ptr(rsp->rda);
82972 rcu_preempt_check_blocked_tasks(rnp);
82973 rnp->qsmask = rnp->qsmaskinit;
82974- ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
82975+ ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
82976 WARN_ON_ONCE(rnp->completed != rsp->completed);
82977- ACCESS_ONCE(rnp->completed) = rsp->completed;
82978+ ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
82979 if (rnp == rdp->mynode)
82980 __note_gp_changes(rsp, rnp, rdp);
82981 rcu_preempt_boost_start_gp(rnp);
82982@@ -1435,7 +1435,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
82983 */
82984 rcu_for_each_node_breadth_first(rsp, rnp) {
82985 raw_spin_lock_irq(&rnp->lock);
82986- ACCESS_ONCE(rnp->completed) = rsp->gpnum;
82987+ ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
82988 rdp = this_cpu_ptr(rsp->rda);
82989 if (rnp == rdp->mynode)
82990 __note_gp_changes(rsp, rnp, rdp);
82991@@ -1765,7 +1765,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
82992 rsp->qlen += rdp->qlen;
82993 rdp->n_cbs_orphaned += rdp->qlen;
82994 rdp->qlen_lazy = 0;
82995- ACCESS_ONCE(rdp->qlen) = 0;
82996+ ACCESS_ONCE_RW(rdp->qlen) = 0;
82997 }
82998
82999 /*
83000@@ -2011,7 +2011,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
83001 }
83002 smp_mb(); /* List handling before counting for rcu_barrier(). */
83003 rdp->qlen_lazy -= count_lazy;
83004- ACCESS_ONCE(rdp->qlen) -= count;
83005+ ACCESS_ONCE_RW(rdp->qlen) -= count;
83006 rdp->n_cbs_invoked += count;
83007
83008 /* Reinstate batch limit if we have worked down the excess. */
83009@@ -2202,7 +2202,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
83010 /*
83011 * Do RCU core processing for the current CPU.
83012 */
83013-static void rcu_process_callbacks(struct softirq_action *unused)
83014+static void rcu_process_callbacks(void)
83015 {
83016 struct rcu_state *rsp;
83017
83018@@ -2325,7 +2325,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
83019 local_irq_restore(flags);
83020 return;
83021 }
83022- ACCESS_ONCE(rdp->qlen)++;
83023+ ACCESS_ONCE_RW(rdp->qlen)++;
83024 if (lazy)
83025 rdp->qlen_lazy++;
83026 else
83027@@ -2534,11 +2534,11 @@ void synchronize_sched_expedited(void)
83028 * counter wrap on a 32-bit system. Quite a few more CPUs would of
83029 * course be required on a 64-bit system.
83030 */
83031- if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
83032+ if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
83033 (ulong)atomic_long_read(&rsp->expedited_done) +
83034 ULONG_MAX / 8)) {
83035 synchronize_sched();
83036- atomic_long_inc(&rsp->expedited_wrap);
83037+ atomic_long_inc_unchecked(&rsp->expedited_wrap);
83038 return;
83039 }
83040
83041@@ -2546,7 +2546,7 @@ void synchronize_sched_expedited(void)
83042 * Take a ticket. Note that atomic_inc_return() implies a
83043 * full memory barrier.
83044 */
83045- snap = atomic_long_inc_return(&rsp->expedited_start);
83046+ snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
83047 firstsnap = snap;
83048 get_online_cpus();
83049 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
83050@@ -2559,14 +2559,14 @@ void synchronize_sched_expedited(void)
83051 synchronize_sched_expedited_cpu_stop,
83052 NULL) == -EAGAIN) {
83053 put_online_cpus();
83054- atomic_long_inc(&rsp->expedited_tryfail);
83055+ atomic_long_inc_unchecked(&rsp->expedited_tryfail);
83056
83057 /* Check to see if someone else did our work for us. */
83058 s = atomic_long_read(&rsp->expedited_done);
83059 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
83060 /* ensure test happens before caller kfree */
83061 smp_mb__before_atomic_inc(); /* ^^^ */
83062- atomic_long_inc(&rsp->expedited_workdone1);
83063+ atomic_long_inc_unchecked(&rsp->expedited_workdone1);
83064 return;
83065 }
83066
83067@@ -2575,7 +2575,7 @@ void synchronize_sched_expedited(void)
83068 udelay(trycount * num_online_cpus());
83069 } else {
83070 wait_rcu_gp(call_rcu_sched);
83071- atomic_long_inc(&rsp->expedited_normal);
83072+ atomic_long_inc_unchecked(&rsp->expedited_normal);
83073 return;
83074 }
83075
83076@@ -2584,7 +2584,7 @@ void synchronize_sched_expedited(void)
83077 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
83078 /* ensure test happens before caller kfree */
83079 smp_mb__before_atomic_inc(); /* ^^^ */
83080- atomic_long_inc(&rsp->expedited_workdone2);
83081+ atomic_long_inc_unchecked(&rsp->expedited_workdone2);
83082 return;
83083 }
83084
83085@@ -2596,10 +2596,10 @@ void synchronize_sched_expedited(void)
83086 * period works for us.
83087 */
83088 get_online_cpus();
83089- snap = atomic_long_read(&rsp->expedited_start);
83090+ snap = atomic_long_read_unchecked(&rsp->expedited_start);
83091 smp_mb(); /* ensure read is before try_stop_cpus(). */
83092 }
83093- atomic_long_inc(&rsp->expedited_stoppedcpus);
83094+ atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
83095
83096 /*
83097 * Everyone up to our most recent fetch is covered by our grace
83098@@ -2608,16 +2608,16 @@ void synchronize_sched_expedited(void)
83099 * than we did already did their update.
83100 */
83101 do {
83102- atomic_long_inc(&rsp->expedited_done_tries);
83103+ atomic_long_inc_unchecked(&rsp->expedited_done_tries);
83104 s = atomic_long_read(&rsp->expedited_done);
83105 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
83106 /* ensure test happens before caller kfree */
83107 smp_mb__before_atomic_inc(); /* ^^^ */
83108- atomic_long_inc(&rsp->expedited_done_lost);
83109+ atomic_long_inc_unchecked(&rsp->expedited_done_lost);
83110 break;
83111 }
83112 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
83113- atomic_long_inc(&rsp->expedited_done_exit);
83114+ atomic_long_inc_unchecked(&rsp->expedited_done_exit);
83115
83116 put_online_cpus();
83117 }
83118@@ -2799,7 +2799,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
83119 * ACCESS_ONCE() to prevent the compiler from speculating
83120 * the increment to precede the early-exit check.
83121 */
83122- ACCESS_ONCE(rsp->n_barrier_done)++;
83123+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
83124 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
83125 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
83126 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
83127@@ -2849,7 +2849,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
83128
83129 /* Increment ->n_barrier_done to prevent duplicate work. */
83130 smp_mb(); /* Keep increment after above mechanism. */
83131- ACCESS_ONCE(rsp->n_barrier_done)++;
83132+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
83133 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
83134 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
83135 smp_mb(); /* Keep increment before caller's subsequent code. */
83136@@ -2894,10 +2894,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
83137 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
83138 init_callback_list(rdp);
83139 rdp->qlen_lazy = 0;
83140- ACCESS_ONCE(rdp->qlen) = 0;
83141+ ACCESS_ONCE_RW(rdp->qlen) = 0;
83142 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
83143 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
83144- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
83145+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
83146 rdp->cpu = cpu;
83147 rdp->rsp = rsp;
83148 rcu_boot_init_nocb_percpu_data(rdp);
83149@@ -2930,8 +2930,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
83150 rdp->blimit = blimit;
83151 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
83152 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
83153- atomic_set(&rdp->dynticks->dynticks,
83154- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
83155+ atomic_set_unchecked(&rdp->dynticks->dynticks,
83156+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
83157 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
83158
83159 /* Add CPU to rcu_node bitmasks. */
83160diff --git a/kernel/rcutree.h b/kernel/rcutree.h
83161index b383258..2440c1e 100644
83162--- a/kernel/rcutree.h
83163+++ b/kernel/rcutree.h
83164@@ -87,7 +87,7 @@ struct rcu_dynticks {
83165 long long dynticks_nesting; /* Track irq/process nesting level. */
83166 /* Process level is worth LLONG_MAX/2. */
83167 int dynticks_nmi_nesting; /* Track NMI nesting level. */
83168- atomic_t dynticks; /* Even value for idle, else odd. */
83169+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
83170 #ifdef CONFIG_RCU_FAST_NO_HZ
83171 bool all_lazy; /* Are all CPU's CBs lazy? */
83172 unsigned long nonlazy_posted;
83173@@ -419,17 +419,17 @@ struct rcu_state {
83174 /* _rcu_barrier(). */
83175 /* End of fields guarded by barrier_mutex. */
83176
83177- atomic_long_t expedited_start; /* Starting ticket. */
83178- atomic_long_t expedited_done; /* Done ticket. */
83179- atomic_long_t expedited_wrap; /* # near-wrap incidents. */
83180- atomic_long_t expedited_tryfail; /* # acquisition failures. */
83181- atomic_long_t expedited_workdone1; /* # done by others #1. */
83182- atomic_long_t expedited_workdone2; /* # done by others #2. */
83183- atomic_long_t expedited_normal; /* # fallbacks to normal. */
83184- atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
83185- atomic_long_t expedited_done_tries; /* # tries to update _done. */
83186- atomic_long_t expedited_done_lost; /* # times beaten to _done. */
83187- atomic_long_t expedited_done_exit; /* # times exited _done loop. */
83188+ atomic_long_unchecked_t expedited_start; /* Starting ticket. */
83189+ atomic_long_t expedited_done; /* Done ticket. */
83190+ atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
83191+ atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
83192+ atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
83193+ atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
83194+ atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
83195+ atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
83196+ atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
83197+ atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
83198+ atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
83199
83200 unsigned long jiffies_force_qs; /* Time at which to invoke */
83201 /* force_quiescent_state(). */
83202diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
83203index 769e12e..7b2139b 100644
83204--- a/kernel/rcutree_plugin.h
83205+++ b/kernel/rcutree_plugin.h
83206@@ -902,7 +902,7 @@ void synchronize_rcu_expedited(void)
83207
83208 /* Clean up and exit. */
83209 smp_mb(); /* ensure expedited GP seen before counter increment. */
83210- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
83211+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
83212 unlock_mb_ret:
83213 mutex_unlock(&sync_rcu_preempt_exp_mutex);
83214 mb_ret:
83215@@ -1476,7 +1476,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
83216 free_cpumask_var(cm);
83217 }
83218
83219-static struct smp_hotplug_thread rcu_cpu_thread_spec = {
83220+static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
83221 .store = &rcu_cpu_kthread_task,
83222 .thread_should_run = rcu_cpu_kthread_should_run,
83223 .thread_fn = rcu_cpu_kthread,
83224@@ -1941,7 +1941,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
83225 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
83226 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
83227 cpu, ticks_value, ticks_title,
83228- atomic_read(&rdtp->dynticks) & 0xfff,
83229+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
83230 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
83231 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
83232 fast_no_hz);
83233@@ -2104,7 +2104,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
83234
83235 /* Enqueue the callback on the nocb list and update counts. */
83236 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
83237- ACCESS_ONCE(*old_rhpp) = rhp;
83238+ ACCESS_ONCE_RW(*old_rhpp) = rhp;
83239 atomic_long_add(rhcount, &rdp->nocb_q_count);
83240 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
83241
83242@@ -2244,12 +2244,12 @@ static int rcu_nocb_kthread(void *arg)
83243 * Extract queued callbacks, update counts, and wait
83244 * for a grace period to elapse.
83245 */
83246- ACCESS_ONCE(rdp->nocb_head) = NULL;
83247+ ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
83248 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
83249 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
83250 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
83251- ACCESS_ONCE(rdp->nocb_p_count) += c;
83252- ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
83253+ ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
83254+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
83255 rcu_nocb_wait_gp(rdp);
83256
83257 /* Each pass through the following loop invokes a callback. */
83258@@ -2271,8 +2271,8 @@ static int rcu_nocb_kthread(void *arg)
83259 list = next;
83260 }
83261 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
83262- ACCESS_ONCE(rdp->nocb_p_count) -= c;
83263- ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
83264+ ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
83265+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
83266 rdp->n_nocbs_invoked += c;
83267 }
83268 return 0;
83269@@ -2299,7 +2299,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
83270 t = kthread_run(rcu_nocb_kthread, rdp,
83271 "rcuo%c/%d", rsp->abbr, cpu);
83272 BUG_ON(IS_ERR(t));
83273- ACCESS_ONCE(rdp->nocb_kthread) = t;
83274+ ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
83275 }
83276 }
83277
83278diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
83279index cf6c174..a8f4b50 100644
83280--- a/kernel/rcutree_trace.c
83281+++ b/kernel/rcutree_trace.c
83282@@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
83283 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
83284 rdp->passed_quiesce, rdp->qs_pending);
83285 seq_printf(m, " dt=%d/%llx/%d df=%lu",
83286- atomic_read(&rdp->dynticks->dynticks),
83287+ atomic_read_unchecked(&rdp->dynticks->dynticks),
83288 rdp->dynticks->dynticks_nesting,
83289 rdp->dynticks->dynticks_nmi_nesting,
83290 rdp->dynticks_fqs);
83291@@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
83292 struct rcu_state *rsp = (struct rcu_state *)m->private;
83293
83294 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",
83295- atomic_long_read(&rsp->expedited_start),
83296+ atomic_long_read_unchecked(&rsp->expedited_start),
83297 atomic_long_read(&rsp->expedited_done),
83298- atomic_long_read(&rsp->expedited_wrap),
83299- atomic_long_read(&rsp->expedited_tryfail),
83300- atomic_long_read(&rsp->expedited_workdone1),
83301- atomic_long_read(&rsp->expedited_workdone2),
83302- atomic_long_read(&rsp->expedited_normal),
83303- atomic_long_read(&rsp->expedited_stoppedcpus),
83304- atomic_long_read(&rsp->expedited_done_tries),
83305- atomic_long_read(&rsp->expedited_done_lost),
83306- atomic_long_read(&rsp->expedited_done_exit));
83307+ atomic_long_read_unchecked(&rsp->expedited_wrap),
83308+ atomic_long_read_unchecked(&rsp->expedited_tryfail),
83309+ atomic_long_read_unchecked(&rsp->expedited_workdone1),
83310+ atomic_long_read_unchecked(&rsp->expedited_workdone2),
83311+ atomic_long_read_unchecked(&rsp->expedited_normal),
83312+ atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
83313+ atomic_long_read_unchecked(&rsp->expedited_done_tries),
83314+ atomic_long_read_unchecked(&rsp->expedited_done_lost),
83315+ atomic_long_read_unchecked(&rsp->expedited_done_exit));
83316 return 0;
83317 }
83318
83319diff --git a/kernel/resource.c b/kernel/resource.c
83320index 3f285dc..5755f62 100644
83321--- a/kernel/resource.c
83322+++ b/kernel/resource.c
83323@@ -152,8 +152,18 @@ static const struct file_operations proc_iomem_operations = {
83324
83325 static int __init ioresources_init(void)
83326 {
83327+#ifdef CONFIG_GRKERNSEC_PROC_ADD
83328+#ifdef CONFIG_GRKERNSEC_PROC_USER
83329+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
83330+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
83331+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
83332+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
83333+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
83334+#endif
83335+#else
83336 proc_create("ioports", 0, NULL, &proc_ioports_operations);
83337 proc_create("iomem", 0, NULL, &proc_iomem_operations);
83338+#endif
83339 return 0;
83340 }
83341 __initcall(ioresources_init);
83342diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
83343index 1d96dd0..994ff19 100644
83344--- a/kernel/rtmutex-tester.c
83345+++ b/kernel/rtmutex-tester.c
83346@@ -22,7 +22,7 @@
83347 #define MAX_RT_TEST_MUTEXES 8
83348
83349 static spinlock_t rttest_lock;
83350-static atomic_t rttest_event;
83351+static atomic_unchecked_t rttest_event;
83352
83353 struct test_thread_data {
83354 int opcode;
83355@@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
83356
83357 case RTTEST_LOCKCONT:
83358 td->mutexes[td->opdata] = 1;
83359- td->event = atomic_add_return(1, &rttest_event);
83360+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83361 return 0;
83362
83363 case RTTEST_RESET:
83364@@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
83365 return 0;
83366
83367 case RTTEST_RESETEVENT:
83368- atomic_set(&rttest_event, 0);
83369+ atomic_set_unchecked(&rttest_event, 0);
83370 return 0;
83371
83372 default:
83373@@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
83374 return ret;
83375
83376 td->mutexes[id] = 1;
83377- td->event = atomic_add_return(1, &rttest_event);
83378+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83379 rt_mutex_lock(&mutexes[id]);
83380- td->event = atomic_add_return(1, &rttest_event);
83381+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83382 td->mutexes[id] = 4;
83383 return 0;
83384
83385@@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
83386 return ret;
83387
83388 td->mutexes[id] = 1;
83389- td->event = atomic_add_return(1, &rttest_event);
83390+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83391 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
83392- td->event = atomic_add_return(1, &rttest_event);
83393+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83394 td->mutexes[id] = ret ? 0 : 4;
83395 return ret ? -EINTR : 0;
83396
83397@@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
83398 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
83399 return ret;
83400
83401- td->event = atomic_add_return(1, &rttest_event);
83402+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83403 rt_mutex_unlock(&mutexes[id]);
83404- td->event = atomic_add_return(1, &rttest_event);
83405+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83406 td->mutexes[id] = 0;
83407 return 0;
83408
83409@@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
83410 break;
83411
83412 td->mutexes[dat] = 2;
83413- td->event = atomic_add_return(1, &rttest_event);
83414+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83415 break;
83416
83417 default:
83418@@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
83419 return;
83420
83421 td->mutexes[dat] = 3;
83422- td->event = atomic_add_return(1, &rttest_event);
83423+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83424 break;
83425
83426 case RTTEST_LOCKNOWAIT:
83427@@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
83428 return;
83429
83430 td->mutexes[dat] = 1;
83431- td->event = atomic_add_return(1, &rttest_event);
83432+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83433 return;
83434
83435 default:
83436diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
83437index 4a07353..66b5291 100644
83438--- a/kernel/sched/auto_group.c
83439+++ b/kernel/sched/auto_group.c
83440@@ -11,7 +11,7 @@
83441
83442 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
83443 static struct autogroup autogroup_default;
83444-static atomic_t autogroup_seq_nr;
83445+static atomic_unchecked_t autogroup_seq_nr;
83446
83447 void __init autogroup_init(struct task_struct *init_task)
83448 {
83449@@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
83450
83451 kref_init(&ag->kref);
83452 init_rwsem(&ag->lock);
83453- ag->id = atomic_inc_return(&autogroup_seq_nr);
83454+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
83455 ag->tg = tg;
83456 #ifdef CONFIG_RT_GROUP_SCHED
83457 /*
83458diff --git a/kernel/sched/core.c b/kernel/sched/core.c
83459index 05c39f0..442e6fe 100644
83460--- a/kernel/sched/core.c
83461+++ b/kernel/sched/core.c
83462@@ -2885,7 +2885,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
83463 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
83464 * or number of jiffies left till timeout) if completed.
83465 */
83466-long __sched
83467+long __sched __intentional_overflow(-1)
83468 wait_for_completion_interruptible_timeout(struct completion *x,
83469 unsigned long timeout)
83470 {
83471@@ -2902,7 +2902,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
83472 *
83473 * Return: -ERESTARTSYS if interrupted, 0 if completed.
83474 */
83475-int __sched wait_for_completion_killable(struct completion *x)
83476+int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
83477 {
83478 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
83479 if (t == -ERESTARTSYS)
83480@@ -2923,7 +2923,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
83481 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
83482 * or number of jiffies left till timeout) if completed.
83483 */
83484-long __sched
83485+long __sched __intentional_overflow(-1)
83486 wait_for_completion_killable_timeout(struct completion *x,
83487 unsigned long timeout)
83488 {
83489@@ -3149,6 +3149,8 @@ int can_nice(const struct task_struct *p, const int nice)
83490 /* convert nice value [19,-20] to rlimit style value [1,40] */
83491 int nice_rlim = 20 - nice;
83492
83493+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
83494+
83495 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
83496 capable(CAP_SYS_NICE));
83497 }
83498@@ -3182,7 +3184,8 @@ SYSCALL_DEFINE1(nice, int, increment)
83499 if (nice > 19)
83500 nice = 19;
83501
83502- if (increment < 0 && !can_nice(current, nice))
83503+ if (increment < 0 && (!can_nice(current, nice) ||
83504+ gr_handle_chroot_nice()))
83505 return -EPERM;
83506
83507 retval = security_task_setnice(current, nice);
83508@@ -3344,6 +3347,7 @@ recheck:
83509 unsigned long rlim_rtprio =
83510 task_rlimit(p, RLIMIT_RTPRIO);
83511
83512+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
83513 /* can't set/change the rt policy */
83514 if (policy != p->policy && !rlim_rtprio)
83515 return -EPERM;
83516@@ -4473,7 +4477,7 @@ static void migrate_tasks(unsigned int dead_cpu)
83517
83518 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
83519
83520-static struct ctl_table sd_ctl_dir[] = {
83521+static ctl_table_no_const sd_ctl_dir[] __read_only = {
83522 {
83523 .procname = "sched_domain",
83524 .mode = 0555,
83525@@ -4490,17 +4494,17 @@ static struct ctl_table sd_ctl_root[] = {
83526 {}
83527 };
83528
83529-static struct ctl_table *sd_alloc_ctl_entry(int n)
83530+static ctl_table_no_const *sd_alloc_ctl_entry(int n)
83531 {
83532- struct ctl_table *entry =
83533+ ctl_table_no_const *entry =
83534 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
83535
83536 return entry;
83537 }
83538
83539-static void sd_free_ctl_entry(struct ctl_table **tablep)
83540+static void sd_free_ctl_entry(ctl_table_no_const *tablep)
83541 {
83542- struct ctl_table *entry;
83543+ ctl_table_no_const *entry;
83544
83545 /*
83546 * In the intermediate directories, both the child directory and
83547@@ -4508,22 +4512,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
83548 * will always be set. In the lowest directory the names are
83549 * static strings and all have proc handlers.
83550 */
83551- for (entry = *tablep; entry->mode; entry++) {
83552- if (entry->child)
83553- sd_free_ctl_entry(&entry->child);
83554+ for (entry = tablep; entry->mode; entry++) {
83555+ if (entry->child) {
83556+ sd_free_ctl_entry(entry->child);
83557+ pax_open_kernel();
83558+ entry->child = NULL;
83559+ pax_close_kernel();
83560+ }
83561 if (entry->proc_handler == NULL)
83562 kfree(entry->procname);
83563 }
83564
83565- kfree(*tablep);
83566- *tablep = NULL;
83567+ kfree(tablep);
83568 }
83569
83570 static int min_load_idx = 0;
83571 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
83572
83573 static void
83574-set_table_entry(struct ctl_table *entry,
83575+set_table_entry(ctl_table_no_const *entry,
83576 const char *procname, void *data, int maxlen,
83577 umode_t mode, proc_handler *proc_handler,
83578 bool load_idx)
83579@@ -4543,7 +4550,7 @@ set_table_entry(struct ctl_table *entry,
83580 static struct ctl_table *
83581 sd_alloc_ctl_domain_table(struct sched_domain *sd)
83582 {
83583- struct ctl_table *table = sd_alloc_ctl_entry(13);
83584+ ctl_table_no_const *table = sd_alloc_ctl_entry(13);
83585
83586 if (table == NULL)
83587 return NULL;
83588@@ -4578,9 +4585,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
83589 return table;
83590 }
83591
83592-static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
83593+static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
83594 {
83595- struct ctl_table *entry, *table;
83596+ ctl_table_no_const *entry, *table;
83597 struct sched_domain *sd;
83598 int domain_num = 0, i;
83599 char buf[32];
83600@@ -4607,11 +4614,13 @@ static struct ctl_table_header *sd_sysctl_header;
83601 static void register_sched_domain_sysctl(void)
83602 {
83603 int i, cpu_num = num_possible_cpus();
83604- struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
83605+ ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
83606 char buf[32];
83607
83608 WARN_ON(sd_ctl_dir[0].child);
83609+ pax_open_kernel();
83610 sd_ctl_dir[0].child = entry;
83611+ pax_close_kernel();
83612
83613 if (entry == NULL)
83614 return;
83615@@ -4634,8 +4643,12 @@ static void unregister_sched_domain_sysctl(void)
83616 if (sd_sysctl_header)
83617 unregister_sysctl_table(sd_sysctl_header);
83618 sd_sysctl_header = NULL;
83619- if (sd_ctl_dir[0].child)
83620- sd_free_ctl_entry(&sd_ctl_dir[0].child);
83621+ if (sd_ctl_dir[0].child) {
83622+ sd_free_ctl_entry(sd_ctl_dir[0].child);
83623+ pax_open_kernel();
83624+ sd_ctl_dir[0].child = NULL;
83625+ pax_close_kernel();
83626+ }
83627 }
83628 #else
83629 static void register_sched_domain_sysctl(void)
83630diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
83631index 68f1609..640ba13 100644
83632--- a/kernel/sched/fair.c
83633+++ b/kernel/sched/fair.c
83634@@ -869,7 +869,7 @@ void task_numa_fault(int node, int pages, bool migrated)
83635
83636 static void reset_ptenuma_scan(struct task_struct *p)
83637 {
83638- ACCESS_ONCE(p->mm->numa_scan_seq)++;
83639+ ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
83640 p->mm->numa_scan_offset = 0;
83641 }
83642
83643@@ -5727,7 +5727,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
83644 * run_rebalance_domains is triggered when needed from the scheduler tick.
83645 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
83646 */
83647-static void run_rebalance_domains(struct softirq_action *h)
83648+static void run_rebalance_domains(void)
83649 {
83650 int this_cpu = smp_processor_id();
83651 struct rq *this_rq = cpu_rq(this_cpu);
83652diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
83653index ef0a7b2..1b728c1 100644
83654--- a/kernel/sched/sched.h
83655+++ b/kernel/sched/sched.h
83656@@ -1004,7 +1004,7 @@ struct sched_class {
83657 #ifdef CONFIG_FAIR_GROUP_SCHED
83658 void (*task_move_group) (struct task_struct *p, int on_rq);
83659 #endif
83660-};
83661+} __do_const;
83662
83663 #define sched_class_highest (&stop_sched_class)
83664 #define for_each_class(class) \
83665diff --git a/kernel/signal.c b/kernel/signal.c
83666index 50e4107..08bcb94 100644
83667--- a/kernel/signal.c
83668+++ b/kernel/signal.c
83669@@ -51,12 +51,12 @@ static struct kmem_cache *sigqueue_cachep;
83670
83671 int print_fatal_signals __read_mostly;
83672
83673-static void __user *sig_handler(struct task_struct *t, int sig)
83674+static __sighandler_t sig_handler(struct task_struct *t, int sig)
83675 {
83676 return t->sighand->action[sig - 1].sa.sa_handler;
83677 }
83678
83679-static int sig_handler_ignored(void __user *handler, int sig)
83680+static int sig_handler_ignored(__sighandler_t handler, int sig)
83681 {
83682 /* Is it explicitly or implicitly ignored? */
83683 return handler == SIG_IGN ||
83684@@ -65,7 +65,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
83685
83686 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
83687 {
83688- void __user *handler;
83689+ __sighandler_t handler;
83690
83691 handler = sig_handler(t, sig);
83692
83693@@ -369,6 +369,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
83694 atomic_inc(&user->sigpending);
83695 rcu_read_unlock();
83696
83697+ if (!override_rlimit)
83698+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
83699+
83700 if (override_rlimit ||
83701 atomic_read(&user->sigpending) <=
83702 task_rlimit(t, RLIMIT_SIGPENDING)) {
83703@@ -496,7 +499,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
83704
83705 int unhandled_signal(struct task_struct *tsk, int sig)
83706 {
83707- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
83708+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
83709 if (is_global_init(tsk))
83710 return 1;
83711 if (handler != SIG_IGN && handler != SIG_DFL)
83712@@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
83713 }
83714 }
83715
83716+ /* allow glibc communication via tgkill to other threads in our
83717+ thread group */
83718+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
83719+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
83720+ && gr_handle_signal(t, sig))
83721+ return -EPERM;
83722+
83723 return security_task_kill(t, info, sig, 0);
83724 }
83725
83726@@ -1199,7 +1209,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
83727 return send_signal(sig, info, p, 1);
83728 }
83729
83730-static int
83731+int
83732 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
83733 {
83734 return send_signal(sig, info, t, 0);
83735@@ -1236,6 +1246,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
83736 unsigned long int flags;
83737 int ret, blocked, ignored;
83738 struct k_sigaction *action;
83739+ int is_unhandled = 0;
83740
83741 spin_lock_irqsave(&t->sighand->siglock, flags);
83742 action = &t->sighand->action[sig-1];
83743@@ -1250,9 +1261,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
83744 }
83745 if (action->sa.sa_handler == SIG_DFL)
83746 t->signal->flags &= ~SIGNAL_UNKILLABLE;
83747+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
83748+ is_unhandled = 1;
83749 ret = specific_send_sig_info(sig, info, t);
83750 spin_unlock_irqrestore(&t->sighand->siglock, flags);
83751
83752+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
83753+ normal operation */
83754+ if (is_unhandled) {
83755+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
83756+ gr_handle_crash(t, sig);
83757+ }
83758+
83759 return ret;
83760 }
83761
83762@@ -1319,8 +1339,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
83763 ret = check_kill_permission(sig, info, p);
83764 rcu_read_unlock();
83765
83766- if (!ret && sig)
83767+ if (!ret && sig) {
83768 ret = do_send_sig_info(sig, info, p, true);
83769+ if (!ret)
83770+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
83771+ }
83772
83773 return ret;
83774 }
83775@@ -2926,7 +2949,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
83776 int error = -ESRCH;
83777
83778 rcu_read_lock();
83779- p = find_task_by_vpid(pid);
83780+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
83781+ /* allow glibc communication via tgkill to other threads in our
83782+ thread group */
83783+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
83784+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
83785+ p = find_task_by_vpid_unrestricted(pid);
83786+ else
83787+#endif
83788+ p = find_task_by_vpid(pid);
83789 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
83790 error = check_kill_permission(sig, info, p);
83791 /*
83792@@ -3219,6 +3250,16 @@ int __save_altstack(stack_t __user *uss, unsigned long sp)
83793 __put_user(t->sas_ss_size, &uss->ss_size);
83794 }
83795
83796+#ifdef CONFIG_X86
83797+void __save_altstack_ex(stack_t __user *uss, unsigned long sp)
83798+{
83799+ struct task_struct *t = current;
83800+ put_user_ex((void __user *)t->sas_ss_sp, &uss->ss_sp);
83801+ put_user_ex(sas_ss_flags(sp), &uss->ss_flags);
83802+ put_user_ex(t->sas_ss_size, &uss->ss_size);
83803+}
83804+#endif
83805+
83806 #ifdef CONFIG_COMPAT
83807 COMPAT_SYSCALL_DEFINE2(sigaltstack,
83808 const compat_stack_t __user *, uss_ptr,
83809@@ -3240,8 +3281,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
83810 }
83811 seg = get_fs();
83812 set_fs(KERNEL_DS);
83813- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
83814- (stack_t __force __user *) &uoss,
83815+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
83816+ (stack_t __force_user *) &uoss,
83817 compat_user_stack_pointer());
83818 set_fs(seg);
83819 if (ret >= 0 && uoss_ptr) {
83820@@ -3268,6 +3309,16 @@ int __compat_save_altstack(compat_stack_t __user *uss, unsigned long sp)
83821 __put_user(sas_ss_flags(sp), &uss->ss_flags) |
83822 __put_user(t->sas_ss_size, &uss->ss_size);
83823 }
83824+
83825+#ifdef CONFIG_X86
83826+void __compat_save_altstack_ex(compat_stack_t __user *uss, unsigned long sp)
83827+{
83828+ struct task_struct *t = current;
83829+ put_user_ex(ptr_to_compat((void __user *)t->sas_ss_sp), &uss->ss_sp);
83830+ put_user_ex(sas_ss_flags(sp), &uss->ss_flags);
83831+ put_user_ex(t->sas_ss_size, &uss->ss_size);
83832+}
83833+#endif
83834 #endif
83835
83836 #ifdef __ARCH_WANT_SYS_SIGPENDING
83837diff --git a/kernel/smpboot.c b/kernel/smpboot.c
83838index eb89e18..a4e6792 100644
83839--- a/kernel/smpboot.c
83840+++ b/kernel/smpboot.c
83841@@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
83842 }
83843 smpboot_unpark_thread(plug_thread, cpu);
83844 }
83845- list_add(&plug_thread->list, &hotplug_threads);
83846+ pax_list_add(&plug_thread->list, &hotplug_threads);
83847 out:
83848 mutex_unlock(&smpboot_threads_lock);
83849 return ret;
83850@@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
83851 {
83852 get_online_cpus();
83853 mutex_lock(&smpboot_threads_lock);
83854- list_del(&plug_thread->list);
83855+ pax_list_del(&plug_thread->list);
83856 smpboot_destroy_threads(plug_thread);
83857 mutex_unlock(&smpboot_threads_lock);
83858 put_online_cpus();
83859diff --git a/kernel/softirq.c b/kernel/softirq.c
83860index be3d351..9e4d5f2 100644
83861--- a/kernel/softirq.c
83862+++ b/kernel/softirq.c
83863@@ -53,11 +53,11 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
83864 EXPORT_SYMBOL(irq_stat);
83865 #endif
83866
83867-static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
83868+static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
83869
83870 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
83871
83872-char *softirq_to_name[NR_SOFTIRQS] = {
83873+const char * const softirq_to_name[NR_SOFTIRQS] = {
83874 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
83875 "TASKLET", "SCHED", "HRTIMER", "RCU"
83876 };
83877@@ -248,7 +248,7 @@ restart:
83878 kstat_incr_softirqs_this_cpu(vec_nr);
83879
83880 trace_softirq_entry(vec_nr);
83881- h->action(h);
83882+ h->action();
83883 trace_softirq_exit(vec_nr);
83884 if (unlikely(prev_count != preempt_count())) {
83885 printk(KERN_ERR "huh, entered softirq %u %s %p"
83886@@ -403,7 +403,7 @@ void __raise_softirq_irqoff(unsigned int nr)
83887 or_softirq_pending(1UL << nr);
83888 }
83889
83890-void open_softirq(int nr, void (*action)(struct softirq_action *))
83891+void __init open_softirq(int nr, void (*action)(void))
83892 {
83893 softirq_vec[nr].action = action;
83894 }
83895@@ -459,7 +459,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
83896
83897 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
83898
83899-static void tasklet_action(struct softirq_action *a)
83900+static void tasklet_action(void)
83901 {
83902 struct tasklet_struct *list;
83903
83904@@ -494,7 +494,7 @@ static void tasklet_action(struct softirq_action *a)
83905 }
83906 }
83907
83908-static void tasklet_hi_action(struct softirq_action *a)
83909+static void tasklet_hi_action(void)
83910 {
83911 struct tasklet_struct *list;
83912
83913@@ -849,7 +849,7 @@ static struct notifier_block cpu_nfb = {
83914 .notifier_call = cpu_callback
83915 };
83916
83917-static struct smp_hotplug_thread softirq_threads = {
83918+static struct smp_hotplug_thread softirq_threads __read_only = {
83919 .store = &ksoftirqd,
83920 .thread_should_run = ksoftirqd_should_run,
83921 .thread_fn = run_ksoftirqd,
83922diff --git a/kernel/srcu.c b/kernel/srcu.c
83923index 01d5ccb..cdcbee6 100644
83924--- a/kernel/srcu.c
83925+++ b/kernel/srcu.c
83926@@ -300,9 +300,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
83927
83928 idx = ACCESS_ONCE(sp->completed) & 0x1;
83929 preempt_disable();
83930- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
83931+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
83932 smp_mb(); /* B */ /* Avoid leaking the critical section. */
83933- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
83934+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
83935 preempt_enable();
83936 return idx;
83937 }
83938diff --git a/kernel/sys.c b/kernel/sys.c
83939index 771129b..dc0c7e3 100644
83940--- a/kernel/sys.c
83941+++ b/kernel/sys.c
83942@@ -149,6 +149,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
83943 error = -EACCES;
83944 goto out;
83945 }
83946+
83947+ if (gr_handle_chroot_setpriority(p, niceval)) {
83948+ error = -EACCES;
83949+ goto out;
83950+ }
83951+
83952 no_nice = security_task_setnice(p, niceval);
83953 if (no_nice) {
83954 error = no_nice;
83955@@ -352,6 +358,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
83956 goto error;
83957 }
83958
83959+ if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
83960+ goto error;
83961+
83962 if (rgid != (gid_t) -1 ||
83963 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
83964 new->sgid = new->egid;
83965@@ -387,6 +396,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
83966 old = current_cred();
83967
83968 retval = -EPERM;
83969+
83970+ if (gr_check_group_change(kgid, kgid, kgid))
83971+ goto error;
83972+
83973 if (nsown_capable(CAP_SETGID))
83974 new->gid = new->egid = new->sgid = new->fsgid = kgid;
83975 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
83976@@ -404,7 +417,7 @@ error:
83977 /*
83978 * change the user struct in a credentials set to match the new UID
83979 */
83980-static int set_user(struct cred *new)
83981+int set_user(struct cred *new)
83982 {
83983 struct user_struct *new_user;
83984
83985@@ -484,6 +497,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
83986 goto error;
83987 }
83988
83989+ if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
83990+ goto error;
83991+
83992 if (!uid_eq(new->uid, old->uid)) {
83993 retval = set_user(new);
83994 if (retval < 0)
83995@@ -534,6 +550,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
83996 old = current_cred();
83997
83998 retval = -EPERM;
83999+
84000+ if (gr_check_crash_uid(kuid))
84001+ goto error;
84002+ if (gr_check_user_change(kuid, kuid, kuid))
84003+ goto error;
84004+
84005 if (nsown_capable(CAP_SETUID)) {
84006 new->suid = new->uid = kuid;
84007 if (!uid_eq(kuid, old->uid)) {
84008@@ -603,6 +625,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
84009 goto error;
84010 }
84011
84012+ if (gr_check_user_change(kruid, keuid, INVALID_UID))
84013+ goto error;
84014+
84015 if (ruid != (uid_t) -1) {
84016 new->uid = kruid;
84017 if (!uid_eq(kruid, old->uid)) {
84018@@ -685,6 +710,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
84019 goto error;
84020 }
84021
84022+ if (gr_check_group_change(krgid, kegid, INVALID_GID))
84023+ goto error;
84024+
84025 if (rgid != (gid_t) -1)
84026 new->gid = krgid;
84027 if (egid != (gid_t) -1)
84028@@ -746,12 +774,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
84029 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
84030 nsown_capable(CAP_SETUID)) {
84031 if (!uid_eq(kuid, old->fsuid)) {
84032+ if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
84033+ goto error;
84034+
84035 new->fsuid = kuid;
84036 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
84037 goto change_okay;
84038 }
84039 }
84040
84041+error:
84042 abort_creds(new);
84043 return old_fsuid;
84044
84045@@ -784,12 +816,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
84046 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
84047 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
84048 nsown_capable(CAP_SETGID)) {
84049+ if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
84050+ goto error;
84051+
84052 if (!gid_eq(kgid, old->fsgid)) {
84053 new->fsgid = kgid;
84054 goto change_okay;
84055 }
84056 }
84057
84058+error:
84059 abort_creds(new);
84060 return old_fsgid;
84061
84062@@ -1169,19 +1205,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
84063 return -EFAULT;
84064
84065 down_read(&uts_sem);
84066- error = __copy_to_user(&name->sysname, &utsname()->sysname,
84067+ error = __copy_to_user(name->sysname, &utsname()->sysname,
84068 __OLD_UTS_LEN);
84069 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
84070- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
84071+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
84072 __OLD_UTS_LEN);
84073 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
84074- error |= __copy_to_user(&name->release, &utsname()->release,
84075+ error |= __copy_to_user(name->release, &utsname()->release,
84076 __OLD_UTS_LEN);
84077 error |= __put_user(0, name->release + __OLD_UTS_LEN);
84078- error |= __copy_to_user(&name->version, &utsname()->version,
84079+ error |= __copy_to_user(name->version, &utsname()->version,
84080 __OLD_UTS_LEN);
84081 error |= __put_user(0, name->version + __OLD_UTS_LEN);
84082- error |= __copy_to_user(&name->machine, &utsname()->machine,
84083+ error |= __copy_to_user(name->machine, &utsname()->machine,
84084 __OLD_UTS_LEN);
84085 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
84086 up_read(&uts_sem);
84087@@ -1383,6 +1419,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
84088 */
84089 new_rlim->rlim_cur = 1;
84090 }
84091+ /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
84092+ is changed to a lower value. Since tasks can be created by the same
84093+ user in between this limit change and an execve by this task, force
84094+ a recheck only for this task by setting PF_NPROC_EXCEEDED
84095+ */
84096+ if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
84097+ tsk->flags |= PF_NPROC_EXCEEDED;
84098 }
84099 if (!retval) {
84100 if (old_rlim)
84101diff --git a/kernel/sysctl.c b/kernel/sysctl.c
84102index 07f6fc4..65fb3d4 100644
84103--- a/kernel/sysctl.c
84104+++ b/kernel/sysctl.c
84105@@ -93,7 +93,6 @@
84106
84107
84108 #if defined(CONFIG_SYSCTL)
84109-
84110 /* External variables not in a header file. */
84111 extern int sysctl_overcommit_memory;
84112 extern int sysctl_overcommit_ratio;
84113@@ -119,17 +118,18 @@ extern int blk_iopoll_enabled;
84114
84115 /* Constants used for minimum and maximum */
84116 #ifdef CONFIG_LOCKUP_DETECTOR
84117-static int sixty = 60;
84118+static int sixty __read_only = 60;
84119 #endif
84120
84121-static int zero;
84122-static int __maybe_unused one = 1;
84123-static int __maybe_unused two = 2;
84124-static int __maybe_unused three = 3;
84125-static unsigned long one_ul = 1;
84126-static int one_hundred = 100;
84127+static int neg_one __read_only = -1;
84128+static int zero __read_only = 0;
84129+static int __maybe_unused one __read_only = 1;
84130+static int __maybe_unused two __read_only = 2;
84131+static int __maybe_unused three __read_only = 3;
84132+static unsigned long one_ul __read_only = 1;
84133+static int one_hundred __read_only = 100;
84134 #ifdef CONFIG_PRINTK
84135-static int ten_thousand = 10000;
84136+static int ten_thousand __read_only = 10000;
84137 #endif
84138
84139 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
84140@@ -176,10 +176,8 @@ static int proc_taint(struct ctl_table *table, int write,
84141 void __user *buffer, size_t *lenp, loff_t *ppos);
84142 #endif
84143
84144-#ifdef CONFIG_PRINTK
84145 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
84146 void __user *buffer, size_t *lenp, loff_t *ppos);
84147-#endif
84148
84149 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
84150 void __user *buffer, size_t *lenp, loff_t *ppos);
84151@@ -210,6 +208,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
84152
84153 #endif
84154
84155+extern struct ctl_table grsecurity_table[];
84156+
84157 static struct ctl_table kern_table[];
84158 static struct ctl_table vm_table[];
84159 static struct ctl_table fs_table[];
84160@@ -224,6 +224,20 @@ extern struct ctl_table epoll_table[];
84161 int sysctl_legacy_va_layout;
84162 #endif
84163
84164+#ifdef CONFIG_PAX_SOFTMODE
84165+static ctl_table pax_table[] = {
84166+ {
84167+ .procname = "softmode",
84168+ .data = &pax_softmode,
84169+ .maxlen = sizeof(unsigned int),
84170+ .mode = 0600,
84171+ .proc_handler = &proc_dointvec,
84172+ },
84173+
84174+ { }
84175+};
84176+#endif
84177+
84178 /* The default sysctl tables: */
84179
84180 static struct ctl_table sysctl_base_table[] = {
84181@@ -272,6 +286,22 @@ static int max_extfrag_threshold = 1000;
84182 #endif
84183
84184 static struct ctl_table kern_table[] = {
84185+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
84186+ {
84187+ .procname = "grsecurity",
84188+ .mode = 0500,
84189+ .child = grsecurity_table,
84190+ },
84191+#endif
84192+
84193+#ifdef CONFIG_PAX_SOFTMODE
84194+ {
84195+ .procname = "pax",
84196+ .mode = 0500,
84197+ .child = pax_table,
84198+ },
84199+#endif
84200+
84201 {
84202 .procname = "sched_child_runs_first",
84203 .data = &sysctl_sched_child_runs_first,
84204@@ -613,7 +643,7 @@ static struct ctl_table kern_table[] = {
84205 .data = &modprobe_path,
84206 .maxlen = KMOD_PATH_LEN,
84207 .mode = 0644,
84208- .proc_handler = proc_dostring,
84209+ .proc_handler = proc_dostring_modpriv,
84210 },
84211 {
84212 .procname = "modules_disabled",
84213@@ -780,16 +810,20 @@ static struct ctl_table kern_table[] = {
84214 .extra1 = &zero,
84215 .extra2 = &one,
84216 },
84217+#endif
84218 {
84219 .procname = "kptr_restrict",
84220 .data = &kptr_restrict,
84221 .maxlen = sizeof(int),
84222 .mode = 0644,
84223 .proc_handler = proc_dointvec_minmax_sysadmin,
84224+#ifdef CONFIG_GRKERNSEC_HIDESYM
84225+ .extra1 = &two,
84226+#else
84227 .extra1 = &zero,
84228+#endif
84229 .extra2 = &two,
84230 },
84231-#endif
84232 {
84233 .procname = "ngroups_max",
84234 .data = &ngroups_max,
84235@@ -1031,10 +1065,17 @@ static struct ctl_table kern_table[] = {
84236 */
84237 {
84238 .procname = "perf_event_paranoid",
84239- .data = &sysctl_perf_event_paranoid,
84240- .maxlen = sizeof(sysctl_perf_event_paranoid),
84241+ .data = &sysctl_perf_event_legitimately_concerned,
84242+ .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
84243 .mode = 0644,
84244- .proc_handler = proc_dointvec,
84245+ /* go ahead, be a hero */
84246+ .proc_handler = proc_dointvec_minmax_sysadmin,
84247+ .extra1 = &neg_one,
84248+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
84249+ .extra2 = &three,
84250+#else
84251+ .extra2 = &two,
84252+#endif
84253 },
84254 {
84255 .procname = "perf_event_mlock_kb",
84256@@ -1297,6 +1338,13 @@ static struct ctl_table vm_table[] = {
84257 .proc_handler = proc_dointvec_minmax,
84258 .extra1 = &zero,
84259 },
84260+ {
84261+ .procname = "heap_stack_gap",
84262+ .data = &sysctl_heap_stack_gap,
84263+ .maxlen = sizeof(sysctl_heap_stack_gap),
84264+ .mode = 0644,
84265+ .proc_handler = proc_doulongvec_minmax,
84266+ },
84267 #else
84268 {
84269 .procname = "nr_trim_pages",
84270@@ -1761,6 +1809,16 @@ int proc_dostring(struct ctl_table *table, int write,
84271 buffer, lenp, ppos);
84272 }
84273
84274+int proc_dostring_modpriv(struct ctl_table *table, int write,
84275+ void __user *buffer, size_t *lenp, loff_t *ppos)
84276+{
84277+ if (write && !capable(CAP_SYS_MODULE))
84278+ return -EPERM;
84279+
84280+ return _proc_do_string(table->data, table->maxlen, write,
84281+ buffer, lenp, ppos);
84282+}
84283+
84284 static size_t proc_skip_spaces(char **buf)
84285 {
84286 size_t ret;
84287@@ -1866,6 +1924,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
84288 len = strlen(tmp);
84289 if (len > *size)
84290 len = *size;
84291+ if (len > sizeof(tmp))
84292+ len = sizeof(tmp);
84293 if (copy_to_user(*buf, tmp, len))
84294 return -EFAULT;
84295 *size -= len;
84296@@ -2030,7 +2090,7 @@ int proc_dointvec(struct ctl_table *table, int write,
84297 static int proc_taint(struct ctl_table *table, int write,
84298 void __user *buffer, size_t *lenp, loff_t *ppos)
84299 {
84300- struct ctl_table t;
84301+ ctl_table_no_const t;
84302 unsigned long tmptaint = get_taint();
84303 int err;
84304
84305@@ -2058,7 +2118,6 @@ static int proc_taint(struct ctl_table *table, int write,
84306 return err;
84307 }
84308
84309-#ifdef CONFIG_PRINTK
84310 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
84311 void __user *buffer, size_t *lenp, loff_t *ppos)
84312 {
84313@@ -2067,7 +2126,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
84314
84315 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
84316 }
84317-#endif
84318
84319 struct do_proc_dointvec_minmax_conv_param {
84320 int *min;
84321@@ -2214,8 +2272,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
84322 *i = val;
84323 } else {
84324 val = convdiv * (*i) / convmul;
84325- if (!first)
84326+ if (!first) {
84327 err = proc_put_char(&buffer, &left, '\t');
84328+ if (err)
84329+ break;
84330+ }
84331 err = proc_put_long(&buffer, &left, val, false);
84332 if (err)
84333 break;
84334@@ -2611,6 +2672,12 @@ int proc_dostring(struct ctl_table *table, int write,
84335 return -ENOSYS;
84336 }
84337
84338+int proc_dostring_modpriv(struct ctl_table *table, int write,
84339+ void __user *buffer, size_t *lenp, loff_t *ppos)
84340+{
84341+ return -ENOSYS;
84342+}
84343+
84344 int proc_dointvec(struct ctl_table *table, int write,
84345 void __user *buffer, size_t *lenp, loff_t *ppos)
84346 {
84347@@ -2667,5 +2734,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
84348 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
84349 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
84350 EXPORT_SYMBOL(proc_dostring);
84351+EXPORT_SYMBOL(proc_dostring_modpriv);
84352 EXPORT_SYMBOL(proc_doulongvec_minmax);
84353 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
84354diff --git a/kernel/taskstats.c b/kernel/taskstats.c
84355index 145bb4d..b2aa969 100644
84356--- a/kernel/taskstats.c
84357+++ b/kernel/taskstats.c
84358@@ -28,9 +28,12 @@
84359 #include <linux/fs.h>
84360 #include <linux/file.h>
84361 #include <linux/pid_namespace.h>
84362+#include <linux/grsecurity.h>
84363 #include <net/genetlink.h>
84364 #include <linux/atomic.h>
84365
84366+extern int gr_is_taskstats_denied(int pid);
84367+
84368 /*
84369 * Maximum length of a cpumask that can be specified in
84370 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
84371@@ -570,6 +573,9 @@ err:
84372
84373 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
84374 {
84375+ if (gr_is_taskstats_denied(current->pid))
84376+ return -EACCES;
84377+
84378 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
84379 return cmd_attr_register_cpumask(info);
84380 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
84381diff --git a/kernel/time.c b/kernel/time.c
84382index 7c7964c..784a599 100644
84383--- a/kernel/time.c
84384+++ b/kernel/time.c
84385@@ -172,6 +172,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
84386 return error;
84387
84388 if (tz) {
84389+ /* we log in do_settimeofday called below, so don't log twice
84390+ */
84391+ if (!tv)
84392+ gr_log_timechange();
84393+
84394 sys_tz = *tz;
84395 update_vsyscall_tz();
84396 if (firsttime) {
84397@@ -502,7 +507,7 @@ EXPORT_SYMBOL(usecs_to_jiffies);
84398 * The >> (NSEC_JIFFIE_SC - SEC_JIFFIE_SC) converts the scaled nsec
84399 * value to a scaled second value.
84400 */
84401-unsigned long
84402+unsigned long __intentional_overflow(-1)
84403 timespec_to_jiffies(const struct timespec *value)
84404 {
84405 unsigned long sec = value->tv_sec;
84406diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
84407index eec50fc..65e5df6 100644
84408--- a/kernel/time/alarmtimer.c
84409+++ b/kernel/time/alarmtimer.c
84410@@ -795,7 +795,7 @@ static int __init alarmtimer_init(void)
84411 struct platform_device *pdev;
84412 int error = 0;
84413 int i;
84414- struct k_clock alarm_clock = {
84415+ static struct k_clock alarm_clock = {
84416 .clock_getres = alarm_clock_getres,
84417 .clock_get = alarm_clock_get,
84418 .timer_create = alarm_timer_create,
84419diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
84420index 48b9fff..9e07e5f 100644
84421--- a/kernel/time/timekeeping.c
84422+++ b/kernel/time/timekeeping.c
84423@@ -15,6 +15,7 @@
84424 #include <linux/init.h>
84425 #include <linux/mm.h>
84426 #include <linux/sched.h>
84427+#include <linux/grsecurity.h>
84428 #include <linux/syscore_ops.h>
84429 #include <linux/clocksource.h>
84430 #include <linux/jiffies.h>
84431@@ -500,6 +501,8 @@ int do_settimeofday(const struct timespec *tv)
84432 if (!timespec_valid_strict(tv))
84433 return -EINVAL;
84434
84435+ gr_log_timechange();
84436+
84437 raw_spin_lock_irqsave(&timekeeper_lock, flags);
84438 write_seqcount_begin(&timekeeper_seq);
84439
84440diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
84441index 61ed862..3b52c65 100644
84442--- a/kernel/time/timer_list.c
84443+++ b/kernel/time/timer_list.c
84444@@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
84445
84446 static void print_name_offset(struct seq_file *m, void *sym)
84447 {
84448+#ifdef CONFIG_GRKERNSEC_HIDESYM
84449+ SEQ_printf(m, "<%p>", NULL);
84450+#else
84451 char symname[KSYM_NAME_LEN];
84452
84453 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
84454 SEQ_printf(m, "<%pK>", sym);
84455 else
84456 SEQ_printf(m, "%s", symname);
84457+#endif
84458 }
84459
84460 static void
84461@@ -119,7 +123,11 @@ next_one:
84462 static void
84463 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
84464 {
84465+#ifdef CONFIG_GRKERNSEC_HIDESYM
84466+ SEQ_printf(m, " .base: %p\n", NULL);
84467+#else
84468 SEQ_printf(m, " .base: %pK\n", base);
84469+#endif
84470 SEQ_printf(m, " .index: %d\n",
84471 base->index);
84472 SEQ_printf(m, " .resolution: %Lu nsecs\n",
84473@@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
84474 {
84475 struct proc_dir_entry *pe;
84476
84477+#ifdef CONFIG_GRKERNSEC_PROC_ADD
84478+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
84479+#else
84480 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
84481+#endif
84482 if (!pe)
84483 return -ENOMEM;
84484 return 0;
84485diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
84486index 0b537f2..40d6c20 100644
84487--- a/kernel/time/timer_stats.c
84488+++ b/kernel/time/timer_stats.c
84489@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
84490 static unsigned long nr_entries;
84491 static struct entry entries[MAX_ENTRIES];
84492
84493-static atomic_t overflow_count;
84494+static atomic_unchecked_t overflow_count;
84495
84496 /*
84497 * The entries are in a hash-table, for fast lookup:
84498@@ -140,7 +140,7 @@ static void reset_entries(void)
84499 nr_entries = 0;
84500 memset(entries, 0, sizeof(entries));
84501 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
84502- atomic_set(&overflow_count, 0);
84503+ atomic_set_unchecked(&overflow_count, 0);
84504 }
84505
84506 static struct entry *alloc_entry(void)
84507@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
84508 if (likely(entry))
84509 entry->count++;
84510 else
84511- atomic_inc(&overflow_count);
84512+ atomic_inc_unchecked(&overflow_count);
84513
84514 out_unlock:
84515 raw_spin_unlock_irqrestore(lock, flags);
84516@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
84517
84518 static void print_name_offset(struct seq_file *m, unsigned long addr)
84519 {
84520+#ifdef CONFIG_GRKERNSEC_HIDESYM
84521+ seq_printf(m, "<%p>", NULL);
84522+#else
84523 char symname[KSYM_NAME_LEN];
84524
84525 if (lookup_symbol_name(addr, symname) < 0)
84526- seq_printf(m, "<%p>", (void *)addr);
84527+ seq_printf(m, "<%pK>", (void *)addr);
84528 else
84529 seq_printf(m, "%s", symname);
84530+#endif
84531 }
84532
84533 static int tstats_show(struct seq_file *m, void *v)
84534@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
84535
84536 seq_puts(m, "Timer Stats Version: v0.2\n");
84537 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
84538- if (atomic_read(&overflow_count))
84539+ if (atomic_read_unchecked(&overflow_count))
84540 seq_printf(m, "Overflow: %d entries\n",
84541- atomic_read(&overflow_count));
84542+ atomic_read_unchecked(&overflow_count));
84543
84544 for (i = 0; i < nr_entries; i++) {
84545 entry = entries + i;
84546@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
84547 {
84548 struct proc_dir_entry *pe;
84549
84550+#ifdef CONFIG_GRKERNSEC_PROC_ADD
84551+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
84552+#else
84553 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
84554+#endif
84555 if (!pe)
84556 return -ENOMEM;
84557 return 0;
84558diff --git a/kernel/timer.c b/kernel/timer.c
84559index 4296d13..8998609 100644
84560--- a/kernel/timer.c
84561+++ b/kernel/timer.c
84562@@ -1366,7 +1366,7 @@ void update_process_times(int user_tick)
84563 /*
84564 * This function runs timers and the timer-tq in bottom half context.
84565 */
84566-static void run_timer_softirq(struct softirq_action *h)
84567+static void run_timer_softirq(void)
84568 {
84569 struct tvec_base *base = __this_cpu_read(tvec_bases);
84570
84571@@ -1429,7 +1429,7 @@ static void process_timeout(unsigned long __data)
84572 *
84573 * In all cases the return value is guaranteed to be non-negative.
84574 */
84575-signed long __sched schedule_timeout(signed long timeout)
84576+signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
84577 {
84578 struct timer_list timer;
84579 unsigned long expire;
84580diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
84581index b8b8560..75b1a09 100644
84582--- a/kernel/trace/blktrace.c
84583+++ b/kernel/trace/blktrace.c
84584@@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
84585 struct blk_trace *bt = filp->private_data;
84586 char buf[16];
84587
84588- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
84589+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
84590
84591 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
84592 }
84593@@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
84594 return 1;
84595
84596 bt = buf->chan->private_data;
84597- atomic_inc(&bt->dropped);
84598+ atomic_inc_unchecked(&bt->dropped);
84599 return 0;
84600 }
84601
84602@@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
84603
84604 bt->dir = dir;
84605 bt->dev = dev;
84606- atomic_set(&bt->dropped, 0);
84607+ atomic_set_unchecked(&bt->dropped, 0);
84608
84609 ret = -EIO;
84610 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
84611diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
84612index a6d098c..bb8cf65 100644
84613--- a/kernel/trace/ftrace.c
84614+++ b/kernel/trace/ftrace.c
84615@@ -1950,12 +1950,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
84616 if (unlikely(ftrace_disabled))
84617 return 0;
84618
84619+ ret = ftrace_arch_code_modify_prepare();
84620+ FTRACE_WARN_ON(ret);
84621+ if (ret)
84622+ return 0;
84623+
84624 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
84625+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
84626 if (ret) {
84627 ftrace_bug(ret, ip);
84628- return 0;
84629 }
84630- return 1;
84631+ return ret ? 0 : 1;
84632 }
84633
84634 /*
84635@@ -4028,8 +4033,10 @@ static int ftrace_process_locs(struct module *mod,
84636 if (!count)
84637 return 0;
84638
84639+ pax_open_kernel();
84640 sort(start, count, sizeof(*start),
84641 ftrace_cmp_ips, ftrace_swap_ips);
84642+ pax_close_kernel();
84643
84644 start_pg = ftrace_allocate_pages(count);
84645 if (!start_pg)
84646@@ -4752,8 +4759,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
84647 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
84648
84649 static int ftrace_graph_active;
84650-static struct notifier_block ftrace_suspend_notifier;
84651-
84652 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
84653 {
84654 return 0;
84655@@ -4897,6 +4902,10 @@ ftrace_suspend_notifier_call(struct notifier_block *bl, unsigned long state,
84656 return NOTIFY_DONE;
84657 }
84658
84659+static struct notifier_block ftrace_suspend_notifier = {
84660+ .notifier_call = ftrace_suspend_notifier_call
84661+};
84662+
84663 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
84664 trace_func_graph_ent_t entryfunc)
84665 {
84666@@ -4910,7 +4919,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
84667 goto out;
84668 }
84669
84670- ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
84671 register_pm_notifier(&ftrace_suspend_notifier);
84672
84673 ftrace_graph_active++;
84674diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
84675index cc2f66f..05edd54 100644
84676--- a/kernel/trace/ring_buffer.c
84677+++ b/kernel/trace/ring_buffer.c
84678@@ -352,9 +352,9 @@ struct buffer_data_page {
84679 */
84680 struct buffer_page {
84681 struct list_head list; /* list of buffer pages */
84682- local_t write; /* index for next write */
84683+ local_unchecked_t write; /* index for next write */
84684 unsigned read; /* index for next read */
84685- local_t entries; /* entries on this page */
84686+ local_unchecked_t entries; /* entries on this page */
84687 unsigned long real_end; /* real end of data */
84688 struct buffer_data_page *page; /* Actual data page */
84689 };
84690@@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
84691 unsigned long last_overrun;
84692 local_t entries_bytes;
84693 local_t entries;
84694- local_t overrun;
84695- local_t commit_overrun;
84696+ local_unchecked_t overrun;
84697+ local_unchecked_t commit_overrun;
84698 local_t dropped_events;
84699 local_t committing;
84700 local_t commits;
84701@@ -992,8 +992,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
84702 *
84703 * We add a counter to the write field to denote this.
84704 */
84705- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
84706- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
84707+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
84708+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
84709
84710 /*
84711 * Just make sure we have seen our old_write and synchronize
84712@@ -1021,8 +1021,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
84713 * cmpxchg to only update if an interrupt did not already
84714 * do it for us. If the cmpxchg fails, we don't care.
84715 */
84716- (void)local_cmpxchg(&next_page->write, old_write, val);
84717- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
84718+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
84719+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
84720
84721 /*
84722 * No need to worry about races with clearing out the commit.
84723@@ -1386,12 +1386,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
84724
84725 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
84726 {
84727- return local_read(&bpage->entries) & RB_WRITE_MASK;
84728+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
84729 }
84730
84731 static inline unsigned long rb_page_write(struct buffer_page *bpage)
84732 {
84733- return local_read(&bpage->write) & RB_WRITE_MASK;
84734+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
84735 }
84736
84737 static int
84738@@ -1486,7 +1486,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
84739 * bytes consumed in ring buffer from here.
84740 * Increment overrun to account for the lost events.
84741 */
84742- local_add(page_entries, &cpu_buffer->overrun);
84743+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
84744 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
84745 }
84746
84747@@ -2064,7 +2064,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
84748 * it is our responsibility to update
84749 * the counters.
84750 */
84751- local_add(entries, &cpu_buffer->overrun);
84752+ local_add_unchecked(entries, &cpu_buffer->overrun);
84753 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
84754
84755 /*
84756@@ -2214,7 +2214,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
84757 if (tail == BUF_PAGE_SIZE)
84758 tail_page->real_end = 0;
84759
84760- local_sub(length, &tail_page->write);
84761+ local_sub_unchecked(length, &tail_page->write);
84762 return;
84763 }
84764
84765@@ -2249,7 +2249,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
84766 rb_event_set_padding(event);
84767
84768 /* Set the write back to the previous setting */
84769- local_sub(length, &tail_page->write);
84770+ local_sub_unchecked(length, &tail_page->write);
84771 return;
84772 }
84773
84774@@ -2261,7 +2261,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
84775
84776 /* Set write to end of buffer */
84777 length = (tail + length) - BUF_PAGE_SIZE;
84778- local_sub(length, &tail_page->write);
84779+ local_sub_unchecked(length, &tail_page->write);
84780 }
84781
84782 /*
84783@@ -2287,7 +2287,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
84784 * about it.
84785 */
84786 if (unlikely(next_page == commit_page)) {
84787- local_inc(&cpu_buffer->commit_overrun);
84788+ local_inc_unchecked(&cpu_buffer->commit_overrun);
84789 goto out_reset;
84790 }
84791
84792@@ -2343,7 +2343,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
84793 cpu_buffer->tail_page) &&
84794 (cpu_buffer->commit_page ==
84795 cpu_buffer->reader_page))) {
84796- local_inc(&cpu_buffer->commit_overrun);
84797+ local_inc_unchecked(&cpu_buffer->commit_overrun);
84798 goto out_reset;
84799 }
84800 }
84801@@ -2391,7 +2391,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
84802 length += RB_LEN_TIME_EXTEND;
84803
84804 tail_page = cpu_buffer->tail_page;
84805- write = local_add_return(length, &tail_page->write);
84806+ write = local_add_return_unchecked(length, &tail_page->write);
84807
84808 /* set write to only the index of the write */
84809 write &= RB_WRITE_MASK;
84810@@ -2408,7 +2408,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
84811 kmemcheck_annotate_bitfield(event, bitfield);
84812 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
84813
84814- local_inc(&tail_page->entries);
84815+ local_inc_unchecked(&tail_page->entries);
84816
84817 /*
84818 * If this is the first commit on the page, then update
84819@@ -2441,7 +2441,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
84820
84821 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
84822 unsigned long write_mask =
84823- local_read(&bpage->write) & ~RB_WRITE_MASK;
84824+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
84825 unsigned long event_length = rb_event_length(event);
84826 /*
84827 * This is on the tail page. It is possible that
84828@@ -2451,7 +2451,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
84829 */
84830 old_index += write_mask;
84831 new_index += write_mask;
84832- index = local_cmpxchg(&bpage->write, old_index, new_index);
84833+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
84834 if (index == old_index) {
84835 /* update counters */
84836 local_sub(event_length, &cpu_buffer->entries_bytes);
84837@@ -2843,7 +2843,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
84838
84839 /* Do the likely case first */
84840 if (likely(bpage->page == (void *)addr)) {
84841- local_dec(&bpage->entries);
84842+ local_dec_unchecked(&bpage->entries);
84843 return;
84844 }
84845
84846@@ -2855,7 +2855,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
84847 start = bpage;
84848 do {
84849 if (bpage->page == (void *)addr) {
84850- local_dec(&bpage->entries);
84851+ local_dec_unchecked(&bpage->entries);
84852 return;
84853 }
84854 rb_inc_page(cpu_buffer, &bpage);
84855@@ -3139,7 +3139,7 @@ static inline unsigned long
84856 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
84857 {
84858 return local_read(&cpu_buffer->entries) -
84859- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
84860+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
84861 }
84862
84863 /**
84864@@ -3228,7 +3228,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
84865 return 0;
84866
84867 cpu_buffer = buffer->buffers[cpu];
84868- ret = local_read(&cpu_buffer->overrun);
84869+ ret = local_read_unchecked(&cpu_buffer->overrun);
84870
84871 return ret;
84872 }
84873@@ -3251,7 +3251,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
84874 return 0;
84875
84876 cpu_buffer = buffer->buffers[cpu];
84877- ret = local_read(&cpu_buffer->commit_overrun);
84878+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
84879
84880 return ret;
84881 }
84882@@ -3336,7 +3336,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
84883 /* if you care about this being correct, lock the buffer */
84884 for_each_buffer_cpu(buffer, cpu) {
84885 cpu_buffer = buffer->buffers[cpu];
84886- overruns += local_read(&cpu_buffer->overrun);
84887+ overruns += local_read_unchecked(&cpu_buffer->overrun);
84888 }
84889
84890 return overruns;
84891@@ -3512,8 +3512,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
84892 /*
84893 * Reset the reader page to size zero.
84894 */
84895- local_set(&cpu_buffer->reader_page->write, 0);
84896- local_set(&cpu_buffer->reader_page->entries, 0);
84897+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
84898+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
84899 local_set(&cpu_buffer->reader_page->page->commit, 0);
84900 cpu_buffer->reader_page->real_end = 0;
84901
84902@@ -3547,7 +3547,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
84903 * want to compare with the last_overrun.
84904 */
84905 smp_mb();
84906- overwrite = local_read(&(cpu_buffer->overrun));
84907+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
84908
84909 /*
84910 * Here's the tricky part.
84911@@ -4117,8 +4117,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
84912
84913 cpu_buffer->head_page
84914 = list_entry(cpu_buffer->pages, struct buffer_page, list);
84915- local_set(&cpu_buffer->head_page->write, 0);
84916- local_set(&cpu_buffer->head_page->entries, 0);
84917+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
84918+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
84919 local_set(&cpu_buffer->head_page->page->commit, 0);
84920
84921 cpu_buffer->head_page->read = 0;
84922@@ -4128,14 +4128,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
84923
84924 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
84925 INIT_LIST_HEAD(&cpu_buffer->new_pages);
84926- local_set(&cpu_buffer->reader_page->write, 0);
84927- local_set(&cpu_buffer->reader_page->entries, 0);
84928+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
84929+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
84930 local_set(&cpu_buffer->reader_page->page->commit, 0);
84931 cpu_buffer->reader_page->read = 0;
84932
84933 local_set(&cpu_buffer->entries_bytes, 0);
84934- local_set(&cpu_buffer->overrun, 0);
84935- local_set(&cpu_buffer->commit_overrun, 0);
84936+ local_set_unchecked(&cpu_buffer->overrun, 0);
84937+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
84938 local_set(&cpu_buffer->dropped_events, 0);
84939 local_set(&cpu_buffer->entries, 0);
84940 local_set(&cpu_buffer->committing, 0);
84941@@ -4540,8 +4540,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
84942 rb_init_page(bpage);
84943 bpage = reader->page;
84944 reader->page = *data_page;
84945- local_set(&reader->write, 0);
84946- local_set(&reader->entries, 0);
84947+ local_set_unchecked(&reader->write, 0);
84948+ local_set_unchecked(&reader->entries, 0);
84949 reader->read = 0;
84950 *data_page = bpage;
84951
84952diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
84953index 496f94d..754aeea 100644
84954--- a/kernel/trace/trace.c
84955+++ b/kernel/trace/trace.c
84956@@ -3335,7 +3335,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
84957 return 0;
84958 }
84959
84960-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
84961+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
84962 {
84963 /* do nothing if flag is already set */
84964 if (!!(trace_flags & mask) == !!enabled)
84965diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
84966index afaae41..64871f8 100644
84967--- a/kernel/trace/trace.h
84968+++ b/kernel/trace/trace.h
84969@@ -1025,7 +1025,7 @@ extern const char *__stop___trace_bprintk_fmt[];
84970 void trace_printk_init_buffers(void);
84971 void trace_printk_start_comm(void);
84972 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
84973-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
84974+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
84975
84976 /*
84977 * Normal trace_printk() and friends allocates special buffers
84978diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
84979index 26dc348..8708ca7 100644
84980--- a/kernel/trace/trace_clock.c
84981+++ b/kernel/trace/trace_clock.c
84982@@ -123,7 +123,7 @@ u64 notrace trace_clock_global(void)
84983 return now;
84984 }
84985
84986-static atomic64_t trace_counter;
84987+static atomic64_unchecked_t trace_counter;
84988
84989 /*
84990 * trace_clock_counter(): simply an atomic counter.
84991@@ -132,5 +132,5 @@ static atomic64_t trace_counter;
84992 */
84993 u64 notrace trace_clock_counter(void)
84994 {
84995- return atomic64_add_return(1, &trace_counter);
84996+ return atomic64_inc_return_unchecked(&trace_counter);
84997 }
84998diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
84999index 29a7ebc..eb473cf 100644
85000--- a/kernel/trace/trace_events.c
85001+++ b/kernel/trace/trace_events.c
85002@@ -1778,10 +1778,6 @@ static LIST_HEAD(ftrace_module_file_list);
85003 struct ftrace_module_file_ops {
85004 struct list_head list;
85005 struct module *mod;
85006- struct file_operations id;
85007- struct file_operations enable;
85008- struct file_operations format;
85009- struct file_operations filter;
85010 };
85011
85012 static struct ftrace_module_file_ops *
85013@@ -1822,17 +1818,12 @@ trace_create_file_ops(struct module *mod)
85014
85015 file_ops->mod = mod;
85016
85017- file_ops->id = ftrace_event_id_fops;
85018- file_ops->id.owner = mod;
85019-
85020- file_ops->enable = ftrace_enable_fops;
85021- file_ops->enable.owner = mod;
85022-
85023- file_ops->filter = ftrace_event_filter_fops;
85024- file_ops->filter.owner = mod;
85025-
85026- file_ops->format = ftrace_event_format_fops;
85027- file_ops->format.owner = mod;
85028+ pax_open_kernel();
85029+ mod->trace_id.owner = mod;
85030+ mod->trace_enable.owner = mod;
85031+ mod->trace_filter.owner = mod;
85032+ mod->trace_format.owner = mod;
85033+ pax_close_kernel();
85034
85035 list_add(&file_ops->list, &ftrace_module_file_list);
85036
85037@@ -1925,8 +1916,8 @@ __trace_add_new_mod_event(struct ftrace_event_call *call,
85038 struct ftrace_module_file_ops *file_ops)
85039 {
85040 return __trace_add_new_event(call, tr,
85041- &file_ops->id, &file_ops->enable,
85042- &file_ops->filter, &file_ops->format);
85043+ &file_ops->mod->trace_id, &file_ops->mod->trace_enable,
85044+ &file_ops->mod->trace_filter, &file_ops->mod->trace_format);
85045 }
85046
85047 #else
85048diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
85049index b3dcfb2..ebee344 100644
85050--- a/kernel/trace/trace_mmiotrace.c
85051+++ b/kernel/trace/trace_mmiotrace.c
85052@@ -24,7 +24,7 @@ struct header_iter {
85053 static struct trace_array *mmio_trace_array;
85054 static bool overrun_detected;
85055 static unsigned long prev_overruns;
85056-static atomic_t dropped_count;
85057+static atomic_unchecked_t dropped_count;
85058
85059 static void mmio_reset_data(struct trace_array *tr)
85060 {
85061@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
85062
85063 static unsigned long count_overruns(struct trace_iterator *iter)
85064 {
85065- unsigned long cnt = atomic_xchg(&dropped_count, 0);
85066+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
85067 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
85068
85069 if (over > prev_overruns)
85070@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
85071 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
85072 sizeof(*entry), 0, pc);
85073 if (!event) {
85074- atomic_inc(&dropped_count);
85075+ atomic_inc_unchecked(&dropped_count);
85076 return;
85077 }
85078 entry = ring_buffer_event_data(event);
85079@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
85080 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
85081 sizeof(*entry), 0, pc);
85082 if (!event) {
85083- atomic_inc(&dropped_count);
85084+ atomic_inc_unchecked(&dropped_count);
85085 return;
85086 }
85087 entry = ring_buffer_event_data(event);
85088diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
85089index 34e7cba..6f9a729 100644
85090--- a/kernel/trace/trace_output.c
85091+++ b/kernel/trace/trace_output.c
85092@@ -294,7 +294,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
85093
85094 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
85095 if (!IS_ERR(p)) {
85096- p = mangle_path(s->buffer + s->len, p, "\n");
85097+ p = mangle_path(s->buffer + s->len, p, "\n\\");
85098 if (p) {
85099 s->len = p - s->buffer;
85100 return 1;
85101@@ -893,14 +893,16 @@ int register_ftrace_event(struct trace_event *event)
85102 goto out;
85103 }
85104
85105+ pax_open_kernel();
85106 if (event->funcs->trace == NULL)
85107- event->funcs->trace = trace_nop_print;
85108+ *(void **)&event->funcs->trace = trace_nop_print;
85109 if (event->funcs->raw == NULL)
85110- event->funcs->raw = trace_nop_print;
85111+ *(void **)&event->funcs->raw = trace_nop_print;
85112 if (event->funcs->hex == NULL)
85113- event->funcs->hex = trace_nop_print;
85114+ *(void **)&event->funcs->hex = trace_nop_print;
85115 if (event->funcs->binary == NULL)
85116- event->funcs->binary = trace_nop_print;
85117+ *(void **)&event->funcs->binary = trace_nop_print;
85118+ pax_close_kernel();
85119
85120 key = event->type & (EVENT_HASHSIZE - 1);
85121
85122diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
85123index b20428c..4845a10 100644
85124--- a/kernel/trace/trace_stack.c
85125+++ b/kernel/trace/trace_stack.c
85126@@ -68,7 +68,7 @@ check_stack(unsigned long ip, unsigned long *stack)
85127 return;
85128
85129 /* we do not handle interrupt stacks yet */
85130- if (!object_is_on_stack(stack))
85131+ if (!object_starts_on_stack(stack))
85132 return;
85133
85134 local_irq_save(flags);
85135diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
85136index 9064b91..1f5d2f8 100644
85137--- a/kernel/user_namespace.c
85138+++ b/kernel/user_namespace.c
85139@@ -82,6 +82,21 @@ int create_user_ns(struct cred *new)
85140 !kgid_has_mapping(parent_ns, group))
85141 return -EPERM;
85142
85143+#ifdef CONFIG_GRKERNSEC
85144+ /*
85145+ * This doesn't really inspire confidence:
85146+ * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
85147+ * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
85148+ * Increases kernel attack surface in areas developers
85149+ * previously cared little about ("low importance due
85150+ * to requiring "root" capability")
85151+ * To be removed when this code receives *proper* review
85152+ */
85153+ if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
85154+ !capable(CAP_SETGID))
85155+ return -EPERM;
85156+#endif
85157+
85158 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
85159 if (!ns)
85160 return -ENOMEM;
85161@@ -862,7 +877,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
85162 if (atomic_read(&current->mm->mm_users) > 1)
85163 return -EINVAL;
85164
85165- if (current->fs->users != 1)
85166+ if (atomic_read(&current->fs->users) != 1)
85167 return -EINVAL;
85168
85169 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
85170diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
85171index 4f69f9a..7c6f8f8 100644
85172--- a/kernel/utsname_sysctl.c
85173+++ b/kernel/utsname_sysctl.c
85174@@ -47,7 +47,7 @@ static void put_uts(ctl_table *table, int write, void *which)
85175 static int proc_do_uts_string(ctl_table *table, int write,
85176 void __user *buffer, size_t *lenp, loff_t *ppos)
85177 {
85178- struct ctl_table uts_table;
85179+ ctl_table_no_const uts_table;
85180 int r;
85181 memcpy(&uts_table, table, sizeof(uts_table));
85182 uts_table.data = get_uts(table, write);
85183diff --git a/kernel/watchdog.c b/kernel/watchdog.c
85184index 1241d8c..d5cfc28 100644
85185--- a/kernel/watchdog.c
85186+++ b/kernel/watchdog.c
85187@@ -475,7 +475,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
85188 static void watchdog_nmi_disable(unsigned int cpu) { return; }
85189 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
85190
85191-static struct smp_hotplug_thread watchdog_threads = {
85192+static struct smp_hotplug_thread watchdog_threads __read_only = {
85193 .store = &softlockup_watchdog,
85194 .thread_should_run = watchdog_should_run,
85195 .thread_fn = watchdog,
85196diff --git a/kernel/workqueue.c b/kernel/workqueue.c
85197index e93f7b9..989fcd7 100644
85198--- a/kernel/workqueue.c
85199+++ b/kernel/workqueue.c
85200@@ -4627,7 +4627,7 @@ static void rebind_workers(struct worker_pool *pool)
85201 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
85202 worker_flags |= WORKER_REBOUND;
85203 worker_flags &= ~WORKER_UNBOUND;
85204- ACCESS_ONCE(worker->flags) = worker_flags;
85205+ ACCESS_ONCE_RW(worker->flags) = worker_flags;
85206 }
85207
85208 spin_unlock_irq(&pool->lock);
85209diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
85210index 1501aa5..e771896 100644
85211--- a/lib/Kconfig.debug
85212+++ b/lib/Kconfig.debug
85213@@ -836,7 +836,7 @@ config DEBUG_MUTEXES
85214
85215 config DEBUG_WW_MUTEX_SLOWPATH
85216 bool "Wait/wound mutex debugging: Slowpath testing"
85217- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
85218+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
85219 select DEBUG_LOCK_ALLOC
85220 select DEBUG_SPINLOCK
85221 select DEBUG_MUTEXES
85222@@ -849,7 +849,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
85223
85224 config DEBUG_LOCK_ALLOC
85225 bool "Lock debugging: detect incorrect freeing of live locks"
85226- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
85227+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
85228 select DEBUG_SPINLOCK
85229 select DEBUG_MUTEXES
85230 select LOCKDEP
85231@@ -863,7 +863,7 @@ config DEBUG_LOCK_ALLOC
85232
85233 config PROVE_LOCKING
85234 bool "Lock debugging: prove locking correctness"
85235- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
85236+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
85237 select LOCKDEP
85238 select DEBUG_SPINLOCK
85239 select DEBUG_MUTEXES
85240@@ -914,7 +914,7 @@ config LOCKDEP
85241
85242 config LOCK_STAT
85243 bool "Lock usage statistics"
85244- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
85245+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
85246 select LOCKDEP
85247 select DEBUG_SPINLOCK
85248 select DEBUG_MUTEXES
85249@@ -1357,6 +1357,7 @@ config LATENCYTOP
85250 depends on DEBUG_KERNEL
85251 depends on STACKTRACE_SUPPORT
85252 depends on PROC_FS
85253+ depends on !GRKERNSEC_HIDESYM
85254 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
85255 select KALLSYMS
85256 select KALLSYMS_ALL
85257@@ -1373,7 +1374,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
85258 config DEBUG_STRICT_USER_COPY_CHECKS
85259 bool "Strict user copy size checks"
85260 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
85261- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
85262+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
85263 help
85264 Enabling this option turns a certain set of sanity checks for user
85265 copy operations into compile time failures.
85266@@ -1483,7 +1484,7 @@ endmenu # runtime tests
85267
85268 config PROVIDE_OHCI1394_DMA_INIT
85269 bool "Remote debugging over FireWire early on boot"
85270- depends on PCI && X86
85271+ depends on PCI && X86 && !GRKERNSEC
85272 help
85273 If you want to debug problems which hang or crash the kernel early
85274 on boot and the crashing machine has a FireWire port, you can use
85275@@ -1512,7 +1513,7 @@ config PROVIDE_OHCI1394_DMA_INIT
85276
85277 config FIREWIRE_OHCI_REMOTE_DMA
85278 bool "Remote debugging over FireWire with firewire-ohci"
85279- depends on FIREWIRE_OHCI
85280+ depends on FIREWIRE_OHCI && !GRKERNSEC
85281 help
85282 This option lets you use the FireWire bus for remote debugging
85283 with help of the firewire-ohci driver. It enables unfiltered
85284diff --git a/lib/Makefile b/lib/Makefile
85285index 7baccfd..3ceb95f 100644
85286--- a/lib/Makefile
85287+++ b/lib/Makefile
85288@@ -50,7 +50,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
85289
85290 obj-$(CONFIG_BTREE) += btree.o
85291 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
85292-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
85293+obj-y += list_debug.o
85294 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
85295
85296 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
85297diff --git a/lib/bitmap.c b/lib/bitmap.c
85298index 06f7e4f..f3cf2b0 100644
85299--- a/lib/bitmap.c
85300+++ b/lib/bitmap.c
85301@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
85302 {
85303 int c, old_c, totaldigits, ndigits, nchunks, nbits;
85304 u32 chunk;
85305- const char __user __force *ubuf = (const char __user __force *)buf;
85306+ const char __user *ubuf = (const char __force_user *)buf;
85307
85308 bitmap_zero(maskp, nmaskbits);
85309
85310@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
85311 {
85312 if (!access_ok(VERIFY_READ, ubuf, ulen))
85313 return -EFAULT;
85314- return __bitmap_parse((const char __force *)ubuf,
85315+ return __bitmap_parse((const char __force_kernel *)ubuf,
85316 ulen, 1, maskp, nmaskbits);
85317
85318 }
85319@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
85320 {
85321 unsigned a, b;
85322 int c, old_c, totaldigits;
85323- const char __user __force *ubuf = (const char __user __force *)buf;
85324+ const char __user *ubuf = (const char __force_user *)buf;
85325 int exp_digit, in_range;
85326
85327 totaldigits = c = 0;
85328@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
85329 {
85330 if (!access_ok(VERIFY_READ, ubuf, ulen))
85331 return -EFAULT;
85332- return __bitmap_parselist((const char __force *)ubuf,
85333+ return __bitmap_parselist((const char __force_kernel *)ubuf,
85334 ulen, 1, maskp, nmaskbits);
85335 }
85336 EXPORT_SYMBOL(bitmap_parselist_user);
85337diff --git a/lib/bug.c b/lib/bug.c
85338index 1686034..a9c00c8 100644
85339--- a/lib/bug.c
85340+++ b/lib/bug.c
85341@@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
85342 return BUG_TRAP_TYPE_NONE;
85343
85344 bug = find_bug(bugaddr);
85345+ if (!bug)
85346+ return BUG_TRAP_TYPE_NONE;
85347
85348 file = NULL;
85349 line = 0;
85350diff --git a/lib/debugobjects.c b/lib/debugobjects.c
85351index 37061ed..da83f48 100644
85352--- a/lib/debugobjects.c
85353+++ b/lib/debugobjects.c
85354@@ -286,7 +286,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
85355 if (limit > 4)
85356 return;
85357
85358- is_on_stack = object_is_on_stack(addr);
85359+ is_on_stack = object_starts_on_stack(addr);
85360 if (is_on_stack == onstack)
85361 return;
85362
85363diff --git a/lib/devres.c b/lib/devres.c
85364index 8235331..5881053 100644
85365--- a/lib/devres.c
85366+++ b/lib/devres.c
85367@@ -81,7 +81,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
85368 void devm_iounmap(struct device *dev, void __iomem *addr)
85369 {
85370 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
85371- (void *)addr));
85372+ (void __force *)addr));
85373 iounmap(addr);
85374 }
85375 EXPORT_SYMBOL(devm_iounmap);
85376@@ -224,7 +224,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
85377 {
85378 ioport_unmap(addr);
85379 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
85380- devm_ioport_map_match, (void *)addr));
85381+ devm_ioport_map_match, (void __force *)addr));
85382 }
85383 EXPORT_SYMBOL(devm_ioport_unmap);
85384 #endif /* CONFIG_HAS_IOPORT */
85385diff --git a/lib/div64.c b/lib/div64.c
85386index a163b6c..9618fa5 100644
85387--- a/lib/div64.c
85388+++ b/lib/div64.c
85389@@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
85390 EXPORT_SYMBOL(__div64_32);
85391
85392 #ifndef div_s64_rem
85393-s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
85394+s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
85395 {
85396 u64 quotient;
85397
85398@@ -90,7 +90,7 @@ EXPORT_SYMBOL(div_s64_rem);
85399 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
85400 */
85401 #ifndef div64_u64
85402-u64 div64_u64(u64 dividend, u64 divisor)
85403+u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
85404 {
85405 u32 high = divisor >> 32;
85406 u64 quot;
85407diff --git a/lib/dma-debug.c b/lib/dma-debug.c
85408index d87a17a..ac0d79a 100644
85409--- a/lib/dma-debug.c
85410+++ b/lib/dma-debug.c
85411@@ -768,7 +768,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
85412
85413 void dma_debug_add_bus(struct bus_type *bus)
85414 {
85415- struct notifier_block *nb;
85416+ notifier_block_no_const *nb;
85417
85418 if (global_disable)
85419 return;
85420@@ -945,7 +945,7 @@ static void check_unmap(struct dma_debug_entry *ref)
85421
85422 static void check_for_stack(struct device *dev, void *addr)
85423 {
85424- if (object_is_on_stack(addr))
85425+ if (object_starts_on_stack(addr))
85426 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
85427 "stack [addr=%p]\n", addr);
85428 }
85429diff --git a/lib/inflate.c b/lib/inflate.c
85430index 013a761..c28f3fc 100644
85431--- a/lib/inflate.c
85432+++ b/lib/inflate.c
85433@@ -269,7 +269,7 @@ static void free(void *where)
85434 malloc_ptr = free_mem_ptr;
85435 }
85436 #else
85437-#define malloc(a) kmalloc(a, GFP_KERNEL)
85438+#define malloc(a) kmalloc((a), GFP_KERNEL)
85439 #define free(a) kfree(a)
85440 #endif
85441
85442diff --git a/lib/ioremap.c b/lib/ioremap.c
85443index 0c9216c..863bd89 100644
85444--- a/lib/ioremap.c
85445+++ b/lib/ioremap.c
85446@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
85447 unsigned long next;
85448
85449 phys_addr -= addr;
85450- pmd = pmd_alloc(&init_mm, pud, addr);
85451+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
85452 if (!pmd)
85453 return -ENOMEM;
85454 do {
85455@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
85456 unsigned long next;
85457
85458 phys_addr -= addr;
85459- pud = pud_alloc(&init_mm, pgd, addr);
85460+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
85461 if (!pud)
85462 return -ENOMEM;
85463 do {
85464diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
85465index bd2bea9..6b3c95e 100644
85466--- a/lib/is_single_threaded.c
85467+++ b/lib/is_single_threaded.c
85468@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
85469 struct task_struct *p, *t;
85470 bool ret;
85471
85472+ if (!mm)
85473+ return true;
85474+
85475 if (atomic_read(&task->signal->live) != 1)
85476 return false;
85477
85478diff --git a/lib/kobject.c b/lib/kobject.c
85479index 4a1f33d..2f3ca75 100644
85480--- a/lib/kobject.c
85481+++ b/lib/kobject.c
85482@@ -859,9 +859,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
85483
85484
85485 static DEFINE_SPINLOCK(kobj_ns_type_lock);
85486-static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
85487+static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
85488
85489-int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
85490+int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
85491 {
85492 enum kobj_ns_type type = ops->type;
85493 int error;
85494diff --git a/lib/list_debug.c b/lib/list_debug.c
85495index c24c2f7..06e070b 100644
85496--- a/lib/list_debug.c
85497+++ b/lib/list_debug.c
85498@@ -11,7 +11,9 @@
85499 #include <linux/bug.h>
85500 #include <linux/kernel.h>
85501 #include <linux/rculist.h>
85502+#include <linux/mm.h>
85503
85504+#ifdef CONFIG_DEBUG_LIST
85505 /*
85506 * Insert a new entry between two known consecutive entries.
85507 *
85508@@ -19,21 +21,32 @@
85509 * the prev/next entries already!
85510 */
85511
85512-void __list_add(struct list_head *new,
85513- struct list_head *prev,
85514- struct list_head *next)
85515+static bool __list_add_debug(struct list_head *new,
85516+ struct list_head *prev,
85517+ struct list_head *next)
85518 {
85519- WARN(next->prev != prev,
85520+ if (WARN(next->prev != prev,
85521 "list_add corruption. next->prev should be "
85522 "prev (%p), but was %p. (next=%p).\n",
85523- prev, next->prev, next);
85524- WARN(prev->next != next,
85525+ prev, next->prev, next) ||
85526+ WARN(prev->next != next,
85527 "list_add corruption. prev->next should be "
85528 "next (%p), but was %p. (prev=%p).\n",
85529- next, prev->next, prev);
85530- WARN(new == prev || new == next,
85531- "list_add double add: new=%p, prev=%p, next=%p.\n",
85532- new, prev, next);
85533+ next, prev->next, prev) ||
85534+ WARN(new == prev || new == next,
85535+ "list_add double add: new=%p, prev=%p, next=%p.\n",
85536+ new, prev, next))
85537+ return false;
85538+ return true;
85539+}
85540+
85541+void __list_add(struct list_head *new,
85542+ struct list_head *prev,
85543+ struct list_head *next)
85544+{
85545+ if (!__list_add_debug(new, prev, next))
85546+ return;
85547+
85548 next->prev = new;
85549 new->next = next;
85550 new->prev = prev;
85551@@ -41,7 +54,7 @@ void __list_add(struct list_head *new,
85552 }
85553 EXPORT_SYMBOL(__list_add);
85554
85555-void __list_del_entry(struct list_head *entry)
85556+static bool __list_del_entry_debug(struct list_head *entry)
85557 {
85558 struct list_head *prev, *next;
85559
85560@@ -60,9 +73,16 @@ void __list_del_entry(struct list_head *entry)
85561 WARN(next->prev != entry,
85562 "list_del corruption. next->prev should be %p, "
85563 "but was %p\n", entry, next->prev))
85564+ return false;
85565+ return true;
85566+}
85567+
85568+void __list_del_entry(struct list_head *entry)
85569+{
85570+ if (!__list_del_entry_debug(entry))
85571 return;
85572
85573- __list_del(prev, next);
85574+ __list_del(entry->prev, entry->next);
85575 }
85576 EXPORT_SYMBOL(__list_del_entry);
85577
85578@@ -86,15 +106,85 @@ EXPORT_SYMBOL(list_del);
85579 void __list_add_rcu(struct list_head *new,
85580 struct list_head *prev, struct list_head *next)
85581 {
85582- WARN(next->prev != prev,
85583- "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
85584- prev, next->prev, next);
85585- WARN(prev->next != next,
85586- "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
85587- next, prev->next, prev);
85588+ if (!__list_add_debug(new, prev, next))
85589+ return;
85590+
85591 new->next = next;
85592 new->prev = prev;
85593 rcu_assign_pointer(list_next_rcu(prev), new);
85594 next->prev = new;
85595 }
85596 EXPORT_SYMBOL(__list_add_rcu);
85597+#endif
85598+
85599+void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
85600+{
85601+#ifdef CONFIG_DEBUG_LIST
85602+ if (!__list_add_debug(new, prev, next))
85603+ return;
85604+#endif
85605+
85606+ pax_open_kernel();
85607+ next->prev = new;
85608+ new->next = next;
85609+ new->prev = prev;
85610+ prev->next = new;
85611+ pax_close_kernel();
85612+}
85613+EXPORT_SYMBOL(__pax_list_add);
85614+
85615+void pax_list_del(struct list_head *entry)
85616+{
85617+#ifdef CONFIG_DEBUG_LIST
85618+ if (!__list_del_entry_debug(entry))
85619+ return;
85620+#endif
85621+
85622+ pax_open_kernel();
85623+ __list_del(entry->prev, entry->next);
85624+ entry->next = LIST_POISON1;
85625+ entry->prev = LIST_POISON2;
85626+ pax_close_kernel();
85627+}
85628+EXPORT_SYMBOL(pax_list_del);
85629+
85630+void pax_list_del_init(struct list_head *entry)
85631+{
85632+ pax_open_kernel();
85633+ __list_del(entry->prev, entry->next);
85634+ INIT_LIST_HEAD(entry);
85635+ pax_close_kernel();
85636+}
85637+EXPORT_SYMBOL(pax_list_del_init);
85638+
85639+void __pax_list_add_rcu(struct list_head *new,
85640+ struct list_head *prev, struct list_head *next)
85641+{
85642+#ifdef CONFIG_DEBUG_LIST
85643+ if (!__list_add_debug(new, prev, next))
85644+ return;
85645+#endif
85646+
85647+ pax_open_kernel();
85648+ new->next = next;
85649+ new->prev = prev;
85650+ rcu_assign_pointer(list_next_rcu(prev), new);
85651+ next->prev = new;
85652+ pax_close_kernel();
85653+}
85654+EXPORT_SYMBOL(__pax_list_add_rcu);
85655+
85656+void pax_list_del_rcu(struct list_head *entry)
85657+{
85658+#ifdef CONFIG_DEBUG_LIST
85659+ if (!__list_del_entry_debug(entry))
85660+ return;
85661+#endif
85662+
85663+ pax_open_kernel();
85664+ __list_del(entry->prev, entry->next);
85665+ entry->next = LIST_POISON1;
85666+ entry->prev = LIST_POISON2;
85667+ pax_close_kernel();
85668+}
85669+EXPORT_SYMBOL(pax_list_del_rcu);
85670diff --git a/lib/radix-tree.c b/lib/radix-tree.c
85671index e796429..6e38f9f 100644
85672--- a/lib/radix-tree.c
85673+++ b/lib/radix-tree.c
85674@@ -92,7 +92,7 @@ struct radix_tree_preload {
85675 int nr;
85676 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
85677 };
85678-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
85679+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
85680
85681 static inline void *ptr_to_indirect(void *ptr)
85682 {
85683diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
85684index bb2b201..46abaf9 100644
85685--- a/lib/strncpy_from_user.c
85686+++ b/lib/strncpy_from_user.c
85687@@ -21,7 +21,7 @@
85688 */
85689 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
85690 {
85691- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
85692+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
85693 long res = 0;
85694
85695 /*
85696diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
85697index a28df52..3d55877 100644
85698--- a/lib/strnlen_user.c
85699+++ b/lib/strnlen_user.c
85700@@ -26,7 +26,7 @@
85701 */
85702 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
85703 {
85704- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
85705+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
85706 long align, res = 0;
85707 unsigned long c;
85708
85709diff --git a/lib/swiotlb.c b/lib/swiotlb.c
85710index d23762e..e21eab2 100644
85711--- a/lib/swiotlb.c
85712+++ b/lib/swiotlb.c
85713@@ -664,7 +664,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
85714
85715 void
85716 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
85717- dma_addr_t dev_addr)
85718+ dma_addr_t dev_addr, struct dma_attrs *attrs)
85719 {
85720 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
85721
85722diff --git a/lib/usercopy.c b/lib/usercopy.c
85723index 4f5b1dd..7cab418 100644
85724--- a/lib/usercopy.c
85725+++ b/lib/usercopy.c
85726@@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
85727 WARN(1, "Buffer overflow detected!\n");
85728 }
85729 EXPORT_SYMBOL(copy_from_user_overflow);
85730+
85731+void copy_to_user_overflow(void)
85732+{
85733+ WARN(1, "Buffer overflow detected!\n");
85734+}
85735+EXPORT_SYMBOL(copy_to_user_overflow);
85736diff --git a/lib/vsprintf.c b/lib/vsprintf.c
85737index 739a363..aa668d7 100644
85738--- a/lib/vsprintf.c
85739+++ b/lib/vsprintf.c
85740@@ -16,6 +16,9 @@
85741 * - scnprintf and vscnprintf
85742 */
85743
85744+#ifdef CONFIG_GRKERNSEC_HIDESYM
85745+#define __INCLUDED_BY_HIDESYM 1
85746+#endif
85747 #include <stdarg.h>
85748 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
85749 #include <linux/types.h>
85750@@ -1078,7 +1081,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
85751 return number(buf, end, *(const netdev_features_t *)addr, spec);
85752 }
85753
85754+#ifdef CONFIG_GRKERNSEC_HIDESYM
85755+int kptr_restrict __read_mostly = 2;
85756+#else
85757 int kptr_restrict __read_mostly;
85758+#endif
85759
85760 /*
85761 * Show a '%p' thing. A kernel extension is that the '%p' is followed
85762@@ -1091,6 +1098,7 @@ int kptr_restrict __read_mostly;
85763 * - 'f' For simple symbolic function names without offset
85764 * - 'S' For symbolic direct pointers with offset
85765 * - 's' For symbolic direct pointers without offset
85766+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
85767 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
85768 * - 'B' For backtraced symbolic direct pointers with offset
85769 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
85770@@ -1155,12 +1163,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
85771
85772 if (!ptr && *fmt != 'K') {
85773 /*
85774- * Print (null) with the same width as a pointer so it makes
85775+ * Print (nil) with the same width as a pointer so it makes
85776 * tabular output look nice.
85777 */
85778 if (spec.field_width == -1)
85779 spec.field_width = default_width;
85780- return string(buf, end, "(null)", spec);
85781+ return string(buf, end, "(nil)", spec);
85782 }
85783
85784 switch (*fmt) {
85785@@ -1170,6 +1178,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
85786 /* Fallthrough */
85787 case 'S':
85788 case 's':
85789+#ifdef CONFIG_GRKERNSEC_HIDESYM
85790+ break;
85791+#else
85792+ return symbol_string(buf, end, ptr, spec, fmt);
85793+#endif
85794+ case 'A':
85795 case 'B':
85796 return symbol_string(buf, end, ptr, spec, fmt);
85797 case 'R':
85798@@ -1225,6 +1239,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
85799 va_end(va);
85800 return buf;
85801 }
85802+ case 'P':
85803+ break;
85804 case 'K':
85805 /*
85806 * %pK cannot be used in IRQ context because its test
85807@@ -1254,6 +1270,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
85808 return number(buf, end,
85809 (unsigned long long) *((phys_addr_t *)ptr), spec);
85810 }
85811+
85812+#ifdef CONFIG_GRKERNSEC_HIDESYM
85813+ /* 'P' = approved pointers to copy to userland,
85814+ as in the /proc/kallsyms case, as we make it display nothing
85815+ for non-root users, and the real contents for root users
85816+ Also ignore 'K' pointers, since we force their NULLing for non-root users
85817+ above
85818+ */
85819+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
85820+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
85821+ dump_stack();
85822+ ptr = NULL;
85823+ }
85824+#endif
85825+
85826 spec.flags |= SMALL;
85827 if (spec.field_width == -1) {
85828 spec.field_width = default_width;
85829@@ -1977,11 +2008,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
85830 typeof(type) value; \
85831 if (sizeof(type) == 8) { \
85832 args = PTR_ALIGN(args, sizeof(u32)); \
85833- *(u32 *)&value = *(u32 *)args; \
85834- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
85835+ *(u32 *)&value = *(const u32 *)args; \
85836+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
85837 } else { \
85838 args = PTR_ALIGN(args, sizeof(type)); \
85839- value = *(typeof(type) *)args; \
85840+ value = *(const typeof(type) *)args; \
85841 } \
85842 args += sizeof(type); \
85843 value; \
85844@@ -2044,7 +2075,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
85845 case FORMAT_TYPE_STR: {
85846 const char *str_arg = args;
85847 args += strlen(str_arg) + 1;
85848- str = string(str, end, (char *)str_arg, spec);
85849+ str = string(str, end, str_arg, spec);
85850 break;
85851 }
85852
85853diff --git a/localversion-grsec b/localversion-grsec
85854new file mode 100644
85855index 0000000..7cd6065
85856--- /dev/null
85857+++ b/localversion-grsec
85858@@ -0,0 +1 @@
85859+-grsec
85860diff --git a/mm/Kconfig b/mm/Kconfig
85861index 8028dcc..9a2dbe7 100644
85862--- a/mm/Kconfig
85863+++ b/mm/Kconfig
85864@@ -317,10 +317,10 @@ config KSM
85865 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
85866
85867 config DEFAULT_MMAP_MIN_ADDR
85868- int "Low address space to protect from user allocation"
85869+ int "Low address space to protect from user allocation"
85870 depends on MMU
85871- default 4096
85872- help
85873+ default 65536
85874+ help
85875 This is the portion of low virtual memory which should be protected
85876 from userspace allocation. Keeping a user from writing to low pages
85877 can help reduce the impact of kernel NULL pointer bugs.
85878@@ -351,7 +351,7 @@ config MEMORY_FAILURE
85879
85880 config HWPOISON_INJECT
85881 tristate "HWPoison pages injector"
85882- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
85883+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
85884 select PROC_PAGE_MONITOR
85885
85886 config NOMMU_INITIAL_TRIM_EXCESS
85887diff --git a/mm/backing-dev.c b/mm/backing-dev.c
85888index e04454c..ca5be3e 100644
85889--- a/mm/backing-dev.c
85890+++ b/mm/backing-dev.c
85891@@ -12,7 +12,7 @@
85892 #include <linux/device.h>
85893 #include <trace/events/writeback.h>
85894
85895-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
85896+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
85897
85898 struct backing_dev_info default_backing_dev_info = {
85899 .name = "default",
85900@@ -522,7 +522,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
85901 return err;
85902
85903 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
85904- atomic_long_inc_return(&bdi_seq));
85905+ atomic_long_inc_return_unchecked(&bdi_seq));
85906 if (err) {
85907 bdi_destroy(bdi);
85908 return err;
85909diff --git a/mm/filemap.c b/mm/filemap.c
85910index 4b51ac1..5aa90ff 100644
85911--- a/mm/filemap.c
85912+++ b/mm/filemap.c
85913@@ -1766,7 +1766,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
85914 struct address_space *mapping = file->f_mapping;
85915
85916 if (!mapping->a_ops->readpage)
85917- return -ENOEXEC;
85918+ return -ENODEV;
85919 file_accessed(file);
85920 vma->vm_ops = &generic_file_vm_ops;
85921 return 0;
85922@@ -1948,7 +1948,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
85923
85924 while (bytes) {
85925 char __user *buf = iov->iov_base + base;
85926- int copy = min(bytes, iov->iov_len - base);
85927+ size_t copy = min(bytes, iov->iov_len - base);
85928
85929 base = 0;
85930 left = __copy_from_user_inatomic(vaddr, buf, copy);
85931@@ -1977,7 +1977,7 @@ size_t iov_iter_copy_from_user_atomic(struct page *page,
85932 BUG_ON(!in_atomic());
85933 kaddr = kmap_atomic(page);
85934 if (likely(i->nr_segs == 1)) {
85935- int left;
85936+ size_t left;
85937 char __user *buf = i->iov->iov_base + i->iov_offset;
85938 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
85939 copied = bytes - left;
85940@@ -2005,7 +2005,7 @@ size_t iov_iter_copy_from_user(struct page *page,
85941
85942 kaddr = kmap(page);
85943 if (likely(i->nr_segs == 1)) {
85944- int left;
85945+ size_t left;
85946 char __user *buf = i->iov->iov_base + i->iov_offset;
85947 left = __copy_from_user(kaddr + offset, buf, bytes);
85948 copied = bytes - left;
85949@@ -2035,7 +2035,7 @@ void iov_iter_advance(struct iov_iter *i, size_t bytes)
85950 * zero-length segments (without overruning the iovec).
85951 */
85952 while (bytes || unlikely(i->count && !iov->iov_len)) {
85953- int copy;
85954+ size_t copy;
85955
85956 copy = min(bytes, iov->iov_len - base);
85957 BUG_ON(!i->count || i->count < copy);
85958@@ -2106,6 +2106,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
85959 *pos = i_size_read(inode);
85960
85961 if (limit != RLIM_INFINITY) {
85962+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
85963 if (*pos >= limit) {
85964 send_sig(SIGXFSZ, current, 0);
85965 return -EFBIG;
85966diff --git a/mm/fremap.c b/mm/fremap.c
85967index 5bff081..d8189a9 100644
85968--- a/mm/fremap.c
85969+++ b/mm/fremap.c
85970@@ -163,6 +163,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
85971 retry:
85972 vma = find_vma(mm, start);
85973
85974+#ifdef CONFIG_PAX_SEGMEXEC
85975+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
85976+ goto out;
85977+#endif
85978+
85979 /*
85980 * Make sure the vma is shared, that it supports prefaulting,
85981 * and that the remapped range is valid and fully within
85982diff --git a/mm/highmem.c b/mm/highmem.c
85983index b32b70c..e512eb0 100644
85984--- a/mm/highmem.c
85985+++ b/mm/highmem.c
85986@@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
85987 * So no dangers, even with speculative execution.
85988 */
85989 page = pte_page(pkmap_page_table[i]);
85990+ pax_open_kernel();
85991 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
85992-
85993+ pax_close_kernel();
85994 set_page_address(page, NULL);
85995 need_flush = 1;
85996 }
85997@@ -198,9 +199,11 @@ start:
85998 }
85999 }
86000 vaddr = PKMAP_ADDR(last_pkmap_nr);
86001+
86002+ pax_open_kernel();
86003 set_pte_at(&init_mm, vaddr,
86004 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
86005-
86006+ pax_close_kernel();
86007 pkmap_count[last_pkmap_nr] = 1;
86008 set_page_address(page, (void *)vaddr);
86009
86010diff --git a/mm/hugetlb.c b/mm/hugetlb.c
86011index b60f330..ee7de7e 100644
86012--- a/mm/hugetlb.c
86013+++ b/mm/hugetlb.c
86014@@ -2022,15 +2022,17 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
86015 struct hstate *h = &default_hstate;
86016 unsigned long tmp;
86017 int ret;
86018+ ctl_table_no_const hugetlb_table;
86019
86020 tmp = h->max_huge_pages;
86021
86022 if (write && h->order >= MAX_ORDER)
86023 return -EINVAL;
86024
86025- table->data = &tmp;
86026- table->maxlen = sizeof(unsigned long);
86027- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
86028+ hugetlb_table = *table;
86029+ hugetlb_table.data = &tmp;
86030+ hugetlb_table.maxlen = sizeof(unsigned long);
86031+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
86032 if (ret)
86033 goto out;
86034
86035@@ -2087,15 +2089,17 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
86036 struct hstate *h = &default_hstate;
86037 unsigned long tmp;
86038 int ret;
86039+ ctl_table_no_const hugetlb_table;
86040
86041 tmp = h->nr_overcommit_huge_pages;
86042
86043 if (write && h->order >= MAX_ORDER)
86044 return -EINVAL;
86045
86046- table->data = &tmp;
86047- table->maxlen = sizeof(unsigned long);
86048- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
86049+ hugetlb_table = *table;
86050+ hugetlb_table.data = &tmp;
86051+ hugetlb_table.maxlen = sizeof(unsigned long);
86052+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
86053 if (ret)
86054 goto out;
86055
86056@@ -2545,6 +2549,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
86057 return 1;
86058 }
86059
86060+#ifdef CONFIG_PAX_SEGMEXEC
86061+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
86062+{
86063+ struct mm_struct *mm = vma->vm_mm;
86064+ struct vm_area_struct *vma_m;
86065+ unsigned long address_m;
86066+ pte_t *ptep_m;
86067+
86068+ vma_m = pax_find_mirror_vma(vma);
86069+ if (!vma_m)
86070+ return;
86071+
86072+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
86073+ address_m = address + SEGMEXEC_TASK_SIZE;
86074+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
86075+ get_page(page_m);
86076+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
86077+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
86078+}
86079+#endif
86080+
86081 /*
86082 * Hugetlb_cow() should be called with page lock of the original hugepage held.
86083 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
86084@@ -2663,6 +2688,11 @@ retry_avoidcopy:
86085 make_huge_pte(vma, new_page, 1));
86086 page_remove_rmap(old_page);
86087 hugepage_add_new_anon_rmap(new_page, vma, address);
86088+
86089+#ifdef CONFIG_PAX_SEGMEXEC
86090+ pax_mirror_huge_pte(vma, address, new_page);
86091+#endif
86092+
86093 /* Make the old page be freed below */
86094 new_page = old_page;
86095 }
86096@@ -2821,6 +2851,10 @@ retry:
86097 && (vma->vm_flags & VM_SHARED)));
86098 set_huge_pte_at(mm, address, ptep, new_pte);
86099
86100+#ifdef CONFIG_PAX_SEGMEXEC
86101+ pax_mirror_huge_pte(vma, address, page);
86102+#endif
86103+
86104 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
86105 /* Optimization, do the COW without a second fault */
86106 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
86107@@ -2850,6 +2884,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
86108 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
86109 struct hstate *h = hstate_vma(vma);
86110
86111+#ifdef CONFIG_PAX_SEGMEXEC
86112+ struct vm_area_struct *vma_m;
86113+#endif
86114+
86115 address &= huge_page_mask(h);
86116
86117 ptep = huge_pte_offset(mm, address);
86118@@ -2863,6 +2901,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
86119 VM_FAULT_SET_HINDEX(hstate_index(h));
86120 }
86121
86122+#ifdef CONFIG_PAX_SEGMEXEC
86123+ vma_m = pax_find_mirror_vma(vma);
86124+ if (vma_m) {
86125+ unsigned long address_m;
86126+
86127+ if (vma->vm_start > vma_m->vm_start) {
86128+ address_m = address;
86129+ address -= SEGMEXEC_TASK_SIZE;
86130+ vma = vma_m;
86131+ h = hstate_vma(vma);
86132+ } else
86133+ address_m = address + SEGMEXEC_TASK_SIZE;
86134+
86135+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
86136+ return VM_FAULT_OOM;
86137+ address_m &= HPAGE_MASK;
86138+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
86139+ }
86140+#endif
86141+
86142 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
86143 if (!ptep)
86144 return VM_FAULT_OOM;
86145diff --git a/mm/internal.h b/mm/internal.h
86146index 4390ac6..fc60373c 100644
86147--- a/mm/internal.h
86148+++ b/mm/internal.h
86149@@ -95,6 +95,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
86150 * in mm/page_alloc.c
86151 */
86152 extern void __free_pages_bootmem(struct page *page, unsigned int order);
86153+extern void free_compound_page(struct page *page);
86154 extern void prep_compound_page(struct page *page, unsigned long order);
86155 #ifdef CONFIG_MEMORY_FAILURE
86156 extern bool is_free_buddy_page(struct page *page);
86157@@ -350,7 +351,7 @@ extern u32 hwpoison_filter_enable;
86158
86159 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
86160 unsigned long, unsigned long,
86161- unsigned long, unsigned long);
86162+ unsigned long, unsigned long) __intentional_overflow(-1);
86163
86164 extern void set_pageblock_order(void);
86165 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
86166diff --git a/mm/kmemleak.c b/mm/kmemleak.c
86167index c8d7f31..2dbeffd 100644
86168--- a/mm/kmemleak.c
86169+++ b/mm/kmemleak.c
86170@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
86171
86172 for (i = 0; i < object->trace_len; i++) {
86173 void *ptr = (void *)object->trace[i];
86174- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
86175+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
86176 }
86177 }
86178
86179@@ -1851,7 +1851,7 @@ static int __init kmemleak_late_init(void)
86180 return -ENOMEM;
86181 }
86182
86183- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
86184+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
86185 &kmemleak_fops);
86186 if (!dentry)
86187 pr_warning("Failed to create the debugfs kmemleak file\n");
86188diff --git a/mm/maccess.c b/mm/maccess.c
86189index d53adf9..03a24bf 100644
86190--- a/mm/maccess.c
86191+++ b/mm/maccess.c
86192@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
86193 set_fs(KERNEL_DS);
86194 pagefault_disable();
86195 ret = __copy_from_user_inatomic(dst,
86196- (__force const void __user *)src, size);
86197+ (const void __force_user *)src, size);
86198 pagefault_enable();
86199 set_fs(old_fs);
86200
86201@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
86202
86203 set_fs(KERNEL_DS);
86204 pagefault_disable();
86205- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
86206+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
86207 pagefault_enable();
86208 set_fs(old_fs);
86209
86210diff --git a/mm/madvise.c b/mm/madvise.c
86211index 7055883..aafb1ed 100644
86212--- a/mm/madvise.c
86213+++ b/mm/madvise.c
86214@@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
86215 pgoff_t pgoff;
86216 unsigned long new_flags = vma->vm_flags;
86217
86218+#ifdef CONFIG_PAX_SEGMEXEC
86219+ struct vm_area_struct *vma_m;
86220+#endif
86221+
86222 switch (behavior) {
86223 case MADV_NORMAL:
86224 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
86225@@ -126,6 +130,13 @@ success:
86226 /*
86227 * vm_flags is protected by the mmap_sem held in write mode.
86228 */
86229+
86230+#ifdef CONFIG_PAX_SEGMEXEC
86231+ vma_m = pax_find_mirror_vma(vma);
86232+ if (vma_m)
86233+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
86234+#endif
86235+
86236 vma->vm_flags = new_flags;
86237
86238 out:
86239@@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
86240 struct vm_area_struct ** prev,
86241 unsigned long start, unsigned long end)
86242 {
86243+
86244+#ifdef CONFIG_PAX_SEGMEXEC
86245+ struct vm_area_struct *vma_m;
86246+#endif
86247+
86248 *prev = vma;
86249 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
86250 return -EINVAL;
86251@@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
86252 zap_page_range(vma, start, end - start, &details);
86253 } else
86254 zap_page_range(vma, start, end - start, NULL);
86255+
86256+#ifdef CONFIG_PAX_SEGMEXEC
86257+ vma_m = pax_find_mirror_vma(vma);
86258+ if (vma_m) {
86259+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
86260+ struct zap_details details = {
86261+ .nonlinear_vma = vma_m,
86262+ .last_index = ULONG_MAX,
86263+ };
86264+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
86265+ } else
86266+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
86267+ }
86268+#endif
86269+
86270 return 0;
86271 }
86272
86273@@ -485,6 +516,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
86274 if (end < start)
86275 return error;
86276
86277+#ifdef CONFIG_PAX_SEGMEXEC
86278+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
86279+ if (end > SEGMEXEC_TASK_SIZE)
86280+ return error;
86281+ } else
86282+#endif
86283+
86284+ if (end > TASK_SIZE)
86285+ return error;
86286+
86287 error = 0;
86288 if (end == start)
86289 return error;
86290diff --git a/mm/memory-failure.c b/mm/memory-failure.c
86291index 2c13aa7..64cbc3f 100644
86292--- a/mm/memory-failure.c
86293+++ b/mm/memory-failure.c
86294@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
86295
86296 int sysctl_memory_failure_recovery __read_mostly = 1;
86297
86298-atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
86299+atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
86300
86301 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
86302
86303@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
86304 pfn, t->comm, t->pid);
86305 si.si_signo = SIGBUS;
86306 si.si_errno = 0;
86307- si.si_addr = (void *)addr;
86308+ si.si_addr = (void __user *)addr;
86309 #ifdef __ARCH_SI_TRAPNO
86310 si.si_trapno = trapno;
86311 #endif
86312@@ -760,7 +760,7 @@ static struct page_state {
86313 unsigned long res;
86314 char *msg;
86315 int (*action)(struct page *p, unsigned long pfn);
86316-} error_states[] = {
86317+} __do_const error_states[] = {
86318 { reserved, reserved, "reserved kernel", me_kernel },
86319 /*
86320 * free pages are specially detected outside this table:
86321@@ -1051,7 +1051,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
86322 nr_pages = 1 << compound_order(hpage);
86323 else /* normal page or thp */
86324 nr_pages = 1;
86325- atomic_long_add(nr_pages, &num_poisoned_pages);
86326+ atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
86327
86328 /*
86329 * We need/can do nothing about count=0 pages.
86330@@ -1081,7 +1081,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
86331 if (!PageHWPoison(hpage)
86332 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
86333 || (p != hpage && TestSetPageHWPoison(hpage))) {
86334- atomic_long_sub(nr_pages, &num_poisoned_pages);
86335+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
86336 return 0;
86337 }
86338 set_page_hwpoison_huge_page(hpage);
86339@@ -1148,7 +1148,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
86340 }
86341 if (hwpoison_filter(p)) {
86342 if (TestClearPageHWPoison(p))
86343- atomic_long_sub(nr_pages, &num_poisoned_pages);
86344+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
86345 unlock_page(hpage);
86346 put_page(hpage);
86347 return 0;
86348@@ -1350,7 +1350,7 @@ int unpoison_memory(unsigned long pfn)
86349 return 0;
86350 }
86351 if (TestClearPageHWPoison(p))
86352- atomic_long_sub(nr_pages, &num_poisoned_pages);
86353+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
86354 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
86355 return 0;
86356 }
86357@@ -1364,7 +1364,7 @@ int unpoison_memory(unsigned long pfn)
86358 */
86359 if (TestClearPageHWPoison(page)) {
86360 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
86361- atomic_long_sub(nr_pages, &num_poisoned_pages);
86362+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
86363 freeit = 1;
86364 if (PageHuge(page))
86365 clear_page_hwpoison_huge_page(page);
86366@@ -1491,7 +1491,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
86367 } else {
86368 set_page_hwpoison_huge_page(hpage);
86369 dequeue_hwpoisoned_huge_page(hpage);
86370- atomic_long_add(1 << compound_trans_order(hpage),
86371+ atomic_long_add_unchecked(1 << compound_trans_order(hpage),
86372 &num_poisoned_pages);
86373 }
86374 return ret;
86375@@ -1551,11 +1551,11 @@ int soft_offline_page(struct page *page, int flags)
86376 if (PageHuge(page)) {
86377 set_page_hwpoison_huge_page(hpage);
86378 dequeue_hwpoisoned_huge_page(hpage);
86379- atomic_long_add(1 << compound_trans_order(hpage),
86380+ atomic_long_add_unchecked(1 << compound_trans_order(hpage),
86381 &num_poisoned_pages);
86382 } else {
86383 SetPageHWPoison(page);
86384- atomic_long_inc(&num_poisoned_pages);
86385+ atomic_long_inc_unchecked(&num_poisoned_pages);
86386 }
86387 }
86388 unset_migratetype_isolate(page, MIGRATE_MOVABLE);
86389@@ -1595,7 +1595,7 @@ static int __soft_offline_page(struct page *page, int flags)
86390 put_page(page);
86391 pr_info("soft_offline: %#lx: invalidated\n", pfn);
86392 SetPageHWPoison(page);
86393- atomic_long_inc(&num_poisoned_pages);
86394+ atomic_long_inc_unchecked(&num_poisoned_pages);
86395 return 0;
86396 }
86397
86398@@ -1640,7 +1640,7 @@ static int __soft_offline_page(struct page *page, int flags)
86399 if (!is_free_buddy_page(page))
86400 pr_info("soft offline: %#lx: page leaked\n",
86401 pfn);
86402- atomic_long_inc(&num_poisoned_pages);
86403+ atomic_long_inc_unchecked(&num_poisoned_pages);
86404 }
86405 } else {
86406 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
86407diff --git a/mm/memory.c b/mm/memory.c
86408index af84bc0..2ed0816 100644
86409--- a/mm/memory.c
86410+++ b/mm/memory.c
86411@@ -426,6 +426,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
86412 free_pte_range(tlb, pmd, addr);
86413 } while (pmd++, addr = next, addr != end);
86414
86415+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
86416 start &= PUD_MASK;
86417 if (start < floor)
86418 return;
86419@@ -440,6 +441,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
86420 pmd = pmd_offset(pud, start);
86421 pud_clear(pud);
86422 pmd_free_tlb(tlb, pmd, start);
86423+#endif
86424+
86425 }
86426
86427 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
86428@@ -459,6 +462,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
86429 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
86430 } while (pud++, addr = next, addr != end);
86431
86432+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
86433 start &= PGDIR_MASK;
86434 if (start < floor)
86435 return;
86436@@ -473,6 +477,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
86437 pud = pud_offset(pgd, start);
86438 pgd_clear(pgd);
86439 pud_free_tlb(tlb, pud, start);
86440+#endif
86441+
86442 }
86443
86444 /*
86445@@ -1645,12 +1651,6 @@ no_page_table:
86446 return page;
86447 }
86448
86449-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
86450-{
86451- return stack_guard_page_start(vma, addr) ||
86452- stack_guard_page_end(vma, addr+PAGE_SIZE);
86453-}
86454-
86455 /**
86456 * __get_user_pages() - pin user pages in memory
86457 * @tsk: task_struct of target task
86458@@ -1737,10 +1737,10 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
86459
86460 i = 0;
86461
86462- do {
86463+ while (nr_pages) {
86464 struct vm_area_struct *vma;
86465
86466- vma = find_extend_vma(mm, start);
86467+ vma = find_vma(mm, start);
86468 if (!vma && in_gate_area(mm, start)) {
86469 unsigned long pg = start & PAGE_MASK;
86470 pgd_t *pgd;
86471@@ -1789,7 +1789,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
86472 goto next_page;
86473 }
86474
86475- if (!vma ||
86476+ if (!vma || start < vma->vm_start ||
86477 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
86478 !(vm_flags & vma->vm_flags))
86479 return i ? : -EFAULT;
86480@@ -1818,11 +1818,6 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
86481 int ret;
86482 unsigned int fault_flags = 0;
86483
86484- /* For mlock, just skip the stack guard page. */
86485- if (foll_flags & FOLL_MLOCK) {
86486- if (stack_guard_page(vma, start))
86487- goto next_page;
86488- }
86489 if (foll_flags & FOLL_WRITE)
86490 fault_flags |= FAULT_FLAG_WRITE;
86491 if (nonblocking)
86492@@ -1902,7 +1897,7 @@ next_page:
86493 start += page_increm * PAGE_SIZE;
86494 nr_pages -= page_increm;
86495 } while (nr_pages && start < vma->vm_end);
86496- } while (nr_pages);
86497+ }
86498 return i;
86499 }
86500 EXPORT_SYMBOL(__get_user_pages);
86501@@ -2109,6 +2104,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
86502 page_add_file_rmap(page);
86503 set_pte_at(mm, addr, pte, mk_pte(page, prot));
86504
86505+#ifdef CONFIG_PAX_SEGMEXEC
86506+ pax_mirror_file_pte(vma, addr, page, ptl);
86507+#endif
86508+
86509 retval = 0;
86510 pte_unmap_unlock(pte, ptl);
86511 return retval;
86512@@ -2153,9 +2152,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
86513 if (!page_count(page))
86514 return -EINVAL;
86515 if (!(vma->vm_flags & VM_MIXEDMAP)) {
86516+
86517+#ifdef CONFIG_PAX_SEGMEXEC
86518+ struct vm_area_struct *vma_m;
86519+#endif
86520+
86521 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
86522 BUG_ON(vma->vm_flags & VM_PFNMAP);
86523 vma->vm_flags |= VM_MIXEDMAP;
86524+
86525+#ifdef CONFIG_PAX_SEGMEXEC
86526+ vma_m = pax_find_mirror_vma(vma);
86527+ if (vma_m)
86528+ vma_m->vm_flags |= VM_MIXEDMAP;
86529+#endif
86530+
86531 }
86532 return insert_page(vma, addr, page, vma->vm_page_prot);
86533 }
86534@@ -2238,6 +2249,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
86535 unsigned long pfn)
86536 {
86537 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
86538+ BUG_ON(vma->vm_mirror);
86539
86540 if (addr < vma->vm_start || addr >= vma->vm_end)
86541 return -EFAULT;
86542@@ -2485,7 +2497,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
86543
86544 BUG_ON(pud_huge(*pud));
86545
86546- pmd = pmd_alloc(mm, pud, addr);
86547+ pmd = (mm == &init_mm) ?
86548+ pmd_alloc_kernel(mm, pud, addr) :
86549+ pmd_alloc(mm, pud, addr);
86550 if (!pmd)
86551 return -ENOMEM;
86552 do {
86553@@ -2505,7 +2519,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
86554 unsigned long next;
86555 int err;
86556
86557- pud = pud_alloc(mm, pgd, addr);
86558+ pud = (mm == &init_mm) ?
86559+ pud_alloc_kernel(mm, pgd, addr) :
86560+ pud_alloc(mm, pgd, addr);
86561 if (!pud)
86562 return -ENOMEM;
86563 do {
86564@@ -2593,6 +2609,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
86565 copy_user_highpage(dst, src, va, vma);
86566 }
86567
86568+#ifdef CONFIG_PAX_SEGMEXEC
86569+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
86570+{
86571+ struct mm_struct *mm = vma->vm_mm;
86572+ spinlock_t *ptl;
86573+ pte_t *pte, entry;
86574+
86575+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
86576+ entry = *pte;
86577+ if (!pte_present(entry)) {
86578+ if (!pte_none(entry)) {
86579+ BUG_ON(pte_file(entry));
86580+ free_swap_and_cache(pte_to_swp_entry(entry));
86581+ pte_clear_not_present_full(mm, address, pte, 0);
86582+ }
86583+ } else {
86584+ struct page *page;
86585+
86586+ flush_cache_page(vma, address, pte_pfn(entry));
86587+ entry = ptep_clear_flush(vma, address, pte);
86588+ BUG_ON(pte_dirty(entry));
86589+ page = vm_normal_page(vma, address, entry);
86590+ if (page) {
86591+ update_hiwater_rss(mm);
86592+ if (PageAnon(page))
86593+ dec_mm_counter_fast(mm, MM_ANONPAGES);
86594+ else
86595+ dec_mm_counter_fast(mm, MM_FILEPAGES);
86596+ page_remove_rmap(page);
86597+ page_cache_release(page);
86598+ }
86599+ }
86600+ pte_unmap_unlock(pte, ptl);
86601+}
86602+
86603+/* PaX: if vma is mirrored, synchronize the mirror's PTE
86604+ *
86605+ * the ptl of the lower mapped page is held on entry and is not released on exit
86606+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
86607+ */
86608+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
86609+{
86610+ struct mm_struct *mm = vma->vm_mm;
86611+ unsigned long address_m;
86612+ spinlock_t *ptl_m;
86613+ struct vm_area_struct *vma_m;
86614+ pmd_t *pmd_m;
86615+ pte_t *pte_m, entry_m;
86616+
86617+ BUG_ON(!page_m || !PageAnon(page_m));
86618+
86619+ vma_m = pax_find_mirror_vma(vma);
86620+ if (!vma_m)
86621+ return;
86622+
86623+ BUG_ON(!PageLocked(page_m));
86624+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
86625+ address_m = address + SEGMEXEC_TASK_SIZE;
86626+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
86627+ pte_m = pte_offset_map(pmd_m, address_m);
86628+ ptl_m = pte_lockptr(mm, pmd_m);
86629+ if (ptl != ptl_m) {
86630+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
86631+ if (!pte_none(*pte_m))
86632+ goto out;
86633+ }
86634+
86635+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
86636+ page_cache_get(page_m);
86637+ page_add_anon_rmap(page_m, vma_m, address_m);
86638+ inc_mm_counter_fast(mm, MM_ANONPAGES);
86639+ set_pte_at(mm, address_m, pte_m, entry_m);
86640+ update_mmu_cache(vma_m, address_m, pte_m);
86641+out:
86642+ if (ptl != ptl_m)
86643+ spin_unlock(ptl_m);
86644+ pte_unmap(pte_m);
86645+ unlock_page(page_m);
86646+}
86647+
86648+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
86649+{
86650+ struct mm_struct *mm = vma->vm_mm;
86651+ unsigned long address_m;
86652+ spinlock_t *ptl_m;
86653+ struct vm_area_struct *vma_m;
86654+ pmd_t *pmd_m;
86655+ pte_t *pte_m, entry_m;
86656+
86657+ BUG_ON(!page_m || PageAnon(page_m));
86658+
86659+ vma_m = pax_find_mirror_vma(vma);
86660+ if (!vma_m)
86661+ return;
86662+
86663+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
86664+ address_m = address + SEGMEXEC_TASK_SIZE;
86665+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
86666+ pte_m = pte_offset_map(pmd_m, address_m);
86667+ ptl_m = pte_lockptr(mm, pmd_m);
86668+ if (ptl != ptl_m) {
86669+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
86670+ if (!pte_none(*pte_m))
86671+ goto out;
86672+ }
86673+
86674+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
86675+ page_cache_get(page_m);
86676+ page_add_file_rmap(page_m);
86677+ inc_mm_counter_fast(mm, MM_FILEPAGES);
86678+ set_pte_at(mm, address_m, pte_m, entry_m);
86679+ update_mmu_cache(vma_m, address_m, pte_m);
86680+out:
86681+ if (ptl != ptl_m)
86682+ spin_unlock(ptl_m);
86683+ pte_unmap(pte_m);
86684+}
86685+
86686+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
86687+{
86688+ struct mm_struct *mm = vma->vm_mm;
86689+ unsigned long address_m;
86690+ spinlock_t *ptl_m;
86691+ struct vm_area_struct *vma_m;
86692+ pmd_t *pmd_m;
86693+ pte_t *pte_m, entry_m;
86694+
86695+ vma_m = pax_find_mirror_vma(vma);
86696+ if (!vma_m)
86697+ return;
86698+
86699+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
86700+ address_m = address + SEGMEXEC_TASK_SIZE;
86701+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
86702+ pte_m = pte_offset_map(pmd_m, address_m);
86703+ ptl_m = pte_lockptr(mm, pmd_m);
86704+ if (ptl != ptl_m) {
86705+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
86706+ if (!pte_none(*pte_m))
86707+ goto out;
86708+ }
86709+
86710+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
86711+ set_pte_at(mm, address_m, pte_m, entry_m);
86712+out:
86713+ if (ptl != ptl_m)
86714+ spin_unlock(ptl_m);
86715+ pte_unmap(pte_m);
86716+}
86717+
86718+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
86719+{
86720+ struct page *page_m;
86721+ pte_t entry;
86722+
86723+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
86724+ goto out;
86725+
86726+ entry = *pte;
86727+ page_m = vm_normal_page(vma, address, entry);
86728+ if (!page_m)
86729+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
86730+ else if (PageAnon(page_m)) {
86731+ if (pax_find_mirror_vma(vma)) {
86732+ pte_unmap_unlock(pte, ptl);
86733+ lock_page(page_m);
86734+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
86735+ if (pte_same(entry, *pte))
86736+ pax_mirror_anon_pte(vma, address, page_m, ptl);
86737+ else
86738+ unlock_page(page_m);
86739+ }
86740+ } else
86741+ pax_mirror_file_pte(vma, address, page_m, ptl);
86742+
86743+out:
86744+ pte_unmap_unlock(pte, ptl);
86745+}
86746+#endif
86747+
86748 /*
86749 * This routine handles present pages, when users try to write
86750 * to a shared page. It is done by copying the page to a new address
86751@@ -2809,6 +3005,12 @@ gotten:
86752 */
86753 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
86754 if (likely(pte_same(*page_table, orig_pte))) {
86755+
86756+#ifdef CONFIG_PAX_SEGMEXEC
86757+ if (pax_find_mirror_vma(vma))
86758+ BUG_ON(!trylock_page(new_page));
86759+#endif
86760+
86761 if (old_page) {
86762 if (!PageAnon(old_page)) {
86763 dec_mm_counter_fast(mm, MM_FILEPAGES);
86764@@ -2860,6 +3062,10 @@ gotten:
86765 page_remove_rmap(old_page);
86766 }
86767
86768+#ifdef CONFIG_PAX_SEGMEXEC
86769+ pax_mirror_anon_pte(vma, address, new_page, ptl);
86770+#endif
86771+
86772 /* Free the old page.. */
86773 new_page = old_page;
86774 ret |= VM_FAULT_WRITE;
86775@@ -3137,6 +3343,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
86776 swap_free(entry);
86777 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
86778 try_to_free_swap(page);
86779+
86780+#ifdef CONFIG_PAX_SEGMEXEC
86781+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
86782+#endif
86783+
86784 unlock_page(page);
86785 if (page != swapcache) {
86786 /*
86787@@ -3160,6 +3371,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
86788
86789 /* No need to invalidate - it was non-present before */
86790 update_mmu_cache(vma, address, page_table);
86791+
86792+#ifdef CONFIG_PAX_SEGMEXEC
86793+ pax_mirror_anon_pte(vma, address, page, ptl);
86794+#endif
86795+
86796 unlock:
86797 pte_unmap_unlock(page_table, ptl);
86798 out:
86799@@ -3179,40 +3395,6 @@ out_release:
86800 }
86801
86802 /*
86803- * This is like a special single-page "expand_{down|up}wards()",
86804- * except we must first make sure that 'address{-|+}PAGE_SIZE'
86805- * doesn't hit another vma.
86806- */
86807-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
86808-{
86809- address &= PAGE_MASK;
86810- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
86811- struct vm_area_struct *prev = vma->vm_prev;
86812-
86813- /*
86814- * Is there a mapping abutting this one below?
86815- *
86816- * That's only ok if it's the same stack mapping
86817- * that has gotten split..
86818- */
86819- if (prev && prev->vm_end == address)
86820- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
86821-
86822- expand_downwards(vma, address - PAGE_SIZE);
86823- }
86824- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
86825- struct vm_area_struct *next = vma->vm_next;
86826-
86827- /* As VM_GROWSDOWN but s/below/above/ */
86828- if (next && next->vm_start == address + PAGE_SIZE)
86829- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
86830-
86831- expand_upwards(vma, address + PAGE_SIZE);
86832- }
86833- return 0;
86834-}
86835-
86836-/*
86837 * We enter with non-exclusive mmap_sem (to exclude vma changes,
86838 * but allow concurrent faults), and pte mapped but not yet locked.
86839 * We return with mmap_sem still held, but pte unmapped and unlocked.
86840@@ -3221,27 +3403,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
86841 unsigned long address, pte_t *page_table, pmd_t *pmd,
86842 unsigned int flags)
86843 {
86844- struct page *page;
86845+ struct page *page = NULL;
86846 spinlock_t *ptl;
86847 pte_t entry;
86848
86849- pte_unmap(page_table);
86850-
86851- /* Check if we need to add a guard page to the stack */
86852- if (check_stack_guard_page(vma, address) < 0)
86853- return VM_FAULT_SIGBUS;
86854-
86855- /* Use the zero-page for reads */
86856 if (!(flags & FAULT_FLAG_WRITE)) {
86857 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
86858 vma->vm_page_prot));
86859- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
86860+ ptl = pte_lockptr(mm, pmd);
86861+ spin_lock(ptl);
86862 if (!pte_none(*page_table))
86863 goto unlock;
86864 goto setpte;
86865 }
86866
86867 /* Allocate our own private page. */
86868+ pte_unmap(page_table);
86869+
86870 if (unlikely(anon_vma_prepare(vma)))
86871 goto oom;
86872 page = alloc_zeroed_user_highpage_movable(vma, address);
86873@@ -3265,6 +3443,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
86874 if (!pte_none(*page_table))
86875 goto release;
86876
86877+#ifdef CONFIG_PAX_SEGMEXEC
86878+ if (pax_find_mirror_vma(vma))
86879+ BUG_ON(!trylock_page(page));
86880+#endif
86881+
86882 inc_mm_counter_fast(mm, MM_ANONPAGES);
86883 page_add_new_anon_rmap(page, vma, address);
86884 setpte:
86885@@ -3272,6 +3455,12 @@ setpte:
86886
86887 /* No need to invalidate - it was non-present before */
86888 update_mmu_cache(vma, address, page_table);
86889+
86890+#ifdef CONFIG_PAX_SEGMEXEC
86891+ if (page)
86892+ pax_mirror_anon_pte(vma, address, page, ptl);
86893+#endif
86894+
86895 unlock:
86896 pte_unmap_unlock(page_table, ptl);
86897 return 0;
86898@@ -3415,6 +3604,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
86899 */
86900 /* Only go through if we didn't race with anybody else... */
86901 if (likely(pte_same(*page_table, orig_pte))) {
86902+
86903+#ifdef CONFIG_PAX_SEGMEXEC
86904+ if (anon && pax_find_mirror_vma(vma))
86905+ BUG_ON(!trylock_page(page));
86906+#endif
86907+
86908 flush_icache_page(vma, page);
86909 entry = mk_pte(page, vma->vm_page_prot);
86910 if (flags & FAULT_FLAG_WRITE)
86911@@ -3436,6 +3631,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
86912
86913 /* no need to invalidate: a not-present page won't be cached */
86914 update_mmu_cache(vma, address, page_table);
86915+
86916+#ifdef CONFIG_PAX_SEGMEXEC
86917+ if (anon)
86918+ pax_mirror_anon_pte(vma, address, page, ptl);
86919+ else
86920+ pax_mirror_file_pte(vma, address, page, ptl);
86921+#endif
86922+
86923 } else {
86924 if (cow_page)
86925 mem_cgroup_uncharge_page(cow_page);
86926@@ -3757,6 +3960,12 @@ int handle_pte_fault(struct mm_struct *mm,
86927 if (flags & FAULT_FLAG_WRITE)
86928 flush_tlb_fix_spurious_fault(vma, address);
86929 }
86930+
86931+#ifdef CONFIG_PAX_SEGMEXEC
86932+ pax_mirror_pte(vma, address, pte, pmd, ptl);
86933+ return 0;
86934+#endif
86935+
86936 unlock:
86937 pte_unmap_unlock(pte, ptl);
86938 return 0;
86939@@ -3773,6 +3982,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
86940 pmd_t *pmd;
86941 pte_t *pte;
86942
86943+#ifdef CONFIG_PAX_SEGMEXEC
86944+ struct vm_area_struct *vma_m;
86945+#endif
86946+
86947 __set_current_state(TASK_RUNNING);
86948
86949 count_vm_event(PGFAULT);
86950@@ -3784,6 +3997,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
86951 if (unlikely(is_vm_hugetlb_page(vma)))
86952 return hugetlb_fault(mm, vma, address, flags);
86953
86954+#ifdef CONFIG_PAX_SEGMEXEC
86955+ vma_m = pax_find_mirror_vma(vma);
86956+ if (vma_m) {
86957+ unsigned long address_m;
86958+ pgd_t *pgd_m;
86959+ pud_t *pud_m;
86960+ pmd_t *pmd_m;
86961+
86962+ if (vma->vm_start > vma_m->vm_start) {
86963+ address_m = address;
86964+ address -= SEGMEXEC_TASK_SIZE;
86965+ vma = vma_m;
86966+ } else
86967+ address_m = address + SEGMEXEC_TASK_SIZE;
86968+
86969+ pgd_m = pgd_offset(mm, address_m);
86970+ pud_m = pud_alloc(mm, pgd_m, address_m);
86971+ if (!pud_m)
86972+ return VM_FAULT_OOM;
86973+ pmd_m = pmd_alloc(mm, pud_m, address_m);
86974+ if (!pmd_m)
86975+ return VM_FAULT_OOM;
86976+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
86977+ return VM_FAULT_OOM;
86978+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
86979+ }
86980+#endif
86981+
86982 retry:
86983 pgd = pgd_offset(mm, address);
86984 pud = pud_alloc(mm, pgd, address);
86985@@ -3882,6 +4123,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
86986 spin_unlock(&mm->page_table_lock);
86987 return 0;
86988 }
86989+
86990+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
86991+{
86992+ pud_t *new = pud_alloc_one(mm, address);
86993+ if (!new)
86994+ return -ENOMEM;
86995+
86996+ smp_wmb(); /* See comment in __pte_alloc */
86997+
86998+ spin_lock(&mm->page_table_lock);
86999+ if (pgd_present(*pgd)) /* Another has populated it */
87000+ pud_free(mm, new);
87001+ else
87002+ pgd_populate_kernel(mm, pgd, new);
87003+ spin_unlock(&mm->page_table_lock);
87004+ return 0;
87005+}
87006 #endif /* __PAGETABLE_PUD_FOLDED */
87007
87008 #ifndef __PAGETABLE_PMD_FOLDED
87009@@ -3912,6 +4170,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
87010 spin_unlock(&mm->page_table_lock);
87011 return 0;
87012 }
87013+
87014+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
87015+{
87016+ pmd_t *new = pmd_alloc_one(mm, address);
87017+ if (!new)
87018+ return -ENOMEM;
87019+
87020+ smp_wmb(); /* See comment in __pte_alloc */
87021+
87022+ spin_lock(&mm->page_table_lock);
87023+#ifndef __ARCH_HAS_4LEVEL_HACK
87024+ if (pud_present(*pud)) /* Another has populated it */
87025+ pmd_free(mm, new);
87026+ else
87027+ pud_populate_kernel(mm, pud, new);
87028+#else
87029+ if (pgd_present(*pud)) /* Another has populated it */
87030+ pmd_free(mm, new);
87031+ else
87032+ pgd_populate_kernel(mm, pud, new);
87033+#endif /* __ARCH_HAS_4LEVEL_HACK */
87034+ spin_unlock(&mm->page_table_lock);
87035+ return 0;
87036+}
87037 #endif /* __PAGETABLE_PMD_FOLDED */
87038
87039 #if !defined(__HAVE_ARCH_GATE_AREA)
87040@@ -3925,7 +4207,7 @@ static int __init gate_vma_init(void)
87041 gate_vma.vm_start = FIXADDR_USER_START;
87042 gate_vma.vm_end = FIXADDR_USER_END;
87043 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
87044- gate_vma.vm_page_prot = __P101;
87045+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
87046
87047 return 0;
87048 }
87049@@ -4059,8 +4341,8 @@ out:
87050 return ret;
87051 }
87052
87053-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
87054- void *buf, int len, int write)
87055+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
87056+ void *buf, size_t len, int write)
87057 {
87058 resource_size_t phys_addr;
87059 unsigned long prot = 0;
87060@@ -4085,8 +4367,8 @@ int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
87061 * Access another process' address space as given in mm. If non-NULL, use the
87062 * given task for page fault accounting.
87063 */
87064-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
87065- unsigned long addr, void *buf, int len, int write)
87066+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
87067+ unsigned long addr, void *buf, size_t len, int write)
87068 {
87069 struct vm_area_struct *vma;
87070 void *old_buf = buf;
87071@@ -4094,7 +4376,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
87072 down_read(&mm->mmap_sem);
87073 /* ignore errors, just check how much was successfully transferred */
87074 while (len) {
87075- int bytes, ret, offset;
87076+ ssize_t bytes, ret, offset;
87077 void *maddr;
87078 struct page *page = NULL;
87079
87080@@ -4153,8 +4435,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
87081 *
87082 * The caller must hold a reference on @mm.
87083 */
87084-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
87085- void *buf, int len, int write)
87086+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
87087+ void *buf, size_t len, int write)
87088 {
87089 return __access_remote_vm(NULL, mm, addr, buf, len, write);
87090 }
87091@@ -4164,11 +4446,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
87092 * Source/target buffer must be kernel space,
87093 * Do not walk the page table directly, use get_user_pages
87094 */
87095-int access_process_vm(struct task_struct *tsk, unsigned long addr,
87096- void *buf, int len, int write)
87097+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
87098+ void *buf, size_t len, int write)
87099 {
87100 struct mm_struct *mm;
87101- int ret;
87102+ ssize_t ret;
87103
87104 mm = get_task_mm(tsk);
87105 if (!mm)
87106diff --git a/mm/mempolicy.c b/mm/mempolicy.c
87107index 4baf12e..5497066 100644
87108--- a/mm/mempolicy.c
87109+++ b/mm/mempolicy.c
87110@@ -708,6 +708,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
87111 unsigned long vmstart;
87112 unsigned long vmend;
87113
87114+#ifdef CONFIG_PAX_SEGMEXEC
87115+ struct vm_area_struct *vma_m;
87116+#endif
87117+
87118 vma = find_vma(mm, start);
87119 if (!vma || vma->vm_start > start)
87120 return -EFAULT;
87121@@ -751,6 +755,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
87122 err = vma_replace_policy(vma, new_pol);
87123 if (err)
87124 goto out;
87125+
87126+#ifdef CONFIG_PAX_SEGMEXEC
87127+ vma_m = pax_find_mirror_vma(vma);
87128+ if (vma_m) {
87129+ err = vma_replace_policy(vma_m, new_pol);
87130+ if (err)
87131+ goto out;
87132+ }
87133+#endif
87134+
87135 }
87136
87137 out:
87138@@ -1206,6 +1220,17 @@ static long do_mbind(unsigned long start, unsigned long len,
87139
87140 if (end < start)
87141 return -EINVAL;
87142+
87143+#ifdef CONFIG_PAX_SEGMEXEC
87144+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
87145+ if (end > SEGMEXEC_TASK_SIZE)
87146+ return -EINVAL;
87147+ } else
87148+#endif
87149+
87150+ if (end > TASK_SIZE)
87151+ return -EINVAL;
87152+
87153 if (end == start)
87154 return 0;
87155
87156@@ -1434,8 +1459,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
87157 */
87158 tcred = __task_cred(task);
87159 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
87160- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
87161- !capable(CAP_SYS_NICE)) {
87162+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
87163 rcu_read_unlock();
87164 err = -EPERM;
87165 goto out_put;
87166@@ -1466,6 +1490,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
87167 goto out;
87168 }
87169
87170+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
87171+ if (mm != current->mm &&
87172+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
87173+ mmput(mm);
87174+ err = -EPERM;
87175+ goto out;
87176+ }
87177+#endif
87178+
87179 err = do_migrate_pages(mm, old, new,
87180 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
87181
87182diff --git a/mm/migrate.c b/mm/migrate.c
87183index 6f0c244..6d1ae32 100644
87184--- a/mm/migrate.c
87185+++ b/mm/migrate.c
87186@@ -1399,8 +1399,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
87187 */
87188 tcred = __task_cred(task);
87189 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
87190- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
87191- !capable(CAP_SYS_NICE)) {
87192+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
87193 rcu_read_unlock();
87194 err = -EPERM;
87195 goto out;
87196diff --git a/mm/mlock.c b/mm/mlock.c
87197index 79b7cf7..9944291 100644
87198--- a/mm/mlock.c
87199+++ b/mm/mlock.c
87200@@ -13,6 +13,7 @@
87201 #include <linux/pagemap.h>
87202 #include <linux/mempolicy.h>
87203 #include <linux/syscalls.h>
87204+#include <linux/security.h>
87205 #include <linux/sched.h>
87206 #include <linux/export.h>
87207 #include <linux/rmap.h>
87208@@ -334,7 +335,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
87209 {
87210 unsigned long nstart, end, tmp;
87211 struct vm_area_struct * vma, * prev;
87212- int error;
87213+ int error = 0;
87214
87215 VM_BUG_ON(start & ~PAGE_MASK);
87216 VM_BUG_ON(len != PAGE_ALIGN(len));
87217@@ -343,6 +344,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
87218 return -EINVAL;
87219 if (end == start)
87220 return 0;
87221+ if (end > TASK_SIZE)
87222+ return -EINVAL;
87223+
87224 vma = find_vma(current->mm, start);
87225 if (!vma || vma->vm_start > start)
87226 return -ENOMEM;
87227@@ -354,6 +358,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
87228 for (nstart = start ; ; ) {
87229 vm_flags_t newflags;
87230
87231+#ifdef CONFIG_PAX_SEGMEXEC
87232+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
87233+ break;
87234+#endif
87235+
87236 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
87237
87238 newflags = vma->vm_flags & ~VM_LOCKED;
87239@@ -466,6 +475,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
87240 lock_limit >>= PAGE_SHIFT;
87241
87242 /* check against resource limits */
87243+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
87244 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
87245 error = do_mlock(start, len, 1);
87246 up_write(&current->mm->mmap_sem);
87247@@ -500,6 +510,11 @@ static int do_mlockall(int flags)
87248 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
87249 vm_flags_t newflags;
87250
87251+#ifdef CONFIG_PAX_SEGMEXEC
87252+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
87253+ break;
87254+#endif
87255+
87256 newflags = vma->vm_flags & ~VM_LOCKED;
87257 if (flags & MCL_CURRENT)
87258 newflags |= VM_LOCKED;
87259@@ -532,6 +547,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
87260 lock_limit >>= PAGE_SHIFT;
87261
87262 ret = -ENOMEM;
87263+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
87264 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
87265 capable(CAP_IPC_LOCK))
87266 ret = do_mlockall(flags);
87267diff --git a/mm/mmap.c b/mm/mmap.c
87268index f9c97d1..3468d3b 100644
87269--- a/mm/mmap.c
87270+++ b/mm/mmap.c
87271@@ -36,6 +36,7 @@
87272 #include <linux/sched/sysctl.h>
87273 #include <linux/notifier.h>
87274 #include <linux/memory.h>
87275+#include <linux/random.h>
87276
87277 #include <asm/uaccess.h>
87278 #include <asm/cacheflush.h>
87279@@ -52,6 +53,16 @@
87280 #define arch_rebalance_pgtables(addr, len) (addr)
87281 #endif
87282
87283+static inline void verify_mm_writelocked(struct mm_struct *mm)
87284+{
87285+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
87286+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
87287+ up_read(&mm->mmap_sem);
87288+ BUG();
87289+ }
87290+#endif
87291+}
87292+
87293 static void unmap_region(struct mm_struct *mm,
87294 struct vm_area_struct *vma, struct vm_area_struct *prev,
87295 unsigned long start, unsigned long end);
87296@@ -71,16 +82,25 @@ static void unmap_region(struct mm_struct *mm,
87297 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
87298 *
87299 */
87300-pgprot_t protection_map[16] = {
87301+pgprot_t protection_map[16] __read_only = {
87302 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
87303 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
87304 };
87305
87306-pgprot_t vm_get_page_prot(unsigned long vm_flags)
87307+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
87308 {
87309- return __pgprot(pgprot_val(protection_map[vm_flags &
87310+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
87311 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
87312 pgprot_val(arch_vm_get_page_prot(vm_flags)));
87313+
87314+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
87315+ if (!(__supported_pte_mask & _PAGE_NX) &&
87316+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
87317+ (vm_flags & (VM_READ | VM_WRITE)))
87318+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
87319+#endif
87320+
87321+ return prot;
87322 }
87323 EXPORT_SYMBOL(vm_get_page_prot);
87324
87325@@ -89,6 +109,7 @@ int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
87326 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
87327 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
87328 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
87329+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
87330 /*
87331 * Make sure vm_committed_as in one cacheline and not cacheline shared with
87332 * other variables. It can be updated by several CPUs frequently.
87333@@ -247,6 +268,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
87334 struct vm_area_struct *next = vma->vm_next;
87335
87336 might_sleep();
87337+ BUG_ON(vma->vm_mirror);
87338 if (vma->vm_ops && vma->vm_ops->close)
87339 vma->vm_ops->close(vma);
87340 if (vma->vm_file)
87341@@ -291,6 +313,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
87342 * not page aligned -Ram Gupta
87343 */
87344 rlim = rlimit(RLIMIT_DATA);
87345+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
87346 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
87347 (mm->end_data - mm->start_data) > rlim)
87348 goto out;
87349@@ -933,6 +956,12 @@ static int
87350 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
87351 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
87352 {
87353+
87354+#ifdef CONFIG_PAX_SEGMEXEC
87355+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
87356+ return 0;
87357+#endif
87358+
87359 if (is_mergeable_vma(vma, file, vm_flags) &&
87360 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
87361 if (vma->vm_pgoff == vm_pgoff)
87362@@ -952,6 +981,12 @@ static int
87363 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
87364 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
87365 {
87366+
87367+#ifdef CONFIG_PAX_SEGMEXEC
87368+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
87369+ return 0;
87370+#endif
87371+
87372 if (is_mergeable_vma(vma, file, vm_flags) &&
87373 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
87374 pgoff_t vm_pglen;
87375@@ -994,13 +1029,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
87376 struct vm_area_struct *vma_merge(struct mm_struct *mm,
87377 struct vm_area_struct *prev, unsigned long addr,
87378 unsigned long end, unsigned long vm_flags,
87379- struct anon_vma *anon_vma, struct file *file,
87380+ struct anon_vma *anon_vma, struct file *file,
87381 pgoff_t pgoff, struct mempolicy *policy)
87382 {
87383 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
87384 struct vm_area_struct *area, *next;
87385 int err;
87386
87387+#ifdef CONFIG_PAX_SEGMEXEC
87388+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
87389+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
87390+
87391+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
87392+#endif
87393+
87394 /*
87395 * We later require that vma->vm_flags == vm_flags,
87396 * so this tests vma->vm_flags & VM_SPECIAL, too.
87397@@ -1016,6 +1058,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
87398 if (next && next->vm_end == end) /* cases 6, 7, 8 */
87399 next = next->vm_next;
87400
87401+#ifdef CONFIG_PAX_SEGMEXEC
87402+ if (prev)
87403+ prev_m = pax_find_mirror_vma(prev);
87404+ if (area)
87405+ area_m = pax_find_mirror_vma(area);
87406+ if (next)
87407+ next_m = pax_find_mirror_vma(next);
87408+#endif
87409+
87410 /*
87411 * Can it merge with the predecessor?
87412 */
87413@@ -1035,9 +1086,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
87414 /* cases 1, 6 */
87415 err = vma_adjust(prev, prev->vm_start,
87416 next->vm_end, prev->vm_pgoff, NULL);
87417- } else /* cases 2, 5, 7 */
87418+
87419+#ifdef CONFIG_PAX_SEGMEXEC
87420+ if (!err && prev_m)
87421+ err = vma_adjust(prev_m, prev_m->vm_start,
87422+ next_m->vm_end, prev_m->vm_pgoff, NULL);
87423+#endif
87424+
87425+ } else { /* cases 2, 5, 7 */
87426 err = vma_adjust(prev, prev->vm_start,
87427 end, prev->vm_pgoff, NULL);
87428+
87429+#ifdef CONFIG_PAX_SEGMEXEC
87430+ if (!err && prev_m)
87431+ err = vma_adjust(prev_m, prev_m->vm_start,
87432+ end_m, prev_m->vm_pgoff, NULL);
87433+#endif
87434+
87435+ }
87436 if (err)
87437 return NULL;
87438 khugepaged_enter_vma_merge(prev);
87439@@ -1051,12 +1117,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
87440 mpol_equal(policy, vma_policy(next)) &&
87441 can_vma_merge_before(next, vm_flags,
87442 anon_vma, file, pgoff+pglen)) {
87443- if (prev && addr < prev->vm_end) /* case 4 */
87444+ if (prev && addr < prev->vm_end) { /* case 4 */
87445 err = vma_adjust(prev, prev->vm_start,
87446 addr, prev->vm_pgoff, NULL);
87447- else /* cases 3, 8 */
87448+
87449+#ifdef CONFIG_PAX_SEGMEXEC
87450+ if (!err && prev_m)
87451+ err = vma_adjust(prev_m, prev_m->vm_start,
87452+ addr_m, prev_m->vm_pgoff, NULL);
87453+#endif
87454+
87455+ } else { /* cases 3, 8 */
87456 err = vma_adjust(area, addr, next->vm_end,
87457 next->vm_pgoff - pglen, NULL);
87458+
87459+#ifdef CONFIG_PAX_SEGMEXEC
87460+ if (!err && area_m)
87461+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
87462+ next_m->vm_pgoff - pglen, NULL);
87463+#endif
87464+
87465+ }
87466 if (err)
87467 return NULL;
87468 khugepaged_enter_vma_merge(area);
87469@@ -1165,8 +1246,10 @@ none:
87470 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
87471 struct file *file, long pages)
87472 {
87473- const unsigned long stack_flags
87474- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
87475+
87476+#ifdef CONFIG_PAX_RANDMMAP
87477+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
87478+#endif
87479
87480 mm->total_vm += pages;
87481
87482@@ -1174,7 +1257,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
87483 mm->shared_vm += pages;
87484 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
87485 mm->exec_vm += pages;
87486- } else if (flags & stack_flags)
87487+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
87488 mm->stack_vm += pages;
87489 }
87490 #endif /* CONFIG_PROC_FS */
87491@@ -1213,7 +1296,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
87492 * (the exception is when the underlying filesystem is noexec
87493 * mounted, in which case we dont add PROT_EXEC.)
87494 */
87495- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
87496+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
87497 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
87498 prot |= PROT_EXEC;
87499
87500@@ -1239,7 +1322,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
87501 /* Obtain the address to map to. we verify (or select) it and ensure
87502 * that it represents a valid section of the address space.
87503 */
87504- addr = get_unmapped_area(file, addr, len, pgoff, flags);
87505+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
87506 if (addr & ~PAGE_MASK)
87507 return addr;
87508
87509@@ -1250,6 +1333,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
87510 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
87511 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
87512
87513+#ifdef CONFIG_PAX_MPROTECT
87514+ if (mm->pax_flags & MF_PAX_MPROTECT) {
87515+
87516+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
87517+ if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
87518+ mm->binfmt->handle_mmap)
87519+ mm->binfmt->handle_mmap(file);
87520+#endif
87521+
87522+#ifndef CONFIG_PAX_MPROTECT_COMPAT
87523+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
87524+ gr_log_rwxmmap(file);
87525+
87526+#ifdef CONFIG_PAX_EMUPLT
87527+ vm_flags &= ~VM_EXEC;
87528+#else
87529+ return -EPERM;
87530+#endif
87531+
87532+ }
87533+
87534+ if (!(vm_flags & VM_EXEC))
87535+ vm_flags &= ~VM_MAYEXEC;
87536+#else
87537+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
87538+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
87539+#endif
87540+ else
87541+ vm_flags &= ~VM_MAYWRITE;
87542+ }
87543+#endif
87544+
87545+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
87546+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
87547+ vm_flags &= ~VM_PAGEEXEC;
87548+#endif
87549+
87550 if (flags & MAP_LOCKED)
87551 if (!can_do_mlock())
87552 return -EPERM;
87553@@ -1261,6 +1381,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
87554 locked += mm->locked_vm;
87555 lock_limit = rlimit(RLIMIT_MEMLOCK);
87556 lock_limit >>= PAGE_SHIFT;
87557+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
87558 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
87559 return -EAGAIN;
87560 }
87561@@ -1341,6 +1462,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
87562 vm_flags |= VM_NORESERVE;
87563 }
87564
87565+ if (!gr_acl_handle_mmap(file, prot))
87566+ return -EACCES;
87567+
87568 addr = mmap_region(file, addr, len, vm_flags, pgoff);
87569 if (!IS_ERR_VALUE(addr) &&
87570 ((vm_flags & VM_LOCKED) ||
87571@@ -1434,7 +1558,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
87572 vm_flags_t vm_flags = vma->vm_flags;
87573
87574 /* If it was private or non-writable, the write bit is already clear */
87575- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
87576+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
87577 return 0;
87578
87579 /* The backer wishes to know when pages are first written to? */
87580@@ -1482,7 +1606,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
87581 unsigned long charged = 0;
87582 struct inode *inode = file ? file_inode(file) : NULL;
87583
87584+#ifdef CONFIG_PAX_SEGMEXEC
87585+ struct vm_area_struct *vma_m = NULL;
87586+#endif
87587+
87588+ /*
87589+ * mm->mmap_sem is required to protect against another thread
87590+ * changing the mappings in case we sleep.
87591+ */
87592+ verify_mm_writelocked(mm);
87593+
87594 /* Check against address space limit. */
87595+
87596+#ifdef CONFIG_PAX_RANDMMAP
87597+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
87598+#endif
87599+
87600 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
87601 unsigned long nr_pages;
87602
87603@@ -1501,11 +1640,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
87604
87605 /* Clear old maps */
87606 error = -ENOMEM;
87607-munmap_back:
87608 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
87609 if (do_munmap(mm, addr, len))
87610 return -ENOMEM;
87611- goto munmap_back;
87612+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
87613 }
87614
87615 /*
87616@@ -1536,6 +1674,16 @@ munmap_back:
87617 goto unacct_error;
87618 }
87619
87620+#ifdef CONFIG_PAX_SEGMEXEC
87621+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
87622+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
87623+ if (!vma_m) {
87624+ error = -ENOMEM;
87625+ goto free_vma;
87626+ }
87627+ }
87628+#endif
87629+
87630 vma->vm_mm = mm;
87631 vma->vm_start = addr;
87632 vma->vm_end = addr + len;
87633@@ -1560,6 +1708,13 @@ munmap_back:
87634 if (error)
87635 goto unmap_and_free_vma;
87636
87637+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
87638+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
87639+ vma->vm_flags |= VM_PAGEEXEC;
87640+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
87641+ }
87642+#endif
87643+
87644 /* Can addr have changed??
87645 *
87646 * Answer: Yes, several device drivers can do it in their
87647@@ -1598,6 +1753,11 @@ munmap_back:
87648 vma_link(mm, vma, prev, rb_link, rb_parent);
87649 file = vma->vm_file;
87650
87651+#ifdef CONFIG_PAX_SEGMEXEC
87652+ if (vma_m)
87653+ BUG_ON(pax_mirror_vma(vma_m, vma));
87654+#endif
87655+
87656 /* Once vma denies write, undo our temporary denial count */
87657 if (correct_wcount)
87658 atomic_inc(&inode->i_writecount);
87659@@ -1605,6 +1765,7 @@ out:
87660 perf_event_mmap(vma);
87661
87662 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
87663+ track_exec_limit(mm, addr, addr + len, vm_flags);
87664 if (vm_flags & VM_LOCKED) {
87665 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
87666 vma == get_gate_vma(current->mm)))
87667@@ -1628,6 +1789,12 @@ unmap_and_free_vma:
87668 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
87669 charged = 0;
87670 free_vma:
87671+
87672+#ifdef CONFIG_PAX_SEGMEXEC
87673+ if (vma_m)
87674+ kmem_cache_free(vm_area_cachep, vma_m);
87675+#endif
87676+
87677 kmem_cache_free(vm_area_cachep, vma);
87678 unacct_error:
87679 if (charged)
87680@@ -1635,7 +1802,63 @@ unacct_error:
87681 return error;
87682 }
87683
87684-unsigned long unmapped_area(struct vm_unmapped_area_info *info)
87685+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
87686+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
87687+{
87688+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
87689+ return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
87690+
87691+ return 0;
87692+}
87693+#endif
87694+
87695+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
87696+{
87697+ if (!vma) {
87698+#ifdef CONFIG_STACK_GROWSUP
87699+ if (addr > sysctl_heap_stack_gap)
87700+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
87701+ else
87702+ vma = find_vma(current->mm, 0);
87703+ if (vma && (vma->vm_flags & VM_GROWSUP))
87704+ return false;
87705+#endif
87706+ return true;
87707+ }
87708+
87709+ if (addr + len > vma->vm_start)
87710+ return false;
87711+
87712+ if (vma->vm_flags & VM_GROWSDOWN)
87713+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
87714+#ifdef CONFIG_STACK_GROWSUP
87715+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
87716+ return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
87717+#endif
87718+ else if (offset)
87719+ return offset <= vma->vm_start - addr - len;
87720+
87721+ return true;
87722+}
87723+
87724+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
87725+{
87726+ if (vma->vm_start < len)
87727+ return -ENOMEM;
87728+
87729+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
87730+ if (offset <= vma->vm_start - len)
87731+ return vma->vm_start - len - offset;
87732+ else
87733+ return -ENOMEM;
87734+ }
87735+
87736+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
87737+ return vma->vm_start - len - sysctl_heap_stack_gap;
87738+ return -ENOMEM;
87739+}
87740+
87741+unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
87742 {
87743 /*
87744 * We implement the search by looking for an rbtree node that
87745@@ -1683,11 +1906,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
87746 }
87747 }
87748
87749- gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
87750+ gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
87751 check_current:
87752 /* Check if current node has a suitable gap */
87753 if (gap_start > high_limit)
87754 return -ENOMEM;
87755+
87756+ if (gap_end - gap_start > info->threadstack_offset)
87757+ gap_start += info->threadstack_offset;
87758+ else
87759+ gap_start = gap_end;
87760+
87761+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
87762+ if (gap_end - gap_start > sysctl_heap_stack_gap)
87763+ gap_start += sysctl_heap_stack_gap;
87764+ else
87765+ gap_start = gap_end;
87766+ }
87767+ if (vma->vm_flags & VM_GROWSDOWN) {
87768+ if (gap_end - gap_start > sysctl_heap_stack_gap)
87769+ gap_end -= sysctl_heap_stack_gap;
87770+ else
87771+ gap_end = gap_start;
87772+ }
87773 if (gap_end >= low_limit && gap_end - gap_start >= length)
87774 goto found;
87775
87776@@ -1737,7 +1978,7 @@ found:
87777 return gap_start;
87778 }
87779
87780-unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
87781+unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
87782 {
87783 struct mm_struct *mm = current->mm;
87784 struct vm_area_struct *vma;
87785@@ -1791,6 +2032,24 @@ check_current:
87786 gap_end = vma->vm_start;
87787 if (gap_end < low_limit)
87788 return -ENOMEM;
87789+
87790+ if (gap_end - gap_start > info->threadstack_offset)
87791+ gap_end -= info->threadstack_offset;
87792+ else
87793+ gap_end = gap_start;
87794+
87795+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
87796+ if (gap_end - gap_start > sysctl_heap_stack_gap)
87797+ gap_start += sysctl_heap_stack_gap;
87798+ else
87799+ gap_start = gap_end;
87800+ }
87801+ if (vma->vm_flags & VM_GROWSDOWN) {
87802+ if (gap_end - gap_start > sysctl_heap_stack_gap)
87803+ gap_end -= sysctl_heap_stack_gap;
87804+ else
87805+ gap_end = gap_start;
87806+ }
87807 if (gap_start <= high_limit && gap_end - gap_start >= length)
87808 goto found;
87809
87810@@ -1854,6 +2113,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
87811 struct mm_struct *mm = current->mm;
87812 struct vm_area_struct *vma;
87813 struct vm_unmapped_area_info info;
87814+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
87815
87816 if (len > TASK_SIZE)
87817 return -ENOMEM;
87818@@ -1861,19 +2121,29 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
87819 if (flags & MAP_FIXED)
87820 return addr;
87821
87822+#ifdef CONFIG_PAX_RANDMMAP
87823+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
87824+#endif
87825+
87826 if (addr) {
87827 addr = PAGE_ALIGN(addr);
87828 vma = find_vma(mm, addr);
87829- if (TASK_SIZE - len >= addr &&
87830- (!vma || addr + len <= vma->vm_start))
87831+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
87832 return addr;
87833 }
87834
87835 info.flags = 0;
87836 info.length = len;
87837 info.low_limit = TASK_UNMAPPED_BASE;
87838+
87839+#ifdef CONFIG_PAX_RANDMMAP
87840+ if (mm->pax_flags & MF_PAX_RANDMMAP)
87841+ info.low_limit += mm->delta_mmap;
87842+#endif
87843+
87844 info.high_limit = TASK_SIZE;
87845 info.align_mask = 0;
87846+ info.threadstack_offset = offset;
87847 return vm_unmapped_area(&info);
87848 }
87849 #endif
87850@@ -1892,6 +2162,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
87851 struct mm_struct *mm = current->mm;
87852 unsigned long addr = addr0;
87853 struct vm_unmapped_area_info info;
87854+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
87855
87856 /* requested length too big for entire address space */
87857 if (len > TASK_SIZE)
87858@@ -1900,12 +2171,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
87859 if (flags & MAP_FIXED)
87860 return addr;
87861
87862+#ifdef CONFIG_PAX_RANDMMAP
87863+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
87864+#endif
87865+
87866 /* requesting a specific address */
87867 if (addr) {
87868 addr = PAGE_ALIGN(addr);
87869 vma = find_vma(mm, addr);
87870- if (TASK_SIZE - len >= addr &&
87871- (!vma || addr + len <= vma->vm_start))
87872+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
87873 return addr;
87874 }
87875
87876@@ -1914,6 +2188,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
87877 info.low_limit = PAGE_SIZE;
87878 info.high_limit = mm->mmap_base;
87879 info.align_mask = 0;
87880+ info.threadstack_offset = offset;
87881 addr = vm_unmapped_area(&info);
87882
87883 /*
87884@@ -1926,6 +2201,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
87885 VM_BUG_ON(addr != -ENOMEM);
87886 info.flags = 0;
87887 info.low_limit = TASK_UNMAPPED_BASE;
87888+
87889+#ifdef CONFIG_PAX_RANDMMAP
87890+ if (mm->pax_flags & MF_PAX_RANDMMAP)
87891+ info.low_limit += mm->delta_mmap;
87892+#endif
87893+
87894 info.high_limit = TASK_SIZE;
87895 addr = vm_unmapped_area(&info);
87896 }
87897@@ -2027,6 +2308,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
87898 return vma;
87899 }
87900
87901+#ifdef CONFIG_PAX_SEGMEXEC
87902+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
87903+{
87904+ struct vm_area_struct *vma_m;
87905+
87906+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
87907+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
87908+ BUG_ON(vma->vm_mirror);
87909+ return NULL;
87910+ }
87911+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
87912+ vma_m = vma->vm_mirror;
87913+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
87914+ BUG_ON(vma->vm_file != vma_m->vm_file);
87915+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
87916+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
87917+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
87918+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
87919+ return vma_m;
87920+}
87921+#endif
87922+
87923 /*
87924 * Verify that the stack growth is acceptable and
87925 * update accounting. This is shared with both the
87926@@ -2043,6 +2346,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
87927 return -ENOMEM;
87928
87929 /* Stack limit test */
87930+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
87931 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
87932 return -ENOMEM;
87933
87934@@ -2053,6 +2357,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
87935 locked = mm->locked_vm + grow;
87936 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
87937 limit >>= PAGE_SHIFT;
87938+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
87939 if (locked > limit && !capable(CAP_IPC_LOCK))
87940 return -ENOMEM;
87941 }
87942@@ -2082,37 +2387,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
87943 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
87944 * vma is the last one with address > vma->vm_end. Have to extend vma.
87945 */
87946+#ifndef CONFIG_IA64
87947+static
87948+#endif
87949 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
87950 {
87951 int error;
87952+ bool locknext;
87953
87954 if (!(vma->vm_flags & VM_GROWSUP))
87955 return -EFAULT;
87956
87957+ /* Also guard against wrapping around to address 0. */
87958+ if (address < PAGE_ALIGN(address+1))
87959+ address = PAGE_ALIGN(address+1);
87960+ else
87961+ return -ENOMEM;
87962+
87963 /*
87964 * We must make sure the anon_vma is allocated
87965 * so that the anon_vma locking is not a noop.
87966 */
87967 if (unlikely(anon_vma_prepare(vma)))
87968 return -ENOMEM;
87969+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
87970+ if (locknext && anon_vma_prepare(vma->vm_next))
87971+ return -ENOMEM;
87972 vma_lock_anon_vma(vma);
87973+ if (locknext)
87974+ vma_lock_anon_vma(vma->vm_next);
87975
87976 /*
87977 * vma->vm_start/vm_end cannot change under us because the caller
87978 * is required to hold the mmap_sem in read mode. We need the
87979- * anon_vma lock to serialize against concurrent expand_stacks.
87980- * Also guard against wrapping around to address 0.
87981+ * anon_vma locks to serialize against concurrent expand_stacks
87982+ * and expand_upwards.
87983 */
87984- if (address < PAGE_ALIGN(address+4))
87985- address = PAGE_ALIGN(address+4);
87986- else {
87987- vma_unlock_anon_vma(vma);
87988- return -ENOMEM;
87989- }
87990 error = 0;
87991
87992 /* Somebody else might have raced and expanded it already */
87993- if (address > vma->vm_end) {
87994+ 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)
87995+ error = -ENOMEM;
87996+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
87997 unsigned long size, grow;
87998
87999 size = address - vma->vm_start;
88000@@ -2147,6 +2463,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
88001 }
88002 }
88003 }
88004+ if (locknext)
88005+ vma_unlock_anon_vma(vma->vm_next);
88006 vma_unlock_anon_vma(vma);
88007 khugepaged_enter_vma_merge(vma);
88008 validate_mm(vma->vm_mm);
88009@@ -2161,6 +2479,8 @@ int expand_downwards(struct vm_area_struct *vma,
88010 unsigned long address)
88011 {
88012 int error;
88013+ bool lockprev = false;
88014+ struct vm_area_struct *prev;
88015
88016 /*
88017 * We must make sure the anon_vma is allocated
88018@@ -2174,6 +2494,15 @@ int expand_downwards(struct vm_area_struct *vma,
88019 if (error)
88020 return error;
88021
88022+ prev = vma->vm_prev;
88023+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
88024+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
88025+#endif
88026+ if (lockprev && anon_vma_prepare(prev))
88027+ return -ENOMEM;
88028+ if (lockprev)
88029+ vma_lock_anon_vma(prev);
88030+
88031 vma_lock_anon_vma(vma);
88032
88033 /*
88034@@ -2183,9 +2512,17 @@ int expand_downwards(struct vm_area_struct *vma,
88035 */
88036
88037 /* Somebody else might have raced and expanded it already */
88038- if (address < vma->vm_start) {
88039+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
88040+ error = -ENOMEM;
88041+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
88042 unsigned long size, grow;
88043
88044+#ifdef CONFIG_PAX_SEGMEXEC
88045+ struct vm_area_struct *vma_m;
88046+
88047+ vma_m = pax_find_mirror_vma(vma);
88048+#endif
88049+
88050 size = vma->vm_end - address;
88051 grow = (vma->vm_start - address) >> PAGE_SHIFT;
88052
88053@@ -2210,13 +2547,27 @@ int expand_downwards(struct vm_area_struct *vma,
88054 vma->vm_pgoff -= grow;
88055 anon_vma_interval_tree_post_update_vma(vma);
88056 vma_gap_update(vma);
88057+
88058+#ifdef CONFIG_PAX_SEGMEXEC
88059+ if (vma_m) {
88060+ anon_vma_interval_tree_pre_update_vma(vma_m);
88061+ vma_m->vm_start -= grow << PAGE_SHIFT;
88062+ vma_m->vm_pgoff -= grow;
88063+ anon_vma_interval_tree_post_update_vma(vma_m);
88064+ vma_gap_update(vma_m);
88065+ }
88066+#endif
88067+
88068 spin_unlock(&vma->vm_mm->page_table_lock);
88069
88070+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
88071 perf_event_mmap(vma);
88072 }
88073 }
88074 }
88075 vma_unlock_anon_vma(vma);
88076+ if (lockprev)
88077+ vma_unlock_anon_vma(prev);
88078 khugepaged_enter_vma_merge(vma);
88079 validate_mm(vma->vm_mm);
88080 return error;
88081@@ -2314,6 +2665,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
88082 do {
88083 long nrpages = vma_pages(vma);
88084
88085+#ifdef CONFIG_PAX_SEGMEXEC
88086+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
88087+ vma = remove_vma(vma);
88088+ continue;
88089+ }
88090+#endif
88091+
88092 if (vma->vm_flags & VM_ACCOUNT)
88093 nr_accounted += nrpages;
88094 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
88095@@ -2358,6 +2716,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
88096 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
88097 vma->vm_prev = NULL;
88098 do {
88099+
88100+#ifdef CONFIG_PAX_SEGMEXEC
88101+ if (vma->vm_mirror) {
88102+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
88103+ vma->vm_mirror->vm_mirror = NULL;
88104+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
88105+ vma->vm_mirror = NULL;
88106+ }
88107+#endif
88108+
88109 vma_rb_erase(vma, &mm->mm_rb);
88110 mm->map_count--;
88111 tail_vma = vma;
88112@@ -2384,14 +2752,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
88113 struct vm_area_struct *new;
88114 int err = -ENOMEM;
88115
88116+#ifdef CONFIG_PAX_SEGMEXEC
88117+ struct vm_area_struct *vma_m, *new_m = NULL;
88118+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
88119+#endif
88120+
88121 if (is_vm_hugetlb_page(vma) && (addr &
88122 ~(huge_page_mask(hstate_vma(vma)))))
88123 return -EINVAL;
88124
88125+#ifdef CONFIG_PAX_SEGMEXEC
88126+ vma_m = pax_find_mirror_vma(vma);
88127+#endif
88128+
88129 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
88130 if (!new)
88131 goto out_err;
88132
88133+#ifdef CONFIG_PAX_SEGMEXEC
88134+ if (vma_m) {
88135+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
88136+ if (!new_m) {
88137+ kmem_cache_free(vm_area_cachep, new);
88138+ goto out_err;
88139+ }
88140+ }
88141+#endif
88142+
88143 /* most fields are the same, copy all, and then fixup */
88144 *new = *vma;
88145
88146@@ -2404,6 +2791,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
88147 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
88148 }
88149
88150+#ifdef CONFIG_PAX_SEGMEXEC
88151+ if (vma_m) {
88152+ *new_m = *vma_m;
88153+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
88154+ new_m->vm_mirror = new;
88155+ new->vm_mirror = new_m;
88156+
88157+ if (new_below)
88158+ new_m->vm_end = addr_m;
88159+ else {
88160+ new_m->vm_start = addr_m;
88161+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
88162+ }
88163+ }
88164+#endif
88165+
88166 pol = mpol_dup(vma_policy(vma));
88167 if (IS_ERR(pol)) {
88168 err = PTR_ERR(pol);
88169@@ -2426,6 +2829,36 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
88170 else
88171 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
88172
88173+#ifdef CONFIG_PAX_SEGMEXEC
88174+ if (!err && vma_m) {
88175+ if (anon_vma_clone(new_m, vma_m))
88176+ goto out_free_mpol;
88177+
88178+ mpol_get(pol);
88179+ vma_set_policy(new_m, pol);
88180+
88181+ if (new_m->vm_file)
88182+ get_file(new_m->vm_file);
88183+
88184+ if (new_m->vm_ops && new_m->vm_ops->open)
88185+ new_m->vm_ops->open(new_m);
88186+
88187+ if (new_below)
88188+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
88189+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
88190+ else
88191+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
88192+
88193+ if (err) {
88194+ if (new_m->vm_ops && new_m->vm_ops->close)
88195+ new_m->vm_ops->close(new_m);
88196+ if (new_m->vm_file)
88197+ fput(new_m->vm_file);
88198+ mpol_put(pol);
88199+ }
88200+ }
88201+#endif
88202+
88203 /* Success. */
88204 if (!err)
88205 return 0;
88206@@ -2435,10 +2868,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
88207 new->vm_ops->close(new);
88208 if (new->vm_file)
88209 fput(new->vm_file);
88210- unlink_anon_vmas(new);
88211 out_free_mpol:
88212 mpol_put(pol);
88213 out_free_vma:
88214+
88215+#ifdef CONFIG_PAX_SEGMEXEC
88216+ if (new_m) {
88217+ unlink_anon_vmas(new_m);
88218+ kmem_cache_free(vm_area_cachep, new_m);
88219+ }
88220+#endif
88221+
88222+ unlink_anon_vmas(new);
88223 kmem_cache_free(vm_area_cachep, new);
88224 out_err:
88225 return err;
88226@@ -2451,6 +2892,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
88227 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
88228 unsigned long addr, int new_below)
88229 {
88230+
88231+#ifdef CONFIG_PAX_SEGMEXEC
88232+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
88233+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
88234+ if (mm->map_count >= sysctl_max_map_count-1)
88235+ return -ENOMEM;
88236+ } else
88237+#endif
88238+
88239 if (mm->map_count >= sysctl_max_map_count)
88240 return -ENOMEM;
88241
88242@@ -2462,11 +2912,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
88243 * work. This now handles partial unmappings.
88244 * Jeremy Fitzhardinge <jeremy@goop.org>
88245 */
88246+#ifdef CONFIG_PAX_SEGMEXEC
88247 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
88248 {
88249+ int ret = __do_munmap(mm, start, len);
88250+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
88251+ return ret;
88252+
88253+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
88254+}
88255+
88256+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
88257+#else
88258+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
88259+#endif
88260+{
88261 unsigned long end;
88262 struct vm_area_struct *vma, *prev, *last;
88263
88264+ /*
88265+ * mm->mmap_sem is required to protect against another thread
88266+ * changing the mappings in case we sleep.
88267+ */
88268+ verify_mm_writelocked(mm);
88269+
88270 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
88271 return -EINVAL;
88272
88273@@ -2541,6 +3010,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
88274 /* Fix up all other VM information */
88275 remove_vma_list(mm, vma);
88276
88277+ track_exec_limit(mm, start, end, 0UL);
88278+
88279 return 0;
88280 }
88281
88282@@ -2549,6 +3020,13 @@ int vm_munmap(unsigned long start, size_t len)
88283 int ret;
88284 struct mm_struct *mm = current->mm;
88285
88286+
88287+#ifdef CONFIG_PAX_SEGMEXEC
88288+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
88289+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
88290+ return -EINVAL;
88291+#endif
88292+
88293 down_write(&mm->mmap_sem);
88294 ret = do_munmap(mm, start, len);
88295 up_write(&mm->mmap_sem);
88296@@ -2562,16 +3040,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
88297 return vm_munmap(addr, len);
88298 }
88299
88300-static inline void verify_mm_writelocked(struct mm_struct *mm)
88301-{
88302-#ifdef CONFIG_DEBUG_VM
88303- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
88304- WARN_ON(1);
88305- up_read(&mm->mmap_sem);
88306- }
88307-#endif
88308-}
88309-
88310 /*
88311 * this is really a simplified "do_mmap". it only handles
88312 * anonymous maps. eventually we may be able to do some
88313@@ -2585,6 +3053,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
88314 struct rb_node ** rb_link, * rb_parent;
88315 pgoff_t pgoff = addr >> PAGE_SHIFT;
88316 int error;
88317+ unsigned long charged;
88318
88319 len = PAGE_ALIGN(len);
88320 if (!len)
88321@@ -2592,16 +3061,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
88322
88323 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
88324
88325+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
88326+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
88327+ flags &= ~VM_EXEC;
88328+
88329+#ifdef CONFIG_PAX_MPROTECT
88330+ if (mm->pax_flags & MF_PAX_MPROTECT)
88331+ flags &= ~VM_MAYEXEC;
88332+#endif
88333+
88334+ }
88335+#endif
88336+
88337 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
88338 if (error & ~PAGE_MASK)
88339 return error;
88340
88341+ charged = len >> PAGE_SHIFT;
88342+
88343 /*
88344 * mlock MCL_FUTURE?
88345 */
88346 if (mm->def_flags & VM_LOCKED) {
88347 unsigned long locked, lock_limit;
88348- locked = len >> PAGE_SHIFT;
88349+ locked = charged;
88350 locked += mm->locked_vm;
88351 lock_limit = rlimit(RLIMIT_MEMLOCK);
88352 lock_limit >>= PAGE_SHIFT;
88353@@ -2618,21 +3101,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
88354 /*
88355 * Clear old maps. this also does some error checking for us
88356 */
88357- munmap_back:
88358 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
88359 if (do_munmap(mm, addr, len))
88360 return -ENOMEM;
88361- goto munmap_back;
88362+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
88363 }
88364
88365 /* Check against address space limits *after* clearing old maps... */
88366- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
88367+ if (!may_expand_vm(mm, charged))
88368 return -ENOMEM;
88369
88370 if (mm->map_count > sysctl_max_map_count)
88371 return -ENOMEM;
88372
88373- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
88374+ if (security_vm_enough_memory_mm(mm, charged))
88375 return -ENOMEM;
88376
88377 /* Can we just expand an old private anonymous mapping? */
88378@@ -2646,7 +3128,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
88379 */
88380 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
88381 if (!vma) {
88382- vm_unacct_memory(len >> PAGE_SHIFT);
88383+ vm_unacct_memory(charged);
88384 return -ENOMEM;
88385 }
88386
88387@@ -2660,9 +3142,10 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
88388 vma_link(mm, vma, prev, rb_link, rb_parent);
88389 out:
88390 perf_event_mmap(vma);
88391- mm->total_vm += len >> PAGE_SHIFT;
88392+ mm->total_vm += charged;
88393 if (flags & VM_LOCKED)
88394- mm->locked_vm += (len >> PAGE_SHIFT);
88395+ mm->locked_vm += charged;
88396+ track_exec_limit(mm, addr, addr + len, flags);
88397 return addr;
88398 }
88399
88400@@ -2724,6 +3207,7 @@ void exit_mmap(struct mm_struct *mm)
88401 while (vma) {
88402 if (vma->vm_flags & VM_ACCOUNT)
88403 nr_accounted += vma_pages(vma);
88404+ vma->vm_mirror = NULL;
88405 vma = remove_vma(vma);
88406 }
88407 vm_unacct_memory(nr_accounted);
88408@@ -2740,6 +3224,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
88409 struct vm_area_struct *prev;
88410 struct rb_node **rb_link, *rb_parent;
88411
88412+#ifdef CONFIG_PAX_SEGMEXEC
88413+ struct vm_area_struct *vma_m = NULL;
88414+#endif
88415+
88416+ if (security_mmap_addr(vma->vm_start))
88417+ return -EPERM;
88418+
88419 /*
88420 * The vm_pgoff of a purely anonymous vma should be irrelevant
88421 * until its first write fault, when page's anon_vma and index
88422@@ -2763,7 +3254,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
88423 security_vm_enough_memory_mm(mm, vma_pages(vma)))
88424 return -ENOMEM;
88425
88426+#ifdef CONFIG_PAX_SEGMEXEC
88427+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
88428+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
88429+ if (!vma_m)
88430+ return -ENOMEM;
88431+ }
88432+#endif
88433+
88434 vma_link(mm, vma, prev, rb_link, rb_parent);
88435+
88436+#ifdef CONFIG_PAX_SEGMEXEC
88437+ if (vma_m)
88438+ BUG_ON(pax_mirror_vma(vma_m, vma));
88439+#endif
88440+
88441 return 0;
88442 }
88443
88444@@ -2783,6 +3288,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
88445 struct mempolicy *pol;
88446 bool faulted_in_anon_vma = true;
88447
88448+ BUG_ON(vma->vm_mirror);
88449+
88450 /*
88451 * If anonymous vma has not yet been faulted, update new pgoff
88452 * to match new location, to increase its chance of merging.
88453@@ -2849,6 +3356,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
88454 return NULL;
88455 }
88456
88457+#ifdef CONFIG_PAX_SEGMEXEC
88458+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
88459+{
88460+ struct vm_area_struct *prev_m;
88461+ struct rb_node **rb_link_m, *rb_parent_m;
88462+ struct mempolicy *pol_m;
88463+
88464+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
88465+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
88466+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
88467+ *vma_m = *vma;
88468+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
88469+ if (anon_vma_clone(vma_m, vma))
88470+ return -ENOMEM;
88471+ pol_m = vma_policy(vma_m);
88472+ mpol_get(pol_m);
88473+ vma_set_policy(vma_m, pol_m);
88474+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
88475+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
88476+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
88477+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
88478+ if (vma_m->vm_file)
88479+ get_file(vma_m->vm_file);
88480+ if (vma_m->vm_ops && vma_m->vm_ops->open)
88481+ vma_m->vm_ops->open(vma_m);
88482+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
88483+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
88484+ vma_m->vm_mirror = vma;
88485+ vma->vm_mirror = vma_m;
88486+ return 0;
88487+}
88488+#endif
88489+
88490 /*
88491 * Return true if the calling process may expand its vm space by the passed
88492 * number of pages
88493@@ -2860,6 +3400,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
88494
88495 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
88496
88497+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
88498 if (cur + npages > lim)
88499 return 0;
88500 return 1;
88501@@ -2930,6 +3471,22 @@ int install_special_mapping(struct mm_struct *mm,
88502 vma->vm_start = addr;
88503 vma->vm_end = addr + len;
88504
88505+#ifdef CONFIG_PAX_MPROTECT
88506+ if (mm->pax_flags & MF_PAX_MPROTECT) {
88507+#ifndef CONFIG_PAX_MPROTECT_COMPAT
88508+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
88509+ return -EPERM;
88510+ if (!(vm_flags & VM_EXEC))
88511+ vm_flags &= ~VM_MAYEXEC;
88512+#else
88513+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
88514+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
88515+#endif
88516+ else
88517+ vm_flags &= ~VM_MAYWRITE;
88518+ }
88519+#endif
88520+
88521 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
88522 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
88523
88524diff --git a/mm/mprotect.c b/mm/mprotect.c
88525index 94722a4..e661e29 100644
88526--- a/mm/mprotect.c
88527+++ b/mm/mprotect.c
88528@@ -23,10 +23,18 @@
88529 #include <linux/mmu_notifier.h>
88530 #include <linux/migrate.h>
88531 #include <linux/perf_event.h>
88532+#include <linux/sched/sysctl.h>
88533+
88534+#ifdef CONFIG_PAX_MPROTECT
88535+#include <linux/elf.h>
88536+#include <linux/binfmts.h>
88537+#endif
88538+
88539 #include <asm/uaccess.h>
88540 #include <asm/pgtable.h>
88541 #include <asm/cacheflush.h>
88542 #include <asm/tlbflush.h>
88543+#include <asm/mmu_context.h>
88544
88545 #ifndef pgprot_modify
88546 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
88547@@ -233,6 +241,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
88548 return pages;
88549 }
88550
88551+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
88552+/* called while holding the mmap semaphor for writing except stack expansion */
88553+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
88554+{
88555+ unsigned long oldlimit, newlimit = 0UL;
88556+
88557+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
88558+ return;
88559+
88560+ spin_lock(&mm->page_table_lock);
88561+ oldlimit = mm->context.user_cs_limit;
88562+ if ((prot & VM_EXEC) && oldlimit < end)
88563+ /* USER_CS limit moved up */
88564+ newlimit = end;
88565+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
88566+ /* USER_CS limit moved down */
88567+ newlimit = start;
88568+
88569+ if (newlimit) {
88570+ mm->context.user_cs_limit = newlimit;
88571+
88572+#ifdef CONFIG_SMP
88573+ wmb();
88574+ cpus_clear(mm->context.cpu_user_cs_mask);
88575+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
88576+#endif
88577+
88578+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
88579+ }
88580+ spin_unlock(&mm->page_table_lock);
88581+ if (newlimit == end) {
88582+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
88583+
88584+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
88585+ if (is_vm_hugetlb_page(vma))
88586+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
88587+ else
88588+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
88589+ }
88590+}
88591+#endif
88592+
88593 int
88594 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
88595 unsigned long start, unsigned long end, unsigned long newflags)
88596@@ -245,11 +295,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
88597 int error;
88598 int dirty_accountable = 0;
88599
88600+#ifdef CONFIG_PAX_SEGMEXEC
88601+ struct vm_area_struct *vma_m = NULL;
88602+ unsigned long start_m, end_m;
88603+
88604+ start_m = start + SEGMEXEC_TASK_SIZE;
88605+ end_m = end + SEGMEXEC_TASK_SIZE;
88606+#endif
88607+
88608 if (newflags == oldflags) {
88609 *pprev = vma;
88610 return 0;
88611 }
88612
88613+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
88614+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
88615+
88616+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
88617+ return -ENOMEM;
88618+
88619+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
88620+ return -ENOMEM;
88621+ }
88622+
88623 /*
88624 * If we make a private mapping writable we increase our commit;
88625 * but (without finer accounting) cannot reduce our commit if we
88626@@ -266,6 +334,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
88627 }
88628 }
88629
88630+#ifdef CONFIG_PAX_SEGMEXEC
88631+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
88632+ if (start != vma->vm_start) {
88633+ error = split_vma(mm, vma, start, 1);
88634+ if (error)
88635+ goto fail;
88636+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
88637+ *pprev = (*pprev)->vm_next;
88638+ }
88639+
88640+ if (end != vma->vm_end) {
88641+ error = split_vma(mm, vma, end, 0);
88642+ if (error)
88643+ goto fail;
88644+ }
88645+
88646+ if (pax_find_mirror_vma(vma)) {
88647+ error = __do_munmap(mm, start_m, end_m - start_m);
88648+ if (error)
88649+ goto fail;
88650+ } else {
88651+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
88652+ if (!vma_m) {
88653+ error = -ENOMEM;
88654+ goto fail;
88655+ }
88656+ vma->vm_flags = newflags;
88657+ error = pax_mirror_vma(vma_m, vma);
88658+ if (error) {
88659+ vma->vm_flags = oldflags;
88660+ goto fail;
88661+ }
88662+ }
88663+ }
88664+#endif
88665+
88666 /*
88667 * First try to merge with previous and/or next vma.
88668 */
88669@@ -296,9 +400,21 @@ success:
88670 * vm_flags and vm_page_prot are protected by the mmap_sem
88671 * held in write mode.
88672 */
88673+
88674+#ifdef CONFIG_PAX_SEGMEXEC
88675+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
88676+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
88677+#endif
88678+
88679 vma->vm_flags = newflags;
88680+
88681+#ifdef CONFIG_PAX_MPROTECT
88682+ if (mm->binfmt && mm->binfmt->handle_mprotect)
88683+ mm->binfmt->handle_mprotect(vma, newflags);
88684+#endif
88685+
88686 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
88687- vm_get_page_prot(newflags));
88688+ vm_get_page_prot(vma->vm_flags));
88689
88690 if (vma_wants_writenotify(vma)) {
88691 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
88692@@ -337,6 +453,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
88693 end = start + len;
88694 if (end <= start)
88695 return -ENOMEM;
88696+
88697+#ifdef CONFIG_PAX_SEGMEXEC
88698+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
88699+ if (end > SEGMEXEC_TASK_SIZE)
88700+ return -EINVAL;
88701+ } else
88702+#endif
88703+
88704+ if (end > TASK_SIZE)
88705+ return -EINVAL;
88706+
88707 if (!arch_validate_prot(prot))
88708 return -EINVAL;
88709
88710@@ -344,7 +471,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
88711 /*
88712 * Does the application expect PROT_READ to imply PROT_EXEC:
88713 */
88714- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
88715+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
88716 prot |= PROT_EXEC;
88717
88718 vm_flags = calc_vm_prot_bits(prot);
88719@@ -376,6 +503,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
88720 if (start > vma->vm_start)
88721 prev = vma;
88722
88723+#ifdef CONFIG_PAX_MPROTECT
88724+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
88725+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
88726+#endif
88727+
88728 for (nstart = start ; ; ) {
88729 unsigned long newflags;
88730
88731@@ -386,6 +518,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
88732
88733 /* newflags >> 4 shift VM_MAY% in place of VM_% */
88734 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
88735+ if (prot & (PROT_WRITE | PROT_EXEC))
88736+ gr_log_rwxmprotect(vma);
88737+
88738+ error = -EACCES;
88739+ goto out;
88740+ }
88741+
88742+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
88743 error = -EACCES;
88744 goto out;
88745 }
88746@@ -400,6 +540,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
88747 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
88748 if (error)
88749 goto out;
88750+
88751+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
88752+
88753 nstart = tmp;
88754
88755 if (nstart < prev->vm_end)
88756diff --git a/mm/mremap.c b/mm/mremap.c
88757index 0843feb..5607f47 100644
88758--- a/mm/mremap.c
88759+++ b/mm/mremap.c
88760@@ -25,6 +25,7 @@
88761 #include <asm/uaccess.h>
88762 #include <asm/cacheflush.h>
88763 #include <asm/tlbflush.h>
88764+#include <asm/pgalloc.h>
88765
88766 #include "internal.h"
88767
88768@@ -62,8 +63,10 @@ static pmd_t *alloc_new_pmd(struct mm_struct *mm, struct vm_area_struct *vma,
88769 return NULL;
88770
88771 pmd = pmd_alloc(mm, pud, addr);
88772- if (!pmd)
88773+ if (!pmd) {
88774+ pud_free(mm, pud);
88775 return NULL;
88776+ }
88777
88778 VM_BUG_ON(pmd_trans_huge(*pmd));
88779
88780@@ -144,6 +147,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
88781 continue;
88782 pte = ptep_get_and_clear(mm, old_addr, old_pte);
88783 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
88784+
88785+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
88786+ if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
88787+ pte = pte_exprotect(pte);
88788+#endif
88789+
88790 pte = move_soft_dirty_pte(pte);
88791 set_pte_at(mm, new_addr, new_pte, pte);
88792 }
88793@@ -337,6 +346,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
88794 if (is_vm_hugetlb_page(vma))
88795 goto Einval;
88796
88797+#ifdef CONFIG_PAX_SEGMEXEC
88798+ if (pax_find_mirror_vma(vma))
88799+ goto Einval;
88800+#endif
88801+
88802 /* We can't remap across vm area boundaries */
88803 if (old_len > vma->vm_end - addr)
88804 goto Efault;
88805@@ -392,20 +406,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
88806 unsigned long ret = -EINVAL;
88807 unsigned long charged = 0;
88808 unsigned long map_flags;
88809+ unsigned long pax_task_size = TASK_SIZE;
88810
88811 if (new_addr & ~PAGE_MASK)
88812 goto out;
88813
88814- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
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 > TASK_SIZE || new_addr > pax_task_size - new_len)
88823 goto out;
88824
88825 /* Check if the location we're moving into overlaps the
88826 * old location at all, and fail if it does.
88827 */
88828- if ((new_addr <= addr) && (new_addr+new_len) > addr)
88829- goto out;
88830-
88831- if ((addr <= new_addr) && (addr+old_len) > new_addr)
88832+ if (addr + old_len > new_addr && new_addr + new_len > addr)
88833 goto out;
88834
88835 ret = do_munmap(mm, new_addr, new_len);
88836@@ -474,6 +493,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
88837 unsigned long ret = -EINVAL;
88838 unsigned long charged = 0;
88839 bool locked = false;
88840+ unsigned long pax_task_size = TASK_SIZE;
88841
88842 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
88843 return ret;
88844@@ -495,6 +515,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
88845 if (!new_len)
88846 return ret;
88847
88848+#ifdef CONFIG_PAX_SEGMEXEC
88849+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
88850+ pax_task_size = SEGMEXEC_TASK_SIZE;
88851+#endif
88852+
88853+ pax_task_size -= PAGE_SIZE;
88854+
88855+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
88856+ old_len > pax_task_size || addr > pax_task_size-old_len)
88857+ return ret;
88858+
88859 down_write(&current->mm->mmap_sem);
88860
88861 if (flags & MREMAP_FIXED) {
88862@@ -545,6 +576,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
88863 new_addr = addr;
88864 }
88865 ret = addr;
88866+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
88867 goto out;
88868 }
88869 }
88870@@ -568,7 +600,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
88871 goto out;
88872 }
88873
88874+ map_flags = vma->vm_flags;
88875 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
88876+ if (!(ret & ~PAGE_MASK)) {
88877+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
88878+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
88879+ }
88880 }
88881 out:
88882 if (ret & ~PAGE_MASK)
88883diff --git a/mm/nommu.c b/mm/nommu.c
88884index ecd1f15..77039bd 100644
88885--- a/mm/nommu.c
88886+++ b/mm/nommu.c
88887@@ -64,7 +64,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
88888 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
88889 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
88890 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
88891-int heap_stack_gap = 0;
88892
88893 atomic_long_t mmap_pages_allocated;
88894
88895@@ -844,15 +843,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
88896 EXPORT_SYMBOL(find_vma);
88897
88898 /*
88899- * find a VMA
88900- * - we don't extend stack VMAs under NOMMU conditions
88901- */
88902-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
88903-{
88904- return find_vma(mm, addr);
88905-}
88906-
88907-/*
88908 * expand a stack to a given address
88909 * - not supported under NOMMU conditions
88910 */
88911@@ -1563,6 +1553,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
88912
88913 /* most fields are the same, copy all, and then fixup */
88914 *new = *vma;
88915+ INIT_LIST_HEAD(&new->anon_vma_chain);
88916 *region = *vma->vm_region;
88917 new->vm_region = region;
88918
88919@@ -1993,8 +1984,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
88920 }
88921 EXPORT_SYMBOL(generic_file_remap_pages);
88922
88923-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
88924- unsigned long addr, void *buf, int len, int write)
88925+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
88926+ unsigned long addr, void *buf, size_t len, int write)
88927 {
88928 struct vm_area_struct *vma;
88929
88930@@ -2035,8 +2026,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
88931 *
88932 * The caller must hold a reference on @mm.
88933 */
88934-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
88935- void *buf, int len, int write)
88936+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
88937+ void *buf, size_t len, int write)
88938 {
88939 return __access_remote_vm(NULL, mm, addr, buf, len, write);
88940 }
88941@@ -2045,7 +2036,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
88942 * Access another process' address space.
88943 * - source/target buffer must be kernel space
88944 */
88945-int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
88946+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
88947 {
88948 struct mm_struct *mm;
88949
88950diff --git a/mm/page-writeback.c b/mm/page-writeback.c
88951index 3f0c895..60cd104 100644
88952--- a/mm/page-writeback.c
88953+++ b/mm/page-writeback.c
88954@@ -659,7 +659,7 @@ unsigned long bdi_dirty_limit(struct backing_dev_info *bdi, unsigned long dirty)
88955 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
88956 * - the bdi dirty thresh drops quickly due to change of JBOD workload
88957 */
88958-static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
88959+static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
88960 unsigned long thresh,
88961 unsigned long bg_thresh,
88962 unsigned long dirty,
88963diff --git a/mm/page_alloc.c b/mm/page_alloc.c
88964index b100255..fba1254 100644
88965--- a/mm/page_alloc.c
88966+++ b/mm/page_alloc.c
88967@@ -60,6 +60,7 @@
88968 #include <linux/page-debug-flags.h>
88969 #include <linux/hugetlb.h>
88970 #include <linux/sched/rt.h>
88971+#include <linux/random.h>
88972
88973 #include <asm/sections.h>
88974 #include <asm/tlbflush.h>
88975@@ -353,7 +354,7 @@ out:
88976 * This usage means that zero-order pages may not be compound.
88977 */
88978
88979-static void free_compound_page(struct page *page)
88980+void free_compound_page(struct page *page)
88981 {
88982 __free_pages_ok(page, compound_order(page));
88983 }
88984@@ -710,6 +711,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
88985 int i;
88986 int bad = 0;
88987
88988+#ifdef CONFIG_PAX_MEMORY_SANITIZE
88989+ unsigned long index = 1UL << order;
88990+#endif
88991+
88992 trace_mm_page_free(page, order);
88993 kmemcheck_free_shadow(page, order);
88994
88995@@ -725,6 +730,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
88996 debug_check_no_obj_freed(page_address(page),
88997 PAGE_SIZE << order);
88998 }
88999+
89000+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89001+ for (; index; --index)
89002+ sanitize_highpage(page + index - 1);
89003+#endif
89004+
89005 arch_free_page(page, order);
89006 kernel_map_pages(page, 1 << order, 0);
89007
89008@@ -747,6 +758,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
89009 local_irq_restore(flags);
89010 }
89011
89012+#ifdef CONFIG_PAX_LATENT_ENTROPY
89013+bool __meminitdata extra_latent_entropy;
89014+
89015+static int __init setup_pax_extra_latent_entropy(char *str)
89016+{
89017+ extra_latent_entropy = true;
89018+ return 0;
89019+}
89020+early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
89021+
89022+volatile u64 latent_entropy;
89023+EXPORT_SYMBOL(latent_entropy);
89024+#endif
89025+
89026 void __init __free_pages_bootmem(struct page *page, unsigned int order)
89027 {
89028 unsigned int nr_pages = 1 << order;
89029@@ -762,6 +787,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
89030 set_page_count(p, 0);
89031 }
89032
89033+#ifdef CONFIG_PAX_LATENT_ENTROPY
89034+ if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
89035+ u64 hash = 0;
89036+ size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
89037+ const u64 *data = lowmem_page_address(page);
89038+
89039+ for (index = 0; index < end; index++)
89040+ hash ^= hash + data[index];
89041+ latent_entropy ^= hash;
89042+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
89043+ }
89044+#endif
89045+
89046 page_zone(page)->managed_pages += 1 << order;
89047 set_page_refcounted(page);
89048 __free_pages(page, order);
89049@@ -867,8 +905,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
89050 arch_alloc_page(page, order);
89051 kernel_map_pages(page, 1 << order, 1);
89052
89053+#ifndef CONFIG_PAX_MEMORY_SANITIZE
89054 if (gfp_flags & __GFP_ZERO)
89055 prep_zero_page(page, order, gfp_flags);
89056+#endif
89057
89058 if (order && (gfp_flags & __GFP_COMP))
89059 prep_compound_page(page, order);
89060diff --git a/mm/page_io.c b/mm/page_io.c
89061index ba05b64..ef2f314 100644
89062--- a/mm/page_io.c
89063+++ b/mm/page_io.c
89064@@ -260,7 +260,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
89065 struct file *swap_file = sis->swap_file;
89066 struct address_space *mapping = swap_file->f_mapping;
89067 struct iovec iov = {
89068- .iov_base = kmap(page),
89069+ .iov_base = (void __force_user *)kmap(page),
89070 .iov_len = PAGE_SIZE,
89071 };
89072
89073diff --git a/mm/percpu.c b/mm/percpu.c
89074index 8c8e08f..73a5cda 100644
89075--- a/mm/percpu.c
89076+++ b/mm/percpu.c
89077@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
89078 static unsigned int pcpu_high_unit_cpu __read_mostly;
89079
89080 /* the address of the first chunk which starts with the kernel static area */
89081-void *pcpu_base_addr __read_mostly;
89082+void *pcpu_base_addr __read_only;
89083 EXPORT_SYMBOL_GPL(pcpu_base_addr);
89084
89085 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
89086diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
89087index fd26d04..0cea1b0 100644
89088--- a/mm/process_vm_access.c
89089+++ b/mm/process_vm_access.c
89090@@ -13,6 +13,7 @@
89091 #include <linux/uio.h>
89092 #include <linux/sched.h>
89093 #include <linux/highmem.h>
89094+#include <linux/security.h>
89095 #include <linux/ptrace.h>
89096 #include <linux/slab.h>
89097 #include <linux/syscalls.h>
89098@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
89099 size_t iov_l_curr_offset = 0;
89100 ssize_t iov_len;
89101
89102+ return -ENOSYS; // PaX: until properly audited
89103+
89104 /*
89105 * Work out how many pages of struct pages we're going to need
89106 * when eventually calling get_user_pages
89107 */
89108 for (i = 0; i < riovcnt; i++) {
89109 iov_len = rvec[i].iov_len;
89110- if (iov_len > 0) {
89111- nr_pages_iov = ((unsigned long)rvec[i].iov_base
89112- + iov_len)
89113- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
89114- / PAGE_SIZE + 1;
89115- nr_pages = max(nr_pages, nr_pages_iov);
89116- }
89117+ if (iov_len <= 0)
89118+ continue;
89119+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
89120+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
89121+ nr_pages = max(nr_pages, nr_pages_iov);
89122 }
89123
89124 if (nr_pages == 0)
89125@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
89126 goto free_proc_pages;
89127 }
89128
89129+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
89130+ rc = -EPERM;
89131+ goto put_task_struct;
89132+ }
89133+
89134 mm = mm_access(task, PTRACE_MODE_ATTACH);
89135 if (!mm || IS_ERR(mm)) {
89136 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
89137diff --git a/mm/rmap.c b/mm/rmap.c
89138index b2e29ac..4168491 100644
89139--- a/mm/rmap.c
89140+++ b/mm/rmap.c
89141@@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
89142 struct anon_vma *anon_vma = vma->anon_vma;
89143 struct anon_vma_chain *avc;
89144
89145+#ifdef CONFIG_PAX_SEGMEXEC
89146+ struct anon_vma_chain *avc_m = NULL;
89147+#endif
89148+
89149 might_sleep();
89150 if (unlikely(!anon_vma)) {
89151 struct mm_struct *mm = vma->vm_mm;
89152@@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
89153 if (!avc)
89154 goto out_enomem;
89155
89156+#ifdef CONFIG_PAX_SEGMEXEC
89157+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
89158+ if (!avc_m)
89159+ goto out_enomem_free_avc;
89160+#endif
89161+
89162 anon_vma = find_mergeable_anon_vma(vma);
89163 allocated = NULL;
89164 if (!anon_vma) {
89165@@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
89166 /* page_table_lock to protect against threads */
89167 spin_lock(&mm->page_table_lock);
89168 if (likely(!vma->anon_vma)) {
89169+
89170+#ifdef CONFIG_PAX_SEGMEXEC
89171+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
89172+
89173+ if (vma_m) {
89174+ BUG_ON(vma_m->anon_vma);
89175+ vma_m->anon_vma = anon_vma;
89176+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
89177+ avc_m = NULL;
89178+ }
89179+#endif
89180+
89181 vma->anon_vma = anon_vma;
89182 anon_vma_chain_link(vma, avc, anon_vma);
89183 allocated = NULL;
89184@@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
89185
89186 if (unlikely(allocated))
89187 put_anon_vma(allocated);
89188+
89189+#ifdef CONFIG_PAX_SEGMEXEC
89190+ if (unlikely(avc_m))
89191+ anon_vma_chain_free(avc_m);
89192+#endif
89193+
89194 if (unlikely(avc))
89195 anon_vma_chain_free(avc);
89196 }
89197 return 0;
89198
89199 out_enomem_free_avc:
89200+
89201+#ifdef CONFIG_PAX_SEGMEXEC
89202+ if (avc_m)
89203+ anon_vma_chain_free(avc_m);
89204+#endif
89205+
89206 anon_vma_chain_free(avc);
89207 out_enomem:
89208 return -ENOMEM;
89209@@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
89210 * Attach the anon_vmas from src to dst.
89211 * Returns 0 on success, -ENOMEM on failure.
89212 */
89213-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
89214+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
89215 {
89216 struct anon_vma_chain *avc, *pavc;
89217 struct anon_vma *root = NULL;
89218@@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
89219 * the corresponding VMA in the parent process is attached to.
89220 * Returns 0 on success, non-zero on failure.
89221 */
89222-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
89223+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
89224 {
89225 struct anon_vma_chain *avc;
89226 struct anon_vma *anon_vma;
89227@@ -373,8 +407,10 @@ static void anon_vma_ctor(void *data)
89228 void __init anon_vma_init(void)
89229 {
89230 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
89231- 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
89232- anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
89233+ 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
89234+ anon_vma_ctor);
89235+ anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
89236+ SLAB_PANIC|SLAB_NO_SANITIZE);
89237 }
89238
89239 /*
89240diff --git a/mm/shmem.c b/mm/shmem.c
89241index e43dc55..930e3a2 100644
89242--- a/mm/shmem.c
89243+++ b/mm/shmem.c
89244@@ -33,7 +33,7 @@
89245 #include <linux/swap.h>
89246 #include <linux/aio.h>
89247
89248-static struct vfsmount *shm_mnt;
89249+struct vfsmount *shm_mnt;
89250
89251 #ifdef CONFIG_SHMEM
89252 /*
89253@@ -77,7 +77,7 @@ static struct vfsmount *shm_mnt;
89254 #define BOGO_DIRENT_SIZE 20
89255
89256 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
89257-#define SHORT_SYMLINK_LEN 128
89258+#define SHORT_SYMLINK_LEN 64
89259
89260 /*
89261 * shmem_fallocate and shmem_writepage communicate via inode->i_private
89262@@ -2232,6 +2232,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
89263 static int shmem_xattr_validate(const char *name)
89264 {
89265 struct { const char *prefix; size_t len; } arr[] = {
89266+
89267+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
89268+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
89269+#endif
89270+
89271 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
89272 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
89273 };
89274@@ -2287,6 +2292,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
89275 if (err)
89276 return err;
89277
89278+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
89279+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
89280+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
89281+ return -EOPNOTSUPP;
89282+ if (size > 8)
89283+ return -EINVAL;
89284+ }
89285+#endif
89286+
89287 return simple_xattr_set(&info->xattrs, name, value, size, flags);
89288 }
89289
89290@@ -2599,8 +2613,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
89291 int err = -ENOMEM;
89292
89293 /* Round up to L1_CACHE_BYTES to resist false sharing */
89294- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
89295- L1_CACHE_BYTES), GFP_KERNEL);
89296+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
89297 if (!sbinfo)
89298 return -ENOMEM;
89299
89300diff --git a/mm/slab.c b/mm/slab.c
89301index 2580db0..0523956 100644
89302--- a/mm/slab.c
89303+++ b/mm/slab.c
89304@@ -366,10 +366,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
89305 if ((x)->max_freeable < i) \
89306 (x)->max_freeable = i; \
89307 } while (0)
89308-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
89309-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
89310-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
89311-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
89312+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
89313+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
89314+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
89315+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
89316+#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
89317+#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
89318 #else
89319 #define STATS_INC_ACTIVE(x) do { } while (0)
89320 #define STATS_DEC_ACTIVE(x) do { } while (0)
89321@@ -386,6 +388,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
89322 #define STATS_INC_ALLOCMISS(x) do { } while (0)
89323 #define STATS_INC_FREEHIT(x) do { } while (0)
89324 #define STATS_INC_FREEMISS(x) do { } while (0)
89325+#define STATS_INC_SANITIZED(x) do { } while (0)
89326+#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
89327 #endif
89328
89329 #if DEBUG
89330@@ -477,7 +481,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
89331 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
89332 */
89333 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
89334- const struct slab *slab, void *obj)
89335+ const struct slab *slab, const void *obj)
89336 {
89337 u32 offset = (obj - slab->s_mem);
89338 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
89339@@ -1571,12 +1575,12 @@ void __init kmem_cache_init(void)
89340 */
89341
89342 kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
89343- kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
89344+ kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
89345
89346 if (INDEX_AC != INDEX_NODE)
89347 kmalloc_caches[INDEX_NODE] =
89348 create_kmalloc_cache("kmalloc-node",
89349- kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
89350+ kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
89351
89352 slab_early_init = 0;
89353
89354@@ -3577,6 +3581,21 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
89355 struct array_cache *ac = cpu_cache_get(cachep);
89356
89357 check_irq_off();
89358+
89359+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89360+ if (pax_sanitize_slab) {
89361+ if (!(cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))) {
89362+ memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
89363+
89364+ if (cachep->ctor)
89365+ cachep->ctor(objp);
89366+
89367+ STATS_INC_SANITIZED(cachep);
89368+ } else
89369+ STATS_INC_NOT_SANITIZED(cachep);
89370+ }
89371+#endif
89372+
89373 kmemleak_free_recursive(objp, cachep->flags);
89374 objp = cache_free_debugcheck(cachep, objp, caller);
89375
89376@@ -3805,6 +3824,7 @@ void kfree(const void *objp)
89377
89378 if (unlikely(ZERO_OR_NULL_PTR(objp)))
89379 return;
89380+ VM_BUG_ON(!virt_addr_valid(objp));
89381 local_irq_save(flags);
89382 kfree_debugcheck(objp);
89383 c = virt_to_cache(objp);
89384@@ -4246,14 +4266,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
89385 }
89386 /* cpu stats */
89387 {
89388- unsigned long allochit = atomic_read(&cachep->allochit);
89389- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
89390- unsigned long freehit = atomic_read(&cachep->freehit);
89391- unsigned long freemiss = atomic_read(&cachep->freemiss);
89392+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
89393+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
89394+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
89395+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
89396
89397 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
89398 allochit, allocmiss, freehit, freemiss);
89399 }
89400+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89401+ {
89402+ unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
89403+ unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
89404+
89405+ seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
89406+ }
89407+#endif
89408 #endif
89409 }
89410
89411@@ -4471,13 +4499,71 @@ static const struct file_operations proc_slabstats_operations = {
89412 static int __init slab_proc_init(void)
89413 {
89414 #ifdef CONFIG_DEBUG_SLAB_LEAK
89415- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
89416+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
89417 #endif
89418 return 0;
89419 }
89420 module_init(slab_proc_init);
89421 #endif
89422
89423+bool is_usercopy_object(const void *ptr)
89424+{
89425+ struct page *page;
89426+ struct kmem_cache *cachep;
89427+
89428+ if (ZERO_OR_NULL_PTR(ptr))
89429+ return false;
89430+
89431+ if (!slab_is_available())
89432+ return false;
89433+
89434+ if (!virt_addr_valid(ptr))
89435+ return false;
89436+
89437+ page = virt_to_head_page(ptr);
89438+
89439+ if (!PageSlab(page))
89440+ return false;
89441+
89442+ cachep = page->slab_cache;
89443+ return cachep->flags & SLAB_USERCOPY;
89444+}
89445+
89446+#ifdef CONFIG_PAX_USERCOPY
89447+const char *check_heap_object(const void *ptr, unsigned long n)
89448+{
89449+ struct page *page;
89450+ struct kmem_cache *cachep;
89451+ struct slab *slabp;
89452+ unsigned int objnr;
89453+ unsigned long offset;
89454+
89455+ if (ZERO_OR_NULL_PTR(ptr))
89456+ return "<null>";
89457+
89458+ if (!virt_addr_valid(ptr))
89459+ return NULL;
89460+
89461+ page = virt_to_head_page(ptr);
89462+
89463+ if (!PageSlab(page))
89464+ return NULL;
89465+
89466+ cachep = page->slab_cache;
89467+ if (!(cachep->flags & SLAB_USERCOPY))
89468+ return cachep->name;
89469+
89470+ slabp = page->slab_page;
89471+ objnr = obj_to_index(cachep, slabp, ptr);
89472+ BUG_ON(objnr >= cachep->num);
89473+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
89474+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
89475+ return NULL;
89476+
89477+ return cachep->name;
89478+}
89479+#endif
89480+
89481 /**
89482 * ksize - get the actual amount of memory allocated for a given object
89483 * @objp: Pointer to the object
89484diff --git a/mm/slab.h b/mm/slab.h
89485index a535033..2f98fe5 100644
89486--- a/mm/slab.h
89487+++ b/mm/slab.h
89488@@ -32,6 +32,15 @@ extern struct list_head slab_caches;
89489 /* The slab cache that manages slab cache information */
89490 extern struct kmem_cache *kmem_cache;
89491
89492+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89493+#ifdef CONFIG_X86_64
89494+#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
89495+#else
89496+#define PAX_MEMORY_SANITIZE_VALUE '\xff'
89497+#endif
89498+extern bool pax_sanitize_slab;
89499+#endif
89500+
89501 unsigned long calculate_alignment(unsigned long flags,
89502 unsigned long align, unsigned long size);
89503
89504@@ -67,7 +76,8 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
89505
89506 /* Legal flag mask for kmem_cache_create(), for various configurations */
89507 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
89508- SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
89509+ SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
89510+ SLAB_USERCOPY | SLAB_NO_SANITIZE)
89511
89512 #if defined(CONFIG_DEBUG_SLAB)
89513 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
89514@@ -231,6 +241,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
89515 return s;
89516
89517 page = virt_to_head_page(x);
89518+
89519+ BUG_ON(!PageSlab(page));
89520+
89521 cachep = page->slab_cache;
89522 if (slab_equal_or_root(cachep, s))
89523 return cachep;
89524diff --git a/mm/slab_common.c b/mm/slab_common.c
89525index 538bade..36fed99 100644
89526--- a/mm/slab_common.c
89527+++ b/mm/slab_common.c
89528@@ -22,11 +22,22 @@
89529
89530 #include "slab.h"
89531
89532-enum slab_state slab_state;
89533+enum slab_state slab_state __read_only;
89534 LIST_HEAD(slab_caches);
89535 DEFINE_MUTEX(slab_mutex);
89536 struct kmem_cache *kmem_cache;
89537
89538+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89539+bool pax_sanitize_slab __read_only = true;
89540+static int __init pax_sanitize_slab_setup(char *str)
89541+{
89542+ pax_sanitize_slab = !!simple_strtol(str, NULL, 0);
89543+ printk("%sabled PaX slab sanitization\n", pax_sanitize_slab ? "En" : "Dis");
89544+ return 1;
89545+}
89546+__setup("pax_sanitize_slab=", pax_sanitize_slab_setup);
89547+#endif
89548+
89549 #ifdef CONFIG_DEBUG_VM
89550 static int kmem_cache_sanity_check(struct mem_cgroup *memcg, const char *name,
89551 size_t size)
89552@@ -209,7 +220,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
89553
89554 err = __kmem_cache_create(s, flags);
89555 if (!err) {
89556- s->refcount = 1;
89557+ atomic_set(&s->refcount, 1);
89558 list_add(&s->list, &slab_caches);
89559 memcg_cache_list_add(memcg, s);
89560 } else {
89561@@ -255,8 +266,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
89562
89563 get_online_cpus();
89564 mutex_lock(&slab_mutex);
89565- s->refcount--;
89566- if (!s->refcount) {
89567+ if (atomic_dec_and_test(&s->refcount)) {
89568 list_del(&s->list);
89569
89570 if (!__kmem_cache_shutdown(s)) {
89571@@ -302,7 +312,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
89572 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
89573 name, size, err);
89574
89575- s->refcount = -1; /* Exempt from merging for now */
89576+ atomic_set(&s->refcount, -1); /* Exempt from merging for now */
89577 }
89578
89579 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
89580@@ -315,7 +325,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
89581
89582 create_boot_cache(s, name, size, flags);
89583 list_add(&s->list, &slab_caches);
89584- s->refcount = 1;
89585+ atomic_set(&s->refcount, 1);
89586 return s;
89587 }
89588
89589@@ -327,6 +337,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
89590 EXPORT_SYMBOL(kmalloc_dma_caches);
89591 #endif
89592
89593+#ifdef CONFIG_PAX_USERCOPY_SLABS
89594+struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
89595+EXPORT_SYMBOL(kmalloc_usercopy_caches);
89596+#endif
89597+
89598 /*
89599 * Conversion table for small slabs sizes / 8 to the index in the
89600 * kmalloc array. This is necessary for slabs < 192 since we have non power
89601@@ -391,6 +406,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
89602 return kmalloc_dma_caches[index];
89603
89604 #endif
89605+
89606+#ifdef CONFIG_PAX_USERCOPY_SLABS
89607+ if (unlikely((flags & GFP_USERCOPY)))
89608+ return kmalloc_usercopy_caches[index];
89609+
89610+#endif
89611+
89612 return kmalloc_caches[index];
89613 }
89614
89615@@ -447,7 +469,7 @@ void __init create_kmalloc_caches(unsigned long flags)
89616 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
89617 if (!kmalloc_caches[i]) {
89618 kmalloc_caches[i] = create_kmalloc_cache(NULL,
89619- 1 << i, flags);
89620+ 1 << i, SLAB_USERCOPY | flags);
89621 }
89622
89623 /*
89624@@ -456,10 +478,10 @@ void __init create_kmalloc_caches(unsigned long flags)
89625 * earlier power of two caches
89626 */
89627 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
89628- kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
89629+ kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
89630
89631 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
89632- kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
89633+ kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
89634 }
89635
89636 /* Kmalloc array is now usable */
89637@@ -492,6 +514,23 @@ void __init create_kmalloc_caches(unsigned long flags)
89638 }
89639 }
89640 #endif
89641+
89642+#ifdef CONFIG_PAX_USERCOPY_SLABS
89643+ for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
89644+ struct kmem_cache *s = kmalloc_caches[i];
89645+
89646+ if (s) {
89647+ int size = kmalloc_size(i);
89648+ char *n = kasprintf(GFP_NOWAIT,
89649+ "usercopy-kmalloc-%d", size);
89650+
89651+ BUG_ON(!n);
89652+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
89653+ size, SLAB_USERCOPY | flags);
89654+ }
89655+ }
89656+#endif
89657+
89658 }
89659 #endif /* !CONFIG_SLOB */
89660
89661@@ -523,6 +562,9 @@ void print_slabinfo_header(struct seq_file *m)
89662 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
89663 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
89664 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
89665+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89666+ seq_puts(m, " : pax <sanitized> <not_sanitized>");
89667+#endif
89668 #endif
89669 seq_putc(m, '\n');
89670 }
89671diff --git a/mm/slob.c b/mm/slob.c
89672index 91bd3f2..e2f549e 100644
89673--- a/mm/slob.c
89674+++ b/mm/slob.c
89675@@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
89676 /*
89677 * Return the size of a slob block.
89678 */
89679-static slobidx_t slob_units(slob_t *s)
89680+static slobidx_t slob_units(const slob_t *s)
89681 {
89682 if (s->units > 0)
89683 return s->units;
89684@@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
89685 /*
89686 * Return the next free slob block pointer after this one.
89687 */
89688-static slob_t *slob_next(slob_t *s)
89689+static slob_t *slob_next(const slob_t *s)
89690 {
89691 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
89692 slobidx_t next;
89693@@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
89694 /*
89695 * Returns true if s is the last free block in its page.
89696 */
89697-static int slob_last(slob_t *s)
89698+static int slob_last(const slob_t *s)
89699 {
89700 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
89701 }
89702
89703-static void *slob_new_pages(gfp_t gfp, int order, int node)
89704+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
89705 {
89706- void *page;
89707+ struct page *page;
89708
89709 #ifdef CONFIG_NUMA
89710 if (node != NUMA_NO_NODE)
89711@@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
89712 if (!page)
89713 return NULL;
89714
89715- return page_address(page);
89716+ __SetPageSlab(page);
89717+ return page;
89718 }
89719
89720-static void slob_free_pages(void *b, int order)
89721+static void slob_free_pages(struct page *sp, int order)
89722 {
89723 if (current->reclaim_state)
89724 current->reclaim_state->reclaimed_slab += 1 << order;
89725- free_pages((unsigned long)b, order);
89726+ __ClearPageSlab(sp);
89727+ page_mapcount_reset(sp);
89728+ sp->private = 0;
89729+ __free_pages(sp, order);
89730 }
89731
89732 /*
89733@@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
89734
89735 /* Not enough space: must allocate a new page */
89736 if (!b) {
89737- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
89738- if (!b)
89739+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
89740+ if (!sp)
89741 return NULL;
89742- sp = virt_to_page(b);
89743- __SetPageSlab(sp);
89744+ b = page_address(sp);
89745
89746 spin_lock_irqsave(&slob_lock, flags);
89747 sp->units = SLOB_UNITS(PAGE_SIZE);
89748 sp->freelist = b;
89749+ sp->private = 0;
89750 INIT_LIST_HEAD(&sp->list);
89751 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
89752 set_slob_page_free(sp, slob_list);
89753@@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
89754 if (slob_page_free(sp))
89755 clear_slob_page_free(sp);
89756 spin_unlock_irqrestore(&slob_lock, flags);
89757- __ClearPageSlab(sp);
89758- page_mapcount_reset(sp);
89759- slob_free_pages(b, 0);
89760+ slob_free_pages(sp, 0);
89761 return;
89762 }
89763
89764+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89765+ if (pax_sanitize_slab)
89766+ memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
89767+#endif
89768+
89769 if (!slob_page_free(sp)) {
89770 /* This slob page is about to become partially free. Easy! */
89771 sp->units = units;
89772@@ -424,11 +431,10 @@ out:
89773 */
89774
89775 static __always_inline void *
89776-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
89777+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
89778 {
89779- unsigned int *m;
89780- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
89781- void *ret;
89782+ slob_t *m;
89783+ void *ret = NULL;
89784
89785 gfp &= gfp_allowed_mask;
89786
89787@@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
89788
89789 if (!m)
89790 return NULL;
89791- *m = size;
89792+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
89793+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
89794+ m[0].units = size;
89795+ m[1].units = align;
89796 ret = (void *)m + align;
89797
89798 trace_kmalloc_node(caller, ret,
89799 size, size + align, gfp, node);
89800 } else {
89801 unsigned int order = get_order(size);
89802+ struct page *page;
89803
89804 if (likely(order))
89805 gfp |= __GFP_COMP;
89806- ret = slob_new_pages(gfp, order, node);
89807+ page = slob_new_pages(gfp, order, node);
89808+ if (page) {
89809+ ret = page_address(page);
89810+ page->private = size;
89811+ }
89812
89813 trace_kmalloc_node(caller, ret,
89814 size, PAGE_SIZE << order, gfp, node);
89815 }
89816
89817- kmemleak_alloc(ret, size, 1, gfp);
89818+ return ret;
89819+}
89820+
89821+static __always_inline void *
89822+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
89823+{
89824+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
89825+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
89826+
89827+ if (!ZERO_OR_NULL_PTR(ret))
89828+ kmemleak_alloc(ret, size, 1, gfp);
89829 return ret;
89830 }
89831
89832@@ -493,34 +517,112 @@ void kfree(const void *block)
89833 return;
89834 kmemleak_free(block);
89835
89836+ VM_BUG_ON(!virt_addr_valid(block));
89837 sp = virt_to_page(block);
89838- if (PageSlab(sp)) {
89839+ VM_BUG_ON(!PageSlab(sp));
89840+ if (!sp->private) {
89841 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
89842- unsigned int *m = (unsigned int *)(block - align);
89843- slob_free(m, *m + align);
89844- } else
89845+ slob_t *m = (slob_t *)(block - align);
89846+ slob_free(m, m[0].units + align);
89847+ } else {
89848+ __ClearPageSlab(sp);
89849+ page_mapcount_reset(sp);
89850+ sp->private = 0;
89851 __free_pages(sp, compound_order(sp));
89852+ }
89853 }
89854 EXPORT_SYMBOL(kfree);
89855
89856+bool is_usercopy_object(const void *ptr)
89857+{
89858+ if (!slab_is_available())
89859+ return false;
89860+
89861+ // PAX: TODO
89862+
89863+ return false;
89864+}
89865+
89866+#ifdef CONFIG_PAX_USERCOPY
89867+const char *check_heap_object(const void *ptr, unsigned long n)
89868+{
89869+ struct page *page;
89870+ const slob_t *free;
89871+ const void *base;
89872+ unsigned long flags;
89873+
89874+ if (ZERO_OR_NULL_PTR(ptr))
89875+ return "<null>";
89876+
89877+ if (!virt_addr_valid(ptr))
89878+ return NULL;
89879+
89880+ page = virt_to_head_page(ptr);
89881+ if (!PageSlab(page))
89882+ return NULL;
89883+
89884+ if (page->private) {
89885+ base = page;
89886+ if (base <= ptr && n <= page->private - (ptr - base))
89887+ return NULL;
89888+ return "<slob>";
89889+ }
89890+
89891+ /* some tricky double walking to find the chunk */
89892+ spin_lock_irqsave(&slob_lock, flags);
89893+ base = (void *)((unsigned long)ptr & PAGE_MASK);
89894+ free = page->freelist;
89895+
89896+ while (!slob_last(free) && (void *)free <= ptr) {
89897+ base = free + slob_units(free);
89898+ free = slob_next(free);
89899+ }
89900+
89901+ while (base < (void *)free) {
89902+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
89903+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
89904+ int offset;
89905+
89906+ if (ptr < base + align)
89907+ break;
89908+
89909+ offset = ptr - base - align;
89910+ if (offset >= m) {
89911+ base += size;
89912+ continue;
89913+ }
89914+
89915+ if (n > m - offset)
89916+ break;
89917+
89918+ spin_unlock_irqrestore(&slob_lock, flags);
89919+ return NULL;
89920+ }
89921+
89922+ spin_unlock_irqrestore(&slob_lock, flags);
89923+ return "<slob>";
89924+}
89925+#endif
89926+
89927 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
89928 size_t ksize(const void *block)
89929 {
89930 struct page *sp;
89931 int align;
89932- unsigned int *m;
89933+ slob_t *m;
89934
89935 BUG_ON(!block);
89936 if (unlikely(block == ZERO_SIZE_PTR))
89937 return 0;
89938
89939 sp = virt_to_page(block);
89940- if (unlikely(!PageSlab(sp)))
89941- return PAGE_SIZE << compound_order(sp);
89942+ VM_BUG_ON(!PageSlab(sp));
89943+ if (sp->private)
89944+ return sp->private;
89945
89946 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
89947- m = (unsigned int *)(block - align);
89948- return SLOB_UNITS(*m) * SLOB_UNIT;
89949+ m = (slob_t *)(block - align);
89950+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
89951 }
89952 EXPORT_SYMBOL(ksize);
89953
89954@@ -536,23 +638,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
89955
89956 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
89957 {
89958- void *b;
89959+ void *b = NULL;
89960
89961 flags &= gfp_allowed_mask;
89962
89963 lockdep_trace_alloc(flags);
89964
89965+#ifdef CONFIG_PAX_USERCOPY_SLABS
89966+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
89967+#else
89968 if (c->size < PAGE_SIZE) {
89969 b = slob_alloc(c->size, flags, c->align, node);
89970 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
89971 SLOB_UNITS(c->size) * SLOB_UNIT,
89972 flags, node);
89973 } else {
89974- b = slob_new_pages(flags, get_order(c->size), node);
89975+ struct page *sp;
89976+
89977+ sp = slob_new_pages(flags, get_order(c->size), node);
89978+ if (sp) {
89979+ b = page_address(sp);
89980+ sp->private = c->size;
89981+ }
89982 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
89983 PAGE_SIZE << get_order(c->size),
89984 flags, node);
89985 }
89986+#endif
89987
89988 if (b && c->ctor)
89989 c->ctor(b);
89990@@ -564,10 +676,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
89991
89992 static void __kmem_cache_free(void *b, int size)
89993 {
89994- if (size < PAGE_SIZE)
89995+ struct page *sp;
89996+
89997+ sp = virt_to_page(b);
89998+ BUG_ON(!PageSlab(sp));
89999+ if (!sp->private)
90000 slob_free(b, size);
90001 else
90002- slob_free_pages(b, get_order(size));
90003+ slob_free_pages(sp, get_order(size));
90004 }
90005
90006 static void kmem_rcu_free(struct rcu_head *head)
90007@@ -580,17 +696,31 @@ static void kmem_rcu_free(struct rcu_head *head)
90008
90009 void kmem_cache_free(struct kmem_cache *c, void *b)
90010 {
90011+ int size = c->size;
90012+
90013+#ifdef CONFIG_PAX_USERCOPY_SLABS
90014+ if (size + c->align < PAGE_SIZE) {
90015+ size += c->align;
90016+ b -= c->align;
90017+ }
90018+#endif
90019+
90020 kmemleak_free_recursive(b, c->flags);
90021 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
90022 struct slob_rcu *slob_rcu;
90023- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
90024- slob_rcu->size = c->size;
90025+ slob_rcu = b + (size - sizeof(struct slob_rcu));
90026+ slob_rcu->size = size;
90027 call_rcu(&slob_rcu->head, kmem_rcu_free);
90028 } else {
90029- __kmem_cache_free(b, c->size);
90030+ __kmem_cache_free(b, size);
90031 }
90032
90033+#ifdef CONFIG_PAX_USERCOPY_SLABS
90034+ trace_kfree(_RET_IP_, b);
90035+#else
90036 trace_kmem_cache_free(_RET_IP_, b);
90037+#endif
90038+
90039 }
90040 EXPORT_SYMBOL(kmem_cache_free);
90041
90042diff --git a/mm/slub.c b/mm/slub.c
90043index e3ba1f2..bd45dac 100644
90044--- a/mm/slub.c
90045+++ b/mm/slub.c
90046@@ -207,7 +207,7 @@ struct track {
90047
90048 enum track_item { TRACK_ALLOC, TRACK_FREE };
90049
90050-#ifdef CONFIG_SYSFS
90051+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
90052 static int sysfs_slab_add(struct kmem_cache *);
90053 static int sysfs_slab_alias(struct kmem_cache *, const char *);
90054 static void sysfs_slab_remove(struct kmem_cache *);
90055@@ -528,7 +528,7 @@ static void print_track(const char *s, struct track *t)
90056 if (!t->addr)
90057 return;
90058
90059- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
90060+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
90061 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
90062 #ifdef CONFIG_STACKTRACE
90063 {
90064@@ -2609,6 +2609,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
90065
90066 slab_free_hook(s, x);
90067
90068+#ifdef CONFIG_PAX_MEMORY_SANITIZE
90069+ if (pax_sanitize_slab && !(s->flags & SLAB_NO_SANITIZE)) {
90070+ memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
90071+ if (s->ctor)
90072+ s->ctor(x);
90073+ }
90074+#endif
90075+
90076 redo:
90077 /*
90078 * Determine the currently cpus per cpu slab.
90079@@ -2676,7 +2684,7 @@ static int slub_min_objects;
90080 * Merge control. If this is set then no merging of slab caches will occur.
90081 * (Could be removed. This was introduced to pacify the merge skeptics.)
90082 */
90083-static int slub_nomerge;
90084+static int slub_nomerge = 1;
90085
90086 /*
90087 * Calculate the order of allocation given an slab object size.
90088@@ -2953,6 +2961,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
90089 s->inuse = size;
90090
90091 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
90092+#ifdef CONFIG_PAX_MEMORY_SANITIZE
90093+ (pax_sanitize_slab && !(flags & SLAB_NO_SANITIZE)) ||
90094+#endif
90095 s->ctor)) {
90096 /*
90097 * Relocate free pointer after the object if it is not
90098@@ -3298,6 +3309,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
90099 EXPORT_SYMBOL(__kmalloc_node);
90100 #endif
90101
90102+bool is_usercopy_object(const void *ptr)
90103+{
90104+ struct page *page;
90105+ struct kmem_cache *s;
90106+
90107+ if (ZERO_OR_NULL_PTR(ptr))
90108+ return false;
90109+
90110+ if (!slab_is_available())
90111+ return false;
90112+
90113+ if (!virt_addr_valid(ptr))
90114+ return false;
90115+
90116+ page = virt_to_head_page(ptr);
90117+
90118+ if (!PageSlab(page))
90119+ return false;
90120+
90121+ s = page->slab_cache;
90122+ return s->flags & SLAB_USERCOPY;
90123+}
90124+
90125+#ifdef CONFIG_PAX_USERCOPY
90126+const char *check_heap_object(const void *ptr, unsigned long n)
90127+{
90128+ struct page *page;
90129+ struct kmem_cache *s;
90130+ unsigned long offset;
90131+
90132+ if (ZERO_OR_NULL_PTR(ptr))
90133+ return "<null>";
90134+
90135+ if (!virt_addr_valid(ptr))
90136+ return NULL;
90137+
90138+ page = virt_to_head_page(ptr);
90139+
90140+ if (!PageSlab(page))
90141+ return NULL;
90142+
90143+ s = page->slab_cache;
90144+ if (!(s->flags & SLAB_USERCOPY))
90145+ return s->name;
90146+
90147+ offset = (ptr - page_address(page)) % s->size;
90148+ if (offset <= s->object_size && n <= s->object_size - offset)
90149+ return NULL;
90150+
90151+ return s->name;
90152+}
90153+#endif
90154+
90155 size_t ksize(const void *object)
90156 {
90157 struct page *page;
90158@@ -3362,6 +3426,7 @@ void kfree(const void *x)
90159 if (unlikely(ZERO_OR_NULL_PTR(x)))
90160 return;
90161
90162+ VM_BUG_ON(!virt_addr_valid(x));
90163 page = virt_to_head_page(x);
90164 if (unlikely(!PageSlab(page))) {
90165 BUG_ON(!PageCompound(page));
90166@@ -3667,7 +3732,7 @@ static int slab_unmergeable(struct kmem_cache *s)
90167 /*
90168 * We may have set a slab to be unmergeable during bootstrap.
90169 */
90170- if (s->refcount < 0)
90171+ if (atomic_read(&s->refcount) < 0)
90172 return 1;
90173
90174 return 0;
90175@@ -3725,7 +3790,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
90176
90177 s = find_mergeable(memcg, size, align, flags, name, ctor);
90178 if (s) {
90179- s->refcount++;
90180+ atomic_inc(&s->refcount);
90181 /*
90182 * Adjust the object sizes so that we clear
90183 * the complete object on kzalloc.
90184@@ -3734,7 +3799,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
90185 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
90186
90187 if (sysfs_slab_alias(s, name)) {
90188- s->refcount--;
90189+ atomic_dec(&s->refcount);
90190 s = NULL;
90191 }
90192 }
90193@@ -3854,7 +3919,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
90194 }
90195 #endif
90196
90197-#ifdef CONFIG_SYSFS
90198+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
90199 static int count_inuse(struct page *page)
90200 {
90201 return page->inuse;
90202@@ -4241,12 +4306,12 @@ static void resiliency_test(void)
90203 validate_slab_cache(kmalloc_caches[9]);
90204 }
90205 #else
90206-#ifdef CONFIG_SYSFS
90207+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
90208 static void resiliency_test(void) {};
90209 #endif
90210 #endif
90211
90212-#ifdef CONFIG_SYSFS
90213+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
90214 enum slab_stat_type {
90215 SL_ALL, /* All slabs */
90216 SL_PARTIAL, /* Only partially allocated slabs */
90217@@ -4490,7 +4555,7 @@ SLAB_ATTR_RO(ctor);
90218
90219 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
90220 {
90221- return sprintf(buf, "%d\n", s->refcount - 1);
90222+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
90223 }
90224 SLAB_ATTR_RO(aliases);
90225
90226@@ -4578,6 +4643,14 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
90227 SLAB_ATTR_RO(cache_dma);
90228 #endif
90229
90230+#ifdef CONFIG_PAX_USERCOPY_SLABS
90231+static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
90232+{
90233+ return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
90234+}
90235+SLAB_ATTR_RO(usercopy);
90236+#endif
90237+
90238 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
90239 {
90240 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
90241@@ -4912,6 +4985,9 @@ static struct attribute *slab_attrs[] = {
90242 #ifdef CONFIG_ZONE_DMA
90243 &cache_dma_attr.attr,
90244 #endif
90245+#ifdef CONFIG_PAX_USERCOPY_SLABS
90246+ &usercopy_attr.attr,
90247+#endif
90248 #ifdef CONFIG_NUMA
90249 &remote_node_defrag_ratio_attr.attr,
90250 #endif
90251@@ -5143,6 +5219,7 @@ static char *create_unique_id(struct kmem_cache *s)
90252 return name;
90253 }
90254
90255+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
90256 static int sysfs_slab_add(struct kmem_cache *s)
90257 {
90258 int err;
90259@@ -5166,7 +5243,7 @@ static int sysfs_slab_add(struct kmem_cache *s)
90260 }
90261
90262 s->kobj.kset = slab_kset;
90263- err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, name);
90264+ err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, "%s", name);
90265 if (err) {
90266 kobject_put(&s->kobj);
90267 return err;
90268@@ -5200,6 +5277,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
90269 kobject_del(&s->kobj);
90270 kobject_put(&s->kobj);
90271 }
90272+#endif
90273
90274 /*
90275 * Need to buffer aliases during bootup until sysfs becomes
90276@@ -5213,6 +5291,7 @@ struct saved_alias {
90277
90278 static struct saved_alias *alias_list;
90279
90280+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
90281 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
90282 {
90283 struct saved_alias *al;
90284@@ -5235,6 +5314,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
90285 alias_list = al;
90286 return 0;
90287 }
90288+#endif
90289
90290 static int __init slab_sysfs_init(void)
90291 {
90292diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
90293index 27eeab3..7c3f7f2 100644
90294--- a/mm/sparse-vmemmap.c
90295+++ b/mm/sparse-vmemmap.c
90296@@ -130,7 +130,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
90297 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
90298 if (!p)
90299 return NULL;
90300- pud_populate(&init_mm, pud, p);
90301+ pud_populate_kernel(&init_mm, pud, p);
90302 }
90303 return pud;
90304 }
90305@@ -142,7 +142,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
90306 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
90307 if (!p)
90308 return NULL;
90309- pgd_populate(&init_mm, pgd, p);
90310+ pgd_populate_kernel(&init_mm, pgd, p);
90311 }
90312 return pgd;
90313 }
90314diff --git a/mm/sparse.c b/mm/sparse.c
90315index 308d503..3dbbd04 100644
90316--- a/mm/sparse.c
90317+++ b/mm/sparse.c
90318@@ -764,7 +764,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
90319
90320 for (i = 0; i < PAGES_PER_SECTION; i++) {
90321 if (PageHWPoison(&memmap[i])) {
90322- atomic_long_sub(1, &num_poisoned_pages);
90323+ atomic_long_sub_unchecked(1, &num_poisoned_pages);
90324 ClearPageHWPoison(&memmap[i]);
90325 }
90326 }
90327diff --git a/mm/swap.c b/mm/swap.c
90328index 62b78a6..0bcf28f 100644
90329--- a/mm/swap.c
90330+++ b/mm/swap.c
90331@@ -31,6 +31,7 @@
90332 #include <linux/memcontrol.h>
90333 #include <linux/gfp.h>
90334 #include <linux/uio.h>
90335+#include <linux/hugetlb.h>
90336
90337 #include "internal.h"
90338
90339@@ -76,6 +77,8 @@ static void __put_compound_page(struct page *page)
90340
90341 __page_cache_release(page);
90342 dtor = get_compound_page_dtor(page);
90343+ if (!PageHuge(page))
90344+ BUG_ON(dtor != free_compound_page);
90345 (*dtor)(page);
90346 }
90347
90348diff --git a/mm/swapfile.c b/mm/swapfile.c
90349index 6cf2e60..d204b3e 100644
90350--- a/mm/swapfile.c
90351+++ b/mm/swapfile.c
90352@@ -66,7 +66,7 @@ static DEFINE_MUTEX(swapon_mutex);
90353
90354 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
90355 /* Activity counter to indicate that a swapon or swapoff has occurred */
90356-static atomic_t proc_poll_event = ATOMIC_INIT(0);
90357+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
90358
90359 static inline unsigned char swap_count(unsigned char ent)
90360 {
90361@@ -1699,7 +1699,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
90362 }
90363 filp_close(swap_file, NULL);
90364 err = 0;
90365- atomic_inc(&proc_poll_event);
90366+ atomic_inc_unchecked(&proc_poll_event);
90367 wake_up_interruptible(&proc_poll_wait);
90368
90369 out_dput:
90370@@ -1716,8 +1716,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
90371
90372 poll_wait(file, &proc_poll_wait, wait);
90373
90374- if (seq->poll_event != atomic_read(&proc_poll_event)) {
90375- seq->poll_event = atomic_read(&proc_poll_event);
90376+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
90377+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
90378 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
90379 }
90380
90381@@ -1815,7 +1815,7 @@ static int swaps_open(struct inode *inode, struct file *file)
90382 return ret;
90383
90384 seq = file->private_data;
90385- seq->poll_event = atomic_read(&proc_poll_event);
90386+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
90387 return 0;
90388 }
90389
90390@@ -2203,7 +2203,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
90391 (frontswap_map) ? "FS" : "");
90392
90393 mutex_unlock(&swapon_mutex);
90394- atomic_inc(&proc_poll_event);
90395+ atomic_inc_unchecked(&proc_poll_event);
90396 wake_up_interruptible(&proc_poll_wait);
90397
90398 if (S_ISREG(inode->i_mode))
90399diff --git a/mm/util.c b/mm/util.c
90400index 7441c41..c3de793 100644
90401--- a/mm/util.c
90402+++ b/mm/util.c
90403@@ -294,6 +294,12 @@ done:
90404 void arch_pick_mmap_layout(struct mm_struct *mm)
90405 {
90406 mm->mmap_base = TASK_UNMAPPED_BASE;
90407+
90408+#ifdef CONFIG_PAX_RANDMMAP
90409+ if (mm->pax_flags & MF_PAX_RANDMMAP)
90410+ mm->mmap_base += mm->delta_mmap;
90411+#endif
90412+
90413 mm->get_unmapped_area = arch_get_unmapped_area;
90414 }
90415 #endif
90416diff --git a/mm/vmalloc.c b/mm/vmalloc.c
90417index 13a5495..6707d97 100644
90418--- a/mm/vmalloc.c
90419+++ b/mm/vmalloc.c
90420@@ -59,8 +59,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
90421
90422 pte = pte_offset_kernel(pmd, addr);
90423 do {
90424- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
90425- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
90426+
90427+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
90428+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
90429+ BUG_ON(!pte_exec(*pte));
90430+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
90431+ continue;
90432+ }
90433+#endif
90434+
90435+ {
90436+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
90437+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
90438+ }
90439 } while (pte++, addr += PAGE_SIZE, addr != end);
90440 }
90441
90442@@ -120,16 +131,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
90443 pte = pte_alloc_kernel(pmd, addr);
90444 if (!pte)
90445 return -ENOMEM;
90446+
90447+ pax_open_kernel();
90448 do {
90449 struct page *page = pages[*nr];
90450
90451- if (WARN_ON(!pte_none(*pte)))
90452+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
90453+ if (pgprot_val(prot) & _PAGE_NX)
90454+#endif
90455+
90456+ if (!pte_none(*pte)) {
90457+ pax_close_kernel();
90458+ WARN_ON(1);
90459 return -EBUSY;
90460- if (WARN_ON(!page))
90461+ }
90462+ if (!page) {
90463+ pax_close_kernel();
90464+ WARN_ON(1);
90465 return -ENOMEM;
90466+ }
90467 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
90468 (*nr)++;
90469 } while (pte++, addr += PAGE_SIZE, addr != end);
90470+ pax_close_kernel();
90471 return 0;
90472 }
90473
90474@@ -139,7 +163,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
90475 pmd_t *pmd;
90476 unsigned long next;
90477
90478- pmd = pmd_alloc(&init_mm, pud, addr);
90479+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
90480 if (!pmd)
90481 return -ENOMEM;
90482 do {
90483@@ -156,7 +180,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
90484 pud_t *pud;
90485 unsigned long next;
90486
90487- pud = pud_alloc(&init_mm, pgd, addr);
90488+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
90489 if (!pud)
90490 return -ENOMEM;
90491 do {
90492@@ -216,6 +240,12 @@ int is_vmalloc_or_module_addr(const void *x)
90493 if (addr >= MODULES_VADDR && addr < MODULES_END)
90494 return 1;
90495 #endif
90496+
90497+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
90498+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
90499+ return 1;
90500+#endif
90501+
90502 return is_vmalloc_addr(x);
90503 }
90504
90505@@ -236,8 +266,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
90506
90507 if (!pgd_none(*pgd)) {
90508 pud_t *pud = pud_offset(pgd, addr);
90509+#ifdef CONFIG_X86
90510+ if (!pud_large(*pud))
90511+#endif
90512 if (!pud_none(*pud)) {
90513 pmd_t *pmd = pmd_offset(pud, addr);
90514+#ifdef CONFIG_X86
90515+ if (!pmd_large(*pmd))
90516+#endif
90517 if (!pmd_none(*pmd)) {
90518 pte_t *ptep, pte;
90519
90520@@ -339,7 +375,7 @@ static void purge_vmap_area_lazy(void);
90521 * Allocate a region of KVA of the specified size and alignment, within the
90522 * vstart and vend.
90523 */
90524-static struct vmap_area *alloc_vmap_area(unsigned long size,
90525+static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
90526 unsigned long align,
90527 unsigned long vstart, unsigned long vend,
90528 int node, gfp_t gfp_mask)
90529@@ -1308,6 +1344,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
90530 struct vm_struct *area;
90531
90532 BUG_ON(in_interrupt());
90533+
90534+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
90535+ if (flags & VM_KERNEXEC) {
90536+ if (start != VMALLOC_START || end != VMALLOC_END)
90537+ return NULL;
90538+ start = (unsigned long)MODULES_EXEC_VADDR;
90539+ end = (unsigned long)MODULES_EXEC_END;
90540+ }
90541+#endif
90542+
90543 if (flags & VM_IOREMAP)
90544 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
90545
90546@@ -1533,6 +1579,11 @@ void *vmap(struct page **pages, unsigned int count,
90547 if (count > totalram_pages)
90548 return NULL;
90549
90550+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
90551+ if (!(pgprot_val(prot) & _PAGE_NX))
90552+ flags |= VM_KERNEXEC;
90553+#endif
90554+
90555 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
90556 __builtin_return_address(0));
90557 if (!area)
90558@@ -1634,6 +1685,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
90559 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
90560 goto fail;
90561
90562+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
90563+ if (!(pgprot_val(prot) & _PAGE_NX))
90564+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
90565+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
90566+ else
90567+#endif
90568+
90569 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
90570 start, end, node, gfp_mask, caller);
90571 if (!area)
90572@@ -1810,10 +1868,9 @@ EXPORT_SYMBOL(vzalloc_node);
90573 * For tight control over page level allocator and protection flags
90574 * use __vmalloc() instead.
90575 */
90576-
90577 void *vmalloc_exec(unsigned long size)
90578 {
90579- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
90580+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
90581 NUMA_NO_NODE, __builtin_return_address(0));
90582 }
90583
90584@@ -2120,6 +2177,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
90585 {
90586 struct vm_struct *area;
90587
90588+ BUG_ON(vma->vm_mirror);
90589+
90590 size = PAGE_ALIGN(size);
90591
90592 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
90593@@ -2605,7 +2664,11 @@ static int s_show(struct seq_file *m, void *p)
90594 v->addr, v->addr + v->size, v->size);
90595
90596 if (v->caller)
90597+#ifdef CONFIG_GRKERNSEC_HIDESYM
90598+ seq_printf(m, " %pK", v->caller);
90599+#else
90600 seq_printf(m, " %pS", v->caller);
90601+#endif
90602
90603 if (v->nr_pages)
90604 seq_printf(m, " pages=%d", v->nr_pages);
90605diff --git a/mm/vmstat.c b/mm/vmstat.c
90606index 20c2ef4..15e7ab7 100644
90607--- a/mm/vmstat.c
90608+++ b/mm/vmstat.c
90609@@ -76,7 +76,7 @@ void vm_events_fold_cpu(int cpu)
90610 *
90611 * vm_stat contains the global counters
90612 */
90613-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
90614+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
90615 EXPORT_SYMBOL(vm_stat);
90616
90617 #ifdef CONFIG_SMP
90618@@ -452,7 +452,7 @@ void refresh_cpu_vm_stats(int cpu)
90619 v = p->vm_stat_diff[i];
90620 p->vm_stat_diff[i] = 0;
90621 local_irq_restore(flags);
90622- atomic_long_add(v, &zone->vm_stat[i]);
90623+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
90624 global_diff[i] += v;
90625 #ifdef CONFIG_NUMA
90626 /* 3 seconds idle till flush */
90627@@ -490,7 +490,7 @@ void refresh_cpu_vm_stats(int cpu)
90628
90629 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
90630 if (global_diff[i])
90631- atomic_long_add(global_diff[i], &vm_stat[i]);
90632+ atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
90633 }
90634
90635 /*
90636@@ -505,8 +505,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
90637 if (pset->vm_stat_diff[i]) {
90638 int v = pset->vm_stat_diff[i];
90639 pset->vm_stat_diff[i] = 0;
90640- atomic_long_add(v, &zone->vm_stat[i]);
90641- atomic_long_add(v, &vm_stat[i]);
90642+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
90643+ atomic_long_add_unchecked(v, &vm_stat[i]);
90644 }
90645 }
90646 #endif
90647@@ -1241,10 +1241,20 @@ static int __init setup_vmstat(void)
90648 start_cpu_timer(cpu);
90649 #endif
90650 #ifdef CONFIG_PROC_FS
90651- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
90652- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
90653- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
90654- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
90655+ {
90656+ mode_t gr_mode = S_IRUGO;
90657+#ifdef CONFIG_GRKERNSEC_PROC_ADD
90658+ gr_mode = S_IRUSR;
90659+#endif
90660+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
90661+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
90662+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
90663+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
90664+#else
90665+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
90666+#endif
90667+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
90668+ }
90669 #endif
90670 return 0;
90671 }
90672diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
90673index 2fb2d88..8c06e40 100644
90674--- a/net/8021q/vlan.c
90675+++ b/net/8021q/vlan.c
90676@@ -469,7 +469,7 @@ out:
90677 return NOTIFY_DONE;
90678 }
90679
90680-static struct notifier_block vlan_notifier_block __read_mostly = {
90681+static struct notifier_block vlan_notifier_block = {
90682 .notifier_call = vlan_device_event,
90683 };
90684
90685@@ -544,8 +544,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
90686 err = -EPERM;
90687 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
90688 break;
90689- if ((args.u.name_type >= 0) &&
90690- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
90691+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
90692 struct vlan_net *vn;
90693
90694 vn = net_generic(net, vlan_net_id);
90695diff --git a/net/9p/mod.c b/net/9p/mod.c
90696index 6ab36ae..6f1841b 100644
90697--- a/net/9p/mod.c
90698+++ b/net/9p/mod.c
90699@@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
90700 void v9fs_register_trans(struct p9_trans_module *m)
90701 {
90702 spin_lock(&v9fs_trans_lock);
90703- list_add_tail(&m->list, &v9fs_trans_list);
90704+ pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
90705 spin_unlock(&v9fs_trans_lock);
90706 }
90707 EXPORT_SYMBOL(v9fs_register_trans);
90708@@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
90709 void v9fs_unregister_trans(struct p9_trans_module *m)
90710 {
90711 spin_lock(&v9fs_trans_lock);
90712- list_del_init(&m->list);
90713+ pax_list_del_init((struct list_head *)&m->list);
90714 spin_unlock(&v9fs_trans_lock);
90715 }
90716 EXPORT_SYMBOL(v9fs_unregister_trans);
90717diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
90718index 3ffda1b..fceac96 100644
90719--- a/net/9p/trans_fd.c
90720+++ b/net/9p/trans_fd.c
90721@@ -432,7 +432,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
90722 oldfs = get_fs();
90723 set_fs(get_ds());
90724 /* The cast to a user pointer is valid due to the set_fs() */
90725- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
90726+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
90727 set_fs(oldfs);
90728
90729 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
90730diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
90731index 876fbe8..8bbea9f 100644
90732--- a/net/atm/atm_misc.c
90733+++ b/net/atm/atm_misc.c
90734@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
90735 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
90736 return 1;
90737 atm_return(vcc, truesize);
90738- atomic_inc(&vcc->stats->rx_drop);
90739+ atomic_inc_unchecked(&vcc->stats->rx_drop);
90740 return 0;
90741 }
90742 EXPORT_SYMBOL(atm_charge);
90743@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
90744 }
90745 }
90746 atm_return(vcc, guess);
90747- atomic_inc(&vcc->stats->rx_drop);
90748+ atomic_inc_unchecked(&vcc->stats->rx_drop);
90749 return NULL;
90750 }
90751 EXPORT_SYMBOL(atm_alloc_charge);
90752@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
90753
90754 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
90755 {
90756-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
90757+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
90758 __SONET_ITEMS
90759 #undef __HANDLE_ITEM
90760 }
90761@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
90762
90763 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
90764 {
90765-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
90766+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
90767 __SONET_ITEMS
90768 #undef __HANDLE_ITEM
90769 }
90770diff --git a/net/atm/lec.h b/net/atm/lec.h
90771index 4149db1..f2ab682 100644
90772--- a/net/atm/lec.h
90773+++ b/net/atm/lec.h
90774@@ -48,7 +48,7 @@ struct lane2_ops {
90775 const u8 *tlvs, u32 sizeoftlvs);
90776 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
90777 const u8 *tlvs, u32 sizeoftlvs);
90778-};
90779+} __no_const;
90780
90781 /*
90782 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
90783diff --git a/net/atm/proc.c b/net/atm/proc.c
90784index bbb6461..cf04016 100644
90785--- a/net/atm/proc.c
90786+++ b/net/atm/proc.c
90787@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
90788 const struct k_atm_aal_stats *stats)
90789 {
90790 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
90791- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
90792- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
90793- atomic_read(&stats->rx_drop));
90794+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
90795+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
90796+ atomic_read_unchecked(&stats->rx_drop));
90797 }
90798
90799 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
90800diff --git a/net/atm/resources.c b/net/atm/resources.c
90801index 0447d5d..3cf4728 100644
90802--- a/net/atm/resources.c
90803+++ b/net/atm/resources.c
90804@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
90805 static void copy_aal_stats(struct k_atm_aal_stats *from,
90806 struct atm_aal_stats *to)
90807 {
90808-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
90809+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
90810 __AAL_STAT_ITEMS
90811 #undef __HANDLE_ITEM
90812 }
90813@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
90814 static void subtract_aal_stats(struct k_atm_aal_stats *from,
90815 struct atm_aal_stats *to)
90816 {
90817-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
90818+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
90819 __AAL_STAT_ITEMS
90820 #undef __HANDLE_ITEM
90821 }
90822diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
90823index 919a5ce..cc6b444 100644
90824--- a/net/ax25/sysctl_net_ax25.c
90825+++ b/net/ax25/sysctl_net_ax25.c
90826@@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
90827 {
90828 char path[sizeof("net/ax25/") + IFNAMSIZ];
90829 int k;
90830- struct ctl_table *table;
90831+ ctl_table_no_const *table;
90832
90833 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
90834 if (!table)
90835diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
90836index 62da527..aa27535 100644
90837--- a/net/batman-adv/bat_iv_ogm.c
90838+++ b/net/batman-adv/bat_iv_ogm.c
90839@@ -120,7 +120,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
90840
90841 /* randomize initial seqno to avoid collision */
90842 get_random_bytes(&random_seqno, sizeof(random_seqno));
90843- atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
90844+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
90845
90846 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
90847 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
90848@@ -701,9 +701,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
90849 batadv_ogm_packet = (struct batadv_ogm_packet *)(*ogm_buff);
90850
90851 /* change sequence number to network order */
90852- seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
90853+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
90854 batadv_ogm_packet->seqno = htonl(seqno);
90855- atomic_inc(&hard_iface->bat_iv.ogm_seqno);
90856+ atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
90857
90858 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->tt.vn);
90859 batadv_ogm_packet->tt_crc = htons(bat_priv->tt.local_crc);
90860@@ -1109,7 +1109,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
90861 return;
90862
90863 /* could be changed by schedule_own_packet() */
90864- if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
90865+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
90866
90867 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
90868 has_directlink_flag = 1;
90869diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
90870index c478e6b..469fd2f 100644
90871--- a/net/batman-adv/hard-interface.c
90872+++ b/net/batman-adv/hard-interface.c
90873@@ -453,7 +453,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
90874 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
90875 dev_add_pack(&hard_iface->batman_adv_ptype);
90876
90877- atomic_set(&hard_iface->frag_seqno, 1);
90878+ atomic_set_unchecked(&hard_iface->frag_seqno, 1);
90879 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
90880 hard_iface->net_dev->name);
90881
90882diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
90883index 0f04e1c..9c0ac11 100644
90884--- a/net/batman-adv/soft-interface.c
90885+++ b/net/batman-adv/soft-interface.c
90886@@ -260,7 +260,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
90887 primary_if->net_dev->dev_addr, ETH_ALEN);
90888
90889 /* set broadcast sequence number */
90890- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
90891+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
90892 bcast_packet->seqno = htonl(seqno);
90893
90894 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
90895@@ -479,7 +479,7 @@ static int batadv_softif_init_late(struct net_device *dev)
90896 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
90897
90898 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
90899- atomic_set(&bat_priv->bcast_seqno, 1);
90900+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
90901 atomic_set(&bat_priv->tt.vn, 0);
90902 atomic_set(&bat_priv->tt.local_changes, 0);
90903 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
90904diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
90905index b2c94e1..3d47e07 100644
90906--- a/net/batman-adv/types.h
90907+++ b/net/batman-adv/types.h
90908@@ -51,7 +51,7 @@
90909 struct batadv_hard_iface_bat_iv {
90910 unsigned char *ogm_buff;
90911 int ogm_buff_len;
90912- atomic_t ogm_seqno;
90913+ atomic_unchecked_t ogm_seqno;
90914 };
90915
90916 /**
90917@@ -76,7 +76,7 @@ struct batadv_hard_iface {
90918 int16_t if_num;
90919 char if_status;
90920 struct net_device *net_dev;
90921- atomic_t frag_seqno;
90922+ atomic_unchecked_t frag_seqno;
90923 uint8_t num_bcasts;
90924 struct kobject *hardif_obj;
90925 atomic_t refcount;
90926@@ -560,7 +560,7 @@ struct batadv_priv {
90927 #ifdef CONFIG_BATMAN_ADV_DEBUG
90928 atomic_t log_level;
90929 #endif
90930- atomic_t bcast_seqno;
90931+ atomic_unchecked_t bcast_seqno;
90932 atomic_t bcast_queue_left;
90933 atomic_t batman_queue_left;
90934 char num_ifaces;
90935diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
90936index 857e1b8..5ad07b2 100644
90937--- a/net/batman-adv/unicast.c
90938+++ b/net/batman-adv/unicast.c
90939@@ -270,7 +270,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
90940 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
90941 frag2->flags = large_tail;
90942
90943- seqno = atomic_add_return(2, &hard_iface->frag_seqno);
90944+ seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
90945 frag1->seqno = htons(seqno - 1);
90946 frag2->seqno = htons(seqno);
90947
90948diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
90949index 9bd7d95..6c4884f 100644
90950--- a/net/bluetooth/hci_sock.c
90951+++ b/net/bluetooth/hci_sock.c
90952@@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
90953 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
90954 }
90955
90956- len = min_t(unsigned int, len, sizeof(uf));
90957+ len = min((size_t)len, sizeof(uf));
90958 if (copy_from_user(&uf, optval, len)) {
90959 err = -EFAULT;
90960 break;
90961diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
90962index 8c3499b..2661c6a 100644
90963--- a/net/bluetooth/l2cap_core.c
90964+++ b/net/bluetooth/l2cap_core.c
90965@@ -3510,8 +3510,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
90966 break;
90967
90968 case L2CAP_CONF_RFC:
90969- if (olen == sizeof(rfc))
90970- memcpy(&rfc, (void *)val, olen);
90971+ if (olen != sizeof(rfc))
90972+ break;
90973+
90974+ memcpy(&rfc, (void *)val, olen);
90975
90976 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
90977 rfc.mode != chan->mode)
90978diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
90979index 0098af8..fb5a31f 100644
90980--- a/net/bluetooth/l2cap_sock.c
90981+++ b/net/bluetooth/l2cap_sock.c
90982@@ -485,7 +485,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
90983 struct sock *sk = sock->sk;
90984 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
90985 struct l2cap_options opts;
90986- int len, err = 0;
90987+ int err = 0;
90988+ size_t len = optlen;
90989 u32 opt;
90990
90991 BT_DBG("sk %p", sk);
90992@@ -507,7 +508,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
90993 opts.max_tx = chan->max_tx;
90994 opts.txwin_size = chan->tx_win;
90995
90996- len = min_t(unsigned int, sizeof(opts), optlen);
90997+ len = min(sizeof(opts), len);
90998 if (copy_from_user((char *) &opts, optval, len)) {
90999 err = -EFAULT;
91000 break;
91001@@ -587,7 +588,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
91002 struct bt_security sec;
91003 struct bt_power pwr;
91004 struct l2cap_conn *conn;
91005- int len, err = 0;
91006+ int err = 0;
91007+ size_t len = optlen;
91008 u32 opt;
91009
91010 BT_DBG("sk %p", sk);
91011@@ -610,7 +612,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
91012
91013 sec.level = BT_SECURITY_LOW;
91014
91015- len = min_t(unsigned int, sizeof(sec), optlen);
91016+ len = min(sizeof(sec), len);
91017 if (copy_from_user((char *) &sec, optval, len)) {
91018 err = -EFAULT;
91019 break;
91020@@ -707,7 +709,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
91021
91022 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
91023
91024- len = min_t(unsigned int, sizeof(pwr), optlen);
91025+ len = min(sizeof(pwr), len);
91026 if (copy_from_user((char *) &pwr, optval, len)) {
91027 err = -EFAULT;
91028 break;
91029diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
91030index 30b3721..c1bd0a0 100644
91031--- a/net/bluetooth/rfcomm/sock.c
91032+++ b/net/bluetooth/rfcomm/sock.c
91033@@ -666,7 +666,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
91034 struct sock *sk = sock->sk;
91035 struct bt_security sec;
91036 int err = 0;
91037- size_t len;
91038+ size_t len = optlen;
91039 u32 opt;
91040
91041 BT_DBG("sk %p", sk);
91042@@ -688,7 +688,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
91043
91044 sec.level = BT_SECURITY_LOW;
91045
91046- len = min_t(unsigned int, sizeof(sec), optlen);
91047+ len = min(sizeof(sec), len);
91048 if (copy_from_user((char *) &sec, optval, len)) {
91049 err = -EFAULT;
91050 break;
91051diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
91052index b6e44ad..5b0d514 100644
91053--- a/net/bluetooth/rfcomm/tty.c
91054+++ b/net/bluetooth/rfcomm/tty.c
91055@@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
91056 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
91057
91058 spin_lock_irqsave(&dev->port.lock, flags);
91059- if (dev->port.count > 0) {
91060+ if (atomic_read(&dev->port.count) > 0) {
91061 spin_unlock_irqrestore(&dev->port.lock, flags);
91062 return;
91063 }
91064@@ -659,10 +659,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
91065 return -ENODEV;
91066
91067 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
91068- dev->channel, dev->port.count);
91069+ dev->channel, atomic_read(&dev->port.count));
91070
91071 spin_lock_irqsave(&dev->port.lock, flags);
91072- if (++dev->port.count > 1) {
91073+ if (atomic_inc_return(&dev->port.count) > 1) {
91074 spin_unlock_irqrestore(&dev->port.lock, flags);
91075 return 0;
91076 }
91077@@ -727,10 +727,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
91078 return;
91079
91080 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
91081- dev->port.count);
91082+ atomic_read(&dev->port.count));
91083
91084 spin_lock_irqsave(&dev->port.lock, flags);
91085- if (!--dev->port.count) {
91086+ if (!atomic_dec_return(&dev->port.count)) {
91087 spin_unlock_irqrestore(&dev->port.lock, flags);
91088 if (dev->tty_dev->parent)
91089 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
91090diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
91091index ac78024..161a80c 100644
91092--- a/net/bridge/netfilter/ebtables.c
91093+++ b/net/bridge/netfilter/ebtables.c
91094@@ -1525,7 +1525,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
91095 tmp.valid_hooks = t->table->valid_hooks;
91096 }
91097 mutex_unlock(&ebt_mutex);
91098- if (copy_to_user(user, &tmp, *len) != 0){
91099+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
91100 BUGPRINT("c2u Didn't work\n");
91101 ret = -EFAULT;
91102 break;
91103@@ -2331,7 +2331,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
91104 goto out;
91105 tmp.valid_hooks = t->valid_hooks;
91106
91107- if (copy_to_user(user, &tmp, *len) != 0) {
91108+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
91109 ret = -EFAULT;
91110 break;
91111 }
91112@@ -2342,7 +2342,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
91113 tmp.entries_size = t->table->entries_size;
91114 tmp.valid_hooks = t->table->valid_hooks;
91115
91116- if (copy_to_user(user, &tmp, *len) != 0) {
91117+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
91118 ret = -EFAULT;
91119 break;
91120 }
91121diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
91122index 2bd4b58..0dc30a1 100644
91123--- a/net/caif/cfctrl.c
91124+++ b/net/caif/cfctrl.c
91125@@ -10,6 +10,7 @@
91126 #include <linux/spinlock.h>
91127 #include <linux/slab.h>
91128 #include <linux/pkt_sched.h>
91129+#include <linux/sched.h>
91130 #include <net/caif/caif_layer.h>
91131 #include <net/caif/cfpkt.h>
91132 #include <net/caif/cfctrl.h>
91133@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
91134 memset(&dev_info, 0, sizeof(dev_info));
91135 dev_info.id = 0xff;
91136 cfsrvl_init(&this->serv, 0, &dev_info, false);
91137- atomic_set(&this->req_seq_no, 1);
91138- atomic_set(&this->rsp_seq_no, 1);
91139+ atomic_set_unchecked(&this->req_seq_no, 1);
91140+ atomic_set_unchecked(&this->rsp_seq_no, 1);
91141 this->serv.layer.receive = cfctrl_recv;
91142 sprintf(this->serv.layer.name, "ctrl");
91143 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
91144@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
91145 struct cfctrl_request_info *req)
91146 {
91147 spin_lock_bh(&ctrl->info_list_lock);
91148- atomic_inc(&ctrl->req_seq_no);
91149- req->sequence_no = atomic_read(&ctrl->req_seq_no);
91150+ atomic_inc_unchecked(&ctrl->req_seq_no);
91151+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
91152 list_add_tail(&req->list, &ctrl->list);
91153 spin_unlock_bh(&ctrl->info_list_lock);
91154 }
91155@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
91156 if (p != first)
91157 pr_warn("Requests are not received in order\n");
91158
91159- atomic_set(&ctrl->rsp_seq_no,
91160+ atomic_set_unchecked(&ctrl->rsp_seq_no,
91161 p->sequence_no);
91162 list_del(&p->list);
91163 goto out;
91164diff --git a/net/can/af_can.c b/net/can/af_can.c
91165index 3ab8dd2..b9aef13 100644
91166--- a/net/can/af_can.c
91167+++ b/net/can/af_can.c
91168@@ -862,7 +862,7 @@ static const struct net_proto_family can_family_ops = {
91169 };
91170
91171 /* notifier block for netdevice event */
91172-static struct notifier_block can_netdev_notifier __read_mostly = {
91173+static struct notifier_block can_netdev_notifier = {
91174 .notifier_call = can_notifier,
91175 };
91176
91177diff --git a/net/can/gw.c b/net/can/gw.c
91178index 2f291f9..98c986a 100644
91179--- a/net/can/gw.c
91180+++ b/net/can/gw.c
91181@@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
91182 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
91183
91184 static HLIST_HEAD(cgw_list);
91185-static struct notifier_block notifier;
91186
91187 static struct kmem_cache *cgw_cache __read_mostly;
91188
91189@@ -927,6 +926,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
91190 return err;
91191 }
91192
91193+static struct notifier_block notifier = {
91194+ .notifier_call = cgw_notifier
91195+};
91196+
91197 static __init int cgw_module_init(void)
91198 {
91199 /* sanitize given module parameter */
91200@@ -942,7 +945,6 @@ static __init int cgw_module_init(void)
91201 return -ENOMEM;
91202
91203 /* set notifier */
91204- notifier.notifier_call = cgw_notifier;
91205 register_netdevice_notifier(&notifier);
91206
91207 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
91208diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
91209index eb0a46a..5f3bae8 100644
91210--- a/net/ceph/messenger.c
91211+++ b/net/ceph/messenger.c
91212@@ -186,7 +186,7 @@ static void con_fault(struct ceph_connection *con);
91213 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
91214
91215 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
91216-static atomic_t addr_str_seq = ATOMIC_INIT(0);
91217+static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
91218
91219 static struct page *zero_page; /* used in certain error cases */
91220
91221@@ -197,7 +197,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
91222 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
91223 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
91224
91225- i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
91226+ i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
91227 s = addr_str[i];
91228
91229 switch (ss->ss_family) {
91230diff --git a/net/compat.c b/net/compat.c
91231index f0a1ba6..0541331 100644
91232--- a/net/compat.c
91233+++ b/net/compat.c
91234@@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
91235 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
91236 __get_user(kmsg->msg_flags, &umsg->msg_flags))
91237 return -EFAULT;
91238- kmsg->msg_name = compat_ptr(tmp1);
91239- kmsg->msg_iov = compat_ptr(tmp2);
91240- kmsg->msg_control = compat_ptr(tmp3);
91241+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
91242+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
91243+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
91244 return 0;
91245 }
91246
91247@@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
91248
91249 if (kern_msg->msg_namelen) {
91250 if (mode == VERIFY_READ) {
91251- int err = move_addr_to_kernel(kern_msg->msg_name,
91252+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
91253 kern_msg->msg_namelen,
91254 kern_address);
91255 if (err < 0)
91256@@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
91257 kern_msg->msg_name = NULL;
91258
91259 tot_len = iov_from_user_compat_to_kern(kern_iov,
91260- (struct compat_iovec __user *)kern_msg->msg_iov,
91261+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
91262 kern_msg->msg_iovlen);
91263 if (tot_len >= 0)
91264 kern_msg->msg_iov = kern_iov;
91265@@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
91266
91267 #define CMSG_COMPAT_FIRSTHDR(msg) \
91268 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
91269- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
91270+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
91271 (struct compat_cmsghdr __user *)NULL)
91272
91273 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
91274 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
91275 (ucmlen) <= (unsigned long) \
91276 ((mhdr)->msg_controllen - \
91277- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
91278+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
91279
91280 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
91281 struct compat_cmsghdr __user *cmsg, int cmsg_len)
91282 {
91283 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
91284- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
91285+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
91286 msg->msg_controllen)
91287 return NULL;
91288 return (struct compat_cmsghdr __user *)ptr;
91289@@ -219,7 +219,7 @@ Efault:
91290
91291 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
91292 {
91293- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
91294+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
91295 struct compat_cmsghdr cmhdr;
91296 struct compat_timeval ctv;
91297 struct compat_timespec cts[3];
91298@@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
91299
91300 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
91301 {
91302- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
91303+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
91304 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
91305 int fdnum = scm->fp->count;
91306 struct file **fp = scm->fp->fp;
91307@@ -363,7 +363,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
91308 return -EFAULT;
91309 old_fs = get_fs();
91310 set_fs(KERNEL_DS);
91311- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
91312+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
91313 set_fs(old_fs);
91314
91315 return err;
91316@@ -424,7 +424,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
91317 len = sizeof(ktime);
91318 old_fs = get_fs();
91319 set_fs(KERNEL_DS);
91320- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
91321+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
91322 set_fs(old_fs);
91323
91324 if (!err) {
91325@@ -567,7 +567,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
91326 case MCAST_JOIN_GROUP:
91327 case MCAST_LEAVE_GROUP:
91328 {
91329- struct compat_group_req __user *gr32 = (void *)optval;
91330+ struct compat_group_req __user *gr32 = (void __user *)optval;
91331 struct group_req __user *kgr =
91332 compat_alloc_user_space(sizeof(struct group_req));
91333 u32 interface;
91334@@ -588,7 +588,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
91335 case MCAST_BLOCK_SOURCE:
91336 case MCAST_UNBLOCK_SOURCE:
91337 {
91338- struct compat_group_source_req __user *gsr32 = (void *)optval;
91339+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
91340 struct group_source_req __user *kgsr = compat_alloc_user_space(
91341 sizeof(struct group_source_req));
91342 u32 interface;
91343@@ -609,7 +609,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
91344 }
91345 case MCAST_MSFILTER:
91346 {
91347- struct compat_group_filter __user *gf32 = (void *)optval;
91348+ struct compat_group_filter __user *gf32 = (void __user *)optval;
91349 struct group_filter __user *kgf;
91350 u32 interface, fmode, numsrc;
91351
91352@@ -647,7 +647,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
91353 char __user *optval, int __user *optlen,
91354 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
91355 {
91356- struct compat_group_filter __user *gf32 = (void *)optval;
91357+ struct compat_group_filter __user *gf32 = (void __user *)optval;
91358 struct group_filter __user *kgf;
91359 int __user *koptlen;
91360 u32 interface, fmode, numsrc;
91361@@ -805,7 +805,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
91362
91363 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
91364 return -EINVAL;
91365- if (copy_from_user(a, args, nas[call]))
91366+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
91367 return -EFAULT;
91368 a0 = a[0];
91369 a1 = a[1];
91370diff --git a/net/core/datagram.c b/net/core/datagram.c
91371index 8ab48cd..57b1a80 100644
91372--- a/net/core/datagram.c
91373+++ b/net/core/datagram.c
91374@@ -300,7 +300,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
91375 }
91376
91377 kfree_skb(skb);
91378- atomic_inc(&sk->sk_drops);
91379+ atomic_inc_unchecked(&sk->sk_drops);
91380 sk_mem_reclaim_partial(sk);
91381
91382 return err;
91383diff --git a/net/core/dev.c b/net/core/dev.c
91384index 26755dd..5020ced 100644
91385--- a/net/core/dev.c
91386+++ b/net/core/dev.c
91387@@ -1680,14 +1680,14 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
91388 {
91389 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
91390 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
91391- atomic_long_inc(&dev->rx_dropped);
91392+ atomic_long_inc_unchecked(&dev->rx_dropped);
91393 kfree_skb(skb);
91394 return NET_RX_DROP;
91395 }
91396 }
91397
91398 if (unlikely(!is_skb_forwardable(dev, skb))) {
91399- atomic_long_inc(&dev->rx_dropped);
91400+ atomic_long_inc_unchecked(&dev->rx_dropped);
91401 kfree_skb(skb);
91402 return NET_RX_DROP;
91403 }
91404@@ -2431,7 +2431,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
91405
91406 struct dev_gso_cb {
91407 void (*destructor)(struct sk_buff *skb);
91408-};
91409+} __no_const;
91410
91411 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
91412
91413@@ -3206,7 +3206,7 @@ enqueue:
91414
91415 local_irq_restore(flags);
91416
91417- atomic_long_inc(&skb->dev->rx_dropped);
91418+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
91419 kfree_skb(skb);
91420 return NET_RX_DROP;
91421 }
91422@@ -3278,7 +3278,7 @@ int netif_rx_ni(struct sk_buff *skb)
91423 }
91424 EXPORT_SYMBOL(netif_rx_ni);
91425
91426-static void net_tx_action(struct softirq_action *h)
91427+static void net_tx_action(void)
91428 {
91429 struct softnet_data *sd = &__get_cpu_var(softnet_data);
91430
91431@@ -3612,7 +3612,7 @@ ncls:
91432 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
91433 } else {
91434 drop:
91435- atomic_long_inc(&skb->dev->rx_dropped);
91436+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
91437 kfree_skb(skb);
91438 /* Jamal, now you will not able to escape explaining
91439 * me how you were going to use this. :-)
91440@@ -4272,7 +4272,7 @@ void netif_napi_del(struct napi_struct *napi)
91441 }
91442 EXPORT_SYMBOL(netif_napi_del);
91443
91444-static void net_rx_action(struct softirq_action *h)
91445+static void net_rx_action(void)
91446 {
91447 struct softnet_data *sd = &__get_cpu_var(softnet_data);
91448 unsigned long time_limit = jiffies + 2;
91449@@ -5730,7 +5730,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
91450 } else {
91451 netdev_stats_to_stats64(storage, &dev->stats);
91452 }
91453- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
91454+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
91455 return storage;
91456 }
91457 EXPORT_SYMBOL(dev_get_stats);
91458diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
91459index 5b7d0e1..cb960fc 100644
91460--- a/net/core/dev_ioctl.c
91461+++ b/net/core/dev_ioctl.c
91462@@ -365,9 +365,13 @@ void dev_load(struct net *net, const char *name)
91463 if (no_module && capable(CAP_NET_ADMIN))
91464 no_module = request_module("netdev-%s", name);
91465 if (no_module && capable(CAP_SYS_MODULE)) {
91466+#ifdef CONFIG_GRKERNSEC_MODHARDEN
91467+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
91468+#else
91469 if (!request_module("%s", name))
91470 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
91471 name);
91472+#endif
91473 }
91474 }
91475 EXPORT_SYMBOL(dev_load);
91476diff --git a/net/core/flow.c b/net/core/flow.c
91477index dfa602c..3103d88 100644
91478--- a/net/core/flow.c
91479+++ b/net/core/flow.c
91480@@ -61,7 +61,7 @@ struct flow_cache {
91481 struct timer_list rnd_timer;
91482 };
91483
91484-atomic_t flow_cache_genid = ATOMIC_INIT(0);
91485+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
91486 EXPORT_SYMBOL(flow_cache_genid);
91487 static struct flow_cache flow_cache_global;
91488 static struct kmem_cache *flow_cachep __read_mostly;
91489@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
91490
91491 static int flow_entry_valid(struct flow_cache_entry *fle)
91492 {
91493- if (atomic_read(&flow_cache_genid) != fle->genid)
91494+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
91495 return 0;
91496 if (fle->object && !fle->object->ops->check(fle->object))
91497 return 0;
91498@@ -258,7 +258,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
91499 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
91500 fcp->hash_count++;
91501 }
91502- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
91503+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
91504 flo = fle->object;
91505 if (!flo)
91506 goto ret_object;
91507@@ -279,7 +279,7 @@ nocache:
91508 }
91509 flo = resolver(net, key, family, dir, flo, ctx);
91510 if (fle) {
91511- fle->genid = atomic_read(&flow_cache_genid);
91512+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
91513 if (!IS_ERR(flo))
91514 fle->object = flo;
91515 else
91516diff --git a/net/core/iovec.c b/net/core/iovec.c
91517index de178e4..1dabd8b 100644
91518--- a/net/core/iovec.c
91519+++ b/net/core/iovec.c
91520@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
91521 if (m->msg_namelen) {
91522 if (mode == VERIFY_READ) {
91523 void __user *namep;
91524- namep = (void __user __force *) m->msg_name;
91525+ namep = (void __force_user *) m->msg_name;
91526 err = move_addr_to_kernel(namep, m->msg_namelen,
91527 address);
91528 if (err < 0)
91529@@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
91530 }
91531
91532 size = m->msg_iovlen * sizeof(struct iovec);
91533- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
91534+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
91535 return -EFAULT;
91536
91537 m->msg_iov = iov;
91538diff --git a/net/core/neighbour.c b/net/core/neighbour.c
91539index 60533db..14842cc 100644
91540--- a/net/core/neighbour.c
91541+++ b/net/core/neighbour.c
91542@@ -2776,7 +2776,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
91543 void __user *buffer, size_t *lenp, loff_t *ppos)
91544 {
91545 int size, ret;
91546- struct ctl_table tmp = *ctl;
91547+ ctl_table_no_const tmp = *ctl;
91548
91549 tmp.extra1 = &zero;
91550 tmp.extra2 = &unres_qlen_max;
91551diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
91552index 2bf8329..7960607 100644
91553--- a/net/core/net-procfs.c
91554+++ b/net/core/net-procfs.c
91555@@ -283,8 +283,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
91556 else
91557 seq_printf(seq, "%04x", ntohs(pt->type));
91558
91559+#ifdef CONFIG_GRKERNSEC_HIDESYM
91560+ seq_printf(seq, " %-8s %pf\n",
91561+ pt->dev ? pt->dev->name : "", NULL);
91562+#else
91563 seq_printf(seq, " %-8s %pf\n",
91564 pt->dev ? pt->dev->name : "", pt->func);
91565+#endif
91566 }
91567
91568 return 0;
91569diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
91570index 981fed3..536af34 100644
91571--- a/net/core/net-sysfs.c
91572+++ b/net/core/net-sysfs.c
91573@@ -1311,7 +1311,7 @@ void netdev_class_remove_file(struct class_attribute *class_attr)
91574 }
91575 EXPORT_SYMBOL(netdev_class_remove_file);
91576
91577-int netdev_kobject_init(void)
91578+int __init netdev_kobject_init(void)
91579 {
91580 kobj_ns_type_register(&net_ns_type_operations);
91581 return class_register(&net_class);
91582diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
91583index f9765203..9feaef8 100644
91584--- a/net/core/net_namespace.c
91585+++ b/net/core/net_namespace.c
91586@@ -443,7 +443,7 @@ static int __register_pernet_operations(struct list_head *list,
91587 int error;
91588 LIST_HEAD(net_exit_list);
91589
91590- list_add_tail(&ops->list, list);
91591+ pax_list_add_tail((struct list_head *)&ops->list, list);
91592 if (ops->init || (ops->id && ops->size)) {
91593 for_each_net(net) {
91594 error = ops_init(ops, net);
91595@@ -456,7 +456,7 @@ static int __register_pernet_operations(struct list_head *list,
91596
91597 out_undo:
91598 /* If I have an error cleanup all namespaces I initialized */
91599- list_del(&ops->list);
91600+ pax_list_del((struct list_head *)&ops->list);
91601 ops_exit_list(ops, &net_exit_list);
91602 ops_free_list(ops, &net_exit_list);
91603 return error;
91604@@ -467,7 +467,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
91605 struct net *net;
91606 LIST_HEAD(net_exit_list);
91607
91608- list_del(&ops->list);
91609+ pax_list_del((struct list_head *)&ops->list);
91610 for_each_net(net)
91611 list_add_tail(&net->exit_list, &net_exit_list);
91612 ops_exit_list(ops, &net_exit_list);
91613@@ -601,7 +601,7 @@ int register_pernet_device(struct pernet_operations *ops)
91614 mutex_lock(&net_mutex);
91615 error = register_pernet_operations(&pernet_list, ops);
91616 if (!error && (first_device == &pernet_list))
91617- first_device = &ops->list;
91618+ first_device = (struct list_head *)&ops->list;
91619 mutex_unlock(&net_mutex);
91620 return error;
91621 }
91622diff --git a/net/core/netpoll.c b/net/core/netpoll.c
91623index 2c637e9..68c9087 100644
91624--- a/net/core/netpoll.c
91625+++ b/net/core/netpoll.c
91626@@ -428,7 +428,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
91627 struct udphdr *udph;
91628 struct iphdr *iph;
91629 struct ethhdr *eth;
91630- static atomic_t ip_ident;
91631+ static atomic_unchecked_t ip_ident;
91632 struct ipv6hdr *ip6h;
91633
91634 udp_len = len + sizeof(*udph);
91635@@ -499,7 +499,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
91636 put_unaligned(0x45, (unsigned char *)iph);
91637 iph->tos = 0;
91638 put_unaligned(htons(ip_len), &(iph->tot_len));
91639- iph->id = htons(atomic_inc_return(&ip_ident));
91640+ iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
91641 iph->frag_off = 0;
91642 iph->ttl = 64;
91643 iph->protocol = IPPROTO_UDP;
91644diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
91645index ca198c1d1..125372f 100644
91646--- a/net/core/rtnetlink.c
91647+++ b/net/core/rtnetlink.c
91648@@ -58,7 +58,7 @@ struct rtnl_link {
91649 rtnl_doit_func doit;
91650 rtnl_dumpit_func dumpit;
91651 rtnl_calcit_func calcit;
91652-};
91653+} __no_const;
91654
91655 static DEFINE_MUTEX(rtnl_mutex);
91656
91657@@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
91658 if (rtnl_link_ops_get(ops->kind))
91659 return -EEXIST;
91660
91661- if (!ops->dellink)
91662- ops->dellink = unregister_netdevice_queue;
91663+ if (!ops->dellink) {
91664+ pax_open_kernel();
91665+ *(void **)&ops->dellink = unregister_netdevice_queue;
91666+ pax_close_kernel();
91667+ }
91668
91669- list_add_tail(&ops->list, &link_ops);
91670+ pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
91671 return 0;
91672 }
91673 EXPORT_SYMBOL_GPL(__rtnl_link_register);
91674@@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
91675 for_each_net(net) {
91676 __rtnl_kill_links(net, ops);
91677 }
91678- list_del(&ops->list);
91679+ pax_list_del((struct list_head *)&ops->list);
91680 }
91681 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
91682
91683diff --git a/net/core/scm.c b/net/core/scm.c
91684index b4da80b..98d6bdb 100644
91685--- a/net/core/scm.c
91686+++ b/net/core/scm.c
91687@@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
91688 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
91689 {
91690 struct cmsghdr __user *cm
91691- = (__force struct cmsghdr __user *)msg->msg_control;
91692+ = (struct cmsghdr __force_user *)msg->msg_control;
91693 struct cmsghdr cmhdr;
91694 int cmlen = CMSG_LEN(len);
91695 int err;
91696@@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
91697 err = -EFAULT;
91698 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
91699 goto out;
91700- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
91701+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
91702 goto out;
91703 cmlen = CMSG_SPACE(len);
91704 if (msg->msg_controllen < cmlen)
91705@@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
91706 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
91707 {
91708 struct cmsghdr __user *cm
91709- = (__force struct cmsghdr __user*)msg->msg_control;
91710+ = (struct cmsghdr __force_user *)msg->msg_control;
91711
91712 int fdmax = 0;
91713 int fdnum = scm->fp->count;
91714@@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
91715 if (fdnum < fdmax)
91716 fdmax = fdnum;
91717
91718- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
91719+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
91720 i++, cmfptr++)
91721 {
91722 struct socket *sock;
91723diff --git a/net/core/skbuff.c b/net/core/skbuff.c
91724index 2c3d0f5..f5a326f 100644
91725--- a/net/core/skbuff.c
91726+++ b/net/core/skbuff.c
91727@@ -3082,13 +3082,15 @@ void __init skb_init(void)
91728 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
91729 sizeof(struct sk_buff),
91730 0,
91731- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
91732+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
91733+ SLAB_NO_SANITIZE,
91734 NULL);
91735 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
91736 (2*sizeof(struct sk_buff)) +
91737 sizeof(atomic_t),
91738 0,
91739- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
91740+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
91741+ SLAB_NO_SANITIZE,
91742 NULL);
91743 }
91744
91745diff --git a/net/core/sock.c b/net/core/sock.c
91746index 2c097c5..bf72858 100644
91747--- a/net/core/sock.c
91748+++ b/net/core/sock.c
91749@@ -392,7 +392,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
91750 struct sk_buff_head *list = &sk->sk_receive_queue;
91751
91752 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
91753- atomic_inc(&sk->sk_drops);
91754+ atomic_inc_unchecked(&sk->sk_drops);
91755 trace_sock_rcvqueue_full(sk, skb);
91756 return -ENOMEM;
91757 }
91758@@ -402,7 +402,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
91759 return err;
91760
91761 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
91762- atomic_inc(&sk->sk_drops);
91763+ atomic_inc_unchecked(&sk->sk_drops);
91764 return -ENOBUFS;
91765 }
91766
91767@@ -422,7 +422,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
91768 skb_dst_force(skb);
91769
91770 spin_lock_irqsave(&list->lock, flags);
91771- skb->dropcount = atomic_read(&sk->sk_drops);
91772+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
91773 __skb_queue_tail(list, skb);
91774 spin_unlock_irqrestore(&list->lock, flags);
91775
91776@@ -442,7 +442,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
91777 skb->dev = NULL;
91778
91779 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
91780- atomic_inc(&sk->sk_drops);
91781+ atomic_inc_unchecked(&sk->sk_drops);
91782 goto discard_and_relse;
91783 }
91784 if (nested)
91785@@ -460,7 +460,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
91786 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
91787 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
91788 bh_unlock_sock(sk);
91789- atomic_inc(&sk->sk_drops);
91790+ atomic_inc_unchecked(&sk->sk_drops);
91791 goto discard_and_relse;
91792 }
91793
91794@@ -948,12 +948,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
91795 struct timeval tm;
91796 } v;
91797
91798- int lv = sizeof(int);
91799- int len;
91800+ unsigned int lv = sizeof(int);
91801+ unsigned int len;
91802
91803 if (get_user(len, optlen))
91804 return -EFAULT;
91805- if (len < 0)
91806+ if (len > INT_MAX)
91807 return -EINVAL;
91808
91809 memset(&v, 0, sizeof(v));
91810@@ -1105,11 +1105,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
91811
91812 case SO_PEERNAME:
91813 {
91814- char address[128];
91815+ char address[_K_SS_MAXSIZE];
91816
91817 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
91818 return -ENOTCONN;
91819- if (lv < len)
91820+ if (lv < len || sizeof address < len)
91821 return -EINVAL;
91822 if (copy_to_user(optval, address, len))
91823 return -EFAULT;
91824@@ -1182,7 +1182,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
91825
91826 if (len > lv)
91827 len = lv;
91828- if (copy_to_user(optval, &v, len))
91829+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
91830 return -EFAULT;
91831 lenout:
91832 if (put_user(len, optlen))
91833@@ -2303,7 +2303,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
91834 */
91835 smp_wmb();
91836 atomic_set(&sk->sk_refcnt, 1);
91837- atomic_set(&sk->sk_drops, 0);
91838+ atomic_set_unchecked(&sk->sk_drops, 0);
91839 }
91840 EXPORT_SYMBOL(sock_init_data);
91841
91842diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
91843index a0e9cf6..ef7f9ed 100644
91844--- a/net/core/sock_diag.c
91845+++ b/net/core/sock_diag.c
91846@@ -9,26 +9,33 @@
91847 #include <linux/inet_diag.h>
91848 #include <linux/sock_diag.h>
91849
91850-static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
91851+static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
91852 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
91853 static DEFINE_MUTEX(sock_diag_table_mutex);
91854
91855 int sock_diag_check_cookie(void *sk, __u32 *cookie)
91856 {
91857+#ifndef CONFIG_GRKERNSEC_HIDESYM
91858 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
91859 cookie[1] != INET_DIAG_NOCOOKIE) &&
91860 ((u32)(unsigned long)sk != cookie[0] ||
91861 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
91862 return -ESTALE;
91863 else
91864+#endif
91865 return 0;
91866 }
91867 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
91868
91869 void sock_diag_save_cookie(void *sk, __u32 *cookie)
91870 {
91871+#ifdef CONFIG_GRKERNSEC_HIDESYM
91872+ cookie[0] = 0;
91873+ cookie[1] = 0;
91874+#else
91875 cookie[0] = (u32)(unsigned long)sk;
91876 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
91877+#endif
91878 }
91879 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
91880
91881@@ -113,8 +120,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
91882 mutex_lock(&sock_diag_table_mutex);
91883 if (sock_diag_handlers[hndl->family])
91884 err = -EBUSY;
91885- else
91886+ else {
91887+ pax_open_kernel();
91888 sock_diag_handlers[hndl->family] = hndl;
91889+ pax_close_kernel();
91890+ }
91891 mutex_unlock(&sock_diag_table_mutex);
91892
91893 return err;
91894@@ -130,7 +140,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
91895
91896 mutex_lock(&sock_diag_table_mutex);
91897 BUG_ON(sock_diag_handlers[family] != hnld);
91898+ pax_open_kernel();
91899 sock_diag_handlers[family] = NULL;
91900+ pax_close_kernel();
91901 mutex_unlock(&sock_diag_table_mutex);
91902 }
91903 EXPORT_SYMBOL_GPL(sock_diag_unregister);
91904diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
91905index 31107ab..ae03d5a 100644
91906--- a/net/core/sysctl_net_core.c
91907+++ b/net/core/sysctl_net_core.c
91908@@ -31,7 +31,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
91909 {
91910 unsigned int orig_size, size;
91911 int ret, i;
91912- struct ctl_table tmp = {
91913+ ctl_table_no_const tmp = {
91914 .data = &size,
91915 .maxlen = sizeof(size),
91916 .mode = table->mode
91917@@ -350,13 +350,12 @@ static struct ctl_table netns_core_table[] = {
91918
91919 static __net_init int sysctl_core_net_init(struct net *net)
91920 {
91921- struct ctl_table *tbl;
91922+ ctl_table_no_const *tbl = NULL;
91923
91924 net->core.sysctl_somaxconn = SOMAXCONN;
91925
91926- tbl = netns_core_table;
91927 if (!net_eq(net, &init_net)) {
91928- tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
91929+ tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
91930 if (tbl == NULL)
91931 goto err_dup;
91932
91933@@ -366,17 +365,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
91934 if (net->user_ns != &init_user_ns) {
91935 tbl[0].procname = NULL;
91936 }
91937- }
91938-
91939- net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
91940+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
91941+ } else
91942+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
91943 if (net->core.sysctl_hdr == NULL)
91944 goto err_reg;
91945
91946 return 0;
91947
91948 err_reg:
91949- if (tbl != netns_core_table)
91950- kfree(tbl);
91951+ kfree(tbl);
91952 err_dup:
91953 return -ENOMEM;
91954 }
91955@@ -391,7 +389,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
91956 kfree(tbl);
91957 }
91958
91959-static __net_initdata struct pernet_operations sysctl_core_ops = {
91960+static __net_initconst struct pernet_operations sysctl_core_ops = {
91961 .init = sysctl_core_net_init,
91962 .exit = sysctl_core_net_exit,
91963 };
91964diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
91965index dd4d506..fb2fb87 100644
91966--- a/net/decnet/af_decnet.c
91967+++ b/net/decnet/af_decnet.c
91968@@ -465,6 +465,7 @@ static struct proto dn_proto = {
91969 .sysctl_rmem = sysctl_decnet_rmem,
91970 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
91971 .obj_size = sizeof(struct dn_sock),
91972+ .slab_flags = SLAB_USERCOPY,
91973 };
91974
91975 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
91976diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
91977index 5325b54..a0d4d69 100644
91978--- a/net/decnet/sysctl_net_decnet.c
91979+++ b/net/decnet/sysctl_net_decnet.c
91980@@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
91981
91982 if (len > *lenp) len = *lenp;
91983
91984- if (copy_to_user(buffer, addr, len))
91985+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
91986 return -EFAULT;
91987
91988 *lenp = len;
91989@@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
91990
91991 if (len > *lenp) len = *lenp;
91992
91993- if (copy_to_user(buffer, devname, len))
91994+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
91995 return -EFAULT;
91996
91997 *lenp = len;
91998diff --git a/net/ieee802154/6lowpan.c b/net/ieee802154/6lowpan.c
91999index 3b9d5f2..d7015c6 100644
92000--- a/net/ieee802154/6lowpan.c
92001+++ b/net/ieee802154/6lowpan.c
92002@@ -459,7 +459,7 @@ static int lowpan_header_create(struct sk_buff *skb,
92003 hc06_ptr += 3;
92004 } else {
92005 /* compress nothing */
92006- memcpy(hc06_ptr, &hdr, 4);
92007+ memcpy(hc06_ptr, hdr, 4);
92008 /* replace the top byte with new ECN | DSCP format */
92009 *hc06_ptr = tmp;
92010 hc06_ptr += 4;
92011diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
92012index b4d0be2..443d0f0 100644
92013--- a/net/ipv4/af_inet.c
92014+++ b/net/ipv4/af_inet.c
92015@@ -1689,13 +1689,9 @@ static int __init inet_init(void)
92016
92017 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb));
92018
92019- sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
92020- if (!sysctl_local_reserved_ports)
92021- goto out;
92022-
92023 rc = proto_register(&tcp_prot, 1);
92024 if (rc)
92025- goto out_free_reserved_ports;
92026+ goto out;
92027
92028 rc = proto_register(&udp_prot, 1);
92029 if (rc)
92030@@ -1804,8 +1800,6 @@ out_unregister_udp_proto:
92031 proto_unregister(&udp_prot);
92032 out_unregister_tcp_proto:
92033 proto_unregister(&tcp_prot);
92034-out_free_reserved_ports:
92035- kfree(sysctl_local_reserved_ports);
92036 goto out;
92037 }
92038
92039diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
92040index 34ca6d5..b6421e8 100644
92041--- a/net/ipv4/devinet.c
92042+++ b/net/ipv4/devinet.c
92043@@ -1532,7 +1532,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
92044 idx = 0;
92045 head = &net->dev_index_head[h];
92046 rcu_read_lock();
92047- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
92048+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
92049 net->dev_base_seq;
92050 hlist_for_each_entry_rcu(dev, head, index_hlist) {
92051 if (idx < s_idx)
92052@@ -1843,7 +1843,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
92053 idx = 0;
92054 head = &net->dev_index_head[h];
92055 rcu_read_lock();
92056- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
92057+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
92058 net->dev_base_seq;
92059 hlist_for_each_entry_rcu(dev, head, index_hlist) {
92060 if (idx < s_idx)
92061@@ -2068,7 +2068,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
92062 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
92063 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
92064
92065-static struct devinet_sysctl_table {
92066+static const struct devinet_sysctl_table {
92067 struct ctl_table_header *sysctl_header;
92068 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
92069 } devinet_sysctl = {
92070@@ -2186,7 +2186,7 @@ static __net_init int devinet_init_net(struct net *net)
92071 int err;
92072 struct ipv4_devconf *all, *dflt;
92073 #ifdef CONFIG_SYSCTL
92074- struct ctl_table *tbl = ctl_forward_entry;
92075+ ctl_table_no_const *tbl = NULL;
92076 struct ctl_table_header *forw_hdr;
92077 #endif
92078
92079@@ -2204,7 +2204,7 @@ static __net_init int devinet_init_net(struct net *net)
92080 goto err_alloc_dflt;
92081
92082 #ifdef CONFIG_SYSCTL
92083- tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
92084+ tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
92085 if (tbl == NULL)
92086 goto err_alloc_ctl;
92087
92088@@ -2224,7 +2224,10 @@ static __net_init int devinet_init_net(struct net *net)
92089 goto err_reg_dflt;
92090
92091 err = -ENOMEM;
92092- forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
92093+ if (!net_eq(net, &init_net))
92094+ forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
92095+ else
92096+ forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
92097 if (forw_hdr == NULL)
92098 goto err_reg_ctl;
92099 net->ipv4.forw_hdr = forw_hdr;
92100@@ -2240,8 +2243,7 @@ err_reg_ctl:
92101 err_reg_dflt:
92102 __devinet_sysctl_unregister(all);
92103 err_reg_all:
92104- if (tbl != ctl_forward_entry)
92105- kfree(tbl);
92106+ kfree(tbl);
92107 err_alloc_ctl:
92108 #endif
92109 if (dflt != &ipv4_devconf_dflt)
92110diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
92111index b3f627a..b0f3e99 100644
92112--- a/net/ipv4/fib_frontend.c
92113+++ b/net/ipv4/fib_frontend.c
92114@@ -1017,12 +1017,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
92115 #ifdef CONFIG_IP_ROUTE_MULTIPATH
92116 fib_sync_up(dev);
92117 #endif
92118- atomic_inc(&net->ipv4.dev_addr_genid);
92119+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
92120 rt_cache_flush(dev_net(dev));
92121 break;
92122 case NETDEV_DOWN:
92123 fib_del_ifaddr(ifa, NULL);
92124- atomic_inc(&net->ipv4.dev_addr_genid);
92125+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
92126 if (ifa->ifa_dev->ifa_list == NULL) {
92127 /* Last address was deleted from this interface.
92128 * Disable IP.
92129@@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
92130 #ifdef CONFIG_IP_ROUTE_MULTIPATH
92131 fib_sync_up(dev);
92132 #endif
92133- atomic_inc(&net->ipv4.dev_addr_genid);
92134+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
92135 rt_cache_flush(net);
92136 break;
92137 case NETDEV_DOWN:
92138diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
92139index d5dbca5..6251d5f 100644
92140--- a/net/ipv4/fib_semantics.c
92141+++ b/net/ipv4/fib_semantics.c
92142@@ -766,7 +766,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
92143 nh->nh_saddr = inet_select_addr(nh->nh_dev,
92144 nh->nh_gw,
92145 nh->nh_parent->fib_scope);
92146- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
92147+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
92148
92149 return nh->nh_saddr;
92150 }
92151diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
92152index 6acb541..9ea617d 100644
92153--- a/net/ipv4/inet_connection_sock.c
92154+++ b/net/ipv4/inet_connection_sock.c
92155@@ -37,7 +37,7 @@ struct local_ports sysctl_local_ports __read_mostly = {
92156 .range = { 32768, 61000 },
92157 };
92158
92159-unsigned long *sysctl_local_reserved_ports;
92160+unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
92161 EXPORT_SYMBOL(sysctl_local_reserved_ports);
92162
92163 void inet_get_local_port_range(int *low, int *high)
92164diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
92165index 7bd8983..3abdcf6 100644
92166--- a/net/ipv4/inet_hashtables.c
92167+++ b/net/ipv4/inet_hashtables.c
92168@@ -18,12 +18,15 @@
92169 #include <linux/sched.h>
92170 #include <linux/slab.h>
92171 #include <linux/wait.h>
92172+#include <linux/security.h>
92173
92174 #include <net/inet_connection_sock.h>
92175 #include <net/inet_hashtables.h>
92176 #include <net/secure_seq.h>
92177 #include <net/ip.h>
92178
92179+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
92180+
92181 /*
92182 * Allocate and initialize a new local port bind bucket.
92183 * The bindhash mutex for snum's hash chain must be held here.
92184@@ -554,6 +557,8 @@ ok:
92185 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
92186 spin_unlock(&head->lock);
92187
92188+ gr_update_task_in_ip_table(current, inet_sk(sk));
92189+
92190 if (tw) {
92191 inet_twsk_deschedule(tw, death_row);
92192 while (twrefcnt) {
92193diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
92194index 000e3d2..5472da3 100644
92195--- a/net/ipv4/inetpeer.c
92196+++ b/net/ipv4/inetpeer.c
92197@@ -503,8 +503,8 @@ relookup:
92198 if (p) {
92199 p->daddr = *daddr;
92200 atomic_set(&p->refcnt, 1);
92201- atomic_set(&p->rid, 0);
92202- atomic_set(&p->ip_id_count,
92203+ atomic_set_unchecked(&p->rid, 0);
92204+ atomic_set_unchecked(&p->ip_id_count,
92205 (daddr->family == AF_INET) ?
92206 secure_ip_id(daddr->addr.a4) :
92207 secure_ipv6_id(daddr->addr.a6));
92208diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
92209index b66910a..cfe416e 100644
92210--- a/net/ipv4/ip_fragment.c
92211+++ b/net/ipv4/ip_fragment.c
92212@@ -282,7 +282,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
92213 return 0;
92214
92215 start = qp->rid;
92216- end = atomic_inc_return(&peer->rid);
92217+ end = atomic_inc_return_unchecked(&peer->rid);
92218 qp->rid = end;
92219
92220 rc = qp->q.fragments && (end - start) > max;
92221@@ -759,12 +759,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
92222
92223 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
92224 {
92225- struct ctl_table *table;
92226+ ctl_table_no_const *table = NULL;
92227 struct ctl_table_header *hdr;
92228
92229- table = ip4_frags_ns_ctl_table;
92230 if (!net_eq(net, &init_net)) {
92231- table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
92232+ table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
92233 if (table == NULL)
92234 goto err_alloc;
92235
92236@@ -775,9 +774,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
92237 /* Don't export sysctls to unprivileged users */
92238 if (net->user_ns != &init_user_ns)
92239 table[0].procname = NULL;
92240- }
92241+ hdr = register_net_sysctl(net, "net/ipv4", table);
92242+ } else
92243+ hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
92244
92245- hdr = register_net_sysctl(net, "net/ipv4", table);
92246 if (hdr == NULL)
92247 goto err_reg;
92248
92249@@ -785,8 +785,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
92250 return 0;
92251
92252 err_reg:
92253- if (!net_eq(net, &init_net))
92254- kfree(table);
92255+ kfree(table);
92256 err_alloc:
92257 return -ENOMEM;
92258 }
92259diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
92260index 8d6939e..19d0a95 100644
92261--- a/net/ipv4/ip_gre.c
92262+++ b/net/ipv4/ip_gre.c
92263@@ -115,7 +115,7 @@ static bool log_ecn_error = true;
92264 module_param(log_ecn_error, bool, 0644);
92265 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
92266
92267-static struct rtnl_link_ops ipgre_link_ops __read_mostly;
92268+static struct rtnl_link_ops ipgre_link_ops;
92269 static int ipgre_tunnel_init(struct net_device *dev);
92270
92271 static int ipgre_net_id __read_mostly;
92272@@ -731,7 +731,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
92273 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
92274 };
92275
92276-static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
92277+static struct rtnl_link_ops ipgre_link_ops = {
92278 .kind = "gre",
92279 .maxtype = IFLA_GRE_MAX,
92280 .policy = ipgre_policy,
92281@@ -745,7 +745,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
92282 .fill_info = ipgre_fill_info,
92283 };
92284
92285-static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
92286+static struct rtnl_link_ops ipgre_tap_ops = {
92287 .kind = "gretap",
92288 .maxtype = IFLA_GRE_MAX,
92289 .policy = ipgre_policy,
92290diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
92291index d9c4f11..02b82dbc 100644
92292--- a/net/ipv4/ip_sockglue.c
92293+++ b/net/ipv4/ip_sockglue.c
92294@@ -1152,7 +1152,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
92295 len = min_t(unsigned int, len, opt->optlen);
92296 if (put_user(len, optlen))
92297 return -EFAULT;
92298- if (copy_to_user(optval, opt->__data, len))
92299+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
92300+ copy_to_user(optval, opt->__data, len))
92301 return -EFAULT;
92302 return 0;
92303 }
92304@@ -1283,7 +1284,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
92305 if (sk->sk_type != SOCK_STREAM)
92306 return -ENOPROTOOPT;
92307
92308- msg.msg_control = optval;
92309+ msg.msg_control = (void __force_kernel *)optval;
92310 msg.msg_controllen = len;
92311 msg.msg_flags = flags;
92312
92313diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
92314index 17cc0ff..63856c4 100644
92315--- a/net/ipv4/ip_vti.c
92316+++ b/net/ipv4/ip_vti.c
92317@@ -47,7 +47,7 @@
92318 #define HASH_SIZE 16
92319 #define HASH(addr) (((__force u32)addr^((__force u32)addr>>4))&(HASH_SIZE-1))
92320
92321-static struct rtnl_link_ops vti_link_ops __read_mostly;
92322+static struct rtnl_link_ops vti_link_ops;
92323
92324 static int vti_net_id __read_mostly;
92325 struct vti_net {
92326@@ -840,7 +840,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
92327 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
92328 };
92329
92330-static struct rtnl_link_ops vti_link_ops __read_mostly = {
92331+static struct rtnl_link_ops vti_link_ops = {
92332 .kind = "vti",
92333 .maxtype = IFLA_VTI_MAX,
92334 .policy = vti_policy,
92335diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
92336index efa1138..20dbba0 100644
92337--- a/net/ipv4/ipconfig.c
92338+++ b/net/ipv4/ipconfig.c
92339@@ -334,7 +334,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
92340
92341 mm_segment_t oldfs = get_fs();
92342 set_fs(get_ds());
92343- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
92344+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
92345 set_fs(oldfs);
92346 return res;
92347 }
92348@@ -345,7 +345,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
92349
92350 mm_segment_t oldfs = get_fs();
92351 set_fs(get_ds());
92352- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
92353+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
92354 set_fs(oldfs);
92355 return res;
92356 }
92357@@ -356,7 +356,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
92358
92359 mm_segment_t oldfs = get_fs();
92360 set_fs(get_ds());
92361- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
92362+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
92363 set_fs(oldfs);
92364 return res;
92365 }
92366diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
92367index b3ac3c3..ec6bd95 100644
92368--- a/net/ipv4/ipip.c
92369+++ b/net/ipv4/ipip.c
92370@@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
92371 static int ipip_net_id __read_mostly;
92372
92373 static int ipip_tunnel_init(struct net_device *dev);
92374-static struct rtnl_link_ops ipip_link_ops __read_mostly;
92375+static struct rtnl_link_ops ipip_link_ops;
92376
92377 static int ipip_err(struct sk_buff *skb, u32 info)
92378 {
92379@@ -409,7 +409,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
92380 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
92381 };
92382
92383-static struct rtnl_link_ops ipip_link_ops __read_mostly = {
92384+static struct rtnl_link_ops ipip_link_ops = {
92385 .kind = "ipip",
92386 .maxtype = IFLA_IPTUN_MAX,
92387 .policy = ipip_policy,
92388diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
92389index 85a4f21..1beb1f5 100644
92390--- a/net/ipv4/netfilter/arp_tables.c
92391+++ b/net/ipv4/netfilter/arp_tables.c
92392@@ -880,14 +880,14 @@ static int compat_table_info(const struct xt_table_info *info,
92393 #endif
92394
92395 static int get_info(struct net *net, void __user *user,
92396- const int *len, int compat)
92397+ int len, int compat)
92398 {
92399 char name[XT_TABLE_MAXNAMELEN];
92400 struct xt_table *t;
92401 int ret;
92402
92403- if (*len != sizeof(struct arpt_getinfo)) {
92404- duprintf("length %u != %Zu\n", *len,
92405+ if (len != sizeof(struct arpt_getinfo)) {
92406+ duprintf("length %u != %Zu\n", len,
92407 sizeof(struct arpt_getinfo));
92408 return -EINVAL;
92409 }
92410@@ -924,7 +924,7 @@ static int get_info(struct net *net, void __user *user,
92411 info.size = private->size;
92412 strcpy(info.name, name);
92413
92414- if (copy_to_user(user, &info, *len) != 0)
92415+ if (copy_to_user(user, &info, len) != 0)
92416 ret = -EFAULT;
92417 else
92418 ret = 0;
92419@@ -1683,7 +1683,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
92420
92421 switch (cmd) {
92422 case ARPT_SO_GET_INFO:
92423- ret = get_info(sock_net(sk), user, len, 1);
92424+ ret = get_info(sock_net(sk), user, *len, 1);
92425 break;
92426 case ARPT_SO_GET_ENTRIES:
92427 ret = compat_get_entries(sock_net(sk), user, len);
92428@@ -1728,7 +1728,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
92429
92430 switch (cmd) {
92431 case ARPT_SO_GET_INFO:
92432- ret = get_info(sock_net(sk), user, len, 0);
92433+ ret = get_info(sock_net(sk), user, *len, 0);
92434 break;
92435
92436 case ARPT_SO_GET_ENTRIES:
92437diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
92438index d23118d..6ad7277 100644
92439--- a/net/ipv4/netfilter/ip_tables.c
92440+++ b/net/ipv4/netfilter/ip_tables.c
92441@@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
92442 #endif
92443
92444 static int get_info(struct net *net, void __user *user,
92445- const int *len, int compat)
92446+ int len, int compat)
92447 {
92448 char name[XT_TABLE_MAXNAMELEN];
92449 struct xt_table *t;
92450 int ret;
92451
92452- if (*len != sizeof(struct ipt_getinfo)) {
92453- duprintf("length %u != %zu\n", *len,
92454+ if (len != sizeof(struct ipt_getinfo)) {
92455+ duprintf("length %u != %zu\n", len,
92456 sizeof(struct ipt_getinfo));
92457 return -EINVAL;
92458 }
92459@@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
92460 info.size = private->size;
92461 strcpy(info.name, name);
92462
92463- if (copy_to_user(user, &info, *len) != 0)
92464+ if (copy_to_user(user, &info, len) != 0)
92465 ret = -EFAULT;
92466 else
92467 ret = 0;
92468@@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
92469
92470 switch (cmd) {
92471 case IPT_SO_GET_INFO:
92472- ret = get_info(sock_net(sk), user, len, 1);
92473+ ret = get_info(sock_net(sk), user, *len, 1);
92474 break;
92475 case IPT_SO_GET_ENTRIES:
92476 ret = compat_get_entries(sock_net(sk), user, len);
92477@@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
92478
92479 switch (cmd) {
92480 case IPT_SO_GET_INFO:
92481- ret = get_info(sock_net(sk), user, len, 0);
92482+ ret = get_info(sock_net(sk), user, *len, 0);
92483 break;
92484
92485 case IPT_SO_GET_ENTRIES:
92486diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
92487index 746427c..80eab72 100644
92488--- a/net/ipv4/ping.c
92489+++ b/net/ipv4/ping.c
92490@@ -55,7 +55,7 @@
92491
92492
92493 struct ping_table ping_table;
92494-struct pingv6_ops pingv6_ops;
92495+struct pingv6_ops *pingv6_ops;
92496 EXPORT_SYMBOL_GPL(pingv6_ops);
92497
92498 static u16 ping_port_rover;
92499@@ -335,7 +335,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
92500 return -ENODEV;
92501 }
92502 }
92503- has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
92504+ has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
92505 scoped);
92506 rcu_read_unlock();
92507
92508@@ -541,7 +541,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
92509 }
92510 #if IS_ENABLED(CONFIG_IPV6)
92511 } else if (skb->protocol == htons(ETH_P_IPV6)) {
92512- harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
92513+ harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
92514 #endif
92515 }
92516
92517@@ -559,7 +559,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
92518 info, (u8 *)icmph);
92519 #if IS_ENABLED(CONFIG_IPV6)
92520 } else if (family == AF_INET6) {
92521- pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
92522+ pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
92523 info, (u8 *)icmph);
92524 #endif
92525 }
92526@@ -850,7 +850,7 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
92527 return ip_recv_error(sk, msg, len);
92528 #if IS_ENABLED(CONFIG_IPV6)
92529 } else if (family == AF_INET6) {
92530- return pingv6_ops.ipv6_recv_error(sk, msg, len);
92531+ return pingv6_ops->ipv6_recv_error(sk, msg, len);
92532 #endif
92533 }
92534 }
92535@@ -900,7 +900,7 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
92536 IP6CB(skb)->iif);
92537
92538 if (inet6_sk(sk)->rxopt.all)
92539- pingv6_ops.ip6_datagram_recv_ctl(sk, msg, skb);
92540+ pingv6_ops->ip6_datagram_recv_ctl(sk, msg, skb);
92541 #endif
92542 } else {
92543 BUG();
92544@@ -1090,7 +1090,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
92545 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
92546 0, sock_i_ino(sp),
92547 atomic_read(&sp->sk_refcnt), sp,
92548- atomic_read(&sp->sk_drops), len);
92549+ atomic_read_unchecked(&sp->sk_drops), len);
92550 }
92551
92552 static int ping_v4_seq_show(struct seq_file *seq, void *v)
92553diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
92554index 61e60d6..d6996cd 100644
92555--- a/net/ipv4/raw.c
92556+++ b/net/ipv4/raw.c
92557@@ -309,7 +309,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
92558 int raw_rcv(struct sock *sk, struct sk_buff *skb)
92559 {
92560 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
92561- atomic_inc(&sk->sk_drops);
92562+ atomic_inc_unchecked(&sk->sk_drops);
92563 kfree_skb(skb);
92564 return NET_RX_DROP;
92565 }
92566@@ -746,16 +746,20 @@ static int raw_init(struct sock *sk)
92567
92568 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
92569 {
92570+ struct icmp_filter filter;
92571+
92572 if (optlen > sizeof(struct icmp_filter))
92573 optlen = sizeof(struct icmp_filter);
92574- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
92575+ if (copy_from_user(&filter, optval, optlen))
92576 return -EFAULT;
92577+ raw_sk(sk)->filter = filter;
92578 return 0;
92579 }
92580
92581 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
92582 {
92583 int len, ret = -EFAULT;
92584+ struct icmp_filter filter;
92585
92586 if (get_user(len, optlen))
92587 goto out;
92588@@ -765,8 +769,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
92589 if (len > sizeof(struct icmp_filter))
92590 len = sizeof(struct icmp_filter);
92591 ret = -EFAULT;
92592- if (put_user(len, optlen) ||
92593- copy_to_user(optval, &raw_sk(sk)->filter, len))
92594+ filter = raw_sk(sk)->filter;
92595+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
92596 goto out;
92597 ret = 0;
92598 out: return ret;
92599@@ -995,7 +999,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
92600 0, 0L, 0,
92601 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
92602 0, sock_i_ino(sp),
92603- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
92604+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
92605 }
92606
92607 static int raw_seq_show(struct seq_file *seq, void *v)
92608diff --git a/net/ipv4/route.c b/net/ipv4/route.c
92609index a9a54a2..647316e 100644
92610--- a/net/ipv4/route.c
92611+++ b/net/ipv4/route.c
92612@@ -2615,34 +2615,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
92613 .maxlen = sizeof(int),
92614 .mode = 0200,
92615 .proc_handler = ipv4_sysctl_rtcache_flush,
92616+ .extra1 = &init_net,
92617 },
92618 { },
92619 };
92620
92621 static __net_init int sysctl_route_net_init(struct net *net)
92622 {
92623- struct ctl_table *tbl;
92624+ ctl_table_no_const *tbl = NULL;
92625
92626- tbl = ipv4_route_flush_table;
92627 if (!net_eq(net, &init_net)) {
92628- tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
92629+ tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
92630 if (tbl == NULL)
92631 goto err_dup;
92632
92633 /* Don't export sysctls to unprivileged users */
92634 if (net->user_ns != &init_user_ns)
92635 tbl[0].procname = NULL;
92636- }
92637- tbl[0].extra1 = net;
92638+ tbl[0].extra1 = net;
92639+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
92640+ } else
92641+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
92642
92643- net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
92644 if (net->ipv4.route_hdr == NULL)
92645 goto err_reg;
92646 return 0;
92647
92648 err_reg:
92649- if (tbl != ipv4_route_flush_table)
92650- kfree(tbl);
92651+ kfree(tbl);
92652 err_dup:
92653 return -ENOMEM;
92654 }
92655@@ -2665,8 +2665,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
92656
92657 static __net_init int rt_genid_init(struct net *net)
92658 {
92659- atomic_set(&net->rt_genid, 0);
92660- atomic_set(&net->fnhe_genid, 0);
92661+ atomic_set_unchecked(&net->rt_genid, 0);
92662+ atomic_set_unchecked(&net->fnhe_genid, 0);
92663 get_random_bytes(&net->ipv4.dev_addr_genid,
92664 sizeof(net->ipv4.dev_addr_genid));
92665 return 0;
92666diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
92667index 610e324..fd42e75 100644
92668--- a/net/ipv4/sysctl_net_ipv4.c
92669+++ b/net/ipv4/sysctl_net_ipv4.c
92670@@ -57,7 +57,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
92671 {
92672 int ret;
92673 int range[2];
92674- struct ctl_table tmp = {
92675+ ctl_table_no_const tmp = {
92676 .data = &range,
92677 .maxlen = sizeof(range),
92678 .mode = table->mode,
92679@@ -110,7 +110,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
92680 int ret;
92681 gid_t urange[2];
92682 kgid_t low, high;
92683- struct ctl_table tmp = {
92684+ ctl_table_no_const tmp = {
92685 .data = &urange,
92686 .maxlen = sizeof(urange),
92687 .mode = table->mode,
92688@@ -141,7 +141,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
92689 void __user *buffer, size_t *lenp, loff_t *ppos)
92690 {
92691 char val[TCP_CA_NAME_MAX];
92692- struct ctl_table tbl = {
92693+ ctl_table_no_const tbl = {
92694 .data = val,
92695 .maxlen = TCP_CA_NAME_MAX,
92696 };
92697@@ -160,7 +160,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
92698 void __user *buffer, size_t *lenp,
92699 loff_t *ppos)
92700 {
92701- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
92702+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
92703 int ret;
92704
92705 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
92706@@ -177,7 +177,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
92707 void __user *buffer, size_t *lenp,
92708 loff_t *ppos)
92709 {
92710- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
92711+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
92712 int ret;
92713
92714 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
92715@@ -203,15 +203,17 @@ static int ipv4_tcp_mem(struct ctl_table *ctl, int write,
92716 struct mem_cgroup *memcg;
92717 #endif
92718
92719- struct ctl_table tmp = {
92720+ ctl_table_no_const tmp = {
92721 .data = &vec,
92722 .maxlen = sizeof(vec),
92723 .mode = ctl->mode,
92724 };
92725
92726 if (!write) {
92727- ctl->data = &net->ipv4.sysctl_tcp_mem;
92728- return proc_doulongvec_minmax(ctl, write, buffer, lenp, ppos);
92729+ ctl_table_no_const tcp_mem = *ctl;
92730+
92731+ tcp_mem.data = &net->ipv4.sysctl_tcp_mem;
92732+ return proc_doulongvec_minmax(&tcp_mem, write, buffer, lenp, ppos);
92733 }
92734
92735 ret = proc_doulongvec_minmax(&tmp, write, buffer, lenp, ppos);
92736@@ -239,7 +241,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
92737 void __user *buffer, size_t *lenp,
92738 loff_t *ppos)
92739 {
92740- struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
92741+ ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
92742 struct tcp_fastopen_context *ctxt;
92743 int ret;
92744 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
92745@@ -482,7 +484,7 @@ static struct ctl_table ipv4_table[] = {
92746 },
92747 {
92748 .procname = "ip_local_reserved_ports",
92749- .data = NULL, /* initialized in sysctl_ipv4_init */
92750+ .data = sysctl_local_reserved_ports,
92751 .maxlen = 65536,
92752 .mode = 0644,
92753 .proc_handler = proc_do_large_bitmap,
92754@@ -847,11 +849,10 @@ static struct ctl_table ipv4_net_table[] = {
92755
92756 static __net_init int ipv4_sysctl_init_net(struct net *net)
92757 {
92758- struct ctl_table *table;
92759+ ctl_table_no_const *table = NULL;
92760
92761- table = ipv4_net_table;
92762 if (!net_eq(net, &init_net)) {
92763- table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
92764+ table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
92765 if (table == NULL)
92766 goto err_alloc;
92767
92768@@ -886,15 +887,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
92769
92770 tcp_init_mem(net);
92771
92772- net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
92773+ if (!net_eq(net, &init_net))
92774+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
92775+ else
92776+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
92777 if (net->ipv4.ipv4_hdr == NULL)
92778 goto err_reg;
92779
92780 return 0;
92781
92782 err_reg:
92783- if (!net_eq(net, &init_net))
92784- kfree(table);
92785+ kfree(table);
92786 err_alloc:
92787 return -ENOMEM;
92788 }
92789@@ -916,16 +919,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
92790 static __init int sysctl_ipv4_init(void)
92791 {
92792 struct ctl_table_header *hdr;
92793- struct ctl_table *i;
92794-
92795- for (i = ipv4_table; i->procname; i++) {
92796- if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
92797- i->data = sysctl_local_reserved_ports;
92798- break;
92799- }
92800- }
92801- if (!i->procname)
92802- return -EINVAL;
92803
92804 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
92805 if (hdr == NULL)
92806diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
92807index 3ca2139..c4cc060 100644
92808--- a/net/ipv4/tcp_input.c
92809+++ b/net/ipv4/tcp_input.c
92810@@ -4379,7 +4379,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
92811 * simplifies code)
92812 */
92813 static void
92814-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
92815+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
92816 struct sk_buff *head, struct sk_buff *tail,
92817 u32 start, u32 end)
92818 {
92819@@ -5465,6 +5465,7 @@ discard:
92820 tcp_paws_reject(&tp->rx_opt, 0))
92821 goto discard_and_undo;
92822
92823+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
92824 if (th->syn) {
92825 /* We see SYN without ACK. It is attempt of
92826 * simultaneous connect with crossed SYNs.
92827@@ -5515,6 +5516,7 @@ discard:
92828 goto discard;
92829 #endif
92830 }
92831+#endif
92832 /* "fifth, if neither of the SYN or RST bits is set then
92833 * drop the segment and return."
92834 */
92835@@ -5560,7 +5562,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
92836 goto discard;
92837
92838 if (th->syn) {
92839- if (th->fin)
92840+ if (th->fin || th->urg || th->psh)
92841 goto discard;
92842 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
92843 return 1;
92844diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
92845index b299da5..097db06 100644
92846--- a/net/ipv4/tcp_ipv4.c
92847+++ b/net/ipv4/tcp_ipv4.c
92848@@ -91,6 +91,10 @@ int sysctl_tcp_low_latency __read_mostly;
92849 EXPORT_SYMBOL(sysctl_tcp_low_latency);
92850
92851
92852+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92853+extern int grsec_enable_blackhole;
92854+#endif
92855+
92856 #ifdef CONFIG_TCP_MD5SIG
92857 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
92858 __be32 daddr, __be32 saddr, const struct tcphdr *th);
92859@@ -1830,6 +1834,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
92860 return 0;
92861
92862 reset:
92863+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92864+ if (!grsec_enable_blackhole)
92865+#endif
92866 tcp_v4_send_reset(rsk, skb);
92867 discard:
92868 kfree_skb(skb);
92869@@ -1975,12 +1982,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
92870 TCP_SKB_CB(skb)->sacked = 0;
92871
92872 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
92873- if (!sk)
92874+ if (!sk) {
92875+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92876+ ret = 1;
92877+#endif
92878 goto no_tcp_socket;
92879-
92880+ }
92881 process:
92882- if (sk->sk_state == TCP_TIME_WAIT)
92883+ if (sk->sk_state == TCP_TIME_WAIT) {
92884+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92885+ ret = 2;
92886+#endif
92887 goto do_time_wait;
92888+ }
92889
92890 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
92891 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
92892@@ -2034,6 +2048,10 @@ csum_error:
92893 bad_packet:
92894 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
92895 } else {
92896+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92897+ if (!grsec_enable_blackhole || (ret == 1 &&
92898+ (skb->dev->flags & IFF_LOOPBACK)))
92899+#endif
92900 tcp_v4_send_reset(NULL, skb);
92901 }
92902
92903diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
92904index ab1c086..2a8d76b 100644
92905--- a/net/ipv4/tcp_minisocks.c
92906+++ b/net/ipv4/tcp_minisocks.c
92907@@ -27,6 +27,10 @@
92908 #include <net/inet_common.h>
92909 #include <net/xfrm.h>
92910
92911+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92912+extern int grsec_enable_blackhole;
92913+#endif
92914+
92915 int sysctl_tcp_syncookies __read_mostly = 1;
92916 EXPORT_SYMBOL(sysctl_tcp_syncookies);
92917
92918@@ -715,7 +719,10 @@ embryonic_reset:
92919 * avoid becoming vulnerable to outside attack aiming at
92920 * resetting legit local connections.
92921 */
92922- req->rsk_ops->send_reset(sk, skb);
92923+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92924+ if (!grsec_enable_blackhole)
92925+#endif
92926+ req->rsk_ops->send_reset(sk, skb);
92927 } else if (fastopen) { /* received a valid RST pkt */
92928 reqsk_fastopen_remove(sk, req, true);
92929 tcp_reset(sk);
92930diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
92931index d4943f6..e7a74a5 100644
92932--- a/net/ipv4/tcp_probe.c
92933+++ b/net/ipv4/tcp_probe.c
92934@@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
92935 if (cnt + width >= len)
92936 break;
92937
92938- if (copy_to_user(buf + cnt, tbuf, width))
92939+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
92940 return -EFAULT;
92941 cnt += width;
92942 }
92943diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
92944index 4b85e6f..22f9ac9 100644
92945--- a/net/ipv4/tcp_timer.c
92946+++ b/net/ipv4/tcp_timer.c
92947@@ -22,6 +22,10 @@
92948 #include <linux/gfp.h>
92949 #include <net/tcp.h>
92950
92951+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92952+extern int grsec_lastack_retries;
92953+#endif
92954+
92955 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
92956 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
92957 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
92958@@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
92959 }
92960 }
92961
92962+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92963+ if ((sk->sk_state == TCP_LAST_ACK) &&
92964+ (grsec_lastack_retries > 0) &&
92965+ (grsec_lastack_retries < retry_until))
92966+ retry_until = grsec_lastack_retries;
92967+#endif
92968+
92969 if (retransmits_timed_out(sk, retry_until,
92970 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
92971 /* Has it gone just too far? */
92972diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
92973index 766e6ba..aff2f8d 100644
92974--- a/net/ipv4/udp.c
92975+++ b/net/ipv4/udp.c
92976@@ -87,6 +87,7 @@
92977 #include <linux/types.h>
92978 #include <linux/fcntl.h>
92979 #include <linux/module.h>
92980+#include <linux/security.h>
92981 #include <linux/socket.h>
92982 #include <linux/sockios.h>
92983 #include <linux/igmp.h>
92984@@ -112,6 +113,10 @@
92985 #include <net/busy_poll.h>
92986 #include "udp_impl.h"
92987
92988+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92989+extern int grsec_enable_blackhole;
92990+#endif
92991+
92992 struct udp_table udp_table __read_mostly;
92993 EXPORT_SYMBOL(udp_table);
92994
92995@@ -595,6 +600,9 @@ found:
92996 return s;
92997 }
92998
92999+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
93000+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
93001+
93002 /*
93003 * This routine is called by the ICMP module when it gets some
93004 * sort of error condition. If err < 0 then the socket should
93005@@ -891,9 +899,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
93006 dport = usin->sin_port;
93007 if (dport == 0)
93008 return -EINVAL;
93009+
93010+ err = gr_search_udp_sendmsg(sk, usin);
93011+ if (err)
93012+ return err;
93013 } else {
93014 if (sk->sk_state != TCP_ESTABLISHED)
93015 return -EDESTADDRREQ;
93016+
93017+ err = gr_search_udp_sendmsg(sk, NULL);
93018+ if (err)
93019+ return err;
93020+
93021 daddr = inet->inet_daddr;
93022 dport = inet->inet_dport;
93023 /* Open fast path for connected socket.
93024@@ -1137,7 +1154,7 @@ static unsigned int first_packet_length(struct sock *sk)
93025 IS_UDPLITE(sk));
93026 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
93027 IS_UDPLITE(sk));
93028- atomic_inc(&sk->sk_drops);
93029+ atomic_inc_unchecked(&sk->sk_drops);
93030 __skb_unlink(skb, rcvq);
93031 __skb_queue_tail(&list_kill, skb);
93032 }
93033@@ -1223,6 +1240,10 @@ try_again:
93034 if (!skb)
93035 goto out;
93036
93037+ err = gr_search_udp_recvmsg(sk, skb);
93038+ if (err)
93039+ goto out_free;
93040+
93041 ulen = skb->len - sizeof(struct udphdr);
93042 copied = len;
93043 if (copied > ulen)
93044@@ -1256,7 +1277,7 @@ try_again:
93045 if (unlikely(err)) {
93046 trace_kfree_skb(skb, udp_recvmsg);
93047 if (!peeked) {
93048- atomic_inc(&sk->sk_drops);
93049+ atomic_inc_unchecked(&sk->sk_drops);
93050 UDP_INC_STATS_USER(sock_net(sk),
93051 UDP_MIB_INERRORS, is_udplite);
93052 }
93053@@ -1543,7 +1564,7 @@ csum_error:
93054 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
93055 drop:
93056 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
93057- atomic_inc(&sk->sk_drops);
93058+ atomic_inc_unchecked(&sk->sk_drops);
93059 kfree_skb(skb);
93060 return -1;
93061 }
93062@@ -1562,7 +1583,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
93063 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
93064
93065 if (!skb1) {
93066- atomic_inc(&sk->sk_drops);
93067+ atomic_inc_unchecked(&sk->sk_drops);
93068 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
93069 IS_UDPLITE(sk));
93070 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
93071@@ -1734,6 +1755,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
93072 goto csum_error;
93073
93074 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
93075+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93076+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
93077+#endif
93078 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
93079
93080 /*
93081@@ -2166,7 +2190,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
93082 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
93083 0, sock_i_ino(sp),
93084 atomic_read(&sp->sk_refcnt), sp,
93085- atomic_read(&sp->sk_drops), len);
93086+ atomic_read_unchecked(&sp->sk_drops), len);
93087 }
93088
93089 int udp4_seq_show(struct seq_file *seq, void *v)
93090diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
93091index 9a459be..c7bc04c 100644
93092--- a/net/ipv4/xfrm4_policy.c
93093+++ b/net/ipv4/xfrm4_policy.c
93094@@ -181,11 +181,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
93095 fl4->flowi4_tos = iph->tos;
93096 }
93097
93098-static inline int xfrm4_garbage_collect(struct dst_ops *ops)
93099+static int xfrm4_garbage_collect(struct dst_ops *ops)
93100 {
93101 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
93102
93103- xfrm4_policy_afinfo.garbage_collect(net);
93104+ xfrm_garbage_collect_deferred(net);
93105 return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
93106 }
93107
93108@@ -264,19 +264,18 @@ static struct ctl_table xfrm4_policy_table[] = {
93109
93110 static int __net_init xfrm4_net_init(struct net *net)
93111 {
93112- struct ctl_table *table;
93113+ ctl_table_no_const *table = NULL;
93114 struct ctl_table_header *hdr;
93115
93116- table = xfrm4_policy_table;
93117 if (!net_eq(net, &init_net)) {
93118- table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
93119+ table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
93120 if (!table)
93121 goto err_alloc;
93122
93123 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
93124- }
93125-
93126- hdr = register_net_sysctl(net, "net/ipv4", table);
93127+ hdr = register_net_sysctl(net, "net/ipv4", table);
93128+ } else
93129+ hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
93130 if (!hdr)
93131 goto err_reg;
93132
93133@@ -284,8 +283,7 @@ static int __net_init xfrm4_net_init(struct net *net)
93134 return 0;
93135
93136 err_reg:
93137- if (!net_eq(net, &init_net))
93138- kfree(table);
93139+ kfree(table);
93140 err_alloc:
93141 return -ENOMEM;
93142 }
93143diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
93144index 498ea99..42501bc 100644
93145--- a/net/ipv6/addrconf.c
93146+++ b/net/ipv6/addrconf.c
93147@@ -618,7 +618,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
93148 idx = 0;
93149 head = &net->dev_index_head[h];
93150 rcu_read_lock();
93151- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
93152+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
93153 net->dev_base_seq;
93154 hlist_for_each_entry_rcu(dev, head, index_hlist) {
93155 if (idx < s_idx)
93156@@ -2381,7 +2381,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
93157 p.iph.ihl = 5;
93158 p.iph.protocol = IPPROTO_IPV6;
93159 p.iph.ttl = 64;
93160- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
93161+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
93162
93163 if (ops->ndo_do_ioctl) {
93164 mm_segment_t oldfs = get_fs();
93165@@ -4030,7 +4030,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
93166 s_ip_idx = ip_idx = cb->args[2];
93167
93168 rcu_read_lock();
93169- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
93170+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
93171 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
93172 idx = 0;
93173 head = &net->dev_index_head[h];
93174@@ -4651,7 +4651,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
93175 dst_free(&ifp->rt->dst);
93176 break;
93177 }
93178- atomic_inc(&net->ipv6.dev_addr_genid);
93179+ atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
93180 }
93181
93182 static void ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
93183@@ -4671,7 +4671,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
93184 int *valp = ctl->data;
93185 int val = *valp;
93186 loff_t pos = *ppos;
93187- struct ctl_table lctl;
93188+ ctl_table_no_const lctl;
93189 int ret;
93190
93191 /*
93192@@ -4756,7 +4756,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
93193 int *valp = ctl->data;
93194 int val = *valp;
93195 loff_t pos = *ppos;
93196- struct ctl_table lctl;
93197+ ctl_table_no_const lctl;
93198 int ret;
93199
93200 /*
93201diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
93202index 197e6f4..16d8396 100644
93203--- a/net/ipv6/datagram.c
93204+++ b/net/ipv6/datagram.c
93205@@ -904,5 +904,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
93206 0,
93207 sock_i_ino(sp),
93208 atomic_read(&sp->sk_refcnt), sp,
93209- atomic_read(&sp->sk_drops));
93210+ atomic_read_unchecked(&sp->sk_drops));
93211 }
93212diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
93213index 7cfc8d2..c5394b6 100644
93214--- a/net/ipv6/icmp.c
93215+++ b/net/ipv6/icmp.c
93216@@ -989,7 +989,7 @@ struct ctl_table ipv6_icmp_table_template[] = {
93217
93218 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
93219 {
93220- struct ctl_table *table;
93221+ ctl_table_no_const *table;
93222
93223 table = kmemdup(ipv6_icmp_table_template,
93224 sizeof(ipv6_icmp_table_template),
93225diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
93226index 90747f1..505320d 100644
93227--- a/net/ipv6/ip6_gre.c
93228+++ b/net/ipv6/ip6_gre.c
93229@@ -74,7 +74,7 @@ struct ip6gre_net {
93230 struct net_device *fb_tunnel_dev;
93231 };
93232
93233-static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
93234+static struct rtnl_link_ops ip6gre_link_ops;
93235 static int ip6gre_tunnel_init(struct net_device *dev);
93236 static void ip6gre_tunnel_setup(struct net_device *dev);
93237 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
93238@@ -1288,7 +1288,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
93239 }
93240
93241
93242-static struct inet6_protocol ip6gre_protocol __read_mostly = {
93243+static struct inet6_protocol ip6gre_protocol = {
93244 .handler = ip6gre_rcv,
93245 .err_handler = ip6gre_err,
93246 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
93247@@ -1622,7 +1622,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
93248 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
93249 };
93250
93251-static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
93252+static struct rtnl_link_ops ip6gre_link_ops = {
93253 .kind = "ip6gre",
93254 .maxtype = IFLA_GRE_MAX,
93255 .policy = ip6gre_policy,
93256@@ -1635,7 +1635,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
93257 .fill_info = ip6gre_fill_info,
93258 };
93259
93260-static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
93261+static struct rtnl_link_ops ip6gre_tap_ops = {
93262 .kind = "ip6gretap",
93263 .maxtype = IFLA_GRE_MAX,
93264 .policy = ip6gre_policy,
93265diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
93266index 46ba243..576f50e 100644
93267--- a/net/ipv6/ip6_tunnel.c
93268+++ b/net/ipv6/ip6_tunnel.c
93269@@ -88,7 +88,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
93270
93271 static int ip6_tnl_dev_init(struct net_device *dev);
93272 static void ip6_tnl_dev_setup(struct net_device *dev);
93273-static struct rtnl_link_ops ip6_link_ops __read_mostly;
93274+static struct rtnl_link_ops ip6_link_ops;
93275
93276 static int ip6_tnl_net_id __read_mostly;
93277 struct ip6_tnl_net {
93278@@ -1678,7 +1678,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
93279 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
93280 };
93281
93282-static struct rtnl_link_ops ip6_link_ops __read_mostly = {
93283+static struct rtnl_link_ops ip6_link_ops = {
93284 .kind = "ip6tnl",
93285 .maxtype = IFLA_IPTUN_MAX,
93286 .policy = ip6_tnl_policy,
93287diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
93288index d1e2e8e..51c19ae 100644
93289--- a/net/ipv6/ipv6_sockglue.c
93290+++ b/net/ipv6/ipv6_sockglue.c
93291@@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
93292 if (sk->sk_type != SOCK_STREAM)
93293 return -ENOPROTOOPT;
93294
93295- msg.msg_control = optval;
93296+ msg.msg_control = (void __force_kernel *)optval;
93297 msg.msg_controllen = len;
93298 msg.msg_flags = flags;
93299
93300diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
93301index 44400c2..8e11f52 100644
93302--- a/net/ipv6/netfilter/ip6_tables.c
93303+++ b/net/ipv6/netfilter/ip6_tables.c
93304@@ -1078,14 +1078,14 @@ static int compat_table_info(const struct xt_table_info *info,
93305 #endif
93306
93307 static int get_info(struct net *net, void __user *user,
93308- const int *len, int compat)
93309+ int len, int compat)
93310 {
93311 char name[XT_TABLE_MAXNAMELEN];
93312 struct xt_table *t;
93313 int ret;
93314
93315- if (*len != sizeof(struct ip6t_getinfo)) {
93316- duprintf("length %u != %zu\n", *len,
93317+ if (len != sizeof(struct ip6t_getinfo)) {
93318+ duprintf("length %u != %zu\n", len,
93319 sizeof(struct ip6t_getinfo));
93320 return -EINVAL;
93321 }
93322@@ -1122,7 +1122,7 @@ static int get_info(struct net *net, void __user *user,
93323 info.size = private->size;
93324 strcpy(info.name, name);
93325
93326- if (copy_to_user(user, &info, *len) != 0)
93327+ if (copy_to_user(user, &info, len) != 0)
93328 ret = -EFAULT;
93329 else
93330 ret = 0;
93331@@ -1976,7 +1976,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
93332
93333 switch (cmd) {
93334 case IP6T_SO_GET_INFO:
93335- ret = get_info(sock_net(sk), user, len, 1);
93336+ ret = get_info(sock_net(sk), user, *len, 1);
93337 break;
93338 case IP6T_SO_GET_ENTRIES:
93339 ret = compat_get_entries(sock_net(sk), user, len);
93340@@ -2023,7 +2023,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
93341
93342 switch (cmd) {
93343 case IP6T_SO_GET_INFO:
93344- ret = get_info(sock_net(sk), user, len, 0);
93345+ ret = get_info(sock_net(sk), user, *len, 0);
93346 break;
93347
93348 case IP6T_SO_GET_ENTRIES:
93349diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
93350index dffdc1a..ccc6678 100644
93351--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
93352+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
93353@@ -90,12 +90,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
93354
93355 static int nf_ct_frag6_sysctl_register(struct net *net)
93356 {
93357- struct ctl_table *table;
93358+ ctl_table_no_const *table = NULL;
93359 struct ctl_table_header *hdr;
93360
93361- table = nf_ct_frag6_sysctl_table;
93362 if (!net_eq(net, &init_net)) {
93363- table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
93364+ table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
93365 GFP_KERNEL);
93366 if (table == NULL)
93367 goto err_alloc;
93368@@ -103,9 +102,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
93369 table[0].data = &net->nf_frag.frags.timeout;
93370 table[1].data = &net->nf_frag.frags.low_thresh;
93371 table[2].data = &net->nf_frag.frags.high_thresh;
93372- }
93373-
93374- hdr = register_net_sysctl(net, "net/netfilter", table);
93375+ hdr = register_net_sysctl(net, "net/netfilter", table);
93376+ } else
93377+ hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
93378 if (hdr == NULL)
93379 goto err_reg;
93380
93381@@ -113,8 +112,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
93382 return 0;
93383
93384 err_reg:
93385- if (!net_eq(net, &init_net))
93386- kfree(table);
93387+ kfree(table);
93388 err_alloc:
93389 return -ENOMEM;
93390 }
93391diff --git a/net/ipv6/output_core.c b/net/ipv6/output_core.c
93392index ab92a36..bb4a528 100644
93393--- a/net/ipv6/output_core.c
93394+++ b/net/ipv6/output_core.c
93395@@ -8,8 +8,8 @@
93396
93397 void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
93398 {
93399- static atomic_t ipv6_fragmentation_id;
93400- int old, new;
93401+ static atomic_unchecked_t ipv6_fragmentation_id;
93402+ int id;
93403
93404 #if IS_ENABLED(CONFIG_IPV6)
93405 if (rt && !(rt->dst.flags & DST_NOPEER)) {
93406@@ -25,13 +25,10 @@ void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
93407 }
93408 }
93409 #endif
93410- do {
93411- old = atomic_read(&ipv6_fragmentation_id);
93412- new = old + 1;
93413- if (!new)
93414- new = 1;
93415- } while (atomic_cmpxchg(&ipv6_fragmentation_id, old, new) != old);
93416- fhdr->identification = htonl(new);
93417+ id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
93418+ if (!id)
93419+ id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
93420+ fhdr->identification = htonl(id);
93421 }
93422 EXPORT_SYMBOL(ipv6_select_ident);
93423
93424diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
93425index 18f19df..b46ada1 100644
93426--- a/net/ipv6/ping.c
93427+++ b/net/ipv6/ping.c
93428@@ -245,6 +245,22 @@ static struct pernet_operations ping_v6_net_ops = {
93429 };
93430 #endif
93431
93432+static struct pingv6_ops real_pingv6_ops = {
93433+ .ipv6_recv_error = ipv6_recv_error,
93434+ .ip6_datagram_recv_ctl = ip6_datagram_recv_ctl,
93435+ .icmpv6_err_convert = icmpv6_err_convert,
93436+ .ipv6_icmp_error = ipv6_icmp_error,
93437+ .ipv6_chk_addr = ipv6_chk_addr,
93438+};
93439+
93440+static struct pingv6_ops dummy_pingv6_ops = {
93441+ .ipv6_recv_error = dummy_ipv6_recv_error,
93442+ .ip6_datagram_recv_ctl = dummy_ip6_datagram_recv_ctl,
93443+ .icmpv6_err_convert = dummy_icmpv6_err_convert,
93444+ .ipv6_icmp_error = dummy_ipv6_icmp_error,
93445+ .ipv6_chk_addr = dummy_ipv6_chk_addr,
93446+};
93447+
93448 int __init pingv6_init(void)
93449 {
93450 #ifdef CONFIG_PROC_FS
93451@@ -252,11 +268,7 @@ int __init pingv6_init(void)
93452 if (ret)
93453 return ret;
93454 #endif
93455- pingv6_ops.ipv6_recv_error = ipv6_recv_error;
93456- pingv6_ops.ip6_datagram_recv_ctl = ip6_datagram_recv_ctl;
93457- pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
93458- pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
93459- pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
93460+ pingv6_ops = &real_pingv6_ops;
93461 return inet6_register_protosw(&pingv6_protosw);
93462 }
93463
93464@@ -265,11 +277,7 @@ int __init pingv6_init(void)
93465 */
93466 void pingv6_exit(void)
93467 {
93468- pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
93469- pingv6_ops.ip6_datagram_recv_ctl = dummy_ip6_datagram_recv_ctl;
93470- pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
93471- pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
93472- pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
93473+ pingv6_ops = &dummy_pingv6_ops;
93474 #ifdef CONFIG_PROC_FS
93475 unregister_pernet_subsys(&ping_v6_net_ops);
93476 #endif
93477diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
93478index cdaed47..515edde9 100644
93479--- a/net/ipv6/raw.c
93480+++ b/net/ipv6/raw.c
93481@@ -108,7 +108,7 @@ found:
93482 */
93483 static int icmpv6_filter(const struct sock *sk, const struct sk_buff *skb)
93484 {
93485- struct icmp6hdr *_hdr;
93486+ struct icmp6hdr _hdr;
93487 const struct icmp6hdr *hdr;
93488
93489 hdr = skb_header_pointer(skb, skb_transport_offset(skb),
93490@@ -378,7 +378,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
93491 {
93492 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
93493 skb_checksum_complete(skb)) {
93494- atomic_inc(&sk->sk_drops);
93495+ atomic_inc_unchecked(&sk->sk_drops);
93496 kfree_skb(skb);
93497 return NET_RX_DROP;
93498 }
93499@@ -406,7 +406,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
93500 struct raw6_sock *rp = raw6_sk(sk);
93501
93502 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
93503- atomic_inc(&sk->sk_drops);
93504+ atomic_inc_unchecked(&sk->sk_drops);
93505 kfree_skb(skb);
93506 return NET_RX_DROP;
93507 }
93508@@ -430,7 +430,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
93509
93510 if (inet->hdrincl) {
93511 if (skb_checksum_complete(skb)) {
93512- atomic_inc(&sk->sk_drops);
93513+ atomic_inc_unchecked(&sk->sk_drops);
93514 kfree_skb(skb);
93515 return NET_RX_DROP;
93516 }
93517@@ -602,7 +602,7 @@ out:
93518 return err;
93519 }
93520
93521-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
93522+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
93523 struct flowi6 *fl6, struct dst_entry **dstp,
93524 unsigned int flags)
93525 {
93526@@ -915,12 +915,15 @@ do_confirm:
93527 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
93528 char __user *optval, int optlen)
93529 {
93530+ struct icmp6_filter filter;
93531+
93532 switch (optname) {
93533 case ICMPV6_FILTER:
93534 if (optlen > sizeof(struct icmp6_filter))
93535 optlen = sizeof(struct icmp6_filter);
93536- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
93537+ if (copy_from_user(&filter, optval, optlen))
93538 return -EFAULT;
93539+ raw6_sk(sk)->filter = filter;
93540 return 0;
93541 default:
93542 return -ENOPROTOOPT;
93543@@ -933,6 +936,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
93544 char __user *optval, int __user *optlen)
93545 {
93546 int len;
93547+ struct icmp6_filter filter;
93548
93549 switch (optname) {
93550 case ICMPV6_FILTER:
93551@@ -944,7 +948,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
93552 len = sizeof(struct icmp6_filter);
93553 if (put_user(len, optlen))
93554 return -EFAULT;
93555- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
93556+ filter = raw6_sk(sk)->filter;
93557+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
93558 return -EFAULT;
93559 return 0;
93560 default:
93561diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
93562index 1aeb473..bea761c 100644
93563--- a/net/ipv6/reassembly.c
93564+++ b/net/ipv6/reassembly.c
93565@@ -626,12 +626,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
93566
93567 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
93568 {
93569- struct ctl_table *table;
93570+ ctl_table_no_const *table = NULL;
93571 struct ctl_table_header *hdr;
93572
93573- table = ip6_frags_ns_ctl_table;
93574 if (!net_eq(net, &init_net)) {
93575- table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
93576+ table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
93577 if (table == NULL)
93578 goto err_alloc;
93579
93580@@ -642,9 +641,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
93581 /* Don't export sysctls to unprivileged users */
93582 if (net->user_ns != &init_user_ns)
93583 table[0].procname = NULL;
93584- }
93585+ hdr = register_net_sysctl(net, "net/ipv6", table);
93586+ } else
93587+ hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
93588
93589- hdr = register_net_sysctl(net, "net/ipv6", table);
93590 if (hdr == NULL)
93591 goto err_reg;
93592
93593@@ -652,8 +652,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
93594 return 0;
93595
93596 err_reg:
93597- if (!net_eq(net, &init_net))
93598- kfree(table);
93599+ kfree(table);
93600 err_alloc:
93601 return -ENOMEM;
93602 }
93603diff --git a/net/ipv6/route.c b/net/ipv6/route.c
93604index 8d9a93ed..cd89616 100644
93605--- a/net/ipv6/route.c
93606+++ b/net/ipv6/route.c
93607@@ -2926,7 +2926,7 @@ struct ctl_table ipv6_route_table_template[] = {
93608
93609 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
93610 {
93611- struct ctl_table *table;
93612+ ctl_table_no_const *table;
93613
93614 table = kmemdup(ipv6_route_table_template,
93615 sizeof(ipv6_route_table_template),
93616diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
93617index 21b25dd..9a43e37 100644
93618--- a/net/ipv6/sit.c
93619+++ b/net/ipv6/sit.c
93620@@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
93621 static void ipip6_dev_free(struct net_device *dev);
93622 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
93623 __be32 *v4dst);
93624-static struct rtnl_link_ops sit_link_ops __read_mostly;
93625+static struct rtnl_link_ops sit_link_ops;
93626
93627 static int sit_net_id __read_mostly;
93628 struct sit_net {
93629@@ -1547,7 +1547,7 @@ static const struct nla_policy ipip6_policy[IFLA_IPTUN_MAX + 1] = {
93630 #endif
93631 };
93632
93633-static struct rtnl_link_ops sit_link_ops __read_mostly = {
93634+static struct rtnl_link_ops sit_link_ops = {
93635 .kind = "sit",
93636 .maxtype = IFLA_IPTUN_MAX,
93637 .policy = ipip6_policy,
93638diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
93639index 107b2f1..72741a9 100644
93640--- a/net/ipv6/sysctl_net_ipv6.c
93641+++ b/net/ipv6/sysctl_net_ipv6.c
93642@@ -40,7 +40,7 @@ static struct ctl_table ipv6_rotable[] = {
93643
93644 static int __net_init ipv6_sysctl_net_init(struct net *net)
93645 {
93646- struct ctl_table *ipv6_table;
93647+ ctl_table_no_const *ipv6_table;
93648 struct ctl_table *ipv6_route_table;
93649 struct ctl_table *ipv6_icmp_table;
93650 int err;
93651diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
93652index 6e1649d..75ddb4c 100644
93653--- a/net/ipv6/tcp_ipv6.c
93654+++ b/net/ipv6/tcp_ipv6.c
93655@@ -104,6 +104,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
93656 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
93657 }
93658
93659+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93660+extern int grsec_enable_blackhole;
93661+#endif
93662+
93663 static void tcp_v6_hash(struct sock *sk)
93664 {
93665 if (sk->sk_state != TCP_CLOSE) {
93666@@ -1399,6 +1403,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
93667 return 0;
93668
93669 reset:
93670+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93671+ if (!grsec_enable_blackhole)
93672+#endif
93673 tcp_v6_send_reset(sk, skb);
93674 discard:
93675 if (opt_skb)
93676@@ -1427,7 +1434,7 @@ ipv6_pktoptions:
93677 if (np->rxopt.bits.rxhlim || np->rxopt.bits.rxohlim)
93678 np->mcast_hops = ipv6_hdr(opt_skb)->hop_limit;
93679 if (np->rxopt.bits.rxtclass)
93680- np->rcv_tclass = ipv6_get_dsfield(ipv6_hdr(skb));
93681+ np->rcv_tclass = ipv6_get_dsfield(ipv6_hdr(opt_skb));
93682 if (ipv6_opt_accepted(sk, opt_skb)) {
93683 skb_set_owner_r(opt_skb, sk);
93684 opt_skb = xchg(&np->pktoptions, opt_skb);
93685@@ -1481,12 +1488,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
93686 TCP_SKB_CB(skb)->sacked = 0;
93687
93688 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
93689- if (!sk)
93690+ if (!sk) {
93691+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93692+ ret = 1;
93693+#endif
93694 goto no_tcp_socket;
93695+ }
93696
93697 process:
93698- if (sk->sk_state == TCP_TIME_WAIT)
93699+ if (sk->sk_state == TCP_TIME_WAIT) {
93700+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93701+ ret = 2;
93702+#endif
93703 goto do_time_wait;
93704+ }
93705
93706 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
93707 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
93708@@ -1538,6 +1553,10 @@ csum_error:
93709 bad_packet:
93710 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
93711 } else {
93712+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93713+ if (!grsec_enable_blackhole || (ret == 1 &&
93714+ (skb->dev->flags & IFF_LOOPBACK)))
93715+#endif
93716 tcp_v6_send_reset(NULL, skb);
93717 }
93718
93719diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
93720index f405815..45a68a6 100644
93721--- a/net/ipv6/udp.c
93722+++ b/net/ipv6/udp.c
93723@@ -53,6 +53,10 @@
93724 #include <trace/events/skb.h>
93725 #include "udp_impl.h"
93726
93727+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93728+extern int grsec_enable_blackhole;
93729+#endif
93730+
93731 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
93732 {
93733 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
93734@@ -420,7 +424,7 @@ try_again:
93735 if (unlikely(err)) {
93736 trace_kfree_skb(skb, udpv6_recvmsg);
93737 if (!peeked) {
93738- atomic_inc(&sk->sk_drops);
93739+ atomic_inc_unchecked(&sk->sk_drops);
93740 if (is_udp4)
93741 UDP_INC_STATS_USER(sock_net(sk),
93742 UDP_MIB_INERRORS,
93743@@ -666,7 +670,7 @@ csum_error:
93744 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
93745 drop:
93746 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
93747- atomic_inc(&sk->sk_drops);
93748+ atomic_inc_unchecked(&sk->sk_drops);
93749 kfree_skb(skb);
93750 return -1;
93751 }
93752@@ -724,7 +728,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
93753 if (likely(skb1 == NULL))
93754 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
93755 if (!skb1) {
93756- atomic_inc(&sk->sk_drops);
93757+ atomic_inc_unchecked(&sk->sk_drops);
93758 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
93759 IS_UDPLITE(sk));
93760 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
93761@@ -864,6 +868,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
93762 goto csum_error;
93763
93764 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
93765+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93766+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
93767+#endif
93768 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
93769
93770 kfree_skb(skb);
93771diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
93772index 23ed03d..6532e67 100644
93773--- a/net/ipv6/xfrm6_policy.c
93774+++ b/net/ipv6/xfrm6_policy.c
93775@@ -207,11 +207,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
93776 }
93777 }
93778
93779-static inline int xfrm6_garbage_collect(struct dst_ops *ops)
93780+static int xfrm6_garbage_collect(struct dst_ops *ops)
93781 {
93782 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
93783
93784- xfrm6_policy_afinfo.garbage_collect(net);
93785+ xfrm_garbage_collect_deferred(net);
93786 return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
93787 }
93788
93789@@ -324,19 +324,19 @@ static struct ctl_table xfrm6_policy_table[] = {
93790
93791 static int __net_init xfrm6_net_init(struct net *net)
93792 {
93793- struct ctl_table *table;
93794+ ctl_table_no_const *table = NULL;
93795 struct ctl_table_header *hdr;
93796
93797- table = xfrm6_policy_table;
93798 if (!net_eq(net, &init_net)) {
93799- table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
93800+ table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
93801 if (!table)
93802 goto err_alloc;
93803
93804 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
93805- }
93806+ hdr = register_net_sysctl(net, "net/ipv6", table);
93807+ } else
93808+ hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
93809
93810- hdr = register_net_sysctl(net, "net/ipv6", table);
93811 if (!hdr)
93812 goto err_reg;
93813
93814@@ -344,8 +344,7 @@ static int __net_init xfrm6_net_init(struct net *net)
93815 return 0;
93816
93817 err_reg:
93818- if (!net_eq(net, &init_net))
93819- kfree(table);
93820+ kfree(table);
93821 err_alloc:
93822 return -ENOMEM;
93823 }
93824diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
93825index 41ac7938..75e3bb1 100644
93826--- a/net/irda/ircomm/ircomm_tty.c
93827+++ b/net/irda/ircomm/ircomm_tty.c
93828@@ -319,11 +319,11 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
93829 add_wait_queue(&port->open_wait, &wait);
93830
93831 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
93832- __FILE__, __LINE__, tty->driver->name, port->count);
93833+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
93834
93835 spin_lock_irqsave(&port->lock, flags);
93836 if (!tty_hung_up_p(filp))
93837- port->count--;
93838+ atomic_dec(&port->count);
93839 port->blocked_open++;
93840 spin_unlock_irqrestore(&port->lock, flags);
93841
93842@@ -358,7 +358,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
93843 }
93844
93845 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
93846- __FILE__, __LINE__, tty->driver->name, port->count);
93847+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
93848
93849 schedule();
93850 }
93851@@ -368,12 +368,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
93852
93853 spin_lock_irqsave(&port->lock, flags);
93854 if (!tty_hung_up_p(filp))
93855- port->count++;
93856+ atomic_inc(&port->count);
93857 port->blocked_open--;
93858 spin_unlock_irqrestore(&port->lock, flags);
93859
93860 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
93861- __FILE__, __LINE__, tty->driver->name, port->count);
93862+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
93863
93864 if (!retval)
93865 port->flags |= ASYNC_NORMAL_ACTIVE;
93866@@ -447,12 +447,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
93867
93868 /* ++ is not atomic, so this should be protected - Jean II */
93869 spin_lock_irqsave(&self->port.lock, flags);
93870- self->port.count++;
93871+ atomic_inc(&self->port.count);
93872 spin_unlock_irqrestore(&self->port.lock, flags);
93873 tty_port_tty_set(&self->port, tty);
93874
93875 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
93876- self->line, self->port.count);
93877+ self->line, atomic_read(&self->port.count));
93878
93879 /* Not really used by us, but lets do it anyway */
93880 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
93881@@ -989,7 +989,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
93882 tty_kref_put(port->tty);
93883 }
93884 port->tty = NULL;
93885- port->count = 0;
93886+ atomic_set(&port->count, 0);
93887 spin_unlock_irqrestore(&port->lock, flags);
93888
93889 wake_up_interruptible(&port->open_wait);
93890@@ -1346,7 +1346,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
93891 seq_putc(m, '\n');
93892
93893 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
93894- seq_printf(m, "Open count: %d\n", self->port.count);
93895+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
93896 seq_printf(m, "Max data size: %d\n", self->max_data_size);
93897 seq_printf(m, "Max header size: %d\n", self->max_header_size);
93898
93899diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
93900index 168aff5..9d43132 100644
93901--- a/net/iucv/af_iucv.c
93902+++ b/net/iucv/af_iucv.c
93903@@ -773,10 +773,10 @@ static int iucv_sock_autobind(struct sock *sk)
93904
93905 write_lock_bh(&iucv_sk_list.lock);
93906
93907- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
93908+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
93909 while (__iucv_get_sock_by_name(name)) {
93910 sprintf(name, "%08x",
93911- atomic_inc_return(&iucv_sk_list.autobind_name));
93912+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
93913 }
93914
93915 write_unlock_bh(&iucv_sk_list.lock);
93916diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
93917index cd5b8ec..f205e6b 100644
93918--- a/net/iucv/iucv.c
93919+++ b/net/iucv/iucv.c
93920@@ -690,7 +690,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
93921 return NOTIFY_OK;
93922 }
93923
93924-static struct notifier_block __refdata iucv_cpu_notifier = {
93925+static struct notifier_block iucv_cpu_notifier = {
93926 .notifier_call = iucv_cpu_notify,
93927 };
93928
93929diff --git a/net/key/af_key.c b/net/key/af_key.c
93930index ab8bd2c..cd2d641 100644
93931--- a/net/key/af_key.c
93932+++ b/net/key/af_key.c
93933@@ -3048,10 +3048,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
93934 static u32 get_acqseq(void)
93935 {
93936 u32 res;
93937- static atomic_t acqseq;
93938+ static atomic_unchecked_t acqseq;
93939
93940 do {
93941- res = atomic_inc_return(&acqseq);
93942+ res = atomic_inc_return_unchecked(&acqseq);
93943 } while (!res);
93944 return res;
93945 }
93946diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
93947index 43dd752..63a23bc 100644
93948--- a/net/mac80211/cfg.c
93949+++ b/net/mac80211/cfg.c
93950@@ -820,7 +820,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
93951 ret = ieee80211_vif_use_channel(sdata, chandef,
93952 IEEE80211_CHANCTX_EXCLUSIVE);
93953 }
93954- } else if (local->open_count == local->monitors) {
93955+ } else if (local_read(&local->open_count) == local->monitors) {
93956 local->_oper_chandef = *chandef;
93957 ieee80211_hw_config(local, 0);
93958 }
93959@@ -2941,7 +2941,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
93960 else
93961 local->probe_req_reg--;
93962
93963- if (!local->open_count)
93964+ if (!local_read(&local->open_count))
93965 break;
93966
93967 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
93968@@ -3404,8 +3404,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
93969 if (chanctx_conf) {
93970 *chandef = chanctx_conf->def;
93971 ret = 0;
93972- } else if (local->open_count > 0 &&
93973- local->open_count == local->monitors &&
93974+ } else if (local_read(&local->open_count) > 0 &&
93975+ local_read(&local->open_count) == local->monitors &&
93976 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
93977 if (local->use_chanctx)
93978 *chandef = local->monitor_chandef;
93979diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
93980index 8412a30..6e00181 100644
93981--- a/net/mac80211/ieee80211_i.h
93982+++ b/net/mac80211/ieee80211_i.h
93983@@ -28,6 +28,7 @@
93984 #include <net/ieee80211_radiotap.h>
93985 #include <net/cfg80211.h>
93986 #include <net/mac80211.h>
93987+#include <asm/local.h>
93988 #include "key.h"
93989 #include "sta_info.h"
93990 #include "debug.h"
93991@@ -907,7 +908,7 @@ struct ieee80211_local {
93992 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
93993 spinlock_t queue_stop_reason_lock;
93994
93995- int open_count;
93996+ local_t open_count;
93997 int monitors, cooked_mntrs;
93998 /* number of interfaces with corresponding FIF_ flags */
93999 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
94000diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
94001index cc11759..11d5541 100644
94002--- a/net/mac80211/iface.c
94003+++ b/net/mac80211/iface.c
94004@@ -511,7 +511,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
94005 break;
94006 }
94007
94008- if (local->open_count == 0) {
94009+ if (local_read(&local->open_count) == 0) {
94010 res = drv_start(local);
94011 if (res)
94012 goto err_del_bss;
94013@@ -558,7 +558,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
94014 res = drv_add_interface(local, sdata);
94015 if (res)
94016 goto err_stop;
94017- } else if (local->monitors == 0 && local->open_count == 0) {
94018+ } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
94019 res = ieee80211_add_virtual_monitor(local);
94020 if (res)
94021 goto err_stop;
94022@@ -666,7 +666,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
94023 atomic_inc(&local->iff_promiscs);
94024
94025 if (coming_up)
94026- local->open_count++;
94027+ local_inc(&local->open_count);
94028
94029 if (hw_reconf_flags)
94030 ieee80211_hw_config(local, hw_reconf_flags);
94031@@ -704,7 +704,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
94032 err_del_interface:
94033 drv_remove_interface(local, sdata);
94034 err_stop:
94035- if (!local->open_count)
94036+ if (!local_read(&local->open_count))
94037 drv_stop(local);
94038 err_del_bss:
94039 sdata->bss = NULL;
94040@@ -841,7 +841,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
94041 }
94042
94043 if (going_down)
94044- local->open_count--;
94045+ local_dec(&local->open_count);
94046
94047 switch (sdata->vif.type) {
94048 case NL80211_IFTYPE_AP_VLAN:
94049@@ -908,7 +908,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
94050 }
94051 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
94052
94053- if (local->open_count == 0)
94054+ if (local_read(&local->open_count) == 0)
94055 ieee80211_clear_tx_pending(local);
94056
94057 /*
94058@@ -948,7 +948,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
94059
94060 ieee80211_recalc_ps(local, -1);
94061
94062- if (local->open_count == 0) {
94063+ if (local_read(&local->open_count) == 0) {
94064 ieee80211_stop_device(local);
94065
94066 /* no reconfiguring after stop! */
94067@@ -959,7 +959,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
94068 ieee80211_configure_filter(local);
94069 ieee80211_hw_config(local, hw_reconf_flags);
94070
94071- if (local->monitors == local->open_count)
94072+ if (local->monitors == local_read(&local->open_count))
94073 ieee80211_add_virtual_monitor(local);
94074 }
94075
94076diff --git a/net/mac80211/main.c b/net/mac80211/main.c
94077index 091088a..daf43c7 100644
94078--- a/net/mac80211/main.c
94079+++ b/net/mac80211/main.c
94080@@ -181,7 +181,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
94081 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
94082 IEEE80211_CONF_CHANGE_POWER);
94083
94084- if (changed && local->open_count) {
94085+ if (changed && local_read(&local->open_count)) {
94086 ret = drv_config(local, changed);
94087 /*
94088 * Goal:
94089diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
94090index 3401262..d5cd68d 100644
94091--- a/net/mac80211/pm.c
94092+++ b/net/mac80211/pm.c
94093@@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
94094 struct ieee80211_sub_if_data *sdata;
94095 struct sta_info *sta;
94096
94097- if (!local->open_count)
94098+ if (!local_read(&local->open_count))
94099 goto suspend;
94100
94101 ieee80211_scan_cancel(local);
94102@@ -59,7 +59,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
94103 cancel_work_sync(&local->dynamic_ps_enable_work);
94104 del_timer_sync(&local->dynamic_ps_timer);
94105
94106- local->wowlan = wowlan && local->open_count;
94107+ local->wowlan = wowlan && local_read(&local->open_count);
94108 if (local->wowlan) {
94109 int err = drv_suspend(local, wowlan);
94110 if (err < 0) {
94111@@ -116,7 +116,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
94112 WARN_ON(!list_empty(&local->chanctx_list));
94113
94114 /* stop hardware - this must stop RX */
94115- if (local->open_count)
94116+ if (local_read(&local->open_count))
94117 ieee80211_stop_device(local);
94118
94119 suspend:
94120diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
94121index 30d58d2..449ac8e 100644
94122--- a/net/mac80211/rate.c
94123+++ b/net/mac80211/rate.c
94124@@ -718,7 +718,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
94125
94126 ASSERT_RTNL();
94127
94128- if (local->open_count)
94129+ if (local_read(&local->open_count))
94130 return -EBUSY;
94131
94132 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
94133diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
94134index c97a065..ff61928 100644
94135--- a/net/mac80211/rc80211_pid_debugfs.c
94136+++ b/net/mac80211/rc80211_pid_debugfs.c
94137@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
94138
94139 spin_unlock_irqrestore(&events->lock, status);
94140
94141- if (copy_to_user(buf, pb, p))
94142+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
94143 return -EFAULT;
94144
94145 return p;
94146diff --git a/net/mac80211/util.c b/net/mac80211/util.c
94147index 2265445..ba14971 100644
94148--- a/net/mac80211/util.c
94149+++ b/net/mac80211/util.c
94150@@ -1452,7 +1452,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
94151 }
94152 #endif
94153 /* everything else happens only if HW was up & running */
94154- if (!local->open_count)
94155+ if (!local_read(&local->open_count))
94156 goto wake_up;
94157
94158 /*
94159@@ -1677,7 +1677,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
94160 local->in_reconfig = false;
94161 barrier();
94162
94163- if (local->monitors == local->open_count && local->monitors > 0)
94164+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
94165 ieee80211_add_virtual_monitor(local);
94166
94167 /*
94168diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
94169index 56d22ca..87c778f 100644
94170--- a/net/netfilter/Kconfig
94171+++ b/net/netfilter/Kconfig
94172@@ -958,6 +958,16 @@ config NETFILTER_XT_MATCH_ESP
94173
94174 To compile it as a module, choose M here. If unsure, say N.
94175
94176+config NETFILTER_XT_MATCH_GRADM
94177+ tristate '"gradm" match support'
94178+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
94179+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
94180+ ---help---
94181+ The gradm match allows to match on grsecurity RBAC being enabled.
94182+ It is useful when iptables rules are applied early on bootup to
94183+ prevent connections to the machine (except from a trusted host)
94184+ while the RBAC system is disabled.
94185+
94186 config NETFILTER_XT_MATCH_HASHLIMIT
94187 tristate '"hashlimit" match support'
94188 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
94189diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
94190index a1abf87..dbcb7ee 100644
94191--- a/net/netfilter/Makefile
94192+++ b/net/netfilter/Makefile
94193@@ -112,6 +112,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
94194 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
94195 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
94196 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
94197+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
94198 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
94199 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
94200 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
94201diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
94202index f771390..145b765 100644
94203--- a/net/netfilter/ipset/ip_set_core.c
94204+++ b/net/netfilter/ipset/ip_set_core.c
94205@@ -1820,7 +1820,7 @@ done:
94206 return ret;
94207 }
94208
94209-static struct nf_sockopt_ops so_set __read_mostly = {
94210+static struct nf_sockopt_ops so_set = {
94211 .pf = PF_INET,
94212 .get_optmin = SO_IP_SET,
94213 .get_optmax = SO_IP_SET + 1,
94214diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
94215index 4c8e5c0..5a79b4d 100644
94216--- a/net/netfilter/ipvs/ip_vs_conn.c
94217+++ b/net/netfilter/ipvs/ip_vs_conn.c
94218@@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
94219 /* Increase the refcnt counter of the dest */
94220 ip_vs_dest_hold(dest);
94221
94222- conn_flags = atomic_read(&dest->conn_flags);
94223+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
94224 if (cp->protocol != IPPROTO_UDP)
94225 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
94226 flags = cp->flags;
94227@@ -900,7 +900,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
94228
94229 cp->control = NULL;
94230 atomic_set(&cp->n_control, 0);
94231- atomic_set(&cp->in_pkts, 0);
94232+ atomic_set_unchecked(&cp->in_pkts, 0);
94233
94234 cp->packet_xmit = NULL;
94235 cp->app = NULL;
94236@@ -1188,7 +1188,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
94237
94238 /* Don't drop the entry if its number of incoming packets is not
94239 located in [0, 8] */
94240- i = atomic_read(&cp->in_pkts);
94241+ i = atomic_read_unchecked(&cp->in_pkts);
94242 if (i > 8 || i < 0) return 0;
94243
94244 if (!todrop_rate[i]) return 0;
94245diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
94246index 4f69e83..da2d8bf 100644
94247--- a/net/netfilter/ipvs/ip_vs_core.c
94248+++ b/net/netfilter/ipvs/ip_vs_core.c
94249@@ -559,7 +559,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
94250 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
94251 /* do not touch skb anymore */
94252
94253- atomic_inc(&cp->in_pkts);
94254+ atomic_inc_unchecked(&cp->in_pkts);
94255 ip_vs_conn_put(cp);
94256 return ret;
94257 }
94258@@ -1711,7 +1711,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
94259 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
94260 pkts = sysctl_sync_threshold(ipvs);
94261 else
94262- pkts = atomic_add_return(1, &cp->in_pkts);
94263+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
94264
94265 if (ipvs->sync_state & IP_VS_STATE_MASTER)
94266 ip_vs_sync_conn(net, cp, pkts);
94267diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
94268index c8148e4..eff604f 100644
94269--- a/net/netfilter/ipvs/ip_vs_ctl.c
94270+++ b/net/netfilter/ipvs/ip_vs_ctl.c
94271@@ -789,7 +789,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
94272 */
94273 ip_vs_rs_hash(ipvs, dest);
94274 }
94275- atomic_set(&dest->conn_flags, conn_flags);
94276+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
94277
94278 /* bind the service */
94279 if (!dest->svc) {
94280@@ -1657,7 +1657,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
94281 * align with netns init in ip_vs_control_net_init()
94282 */
94283
94284-static struct ctl_table vs_vars[] = {
94285+static ctl_table_no_const vs_vars[] __read_only = {
94286 {
94287 .procname = "amemthresh",
94288 .maxlen = sizeof(int),
94289@@ -2078,7 +2078,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
94290 " %-7s %-6d %-10d %-10d\n",
94291 &dest->addr.in6,
94292 ntohs(dest->port),
94293- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
94294+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
94295 atomic_read(&dest->weight),
94296 atomic_read(&dest->activeconns),
94297 atomic_read(&dest->inactconns));
94298@@ -2089,7 +2089,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
94299 "%-7s %-6d %-10d %-10d\n",
94300 ntohl(dest->addr.ip),
94301 ntohs(dest->port),
94302- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
94303+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
94304 atomic_read(&dest->weight),
94305 atomic_read(&dest->activeconns),
94306 atomic_read(&dest->inactconns));
94307@@ -2567,7 +2567,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
94308
94309 entry.addr = dest->addr.ip;
94310 entry.port = dest->port;
94311- entry.conn_flags = atomic_read(&dest->conn_flags);
94312+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
94313 entry.weight = atomic_read(&dest->weight);
94314 entry.u_threshold = dest->u_threshold;
94315 entry.l_threshold = dest->l_threshold;
94316@@ -3110,7 +3110,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
94317 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
94318 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
94319 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
94320- (atomic_read(&dest->conn_flags) &
94321+ (atomic_read_unchecked(&dest->conn_flags) &
94322 IP_VS_CONN_F_FWD_MASK)) ||
94323 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
94324 atomic_read(&dest->weight)) ||
94325@@ -3700,7 +3700,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
94326 {
94327 int idx;
94328 struct netns_ipvs *ipvs = net_ipvs(net);
94329- struct ctl_table *tbl;
94330+ ctl_table_no_const *tbl;
94331
94332 atomic_set(&ipvs->dropentry, 0);
94333 spin_lock_init(&ipvs->dropentry_lock);
94334diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
94335index 1383b0e..91f68ae 100644
94336--- a/net/netfilter/ipvs/ip_vs_lblc.c
94337+++ b/net/netfilter/ipvs/ip_vs_lblc.c
94338@@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
94339 * IPVS LBLC sysctl table
94340 */
94341 #ifdef CONFIG_SYSCTL
94342-static struct ctl_table vs_vars_table[] = {
94343+static struct ctl_table vs_vars_table[] __read_only = {
94344 {
94345 .procname = "lblc_expiration",
94346 .data = NULL,
94347diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
94348index 3cd85b2..b45b17e 100644
94349--- a/net/netfilter/ipvs/ip_vs_lblcr.c
94350+++ b/net/netfilter/ipvs/ip_vs_lblcr.c
94351@@ -299,7 +299,7 @@ struct ip_vs_lblcr_table {
94352 * IPVS LBLCR sysctl table
94353 */
94354
94355-static struct ctl_table vs_vars_table[] = {
94356+static struct ctl_table vs_vars_table[] __read_only = {
94357 {
94358 .procname = "lblcr_expiration",
94359 .data = NULL,
94360diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
94361index f448471..995f131 100644
94362--- a/net/netfilter/ipvs/ip_vs_sync.c
94363+++ b/net/netfilter/ipvs/ip_vs_sync.c
94364@@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
94365 cp = cp->control;
94366 if (cp) {
94367 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
94368- pkts = atomic_add_return(1, &cp->in_pkts);
94369+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
94370 else
94371 pkts = sysctl_sync_threshold(ipvs);
94372 ip_vs_sync_conn(net, cp->control, pkts);
94373@@ -771,7 +771,7 @@ control:
94374 if (!cp)
94375 return;
94376 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
94377- pkts = atomic_add_return(1, &cp->in_pkts);
94378+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
94379 else
94380 pkts = sysctl_sync_threshold(ipvs);
94381 goto sloop;
94382@@ -895,7 +895,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
94383
94384 if (opt)
94385 memcpy(&cp->in_seq, opt, sizeof(*opt));
94386- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
94387+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
94388 cp->state = state;
94389 cp->old_state = cp->state;
94390 /*
94391diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
94392index b75ff64..0c51bbe 100644
94393--- a/net/netfilter/ipvs/ip_vs_xmit.c
94394+++ b/net/netfilter/ipvs/ip_vs_xmit.c
94395@@ -1102,7 +1102,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
94396 else
94397 rc = NF_ACCEPT;
94398 /* do not touch skb anymore */
94399- atomic_inc(&cp->in_pkts);
94400+ atomic_inc_unchecked(&cp->in_pkts);
94401 goto out;
94402 }
94403
94404@@ -1194,7 +1194,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
94405 else
94406 rc = NF_ACCEPT;
94407 /* do not touch skb anymore */
94408- atomic_inc(&cp->in_pkts);
94409+ atomic_inc_unchecked(&cp->in_pkts);
94410 goto out;
94411 }
94412
94413diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
94414index 2d3030a..7ba1c0a 100644
94415--- a/net/netfilter/nf_conntrack_acct.c
94416+++ b/net/netfilter/nf_conntrack_acct.c
94417@@ -60,7 +60,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
94418 #ifdef CONFIG_SYSCTL
94419 static int nf_conntrack_acct_init_sysctl(struct net *net)
94420 {
94421- struct ctl_table *table;
94422+ ctl_table_no_const *table;
94423
94424 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
94425 GFP_KERNEL);
94426diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
94427index 0283bae..5febcb0 100644
94428--- a/net/netfilter/nf_conntrack_core.c
94429+++ b/net/netfilter/nf_conntrack_core.c
94430@@ -1614,6 +1614,10 @@ void nf_conntrack_init_end(void)
94431 #define DYING_NULLS_VAL ((1<<30)+1)
94432 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
94433
94434+#ifdef CONFIG_GRKERNSEC_HIDESYM
94435+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
94436+#endif
94437+
94438 int nf_conntrack_init_net(struct net *net)
94439 {
94440 int ret;
94441@@ -1628,7 +1632,11 @@ int nf_conntrack_init_net(struct net *net)
94442 goto err_stat;
94443 }
94444
94445+#ifdef CONFIG_GRKERNSEC_HIDESYM
94446+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
94447+#else
94448 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
94449+#endif
94450 if (!net->ct.slabname) {
94451 ret = -ENOMEM;
94452 goto err_slabname;
94453diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
94454index 1df1761..ce8b88a 100644
94455--- a/net/netfilter/nf_conntrack_ecache.c
94456+++ b/net/netfilter/nf_conntrack_ecache.c
94457@@ -188,7 +188,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
94458 #ifdef CONFIG_SYSCTL
94459 static int nf_conntrack_event_init_sysctl(struct net *net)
94460 {
94461- struct ctl_table *table;
94462+ ctl_table_no_const *table;
94463
94464 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
94465 GFP_KERNEL);
94466diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
94467index 974a2a4..52cc6ff 100644
94468--- a/net/netfilter/nf_conntrack_helper.c
94469+++ b/net/netfilter/nf_conntrack_helper.c
94470@@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
94471
94472 static int nf_conntrack_helper_init_sysctl(struct net *net)
94473 {
94474- struct ctl_table *table;
94475+ ctl_table_no_const *table;
94476
94477 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
94478 GFP_KERNEL);
94479diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
94480index 0ab9636..cea3c6a 100644
94481--- a/net/netfilter/nf_conntrack_proto.c
94482+++ b/net/netfilter/nf_conntrack_proto.c
94483@@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
94484
94485 static void
94486 nf_ct_unregister_sysctl(struct ctl_table_header **header,
94487- struct ctl_table **table,
94488+ ctl_table_no_const **table,
94489 unsigned int users)
94490 {
94491 if (users > 0)
94492diff --git a/net/netfilter/nf_conntrack_proto_dccp.c b/net/netfilter/nf_conntrack_proto_dccp.c
94493index a99b6c3..cb372f9 100644
94494--- a/net/netfilter/nf_conntrack_proto_dccp.c
94495+++ b/net/netfilter/nf_conntrack_proto_dccp.c
94496@@ -428,7 +428,7 @@ static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
94497 const char *msg;
94498 u_int8_t state;
94499
94500- dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
94501+ dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
94502 BUG_ON(dh == NULL);
94503
94504 state = dccp_state_table[CT_DCCP_ROLE_CLIENT][dh->dccph_type][CT_DCCP_NONE];
94505@@ -457,7 +457,7 @@ static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
94506 out_invalid:
94507 if (LOG_INVALID(net, IPPROTO_DCCP))
94508 nf_log_packet(net, nf_ct_l3num(ct), 0, skb, NULL, NULL,
94509- NULL, msg);
94510+ NULL, "%s", msg);
94511 return false;
94512 }
94513
94514@@ -486,7 +486,7 @@ static int dccp_packet(struct nf_conn *ct, const struct sk_buff *skb,
94515 u_int8_t type, old_state, new_state;
94516 enum ct_dccp_roles role;
94517
94518- dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
94519+ dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
94520 BUG_ON(dh == NULL);
94521 type = dh->dccph_type;
94522
94523@@ -577,7 +577,7 @@ static int dccp_error(struct net *net, struct nf_conn *tmpl,
94524 unsigned int cscov;
94525 const char *msg;
94526
94527- dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
94528+ dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
94529 if (dh == NULL) {
94530 msg = "nf_ct_dccp: short packet ";
94531 goto out_invalid;
94532@@ -614,7 +614,7 @@ static int dccp_error(struct net *net, struct nf_conn *tmpl,
94533
94534 out_invalid:
94535 if (LOG_INVALID(net, IPPROTO_DCCP))
94536- nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, msg);
94537+ nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, "%s", msg);
94538 return -NF_ACCEPT;
94539 }
94540
94541diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
94542index f641751..d3c5b51 100644
94543--- a/net/netfilter/nf_conntrack_standalone.c
94544+++ b/net/netfilter/nf_conntrack_standalone.c
94545@@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
94546
94547 static int nf_conntrack_standalone_init_sysctl(struct net *net)
94548 {
94549- struct ctl_table *table;
94550+ ctl_table_no_const *table;
94551
94552 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
94553 GFP_KERNEL);
94554diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
94555index 902fb0a..87f7fdb 100644
94556--- a/net/netfilter/nf_conntrack_timestamp.c
94557+++ b/net/netfilter/nf_conntrack_timestamp.c
94558@@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
94559 #ifdef CONFIG_SYSCTL
94560 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
94561 {
94562- struct ctl_table *table;
94563+ ctl_table_no_const *table;
94564
94565 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
94566 GFP_KERNEL);
94567diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
94568index 85296d4..8becdec 100644
94569--- a/net/netfilter/nf_log.c
94570+++ b/net/netfilter/nf_log.c
94571@@ -243,7 +243,7 @@ static const struct file_operations nflog_file_ops = {
94572
94573 #ifdef CONFIG_SYSCTL
94574 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
94575-static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
94576+static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
94577
94578 static int nf_log_proc_dostring(struct ctl_table *table, int write,
94579 void __user *buffer, size_t *lenp, loff_t *ppos)
94580@@ -274,14 +274,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
94581 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
94582 mutex_unlock(&nf_log_mutex);
94583 } else {
94584+ ctl_table_no_const nf_log_table = *table;
94585+
94586 mutex_lock(&nf_log_mutex);
94587 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
94588 lockdep_is_held(&nf_log_mutex));
94589 if (!logger)
94590- table->data = "NONE";
94591+ nf_log_table.data = "NONE";
94592 else
94593- table->data = logger->name;
94594- r = proc_dostring(table, write, buffer, lenp, ppos);
94595+ nf_log_table.data = logger->name;
94596+ r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
94597 mutex_unlock(&nf_log_mutex);
94598 }
94599
94600diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
94601index f042ae5..30ea486 100644
94602--- a/net/netfilter/nf_sockopt.c
94603+++ b/net/netfilter/nf_sockopt.c
94604@@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
94605 }
94606 }
94607
94608- list_add(&reg->list, &nf_sockopts);
94609+ pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
94610 out:
94611 mutex_unlock(&nf_sockopt_mutex);
94612 return ret;
94613@@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
94614 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
94615 {
94616 mutex_lock(&nf_sockopt_mutex);
94617- list_del(&reg->list);
94618+ pax_list_del((struct list_head *)&reg->list);
94619 mutex_unlock(&nf_sockopt_mutex);
94620 }
94621 EXPORT_SYMBOL(nf_unregister_sockopt);
94622diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
94623index d92cc31..e46f350 100644
94624--- a/net/netfilter/nfnetlink_log.c
94625+++ b/net/netfilter/nfnetlink_log.c
94626@@ -82,7 +82,7 @@ static int nfnl_log_net_id __read_mostly;
94627 struct nfnl_log_net {
94628 spinlock_t instances_lock;
94629 struct hlist_head instance_table[INSTANCE_BUCKETS];
94630- atomic_t global_seq;
94631+ atomic_unchecked_t global_seq;
94632 };
94633
94634 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
94635@@ -563,7 +563,7 @@ __build_packet_message(struct nfnl_log_net *log,
94636 /* global sequence number */
94637 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
94638 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
94639- htonl(atomic_inc_return(&log->global_seq))))
94640+ htonl(atomic_inc_return_unchecked(&log->global_seq))))
94641 goto nla_put_failure;
94642
94643 if (data_len) {
94644diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
94645new file mode 100644
94646index 0000000..c566332
94647--- /dev/null
94648+++ b/net/netfilter/xt_gradm.c
94649@@ -0,0 +1,51 @@
94650+/*
94651+ * gradm match for netfilter
94652