]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-2.9.1-3.11.3-201310012249.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.11.3-201310012249.patch
CommitLineData
f8fe7a20
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 4f91b99..cb9dcfc 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..e425391 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@@ -413,6 +441,12 @@ ENTRY(vector_swi)
2611 USER( ldr scno, [lr, #-4] ) @ get SWI instruction
2612 #endif
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 adr tbl, sys_call_table @ load syscall table pointer
2621
2622 #if defined(CONFIG_OABI_COMPAT)
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..054c2dc 100644
2749--- a/arch/arm/kernel/module.c
2750+++ b/arch/arm/kernel/module.c
2751@@ -37,12 +37,39 @@
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+EXPORT_SYMBOL(module_free_exec);
2783+
2784+void *module_alloc_exec(unsigned long size)
2785+{
2786+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2787+}
2788+EXPORT_SYMBOL(module_alloc_exec);
2789+#endif
2790 #endif
2791
2792 int
2793diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
2794index 07314af..c46655c 100644
2795--- a/arch/arm/kernel/patch.c
2796+++ b/arch/arm/kernel/patch.c
2797@@ -18,6 +18,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2798 bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
2799 int size;
2800
2801+ pax_open_kernel();
2802 if (thumb2 && __opcode_is_thumb16(insn)) {
2803 *(u16 *)addr = __opcode_to_mem_thumb16(insn);
2804 size = sizeof(u16);
2805@@ -39,6 +40,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2806 *(u32 *)addr = insn;
2807 size = sizeof(u32);
2808 }
2809+ pax_close_kernel();
2810
2811 flush_icache_range((uintptr_t)(addr),
2812 (uintptr_t)(addr) + size);
2813diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
2814index 94f6b05..efd7312 100644
2815--- a/arch/arm/kernel/process.c
2816+++ b/arch/arm/kernel/process.c
2817@@ -217,6 +217,7 @@ void machine_power_off(void)
2818
2819 if (pm_power_off)
2820 pm_power_off();
2821+ BUG();
2822 }
2823
2824 /*
2825@@ -230,7 +231,7 @@ void machine_power_off(void)
2826 * executing pre-reset code, and using RAM that the primary CPU's code wishes
2827 * to use. Implementing such co-ordination would be essentially impossible.
2828 */
2829-void machine_restart(char *cmd)
2830+__noreturn void machine_restart(char *cmd)
2831 {
2832 local_irq_disable();
2833 smp_send_stop();
2834@@ -253,8 +254,8 @@ void __show_regs(struct pt_regs *regs)
2835
2836 show_regs_print_info(KERN_DEFAULT);
2837
2838- print_symbol("PC is at %s\n", instruction_pointer(regs));
2839- print_symbol("LR is at %s\n", regs->ARM_lr);
2840+ printk("PC is at %pA\n", (void *)instruction_pointer(regs));
2841+ printk("LR is at %pA\n", (void *)regs->ARM_lr);
2842 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2843 "sp : %08lx ip : %08lx fp : %08lx\n",
2844 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2845@@ -422,12 +423,6 @@ unsigned long get_wchan(struct task_struct *p)
2846 return 0;
2847 }
2848
2849-unsigned long arch_randomize_brk(struct mm_struct *mm)
2850-{
2851- unsigned long range_end = mm->brk + 0x02000000;
2852- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2853-}
2854-
2855 #ifdef CONFIG_MMU
2856 #ifdef CONFIG_KUSER_HELPERS
2857 /*
2858@@ -443,7 +438,7 @@ static struct vm_area_struct gate_vma = {
2859
2860 static int __init gate_vma_init(void)
2861 {
2862- gate_vma.vm_page_prot = PAGE_READONLY_EXEC;
2863+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
2864 return 0;
2865 }
2866 arch_initcall(gate_vma_init);
2867@@ -469,41 +464,16 @@ int in_gate_area_no_mm(unsigned long addr)
2868
2869 const char *arch_vma_name(struct vm_area_struct *vma)
2870 {
2871- return is_gate_vma(vma) ? "[vectors]" :
2872- (vma->vm_mm && vma->vm_start == vma->vm_mm->context.sigpage) ?
2873- "[sigpage]" : NULL;
2874+ return is_gate_vma(vma) ? "[vectors]" : NULL;
2875 }
2876
2877-static struct page *signal_page;
2878-extern struct page *get_signal_page(void);
2879-
2880 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
2881 {
2882 struct mm_struct *mm = current->mm;
2883- unsigned long addr;
2884- int ret;
2885-
2886- if (!signal_page)
2887- signal_page = get_signal_page();
2888- if (!signal_page)
2889- return -ENOMEM;
2890
2891 down_write(&mm->mmap_sem);
2892- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
2893- if (IS_ERR_VALUE(addr)) {
2894- ret = addr;
2895- goto up_fail;
2896- }
2897-
2898- ret = install_special_mapping(mm, addr, PAGE_SIZE,
2899- VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC,
2900- &signal_page);
2901-
2902- if (ret == 0)
2903- mm->context.sigpage = addr;
2904-
2905- up_fail:
2906+ mm->context.sigpage = (PAGE_OFFSET + (get_random_int() % 0x3FFEFFE0)) & 0xFFFFFFFC;
2907 up_write(&mm->mmap_sem);
2908- return ret;
2909+ return 0;
2910 }
2911 #endif
2912diff --git a/arch/arm/kernel/psci.c b/arch/arm/kernel/psci.c
2913index 4693188..4596c5e 100644
2914--- a/arch/arm/kernel/psci.c
2915+++ b/arch/arm/kernel/psci.c
2916@@ -24,7 +24,7 @@
2917 #include <asm/opcodes-virt.h>
2918 #include <asm/psci.h>
2919
2920-struct psci_operations psci_ops;
2921+struct psci_operations psci_ops __read_only;
2922
2923 static int (*invoke_psci_fn)(u32, u32, u32, u32);
2924
2925diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
2926index 0dd3b79..e018f64 100644
2927--- a/arch/arm/kernel/ptrace.c
2928+++ b/arch/arm/kernel/ptrace.c
2929@@ -929,10 +929,19 @@ static int tracehook_report_syscall(struct pt_regs *regs,
2930 return current_thread_info()->syscall;
2931 }
2932
2933+#ifdef CONFIG_GRKERNSEC_SETXID
2934+extern void gr_delayed_cred_worker(void);
2935+#endif
2936+
2937 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
2938 {
2939 current_thread_info()->syscall = scno;
2940
2941+#ifdef CONFIG_GRKERNSEC_SETXID
2942+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2943+ gr_delayed_cred_worker();
2944+#endif
2945+
2946 /* Do the secure computing check first; failures should be fast. */
2947 if (secure_computing(scno) == -1)
2948 return -1;
2949diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
2950index afc2489..6372bc8 100644
2951--- a/arch/arm/kernel/setup.c
2952+++ b/arch/arm/kernel/setup.c
2953@@ -98,21 +98,23 @@ EXPORT_SYMBOL(system_serial_high);
2954 unsigned int elf_hwcap __read_mostly;
2955 EXPORT_SYMBOL(elf_hwcap);
2956
2957+pteval_t __supported_pte_mask __read_only;
2958+pmdval_t __supported_pmd_mask __read_only;
2959
2960 #ifdef MULTI_CPU
2961-struct processor processor __read_mostly;
2962+struct processor processor;
2963 #endif
2964 #ifdef MULTI_TLB
2965-struct cpu_tlb_fns cpu_tlb __read_mostly;
2966+struct cpu_tlb_fns cpu_tlb __read_only;
2967 #endif
2968 #ifdef MULTI_USER
2969-struct cpu_user_fns cpu_user __read_mostly;
2970+struct cpu_user_fns cpu_user __read_only;
2971 #endif
2972 #ifdef MULTI_CACHE
2973-struct cpu_cache_fns cpu_cache __read_mostly;
2974+struct cpu_cache_fns cpu_cache __read_only;
2975 #endif
2976 #ifdef CONFIG_OUTER_CACHE
2977-struct outer_cache_fns outer_cache __read_mostly;
2978+struct outer_cache_fns outer_cache __read_only;
2979 EXPORT_SYMBOL(outer_cache);
2980 #endif
2981
2982@@ -245,9 +247,13 @@ static int __get_cpu_architecture(void)
2983 asm("mrc p15, 0, %0, c0, c1, 4"
2984 : "=r" (mmfr0));
2985 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
2986- (mmfr0 & 0x000000f0) >= 0x00000030)
2987+ (mmfr0 & 0x000000f0) >= 0x00000030) {
2988 cpu_arch = CPU_ARCH_ARMv7;
2989- else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
2990+ if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
2991+ __supported_pte_mask |= L_PTE_PXN;
2992+ __supported_pmd_mask |= PMD_PXNTABLE;
2993+ }
2994+ } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
2995 (mmfr0 & 0x000000f0) == 0x00000020)
2996 cpu_arch = CPU_ARCH_ARMv6;
2997 else
2998@@ -571,7 +577,7 @@ static void __init setup_processor(void)
2999 __cpu_architecture = __get_cpu_architecture();
3000
3001 #ifdef MULTI_CPU
3002- processor = *list->proc;
3003+ memcpy((void *)&processor, list->proc, sizeof processor);
3004 #endif
3005 #ifdef MULTI_TLB
3006 cpu_tlb = *list->tlb;
3007diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
3008index ab33042..11248a8 100644
3009--- a/arch/arm/kernel/signal.c
3010+++ b/arch/arm/kernel/signal.c
3011@@ -45,8 +45,6 @@ static const unsigned long sigreturn_codes[7] = {
3012 MOV_R7_NR_RT_SIGRETURN, SWI_SYS_RT_SIGRETURN, SWI_THUMB_RT_SIGRETURN,
3013 };
3014
3015-static unsigned long signal_return_offset;
3016-
3017 #ifdef CONFIG_CRUNCH
3018 static int preserve_crunch_context(struct crunch_sigframe __user *frame)
3019 {
3020@@ -411,8 +409,7 @@ setup_return(struct pt_regs *regs, struct ksignal *ksig,
3021 * except when the MPU has protected the vectors
3022 * page from PL0
3023 */
3024- retcode = mm->context.sigpage + signal_return_offset +
3025- (idx << 2) + thumb;
3026+ retcode = mm->context.sigpage + (idx << 2) + thumb;
3027 } else
3028 #endif
3029 {
3030@@ -616,33 +613,3 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
3031 } while (thread_flags & _TIF_WORK_MASK);
3032 return 0;
3033 }
3034-
3035-struct page *get_signal_page(void)
3036-{
3037- unsigned long ptr;
3038- unsigned offset;
3039- struct page *page;
3040- void *addr;
3041-
3042- page = alloc_pages(GFP_KERNEL, 0);
3043-
3044- if (!page)
3045- return NULL;
3046-
3047- addr = page_address(page);
3048-
3049- /* Give the signal return code some randomness */
3050- offset = 0x200 + (get_random_int() & 0x7fc);
3051- signal_return_offset = offset;
3052-
3053- /*
3054- * Copy signal return handlers into the vector page, and
3055- * set sigreturn to be a pointer to these.
3056- */
3057- memcpy(addr + offset, sigreturn_codes, sizeof(sigreturn_codes));
3058-
3059- ptr = (unsigned long)addr + offset;
3060- flush_icache_range(ptr, ptr + sizeof(sigreturn_codes));
3061-
3062- return page;
3063-}
3064diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
3065index 2dc1934..ecf0e21 100644
3066--- a/arch/arm/kernel/smp.c
3067+++ b/arch/arm/kernel/smp.c
3068@@ -71,7 +71,7 @@ enum ipi_msg_type {
3069
3070 static DECLARE_COMPLETION(cpu_running);
3071
3072-static struct smp_operations smp_ops;
3073+static struct smp_operations smp_ops __read_only;
3074
3075 void __init smp_set_ops(struct smp_operations *ops)
3076 {
3077diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
3078index ab517fc..9adf2fa 100644
3079--- a/arch/arm/kernel/traps.c
3080+++ b/arch/arm/kernel/traps.c
3081@@ -55,7 +55,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
3082 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
3083 {
3084 #ifdef CONFIG_KALLSYMS
3085- printk("[<%08lx>] (%pS) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
3086+ printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
3087 #else
3088 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
3089 #endif
3090@@ -257,6 +257,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
3091 static int die_owner = -1;
3092 static unsigned int die_nest_count;
3093
3094+extern void gr_handle_kernel_exploit(void);
3095+
3096 static unsigned long oops_begin(void)
3097 {
3098 int cpu;
3099@@ -299,6 +301,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3100 panic("Fatal exception in interrupt");
3101 if (panic_on_oops)
3102 panic("Fatal exception");
3103+
3104+ gr_handle_kernel_exploit();
3105+
3106 if (signr)
3107 do_exit(signr);
3108 }
3109@@ -592,7 +597,9 @@ asmlinkage int arm_syscall(int no, struct pt_regs *regs)
3110 * The user helper at 0xffff0fe0 must be used instead.
3111 * (see entry-armv.S for details)
3112 */
3113+ pax_open_kernel();
3114 *((unsigned int *)0xffff0ff0) = regs->ARM_r0;
3115+ pax_close_kernel();
3116 }
3117 return 0;
3118
3119@@ -849,7 +856,11 @@ void __init early_trap_init(void *vectors_base)
3120 kuser_init(vectors_base);
3121
3122 flush_icache_range(vectors, vectors + PAGE_SIZE * 2);
3123- modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3124+
3125+#ifndef CONFIG_PAX_MEMORY_UDEREF
3126+ modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3127+#endif
3128+
3129 #else /* ifndef CONFIG_CPU_V7M */
3130 /*
3131 * on V7-M there is no need to copy the vector table to a dedicated
3132diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
3133index 7bcee5c..e2f3249 100644
3134--- a/arch/arm/kernel/vmlinux.lds.S
3135+++ b/arch/arm/kernel/vmlinux.lds.S
3136@@ -8,7 +8,11 @@
3137 #include <asm/thread_info.h>
3138 #include <asm/memory.h>
3139 #include <asm/page.h>
3140-
3141+
3142+#ifdef CONFIG_PAX_KERNEXEC
3143+#include <asm/pgtable.h>
3144+#endif
3145+
3146 #define PROC_INFO \
3147 . = ALIGN(4); \
3148 VMLINUX_SYMBOL(__proc_info_begin) = .; \
3149@@ -34,7 +38,7 @@
3150 #endif
3151
3152 #if (defined(CONFIG_SMP_ON_UP) && !defined(CONFIG_DEBUG_SPINLOCK)) || \
3153- defined(CONFIG_GENERIC_BUG)
3154+ defined(CONFIG_GENERIC_BUG) || defined(CONFIG_PAX_REFCOUNT)
3155 #define ARM_EXIT_KEEP(x) x
3156 #define ARM_EXIT_DISCARD(x)
3157 #else
3158@@ -90,6 +94,11 @@ SECTIONS
3159 _text = .;
3160 HEAD_TEXT
3161 }
3162+
3163+#ifdef CONFIG_PAX_KERNEXEC
3164+ . = ALIGN(1<<SECTION_SHIFT);
3165+#endif
3166+
3167 .text : { /* Real text segment */
3168 _stext = .; /* Text and read-only data */
3169 __exception_text_start = .;
3170@@ -112,6 +121,8 @@ SECTIONS
3171 ARM_CPU_KEEP(PROC_INFO)
3172 }
3173
3174+ _etext = .; /* End of text section */
3175+
3176 RO_DATA(PAGE_SIZE)
3177
3178 . = ALIGN(4);
3179@@ -142,7 +153,9 @@ SECTIONS
3180
3181 NOTES
3182
3183- _etext = .; /* End of text and rodata section */
3184+#ifdef CONFIG_PAX_KERNEXEC
3185+ . = ALIGN(1<<SECTION_SHIFT);
3186+#endif
3187
3188 #ifndef CONFIG_XIP_KERNEL
3189 . = ALIGN(PAGE_SIZE);
3190@@ -220,6 +233,11 @@ SECTIONS
3191 . = PAGE_OFFSET + TEXT_OFFSET;
3192 #else
3193 __init_end = .;
3194+
3195+#ifdef CONFIG_PAX_KERNEXEC
3196+ . = ALIGN(1<<SECTION_SHIFT);
3197+#endif
3198+
3199 . = ALIGN(THREAD_SIZE);
3200 __data_loc = .;
3201 #endif
3202diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
3203index 741f66a..8a5615c 100644
3204--- a/arch/arm/kvm/arm.c
3205+++ b/arch/arm/kvm/arm.c
3206@@ -56,7 +56,7 @@ static unsigned long hyp_default_vectors;
3207 static DEFINE_PER_CPU(struct kvm_vcpu *, kvm_arm_running_vcpu);
3208
3209 /* The VMID used in the VTTBR */
3210-static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1);
3211+static atomic64_unchecked_t kvm_vmid_gen = ATOMIC64_INIT(1);
3212 static u8 kvm_next_vmid;
3213 static DEFINE_SPINLOCK(kvm_vmid_lock);
3214
3215@@ -392,7 +392,7 @@ void force_vm_exit(const cpumask_t *mask)
3216 */
3217 static bool need_new_vmid_gen(struct kvm *kvm)
3218 {
3219- return unlikely(kvm->arch.vmid_gen != atomic64_read(&kvm_vmid_gen));
3220+ return unlikely(kvm->arch.vmid_gen != atomic64_read_unchecked(&kvm_vmid_gen));
3221 }
3222
3223 /**
3224@@ -425,7 +425,7 @@ static void update_vttbr(struct kvm *kvm)
3225
3226 /* First user of a new VMID generation? */
3227 if (unlikely(kvm_next_vmid == 0)) {
3228- atomic64_inc(&kvm_vmid_gen);
3229+ atomic64_inc_unchecked(&kvm_vmid_gen);
3230 kvm_next_vmid = 1;
3231
3232 /*
3233@@ -442,7 +442,7 @@ static void update_vttbr(struct kvm *kvm)
3234 kvm_call_hyp(__kvm_flush_vm_context);
3235 }
3236
3237- kvm->arch.vmid_gen = atomic64_read(&kvm_vmid_gen);
3238+ kvm->arch.vmid_gen = atomic64_read_unchecked(&kvm_vmid_gen);
3239 kvm->arch.vmid = kvm_next_vmid;
3240 kvm_next_vmid++;
3241
3242diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3243index 14a0d98..7771a7d 100644
3244--- a/arch/arm/lib/clear_user.S
3245+++ b/arch/arm/lib/clear_user.S
3246@@ -12,14 +12,14 @@
3247
3248 .text
3249
3250-/* Prototype: int __clear_user(void *addr, size_t sz)
3251+/* Prototype: int ___clear_user(void *addr, size_t sz)
3252 * Purpose : clear some user memory
3253 * Params : addr - user memory address to clear
3254 * : sz - number of bytes to clear
3255 * Returns : number of bytes NOT cleared
3256 */
3257 ENTRY(__clear_user_std)
3258-WEAK(__clear_user)
3259+WEAK(___clear_user)
3260 stmfd sp!, {r1, lr}
3261 mov r2, #0
3262 cmp r1, #4
3263@@ -44,7 +44,7 @@ WEAK(__clear_user)
3264 USER( strnebt r2, [r0])
3265 mov r0, #0
3266 ldmfd sp!, {r1, pc}
3267-ENDPROC(__clear_user)
3268+ENDPROC(___clear_user)
3269 ENDPROC(__clear_user_std)
3270
3271 .pushsection .fixup,"ax"
3272diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3273index 66a477a..bee61d3 100644
3274--- a/arch/arm/lib/copy_from_user.S
3275+++ b/arch/arm/lib/copy_from_user.S
3276@@ -16,7 +16,7 @@
3277 /*
3278 * Prototype:
3279 *
3280- * size_t __copy_from_user(void *to, const void *from, size_t n)
3281+ * size_t ___copy_from_user(void *to, const void *from, size_t n)
3282 *
3283 * Purpose:
3284 *
3285@@ -84,11 +84,11 @@
3286
3287 .text
3288
3289-ENTRY(__copy_from_user)
3290+ENTRY(___copy_from_user)
3291
3292 #include "copy_template.S"
3293
3294-ENDPROC(__copy_from_user)
3295+ENDPROC(___copy_from_user)
3296
3297 .pushsection .fixup,"ax"
3298 .align 0
3299diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3300index 6ee2f67..d1cce76 100644
3301--- a/arch/arm/lib/copy_page.S
3302+++ b/arch/arm/lib/copy_page.S
3303@@ -10,6 +10,7 @@
3304 * ASM optimised string functions
3305 */
3306 #include <linux/linkage.h>
3307+#include <linux/const.h>
3308 #include <asm/assembler.h>
3309 #include <asm/asm-offsets.h>
3310 #include <asm/cache.h>
3311diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3312index d066df6..df28194 100644
3313--- a/arch/arm/lib/copy_to_user.S
3314+++ b/arch/arm/lib/copy_to_user.S
3315@@ -16,7 +16,7 @@
3316 /*
3317 * Prototype:
3318 *
3319- * size_t __copy_to_user(void *to, const void *from, size_t n)
3320+ * size_t ___copy_to_user(void *to, const void *from, size_t n)
3321 *
3322 * Purpose:
3323 *
3324@@ -88,11 +88,11 @@
3325 .text
3326
3327 ENTRY(__copy_to_user_std)
3328-WEAK(__copy_to_user)
3329+WEAK(___copy_to_user)
3330
3331 #include "copy_template.S"
3332
3333-ENDPROC(__copy_to_user)
3334+ENDPROC(___copy_to_user)
3335 ENDPROC(__copy_to_user_std)
3336
3337 .pushsection .fixup,"ax"
3338diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3339index 7d08b43..f7ca7ea 100644
3340--- a/arch/arm/lib/csumpartialcopyuser.S
3341+++ b/arch/arm/lib/csumpartialcopyuser.S
3342@@ -57,8 +57,8 @@
3343 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3344 */
3345
3346-#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3347-#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3348+#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3349+#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3350
3351 #include "csumpartialcopygeneric.S"
3352
3353diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3354index 5306de3..aed6d03 100644
3355--- a/arch/arm/lib/delay.c
3356+++ b/arch/arm/lib/delay.c
3357@@ -28,7 +28,7 @@
3358 /*
3359 * Default to the loop-based delay implementation.
3360 */
3361-struct arm_delay_ops arm_delay_ops = {
3362+struct arm_delay_ops arm_delay_ops __read_only = {
3363 .delay = __loop_delay,
3364 .const_udelay = __loop_const_udelay,
3365 .udelay = __loop_udelay,
3366diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3367index 025f742..a9e5b3b 100644
3368--- a/arch/arm/lib/uaccess_with_memcpy.c
3369+++ b/arch/arm/lib/uaccess_with_memcpy.c
3370@@ -104,7 +104,7 @@ out:
3371 }
3372
3373 unsigned long
3374-__copy_to_user(void __user *to, const void *from, unsigned long n)
3375+___copy_to_user(void __user *to, const void *from, unsigned long n)
3376 {
3377 /*
3378 * This test is stubbed out of the main function above to keep
3379@@ -155,7 +155,7 @@ out:
3380 return n;
3381 }
3382
3383-unsigned long __clear_user(void __user *addr, unsigned long n)
3384+unsigned long ___clear_user(void __user *addr, unsigned long n)
3385 {
3386 /* See rational for this in __copy_to_user() above. */
3387 if (n < 64)
3388diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
3389index e9238b5..6ed904a 100644
3390--- a/arch/arm/mach-kirkwood/common.c
3391+++ b/arch/arm/mach-kirkwood/common.c
3392@@ -150,7 +150,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
3393 clk_gate_ops.disable(hw);
3394 }
3395
3396-static struct clk_ops clk_gate_fn_ops;
3397+static int clk_gate_fn_is_enabled(struct clk_hw *hw)
3398+{
3399+ return clk_gate_ops.is_enabled(hw);
3400+}
3401+
3402+static struct clk_ops clk_gate_fn_ops = {
3403+ .enable = clk_gate_fn_enable,
3404+ .disable = clk_gate_fn_disable,
3405+ .is_enabled = clk_gate_fn_is_enabled,
3406+};
3407
3408 static struct clk __init *clk_register_gate_fn(struct device *dev,
3409 const char *name,
3410@@ -184,14 +193,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
3411 gate_fn->fn_en = fn_en;
3412 gate_fn->fn_dis = fn_dis;
3413
3414- /* ops is the gate ops, but with our enable/disable functions */
3415- if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
3416- clk_gate_fn_ops.disable != clk_gate_fn_disable) {
3417- clk_gate_fn_ops = clk_gate_ops;
3418- clk_gate_fn_ops.enable = clk_gate_fn_enable;
3419- clk_gate_fn_ops.disable = clk_gate_fn_disable;
3420- }
3421-
3422 clk = clk_register(dev, &gate_fn->gate.hw);
3423
3424 if (IS_ERR(clk))
3425diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3426index 827d1500..2885dc6 100644
3427--- a/arch/arm/mach-omap2/board-n8x0.c
3428+++ b/arch/arm/mach-omap2/board-n8x0.c
3429@@ -627,7 +627,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3430 }
3431 #endif
3432
3433-static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3434+static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3435 .late_init = n8x0_menelaus_late_init,
3436 };
3437
3438diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
3439index f3fdd6a..3564800 100644
3440--- a/arch/arm/mach-omap2/gpmc.c
3441+++ b/arch/arm/mach-omap2/gpmc.c
3442@@ -148,7 +148,6 @@ struct omap3_gpmc_regs {
3443 };
3444
3445 static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
3446-static struct irq_chip gpmc_irq_chip;
3447 static unsigned gpmc_irq_start;
3448
3449 static struct resource gpmc_mem_root;
3450@@ -716,6 +715,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
3451
3452 static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
3453
3454+static struct irq_chip gpmc_irq_chip = {
3455+ .name = "gpmc",
3456+ .irq_startup = gpmc_irq_noop_ret,
3457+ .irq_enable = gpmc_irq_enable,
3458+ .irq_disable = gpmc_irq_disable,
3459+ .irq_shutdown = gpmc_irq_noop,
3460+ .irq_ack = gpmc_irq_noop,
3461+ .irq_mask = gpmc_irq_noop,
3462+ .irq_unmask = gpmc_irq_noop,
3463+
3464+};
3465+
3466 static int gpmc_setup_irq(void)
3467 {
3468 int i;
3469@@ -730,15 +741,6 @@ static int gpmc_setup_irq(void)
3470 return gpmc_irq_start;
3471 }
3472
3473- gpmc_irq_chip.name = "gpmc";
3474- gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
3475- gpmc_irq_chip.irq_enable = gpmc_irq_enable;
3476- gpmc_irq_chip.irq_disable = gpmc_irq_disable;
3477- gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
3478- gpmc_irq_chip.irq_ack = gpmc_irq_noop;
3479- gpmc_irq_chip.irq_mask = gpmc_irq_noop;
3480- gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
3481-
3482 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
3483 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
3484
3485diff --git a/arch/arm/mach-omap2/omap-mpuss-lowpower.c b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3486index f991016..145ebeb 100644
3487--- a/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3488+++ b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3489@@ -84,7 +84,7 @@ struct cpu_pm_ops {
3490 int (*finish_suspend)(unsigned long cpu_state);
3491 void (*resume)(void);
3492 void (*scu_prepare)(unsigned int cpu_id, unsigned int cpu_state);
3493-};
3494+} __no_const;
3495
3496 static DEFINE_PER_CPU(struct omap4_cpu_pm_info, omap4_pm_info);
3497 static struct powerdomain *mpuss_pd;
3498@@ -102,7 +102,7 @@ static void dummy_cpu_resume(void)
3499 static void dummy_scu_prepare(unsigned int cpu_id, unsigned int cpu_state)
3500 {}
3501
3502-struct cpu_pm_ops omap_pm_ops = {
3503+static struct cpu_pm_ops omap_pm_ops __read_only = {
3504 .finish_suspend = default_finish_suspend,
3505 .resume = dummy_cpu_resume,
3506 .scu_prepare = dummy_scu_prepare,
3507diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3508index 813c615..ce467c6 100644
3509--- a/arch/arm/mach-omap2/omap-wakeupgen.c
3510+++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3511@@ -339,7 +339,7 @@ static int irq_cpu_hotplug_notify(struct notifier_block *self,
3512 return NOTIFY_OK;
3513 }
3514
3515-static struct notifier_block __refdata irq_hotplug_notifier = {
3516+static struct notifier_block irq_hotplug_notifier = {
3517 .notifier_call = irq_cpu_hotplug_notify,
3518 };
3519
3520diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
3521index f99f68e..e573e20 100644
3522--- a/arch/arm/mach-omap2/omap_device.c
3523+++ b/arch/arm/mach-omap2/omap_device.c
3524@@ -504,7 +504,7 @@ void omap_device_delete(struct omap_device *od)
3525 struct platform_device __init *omap_device_build(const char *pdev_name,
3526 int pdev_id,
3527 struct omap_hwmod *oh,
3528- void *pdata, int pdata_len)
3529+ const void *pdata, int pdata_len)
3530 {
3531 struct omap_hwmod *ohs[] = { oh };
3532
3533@@ -532,7 +532,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name,
3534 struct platform_device __init *omap_device_build_ss(const char *pdev_name,
3535 int pdev_id,
3536 struct omap_hwmod **ohs,
3537- int oh_cnt, void *pdata,
3538+ int oh_cnt, const void *pdata,
3539 int pdata_len)
3540 {
3541 int ret = -ENOMEM;
3542diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
3543index 17ca1ae..beba869 100644
3544--- a/arch/arm/mach-omap2/omap_device.h
3545+++ b/arch/arm/mach-omap2/omap_device.h
3546@@ -71,12 +71,12 @@ int omap_device_idle(struct platform_device *pdev);
3547 /* Core code interface */
3548
3549 struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
3550- struct omap_hwmod *oh, void *pdata,
3551+ struct omap_hwmod *oh, const void *pdata,
3552 int pdata_len);
3553
3554 struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
3555 struct omap_hwmod **oh, int oh_cnt,
3556- void *pdata, int pdata_len);
3557+ const void *pdata, int pdata_len);
3558
3559 struct omap_device *omap_device_alloc(struct platform_device *pdev,
3560 struct omap_hwmod **ohs, int oh_cnt);
3561diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3562index 7f4db12..0243012 100644
3563--- a/arch/arm/mach-omap2/omap_hwmod.c
3564+++ b/arch/arm/mach-omap2/omap_hwmod.c
3565@@ -194,10 +194,10 @@ struct omap_hwmod_soc_ops {
3566 int (*init_clkdm)(struct omap_hwmod *oh);
3567 void (*update_context_lost)(struct omap_hwmod *oh);
3568 int (*get_context_lost)(struct omap_hwmod *oh);
3569-};
3570+} __no_const;
3571
3572 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3573-static struct omap_hwmod_soc_ops soc_ops;
3574+static struct omap_hwmod_soc_ops soc_ops __read_only;
3575
3576 /* omap_hwmod_list contains all registered struct omap_hwmods */
3577 static LIST_HEAD(omap_hwmod_list);
3578diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
3579index d15c7bb..b2d1f0c 100644
3580--- a/arch/arm/mach-omap2/wd_timer.c
3581+++ b/arch/arm/mach-omap2/wd_timer.c
3582@@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
3583 struct omap_hwmod *oh;
3584 char *oh_name = "wd_timer2";
3585 char *dev_name = "omap_wdt";
3586- struct omap_wd_timer_platform_data pdata;
3587+ static struct omap_wd_timer_platform_data pdata = {
3588+ .read_reset_sources = prm_read_reset_sources
3589+ };
3590
3591 if (!cpu_class_is_omap2() || of_have_populated_dt())
3592 return 0;
3593@@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
3594 return -EINVAL;
3595 }
3596
3597- pdata.read_reset_sources = prm_read_reset_sources;
3598-
3599 pdev = omap_device_build(dev_name, id, oh, &pdata,
3600 sizeof(struct omap_wd_timer_platform_data));
3601 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
3602diff --git a/arch/arm/mach-tegra/cpuidle-tegra20.c b/arch/arm/mach-tegra/cpuidle-tegra20.c
3603index 706aa42..f85e9131 100644
3604--- a/arch/arm/mach-tegra/cpuidle-tegra20.c
3605+++ b/arch/arm/mach-tegra/cpuidle-tegra20.c
3606@@ -180,7 +180,7 @@ static int tegra20_idle_lp2_coupled(struct cpuidle_device *dev,
3607 bool entered_lp2 = false;
3608
3609 if (tegra_pending_sgi())
3610- ACCESS_ONCE(abort_flag) = true;
3611+ ACCESS_ONCE_RW(abort_flag) = true;
3612
3613 cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
3614
3615diff --git a/arch/arm/mach-ux500/setup.h b/arch/arm/mach-ux500/setup.h
3616index cad3ca86..1d79e0f 100644
3617--- a/arch/arm/mach-ux500/setup.h
3618+++ b/arch/arm/mach-ux500/setup.h
3619@@ -37,13 +37,6 @@ extern void ux500_timer_init(void);
3620 .type = MT_DEVICE, \
3621 }
3622
3623-#define __MEM_DEV_DESC(x, sz) { \
3624- .virtual = IO_ADDRESS(x), \
3625- .pfn = __phys_to_pfn(x), \
3626- .length = sz, \
3627- .type = MT_MEMORY, \
3628-}
3629-
3630 extern struct smp_operations ux500_smp_ops;
3631 extern void ux500_cpu_die(unsigned int cpu);
3632
3633diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3634index cd2c88e..7430282 100644
3635--- a/arch/arm/mm/Kconfig
3636+++ b/arch/arm/mm/Kconfig
3637@@ -446,7 +446,7 @@ config CPU_32v5
3638
3639 config CPU_32v6
3640 bool
3641- select CPU_USE_DOMAINS if CPU_V6 && MMU
3642+ select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3643 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3644
3645 config CPU_32v6K
3646@@ -601,6 +601,7 @@ config CPU_CP15_MPU
3647
3648 config CPU_USE_DOMAINS
3649 bool
3650+ depends on !ARM_LPAE && !PAX_KERNEXEC
3651 help
3652 This option enables or disables the use of domain switching
3653 via the set_fs() function.
3654@@ -800,6 +801,7 @@ config NEED_KUSER_HELPERS
3655 config KUSER_HELPERS
3656 bool "Enable kuser helpers in vector page" if !NEED_KUSER_HELPERS
3657 default y
3658+ depends on !(CPU_V6 || CPU_V6K || CPU_V7)
3659 help
3660 Warning: disabling this option may break user programs.
3661
3662@@ -812,7 +814,7 @@ config KUSER_HELPERS
3663 See Documentation/arm/kernel_user_helpers.txt for details.
3664
3665 However, the fixed address nature of these helpers can be used
3666- by ROP (return orientated programming) authors when creating
3667+ by ROP (Return Oriented Programming) authors when creating
3668 exploits.
3669
3670 If all of the binaries and libraries which run on your platform
3671diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
3672index 6f4585b..7b6f52b 100644
3673--- a/arch/arm/mm/alignment.c
3674+++ b/arch/arm/mm/alignment.c
3675@@ -211,10 +211,12 @@ union offset_union {
3676 #define __get16_unaligned_check(ins,val,addr) \
3677 do { \
3678 unsigned int err = 0, v, a = addr; \
3679+ pax_open_userland(); \
3680 __get8_unaligned_check(ins,v,a,err); \
3681 val = v << ((BE) ? 8 : 0); \
3682 __get8_unaligned_check(ins,v,a,err); \
3683 val |= v << ((BE) ? 0 : 8); \
3684+ pax_close_userland(); \
3685 if (err) \
3686 goto fault; \
3687 } while (0)
3688@@ -228,6 +230,7 @@ union offset_union {
3689 #define __get32_unaligned_check(ins,val,addr) \
3690 do { \
3691 unsigned int err = 0, v, a = addr; \
3692+ pax_open_userland(); \
3693 __get8_unaligned_check(ins,v,a,err); \
3694 val = v << ((BE) ? 24 : 0); \
3695 __get8_unaligned_check(ins,v,a,err); \
3696@@ -236,6 +239,7 @@ union offset_union {
3697 val |= v << ((BE) ? 8 : 16); \
3698 __get8_unaligned_check(ins,v,a,err); \
3699 val |= v << ((BE) ? 0 : 24); \
3700+ pax_close_userland(); \
3701 if (err) \
3702 goto fault; \
3703 } while (0)
3704@@ -249,6 +253,7 @@ union offset_union {
3705 #define __put16_unaligned_check(ins,val,addr) \
3706 do { \
3707 unsigned int err = 0, v = val, a = addr; \
3708+ pax_open_userland(); \
3709 __asm__( FIRST_BYTE_16 \
3710 ARM( "1: "ins" %1, [%2], #1\n" ) \
3711 THUMB( "1: "ins" %1, [%2]\n" ) \
3712@@ -268,6 +273,7 @@ union offset_union {
3713 " .popsection\n" \
3714 : "=r" (err), "=&r" (v), "=&r" (a) \
3715 : "0" (err), "1" (v), "2" (a)); \
3716+ pax_close_userland(); \
3717 if (err) \
3718 goto fault; \
3719 } while (0)
3720@@ -281,6 +287,7 @@ union offset_union {
3721 #define __put32_unaligned_check(ins,val,addr) \
3722 do { \
3723 unsigned int err = 0, v = val, a = addr; \
3724+ pax_open_userland(); \
3725 __asm__( FIRST_BYTE_32 \
3726 ARM( "1: "ins" %1, [%2], #1\n" ) \
3727 THUMB( "1: "ins" %1, [%2]\n" ) \
3728@@ -310,6 +317,7 @@ union offset_union {
3729 " .popsection\n" \
3730 : "=r" (err), "=&r" (v), "=&r" (a) \
3731 : "0" (err), "1" (v), "2" (a)); \
3732+ pax_close_userland(); \
3733 if (err) \
3734 goto fault; \
3735 } while (0)
3736diff --git a/arch/arm/mm/context.c b/arch/arm/mm/context.c
3737index 4a05444..d21968c 100644
3738--- a/arch/arm/mm/context.c
3739+++ b/arch/arm/mm/context.c
3740@@ -43,7 +43,7 @@
3741 #define NUM_USER_ASIDS ASID_FIRST_VERSION
3742
3743 static DEFINE_RAW_SPINLOCK(cpu_asid_lock);
3744-static atomic64_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3745+static atomic64_unchecked_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3746 static DECLARE_BITMAP(asid_map, NUM_USER_ASIDS);
3747
3748 static DEFINE_PER_CPU(atomic64_t, active_asids);
3749@@ -183,7 +183,7 @@ static int is_reserved_asid(u64 asid)
3750 static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3751 {
3752 u64 asid = atomic64_read(&mm->context.id);
3753- u64 generation = atomic64_read(&asid_generation);
3754+ u64 generation = atomic64_read_unchecked(&asid_generation);
3755
3756 if (asid != 0 && is_reserved_asid(asid)) {
3757 /*
3758@@ -201,7 +201,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3759 */
3760 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3761 if (asid == NUM_USER_ASIDS) {
3762- generation = atomic64_add_return(ASID_FIRST_VERSION,
3763+ generation = atomic64_add_return_unchecked(ASID_FIRST_VERSION,
3764 &asid_generation);
3765 flush_context(cpu);
3766 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3767@@ -230,14 +230,14 @@ void check_and_switch_context(struct mm_struct *mm, struct task_struct *tsk)
3768 cpu_set_reserved_ttbr0();
3769
3770 asid = atomic64_read(&mm->context.id);
3771- if (!((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS)
3772+ if (!((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS)
3773 && atomic64_xchg(&per_cpu(active_asids, cpu), asid))
3774 goto switch_mm_fastpath;
3775
3776 raw_spin_lock_irqsave(&cpu_asid_lock, flags);
3777 /* Check that our ASID belongs to the current generation. */
3778 asid = atomic64_read(&mm->context.id);
3779- if ((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS) {
3780+ if ((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS) {
3781 asid = new_context(mm, cpu);
3782 atomic64_set(&mm->context.id, asid);
3783 }
3784diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
3785index c97f794..6461880 100644
3786--- a/arch/arm/mm/fault.c
3787+++ b/arch/arm/mm/fault.c
3788@@ -25,6 +25,7 @@
3789 #include <asm/system_misc.h>
3790 #include <asm/system_info.h>
3791 #include <asm/tlbflush.h>
3792+#include <asm/sections.h>
3793
3794 #include "fault.h"
3795
3796@@ -138,6 +139,20 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
3797 if (fixup_exception(regs))
3798 return;
3799
3800+#ifdef CONFIG_PAX_KERNEXEC
3801+ if ((fsr & FSR_WRITE) &&
3802+ (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
3803+ (MODULES_VADDR <= addr && addr < MODULES_END)))
3804+ {
3805+ if (current->signal->curr_ip)
3806+ 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),
3807+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3808+ else
3809+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
3810+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3811+ }
3812+#endif
3813+
3814 /*
3815 * No handler, we'll have to terminate things with extreme prejudice.
3816 */
3817@@ -174,6 +189,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
3818 }
3819 #endif
3820
3821+#ifdef CONFIG_PAX_PAGEEXEC
3822+ if (fsr & FSR_LNX_PF) {
3823+ pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
3824+ do_group_exit(SIGKILL);
3825+ }
3826+#endif
3827+
3828 tsk->thread.address = addr;
3829 tsk->thread.error_code = fsr;
3830 tsk->thread.trap_no = 14;
3831@@ -398,6 +420,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3832 }
3833 #endif /* CONFIG_MMU */
3834
3835+#ifdef CONFIG_PAX_PAGEEXEC
3836+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3837+{
3838+ long i;
3839+
3840+ printk(KERN_ERR "PAX: bytes at PC: ");
3841+ for (i = 0; i < 20; i++) {
3842+ unsigned char c;
3843+ if (get_user(c, (__force unsigned char __user *)pc+i))
3844+ printk(KERN_CONT "?? ");
3845+ else
3846+ printk(KERN_CONT "%02x ", c);
3847+ }
3848+ printk("\n");
3849+
3850+ printk(KERN_ERR "PAX: bytes at SP-4: ");
3851+ for (i = -1; i < 20; i++) {
3852+ unsigned long c;
3853+ if (get_user(c, (__force unsigned long __user *)sp+i))
3854+ printk(KERN_CONT "???????? ");
3855+ else
3856+ printk(KERN_CONT "%08lx ", c);
3857+ }
3858+ printk("\n");
3859+}
3860+#endif
3861+
3862 /*
3863 * First Level Translation Fault Handler
3864 *
3865@@ -545,9 +594,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3866 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
3867 struct siginfo info;
3868
3869+#ifdef CONFIG_PAX_MEMORY_UDEREF
3870+ if (addr < TASK_SIZE && is_domain_fault(fsr)) {
3871+ if (current->signal->curr_ip)
3872+ 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),
3873+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3874+ else
3875+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3876+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3877+ goto die;
3878+ }
3879+#endif
3880+
3881 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
3882 return;
3883
3884+die:
3885 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
3886 inf->name, fsr, addr);
3887
3888@@ -571,15 +633,92 @@ hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int, struct pt_regs *
3889 ifsr_info[nr].name = name;
3890 }
3891
3892+asmlinkage int sys_sigreturn(struct pt_regs *regs);
3893+asmlinkage int sys_rt_sigreturn(struct pt_regs *regs);
3894+
3895 asmlinkage void __exception
3896 do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
3897 {
3898 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
3899 struct siginfo info;
3900+ unsigned long pc = instruction_pointer(regs);
3901+
3902+ if (user_mode(regs)) {
3903+ unsigned long sigpage = current->mm->context.sigpage;
3904+
3905+ if (sigpage <= pc && pc < sigpage + 7*4) {
3906+ if (pc < sigpage + 3*4)
3907+ sys_sigreturn(regs);
3908+ else
3909+ sys_rt_sigreturn(regs);
3910+ return;
3911+ }
3912+ if (pc == 0xffff0f60UL) {
3913+ /*
3914+ * PaX: __kuser_cmpxchg64 emulation
3915+ */
3916+ // TODO
3917+ //regs->ARM_pc = regs->ARM_lr;
3918+ //return;
3919+ }
3920+ if (pc == 0xffff0fa0UL) {
3921+ /*
3922+ * PaX: __kuser_memory_barrier emulation
3923+ */
3924+ // dmb(); implied by the exception
3925+ regs->ARM_pc = regs->ARM_lr;
3926+ return;
3927+ }
3928+ if (pc == 0xffff0fc0UL) {
3929+ /*
3930+ * PaX: __kuser_cmpxchg emulation
3931+ */
3932+ // TODO
3933+ //regs->ARM_pc = regs->ARM_lr;
3934+ //return;
3935+ }
3936+ if (pc == 0xffff0fe0UL) {
3937+ /*
3938+ * PaX: __kuser_get_tls emulation
3939+ */
3940+ regs->ARM_r0 = current_thread_info()->tp_value[0];
3941+ regs->ARM_pc = regs->ARM_lr;
3942+ return;
3943+ }
3944+ }
3945+
3946+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3947+ else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
3948+ if (current->signal->curr_ip)
3949+ 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),
3950+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
3951+ pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
3952+ else
3953+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
3954+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
3955+ pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
3956+ goto die;
3957+ }
3958+#endif
3959+
3960+#ifdef CONFIG_PAX_REFCOUNT
3961+ if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
3962+ unsigned int bkpt;
3963+
3964+ if (!probe_kernel_address(pc, bkpt) && cpu_to_le32(bkpt) == 0xe12f1073) {
3965+ current->thread.error_code = ifsr;
3966+ current->thread.trap_no = 0;
3967+ pax_report_refcount_overflow(regs);
3968+ fixup_exception(regs);
3969+ return;
3970+ }
3971+ }
3972+#endif
3973
3974 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
3975 return;
3976
3977+die:
3978 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
3979 inf->name, ifsr, addr);
3980
3981diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
3982index cf08bdf..772656c 100644
3983--- a/arch/arm/mm/fault.h
3984+++ b/arch/arm/mm/fault.h
3985@@ -3,6 +3,7 @@
3986
3987 /*
3988 * Fault status register encodings. We steal bit 31 for our own purposes.
3989+ * Set when the FSR value is from an instruction fault.
3990 */
3991 #define FSR_LNX_PF (1 << 31)
3992 #define FSR_WRITE (1 << 11)
3993@@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
3994 }
3995 #endif
3996
3997+/* valid for LPAE and !LPAE */
3998+static inline int is_xn_fault(unsigned int fsr)
3999+{
4000+ return ((fsr_fs(fsr) & 0x3c) == 0xc);
4001+}
4002+
4003+static inline int is_domain_fault(unsigned int fsr)
4004+{
4005+ return ((fsr_fs(fsr) & 0xD) == 0x9);
4006+}
4007+
4008 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
4009 unsigned long search_exception_table(unsigned long addr);
4010
4011diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
4012index 15225d8..25e2e3c 100644
4013--- a/arch/arm/mm/init.c
4014+++ b/arch/arm/mm/init.c
4015@@ -30,6 +30,8 @@
4016 #include <asm/setup.h>
4017 #include <asm/tlb.h>
4018 #include <asm/fixmap.h>
4019+#include <asm/system_info.h>
4020+#include <asm/cp15.h>
4021
4022 #include <asm/mach/arch.h>
4023 #include <asm/mach/map.h>
4024@@ -683,7 +685,46 @@ void free_initmem(void)
4025 {
4026 #ifdef CONFIG_HAVE_TCM
4027 extern char __tcm_start, __tcm_end;
4028+#endif
4029
4030+#ifdef CONFIG_PAX_KERNEXEC
4031+ unsigned long addr;
4032+ pgd_t *pgd;
4033+ pud_t *pud;
4034+ pmd_t *pmd;
4035+ int cpu_arch = cpu_architecture();
4036+ unsigned int cr = get_cr();
4037+
4038+ if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
4039+ /* make pages tables, etc before .text NX */
4040+ for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
4041+ pgd = pgd_offset_k(addr);
4042+ pud = pud_offset(pgd, addr);
4043+ pmd = pmd_offset(pud, addr);
4044+ __section_update(pmd, addr, PMD_SECT_XN);
4045+ }
4046+ /* make init NX */
4047+ for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
4048+ pgd = pgd_offset_k(addr);
4049+ pud = pud_offset(pgd, addr);
4050+ pmd = pmd_offset(pud, addr);
4051+ __section_update(pmd, addr, PMD_SECT_XN);
4052+ }
4053+ /* make kernel code/rodata RX */
4054+ for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
4055+ pgd = pgd_offset_k(addr);
4056+ pud = pud_offset(pgd, addr);
4057+ pmd = pmd_offset(pud, addr);
4058+#ifdef CONFIG_ARM_LPAE
4059+ __section_update(pmd, addr, PMD_SECT_RDONLY);
4060+#else
4061+ __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
4062+#endif
4063+ }
4064+ }
4065+#endif
4066+
4067+#ifdef CONFIG_HAVE_TCM
4068 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
4069 free_reserved_area(&__tcm_start, &__tcm_end, -1, "TCM link");
4070 #endif
4071diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
4072index f123d6e..04bf569 100644
4073--- a/arch/arm/mm/ioremap.c
4074+++ b/arch/arm/mm/ioremap.c
4075@@ -392,9 +392,9 @@ __arm_ioremap_exec(phys_addr_t phys_addr, size_t size, bool cached)
4076 unsigned int mtype;
4077
4078 if (cached)
4079- mtype = MT_MEMORY;
4080+ mtype = MT_MEMORY_RX;
4081 else
4082- mtype = MT_MEMORY_NONCACHED;
4083+ mtype = MT_MEMORY_NONCACHED_RX;
4084
4085 return __arm_ioremap_caller(phys_addr, size, mtype,
4086 __builtin_return_address(0));
4087diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
4088index 0c63562..7128a90 100644
4089--- a/arch/arm/mm/mmap.c
4090+++ b/arch/arm/mm/mmap.c
4091@@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4092 struct vm_area_struct *vma;
4093 int do_align = 0;
4094 int aliasing = cache_is_vipt_aliasing();
4095+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4096 struct vm_unmapped_area_info info;
4097
4098 /*
4099@@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4100 if (len > TASK_SIZE)
4101 return -ENOMEM;
4102
4103+#ifdef CONFIG_PAX_RANDMMAP
4104+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4105+#endif
4106+
4107 if (addr) {
4108 if (do_align)
4109 addr = COLOUR_ALIGN(addr, pgoff);
4110@@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4111 addr = PAGE_ALIGN(addr);
4112
4113 vma = find_vma(mm, addr);
4114- if (TASK_SIZE - len >= addr &&
4115- (!vma || addr + len <= vma->vm_start))
4116+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4117 return addr;
4118 }
4119
4120@@ -99,6 +103,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4121 info.high_limit = TASK_SIZE;
4122 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4123 info.align_offset = pgoff << PAGE_SHIFT;
4124+ info.threadstack_offset = offset;
4125 return vm_unmapped_area(&info);
4126 }
4127
4128@@ -112,6 +117,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4129 unsigned long addr = addr0;
4130 int do_align = 0;
4131 int aliasing = cache_is_vipt_aliasing();
4132+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4133 struct vm_unmapped_area_info info;
4134
4135 /*
4136@@ -132,6 +138,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4137 return addr;
4138 }
4139
4140+#ifdef CONFIG_PAX_RANDMMAP
4141+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4142+#endif
4143+
4144 /* requesting a specific address */
4145 if (addr) {
4146 if (do_align)
4147@@ -139,8 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4148 else
4149 addr = PAGE_ALIGN(addr);
4150 vma = find_vma(mm, addr);
4151- if (TASK_SIZE - len >= addr &&
4152- (!vma || addr + len <= vma->vm_start))
4153+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4154 return addr;
4155 }
4156
4157@@ -150,6 +159,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4158 info.high_limit = mm->mmap_base;
4159 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4160 info.align_offset = pgoff << PAGE_SHIFT;
4161+ info.threadstack_offset = offset;
4162 addr = vm_unmapped_area(&info);
4163
4164 /*
4165@@ -173,6 +183,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4166 {
4167 unsigned long random_factor = 0UL;
4168
4169+#ifdef CONFIG_PAX_RANDMMAP
4170+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4171+#endif
4172+
4173 /* 8 bits of randomness in 20 address space bits */
4174 if ((current->flags & PF_RANDOMIZE) &&
4175 !(current->personality & ADDR_NO_RANDOMIZE))
4176@@ -180,9 +194,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4177
4178 if (mmap_is_legacy()) {
4179 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4180+
4181+#ifdef CONFIG_PAX_RANDMMAP
4182+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4183+ mm->mmap_base += mm->delta_mmap;
4184+#endif
4185+
4186 mm->get_unmapped_area = arch_get_unmapped_area;
4187 } else {
4188 mm->mmap_base = mmap_base(random_factor);
4189+
4190+#ifdef CONFIG_PAX_RANDMMAP
4191+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4192+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4193+#endif
4194+
4195 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4196 }
4197 }
4198diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
4199index 53cdbd3..670f177 100644
4200--- a/arch/arm/mm/mmu.c
4201+++ b/arch/arm/mm/mmu.c
4202@@ -36,6 +36,22 @@
4203 #include "mm.h"
4204 #include "tcm.h"
4205
4206+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4207+void modify_domain(unsigned int dom, unsigned int type)
4208+{
4209+ struct thread_info *thread = current_thread_info();
4210+ unsigned int domain = thread->cpu_domain;
4211+ /*
4212+ * DOMAIN_MANAGER might be defined to some other value,
4213+ * use the arch-defined constant
4214+ */
4215+ domain &= ~domain_val(dom, 3);
4216+ thread->cpu_domain = domain | domain_val(dom, type);
4217+ set_domain(thread->cpu_domain);
4218+}
4219+EXPORT_SYMBOL(modify_domain);
4220+#endif
4221+
4222 /*
4223 * empty_zero_page is a special page that is used for
4224 * zero-initialized data and COW.
4225@@ -228,10 +244,18 @@ __setup("noalign", noalign_setup);
4226
4227 #endif /* ifdef CONFIG_CPU_CP15 / else */
4228
4229-#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY|L_PTE_XN
4230+#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY
4231 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
4232
4233-static struct mem_type mem_types[] = {
4234+#ifdef CONFIG_PAX_KERNEXEC
4235+#define L_PTE_KERNEXEC L_PTE_RDONLY
4236+#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
4237+#else
4238+#define L_PTE_KERNEXEC L_PTE_DIRTY
4239+#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
4240+#endif
4241+
4242+static struct mem_type mem_types[] __read_only = {
4243 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
4244 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
4245 L_PTE_SHARED,
4246@@ -260,16 +284,16 @@ static struct mem_type mem_types[] = {
4247 [MT_UNCACHED] = {
4248 .prot_pte = PROT_PTE_DEVICE,
4249 .prot_l1 = PMD_TYPE_TABLE,
4250- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4251+ .prot_sect = PROT_SECT_DEVICE,
4252 .domain = DOMAIN_IO,
4253 },
4254 [MT_CACHECLEAN] = {
4255- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4256+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4257 .domain = DOMAIN_KERNEL,
4258 },
4259 #ifndef CONFIG_ARM_LPAE
4260 [MT_MINICLEAN] = {
4261- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
4262+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_RDONLY,
4263 .domain = DOMAIN_KERNEL,
4264 },
4265 #endif
4266@@ -277,36 +301,54 @@ static struct mem_type mem_types[] = {
4267 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4268 L_PTE_RDONLY,
4269 .prot_l1 = PMD_TYPE_TABLE,
4270- .domain = DOMAIN_USER,
4271+ .domain = DOMAIN_VECTORS,
4272 },
4273 [MT_HIGH_VECTORS] = {
4274 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4275 L_PTE_USER | L_PTE_RDONLY,
4276 .prot_l1 = PMD_TYPE_TABLE,
4277- .domain = DOMAIN_USER,
4278+ .domain = DOMAIN_VECTORS,
4279 },
4280- [MT_MEMORY] = {
4281+ [MT_MEMORY_RWX] = {
4282 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4283 .prot_l1 = PMD_TYPE_TABLE,
4284 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4285 .domain = DOMAIN_KERNEL,
4286 },
4287+ [MT_MEMORY_RW] = {
4288+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4289+ .prot_l1 = PMD_TYPE_TABLE,
4290+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4291+ .domain = DOMAIN_KERNEL,
4292+ },
4293+ [MT_MEMORY_RX] = {
4294+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4295+ .prot_l1 = PMD_TYPE_TABLE,
4296+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4297+ .domain = DOMAIN_KERNEL,
4298+ },
4299 [MT_ROM] = {
4300- .prot_sect = PMD_TYPE_SECT,
4301+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4302 .domain = DOMAIN_KERNEL,
4303 },
4304- [MT_MEMORY_NONCACHED] = {
4305+ [MT_MEMORY_NONCACHED_RW] = {
4306 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4307 L_PTE_MT_BUFFERABLE,
4308 .prot_l1 = PMD_TYPE_TABLE,
4309 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4310 .domain = DOMAIN_KERNEL,
4311 },
4312+ [MT_MEMORY_NONCACHED_RX] = {
4313+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
4314+ L_PTE_MT_BUFFERABLE,
4315+ .prot_l1 = PMD_TYPE_TABLE,
4316+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4317+ .domain = DOMAIN_KERNEL,
4318+ },
4319 [MT_MEMORY_DTCM] = {
4320- .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4321- L_PTE_XN,
4322+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4323 .prot_l1 = PMD_TYPE_TABLE,
4324- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4325+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4326 .domain = DOMAIN_KERNEL,
4327 },
4328 [MT_MEMORY_ITCM] = {
4329@@ -316,10 +358,10 @@ static struct mem_type mem_types[] = {
4330 },
4331 [MT_MEMORY_SO] = {
4332 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4333- L_PTE_MT_UNCACHED | L_PTE_XN,
4334+ L_PTE_MT_UNCACHED,
4335 .prot_l1 = PMD_TYPE_TABLE,
4336 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_SECT_S |
4337- PMD_SECT_UNCACHED | PMD_SECT_XN,
4338+ PMD_SECT_UNCACHED,
4339 .domain = DOMAIN_KERNEL,
4340 },
4341 [MT_MEMORY_DMA_READY] = {
4342@@ -405,9 +447,35 @@ static void __init build_mem_type_table(void)
4343 * to prevent speculative instruction fetches.
4344 */
4345 mem_types[MT_DEVICE].prot_sect |= PMD_SECT_XN;
4346+ mem_types[MT_DEVICE].prot_pte |= L_PTE_XN;
4347 mem_types[MT_DEVICE_NONSHARED].prot_sect |= PMD_SECT_XN;
4348+ mem_types[MT_DEVICE_NONSHARED].prot_pte |= L_PTE_XN;
4349 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_XN;
4350+ mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_XN;
4351 mem_types[MT_DEVICE_WC].prot_sect |= PMD_SECT_XN;
4352+ mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_XN;
4353+
4354+ /* Mark other regions on ARMv6+ as execute-never */
4355+
4356+#ifdef CONFIG_PAX_KERNEXEC
4357+ mem_types[MT_UNCACHED].prot_sect |= PMD_SECT_XN;
4358+ mem_types[MT_UNCACHED].prot_pte |= L_PTE_XN;
4359+ mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_XN;
4360+ mem_types[MT_CACHECLEAN].prot_pte |= L_PTE_XN;
4361+#ifndef CONFIG_ARM_LPAE
4362+ mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_XN;
4363+ mem_types[MT_MINICLEAN].prot_pte |= L_PTE_XN;
4364+#endif
4365+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_XN;
4366+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_XN;
4367+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_XN;
4368+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= PMD_SECT_XN;
4369+ mem_types[MT_MEMORY_DTCM].prot_sect |= PMD_SECT_XN;
4370+ mem_types[MT_MEMORY_DTCM].prot_pte |= L_PTE_XN;
4371+#endif
4372+
4373+ mem_types[MT_MEMORY_SO].prot_sect |= PMD_SECT_XN;
4374+ mem_types[MT_MEMORY_SO].prot_pte |= L_PTE_XN;
4375 }
4376 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4377 /*
4378@@ -468,6 +536,9 @@ static void __init build_mem_type_table(void)
4379 * from SVC mode and no access from userspace.
4380 */
4381 mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4382+#ifdef CONFIG_PAX_KERNEXEC
4383+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4384+#endif
4385 mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4386 mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4387 #endif
4388@@ -485,11 +556,17 @@ static void __init build_mem_type_table(void)
4389 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
4390 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
4391 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
4392- mem_types[MT_MEMORY].prot_sect |= PMD_SECT_S;
4393- mem_types[MT_MEMORY].prot_pte |= L_PTE_SHARED;
4394+ mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4395+ mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4396+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
4397+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
4398+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
4399+ mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
4400 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
4401- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_S;
4402- mem_types[MT_MEMORY_NONCACHED].prot_pte |= L_PTE_SHARED;
4403+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_S;
4404+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= L_PTE_SHARED;
4405+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_S;
4406+ mem_types[MT_MEMORY_NONCACHED_RX].prot_pte |= L_PTE_SHARED;
4407 }
4408 }
4409
4410@@ -500,15 +577,20 @@ static void __init build_mem_type_table(void)
4411 if (cpu_arch >= CPU_ARCH_ARMv6) {
4412 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4413 /* Non-cacheable Normal is XCB = 001 */
4414- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4415+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4416+ PMD_SECT_BUFFERED;
4417+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4418 PMD_SECT_BUFFERED;
4419 } else {
4420 /* For both ARMv6 and non-TEX-remapping ARMv7 */
4421- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4422+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4423+ PMD_SECT_TEX(1);
4424+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4425 PMD_SECT_TEX(1);
4426 }
4427 } else {
4428- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4429+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_BUFFERABLE;
4430+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_BUFFERABLE;
4431 }
4432
4433 #ifdef CONFIG_ARM_LPAE
4434@@ -524,6 +606,8 @@ static void __init build_mem_type_table(void)
4435 vecs_pgprot |= PTE_EXT_AF;
4436 #endif
4437
4438+ user_pgprot |= __supported_pte_mask;
4439+
4440 for (i = 0; i < 16; i++) {
4441 pteval_t v = pgprot_val(protection_map[i]);
4442 protection_map[i] = __pgprot(v | user_pgprot);
4443@@ -541,10 +625,15 @@ static void __init build_mem_type_table(void)
4444
4445 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
4446 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
4447- mem_types[MT_MEMORY].prot_sect |= ecc_mask | cp->pmd;
4448- mem_types[MT_MEMORY].prot_pte |= kern_pgprot;
4449+ mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4450+ mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4451+ mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
4452+ mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
4453+ mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
4454+ mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
4455 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
4456- mem_types[MT_MEMORY_NONCACHED].prot_sect |= ecc_mask;
4457+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= ecc_mask;
4458+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= ecc_mask;
4459 mem_types[MT_ROM].prot_sect |= cp->pmd;
4460
4461 switch (cp->pmd) {
4462@@ -1186,18 +1275,15 @@ void __init arm_mm_memblock_reserve(void)
4463 * called function. This means you can't use any function or debugging
4464 * method which may touch any device, otherwise the kernel _will_ crash.
4465 */
4466+
4467+static char vectors[PAGE_SIZE * 2] __read_only __aligned(PAGE_SIZE);
4468+
4469 static void __init devicemaps_init(struct machine_desc *mdesc)
4470 {
4471 struct map_desc map;
4472 unsigned long addr;
4473- void *vectors;
4474
4475- /*
4476- * Allocate the vector page early.
4477- */
4478- vectors = early_alloc(PAGE_SIZE * 2);
4479-
4480- early_trap_init(vectors);
4481+ early_trap_init(&vectors);
4482
4483 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
4484 pmd_clear(pmd_off_k(addr));
4485@@ -1237,7 +1323,7 @@ static void __init devicemaps_init(struct machine_desc *mdesc)
4486 * location (0xffff0000). If we aren't using high-vectors, also
4487 * create a mapping at the low-vectors virtual address.
4488 */
4489- map.pfn = __phys_to_pfn(virt_to_phys(vectors));
4490+ map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
4491 map.virtual = 0xffff0000;
4492 map.length = PAGE_SIZE;
4493 #ifdef CONFIG_KUSER_HELPERS
4494@@ -1309,8 +1395,39 @@ static void __init map_lowmem(void)
4495 map.pfn = __phys_to_pfn(start);
4496 map.virtual = __phys_to_virt(start);
4497 map.length = end - start;
4498- map.type = MT_MEMORY;
4499
4500+#ifdef CONFIG_PAX_KERNEXEC
4501+ if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
4502+ struct map_desc kernel;
4503+ struct map_desc initmap;
4504+
4505+ /* when freeing initmem we will make this RW */
4506+ initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4507+ initmap.virtual = (unsigned long)__init_begin;
4508+ initmap.length = _sdata - __init_begin;
4509+ initmap.type = MT_MEMORY_RWX;
4510+ create_mapping(&initmap);
4511+
4512+ /* when freeing initmem we will make this RX */
4513+ kernel.pfn = __phys_to_pfn(__pa(_stext));
4514+ kernel.virtual = (unsigned long)_stext;
4515+ kernel.length = __init_begin - _stext;
4516+ kernel.type = MT_MEMORY_RWX;
4517+ create_mapping(&kernel);
4518+
4519+ if (map.virtual < (unsigned long)_stext) {
4520+ map.length = (unsigned long)_stext - map.virtual;
4521+ map.type = MT_MEMORY_RWX;
4522+ create_mapping(&map);
4523+ }
4524+
4525+ map.pfn = __phys_to_pfn(__pa(_sdata));
4526+ map.virtual = (unsigned long)_sdata;
4527+ map.length = end - __pa(_sdata);
4528+ }
4529+#endif
4530+
4531+ map.type = MT_MEMORY_RW;
4532 create_mapping(&map);
4533 }
4534 }
4535diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4536index a5bc92d..0bb4730 100644
4537--- a/arch/arm/plat-omap/sram.c
4538+++ b/arch/arm/plat-omap/sram.c
4539@@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4540 * Looks like we need to preserve some bootloader code at the
4541 * beginning of SRAM for jumping to flash for reboot to work...
4542 */
4543+ pax_open_kernel();
4544 memset_io(omap_sram_base + omap_sram_skip, 0,
4545 omap_sram_size - omap_sram_skip);
4546+ pax_close_kernel();
4547 }
4548diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4549index ce6d763..cfea917 100644
4550--- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4551+++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4552@@ -47,7 +47,7 @@ struct samsung_dma_ops {
4553 int (*started)(unsigned ch);
4554 int (*flush)(unsigned ch);
4555 int (*stop)(unsigned ch);
4556-};
4557+} __no_const;
4558
4559 extern void *samsung_dmadev_get_ops(void);
4560 extern void *s3c_dma_get_ops(void);
4561diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4562index c3a58a1..78fbf54 100644
4563--- a/arch/avr32/include/asm/cache.h
4564+++ b/arch/avr32/include/asm/cache.h
4565@@ -1,8 +1,10 @@
4566 #ifndef __ASM_AVR32_CACHE_H
4567 #define __ASM_AVR32_CACHE_H
4568
4569+#include <linux/const.h>
4570+
4571 #define L1_CACHE_SHIFT 5
4572-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4573+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4574
4575 /*
4576 * Memory returned by kmalloc() may be used for DMA, so we must make
4577diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4578index d232888..87c8df1 100644
4579--- a/arch/avr32/include/asm/elf.h
4580+++ b/arch/avr32/include/asm/elf.h
4581@@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4582 the loader. We need to make sure that it is out of the way of the program
4583 that it will "exec", and that there is sufficient room for the brk. */
4584
4585-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4586+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4587
4588+#ifdef CONFIG_PAX_ASLR
4589+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4590+
4591+#define PAX_DELTA_MMAP_LEN 15
4592+#define PAX_DELTA_STACK_LEN 15
4593+#endif
4594
4595 /* This yields a mask that user programs can use to figure out what
4596 instruction set this CPU supports. This could be done in user space,
4597diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4598index 479330b..53717a8 100644
4599--- a/arch/avr32/include/asm/kmap_types.h
4600+++ b/arch/avr32/include/asm/kmap_types.h
4601@@ -2,9 +2,9 @@
4602 #define __ASM_AVR32_KMAP_TYPES_H
4603
4604 #ifdef CONFIG_DEBUG_HIGHMEM
4605-# define KM_TYPE_NR 29
4606+# define KM_TYPE_NR 30
4607 #else
4608-# define KM_TYPE_NR 14
4609+# define KM_TYPE_NR 15
4610 #endif
4611
4612 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4613diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4614index b2f2d2d..d1c85cb 100644
4615--- a/arch/avr32/mm/fault.c
4616+++ b/arch/avr32/mm/fault.c
4617@@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4618
4619 int exception_trace = 1;
4620
4621+#ifdef CONFIG_PAX_PAGEEXEC
4622+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4623+{
4624+ unsigned long i;
4625+
4626+ printk(KERN_ERR "PAX: bytes at PC: ");
4627+ for (i = 0; i < 20; i++) {
4628+ unsigned char c;
4629+ if (get_user(c, (unsigned char *)pc+i))
4630+ printk(KERN_CONT "???????? ");
4631+ else
4632+ printk(KERN_CONT "%02x ", c);
4633+ }
4634+ printk("\n");
4635+}
4636+#endif
4637+
4638 /*
4639 * This routine handles page faults. It determines the address and the
4640 * problem, and then passes it off to one of the appropriate routines.
4641@@ -174,6 +191,16 @@ bad_area:
4642 up_read(&mm->mmap_sem);
4643
4644 if (user_mode(regs)) {
4645+
4646+#ifdef CONFIG_PAX_PAGEEXEC
4647+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4648+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
4649+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
4650+ do_group_exit(SIGKILL);
4651+ }
4652+ }
4653+#endif
4654+
4655 if (exception_trace && printk_ratelimit())
4656 printk("%s%s[%d]: segfault at %08lx pc %08lx "
4657 "sp %08lx ecr %lu\n",
4658diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
4659index 568885a..f8008df 100644
4660--- a/arch/blackfin/include/asm/cache.h
4661+++ b/arch/blackfin/include/asm/cache.h
4662@@ -7,6 +7,7 @@
4663 #ifndef __ARCH_BLACKFIN_CACHE_H
4664 #define __ARCH_BLACKFIN_CACHE_H
4665
4666+#include <linux/const.h>
4667 #include <linux/linkage.h> /* for asmlinkage */
4668
4669 /*
4670@@ -14,7 +15,7 @@
4671 * Blackfin loads 32 bytes for cache
4672 */
4673 #define L1_CACHE_SHIFT 5
4674-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4675+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4676 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4677
4678 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4679diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
4680index aea2718..3639a60 100644
4681--- a/arch/cris/include/arch-v10/arch/cache.h
4682+++ b/arch/cris/include/arch-v10/arch/cache.h
4683@@ -1,8 +1,9 @@
4684 #ifndef _ASM_ARCH_CACHE_H
4685 #define _ASM_ARCH_CACHE_H
4686
4687+#include <linux/const.h>
4688 /* Etrax 100LX have 32-byte cache-lines. */
4689-#define L1_CACHE_BYTES 32
4690 #define L1_CACHE_SHIFT 5
4691+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4692
4693 #endif /* _ASM_ARCH_CACHE_H */
4694diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
4695index 7caf25d..ee65ac5 100644
4696--- a/arch/cris/include/arch-v32/arch/cache.h
4697+++ b/arch/cris/include/arch-v32/arch/cache.h
4698@@ -1,11 +1,12 @@
4699 #ifndef _ASM_CRIS_ARCH_CACHE_H
4700 #define _ASM_CRIS_ARCH_CACHE_H
4701
4702+#include <linux/const.h>
4703 #include <arch/hwregs/dma.h>
4704
4705 /* A cache-line is 32 bytes. */
4706-#define L1_CACHE_BYTES 32
4707 #define L1_CACHE_SHIFT 5
4708+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4709
4710 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4711
4712diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
4713index b86329d..6709906 100644
4714--- a/arch/frv/include/asm/atomic.h
4715+++ b/arch/frv/include/asm/atomic.h
4716@@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
4717 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
4718 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
4719
4720+#define atomic64_read_unchecked(v) atomic64_read(v)
4721+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4722+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4723+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4724+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4725+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4726+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4727+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4728+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4729+
4730 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
4731 {
4732 int c, old;
4733diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
4734index 2797163..c2a401d 100644
4735--- a/arch/frv/include/asm/cache.h
4736+++ b/arch/frv/include/asm/cache.h
4737@@ -12,10 +12,11 @@
4738 #ifndef __ASM_CACHE_H
4739 #define __ASM_CACHE_H
4740
4741+#include <linux/const.h>
4742
4743 /* bytes per L1 cache line */
4744 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
4745-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4746+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4747
4748 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4749 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4750diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
4751index 43901f2..0d8b865 100644
4752--- a/arch/frv/include/asm/kmap_types.h
4753+++ b/arch/frv/include/asm/kmap_types.h
4754@@ -2,6 +2,6 @@
4755 #ifndef _ASM_KMAP_TYPES_H
4756 #define _ASM_KMAP_TYPES_H
4757
4758-#define KM_TYPE_NR 17
4759+#define KM_TYPE_NR 18
4760
4761 #endif
4762diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
4763index 836f147..4cf23f5 100644
4764--- a/arch/frv/mm/elf-fdpic.c
4765+++ b/arch/frv/mm/elf-fdpic.c
4766@@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4767 {
4768 struct vm_area_struct *vma;
4769 struct vm_unmapped_area_info info;
4770+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4771
4772 if (len > TASK_SIZE)
4773 return -ENOMEM;
4774@@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4775 if (addr) {
4776 addr = PAGE_ALIGN(addr);
4777 vma = find_vma(current->mm, addr);
4778- if (TASK_SIZE - len >= addr &&
4779- (!vma || addr + len <= vma->vm_start))
4780+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4781 goto success;
4782 }
4783
4784@@ -85,6 +85,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4785 info.high_limit = (current->mm->start_stack - 0x00200000);
4786 info.align_mask = 0;
4787 info.align_offset = 0;
4788+ info.threadstack_offset = offset;
4789 addr = vm_unmapped_area(&info);
4790 if (!(addr & ~PAGE_MASK))
4791 goto success;
4792diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
4793index f4ca594..adc72fd6 100644
4794--- a/arch/hexagon/include/asm/cache.h
4795+++ b/arch/hexagon/include/asm/cache.h
4796@@ -21,9 +21,11 @@
4797 #ifndef __ASM_CACHE_H
4798 #define __ASM_CACHE_H
4799
4800+#include <linux/const.h>
4801+
4802 /* Bytes per L1 cache line */
4803-#define L1_CACHE_SHIFT (5)
4804-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4805+#define L1_CACHE_SHIFT 5
4806+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4807
4808 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
4809 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
4810diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
4811index 6e6fe18..a6ae668 100644
4812--- a/arch/ia64/include/asm/atomic.h
4813+++ b/arch/ia64/include/asm/atomic.h
4814@@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
4815 #define atomic64_inc(v) atomic64_add(1, (v))
4816 #define atomic64_dec(v) atomic64_sub(1, (v))
4817
4818+#define atomic64_read_unchecked(v) atomic64_read(v)
4819+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4820+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4821+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4822+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4823+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4824+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4825+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4826+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4827+
4828 /* Atomic operations are already serializing */
4829 #define smp_mb__before_atomic_dec() barrier()
4830 #define smp_mb__after_atomic_dec() barrier()
4831diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
4832index 988254a..e1ee885 100644
4833--- a/arch/ia64/include/asm/cache.h
4834+++ b/arch/ia64/include/asm/cache.h
4835@@ -1,6 +1,7 @@
4836 #ifndef _ASM_IA64_CACHE_H
4837 #define _ASM_IA64_CACHE_H
4838
4839+#include <linux/const.h>
4840
4841 /*
4842 * Copyright (C) 1998-2000 Hewlett-Packard Co
4843@@ -9,7 +10,7 @@
4844
4845 /* Bytes per L1 (data) cache line. */
4846 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
4847-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4848+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4849
4850 #ifdef CONFIG_SMP
4851 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
4852diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
4853index 5a83c5c..4d7f553 100644
4854--- a/arch/ia64/include/asm/elf.h
4855+++ b/arch/ia64/include/asm/elf.h
4856@@ -42,6 +42,13 @@
4857 */
4858 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
4859
4860+#ifdef CONFIG_PAX_ASLR
4861+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
4862+
4863+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4864+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4865+#endif
4866+
4867 #define PT_IA_64_UNWIND 0x70000001
4868
4869 /* IA-64 relocations: */
4870diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
4871index 96a8d92..617a1cf 100644
4872--- a/arch/ia64/include/asm/pgalloc.h
4873+++ b/arch/ia64/include/asm/pgalloc.h
4874@@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4875 pgd_val(*pgd_entry) = __pa(pud);
4876 }
4877
4878+static inline void
4879+pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4880+{
4881+ pgd_populate(mm, pgd_entry, pud);
4882+}
4883+
4884 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
4885 {
4886 return quicklist_alloc(0, GFP_KERNEL, NULL);
4887@@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4888 pud_val(*pud_entry) = __pa(pmd);
4889 }
4890
4891+static inline void
4892+pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4893+{
4894+ pud_populate(mm, pud_entry, pmd);
4895+}
4896+
4897 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
4898 {
4899 return quicklist_alloc(0, GFP_KERNEL, NULL);
4900diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
4901index 7935115..c0eca6a 100644
4902--- a/arch/ia64/include/asm/pgtable.h
4903+++ b/arch/ia64/include/asm/pgtable.h
4904@@ -12,7 +12,7 @@
4905 * David Mosberger-Tang <davidm@hpl.hp.com>
4906 */
4907
4908-
4909+#include <linux/const.h>
4910 #include <asm/mman.h>
4911 #include <asm/page.h>
4912 #include <asm/processor.h>
4913@@ -142,6 +142,17 @@
4914 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4915 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4916 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
4917+
4918+#ifdef CONFIG_PAX_PAGEEXEC
4919+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
4920+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4921+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4922+#else
4923+# define PAGE_SHARED_NOEXEC PAGE_SHARED
4924+# define PAGE_READONLY_NOEXEC PAGE_READONLY
4925+# define PAGE_COPY_NOEXEC PAGE_COPY
4926+#endif
4927+
4928 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
4929 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
4930 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
4931diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
4932index 54ff557..70c88b7 100644
4933--- a/arch/ia64/include/asm/spinlock.h
4934+++ b/arch/ia64/include/asm/spinlock.h
4935@@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
4936 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
4937
4938 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
4939- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
4940+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
4941 }
4942
4943 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
4944diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
4945index 449c8c0..18965fb 100644
4946--- a/arch/ia64/include/asm/uaccess.h
4947+++ b/arch/ia64/include/asm/uaccess.h
4948@@ -240,12 +240,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
4949 static inline unsigned long
4950 __copy_to_user (void __user *to, const void *from, unsigned long count)
4951 {
4952+ if (count > INT_MAX)
4953+ return count;
4954+
4955+ if (!__builtin_constant_p(count))
4956+ check_object_size(from, count, true);
4957+
4958 return __copy_user(to, (__force void __user *) from, count);
4959 }
4960
4961 static inline unsigned long
4962 __copy_from_user (void *to, const void __user *from, unsigned long count)
4963 {
4964+ if (count > INT_MAX)
4965+ return count;
4966+
4967+ if (!__builtin_constant_p(count))
4968+ check_object_size(to, count, false);
4969+
4970 return __copy_user((__force void __user *) to, from, count);
4971 }
4972
4973@@ -255,10 +267,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
4974 ({ \
4975 void __user *__cu_to = (to); \
4976 const void *__cu_from = (from); \
4977- long __cu_len = (n); \
4978+ unsigned long __cu_len = (n); \
4979 \
4980- if (__access_ok(__cu_to, __cu_len, get_fs())) \
4981+ if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
4982+ if (!__builtin_constant_p(n)) \
4983+ check_object_size(__cu_from, __cu_len, true); \
4984 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
4985+ } \
4986 __cu_len; \
4987 })
4988
4989@@ -266,11 +281,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
4990 ({ \
4991 void *__cu_to = (to); \
4992 const void __user *__cu_from = (from); \
4993- long __cu_len = (n); \
4994+ unsigned long __cu_len = (n); \
4995 \
4996 __chk_user_ptr(__cu_from); \
4997- if (__access_ok(__cu_from, __cu_len, get_fs())) \
4998+ if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
4999+ if (!__builtin_constant_p(n)) \
5000+ check_object_size(__cu_to, __cu_len, false); \
5001 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
5002+ } \
5003 __cu_len; \
5004 })
5005
5006diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
5007index 24603be..948052d 100644
5008--- a/arch/ia64/kernel/module.c
5009+++ b/arch/ia64/kernel/module.c
5010@@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
5011 void
5012 module_free (struct module *mod, void *module_region)
5013 {
5014- if (mod && mod->arch.init_unw_table &&
5015- module_region == mod->module_init) {
5016+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
5017 unw_remove_unwind_table(mod->arch.init_unw_table);
5018 mod->arch.init_unw_table = NULL;
5019 }
5020@@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
5021 }
5022
5023 static inline int
5024+in_init_rx (const struct module *mod, uint64_t addr)
5025+{
5026+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
5027+}
5028+
5029+static inline int
5030+in_init_rw (const struct module *mod, uint64_t addr)
5031+{
5032+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
5033+}
5034+
5035+static inline int
5036 in_init (const struct module *mod, uint64_t addr)
5037 {
5038- return addr - (uint64_t) mod->module_init < mod->init_size;
5039+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
5040+}
5041+
5042+static inline int
5043+in_core_rx (const struct module *mod, uint64_t addr)
5044+{
5045+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
5046+}
5047+
5048+static inline int
5049+in_core_rw (const struct module *mod, uint64_t addr)
5050+{
5051+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
5052 }
5053
5054 static inline int
5055 in_core (const struct module *mod, uint64_t addr)
5056 {
5057- return addr - (uint64_t) mod->module_core < mod->core_size;
5058+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
5059 }
5060
5061 static inline int
5062@@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
5063 break;
5064
5065 case RV_BDREL:
5066- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
5067+ if (in_init_rx(mod, val))
5068+ val -= (uint64_t) mod->module_init_rx;
5069+ else if (in_init_rw(mod, val))
5070+ val -= (uint64_t) mod->module_init_rw;
5071+ else if (in_core_rx(mod, val))
5072+ val -= (uint64_t) mod->module_core_rx;
5073+ else if (in_core_rw(mod, val))
5074+ val -= (uint64_t) mod->module_core_rw;
5075 break;
5076
5077 case RV_LTV:
5078@@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
5079 * addresses have been selected...
5080 */
5081 uint64_t gp;
5082- if (mod->core_size > MAX_LTOFF)
5083+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
5084 /*
5085 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
5086 * at the end of the module.
5087 */
5088- gp = mod->core_size - MAX_LTOFF / 2;
5089+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
5090 else
5091- gp = mod->core_size / 2;
5092- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
5093+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
5094+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
5095 mod->arch.gp = gp;
5096 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
5097 }
5098diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
5099index ab33328..f39506c 100644
5100--- a/arch/ia64/kernel/palinfo.c
5101+++ b/arch/ia64/kernel/palinfo.c
5102@@ -980,7 +980,7 @@ static int palinfo_cpu_callback(struct notifier_block *nfb,
5103 return NOTIFY_OK;
5104 }
5105
5106-static struct notifier_block __refdata palinfo_cpu_notifier =
5107+static struct notifier_block palinfo_cpu_notifier =
5108 {
5109 .notifier_call = palinfo_cpu_callback,
5110 .priority = 0,
5111diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
5112index 41e33f8..65180b2 100644
5113--- a/arch/ia64/kernel/sys_ia64.c
5114+++ b/arch/ia64/kernel/sys_ia64.c
5115@@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5116 unsigned long align_mask = 0;
5117 struct mm_struct *mm = current->mm;
5118 struct vm_unmapped_area_info info;
5119+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5120
5121 if (len > RGN_MAP_LIMIT)
5122 return -ENOMEM;
5123@@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5124 if (REGION_NUMBER(addr) == RGN_HPAGE)
5125 addr = 0;
5126 #endif
5127+
5128+#ifdef CONFIG_PAX_RANDMMAP
5129+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5130+ addr = mm->free_area_cache;
5131+ else
5132+#endif
5133+
5134 if (!addr)
5135 addr = TASK_UNMAPPED_BASE;
5136
5137@@ -61,6 +69,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5138 info.high_limit = TASK_SIZE;
5139 info.align_mask = align_mask;
5140 info.align_offset = 0;
5141+ info.threadstack_offset = offset;
5142 return vm_unmapped_area(&info);
5143 }
5144
5145diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
5146index 0ccb28f..8992469 100644
5147--- a/arch/ia64/kernel/vmlinux.lds.S
5148+++ b/arch/ia64/kernel/vmlinux.lds.S
5149@@ -198,7 +198,7 @@ SECTIONS {
5150 /* Per-cpu data: */
5151 . = ALIGN(PERCPU_PAGE_SIZE);
5152 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
5153- __phys_per_cpu_start = __per_cpu_load;
5154+ __phys_per_cpu_start = per_cpu_load;
5155 /*
5156 * ensure percpu data fits
5157 * into percpu page size
5158diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
5159index 6cf0341..d352594 100644
5160--- a/arch/ia64/mm/fault.c
5161+++ b/arch/ia64/mm/fault.c
5162@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
5163 return pte_present(pte);
5164 }
5165
5166+#ifdef CONFIG_PAX_PAGEEXEC
5167+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5168+{
5169+ unsigned long i;
5170+
5171+ printk(KERN_ERR "PAX: bytes at PC: ");
5172+ for (i = 0; i < 8; i++) {
5173+ unsigned int c;
5174+ if (get_user(c, (unsigned int *)pc+i))
5175+ printk(KERN_CONT "???????? ");
5176+ else
5177+ printk(KERN_CONT "%08x ", c);
5178+ }
5179+ printk("\n");
5180+}
5181+#endif
5182+
5183 # define VM_READ_BIT 0
5184 # define VM_WRITE_BIT 1
5185 # define VM_EXEC_BIT 2
5186@@ -149,8 +166,21 @@ retry:
5187 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
5188 goto bad_area;
5189
5190- if ((vma->vm_flags & mask) != mask)
5191+ if ((vma->vm_flags & mask) != mask) {
5192+
5193+#ifdef CONFIG_PAX_PAGEEXEC
5194+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5195+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5196+ goto bad_area;
5197+
5198+ up_read(&mm->mmap_sem);
5199+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
5200+ do_group_exit(SIGKILL);
5201+ }
5202+#endif
5203+
5204 goto bad_area;
5205+ }
5206
5207 /*
5208 * If for any reason at all we couldn't handle the fault, make
5209diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
5210index 76069c1..c2aa816 100644
5211--- a/arch/ia64/mm/hugetlbpage.c
5212+++ b/arch/ia64/mm/hugetlbpage.c
5213@@ -149,6 +149,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5214 unsigned long pgoff, unsigned long flags)
5215 {
5216 struct vm_unmapped_area_info info;
5217+ unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
5218
5219 if (len > RGN_MAP_LIMIT)
5220 return -ENOMEM;
5221@@ -172,6 +173,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5222 info.high_limit = HPAGE_REGION_BASE + RGN_MAP_LIMIT;
5223 info.align_mask = PAGE_MASK & (HPAGE_SIZE - 1);
5224 info.align_offset = 0;
5225+ info.threadstack_offset = offset;
5226 return vm_unmapped_area(&info);
5227 }
5228
5229diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
5230index b6f7f43..c04320d 100644
5231--- a/arch/ia64/mm/init.c
5232+++ b/arch/ia64/mm/init.c
5233@@ -120,6 +120,19 @@ ia64_init_addr_space (void)
5234 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
5235 vma->vm_end = vma->vm_start + PAGE_SIZE;
5236 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
5237+
5238+#ifdef CONFIG_PAX_PAGEEXEC
5239+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
5240+ vma->vm_flags &= ~VM_EXEC;
5241+
5242+#ifdef CONFIG_PAX_MPROTECT
5243+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
5244+ vma->vm_flags &= ~VM_MAYEXEC;
5245+#endif
5246+
5247+ }
5248+#endif
5249+
5250 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5251 down_write(&current->mm->mmap_sem);
5252 if (insert_vm_struct(current->mm, vma)) {
5253diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
5254index 40b3ee9..8c2c112 100644
5255--- a/arch/m32r/include/asm/cache.h
5256+++ b/arch/m32r/include/asm/cache.h
5257@@ -1,8 +1,10 @@
5258 #ifndef _ASM_M32R_CACHE_H
5259 #define _ASM_M32R_CACHE_H
5260
5261+#include <linux/const.h>
5262+
5263 /* L1 cache line size */
5264 #define L1_CACHE_SHIFT 4
5265-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5266+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5267
5268 #endif /* _ASM_M32R_CACHE_H */
5269diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
5270index 82abd15..d95ae5d 100644
5271--- a/arch/m32r/lib/usercopy.c
5272+++ b/arch/m32r/lib/usercopy.c
5273@@ -14,6 +14,9 @@
5274 unsigned long
5275 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5276 {
5277+ if ((long)n < 0)
5278+ return n;
5279+
5280 prefetch(from);
5281 if (access_ok(VERIFY_WRITE, to, n))
5282 __copy_user(to,from,n);
5283@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5284 unsigned long
5285 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
5286 {
5287+ if ((long)n < 0)
5288+ return n;
5289+
5290 prefetchw(to);
5291 if (access_ok(VERIFY_READ, from, n))
5292 __copy_user_zeroing(to,from,n);
5293diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
5294index 0395c51..5f26031 100644
5295--- a/arch/m68k/include/asm/cache.h
5296+++ b/arch/m68k/include/asm/cache.h
5297@@ -4,9 +4,11 @@
5298 #ifndef __ARCH_M68K_CACHE_H
5299 #define __ARCH_M68K_CACHE_H
5300
5301+#include <linux/const.h>
5302+
5303 /* bytes per L1 cache line */
5304 #define L1_CACHE_SHIFT 4
5305-#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
5306+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5307
5308 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5309
5310diff --git a/arch/metag/mm/hugetlbpage.c b/arch/metag/mm/hugetlbpage.c
5311index 3c52fa6..11b2ad8 100644
5312--- a/arch/metag/mm/hugetlbpage.c
5313+++ b/arch/metag/mm/hugetlbpage.c
5314@@ -200,6 +200,7 @@ hugetlb_get_unmapped_area_new_pmd(unsigned long len)
5315 info.high_limit = TASK_SIZE;
5316 info.align_mask = PAGE_MASK & HUGEPT_MASK;
5317 info.align_offset = 0;
5318+ info.threadstack_offset = 0;
5319 return vm_unmapped_area(&info);
5320 }
5321
5322diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
5323index 4efe96a..60e8699 100644
5324--- a/arch/microblaze/include/asm/cache.h
5325+++ b/arch/microblaze/include/asm/cache.h
5326@@ -13,11 +13,12 @@
5327 #ifndef _ASM_MICROBLAZE_CACHE_H
5328 #define _ASM_MICROBLAZE_CACHE_H
5329
5330+#include <linux/const.h>
5331 #include <asm/registers.h>
5332
5333 #define L1_CACHE_SHIFT 5
5334 /* word-granular cache in microblaze */
5335-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5336+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5337
5338 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5339
5340diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
5341index 08b6079..8b554d2 100644
5342--- a/arch/mips/include/asm/atomic.h
5343+++ b/arch/mips/include/asm/atomic.h
5344@@ -21,15 +21,39 @@
5345 #include <asm/cmpxchg.h>
5346 #include <asm/war.h>
5347
5348+#ifdef CONFIG_GENERIC_ATOMIC64
5349+#include <asm-generic/atomic64.h>
5350+#endif
5351+
5352 #define ATOMIC_INIT(i) { (i) }
5353
5354+#ifdef CONFIG_64BIT
5355+#define _ASM_EXTABLE(from, to) \
5356+" .section __ex_table,\"a\"\n" \
5357+" .dword " #from ", " #to"\n" \
5358+" .previous\n"
5359+#else
5360+#define _ASM_EXTABLE(from, to) \
5361+" .section __ex_table,\"a\"\n" \
5362+" .word " #from ", " #to"\n" \
5363+" .previous\n"
5364+#endif
5365+
5366 /*
5367 * atomic_read - read atomic variable
5368 * @v: pointer of type atomic_t
5369 *
5370 * Atomically reads the value of @v.
5371 */
5372-#define atomic_read(v) (*(volatile int *)&(v)->counter)
5373+static inline int atomic_read(const atomic_t *v)
5374+{
5375+ return (*(volatile const int *) &v->counter);
5376+}
5377+
5378+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5379+{
5380+ return (*(volatile const int *) &v->counter);
5381+}
5382
5383 /*
5384 * atomic_set - set atomic variable
5385@@ -38,7 +62,15 @@
5386 *
5387 * Atomically sets the value of @v to @i.
5388 */
5389-#define atomic_set(v, i) ((v)->counter = (i))
5390+static inline void atomic_set(atomic_t *v, int i)
5391+{
5392+ v->counter = i;
5393+}
5394+
5395+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5396+{
5397+ v->counter = i;
5398+}
5399
5400 /*
5401 * atomic_add - add integer to atomic variable
5402@@ -47,7 +79,67 @@
5403 *
5404 * Atomically adds @i to @v.
5405 */
5406-static __inline__ void atomic_add(int i, atomic_t * v)
5407+static __inline__ void atomic_add(int i, atomic_t *v)
5408+{
5409+ int temp;
5410+
5411+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5412+ __asm__ __volatile__(
5413+ " .set mips3 \n"
5414+ "1: ll %0, %1 # atomic_add \n"
5415+#ifdef CONFIG_PAX_REFCOUNT
5416+ /* Exception on overflow. */
5417+ "2: add %0, %2 \n"
5418+#else
5419+ " addu %0, %2 \n"
5420+#endif
5421+ " sc %0, %1 \n"
5422+ " beqzl %0, 1b \n"
5423+#ifdef CONFIG_PAX_REFCOUNT
5424+ "3: \n"
5425+ _ASM_EXTABLE(2b, 3b)
5426+#endif
5427+ " .set mips0 \n"
5428+ : "=&r" (temp), "+m" (v->counter)
5429+ : "Ir" (i));
5430+ } else if (kernel_uses_llsc) {
5431+ __asm__ __volatile__(
5432+ " .set mips3 \n"
5433+ "1: ll %0, %1 # atomic_add \n"
5434+#ifdef CONFIG_PAX_REFCOUNT
5435+ /* Exception on overflow. */
5436+ "2: add %0, %2 \n"
5437+#else
5438+ " addu %0, %2 \n"
5439+#endif
5440+ " sc %0, %1 \n"
5441+ " beqz %0, 1b \n"
5442+#ifdef CONFIG_PAX_REFCOUNT
5443+ "3: \n"
5444+ _ASM_EXTABLE(2b, 3b)
5445+#endif
5446+ " .set mips0 \n"
5447+ : "=&r" (temp), "+m" (v->counter)
5448+ : "Ir" (i));
5449+ } else {
5450+ unsigned long flags;
5451+
5452+ raw_local_irq_save(flags);
5453+ __asm__ __volatile__(
5454+#ifdef CONFIG_PAX_REFCOUNT
5455+ /* Exception on overflow. */
5456+ "1: add %0, %1 \n"
5457+ "2: \n"
5458+ _ASM_EXTABLE(1b, 2b)
5459+#else
5460+ " addu %0, %1 \n"
5461+#endif
5462+ : "+r" (v->counter) : "Ir" (i));
5463+ raw_local_irq_restore(flags);
5464+ }
5465+}
5466+
5467+static __inline__ void atomic_add_unchecked(int i, atomic_unchecked_t *v)
5468 {
5469 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5470 int temp;
5471@@ -90,7 +182,67 @@ static __inline__ void atomic_add(int i, atomic_t * v)
5472 *
5473 * Atomically subtracts @i from @v.
5474 */
5475-static __inline__ void atomic_sub(int i, atomic_t * v)
5476+static __inline__ void atomic_sub(int i, atomic_t *v)
5477+{
5478+ int temp;
5479+
5480+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5481+ __asm__ __volatile__(
5482+ " .set mips3 \n"
5483+ "1: ll %0, %1 # atomic64_sub \n"
5484+#ifdef CONFIG_PAX_REFCOUNT
5485+ /* Exception on overflow. */
5486+ "2: sub %0, %2 \n"
5487+#else
5488+ " subu %0, %2 \n"
5489+#endif
5490+ " sc %0, %1 \n"
5491+ " beqzl %0, 1b \n"
5492+#ifdef CONFIG_PAX_REFCOUNT
5493+ "3: \n"
5494+ _ASM_EXTABLE(2b, 3b)
5495+#endif
5496+ " .set mips0 \n"
5497+ : "=&r" (temp), "+m" (v->counter)
5498+ : "Ir" (i));
5499+ } else if (kernel_uses_llsc) {
5500+ __asm__ __volatile__(
5501+ " .set mips3 \n"
5502+ "1: ll %0, %1 # atomic64_sub \n"
5503+#ifdef CONFIG_PAX_REFCOUNT
5504+ /* Exception on overflow. */
5505+ "2: sub %0, %2 \n"
5506+#else
5507+ " subu %0, %2 \n"
5508+#endif
5509+ " sc %0, %1 \n"
5510+ " beqz %0, 1b \n"
5511+#ifdef CONFIG_PAX_REFCOUNT
5512+ "3: \n"
5513+ _ASM_EXTABLE(2b, 3b)
5514+#endif
5515+ " .set mips0 \n"
5516+ : "=&r" (temp), "+m" (v->counter)
5517+ : "Ir" (i));
5518+ } else {
5519+ unsigned long flags;
5520+
5521+ raw_local_irq_save(flags);
5522+ __asm__ __volatile__(
5523+#ifdef CONFIG_PAX_REFCOUNT
5524+ /* Exception on overflow. */
5525+ "1: sub %0, %1 \n"
5526+ "2: \n"
5527+ _ASM_EXTABLE(1b, 2b)
5528+#else
5529+ " subu %0, %1 \n"
5530+#endif
5531+ : "+r" (v->counter) : "Ir" (i));
5532+ raw_local_irq_restore(flags);
5533+ }
5534+}
5535+
5536+static __inline__ void atomic_sub_unchecked(long i, atomic_unchecked_t *v)
5537 {
5538 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5539 int temp;
5540@@ -129,7 +281,93 @@ static __inline__ void atomic_sub(int i, atomic_t * v)
5541 /*
5542 * Same as above, but return the result value
5543 */
5544-static __inline__ int atomic_add_return(int i, atomic_t * v)
5545+static __inline__ int atomic_add_return(int i, atomic_t *v)
5546+{
5547+ int result;
5548+ int temp;
5549+
5550+ smp_mb__before_llsc();
5551+
5552+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5553+ __asm__ __volatile__(
5554+ " .set mips3 \n"
5555+ "1: ll %1, %2 # atomic_add_return \n"
5556+#ifdef CONFIG_PAX_REFCOUNT
5557+ "2: add %0, %1, %3 \n"
5558+#else
5559+ " addu %0, %1, %3 \n"
5560+#endif
5561+ " sc %0, %2 \n"
5562+ " beqzl %0, 1b \n"
5563+#ifdef CONFIG_PAX_REFCOUNT
5564+ " b 4f \n"
5565+ " .set noreorder \n"
5566+ "3: b 5f \n"
5567+ " move %0, %1 \n"
5568+ " .set reorder \n"
5569+ _ASM_EXTABLE(2b, 3b)
5570+#endif
5571+ "4: addu %0, %1, %3 \n"
5572+#ifdef CONFIG_PAX_REFCOUNT
5573+ "5: \n"
5574+#endif
5575+ " .set mips0 \n"
5576+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5577+ : "Ir" (i));
5578+ } else if (kernel_uses_llsc) {
5579+ __asm__ __volatile__(
5580+ " .set mips3 \n"
5581+ "1: ll %1, %2 # atomic_add_return \n"
5582+#ifdef CONFIG_PAX_REFCOUNT
5583+ "2: add %0, %1, %3 \n"
5584+#else
5585+ " addu %0, %1, %3 \n"
5586+#endif
5587+ " sc %0, %2 \n"
5588+ " bnez %0, 4f \n"
5589+ " b 1b \n"
5590+#ifdef CONFIG_PAX_REFCOUNT
5591+ " .set noreorder \n"
5592+ "3: b 5f \n"
5593+ " move %0, %1 \n"
5594+ " .set reorder \n"
5595+ _ASM_EXTABLE(2b, 3b)
5596+#endif
5597+ "4: addu %0, %1, %3 \n"
5598+#ifdef CONFIG_PAX_REFCOUNT
5599+ "5: \n"
5600+#endif
5601+ " .set mips0 \n"
5602+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5603+ : "Ir" (i));
5604+ } else {
5605+ unsigned long flags;
5606+
5607+ raw_local_irq_save(flags);
5608+ __asm__ __volatile__(
5609+ " lw %0, %1 \n"
5610+#ifdef CONFIG_PAX_REFCOUNT
5611+ /* Exception on overflow. */
5612+ "1: add %0, %2 \n"
5613+#else
5614+ " addu %0, %2 \n"
5615+#endif
5616+ " sw %0, %1 \n"
5617+#ifdef CONFIG_PAX_REFCOUNT
5618+ /* Note: Dest reg is not modified on overflow */
5619+ "2: \n"
5620+ _ASM_EXTABLE(1b, 2b)
5621+#endif
5622+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5623+ raw_local_irq_restore(flags);
5624+ }
5625+
5626+ smp_llsc_mb();
5627+
5628+ return result;
5629+}
5630+
5631+static __inline__ int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5632 {
5633 int result;
5634
5635@@ -178,7 +416,93 @@ static __inline__ int atomic_add_return(int i, atomic_t * v)
5636 return result;
5637 }
5638
5639-static __inline__ int atomic_sub_return(int i, atomic_t * v)
5640+static __inline__ int atomic_sub_return(int i, atomic_t *v)
5641+{
5642+ int result;
5643+ int temp;
5644+
5645+ smp_mb__before_llsc();
5646+
5647+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5648+ __asm__ __volatile__(
5649+ " .set mips3 \n"
5650+ "1: ll %1, %2 # atomic_sub_return \n"
5651+#ifdef CONFIG_PAX_REFCOUNT
5652+ "2: sub %0, %1, %3 \n"
5653+#else
5654+ " subu %0, %1, %3 \n"
5655+#endif
5656+ " sc %0, %2 \n"
5657+ " beqzl %0, 1b \n"
5658+#ifdef CONFIG_PAX_REFCOUNT
5659+ " b 4f \n"
5660+ " .set noreorder \n"
5661+ "3: b 5f \n"
5662+ " move %0, %1 \n"
5663+ " .set reorder \n"
5664+ _ASM_EXTABLE(2b, 3b)
5665+#endif
5666+ "4: subu %0, %1, %3 \n"
5667+#ifdef CONFIG_PAX_REFCOUNT
5668+ "5: \n"
5669+#endif
5670+ " .set mips0 \n"
5671+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
5672+ : "Ir" (i), "m" (v->counter)
5673+ : "memory");
5674+ } else if (kernel_uses_llsc) {
5675+ __asm__ __volatile__(
5676+ " .set mips3 \n"
5677+ "1: ll %1, %2 # atomic_sub_return \n"
5678+#ifdef CONFIG_PAX_REFCOUNT
5679+ "2: sub %0, %1, %3 \n"
5680+#else
5681+ " subu %0, %1, %3 \n"
5682+#endif
5683+ " sc %0, %2 \n"
5684+ " bnez %0, 4f \n"
5685+ " b 1b \n"
5686+#ifdef CONFIG_PAX_REFCOUNT
5687+ " .set noreorder \n"
5688+ "3: b 5f \n"
5689+ " move %0, %1 \n"
5690+ " .set reorder \n"
5691+ _ASM_EXTABLE(2b, 3b)
5692+#endif
5693+ "4: subu %0, %1, %3 \n"
5694+#ifdef CONFIG_PAX_REFCOUNT
5695+ "5: \n"
5696+#endif
5697+ " .set mips0 \n"
5698+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5699+ : "Ir" (i));
5700+ } else {
5701+ unsigned long flags;
5702+
5703+ raw_local_irq_save(flags);
5704+ __asm__ __volatile__(
5705+ " lw %0, %1 \n"
5706+#ifdef CONFIG_PAX_REFCOUNT
5707+ /* Exception on overflow. */
5708+ "1: sub %0, %2 \n"
5709+#else
5710+ " subu %0, %2 \n"
5711+#endif
5712+ " sw %0, %1 \n"
5713+#ifdef CONFIG_PAX_REFCOUNT
5714+ /* Note: Dest reg is not modified on overflow */
5715+ "2: \n"
5716+ _ASM_EXTABLE(1b, 2b)
5717+#endif
5718+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5719+ raw_local_irq_restore(flags);
5720+ }
5721+
5722+ smp_llsc_mb();
5723+
5724+ return result;
5725+}
5726+static __inline__ int atomic_sub_return_unchecked(int i, atomic_unchecked_t *v)
5727 {
5728 int result;
5729
5730@@ -238,7 +562,7 @@ static __inline__ int atomic_sub_return(int i, atomic_t * v)
5731 * Atomically test @v and subtract @i if @v is greater or equal than @i.
5732 * The function returns the old value of @v minus @i.
5733 */
5734-static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5735+static __inline__ int atomic_sub_if_positive(int i, atomic_t *v)
5736 {
5737 int result;
5738
5739@@ -295,8 +619,26 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5740 return result;
5741 }
5742
5743-#define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5744-#define atomic_xchg(v, new) (xchg(&((v)->counter), (new)))
5745+static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
5746+{
5747+ return cmpxchg(&v->counter, old, new);
5748+}
5749+
5750+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old,
5751+ int new)
5752+{
5753+ return cmpxchg(&(v->counter), old, new);
5754+}
5755+
5756+static inline int atomic_xchg(atomic_t *v, int new)
5757+{
5758+ return xchg(&v->counter, new);
5759+}
5760+
5761+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5762+{
5763+ return xchg(&(v->counter), new);
5764+}
5765
5766 /**
5767 * __atomic_add_unless - add unless the number is a given value
5768@@ -324,6 +666,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5769
5770 #define atomic_dec_return(v) atomic_sub_return(1, (v))
5771 #define atomic_inc_return(v) atomic_add_return(1, (v))
5772+static __inline__ int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5773+{
5774+ return atomic_add_return_unchecked(1, v);
5775+}
5776
5777 /*
5778 * atomic_sub_and_test - subtract value from variable and test result
5779@@ -345,6 +691,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5780 * other cases.
5781 */
5782 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5783+static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
5784+{
5785+ return atomic_add_return_unchecked(1, v) == 0;
5786+}
5787
5788 /*
5789 * atomic_dec_and_test - decrement by 1 and test
5790@@ -369,6 +719,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5791 * Atomically increments @v by 1.
5792 */
5793 #define atomic_inc(v) atomic_add(1, (v))
5794+static __inline__ void atomic_inc_unchecked(atomic_unchecked_t *v)
5795+{
5796+ atomic_add_unchecked(1, v);
5797+}
5798
5799 /*
5800 * atomic_dec - decrement and test
5801@@ -377,6 +731,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5802 * Atomically decrements @v by 1.
5803 */
5804 #define atomic_dec(v) atomic_sub(1, (v))
5805+static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
5806+{
5807+ atomic_sub_unchecked(1, v);
5808+}
5809
5810 /*
5811 * atomic_add_negative - add and test if negative
5812@@ -398,14 +756,30 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5813 * @v: pointer of type atomic64_t
5814 *
5815 */
5816-#define atomic64_read(v) (*(volatile long *)&(v)->counter)
5817+static inline long atomic64_read(const atomic64_t *v)
5818+{
5819+ return (*(volatile const long *) &v->counter);
5820+}
5821+
5822+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
5823+{
5824+ return (*(volatile const long *) &v->counter);
5825+}
5826
5827 /*
5828 * atomic64_set - set atomic variable
5829 * @v: pointer of type atomic64_t
5830 * @i: required value
5831 */
5832-#define atomic64_set(v, i) ((v)->counter = (i))
5833+static inline void atomic64_set(atomic64_t *v, long i)
5834+{
5835+ v->counter = i;
5836+}
5837+
5838+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
5839+{
5840+ v->counter = i;
5841+}
5842
5843 /*
5844 * atomic64_add - add integer to atomic variable
5845@@ -414,7 +788,66 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5846 *
5847 * Atomically adds @i to @v.
5848 */
5849-static __inline__ void atomic64_add(long i, atomic64_t * v)
5850+static __inline__ void atomic64_add(long i, atomic64_t *v)
5851+{
5852+ long temp;
5853+
5854+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5855+ __asm__ __volatile__(
5856+ " .set mips3 \n"
5857+ "1: lld %0, %1 # atomic64_add \n"
5858+#ifdef CONFIG_PAX_REFCOUNT
5859+ /* Exception on overflow. */
5860+ "2: dadd %0, %2 \n"
5861+#else
5862+ " daddu %0, %2 \n"
5863+#endif
5864+ " scd %0, %1 \n"
5865+ " beqzl %0, 1b \n"
5866+#ifdef CONFIG_PAX_REFCOUNT
5867+ "3: \n"
5868+ _ASM_EXTABLE(2b, 3b)
5869+#endif
5870+ " .set mips0 \n"
5871+ : "=&r" (temp), "+m" (v->counter)
5872+ : "Ir" (i));
5873+ } else if (kernel_uses_llsc) {
5874+ __asm__ __volatile__(
5875+ " .set mips3 \n"
5876+ "1: lld %0, %1 # atomic64_add \n"
5877+#ifdef CONFIG_PAX_REFCOUNT
5878+ /* Exception on overflow. */
5879+ "2: dadd %0, %2 \n"
5880+#else
5881+ " daddu %0, %2 \n"
5882+#endif
5883+ " scd %0, %1 \n"
5884+ " beqz %0, 1b \n"
5885+#ifdef CONFIG_PAX_REFCOUNT
5886+ "3: \n"
5887+ _ASM_EXTABLE(2b, 3b)
5888+#endif
5889+ " .set mips0 \n"
5890+ : "=&r" (temp), "+m" (v->counter)
5891+ : "Ir" (i));
5892+ } else {
5893+ unsigned long flags;
5894+
5895+ raw_local_irq_save(flags);
5896+ __asm__ __volatile__(
5897+#ifdef CONFIG_PAX_REFCOUNT
5898+ /* Exception on overflow. */
5899+ "1: dadd %0, %1 \n"
5900+ "2: \n"
5901+ _ASM_EXTABLE(1b, 2b)
5902+#else
5903+ " daddu %0, %1 \n"
5904+#endif
5905+ : "+r" (v->counter) : "Ir" (i));
5906+ raw_local_irq_restore(flags);
5907+ }
5908+}
5909+static __inline__ void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
5910 {
5911 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5912 long temp;
5913@@ -457,7 +890,67 @@ static __inline__ void atomic64_add(long i, atomic64_t * v)
5914 *
5915 * Atomically subtracts @i from @v.
5916 */
5917-static __inline__ void atomic64_sub(long i, atomic64_t * v)
5918+static __inline__ void atomic64_sub(long i, atomic64_t *v)
5919+{
5920+ long temp;
5921+
5922+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5923+ __asm__ __volatile__(
5924+ " .set mips3 \n"
5925+ "1: lld %0, %1 # atomic64_sub \n"
5926+#ifdef CONFIG_PAX_REFCOUNT
5927+ /* Exception on overflow. */
5928+ "2: dsub %0, %2 \n"
5929+#else
5930+ " dsubu %0, %2 \n"
5931+#endif
5932+ " scd %0, %1 \n"
5933+ " beqzl %0, 1b \n"
5934+#ifdef CONFIG_PAX_REFCOUNT
5935+ "3: \n"
5936+ _ASM_EXTABLE(2b, 3b)
5937+#endif
5938+ " .set mips0 \n"
5939+ : "=&r" (temp), "+m" (v->counter)
5940+ : "Ir" (i));
5941+ } else if (kernel_uses_llsc) {
5942+ __asm__ __volatile__(
5943+ " .set mips3 \n"
5944+ "1: lld %0, %1 # atomic64_sub \n"
5945+#ifdef CONFIG_PAX_REFCOUNT
5946+ /* Exception on overflow. */
5947+ "2: dsub %0, %2 \n"
5948+#else
5949+ " dsubu %0, %2 \n"
5950+#endif
5951+ " scd %0, %1 \n"
5952+ " beqz %0, 1b \n"
5953+#ifdef CONFIG_PAX_REFCOUNT
5954+ "3: \n"
5955+ _ASM_EXTABLE(2b, 3b)
5956+#endif
5957+ " .set mips0 \n"
5958+ : "=&r" (temp), "+m" (v->counter)
5959+ : "Ir" (i));
5960+ } else {
5961+ unsigned long flags;
5962+
5963+ raw_local_irq_save(flags);
5964+ __asm__ __volatile__(
5965+#ifdef CONFIG_PAX_REFCOUNT
5966+ /* Exception on overflow. */
5967+ "1: dsub %0, %1 \n"
5968+ "2: \n"
5969+ _ASM_EXTABLE(1b, 2b)
5970+#else
5971+ " dsubu %0, %1 \n"
5972+#endif
5973+ : "+r" (v->counter) : "Ir" (i));
5974+ raw_local_irq_restore(flags);
5975+ }
5976+}
5977+
5978+static __inline__ void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
5979 {
5980 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5981 long temp;
5982@@ -496,7 +989,93 @@ static __inline__ void atomic64_sub(long i, atomic64_t * v)
5983 /*
5984 * Same as above, but return the result value
5985 */
5986-static __inline__ long atomic64_add_return(long i, atomic64_t * v)
5987+static __inline__ long atomic64_add_return(long i, atomic64_t *v)
5988+{
5989+ long result;
5990+ long temp;
5991+
5992+ smp_mb__before_llsc();
5993+
5994+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5995+ __asm__ __volatile__(
5996+ " .set mips3 \n"
5997+ "1: lld %1, %2 # atomic64_add_return \n"
5998+#ifdef CONFIG_PAX_REFCOUNT
5999+ "2: dadd %0, %1, %3 \n"
6000+#else
6001+ " daddu %0, %1, %3 \n"
6002+#endif
6003+ " scd %0, %2 \n"
6004+ " beqzl %0, 1b \n"
6005+#ifdef CONFIG_PAX_REFCOUNT
6006+ " b 4f \n"
6007+ " .set noreorder \n"
6008+ "3: b 5f \n"
6009+ " move %0, %1 \n"
6010+ " .set reorder \n"
6011+ _ASM_EXTABLE(2b, 3b)
6012+#endif
6013+ "4: daddu %0, %1, %3 \n"
6014+#ifdef CONFIG_PAX_REFCOUNT
6015+ "5: \n"
6016+#endif
6017+ " .set mips0 \n"
6018+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6019+ : "Ir" (i));
6020+ } else if (kernel_uses_llsc) {
6021+ __asm__ __volatile__(
6022+ " .set mips3 \n"
6023+ "1: lld %1, %2 # atomic64_add_return \n"
6024+#ifdef CONFIG_PAX_REFCOUNT
6025+ "2: dadd %0, %1, %3 \n"
6026+#else
6027+ " daddu %0, %1, %3 \n"
6028+#endif
6029+ " scd %0, %2 \n"
6030+ " bnez %0, 4f \n"
6031+ " b 1b \n"
6032+#ifdef CONFIG_PAX_REFCOUNT
6033+ " .set noreorder \n"
6034+ "3: b 5f \n"
6035+ " move %0, %1 \n"
6036+ " .set reorder \n"
6037+ _ASM_EXTABLE(2b, 3b)
6038+#endif
6039+ "4: daddu %0, %1, %3 \n"
6040+#ifdef CONFIG_PAX_REFCOUNT
6041+ "5: \n"
6042+#endif
6043+ " .set mips0 \n"
6044+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6045+ : "Ir" (i), "m" (v->counter)
6046+ : "memory");
6047+ } else {
6048+ unsigned long flags;
6049+
6050+ raw_local_irq_save(flags);
6051+ __asm__ __volatile__(
6052+ " ld %0, %1 \n"
6053+#ifdef CONFIG_PAX_REFCOUNT
6054+ /* Exception on overflow. */
6055+ "1: dadd %0, %2 \n"
6056+#else
6057+ " daddu %0, %2 \n"
6058+#endif
6059+ " sd %0, %1 \n"
6060+#ifdef CONFIG_PAX_REFCOUNT
6061+ /* Note: Dest reg is not modified on overflow */
6062+ "2: \n"
6063+ _ASM_EXTABLE(1b, 2b)
6064+#endif
6065+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6066+ raw_local_irq_restore(flags);
6067+ }
6068+
6069+ smp_llsc_mb();
6070+
6071+ return result;
6072+}
6073+static __inline__ long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
6074 {
6075 long result;
6076
6077@@ -546,7 +1125,97 @@ static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6078 return result;
6079 }
6080
6081-static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6082+static __inline__ long atomic64_sub_return(long i, atomic64_t *v)
6083+{
6084+ long result;
6085+ long temp;
6086+
6087+ smp_mb__before_llsc();
6088+
6089+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6090+ long temp;
6091+
6092+ __asm__ __volatile__(
6093+ " .set mips3 \n"
6094+ "1: lld %1, %2 # atomic64_sub_return \n"
6095+#ifdef CONFIG_PAX_REFCOUNT
6096+ "2: dsub %0, %1, %3 \n"
6097+#else
6098+ " dsubu %0, %1, %3 \n"
6099+#endif
6100+ " scd %0, %2 \n"
6101+ " beqzl %0, 1b \n"
6102+#ifdef CONFIG_PAX_REFCOUNT
6103+ " b 4f \n"
6104+ " .set noreorder \n"
6105+ "3: b 5f \n"
6106+ " move %0, %1 \n"
6107+ " .set reorder \n"
6108+ _ASM_EXTABLE(2b, 3b)
6109+#endif
6110+ "4: dsubu %0, %1, %3 \n"
6111+#ifdef CONFIG_PAX_REFCOUNT
6112+ "5: \n"
6113+#endif
6114+ " .set mips0 \n"
6115+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6116+ : "Ir" (i), "m" (v->counter)
6117+ : "memory");
6118+ } else if (kernel_uses_llsc) {
6119+ __asm__ __volatile__(
6120+ " .set mips3 \n"
6121+ "1: lld %1, %2 # atomic64_sub_return \n"
6122+#ifdef CONFIG_PAX_REFCOUNT
6123+ "2: dsub %0, %1, %3 \n"
6124+#else
6125+ " dsubu %0, %1, %3 \n"
6126+#endif
6127+ " scd %0, %2 \n"
6128+ " bnez %0, 4f \n"
6129+ " b 1b \n"
6130+#ifdef CONFIG_PAX_REFCOUNT
6131+ " .set noreorder \n"
6132+ "3: b 5f \n"
6133+ " move %0, %1 \n"
6134+ " .set reorder \n"
6135+ _ASM_EXTABLE(2b, 3b)
6136+#endif
6137+ "4: dsubu %0, %1, %3 \n"
6138+#ifdef CONFIG_PAX_REFCOUNT
6139+ "5: \n"
6140+#endif
6141+ " .set mips0 \n"
6142+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6143+ : "Ir" (i), "m" (v->counter)
6144+ : "memory");
6145+ } else {
6146+ unsigned long flags;
6147+
6148+ raw_local_irq_save(flags);
6149+ __asm__ __volatile__(
6150+ " ld %0, %1 \n"
6151+#ifdef CONFIG_PAX_REFCOUNT
6152+ /* Exception on overflow. */
6153+ "1: dsub %0, %2 \n"
6154+#else
6155+ " dsubu %0, %2 \n"
6156+#endif
6157+ " sd %0, %1 \n"
6158+#ifdef CONFIG_PAX_REFCOUNT
6159+ /* Note: Dest reg is not modified on overflow */
6160+ "2: \n"
6161+ _ASM_EXTABLE(1b, 2b)
6162+#endif
6163+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6164+ raw_local_irq_restore(flags);
6165+ }
6166+
6167+ smp_llsc_mb();
6168+
6169+ return result;
6170+}
6171+
6172+static __inline__ long atomic64_sub_return_unchecked(long i, atomic64_unchecked_t *v)
6173 {
6174 long result;
6175
6176@@ -605,7 +1274,7 @@ static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6177 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6178 * The function returns the old value of @v minus @i.
6179 */
6180-static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6181+static __inline__ long atomic64_sub_if_positive(long i, atomic64_t *v)
6182 {
6183 long result;
6184
6185@@ -662,9 +1331,26 @@ static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6186 return result;
6187 }
6188
6189-#define atomic64_cmpxchg(v, o, n) \
6190- ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
6191-#define atomic64_xchg(v, new) (xchg(&((v)->counter), (new)))
6192+static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
6193+{
6194+ return cmpxchg(&v->counter, old, new);
6195+}
6196+
6197+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old,
6198+ long new)
6199+{
6200+ return cmpxchg(&(v->counter), old, new);
6201+}
6202+
6203+static inline long atomic64_xchg(atomic64_t *v, long new)
6204+{
6205+ return xchg(&v->counter, new);
6206+}
6207+
6208+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
6209+{
6210+ return xchg(&(v->counter), new);
6211+}
6212
6213 /**
6214 * atomic64_add_unless - add unless the number is a given value
6215@@ -694,6 +1380,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6216
6217 #define atomic64_dec_return(v) atomic64_sub_return(1, (v))
6218 #define atomic64_inc_return(v) atomic64_add_return(1, (v))
6219+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1, (v))
6220
6221 /*
6222 * atomic64_sub_and_test - subtract value from variable and test result
6223@@ -715,6 +1402,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6224 * other cases.
6225 */
6226 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
6227+#define atomic64_inc_and_test_unchecked(v) atomic64_add_return_unchecked(1, (v)) == 0)
6228
6229 /*
6230 * atomic64_dec_and_test - decrement by 1 and test
6231@@ -739,6 +1427,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6232 * Atomically increments @v by 1.
6233 */
6234 #define atomic64_inc(v) atomic64_add(1, (v))
6235+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1, (v))
6236
6237 /*
6238 * atomic64_dec - decrement and test
6239@@ -747,6 +1436,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6240 * Atomically decrements @v by 1.
6241 */
6242 #define atomic64_dec(v) atomic64_sub(1, (v))
6243+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1, (v))
6244
6245 /*
6246 * atomic64_add_negative - add and test if negative
6247diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
6248index b4db69f..8f3b093 100644
6249--- a/arch/mips/include/asm/cache.h
6250+++ b/arch/mips/include/asm/cache.h
6251@@ -9,10 +9,11 @@
6252 #ifndef _ASM_CACHE_H
6253 #define _ASM_CACHE_H
6254
6255+#include <linux/const.h>
6256 #include <kmalloc.h>
6257
6258 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
6259-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6260+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6261
6262 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
6263 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6264diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
6265index cf3ae24..238d22f 100644
6266--- a/arch/mips/include/asm/elf.h
6267+++ b/arch/mips/include/asm/elf.h
6268@@ -372,13 +372,16 @@ extern const char *__elf_platform;
6269 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
6270 #endif
6271
6272+#ifdef CONFIG_PAX_ASLR
6273+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6274+
6275+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6276+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6277+#endif
6278+
6279 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
6280 struct linux_binprm;
6281 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
6282 int uses_interp);
6283
6284-struct mm_struct;
6285-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6286-#define arch_randomize_brk arch_randomize_brk
6287-
6288 #endif /* _ASM_ELF_H */
6289diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
6290index c1f6afa..38cc6e9 100644
6291--- a/arch/mips/include/asm/exec.h
6292+++ b/arch/mips/include/asm/exec.h
6293@@ -12,6 +12,6 @@
6294 #ifndef _ASM_EXEC_H
6295 #define _ASM_EXEC_H
6296
6297-extern unsigned long arch_align_stack(unsigned long sp);
6298+#define arch_align_stack(x) ((x) & ~0xfUL)
6299
6300 #endif /* _ASM_EXEC_H */
6301diff --git a/arch/mips/include/asm/local.h b/arch/mips/include/asm/local.h
6302index d44622c..64990d2 100644
6303--- a/arch/mips/include/asm/local.h
6304+++ b/arch/mips/include/asm/local.h
6305@@ -12,15 +12,25 @@ typedef struct
6306 atomic_long_t a;
6307 } local_t;
6308
6309+typedef struct {
6310+ atomic_long_unchecked_t a;
6311+} local_unchecked_t;
6312+
6313 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
6314
6315 #define local_read(l) atomic_long_read(&(l)->a)
6316+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
6317 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
6318+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
6319
6320 #define local_add(i, l) atomic_long_add((i), (&(l)->a))
6321+#define local_add_unchecked(i, l) atomic_long_add_unchecked((i), (&(l)->a))
6322 #define local_sub(i, l) atomic_long_sub((i), (&(l)->a))
6323+#define local_sub_unchecked(i, l) atomic_long_sub_unchecked((i), (&(l)->a))
6324 #define local_inc(l) atomic_long_inc(&(l)->a)
6325+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
6326 #define local_dec(l) atomic_long_dec(&(l)->a)
6327+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
6328
6329 /*
6330 * Same as above, but return the result value
6331@@ -70,6 +80,51 @@ static __inline__ long local_add_return(long i, local_t * l)
6332 return result;
6333 }
6334
6335+static __inline__ long local_add_return_unchecked(long i, local_unchecked_t * l)
6336+{
6337+ unsigned long result;
6338+
6339+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6340+ unsigned long temp;
6341+
6342+ __asm__ __volatile__(
6343+ " .set mips3 \n"
6344+ "1:" __LL "%1, %2 # local_add_return \n"
6345+ " addu %0, %1, %3 \n"
6346+ __SC "%0, %2 \n"
6347+ " beqzl %0, 1b \n"
6348+ " addu %0, %1, %3 \n"
6349+ " .set mips0 \n"
6350+ : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6351+ : "Ir" (i), "m" (l->a.counter)
6352+ : "memory");
6353+ } else if (kernel_uses_llsc) {
6354+ unsigned long temp;
6355+
6356+ __asm__ __volatile__(
6357+ " .set mips3 \n"
6358+ "1:" __LL "%1, %2 # local_add_return \n"
6359+ " addu %0, %1, %3 \n"
6360+ __SC "%0, %2 \n"
6361+ " beqz %0, 1b \n"
6362+ " addu %0, %1, %3 \n"
6363+ " .set mips0 \n"
6364+ : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6365+ : "Ir" (i), "m" (l->a.counter)
6366+ : "memory");
6367+ } else {
6368+ unsigned long flags;
6369+
6370+ local_irq_save(flags);
6371+ result = l->a.counter;
6372+ result += i;
6373+ l->a.counter = result;
6374+ local_irq_restore(flags);
6375+ }
6376+
6377+ return result;
6378+}
6379+
6380 static __inline__ long local_sub_return(long i, local_t * l)
6381 {
6382 unsigned long result;
6383@@ -117,6 +172,8 @@ static __inline__ long local_sub_return(long i, local_t * l)
6384
6385 #define local_cmpxchg(l, o, n) \
6386 ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6387+#define local_cmpxchg_unchecked(l, o, n) \
6388+ ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6389 #define local_xchg(l, n) (atomic_long_xchg((&(l)->a), (n)))
6390
6391 /**
6392diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
6393index f6be474..12ad554 100644
6394--- a/arch/mips/include/asm/page.h
6395+++ b/arch/mips/include/asm/page.h
6396@@ -95,7 +95,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
6397 #ifdef CONFIG_CPU_MIPS32
6398 typedef struct { unsigned long pte_low, pte_high; } pte_t;
6399 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
6400- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
6401+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
6402 #else
6403 typedef struct { unsigned long long pte; } pte_t;
6404 #define pte_val(x) ((x).pte)
6405diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
6406index 881d18b..cea38bc 100644
6407--- a/arch/mips/include/asm/pgalloc.h
6408+++ b/arch/mips/include/asm/pgalloc.h
6409@@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6410 {
6411 set_pud(pud, __pud((unsigned long)pmd));
6412 }
6413+
6414+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6415+{
6416+ pud_populate(mm, pud, pmd);
6417+}
6418 #endif
6419
6420 /*
6421diff --git a/arch/mips/include/asm/smtc_proc.h b/arch/mips/include/asm/smtc_proc.h
6422index 25da651..ae2a259 100644
6423--- a/arch/mips/include/asm/smtc_proc.h
6424+++ b/arch/mips/include/asm/smtc_proc.h
6425@@ -18,6 +18,6 @@ extern struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6426
6427 /* Count of number of recoveries of "stolen" FPU access rights on 34K */
6428
6429-extern atomic_t smtc_fpu_recoveries;
6430+extern atomic_unchecked_t smtc_fpu_recoveries;
6431
6432 #endif /* __ASM_SMTC_PROC_H */
6433diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
6434index 61215a3..213ee0e 100644
6435--- a/arch/mips/include/asm/thread_info.h
6436+++ b/arch/mips/include/asm/thread_info.h
6437@@ -116,6 +116,8 @@ static inline struct thread_info *current_thread_info(void)
6438 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
6439 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
6440 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
6441+/* li takes a 32bit immediate */
6442+#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
6443 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
6444
6445 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
6446@@ -132,20 +134,18 @@ static inline struct thread_info *current_thread_info(void)
6447 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
6448 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
6449 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
6450+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6451
6452-#define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6453- _TIF_SYSCALL_AUDIT)
6454+#define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
6455
6456 /* work to do in syscall_trace_leave() */
6457-#define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6458- _TIF_SYSCALL_AUDIT)
6459+#define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
6460
6461 /* work to do on interrupt/exception return */
6462 #define _TIF_WORK_MASK \
6463 (_TIF_SIGPENDING | _TIF_NEED_RESCHED | _TIF_NOTIFY_RESUME)
6464 /* work to do on any return to u-space */
6465-#define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | \
6466- _TIF_WORK_SYSCALL_EXIT)
6467+#define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT | _TIF_GRSEC_SETXID)
6468
6469 #endif /* __KERNEL__ */
6470
6471diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
6472index 1188e00..41cf144 100644
6473--- a/arch/mips/kernel/binfmt_elfn32.c
6474+++ b/arch/mips/kernel/binfmt_elfn32.c
6475@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6476 #undef ELF_ET_DYN_BASE
6477 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6478
6479+#ifdef CONFIG_PAX_ASLR
6480+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6481+
6482+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6483+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6484+#endif
6485+
6486 #include <asm/processor.h>
6487 #include <linux/module.h>
6488 #include <linux/elfcore.h>
6489diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
6490index 202e581..689ca79 100644
6491--- a/arch/mips/kernel/binfmt_elfo32.c
6492+++ b/arch/mips/kernel/binfmt_elfo32.c
6493@@ -56,6 +56,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6494 #undef ELF_ET_DYN_BASE
6495 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6496
6497+#ifdef CONFIG_PAX_ASLR
6498+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6499+
6500+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6501+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6502+#endif
6503+
6504 #include <asm/processor.h>
6505
6506 /*
6507diff --git a/arch/mips/kernel/irq.c b/arch/mips/kernel/irq.c
6508index d1fea7a..45602ea 100644
6509--- a/arch/mips/kernel/irq.c
6510+++ b/arch/mips/kernel/irq.c
6511@@ -77,17 +77,17 @@ void ack_bad_irq(unsigned int irq)
6512 printk("unexpected IRQ # %d\n", irq);
6513 }
6514
6515-atomic_t irq_err_count;
6516+atomic_unchecked_t irq_err_count;
6517
6518 int arch_show_interrupts(struct seq_file *p, int prec)
6519 {
6520- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
6521+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
6522 return 0;
6523 }
6524
6525 asmlinkage void spurious_interrupt(void)
6526 {
6527- atomic_inc(&irq_err_count);
6528+ atomic_inc_unchecked(&irq_err_count);
6529 }
6530
6531 void __init init_IRQ(void)
6532diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
6533index ddc7610..8c58f17 100644
6534--- a/arch/mips/kernel/process.c
6535+++ b/arch/mips/kernel/process.c
6536@@ -566,15 +566,3 @@ unsigned long get_wchan(struct task_struct *task)
6537 out:
6538 return pc;
6539 }
6540-
6541-/*
6542- * Don't forget that the stack pointer must be aligned on a 8 bytes
6543- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
6544- */
6545-unsigned long arch_align_stack(unsigned long sp)
6546-{
6547- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6548- sp -= get_random_int() & ~PAGE_MASK;
6549-
6550- return sp & ALMASK;
6551-}
6552diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
6553index 8ae1ebe..1bcbf47 100644
6554--- a/arch/mips/kernel/ptrace.c
6555+++ b/arch/mips/kernel/ptrace.c
6556@@ -529,6 +529,10 @@ static inline int audit_arch(void)
6557 return arch;
6558 }
6559
6560+#ifdef CONFIG_GRKERNSEC_SETXID
6561+extern void gr_delayed_cred_worker(void);
6562+#endif
6563+
6564 /*
6565 * Notification of system call entry/exit
6566 * - triggered by current->work.syscall_trace
6567@@ -540,6 +544,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
6568 /* do the secure computing check first */
6569 secure_computing_strict(regs->regs[2]);
6570
6571+#ifdef CONFIG_GRKERNSEC_SETXID
6572+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6573+ gr_delayed_cred_worker();
6574+#endif
6575+
6576 if (!(current->ptrace & PT_PTRACED))
6577 goto out;
6578
6579diff --git a/arch/mips/kernel/smtc-proc.c b/arch/mips/kernel/smtc-proc.c
6580index c10aa84..9ec2e60 100644
6581--- a/arch/mips/kernel/smtc-proc.c
6582+++ b/arch/mips/kernel/smtc-proc.c
6583@@ -31,7 +31,7 @@ unsigned long selfipis[NR_CPUS];
6584
6585 struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6586
6587-atomic_t smtc_fpu_recoveries;
6588+atomic_unchecked_t smtc_fpu_recoveries;
6589
6590 static int smtc_proc_show(struct seq_file *m, void *v)
6591 {
6592@@ -48,7 +48,7 @@ static int smtc_proc_show(struct seq_file *m, void *v)
6593 for(i = 0; i < NR_CPUS; i++)
6594 seq_printf(m, "%d: %ld\n", i, smtc_cpu_stats[i].selfipis);
6595 seq_printf(m, "%d Recoveries of \"stolen\" FPU\n",
6596- atomic_read(&smtc_fpu_recoveries));
6597+ atomic_read_unchecked(&smtc_fpu_recoveries));
6598 return 0;
6599 }
6600
6601@@ -73,7 +73,7 @@ void init_smtc_stats(void)
6602 smtc_cpu_stats[i].selfipis = 0;
6603 }
6604
6605- atomic_set(&smtc_fpu_recoveries, 0);
6606+ atomic_set_unchecked(&smtc_fpu_recoveries, 0);
6607
6608 proc_create("smtc", 0444, NULL, &smtc_proc_fops);
6609 }
6610diff --git a/arch/mips/kernel/smtc.c b/arch/mips/kernel/smtc.c
6611index dfc1b91..11a2c07 100644
6612--- a/arch/mips/kernel/smtc.c
6613+++ b/arch/mips/kernel/smtc.c
6614@@ -1359,7 +1359,7 @@ void smtc_soft_dump(void)
6615 }
6616 smtc_ipi_qdump();
6617 printk("%d Recoveries of \"stolen\" FPU\n",
6618- atomic_read(&smtc_fpu_recoveries));
6619+ atomic_read_unchecked(&smtc_fpu_recoveries));
6620 }
6621
6622
6623diff --git a/arch/mips/kernel/sync-r4k.c b/arch/mips/kernel/sync-r4k.c
6624index 84536bf..79caa4d 100644
6625--- a/arch/mips/kernel/sync-r4k.c
6626+++ b/arch/mips/kernel/sync-r4k.c
6627@@ -21,8 +21,8 @@
6628 #include <asm/mipsregs.h>
6629
6630 static atomic_t count_start_flag = ATOMIC_INIT(0);
6631-static atomic_t count_count_start = ATOMIC_INIT(0);
6632-static atomic_t count_count_stop = ATOMIC_INIT(0);
6633+static atomic_unchecked_t count_count_start = ATOMIC_INIT(0);
6634+static atomic_unchecked_t count_count_stop = ATOMIC_INIT(0);
6635 static atomic_t count_reference = ATOMIC_INIT(0);
6636
6637 #define COUNTON 100
6638@@ -69,13 +69,13 @@ void synchronise_count_master(int cpu)
6639
6640 for (i = 0; i < NR_LOOPS; i++) {
6641 /* slaves loop on '!= 2' */
6642- while (atomic_read(&count_count_start) != 1)
6643+ while (atomic_read_unchecked(&count_count_start) != 1)
6644 mb();
6645- atomic_set(&count_count_stop, 0);
6646+ atomic_set_unchecked(&count_count_stop, 0);
6647 smp_wmb();
6648
6649 /* this lets the slaves write their count register */
6650- atomic_inc(&count_count_start);
6651+ atomic_inc_unchecked(&count_count_start);
6652
6653 /*
6654 * Everyone initialises count in the last loop:
6655@@ -86,11 +86,11 @@ void synchronise_count_master(int cpu)
6656 /*
6657 * Wait for all slaves to leave the synchronization point:
6658 */
6659- while (atomic_read(&count_count_stop) != 1)
6660+ while (atomic_read_unchecked(&count_count_stop) != 1)
6661 mb();
6662- atomic_set(&count_count_start, 0);
6663+ atomic_set_unchecked(&count_count_start, 0);
6664 smp_wmb();
6665- atomic_inc(&count_count_stop);
6666+ atomic_inc_unchecked(&count_count_stop);
6667 }
6668 /* Arrange for an interrupt in a short while */
6669 write_c0_compare(read_c0_count() + COUNTON);
6670@@ -131,8 +131,8 @@ void synchronise_count_slave(int cpu)
6671 initcount = atomic_read(&count_reference);
6672
6673 for (i = 0; i < NR_LOOPS; i++) {
6674- atomic_inc(&count_count_start);
6675- while (atomic_read(&count_count_start) != 2)
6676+ atomic_inc_unchecked(&count_count_start);
6677+ while (atomic_read_unchecked(&count_count_start) != 2)
6678 mb();
6679
6680 /*
6681@@ -141,8 +141,8 @@ void synchronise_count_slave(int cpu)
6682 if (i == NR_LOOPS-1)
6683 write_c0_count(initcount);
6684
6685- atomic_inc(&count_count_stop);
6686- while (atomic_read(&count_count_stop) != 2)
6687+ atomic_inc_unchecked(&count_count_stop);
6688+ while (atomic_read_unchecked(&count_count_stop) != 2)
6689 mb();
6690 }
6691 /* Arrange for an interrupt in a short while */
6692diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
6693index aec3408..74d79d3 100644
6694--- a/arch/mips/kernel/traps.c
6695+++ b/arch/mips/kernel/traps.c
6696@@ -683,7 +683,18 @@ asmlinkage void do_ov(struct pt_regs *regs)
6697 siginfo_t info;
6698
6699 prev_state = exception_enter();
6700- die_if_kernel("Integer overflow", regs);
6701+ if (unlikely(!user_mode(regs))) {
6702+
6703+#ifdef CONFIG_PAX_REFCOUNT
6704+ if (fixup_exception(regs)) {
6705+ pax_report_refcount_overflow(regs);
6706+ exception_exit(prev_state);
6707+ return;
6708+ }
6709+#endif
6710+
6711+ die("Integer overflow", regs);
6712+ }
6713
6714 info.si_code = FPE_INTOVF;
6715 info.si_signo = SIGFPE;
6716diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
6717index 85df1cd..4f0a4de 100644
6718--- a/arch/mips/mm/fault.c
6719+++ b/arch/mips/mm/fault.c
6720@@ -28,6 +28,23 @@
6721 #include <asm/highmem.h> /* For VMALLOC_END */
6722 #include <linux/kdebug.h>
6723
6724+#ifdef CONFIG_PAX_PAGEEXEC
6725+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6726+{
6727+ unsigned long i;
6728+
6729+ printk(KERN_ERR "PAX: bytes at PC: ");
6730+ for (i = 0; i < 5; i++) {
6731+ unsigned int c;
6732+ if (get_user(c, (unsigned int *)pc+i))
6733+ printk(KERN_CONT "???????? ");
6734+ else
6735+ printk(KERN_CONT "%08x ", c);
6736+ }
6737+ printk("\n");
6738+}
6739+#endif
6740+
6741 /*
6742 * This routine handles page faults. It determines the address,
6743 * and the problem, and then passes it off to one of the appropriate
6744@@ -197,6 +214,14 @@ bad_area:
6745 bad_area_nosemaphore:
6746 /* User mode accesses just cause a SIGSEGV */
6747 if (user_mode(regs)) {
6748+
6749+#ifdef CONFIG_PAX_PAGEEXEC
6750+ if (cpu_has_rixi && (mm->pax_flags & MF_PAX_PAGEEXEC) && !write && address == instruction_pointer(regs)) {
6751+ pax_report_fault(regs, (void *)address, (void *)user_stack_pointer(regs));
6752+ do_group_exit(SIGKILL);
6753+ }
6754+#endif
6755+
6756 tsk->thread.cp0_badvaddr = address;
6757 tsk->thread.error_code = write;
6758 #if 0
6759diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
6760index f1baadd..8537544 100644
6761--- a/arch/mips/mm/mmap.c
6762+++ b/arch/mips/mm/mmap.c
6763@@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6764 struct vm_area_struct *vma;
6765 unsigned long addr = addr0;
6766 int do_color_align;
6767+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
6768 struct vm_unmapped_area_info info;
6769
6770 if (unlikely(len > TASK_SIZE))
6771@@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6772 do_color_align = 1;
6773
6774 /* requesting a specific address */
6775+
6776+#ifdef CONFIG_PAX_RANDMMAP
6777+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
6778+#endif
6779+
6780 if (addr) {
6781 if (do_color_align)
6782 addr = COLOUR_ALIGN(addr, pgoff);
6783@@ -91,14 +97,14 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6784 addr = PAGE_ALIGN(addr);
6785
6786 vma = find_vma(mm, addr);
6787- if (TASK_SIZE - len >= addr &&
6788- (!vma || addr + len <= vma->vm_start))
6789+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len, offset))
6790 return addr;
6791 }
6792
6793 info.length = len;
6794 info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;
6795 info.align_offset = pgoff << PAGE_SHIFT;
6796+ info.threadstack_offset = offset;
6797
6798 if (dir == DOWN) {
6799 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
6800@@ -146,6 +152,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6801 {
6802 unsigned long random_factor = 0UL;
6803
6804+#ifdef CONFIG_PAX_RANDMMAP
6805+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
6806+#endif
6807+
6808 if (current->flags & PF_RANDOMIZE) {
6809 random_factor = get_random_int();
6810 random_factor = random_factor << PAGE_SHIFT;
6811@@ -157,40 +167,25 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6812
6813 if (mmap_is_legacy()) {
6814 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
6815+
6816+#ifdef CONFIG_PAX_RANDMMAP
6817+ if (mm->pax_flags & MF_PAX_RANDMMAP)
6818+ mm->mmap_base += mm->delta_mmap;
6819+#endif
6820+
6821 mm->get_unmapped_area = arch_get_unmapped_area;
6822 } else {
6823 mm->mmap_base = mmap_base(random_factor);
6824+
6825+#ifdef CONFIG_PAX_RANDMMAP
6826+ if (mm->pax_flags & MF_PAX_RANDMMAP)
6827+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
6828+#endif
6829+
6830 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
6831 }
6832 }
6833
6834-static inline unsigned long brk_rnd(void)
6835-{
6836- unsigned long rnd = get_random_int();
6837-
6838- rnd = rnd << PAGE_SHIFT;
6839- /* 8MB for 32bit, 256MB for 64bit */
6840- if (TASK_IS_32BIT_ADDR)
6841- rnd = rnd & 0x7ffffful;
6842- else
6843- rnd = rnd & 0xffffffful;
6844-
6845- return rnd;
6846-}
6847-
6848-unsigned long arch_randomize_brk(struct mm_struct *mm)
6849-{
6850- unsigned long base = mm->brk;
6851- unsigned long ret;
6852-
6853- ret = PAGE_ALIGN(base + brk_rnd());
6854-
6855- if (ret < mm->brk)
6856- return mm->brk;
6857-
6858- return ret;
6859-}
6860-
6861 int __virt_addr_valid(const volatile void *kaddr)
6862 {
6863 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
6864diff --git a/arch/mips/sgi-ip27/ip27-nmi.c b/arch/mips/sgi-ip27/ip27-nmi.c
6865index a2358b4..7cead4f 100644
6866--- a/arch/mips/sgi-ip27/ip27-nmi.c
6867+++ b/arch/mips/sgi-ip27/ip27-nmi.c
6868@@ -187,9 +187,9 @@ void
6869 cont_nmi_dump(void)
6870 {
6871 #ifndef REAL_NMI_SIGNAL
6872- static atomic_t nmied_cpus = ATOMIC_INIT(0);
6873+ static atomic_unchecked_t nmied_cpus = ATOMIC_INIT(0);
6874
6875- atomic_inc(&nmied_cpus);
6876+ atomic_inc_unchecked(&nmied_cpus);
6877 #endif
6878 /*
6879 * Only allow 1 cpu to proceed
6880@@ -233,7 +233,7 @@ cont_nmi_dump(void)
6881 udelay(10000);
6882 }
6883 #else
6884- while (atomic_read(&nmied_cpus) != num_online_cpus());
6885+ while (atomic_read_unchecked(&nmied_cpus) != num_online_cpus());
6886 #endif
6887
6888 /*
6889diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
6890index 967d144..db12197 100644
6891--- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
6892+++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
6893@@ -11,12 +11,14 @@
6894 #ifndef _ASM_PROC_CACHE_H
6895 #define _ASM_PROC_CACHE_H
6896
6897+#include <linux/const.h>
6898+
6899 /* L1 cache */
6900
6901 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
6902 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
6903-#define L1_CACHE_BYTES 16 /* bytes per entry */
6904 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
6905+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
6906 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
6907
6908 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
6909diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
6910index bcb5df2..84fabd2 100644
6911--- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
6912+++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
6913@@ -16,13 +16,15 @@
6914 #ifndef _ASM_PROC_CACHE_H
6915 #define _ASM_PROC_CACHE_H
6916
6917+#include <linux/const.h>
6918+
6919 /*
6920 * L1 cache
6921 */
6922 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
6923 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
6924-#define L1_CACHE_BYTES 32 /* bytes per entry */
6925 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
6926+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
6927 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
6928
6929 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
6930diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
6931index 4ce7a01..449202a 100644
6932--- a/arch/openrisc/include/asm/cache.h
6933+++ b/arch/openrisc/include/asm/cache.h
6934@@ -19,11 +19,13 @@
6935 #ifndef __ASM_OPENRISC_CACHE_H
6936 #define __ASM_OPENRISC_CACHE_H
6937
6938+#include <linux/const.h>
6939+
6940 /* FIXME: How can we replace these with values from the CPU...
6941 * they shouldn't be hard-coded!
6942 */
6943
6944-#define L1_CACHE_BYTES 16
6945 #define L1_CACHE_SHIFT 4
6946+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6947
6948 #endif /* __ASM_OPENRISC_CACHE_H */
6949diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
6950index 472886c..00e7df9 100644
6951--- a/arch/parisc/include/asm/atomic.h
6952+++ b/arch/parisc/include/asm/atomic.h
6953@@ -252,6 +252,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
6954 return dec;
6955 }
6956
6957+#define atomic64_read_unchecked(v) atomic64_read(v)
6958+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
6959+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
6960+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
6961+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
6962+#define atomic64_inc_unchecked(v) atomic64_inc(v)
6963+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
6964+#define atomic64_dec_unchecked(v) atomic64_dec(v)
6965+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
6966+
6967 #endif /* !CONFIG_64BIT */
6968
6969
6970diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
6971index 47f11c7..3420df2 100644
6972--- a/arch/parisc/include/asm/cache.h
6973+++ b/arch/parisc/include/asm/cache.h
6974@@ -5,6 +5,7 @@
6975 #ifndef __ARCH_PARISC_CACHE_H
6976 #define __ARCH_PARISC_CACHE_H
6977
6978+#include <linux/const.h>
6979
6980 /*
6981 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
6982@@ -15,13 +16,13 @@
6983 * just ruin performance.
6984 */
6985 #ifdef CONFIG_PA20
6986-#define L1_CACHE_BYTES 64
6987 #define L1_CACHE_SHIFT 6
6988 #else
6989-#define L1_CACHE_BYTES 32
6990 #define L1_CACHE_SHIFT 5
6991 #endif
6992
6993+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6994+
6995 #ifndef __ASSEMBLY__
6996
6997 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6998diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
6999index ad2b503..bdf1651 100644
7000--- a/arch/parisc/include/asm/elf.h
7001+++ b/arch/parisc/include/asm/elf.h
7002@@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
7003
7004 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
7005
7006+#ifdef CONFIG_PAX_ASLR
7007+#define PAX_ELF_ET_DYN_BASE 0x10000UL
7008+
7009+#define PAX_DELTA_MMAP_LEN 16
7010+#define PAX_DELTA_STACK_LEN 16
7011+#endif
7012+
7013 /* This yields a mask that user programs can use to figure out what
7014 instruction set this CPU supports. This could be done in user space,
7015 but it's not easy, and we've already done it here. */
7016diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
7017index fc987a1..6e068ef 100644
7018--- a/arch/parisc/include/asm/pgalloc.h
7019+++ b/arch/parisc/include/asm/pgalloc.h
7020@@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7021 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
7022 }
7023
7024+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7025+{
7026+ pgd_populate(mm, pgd, pmd);
7027+}
7028+
7029 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
7030 {
7031 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
7032@@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
7033 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
7034 #define pmd_free(mm, x) do { } while (0)
7035 #define pgd_populate(mm, pmd, pte) BUG()
7036+#define pgd_populate_kernel(mm, pmd, pte) BUG()
7037
7038 #endif
7039
7040diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
7041index 34899b5..02dd060 100644
7042--- a/arch/parisc/include/asm/pgtable.h
7043+++ b/arch/parisc/include/asm/pgtable.h
7044@@ -223,6 +223,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
7045 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
7046 #define PAGE_COPY PAGE_EXECREAD
7047 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
7048+
7049+#ifdef CONFIG_PAX_PAGEEXEC
7050+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
7051+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7052+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7053+#else
7054+# define PAGE_SHARED_NOEXEC PAGE_SHARED
7055+# define PAGE_COPY_NOEXEC PAGE_COPY
7056+# define PAGE_READONLY_NOEXEC PAGE_READONLY
7057+#endif
7058+
7059 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
7060 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
7061 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
7062diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
7063index e0a8235..ce2f1e1 100644
7064--- a/arch/parisc/include/asm/uaccess.h
7065+++ b/arch/parisc/include/asm/uaccess.h
7066@@ -245,10 +245,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
7067 const void __user *from,
7068 unsigned long n)
7069 {
7070- int sz = __compiletime_object_size(to);
7071+ size_t sz = __compiletime_object_size(to);
7072 int ret = -EFAULT;
7073
7074- if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
7075+ if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
7076 ret = __copy_from_user(to, from, n);
7077 else
7078 copy_from_user_overflow();
7079diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
7080index 2a625fb..9908930 100644
7081--- a/arch/parisc/kernel/module.c
7082+++ b/arch/parisc/kernel/module.c
7083@@ -98,16 +98,38 @@
7084
7085 /* three functions to determine where in the module core
7086 * or init pieces the location is */
7087+static inline int in_init_rx(struct module *me, void *loc)
7088+{
7089+ return (loc >= me->module_init_rx &&
7090+ loc < (me->module_init_rx + me->init_size_rx));
7091+}
7092+
7093+static inline int in_init_rw(struct module *me, void *loc)
7094+{
7095+ return (loc >= me->module_init_rw &&
7096+ loc < (me->module_init_rw + me->init_size_rw));
7097+}
7098+
7099 static inline int in_init(struct module *me, void *loc)
7100 {
7101- return (loc >= me->module_init &&
7102- loc <= (me->module_init + me->init_size));
7103+ return in_init_rx(me, loc) || in_init_rw(me, loc);
7104+}
7105+
7106+static inline int in_core_rx(struct module *me, void *loc)
7107+{
7108+ return (loc >= me->module_core_rx &&
7109+ loc < (me->module_core_rx + me->core_size_rx));
7110+}
7111+
7112+static inline int in_core_rw(struct module *me, void *loc)
7113+{
7114+ return (loc >= me->module_core_rw &&
7115+ loc < (me->module_core_rw + me->core_size_rw));
7116 }
7117
7118 static inline int in_core(struct module *me, void *loc)
7119 {
7120- return (loc >= me->module_core &&
7121- loc <= (me->module_core + me->core_size));
7122+ return in_core_rx(me, loc) || in_core_rw(me, loc);
7123 }
7124
7125 static inline int in_local(struct module *me, void *loc)
7126@@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
7127 }
7128
7129 /* align things a bit */
7130- me->core_size = ALIGN(me->core_size, 16);
7131- me->arch.got_offset = me->core_size;
7132- me->core_size += gots * sizeof(struct got_entry);
7133+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
7134+ me->arch.got_offset = me->core_size_rw;
7135+ me->core_size_rw += gots * sizeof(struct got_entry);
7136
7137- me->core_size = ALIGN(me->core_size, 16);
7138- me->arch.fdesc_offset = me->core_size;
7139- me->core_size += fdescs * sizeof(Elf_Fdesc);
7140+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
7141+ me->arch.fdesc_offset = me->core_size_rw;
7142+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
7143
7144 me->arch.got_max = gots;
7145 me->arch.fdesc_max = fdescs;
7146@@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7147
7148 BUG_ON(value == 0);
7149
7150- got = me->module_core + me->arch.got_offset;
7151+ got = me->module_core_rw + me->arch.got_offset;
7152 for (i = 0; got[i].addr; i++)
7153 if (got[i].addr == value)
7154 goto out;
7155@@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7156 #ifdef CONFIG_64BIT
7157 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7158 {
7159- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
7160+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
7161
7162 if (!value) {
7163 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
7164@@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7165
7166 /* Create new one */
7167 fdesc->addr = value;
7168- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7169+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7170 return (Elf_Addr)fdesc;
7171 }
7172 #endif /* CONFIG_64BIT */
7173@@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
7174
7175 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
7176 end = table + sechdrs[me->arch.unwind_section].sh_size;
7177- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7178+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7179
7180 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
7181 me->arch.unwind_section, table, end, gp);
7182diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
7183index 5dfd248..64914ac 100644
7184--- a/arch/parisc/kernel/sys_parisc.c
7185+++ b/arch/parisc/kernel/sys_parisc.c
7186@@ -33,9 +33,11 @@
7187 #include <linux/utsname.h>
7188 #include <linux/personality.h>
7189
7190-static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
7191+static unsigned long get_unshared_area(struct file *filp, unsigned long addr, unsigned long len,
7192+ unsigned long flags)
7193 {
7194 struct vm_unmapped_area_info info;
7195+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7196
7197 info.flags = 0;
7198 info.length = len;
7199@@ -43,6 +45,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
7200 info.high_limit = TASK_SIZE;
7201 info.align_mask = 0;
7202 info.align_offset = 0;
7203+ info.threadstack_offset = offset;
7204 return vm_unmapped_area(&info);
7205 }
7206
7207@@ -61,10 +64,11 @@ static int get_offset(struct address_space *mapping)
7208 return (unsigned long) mapping >> 8;
7209 }
7210
7211-static unsigned long get_shared_area(struct address_space *mapping,
7212- unsigned long addr, unsigned long len, unsigned long pgoff)
7213+static unsigned long get_shared_area(struct file *filp, struct address_space *mapping,
7214+ unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags)
7215 {
7216 struct vm_unmapped_area_info info;
7217+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7218
7219 info.flags = 0;
7220 info.length = len;
7221@@ -72,6 +76,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
7222 info.high_limit = TASK_SIZE;
7223 info.align_mask = PAGE_MASK & (SHMLBA - 1);
7224 info.align_offset = (get_offset(mapping) + pgoff) << PAGE_SHIFT;
7225+ info.threadstack_offset = offset;
7226 return vm_unmapped_area(&info);
7227 }
7228
7229@@ -86,15 +91,22 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7230 return -EINVAL;
7231 return addr;
7232 }
7233- if (!addr)
7234+ if (!addr) {
7235 addr = TASK_UNMAPPED_BASE;
7236
7237+#ifdef CONFIG_PAX_RANDMMAP
7238+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
7239+ addr += current->mm->delta_mmap;
7240+#endif
7241+
7242+ }
7243+
7244 if (filp) {
7245- addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
7246+ addr = get_shared_area(filp, filp->f_mapping, addr, len, pgoff, flags);
7247 } else if(flags & MAP_SHARED) {
7248- addr = get_shared_area(NULL, addr, len, pgoff);
7249+ addr = get_shared_area(filp, NULL, addr, len, pgoff, flags);
7250 } else {
7251- addr = get_unshared_area(addr, len);
7252+ addr = get_unshared_area(filp, addr, len, flags);
7253 }
7254 return addr;
7255 }
7256diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
7257index 04e47c6..7a8faf6 100644
7258--- a/arch/parisc/kernel/traps.c
7259+++ b/arch/parisc/kernel/traps.c
7260@@ -727,9 +727,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
7261
7262 down_read(&current->mm->mmap_sem);
7263 vma = find_vma(current->mm,regs->iaoq[0]);
7264- if (vma && (regs->iaoq[0] >= vma->vm_start)
7265- && (vma->vm_flags & VM_EXEC)) {
7266-
7267+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
7268 fault_address = regs->iaoq[0];
7269 fault_space = regs->iasq[0];
7270
7271diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
7272index f247a34..dc0f219 100644
7273--- a/arch/parisc/mm/fault.c
7274+++ b/arch/parisc/mm/fault.c
7275@@ -15,6 +15,7 @@
7276 #include <linux/sched.h>
7277 #include <linux/interrupt.h>
7278 #include <linux/module.h>
7279+#include <linux/unistd.h>
7280
7281 #include <asm/uaccess.h>
7282 #include <asm/traps.h>
7283@@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
7284 static unsigned long
7285 parisc_acctyp(unsigned long code, unsigned int inst)
7286 {
7287- if (code == 6 || code == 16)
7288+ if (code == 6 || code == 7 || code == 16)
7289 return VM_EXEC;
7290
7291 switch (inst & 0xf0000000) {
7292@@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
7293 }
7294 #endif
7295
7296+#ifdef CONFIG_PAX_PAGEEXEC
7297+/*
7298+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
7299+ *
7300+ * returns 1 when task should be killed
7301+ * 2 when rt_sigreturn trampoline was detected
7302+ * 3 when unpatched PLT trampoline was detected
7303+ */
7304+static int pax_handle_fetch_fault(struct pt_regs *regs)
7305+{
7306+
7307+#ifdef CONFIG_PAX_EMUPLT
7308+ int err;
7309+
7310+ do { /* PaX: unpatched PLT emulation */
7311+ unsigned int bl, depwi;
7312+
7313+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
7314+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
7315+
7316+ if (err)
7317+ break;
7318+
7319+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
7320+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
7321+
7322+ err = get_user(ldw, (unsigned int *)addr);
7323+ err |= get_user(bv, (unsigned int *)(addr+4));
7324+ err |= get_user(ldw2, (unsigned int *)(addr+8));
7325+
7326+ if (err)
7327+ break;
7328+
7329+ if (ldw == 0x0E801096U &&
7330+ bv == 0xEAC0C000U &&
7331+ ldw2 == 0x0E881095U)
7332+ {
7333+ unsigned int resolver, map;
7334+
7335+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
7336+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
7337+ if (err)
7338+ break;
7339+
7340+ regs->gr[20] = instruction_pointer(regs)+8;
7341+ regs->gr[21] = map;
7342+ regs->gr[22] = resolver;
7343+ regs->iaoq[0] = resolver | 3UL;
7344+ regs->iaoq[1] = regs->iaoq[0] + 4;
7345+ return 3;
7346+ }
7347+ }
7348+ } while (0);
7349+#endif
7350+
7351+#ifdef CONFIG_PAX_EMUTRAMP
7352+
7353+#ifndef CONFIG_PAX_EMUSIGRT
7354+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
7355+ return 1;
7356+#endif
7357+
7358+ do { /* PaX: rt_sigreturn emulation */
7359+ unsigned int ldi1, ldi2, bel, nop;
7360+
7361+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
7362+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
7363+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
7364+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
7365+
7366+ if (err)
7367+ break;
7368+
7369+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
7370+ ldi2 == 0x3414015AU &&
7371+ bel == 0xE4008200U &&
7372+ nop == 0x08000240U)
7373+ {
7374+ regs->gr[25] = (ldi1 & 2) >> 1;
7375+ regs->gr[20] = __NR_rt_sigreturn;
7376+ regs->gr[31] = regs->iaoq[1] + 16;
7377+ regs->sr[0] = regs->iasq[1];
7378+ regs->iaoq[0] = 0x100UL;
7379+ regs->iaoq[1] = regs->iaoq[0] + 4;
7380+ regs->iasq[0] = regs->sr[2];
7381+ regs->iasq[1] = regs->sr[2];
7382+ return 2;
7383+ }
7384+ } while (0);
7385+#endif
7386+
7387+ return 1;
7388+}
7389+
7390+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7391+{
7392+ unsigned long i;
7393+
7394+ printk(KERN_ERR "PAX: bytes at PC: ");
7395+ for (i = 0; i < 5; i++) {
7396+ unsigned int c;
7397+ if (get_user(c, (unsigned int *)pc+i))
7398+ printk(KERN_CONT "???????? ");
7399+ else
7400+ printk(KERN_CONT "%08x ", c);
7401+ }
7402+ printk("\n");
7403+}
7404+#endif
7405+
7406 int fixup_exception(struct pt_regs *regs)
7407 {
7408 const struct exception_table_entry *fix;
7409@@ -194,8 +305,33 @@ good_area:
7410
7411 acc_type = parisc_acctyp(code,regs->iir);
7412
7413- if ((vma->vm_flags & acc_type) != acc_type)
7414+ if ((vma->vm_flags & acc_type) != acc_type) {
7415+
7416+#ifdef CONFIG_PAX_PAGEEXEC
7417+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
7418+ (address & ~3UL) == instruction_pointer(regs))
7419+ {
7420+ up_read(&mm->mmap_sem);
7421+ switch (pax_handle_fetch_fault(regs)) {
7422+
7423+#ifdef CONFIG_PAX_EMUPLT
7424+ case 3:
7425+ return;
7426+#endif
7427+
7428+#ifdef CONFIG_PAX_EMUTRAMP
7429+ case 2:
7430+ return;
7431+#endif
7432+
7433+ }
7434+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
7435+ do_group_exit(SIGKILL);
7436+ }
7437+#endif
7438+
7439 goto bad_area;
7440+ }
7441
7442 /*
7443 * If for any reason at all we couldn't handle the fault, make
7444diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
7445index e3b1d41..8e81edf 100644
7446--- a/arch/powerpc/include/asm/atomic.h
7447+++ b/arch/powerpc/include/asm/atomic.h
7448@@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
7449 return t1;
7450 }
7451
7452+#define atomic64_read_unchecked(v) atomic64_read(v)
7453+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7454+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7455+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7456+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7457+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7458+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7459+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7460+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7461+
7462 #endif /* __powerpc64__ */
7463
7464 #endif /* __KERNEL__ */
7465diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
7466index 9e495c9..b6878e5 100644
7467--- a/arch/powerpc/include/asm/cache.h
7468+++ b/arch/powerpc/include/asm/cache.h
7469@@ -3,6 +3,7 @@
7470
7471 #ifdef __KERNEL__
7472
7473+#include <linux/const.h>
7474
7475 /* bytes per L1 cache line */
7476 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
7477@@ -22,7 +23,7 @@
7478 #define L1_CACHE_SHIFT 7
7479 #endif
7480
7481-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7482+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7483
7484 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7485
7486diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
7487index cc0655a..13eac2e 100644
7488--- a/arch/powerpc/include/asm/elf.h
7489+++ b/arch/powerpc/include/asm/elf.h
7490@@ -28,8 +28,19 @@
7491 the loader. We need to make sure that it is out of the way of the program
7492 that it will "exec", and that there is sufficient room for the brk. */
7493
7494-extern unsigned long randomize_et_dyn(unsigned long base);
7495-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
7496+#define ELF_ET_DYN_BASE (0x20000000)
7497+
7498+#ifdef CONFIG_PAX_ASLR
7499+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
7500+
7501+#ifdef __powerpc64__
7502+#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
7503+#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
7504+#else
7505+#define PAX_DELTA_MMAP_LEN 15
7506+#define PAX_DELTA_STACK_LEN 15
7507+#endif
7508+#endif
7509
7510 /*
7511 * Our registers are always unsigned longs, whether we're a 32 bit
7512@@ -123,10 +134,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
7513 (0x7ff >> (PAGE_SHIFT - 12)) : \
7514 (0x3ffff >> (PAGE_SHIFT - 12)))
7515
7516-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
7517-#define arch_randomize_brk arch_randomize_brk
7518-
7519-
7520 #ifdef CONFIG_SPU_BASE
7521 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
7522 #define NT_SPU 1
7523diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
7524index 8196e9c..d83a9f3 100644
7525--- a/arch/powerpc/include/asm/exec.h
7526+++ b/arch/powerpc/include/asm/exec.h
7527@@ -4,6 +4,6 @@
7528 #ifndef _ASM_POWERPC_EXEC_H
7529 #define _ASM_POWERPC_EXEC_H
7530
7531-extern unsigned long arch_align_stack(unsigned long sp);
7532+#define arch_align_stack(x) ((x) & ~0xfUL)
7533
7534 #endif /* _ASM_POWERPC_EXEC_H */
7535diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
7536index 5acabbd..7ea14fa 100644
7537--- a/arch/powerpc/include/asm/kmap_types.h
7538+++ b/arch/powerpc/include/asm/kmap_types.h
7539@@ -10,7 +10,7 @@
7540 * 2 of the License, or (at your option) any later version.
7541 */
7542
7543-#define KM_TYPE_NR 16
7544+#define KM_TYPE_NR 17
7545
7546 #endif /* __KERNEL__ */
7547 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
7548diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
7549index 8565c25..2865190 100644
7550--- a/arch/powerpc/include/asm/mman.h
7551+++ b/arch/powerpc/include/asm/mman.h
7552@@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
7553 }
7554 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
7555
7556-static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
7557+static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
7558 {
7559 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
7560 }
7561diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
7562index b9f4262..dcf04f7 100644
7563--- a/arch/powerpc/include/asm/page.h
7564+++ b/arch/powerpc/include/asm/page.h
7565@@ -230,8 +230,9 @@ extern long long virt_phys_offset;
7566 * and needs to be executable. This means the whole heap ends
7567 * up being executable.
7568 */
7569-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
7570- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7571+#define VM_DATA_DEFAULT_FLAGS32 \
7572+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
7573+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7574
7575 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
7576 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7577@@ -259,6 +260,9 @@ extern long long virt_phys_offset;
7578 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
7579 #endif
7580
7581+#define ktla_ktva(addr) (addr)
7582+#define ktva_ktla(addr) (addr)
7583+
7584 #ifndef CONFIG_PPC_BOOK3S_64
7585 /*
7586 * Use the top bit of the higher-level page table entries to indicate whether
7587diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
7588index 88693ce..ac6f9ab 100644
7589--- a/arch/powerpc/include/asm/page_64.h
7590+++ b/arch/powerpc/include/asm/page_64.h
7591@@ -153,15 +153,18 @@ do { \
7592 * stack by default, so in the absence of a PT_GNU_STACK program header
7593 * we turn execute permission off.
7594 */
7595-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
7596- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7597+#define VM_STACK_DEFAULT_FLAGS32 \
7598+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
7599+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7600
7601 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
7602 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7603
7604+#ifndef CONFIG_PAX_PAGEEXEC
7605 #define VM_STACK_DEFAULT_FLAGS \
7606 (is_32bit_task() ? \
7607 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
7608+#endif
7609
7610 #include <asm-generic/getorder.h>
7611
7612diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
7613index f65e27b..23ffb5b 100644
7614--- a/arch/powerpc/include/asm/pgalloc-64.h
7615+++ b/arch/powerpc/include/asm/pgalloc-64.h
7616@@ -53,6 +53,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
7617 #ifndef CONFIG_PPC_64K_PAGES
7618
7619 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
7620+#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
7621
7622 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
7623 {
7624@@ -70,6 +71,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
7625 pud_set(pud, (unsigned long)pmd);
7626 }
7627
7628+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
7629+{
7630+ pud_populate(mm, pud, pmd);
7631+}
7632+
7633 #define pmd_populate(mm, pmd, pte_page) \
7634 pmd_populate_kernel(mm, pmd, page_address(pte_page))
7635 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
7636@@ -171,6 +177,7 @@ extern void __tlb_remove_table(void *_table);
7637 #endif
7638
7639 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
7640+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
7641
7642 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
7643 pte_t *pte)
7644diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
7645index 7d6eacf..14c0240 100644
7646--- a/arch/powerpc/include/asm/pgtable.h
7647+++ b/arch/powerpc/include/asm/pgtable.h
7648@@ -2,6 +2,7 @@
7649 #define _ASM_POWERPC_PGTABLE_H
7650 #ifdef __KERNEL__
7651
7652+#include <linux/const.h>
7653 #ifndef __ASSEMBLY__
7654 #include <asm/processor.h> /* For TASK_SIZE */
7655 #include <asm/mmu.h>
7656diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
7657index 4aad413..85d86bf 100644
7658--- a/arch/powerpc/include/asm/pte-hash32.h
7659+++ b/arch/powerpc/include/asm/pte-hash32.h
7660@@ -21,6 +21,7 @@
7661 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
7662 #define _PAGE_USER 0x004 /* usermode access allowed */
7663 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
7664+#define _PAGE_EXEC _PAGE_GUARDED
7665 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
7666 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
7667 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
7668diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
7669index 99222e2..f629aef 100644
7670--- a/arch/powerpc/include/asm/reg.h
7671+++ b/arch/powerpc/include/asm/reg.h
7672@@ -234,6 +234,7 @@
7673 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
7674 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
7675 #define DSISR_NOHPTE 0x40000000 /* no translation found */
7676+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
7677 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
7678 #define DSISR_ISSTORE 0x02000000 /* access was a store */
7679 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
7680diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
7681index 48cfc85..891382f 100644
7682--- a/arch/powerpc/include/asm/smp.h
7683+++ b/arch/powerpc/include/asm/smp.h
7684@@ -50,7 +50,7 @@ struct smp_ops_t {
7685 int (*cpu_disable)(void);
7686 void (*cpu_die)(unsigned int nr);
7687 int (*cpu_bootable)(unsigned int nr);
7688-};
7689+} __no_const;
7690
7691 extern void smp_send_debugger_break(void);
7692 extern void start_secondary_resume(void);
7693diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
7694index ba7b197..d292e26 100644
7695--- a/arch/powerpc/include/asm/thread_info.h
7696+++ b/arch/powerpc/include/asm/thread_info.h
7697@@ -93,7 +93,6 @@ static inline struct thread_info *current_thread_info(void)
7698 #define TIF_POLLING_NRFLAG 3 /* true if poll_idle() is polling
7699 TIF_NEED_RESCHED */
7700 #define TIF_32BIT 4 /* 32 bit binary */
7701-#define TIF_PERFMON_WORK 5 /* work for pfm_handle_work() */
7702 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
7703 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
7704 #define TIF_SINGLESTEP 8 /* singlestepping active */
7705@@ -107,6 +106,9 @@ static inline struct thread_info *current_thread_info(void)
7706 #define TIF_EMULATE_STACK_STORE 16 /* Is an instruction emulation
7707 for stack store? */
7708 #define TIF_MEMDIE 17 /* is terminating due to OOM killer */
7709+#define TIF_PERFMON_WORK 18 /* work for pfm_handle_work() */
7710+/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
7711+#define TIF_GRSEC_SETXID 5 /* update credentials on syscall entry/exit */
7712
7713 /* as above, but as bit values */
7714 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
7715@@ -126,9 +128,10 @@ static inline struct thread_info *current_thread_info(void)
7716 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
7717 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
7718 #define _TIF_NOHZ (1<<TIF_NOHZ)
7719+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
7720 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
7721 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
7722- _TIF_NOHZ)
7723+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
7724
7725 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
7726 _TIF_NOTIFY_RESUME | _TIF_UPROBE)
7727diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
7728index 9485b43..4718d50 100644
7729--- a/arch/powerpc/include/asm/uaccess.h
7730+++ b/arch/powerpc/include/asm/uaccess.h
7731@@ -318,52 +318,6 @@ do { \
7732 extern unsigned long __copy_tofrom_user(void __user *to,
7733 const void __user *from, unsigned long size);
7734
7735-#ifndef __powerpc64__
7736-
7737-static inline unsigned long copy_from_user(void *to,
7738- const void __user *from, unsigned long n)
7739-{
7740- unsigned long over;
7741-
7742- if (access_ok(VERIFY_READ, from, n))
7743- return __copy_tofrom_user((__force void __user *)to, from, n);
7744- if ((unsigned long)from < TASK_SIZE) {
7745- over = (unsigned long)from + n - TASK_SIZE;
7746- return __copy_tofrom_user((__force void __user *)to, from,
7747- n - over) + over;
7748- }
7749- return n;
7750-}
7751-
7752-static inline unsigned long copy_to_user(void __user *to,
7753- const void *from, unsigned long n)
7754-{
7755- unsigned long over;
7756-
7757- if (access_ok(VERIFY_WRITE, to, n))
7758- return __copy_tofrom_user(to, (__force void __user *)from, n);
7759- if ((unsigned long)to < TASK_SIZE) {
7760- over = (unsigned long)to + n - TASK_SIZE;
7761- return __copy_tofrom_user(to, (__force void __user *)from,
7762- n - over) + over;
7763- }
7764- return n;
7765-}
7766-
7767-#else /* __powerpc64__ */
7768-
7769-#define __copy_in_user(to, from, size) \
7770- __copy_tofrom_user((to), (from), (size))
7771-
7772-extern unsigned long copy_from_user(void *to, const void __user *from,
7773- unsigned long n);
7774-extern unsigned long copy_to_user(void __user *to, const void *from,
7775- unsigned long n);
7776-extern unsigned long copy_in_user(void __user *to, const void __user *from,
7777- unsigned long n);
7778-
7779-#endif /* __powerpc64__ */
7780-
7781 static inline unsigned long __copy_from_user_inatomic(void *to,
7782 const void __user *from, unsigned long n)
7783 {
7784@@ -387,6 +341,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
7785 if (ret == 0)
7786 return 0;
7787 }
7788+
7789+ if (!__builtin_constant_p(n))
7790+ check_object_size(to, n, false);
7791+
7792 return __copy_tofrom_user((__force void __user *)to, from, n);
7793 }
7794
7795@@ -413,6 +371,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
7796 if (ret == 0)
7797 return 0;
7798 }
7799+
7800+ if (!__builtin_constant_p(n))
7801+ check_object_size(from, n, true);
7802+
7803 return __copy_tofrom_user(to, (__force const void __user *)from, n);
7804 }
7805
7806@@ -430,6 +392,92 @@ static inline unsigned long __copy_to_user(void __user *to,
7807 return __copy_to_user_inatomic(to, from, size);
7808 }
7809
7810+#ifndef __powerpc64__
7811+
7812+static inline unsigned long __must_check copy_from_user(void *to,
7813+ const void __user *from, unsigned long n)
7814+{
7815+ unsigned long over;
7816+
7817+ if ((long)n < 0)
7818+ return n;
7819+
7820+ if (access_ok(VERIFY_READ, from, n)) {
7821+ if (!__builtin_constant_p(n))
7822+ check_object_size(to, n, false);
7823+ return __copy_tofrom_user((__force void __user *)to, from, n);
7824+ }
7825+ if ((unsigned long)from < TASK_SIZE) {
7826+ over = (unsigned long)from + n - TASK_SIZE;
7827+ if (!__builtin_constant_p(n - over))
7828+ check_object_size(to, n - over, false);
7829+ return __copy_tofrom_user((__force void __user *)to, from,
7830+ n - over) + over;
7831+ }
7832+ return n;
7833+}
7834+
7835+static inline unsigned long __must_check copy_to_user(void __user *to,
7836+ const void *from, unsigned long n)
7837+{
7838+ unsigned long over;
7839+
7840+ if ((long)n < 0)
7841+ return n;
7842+
7843+ if (access_ok(VERIFY_WRITE, to, n)) {
7844+ if (!__builtin_constant_p(n))
7845+ check_object_size(from, n, true);
7846+ return __copy_tofrom_user(to, (__force void __user *)from, n);
7847+ }
7848+ if ((unsigned long)to < TASK_SIZE) {
7849+ over = (unsigned long)to + n - TASK_SIZE;
7850+ if (!__builtin_constant_p(n))
7851+ check_object_size(from, n - over, true);
7852+ return __copy_tofrom_user(to, (__force void __user *)from,
7853+ n - over) + over;
7854+ }
7855+ return n;
7856+}
7857+
7858+#else /* __powerpc64__ */
7859+
7860+#define __copy_in_user(to, from, size) \
7861+ __copy_tofrom_user((to), (from), (size))
7862+
7863+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
7864+{
7865+ if ((long)n < 0 || n > INT_MAX)
7866+ return n;
7867+
7868+ if (!__builtin_constant_p(n))
7869+ check_object_size(to, n, false);
7870+
7871+ if (likely(access_ok(VERIFY_READ, from, n)))
7872+ n = __copy_from_user(to, from, n);
7873+ else
7874+ memset(to, 0, n);
7875+ return n;
7876+}
7877+
7878+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
7879+{
7880+ if ((long)n < 0 || n > INT_MAX)
7881+ return n;
7882+
7883+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
7884+ if (!__builtin_constant_p(n))
7885+ check_object_size(from, n, true);
7886+ n = __copy_to_user(to, from, n);
7887+ }
7888+ return n;
7889+}
7890+
7891+extern unsigned long copy_in_user(void __user *to, const void __user *from,
7892+ unsigned long n);
7893+
7894+#endif /* __powerpc64__ */
7895+
7896 extern unsigned long __clear_user(void __user *addr, unsigned long size);
7897
7898 static inline unsigned long clear_user(void __user *addr, unsigned long size)
7899diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
7900index 645170a..6cf0271 100644
7901--- a/arch/powerpc/kernel/exceptions-64e.S
7902+++ b/arch/powerpc/kernel/exceptions-64e.S
7903@@ -757,6 +757,7 @@ storage_fault_common:
7904 std r14,_DAR(r1)
7905 std r15,_DSISR(r1)
7906 addi r3,r1,STACK_FRAME_OVERHEAD
7907+ bl .save_nvgprs
7908 mr r4,r14
7909 mr r5,r15
7910 ld r14,PACA_EXGEN+EX_R14(r13)
7911@@ -765,8 +766,7 @@ storage_fault_common:
7912 cmpdi r3,0
7913 bne- 1f
7914 b .ret_from_except_lite
7915-1: bl .save_nvgprs
7916- mr r5,r3
7917+1: mr r5,r3
7918 addi r3,r1,STACK_FRAME_OVERHEAD
7919 ld r4,_DAR(r1)
7920 bl .bad_page_fault
7921diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
7922index 902ca3c..e942155 100644
7923--- a/arch/powerpc/kernel/exceptions-64s.S
7924+++ b/arch/powerpc/kernel/exceptions-64s.S
7925@@ -1357,10 +1357,10 @@ handle_page_fault:
7926 11: ld r4,_DAR(r1)
7927 ld r5,_DSISR(r1)
7928 addi r3,r1,STACK_FRAME_OVERHEAD
7929+ bl .save_nvgprs
7930 bl .do_page_fault
7931 cmpdi r3,0
7932 beq+ 12f
7933- bl .save_nvgprs
7934 mr r5,r3
7935 addi r3,r1,STACK_FRAME_OVERHEAD
7936 lwz r4,_DAR(r1)
7937diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
7938index 2e3200c..72095ce 100644
7939--- a/arch/powerpc/kernel/module_32.c
7940+++ b/arch/powerpc/kernel/module_32.c
7941@@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
7942 me->arch.core_plt_section = i;
7943 }
7944 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
7945- printk("Module doesn't contain .plt or .init.plt sections.\n");
7946+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
7947 return -ENOEXEC;
7948 }
7949
7950@@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
7951
7952 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
7953 /* Init, or core PLT? */
7954- if (location >= mod->module_core
7955- && location < mod->module_core + mod->core_size)
7956+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
7957+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
7958 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
7959- else
7960+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
7961+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
7962 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
7963+ else {
7964+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
7965+ return ~0UL;
7966+ }
7967
7968 /* Find this entry, or if that fails, the next avail. entry */
7969 while (entry->jump[0]) {
7970diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
7971index 8083be2..10aa352 100644
7972--- a/arch/powerpc/kernel/process.c
7973+++ b/arch/powerpc/kernel/process.c
7974@@ -884,8 +884,8 @@ void show_regs(struct pt_regs * regs)
7975 * Lookup NIP late so we have the best change of getting the
7976 * above info out without failing
7977 */
7978- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
7979- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
7980+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
7981+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
7982 #endif
7983 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
7984 printk("PACATMSCRATCH [%llx]\n", get_paca()->tm_scratch);
7985@@ -1349,10 +1349,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
7986 newsp = stack[0];
7987 ip = stack[STACK_FRAME_LR_SAVE];
7988 if (!firstframe || ip != lr) {
7989- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
7990+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
7991 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
7992 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
7993- printk(" (%pS)",
7994+ printk(" (%pA)",
7995 (void *)current->ret_stack[curr_frame].ret);
7996 curr_frame--;
7997 }
7998@@ -1372,7 +1372,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
7999 struct pt_regs *regs = (struct pt_regs *)
8000 (sp + STACK_FRAME_OVERHEAD);
8001 lr = regs->link;
8002- printk("--- Exception: %lx at %pS\n LR = %pS\n",
8003+ printk("--- Exception: %lx at %pA\n LR = %pA\n",
8004 regs->trap, (void *)regs->nip, (void *)lr);
8005 firstframe = 1;
8006 }
8007@@ -1408,58 +1408,3 @@ void notrace __ppc64_runlatch_off(void)
8008 mtspr(SPRN_CTRLT, ctrl);
8009 }
8010 #endif /* CONFIG_PPC64 */
8011-
8012-unsigned long arch_align_stack(unsigned long sp)
8013-{
8014- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8015- sp -= get_random_int() & ~PAGE_MASK;
8016- return sp & ~0xf;
8017-}
8018-
8019-static inline unsigned long brk_rnd(void)
8020-{
8021- unsigned long rnd = 0;
8022-
8023- /* 8MB for 32bit, 1GB for 64bit */
8024- if (is_32bit_task())
8025- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
8026- else
8027- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
8028-
8029- return rnd << PAGE_SHIFT;
8030-}
8031-
8032-unsigned long arch_randomize_brk(struct mm_struct *mm)
8033-{
8034- unsigned long base = mm->brk;
8035- unsigned long ret;
8036-
8037-#ifdef CONFIG_PPC_STD_MMU_64
8038- /*
8039- * If we are using 1TB segments and we are allowed to randomise
8040- * the heap, we can put it above 1TB so it is backed by a 1TB
8041- * segment. Otherwise the heap will be in the bottom 1TB
8042- * which always uses 256MB segments and this may result in a
8043- * performance penalty.
8044- */
8045- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
8046- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
8047-#endif
8048-
8049- ret = PAGE_ALIGN(base + brk_rnd());
8050-
8051- if (ret < mm->brk)
8052- return mm->brk;
8053-
8054- return ret;
8055-}
8056-
8057-unsigned long randomize_et_dyn(unsigned long base)
8058-{
8059- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
8060-
8061- if (ret < base)
8062- return base;
8063-
8064- return ret;
8065-}
8066diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
8067index 9a0d24c..e7fbedf 100644
8068--- a/arch/powerpc/kernel/ptrace.c
8069+++ b/arch/powerpc/kernel/ptrace.c
8070@@ -1761,6 +1761,10 @@ long arch_ptrace(struct task_struct *child, long request,
8071 return ret;
8072 }
8073
8074+#ifdef CONFIG_GRKERNSEC_SETXID
8075+extern void gr_delayed_cred_worker(void);
8076+#endif
8077+
8078 /*
8079 * We must return the syscall number to actually look up in the table.
8080 * This can be -1L to skip running any syscall at all.
8081@@ -1773,6 +1777,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
8082
8083 secure_computing_strict(regs->gpr[0]);
8084
8085+#ifdef CONFIG_GRKERNSEC_SETXID
8086+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8087+ gr_delayed_cred_worker();
8088+#endif
8089+
8090 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
8091 tracehook_report_syscall_entry(regs))
8092 /*
8093@@ -1807,6 +1816,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
8094 {
8095 int step;
8096
8097+#ifdef CONFIG_GRKERNSEC_SETXID
8098+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8099+ gr_delayed_cred_worker();
8100+#endif
8101+
8102 audit_syscall_exit(regs);
8103
8104 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
8105diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
8106index 0f83122..c0aca6a 100644
8107--- a/arch/powerpc/kernel/signal_32.c
8108+++ b/arch/powerpc/kernel/signal_32.c
8109@@ -987,7 +987,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
8110 /* Save user registers on the stack */
8111 frame = &rt_sf->uc.uc_mcontext;
8112 addr = frame;
8113- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
8114+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8115 sigret = 0;
8116 tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp;
8117 } else {
8118diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
8119index 887e99d..310bc11 100644
8120--- a/arch/powerpc/kernel/signal_64.c
8121+++ b/arch/powerpc/kernel/signal_64.c
8122@@ -751,7 +751,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
8123 #endif
8124
8125 /* Set up to return from userspace. */
8126- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
8127+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8128 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
8129 } else {
8130 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
8131diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
8132index e435bc0..41c2964 100644
8133--- a/arch/powerpc/kernel/traps.c
8134+++ b/arch/powerpc/kernel/traps.c
8135@@ -141,6 +141,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
8136 return flags;
8137 }
8138
8139+extern void gr_handle_kernel_exploit(void);
8140+
8141 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8142 int signr)
8143 {
8144@@ -190,6 +192,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8145 panic("Fatal exception in interrupt");
8146 if (panic_on_oops)
8147 panic("Fatal exception");
8148+
8149+ gr_handle_kernel_exploit();
8150+
8151 do_exit(signr);
8152 }
8153
8154diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
8155index 1d9c926..25f4741 100644
8156--- a/arch/powerpc/kernel/vdso.c
8157+++ b/arch/powerpc/kernel/vdso.c
8158@@ -34,6 +34,7 @@
8159 #include <asm/firmware.h>
8160 #include <asm/vdso.h>
8161 #include <asm/vdso_datapage.h>
8162+#include <asm/mman.h>
8163
8164 #include "setup.h"
8165
8166@@ -222,7 +223,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8167 vdso_base = VDSO32_MBASE;
8168 #endif
8169
8170- current->mm->context.vdso_base = 0;
8171+ current->mm->context.vdso_base = ~0UL;
8172
8173 /* vDSO has a problem and was disabled, just don't "enable" it for the
8174 * process
8175@@ -242,7 +243,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8176 vdso_base = get_unmapped_area(NULL, vdso_base,
8177 (vdso_pages << PAGE_SHIFT) +
8178 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
8179- 0, 0);
8180+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
8181 if (IS_ERR_VALUE(vdso_base)) {
8182 rc = vdso_base;
8183 goto fail_mmapsem;
8184diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
8185index 5eea6f3..5d10396 100644
8186--- a/arch/powerpc/lib/usercopy_64.c
8187+++ b/arch/powerpc/lib/usercopy_64.c
8188@@ -9,22 +9,6 @@
8189 #include <linux/module.h>
8190 #include <asm/uaccess.h>
8191
8192-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
8193-{
8194- if (likely(access_ok(VERIFY_READ, from, n)))
8195- n = __copy_from_user(to, from, n);
8196- else
8197- memset(to, 0, n);
8198- return n;
8199-}
8200-
8201-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
8202-{
8203- if (likely(access_ok(VERIFY_WRITE, to, n)))
8204- n = __copy_to_user(to, from, n);
8205- return n;
8206-}
8207-
8208 unsigned long copy_in_user(void __user *to, const void __user *from,
8209 unsigned long n)
8210 {
8211@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
8212 return n;
8213 }
8214
8215-EXPORT_SYMBOL(copy_from_user);
8216-EXPORT_SYMBOL(copy_to_user);
8217 EXPORT_SYMBOL(copy_in_user);
8218
8219diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
8220index 8726779..a33c512 100644
8221--- a/arch/powerpc/mm/fault.c
8222+++ b/arch/powerpc/mm/fault.c
8223@@ -33,6 +33,10 @@
8224 #include <linux/magic.h>
8225 #include <linux/ratelimit.h>
8226 #include <linux/context_tracking.h>
8227+#include <linux/slab.h>
8228+#include <linux/pagemap.h>
8229+#include <linux/compiler.h>
8230+#include <linux/unistd.h>
8231
8232 #include <asm/firmware.h>
8233 #include <asm/page.h>
8234@@ -69,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
8235 }
8236 #endif
8237
8238+#ifdef CONFIG_PAX_PAGEEXEC
8239+/*
8240+ * PaX: decide what to do with offenders (regs->nip = fault address)
8241+ *
8242+ * returns 1 when task should be killed
8243+ */
8244+static int pax_handle_fetch_fault(struct pt_regs *regs)
8245+{
8246+ return 1;
8247+}
8248+
8249+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
8250+{
8251+ unsigned long i;
8252+
8253+ printk(KERN_ERR "PAX: bytes at PC: ");
8254+ for (i = 0; i < 5; i++) {
8255+ unsigned int c;
8256+ if (get_user(c, (unsigned int __user *)pc+i))
8257+ printk(KERN_CONT "???????? ");
8258+ else
8259+ printk(KERN_CONT "%08x ", c);
8260+ }
8261+ printk("\n");
8262+}
8263+#endif
8264+
8265 /*
8266 * Check whether the instruction at regs->nip is a store using
8267 * an update addressing form which will update r1.
8268@@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
8269 * indicate errors in DSISR but can validly be set in SRR1.
8270 */
8271 if (trap == 0x400)
8272- error_code &= 0x48200000;
8273+ error_code &= 0x58200000;
8274 else
8275 is_write = error_code & DSISR_ISSTORE;
8276 #else
8277@@ -371,7 +402,7 @@ good_area:
8278 * "undefined". Of those that can be set, this is the only
8279 * one which seems bad.
8280 */
8281- if (error_code & 0x10000000)
8282+ if (error_code & DSISR_GUARDED)
8283 /* Guarded storage error. */
8284 goto bad_area;
8285 #endif /* CONFIG_8xx */
8286@@ -386,7 +417,7 @@ good_area:
8287 * processors use the same I/D cache coherency mechanism
8288 * as embedded.
8289 */
8290- if (error_code & DSISR_PROTFAULT)
8291+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
8292 goto bad_area;
8293 #endif /* CONFIG_PPC_STD_MMU */
8294
8295@@ -471,6 +502,23 @@ bad_area:
8296 bad_area_nosemaphore:
8297 /* User mode accesses cause a SIGSEGV */
8298 if (user_mode(regs)) {
8299+
8300+#ifdef CONFIG_PAX_PAGEEXEC
8301+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
8302+#ifdef CONFIG_PPC_STD_MMU
8303+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
8304+#else
8305+ if (is_exec && regs->nip == address) {
8306+#endif
8307+ switch (pax_handle_fetch_fault(regs)) {
8308+ }
8309+
8310+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
8311+ do_group_exit(SIGKILL);
8312+ }
8313+ }
8314+#endif
8315+
8316 _exception(SIGSEGV, regs, code, address);
8317 goto bail;
8318 }
8319diff --git a/arch/powerpc/mm/mmap.c b/arch/powerpc/mm/mmap.c
8320index cb8bdbe..d770680 100644
8321--- a/arch/powerpc/mm/mmap.c
8322+++ b/arch/powerpc/mm/mmap.c
8323@@ -57,6 +57,10 @@ static unsigned long mmap_rnd(void)
8324 {
8325 unsigned long rnd = 0;
8326
8327+#ifdef CONFIG_PAX_RANDMMAP
8328+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8329+#endif
8330+
8331 if (current->flags & PF_RANDOMIZE) {
8332 /* 8MB for 32bit, 1GB for 64bit */
8333 if (is_32bit_task())
8334@@ -91,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8335 */
8336 if (mmap_is_legacy()) {
8337 mm->mmap_base = TASK_UNMAPPED_BASE;
8338+
8339+#ifdef CONFIG_PAX_RANDMMAP
8340+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8341+ mm->mmap_base += mm->delta_mmap;
8342+#endif
8343+
8344 mm->get_unmapped_area = arch_get_unmapped_area;
8345 } else {
8346 mm->mmap_base = mmap_base();
8347+
8348+#ifdef CONFIG_PAX_RANDMMAP
8349+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8350+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8351+#endif
8352+
8353 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8354 }
8355 }
8356diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
8357index 3e99c14..f00953c 100644
8358--- a/arch/powerpc/mm/slice.c
8359+++ b/arch/powerpc/mm/slice.c
8360@@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
8361 if ((mm->task_size - len) < addr)
8362 return 0;
8363 vma = find_vma(mm, addr);
8364- return (!vma || (addr + len) <= vma->vm_start);
8365+ return check_heap_stack_gap(vma, addr, len, 0);
8366 }
8367
8368 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
8369@@ -277,6 +277,12 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
8370 info.align_offset = 0;
8371
8372 addr = TASK_UNMAPPED_BASE;
8373+
8374+#ifdef CONFIG_PAX_RANDMMAP
8375+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8376+ addr += mm->delta_mmap;
8377+#endif
8378+
8379 while (addr < TASK_SIZE) {
8380 info.low_limit = addr;
8381 if (!slice_scan_available(addr, available, 1, &addr))
8382@@ -410,6 +416,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
8383 if (fixed && addr > (mm->task_size - len))
8384 return -EINVAL;
8385
8386+#ifdef CONFIG_PAX_RANDMMAP
8387+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
8388+ addr = 0;
8389+#endif
8390+
8391 /* If hint, make sure it matches our alignment restrictions */
8392 if (!fixed && addr) {
8393 addr = _ALIGN_UP(addr, 1ul << pshift);
8394diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
8395index 9098692..3d54cd1 100644
8396--- a/arch/powerpc/platforms/cell/spufs/file.c
8397+++ b/arch/powerpc/platforms/cell/spufs/file.c
8398@@ -280,9 +280,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
8399 return VM_FAULT_NOPAGE;
8400 }
8401
8402-static int spufs_mem_mmap_access(struct vm_area_struct *vma,
8403+static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
8404 unsigned long address,
8405- void *buf, int len, int write)
8406+ void *buf, size_t len, int write)
8407 {
8408 struct spu_context *ctx = vma->vm_file->private_data;
8409 unsigned long offset = address - vma->vm_start;
8410diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
8411index c797832..ce575c8 100644
8412--- a/arch/s390/include/asm/atomic.h
8413+++ b/arch/s390/include/asm/atomic.h
8414@@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
8415 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
8416 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
8417
8418+#define atomic64_read_unchecked(v) atomic64_read(v)
8419+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
8420+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
8421+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
8422+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
8423+#define atomic64_inc_unchecked(v) atomic64_inc(v)
8424+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
8425+#define atomic64_dec_unchecked(v) atomic64_dec(v)
8426+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
8427+
8428 #define smp_mb__before_atomic_dec() smp_mb()
8429 #define smp_mb__after_atomic_dec() smp_mb()
8430 #define smp_mb__before_atomic_inc() smp_mb()
8431diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
8432index 4d7ccac..d03d0ad 100644
8433--- a/arch/s390/include/asm/cache.h
8434+++ b/arch/s390/include/asm/cache.h
8435@@ -9,8 +9,10 @@
8436 #ifndef __ARCH_S390_CACHE_H
8437 #define __ARCH_S390_CACHE_H
8438
8439-#define L1_CACHE_BYTES 256
8440+#include <linux/const.h>
8441+
8442 #define L1_CACHE_SHIFT 8
8443+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8444 #define NET_SKB_PAD 32
8445
8446 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
8447diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
8448index 78f4f87..598ce39 100644
8449--- a/arch/s390/include/asm/elf.h
8450+++ b/arch/s390/include/asm/elf.h
8451@@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
8452 the loader. We need to make sure that it is out of the way of the program
8453 that it will "exec", and that there is sufficient room for the brk. */
8454
8455-extern unsigned long randomize_et_dyn(unsigned long base);
8456-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
8457+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
8458+
8459+#ifdef CONFIG_PAX_ASLR
8460+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
8461+
8462+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
8463+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
8464+#endif
8465
8466 /* This yields a mask that user programs can use to figure out what
8467 instruction set this CPU supports. */
8468@@ -222,9 +228,6 @@ struct linux_binprm;
8469 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
8470 int arch_setup_additional_pages(struct linux_binprm *, int);
8471
8472-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
8473-#define arch_randomize_brk arch_randomize_brk
8474-
8475 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
8476
8477 #endif
8478diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
8479index c4a93d6..4d2a9b4 100644
8480--- a/arch/s390/include/asm/exec.h
8481+++ b/arch/s390/include/asm/exec.h
8482@@ -7,6 +7,6 @@
8483 #ifndef __ASM_EXEC_H
8484 #define __ASM_EXEC_H
8485
8486-extern unsigned long arch_align_stack(unsigned long sp);
8487+#define arch_align_stack(x) ((x) & ~0xfUL)
8488
8489 #endif /* __ASM_EXEC_H */
8490diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
8491index 9c33ed4..e40cbef 100644
8492--- a/arch/s390/include/asm/uaccess.h
8493+++ b/arch/s390/include/asm/uaccess.h
8494@@ -252,6 +252,10 @@ static inline unsigned long __must_check
8495 copy_to_user(void __user *to, const void *from, unsigned long n)
8496 {
8497 might_fault();
8498+
8499+ if ((long)n < 0)
8500+ return n;
8501+
8502 return __copy_to_user(to, from, n);
8503 }
8504
8505@@ -275,6 +279,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
8506 static inline unsigned long __must_check
8507 __copy_from_user(void *to, const void __user *from, unsigned long n)
8508 {
8509+ if ((long)n < 0)
8510+ return n;
8511+
8512 if (__builtin_constant_p(n) && (n <= 256))
8513 return uaccess.copy_from_user_small(n, from, to);
8514 else
8515@@ -306,10 +313,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
8516 static inline unsigned long __must_check
8517 copy_from_user(void *to, const void __user *from, unsigned long n)
8518 {
8519- unsigned int sz = __compiletime_object_size(to);
8520+ size_t sz = __compiletime_object_size(to);
8521
8522 might_fault();
8523- if (unlikely(sz != -1 && sz < n)) {
8524+
8525+ if ((long)n < 0)
8526+ return n;
8527+
8528+ if (unlikely(sz != (size_t)-1 && sz < n)) {
8529 copy_from_user_overflow();
8530 return n;
8531 }
8532diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
8533index 7845e15..59c4353 100644
8534--- a/arch/s390/kernel/module.c
8535+++ b/arch/s390/kernel/module.c
8536@@ -169,11 +169,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
8537
8538 /* Increase core size by size of got & plt and set start
8539 offsets for got and plt. */
8540- me->core_size = ALIGN(me->core_size, 4);
8541- me->arch.got_offset = me->core_size;
8542- me->core_size += me->arch.got_size;
8543- me->arch.plt_offset = me->core_size;
8544- me->core_size += me->arch.plt_size;
8545+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
8546+ me->arch.got_offset = me->core_size_rw;
8547+ me->core_size_rw += me->arch.got_size;
8548+ me->arch.plt_offset = me->core_size_rx;
8549+ me->core_size_rx += me->arch.plt_size;
8550 return 0;
8551 }
8552
8553@@ -289,7 +289,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8554 if (info->got_initialized == 0) {
8555 Elf_Addr *gotent;
8556
8557- gotent = me->module_core + me->arch.got_offset +
8558+ gotent = me->module_core_rw + me->arch.got_offset +
8559 info->got_offset;
8560 *gotent = val;
8561 info->got_initialized = 1;
8562@@ -312,7 +312,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8563 rc = apply_rela_bits(loc, val, 0, 64, 0);
8564 else if (r_type == R_390_GOTENT ||
8565 r_type == R_390_GOTPLTENT) {
8566- val += (Elf_Addr) me->module_core - loc;
8567+ val += (Elf_Addr) me->module_core_rw - loc;
8568 rc = apply_rela_bits(loc, val, 1, 32, 1);
8569 }
8570 break;
8571@@ -325,7 +325,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8572 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
8573 if (info->plt_initialized == 0) {
8574 unsigned int *ip;
8575- ip = me->module_core + me->arch.plt_offset +
8576+ ip = me->module_core_rx + me->arch.plt_offset +
8577 info->plt_offset;
8578 #ifndef CONFIG_64BIT
8579 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
8580@@ -350,7 +350,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8581 val - loc + 0xffffUL < 0x1ffffeUL) ||
8582 (r_type == R_390_PLT32DBL &&
8583 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
8584- val = (Elf_Addr) me->module_core +
8585+ val = (Elf_Addr) me->module_core_rx +
8586 me->arch.plt_offset +
8587 info->plt_offset;
8588 val += rela->r_addend - loc;
8589@@ -372,7 +372,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8590 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
8591 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
8592 val = val + rela->r_addend -
8593- ((Elf_Addr) me->module_core + me->arch.got_offset);
8594+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
8595 if (r_type == R_390_GOTOFF16)
8596 rc = apply_rela_bits(loc, val, 0, 16, 0);
8597 else if (r_type == R_390_GOTOFF32)
8598@@ -382,7 +382,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8599 break;
8600 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
8601 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
8602- val = (Elf_Addr) me->module_core + me->arch.got_offset +
8603+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
8604 rela->r_addend - loc;
8605 if (r_type == R_390_GOTPC)
8606 rc = apply_rela_bits(loc, val, 1, 32, 0);
8607diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
8608index 2bc3edd..ab9d598 100644
8609--- a/arch/s390/kernel/process.c
8610+++ b/arch/s390/kernel/process.c
8611@@ -236,39 +236,3 @@ unsigned long get_wchan(struct task_struct *p)
8612 }
8613 return 0;
8614 }
8615-
8616-unsigned long arch_align_stack(unsigned long sp)
8617-{
8618- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8619- sp -= get_random_int() & ~PAGE_MASK;
8620- return sp & ~0xf;
8621-}
8622-
8623-static inline unsigned long brk_rnd(void)
8624-{
8625- /* 8MB for 32bit, 1GB for 64bit */
8626- if (is_32bit_task())
8627- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
8628- else
8629- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
8630-}
8631-
8632-unsigned long arch_randomize_brk(struct mm_struct *mm)
8633-{
8634- unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
8635-
8636- if (ret < mm->brk)
8637- return mm->brk;
8638- return ret;
8639-}
8640-
8641-unsigned long randomize_et_dyn(unsigned long base)
8642-{
8643- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
8644-
8645- if (!(current->flags & PF_RANDOMIZE))
8646- return base;
8647- if (ret < base)
8648- return base;
8649- return ret;
8650-}
8651diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
8652index 4002329..99b67cb 100644
8653--- a/arch/s390/mm/mmap.c
8654+++ b/arch/s390/mm/mmap.c
8655@@ -90,9 +90,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8656 */
8657 if (mmap_is_legacy()) {
8658 mm->mmap_base = TASK_UNMAPPED_BASE;
8659+
8660+#ifdef CONFIG_PAX_RANDMMAP
8661+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8662+ mm->mmap_base += mm->delta_mmap;
8663+#endif
8664+
8665 mm->get_unmapped_area = arch_get_unmapped_area;
8666 } else {
8667 mm->mmap_base = mmap_base();
8668+
8669+#ifdef CONFIG_PAX_RANDMMAP
8670+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8671+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8672+#endif
8673+
8674 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8675 }
8676 }
8677@@ -173,9 +185,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8678 */
8679 if (mmap_is_legacy()) {
8680 mm->mmap_base = TASK_UNMAPPED_BASE;
8681+
8682+#ifdef CONFIG_PAX_RANDMMAP
8683+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8684+ mm->mmap_base += mm->delta_mmap;
8685+#endif
8686+
8687 mm->get_unmapped_area = s390_get_unmapped_area;
8688 } else {
8689 mm->mmap_base = mmap_base();
8690+
8691+#ifdef CONFIG_PAX_RANDMMAP
8692+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8693+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8694+#endif
8695+
8696 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
8697 }
8698 }
8699diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
8700index ae3d59f..f65f075 100644
8701--- a/arch/score/include/asm/cache.h
8702+++ b/arch/score/include/asm/cache.h
8703@@ -1,7 +1,9 @@
8704 #ifndef _ASM_SCORE_CACHE_H
8705 #define _ASM_SCORE_CACHE_H
8706
8707+#include <linux/const.h>
8708+
8709 #define L1_CACHE_SHIFT 4
8710-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8711+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8712
8713 #endif /* _ASM_SCORE_CACHE_H */
8714diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
8715index f9f3cd5..58ff438 100644
8716--- a/arch/score/include/asm/exec.h
8717+++ b/arch/score/include/asm/exec.h
8718@@ -1,6 +1,6 @@
8719 #ifndef _ASM_SCORE_EXEC_H
8720 #define _ASM_SCORE_EXEC_H
8721
8722-extern unsigned long arch_align_stack(unsigned long sp);
8723+#define arch_align_stack(x) (x)
8724
8725 #endif /* _ASM_SCORE_EXEC_H */
8726diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
8727index f4c6d02..e9355c3 100644
8728--- a/arch/score/kernel/process.c
8729+++ b/arch/score/kernel/process.c
8730@@ -116,8 +116,3 @@ unsigned long get_wchan(struct task_struct *task)
8731
8732 return task_pt_regs(task)->cp0_epc;
8733 }
8734-
8735-unsigned long arch_align_stack(unsigned long sp)
8736-{
8737- return sp;
8738-}
8739diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
8740index ef9e555..331bd29 100644
8741--- a/arch/sh/include/asm/cache.h
8742+++ b/arch/sh/include/asm/cache.h
8743@@ -9,10 +9,11 @@
8744 #define __ASM_SH_CACHE_H
8745 #ifdef __KERNEL__
8746
8747+#include <linux/const.h>
8748 #include <linux/init.h>
8749 #include <cpu/cache.h>
8750
8751-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8752+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8753
8754 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
8755
8756diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
8757index 6777177..cb5e44f 100644
8758--- a/arch/sh/mm/mmap.c
8759+++ b/arch/sh/mm/mmap.c
8760@@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
8761 struct mm_struct *mm = current->mm;
8762 struct vm_area_struct *vma;
8763 int do_colour_align;
8764+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8765 struct vm_unmapped_area_info info;
8766
8767 if (flags & MAP_FIXED) {
8768@@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
8769 if (filp || (flags & MAP_SHARED))
8770 do_colour_align = 1;
8771
8772+#ifdef CONFIG_PAX_RANDMMAP
8773+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8774+#endif
8775+
8776 if (addr) {
8777 if (do_colour_align)
8778 addr = COLOUR_ALIGN(addr, pgoff);
8779@@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
8780 addr = PAGE_ALIGN(addr);
8781
8782 vma = find_vma(mm, addr);
8783- if (TASK_SIZE - len >= addr &&
8784- (!vma || addr + len <= vma->vm_start))
8785+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8786 return addr;
8787 }
8788
8789 info.flags = 0;
8790 info.length = len;
8791- info.low_limit = TASK_UNMAPPED_BASE;
8792+ info.low_limit = mm->mmap_base;
8793 info.high_limit = TASK_SIZE;
8794 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
8795 info.align_offset = pgoff << PAGE_SHIFT;
8796@@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8797 struct mm_struct *mm = current->mm;
8798 unsigned long addr = addr0;
8799 int do_colour_align;
8800+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8801 struct vm_unmapped_area_info info;
8802
8803 if (flags & MAP_FIXED) {
8804@@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8805 if (filp || (flags & MAP_SHARED))
8806 do_colour_align = 1;
8807
8808+#ifdef CONFIG_PAX_RANDMMAP
8809+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8810+#endif
8811+
8812 /* requesting a specific address */
8813 if (addr) {
8814 if (do_colour_align)
8815@@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8816 addr = PAGE_ALIGN(addr);
8817
8818 vma = find_vma(mm, addr);
8819- if (TASK_SIZE - len >= addr &&
8820- (!vma || addr + len <= vma->vm_start))
8821+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8822 return addr;
8823 }
8824
8825@@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8826 VM_BUG_ON(addr != -ENOMEM);
8827 info.flags = 0;
8828 info.low_limit = TASK_UNMAPPED_BASE;
8829+
8830+#ifdef CONFIG_PAX_RANDMMAP
8831+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8832+ info.low_limit += mm->delta_mmap;
8833+#endif
8834+
8835 info.high_limit = TASK_SIZE;
8836 addr = vm_unmapped_area(&info);
8837 }
8838diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
8839index be56a24..443328f 100644
8840--- a/arch/sparc/include/asm/atomic_64.h
8841+++ b/arch/sparc/include/asm/atomic_64.h
8842@@ -14,18 +14,40 @@
8843 #define ATOMIC64_INIT(i) { (i) }
8844
8845 #define atomic_read(v) (*(volatile int *)&(v)->counter)
8846+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
8847+{
8848+ return v->counter;
8849+}
8850 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
8851+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
8852+{
8853+ return v->counter;
8854+}
8855
8856 #define atomic_set(v, i) (((v)->counter) = i)
8857+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
8858+{
8859+ v->counter = i;
8860+}
8861 #define atomic64_set(v, i) (((v)->counter) = i)
8862+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
8863+{
8864+ v->counter = i;
8865+}
8866
8867 extern void atomic_add(int, atomic_t *);
8868+extern void atomic_add_unchecked(int, atomic_unchecked_t *);
8869 extern void atomic64_add(long, atomic64_t *);
8870+extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
8871 extern void atomic_sub(int, atomic_t *);
8872+extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
8873 extern void atomic64_sub(long, atomic64_t *);
8874+extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
8875
8876 extern int atomic_add_ret(int, atomic_t *);
8877+extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
8878 extern long atomic64_add_ret(long, atomic64_t *);
8879+extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
8880 extern int atomic_sub_ret(int, atomic_t *);
8881 extern long atomic64_sub_ret(long, atomic64_t *);
8882
8883@@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
8884 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
8885
8886 #define atomic_inc_return(v) atomic_add_ret(1, v)
8887+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
8888+{
8889+ return atomic_add_ret_unchecked(1, v);
8890+}
8891 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
8892+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
8893+{
8894+ return atomic64_add_ret_unchecked(1, v);
8895+}
8896
8897 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
8898 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
8899
8900 #define atomic_add_return(i, v) atomic_add_ret(i, v)
8901+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
8902+{
8903+ return atomic_add_ret_unchecked(i, v);
8904+}
8905 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
8906+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
8907+{
8908+ return atomic64_add_ret_unchecked(i, v);
8909+}
8910
8911 /*
8912 * atomic_inc_and_test - increment and test
8913@@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
8914 * other cases.
8915 */
8916 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
8917+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
8918+{
8919+ return atomic_inc_return_unchecked(v) == 0;
8920+}
8921 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
8922
8923 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
8924@@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
8925 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
8926
8927 #define atomic_inc(v) atomic_add(1, v)
8928+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
8929+{
8930+ atomic_add_unchecked(1, v);
8931+}
8932 #define atomic64_inc(v) atomic64_add(1, v)
8933+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
8934+{
8935+ atomic64_add_unchecked(1, v);
8936+}
8937
8938 #define atomic_dec(v) atomic_sub(1, v)
8939+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
8940+{
8941+ atomic_sub_unchecked(1, v);
8942+}
8943 #define atomic64_dec(v) atomic64_sub(1, v)
8944+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
8945+{
8946+ atomic64_sub_unchecked(1, v);
8947+}
8948
8949 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
8950 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
8951
8952 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
8953+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
8954+{
8955+ return cmpxchg(&v->counter, old, new);
8956+}
8957 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
8958+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
8959+{
8960+ return xchg(&v->counter, new);
8961+}
8962
8963 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
8964 {
8965- int c, old;
8966+ int c, old, new;
8967 c = atomic_read(v);
8968 for (;;) {
8969- if (unlikely(c == (u)))
8970+ if (unlikely(c == u))
8971 break;
8972- old = atomic_cmpxchg((v), c, c + (a));
8973+
8974+ asm volatile("addcc %2, %0, %0\n"
8975+
8976+#ifdef CONFIG_PAX_REFCOUNT
8977+ "tvs %%icc, 6\n"
8978+#endif
8979+
8980+ : "=r" (new)
8981+ : "0" (c), "ir" (a)
8982+ : "cc");
8983+
8984+ old = atomic_cmpxchg(v, c, new);
8985 if (likely(old == c))
8986 break;
8987 c = old;
8988@@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
8989 #define atomic64_cmpxchg(v, o, n) \
8990 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
8991 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
8992+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
8993+{
8994+ return xchg(&v->counter, new);
8995+}
8996
8997 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
8998 {
8999- long c, old;
9000+ long c, old, new;
9001 c = atomic64_read(v);
9002 for (;;) {
9003- if (unlikely(c == (u)))
9004+ if (unlikely(c == u))
9005 break;
9006- old = atomic64_cmpxchg((v), c, c + (a));
9007+
9008+ asm volatile("addcc %2, %0, %0\n"
9009+
9010+#ifdef CONFIG_PAX_REFCOUNT
9011+ "tvs %%xcc, 6\n"
9012+#endif
9013+
9014+ : "=r" (new)
9015+ : "0" (c), "ir" (a)
9016+ : "cc");
9017+
9018+ old = atomic64_cmpxchg(v, c, new);
9019 if (likely(old == c))
9020 break;
9021 c = old;
9022 }
9023- return c != (u);
9024+ return c != u;
9025 }
9026
9027 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9028diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
9029index 5bb6991..5c2132e 100644
9030--- a/arch/sparc/include/asm/cache.h
9031+++ b/arch/sparc/include/asm/cache.h
9032@@ -7,10 +7,12 @@
9033 #ifndef _SPARC_CACHE_H
9034 #define _SPARC_CACHE_H
9035
9036+#include <linux/const.h>
9037+
9038 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
9039
9040 #define L1_CACHE_SHIFT 5
9041-#define L1_CACHE_BYTES 32
9042+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9043
9044 #ifdef CONFIG_SPARC32
9045 #define SMP_CACHE_BYTES_SHIFT 5
9046diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
9047index a24e41f..47677ff 100644
9048--- a/arch/sparc/include/asm/elf_32.h
9049+++ b/arch/sparc/include/asm/elf_32.h
9050@@ -114,6 +114,13 @@ typedef struct {
9051
9052 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
9053
9054+#ifdef CONFIG_PAX_ASLR
9055+#define PAX_ELF_ET_DYN_BASE 0x10000UL
9056+
9057+#define PAX_DELTA_MMAP_LEN 16
9058+#define PAX_DELTA_STACK_LEN 16
9059+#endif
9060+
9061 /* This yields a mask that user programs can use to figure out what
9062 instruction set this cpu supports. This can NOT be done in userspace
9063 on Sparc. */
9064diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
9065index 370ca1e..d4f4a98 100644
9066--- a/arch/sparc/include/asm/elf_64.h
9067+++ b/arch/sparc/include/asm/elf_64.h
9068@@ -189,6 +189,13 @@ typedef struct {
9069 #define ELF_ET_DYN_BASE 0x0000010000000000UL
9070 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
9071
9072+#ifdef CONFIG_PAX_ASLR
9073+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
9074+
9075+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
9076+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
9077+#endif
9078+
9079 extern unsigned long sparc64_elf_hwcap;
9080 #define ELF_HWCAP sparc64_elf_hwcap
9081
9082diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
9083index 9b1c36d..209298b 100644
9084--- a/arch/sparc/include/asm/pgalloc_32.h
9085+++ b/arch/sparc/include/asm/pgalloc_32.h
9086@@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
9087 }
9088
9089 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
9090+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
9091
9092 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
9093 unsigned long address)
9094diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
9095index bcfe063..b333142 100644
9096--- a/arch/sparc/include/asm/pgalloc_64.h
9097+++ b/arch/sparc/include/asm/pgalloc_64.h
9098@@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
9099 }
9100
9101 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
9102+#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
9103
9104 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
9105 {
9106diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
9107index 502f632..da1917f 100644
9108--- a/arch/sparc/include/asm/pgtable_32.h
9109+++ b/arch/sparc/include/asm/pgtable_32.h
9110@@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
9111 #define PAGE_SHARED SRMMU_PAGE_SHARED
9112 #define PAGE_COPY SRMMU_PAGE_COPY
9113 #define PAGE_READONLY SRMMU_PAGE_RDONLY
9114+#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
9115+#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
9116+#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
9117 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
9118
9119 /* Top-level page directory - dummy used by init-mm.
9120@@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
9121
9122 /* xwr */
9123 #define __P000 PAGE_NONE
9124-#define __P001 PAGE_READONLY
9125-#define __P010 PAGE_COPY
9126-#define __P011 PAGE_COPY
9127+#define __P001 PAGE_READONLY_NOEXEC
9128+#define __P010 PAGE_COPY_NOEXEC
9129+#define __P011 PAGE_COPY_NOEXEC
9130 #define __P100 PAGE_READONLY
9131 #define __P101 PAGE_READONLY
9132 #define __P110 PAGE_COPY
9133 #define __P111 PAGE_COPY
9134
9135 #define __S000 PAGE_NONE
9136-#define __S001 PAGE_READONLY
9137-#define __S010 PAGE_SHARED
9138-#define __S011 PAGE_SHARED
9139+#define __S001 PAGE_READONLY_NOEXEC
9140+#define __S010 PAGE_SHARED_NOEXEC
9141+#define __S011 PAGE_SHARED_NOEXEC
9142 #define __S100 PAGE_READONLY
9143 #define __S101 PAGE_READONLY
9144 #define __S110 PAGE_SHARED
9145diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
9146index 79da178..c2eede8 100644
9147--- a/arch/sparc/include/asm/pgtsrmmu.h
9148+++ b/arch/sparc/include/asm/pgtsrmmu.h
9149@@ -115,6 +115,11 @@
9150 SRMMU_EXEC | SRMMU_REF)
9151 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
9152 SRMMU_EXEC | SRMMU_REF)
9153+
9154+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
9155+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9156+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9157+
9158 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
9159 SRMMU_DIRTY | SRMMU_REF)
9160
9161diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
9162index 9689176..63c18ea 100644
9163--- a/arch/sparc/include/asm/spinlock_64.h
9164+++ b/arch/sparc/include/asm/spinlock_64.h
9165@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
9166
9167 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
9168
9169-static void inline arch_read_lock(arch_rwlock_t *lock)
9170+static inline void arch_read_lock(arch_rwlock_t *lock)
9171 {
9172 unsigned long tmp1, tmp2;
9173
9174 __asm__ __volatile__ (
9175 "1: ldsw [%2], %0\n"
9176 " brlz,pn %0, 2f\n"
9177-"4: add %0, 1, %1\n"
9178+"4: addcc %0, 1, %1\n"
9179+
9180+#ifdef CONFIG_PAX_REFCOUNT
9181+" tvs %%icc, 6\n"
9182+#endif
9183+
9184 " cas [%2], %0, %1\n"
9185 " cmp %0, %1\n"
9186 " bne,pn %%icc, 1b\n"
9187@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
9188 " .previous"
9189 : "=&r" (tmp1), "=&r" (tmp2)
9190 : "r" (lock)
9191- : "memory");
9192+ : "memory", "cc");
9193 }
9194
9195-static int inline arch_read_trylock(arch_rwlock_t *lock)
9196+static inline int arch_read_trylock(arch_rwlock_t *lock)
9197 {
9198 int tmp1, tmp2;
9199
9200@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9201 "1: ldsw [%2], %0\n"
9202 " brlz,a,pn %0, 2f\n"
9203 " mov 0, %0\n"
9204-" add %0, 1, %1\n"
9205+" addcc %0, 1, %1\n"
9206+
9207+#ifdef CONFIG_PAX_REFCOUNT
9208+" tvs %%icc, 6\n"
9209+#endif
9210+
9211 " cas [%2], %0, %1\n"
9212 " cmp %0, %1\n"
9213 " bne,pn %%icc, 1b\n"
9214@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9215 return tmp1;
9216 }
9217
9218-static void inline arch_read_unlock(arch_rwlock_t *lock)
9219+static inline void arch_read_unlock(arch_rwlock_t *lock)
9220 {
9221 unsigned long tmp1, tmp2;
9222
9223 __asm__ __volatile__(
9224 "1: lduw [%2], %0\n"
9225-" sub %0, 1, %1\n"
9226+" subcc %0, 1, %1\n"
9227+
9228+#ifdef CONFIG_PAX_REFCOUNT
9229+" tvs %%icc, 6\n"
9230+#endif
9231+
9232 " cas [%2], %0, %1\n"
9233 " cmp %0, %1\n"
9234 " bne,pn %%xcc, 1b\n"
9235@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
9236 : "memory");
9237 }
9238
9239-static void inline arch_write_lock(arch_rwlock_t *lock)
9240+static inline void arch_write_lock(arch_rwlock_t *lock)
9241 {
9242 unsigned long mask, tmp1, tmp2;
9243
9244@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
9245 : "memory");
9246 }
9247
9248-static void inline arch_write_unlock(arch_rwlock_t *lock)
9249+static inline void arch_write_unlock(arch_rwlock_t *lock)
9250 {
9251 __asm__ __volatile__(
9252 " stw %%g0, [%0]"
9253@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
9254 : "memory");
9255 }
9256
9257-static int inline arch_write_trylock(arch_rwlock_t *lock)
9258+static inline int arch_write_trylock(arch_rwlock_t *lock)
9259 {
9260 unsigned long mask, tmp1, tmp2, result;
9261
9262diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
9263index dd38075..e7cac83 100644
9264--- a/arch/sparc/include/asm/thread_info_32.h
9265+++ b/arch/sparc/include/asm/thread_info_32.h
9266@@ -49,6 +49,8 @@ struct thread_info {
9267 unsigned long w_saved;
9268
9269 struct restart_block restart_block;
9270+
9271+ unsigned long lowest_stack;
9272 };
9273
9274 /*
9275diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
9276index d5e5042..9bfee76 100644
9277--- a/arch/sparc/include/asm/thread_info_64.h
9278+++ b/arch/sparc/include/asm/thread_info_64.h
9279@@ -63,6 +63,8 @@ struct thread_info {
9280 struct pt_regs *kern_una_regs;
9281 unsigned int kern_una_insn;
9282
9283+ unsigned long lowest_stack;
9284+
9285 unsigned long fpregs[0] __attribute__ ((aligned(64)));
9286 };
9287
9288@@ -192,10 +194,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
9289 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
9290 /* flag bit 6 is available */
9291 #define TIF_32BIT 7 /* 32-bit binary */
9292-/* flag bit 8 is available */
9293+#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
9294 #define TIF_SECCOMP 9 /* secure computing */
9295 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
9296 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
9297+
9298 /* NOTE: Thread flags >= 12 should be ones we have no interest
9299 * in using in assembly, else we can't use the mask as
9300 * an immediate value in instructions such as andcc.
9301@@ -214,12 +217,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
9302 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
9303 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
9304 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
9305+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
9306
9307 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
9308 _TIF_DO_NOTIFY_RESUME_MASK | \
9309 _TIF_NEED_RESCHED)
9310 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
9311
9312+#define _TIF_WORK_SYSCALL \
9313+ (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
9314+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
9315+
9316+
9317 /*
9318 * Thread-synchronous status.
9319 *
9320diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
9321index 0167d26..767bb0c 100644
9322--- a/arch/sparc/include/asm/uaccess.h
9323+++ b/arch/sparc/include/asm/uaccess.h
9324@@ -1,5 +1,6 @@
9325 #ifndef ___ASM_SPARC_UACCESS_H
9326 #define ___ASM_SPARC_UACCESS_H
9327+
9328 #if defined(__sparc__) && defined(__arch64__)
9329 #include <asm/uaccess_64.h>
9330 #else
9331diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
9332index 53a28dd..50c38c3 100644
9333--- a/arch/sparc/include/asm/uaccess_32.h
9334+++ b/arch/sparc/include/asm/uaccess_32.h
9335@@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
9336
9337 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
9338 {
9339- if (n && __access_ok((unsigned long) to, n))
9340+ if ((long)n < 0)
9341+ return n;
9342+
9343+ if (n && __access_ok((unsigned long) to, n)) {
9344+ if (!__builtin_constant_p(n))
9345+ check_object_size(from, n, true);
9346 return __copy_user(to, (__force void __user *) from, n);
9347- else
9348+ } else
9349 return n;
9350 }
9351
9352 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
9353 {
9354+ if ((long)n < 0)
9355+ return n;
9356+
9357+ if (!__builtin_constant_p(n))
9358+ check_object_size(from, n, true);
9359+
9360 return __copy_user(to, (__force void __user *) from, n);
9361 }
9362
9363 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
9364 {
9365- if (n && __access_ok((unsigned long) from, n))
9366+ if ((long)n < 0)
9367+ return n;
9368+
9369+ if (n && __access_ok((unsigned long) from, n)) {
9370+ if (!__builtin_constant_p(n))
9371+ check_object_size(to, n, false);
9372 return __copy_user((__force void __user *) to, from, n);
9373- else
9374+ } else
9375 return n;
9376 }
9377
9378 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
9379 {
9380+ if ((long)n < 0)
9381+ return n;
9382+
9383 return __copy_user((__force void __user *) to, from, n);
9384 }
9385
9386diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
9387index e562d3c..191f176 100644
9388--- a/arch/sparc/include/asm/uaccess_64.h
9389+++ b/arch/sparc/include/asm/uaccess_64.h
9390@@ -10,6 +10,7 @@
9391 #include <linux/compiler.h>
9392 #include <linux/string.h>
9393 #include <linux/thread_info.h>
9394+#include <linux/kernel.h>
9395 #include <asm/asi.h>
9396 #include <asm/spitfire.h>
9397 #include <asm-generic/uaccess-unaligned.h>
9398@@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
9399 static inline unsigned long __must_check
9400 copy_from_user(void *to, const void __user *from, unsigned long size)
9401 {
9402- unsigned long ret = ___copy_from_user(to, from, size);
9403+ unsigned long ret;
9404
9405+ if ((long)size < 0 || size > INT_MAX)
9406+ return size;
9407+
9408+ if (!__builtin_constant_p(size))
9409+ check_object_size(to, size, false);
9410+
9411+ ret = ___copy_from_user(to, from, size);
9412 if (unlikely(ret))
9413 ret = copy_from_user_fixup(to, from, size);
9414
9415@@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
9416 static inline unsigned long __must_check
9417 copy_to_user(void __user *to, const void *from, unsigned long size)
9418 {
9419- unsigned long ret = ___copy_to_user(to, from, size);
9420+ unsigned long ret;
9421
9422+ if ((long)size < 0 || size > INT_MAX)
9423+ return size;
9424+
9425+ if (!__builtin_constant_p(size))
9426+ check_object_size(from, size, true);
9427+
9428+ ret = ___copy_to_user(to, from, size);
9429 if (unlikely(ret))
9430 ret = copy_to_user_fixup(to, from, size);
9431 return ret;
9432diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
9433index d432fb2..6056af1 100644
9434--- a/arch/sparc/kernel/Makefile
9435+++ b/arch/sparc/kernel/Makefile
9436@@ -3,7 +3,7 @@
9437 #
9438
9439 asflags-y := -ansi
9440-ccflags-y := -Werror
9441+#ccflags-y := -Werror
9442
9443 extra-y := head_$(BITS).o
9444
9445diff --git a/arch/sparc/kernel/ds.c b/arch/sparc/kernel/ds.c
9446index 62d6b15..9231031 100644
9447--- a/arch/sparc/kernel/ds.c
9448+++ b/arch/sparc/kernel/ds.c
9449@@ -849,10 +849,9 @@ void ldom_reboot(const char *boot_command)
9450 if (boot_command && strlen(boot_command)) {
9451 unsigned long len;
9452
9453- strcpy(full_boot_str, "boot ");
9454- strlcpy(full_boot_str + strlen("boot "), boot_command,
9455- sizeof(full_boot_str + strlen("boot ")));
9456- len = strlen(full_boot_str);
9457+ len = snprintf(full_boot_str, sizeof(full_boot_str), "boot %s", boot_command);
9458+ if (len >= sizeof(full_boot_str))
9459+ len = sizeof(full_boot_str) - 1;
9460
9461 if (reboot_data_supported) {
9462 unsigned long ra = kimage_addr_to_ra(full_boot_str);
9463diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
9464index fdd819d..5af08c8 100644
9465--- a/arch/sparc/kernel/process_32.c
9466+++ b/arch/sparc/kernel/process_32.c
9467@@ -116,14 +116,14 @@ void show_regs(struct pt_regs *r)
9468
9469 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
9470 r->psr, r->pc, r->npc, r->y, print_tainted());
9471- printk("PC: <%pS>\n", (void *) r->pc);
9472+ printk("PC: <%pA>\n", (void *) r->pc);
9473 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
9474 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
9475 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
9476 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
9477 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
9478 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
9479- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
9480+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
9481
9482 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
9483 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
9484@@ -160,7 +160,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
9485 rw = (struct reg_window32 *) fp;
9486 pc = rw->ins[7];
9487 printk("[%08lx : ", pc);
9488- printk("%pS ] ", (void *) pc);
9489+ printk("%pA ] ", (void *) pc);
9490 fp = rw->ins[6];
9491 } while (++count < 16);
9492 printk("\n");
9493diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
9494index baebab2..9cd13b1 100644
9495--- a/arch/sparc/kernel/process_64.c
9496+++ b/arch/sparc/kernel/process_64.c
9497@@ -158,7 +158,7 @@ static void show_regwindow(struct pt_regs *regs)
9498 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
9499 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
9500 if (regs->tstate & TSTATE_PRIV)
9501- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
9502+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
9503 }
9504
9505 void show_regs(struct pt_regs *regs)
9506@@ -167,7 +167,7 @@ void show_regs(struct pt_regs *regs)
9507
9508 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
9509 regs->tpc, regs->tnpc, regs->y, print_tainted());
9510- printk("TPC: <%pS>\n", (void *) regs->tpc);
9511+ printk("TPC: <%pA>\n", (void *) regs->tpc);
9512 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
9513 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
9514 regs->u_regs[3]);
9515@@ -180,7 +180,7 @@ void show_regs(struct pt_regs *regs)
9516 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
9517 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
9518 regs->u_regs[15]);
9519- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
9520+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
9521 show_regwindow(regs);
9522 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
9523 }
9524@@ -269,7 +269,7 @@ void arch_trigger_all_cpu_backtrace(void)
9525 ((tp && tp->task) ? tp->task->pid : -1));
9526
9527 if (gp->tstate & TSTATE_PRIV) {
9528- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
9529+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
9530 (void *) gp->tpc,
9531 (void *) gp->o7,
9532 (void *) gp->i7,
9533diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
9534index 79cc0d1..ec62734 100644
9535--- a/arch/sparc/kernel/prom_common.c
9536+++ b/arch/sparc/kernel/prom_common.c
9537@@ -144,7 +144,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
9538
9539 unsigned int prom_early_allocated __initdata;
9540
9541-static struct of_pdt_ops prom_sparc_ops __initdata = {
9542+static struct of_pdt_ops prom_sparc_ops __initconst = {
9543 .nextprop = prom_common_nextprop,
9544 .getproplen = prom_getproplen,
9545 .getproperty = prom_getproperty,
9546diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
9547index 7ff45e4..a58f271 100644
9548--- a/arch/sparc/kernel/ptrace_64.c
9549+++ b/arch/sparc/kernel/ptrace_64.c
9550@@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
9551 return ret;
9552 }
9553
9554+#ifdef CONFIG_GRKERNSEC_SETXID
9555+extern void gr_delayed_cred_worker(void);
9556+#endif
9557+
9558 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
9559 {
9560 int ret = 0;
9561@@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
9562 /* do the secure computing check first */
9563 secure_computing_strict(regs->u_regs[UREG_G1]);
9564
9565+#ifdef CONFIG_GRKERNSEC_SETXID
9566+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9567+ gr_delayed_cred_worker();
9568+#endif
9569+
9570 if (test_thread_flag(TIF_SYSCALL_TRACE))
9571 ret = tracehook_report_syscall_entry(regs);
9572
9573@@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
9574
9575 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
9576 {
9577+#ifdef CONFIG_GRKERNSEC_SETXID
9578+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9579+ gr_delayed_cred_worker();
9580+#endif
9581+
9582 audit_syscall_exit(regs);
9583
9584 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
9585diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
9586index e142545..fd29654 100644
9587--- a/arch/sparc/kernel/smp_64.c
9588+++ b/arch/sparc/kernel/smp_64.c
9589@@ -869,8 +869,8 @@ extern unsigned long xcall_flush_dcache_page_cheetah;
9590 extern unsigned long xcall_flush_dcache_page_spitfire;
9591
9592 #ifdef CONFIG_DEBUG_DCFLUSH
9593-extern atomic_t dcpage_flushes;
9594-extern atomic_t dcpage_flushes_xcall;
9595+extern atomic_unchecked_t dcpage_flushes;
9596+extern atomic_unchecked_t dcpage_flushes_xcall;
9597 #endif
9598
9599 static inline void __local_flush_dcache_page(struct page *page)
9600@@ -894,7 +894,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
9601 return;
9602
9603 #ifdef CONFIG_DEBUG_DCFLUSH
9604- atomic_inc(&dcpage_flushes);
9605+ atomic_inc_unchecked(&dcpage_flushes);
9606 #endif
9607
9608 this_cpu = get_cpu();
9609@@ -918,7 +918,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
9610 xcall_deliver(data0, __pa(pg_addr),
9611 (u64) pg_addr, cpumask_of(cpu));
9612 #ifdef CONFIG_DEBUG_DCFLUSH
9613- atomic_inc(&dcpage_flushes_xcall);
9614+ atomic_inc_unchecked(&dcpage_flushes_xcall);
9615 #endif
9616 }
9617 }
9618@@ -937,7 +937,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
9619 preempt_disable();
9620
9621 #ifdef CONFIG_DEBUG_DCFLUSH
9622- atomic_inc(&dcpage_flushes);
9623+ atomic_inc_unchecked(&dcpage_flushes);
9624 #endif
9625 data0 = 0;
9626 pg_addr = page_address(page);
9627@@ -954,7 +954,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
9628 xcall_deliver(data0, __pa(pg_addr),
9629 (u64) pg_addr, cpu_online_mask);
9630 #ifdef CONFIG_DEBUG_DCFLUSH
9631- atomic_inc(&dcpage_flushes_xcall);
9632+ atomic_inc_unchecked(&dcpage_flushes_xcall);
9633 #endif
9634 }
9635 __local_flush_dcache_page(page);
9636diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
9637index 3a8d184..49498a8 100644
9638--- a/arch/sparc/kernel/sys_sparc_32.c
9639+++ b/arch/sparc/kernel/sys_sparc_32.c
9640@@ -52,7 +52,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9641 if (len > TASK_SIZE - PAGE_SIZE)
9642 return -ENOMEM;
9643 if (!addr)
9644- addr = TASK_UNMAPPED_BASE;
9645+ addr = current->mm->mmap_base;
9646
9647 info.flags = 0;
9648 info.length = len;
9649diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
9650index 51561b8..8256764 100644
9651--- a/arch/sparc/kernel/sys_sparc_64.c
9652+++ b/arch/sparc/kernel/sys_sparc_64.c
9653@@ -90,13 +90,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9654 struct vm_area_struct * vma;
9655 unsigned long task_size = TASK_SIZE;
9656 int do_color_align;
9657+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9658 struct vm_unmapped_area_info info;
9659
9660 if (flags & MAP_FIXED) {
9661 /* We do not accept a shared mapping if it would violate
9662 * cache aliasing constraints.
9663 */
9664- if ((flags & MAP_SHARED) &&
9665+ if ((filp || (flags & MAP_SHARED)) &&
9666 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
9667 return -EINVAL;
9668 return addr;
9669@@ -111,6 +112,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9670 if (filp || (flags & MAP_SHARED))
9671 do_color_align = 1;
9672
9673+#ifdef CONFIG_PAX_RANDMMAP
9674+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9675+#endif
9676+
9677 if (addr) {
9678 if (do_color_align)
9679 addr = COLOR_ALIGN(addr, pgoff);
9680@@ -118,22 +123,28 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9681 addr = PAGE_ALIGN(addr);
9682
9683 vma = find_vma(mm, addr);
9684- if (task_size - len >= addr &&
9685- (!vma || addr + len <= vma->vm_start))
9686+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9687 return addr;
9688 }
9689
9690 info.flags = 0;
9691 info.length = len;
9692- info.low_limit = TASK_UNMAPPED_BASE;
9693+ info.low_limit = mm->mmap_base;
9694 info.high_limit = min(task_size, VA_EXCLUDE_START);
9695 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
9696 info.align_offset = pgoff << PAGE_SHIFT;
9697+ info.threadstack_offset = offset;
9698 addr = vm_unmapped_area(&info);
9699
9700 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
9701 VM_BUG_ON(addr != -ENOMEM);
9702 info.low_limit = VA_EXCLUDE_END;
9703+
9704+#ifdef CONFIG_PAX_RANDMMAP
9705+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9706+ info.low_limit += mm->delta_mmap;
9707+#endif
9708+
9709 info.high_limit = task_size;
9710 addr = vm_unmapped_area(&info);
9711 }
9712@@ -151,6 +162,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9713 unsigned long task_size = STACK_TOP32;
9714 unsigned long addr = addr0;
9715 int do_color_align;
9716+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9717 struct vm_unmapped_area_info info;
9718
9719 /* This should only ever run for 32-bit processes. */
9720@@ -160,7 +172,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9721 /* We do not accept a shared mapping if it would violate
9722 * cache aliasing constraints.
9723 */
9724- if ((flags & MAP_SHARED) &&
9725+ if ((filp || (flags & MAP_SHARED)) &&
9726 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
9727 return -EINVAL;
9728 return addr;
9729@@ -173,6 +185,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9730 if (filp || (flags & MAP_SHARED))
9731 do_color_align = 1;
9732
9733+#ifdef CONFIG_PAX_RANDMMAP
9734+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9735+#endif
9736+
9737 /* requesting a specific address */
9738 if (addr) {
9739 if (do_color_align)
9740@@ -181,8 +197,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9741 addr = PAGE_ALIGN(addr);
9742
9743 vma = find_vma(mm, addr);
9744- if (task_size - len >= addr &&
9745- (!vma || addr + len <= vma->vm_start))
9746+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9747 return addr;
9748 }
9749
9750@@ -192,6 +207,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9751 info.high_limit = mm->mmap_base;
9752 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
9753 info.align_offset = pgoff << PAGE_SHIFT;
9754+ info.threadstack_offset = offset;
9755 addr = vm_unmapped_area(&info);
9756
9757 /*
9758@@ -204,6 +220,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9759 VM_BUG_ON(addr != -ENOMEM);
9760 info.flags = 0;
9761 info.low_limit = TASK_UNMAPPED_BASE;
9762+
9763+#ifdef CONFIG_PAX_RANDMMAP
9764+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9765+ info.low_limit += mm->delta_mmap;
9766+#endif
9767+
9768 info.high_limit = STACK_TOP32;
9769 addr = vm_unmapped_area(&info);
9770 }
9771@@ -260,10 +282,14 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u
9772 EXPORT_SYMBOL(get_fb_unmapped_area);
9773
9774 /* Essentially the same as PowerPC. */
9775-static unsigned long mmap_rnd(void)
9776+static unsigned long mmap_rnd(struct mm_struct *mm)
9777 {
9778 unsigned long rnd = 0UL;
9779
9780+#ifdef CONFIG_PAX_RANDMMAP
9781+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9782+#endif
9783+
9784 if (current->flags & PF_RANDOMIZE) {
9785 unsigned long val = get_random_int();
9786 if (test_thread_flag(TIF_32BIT))
9787@@ -276,7 +302,7 @@ static unsigned long mmap_rnd(void)
9788
9789 void arch_pick_mmap_layout(struct mm_struct *mm)
9790 {
9791- unsigned long random_factor = mmap_rnd();
9792+ unsigned long random_factor = mmap_rnd(mm);
9793 unsigned long gap;
9794
9795 /*
9796@@ -289,6 +315,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9797 gap == RLIM_INFINITY ||
9798 sysctl_legacy_va_layout) {
9799 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
9800+
9801+#ifdef CONFIG_PAX_RANDMMAP
9802+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9803+ mm->mmap_base += mm->delta_mmap;
9804+#endif
9805+
9806 mm->get_unmapped_area = arch_get_unmapped_area;
9807 } else {
9808 /* We know it's 32-bit */
9809@@ -300,6 +332,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9810 gap = (task_size / 6 * 5);
9811
9812 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
9813+
9814+#ifdef CONFIG_PAX_RANDMMAP
9815+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9816+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9817+#endif
9818+
9819 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9820 }
9821 }
9822diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
9823index 22a1098..6255eb9 100644
9824--- a/arch/sparc/kernel/syscalls.S
9825+++ b/arch/sparc/kernel/syscalls.S
9826@@ -52,7 +52,7 @@ sys32_rt_sigreturn:
9827 #endif
9828 .align 32
9829 1: ldx [%g6 + TI_FLAGS], %l5
9830- andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
9831+ andcc %l5, _TIF_WORK_SYSCALL, %g0
9832 be,pt %icc, rtrap
9833 nop
9834 call syscall_trace_leave
9835@@ -184,7 +184,7 @@ linux_sparc_syscall32:
9836
9837 srl %i5, 0, %o5 ! IEU1
9838 srl %i2, 0, %o2 ! IEU0 Group
9839- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
9840+ andcc %l0, _TIF_WORK_SYSCALL, %g0
9841 bne,pn %icc, linux_syscall_trace32 ! CTI
9842 mov %i0, %l5 ! IEU1
9843 call %l7 ! CTI Group brk forced
9844@@ -207,7 +207,7 @@ linux_sparc_syscall:
9845
9846 mov %i3, %o3 ! IEU1
9847 mov %i4, %o4 ! IEU0 Group
9848- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
9849+ andcc %l0, _TIF_WORK_SYSCALL, %g0
9850 bne,pn %icc, linux_syscall_trace ! CTI Group
9851 mov %i0, %l5 ! IEU0
9852 2: call %l7 ! CTI Group brk forced
9853@@ -223,7 +223,7 @@ ret_sys_call:
9854
9855 cmp %o0, -ERESTART_RESTARTBLOCK
9856 bgeu,pn %xcc, 1f
9857- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
9858+ andcc %l0, _TIF_WORK_SYSCALL, %g0
9859 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
9860
9861 2:
9862diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
9863index 6629829..036032d 100644
9864--- a/arch/sparc/kernel/traps_32.c
9865+++ b/arch/sparc/kernel/traps_32.c
9866@@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
9867 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
9868 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
9869
9870+extern void gr_handle_kernel_exploit(void);
9871+
9872 void die_if_kernel(char *str, struct pt_regs *regs)
9873 {
9874 static int die_counter;
9875@@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
9876 count++ < 30 &&
9877 (((unsigned long) rw) >= PAGE_OFFSET) &&
9878 !(((unsigned long) rw) & 0x7)) {
9879- printk("Caller[%08lx]: %pS\n", rw->ins[7],
9880+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
9881 (void *) rw->ins[7]);
9882 rw = (struct reg_window32 *)rw->ins[6];
9883 }
9884 }
9885 printk("Instruction DUMP:");
9886 instruction_dump ((unsigned long *) regs->pc);
9887- if(regs->psr & PSR_PS)
9888+ if(regs->psr & PSR_PS) {
9889+ gr_handle_kernel_exploit();
9890 do_exit(SIGKILL);
9891+ }
9892 do_exit(SIGSEGV);
9893 }
9894
9895diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
9896index b3f833a..f485f80 100644
9897--- a/arch/sparc/kernel/traps_64.c
9898+++ b/arch/sparc/kernel/traps_64.c
9899@@ -76,7 +76,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
9900 i + 1,
9901 p->trapstack[i].tstate, p->trapstack[i].tpc,
9902 p->trapstack[i].tnpc, p->trapstack[i].tt);
9903- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
9904+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
9905 }
9906 }
9907
9908@@ -96,6 +96,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
9909
9910 lvl -= 0x100;
9911 if (regs->tstate & TSTATE_PRIV) {
9912+
9913+#ifdef CONFIG_PAX_REFCOUNT
9914+ if (lvl == 6)
9915+ pax_report_refcount_overflow(regs);
9916+#endif
9917+
9918 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
9919 die_if_kernel(buffer, regs);
9920 }
9921@@ -114,11 +120,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
9922 void bad_trap_tl1(struct pt_regs *regs, long lvl)
9923 {
9924 char buffer[32];
9925-
9926+
9927 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
9928 0, lvl, SIGTRAP) == NOTIFY_STOP)
9929 return;
9930
9931+#ifdef CONFIG_PAX_REFCOUNT
9932+ if (lvl == 6)
9933+ pax_report_refcount_overflow(regs);
9934+#endif
9935+
9936 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
9937
9938 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
9939@@ -1142,7 +1153,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
9940 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
9941 printk("%s" "ERROR(%d): ",
9942 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
9943- printk("TPC<%pS>\n", (void *) regs->tpc);
9944+ printk("TPC<%pA>\n", (void *) regs->tpc);
9945 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
9946 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
9947 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
9948@@ -1749,7 +1760,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
9949 smp_processor_id(),
9950 (type & 0x1) ? 'I' : 'D',
9951 regs->tpc);
9952- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
9953+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
9954 panic("Irrecoverable Cheetah+ parity error.");
9955 }
9956
9957@@ -1757,7 +1768,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
9958 smp_processor_id(),
9959 (type & 0x1) ? 'I' : 'D',
9960 regs->tpc);
9961- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
9962+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
9963 }
9964
9965 struct sun4v_error_entry {
9966@@ -1830,8 +1841,8 @@ struct sun4v_error_entry {
9967 /*0x38*/u64 reserved_5;
9968 };
9969
9970-static atomic_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
9971-static atomic_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
9972+static atomic_unchecked_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
9973+static atomic_unchecked_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
9974
9975 static const char *sun4v_err_type_to_str(u8 type)
9976 {
9977@@ -1923,7 +1934,7 @@ static void sun4v_report_real_raddr(const char *pfx, struct pt_regs *regs)
9978 }
9979
9980 static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
9981- int cpu, const char *pfx, atomic_t *ocnt)
9982+ int cpu, const char *pfx, atomic_unchecked_t *ocnt)
9983 {
9984 u64 *raw_ptr = (u64 *) ent;
9985 u32 attrs;
9986@@ -1981,8 +1992,8 @@ static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
9987
9988 show_regs(regs);
9989
9990- if ((cnt = atomic_read(ocnt)) != 0) {
9991- atomic_set(ocnt, 0);
9992+ if ((cnt = atomic_read_unchecked(ocnt)) != 0) {
9993+ atomic_set_unchecked(ocnt, 0);
9994 wmb();
9995 printk("%s: Queue overflowed %d times.\n",
9996 pfx, cnt);
9997@@ -2036,7 +2047,7 @@ void sun4v_resum_error(struct pt_regs *regs, unsigned long offset)
9998 */
9999 void sun4v_resum_overflow(struct pt_regs *regs)
10000 {
10001- atomic_inc(&sun4v_resum_oflow_cnt);
10002+ atomic_inc_unchecked(&sun4v_resum_oflow_cnt);
10003 }
10004
10005 /* We run with %pil set to PIL_NORMAL_MAX and PSTATE_IE enabled in %pstate.
10006@@ -2089,7 +2100,7 @@ void sun4v_nonresum_overflow(struct pt_regs *regs)
10007 /* XXX Actually even this can make not that much sense. Perhaps
10008 * XXX we should just pull the plug and panic directly from here?
10009 */
10010- atomic_inc(&sun4v_nonresum_oflow_cnt);
10011+ atomic_inc_unchecked(&sun4v_nonresum_oflow_cnt);
10012 }
10013
10014 unsigned long sun4v_err_itlb_vaddr;
10015@@ -2104,9 +2115,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
10016
10017 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
10018 regs->tpc, tl);
10019- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
10020+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
10021 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10022- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
10023+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
10024 (void *) regs->u_regs[UREG_I7]);
10025 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
10026 "pte[%lx] error[%lx]\n",
10027@@ -2128,9 +2139,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
10028
10029 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
10030 regs->tpc, tl);
10031- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
10032+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
10033 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10034- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
10035+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
10036 (void *) regs->u_regs[UREG_I7]);
10037 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
10038 "pte[%lx] error[%lx]\n",
10039@@ -2336,13 +2347,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10040 fp = (unsigned long)sf->fp + STACK_BIAS;
10041 }
10042
10043- printk(" [%016lx] %pS\n", pc, (void *) pc);
10044+ printk(" [%016lx] %pA\n", pc, (void *) pc);
10045 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
10046 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
10047 int index = tsk->curr_ret_stack;
10048 if (tsk->ret_stack && index >= graph) {
10049 pc = tsk->ret_stack[index - graph].ret;
10050- printk(" [%016lx] %pS\n", pc, (void *) pc);
10051+ printk(" [%016lx] %pA\n", pc, (void *) pc);
10052 graph++;
10053 }
10054 }
10055@@ -2360,6 +2371,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
10056 return (struct reg_window *) (fp + STACK_BIAS);
10057 }
10058
10059+extern void gr_handle_kernel_exploit(void);
10060+
10061 void die_if_kernel(char *str, struct pt_regs *regs)
10062 {
10063 static int die_counter;
10064@@ -2388,7 +2401,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10065 while (rw &&
10066 count++ < 30 &&
10067 kstack_valid(tp, (unsigned long) rw)) {
10068- printk("Caller[%016lx]: %pS\n", rw->ins[7],
10069+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
10070 (void *) rw->ins[7]);
10071
10072 rw = kernel_stack_up(rw);
10073@@ -2401,8 +2414,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10074 }
10075 user_instruction_dump ((unsigned int __user *) regs->tpc);
10076 }
10077- if (regs->tstate & TSTATE_PRIV)
10078+ if (regs->tstate & TSTATE_PRIV) {
10079+ gr_handle_kernel_exploit();
10080 do_exit(SIGKILL);
10081+ }
10082 do_exit(SIGSEGV);
10083 }
10084 EXPORT_SYMBOL(die_if_kernel);
10085diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
10086index 8201c25e..072a2a7 100644
10087--- a/arch/sparc/kernel/unaligned_64.c
10088+++ b/arch/sparc/kernel/unaligned_64.c
10089@@ -286,7 +286,7 @@ static void log_unaligned(struct pt_regs *regs)
10090 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
10091
10092 if (__ratelimit(&ratelimit)) {
10093- printk("Kernel unaligned access at TPC[%lx] %pS\n",
10094+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
10095 regs->tpc, (void *) regs->tpc);
10096 }
10097 }
10098diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
10099index dbe119b..089c7c1 100644
10100--- a/arch/sparc/lib/Makefile
10101+++ b/arch/sparc/lib/Makefile
10102@@ -2,7 +2,7 @@
10103 #
10104
10105 asflags-y := -ansi -DST_DIV0=0x02
10106-ccflags-y := -Werror
10107+#ccflags-y := -Werror
10108
10109 lib-$(CONFIG_SPARC32) += ashrdi3.o
10110 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
10111diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
10112index 85c233d..68500e0 100644
10113--- a/arch/sparc/lib/atomic_64.S
10114+++ b/arch/sparc/lib/atomic_64.S
10115@@ -17,7 +17,12 @@
10116 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10117 BACKOFF_SETUP(%o2)
10118 1: lduw [%o1], %g1
10119- add %g1, %o0, %g7
10120+ addcc %g1, %o0, %g7
10121+
10122+#ifdef CONFIG_PAX_REFCOUNT
10123+ tvs %icc, 6
10124+#endif
10125+
10126 cas [%o1], %g1, %g7
10127 cmp %g1, %g7
10128 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10129@@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10130 2: BACKOFF_SPIN(%o2, %o3, 1b)
10131 ENDPROC(atomic_add)
10132
10133+ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10134+ BACKOFF_SETUP(%o2)
10135+1: lduw [%o1], %g1
10136+ add %g1, %o0, %g7
10137+ cas [%o1], %g1, %g7
10138+ cmp %g1, %g7
10139+ bne,pn %icc, 2f
10140+ nop
10141+ retl
10142+ nop
10143+2: BACKOFF_SPIN(%o2, %o3, 1b)
10144+ENDPROC(atomic_add_unchecked)
10145+
10146 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10147 BACKOFF_SETUP(%o2)
10148 1: lduw [%o1], %g1
10149- sub %g1, %o0, %g7
10150+ subcc %g1, %o0, %g7
10151+
10152+#ifdef CONFIG_PAX_REFCOUNT
10153+ tvs %icc, 6
10154+#endif
10155+
10156 cas [%o1], %g1, %g7
10157 cmp %g1, %g7
10158 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10159@@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10160 2: BACKOFF_SPIN(%o2, %o3, 1b)
10161 ENDPROC(atomic_sub)
10162
10163+ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10164+ BACKOFF_SETUP(%o2)
10165+1: lduw [%o1], %g1
10166+ sub %g1, %o0, %g7
10167+ cas [%o1], %g1, %g7
10168+ cmp %g1, %g7
10169+ bne,pn %icc, 2f
10170+ nop
10171+ retl
10172+ nop
10173+2: BACKOFF_SPIN(%o2, %o3, 1b)
10174+ENDPROC(atomic_sub_unchecked)
10175+
10176 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10177 BACKOFF_SETUP(%o2)
10178 1: lduw [%o1], %g1
10179- add %g1, %o0, %g7
10180+ addcc %g1, %o0, %g7
10181+
10182+#ifdef CONFIG_PAX_REFCOUNT
10183+ tvs %icc, 6
10184+#endif
10185+
10186 cas [%o1], %g1, %g7
10187 cmp %g1, %g7
10188 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10189@@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10190 2: BACKOFF_SPIN(%o2, %o3, 1b)
10191 ENDPROC(atomic_add_ret)
10192
10193+ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10194+ BACKOFF_SETUP(%o2)
10195+1: lduw [%o1], %g1
10196+ addcc %g1, %o0, %g7
10197+ cas [%o1], %g1, %g7
10198+ cmp %g1, %g7
10199+ bne,pn %icc, 2f
10200+ add %g7, %o0, %g7
10201+ sra %g7, 0, %o0
10202+ retl
10203+ nop
10204+2: BACKOFF_SPIN(%o2, %o3, 1b)
10205+ENDPROC(atomic_add_ret_unchecked)
10206+
10207 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
10208 BACKOFF_SETUP(%o2)
10209 1: lduw [%o1], %g1
10210- sub %g1, %o0, %g7
10211+ subcc %g1, %o0, %g7
10212+
10213+#ifdef CONFIG_PAX_REFCOUNT
10214+ tvs %icc, 6
10215+#endif
10216+
10217 cas [%o1], %g1, %g7
10218 cmp %g1, %g7
10219 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10220@@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
10221 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10222 BACKOFF_SETUP(%o2)
10223 1: ldx [%o1], %g1
10224- add %g1, %o0, %g7
10225+ addcc %g1, %o0, %g7
10226+
10227+#ifdef CONFIG_PAX_REFCOUNT
10228+ tvs %xcc, 6
10229+#endif
10230+
10231 casx [%o1], %g1, %g7
10232 cmp %g1, %g7
10233 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10234@@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10235 2: BACKOFF_SPIN(%o2, %o3, 1b)
10236 ENDPROC(atomic64_add)
10237
10238+ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10239+ BACKOFF_SETUP(%o2)
10240+1: ldx [%o1], %g1
10241+ addcc %g1, %o0, %g7
10242+ casx [%o1], %g1, %g7
10243+ cmp %g1, %g7
10244+ bne,pn %xcc, 2f
10245+ nop
10246+ retl
10247+ nop
10248+2: BACKOFF_SPIN(%o2, %o3, 1b)
10249+ENDPROC(atomic64_add_unchecked)
10250+
10251 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10252 BACKOFF_SETUP(%o2)
10253 1: ldx [%o1], %g1
10254- sub %g1, %o0, %g7
10255+ subcc %g1, %o0, %g7
10256+
10257+#ifdef CONFIG_PAX_REFCOUNT
10258+ tvs %xcc, 6
10259+#endif
10260+
10261 casx [%o1], %g1, %g7
10262 cmp %g1, %g7
10263 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10264@@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10265 2: BACKOFF_SPIN(%o2, %o3, 1b)
10266 ENDPROC(atomic64_sub)
10267
10268+ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10269+ BACKOFF_SETUP(%o2)
10270+1: ldx [%o1], %g1
10271+ subcc %g1, %o0, %g7
10272+ casx [%o1], %g1, %g7
10273+ cmp %g1, %g7
10274+ bne,pn %xcc, 2f
10275+ nop
10276+ retl
10277+ nop
10278+2: BACKOFF_SPIN(%o2, %o3, 1b)
10279+ENDPROC(atomic64_sub_unchecked)
10280+
10281 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10282 BACKOFF_SETUP(%o2)
10283 1: ldx [%o1], %g1
10284- add %g1, %o0, %g7
10285+ addcc %g1, %o0, %g7
10286+
10287+#ifdef CONFIG_PAX_REFCOUNT
10288+ tvs %xcc, 6
10289+#endif
10290+
10291 casx [%o1], %g1, %g7
10292 cmp %g1, %g7
10293 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10294@@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10295 2: BACKOFF_SPIN(%o2, %o3, 1b)
10296 ENDPROC(atomic64_add_ret)
10297
10298+ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10299+ BACKOFF_SETUP(%o2)
10300+1: ldx [%o1], %g1
10301+ addcc %g1, %o0, %g7
10302+ casx [%o1], %g1, %g7
10303+ cmp %g1, %g7
10304+ bne,pn %xcc, 2f
10305+ add %g7, %o0, %g7
10306+ mov %g7, %o0
10307+ retl
10308+ nop
10309+2: BACKOFF_SPIN(%o2, %o3, 1b)
10310+ENDPROC(atomic64_add_ret_unchecked)
10311+
10312 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
10313 BACKOFF_SETUP(%o2)
10314 1: ldx [%o1], %g1
10315- sub %g1, %o0, %g7
10316+ subcc %g1, %o0, %g7
10317+
10318+#ifdef CONFIG_PAX_REFCOUNT
10319+ tvs %xcc, 6
10320+#endif
10321+
10322 casx [%o1], %g1, %g7
10323 cmp %g1, %g7
10324 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10325diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
10326index 0c4e35e..745d3e4 100644
10327--- a/arch/sparc/lib/ksyms.c
10328+++ b/arch/sparc/lib/ksyms.c
10329@@ -109,12 +109,18 @@ EXPORT_SYMBOL(__downgrade_write);
10330
10331 /* Atomic counter implementation. */
10332 EXPORT_SYMBOL(atomic_add);
10333+EXPORT_SYMBOL(atomic_add_unchecked);
10334 EXPORT_SYMBOL(atomic_add_ret);
10335+EXPORT_SYMBOL(atomic_add_ret_unchecked);
10336 EXPORT_SYMBOL(atomic_sub);
10337+EXPORT_SYMBOL(atomic_sub_unchecked);
10338 EXPORT_SYMBOL(atomic_sub_ret);
10339 EXPORT_SYMBOL(atomic64_add);
10340+EXPORT_SYMBOL(atomic64_add_unchecked);
10341 EXPORT_SYMBOL(atomic64_add_ret);
10342+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
10343 EXPORT_SYMBOL(atomic64_sub);
10344+EXPORT_SYMBOL(atomic64_sub_unchecked);
10345 EXPORT_SYMBOL(atomic64_sub_ret);
10346 EXPORT_SYMBOL(atomic64_dec_if_positive);
10347
10348diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
10349index 30c3ecc..736f015 100644
10350--- a/arch/sparc/mm/Makefile
10351+++ b/arch/sparc/mm/Makefile
10352@@ -2,7 +2,7 @@
10353 #
10354
10355 asflags-y := -ansi
10356-ccflags-y := -Werror
10357+#ccflags-y := -Werror
10358
10359 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
10360 obj-y += fault_$(BITS).o
10361diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
10362index e98bfda..ea8d221 100644
10363--- a/arch/sparc/mm/fault_32.c
10364+++ b/arch/sparc/mm/fault_32.c
10365@@ -21,6 +21,9 @@
10366 #include <linux/perf_event.h>
10367 #include <linux/interrupt.h>
10368 #include <linux/kdebug.h>
10369+#include <linux/slab.h>
10370+#include <linux/pagemap.h>
10371+#include <linux/compiler.h>
10372
10373 #include <asm/page.h>
10374 #include <asm/pgtable.h>
10375@@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
10376 return safe_compute_effective_address(regs, insn);
10377 }
10378
10379+#ifdef CONFIG_PAX_PAGEEXEC
10380+#ifdef CONFIG_PAX_DLRESOLVE
10381+static void pax_emuplt_close(struct vm_area_struct *vma)
10382+{
10383+ vma->vm_mm->call_dl_resolve = 0UL;
10384+}
10385+
10386+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
10387+{
10388+ unsigned int *kaddr;
10389+
10390+ vmf->page = alloc_page(GFP_HIGHUSER);
10391+ if (!vmf->page)
10392+ return VM_FAULT_OOM;
10393+
10394+ kaddr = kmap(vmf->page);
10395+ memset(kaddr, 0, PAGE_SIZE);
10396+ kaddr[0] = 0x9DE3BFA8U; /* save */
10397+ flush_dcache_page(vmf->page);
10398+ kunmap(vmf->page);
10399+ return VM_FAULT_MAJOR;
10400+}
10401+
10402+static const struct vm_operations_struct pax_vm_ops = {
10403+ .close = pax_emuplt_close,
10404+ .fault = pax_emuplt_fault
10405+};
10406+
10407+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
10408+{
10409+ int ret;
10410+
10411+ INIT_LIST_HEAD(&vma->anon_vma_chain);
10412+ vma->vm_mm = current->mm;
10413+ vma->vm_start = addr;
10414+ vma->vm_end = addr + PAGE_SIZE;
10415+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
10416+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
10417+ vma->vm_ops = &pax_vm_ops;
10418+
10419+ ret = insert_vm_struct(current->mm, vma);
10420+ if (ret)
10421+ return ret;
10422+
10423+ ++current->mm->total_vm;
10424+ return 0;
10425+}
10426+#endif
10427+
10428+/*
10429+ * PaX: decide what to do with offenders (regs->pc = fault address)
10430+ *
10431+ * returns 1 when task should be killed
10432+ * 2 when patched PLT trampoline was detected
10433+ * 3 when unpatched PLT trampoline was detected
10434+ */
10435+static int pax_handle_fetch_fault(struct pt_regs *regs)
10436+{
10437+
10438+#ifdef CONFIG_PAX_EMUPLT
10439+ int err;
10440+
10441+ do { /* PaX: patched PLT emulation #1 */
10442+ unsigned int sethi1, sethi2, jmpl;
10443+
10444+ err = get_user(sethi1, (unsigned int *)regs->pc);
10445+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
10446+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
10447+
10448+ if (err)
10449+ break;
10450+
10451+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
10452+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
10453+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
10454+ {
10455+ unsigned int addr;
10456+
10457+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
10458+ addr = regs->u_regs[UREG_G1];
10459+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
10460+ regs->pc = addr;
10461+ regs->npc = addr+4;
10462+ return 2;
10463+ }
10464+ } while (0);
10465+
10466+ do { /* PaX: patched PLT emulation #2 */
10467+ unsigned int ba;
10468+
10469+ err = get_user(ba, (unsigned int *)regs->pc);
10470+
10471+ if (err)
10472+ break;
10473+
10474+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
10475+ unsigned int addr;
10476+
10477+ if ((ba & 0xFFC00000U) == 0x30800000U)
10478+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
10479+ else
10480+ addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
10481+ regs->pc = addr;
10482+ regs->npc = addr+4;
10483+ return 2;
10484+ }
10485+ } while (0);
10486+
10487+ do { /* PaX: patched PLT emulation #3 */
10488+ unsigned int sethi, bajmpl, nop;
10489+
10490+ err = get_user(sethi, (unsigned int *)regs->pc);
10491+ err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
10492+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
10493+
10494+ if (err)
10495+ break;
10496+
10497+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10498+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
10499+ nop == 0x01000000U)
10500+ {
10501+ unsigned int addr;
10502+
10503+ addr = (sethi & 0x003FFFFFU) << 10;
10504+ regs->u_regs[UREG_G1] = addr;
10505+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
10506+ addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
10507+ else
10508+ addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
10509+ regs->pc = addr;
10510+ regs->npc = addr+4;
10511+ return 2;
10512+ }
10513+ } while (0);
10514+
10515+ do { /* PaX: unpatched PLT emulation step 1 */
10516+ unsigned int sethi, ba, nop;
10517+
10518+ err = get_user(sethi, (unsigned int *)regs->pc);
10519+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
10520+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
10521+
10522+ if (err)
10523+ break;
10524+
10525+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10526+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
10527+ nop == 0x01000000U)
10528+ {
10529+ unsigned int addr, save, call;
10530+
10531+ if ((ba & 0xFFC00000U) == 0x30800000U)
10532+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
10533+ else
10534+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
10535+
10536+ err = get_user(save, (unsigned int *)addr);
10537+ err |= get_user(call, (unsigned int *)(addr+4));
10538+ err |= get_user(nop, (unsigned int *)(addr+8));
10539+ if (err)
10540+ break;
10541+
10542+#ifdef CONFIG_PAX_DLRESOLVE
10543+ if (save == 0x9DE3BFA8U &&
10544+ (call & 0xC0000000U) == 0x40000000U &&
10545+ nop == 0x01000000U)
10546+ {
10547+ struct vm_area_struct *vma;
10548+ unsigned long call_dl_resolve;
10549+
10550+ down_read(&current->mm->mmap_sem);
10551+ call_dl_resolve = current->mm->call_dl_resolve;
10552+ up_read(&current->mm->mmap_sem);
10553+ if (likely(call_dl_resolve))
10554+ goto emulate;
10555+
10556+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
10557+
10558+ down_write(&current->mm->mmap_sem);
10559+ if (current->mm->call_dl_resolve) {
10560+ call_dl_resolve = current->mm->call_dl_resolve;
10561+ up_write(&current->mm->mmap_sem);
10562+ if (vma)
10563+ kmem_cache_free(vm_area_cachep, vma);
10564+ goto emulate;
10565+ }
10566+
10567+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
10568+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
10569+ up_write(&current->mm->mmap_sem);
10570+ if (vma)
10571+ kmem_cache_free(vm_area_cachep, vma);
10572+ return 1;
10573+ }
10574+
10575+ if (pax_insert_vma(vma, call_dl_resolve)) {
10576+ up_write(&current->mm->mmap_sem);
10577+ kmem_cache_free(vm_area_cachep, vma);
10578+ return 1;
10579+ }
10580+
10581+ current->mm->call_dl_resolve = call_dl_resolve;
10582+ up_write(&current->mm->mmap_sem);
10583+
10584+emulate:
10585+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
10586+ regs->pc = call_dl_resolve;
10587+ regs->npc = addr+4;
10588+ return 3;
10589+ }
10590+#endif
10591+
10592+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
10593+ if ((save & 0xFFC00000U) == 0x05000000U &&
10594+ (call & 0xFFFFE000U) == 0x85C0A000U &&
10595+ nop == 0x01000000U)
10596+ {
10597+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
10598+ regs->u_regs[UREG_G2] = addr + 4;
10599+ addr = (save & 0x003FFFFFU) << 10;
10600+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
10601+ regs->pc = addr;
10602+ regs->npc = addr+4;
10603+ return 3;
10604+ }
10605+ }
10606+ } while (0);
10607+
10608+ do { /* PaX: unpatched PLT emulation step 2 */
10609+ unsigned int save, call, nop;
10610+
10611+ err = get_user(save, (unsigned int *)(regs->pc-4));
10612+ err |= get_user(call, (unsigned int *)regs->pc);
10613+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
10614+ if (err)
10615+ break;
10616+
10617+ if (save == 0x9DE3BFA8U &&
10618+ (call & 0xC0000000U) == 0x40000000U &&
10619+ nop == 0x01000000U)
10620+ {
10621+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
10622+
10623+ regs->u_regs[UREG_RETPC] = regs->pc;
10624+ regs->pc = dl_resolve;
10625+ regs->npc = dl_resolve+4;
10626+ return 3;
10627+ }
10628+ } while (0);
10629+#endif
10630+
10631+ return 1;
10632+}
10633+
10634+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
10635+{
10636+ unsigned long i;
10637+
10638+ printk(KERN_ERR "PAX: bytes at PC: ");
10639+ for (i = 0; i < 8; i++) {
10640+ unsigned int c;
10641+ if (get_user(c, (unsigned int *)pc+i))
10642+ printk(KERN_CONT "???????? ");
10643+ else
10644+ printk(KERN_CONT "%08x ", c);
10645+ }
10646+ printk("\n");
10647+}
10648+#endif
10649+
10650 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
10651 int text_fault)
10652 {
10653@@ -230,6 +504,24 @@ good_area:
10654 if (!(vma->vm_flags & VM_WRITE))
10655 goto bad_area;
10656 } else {
10657+
10658+#ifdef CONFIG_PAX_PAGEEXEC
10659+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
10660+ up_read(&mm->mmap_sem);
10661+ switch (pax_handle_fetch_fault(regs)) {
10662+
10663+#ifdef CONFIG_PAX_EMUPLT
10664+ case 2:
10665+ case 3:
10666+ return;
10667+#endif
10668+
10669+ }
10670+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
10671+ do_group_exit(SIGKILL);
10672+ }
10673+#endif
10674+
10675 /* Allow reads even for write-only mappings */
10676 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
10677 goto bad_area;
10678diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
10679index 5062ff3..e0b75f3 100644
10680--- a/arch/sparc/mm/fault_64.c
10681+++ b/arch/sparc/mm/fault_64.c
10682@@ -21,6 +21,9 @@
10683 #include <linux/kprobes.h>
10684 #include <linux/kdebug.h>
10685 #include <linux/percpu.h>
10686+#include <linux/slab.h>
10687+#include <linux/pagemap.h>
10688+#include <linux/compiler.h>
10689
10690 #include <asm/page.h>
10691 #include <asm/pgtable.h>
10692@@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
10693 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
10694 regs->tpc);
10695 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
10696- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
10697+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
10698 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
10699 dump_stack();
10700 unhandled_fault(regs->tpc, current, regs);
10701@@ -270,6 +273,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
10702 show_regs(regs);
10703 }
10704
10705+#ifdef CONFIG_PAX_PAGEEXEC
10706+#ifdef CONFIG_PAX_DLRESOLVE
10707+static void pax_emuplt_close(struct vm_area_struct *vma)
10708+{
10709+ vma->vm_mm->call_dl_resolve = 0UL;
10710+}
10711+
10712+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
10713+{
10714+ unsigned int *kaddr;
10715+
10716+ vmf->page = alloc_page(GFP_HIGHUSER);
10717+ if (!vmf->page)
10718+ return VM_FAULT_OOM;
10719+
10720+ kaddr = kmap(vmf->page);
10721+ memset(kaddr, 0, PAGE_SIZE);
10722+ kaddr[0] = 0x9DE3BFA8U; /* save */
10723+ flush_dcache_page(vmf->page);
10724+ kunmap(vmf->page);
10725+ return VM_FAULT_MAJOR;
10726+}
10727+
10728+static const struct vm_operations_struct pax_vm_ops = {
10729+ .close = pax_emuplt_close,
10730+ .fault = pax_emuplt_fault
10731+};
10732+
10733+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
10734+{
10735+ int ret;
10736+
10737+ INIT_LIST_HEAD(&vma->anon_vma_chain);
10738+ vma->vm_mm = current->mm;
10739+ vma->vm_start = addr;
10740+ vma->vm_end = addr + PAGE_SIZE;
10741+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
10742+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
10743+ vma->vm_ops = &pax_vm_ops;
10744+
10745+ ret = insert_vm_struct(current->mm, vma);
10746+ if (ret)
10747+ return ret;
10748+
10749+ ++current->mm->total_vm;
10750+ return 0;
10751+}
10752+#endif
10753+
10754+/*
10755+ * PaX: decide what to do with offenders (regs->tpc = fault address)
10756+ *
10757+ * returns 1 when task should be killed
10758+ * 2 when patched PLT trampoline was detected
10759+ * 3 when unpatched PLT trampoline was detected
10760+ */
10761+static int pax_handle_fetch_fault(struct pt_regs *regs)
10762+{
10763+
10764+#ifdef CONFIG_PAX_EMUPLT
10765+ int err;
10766+
10767+ do { /* PaX: patched PLT emulation #1 */
10768+ unsigned int sethi1, sethi2, jmpl;
10769+
10770+ err = get_user(sethi1, (unsigned int *)regs->tpc);
10771+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
10772+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
10773+
10774+ if (err)
10775+ break;
10776+
10777+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
10778+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
10779+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
10780+ {
10781+ unsigned long addr;
10782+
10783+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
10784+ addr = regs->u_regs[UREG_G1];
10785+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
10786+
10787+ if (test_thread_flag(TIF_32BIT))
10788+ addr &= 0xFFFFFFFFUL;
10789+
10790+ regs->tpc = addr;
10791+ regs->tnpc = addr+4;
10792+ return 2;
10793+ }
10794+ } while (0);
10795+
10796+ do { /* PaX: patched PLT emulation #2 */
10797+ unsigned int ba;
10798+
10799+ err = get_user(ba, (unsigned int *)regs->tpc);
10800+
10801+ if (err)
10802+ break;
10803+
10804+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
10805+ unsigned long addr;
10806+
10807+ if ((ba & 0xFFC00000U) == 0x30800000U)
10808+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
10809+ else
10810+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
10811+
10812+ if (test_thread_flag(TIF_32BIT))
10813+ addr &= 0xFFFFFFFFUL;
10814+
10815+ regs->tpc = addr;
10816+ regs->tnpc = addr+4;
10817+ return 2;
10818+ }
10819+ } while (0);
10820+
10821+ do { /* PaX: patched PLT emulation #3 */
10822+ unsigned int sethi, bajmpl, nop;
10823+
10824+ err = get_user(sethi, (unsigned int *)regs->tpc);
10825+ err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
10826+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
10827+
10828+ if (err)
10829+ break;
10830+
10831+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10832+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
10833+ nop == 0x01000000U)
10834+ {
10835+ unsigned long addr;
10836+
10837+ addr = (sethi & 0x003FFFFFU) << 10;
10838+ regs->u_regs[UREG_G1] = addr;
10839+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
10840+ addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
10841+ else
10842+ addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
10843+
10844+ if (test_thread_flag(TIF_32BIT))
10845+ addr &= 0xFFFFFFFFUL;
10846+
10847+ regs->tpc = addr;
10848+ regs->tnpc = addr+4;
10849+ return 2;
10850+ }
10851+ } while (0);
10852+
10853+ do { /* PaX: patched PLT emulation #4 */
10854+ unsigned int sethi, mov1, call, mov2;
10855+
10856+ err = get_user(sethi, (unsigned int *)regs->tpc);
10857+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
10858+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
10859+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
10860+
10861+ if (err)
10862+ break;
10863+
10864+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10865+ mov1 == 0x8210000FU &&
10866+ (call & 0xC0000000U) == 0x40000000U &&
10867+ mov2 == 0x9E100001U)
10868+ {
10869+ unsigned long addr;
10870+
10871+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
10872+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
10873+
10874+ if (test_thread_flag(TIF_32BIT))
10875+ addr &= 0xFFFFFFFFUL;
10876+
10877+ regs->tpc = addr;
10878+ regs->tnpc = addr+4;
10879+ return 2;
10880+ }
10881+ } while (0);
10882+
10883+ do { /* PaX: patched PLT emulation #5 */
10884+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
10885+
10886+ err = get_user(sethi, (unsigned int *)regs->tpc);
10887+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
10888+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
10889+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
10890+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
10891+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
10892+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
10893+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
10894+
10895+ if (err)
10896+ break;
10897+
10898+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10899+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
10900+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
10901+ (or1 & 0xFFFFE000U) == 0x82106000U &&
10902+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
10903+ sllx == 0x83287020U &&
10904+ jmpl == 0x81C04005U &&
10905+ nop == 0x01000000U)
10906+ {
10907+ unsigned long addr;
10908+
10909+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
10910+ regs->u_regs[UREG_G1] <<= 32;
10911+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
10912+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
10913+ regs->tpc = addr;
10914+ regs->tnpc = addr+4;
10915+ return 2;
10916+ }
10917+ } while (0);
10918+
10919+ do { /* PaX: patched PLT emulation #6 */
10920+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
10921+
10922+ err = get_user(sethi, (unsigned int *)regs->tpc);
10923+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
10924+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
10925+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
10926+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
10927+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
10928+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
10929+
10930+ if (err)
10931+ break;
10932+
10933+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10934+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
10935+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
10936+ sllx == 0x83287020U &&
10937+ (or & 0xFFFFE000U) == 0x8A116000U &&
10938+ jmpl == 0x81C04005U &&
10939+ nop == 0x01000000U)
10940+ {
10941+ unsigned long addr;
10942+
10943+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
10944+ regs->u_regs[UREG_G1] <<= 32;
10945+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
10946+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
10947+ regs->tpc = addr;
10948+ regs->tnpc = addr+4;
10949+ return 2;
10950+ }
10951+ } while (0);
10952+
10953+ do { /* PaX: unpatched PLT emulation step 1 */
10954+ unsigned int sethi, ba, nop;
10955+
10956+ err = get_user(sethi, (unsigned int *)regs->tpc);
10957+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
10958+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
10959+
10960+ if (err)
10961+ break;
10962+
10963+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10964+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
10965+ nop == 0x01000000U)
10966+ {
10967+ unsigned long addr;
10968+ unsigned int save, call;
10969+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
10970+
10971+ if ((ba & 0xFFC00000U) == 0x30800000U)
10972+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
10973+ else
10974+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
10975+
10976+ if (test_thread_flag(TIF_32BIT))
10977+ addr &= 0xFFFFFFFFUL;
10978+
10979+ err = get_user(save, (unsigned int *)addr);
10980+ err |= get_user(call, (unsigned int *)(addr+4));
10981+ err |= get_user(nop, (unsigned int *)(addr+8));
10982+ if (err)
10983+ break;
10984+
10985+#ifdef CONFIG_PAX_DLRESOLVE
10986+ if (save == 0x9DE3BFA8U &&
10987+ (call & 0xC0000000U) == 0x40000000U &&
10988+ nop == 0x01000000U)
10989+ {
10990+ struct vm_area_struct *vma;
10991+ unsigned long call_dl_resolve;
10992+
10993+ down_read(&current->mm->mmap_sem);
10994+ call_dl_resolve = current->mm->call_dl_resolve;
10995+ up_read(&current->mm->mmap_sem);
10996+ if (likely(call_dl_resolve))
10997+ goto emulate;
10998+
10999+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11000+
11001+ down_write(&current->mm->mmap_sem);
11002+ if (current->mm->call_dl_resolve) {
11003+ call_dl_resolve = current->mm->call_dl_resolve;
11004+ up_write(&current->mm->mmap_sem);
11005+ if (vma)
11006+ kmem_cache_free(vm_area_cachep, vma);
11007+ goto emulate;
11008+ }
11009+
11010+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11011+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11012+ up_write(&current->mm->mmap_sem);
11013+ if (vma)
11014+ kmem_cache_free(vm_area_cachep, vma);
11015+ return 1;
11016+ }
11017+
11018+ if (pax_insert_vma(vma, call_dl_resolve)) {
11019+ up_write(&current->mm->mmap_sem);
11020+ kmem_cache_free(vm_area_cachep, vma);
11021+ return 1;
11022+ }
11023+
11024+ current->mm->call_dl_resolve = call_dl_resolve;
11025+ up_write(&current->mm->mmap_sem);
11026+
11027+emulate:
11028+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11029+ regs->tpc = call_dl_resolve;
11030+ regs->tnpc = addr+4;
11031+ return 3;
11032+ }
11033+#endif
11034+
11035+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11036+ if ((save & 0xFFC00000U) == 0x05000000U &&
11037+ (call & 0xFFFFE000U) == 0x85C0A000U &&
11038+ nop == 0x01000000U)
11039+ {
11040+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11041+ regs->u_regs[UREG_G2] = addr + 4;
11042+ addr = (save & 0x003FFFFFU) << 10;
11043+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11044+
11045+ if (test_thread_flag(TIF_32BIT))
11046+ addr &= 0xFFFFFFFFUL;
11047+
11048+ regs->tpc = addr;
11049+ regs->tnpc = addr+4;
11050+ return 3;
11051+ }
11052+
11053+ /* PaX: 64-bit PLT stub */
11054+ err = get_user(sethi1, (unsigned int *)addr);
11055+ err |= get_user(sethi2, (unsigned int *)(addr+4));
11056+ err |= get_user(or1, (unsigned int *)(addr+8));
11057+ err |= get_user(or2, (unsigned int *)(addr+12));
11058+ err |= get_user(sllx, (unsigned int *)(addr+16));
11059+ err |= get_user(add, (unsigned int *)(addr+20));
11060+ err |= get_user(jmpl, (unsigned int *)(addr+24));
11061+ err |= get_user(nop, (unsigned int *)(addr+28));
11062+ if (err)
11063+ break;
11064+
11065+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
11066+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11067+ (or1 & 0xFFFFE000U) == 0x88112000U &&
11068+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
11069+ sllx == 0x89293020U &&
11070+ add == 0x8A010005U &&
11071+ jmpl == 0x89C14000U &&
11072+ nop == 0x01000000U)
11073+ {
11074+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11075+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11076+ regs->u_regs[UREG_G4] <<= 32;
11077+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11078+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
11079+ regs->u_regs[UREG_G4] = addr + 24;
11080+ addr = regs->u_regs[UREG_G5];
11081+ regs->tpc = addr;
11082+ regs->tnpc = addr+4;
11083+ return 3;
11084+ }
11085+ }
11086+ } while (0);
11087+
11088+#ifdef CONFIG_PAX_DLRESOLVE
11089+ do { /* PaX: unpatched PLT emulation step 2 */
11090+ unsigned int save, call, nop;
11091+
11092+ err = get_user(save, (unsigned int *)(regs->tpc-4));
11093+ err |= get_user(call, (unsigned int *)regs->tpc);
11094+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
11095+ if (err)
11096+ break;
11097+
11098+ if (save == 0x9DE3BFA8U &&
11099+ (call & 0xC0000000U) == 0x40000000U &&
11100+ nop == 0x01000000U)
11101+ {
11102+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11103+
11104+ if (test_thread_flag(TIF_32BIT))
11105+ dl_resolve &= 0xFFFFFFFFUL;
11106+
11107+ regs->u_regs[UREG_RETPC] = regs->tpc;
11108+ regs->tpc = dl_resolve;
11109+ regs->tnpc = dl_resolve+4;
11110+ return 3;
11111+ }
11112+ } while (0);
11113+#endif
11114+
11115+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
11116+ unsigned int sethi, ba, nop;
11117+
11118+ err = get_user(sethi, (unsigned int *)regs->tpc);
11119+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11120+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11121+
11122+ if (err)
11123+ break;
11124+
11125+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11126+ (ba & 0xFFF00000U) == 0x30600000U &&
11127+ nop == 0x01000000U)
11128+ {
11129+ unsigned long addr;
11130+
11131+ addr = (sethi & 0x003FFFFFU) << 10;
11132+ regs->u_regs[UREG_G1] = addr;
11133+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11134+
11135+ if (test_thread_flag(TIF_32BIT))
11136+ addr &= 0xFFFFFFFFUL;
11137+
11138+ regs->tpc = addr;
11139+ regs->tnpc = addr+4;
11140+ return 2;
11141+ }
11142+ } while (0);
11143+
11144+#endif
11145+
11146+ return 1;
11147+}
11148+
11149+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11150+{
11151+ unsigned long i;
11152+
11153+ printk(KERN_ERR "PAX: bytes at PC: ");
11154+ for (i = 0; i < 8; i++) {
11155+ unsigned int c;
11156+ if (get_user(c, (unsigned int *)pc+i))
11157+ printk(KERN_CONT "???????? ");
11158+ else
11159+ printk(KERN_CONT "%08x ", c);
11160+ }
11161+ printk("\n");
11162+}
11163+#endif
11164+
11165 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
11166 {
11167 struct mm_struct *mm = current->mm;
11168@@ -341,6 +804,29 @@ retry:
11169 if (!vma)
11170 goto bad_area;
11171
11172+#ifdef CONFIG_PAX_PAGEEXEC
11173+ /* PaX: detect ITLB misses on non-exec pages */
11174+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
11175+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
11176+ {
11177+ if (address != regs->tpc)
11178+ goto good_area;
11179+
11180+ up_read(&mm->mmap_sem);
11181+ switch (pax_handle_fetch_fault(regs)) {
11182+
11183+#ifdef CONFIG_PAX_EMUPLT
11184+ case 2:
11185+ case 3:
11186+ return;
11187+#endif
11188+
11189+ }
11190+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
11191+ do_group_exit(SIGKILL);
11192+ }
11193+#endif
11194+
11195 /* Pure DTLB misses do not tell us whether the fault causing
11196 * load/store/atomic was a write or not, it only says that there
11197 * was no match. So in such a case we (carefully) read the
11198diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
11199index d2b5944..d878f3c 100644
11200--- a/arch/sparc/mm/hugetlbpage.c
11201+++ b/arch/sparc/mm/hugetlbpage.c
11202@@ -28,7 +28,8 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11203 unsigned long addr,
11204 unsigned long len,
11205 unsigned long pgoff,
11206- unsigned long flags)
11207+ unsigned long flags,
11208+ unsigned long offset)
11209 {
11210 unsigned long task_size = TASK_SIZE;
11211 struct vm_unmapped_area_info info;
11212@@ -38,15 +39,22 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11213
11214 info.flags = 0;
11215 info.length = len;
11216- info.low_limit = TASK_UNMAPPED_BASE;
11217+ info.low_limit = mm->mmap_base;
11218 info.high_limit = min(task_size, VA_EXCLUDE_START);
11219 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11220 info.align_offset = 0;
11221+ info.threadstack_offset = offset;
11222 addr = vm_unmapped_area(&info);
11223
11224 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
11225 VM_BUG_ON(addr != -ENOMEM);
11226 info.low_limit = VA_EXCLUDE_END;
11227+
11228+#ifdef CONFIG_PAX_RANDMMAP
11229+ if (mm->pax_flags & MF_PAX_RANDMMAP)
11230+ info.low_limit += mm->delta_mmap;
11231+#endif
11232+
11233 info.high_limit = task_size;
11234 addr = vm_unmapped_area(&info);
11235 }
11236@@ -58,7 +66,8 @@ static unsigned long
11237 hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11238 const unsigned long len,
11239 const unsigned long pgoff,
11240- const unsigned long flags)
11241+ const unsigned long flags,
11242+ const unsigned long offset)
11243 {
11244 struct mm_struct *mm = current->mm;
11245 unsigned long addr = addr0;
11246@@ -73,6 +82,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11247 info.high_limit = mm->mmap_base;
11248 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11249 info.align_offset = 0;
11250+ info.threadstack_offset = offset;
11251 addr = vm_unmapped_area(&info);
11252
11253 /*
11254@@ -85,6 +95,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11255 VM_BUG_ON(addr != -ENOMEM);
11256 info.flags = 0;
11257 info.low_limit = TASK_UNMAPPED_BASE;
11258+
11259+#ifdef CONFIG_PAX_RANDMMAP
11260+ if (mm->pax_flags & MF_PAX_RANDMMAP)
11261+ info.low_limit += mm->delta_mmap;
11262+#endif
11263+
11264 info.high_limit = STACK_TOP32;
11265 addr = vm_unmapped_area(&info);
11266 }
11267@@ -99,6 +115,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
11268 struct mm_struct *mm = current->mm;
11269 struct vm_area_struct *vma;
11270 unsigned long task_size = TASK_SIZE;
11271+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
11272
11273 if (test_thread_flag(TIF_32BIT))
11274 task_size = STACK_TOP32;
11275@@ -114,19 +131,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
11276 return addr;
11277 }
11278
11279+#ifdef CONFIG_PAX_RANDMMAP
11280+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
11281+#endif
11282+
11283 if (addr) {
11284 addr = ALIGN(addr, HPAGE_SIZE);
11285 vma = find_vma(mm, addr);
11286- if (task_size - len >= addr &&
11287- (!vma || addr + len <= vma->vm_start))
11288+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
11289 return addr;
11290 }
11291 if (mm->get_unmapped_area == arch_get_unmapped_area)
11292 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
11293- pgoff, flags);
11294+ pgoff, flags, offset);
11295 else
11296 return hugetlb_get_unmapped_area_topdown(file, addr, len,
11297- pgoff, flags);
11298+ pgoff, flags, offset);
11299 }
11300
11301 pte_t *huge_pte_alloc(struct mm_struct *mm,
11302diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
11303index ed82eda..0d80e77 100644
11304--- a/arch/sparc/mm/init_64.c
11305+++ b/arch/sparc/mm/init_64.c
11306@@ -188,9 +188,9 @@ unsigned long sparc64_kern_sec_context __read_mostly;
11307 int num_kernel_image_mappings;
11308
11309 #ifdef CONFIG_DEBUG_DCFLUSH
11310-atomic_t dcpage_flushes = ATOMIC_INIT(0);
11311+atomic_unchecked_t dcpage_flushes = ATOMIC_INIT(0);
11312 #ifdef CONFIG_SMP
11313-atomic_t dcpage_flushes_xcall = ATOMIC_INIT(0);
11314+atomic_unchecked_t dcpage_flushes_xcall = ATOMIC_INIT(0);
11315 #endif
11316 #endif
11317
11318@@ -198,7 +198,7 @@ inline void flush_dcache_page_impl(struct page *page)
11319 {
11320 BUG_ON(tlb_type == hypervisor);
11321 #ifdef CONFIG_DEBUG_DCFLUSH
11322- atomic_inc(&dcpage_flushes);
11323+ atomic_inc_unchecked(&dcpage_flushes);
11324 #endif
11325
11326 #ifdef DCACHE_ALIASING_POSSIBLE
11327@@ -466,10 +466,10 @@ void mmu_info(struct seq_file *m)
11328
11329 #ifdef CONFIG_DEBUG_DCFLUSH
11330 seq_printf(m, "DCPageFlushes\t: %d\n",
11331- atomic_read(&dcpage_flushes));
11332+ atomic_read_unchecked(&dcpage_flushes));
11333 #ifdef CONFIG_SMP
11334 seq_printf(m, "DCPageFlushesXC\t: %d\n",
11335- atomic_read(&dcpage_flushes_xcall));
11336+ atomic_read_unchecked(&dcpage_flushes_xcall));
11337 #endif /* CONFIG_SMP */
11338 #endif /* CONFIG_DEBUG_DCFLUSH */
11339 }
11340diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
11341index f4500c6..889656c 100644
11342--- a/arch/tile/include/asm/atomic_64.h
11343+++ b/arch/tile/include/asm/atomic_64.h
11344@@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
11345
11346 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
11347
11348+#define atomic64_read_unchecked(v) atomic64_read(v)
11349+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
11350+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
11351+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
11352+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
11353+#define atomic64_inc_unchecked(v) atomic64_inc(v)
11354+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
11355+#define atomic64_dec_unchecked(v) atomic64_dec(v)
11356+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
11357+
11358 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
11359 #define smp_mb__before_atomic_dec() smp_mb()
11360 #define smp_mb__after_atomic_dec() smp_mb()
11361diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
11362index a9a5299..0fce79e 100644
11363--- a/arch/tile/include/asm/cache.h
11364+++ b/arch/tile/include/asm/cache.h
11365@@ -15,11 +15,12 @@
11366 #ifndef _ASM_TILE_CACHE_H
11367 #define _ASM_TILE_CACHE_H
11368
11369+#include <linux/const.h>
11370 #include <arch/chip.h>
11371
11372 /* bytes per L1 data cache line */
11373 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
11374-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11375+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11376
11377 /* bytes per L2 cache line */
11378 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
11379diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
11380index e4d44bd..99927a3 100644
11381--- a/arch/tile/include/asm/uaccess.h
11382+++ b/arch/tile/include/asm/uaccess.h
11383@@ -408,9 +408,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
11384 const void __user *from,
11385 unsigned long n)
11386 {
11387- int sz = __compiletime_object_size(to);
11388+ size_t sz = __compiletime_object_size(to);
11389
11390- if (likely(sz == -1 || sz >= n))
11391+ if (likely(sz == (size_t)-1 || sz >= n))
11392 n = _copy_from_user(to, from, n);
11393 else
11394 copy_from_user_overflow();
11395diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
11396index 650ccff..45fe2d6 100644
11397--- a/arch/tile/mm/hugetlbpage.c
11398+++ b/arch/tile/mm/hugetlbpage.c
11399@@ -239,6 +239,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
11400 info.high_limit = TASK_SIZE;
11401 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
11402 info.align_offset = 0;
11403+ info.threadstack_offset = 0;
11404 return vm_unmapped_area(&info);
11405 }
11406
11407@@ -256,6 +257,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
11408 info.high_limit = current->mm->mmap_base;
11409 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
11410 info.align_offset = 0;
11411+ info.threadstack_offset = 0;
11412 addr = vm_unmapped_area(&info);
11413
11414 /*
11415diff --git a/arch/um/Makefile b/arch/um/Makefile
11416index 133f7de..1d6f2f1 100644
11417--- a/arch/um/Makefile
11418+++ b/arch/um/Makefile
11419@@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
11420 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
11421 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
11422
11423+ifdef CONSTIFY_PLUGIN
11424+USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
11425+endif
11426+
11427 #This will adjust *FLAGS accordingly to the platform.
11428 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
11429
11430diff --git a/arch/um/defconfig b/arch/um/defconfig
11431index 08107a7..ab22afe 100644
11432--- a/arch/um/defconfig
11433+++ b/arch/um/defconfig
11434@@ -51,7 +51,6 @@ CONFIG_X86_CMPXCHG=y
11435 CONFIG_X86_L1_CACHE_SHIFT=5
11436 CONFIG_X86_XADD=y
11437 CONFIG_X86_PPRO_FENCE=y
11438-CONFIG_X86_WP_WORKS_OK=y
11439 CONFIG_X86_INVLPG=y
11440 CONFIG_X86_BSWAP=y
11441 CONFIG_X86_POPAD_OK=y
11442diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
11443index 19e1bdd..3665b77 100644
11444--- a/arch/um/include/asm/cache.h
11445+++ b/arch/um/include/asm/cache.h
11446@@ -1,6 +1,7 @@
11447 #ifndef __UM_CACHE_H
11448 #define __UM_CACHE_H
11449
11450+#include <linux/const.h>
11451
11452 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
11453 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
11454@@ -12,6 +13,6 @@
11455 # define L1_CACHE_SHIFT 5
11456 #endif
11457
11458-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11459+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11460
11461 #endif
11462diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
11463index 2e0a6b1..a64d0f5 100644
11464--- a/arch/um/include/asm/kmap_types.h
11465+++ b/arch/um/include/asm/kmap_types.h
11466@@ -8,6 +8,6 @@
11467
11468 /* No more #include "asm/arch/kmap_types.h" ! */
11469
11470-#define KM_TYPE_NR 14
11471+#define KM_TYPE_NR 15
11472
11473 #endif
11474diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
11475index 5ff53d9..5850cdf 100644
11476--- a/arch/um/include/asm/page.h
11477+++ b/arch/um/include/asm/page.h
11478@@ -14,6 +14,9 @@
11479 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
11480 #define PAGE_MASK (~(PAGE_SIZE-1))
11481
11482+#define ktla_ktva(addr) (addr)
11483+#define ktva_ktla(addr) (addr)
11484+
11485 #ifndef __ASSEMBLY__
11486
11487 struct page;
11488diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
11489index 0032f92..cd151e0 100644
11490--- a/arch/um/include/asm/pgtable-3level.h
11491+++ b/arch/um/include/asm/pgtable-3level.h
11492@@ -58,6 +58,7 @@
11493 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
11494 #define pud_populate(mm, pud, pmd) \
11495 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
11496+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
11497
11498 #ifdef CONFIG_64BIT
11499 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
11500diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
11501index bbcef52..6a2a483 100644
11502--- a/arch/um/kernel/process.c
11503+++ b/arch/um/kernel/process.c
11504@@ -367,22 +367,6 @@ int singlestepping(void * t)
11505 return 2;
11506 }
11507
11508-/*
11509- * Only x86 and x86_64 have an arch_align_stack().
11510- * All other arches have "#define arch_align_stack(x) (x)"
11511- * in their asm/system.h
11512- * As this is included in UML from asm-um/system-generic.h,
11513- * we can use it to behave as the subarch does.
11514- */
11515-#ifndef arch_align_stack
11516-unsigned long arch_align_stack(unsigned long sp)
11517-{
11518- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
11519- sp -= get_random_int() % 8192;
11520- return sp & ~0xf;
11521-}
11522-#endif
11523-
11524 unsigned long get_wchan(struct task_struct *p)
11525 {
11526 unsigned long stack_page, sp, ip;
11527diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
11528index ad8f795..2c7eec6 100644
11529--- a/arch/unicore32/include/asm/cache.h
11530+++ b/arch/unicore32/include/asm/cache.h
11531@@ -12,8 +12,10 @@
11532 #ifndef __UNICORE_CACHE_H__
11533 #define __UNICORE_CACHE_H__
11534
11535-#define L1_CACHE_SHIFT (5)
11536-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11537+#include <linux/const.h>
11538+
11539+#define L1_CACHE_SHIFT 5
11540+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11541
11542 /*
11543 * Memory returned by kmalloc() may be used for DMA, so we must make
11544diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
11545index b32ebf9..5704f98 100644
11546--- a/arch/x86/Kconfig
11547+++ b/arch/x86/Kconfig
11548@@ -248,7 +248,7 @@ config X86_HT
11549
11550 config X86_32_LAZY_GS
11551 def_bool y
11552- depends on X86_32 && !CC_STACKPROTECTOR
11553+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
11554
11555 config ARCH_HWEIGHT_CFLAGS
11556 string
11557@@ -1088,6 +1088,7 @@ config MICROCODE_EARLY
11558
11559 config X86_MSR
11560 tristate "/dev/cpu/*/msr - Model-specific register support"
11561+ depends on !GRKERNSEC_KMEM
11562 ---help---
11563 This device gives privileged processes access to the x86
11564 Model-Specific Registers (MSRs). It is a character device with
11565@@ -1111,7 +1112,7 @@ choice
11566
11567 config NOHIGHMEM
11568 bool "off"
11569- depends on !X86_NUMAQ
11570+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
11571 ---help---
11572 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
11573 However, the address space of 32-bit x86 processors is only 4
11574@@ -1148,7 +1149,7 @@ config NOHIGHMEM
11575
11576 config HIGHMEM4G
11577 bool "4GB"
11578- depends on !X86_NUMAQ
11579+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
11580 ---help---
11581 Select this if you have a 32-bit processor and between 1 and 4
11582 gigabytes of physical RAM.
11583@@ -1201,7 +1202,7 @@ config PAGE_OFFSET
11584 hex
11585 default 0xB0000000 if VMSPLIT_3G_OPT
11586 default 0x80000000 if VMSPLIT_2G
11587- default 0x78000000 if VMSPLIT_2G_OPT
11588+ default 0x70000000 if VMSPLIT_2G_OPT
11589 default 0x40000000 if VMSPLIT_1G
11590 default 0xC0000000
11591 depends on X86_32
11592@@ -1599,6 +1600,7 @@ config SECCOMP
11593
11594 config CC_STACKPROTECTOR
11595 bool "Enable -fstack-protector buffer overflow detection"
11596+ depends on X86_64 || !PAX_MEMORY_UDEREF
11597 ---help---
11598 This option turns on the -fstack-protector GCC feature. This
11599 feature puts, at the beginning of functions, a canary value on
11600@@ -1718,6 +1720,8 @@ config X86_NEED_RELOCS
11601 config PHYSICAL_ALIGN
11602 hex "Alignment value to which kernel should be aligned" if X86_32
11603 default "0x1000000"
11604+ range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
11605+ range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
11606 range 0x2000 0x1000000
11607 ---help---
11608 This value puts the alignment restrictions on physical address
11609@@ -1793,9 +1797,10 @@ config DEBUG_HOTPLUG_CPU0
11610 If unsure, say N.
11611
11612 config COMPAT_VDSO
11613- def_bool y
11614+ def_bool n
11615 prompt "Compat VDSO support"
11616 depends on X86_32 || IA32_EMULATION
11617+ depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
11618 ---help---
11619 Map the 32-bit VDSO to the predictable old-style address too.
11620
11621diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
11622index c026cca..14657ae 100644
11623--- a/arch/x86/Kconfig.cpu
11624+++ b/arch/x86/Kconfig.cpu
11625@@ -319,7 +319,7 @@ config X86_PPRO_FENCE
11626
11627 config X86_F00F_BUG
11628 def_bool y
11629- depends on M586MMX || M586TSC || M586 || M486
11630+ depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
11631
11632 config X86_INVD_BUG
11633 def_bool y
11634@@ -327,7 +327,7 @@ config X86_INVD_BUG
11635
11636 config X86_ALIGNMENT_16
11637 def_bool y
11638- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
11639+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
11640
11641 config X86_INTEL_USERCOPY
11642 def_bool y
11643@@ -373,7 +373,7 @@ config X86_CMPXCHG64
11644 # generates cmov.
11645 config X86_CMOV
11646 def_bool y
11647- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
11648+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
11649
11650 config X86_MINIMUM_CPU_FAMILY
11651 int
11652diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
11653index 78d91af..8ceb94b 100644
11654--- a/arch/x86/Kconfig.debug
11655+++ b/arch/x86/Kconfig.debug
11656@@ -74,7 +74,7 @@ config X86_PTDUMP
11657 config DEBUG_RODATA
11658 bool "Write protect kernel read-only data structures"
11659 default y
11660- depends on DEBUG_KERNEL
11661+ depends on DEBUG_KERNEL && BROKEN
11662 ---help---
11663 Mark the kernel read-only data as write-protected in the pagetables,
11664 in order to catch accidental (and incorrect) writes to such const
11665@@ -92,7 +92,7 @@ config DEBUG_RODATA_TEST
11666
11667 config DEBUG_SET_MODULE_RONX
11668 bool "Set loadable kernel module data as NX and text as RO"
11669- depends on MODULES
11670+ depends on MODULES && BROKEN
11671 ---help---
11672 This option helps catch unintended modifications to loadable
11673 kernel module's text and read-only data. It also prevents execution
11674diff --git a/arch/x86/Makefile b/arch/x86/Makefile
11675index 07639c6..6f2c901 100644
11676--- a/arch/x86/Makefile
11677+++ b/arch/x86/Makefile
11678@@ -54,6 +54,7 @@ else
11679 UTS_MACHINE := x86_64
11680 CHECKFLAGS += -D__x86_64__ -m64
11681
11682+ biarch := $(call cc-option,-m64)
11683 KBUILD_AFLAGS += -m64
11684 KBUILD_CFLAGS += -m64
11685
11686@@ -241,3 +242,12 @@ define archhelp
11687 echo ' FDINITRD=file initrd for the booted kernel'
11688 echo ' kvmconfig - Enable additional options for guest kernel support'
11689 endef
11690+
11691+define OLD_LD
11692+
11693+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
11694+*** Please upgrade your binutils to 2.18 or newer
11695+endef
11696+
11697+archprepare:
11698+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
11699diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
11700index 379814b..add62ce 100644
11701--- a/arch/x86/boot/Makefile
11702+++ b/arch/x86/boot/Makefile
11703@@ -65,6 +65,9 @@ KBUILD_CFLAGS := $(USERINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
11704 $(call cc-option, -fno-stack-protector) \
11705 $(call cc-option, -mpreferred-stack-boundary=2)
11706 KBUILD_CFLAGS += $(call cc-option, -m32)
11707+ifdef CONSTIFY_PLUGIN
11708+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
11709+endif
11710 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
11711 GCOV_PROFILE := n
11712
11713diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
11714index 878e4b9..20537ab 100644
11715--- a/arch/x86/boot/bitops.h
11716+++ b/arch/x86/boot/bitops.h
11717@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
11718 u8 v;
11719 const u32 *p = (const u32 *)addr;
11720
11721- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
11722+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
11723 return v;
11724 }
11725
11726@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
11727
11728 static inline void set_bit(int nr, void *addr)
11729 {
11730- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
11731+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
11732 }
11733
11734 #endif /* BOOT_BITOPS_H */
11735diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
11736index 5b75319..331a4ca 100644
11737--- a/arch/x86/boot/boot.h
11738+++ b/arch/x86/boot/boot.h
11739@@ -85,7 +85,7 @@ static inline void io_delay(void)
11740 static inline u16 ds(void)
11741 {
11742 u16 seg;
11743- asm("movw %%ds,%0" : "=rm" (seg));
11744+ asm volatile("movw %%ds,%0" : "=rm" (seg));
11745 return seg;
11746 }
11747
11748@@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
11749 static inline int memcmp(const void *s1, const void *s2, size_t len)
11750 {
11751 u8 diff;
11752- asm("repe; cmpsb; setnz %0"
11753+ asm volatile("repe; cmpsb; setnz %0"
11754 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
11755 return diff;
11756 }
11757diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
11758index dcd90df..c830d7d 100644
11759--- a/arch/x86/boot/compressed/Makefile
11760+++ b/arch/x86/boot/compressed/Makefile
11761@@ -15,6 +15,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
11762 KBUILD_CFLAGS += $(cflags-y)
11763 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
11764 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
11765+ifdef CONSTIFY_PLUGIN
11766+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
11767+endif
11768
11769 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
11770 GCOV_PROFILE := n
11771diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
11772index b7388a4..03844ec 100644
11773--- a/arch/x86/boot/compressed/eboot.c
11774+++ b/arch/x86/boot/compressed/eboot.c
11775@@ -150,7 +150,6 @@ again:
11776 *addr = max_addr;
11777 }
11778
11779-free_pool:
11780 efi_call_phys1(sys_table->boottime->free_pool, map);
11781
11782 fail:
11783@@ -214,7 +213,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
11784 if (i == map_size / desc_size)
11785 status = EFI_NOT_FOUND;
11786
11787-free_pool:
11788 efi_call_phys1(sys_table->boottime->free_pool, map);
11789 fail:
11790 return status;
11791diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
11792index a53440e..c3dbf1e 100644
11793--- a/arch/x86/boot/compressed/efi_stub_32.S
11794+++ b/arch/x86/boot/compressed/efi_stub_32.S
11795@@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
11796 * parameter 2, ..., param n. To make things easy, we save the return
11797 * address of efi_call_phys in a global variable.
11798 */
11799- popl %ecx
11800- movl %ecx, saved_return_addr(%edx)
11801- /* get the function pointer into ECX*/
11802- popl %ecx
11803- movl %ecx, efi_rt_function_ptr(%edx)
11804+ popl saved_return_addr(%edx)
11805+ popl efi_rt_function_ptr(%edx)
11806
11807 /*
11808 * 3. Call the physical function.
11809 */
11810- call *%ecx
11811+ call *efi_rt_function_ptr(%edx)
11812
11813 /*
11814 * 4. Balance the stack. And because EAX contain the return value,
11815@@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
11816 1: popl %edx
11817 subl $1b, %edx
11818
11819- movl efi_rt_function_ptr(%edx), %ecx
11820- pushl %ecx
11821+ pushl efi_rt_function_ptr(%edx)
11822
11823 /*
11824 * 10. Push the saved return address onto the stack and return.
11825 */
11826- movl saved_return_addr(%edx), %ecx
11827- pushl %ecx
11828- ret
11829+ jmpl *saved_return_addr(%edx)
11830 ENDPROC(efi_call_phys)
11831 .previous
11832
11833diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
11834index 1e3184f..0d11e2e 100644
11835--- a/arch/x86/boot/compressed/head_32.S
11836+++ b/arch/x86/boot/compressed/head_32.S
11837@@ -118,7 +118,7 @@ preferred_addr:
11838 notl %eax
11839 andl %eax, %ebx
11840 #else
11841- movl $LOAD_PHYSICAL_ADDR, %ebx
11842+ movl $____LOAD_PHYSICAL_ADDR, %ebx
11843 #endif
11844
11845 /* Target address to relocate to for decompression */
11846@@ -204,7 +204,7 @@ relocated:
11847 * and where it was actually loaded.
11848 */
11849 movl %ebp, %ebx
11850- subl $LOAD_PHYSICAL_ADDR, %ebx
11851+ subl $____LOAD_PHYSICAL_ADDR, %ebx
11852 jz 2f /* Nothing to be done if loaded at compiled addr. */
11853 /*
11854 * Process relocations.
11855@@ -212,8 +212,7 @@ relocated:
11856
11857 1: subl $4, %edi
11858 movl (%edi), %ecx
11859- testl %ecx, %ecx
11860- jz 2f
11861+ jecxz 2f
11862 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
11863 jmp 1b
11864 2:
11865diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
11866index 06e71c2..88a98264 100644
11867--- a/arch/x86/boot/compressed/head_64.S
11868+++ b/arch/x86/boot/compressed/head_64.S
11869@@ -95,7 +95,7 @@ ENTRY(startup_32)
11870 notl %eax
11871 andl %eax, %ebx
11872 #else
11873- movl $LOAD_PHYSICAL_ADDR, %ebx
11874+ movl $____LOAD_PHYSICAL_ADDR, %ebx
11875 #endif
11876
11877 /* Target address to relocate to for decompression */
11878@@ -270,7 +270,7 @@ preferred_addr:
11879 notq %rax
11880 andq %rax, %rbp
11881 #else
11882- movq $LOAD_PHYSICAL_ADDR, %rbp
11883+ movq $____LOAD_PHYSICAL_ADDR, %rbp
11884 #endif
11885
11886 /* Target address to relocate to for decompression */
11887@@ -361,8 +361,8 @@ gdt:
11888 .long gdt
11889 .word 0
11890 .quad 0x0000000000000000 /* NULL descriptor */
11891- .quad 0x00af9a000000ffff /* __KERNEL_CS */
11892- .quad 0x00cf92000000ffff /* __KERNEL_DS */
11893+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
11894+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
11895 .quad 0x0080890000000000 /* TS descriptor */
11896 .quad 0x0000000000000000 /* TS continued */
11897 gdt_end:
11898diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
11899index 0319c88..7c1931f 100644
11900--- a/arch/x86/boot/compressed/misc.c
11901+++ b/arch/x86/boot/compressed/misc.c
11902@@ -307,7 +307,7 @@ static void parse_elf(void *output)
11903 case PT_LOAD:
11904 #ifdef CONFIG_RELOCATABLE
11905 dest = output;
11906- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
11907+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
11908 #else
11909 dest = (void *)(phdr->p_paddr);
11910 #endif
11911@@ -358,7 +358,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
11912 error("Destination address too large");
11913 #endif
11914 #ifndef CONFIG_RELOCATABLE
11915- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
11916+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
11917 error("Wrong destination address");
11918 #endif
11919
11920diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
11921index 4d3ff03..e4972ff 100644
11922--- a/arch/x86/boot/cpucheck.c
11923+++ b/arch/x86/boot/cpucheck.c
11924@@ -74,7 +74,7 @@ static int has_fpu(void)
11925 u16 fcw = -1, fsw = -1;
11926 u32 cr0;
11927
11928- asm("movl %%cr0,%0" : "=r" (cr0));
11929+ asm volatile("movl %%cr0,%0" : "=r" (cr0));
11930 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
11931 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
11932 asm volatile("movl %0,%%cr0" : : "r" (cr0));
11933@@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
11934 {
11935 u32 f0, f1;
11936
11937- asm("pushfl ; "
11938+ asm volatile("pushfl ; "
11939 "pushfl ; "
11940 "popl %0 ; "
11941 "movl %0,%1 ; "
11942@@ -115,7 +115,7 @@ static void get_flags(void)
11943 set_bit(X86_FEATURE_FPU, cpu.flags);
11944
11945 if (has_eflag(X86_EFLAGS_ID)) {
11946- asm("cpuid"
11947+ asm volatile("cpuid"
11948 : "=a" (max_intel_level),
11949 "=b" (cpu_vendor[0]),
11950 "=d" (cpu_vendor[1]),
11951@@ -124,7 +124,7 @@ static void get_flags(void)
11952
11953 if (max_intel_level >= 0x00000001 &&
11954 max_intel_level <= 0x0000ffff) {
11955- asm("cpuid"
11956+ asm volatile("cpuid"
11957 : "=a" (tfms),
11958 "=c" (cpu.flags[4]),
11959 "=d" (cpu.flags[0])
11960@@ -136,7 +136,7 @@ static void get_flags(void)
11961 cpu.model += ((tfms >> 16) & 0xf) << 4;
11962 }
11963
11964- asm("cpuid"
11965+ asm volatile("cpuid"
11966 : "=a" (max_amd_level)
11967 : "a" (0x80000000)
11968 : "ebx", "ecx", "edx");
11969@@ -144,7 +144,7 @@ static void get_flags(void)
11970 if (max_amd_level >= 0x80000001 &&
11971 max_amd_level <= 0x8000ffff) {
11972 u32 eax = 0x80000001;
11973- asm("cpuid"
11974+ asm volatile("cpuid"
11975 : "+a" (eax),
11976 "=c" (cpu.flags[6]),
11977 "=d" (cpu.flags[1])
11978@@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
11979 u32 ecx = MSR_K7_HWCR;
11980 u32 eax, edx;
11981
11982- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
11983+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
11984 eax &= ~(1 << 15);
11985- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
11986+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
11987
11988 get_flags(); /* Make sure it really did something */
11989 err = check_flags();
11990@@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
11991 u32 ecx = MSR_VIA_FCR;
11992 u32 eax, edx;
11993
11994- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
11995+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
11996 eax |= (1<<1)|(1<<7);
11997- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
11998+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
11999
12000 set_bit(X86_FEATURE_CX8, cpu.flags);
12001 err = check_flags();
12002@@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12003 u32 eax, edx;
12004 u32 level = 1;
12005
12006- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12007- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12008- asm("cpuid"
12009+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12010+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12011+ asm volatile("cpuid"
12012 : "+a" (level), "=d" (cpu.flags[0])
12013 : : "ecx", "ebx");
12014- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12015+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12016
12017 err = check_flags();
12018 }
12019diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
12020index 9ec06a1..2c25e79 100644
12021--- a/arch/x86/boot/header.S
12022+++ b/arch/x86/boot/header.S
12023@@ -409,10 +409,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
12024 # single linked list of
12025 # struct setup_data
12026
12027-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
12028+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
12029
12030 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
12031+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
12032+#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
12033+#else
12034 #define VO_INIT_SIZE (VO__end - VO__text)
12035+#endif
12036 #if ZO_INIT_SIZE > VO_INIT_SIZE
12037 #define INIT_SIZE ZO_INIT_SIZE
12038 #else
12039diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
12040index db75d07..8e6d0af 100644
12041--- a/arch/x86/boot/memory.c
12042+++ b/arch/x86/boot/memory.c
12043@@ -19,7 +19,7 @@
12044
12045 static int detect_memory_e820(void)
12046 {
12047- int count = 0;
12048+ unsigned int count = 0;
12049 struct biosregs ireg, oreg;
12050 struct e820entry *desc = boot_params.e820_map;
12051 static struct e820entry buf; /* static so it is zeroed */
12052diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
12053index 11e8c6e..fdbb1ed 100644
12054--- a/arch/x86/boot/video-vesa.c
12055+++ b/arch/x86/boot/video-vesa.c
12056@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
12057
12058 boot_params.screen_info.vesapm_seg = oreg.es;
12059 boot_params.screen_info.vesapm_off = oreg.di;
12060+ boot_params.screen_info.vesapm_size = oreg.cx;
12061 }
12062
12063 /*
12064diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
12065index 43eda28..5ab5fdb 100644
12066--- a/arch/x86/boot/video.c
12067+++ b/arch/x86/boot/video.c
12068@@ -96,7 +96,7 @@ static void store_mode_params(void)
12069 static unsigned int get_entry(void)
12070 {
12071 char entry_buf[4];
12072- int i, len = 0;
12073+ unsigned int i, len = 0;
12074 int key;
12075 unsigned int v;
12076
12077diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
12078index 9105655..5e37f27 100644
12079--- a/arch/x86/crypto/aes-x86_64-asm_64.S
12080+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
12081@@ -8,6 +8,8 @@
12082 * including this sentence is retained in full.
12083 */
12084
12085+#include <asm/alternative-asm.h>
12086+
12087 .extern crypto_ft_tab
12088 .extern crypto_it_tab
12089 .extern crypto_fl_tab
12090@@ -70,6 +72,8 @@
12091 je B192; \
12092 leaq 32(r9),r9;
12093
12094+#define ret pax_force_retaddr 0, 1; ret
12095+
12096 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
12097 movq r1,r2; \
12098 movq r3,r4; \
12099diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
12100index 477e9d7..3ab339f 100644
12101--- a/arch/x86/crypto/aesni-intel_asm.S
12102+++ b/arch/x86/crypto/aesni-intel_asm.S
12103@@ -31,6 +31,7 @@
12104
12105 #include <linux/linkage.h>
12106 #include <asm/inst.h>
12107+#include <asm/alternative-asm.h>
12108
12109 #ifdef __x86_64__
12110 .data
12111@@ -1441,6 +1442,7 @@ _return_T_done_decrypt:
12112 pop %r14
12113 pop %r13
12114 pop %r12
12115+ pax_force_retaddr 0, 1
12116 ret
12117 ENDPROC(aesni_gcm_dec)
12118
12119@@ -1705,6 +1707,7 @@ _return_T_done_encrypt:
12120 pop %r14
12121 pop %r13
12122 pop %r12
12123+ pax_force_retaddr 0, 1
12124 ret
12125 ENDPROC(aesni_gcm_enc)
12126
12127@@ -1722,6 +1725,7 @@ _key_expansion_256a:
12128 pxor %xmm1, %xmm0
12129 movaps %xmm0, (TKEYP)
12130 add $0x10, TKEYP
12131+ pax_force_retaddr_bts
12132 ret
12133 ENDPROC(_key_expansion_128)
12134 ENDPROC(_key_expansion_256a)
12135@@ -1748,6 +1752,7 @@ _key_expansion_192a:
12136 shufps $0b01001110, %xmm2, %xmm1
12137 movaps %xmm1, 0x10(TKEYP)
12138 add $0x20, TKEYP
12139+ pax_force_retaddr_bts
12140 ret
12141 ENDPROC(_key_expansion_192a)
12142
12143@@ -1768,6 +1773,7 @@ _key_expansion_192b:
12144
12145 movaps %xmm0, (TKEYP)
12146 add $0x10, TKEYP
12147+ pax_force_retaddr_bts
12148 ret
12149 ENDPROC(_key_expansion_192b)
12150
12151@@ -1781,6 +1787,7 @@ _key_expansion_256b:
12152 pxor %xmm1, %xmm2
12153 movaps %xmm2, (TKEYP)
12154 add $0x10, TKEYP
12155+ pax_force_retaddr_bts
12156 ret
12157 ENDPROC(_key_expansion_256b)
12158
12159@@ -1894,6 +1901,7 @@ ENTRY(aesni_set_key)
12160 #ifndef __x86_64__
12161 popl KEYP
12162 #endif
12163+ pax_force_retaddr 0, 1
12164 ret
12165 ENDPROC(aesni_set_key)
12166
12167@@ -1916,6 +1924,7 @@ ENTRY(aesni_enc)
12168 popl KLEN
12169 popl KEYP
12170 #endif
12171+ pax_force_retaddr 0, 1
12172 ret
12173 ENDPROC(aesni_enc)
12174
12175@@ -1974,6 +1983,7 @@ _aesni_enc1:
12176 AESENC KEY STATE
12177 movaps 0x70(TKEYP), KEY
12178 AESENCLAST KEY STATE
12179+ pax_force_retaddr_bts
12180 ret
12181 ENDPROC(_aesni_enc1)
12182
12183@@ -2083,6 +2093,7 @@ _aesni_enc4:
12184 AESENCLAST KEY STATE2
12185 AESENCLAST KEY STATE3
12186 AESENCLAST KEY STATE4
12187+ pax_force_retaddr_bts
12188 ret
12189 ENDPROC(_aesni_enc4)
12190
12191@@ -2106,6 +2117,7 @@ ENTRY(aesni_dec)
12192 popl KLEN
12193 popl KEYP
12194 #endif
12195+ pax_force_retaddr 0, 1
12196 ret
12197 ENDPROC(aesni_dec)
12198
12199@@ -2164,6 +2176,7 @@ _aesni_dec1:
12200 AESDEC KEY STATE
12201 movaps 0x70(TKEYP), KEY
12202 AESDECLAST KEY STATE
12203+ pax_force_retaddr_bts
12204 ret
12205 ENDPROC(_aesni_dec1)
12206
12207@@ -2273,6 +2286,7 @@ _aesni_dec4:
12208 AESDECLAST KEY STATE2
12209 AESDECLAST KEY STATE3
12210 AESDECLAST KEY STATE4
12211+ pax_force_retaddr_bts
12212 ret
12213 ENDPROC(_aesni_dec4)
12214
12215@@ -2331,6 +2345,7 @@ ENTRY(aesni_ecb_enc)
12216 popl KEYP
12217 popl LEN
12218 #endif
12219+ pax_force_retaddr 0, 1
12220 ret
12221 ENDPROC(aesni_ecb_enc)
12222
12223@@ -2390,6 +2405,7 @@ ENTRY(aesni_ecb_dec)
12224 popl KEYP
12225 popl LEN
12226 #endif
12227+ pax_force_retaddr 0, 1
12228 ret
12229 ENDPROC(aesni_ecb_dec)
12230
12231@@ -2432,6 +2448,7 @@ ENTRY(aesni_cbc_enc)
12232 popl LEN
12233 popl IVP
12234 #endif
12235+ pax_force_retaddr 0, 1
12236 ret
12237 ENDPROC(aesni_cbc_enc)
12238
12239@@ -2523,6 +2540,7 @@ ENTRY(aesni_cbc_dec)
12240 popl LEN
12241 popl IVP
12242 #endif
12243+ pax_force_retaddr 0, 1
12244 ret
12245 ENDPROC(aesni_cbc_dec)
12246
12247@@ -2550,6 +2568,7 @@ _aesni_inc_init:
12248 mov $1, TCTR_LOW
12249 MOVQ_R64_XMM TCTR_LOW INC
12250 MOVQ_R64_XMM CTR TCTR_LOW
12251+ pax_force_retaddr_bts
12252 ret
12253 ENDPROC(_aesni_inc_init)
12254
12255@@ -2579,6 +2598,7 @@ _aesni_inc:
12256 .Linc_low:
12257 movaps CTR, IV
12258 PSHUFB_XMM BSWAP_MASK IV
12259+ pax_force_retaddr_bts
12260 ret
12261 ENDPROC(_aesni_inc)
12262
12263@@ -2640,6 +2660,7 @@ ENTRY(aesni_ctr_enc)
12264 .Lctr_enc_ret:
12265 movups IV, (IVP)
12266 .Lctr_enc_just_ret:
12267+ pax_force_retaddr 0, 1
12268 ret
12269 ENDPROC(aesni_ctr_enc)
12270
12271@@ -2766,6 +2787,7 @@ ENTRY(aesni_xts_crypt8)
12272 pxor INC, STATE4
12273 movdqu STATE4, 0x70(OUTP)
12274
12275+ pax_force_retaddr 0, 1
12276 ret
12277 ENDPROC(aesni_xts_crypt8)
12278
12279diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
12280index 246c670..4d1ed00 100644
12281--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
12282+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
12283@@ -21,6 +21,7 @@
12284 */
12285
12286 #include <linux/linkage.h>
12287+#include <asm/alternative-asm.h>
12288
12289 .file "blowfish-x86_64-asm.S"
12290 .text
12291@@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
12292 jnz .L__enc_xor;
12293
12294 write_block();
12295+ pax_force_retaddr 0, 1
12296 ret;
12297 .L__enc_xor:
12298 xor_block();
12299+ pax_force_retaddr 0, 1
12300 ret;
12301 ENDPROC(__blowfish_enc_blk)
12302
12303@@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
12304
12305 movq %r11, %rbp;
12306
12307+ pax_force_retaddr 0, 1
12308 ret;
12309 ENDPROC(blowfish_dec_blk)
12310
12311@@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
12312
12313 popq %rbx;
12314 popq %rbp;
12315+ pax_force_retaddr 0, 1
12316 ret;
12317
12318 .L__enc_xor4:
12319@@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
12320
12321 popq %rbx;
12322 popq %rbp;
12323+ pax_force_retaddr 0, 1
12324 ret;
12325 ENDPROC(__blowfish_enc_blk_4way)
12326
12327@@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
12328 popq %rbx;
12329 popq %rbp;
12330
12331+ pax_force_retaddr 0, 1
12332 ret;
12333 ENDPROC(blowfish_dec_blk_4way)
12334diff --git a/arch/x86/crypto/camellia-aesni-avx-asm_64.S b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
12335index ce71f92..2dd5b1e 100644
12336--- a/arch/x86/crypto/camellia-aesni-avx-asm_64.S
12337+++ b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
12338@@ -16,6 +16,7 @@
12339 */
12340
12341 #include <linux/linkage.h>
12342+#include <asm/alternative-asm.h>
12343
12344 #define CAMELLIA_TABLE_BYTE_LEN 272
12345
12346@@ -191,6 +192,7 @@ roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
12347 roundsm16(%xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7,
12348 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14, %xmm15,
12349 %rcx, (%r9));
12350+ pax_force_retaddr_bts
12351 ret;
12352 ENDPROC(roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
12353
12354@@ -199,6 +201,7 @@ roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
12355 roundsm16(%xmm4, %xmm5, %xmm6, %xmm7, %xmm0, %xmm1, %xmm2, %xmm3,
12356 %xmm12, %xmm13, %xmm14, %xmm15, %xmm8, %xmm9, %xmm10, %xmm11,
12357 %rax, (%r9));
12358+ pax_force_retaddr_bts
12359 ret;
12360 ENDPROC(roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
12361
12362@@ -780,6 +783,7 @@ __camellia_enc_blk16:
12363 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
12364 %xmm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 16(%rax));
12365
12366+ pax_force_retaddr_bts
12367 ret;
12368
12369 .align 8
12370@@ -865,6 +869,7 @@ __camellia_dec_blk16:
12371 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
12372 %xmm15, (key_table)(CTX), (%rax), 1 * 16(%rax));
12373
12374+ pax_force_retaddr_bts
12375 ret;
12376
12377 .align 8
12378@@ -904,6 +909,7 @@ ENTRY(camellia_ecb_enc_16way)
12379 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12380 %xmm8, %rsi);
12381
12382+ pax_force_retaddr 0, 1
12383 ret;
12384 ENDPROC(camellia_ecb_enc_16way)
12385
12386@@ -932,6 +938,7 @@ ENTRY(camellia_ecb_dec_16way)
12387 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12388 %xmm8, %rsi);
12389
12390+ pax_force_retaddr 0, 1
12391 ret;
12392 ENDPROC(camellia_ecb_dec_16way)
12393
12394@@ -981,6 +988,7 @@ ENTRY(camellia_cbc_dec_16way)
12395 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12396 %xmm8, %rsi);
12397
12398+ pax_force_retaddr 0, 1
12399 ret;
12400 ENDPROC(camellia_cbc_dec_16way)
12401
12402@@ -1092,6 +1100,7 @@ ENTRY(camellia_ctr_16way)
12403 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12404 %xmm8, %rsi);
12405
12406+ pax_force_retaddr 0, 1
12407 ret;
12408 ENDPROC(camellia_ctr_16way)
12409
12410@@ -1234,6 +1243,7 @@ camellia_xts_crypt_16way:
12411 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12412 %xmm8, %rsi);
12413
12414+ pax_force_retaddr 0, 1
12415 ret;
12416 ENDPROC(camellia_xts_crypt_16way)
12417
12418diff --git a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
12419index 0e0b886..8fc756a 100644
12420--- a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
12421+++ b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
12422@@ -11,6 +11,7 @@
12423 */
12424
12425 #include <linux/linkage.h>
12426+#include <asm/alternative-asm.h>
12427
12428 #define CAMELLIA_TABLE_BYTE_LEN 272
12429
12430@@ -230,6 +231,7 @@ roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
12431 roundsm32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
12432 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15,
12433 %rcx, (%r9));
12434+ pax_force_retaddr_bts
12435 ret;
12436 ENDPROC(roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
12437
12438@@ -238,6 +240,7 @@ roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
12439 roundsm32(%ymm4, %ymm5, %ymm6, %ymm7, %ymm0, %ymm1, %ymm2, %ymm3,
12440 %ymm12, %ymm13, %ymm14, %ymm15, %ymm8, %ymm9, %ymm10, %ymm11,
12441 %rax, (%r9));
12442+ pax_force_retaddr_bts
12443 ret;
12444 ENDPROC(roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
12445
12446@@ -820,6 +823,7 @@ __camellia_enc_blk32:
12447 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
12448 %ymm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 32(%rax));
12449
12450+ pax_force_retaddr_bts
12451 ret;
12452
12453 .align 8
12454@@ -905,6 +909,7 @@ __camellia_dec_blk32:
12455 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
12456 %ymm15, (key_table)(CTX), (%rax), 1 * 32(%rax));
12457
12458+ pax_force_retaddr_bts
12459 ret;
12460
12461 .align 8
12462@@ -948,6 +953,7 @@ ENTRY(camellia_ecb_enc_32way)
12463
12464 vzeroupper;
12465
12466+ pax_force_retaddr 0, 1
12467 ret;
12468 ENDPROC(camellia_ecb_enc_32way)
12469
12470@@ -980,6 +986,7 @@ ENTRY(camellia_ecb_dec_32way)
12471
12472 vzeroupper;
12473
12474+ pax_force_retaddr 0, 1
12475 ret;
12476 ENDPROC(camellia_ecb_dec_32way)
12477
12478@@ -1046,6 +1053,7 @@ ENTRY(camellia_cbc_dec_32way)
12479
12480 vzeroupper;
12481
12482+ pax_force_retaddr 0, 1
12483 ret;
12484 ENDPROC(camellia_cbc_dec_32way)
12485
12486@@ -1184,6 +1192,7 @@ ENTRY(camellia_ctr_32way)
12487
12488 vzeroupper;
12489
12490+ pax_force_retaddr 0, 1
12491 ret;
12492 ENDPROC(camellia_ctr_32way)
12493
12494@@ -1349,6 +1358,7 @@ camellia_xts_crypt_32way:
12495
12496 vzeroupper;
12497
12498+ pax_force_retaddr 0, 1
12499 ret;
12500 ENDPROC(camellia_xts_crypt_32way)
12501
12502diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
12503index 310319c..ce174a4 100644
12504--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
12505+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
12506@@ -21,6 +21,7 @@
12507 */
12508
12509 #include <linux/linkage.h>
12510+#include <asm/alternative-asm.h>
12511
12512 .file "camellia-x86_64-asm_64.S"
12513 .text
12514@@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
12515 enc_outunpack(mov, RT1);
12516
12517 movq RRBP, %rbp;
12518+ pax_force_retaddr 0, 1
12519 ret;
12520
12521 .L__enc_xor:
12522 enc_outunpack(xor, RT1);
12523
12524 movq RRBP, %rbp;
12525+ pax_force_retaddr 0, 1
12526 ret;
12527 ENDPROC(__camellia_enc_blk)
12528
12529@@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
12530 dec_outunpack();
12531
12532 movq RRBP, %rbp;
12533+ pax_force_retaddr 0, 1
12534 ret;
12535 ENDPROC(camellia_dec_blk)
12536
12537@@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
12538
12539 movq RRBP, %rbp;
12540 popq %rbx;
12541+ pax_force_retaddr 0, 1
12542 ret;
12543
12544 .L__enc2_xor:
12545@@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
12546
12547 movq RRBP, %rbp;
12548 popq %rbx;
12549+ pax_force_retaddr 0, 1
12550 ret;
12551 ENDPROC(__camellia_enc_blk_2way)
12552
12553@@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
12554
12555 movq RRBP, %rbp;
12556 movq RXOR, %rbx;
12557+ pax_force_retaddr 0, 1
12558 ret;
12559 ENDPROC(camellia_dec_blk_2way)
12560diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
12561index c35fd5d..c1ee236 100644
12562--- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
12563+++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
12564@@ -24,6 +24,7 @@
12565 */
12566
12567 #include <linux/linkage.h>
12568+#include <asm/alternative-asm.h>
12569
12570 .file "cast5-avx-x86_64-asm_64.S"
12571
12572@@ -281,6 +282,7 @@ __cast5_enc_blk16:
12573 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
12574 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
12575
12576+ pax_force_retaddr 0, 1
12577 ret;
12578 ENDPROC(__cast5_enc_blk16)
12579
12580@@ -352,6 +354,7 @@ __cast5_dec_blk16:
12581 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
12582 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
12583
12584+ pax_force_retaddr 0, 1
12585 ret;
12586
12587 .L__skip_dec:
12588@@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
12589 vmovdqu RR4, (6*4*4)(%r11);
12590 vmovdqu RL4, (7*4*4)(%r11);
12591
12592+ pax_force_retaddr
12593 ret;
12594 ENDPROC(cast5_ecb_enc_16way)
12595
12596@@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
12597 vmovdqu RR4, (6*4*4)(%r11);
12598 vmovdqu RL4, (7*4*4)(%r11);
12599
12600+ pax_force_retaddr
12601 ret;
12602 ENDPROC(cast5_ecb_dec_16way)
12603
12604@@ -469,6 +474,7 @@ ENTRY(cast5_cbc_dec_16way)
12605
12606 popq %r12;
12607
12608+ pax_force_retaddr
12609 ret;
12610 ENDPROC(cast5_cbc_dec_16way)
12611
12612@@ -542,5 +548,6 @@ ENTRY(cast5_ctr_16way)
12613
12614 popq %r12;
12615
12616+ pax_force_retaddr
12617 ret;
12618 ENDPROC(cast5_ctr_16way)
12619diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
12620index e3531f8..18ded3a 100644
12621--- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
12622+++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
12623@@ -24,6 +24,7 @@
12624 */
12625
12626 #include <linux/linkage.h>
12627+#include <asm/alternative-asm.h>
12628 #include "glue_helper-asm-avx.S"
12629
12630 .file "cast6-avx-x86_64-asm_64.S"
12631@@ -295,6 +296,7 @@ __cast6_enc_blk8:
12632 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
12633 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
12634
12635+ pax_force_retaddr 0, 1
12636 ret;
12637 ENDPROC(__cast6_enc_blk8)
12638
12639@@ -340,6 +342,7 @@ __cast6_dec_blk8:
12640 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
12641 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
12642
12643+ pax_force_retaddr 0, 1
12644 ret;
12645 ENDPROC(__cast6_dec_blk8)
12646
12647@@ -358,6 +361,7 @@ ENTRY(cast6_ecb_enc_8way)
12648
12649 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12650
12651+ pax_force_retaddr
12652 ret;
12653 ENDPROC(cast6_ecb_enc_8way)
12654
12655@@ -376,6 +380,7 @@ ENTRY(cast6_ecb_dec_8way)
12656
12657 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12658
12659+ pax_force_retaddr
12660 ret;
12661 ENDPROC(cast6_ecb_dec_8way)
12662
12663@@ -399,6 +404,7 @@ ENTRY(cast6_cbc_dec_8way)
12664
12665 popq %r12;
12666
12667+ pax_force_retaddr
12668 ret;
12669 ENDPROC(cast6_cbc_dec_8way)
12670
12671@@ -424,6 +430,7 @@ ENTRY(cast6_ctr_8way)
12672
12673 popq %r12;
12674
12675+ pax_force_retaddr
12676 ret;
12677 ENDPROC(cast6_ctr_8way)
12678
12679@@ -446,6 +453,7 @@ ENTRY(cast6_xts_enc_8way)
12680 /* dst <= regs xor IVs(in dst) */
12681 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12682
12683+ pax_force_retaddr
12684 ret;
12685 ENDPROC(cast6_xts_enc_8way)
12686
12687@@ -468,5 +476,6 @@ ENTRY(cast6_xts_dec_8way)
12688 /* dst <= regs xor IVs(in dst) */
12689 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12690
12691+ pax_force_retaddr
12692 ret;
12693 ENDPROC(cast6_xts_dec_8way)
12694diff --git a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
12695index dbc4339..3d868c5 100644
12696--- a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
12697+++ b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
12698@@ -45,6 +45,7 @@
12699
12700 #include <asm/inst.h>
12701 #include <linux/linkage.h>
12702+#include <asm/alternative-asm.h>
12703
12704 ## ISCSI CRC 32 Implementation with crc32 and pclmulqdq Instruction
12705
12706@@ -312,6 +313,7 @@ do_return:
12707 popq %rsi
12708 popq %rdi
12709 popq %rbx
12710+ pax_force_retaddr 0, 1
12711 ret
12712
12713 ################################################################
12714diff --git a/arch/x86/crypto/ghash-clmulni-intel_asm.S b/arch/x86/crypto/ghash-clmulni-intel_asm.S
12715index 586f41a..d02851e 100644
12716--- a/arch/x86/crypto/ghash-clmulni-intel_asm.S
12717+++ b/arch/x86/crypto/ghash-clmulni-intel_asm.S
12718@@ -18,6 +18,7 @@
12719
12720 #include <linux/linkage.h>
12721 #include <asm/inst.h>
12722+#include <asm/alternative-asm.h>
12723
12724 .data
12725
12726@@ -93,6 +94,7 @@ __clmul_gf128mul_ble:
12727 psrlq $1, T2
12728 pxor T2, T1
12729 pxor T1, DATA
12730+ pax_force_retaddr
12731 ret
12732 ENDPROC(__clmul_gf128mul_ble)
12733
12734@@ -105,6 +107,7 @@ ENTRY(clmul_ghash_mul)
12735 call __clmul_gf128mul_ble
12736 PSHUFB_XMM BSWAP DATA
12737 movups DATA, (%rdi)
12738+ pax_force_retaddr
12739 ret
12740 ENDPROC(clmul_ghash_mul)
12741
12742@@ -132,6 +135,7 @@ ENTRY(clmul_ghash_update)
12743 PSHUFB_XMM BSWAP DATA
12744 movups DATA, (%rdi)
12745 .Lupdate_just_ret:
12746+ pax_force_retaddr
12747 ret
12748 ENDPROC(clmul_ghash_update)
12749
12750@@ -157,5 +161,6 @@ ENTRY(clmul_ghash_setkey)
12751 pand .Lpoly, %xmm1
12752 pxor %xmm1, %xmm0
12753 movups %xmm0, (%rdi)
12754+ pax_force_retaddr
12755 ret
12756 ENDPROC(clmul_ghash_setkey)
12757diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
12758index 9279e0b..9270820 100644
12759--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
12760+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
12761@@ -1,4 +1,5 @@
12762 #include <linux/linkage.h>
12763+#include <asm/alternative-asm.h>
12764
12765 # enter salsa20_encrypt_bytes
12766 ENTRY(salsa20_encrypt_bytes)
12767@@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
12768 add %r11,%rsp
12769 mov %rdi,%rax
12770 mov %rsi,%rdx
12771+ pax_force_retaddr 0, 1
12772 ret
12773 # bytesatleast65:
12774 ._bytesatleast65:
12775@@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
12776 add %r11,%rsp
12777 mov %rdi,%rax
12778 mov %rsi,%rdx
12779+ pax_force_retaddr
12780 ret
12781 ENDPROC(salsa20_keysetup)
12782
12783@@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
12784 add %r11,%rsp
12785 mov %rdi,%rax
12786 mov %rsi,%rdx
12787+ pax_force_retaddr
12788 ret
12789 ENDPROC(salsa20_ivsetup)
12790diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
12791index 2f202f4..d9164d6 100644
12792--- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
12793+++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
12794@@ -24,6 +24,7 @@
12795 */
12796
12797 #include <linux/linkage.h>
12798+#include <asm/alternative-asm.h>
12799 #include "glue_helper-asm-avx.S"
12800
12801 .file "serpent-avx-x86_64-asm_64.S"
12802@@ -618,6 +619,7 @@ __serpent_enc_blk8_avx:
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_blk8_avx)
12809
12810@@ -672,6 +674,7 @@ __serpent_dec_blk8_avx:
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_blk8_avx)
12817
12818@@ -688,6 +691,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
12819
12820 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12821
12822+ pax_force_retaddr
12823 ret;
12824 ENDPROC(serpent_ecb_enc_8way_avx)
12825
12826@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
12827
12828 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
12829
12830+ pax_force_retaddr
12831 ret;
12832 ENDPROC(serpent_ecb_dec_8way_avx)
12833
12834@@ -720,6 +725,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
12835
12836 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
12837
12838+ pax_force_retaddr
12839 ret;
12840 ENDPROC(serpent_cbc_dec_8way_avx)
12841
12842@@ -738,6 +744,7 @@ ENTRY(serpent_ctr_8way_avx)
12843
12844 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12845
12846+ pax_force_retaddr
12847 ret;
12848 ENDPROC(serpent_ctr_8way_avx)
12849
12850@@ -758,6 +765,7 @@ ENTRY(serpent_xts_enc_8way_avx)
12851 /* dst <= regs xor IVs(in dst) */
12852 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12853
12854+ pax_force_retaddr
12855 ret;
12856 ENDPROC(serpent_xts_enc_8way_avx)
12857
12858@@ -778,5 +786,6 @@ ENTRY(serpent_xts_dec_8way_avx)
12859 /* dst <= regs xor IVs(in dst) */
12860 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
12861
12862+ pax_force_retaddr
12863 ret;
12864 ENDPROC(serpent_xts_dec_8way_avx)
12865diff --git a/arch/x86/crypto/serpent-avx2-asm_64.S b/arch/x86/crypto/serpent-avx2-asm_64.S
12866index b222085..abd483c 100644
12867--- a/arch/x86/crypto/serpent-avx2-asm_64.S
12868+++ b/arch/x86/crypto/serpent-avx2-asm_64.S
12869@@ -15,6 +15,7 @@
12870 */
12871
12872 #include <linux/linkage.h>
12873+#include <asm/alternative-asm.h>
12874 #include "glue_helper-asm-avx2.S"
12875
12876 .file "serpent-avx2-asm_64.S"
12877@@ -610,6 +611,7 @@ __serpent_enc_blk16:
12878 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
12879 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
12880
12881+ pax_force_retaddr
12882 ret;
12883 ENDPROC(__serpent_enc_blk16)
12884
12885@@ -664,6 +666,7 @@ __serpent_dec_blk16:
12886 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
12887 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
12888
12889+ pax_force_retaddr
12890 ret;
12891 ENDPROC(__serpent_dec_blk16)
12892
12893@@ -684,6 +687,7 @@ ENTRY(serpent_ecb_enc_16way)
12894
12895 vzeroupper;
12896
12897+ pax_force_retaddr
12898 ret;
12899 ENDPROC(serpent_ecb_enc_16way)
12900
12901@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_16way)
12902
12903 vzeroupper;
12904
12905+ pax_force_retaddr
12906 ret;
12907 ENDPROC(serpent_ecb_dec_16way)
12908
12909@@ -725,6 +730,7 @@ ENTRY(serpent_cbc_dec_16way)
12910
12911 vzeroupper;
12912
12913+ pax_force_retaddr
12914 ret;
12915 ENDPROC(serpent_cbc_dec_16way)
12916
12917@@ -748,6 +754,7 @@ ENTRY(serpent_ctr_16way)
12918
12919 vzeroupper;
12920
12921+ pax_force_retaddr
12922 ret;
12923 ENDPROC(serpent_ctr_16way)
12924
12925@@ -772,6 +779,7 @@ ENTRY(serpent_xts_enc_16way)
12926
12927 vzeroupper;
12928
12929+ pax_force_retaddr
12930 ret;
12931 ENDPROC(serpent_xts_enc_16way)
12932
12933@@ -796,5 +804,6 @@ ENTRY(serpent_xts_dec_16way)
12934
12935 vzeroupper;
12936
12937+ pax_force_retaddr
12938 ret;
12939 ENDPROC(serpent_xts_dec_16way)
12940diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
12941index acc066c..1559cc4 100644
12942--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
12943+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
12944@@ -25,6 +25,7 @@
12945 */
12946
12947 #include <linux/linkage.h>
12948+#include <asm/alternative-asm.h>
12949
12950 .file "serpent-sse2-x86_64-asm_64.S"
12951 .text
12952@@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
12953 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
12954 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
12955
12956+ pax_force_retaddr
12957 ret;
12958
12959 .L__enc_xor8:
12960 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
12961 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
12962
12963+ pax_force_retaddr
12964 ret;
12965 ENDPROC(__serpent_enc_blk_8way)
12966
12967@@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
12968 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
12969 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
12970
12971+ pax_force_retaddr
12972 ret;
12973 ENDPROC(serpent_dec_blk_8way)
12974diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
12975index a410950..3356d42 100644
12976--- a/arch/x86/crypto/sha1_ssse3_asm.S
12977+++ b/arch/x86/crypto/sha1_ssse3_asm.S
12978@@ -29,6 +29,7 @@
12979 */
12980
12981 #include <linux/linkage.h>
12982+#include <asm/alternative-asm.h>
12983
12984 #define CTX %rdi // arg1
12985 #define BUF %rsi // arg2
12986@@ -104,6 +105,7 @@
12987 pop %r12
12988 pop %rbp
12989 pop %rbx
12990+ pax_force_retaddr 0, 1
12991 ret
12992
12993 ENDPROC(\name)
12994diff --git a/arch/x86/crypto/sha256-avx-asm.S b/arch/x86/crypto/sha256-avx-asm.S
12995index 642f156..4ab07b9 100644
12996--- a/arch/x86/crypto/sha256-avx-asm.S
12997+++ b/arch/x86/crypto/sha256-avx-asm.S
12998@@ -49,6 +49,7 @@
12999
13000 #ifdef CONFIG_AS_AVX
13001 #include <linux/linkage.h>
13002+#include <asm/alternative-asm.h>
13003
13004 ## assume buffers not aligned
13005 #define VMOVDQ vmovdqu
13006@@ -460,6 +461,7 @@ done_hash:
13007 popq %r13
13008 popq %rbp
13009 popq %rbx
13010+ pax_force_retaddr 0, 1
13011 ret
13012 ENDPROC(sha256_transform_avx)
13013
13014diff --git a/arch/x86/crypto/sha256-avx2-asm.S b/arch/x86/crypto/sha256-avx2-asm.S
13015index 9e86944..2e7f95a 100644
13016--- a/arch/x86/crypto/sha256-avx2-asm.S
13017+++ b/arch/x86/crypto/sha256-avx2-asm.S
13018@@ -50,6 +50,7 @@
13019
13020 #ifdef CONFIG_AS_AVX2
13021 #include <linux/linkage.h>
13022+#include <asm/alternative-asm.h>
13023
13024 ## assume buffers not aligned
13025 #define VMOVDQ vmovdqu
13026@@ -720,6 +721,7 @@ done_hash:
13027 popq %r12
13028 popq %rbp
13029 popq %rbx
13030+ pax_force_retaddr 0, 1
13031 ret
13032 ENDPROC(sha256_transform_rorx)
13033
13034diff --git a/arch/x86/crypto/sha256-ssse3-asm.S b/arch/x86/crypto/sha256-ssse3-asm.S
13035index f833b74..c36ed14 100644
13036--- a/arch/x86/crypto/sha256-ssse3-asm.S
13037+++ b/arch/x86/crypto/sha256-ssse3-asm.S
13038@@ -47,6 +47,7 @@
13039 ########################################################################
13040
13041 #include <linux/linkage.h>
13042+#include <asm/alternative-asm.h>
13043
13044 ## assume buffers not aligned
13045 #define MOVDQ movdqu
13046@@ -471,6 +472,7 @@ done_hash:
13047 popq %rbp
13048 popq %rbx
13049
13050+ pax_force_retaddr 0, 1
13051 ret
13052 ENDPROC(sha256_transform_ssse3)
13053
13054diff --git a/arch/x86/crypto/sha512-avx-asm.S b/arch/x86/crypto/sha512-avx-asm.S
13055index 974dde9..4533d34 100644
13056--- a/arch/x86/crypto/sha512-avx-asm.S
13057+++ b/arch/x86/crypto/sha512-avx-asm.S
13058@@ -49,6 +49,7 @@
13059
13060 #ifdef CONFIG_AS_AVX
13061 #include <linux/linkage.h>
13062+#include <asm/alternative-asm.h>
13063
13064 .text
13065
13066@@ -364,6 +365,7 @@ updateblock:
13067 mov frame_RSPSAVE(%rsp), %rsp
13068
13069 nowork:
13070+ pax_force_retaddr 0, 1
13071 ret
13072 ENDPROC(sha512_transform_avx)
13073
13074diff --git a/arch/x86/crypto/sha512-avx2-asm.S b/arch/x86/crypto/sha512-avx2-asm.S
13075index 568b961..061ef1d 100644
13076--- a/arch/x86/crypto/sha512-avx2-asm.S
13077+++ b/arch/x86/crypto/sha512-avx2-asm.S
13078@@ -51,6 +51,7 @@
13079
13080 #ifdef CONFIG_AS_AVX2
13081 #include <linux/linkage.h>
13082+#include <asm/alternative-asm.h>
13083
13084 .text
13085
13086@@ -678,6 +679,7 @@ done_hash:
13087
13088 # Restore Stack Pointer
13089 mov frame_RSPSAVE(%rsp), %rsp
13090+ pax_force_retaddr 0, 1
13091 ret
13092 ENDPROC(sha512_transform_rorx)
13093
13094diff --git a/arch/x86/crypto/sha512-ssse3-asm.S b/arch/x86/crypto/sha512-ssse3-asm.S
13095index fb56855..e23914f 100644
13096--- a/arch/x86/crypto/sha512-ssse3-asm.S
13097+++ b/arch/x86/crypto/sha512-ssse3-asm.S
13098@@ -48,6 +48,7 @@
13099 ########################################################################
13100
13101 #include <linux/linkage.h>
13102+#include <asm/alternative-asm.h>
13103
13104 .text
13105
13106@@ -363,6 +364,7 @@ updateblock:
13107 mov frame_RSPSAVE(%rsp), %rsp
13108
13109 nowork:
13110+ pax_force_retaddr 0, 1
13111 ret
13112 ENDPROC(sha512_transform_ssse3)
13113
13114diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
13115index 0505813..63b1d00 100644
13116--- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
13117+++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
13118@@ -24,6 +24,7 @@
13119 */
13120
13121 #include <linux/linkage.h>
13122+#include <asm/alternative-asm.h>
13123 #include "glue_helper-asm-avx.S"
13124
13125 .file "twofish-avx-x86_64-asm_64.S"
13126@@ -284,6 +285,7 @@ __twofish_enc_blk8:
13127 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
13128 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
13129
13130+ pax_force_retaddr 0, 1
13131 ret;
13132 ENDPROC(__twofish_enc_blk8)
13133
13134@@ -324,6 +326,7 @@ __twofish_dec_blk8:
13135 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
13136 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
13137
13138+ pax_force_retaddr 0, 1
13139 ret;
13140 ENDPROC(__twofish_dec_blk8)
13141
13142@@ -342,6 +345,7 @@ ENTRY(twofish_ecb_enc_8way)
13143
13144 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
13145
13146+ pax_force_retaddr 0, 1
13147 ret;
13148 ENDPROC(twofish_ecb_enc_8way)
13149
13150@@ -360,6 +364,7 @@ ENTRY(twofish_ecb_dec_8way)
13151
13152 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13153
13154+ pax_force_retaddr 0, 1
13155 ret;
13156 ENDPROC(twofish_ecb_dec_8way)
13157
13158@@ -383,6 +388,7 @@ ENTRY(twofish_cbc_dec_8way)
13159
13160 popq %r12;
13161
13162+ pax_force_retaddr 0, 1
13163 ret;
13164 ENDPROC(twofish_cbc_dec_8way)
13165
13166@@ -408,6 +414,7 @@ ENTRY(twofish_ctr_8way)
13167
13168 popq %r12;
13169
13170+ pax_force_retaddr 0, 1
13171 ret;
13172 ENDPROC(twofish_ctr_8way)
13173
13174@@ -430,6 +437,7 @@ ENTRY(twofish_xts_enc_8way)
13175 /* dst <= regs xor IVs(in dst) */
13176 store_xts_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
13177
13178+ pax_force_retaddr 0, 1
13179 ret;
13180 ENDPROC(twofish_xts_enc_8way)
13181
13182@@ -452,5 +460,6 @@ ENTRY(twofish_xts_dec_8way)
13183 /* dst <= regs xor IVs(in dst) */
13184 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13185
13186+ pax_force_retaddr 0, 1
13187 ret;
13188 ENDPROC(twofish_xts_dec_8way)
13189diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
13190index 1c3b7ce..b365c5e 100644
13191--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
13192+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
13193@@ -21,6 +21,7 @@
13194 */
13195
13196 #include <linux/linkage.h>
13197+#include <asm/alternative-asm.h>
13198
13199 .file "twofish-x86_64-asm-3way.S"
13200 .text
13201@@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
13202 popq %r13;
13203 popq %r14;
13204 popq %r15;
13205+ pax_force_retaddr 0, 1
13206 ret;
13207
13208 .L__enc_xor3:
13209@@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
13210 popq %r13;
13211 popq %r14;
13212 popq %r15;
13213+ pax_force_retaddr 0, 1
13214 ret;
13215 ENDPROC(__twofish_enc_blk_3way)
13216
13217@@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
13218 popq %r13;
13219 popq %r14;
13220 popq %r15;
13221+ pax_force_retaddr 0, 1
13222 ret;
13223 ENDPROC(twofish_dec_blk_3way)
13224diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
13225index a039d21..29e7615 100644
13226--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
13227+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
13228@@ -22,6 +22,7 @@
13229
13230 #include <linux/linkage.h>
13231 #include <asm/asm-offsets.h>
13232+#include <asm/alternative-asm.h>
13233
13234 #define a_offset 0
13235 #define b_offset 4
13236@@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
13237
13238 popq R1
13239 movq $1,%rax
13240+ pax_force_retaddr 0, 1
13241 ret
13242 ENDPROC(twofish_enc_blk)
13243
13244@@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
13245
13246 popq R1
13247 movq $1,%rax
13248+ pax_force_retaddr 0, 1
13249 ret
13250 ENDPROC(twofish_dec_blk)
13251diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
13252index bae3aba..c1788c1 100644
13253--- a/arch/x86/ia32/ia32_aout.c
13254+++ b/arch/x86/ia32/ia32_aout.c
13255@@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
13256 unsigned long dump_start, dump_size;
13257 struct user32 dump;
13258
13259+ memset(&dump, 0, sizeof(dump));
13260+
13261 fs = get_fs();
13262 set_fs(KERNEL_DS);
13263 has_dumped = 1;
13264diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
13265index 665a730..8e7a67a 100644
13266--- a/arch/x86/ia32/ia32_signal.c
13267+++ b/arch/x86/ia32/ia32_signal.c
13268@@ -338,7 +338,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
13269 sp -= frame_size;
13270 /* Align the stack pointer according to the i386 ABI,
13271 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
13272- sp = ((sp + 4) & -16ul) - 4;
13273+ sp = ((sp - 12) & -16ul) - 4;
13274 return (void __user *) sp;
13275 }
13276
13277@@ -396,7 +396,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
13278 * These are actually not used anymore, but left because some
13279 * gdb versions depend on them as a marker.
13280 */
13281- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
13282+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
13283 } put_user_catch(err);
13284
13285 if (err)
13286@@ -438,7 +438,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
13287 0xb8,
13288 __NR_ia32_rt_sigreturn,
13289 0x80cd,
13290- 0,
13291+ 0
13292 };
13293
13294 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
13295@@ -461,16 +461,18 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
13296
13297 if (ksig->ka.sa.sa_flags & SA_RESTORER)
13298 restorer = ksig->ka.sa.sa_restorer;
13299+ else if (current->mm->context.vdso)
13300+ /* Return stub is in 32bit vsyscall page */
13301+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
13302 else
13303- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
13304- rt_sigreturn);
13305+ restorer = &frame->retcode;
13306 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
13307
13308 /*
13309 * Not actually used anymore, but left because some gdb
13310 * versions need it.
13311 */
13312- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
13313+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
13314 } put_user_catch(err);
13315
13316 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
13317diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
13318index 474dc1b..9297c58 100644
13319--- a/arch/x86/ia32/ia32entry.S
13320+++ b/arch/x86/ia32/ia32entry.S
13321@@ -15,8 +15,10 @@
13322 #include <asm/irqflags.h>
13323 #include <asm/asm.h>
13324 #include <asm/smap.h>
13325+#include <asm/pgtable.h>
13326 #include <linux/linkage.h>
13327 #include <linux/err.h>
13328+#include <asm/alternative-asm.h>
13329
13330 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
13331 #include <linux/elf-em.h>
13332@@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
13333 ENDPROC(native_irq_enable_sysexit)
13334 #endif
13335
13336+ .macro pax_enter_kernel_user
13337+ pax_set_fptr_mask
13338+#ifdef CONFIG_PAX_MEMORY_UDEREF
13339+ call pax_enter_kernel_user
13340+#endif
13341+ .endm
13342+
13343+ .macro pax_exit_kernel_user
13344+#ifdef CONFIG_PAX_MEMORY_UDEREF
13345+ call pax_exit_kernel_user
13346+#endif
13347+#ifdef CONFIG_PAX_RANDKSTACK
13348+ pushq %rax
13349+ pushq %r11
13350+ call pax_randomize_kstack
13351+ popq %r11
13352+ popq %rax
13353+#endif
13354+ .endm
13355+
13356+ .macro pax_erase_kstack
13357+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
13358+ call pax_erase_kstack
13359+#endif
13360+ .endm
13361+
13362 /*
13363 * 32bit SYSENTER instruction entry.
13364 *
13365@@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
13366 CFI_REGISTER rsp,rbp
13367 SWAPGS_UNSAFE_STACK
13368 movq PER_CPU_VAR(kernel_stack), %rsp
13369- addq $(KERNEL_STACK_OFFSET),%rsp
13370- /*
13371- * No need to follow this irqs on/off section: the syscall
13372- * disabled irqs, here we enable it straight after entry:
13373- */
13374- ENABLE_INTERRUPTS(CLBR_NONE)
13375 movl %ebp,%ebp /* zero extension */
13376 pushq_cfi $__USER32_DS
13377 /*CFI_REL_OFFSET ss,0*/
13378@@ -135,24 +157,49 @@ ENTRY(ia32_sysenter_target)
13379 CFI_REL_OFFSET rsp,0
13380 pushfq_cfi
13381 /*CFI_REL_OFFSET rflags,0*/
13382- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
13383- CFI_REGISTER rip,r10
13384+ orl $X86_EFLAGS_IF,(%rsp)
13385+ GET_THREAD_INFO(%r11)
13386+ movl TI_sysenter_return(%r11), %r11d
13387+ CFI_REGISTER rip,r11
13388 pushq_cfi $__USER32_CS
13389 /*CFI_REL_OFFSET cs,0*/
13390 movl %eax, %eax
13391- pushq_cfi %r10
13392+ pushq_cfi %r11
13393 CFI_REL_OFFSET rip,0
13394 pushq_cfi %rax
13395 cld
13396 SAVE_ARGS 0,1,0
13397+ pax_enter_kernel_user
13398+
13399+#ifdef CONFIG_PAX_RANDKSTACK
13400+ pax_erase_kstack
13401+#endif
13402+
13403+ /*
13404+ * No need to follow this irqs on/off section: the syscall
13405+ * disabled irqs, here we enable it straight after entry:
13406+ */
13407+ ENABLE_INTERRUPTS(CLBR_NONE)
13408 /* no need to do an access_ok check here because rbp has been
13409 32bit zero extended */
13410+
13411+#ifdef CONFIG_PAX_MEMORY_UDEREF
13412+ addq pax_user_shadow_base,%rbp
13413+ ASM_PAX_OPEN_USERLAND
13414+#endif
13415+
13416 ASM_STAC
13417 1: movl (%rbp),%ebp
13418 _ASM_EXTABLE(1b,ia32_badarg)
13419 ASM_CLAC
13420- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13421- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13422+
13423+#ifdef CONFIG_PAX_MEMORY_UDEREF
13424+ ASM_PAX_CLOSE_USERLAND
13425+#endif
13426+
13427+ GET_THREAD_INFO(%r11)
13428+ orl $TS_COMPAT,TI_status(%r11)
13429+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
13430 CFI_REMEMBER_STATE
13431 jnz sysenter_tracesys
13432 cmpq $(IA32_NR_syscalls-1),%rax
13433@@ -162,12 +209,15 @@ sysenter_do_call:
13434 sysenter_dispatch:
13435 call *ia32_sys_call_table(,%rax,8)
13436 movq %rax,RAX-ARGOFFSET(%rsp)
13437+ GET_THREAD_INFO(%r11)
13438 DISABLE_INTERRUPTS(CLBR_NONE)
13439 TRACE_IRQS_OFF
13440- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13441+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
13442 jnz sysexit_audit
13443 sysexit_from_sys_call:
13444- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13445+ pax_exit_kernel_user
13446+ pax_erase_kstack
13447+ andl $~TS_COMPAT,TI_status(%r11)
13448 /* clear IF, that popfq doesn't enable interrupts early */
13449 andl $~0x200,EFLAGS-R11(%rsp)
13450 movl RIP-R11(%rsp),%edx /* User %eip */
13451@@ -193,6 +243,9 @@ sysexit_from_sys_call:
13452 movl %eax,%esi /* 2nd arg: syscall number */
13453 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
13454 call __audit_syscall_entry
13455+
13456+ pax_erase_kstack
13457+
13458 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
13459 cmpq $(IA32_NR_syscalls-1),%rax
13460 ja ia32_badsys
13461@@ -204,7 +257,7 @@ sysexit_from_sys_call:
13462 .endm
13463
13464 .macro auditsys_exit exit
13465- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13466+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
13467 jnz ia32_ret_from_sys_call
13468 TRACE_IRQS_ON
13469 ENABLE_INTERRUPTS(CLBR_NONE)
13470@@ -215,11 +268,12 @@ sysexit_from_sys_call:
13471 1: setbe %al /* 1 if error, 0 if not */
13472 movzbl %al,%edi /* zero-extend that into %edi */
13473 call __audit_syscall_exit
13474+ GET_THREAD_INFO(%r11)
13475 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
13476 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
13477 DISABLE_INTERRUPTS(CLBR_NONE)
13478 TRACE_IRQS_OFF
13479- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13480+ testl %edi,TI_flags(%r11)
13481 jz \exit
13482 CLEAR_RREGS -ARGOFFSET
13483 jmp int_with_check
13484@@ -237,7 +291,7 @@ sysexit_audit:
13485
13486 sysenter_tracesys:
13487 #ifdef CONFIG_AUDITSYSCALL
13488- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13489+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
13490 jz sysenter_auditsys
13491 #endif
13492 SAVE_REST
13493@@ -249,6 +303,9 @@ sysenter_tracesys:
13494 RESTORE_REST
13495 cmpq $(IA32_NR_syscalls-1),%rax
13496 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
13497+
13498+ pax_erase_kstack
13499+
13500 jmp sysenter_do_call
13501 CFI_ENDPROC
13502 ENDPROC(ia32_sysenter_target)
13503@@ -276,19 +333,25 @@ ENDPROC(ia32_sysenter_target)
13504 ENTRY(ia32_cstar_target)
13505 CFI_STARTPROC32 simple
13506 CFI_SIGNAL_FRAME
13507- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
13508+ CFI_DEF_CFA rsp,0
13509 CFI_REGISTER rip,rcx
13510 /*CFI_REGISTER rflags,r11*/
13511 SWAPGS_UNSAFE_STACK
13512 movl %esp,%r8d
13513 CFI_REGISTER rsp,r8
13514 movq PER_CPU_VAR(kernel_stack),%rsp
13515+ SAVE_ARGS 8*6,0,0
13516+ pax_enter_kernel_user
13517+
13518+#ifdef CONFIG_PAX_RANDKSTACK
13519+ pax_erase_kstack
13520+#endif
13521+
13522 /*
13523 * No need to follow this irqs on/off section: the syscall
13524 * disabled irqs and here we enable it straight after entry:
13525 */
13526 ENABLE_INTERRUPTS(CLBR_NONE)
13527- SAVE_ARGS 8,0,0
13528 movl %eax,%eax /* zero extension */
13529 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
13530 movq %rcx,RIP-ARGOFFSET(%rsp)
13531@@ -304,12 +367,25 @@ ENTRY(ia32_cstar_target)
13532 /* no need to do an access_ok check here because r8 has been
13533 32bit zero extended */
13534 /* hardware stack frame is complete now */
13535+
13536+#ifdef CONFIG_PAX_MEMORY_UDEREF
13537+ ASM_PAX_OPEN_USERLAND
13538+ movq pax_user_shadow_base,%r8
13539+ addq RSP-ARGOFFSET(%rsp),%r8
13540+#endif
13541+
13542 ASM_STAC
13543 1: movl (%r8),%r9d
13544 _ASM_EXTABLE(1b,ia32_badarg)
13545 ASM_CLAC
13546- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13547- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13548+
13549+#ifdef CONFIG_PAX_MEMORY_UDEREF
13550+ ASM_PAX_CLOSE_USERLAND
13551+#endif
13552+
13553+ GET_THREAD_INFO(%r11)
13554+ orl $TS_COMPAT,TI_status(%r11)
13555+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
13556 CFI_REMEMBER_STATE
13557 jnz cstar_tracesys
13558 cmpq $IA32_NR_syscalls-1,%rax
13559@@ -319,12 +395,15 @@ cstar_do_call:
13560 cstar_dispatch:
13561 call *ia32_sys_call_table(,%rax,8)
13562 movq %rax,RAX-ARGOFFSET(%rsp)
13563+ GET_THREAD_INFO(%r11)
13564 DISABLE_INTERRUPTS(CLBR_NONE)
13565 TRACE_IRQS_OFF
13566- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13567+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
13568 jnz sysretl_audit
13569 sysretl_from_sys_call:
13570- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13571+ pax_exit_kernel_user
13572+ pax_erase_kstack
13573+ andl $~TS_COMPAT,TI_status(%r11)
13574 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
13575 movl RIP-ARGOFFSET(%rsp),%ecx
13576 CFI_REGISTER rip,rcx
13577@@ -352,7 +431,7 @@ sysretl_audit:
13578
13579 cstar_tracesys:
13580 #ifdef CONFIG_AUDITSYSCALL
13581- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13582+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
13583 jz cstar_auditsys
13584 #endif
13585 xchgl %r9d,%ebp
13586@@ -366,11 +445,19 @@ cstar_tracesys:
13587 xchgl %ebp,%r9d
13588 cmpq $(IA32_NR_syscalls-1),%rax
13589 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
13590+
13591+ pax_erase_kstack
13592+
13593 jmp cstar_do_call
13594 END(ia32_cstar_target)
13595
13596 ia32_badarg:
13597 ASM_CLAC
13598+
13599+#ifdef CONFIG_PAX_MEMORY_UDEREF
13600+ ASM_PAX_CLOSE_USERLAND
13601+#endif
13602+
13603 movq $-EFAULT,%rax
13604 jmp ia32_sysret
13605 CFI_ENDPROC
13606@@ -407,19 +494,26 @@ ENTRY(ia32_syscall)
13607 CFI_REL_OFFSET rip,RIP-RIP
13608 PARAVIRT_ADJUST_EXCEPTION_FRAME
13609 SWAPGS
13610- /*
13611- * No need to follow this irqs on/off section: the syscall
13612- * disabled irqs and here we enable it straight after entry:
13613- */
13614- ENABLE_INTERRUPTS(CLBR_NONE)
13615 movl %eax,%eax
13616 pushq_cfi %rax
13617 cld
13618 /* note the registers are not zero extended to the sf.
13619 this could be a problem. */
13620 SAVE_ARGS 0,1,0
13621- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13622- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13623+ pax_enter_kernel_user
13624+
13625+#ifdef CONFIG_PAX_RANDKSTACK
13626+ pax_erase_kstack
13627+#endif
13628+
13629+ /*
13630+ * No need to follow this irqs on/off section: the syscall
13631+ * disabled irqs and here we enable it straight after entry:
13632+ */
13633+ ENABLE_INTERRUPTS(CLBR_NONE)
13634+ GET_THREAD_INFO(%r11)
13635+ orl $TS_COMPAT,TI_status(%r11)
13636+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
13637 jnz ia32_tracesys
13638 cmpq $(IA32_NR_syscalls-1),%rax
13639 ja ia32_badsys
13640@@ -442,6 +536,9 @@ ia32_tracesys:
13641 RESTORE_REST
13642 cmpq $(IA32_NR_syscalls-1),%rax
13643 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
13644+
13645+ pax_erase_kstack
13646+
13647 jmp ia32_do_call
13648 END(ia32_syscall)
13649
13650diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
13651index 8e0ceec..af13504 100644
13652--- a/arch/x86/ia32/sys_ia32.c
13653+++ b/arch/x86/ia32/sys_ia32.c
13654@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
13655 */
13656 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
13657 {
13658- typeof(ubuf->st_uid) uid = 0;
13659- typeof(ubuf->st_gid) gid = 0;
13660+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
13661+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
13662 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
13663 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
13664 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
13665diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
13666index 372231c..a5aa1a1 100644
13667--- a/arch/x86/include/asm/alternative-asm.h
13668+++ b/arch/x86/include/asm/alternative-asm.h
13669@@ -18,6 +18,45 @@
13670 .endm
13671 #endif
13672
13673+#ifdef KERNEXEC_PLUGIN
13674+ .macro pax_force_retaddr_bts rip=0
13675+ btsq $63,\rip(%rsp)
13676+ .endm
13677+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
13678+ .macro pax_force_retaddr rip=0, reload=0
13679+ btsq $63,\rip(%rsp)
13680+ .endm
13681+ .macro pax_force_fptr ptr
13682+ btsq $63,\ptr
13683+ .endm
13684+ .macro pax_set_fptr_mask
13685+ .endm
13686+#endif
13687+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
13688+ .macro pax_force_retaddr rip=0, reload=0
13689+ .if \reload
13690+ pax_set_fptr_mask
13691+ .endif
13692+ orq %r10,\rip(%rsp)
13693+ .endm
13694+ .macro pax_force_fptr ptr
13695+ orq %r10,\ptr
13696+ .endm
13697+ .macro pax_set_fptr_mask
13698+ movabs $0x8000000000000000,%r10
13699+ .endm
13700+#endif
13701+#else
13702+ .macro pax_force_retaddr rip=0, reload=0
13703+ .endm
13704+ .macro pax_force_fptr ptr
13705+ .endm
13706+ .macro pax_force_retaddr_bts rip=0
13707+ .endm
13708+ .macro pax_set_fptr_mask
13709+ .endm
13710+#endif
13711+
13712 .macro altinstruction_entry orig alt feature orig_len alt_len
13713 .long \orig - .
13714 .long \alt - .
13715diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
13716index 58ed6d9..f1cbe58 100644
13717--- a/arch/x86/include/asm/alternative.h
13718+++ b/arch/x86/include/asm/alternative.h
13719@@ -105,7 +105,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
13720 ".pushsection .discard,\"aw\",@progbits\n" \
13721 DISCARD_ENTRY(1) \
13722 ".popsection\n" \
13723- ".pushsection .altinstr_replacement, \"ax\"\n" \
13724+ ".pushsection .altinstr_replacement, \"a\"\n" \
13725 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
13726 ".popsection"
13727
13728@@ -119,7 +119,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
13729 DISCARD_ENTRY(1) \
13730 DISCARD_ENTRY(2) \
13731 ".popsection\n" \
13732- ".pushsection .altinstr_replacement, \"ax\"\n" \
13733+ ".pushsection .altinstr_replacement, \"a\"\n" \
13734 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
13735 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
13736 ".popsection"
13737diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
13738index f8119b5..7209d5b 100644
13739--- a/arch/x86/include/asm/apic.h
13740+++ b/arch/x86/include/asm/apic.h
13741@@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
13742
13743 #ifdef CONFIG_X86_LOCAL_APIC
13744
13745-extern unsigned int apic_verbosity;
13746+extern int apic_verbosity;
13747 extern int local_apic_timer_c2_ok;
13748
13749 extern int disable_apic;
13750diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
13751index 20370c6..a2eb9b0 100644
13752--- a/arch/x86/include/asm/apm.h
13753+++ b/arch/x86/include/asm/apm.h
13754@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
13755 __asm__ __volatile__(APM_DO_ZERO_SEGS
13756 "pushl %%edi\n\t"
13757 "pushl %%ebp\n\t"
13758- "lcall *%%cs:apm_bios_entry\n\t"
13759+ "lcall *%%ss:apm_bios_entry\n\t"
13760 "setc %%al\n\t"
13761 "popl %%ebp\n\t"
13762 "popl %%edi\n\t"
13763@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
13764 __asm__ __volatile__(APM_DO_ZERO_SEGS
13765 "pushl %%edi\n\t"
13766 "pushl %%ebp\n\t"
13767- "lcall *%%cs:apm_bios_entry\n\t"
13768+ "lcall *%%ss:apm_bios_entry\n\t"
13769 "setc %%bl\n\t"
13770 "popl %%ebp\n\t"
13771 "popl %%edi\n\t"
13772diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
13773index 722aa3b..3a0bb27 100644
13774--- a/arch/x86/include/asm/atomic.h
13775+++ b/arch/x86/include/asm/atomic.h
13776@@ -22,7 +22,18 @@
13777 */
13778 static inline int atomic_read(const atomic_t *v)
13779 {
13780- return (*(volatile int *)&(v)->counter);
13781+ return (*(volatile const int *)&(v)->counter);
13782+}
13783+
13784+/**
13785+ * atomic_read_unchecked - read atomic variable
13786+ * @v: pointer of type atomic_unchecked_t
13787+ *
13788+ * Atomically reads the value of @v.
13789+ */
13790+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
13791+{
13792+ return (*(volatile const int *)&(v)->counter);
13793 }
13794
13795 /**
13796@@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
13797 }
13798
13799 /**
13800+ * atomic_set_unchecked - set atomic variable
13801+ * @v: pointer of type atomic_unchecked_t
13802+ * @i: required value
13803+ *
13804+ * Atomically sets the value of @v to @i.
13805+ */
13806+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
13807+{
13808+ v->counter = i;
13809+}
13810+
13811+/**
13812 * atomic_add - add integer to atomic variable
13813 * @i: integer value to add
13814 * @v: pointer of type atomic_t
13815@@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
13816 */
13817 static inline void atomic_add(int i, atomic_t *v)
13818 {
13819- asm volatile(LOCK_PREFIX "addl %1,%0"
13820+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
13821+
13822+#ifdef CONFIG_PAX_REFCOUNT
13823+ "jno 0f\n"
13824+ LOCK_PREFIX "subl %1,%0\n"
13825+ "int $4\n0:\n"
13826+ _ASM_EXTABLE(0b, 0b)
13827+#endif
13828+
13829+ : "+m" (v->counter)
13830+ : "ir" (i));
13831+}
13832+
13833+/**
13834+ * atomic_add_unchecked - add integer to atomic variable
13835+ * @i: integer value to add
13836+ * @v: pointer of type atomic_unchecked_t
13837+ *
13838+ * Atomically adds @i to @v.
13839+ */
13840+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
13841+{
13842+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
13843 : "+m" (v->counter)
13844 : "ir" (i));
13845 }
13846@@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
13847 */
13848 static inline void atomic_sub(int i, atomic_t *v)
13849 {
13850- asm volatile(LOCK_PREFIX "subl %1,%0"
13851+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
13852+
13853+#ifdef CONFIG_PAX_REFCOUNT
13854+ "jno 0f\n"
13855+ LOCK_PREFIX "addl %1,%0\n"
13856+ "int $4\n0:\n"
13857+ _ASM_EXTABLE(0b, 0b)
13858+#endif
13859+
13860+ : "+m" (v->counter)
13861+ : "ir" (i));
13862+}
13863+
13864+/**
13865+ * atomic_sub_unchecked - subtract integer from atomic variable
13866+ * @i: integer value to subtract
13867+ * @v: pointer of type atomic_unchecked_t
13868+ *
13869+ * Atomically subtracts @i from @v.
13870+ */
13871+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
13872+{
13873+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
13874 : "+m" (v->counter)
13875 : "ir" (i));
13876 }
13877@@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
13878 {
13879 unsigned char c;
13880
13881- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
13882+ asm volatile(LOCK_PREFIX "subl %2,%0\n"
13883+
13884+#ifdef CONFIG_PAX_REFCOUNT
13885+ "jno 0f\n"
13886+ LOCK_PREFIX "addl %2,%0\n"
13887+ "int $4\n0:\n"
13888+ _ASM_EXTABLE(0b, 0b)
13889+#endif
13890+
13891+ "sete %1\n"
13892 : "+m" (v->counter), "=qm" (c)
13893 : "ir" (i) : "memory");
13894 return c;
13895@@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
13896 */
13897 static inline void atomic_inc(atomic_t *v)
13898 {
13899- asm volatile(LOCK_PREFIX "incl %0"
13900+ asm volatile(LOCK_PREFIX "incl %0\n"
13901+
13902+#ifdef CONFIG_PAX_REFCOUNT
13903+ "jno 0f\n"
13904+ LOCK_PREFIX "decl %0\n"
13905+ "int $4\n0:\n"
13906+ _ASM_EXTABLE(0b, 0b)
13907+#endif
13908+
13909+ : "+m" (v->counter));
13910+}
13911+
13912+/**
13913+ * atomic_inc_unchecked - increment atomic variable
13914+ * @v: pointer of type atomic_unchecked_t
13915+ *
13916+ * Atomically increments @v by 1.
13917+ */
13918+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
13919+{
13920+ asm volatile(LOCK_PREFIX "incl %0\n"
13921 : "+m" (v->counter));
13922 }
13923
13924@@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
13925 */
13926 static inline void atomic_dec(atomic_t *v)
13927 {
13928- asm volatile(LOCK_PREFIX "decl %0"
13929+ asm volatile(LOCK_PREFIX "decl %0\n"
13930+
13931+#ifdef CONFIG_PAX_REFCOUNT
13932+ "jno 0f\n"
13933+ LOCK_PREFIX "incl %0\n"
13934+ "int $4\n0:\n"
13935+ _ASM_EXTABLE(0b, 0b)
13936+#endif
13937+
13938+ : "+m" (v->counter));
13939+}
13940+
13941+/**
13942+ * atomic_dec_unchecked - decrement atomic variable
13943+ * @v: pointer of type atomic_unchecked_t
13944+ *
13945+ * Atomically decrements @v by 1.
13946+ */
13947+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
13948+{
13949+ asm volatile(LOCK_PREFIX "decl %0\n"
13950 : "+m" (v->counter));
13951 }
13952
13953@@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
13954 {
13955 unsigned char c;
13956
13957- asm volatile(LOCK_PREFIX "decl %0; sete %1"
13958+ asm volatile(LOCK_PREFIX "decl %0\n"
13959+
13960+#ifdef CONFIG_PAX_REFCOUNT
13961+ "jno 0f\n"
13962+ LOCK_PREFIX "incl %0\n"
13963+ "int $4\n0:\n"
13964+ _ASM_EXTABLE(0b, 0b)
13965+#endif
13966+
13967+ "sete %1\n"
13968 : "+m" (v->counter), "=qm" (c)
13969 : : "memory");
13970 return c != 0;
13971@@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
13972 {
13973 unsigned char c;
13974
13975- asm volatile(LOCK_PREFIX "incl %0; sete %1"
13976+ asm volatile(LOCK_PREFIX "incl %0\n"
13977+
13978+#ifdef CONFIG_PAX_REFCOUNT
13979+ "jno 0f\n"
13980+ LOCK_PREFIX "decl %0\n"
13981+ "int $4\n0:\n"
13982+ _ASM_EXTABLE(0b, 0b)
13983+#endif
13984+
13985+ "sete %1\n"
13986+ : "+m" (v->counter), "=qm" (c)
13987+ : : "memory");
13988+ return c != 0;
13989+}
13990+
13991+/**
13992+ * atomic_inc_and_test_unchecked - increment and test
13993+ * @v: pointer of type atomic_unchecked_t
13994+ *
13995+ * Atomically increments @v by 1
13996+ * and returns true if the result is zero, or false for all
13997+ * other cases.
13998+ */
13999+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
14000+{
14001+ unsigned char c;
14002+
14003+ asm volatile(LOCK_PREFIX "incl %0\n"
14004+ "sete %1\n"
14005 : "+m" (v->counter), "=qm" (c)
14006 : : "memory");
14007 return c != 0;
14008@@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
14009 {
14010 unsigned char c;
14011
14012- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
14013+ asm volatile(LOCK_PREFIX "addl %2,%0\n"
14014+
14015+#ifdef CONFIG_PAX_REFCOUNT
14016+ "jno 0f\n"
14017+ LOCK_PREFIX "subl %2,%0\n"
14018+ "int $4\n0:\n"
14019+ _ASM_EXTABLE(0b, 0b)
14020+#endif
14021+
14022+ "sets %1\n"
14023 : "+m" (v->counter), "=qm" (c)
14024 : "ir" (i) : "memory");
14025 return c;
14026@@ -172,6 +334,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
14027 */
14028 static inline int atomic_add_return(int i, atomic_t *v)
14029 {
14030+ return i + xadd_check_overflow(&v->counter, i);
14031+}
14032+
14033+/**
14034+ * atomic_add_return_unchecked - add integer and return
14035+ * @i: integer value to add
14036+ * @v: pointer of type atomic_unchecked_t
14037+ *
14038+ * Atomically adds @i to @v and returns @i + @v
14039+ */
14040+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
14041+{
14042 return i + xadd(&v->counter, i);
14043 }
14044
14045@@ -188,6 +362,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
14046 }
14047
14048 #define atomic_inc_return(v) (atomic_add_return(1, v))
14049+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
14050+{
14051+ return atomic_add_return_unchecked(1, v);
14052+}
14053 #define atomic_dec_return(v) (atomic_sub_return(1, v))
14054
14055 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
14056@@ -195,11 +373,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
14057 return cmpxchg(&v->counter, old, new);
14058 }
14059
14060+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
14061+{
14062+ return cmpxchg(&v->counter, old, new);
14063+}
14064+
14065 static inline int atomic_xchg(atomic_t *v, int new)
14066 {
14067 return xchg(&v->counter, new);
14068 }
14069
14070+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
14071+{
14072+ return xchg(&v->counter, new);
14073+}
14074+
14075 /**
14076 * __atomic_add_unless - add unless the number is already a given value
14077 * @v: pointer of type atomic_t
14078@@ -211,12 +399,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
14079 */
14080 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
14081 {
14082- int c, old;
14083+ int c, old, new;
14084 c = atomic_read(v);
14085 for (;;) {
14086- if (unlikely(c == (u)))
14087+ if (unlikely(c == u))
14088 break;
14089- old = atomic_cmpxchg((v), c, c + (a));
14090+
14091+ asm volatile("addl %2,%0\n"
14092+
14093+#ifdef CONFIG_PAX_REFCOUNT
14094+ "jno 0f\n"
14095+ "subl %2,%0\n"
14096+ "int $4\n0:\n"
14097+ _ASM_EXTABLE(0b, 0b)
14098+#endif
14099+
14100+ : "=r" (new)
14101+ : "0" (c), "ir" (a));
14102+
14103+ old = atomic_cmpxchg(v, c, new);
14104 if (likely(old == c))
14105 break;
14106 c = old;
14107@@ -225,6 +426,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
14108 }
14109
14110 /**
14111+ * atomic_inc_not_zero_hint - increment if not null
14112+ * @v: pointer of type atomic_t
14113+ * @hint: probable value of the atomic before the increment
14114+ *
14115+ * This version of atomic_inc_not_zero() gives a hint of probable
14116+ * value of the atomic. This helps processor to not read the memory
14117+ * before doing the atomic read/modify/write cycle, lowering
14118+ * number of bus transactions on some arches.
14119+ *
14120+ * Returns: 0 if increment was not done, 1 otherwise.
14121+ */
14122+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
14123+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
14124+{
14125+ int val, c = hint, new;
14126+
14127+ /* sanity test, should be removed by compiler if hint is a constant */
14128+ if (!hint)
14129+ return __atomic_add_unless(v, 1, 0);
14130+
14131+ do {
14132+ asm volatile("incl %0\n"
14133+
14134+#ifdef CONFIG_PAX_REFCOUNT
14135+ "jno 0f\n"
14136+ "decl %0\n"
14137+ "int $4\n0:\n"
14138+ _ASM_EXTABLE(0b, 0b)
14139+#endif
14140+
14141+ : "=r" (new)
14142+ : "0" (c));
14143+
14144+ val = atomic_cmpxchg(v, c, new);
14145+ if (val == c)
14146+ return 1;
14147+ c = val;
14148+ } while (c);
14149+
14150+ return 0;
14151+}
14152+
14153+/**
14154 * atomic_inc_short - increment of a short integer
14155 * @v: pointer to type int
14156 *
14157@@ -253,14 +497,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
14158 #endif
14159
14160 /* These are x86-specific, used by some header files */
14161-#define atomic_clear_mask(mask, addr) \
14162- asm volatile(LOCK_PREFIX "andl %0,%1" \
14163- : : "r" (~(mask)), "m" (*(addr)) : "memory")
14164+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
14165+{
14166+ asm volatile(LOCK_PREFIX "andl %1,%0"
14167+ : "+m" (v->counter)
14168+ : "r" (~(mask))
14169+ : "memory");
14170+}
14171
14172-#define atomic_set_mask(mask, addr) \
14173- asm volatile(LOCK_PREFIX "orl %0,%1" \
14174- : : "r" ((unsigned)(mask)), "m" (*(addr)) \
14175- : "memory")
14176+static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
14177+{
14178+ asm volatile(LOCK_PREFIX "andl %1,%0"
14179+ : "+m" (v->counter)
14180+ : "r" (~(mask))
14181+ : "memory");
14182+}
14183+
14184+static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
14185+{
14186+ asm volatile(LOCK_PREFIX "orl %1,%0"
14187+ : "+m" (v->counter)
14188+ : "r" (mask)
14189+ : "memory");
14190+}
14191+
14192+static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
14193+{
14194+ asm volatile(LOCK_PREFIX "orl %1,%0"
14195+ : "+m" (v->counter)
14196+ : "r" (mask)
14197+ : "memory");
14198+}
14199
14200 /* Atomic operations are already serializing on x86 */
14201 #define smp_mb__before_atomic_dec() barrier()
14202diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
14203index b154de7..aadebd8 100644
14204--- a/arch/x86/include/asm/atomic64_32.h
14205+++ b/arch/x86/include/asm/atomic64_32.h
14206@@ -12,6 +12,14 @@ typedef struct {
14207 u64 __aligned(8) counter;
14208 } atomic64_t;
14209
14210+#ifdef CONFIG_PAX_REFCOUNT
14211+typedef struct {
14212+ u64 __aligned(8) counter;
14213+} atomic64_unchecked_t;
14214+#else
14215+typedef atomic64_t atomic64_unchecked_t;
14216+#endif
14217+
14218 #define ATOMIC64_INIT(val) { (val) }
14219
14220 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
14221@@ -37,21 +45,31 @@ typedef struct {
14222 ATOMIC64_DECL_ONE(sym##_386)
14223
14224 ATOMIC64_DECL_ONE(add_386);
14225+ATOMIC64_DECL_ONE(add_unchecked_386);
14226 ATOMIC64_DECL_ONE(sub_386);
14227+ATOMIC64_DECL_ONE(sub_unchecked_386);
14228 ATOMIC64_DECL_ONE(inc_386);
14229+ATOMIC64_DECL_ONE(inc_unchecked_386);
14230 ATOMIC64_DECL_ONE(dec_386);
14231+ATOMIC64_DECL_ONE(dec_unchecked_386);
14232 #endif
14233
14234 #define alternative_atomic64(f, out, in...) \
14235 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
14236
14237 ATOMIC64_DECL(read);
14238+ATOMIC64_DECL(read_unchecked);
14239 ATOMIC64_DECL(set);
14240+ATOMIC64_DECL(set_unchecked);
14241 ATOMIC64_DECL(xchg);
14242 ATOMIC64_DECL(add_return);
14243+ATOMIC64_DECL(add_return_unchecked);
14244 ATOMIC64_DECL(sub_return);
14245+ATOMIC64_DECL(sub_return_unchecked);
14246 ATOMIC64_DECL(inc_return);
14247+ATOMIC64_DECL(inc_return_unchecked);
14248 ATOMIC64_DECL(dec_return);
14249+ATOMIC64_DECL(dec_return_unchecked);
14250 ATOMIC64_DECL(dec_if_positive);
14251 ATOMIC64_DECL(inc_not_zero);
14252 ATOMIC64_DECL(add_unless);
14253@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
14254 }
14255
14256 /**
14257+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
14258+ * @p: pointer to type atomic64_unchecked_t
14259+ * @o: expected value
14260+ * @n: new value
14261+ *
14262+ * Atomically sets @v to @n if it was equal to @o and returns
14263+ * the old value.
14264+ */
14265+
14266+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
14267+{
14268+ return cmpxchg64(&v->counter, o, n);
14269+}
14270+
14271+/**
14272 * atomic64_xchg - xchg atomic64 variable
14273 * @v: pointer to type atomic64_t
14274 * @n: value to assign
14275@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
14276 }
14277
14278 /**
14279+ * atomic64_set_unchecked - set atomic64 variable
14280+ * @v: pointer to type atomic64_unchecked_t
14281+ * @n: value to assign
14282+ *
14283+ * Atomically sets the value of @v to @n.
14284+ */
14285+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
14286+{
14287+ unsigned high = (unsigned)(i >> 32);
14288+ unsigned low = (unsigned)i;
14289+ alternative_atomic64(set, /* no output */,
14290+ "S" (v), "b" (low), "c" (high)
14291+ : "eax", "edx", "memory");
14292+}
14293+
14294+/**
14295 * atomic64_read - read atomic64 variable
14296 * @v: pointer to type atomic64_t
14297 *
14298@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
14299 }
14300
14301 /**
14302+ * atomic64_read_unchecked - read atomic64 variable
14303+ * @v: pointer to type atomic64_unchecked_t
14304+ *
14305+ * Atomically reads the value of @v and returns it.
14306+ */
14307+static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
14308+{
14309+ long long r;
14310+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
14311+ return r;
14312+ }
14313+
14314+/**
14315 * atomic64_add_return - add and return
14316 * @i: integer value to add
14317 * @v: pointer to type atomic64_t
14318@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
14319 return i;
14320 }
14321
14322+/**
14323+ * atomic64_add_return_unchecked - add and return
14324+ * @i: integer value to add
14325+ * @v: pointer to type atomic64_unchecked_t
14326+ *
14327+ * Atomically adds @i to @v and returns @i + *@v
14328+ */
14329+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
14330+{
14331+ alternative_atomic64(add_return_unchecked,
14332+ ASM_OUTPUT2("+A" (i), "+c" (v)),
14333+ ASM_NO_INPUT_CLOBBER("memory"));
14334+ return i;
14335+}
14336+
14337 /*
14338 * Other variants with different arithmetic operators:
14339 */
14340@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
14341 return a;
14342 }
14343
14344+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
14345+{
14346+ long long a;
14347+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
14348+ "S" (v) : "memory", "ecx");
14349+ return a;
14350+}
14351+
14352 static inline long long atomic64_dec_return(atomic64_t *v)
14353 {
14354 long long a;
14355@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
14356 }
14357
14358 /**
14359+ * atomic64_add_unchecked - add integer to atomic64 variable
14360+ * @i: integer value to add
14361+ * @v: pointer to type atomic64_unchecked_t
14362+ *
14363+ * Atomically adds @i to @v.
14364+ */
14365+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
14366+{
14367+ __alternative_atomic64(add_unchecked, add_return_unchecked,
14368+ ASM_OUTPUT2("+A" (i), "+c" (v)),
14369+ ASM_NO_INPUT_CLOBBER("memory"));
14370+ return i;
14371+}
14372+
14373+/**
14374 * atomic64_sub - subtract the atomic64 variable
14375 * @i: integer value to subtract
14376 * @v: pointer to type atomic64_t
14377diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
14378index 0e1cbfc..5623683 100644
14379--- a/arch/x86/include/asm/atomic64_64.h
14380+++ b/arch/x86/include/asm/atomic64_64.h
14381@@ -18,7 +18,19 @@
14382 */
14383 static inline long atomic64_read(const atomic64_t *v)
14384 {
14385- return (*(volatile long *)&(v)->counter);
14386+ return (*(volatile const long *)&(v)->counter);
14387+}
14388+
14389+/**
14390+ * atomic64_read_unchecked - read atomic64 variable
14391+ * @v: pointer of type atomic64_unchecked_t
14392+ *
14393+ * Atomically reads the value of @v.
14394+ * Doesn't imply a read memory barrier.
14395+ */
14396+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
14397+{
14398+ return (*(volatile const long *)&(v)->counter);
14399 }
14400
14401 /**
14402@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
14403 }
14404
14405 /**
14406+ * atomic64_set_unchecked - set atomic64 variable
14407+ * @v: pointer to type atomic64_unchecked_t
14408+ * @i: required value
14409+ *
14410+ * Atomically sets the value of @v to @i.
14411+ */
14412+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
14413+{
14414+ v->counter = i;
14415+}
14416+
14417+/**
14418 * atomic64_add - add integer to atomic64 variable
14419 * @i: integer value to add
14420 * @v: pointer to type atomic64_t
14421@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
14422 */
14423 static inline void atomic64_add(long i, atomic64_t *v)
14424 {
14425+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
14426+
14427+#ifdef CONFIG_PAX_REFCOUNT
14428+ "jno 0f\n"
14429+ LOCK_PREFIX "subq %1,%0\n"
14430+ "int $4\n0:\n"
14431+ _ASM_EXTABLE(0b, 0b)
14432+#endif
14433+
14434+ : "=m" (v->counter)
14435+ : "er" (i), "m" (v->counter));
14436+}
14437+
14438+/**
14439+ * atomic64_add_unchecked - add integer to atomic64 variable
14440+ * @i: integer value to add
14441+ * @v: pointer to type atomic64_unchecked_t
14442+ *
14443+ * Atomically adds @i to @v.
14444+ */
14445+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
14446+{
14447 asm volatile(LOCK_PREFIX "addq %1,%0"
14448 : "=m" (v->counter)
14449 : "er" (i), "m" (v->counter));
14450@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
14451 */
14452 static inline void atomic64_sub(long i, atomic64_t *v)
14453 {
14454- asm volatile(LOCK_PREFIX "subq %1,%0"
14455+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
14456+
14457+#ifdef CONFIG_PAX_REFCOUNT
14458+ "jno 0f\n"
14459+ LOCK_PREFIX "addq %1,%0\n"
14460+ "int $4\n0:\n"
14461+ _ASM_EXTABLE(0b, 0b)
14462+#endif
14463+
14464+ : "=m" (v->counter)
14465+ : "er" (i), "m" (v->counter));
14466+}
14467+
14468+/**
14469+ * atomic64_sub_unchecked - subtract the atomic64 variable
14470+ * @i: integer value to subtract
14471+ * @v: pointer to type atomic64_unchecked_t
14472+ *
14473+ * Atomically subtracts @i from @v.
14474+ */
14475+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
14476+{
14477+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
14478 : "=m" (v->counter)
14479 : "er" (i), "m" (v->counter));
14480 }
14481@@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
14482 {
14483 unsigned char c;
14484
14485- asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
14486+ asm volatile(LOCK_PREFIX "subq %2,%0\n"
14487+
14488+#ifdef CONFIG_PAX_REFCOUNT
14489+ "jno 0f\n"
14490+ LOCK_PREFIX "addq %2,%0\n"
14491+ "int $4\n0:\n"
14492+ _ASM_EXTABLE(0b, 0b)
14493+#endif
14494+
14495+ "sete %1\n"
14496 : "=m" (v->counter), "=qm" (c)
14497 : "er" (i), "m" (v->counter) : "memory");
14498 return c;
14499@@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
14500 */
14501 static inline void atomic64_inc(atomic64_t *v)
14502 {
14503+ asm volatile(LOCK_PREFIX "incq %0\n"
14504+
14505+#ifdef CONFIG_PAX_REFCOUNT
14506+ "jno 0f\n"
14507+ LOCK_PREFIX "decq %0\n"
14508+ "int $4\n0:\n"
14509+ _ASM_EXTABLE(0b, 0b)
14510+#endif
14511+
14512+ : "=m" (v->counter)
14513+ : "m" (v->counter));
14514+}
14515+
14516+/**
14517+ * atomic64_inc_unchecked - increment atomic64 variable
14518+ * @v: pointer to type atomic64_unchecked_t
14519+ *
14520+ * Atomically increments @v by 1.
14521+ */
14522+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
14523+{
14524 asm volatile(LOCK_PREFIX "incq %0"
14525 : "=m" (v->counter)
14526 : "m" (v->counter));
14527@@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
14528 */
14529 static inline void atomic64_dec(atomic64_t *v)
14530 {
14531- asm volatile(LOCK_PREFIX "decq %0"
14532+ asm volatile(LOCK_PREFIX "decq %0\n"
14533+
14534+#ifdef CONFIG_PAX_REFCOUNT
14535+ "jno 0f\n"
14536+ LOCK_PREFIX "incq %0\n"
14537+ "int $4\n0:\n"
14538+ _ASM_EXTABLE(0b, 0b)
14539+#endif
14540+
14541+ : "=m" (v->counter)
14542+ : "m" (v->counter));
14543+}
14544+
14545+/**
14546+ * atomic64_dec_unchecked - decrement atomic64 variable
14547+ * @v: pointer to type atomic64_t
14548+ *
14549+ * Atomically decrements @v by 1.
14550+ */
14551+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
14552+{
14553+ asm volatile(LOCK_PREFIX "decq %0\n"
14554 : "=m" (v->counter)
14555 : "m" (v->counter));
14556 }
14557@@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
14558 {
14559 unsigned char c;
14560
14561- asm volatile(LOCK_PREFIX "decq %0; sete %1"
14562+ asm volatile(LOCK_PREFIX "decq %0\n"
14563+
14564+#ifdef CONFIG_PAX_REFCOUNT
14565+ "jno 0f\n"
14566+ LOCK_PREFIX "incq %0\n"
14567+ "int $4\n0:\n"
14568+ _ASM_EXTABLE(0b, 0b)
14569+#endif
14570+
14571+ "sete %1\n"
14572 : "=m" (v->counter), "=qm" (c)
14573 : "m" (v->counter) : "memory");
14574 return c != 0;
14575@@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
14576 {
14577 unsigned char c;
14578
14579- asm volatile(LOCK_PREFIX "incq %0; sete %1"
14580+ asm volatile(LOCK_PREFIX "incq %0\n"
14581+
14582+#ifdef CONFIG_PAX_REFCOUNT
14583+ "jno 0f\n"
14584+ LOCK_PREFIX "decq %0\n"
14585+ "int $4\n0:\n"
14586+ _ASM_EXTABLE(0b, 0b)
14587+#endif
14588+
14589+ "sete %1\n"
14590 : "=m" (v->counter), "=qm" (c)
14591 : "m" (v->counter) : "memory");
14592 return c != 0;
14593@@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
14594 {
14595 unsigned char c;
14596
14597- asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
14598+ asm volatile(LOCK_PREFIX "addq %2,%0\n"
14599+
14600+#ifdef CONFIG_PAX_REFCOUNT
14601+ "jno 0f\n"
14602+ LOCK_PREFIX "subq %2,%0\n"
14603+ "int $4\n0:\n"
14604+ _ASM_EXTABLE(0b, 0b)
14605+#endif
14606+
14607+ "sets %1\n"
14608 : "=m" (v->counter), "=qm" (c)
14609 : "er" (i), "m" (v->counter) : "memory");
14610 return c;
14611@@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
14612 */
14613 static inline long atomic64_add_return(long i, atomic64_t *v)
14614 {
14615+ return i + xadd_check_overflow(&v->counter, i);
14616+}
14617+
14618+/**
14619+ * atomic64_add_return_unchecked - add and return
14620+ * @i: integer value to add
14621+ * @v: pointer to type atomic64_unchecked_t
14622+ *
14623+ * Atomically adds @i to @v and returns @i + @v
14624+ */
14625+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
14626+{
14627 return i + xadd(&v->counter, i);
14628 }
14629
14630@@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
14631 }
14632
14633 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
14634+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
14635+{
14636+ return atomic64_add_return_unchecked(1, v);
14637+}
14638 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
14639
14640 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
14641@@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
14642 return cmpxchg(&v->counter, old, new);
14643 }
14644
14645+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
14646+{
14647+ return cmpxchg(&v->counter, old, new);
14648+}
14649+
14650 static inline long atomic64_xchg(atomic64_t *v, long new)
14651 {
14652 return xchg(&v->counter, new);
14653@@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
14654 */
14655 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
14656 {
14657- long c, old;
14658+ long c, old, new;
14659 c = atomic64_read(v);
14660 for (;;) {
14661- if (unlikely(c == (u)))
14662+ if (unlikely(c == u))
14663 break;
14664- old = atomic64_cmpxchg((v), c, c + (a));
14665+
14666+ asm volatile("add %2,%0\n"
14667+
14668+#ifdef CONFIG_PAX_REFCOUNT
14669+ "jno 0f\n"
14670+ "sub %2,%0\n"
14671+ "int $4\n0:\n"
14672+ _ASM_EXTABLE(0b, 0b)
14673+#endif
14674+
14675+ : "=r" (new)
14676+ : "0" (c), "ir" (a));
14677+
14678+ old = atomic64_cmpxchg(v, c, new);
14679 if (likely(old == c))
14680 break;
14681 c = old;
14682 }
14683- return c != (u);
14684+ return c != u;
14685 }
14686
14687 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
14688diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
14689index 6dfd019..28e188d 100644
14690--- a/arch/x86/include/asm/bitops.h
14691+++ b/arch/x86/include/asm/bitops.h
14692@@ -40,7 +40,7 @@
14693 * a mask operation on a byte.
14694 */
14695 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
14696-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
14697+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
14698 #define CONST_MASK(nr) (1 << ((nr) & 7))
14699
14700 /**
14701@@ -486,7 +486,7 @@ static inline int fls(int x)
14702 * at position 64.
14703 */
14704 #ifdef CONFIG_X86_64
14705-static __always_inline int fls64(__u64 x)
14706+static __always_inline long fls64(__u64 x)
14707 {
14708 int bitpos = -1;
14709 /*
14710diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
14711index 4fa687a..60f2d39 100644
14712--- a/arch/x86/include/asm/boot.h
14713+++ b/arch/x86/include/asm/boot.h
14714@@ -6,10 +6,15 @@
14715 #include <uapi/asm/boot.h>
14716
14717 /* Physical address where kernel should be loaded. */
14718-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
14719+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
14720 + (CONFIG_PHYSICAL_ALIGN - 1)) \
14721 & ~(CONFIG_PHYSICAL_ALIGN - 1))
14722
14723+#ifndef __ASSEMBLY__
14724+extern unsigned char __LOAD_PHYSICAL_ADDR[];
14725+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
14726+#endif
14727+
14728 /* Minimum kernel alignment, as a power of two */
14729 #ifdef CONFIG_X86_64
14730 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
14731diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
14732index 48f99f1..d78ebf9 100644
14733--- a/arch/x86/include/asm/cache.h
14734+++ b/arch/x86/include/asm/cache.h
14735@@ -5,12 +5,13 @@
14736
14737 /* L1 cache line size */
14738 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
14739-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
14740+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
14741
14742 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
14743+#define __read_only __attribute__((__section__(".data..read_only")))
14744
14745 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
14746-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
14747+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
14748
14749 #ifdef CONFIG_X86_VSMP
14750 #ifdef CONFIG_SMP
14751diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
14752index 9863ee3..4a1f8e1 100644
14753--- a/arch/x86/include/asm/cacheflush.h
14754+++ b/arch/x86/include/asm/cacheflush.h
14755@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
14756 unsigned long pg_flags = pg->flags & _PGMT_MASK;
14757
14758 if (pg_flags == _PGMT_DEFAULT)
14759- return -1;
14760+ return ~0UL;
14761 else if (pg_flags == _PGMT_WC)
14762 return _PAGE_CACHE_WC;
14763 else if (pg_flags == _PGMT_UC_MINUS)
14764diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
14765index f50de69..2b0a458 100644
14766--- a/arch/x86/include/asm/checksum_32.h
14767+++ b/arch/x86/include/asm/checksum_32.h
14768@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
14769 int len, __wsum sum,
14770 int *src_err_ptr, int *dst_err_ptr);
14771
14772+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
14773+ int len, __wsum sum,
14774+ int *src_err_ptr, int *dst_err_ptr);
14775+
14776+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
14777+ int len, __wsum sum,
14778+ int *src_err_ptr, int *dst_err_ptr);
14779+
14780 /*
14781 * Note: when you get a NULL pointer exception here this means someone
14782 * passed in an incorrect kernel address to one of these functions.
14783@@ -53,7 +61,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
14784
14785 might_sleep();
14786 stac();
14787- ret = csum_partial_copy_generic((__force void *)src, dst,
14788+ ret = csum_partial_copy_generic_from_user((__force void *)src, dst,
14789 len, sum, err_ptr, NULL);
14790 clac();
14791
14792@@ -187,7 +195,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
14793 might_sleep();
14794 if (access_ok(VERIFY_WRITE, dst, len)) {
14795 stac();
14796- ret = csum_partial_copy_generic(src, (__force void *)dst,
14797+ ret = csum_partial_copy_generic_to_user(src, (__force void *)dst,
14798 len, sum, NULL, err_ptr);
14799 clac();
14800 return ret;
14801diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
14802index d47786a..ce1b05d 100644
14803--- a/arch/x86/include/asm/cmpxchg.h
14804+++ b/arch/x86/include/asm/cmpxchg.h
14805@@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
14806 __compiletime_error("Bad argument size for cmpxchg");
14807 extern void __xadd_wrong_size(void)
14808 __compiletime_error("Bad argument size for xadd");
14809+extern void __xadd_check_overflow_wrong_size(void)
14810+ __compiletime_error("Bad argument size for xadd_check_overflow");
14811 extern void __add_wrong_size(void)
14812 __compiletime_error("Bad argument size for add");
14813+extern void __add_check_overflow_wrong_size(void)
14814+ __compiletime_error("Bad argument size for add_check_overflow");
14815
14816 /*
14817 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
14818@@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
14819 __ret; \
14820 })
14821
14822+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
14823+ ({ \
14824+ __typeof__ (*(ptr)) __ret = (arg); \
14825+ switch (sizeof(*(ptr))) { \
14826+ case __X86_CASE_L: \
14827+ asm volatile (lock #op "l %0, %1\n" \
14828+ "jno 0f\n" \
14829+ "mov %0,%1\n" \
14830+ "int $4\n0:\n" \
14831+ _ASM_EXTABLE(0b, 0b) \
14832+ : "+r" (__ret), "+m" (*(ptr)) \
14833+ : : "memory", "cc"); \
14834+ break; \
14835+ case __X86_CASE_Q: \
14836+ asm volatile (lock #op "q %q0, %1\n" \
14837+ "jno 0f\n" \
14838+ "mov %0,%1\n" \
14839+ "int $4\n0:\n" \
14840+ _ASM_EXTABLE(0b, 0b) \
14841+ : "+r" (__ret), "+m" (*(ptr)) \
14842+ : : "memory", "cc"); \
14843+ break; \
14844+ default: \
14845+ __ ## op ## _check_overflow_wrong_size(); \
14846+ } \
14847+ __ret; \
14848+ })
14849+
14850 /*
14851 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
14852 * Since this is generally used to protect other memory information, we
14853@@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
14854 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
14855 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
14856
14857+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
14858+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
14859+
14860 #define __add(ptr, inc, lock) \
14861 ({ \
14862 __typeof__ (*(ptr)) __ret = (inc); \
14863diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
14864index 59c6c40..5e0b22c 100644
14865--- a/arch/x86/include/asm/compat.h
14866+++ b/arch/x86/include/asm/compat.h
14867@@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
14868 typedef u32 compat_uint_t;
14869 typedef u32 compat_ulong_t;
14870 typedef u64 __attribute__((aligned(4))) compat_u64;
14871-typedef u32 compat_uptr_t;
14872+typedef u32 __user compat_uptr_t;
14873
14874 struct compat_timespec {
14875 compat_time_t tv_sec;
14876diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
14877index 47538a6..44902d1 100644
14878--- a/arch/x86/include/asm/cpufeature.h
14879+++ b/arch/x86/include/asm/cpufeature.h
14880@@ -203,7 +203,7 @@
14881 #define X86_FEATURE_DECODEASSISTS (8*32+12) /* AMD Decode Assists support */
14882 #define X86_FEATURE_PAUSEFILTER (8*32+13) /* AMD filtered pause intercept */
14883 #define X86_FEATURE_PFTHRESHOLD (8*32+14) /* AMD pause filter threshold */
14884-
14885+#define X86_FEATURE_STRONGUDEREF (8*32+31) /* PaX PCID based strong UDEREF */
14886
14887 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */
14888 #define X86_FEATURE_FSGSBASE (9*32+ 0) /* {RD/WR}{FS/GS}BASE instructions*/
14889@@ -211,7 +211,7 @@
14890 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
14891 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
14892 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
14893-#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
14894+#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
14895 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
14896 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
14897 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
14898@@ -353,6 +353,7 @@ extern const char * const x86_power_flags[32];
14899 #undef cpu_has_centaur_mcr
14900 #define cpu_has_centaur_mcr 0
14901
14902+#define cpu_has_pcid boot_cpu_has(X86_FEATURE_PCID)
14903 #endif /* CONFIG_X86_64 */
14904
14905 #if __GNUC__ >= 4
14906@@ -403,7 +404,8 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
14907
14908 #ifdef CONFIG_X86_DEBUG_STATIC_CPU_HAS
14909 t_warn:
14910- warn_pre_alternatives();
14911+ if (bit != X86_FEATURE_PCID && bit != X86_FEATURE_INVPCID)
14912+ warn_pre_alternatives();
14913 return false;
14914 #endif
14915 #else /* GCC_VERSION >= 40500 */
14916@@ -421,7 +423,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
14917 ".section .discard,\"aw\",@progbits\n"
14918 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
14919 ".previous\n"
14920- ".section .altinstr_replacement,\"ax\"\n"
14921+ ".section .altinstr_replacement,\"a\"\n"
14922 "3: movb $1,%0\n"
14923 "4:\n"
14924 ".previous\n"
14925@@ -457,7 +459,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
14926 " .byte 2b - 1b\n" /* src len */
14927 " .byte 4f - 3f\n" /* repl len */
14928 ".previous\n"
14929- ".section .altinstr_replacement,\"ax\"\n"
14930+ ".section .altinstr_replacement,\"a\"\n"
14931 "3: .byte 0xe9\n .long %l[t_no] - 2b\n"
14932 "4:\n"
14933 ".previous\n"
14934@@ -490,7 +492,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
14935 ".section .discard,\"aw\",@progbits\n"
14936 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
14937 ".previous\n"
14938- ".section .altinstr_replacement,\"ax\"\n"
14939+ ".section .altinstr_replacement,\"a\"\n"
14940 "3: movb $0,%0\n"
14941 "4:\n"
14942 ".previous\n"
14943@@ -504,7 +506,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
14944 ".section .discard,\"aw\",@progbits\n"
14945 " .byte 0xff + (6f-5f) - (4b-3b)\n" /* size check */
14946 ".previous\n"
14947- ".section .altinstr_replacement,\"ax\"\n"
14948+ ".section .altinstr_replacement,\"a\"\n"
14949 "5: movb $1,%0\n"
14950 "6:\n"
14951 ".previous\n"
14952diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
14953index b90e5df..b462c91 100644
14954--- a/arch/x86/include/asm/desc.h
14955+++ b/arch/x86/include/asm/desc.h
14956@@ -4,6 +4,7 @@
14957 #include <asm/desc_defs.h>
14958 #include <asm/ldt.h>
14959 #include <asm/mmu.h>
14960+#include <asm/pgtable.h>
14961
14962 #include <linux/smp.h>
14963 #include <linux/percpu.h>
14964@@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
14965
14966 desc->type = (info->read_exec_only ^ 1) << 1;
14967 desc->type |= info->contents << 2;
14968+ desc->type |= info->seg_not_present ^ 1;
14969
14970 desc->s = 1;
14971 desc->dpl = 0x3;
14972@@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
14973 }
14974
14975 extern struct desc_ptr idt_descr;
14976-extern gate_desc idt_table[];
14977-extern struct desc_ptr debug_idt_descr;
14978-extern gate_desc debug_idt_table[];
14979-
14980-struct gdt_page {
14981- struct desc_struct gdt[GDT_ENTRIES];
14982-} __attribute__((aligned(PAGE_SIZE)));
14983-
14984-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
14985+extern gate_desc idt_table[IDT_ENTRIES];
14986+extern const struct desc_ptr debug_idt_descr;
14987+extern gate_desc debug_idt_table[IDT_ENTRIES];
14988
14989+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
14990 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
14991 {
14992- return per_cpu(gdt_page, cpu).gdt;
14993+ return cpu_gdt_table[cpu];
14994 }
14995
14996 #ifdef CONFIG_X86_64
14997@@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
14998 unsigned long base, unsigned dpl, unsigned flags,
14999 unsigned short seg)
15000 {
15001- gate->a = (seg << 16) | (base & 0xffff);
15002- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
15003+ gate->gate.offset_low = base;
15004+ gate->gate.seg = seg;
15005+ gate->gate.reserved = 0;
15006+ gate->gate.type = type;
15007+ gate->gate.s = 0;
15008+ gate->gate.dpl = dpl;
15009+ gate->gate.p = 1;
15010+ gate->gate.offset_high = base >> 16;
15011 }
15012
15013 #endif
15014@@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
15015
15016 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
15017 {
15018+ pax_open_kernel();
15019 memcpy(&idt[entry], gate, sizeof(*gate));
15020+ pax_close_kernel();
15021 }
15022
15023 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
15024 {
15025+ pax_open_kernel();
15026 memcpy(&ldt[entry], desc, 8);
15027+ pax_close_kernel();
15028 }
15029
15030 static inline void
15031@@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
15032 default: size = sizeof(*gdt); break;
15033 }
15034
15035+ pax_open_kernel();
15036 memcpy(&gdt[entry], desc, size);
15037+ pax_close_kernel();
15038 }
15039
15040 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
15041@@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
15042
15043 static inline void native_load_tr_desc(void)
15044 {
15045+ pax_open_kernel();
15046 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
15047+ pax_close_kernel();
15048 }
15049
15050 static inline void native_load_gdt(const struct desc_ptr *dtr)
15051@@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
15052 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
15053 unsigned int i;
15054
15055+ pax_open_kernel();
15056 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
15057 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
15058+ pax_close_kernel();
15059 }
15060
15061 #define _LDT_empty(info) \
15062@@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
15063 preempt_enable();
15064 }
15065
15066-static inline unsigned long get_desc_base(const struct desc_struct *desc)
15067+static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
15068 {
15069 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
15070 }
15071@@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
15072 }
15073
15074 #ifdef CONFIG_X86_64
15075-static inline void set_nmi_gate(int gate, void *addr)
15076+static inline void set_nmi_gate(int gate, const void *addr)
15077 {
15078 gate_desc s;
15079
15080@@ -321,8 +334,8 @@ static inline void set_nmi_gate(int gate, void *addr)
15081 #endif
15082
15083 #ifdef CONFIG_TRACING
15084-extern struct desc_ptr trace_idt_descr;
15085-extern gate_desc trace_idt_table[];
15086+extern const struct desc_ptr trace_idt_descr;
15087+extern gate_desc trace_idt_table[IDT_ENTRIES];
15088 static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
15089 {
15090 write_idt_entry(trace_idt_table, entry, gate);
15091@@ -333,7 +346,7 @@ static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
15092 }
15093 #endif
15094
15095-static inline void _set_gate(int gate, unsigned type, void *addr,
15096+static inline void _set_gate(int gate, unsigned type, const void *addr,
15097 unsigned dpl, unsigned ist, unsigned seg)
15098 {
15099 gate_desc s;
15100@@ -353,7 +366,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
15101 * Pentium F0 0F bugfix can have resulted in the mapped
15102 * IDT being write-protected.
15103 */
15104-static inline void set_intr_gate(unsigned int n, void *addr)
15105+static inline void set_intr_gate(unsigned int n, const void *addr)
15106 {
15107 BUG_ON((unsigned)n > 0xFF);
15108 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
15109@@ -410,19 +423,19 @@ static inline void __alloc_intr_gate(unsigned int n, void *addr)
15110 /*
15111 * This routine sets up an interrupt gate at directory privilege level 3.
15112 */
15113-static inline void set_system_intr_gate(unsigned int n, void *addr)
15114+static inline void set_system_intr_gate(unsigned int n, const void *addr)
15115 {
15116 BUG_ON((unsigned)n > 0xFF);
15117 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
15118 }
15119
15120-static inline void set_system_trap_gate(unsigned int n, void *addr)
15121+static inline void set_system_trap_gate(unsigned int n, const void *addr)
15122 {
15123 BUG_ON((unsigned)n > 0xFF);
15124 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
15125 }
15126
15127-static inline void set_trap_gate(unsigned int n, void *addr)
15128+static inline void set_trap_gate(unsigned int n, const void *addr)
15129 {
15130 BUG_ON((unsigned)n > 0xFF);
15131 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
15132@@ -431,16 +444,16 @@ static inline void set_trap_gate(unsigned int n, void *addr)
15133 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
15134 {
15135 BUG_ON((unsigned)n > 0xFF);
15136- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
15137+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
15138 }
15139
15140-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
15141+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
15142 {
15143 BUG_ON((unsigned)n > 0xFF);
15144 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
15145 }
15146
15147-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
15148+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
15149 {
15150 BUG_ON((unsigned)n > 0xFF);
15151 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
15152@@ -512,4 +525,17 @@ static inline void load_current_idt(void)
15153 else
15154 load_idt((const struct desc_ptr *)&idt_descr);
15155 }
15156+
15157+#ifdef CONFIG_X86_32
15158+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
15159+{
15160+ struct desc_struct d;
15161+
15162+ if (likely(limit))
15163+ limit = (limit - 1UL) >> PAGE_SHIFT;
15164+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
15165+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
15166+}
15167+#endif
15168+
15169 #endif /* _ASM_X86_DESC_H */
15170diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
15171index 278441f..b95a174 100644
15172--- a/arch/x86/include/asm/desc_defs.h
15173+++ b/arch/x86/include/asm/desc_defs.h
15174@@ -31,6 +31,12 @@ struct desc_struct {
15175 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
15176 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
15177 };
15178+ struct {
15179+ u16 offset_low;
15180+ u16 seg;
15181+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
15182+ unsigned offset_high: 16;
15183+ } gate;
15184 };
15185 } __attribute__((packed));
15186
15187diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
15188index ced283a..ffe04cc 100644
15189--- a/arch/x86/include/asm/div64.h
15190+++ b/arch/x86/include/asm/div64.h
15191@@ -39,7 +39,7 @@
15192 __mod; \
15193 })
15194
15195-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
15196+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
15197 {
15198 union {
15199 u64 v64;
15200diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
15201index 9c999c1..3860cb8 100644
15202--- a/arch/x86/include/asm/elf.h
15203+++ b/arch/x86/include/asm/elf.h
15204@@ -243,7 +243,25 @@ extern int force_personality32;
15205 the loader. We need to make sure that it is out of the way of the program
15206 that it will "exec", and that there is sufficient room for the brk. */
15207
15208+#ifdef CONFIG_PAX_SEGMEXEC
15209+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
15210+#else
15211 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
15212+#endif
15213+
15214+#ifdef CONFIG_PAX_ASLR
15215+#ifdef CONFIG_X86_32
15216+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
15217+
15218+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
15219+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
15220+#else
15221+#define PAX_ELF_ET_DYN_BASE 0x400000UL
15222+
15223+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
15224+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
15225+#endif
15226+#endif
15227
15228 /* This yields a mask that user programs can use to figure out what
15229 instruction set this CPU supports. This could be done in user space,
15230@@ -296,16 +314,12 @@ do { \
15231
15232 #define ARCH_DLINFO \
15233 do { \
15234- if (vdso_enabled) \
15235- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
15236- (unsigned long)current->mm->context.vdso); \
15237+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
15238 } while (0)
15239
15240 #define ARCH_DLINFO_X32 \
15241 do { \
15242- if (vdso_enabled) \
15243- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
15244- (unsigned long)current->mm->context.vdso); \
15245+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
15246 } while (0)
15247
15248 #define AT_SYSINFO 32
15249@@ -320,7 +334,7 @@ else \
15250
15251 #endif /* !CONFIG_X86_32 */
15252
15253-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
15254+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
15255
15256 #define VDSO_ENTRY \
15257 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
15258@@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
15259 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
15260 #define compat_arch_setup_additional_pages syscall32_setup_pages
15261
15262-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
15263-#define arch_randomize_brk arch_randomize_brk
15264-
15265 /*
15266 * True on X86_32 or when emulating IA32 on X86_64
15267 */
15268diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
15269index 77a99ac..39ff7f5 100644
15270--- a/arch/x86/include/asm/emergency-restart.h
15271+++ b/arch/x86/include/asm/emergency-restart.h
15272@@ -1,6 +1,6 @@
15273 #ifndef _ASM_X86_EMERGENCY_RESTART_H
15274 #define _ASM_X86_EMERGENCY_RESTART_H
15275
15276-extern void machine_emergency_restart(void);
15277+extern void machine_emergency_restart(void) __noreturn;
15278
15279 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
15280diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
15281index 4d0bda7..221da4d 100644
15282--- a/arch/x86/include/asm/fpu-internal.h
15283+++ b/arch/x86/include/asm/fpu-internal.h
15284@@ -124,8 +124,11 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
15285 #define user_insn(insn, output, input...) \
15286 ({ \
15287 int err; \
15288+ pax_open_userland(); \
15289 asm volatile(ASM_STAC "\n" \
15290- "1:" #insn "\n\t" \
15291+ "1:" \
15292+ __copyuser_seg \
15293+ #insn "\n\t" \
15294 "2: " ASM_CLAC "\n" \
15295 ".section .fixup,\"ax\"\n" \
15296 "3: movl $-1,%[err]\n" \
15297@@ -134,6 +137,7 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
15298 _ASM_EXTABLE(1b, 3b) \
15299 : [err] "=r" (err), output \
15300 : "0"(0), input); \
15301+ pax_close_userland(); \
15302 err; \
15303 })
15304
15305@@ -298,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
15306 "emms\n\t" /* clear stack tags */
15307 "fildl %P[addr]", /* set F?P to defined value */
15308 X86_FEATURE_FXSAVE_LEAK,
15309- [addr] "m" (tsk->thread.fpu.has_fpu));
15310+ [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
15311
15312 return fpu_restore_checking(&tsk->thread.fpu);
15313 }
15314diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
15315index be27ba1..04a8801 100644
15316--- a/arch/x86/include/asm/futex.h
15317+++ b/arch/x86/include/asm/futex.h
15318@@ -12,6 +12,7 @@
15319 #include <asm/smap.h>
15320
15321 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
15322+ typecheck(u32 __user *, uaddr); \
15323 asm volatile("\t" ASM_STAC "\n" \
15324 "1:\t" insn "\n" \
15325 "2:\t" ASM_CLAC "\n" \
15326@@ -20,15 +21,16 @@
15327 "\tjmp\t2b\n" \
15328 "\t.previous\n" \
15329 _ASM_EXTABLE(1b, 3b) \
15330- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
15331+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
15332 : "i" (-EFAULT), "0" (oparg), "1" (0))
15333
15334 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
15335+ typecheck(u32 __user *, uaddr); \
15336 asm volatile("\t" ASM_STAC "\n" \
15337 "1:\tmovl %2, %0\n" \
15338 "\tmovl\t%0, %3\n" \
15339 "\t" insn "\n" \
15340- "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
15341+ "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
15342 "\tjnz\t1b\n" \
15343 "3:\t" ASM_CLAC "\n" \
15344 "\t.section .fixup,\"ax\"\n" \
15345@@ -38,7 +40,7 @@
15346 _ASM_EXTABLE(1b, 4b) \
15347 _ASM_EXTABLE(2b, 4b) \
15348 : "=&a" (oldval), "=&r" (ret), \
15349- "+m" (*uaddr), "=&r" (tem) \
15350+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
15351 : "r" (oparg), "i" (-EFAULT), "1" (0))
15352
15353 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
15354@@ -57,12 +59,13 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
15355
15356 pagefault_disable();
15357
15358+ pax_open_userland();
15359 switch (op) {
15360 case FUTEX_OP_SET:
15361- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
15362+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
15363 break;
15364 case FUTEX_OP_ADD:
15365- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
15366+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
15367 uaddr, oparg);
15368 break;
15369 case FUTEX_OP_OR:
15370@@ -77,6 +80,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
15371 default:
15372 ret = -ENOSYS;
15373 }
15374+ pax_close_userland();
15375
15376 pagefault_enable();
15377
15378@@ -115,18 +119,20 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
15379 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
15380 return -EFAULT;
15381
15382+ pax_open_userland();
15383 asm volatile("\t" ASM_STAC "\n"
15384- "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
15385+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
15386 "2:\t" ASM_CLAC "\n"
15387 "\t.section .fixup, \"ax\"\n"
15388 "3:\tmov %3, %0\n"
15389 "\tjmp 2b\n"
15390 "\t.previous\n"
15391 _ASM_EXTABLE(1b, 3b)
15392- : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
15393+ : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
15394 : "i" (-EFAULT), "r" (newval), "1" (oldval)
15395 : "memory"
15396 );
15397+ pax_close_userland();
15398
15399 *uval = oldval;
15400 return ret;
15401diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
15402index e4ac559..c1c0c87 100644
15403--- a/arch/x86/include/asm/hw_irq.h
15404+++ b/arch/x86/include/asm/hw_irq.h
15405@@ -165,8 +165,8 @@ extern void setup_ioapic_dest(void);
15406 extern void enable_IO_APIC(void);
15407
15408 /* Statistics */
15409-extern atomic_t irq_err_count;
15410-extern atomic_t irq_mis_count;
15411+extern atomic_unchecked_t irq_err_count;
15412+extern atomic_unchecked_t irq_mis_count;
15413
15414 /* EISA */
15415 extern void eisa_set_level_irq(unsigned int irq);
15416diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
15417index a203659..9889f1c 100644
15418--- a/arch/x86/include/asm/i8259.h
15419+++ b/arch/x86/include/asm/i8259.h
15420@@ -62,7 +62,7 @@ struct legacy_pic {
15421 void (*init)(int auto_eoi);
15422 int (*irq_pending)(unsigned int irq);
15423 void (*make_irq)(unsigned int irq);
15424-};
15425+} __do_const;
15426
15427 extern struct legacy_pic *legacy_pic;
15428 extern struct legacy_pic null_legacy_pic;
15429diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
15430index 34f69cb..6d95446 100644
15431--- a/arch/x86/include/asm/io.h
15432+++ b/arch/x86/include/asm/io.h
15433@@ -51,12 +51,12 @@ static inline void name(type val, volatile void __iomem *addr) \
15434 "m" (*(volatile type __force *)addr) barrier); }
15435
15436 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
15437-build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
15438-build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
15439+build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
15440+build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
15441
15442 build_mmio_read(__readb, "b", unsigned char, "=q", )
15443-build_mmio_read(__readw, "w", unsigned short, "=r", )
15444-build_mmio_read(__readl, "l", unsigned int, "=r", )
15445+build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
15446+build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
15447
15448 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
15449 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
15450@@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
15451 return ioremap_nocache(offset, size);
15452 }
15453
15454-extern void iounmap(volatile void __iomem *addr);
15455+extern void iounmap(const volatile void __iomem *addr);
15456
15457 extern void set_iounmap_nonlazy(void);
15458
15459@@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
15460
15461 #include <linux/vmalloc.h>
15462
15463+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
15464+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
15465+{
15466+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
15467+}
15468+
15469+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
15470+{
15471+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
15472+}
15473+
15474 /*
15475 * Convert a virtual cached pointer to an uncached pointer
15476 */
15477diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
15478index bba3cf8..06bc8da 100644
15479--- a/arch/x86/include/asm/irqflags.h
15480+++ b/arch/x86/include/asm/irqflags.h
15481@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
15482 sti; \
15483 sysexit
15484
15485+#define GET_CR0_INTO_RDI mov %cr0, %rdi
15486+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
15487+#define GET_CR3_INTO_RDI mov %cr3, %rdi
15488+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
15489+
15490 #else
15491 #define INTERRUPT_RETURN iret
15492 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
15493diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
15494index 5a6d287..f815789 100644
15495--- a/arch/x86/include/asm/kprobes.h
15496+++ b/arch/x86/include/asm/kprobes.h
15497@@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
15498 #define RELATIVEJUMP_SIZE 5
15499 #define RELATIVECALL_OPCODE 0xe8
15500 #define RELATIVE_ADDR_SIZE 4
15501-#define MAX_STACK_SIZE 64
15502-#define MIN_STACK_SIZE(ADDR) \
15503- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
15504- THREAD_SIZE - (unsigned long)(ADDR))) \
15505- ? (MAX_STACK_SIZE) \
15506- : (((unsigned long)current_thread_info()) + \
15507- THREAD_SIZE - (unsigned long)(ADDR)))
15508+#define MAX_STACK_SIZE 64UL
15509+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
15510
15511 #define flush_insn_slot(p) do { } while (0)
15512
15513diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
15514index 2d89e39..baee879 100644
15515--- a/arch/x86/include/asm/local.h
15516+++ b/arch/x86/include/asm/local.h
15517@@ -10,33 +10,97 @@ typedef struct {
15518 atomic_long_t a;
15519 } local_t;
15520
15521+typedef struct {
15522+ atomic_long_unchecked_t a;
15523+} local_unchecked_t;
15524+
15525 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
15526
15527 #define local_read(l) atomic_long_read(&(l)->a)
15528+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
15529 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
15530+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
15531
15532 static inline void local_inc(local_t *l)
15533 {
15534- asm volatile(_ASM_INC "%0"
15535+ asm volatile(_ASM_INC "%0\n"
15536+
15537+#ifdef CONFIG_PAX_REFCOUNT
15538+ "jno 0f\n"
15539+ _ASM_DEC "%0\n"
15540+ "int $4\n0:\n"
15541+ _ASM_EXTABLE(0b, 0b)
15542+#endif
15543+
15544+ : "+m" (l->a.counter));
15545+}
15546+
15547+static inline void local_inc_unchecked(local_unchecked_t *l)
15548+{
15549+ asm volatile(_ASM_INC "%0\n"
15550 : "+m" (l->a.counter));
15551 }
15552
15553 static inline void local_dec(local_t *l)
15554 {
15555- asm volatile(_ASM_DEC "%0"
15556+ asm volatile(_ASM_DEC "%0\n"
15557+
15558+#ifdef CONFIG_PAX_REFCOUNT
15559+ "jno 0f\n"
15560+ _ASM_INC "%0\n"
15561+ "int $4\n0:\n"
15562+ _ASM_EXTABLE(0b, 0b)
15563+#endif
15564+
15565+ : "+m" (l->a.counter));
15566+}
15567+
15568+static inline void local_dec_unchecked(local_unchecked_t *l)
15569+{
15570+ asm volatile(_ASM_DEC "%0\n"
15571 : "+m" (l->a.counter));
15572 }
15573
15574 static inline void local_add(long i, local_t *l)
15575 {
15576- asm volatile(_ASM_ADD "%1,%0"
15577+ asm volatile(_ASM_ADD "%1,%0\n"
15578+
15579+#ifdef CONFIG_PAX_REFCOUNT
15580+ "jno 0f\n"
15581+ _ASM_SUB "%1,%0\n"
15582+ "int $4\n0:\n"
15583+ _ASM_EXTABLE(0b, 0b)
15584+#endif
15585+
15586+ : "+m" (l->a.counter)
15587+ : "ir" (i));
15588+}
15589+
15590+static inline void local_add_unchecked(long i, local_unchecked_t *l)
15591+{
15592+ asm volatile(_ASM_ADD "%1,%0\n"
15593 : "+m" (l->a.counter)
15594 : "ir" (i));
15595 }
15596
15597 static inline void local_sub(long i, local_t *l)
15598 {
15599- asm volatile(_ASM_SUB "%1,%0"
15600+ asm volatile(_ASM_SUB "%1,%0\n"
15601+
15602+#ifdef CONFIG_PAX_REFCOUNT
15603+ "jno 0f\n"
15604+ _ASM_ADD "%1,%0\n"
15605+ "int $4\n0:\n"
15606+ _ASM_EXTABLE(0b, 0b)
15607+#endif
15608+
15609+ : "+m" (l->a.counter)
15610+ : "ir" (i));
15611+}
15612+
15613+static inline void local_sub_unchecked(long i, local_unchecked_t *l)
15614+{
15615+ asm volatile(_ASM_SUB "%1,%0\n"
15616 : "+m" (l->a.counter)
15617 : "ir" (i));
15618 }
15619@@ -54,7 +118,16 @@ static inline int local_sub_and_test(long i, local_t *l)
15620 {
15621 unsigned char c;
15622
15623- asm volatile(_ASM_SUB "%2,%0; sete %1"
15624+ asm volatile(_ASM_SUB "%2,%0\n"
15625+
15626+#ifdef CONFIG_PAX_REFCOUNT
15627+ "jno 0f\n"
15628+ _ASM_ADD "%2,%0\n"
15629+ "int $4\n0:\n"
15630+ _ASM_EXTABLE(0b, 0b)
15631+#endif
15632+
15633+ "sete %1\n"
15634 : "+m" (l->a.counter), "=qm" (c)
15635 : "ir" (i) : "memory");
15636 return c;
15637@@ -72,7 +145,16 @@ static inline int local_dec_and_test(local_t *l)
15638 {
15639 unsigned char c;
15640
15641- asm volatile(_ASM_DEC "%0; sete %1"
15642+ asm volatile(_ASM_DEC "%0\n"
15643+
15644+#ifdef CONFIG_PAX_REFCOUNT
15645+ "jno 0f\n"
15646+ _ASM_INC "%0\n"
15647+ "int $4\n0:\n"
15648+ _ASM_EXTABLE(0b, 0b)
15649+#endif
15650+
15651+ "sete %1\n"
15652 : "+m" (l->a.counter), "=qm" (c)
15653 : : "memory");
15654 return c != 0;
15655@@ -90,7 +172,16 @@ static inline int local_inc_and_test(local_t *l)
15656 {
15657 unsigned char c;
15658
15659- asm volatile(_ASM_INC "%0; sete %1"
15660+ asm volatile(_ASM_INC "%0\n"
15661+
15662+#ifdef CONFIG_PAX_REFCOUNT
15663+ "jno 0f\n"
15664+ _ASM_DEC "%0\n"
15665+ "int $4\n0:\n"
15666+ _ASM_EXTABLE(0b, 0b)
15667+#endif
15668+
15669+ "sete %1\n"
15670 : "+m" (l->a.counter), "=qm" (c)
15671 : : "memory");
15672 return c != 0;
15673@@ -109,7 +200,16 @@ static inline int local_add_negative(long i, local_t *l)
15674 {
15675 unsigned char c;
15676
15677- asm volatile(_ASM_ADD "%2,%0; sets %1"
15678+ asm volatile(_ASM_ADD "%2,%0\n"
15679+
15680+#ifdef CONFIG_PAX_REFCOUNT
15681+ "jno 0f\n"
15682+ _ASM_SUB "%2,%0\n"
15683+ "int $4\n0:\n"
15684+ _ASM_EXTABLE(0b, 0b)
15685+#endif
15686+
15687+ "sets %1\n"
15688 : "+m" (l->a.counter), "=qm" (c)
15689 : "ir" (i) : "memory");
15690 return c;
15691@@ -125,6 +225,30 @@ static inline int local_add_negative(long i, local_t *l)
15692 static inline long local_add_return(long i, local_t *l)
15693 {
15694 long __i = i;
15695+ asm volatile(_ASM_XADD "%0, %1\n"
15696+
15697+#ifdef CONFIG_PAX_REFCOUNT
15698+ "jno 0f\n"
15699+ _ASM_MOV "%0,%1\n"
15700+ "int $4\n0:\n"
15701+ _ASM_EXTABLE(0b, 0b)
15702+#endif
15703+
15704+ : "+r" (i), "+m" (l->a.counter)
15705+ : : "memory");
15706+ return i + __i;
15707+}
15708+
15709+/**
15710+ * local_add_return_unchecked - add and return
15711+ * @i: integer value to add
15712+ * @l: pointer to type local_unchecked_t
15713+ *
15714+ * Atomically adds @i to @l and returns @i + @l
15715+ */
15716+static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
15717+{
15718+ long __i = i;
15719 asm volatile(_ASM_XADD "%0, %1;"
15720 : "+r" (i), "+m" (l->a.counter)
15721 : : "memory");
15722@@ -141,6 +265,8 @@ static inline long local_sub_return(long i, local_t *l)
15723
15724 #define local_cmpxchg(l, o, n) \
15725 (cmpxchg_local(&((l)->a.counter), (o), (n)))
15726+#define local_cmpxchg_unchecked(l, o, n) \
15727+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
15728 /* Always has a lock prefix */
15729 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
15730
15731diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
15732new file mode 100644
15733index 0000000..2bfd3ba
15734--- /dev/null
15735+++ b/arch/x86/include/asm/mman.h
15736@@ -0,0 +1,15 @@
15737+#ifndef _X86_MMAN_H
15738+#define _X86_MMAN_H
15739+
15740+#include <uapi/asm/mman.h>
15741+
15742+#ifdef __KERNEL__
15743+#ifndef __ASSEMBLY__
15744+#ifdef CONFIG_X86_32
15745+#define arch_mmap_check i386_mmap_check
15746+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
15747+#endif
15748+#endif
15749+#endif
15750+
15751+#endif /* X86_MMAN_H */
15752diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
15753index 5f55e69..e20bfb1 100644
15754--- a/arch/x86/include/asm/mmu.h
15755+++ b/arch/x86/include/asm/mmu.h
15756@@ -9,7 +9,7 @@
15757 * we put the segment information here.
15758 */
15759 typedef struct {
15760- void *ldt;
15761+ struct desc_struct *ldt;
15762 int size;
15763
15764 #ifdef CONFIG_X86_64
15765@@ -18,7 +18,19 @@ typedef struct {
15766 #endif
15767
15768 struct mutex lock;
15769- void *vdso;
15770+ unsigned long vdso;
15771+
15772+#ifdef CONFIG_X86_32
15773+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
15774+ unsigned long user_cs_base;
15775+ unsigned long user_cs_limit;
15776+
15777+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
15778+ cpumask_t cpu_user_cs_mask;
15779+#endif
15780+
15781+#endif
15782+#endif
15783 } mm_context_t;
15784
15785 #ifdef CONFIG_SMP
15786diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
15787index be12c53..2124e35 100644
15788--- a/arch/x86/include/asm/mmu_context.h
15789+++ b/arch/x86/include/asm/mmu_context.h
15790@@ -24,6 +24,20 @@ void destroy_context(struct mm_struct *mm);
15791
15792 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
15793 {
15794+
15795+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15796+ if (!(static_cpu_has(X86_FEATURE_PCID))) {
15797+ unsigned int i;
15798+ pgd_t *pgd;
15799+
15800+ pax_open_kernel();
15801+ pgd = get_cpu_pgd(smp_processor_id(), kernel);
15802+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
15803+ set_pgd_batched(pgd+i, native_make_pgd(0));
15804+ pax_close_kernel();
15805+ }
15806+#endif
15807+
15808 #ifdef CONFIG_SMP
15809 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
15810 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
15811@@ -34,16 +48,55 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
15812 struct task_struct *tsk)
15813 {
15814 unsigned cpu = smp_processor_id();
15815+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
15816+ int tlbstate = TLBSTATE_OK;
15817+#endif
15818
15819 if (likely(prev != next)) {
15820 #ifdef CONFIG_SMP
15821+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
15822+ tlbstate = this_cpu_read(cpu_tlbstate.state);
15823+#endif
15824 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
15825 this_cpu_write(cpu_tlbstate.active_mm, next);
15826 #endif
15827 cpumask_set_cpu(cpu, mm_cpumask(next));
15828
15829 /* Re-load page tables */
15830+#ifdef CONFIG_PAX_PER_CPU_PGD
15831+ pax_open_kernel();
15832+
15833+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15834+ if (static_cpu_has(X86_FEATURE_PCID))
15835+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
15836+ else
15837+#endif
15838+
15839+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
15840+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
15841+ pax_close_kernel();
15842+ 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));
15843+
15844+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15845+ if (static_cpu_has(X86_FEATURE_PCID)) {
15846+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
15847+ u64 descriptor[2];
15848+ descriptor[0] = PCID_USER;
15849+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
15850+ } else {
15851+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
15852+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
15853+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
15854+ else
15855+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
15856+ }
15857+ } else
15858+#endif
15859+
15860+ load_cr3(get_cpu_pgd(cpu, kernel));
15861+#else
15862 load_cr3(next->pgd);
15863+#endif
15864
15865 /* Stop flush ipis for the previous mm */
15866 cpumask_clear_cpu(cpu, mm_cpumask(prev));
15867@@ -51,9 +104,63 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
15868 /* Load the LDT, if the LDT is different: */
15869 if (unlikely(prev->context.ldt != next->context.ldt))
15870 load_LDT_nolock(&next->context);
15871+
15872+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
15873+ if (!(__supported_pte_mask & _PAGE_NX)) {
15874+ smp_mb__before_clear_bit();
15875+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
15876+ smp_mb__after_clear_bit();
15877+ cpu_set(cpu, next->context.cpu_user_cs_mask);
15878+ }
15879+#endif
15880+
15881+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
15882+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
15883+ prev->context.user_cs_limit != next->context.user_cs_limit))
15884+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
15885+#ifdef CONFIG_SMP
15886+ else if (unlikely(tlbstate != TLBSTATE_OK))
15887+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
15888+#endif
15889+#endif
15890+
15891 }
15892+ else {
15893+
15894+#ifdef CONFIG_PAX_PER_CPU_PGD
15895+ pax_open_kernel();
15896+
15897+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15898+ if (static_cpu_has(X86_FEATURE_PCID))
15899+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
15900+ else
15901+#endif
15902+
15903+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
15904+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
15905+ pax_close_kernel();
15906+ 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));
15907+
15908+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15909+ if (static_cpu_has(X86_FEATURE_PCID)) {
15910+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
15911+ u64 descriptor[2];
15912+ descriptor[0] = PCID_USER;
15913+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
15914+ } else {
15915+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
15916+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
15917+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
15918+ else
15919+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
15920+ }
15921+ } else
15922+#endif
15923+
15924+ load_cr3(get_cpu_pgd(cpu, kernel));
15925+#endif
15926+
15927 #ifdef CONFIG_SMP
15928- else {
15929 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
15930 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
15931
15932@@ -70,11 +177,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
15933 * tlb flush IPI delivery. We must reload CR3
15934 * to make sure to use no freed page tables.
15935 */
15936+
15937+#ifndef CONFIG_PAX_PER_CPU_PGD
15938 load_cr3(next->pgd);
15939+#endif
15940+
15941 load_LDT_nolock(&next->context);
15942+
15943+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
15944+ if (!(__supported_pte_mask & _PAGE_NX))
15945+ cpu_set(cpu, next->context.cpu_user_cs_mask);
15946+#endif
15947+
15948+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
15949+#ifdef CONFIG_PAX_PAGEEXEC
15950+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
15951+#endif
15952+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
15953+#endif
15954+
15955 }
15956+#endif
15957 }
15958-#endif
15959 }
15960
15961 #define activate_mm(prev, next) \
15962diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
15963index e3b7819..b257c64 100644
15964--- a/arch/x86/include/asm/module.h
15965+++ b/arch/x86/include/asm/module.h
15966@@ -5,6 +5,7 @@
15967
15968 #ifdef CONFIG_X86_64
15969 /* X86_64 does not define MODULE_PROC_FAMILY */
15970+#define MODULE_PROC_FAMILY ""
15971 #elif defined CONFIG_M486
15972 #define MODULE_PROC_FAMILY "486 "
15973 #elif defined CONFIG_M586
15974@@ -57,8 +58,20 @@
15975 #error unknown processor family
15976 #endif
15977
15978-#ifdef CONFIG_X86_32
15979-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
15980+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
15981+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
15982+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
15983+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
15984+#else
15985+#define MODULE_PAX_KERNEXEC ""
15986 #endif
15987
15988+#ifdef CONFIG_PAX_MEMORY_UDEREF
15989+#define MODULE_PAX_UDEREF "UDEREF "
15990+#else
15991+#define MODULE_PAX_UDEREF ""
15992+#endif
15993+
15994+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
15995+
15996 #endif /* _ASM_X86_MODULE_H */
15997diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
15998index 86f9301..b365cda 100644
15999--- a/arch/x86/include/asm/nmi.h
16000+++ b/arch/x86/include/asm/nmi.h
16001@@ -40,11 +40,11 @@ struct nmiaction {
16002 nmi_handler_t handler;
16003 unsigned long flags;
16004 const char *name;
16005-};
16006+} __do_const;
16007
16008 #define register_nmi_handler(t, fn, fg, n, init...) \
16009 ({ \
16010- static struct nmiaction init fn##_na = { \
16011+ static const struct nmiaction init fn##_na = { \
16012 .handler = (fn), \
16013 .name = (n), \
16014 .flags = (fg), \
16015@@ -52,7 +52,7 @@ struct nmiaction {
16016 __register_nmi_handler((t), &fn##_na); \
16017 })
16018
16019-int __register_nmi_handler(unsigned int, struct nmiaction *);
16020+int __register_nmi_handler(unsigned int, const struct nmiaction *);
16021
16022 void unregister_nmi_handler(unsigned int, const char *);
16023
16024diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
16025index c878924..21f4889 100644
16026--- a/arch/x86/include/asm/page.h
16027+++ b/arch/x86/include/asm/page.h
16028@@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
16029 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
16030
16031 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
16032+#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
16033
16034 #define __boot_va(x) __va(x)
16035 #define __boot_pa(x) __pa(x)
16036diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
16037index 0f1ddee..e2fc3d1 100644
16038--- a/arch/x86/include/asm/page_64.h
16039+++ b/arch/x86/include/asm/page_64.h
16040@@ -7,9 +7,9 @@
16041
16042 /* duplicated to the one in bootmem.h */
16043 extern unsigned long max_pfn;
16044-extern unsigned long phys_base;
16045+extern const unsigned long phys_base;
16046
16047-static inline unsigned long __phys_addr_nodebug(unsigned long x)
16048+static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
16049 {
16050 unsigned long y = x - __START_KERNEL_map;
16051
16052diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
16053index cfdc9ee..3f7b5d6 100644
16054--- a/arch/x86/include/asm/paravirt.h
16055+++ b/arch/x86/include/asm/paravirt.h
16056@@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
16057 return (pmd_t) { ret };
16058 }
16059
16060-static inline pmdval_t pmd_val(pmd_t pmd)
16061+static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
16062 {
16063 pmdval_t ret;
16064
16065@@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
16066 val);
16067 }
16068
16069+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
16070+{
16071+ pgdval_t val = native_pgd_val(pgd);
16072+
16073+ if (sizeof(pgdval_t) > sizeof(long))
16074+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
16075+ val, (u64)val >> 32);
16076+ else
16077+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
16078+ val);
16079+}
16080+
16081 static inline void pgd_clear(pgd_t *pgdp)
16082 {
16083 set_pgd(pgdp, __pgd(0));
16084@@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
16085 pv_mmu_ops.set_fixmap(idx, phys, flags);
16086 }
16087
16088+#ifdef CONFIG_PAX_KERNEXEC
16089+static inline unsigned long pax_open_kernel(void)
16090+{
16091+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
16092+}
16093+
16094+static inline unsigned long pax_close_kernel(void)
16095+{
16096+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
16097+}
16098+#else
16099+static inline unsigned long pax_open_kernel(void) { return 0; }
16100+static inline unsigned long pax_close_kernel(void) { return 0; }
16101+#endif
16102+
16103 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
16104
16105 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
16106@@ -926,7 +953,7 @@ extern void default_banner(void);
16107
16108 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
16109 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
16110-#define PARA_INDIRECT(addr) *%cs:addr
16111+#define PARA_INDIRECT(addr) *%ss:addr
16112 #endif
16113
16114 #define INTERRUPT_RETURN \
16115@@ -1001,6 +1028,21 @@ extern void default_banner(void);
16116 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
16117 CLBR_NONE, \
16118 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
16119+
16120+#define GET_CR0_INTO_RDI \
16121+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
16122+ mov %rax,%rdi
16123+
16124+#define SET_RDI_INTO_CR0 \
16125+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
16126+
16127+#define GET_CR3_INTO_RDI \
16128+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
16129+ mov %rax,%rdi
16130+
16131+#define SET_RDI_INTO_CR3 \
16132+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
16133+
16134 #endif /* CONFIG_X86_32 */
16135
16136 #endif /* __ASSEMBLY__ */
16137diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
16138index 0db1fca..52310cc 100644
16139--- a/arch/x86/include/asm/paravirt_types.h
16140+++ b/arch/x86/include/asm/paravirt_types.h
16141@@ -84,7 +84,7 @@ struct pv_init_ops {
16142 */
16143 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
16144 unsigned long addr, unsigned len);
16145-};
16146+} __no_const;
16147
16148
16149 struct pv_lazy_ops {
16150@@ -98,7 +98,7 @@ struct pv_time_ops {
16151 unsigned long long (*sched_clock)(void);
16152 unsigned long long (*steal_clock)(int cpu);
16153 unsigned long (*get_tsc_khz)(void);
16154-};
16155+} __no_const;
16156
16157 struct pv_cpu_ops {
16158 /* hooks for various privileged instructions */
16159@@ -192,7 +192,7 @@ struct pv_cpu_ops {
16160
16161 void (*start_context_switch)(struct task_struct *prev);
16162 void (*end_context_switch)(struct task_struct *next);
16163-};
16164+} __no_const;
16165
16166 struct pv_irq_ops {
16167 /*
16168@@ -223,7 +223,7 @@ struct pv_apic_ops {
16169 unsigned long start_eip,
16170 unsigned long start_esp);
16171 #endif
16172-};
16173+} __no_const;
16174
16175 struct pv_mmu_ops {
16176 unsigned long (*read_cr2)(void);
16177@@ -313,6 +313,7 @@ struct pv_mmu_ops {
16178 struct paravirt_callee_save make_pud;
16179
16180 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
16181+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
16182 #endif /* PAGETABLE_LEVELS == 4 */
16183 #endif /* PAGETABLE_LEVELS >= 3 */
16184
16185@@ -324,6 +325,12 @@ struct pv_mmu_ops {
16186 an mfn. We can tell which is which from the index. */
16187 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
16188 phys_addr_t phys, pgprot_t flags);
16189+
16190+#ifdef CONFIG_PAX_KERNEXEC
16191+ unsigned long (*pax_open_kernel)(void);
16192+ unsigned long (*pax_close_kernel)(void);
16193+#endif
16194+
16195 };
16196
16197 struct arch_spinlock;
16198@@ -334,7 +341,7 @@ struct pv_lock_ops {
16199 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
16200 int (*spin_trylock)(struct arch_spinlock *lock);
16201 void (*spin_unlock)(struct arch_spinlock *lock);
16202-};
16203+} __no_const;
16204
16205 /* This contains all the paravirt structures: we get a convenient
16206 * number for each function using the offset which we use to indicate
16207diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
16208index b4389a4..7024269 100644
16209--- a/arch/x86/include/asm/pgalloc.h
16210+++ b/arch/x86/include/asm/pgalloc.h
16211@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
16212 pmd_t *pmd, pte_t *pte)
16213 {
16214 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
16215+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
16216+}
16217+
16218+static inline void pmd_populate_user(struct mm_struct *mm,
16219+ pmd_t *pmd, pte_t *pte)
16220+{
16221+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
16222 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
16223 }
16224
16225@@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
16226
16227 #ifdef CONFIG_X86_PAE
16228 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
16229+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
16230+{
16231+ pud_populate(mm, pudp, pmd);
16232+}
16233 #else /* !CONFIG_X86_PAE */
16234 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
16235 {
16236 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
16237 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
16238 }
16239+
16240+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
16241+{
16242+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
16243+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
16244+}
16245 #endif /* CONFIG_X86_PAE */
16246
16247 #if PAGETABLE_LEVELS > 3
16248@@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
16249 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
16250 }
16251
16252+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
16253+{
16254+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
16255+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
16256+}
16257+
16258 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
16259 {
16260 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
16261diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
16262index 3bf2dd0..23d2a9f 100644
16263--- a/arch/x86/include/asm/pgtable-2level.h
16264+++ b/arch/x86/include/asm/pgtable-2level.h
16265@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
16266
16267 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
16268 {
16269+ pax_open_kernel();
16270 *pmdp = pmd;
16271+ pax_close_kernel();
16272 }
16273
16274 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
16275diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
16276index 81bb91b..9392125 100644
16277--- a/arch/x86/include/asm/pgtable-3level.h
16278+++ b/arch/x86/include/asm/pgtable-3level.h
16279@@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
16280
16281 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
16282 {
16283+ pax_open_kernel();
16284 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
16285+ pax_close_kernel();
16286 }
16287
16288 static inline void native_set_pud(pud_t *pudp, pud_t pud)
16289 {
16290+ pax_open_kernel();
16291 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
16292+ pax_close_kernel();
16293 }
16294
16295 /*
16296diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
16297index 1c00631..845f898 100644
16298--- a/arch/x86/include/asm/pgtable.h
16299+++ b/arch/x86/include/asm/pgtable.h
16300@@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
16301
16302 #ifndef __PAGETABLE_PUD_FOLDED
16303 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
16304+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
16305 #define pgd_clear(pgd) native_pgd_clear(pgd)
16306 #endif
16307
16308@@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
16309
16310 #define arch_end_context_switch(prev) do {} while(0)
16311
16312+#define pax_open_kernel() native_pax_open_kernel()
16313+#define pax_close_kernel() native_pax_close_kernel()
16314 #endif /* CONFIG_PARAVIRT */
16315
16316+#define __HAVE_ARCH_PAX_OPEN_KERNEL
16317+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
16318+
16319+#ifdef CONFIG_PAX_KERNEXEC
16320+static inline unsigned long native_pax_open_kernel(void)
16321+{
16322+ unsigned long cr0;
16323+
16324+ preempt_disable();
16325+ barrier();
16326+ cr0 = read_cr0() ^ X86_CR0_WP;
16327+ BUG_ON(cr0 & X86_CR0_WP);
16328+ write_cr0(cr0);
16329+ return cr0 ^ X86_CR0_WP;
16330+}
16331+
16332+static inline unsigned long native_pax_close_kernel(void)
16333+{
16334+ unsigned long cr0;
16335+
16336+ cr0 = read_cr0() ^ X86_CR0_WP;
16337+ BUG_ON(!(cr0 & X86_CR0_WP));
16338+ write_cr0(cr0);
16339+ barrier();
16340+ preempt_enable_no_resched();
16341+ return cr0 ^ X86_CR0_WP;
16342+}
16343+#else
16344+static inline unsigned long native_pax_open_kernel(void) { return 0; }
16345+static inline unsigned long native_pax_close_kernel(void) { return 0; }
16346+#endif
16347+
16348 /*
16349 * The following only work if pte_present() is true.
16350 * Undefined behaviour if not..
16351 */
16352+static inline int pte_user(pte_t pte)
16353+{
16354+ return pte_val(pte) & _PAGE_USER;
16355+}
16356+
16357 static inline int pte_dirty(pte_t pte)
16358 {
16359 return pte_flags(pte) & _PAGE_DIRTY;
16360@@ -147,6 +187,11 @@ static inline unsigned long pud_pfn(pud_t pud)
16361 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
16362 }
16363
16364+static inline unsigned long pgd_pfn(pgd_t pgd)
16365+{
16366+ return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
16367+}
16368+
16369 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
16370
16371 static inline int pmd_large(pmd_t pte)
16372@@ -200,9 +245,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
16373 return pte_clear_flags(pte, _PAGE_RW);
16374 }
16375
16376+static inline pte_t pte_mkread(pte_t pte)
16377+{
16378+ return __pte(pte_val(pte) | _PAGE_USER);
16379+}
16380+
16381 static inline pte_t pte_mkexec(pte_t pte)
16382 {
16383- return pte_clear_flags(pte, _PAGE_NX);
16384+#ifdef CONFIG_X86_PAE
16385+ if (__supported_pte_mask & _PAGE_NX)
16386+ return pte_clear_flags(pte, _PAGE_NX);
16387+ else
16388+#endif
16389+ return pte_set_flags(pte, _PAGE_USER);
16390+}
16391+
16392+static inline pte_t pte_exprotect(pte_t pte)
16393+{
16394+#ifdef CONFIG_X86_PAE
16395+ if (__supported_pte_mask & _PAGE_NX)
16396+ return pte_set_flags(pte, _PAGE_NX);
16397+ else
16398+#endif
16399+ return pte_clear_flags(pte, _PAGE_USER);
16400 }
16401
16402 static inline pte_t pte_mkdirty(pte_t pte)
16403@@ -444,6 +509,16 @@ pte_t *populate_extra_pte(unsigned long vaddr);
16404 #endif
16405
16406 #ifndef __ASSEMBLY__
16407+
16408+#ifdef CONFIG_PAX_PER_CPU_PGD
16409+extern pgd_t cpu_pgd[NR_CPUS][2][PTRS_PER_PGD];
16410+enum cpu_pgd_type {kernel = 0, user = 1};
16411+static inline pgd_t *get_cpu_pgd(unsigned int cpu, enum cpu_pgd_type type)
16412+{
16413+ return cpu_pgd[cpu][type];
16414+}
16415+#endif
16416+
16417 #include <linux/mm_types.h>
16418 #include <linux/log2.h>
16419
16420@@ -576,7 +651,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
16421 * Currently stuck as a macro due to indirect forward reference to
16422 * linux/mmzone.h's __section_mem_map_addr() definition:
16423 */
16424-#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
16425+#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
16426
16427 /* Find an entry in the second-level page table.. */
16428 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
16429@@ -616,7 +691,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
16430 * Currently stuck as a macro due to indirect forward reference to
16431 * linux/mmzone.h's __section_mem_map_addr() definition:
16432 */
16433-#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
16434+#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
16435
16436 /* to find an entry in a page-table-directory. */
16437 static inline unsigned long pud_index(unsigned long address)
16438@@ -631,7 +706,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
16439
16440 static inline int pgd_bad(pgd_t pgd)
16441 {
16442- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
16443+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
16444 }
16445
16446 static inline int pgd_none(pgd_t pgd)
16447@@ -654,7 +729,12 @@ static inline int pgd_none(pgd_t pgd)
16448 * pgd_offset() returns a (pgd_t *)
16449 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
16450 */
16451-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
16452+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
16453+
16454+#ifdef CONFIG_PAX_PER_CPU_PGD
16455+#define pgd_offset_cpu(cpu, type, address) (get_cpu_pgd(cpu, type) + pgd_index(address))
16456+#endif
16457+
16458 /*
16459 * a shortcut which implies the use of the kernel's pgd, instead
16460 * of a process's
16461@@ -665,6 +745,23 @@ static inline int pgd_none(pgd_t pgd)
16462 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
16463 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
16464
16465+#ifdef CONFIG_X86_32
16466+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
16467+#else
16468+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
16469+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
16470+
16471+#ifdef CONFIG_PAX_MEMORY_UDEREF
16472+#ifdef __ASSEMBLY__
16473+#define pax_user_shadow_base pax_user_shadow_base(%rip)
16474+#else
16475+extern unsigned long pax_user_shadow_base;
16476+extern pgdval_t clone_pgd_mask;
16477+#endif
16478+#endif
16479+
16480+#endif
16481+
16482 #ifndef __ASSEMBLY__
16483
16484 extern int direct_gbpages;
16485@@ -831,11 +928,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
16486 * dst and src can be on the same page, but the range must not overlap,
16487 * and must not cross a page boundary.
16488 */
16489-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
16490+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
16491 {
16492- memcpy(dst, src, count * sizeof(pgd_t));
16493+ pax_open_kernel();
16494+ while (count--)
16495+ *dst++ = *src++;
16496+ pax_close_kernel();
16497 }
16498
16499+#ifdef CONFIG_PAX_PER_CPU_PGD
16500+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
16501+#endif
16502+
16503+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16504+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
16505+#else
16506+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
16507+#endif
16508+
16509 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
16510 static inline int page_level_shift(enum pg_level level)
16511 {
16512diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
16513index 9ee3221..b979c6b 100644
16514--- a/arch/x86/include/asm/pgtable_32.h
16515+++ b/arch/x86/include/asm/pgtable_32.h
16516@@ -25,9 +25,6 @@
16517 struct mm_struct;
16518 struct vm_area_struct;
16519
16520-extern pgd_t swapper_pg_dir[1024];
16521-extern pgd_t initial_page_table[1024];
16522-
16523 static inline void pgtable_cache_init(void) { }
16524 static inline void check_pgt_cache(void) { }
16525 void paging_init(void);
16526@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
16527 # include <asm/pgtable-2level.h>
16528 #endif
16529
16530+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
16531+extern pgd_t initial_page_table[PTRS_PER_PGD];
16532+#ifdef CONFIG_X86_PAE
16533+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
16534+#endif
16535+
16536 #if defined(CONFIG_HIGHPTE)
16537 #define pte_offset_map(dir, address) \
16538 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
16539@@ -62,12 +65,17 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
16540 /* Clear a kernel PTE and flush it from the TLB */
16541 #define kpte_clear_flush(ptep, vaddr) \
16542 do { \
16543+ pax_open_kernel(); \
16544 pte_clear(&init_mm, (vaddr), (ptep)); \
16545+ pax_close_kernel(); \
16546 __flush_tlb_one((vaddr)); \
16547 } while (0)
16548
16549 #endif /* !__ASSEMBLY__ */
16550
16551+#define HAVE_ARCH_UNMAPPED_AREA
16552+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
16553+
16554 /*
16555 * kern_addr_valid() is (1) for FLATMEM and (0) for
16556 * SPARSEMEM and DISCONTIGMEM
16557diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
16558index ed5903b..c7fe163 100644
16559--- a/arch/x86/include/asm/pgtable_32_types.h
16560+++ b/arch/x86/include/asm/pgtable_32_types.h
16561@@ -8,7 +8,7 @@
16562 */
16563 #ifdef CONFIG_X86_PAE
16564 # include <asm/pgtable-3level_types.h>
16565-# define PMD_SIZE (1UL << PMD_SHIFT)
16566+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
16567 # define PMD_MASK (~(PMD_SIZE - 1))
16568 #else
16569 # include <asm/pgtable-2level_types.h>
16570@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
16571 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
16572 #endif
16573
16574+#ifdef CONFIG_PAX_KERNEXEC
16575+#ifndef __ASSEMBLY__
16576+extern unsigned char MODULES_EXEC_VADDR[];
16577+extern unsigned char MODULES_EXEC_END[];
16578+#endif
16579+#include <asm/boot.h>
16580+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
16581+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
16582+#else
16583+#define ktla_ktva(addr) (addr)
16584+#define ktva_ktla(addr) (addr)
16585+#endif
16586+
16587 #define MODULES_VADDR VMALLOC_START
16588 #define MODULES_END VMALLOC_END
16589 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
16590diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
16591index e22c1db..23a625a 100644
16592--- a/arch/x86/include/asm/pgtable_64.h
16593+++ b/arch/x86/include/asm/pgtable_64.h
16594@@ -16,10 +16,14 @@
16595
16596 extern pud_t level3_kernel_pgt[512];
16597 extern pud_t level3_ident_pgt[512];
16598+extern pud_t level3_vmalloc_start_pgt[512];
16599+extern pud_t level3_vmalloc_end_pgt[512];
16600+extern pud_t level3_vmemmap_pgt[512];
16601+extern pud_t level2_vmemmap_pgt[512];
16602 extern pmd_t level2_kernel_pgt[512];
16603 extern pmd_t level2_fixmap_pgt[512];
16604-extern pmd_t level2_ident_pgt[512];
16605-extern pgd_t init_level4_pgt[];
16606+extern pmd_t level2_ident_pgt[512*2];
16607+extern pgd_t init_level4_pgt[512];
16608
16609 #define swapper_pg_dir init_level4_pgt
16610
16611@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
16612
16613 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
16614 {
16615+ pax_open_kernel();
16616 *pmdp = pmd;
16617+ pax_close_kernel();
16618 }
16619
16620 static inline void native_pmd_clear(pmd_t *pmd)
16621@@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
16622
16623 static inline void native_set_pud(pud_t *pudp, pud_t pud)
16624 {
16625+ pax_open_kernel();
16626 *pudp = pud;
16627+ pax_close_kernel();
16628 }
16629
16630 static inline void native_pud_clear(pud_t *pud)
16631@@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
16632
16633 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
16634 {
16635+ pax_open_kernel();
16636+ *pgdp = pgd;
16637+ pax_close_kernel();
16638+}
16639+
16640+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
16641+{
16642 *pgdp = pgd;
16643 }
16644
16645diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
16646index 2d88344..4679fc3 100644
16647--- a/arch/x86/include/asm/pgtable_64_types.h
16648+++ b/arch/x86/include/asm/pgtable_64_types.h
16649@@ -61,6 +61,11 @@ typedef struct { pteval_t pte; } pte_t;
16650 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
16651 #define MODULES_END _AC(0xffffffffff000000, UL)
16652 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
16653+#define MODULES_EXEC_VADDR MODULES_VADDR
16654+#define MODULES_EXEC_END MODULES_END
16655+
16656+#define ktla_ktva(addr) (addr)
16657+#define ktva_ktla(addr) (addr)
16658
16659 #define EARLY_DYNAMIC_PAGE_TABLES 64
16660
16661diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
16662index f4843e0..a2526f8 100644
16663--- a/arch/x86/include/asm/pgtable_types.h
16664+++ b/arch/x86/include/asm/pgtable_types.h
16665@@ -16,13 +16,12 @@
16666 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
16667 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
16668 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
16669-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
16670+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
16671 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
16672 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
16673 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
16674-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
16675-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
16676-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
16677+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
16678+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
16679 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
16680
16681 /* If _PAGE_BIT_PRESENT is clear, we use these: */
16682@@ -40,7 +39,6 @@
16683 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
16684 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
16685 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
16686-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
16687 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
16688 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
16689 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
16690@@ -84,8 +82,10 @@
16691
16692 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
16693 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
16694-#else
16695+#elif defined(CONFIG_KMEMCHECK)
16696 #define _PAGE_NX (_AT(pteval_t, 0))
16697+#else
16698+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
16699 #endif
16700
16701 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
16702@@ -143,6 +143,9 @@
16703 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
16704 _PAGE_ACCESSED)
16705
16706+#define PAGE_READONLY_NOEXEC PAGE_READONLY
16707+#define PAGE_SHARED_NOEXEC PAGE_SHARED
16708+
16709 #define __PAGE_KERNEL_EXEC \
16710 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
16711 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
16712@@ -153,7 +156,7 @@
16713 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
16714 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
16715 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
16716-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
16717+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
16718 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
16719 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
16720 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
16721@@ -215,8 +218,8 @@
16722 * bits are combined, this will alow user to access the high address mapped
16723 * VDSO in the presence of CONFIG_COMPAT_VDSO
16724 */
16725-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
16726-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
16727+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
16728+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
16729 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
16730 #endif
16731
16732@@ -254,7 +257,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
16733 {
16734 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
16735 }
16736+#endif
16737
16738+#if PAGETABLE_LEVELS == 3
16739+#include <asm-generic/pgtable-nopud.h>
16740+#endif
16741+
16742+#if PAGETABLE_LEVELS == 2
16743+#include <asm-generic/pgtable-nopmd.h>
16744+#endif
16745+
16746+#ifndef __ASSEMBLY__
16747 #if PAGETABLE_LEVELS > 3
16748 typedef struct { pudval_t pud; } pud_t;
16749
16750@@ -268,8 +281,6 @@ static inline pudval_t native_pud_val(pud_t pud)
16751 return pud.pud;
16752 }
16753 #else
16754-#include <asm-generic/pgtable-nopud.h>
16755-
16756 static inline pudval_t native_pud_val(pud_t pud)
16757 {
16758 return native_pgd_val(pud.pgd);
16759@@ -289,8 +300,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
16760 return pmd.pmd;
16761 }
16762 #else
16763-#include <asm-generic/pgtable-nopmd.h>
16764-
16765 static inline pmdval_t native_pmd_val(pmd_t pmd)
16766 {
16767 return native_pgd_val(pmd.pud.pgd);
16768@@ -330,7 +339,6 @@ typedef struct page *pgtable_t;
16769
16770 extern pteval_t __supported_pte_mask;
16771 extern void set_nx(void);
16772-extern int nx_enabled;
16773
16774 #define pgprot_writecombine pgprot_writecombine
16775 extern pgprot_t pgprot_writecombine(pgprot_t prot);
16776diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
16777index 24cf5ae..4d9fa2d 100644
16778--- a/arch/x86/include/asm/processor.h
16779+++ b/arch/x86/include/asm/processor.h
16780@@ -199,9 +199,21 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
16781 : "memory");
16782 }
16783
16784+/* invpcid (%rdx),%rax */
16785+#define __ASM_INVPCID ".byte 0x66,0x0f,0x38,0x82,0x02"
16786+
16787+#define INVPCID_SINGLE_ADDRESS 0UL
16788+#define INVPCID_SINGLE_CONTEXT 1UL
16789+#define INVPCID_ALL_GLOBAL 2UL
16790+#define INVPCID_ALL_MONGLOBAL 3UL
16791+
16792+#define PCID_KERNEL 0UL
16793+#define PCID_USER 1UL
16794+#define PCID_NOFLUSH (1UL << 63)
16795+
16796 static inline void load_cr3(pgd_t *pgdir)
16797 {
16798- write_cr3(__pa(pgdir));
16799+ write_cr3(__pa(pgdir) | PCID_KERNEL);
16800 }
16801
16802 #ifdef CONFIG_X86_32
16803@@ -283,7 +295,7 @@ struct tss_struct {
16804
16805 } ____cacheline_aligned;
16806
16807-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
16808+extern struct tss_struct init_tss[NR_CPUS];
16809
16810 /*
16811 * Save the original ist values for checking stack pointers during debugging
16812@@ -453,6 +465,7 @@ struct thread_struct {
16813 unsigned short ds;
16814 unsigned short fsindex;
16815 unsigned short gsindex;
16816+ unsigned short ss;
16817 #endif
16818 #ifdef CONFIG_X86_32
16819 unsigned long ip;
16820@@ -553,29 +566,8 @@ static inline void load_sp0(struct tss_struct *tss,
16821 extern unsigned long mmu_cr4_features;
16822 extern u32 *trampoline_cr4_features;
16823
16824-static inline void set_in_cr4(unsigned long mask)
16825-{
16826- unsigned long cr4;
16827-
16828- mmu_cr4_features |= mask;
16829- if (trampoline_cr4_features)
16830- *trampoline_cr4_features = mmu_cr4_features;
16831- cr4 = read_cr4();
16832- cr4 |= mask;
16833- write_cr4(cr4);
16834-}
16835-
16836-static inline void clear_in_cr4(unsigned long mask)
16837-{
16838- unsigned long cr4;
16839-
16840- mmu_cr4_features &= ~mask;
16841- if (trampoline_cr4_features)
16842- *trampoline_cr4_features = mmu_cr4_features;
16843- cr4 = read_cr4();
16844- cr4 &= ~mask;
16845- write_cr4(cr4);
16846-}
16847+extern void set_in_cr4(unsigned long mask);
16848+extern void clear_in_cr4(unsigned long mask);
16849
16850 typedef struct {
16851 unsigned long seg;
16852@@ -824,11 +816,18 @@ static inline void spin_lock_prefetch(const void *x)
16853 */
16854 #define TASK_SIZE PAGE_OFFSET
16855 #define TASK_SIZE_MAX TASK_SIZE
16856+
16857+#ifdef CONFIG_PAX_SEGMEXEC
16858+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
16859+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
16860+#else
16861 #define STACK_TOP TASK_SIZE
16862-#define STACK_TOP_MAX STACK_TOP
16863+#endif
16864+
16865+#define STACK_TOP_MAX TASK_SIZE
16866
16867 #define INIT_THREAD { \
16868- .sp0 = sizeof(init_stack) + (long)&init_stack, \
16869+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
16870 .vm86_info = NULL, \
16871 .sysenter_cs = __KERNEL_CS, \
16872 .io_bitmap_ptr = NULL, \
16873@@ -842,7 +841,7 @@ static inline void spin_lock_prefetch(const void *x)
16874 */
16875 #define INIT_TSS { \
16876 .x86_tss = { \
16877- .sp0 = sizeof(init_stack) + (long)&init_stack, \
16878+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
16879 .ss0 = __KERNEL_DS, \
16880 .ss1 = __KERNEL_CS, \
16881 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
16882@@ -853,11 +852,7 @@ static inline void spin_lock_prefetch(const void *x)
16883 extern unsigned long thread_saved_pc(struct task_struct *tsk);
16884
16885 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
16886-#define KSTK_TOP(info) \
16887-({ \
16888- unsigned long *__ptr = (unsigned long *)(info); \
16889- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
16890-})
16891+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
16892
16893 /*
16894 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
16895@@ -872,7 +867,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
16896 #define task_pt_regs(task) \
16897 ({ \
16898 struct pt_regs *__regs__; \
16899- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
16900+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
16901 __regs__ - 1; \
16902 })
16903
16904@@ -882,13 +877,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
16905 /*
16906 * User space process size. 47bits minus one guard page.
16907 */
16908-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
16909+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
16910
16911 /* This decides where the kernel will search for a free chunk of vm
16912 * space during mmap's.
16913 */
16914 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
16915- 0xc0000000 : 0xFFFFe000)
16916+ 0xc0000000 : 0xFFFFf000)
16917
16918 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
16919 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
16920@@ -899,11 +894,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
16921 #define STACK_TOP_MAX TASK_SIZE_MAX
16922
16923 #define INIT_THREAD { \
16924- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
16925+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
16926 }
16927
16928 #define INIT_TSS { \
16929- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
16930+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
16931 }
16932
16933 /*
16934@@ -931,6 +926,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
16935 */
16936 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
16937
16938+#ifdef CONFIG_PAX_SEGMEXEC
16939+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
16940+#endif
16941+
16942 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
16943
16944 /* Get/set a process' ability to use the timestamp counter instruction */
16945@@ -943,7 +942,8 @@ extern int set_tsc_mode(unsigned int val);
16946 extern u16 amd_get_nb_id(int cpu);
16947
16948 struct aperfmperf {
16949- u64 aperf, mperf;
16950+ u64 aperf __intentional_overflow(0);
16951+ u64 mperf __intentional_overflow(0);
16952 };
16953
16954 static inline void get_aperfmperf(struct aperfmperf *am)
16955@@ -971,7 +971,7 @@ unsigned long calc_aperfmperf_ratio(struct aperfmperf *old,
16956 return ratio;
16957 }
16958
16959-extern unsigned long arch_align_stack(unsigned long sp);
16960+#define arch_align_stack(x) ((x) & ~0xfUL)
16961 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
16962
16963 void default_idle(void);
16964@@ -981,6 +981,6 @@ bool xen_set_default_idle(void);
16965 #define xen_set_default_idle 0
16966 #endif
16967
16968-void stop_this_cpu(void *dummy);
16969+void stop_this_cpu(void *dummy) __noreturn;
16970 void df_debug(struct pt_regs *regs, long error_code);
16971 #endif /* _ASM_X86_PROCESSOR_H */
16972diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
16973index 942a086..6c26446 100644
16974--- a/arch/x86/include/asm/ptrace.h
16975+++ b/arch/x86/include/asm/ptrace.h
16976@@ -85,28 +85,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
16977 }
16978
16979 /*
16980- * user_mode_vm(regs) determines whether a register set came from user mode.
16981+ * user_mode(regs) determines whether a register set came from user mode.
16982 * This is true if V8086 mode was enabled OR if the register set was from
16983 * protected mode with RPL-3 CS value. This tricky test checks that with
16984 * one comparison. Many places in the kernel can bypass this full check
16985- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
16986+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
16987+ * be used.
16988 */
16989-static inline int user_mode(struct pt_regs *regs)
16990+static inline int user_mode_novm(struct pt_regs *regs)
16991 {
16992 #ifdef CONFIG_X86_32
16993 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
16994 #else
16995- return !!(regs->cs & 3);
16996+ return !!(regs->cs & SEGMENT_RPL_MASK);
16997 #endif
16998 }
16999
17000-static inline int user_mode_vm(struct pt_regs *regs)
17001+static inline int user_mode(struct pt_regs *regs)
17002 {
17003 #ifdef CONFIG_X86_32
17004 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
17005 USER_RPL;
17006 #else
17007- return user_mode(regs);
17008+ return user_mode_novm(regs);
17009 #endif
17010 }
17011
17012@@ -122,15 +123,16 @@ static inline int v8086_mode(struct pt_regs *regs)
17013 #ifdef CONFIG_X86_64
17014 static inline bool user_64bit_mode(struct pt_regs *regs)
17015 {
17016+ unsigned long cs = regs->cs & 0xffff;
17017 #ifndef CONFIG_PARAVIRT
17018 /*
17019 * On non-paravirt systems, this is the only long mode CPL 3
17020 * selector. We do not allow long mode selectors in the LDT.
17021 */
17022- return regs->cs == __USER_CS;
17023+ return cs == __USER_CS;
17024 #else
17025 /* Headers are too twisted for this to go in paravirt.h. */
17026- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
17027+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
17028 #endif
17029 }
17030
17031@@ -181,9 +183,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
17032 * Traps from the kernel do not save sp and ss.
17033 * Use the helper function to retrieve sp.
17034 */
17035- if (offset == offsetof(struct pt_regs, sp) &&
17036- regs->cs == __KERNEL_CS)
17037- return kernel_stack_pointer(regs);
17038+ if (offset == offsetof(struct pt_regs, sp)) {
17039+ unsigned long cs = regs->cs & 0xffff;
17040+ if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
17041+ return kernel_stack_pointer(regs);
17042+ }
17043 #endif
17044 return *(unsigned long *)((unsigned long)regs + offset);
17045 }
17046diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
17047index 9c6b890..5305f53 100644
17048--- a/arch/x86/include/asm/realmode.h
17049+++ b/arch/x86/include/asm/realmode.h
17050@@ -22,16 +22,14 @@ struct real_mode_header {
17051 #endif
17052 /* APM/BIOS reboot */
17053 u32 machine_real_restart_asm;
17054-#ifdef CONFIG_X86_64
17055 u32 machine_real_restart_seg;
17056-#endif
17057 };
17058
17059 /* This must match data at trampoline_32/64.S */
17060 struct trampoline_header {
17061 #ifdef CONFIG_X86_32
17062 u32 start;
17063- u16 gdt_pad;
17064+ u16 boot_cs;
17065 u16 gdt_limit;
17066 u32 gdt_base;
17067 #else
17068diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
17069index a82c4f1..ac45053 100644
17070--- a/arch/x86/include/asm/reboot.h
17071+++ b/arch/x86/include/asm/reboot.h
17072@@ -6,13 +6,13 @@
17073 struct pt_regs;
17074
17075 struct machine_ops {
17076- void (*restart)(char *cmd);
17077- void (*halt)(void);
17078- void (*power_off)(void);
17079+ void (* __noreturn restart)(char *cmd);
17080+ void (* __noreturn halt)(void);
17081+ void (* __noreturn power_off)(void);
17082 void (*shutdown)(void);
17083 void (*crash_shutdown)(struct pt_regs *);
17084- void (*emergency_restart)(void);
17085-};
17086+ void (* __noreturn emergency_restart)(void);
17087+} __no_const;
17088
17089 extern struct machine_ops machine_ops;
17090
17091diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
17092index cad82c9..2e5c5c1 100644
17093--- a/arch/x86/include/asm/rwsem.h
17094+++ b/arch/x86/include/asm/rwsem.h
17095@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
17096 {
17097 asm volatile("# beginning down_read\n\t"
17098 LOCK_PREFIX _ASM_INC "(%1)\n\t"
17099+
17100+#ifdef CONFIG_PAX_REFCOUNT
17101+ "jno 0f\n"
17102+ LOCK_PREFIX _ASM_DEC "(%1)\n"
17103+ "int $4\n0:\n"
17104+ _ASM_EXTABLE(0b, 0b)
17105+#endif
17106+
17107 /* adds 0x00000001 */
17108 " jns 1f\n"
17109 " call call_rwsem_down_read_failed\n"
17110@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
17111 "1:\n\t"
17112 " mov %1,%2\n\t"
17113 " add %3,%2\n\t"
17114+
17115+#ifdef CONFIG_PAX_REFCOUNT
17116+ "jno 0f\n"
17117+ "sub %3,%2\n"
17118+ "int $4\n0:\n"
17119+ _ASM_EXTABLE(0b, 0b)
17120+#endif
17121+
17122 " jle 2f\n\t"
17123 LOCK_PREFIX " cmpxchg %2,%0\n\t"
17124 " jnz 1b\n\t"
17125@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
17126 long tmp;
17127 asm volatile("# beginning down_write\n\t"
17128 LOCK_PREFIX " xadd %1,(%2)\n\t"
17129+
17130+#ifdef CONFIG_PAX_REFCOUNT
17131+ "jno 0f\n"
17132+ "mov %1,(%2)\n"
17133+ "int $4\n0:\n"
17134+ _ASM_EXTABLE(0b, 0b)
17135+#endif
17136+
17137 /* adds 0xffff0001, returns the old value */
17138 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
17139 /* was the active mask 0 before? */
17140@@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
17141 long tmp;
17142 asm volatile("# beginning __up_read\n\t"
17143 LOCK_PREFIX " xadd %1,(%2)\n\t"
17144+
17145+#ifdef CONFIG_PAX_REFCOUNT
17146+ "jno 0f\n"
17147+ "mov %1,(%2)\n"
17148+ "int $4\n0:\n"
17149+ _ASM_EXTABLE(0b, 0b)
17150+#endif
17151+
17152 /* subtracts 1, returns the old value */
17153 " jns 1f\n\t"
17154 " call call_rwsem_wake\n" /* expects old value in %edx */
17155@@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
17156 long tmp;
17157 asm volatile("# beginning __up_write\n\t"
17158 LOCK_PREFIX " xadd %1,(%2)\n\t"
17159+
17160+#ifdef CONFIG_PAX_REFCOUNT
17161+ "jno 0f\n"
17162+ "mov %1,(%2)\n"
17163+ "int $4\n0:\n"
17164+ _ASM_EXTABLE(0b, 0b)
17165+#endif
17166+
17167 /* subtracts 0xffff0001, returns the old value */
17168 " jns 1f\n\t"
17169 " call call_rwsem_wake\n" /* expects old value in %edx */
17170@@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
17171 {
17172 asm volatile("# beginning __downgrade_write\n\t"
17173 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
17174+
17175+#ifdef CONFIG_PAX_REFCOUNT
17176+ "jno 0f\n"
17177+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
17178+ "int $4\n0:\n"
17179+ _ASM_EXTABLE(0b, 0b)
17180+#endif
17181+
17182 /*
17183 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
17184 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
17185@@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
17186 */
17187 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
17188 {
17189- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
17190+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
17191+
17192+#ifdef CONFIG_PAX_REFCOUNT
17193+ "jno 0f\n"
17194+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
17195+ "int $4\n0:\n"
17196+ _ASM_EXTABLE(0b, 0b)
17197+#endif
17198+
17199 : "+m" (sem->count)
17200 : "er" (delta));
17201 }
17202@@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
17203 */
17204 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
17205 {
17206- return delta + xadd(&sem->count, delta);
17207+ return delta + xadd_check_overflow(&sem->count, delta);
17208 }
17209
17210 #endif /* __KERNEL__ */
17211diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
17212index c48a950..bc40804 100644
17213--- a/arch/x86/include/asm/segment.h
17214+++ b/arch/x86/include/asm/segment.h
17215@@ -64,10 +64,15 @@
17216 * 26 - ESPFIX small SS
17217 * 27 - per-cpu [ offset to per-cpu data area ]
17218 * 28 - stack_canary-20 [ for stack protector ]
17219- * 29 - unused
17220- * 30 - unused
17221+ * 29 - PCI BIOS CS
17222+ * 30 - PCI BIOS DS
17223 * 31 - TSS for double fault handler
17224 */
17225+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
17226+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
17227+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
17228+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
17229+
17230 #define GDT_ENTRY_TLS_MIN 6
17231 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
17232
17233@@ -79,6 +84,8 @@
17234
17235 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
17236
17237+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
17238+
17239 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
17240
17241 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
17242@@ -104,6 +111,12 @@
17243 #define __KERNEL_STACK_CANARY 0
17244 #endif
17245
17246+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
17247+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
17248+
17249+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
17250+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
17251+
17252 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
17253
17254 /*
17255@@ -141,7 +154,7 @@
17256 */
17257
17258 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
17259-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
17260+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
17261
17262
17263 #else
17264@@ -165,6 +178,8 @@
17265 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
17266 #define __USER32_DS __USER_DS
17267
17268+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
17269+
17270 #define GDT_ENTRY_TSS 8 /* needs two entries */
17271 #define GDT_ENTRY_LDT 10 /* needs two entries */
17272 #define GDT_ENTRY_TLS_MIN 12
17273@@ -173,6 +188,8 @@
17274 #define GDT_ENTRY_PER_CPU 15 /* Abused to load per CPU data from limit */
17275 #define __PER_CPU_SEG (GDT_ENTRY_PER_CPU * 8 + 3)
17276
17277+#define GDT_ENTRY_UDEREF_KERNEL_DS 16
17278+
17279 /* TLS indexes for 64bit - hardcoded in arch_prctl */
17280 #define FS_TLS 0
17281 #define GS_TLS 1
17282@@ -180,12 +197,14 @@
17283 #define GS_TLS_SEL ((GDT_ENTRY_TLS_MIN+GS_TLS)*8 + 3)
17284 #define FS_TLS_SEL ((GDT_ENTRY_TLS_MIN+FS_TLS)*8 + 3)
17285
17286-#define GDT_ENTRIES 16
17287+#define GDT_ENTRIES 17
17288
17289 #endif
17290
17291 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
17292+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
17293 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
17294+#define __UDEREF_KERNEL_DS (GDT_ENTRY_UDEREF_KERNEL_DS*8)
17295 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
17296 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
17297 #ifndef CONFIG_PARAVIRT
17298@@ -265,7 +284,7 @@ static inline unsigned long get_limit(unsigned long segment)
17299 {
17300 unsigned long __limit;
17301 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
17302- return __limit + 1;
17303+ return __limit;
17304 }
17305
17306 #endif /* !__ASSEMBLY__ */
17307diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
17308index 8d3120f..352b440 100644
17309--- a/arch/x86/include/asm/smap.h
17310+++ b/arch/x86/include/asm/smap.h
17311@@ -25,11 +25,40 @@
17312
17313 #include <asm/alternative-asm.h>
17314
17315+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17316+#define ASM_PAX_OPEN_USERLAND \
17317+ 661: jmp 663f; \
17318+ .pushsection .altinstr_replacement, "a" ; \
17319+ 662: pushq %rax; nop; \
17320+ .popsection ; \
17321+ .pushsection .altinstructions, "a" ; \
17322+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
17323+ .popsection ; \
17324+ call __pax_open_userland; \
17325+ popq %rax; \
17326+ 663:
17327+
17328+#define ASM_PAX_CLOSE_USERLAND \
17329+ 661: jmp 663f; \
17330+ .pushsection .altinstr_replacement, "a" ; \
17331+ 662: pushq %rax; nop; \
17332+ .popsection; \
17333+ .pushsection .altinstructions, "a" ; \
17334+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
17335+ .popsection; \
17336+ call __pax_close_userland; \
17337+ popq %rax; \
17338+ 663:
17339+#else
17340+#define ASM_PAX_OPEN_USERLAND
17341+#define ASM_PAX_CLOSE_USERLAND
17342+#endif
17343+
17344 #ifdef CONFIG_X86_SMAP
17345
17346 #define ASM_CLAC \
17347 661: ASM_NOP3 ; \
17348- .pushsection .altinstr_replacement, "ax" ; \
17349+ .pushsection .altinstr_replacement, "a" ; \
17350 662: __ASM_CLAC ; \
17351 .popsection ; \
17352 .pushsection .altinstructions, "a" ; \
17353@@ -38,7 +67,7 @@
17354
17355 #define ASM_STAC \
17356 661: ASM_NOP3 ; \
17357- .pushsection .altinstr_replacement, "ax" ; \
17358+ .pushsection .altinstr_replacement, "a" ; \
17359 662: __ASM_STAC ; \
17360 .popsection ; \
17361 .pushsection .altinstructions, "a" ; \
17362@@ -56,6 +85,37 @@
17363
17364 #include <asm/alternative.h>
17365
17366+#define __HAVE_ARCH_PAX_OPEN_USERLAND
17367+#define __HAVE_ARCH_PAX_CLOSE_USERLAND
17368+
17369+extern void __pax_open_userland(void);
17370+static __always_inline unsigned long pax_open_userland(void)
17371+{
17372+
17373+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17374+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[open]", X86_FEATURE_STRONGUDEREF)
17375+ :
17376+ : [open] "i" (__pax_open_userland)
17377+ : "memory", "rax");
17378+#endif
17379+
17380+ return 0;
17381+}
17382+
17383+extern void __pax_close_userland(void);
17384+static __always_inline unsigned long pax_close_userland(void)
17385+{
17386+
17387+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17388+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[close]", X86_FEATURE_STRONGUDEREF)
17389+ :
17390+ : [close] "i" (__pax_close_userland)
17391+ : "memory", "rax");
17392+#endif
17393+
17394+ return 0;
17395+}
17396+
17397 #ifdef CONFIG_X86_SMAP
17398
17399 static __always_inline void clac(void)
17400diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
17401index 4137890..03fa172 100644
17402--- a/arch/x86/include/asm/smp.h
17403+++ b/arch/x86/include/asm/smp.h
17404@@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
17405 /* cpus sharing the last level cache: */
17406 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
17407 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
17408-DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
17409+DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
17410
17411 static inline struct cpumask *cpu_sibling_mask(int cpu)
17412 {
17413@@ -79,7 +79,7 @@ struct smp_ops {
17414
17415 void (*send_call_func_ipi)(const struct cpumask *mask);
17416 void (*send_call_func_single_ipi)(int cpu);
17417-};
17418+} __no_const;
17419
17420 /* Globals due to paravirt */
17421 extern void set_cpu_sibling_map(int cpu);
17422@@ -191,14 +191,8 @@ extern unsigned disabled_cpus;
17423 extern int safe_smp_processor_id(void);
17424
17425 #elif defined(CONFIG_X86_64_SMP)
17426-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
17427-
17428-#define stack_smp_processor_id() \
17429-({ \
17430- struct thread_info *ti; \
17431- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
17432- ti->cpu; \
17433-})
17434+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
17435+#define stack_smp_processor_id() raw_smp_processor_id()
17436 #define safe_smp_processor_id() smp_processor_id()
17437
17438 #endif
17439diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
17440index e3ddd7d..3611fce 100644
17441--- a/arch/x86/include/asm/spinlock.h
17442+++ b/arch/x86/include/asm/spinlock.h
17443@@ -172,6 +172,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
17444 static inline void arch_read_lock(arch_rwlock_t *rw)
17445 {
17446 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
17447+
17448+#ifdef CONFIG_PAX_REFCOUNT
17449+ "jno 0f\n"
17450+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
17451+ "int $4\n0:\n"
17452+ _ASM_EXTABLE(0b, 0b)
17453+#endif
17454+
17455 "jns 1f\n"
17456 "call __read_lock_failed\n\t"
17457 "1:\n"
17458@@ -181,6 +189,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
17459 static inline void arch_write_lock(arch_rwlock_t *rw)
17460 {
17461 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
17462+
17463+#ifdef CONFIG_PAX_REFCOUNT
17464+ "jno 0f\n"
17465+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
17466+ "int $4\n0:\n"
17467+ _ASM_EXTABLE(0b, 0b)
17468+#endif
17469+
17470 "jz 1f\n"
17471 "call __write_lock_failed\n\t"
17472 "1:\n"
17473@@ -210,13 +226,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
17474
17475 static inline void arch_read_unlock(arch_rwlock_t *rw)
17476 {
17477- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
17478+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
17479+
17480+#ifdef CONFIG_PAX_REFCOUNT
17481+ "jno 0f\n"
17482+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
17483+ "int $4\n0:\n"
17484+ _ASM_EXTABLE(0b, 0b)
17485+#endif
17486+
17487 :"+m" (rw->lock) : : "memory");
17488 }
17489
17490 static inline void arch_write_unlock(arch_rwlock_t *rw)
17491 {
17492- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
17493+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
17494+
17495+#ifdef CONFIG_PAX_REFCOUNT
17496+ "jno 0f\n"
17497+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
17498+ "int $4\n0:\n"
17499+ _ASM_EXTABLE(0b, 0b)
17500+#endif
17501+
17502 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
17503 }
17504
17505diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
17506index 6a99859..03cb807 100644
17507--- a/arch/x86/include/asm/stackprotector.h
17508+++ b/arch/x86/include/asm/stackprotector.h
17509@@ -47,7 +47,7 @@
17510 * head_32 for boot CPU and setup_per_cpu_areas() for others.
17511 */
17512 #define GDT_STACK_CANARY_INIT \
17513- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
17514+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
17515
17516 /*
17517 * Initialize the stackprotector canary value.
17518@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
17519
17520 static inline void load_stack_canary_segment(void)
17521 {
17522-#ifdef CONFIG_X86_32
17523+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
17524 asm volatile ("mov %0, %%gs" : : "r" (0));
17525 #endif
17526 }
17527diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
17528index 70bbe39..4ae2bd4 100644
17529--- a/arch/x86/include/asm/stacktrace.h
17530+++ b/arch/x86/include/asm/stacktrace.h
17531@@ -11,28 +11,20 @@
17532
17533 extern int kstack_depth_to_print;
17534
17535-struct thread_info;
17536+struct task_struct;
17537 struct stacktrace_ops;
17538
17539-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
17540- unsigned long *stack,
17541- unsigned long bp,
17542- const struct stacktrace_ops *ops,
17543- void *data,
17544- unsigned long *end,
17545- int *graph);
17546+typedef unsigned long walk_stack_t(struct task_struct *task,
17547+ void *stack_start,
17548+ unsigned long *stack,
17549+ unsigned long bp,
17550+ const struct stacktrace_ops *ops,
17551+ void *data,
17552+ unsigned long *end,
17553+ int *graph);
17554
17555-extern unsigned long
17556-print_context_stack(struct thread_info *tinfo,
17557- unsigned long *stack, unsigned long bp,
17558- const struct stacktrace_ops *ops, void *data,
17559- unsigned long *end, int *graph);
17560-
17561-extern unsigned long
17562-print_context_stack_bp(struct thread_info *tinfo,
17563- unsigned long *stack, unsigned long bp,
17564- const struct stacktrace_ops *ops, void *data,
17565- unsigned long *end, int *graph);
17566+extern walk_stack_t print_context_stack;
17567+extern walk_stack_t print_context_stack_bp;
17568
17569 /* Generic stack tracer with callbacks */
17570
17571@@ -40,7 +32,7 @@ struct stacktrace_ops {
17572 void (*address)(void *data, unsigned long address, int reliable);
17573 /* On negative return stop dumping */
17574 int (*stack)(void *data, char *name);
17575- walk_stack_t walk_stack;
17576+ walk_stack_t *walk_stack;
17577 };
17578
17579 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
17580diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
17581index 4ec45b3..a4f0a8a 100644
17582--- a/arch/x86/include/asm/switch_to.h
17583+++ b/arch/x86/include/asm/switch_to.h
17584@@ -108,7 +108,7 @@ do { \
17585 "call __switch_to\n\t" \
17586 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
17587 __switch_canary \
17588- "movq %P[thread_info](%%rsi),%%r8\n\t" \
17589+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
17590 "movq %%rax,%%rdi\n\t" \
17591 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
17592 "jnz ret_from_fork\n\t" \
17593@@ -119,7 +119,7 @@ do { \
17594 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
17595 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
17596 [_tif_fork] "i" (_TIF_FORK), \
17597- [thread_info] "i" (offsetof(struct task_struct, stack)), \
17598+ [thread_info] "m" (current_tinfo), \
17599 [current_task] "m" (current_task) \
17600 __switch_canary_iparam \
17601 : "memory", "cc" __EXTRA_CLOBBER)
17602diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
17603index 2781119..618b59b 100644
17604--- a/arch/x86/include/asm/thread_info.h
17605+++ b/arch/x86/include/asm/thread_info.h
17606@@ -10,6 +10,7 @@
17607 #include <linux/compiler.h>
17608 #include <asm/page.h>
17609 #include <asm/types.h>
17610+#include <asm/percpu.h>
17611
17612 /*
17613 * low level task data that entry.S needs immediate access to
17614@@ -23,7 +24,6 @@ struct exec_domain;
17615 #include <linux/atomic.h>
17616
17617 struct thread_info {
17618- struct task_struct *task; /* main task structure */
17619 struct exec_domain *exec_domain; /* execution domain */
17620 __u32 flags; /* low level flags */
17621 __u32 status; /* thread synchronous flags */
17622@@ -33,19 +33,13 @@ struct thread_info {
17623 mm_segment_t addr_limit;
17624 struct restart_block restart_block;
17625 void __user *sysenter_return;
17626-#ifdef CONFIG_X86_32
17627- unsigned long previous_esp; /* ESP of the previous stack in
17628- case of nested (IRQ) stacks
17629- */
17630- __u8 supervisor_stack[0];
17631-#endif
17632+ unsigned long lowest_stack;
17633 unsigned int sig_on_uaccess_error:1;
17634 unsigned int uaccess_err:1; /* uaccess failed */
17635 };
17636
17637-#define INIT_THREAD_INFO(tsk) \
17638+#define INIT_THREAD_INFO \
17639 { \
17640- .task = &tsk, \
17641 .exec_domain = &default_exec_domain, \
17642 .flags = 0, \
17643 .cpu = 0, \
17644@@ -56,7 +50,7 @@ struct thread_info {
17645 }, \
17646 }
17647
17648-#define init_thread_info (init_thread_union.thread_info)
17649+#define init_thread_info (init_thread_union.stack)
17650 #define init_stack (init_thread_union.stack)
17651
17652 #else /* !__ASSEMBLY__ */
17653@@ -96,6 +90,7 @@ struct thread_info {
17654 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
17655 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
17656 #define TIF_X32 30 /* 32-bit native x86-64 binary */
17657+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
17658
17659 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
17660 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
17661@@ -119,17 +114,18 @@ struct thread_info {
17662 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
17663 #define _TIF_ADDR32 (1 << TIF_ADDR32)
17664 #define _TIF_X32 (1 << TIF_X32)
17665+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
17666
17667 /* work to do in syscall_trace_enter() */
17668 #define _TIF_WORK_SYSCALL_ENTRY \
17669 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
17670 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
17671- _TIF_NOHZ)
17672+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
17673
17674 /* work to do in syscall_trace_leave() */
17675 #define _TIF_WORK_SYSCALL_EXIT \
17676 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
17677- _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
17678+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
17679
17680 /* work to do on interrupt/exception return */
17681 #define _TIF_WORK_MASK \
17682@@ -140,7 +136,7 @@ struct thread_info {
17683 /* work to do on any return to user space */
17684 #define _TIF_ALLWORK_MASK \
17685 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
17686- _TIF_NOHZ)
17687+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
17688
17689 /* Only used for 64 bit */
17690 #define _TIF_DO_NOTIFY_MASK \
17691@@ -156,45 +152,40 @@ struct thread_info {
17692
17693 #define PREEMPT_ACTIVE 0x10000000
17694
17695-#ifdef CONFIG_X86_32
17696-
17697-#define STACK_WARN (THREAD_SIZE/8)
17698-/*
17699- * macros/functions for gaining access to the thread information structure
17700- *
17701- * preempt_count needs to be 1 initially, until the scheduler is functional.
17702- */
17703-#ifndef __ASSEMBLY__
17704-
17705-
17706-/* how to get the current stack pointer from C */
17707-register unsigned long current_stack_pointer asm("esp") __used;
17708-
17709-/* how to get the thread information struct from C */
17710-static inline struct thread_info *current_thread_info(void)
17711-{
17712- return (struct thread_info *)
17713- (current_stack_pointer & ~(THREAD_SIZE - 1));
17714-}
17715-
17716-#else /* !__ASSEMBLY__ */
17717-
17718+#ifdef __ASSEMBLY__
17719 /* how to get the thread information struct from ASM */
17720 #define GET_THREAD_INFO(reg) \
17721- movl $-THREAD_SIZE, reg; \
17722- andl %esp, reg
17723+ mov PER_CPU_VAR(current_tinfo), reg
17724
17725 /* use this one if reg already contains %esp */
17726-#define GET_THREAD_INFO_WITH_ESP(reg) \
17727- andl $-THREAD_SIZE, reg
17728+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
17729+#else
17730+/* how to get the thread information struct from C */
17731+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
17732+
17733+static __always_inline struct thread_info *current_thread_info(void)
17734+{
17735+ return this_cpu_read_stable(current_tinfo);
17736+}
17737+#endif
17738+
17739+#ifdef CONFIG_X86_32
17740+
17741+#define STACK_WARN (THREAD_SIZE/8)
17742+/*
17743+ * macros/functions for gaining access to the thread information structure
17744+ *
17745+ * preempt_count needs to be 1 initially, until the scheduler is functional.
17746+ */
17747+#ifndef __ASSEMBLY__
17748+
17749+/* how to get the current stack pointer from C */
17750+register unsigned long current_stack_pointer asm("esp") __used;
17751
17752 #endif
17753
17754 #else /* X86_32 */
17755
17756-#include <asm/percpu.h>
17757-#define KERNEL_STACK_OFFSET (5*8)
17758-
17759 /*
17760 * macros/functions for gaining access to the thread information structure
17761 * preempt_count needs to be 1 initially, until the scheduler is functional.
17762@@ -202,27 +193,8 @@ static inline struct thread_info *current_thread_info(void)
17763 #ifndef __ASSEMBLY__
17764 DECLARE_PER_CPU(unsigned long, kernel_stack);
17765
17766-static inline struct thread_info *current_thread_info(void)
17767-{
17768- struct thread_info *ti;
17769- ti = (void *)(this_cpu_read_stable(kernel_stack) +
17770- KERNEL_STACK_OFFSET - THREAD_SIZE);
17771- return ti;
17772-}
17773-
17774-#else /* !__ASSEMBLY__ */
17775-
17776-/* how to get the thread information struct from ASM */
17777-#define GET_THREAD_INFO(reg) \
17778- movq PER_CPU_VAR(kernel_stack),reg ; \
17779- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
17780-
17781-/*
17782- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
17783- * a certain register (to be used in assembler memory operands).
17784- */
17785-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
17786-
17787+/* how to get the current stack pointer from C */
17788+register unsigned long current_stack_pointer asm("rsp") __used;
17789 #endif
17790
17791 #endif /* !X86_32 */
17792@@ -281,5 +253,12 @@ static inline bool is_ia32_task(void)
17793 extern void arch_task_cache_init(void);
17794 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
17795 extern void arch_release_task_struct(struct task_struct *tsk);
17796+
17797+#define __HAVE_THREAD_FUNCTIONS
17798+#define task_thread_info(task) (&(task)->tinfo)
17799+#define task_stack_page(task) ((task)->stack)
17800+#define setup_thread_stack(p, org) do {} while (0)
17801+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
17802+
17803 #endif
17804 #endif /* _ASM_X86_THREAD_INFO_H */
17805diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
17806index cf51200..63ff068 100644
17807--- a/arch/x86/include/asm/tlbflush.h
17808+++ b/arch/x86/include/asm/tlbflush.h
17809@@ -17,18 +17,44 @@
17810
17811 static inline void __native_flush_tlb(void)
17812 {
17813+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
17814+ u64 descriptor[2];
17815+
17816+ descriptor[0] = PCID_KERNEL;
17817+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_MONGLOBAL) : "memory");
17818+ return;
17819+ }
17820+
17821+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17822+ if (static_cpu_has(X86_FEATURE_PCID)) {
17823+ unsigned int cpu = raw_get_cpu();
17824+
17825+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17826+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17827+ raw_put_cpu_no_resched();
17828+ return;
17829+ }
17830+#endif
17831+
17832 native_write_cr3(native_read_cr3());
17833 }
17834
17835 static inline void __native_flush_tlb_global_irq_disabled(void)
17836 {
17837- unsigned long cr4;
17838+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
17839+ u64 descriptor[2];
17840
17841- cr4 = native_read_cr4();
17842- /* clear PGE */
17843- native_write_cr4(cr4 & ~X86_CR4_PGE);
17844- /* write old PGE again and flush TLBs */
17845- native_write_cr4(cr4);
17846+ descriptor[0] = PCID_KERNEL;
17847+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_GLOBAL) : "memory");
17848+ } else {
17849+ unsigned long cr4;
17850+
17851+ cr4 = native_read_cr4();
17852+ /* clear PGE */
17853+ native_write_cr4(cr4 & ~X86_CR4_PGE);
17854+ /* write old PGE again and flush TLBs */
17855+ native_write_cr4(cr4);
17856+ }
17857 }
17858
17859 static inline void __native_flush_tlb_global(void)
17860@@ -49,6 +75,42 @@ static inline void __native_flush_tlb_global(void)
17861
17862 static inline void __native_flush_tlb_single(unsigned long addr)
17863 {
17864+
17865+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
17866+ u64 descriptor[2];
17867+
17868+ descriptor[0] = PCID_KERNEL;
17869+ descriptor[1] = addr;
17870+
17871+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17872+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) || addr >= TASK_SIZE_MAX) {
17873+ if (addr < TASK_SIZE_MAX)
17874+ descriptor[1] += pax_user_shadow_base;
17875+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
17876+ }
17877+
17878+ descriptor[0] = PCID_USER;
17879+ descriptor[1] = addr;
17880+#endif
17881+
17882+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
17883+ return;
17884+ }
17885+
17886+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17887+ if (static_cpu_has(X86_FEATURE_PCID)) {
17888+ unsigned int cpu = raw_get_cpu();
17889+
17890+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
17891+ asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
17892+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17893+ raw_put_cpu_no_resched();
17894+
17895+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) && addr < TASK_SIZE_MAX)
17896+ addr += pax_user_shadow_base;
17897+ }
17898+#endif
17899+
17900 asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
17901 }
17902
17903diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
17904index 5ee2687..74590b9 100644
17905--- a/arch/x86/include/asm/uaccess.h
17906+++ b/arch/x86/include/asm/uaccess.h
17907@@ -7,6 +7,7 @@
17908 #include <linux/compiler.h>
17909 #include <linux/thread_info.h>
17910 #include <linux/string.h>
17911+#include <linux/sched.h>
17912 #include <asm/asm.h>
17913 #include <asm/page.h>
17914 #include <asm/smap.h>
17915@@ -29,7 +30,12 @@
17916
17917 #define get_ds() (KERNEL_DS)
17918 #define get_fs() (current_thread_info()->addr_limit)
17919+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
17920+void __set_fs(mm_segment_t x);
17921+void set_fs(mm_segment_t x);
17922+#else
17923 #define set_fs(x) (current_thread_info()->addr_limit = (x))
17924+#endif
17925
17926 #define segment_eq(a, b) ((a).seg == (b).seg)
17927
17928@@ -77,8 +83,33 @@
17929 * checks that the pointer is in the user space range - after calling
17930 * this function, memory access functions may still return -EFAULT.
17931 */
17932-#define access_ok(type, addr, size) \
17933- (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
17934+#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
17935+#define access_ok(type, addr, size) \
17936+({ \
17937+ long __size = size; \
17938+ unsigned long __addr = (unsigned long)addr; \
17939+ unsigned long __addr_ao = __addr & PAGE_MASK; \
17940+ unsigned long __end_ao = __addr + __size - 1; \
17941+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
17942+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
17943+ while(__addr_ao <= __end_ao) { \
17944+ char __c_ao; \
17945+ __addr_ao += PAGE_SIZE; \
17946+ if (__size > PAGE_SIZE) \
17947+ cond_resched(); \
17948+ if (__get_user(__c_ao, (char __user *)__addr)) \
17949+ break; \
17950+ if (type != VERIFY_WRITE) { \
17951+ __addr = __addr_ao; \
17952+ continue; \
17953+ } \
17954+ if (__put_user(__c_ao, (char __user *)__addr)) \
17955+ break; \
17956+ __addr = __addr_ao; \
17957+ } \
17958+ } \
17959+ __ret_ao; \
17960+})
17961
17962 /*
17963 * The exception table consists of pairs of addresses relative to the
17964@@ -165,10 +196,12 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
17965 register __inttype(*(ptr)) __val_gu asm("%edx"); \
17966 __chk_user_ptr(ptr); \
17967 might_fault(); \
17968+ pax_open_userland(); \
17969 asm volatile("call __get_user_%P3" \
17970 : "=a" (__ret_gu), "=r" (__val_gu) \
17971 : "0" (ptr), "i" (sizeof(*(ptr)))); \
17972 (x) = (__typeof__(*(ptr))) __val_gu; \
17973+ pax_close_userland(); \
17974 __ret_gu; \
17975 })
17976
17977@@ -176,13 +209,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
17978 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
17979 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
17980
17981-
17982+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
17983+#define __copyuser_seg "gs;"
17984+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
17985+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
17986+#else
17987+#define __copyuser_seg
17988+#define __COPYUSER_SET_ES
17989+#define __COPYUSER_RESTORE_ES
17990+#endif
17991
17992 #ifdef CONFIG_X86_32
17993 #define __put_user_asm_u64(x, addr, err, errret) \
17994 asm volatile(ASM_STAC "\n" \
17995- "1: movl %%eax,0(%2)\n" \
17996- "2: movl %%edx,4(%2)\n" \
17997+ "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
17998+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
17999 "3: " ASM_CLAC "\n" \
18000 ".section .fixup,\"ax\"\n" \
18001 "4: movl %3,%0\n" \
18002@@ -195,8 +236,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
18003
18004 #define __put_user_asm_ex_u64(x, addr) \
18005 asm volatile(ASM_STAC "\n" \
18006- "1: movl %%eax,0(%1)\n" \
18007- "2: movl %%edx,4(%1)\n" \
18008+ "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
18009+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
18010 "3: " ASM_CLAC "\n" \
18011 _ASM_EXTABLE_EX(1b, 2b) \
18012 _ASM_EXTABLE_EX(2b, 3b) \
18013@@ -246,7 +287,8 @@ extern void __put_user_8(void);
18014 __typeof__(*(ptr)) __pu_val; \
18015 __chk_user_ptr(ptr); \
18016 might_fault(); \
18017- __pu_val = x; \
18018+ __pu_val = (x); \
18019+ pax_open_userland(); \
18020 switch (sizeof(*(ptr))) { \
18021 case 1: \
18022 __put_user_x(1, __pu_val, ptr, __ret_pu); \
18023@@ -264,6 +306,7 @@ extern void __put_user_8(void);
18024 __put_user_x(X, __pu_val, ptr, __ret_pu); \
18025 break; \
18026 } \
18027+ pax_close_userland(); \
18028 __ret_pu; \
18029 })
18030
18031@@ -344,8 +387,10 @@ do { \
18032 } while (0)
18033
18034 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
18035+do { \
18036+ pax_open_userland(); \
18037 asm volatile(ASM_STAC "\n" \
18038- "1: mov"itype" %2,%"rtype"1\n" \
18039+ "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
18040 "2: " ASM_CLAC "\n" \
18041 ".section .fixup,\"ax\"\n" \
18042 "3: mov %3,%0\n" \
18043@@ -353,8 +398,10 @@ do { \
18044 " jmp 2b\n" \
18045 ".previous\n" \
18046 _ASM_EXTABLE(1b, 3b) \
18047- : "=r" (err), ltype(x) \
18048- : "m" (__m(addr)), "i" (errret), "0" (err))
18049+ : "=r" (err), ltype (x) \
18050+ : "m" (__m(addr)), "i" (errret), "0" (err)); \
18051+ pax_close_userland(); \
18052+} while (0)
18053
18054 #define __get_user_size_ex(x, ptr, size) \
18055 do { \
18056@@ -378,7 +425,7 @@ do { \
18057 } while (0)
18058
18059 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
18060- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
18061+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
18062 "2:\n" \
18063 _ASM_EXTABLE_EX(1b, 2b) \
18064 : ltype(x) : "m" (__m(addr)))
18065@@ -395,13 +442,24 @@ do { \
18066 int __gu_err; \
18067 unsigned long __gu_val; \
18068 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
18069- (x) = (__force __typeof__(*(ptr)))__gu_val; \
18070+ (x) = (__typeof__(*(ptr)))__gu_val; \
18071 __gu_err; \
18072 })
18073
18074 /* FIXME: this hack is definitely wrong -AK */
18075 struct __large_struct { unsigned long buf[100]; };
18076-#define __m(x) (*(struct __large_struct __user *)(x))
18077+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18078+#define ____m(x) \
18079+({ \
18080+ unsigned long ____x = (unsigned long)(x); \
18081+ if (____x < pax_user_shadow_base) \
18082+ ____x += pax_user_shadow_base; \
18083+ (typeof(x))____x; \
18084+})
18085+#else
18086+#define ____m(x) (x)
18087+#endif
18088+#define __m(x) (*(struct __large_struct __user *)____m(x))
18089
18090 /*
18091 * Tell gcc we read from memory instead of writing: this is because
18092@@ -409,8 +467,10 @@ struct __large_struct { unsigned long buf[100]; };
18093 * aliasing issues.
18094 */
18095 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
18096+do { \
18097+ pax_open_userland(); \
18098 asm volatile(ASM_STAC "\n" \
18099- "1: mov"itype" %"rtype"1,%2\n" \
18100+ "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
18101 "2: " ASM_CLAC "\n" \
18102 ".section .fixup,\"ax\"\n" \
18103 "3: mov %3,%0\n" \
18104@@ -418,10 +478,12 @@ struct __large_struct { unsigned long buf[100]; };
18105 ".previous\n" \
18106 _ASM_EXTABLE(1b, 3b) \
18107 : "=r"(err) \
18108- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
18109+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err));\
18110+ pax_close_userland(); \
18111+} while (0)
18112
18113 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
18114- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
18115+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
18116 "2:\n" \
18117 _ASM_EXTABLE_EX(1b, 2b) \
18118 : : ltype(x), "m" (__m(addr)))
18119@@ -431,11 +493,13 @@ struct __large_struct { unsigned long buf[100]; };
18120 */
18121 #define uaccess_try do { \
18122 current_thread_info()->uaccess_err = 0; \
18123+ pax_open_userland(); \
18124 stac(); \
18125 barrier();
18126
18127 #define uaccess_catch(err) \
18128 clac(); \
18129+ pax_close_userland(); \
18130 (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
18131 } while (0)
18132
18133@@ -460,8 +524,12 @@ struct __large_struct { unsigned long buf[100]; };
18134 * On error, the variable @x is set to zero.
18135 */
18136
18137+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18138+#define __get_user(x, ptr) get_user((x), (ptr))
18139+#else
18140 #define __get_user(x, ptr) \
18141 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
18142+#endif
18143
18144 /**
18145 * __put_user: - Write a simple value into user space, with less checking.
18146@@ -483,8 +551,12 @@ struct __large_struct { unsigned long buf[100]; };
18147 * Returns zero on success, or -EFAULT on error.
18148 */
18149
18150+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18151+#define __put_user(x, ptr) put_user((x), (ptr))
18152+#else
18153 #define __put_user(x, ptr) \
18154 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
18155+#endif
18156
18157 #define __get_user_unaligned __get_user
18158 #define __put_user_unaligned __put_user
18159@@ -502,7 +574,7 @@ struct __large_struct { unsigned long buf[100]; };
18160 #define get_user_ex(x, ptr) do { \
18161 unsigned long __gue_val; \
18162 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
18163- (x) = (__force __typeof__(*(ptr)))__gue_val; \
18164+ (x) = (__typeof__(*(ptr)))__gue_val; \
18165 } while (0)
18166
18167 #define put_user_try uaccess_try
18168@@ -519,8 +591,8 @@ strncpy_from_user(char *dst, const char __user *src, long count);
18169 extern __must_check long strlen_user(const char __user *str);
18170 extern __must_check long strnlen_user(const char __user *str, long n);
18171
18172-unsigned long __must_check clear_user(void __user *mem, unsigned long len);
18173-unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
18174+unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
18175+unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
18176
18177 /*
18178 * movsl can be slow when source and dest are not both 8-byte aligned
18179diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
18180index 7f760a9..04b1c65 100644
18181--- a/arch/x86/include/asm/uaccess_32.h
18182+++ b/arch/x86/include/asm/uaccess_32.h
18183@@ -11,15 +11,15 @@
18184 #include <asm/page.h>
18185
18186 unsigned long __must_check __copy_to_user_ll
18187- (void __user *to, const void *from, unsigned long n);
18188+ (void __user *to, const void *from, unsigned long n) __size_overflow(3);
18189 unsigned long __must_check __copy_from_user_ll
18190- (void *to, const void __user *from, unsigned long n);
18191+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
18192 unsigned long __must_check __copy_from_user_ll_nozero
18193- (void *to, const void __user *from, unsigned long n);
18194+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
18195 unsigned long __must_check __copy_from_user_ll_nocache
18196- (void *to, const void __user *from, unsigned long n);
18197+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
18198 unsigned long __must_check __copy_from_user_ll_nocache_nozero
18199- (void *to, const void __user *from, unsigned long n);
18200+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
18201
18202 /**
18203 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
18204@@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
18205 static __always_inline unsigned long __must_check
18206 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
18207 {
18208+ if ((long)n < 0)
18209+ return n;
18210+
18211+ check_object_size(from, n, true);
18212+
18213 if (__builtin_constant_p(n)) {
18214 unsigned long ret;
18215
18216@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
18217 __copy_to_user(void __user *to, const void *from, unsigned long n)
18218 {
18219 might_fault();
18220+
18221 return __copy_to_user_inatomic(to, from, n);
18222 }
18223
18224 static __always_inline unsigned long
18225 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
18226 {
18227+ if ((long)n < 0)
18228+ return n;
18229+
18230 /* Avoid zeroing the tail if the copy fails..
18231 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
18232 * but as the zeroing behaviour is only significant when n is not
18233@@ -137,6 +146,12 @@ static __always_inline unsigned long
18234 __copy_from_user(void *to, const void __user *from, unsigned long n)
18235 {
18236 might_fault();
18237+
18238+ if ((long)n < 0)
18239+ return n;
18240+
18241+ check_object_size(to, n, false);
18242+
18243 if (__builtin_constant_p(n)) {
18244 unsigned long ret;
18245
18246@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
18247 const void __user *from, unsigned long n)
18248 {
18249 might_fault();
18250+
18251+ if ((long)n < 0)
18252+ return n;
18253+
18254 if (__builtin_constant_p(n)) {
18255 unsigned long ret;
18256
18257@@ -181,15 +200,19 @@ static __always_inline unsigned long
18258 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
18259 unsigned long n)
18260 {
18261- return __copy_from_user_ll_nocache_nozero(to, from, n);
18262+ if ((long)n < 0)
18263+ return n;
18264+
18265+ return __copy_from_user_ll_nocache_nozero(to, from, n);
18266 }
18267
18268-unsigned long __must_check copy_to_user(void __user *to,
18269- const void *from, unsigned long n);
18270-unsigned long __must_check _copy_from_user(void *to,
18271- const void __user *from,
18272- unsigned long n);
18273-
18274+extern void copy_to_user_overflow(void)
18275+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
18276+ __compiletime_error("copy_to_user() buffer size is not provably correct")
18277+#else
18278+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
18279+#endif
18280+;
18281
18282 extern void copy_from_user_overflow(void)
18283 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
18284@@ -199,17 +222,60 @@ extern void copy_from_user_overflow(void)
18285 #endif
18286 ;
18287
18288-static inline unsigned long __must_check copy_from_user(void *to,
18289- const void __user *from,
18290- unsigned long n)
18291+/**
18292+ * copy_to_user: - Copy a block of data into user space.
18293+ * @to: Destination address, in user space.
18294+ * @from: Source address, in kernel space.
18295+ * @n: Number of bytes to copy.
18296+ *
18297+ * Context: User context only. This function may sleep.
18298+ *
18299+ * Copy data from kernel space to user space.
18300+ *
18301+ * Returns number of bytes that could not be copied.
18302+ * On success, this will be zero.
18303+ */
18304+static inline unsigned long __must_check
18305+copy_to_user(void __user *to, const void *from, unsigned long n)
18306 {
18307- int sz = __compiletime_object_size(to);
18308+ size_t sz = __compiletime_object_size(from);
18309
18310- if (likely(sz == -1 || sz >= n))
18311- n = _copy_from_user(to, from, n);
18312- else
18313+ if (unlikely(sz != (size_t)-1 && sz < n))
18314+ copy_to_user_overflow();
18315+ else if (access_ok(VERIFY_WRITE, to, n))
18316+ n = __copy_to_user(to, from, n);
18317+ return n;
18318+}
18319+
18320+/**
18321+ * copy_from_user: - Copy a block of data from user space.
18322+ * @to: Destination address, in kernel space.
18323+ * @from: Source address, in user space.
18324+ * @n: Number of bytes to copy.
18325+ *
18326+ * Context: User context only. This function may sleep.
18327+ *
18328+ * Copy data from user space to kernel space.
18329+ *
18330+ * Returns number of bytes that could not be copied.
18331+ * On success, this will be zero.
18332+ *
18333+ * If some data could not be copied, this function will pad the copied
18334+ * data to the requested size using zero bytes.
18335+ */
18336+static inline unsigned long __must_check
18337+copy_from_user(void *to, const void __user *from, unsigned long n)
18338+{
18339+ size_t sz = __compiletime_object_size(to);
18340+
18341+ check_object_size(to, n, false);
18342+
18343+ if (unlikely(sz != (size_t)-1 && sz < n))
18344 copy_from_user_overflow();
18345-
18346+ else if (access_ok(VERIFY_READ, from, n))
18347+ n = __copy_from_user(to, from, n);
18348+ else if ((long)n > 0)
18349+ memset(to, 0, n);
18350 return n;
18351 }
18352
18353diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
18354index 4f7923d..20cb24e 100644
18355--- a/arch/x86/include/asm/uaccess_64.h
18356+++ b/arch/x86/include/asm/uaccess_64.h
18357@@ -10,6 +10,9 @@
18358 #include <asm/alternative.h>
18359 #include <asm/cpufeature.h>
18360 #include <asm/page.h>
18361+#include <asm/pgtable.h>
18362+
18363+#define set_fs(x) (current_thread_info()->addr_limit = (x))
18364
18365 /*
18366 * Copy To/From Userspace
18367@@ -17,13 +20,13 @@
18368
18369 /* Handles exceptions in both to and from, but doesn't do access_ok */
18370 __must_check unsigned long
18371-copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
18372+copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
18373 __must_check unsigned long
18374-copy_user_generic_string(void *to, const void *from, unsigned len);
18375+copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
18376 __must_check unsigned long
18377-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
18378+copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
18379
18380-static __always_inline __must_check unsigned long
18381+static __always_inline __must_check __size_overflow(3) unsigned long
18382 copy_user_generic(void *to, const void *from, unsigned len)
18383 {
18384 unsigned ret;
18385@@ -41,142 +44,204 @@ copy_user_generic(void *to, const void *from, unsigned len)
18386 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
18387 "=d" (len)),
18388 "1" (to), "2" (from), "3" (len)
18389- : "memory", "rcx", "r8", "r9", "r10", "r11");
18390+ : "memory", "rcx", "r8", "r9", "r11");
18391 return ret;
18392 }
18393
18394+static __always_inline __must_check unsigned long
18395+__copy_to_user(void __user *to, const void *from, unsigned long len);
18396+static __always_inline __must_check unsigned long
18397+__copy_from_user(void *to, const void __user *from, unsigned long len);
18398 __must_check unsigned long
18399-_copy_to_user(void __user *to, const void *from, unsigned len);
18400-__must_check unsigned long
18401-_copy_from_user(void *to, const void __user *from, unsigned len);
18402-__must_check unsigned long
18403-copy_in_user(void __user *to, const void __user *from, unsigned len);
18404+copy_in_user(void __user *to, const void __user *from, unsigned long len);
18405+
18406+extern void copy_to_user_overflow(void)
18407+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
18408+ __compiletime_error("copy_to_user() buffer size is not provably correct")
18409+#else
18410+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
18411+#endif
18412+;
18413+
18414+extern void copy_from_user_overflow(void)
18415+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
18416+ __compiletime_error("copy_from_user() buffer size is not provably correct")
18417+#else
18418+ __compiletime_warning("copy_from_user() buffer size is not provably correct")
18419+#endif
18420+;
18421
18422 static inline unsigned long __must_check copy_from_user(void *to,
18423 const void __user *from,
18424 unsigned long n)
18425 {
18426- int sz = __compiletime_object_size(to);
18427-
18428 might_fault();
18429- if (likely(sz == -1 || sz >= n))
18430- n = _copy_from_user(to, from, n);
18431-#ifdef CONFIG_DEBUG_VM
18432- else
18433- WARN(1, "Buffer overflow detected!\n");
18434-#endif
18435+
18436+ check_object_size(to, n, false);
18437+
18438+ if (access_ok(VERIFY_READ, from, n))
18439+ n = __copy_from_user(to, from, n);
18440+ else if (n < INT_MAX)
18441+ memset(to, 0, n);
18442 return n;
18443 }
18444
18445 static __always_inline __must_check
18446-int copy_to_user(void __user *dst, const void *src, unsigned size)
18447+int copy_to_user(void __user *dst, const void *src, unsigned long size)
18448 {
18449 might_fault();
18450
18451- return _copy_to_user(dst, src, size);
18452+ if (access_ok(VERIFY_WRITE, dst, size))
18453+ size = __copy_to_user(dst, src, size);
18454+ return size;
18455 }
18456
18457 static __always_inline __must_check
18458-int __copy_from_user(void *dst, const void __user *src, unsigned size)
18459+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
18460 {
18461- int ret = 0;
18462+ size_t sz = __compiletime_object_size(dst);
18463+ unsigned ret = 0;
18464
18465 might_fault();
18466+
18467+ if (size > INT_MAX)
18468+ return size;
18469+
18470+ check_object_size(dst, size, false);
18471+
18472+#ifdef CONFIG_PAX_MEMORY_UDEREF
18473+ if (!__access_ok(VERIFY_READ, src, size))
18474+ return size;
18475+#endif
18476+
18477+ if (unlikely(sz != (size_t)-1 && sz < size)) {
18478+ copy_from_user_overflow();
18479+ return size;
18480+ }
18481+
18482 if (!__builtin_constant_p(size))
18483- return copy_user_generic(dst, (__force void *)src, size);
18484+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
18485 switch (size) {
18486- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
18487+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
18488 ret, "b", "b", "=q", 1);
18489 return ret;
18490- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
18491+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
18492 ret, "w", "w", "=r", 2);
18493 return ret;
18494- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
18495+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
18496 ret, "l", "k", "=r", 4);
18497 return ret;
18498- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
18499+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
18500 ret, "q", "", "=r", 8);
18501 return ret;
18502 case 10:
18503- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
18504+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
18505 ret, "q", "", "=r", 10);
18506 if (unlikely(ret))
18507 return ret;
18508 __get_user_asm(*(u16 *)(8 + (char *)dst),
18509- (u16 __user *)(8 + (char __user *)src),
18510+ (const u16 __user *)(8 + (const char __user *)src),
18511 ret, "w", "w", "=r", 2);
18512 return ret;
18513 case 16:
18514- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
18515+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
18516 ret, "q", "", "=r", 16);
18517 if (unlikely(ret))
18518 return ret;
18519 __get_user_asm(*(u64 *)(8 + (char *)dst),
18520- (u64 __user *)(8 + (char __user *)src),
18521+ (const u64 __user *)(8 + (const char __user *)src),
18522 ret, "q", "", "=r", 8);
18523 return ret;
18524 default:
18525- return copy_user_generic(dst, (__force void *)src, size);
18526+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
18527 }
18528 }
18529
18530 static __always_inline __must_check
18531-int __copy_to_user(void __user *dst, const void *src, unsigned size)
18532+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
18533 {
18534- int ret = 0;
18535+ size_t sz = __compiletime_object_size(src);
18536+ unsigned ret = 0;
18537
18538 might_fault();
18539+
18540+ if (size > INT_MAX)
18541+ return size;
18542+
18543+ check_object_size(src, size, true);
18544+
18545+#ifdef CONFIG_PAX_MEMORY_UDEREF
18546+ if (!__access_ok(VERIFY_WRITE, dst, size))
18547+ return size;
18548+#endif
18549+
18550+ if (unlikely(sz != (size_t)-1 && sz < size)) {
18551+ copy_to_user_overflow();
18552+ return size;
18553+ }
18554+
18555 if (!__builtin_constant_p(size))
18556- return copy_user_generic((__force void *)dst, src, size);
18557+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
18558 switch (size) {
18559- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
18560+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
18561 ret, "b", "b", "iq", 1);
18562 return ret;
18563- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
18564+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
18565 ret, "w", "w", "ir", 2);
18566 return ret;
18567- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
18568+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
18569 ret, "l", "k", "ir", 4);
18570 return ret;
18571- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
18572+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
18573 ret, "q", "", "er", 8);
18574 return ret;
18575 case 10:
18576- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
18577+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
18578 ret, "q", "", "er", 10);
18579 if (unlikely(ret))
18580 return ret;
18581 asm("":::"memory");
18582- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
18583+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
18584 ret, "w", "w", "ir", 2);
18585 return ret;
18586 case 16:
18587- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
18588+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
18589 ret, "q", "", "er", 16);
18590 if (unlikely(ret))
18591 return ret;
18592 asm("":::"memory");
18593- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
18594+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
18595 ret, "q", "", "er", 8);
18596 return ret;
18597 default:
18598- return copy_user_generic((__force void *)dst, src, size);
18599+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
18600 }
18601 }
18602
18603 static __always_inline __must_check
18604-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
18605+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
18606 {
18607- int ret = 0;
18608+ unsigned ret = 0;
18609
18610 might_fault();
18611+
18612+ if (size > INT_MAX)
18613+ return size;
18614+
18615+#ifdef CONFIG_PAX_MEMORY_UDEREF
18616+ if (!__access_ok(VERIFY_READ, src, size))
18617+ return size;
18618+ if (!__access_ok(VERIFY_WRITE, dst, size))
18619+ return size;
18620+#endif
18621+
18622 if (!__builtin_constant_p(size))
18623- return copy_user_generic((__force void *)dst,
18624- (__force void *)src, size);
18625+ return copy_user_generic((__force_kernel void *)____m(dst),
18626+ (__force_kernel const void *)____m(src), size);
18627 switch (size) {
18628 case 1: {
18629 u8 tmp;
18630- __get_user_asm(tmp, (u8 __user *)src,
18631+ __get_user_asm(tmp, (const u8 __user *)src,
18632 ret, "b", "b", "=q", 1);
18633 if (likely(!ret))
18634 __put_user_asm(tmp, (u8 __user *)dst,
18635@@ -185,7 +250,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
18636 }
18637 case 2: {
18638 u16 tmp;
18639- __get_user_asm(tmp, (u16 __user *)src,
18640+ __get_user_asm(tmp, (const u16 __user *)src,
18641 ret, "w", "w", "=r", 2);
18642 if (likely(!ret))
18643 __put_user_asm(tmp, (u16 __user *)dst,
18644@@ -195,7 +260,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
18645
18646 case 4: {
18647 u32 tmp;
18648- __get_user_asm(tmp, (u32 __user *)src,
18649+ __get_user_asm(tmp, (const u32 __user *)src,
18650 ret, "l", "k", "=r", 4);
18651 if (likely(!ret))
18652 __put_user_asm(tmp, (u32 __user *)dst,
18653@@ -204,7 +269,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
18654 }
18655 case 8: {
18656 u64 tmp;
18657- __get_user_asm(tmp, (u64 __user *)src,
18658+ __get_user_asm(tmp, (const u64 __user *)src,
18659 ret, "q", "", "=r", 8);
18660 if (likely(!ret))
18661 __put_user_asm(tmp, (u64 __user *)dst,
18662@@ -212,41 +277,74 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
18663 return ret;
18664 }
18665 default:
18666- return copy_user_generic((__force void *)dst,
18667- (__force void *)src, size);
18668+ return copy_user_generic((__force_kernel void *)____m(dst),
18669+ (__force_kernel const void *)____m(src), size);
18670 }
18671 }
18672
18673-static __must_check __always_inline int
18674-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
18675+static __must_check __always_inline unsigned long
18676+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
18677 {
18678- return copy_user_generic(dst, (__force const void *)src, size);
18679+ if (size > INT_MAX)
18680+ return size;
18681+
18682+#ifdef CONFIG_PAX_MEMORY_UDEREF
18683+ if (!__access_ok(VERIFY_READ, src, size))
18684+ return size;
18685+#endif
18686+
18687+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
18688 }
18689
18690-static __must_check __always_inline int
18691-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
18692+static __must_check __always_inline unsigned long
18693+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
18694 {
18695- return copy_user_generic((__force void *)dst, src, size);
18696+ if (size > INT_MAX)
18697+ return size;
18698+
18699+#ifdef CONFIG_PAX_MEMORY_UDEREF
18700+ if (!__access_ok(VERIFY_WRITE, dst, size))
18701+ return size;
18702+#endif
18703+
18704+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
18705 }
18706
18707-extern long __copy_user_nocache(void *dst, const void __user *src,
18708- unsigned size, int zerorest);
18709+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
18710+ unsigned long size, int zerorest) __size_overflow(3);
18711
18712-static inline int
18713-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
18714+static inline unsigned long
18715+__copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
18716 {
18717 might_fault();
18718+
18719+ if (size > INT_MAX)
18720+ return size;
18721+
18722+#ifdef CONFIG_PAX_MEMORY_UDEREF
18723+ if (!__access_ok(VERIFY_READ, src, size))
18724+ return size;
18725+#endif
18726+
18727 return __copy_user_nocache(dst, src, size, 1);
18728 }
18729
18730-static inline int
18731+static inline unsigned long
18732 __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
18733- unsigned size)
18734+ unsigned long size)
18735 {
18736+ if (size > INT_MAX)
18737+ return size;
18738+
18739+#ifdef CONFIG_PAX_MEMORY_UDEREF
18740+ if (!__access_ok(VERIFY_READ, src, size))
18741+ return size;
18742+#endif
18743+
18744 return __copy_user_nocache(dst, src, size, 0);
18745 }
18746
18747 unsigned long
18748-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
18749+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
18750
18751 #endif /* _ASM_X86_UACCESS_64_H */
18752diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
18753index 5b238981..77fdd78 100644
18754--- a/arch/x86/include/asm/word-at-a-time.h
18755+++ b/arch/x86/include/asm/word-at-a-time.h
18756@@ -11,7 +11,7 @@
18757 * and shift, for example.
18758 */
18759 struct word_at_a_time {
18760- const unsigned long one_bits, high_bits;
18761+ unsigned long one_bits, high_bits;
18762 };
18763
18764 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
18765diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
18766index 828a156..650e625 100644
18767--- a/arch/x86/include/asm/x86_init.h
18768+++ b/arch/x86/include/asm/x86_init.h
18769@@ -129,7 +129,7 @@ struct x86_init_ops {
18770 struct x86_init_timers timers;
18771 struct x86_init_iommu iommu;
18772 struct x86_init_pci pci;
18773-};
18774+} __no_const;
18775
18776 /**
18777 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
18778@@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
18779 void (*setup_percpu_clockev)(void);
18780 void (*early_percpu_clock_init)(void);
18781 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
18782-};
18783+} __no_const;
18784
18785 struct timespec;
18786
18787@@ -168,7 +168,7 @@ struct x86_platform_ops {
18788 void (*save_sched_clock_state)(void);
18789 void (*restore_sched_clock_state)(void);
18790 void (*apic_post_init)(void);
18791-};
18792+} __no_const;
18793
18794 struct pci_dev;
18795 struct msi_msg;
18796@@ -182,7 +182,7 @@ struct x86_msi_ops {
18797 void (*teardown_msi_irqs)(struct pci_dev *dev);
18798 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
18799 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
18800-};
18801+} __no_const;
18802
18803 struct IO_APIC_route_entry;
18804 struct io_apic_irq_attr;
18805@@ -203,7 +203,7 @@ struct x86_io_apic_ops {
18806 unsigned int destination, int vector,
18807 struct io_apic_irq_attr *attr);
18808 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
18809-};
18810+} __no_const;
18811
18812 extern struct x86_init_ops x86_init;
18813 extern struct x86_cpuinit_ops x86_cpuinit;
18814diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
18815index 0415cda..3b22adc 100644
18816--- a/arch/x86/include/asm/xsave.h
18817+++ b/arch/x86/include/asm/xsave.h
18818@@ -70,8 +70,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
18819 if (unlikely(err))
18820 return -EFAULT;
18821
18822+ pax_open_userland();
18823 __asm__ __volatile__(ASM_STAC "\n"
18824- "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
18825+ "1:"
18826+ __copyuser_seg
18827+ ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
18828 "2: " ASM_CLAC "\n"
18829 ".section .fixup,\"ax\"\n"
18830 "3: movl $-1,%[err]\n"
18831@@ -81,18 +84,22 @@ static inline int xsave_user(struct xsave_struct __user *buf)
18832 : [err] "=r" (err)
18833 : "D" (buf), "a" (-1), "d" (-1), "0" (0)
18834 : "memory");
18835+ pax_close_userland();
18836 return err;
18837 }
18838
18839 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
18840 {
18841 int err;
18842- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
18843+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
18844 u32 lmask = mask;
18845 u32 hmask = mask >> 32;
18846
18847+ pax_open_userland();
18848 __asm__ __volatile__(ASM_STAC "\n"
18849- "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
18850+ "1:"
18851+ __copyuser_seg
18852+ ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
18853 "2: " ASM_CLAC "\n"
18854 ".section .fixup,\"ax\"\n"
18855 "3: movl $-1,%[err]\n"
18856@@ -102,6 +109,7 @@ static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
18857 : [err] "=r" (err)
18858 : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
18859 : "memory"); /* memory required? */
18860+ pax_close_userland();
18861 return err;
18862 }
18863
18864diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
18865index bbae024..e1528f9 100644
18866--- a/arch/x86/include/uapi/asm/e820.h
18867+++ b/arch/x86/include/uapi/asm/e820.h
18868@@ -63,7 +63,7 @@ struct e820map {
18869 #define ISA_START_ADDRESS 0xa0000
18870 #define ISA_END_ADDRESS 0x100000
18871
18872-#define BIOS_BEGIN 0x000a0000
18873+#define BIOS_BEGIN 0x000c0000
18874 #define BIOS_END 0x00100000
18875
18876 #define BIOS_ROM_BASE 0xffe00000
18877diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
18878index 88d99ea..9fc7e17 100644
18879--- a/arch/x86/kernel/Makefile
18880+++ b/arch/x86/kernel/Makefile
18881@@ -24,7 +24,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
18882 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
18883 obj-$(CONFIG_IRQ_WORK) += irq_work.o
18884 obj-y += probe_roms.o
18885-obj-$(CONFIG_X86_32) += i386_ksyms_32.o
18886+obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
18887 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
18888 obj-y += syscall_$(BITS).o
18889 obj-$(CONFIG_X86_64) += vsyscall_64.o
18890diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
18891index 2627a81..cd8325e 100644
18892--- a/arch/x86/kernel/acpi/boot.c
18893+++ b/arch/x86/kernel/acpi/boot.c
18894@@ -1368,7 +1368,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
18895 * If your system is blacklisted here, but you find that acpi=force
18896 * works for you, please contact linux-acpi@vger.kernel.org
18897 */
18898-static struct dmi_system_id __initdata acpi_dmi_table[] = {
18899+static const struct dmi_system_id __initconst acpi_dmi_table[] = {
18900 /*
18901 * Boxes that need ACPI disabled
18902 */
18903@@ -1443,7 +1443,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
18904 };
18905
18906 /* second table for DMI checks that should run after early-quirks */
18907-static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
18908+static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
18909 /*
18910 * HP laptops which use a DSDT reporting as HP/SB400/10000,
18911 * which includes some code which overrides all temperature
18912diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
18913index 3312010..a65ca7b 100644
18914--- a/arch/x86/kernel/acpi/sleep.c
18915+++ b/arch/x86/kernel/acpi/sleep.c
18916@@ -88,8 +88,12 @@ int x86_acpi_suspend_lowlevel(void)
18917 #else /* CONFIG_64BIT */
18918 #ifdef CONFIG_SMP
18919 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
18920+
18921+ pax_open_kernel();
18922 early_gdt_descr.address =
18923 (unsigned long)get_cpu_gdt_table(smp_processor_id());
18924+ pax_close_kernel();
18925+
18926 initial_gs = per_cpu_offset(smp_processor_id());
18927 #endif
18928 initial_code = (unsigned long)wakeup_long64;
18929diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
18930index d1daa66..59fecba 100644
18931--- a/arch/x86/kernel/acpi/wakeup_32.S
18932+++ b/arch/x86/kernel/acpi/wakeup_32.S
18933@@ -29,13 +29,11 @@ wakeup_pmode_return:
18934 # and restore the stack ... but you need gdt for this to work
18935 movl saved_context_esp, %esp
18936
18937- movl %cs:saved_magic, %eax
18938- cmpl $0x12345678, %eax
18939+ cmpl $0x12345678, saved_magic
18940 jne bogus_magic
18941
18942 # jump to place where we left off
18943- movl saved_eip, %eax
18944- jmp *%eax
18945+ jmp *(saved_eip)
18946
18947 bogus_magic:
18948 jmp bogus_magic
18949diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
18950index c15cf9a..0e63558 100644
18951--- a/arch/x86/kernel/alternative.c
18952+++ b/arch/x86/kernel/alternative.c
18953@@ -268,6 +268,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
18954 */
18955 for (a = start; a < end; a++) {
18956 instr = (u8 *)&a->instr_offset + a->instr_offset;
18957+
18958+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18959+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
18960+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
18961+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
18962+#endif
18963+
18964 replacement = (u8 *)&a->repl_offset + a->repl_offset;
18965 BUG_ON(a->replacementlen > a->instrlen);
18966 BUG_ON(a->instrlen > sizeof(insnbuf));
18967@@ -299,10 +306,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
18968 for (poff = start; poff < end; poff++) {
18969 u8 *ptr = (u8 *)poff + *poff;
18970
18971+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18972+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
18973+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
18974+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
18975+#endif
18976+
18977 if (!*poff || ptr < text || ptr >= text_end)
18978 continue;
18979 /* turn DS segment override prefix into lock prefix */
18980- if (*ptr == 0x3e)
18981+ if (*ktla_ktva(ptr) == 0x3e)
18982 text_poke(ptr, ((unsigned char []){0xf0}), 1);
18983 }
18984 mutex_unlock(&text_mutex);
18985@@ -317,10 +330,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
18986 for (poff = start; poff < end; poff++) {
18987 u8 *ptr = (u8 *)poff + *poff;
18988
18989+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18990+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
18991+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
18992+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
18993+#endif
18994+
18995 if (!*poff || ptr < text || ptr >= text_end)
18996 continue;
18997 /* turn lock prefix into DS segment override prefix */
18998- if (*ptr == 0xf0)
18999+ if (*ktla_ktva(ptr) == 0xf0)
19000 text_poke(ptr, ((unsigned char []){0x3E}), 1);
19001 }
19002 mutex_unlock(&text_mutex);
19003@@ -468,7 +487,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
19004
19005 BUG_ON(p->len > MAX_PATCH_LEN);
19006 /* prep the buffer with the original instructions */
19007- memcpy(insnbuf, p->instr, p->len);
19008+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
19009 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
19010 (unsigned long)p->instr, p->len);
19011
19012@@ -515,7 +534,7 @@ void __init alternative_instructions(void)
19013 if (!uniproc_patched || num_possible_cpus() == 1)
19014 free_init_pages("SMP alternatives",
19015 (unsigned long)__smp_locks,
19016- (unsigned long)__smp_locks_end);
19017+ PAGE_ALIGN((unsigned long)__smp_locks_end));
19018 #endif
19019
19020 apply_paravirt(__parainstructions, __parainstructions_end);
19021@@ -535,13 +554,17 @@ void __init alternative_instructions(void)
19022 * instructions. And on the local CPU you need to be protected again NMI or MCE
19023 * handlers seeing an inconsistent instruction while you patch.
19024 */
19025-void *__init_or_module text_poke_early(void *addr, const void *opcode,
19026+void *__kprobes text_poke_early(void *addr, const void *opcode,
19027 size_t len)
19028 {
19029 unsigned long flags;
19030 local_irq_save(flags);
19031- memcpy(addr, opcode, len);
19032+
19033+ pax_open_kernel();
19034+ memcpy(ktla_ktva(addr), opcode, len);
19035 sync_core();
19036+ pax_close_kernel();
19037+
19038 local_irq_restore(flags);
19039 /* Could also do a CLFLUSH here to speed up CPU recovery; but
19040 that causes hangs on some VIA CPUs. */
19041@@ -563,36 +586,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
19042 */
19043 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
19044 {
19045- unsigned long flags;
19046- char *vaddr;
19047+ unsigned char *vaddr = ktla_ktva(addr);
19048 struct page *pages[2];
19049- int i;
19050+ size_t i;
19051
19052 if (!core_kernel_text((unsigned long)addr)) {
19053- pages[0] = vmalloc_to_page(addr);
19054- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
19055+ pages[0] = vmalloc_to_page(vaddr);
19056+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
19057 } else {
19058- pages[0] = virt_to_page(addr);
19059+ pages[0] = virt_to_page(vaddr);
19060 WARN_ON(!PageReserved(pages[0]));
19061- pages[1] = virt_to_page(addr + PAGE_SIZE);
19062+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
19063 }
19064 BUG_ON(!pages[0]);
19065- local_irq_save(flags);
19066- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
19067- if (pages[1])
19068- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
19069- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
19070- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
19071- clear_fixmap(FIX_TEXT_POKE0);
19072- if (pages[1])
19073- clear_fixmap(FIX_TEXT_POKE1);
19074- local_flush_tlb();
19075- sync_core();
19076- /* Could also do a CLFLUSH here to speed up CPU recovery; but
19077- that causes hangs on some VIA CPUs. */
19078+ text_poke_early(addr, opcode, len);
19079 for (i = 0; i < len; i++)
19080- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
19081- local_irq_restore(flags);
19082+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
19083 return addr;
19084 }
19085
19086diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
19087index eca89c5..d566b78 100644
19088--- a/arch/x86/kernel/apic/apic.c
19089+++ b/arch/x86/kernel/apic/apic.c
19090@@ -190,7 +190,7 @@ int first_system_vector = 0xfe;
19091 /*
19092 * Debug level, exported for io_apic.c
19093 */
19094-unsigned int apic_verbosity;
19095+int apic_verbosity;
19096
19097 int pic_mode;
19098
19099@@ -1985,7 +1985,7 @@ static inline void __smp_error_interrupt(struct pt_regs *regs)
19100 apic_write(APIC_ESR, 0);
19101 v1 = apic_read(APIC_ESR);
19102 ack_APIC_irq();
19103- atomic_inc(&irq_err_count);
19104+ atomic_inc_unchecked(&irq_err_count);
19105
19106 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
19107 smp_processor_id(), v0 , v1);
19108diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
19109index 00c77cf..2dc6a2d 100644
19110--- a/arch/x86/kernel/apic/apic_flat_64.c
19111+++ b/arch/x86/kernel/apic/apic_flat_64.c
19112@@ -157,7 +157,7 @@ static int flat_probe(void)
19113 return 1;
19114 }
19115
19116-static struct apic apic_flat = {
19117+static struct apic apic_flat __read_only = {
19118 .name = "flat",
19119 .probe = flat_probe,
19120 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
19121@@ -271,7 +271,7 @@ static int physflat_probe(void)
19122 return 0;
19123 }
19124
19125-static struct apic apic_physflat = {
19126+static struct apic apic_physflat __read_only = {
19127
19128 .name = "physical flat",
19129 .probe = physflat_probe,
19130diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
19131index e145f28..2752888 100644
19132--- a/arch/x86/kernel/apic/apic_noop.c
19133+++ b/arch/x86/kernel/apic/apic_noop.c
19134@@ -119,7 +119,7 @@ static void noop_apic_write(u32 reg, u32 v)
19135 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
19136 }
19137
19138-struct apic apic_noop = {
19139+struct apic apic_noop __read_only = {
19140 .name = "noop",
19141 .probe = noop_probe,
19142 .acpi_madt_oem_check = NULL,
19143diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
19144index d50e364..543bee3 100644
19145--- a/arch/x86/kernel/apic/bigsmp_32.c
19146+++ b/arch/x86/kernel/apic/bigsmp_32.c
19147@@ -152,7 +152,7 @@ static int probe_bigsmp(void)
19148 return dmi_bigsmp;
19149 }
19150
19151-static struct apic apic_bigsmp = {
19152+static struct apic apic_bigsmp __read_only = {
19153
19154 .name = "bigsmp",
19155 .probe = probe_bigsmp,
19156diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c
19157index c552247..587a316 100644
19158--- a/arch/x86/kernel/apic/es7000_32.c
19159+++ b/arch/x86/kernel/apic/es7000_32.c
19160@@ -608,8 +608,7 @@ static int es7000_mps_oem_check_cluster(struct mpc_table *mpc, char *oem,
19161 return ret && es7000_apic_is_cluster();
19162 }
19163
19164-/* We've been warned by a false positive warning.Use __refdata to keep calm. */
19165-static struct apic __refdata apic_es7000_cluster = {
19166+static struct apic apic_es7000_cluster __read_only = {
19167
19168 .name = "es7000",
19169 .probe = probe_es7000,
19170@@ -675,7 +674,7 @@ static struct apic __refdata apic_es7000_cluster = {
19171 .x86_32_early_logical_apicid = es7000_early_logical_apicid,
19172 };
19173
19174-static struct apic __refdata apic_es7000 = {
19175+static struct apic apic_es7000 __read_only = {
19176
19177 .name = "es7000",
19178 .probe = probe_es7000,
19179diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
19180index 9ed796c..e930fe4 100644
19181--- a/arch/x86/kernel/apic/io_apic.c
19182+++ b/arch/x86/kernel/apic/io_apic.c
19183@@ -1060,7 +1060,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
19184 }
19185 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
19186
19187-void lock_vector_lock(void)
19188+void lock_vector_lock(void) __acquires(vector_lock)
19189 {
19190 /* Used to the online set of cpus does not change
19191 * during assign_irq_vector.
19192@@ -1068,7 +1068,7 @@ void lock_vector_lock(void)
19193 raw_spin_lock(&vector_lock);
19194 }
19195
19196-void unlock_vector_lock(void)
19197+void unlock_vector_lock(void) __releases(vector_lock)
19198 {
19199 raw_spin_unlock(&vector_lock);
19200 }
19201@@ -2362,7 +2362,7 @@ static void ack_apic_edge(struct irq_data *data)
19202 ack_APIC_irq();
19203 }
19204
19205-atomic_t irq_mis_count;
19206+atomic_unchecked_t irq_mis_count;
19207
19208 #ifdef CONFIG_GENERIC_PENDING_IRQ
19209 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
19210@@ -2503,7 +2503,7 @@ static void ack_apic_level(struct irq_data *data)
19211 * at the cpu.
19212 */
19213 if (!(v & (1 << (i & 0x1f)))) {
19214- atomic_inc(&irq_mis_count);
19215+ atomic_inc_unchecked(&irq_mis_count);
19216
19217 eoi_ioapic_irq(irq, cfg);
19218 }
19219diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
19220index 1e42e8f..daacf44 100644
19221--- a/arch/x86/kernel/apic/numaq_32.c
19222+++ b/arch/x86/kernel/apic/numaq_32.c
19223@@ -455,8 +455,7 @@ static void numaq_setup_portio_remap(void)
19224 (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
19225 }
19226
19227-/* Use __refdata to keep false positive warning calm. */
19228-static struct apic __refdata apic_numaq = {
19229+static struct apic apic_numaq __read_only = {
19230
19231 .name = "NUMAQ",
19232 .probe = probe_numaq,
19233diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
19234index eb35ef9..f184a21 100644
19235--- a/arch/x86/kernel/apic/probe_32.c
19236+++ b/arch/x86/kernel/apic/probe_32.c
19237@@ -72,7 +72,7 @@ static int probe_default(void)
19238 return 1;
19239 }
19240
19241-static struct apic apic_default = {
19242+static struct apic apic_default __read_only = {
19243
19244 .name = "default",
19245 .probe = probe_default,
19246diff --git a/arch/x86/kernel/apic/summit_32.c b/arch/x86/kernel/apic/summit_32.c
19247index 77c95c0..434f8a4 100644
19248--- a/arch/x86/kernel/apic/summit_32.c
19249+++ b/arch/x86/kernel/apic/summit_32.c
19250@@ -486,7 +486,7 @@ void setup_summit(void)
19251 }
19252 #endif
19253
19254-static struct apic apic_summit = {
19255+static struct apic apic_summit __read_only = {
19256
19257 .name = "summit",
19258 .probe = probe_summit,
19259diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
19260index 140e29d..d88bc95 100644
19261--- a/arch/x86/kernel/apic/x2apic_cluster.c
19262+++ b/arch/x86/kernel/apic/x2apic_cluster.c
19263@@ -183,7 +183,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
19264 return notifier_from_errno(err);
19265 }
19266
19267-static struct notifier_block __refdata x2apic_cpu_notifier = {
19268+static struct notifier_block x2apic_cpu_notifier = {
19269 .notifier_call = update_clusterinfo,
19270 };
19271
19272@@ -235,7 +235,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
19273 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
19274 }
19275
19276-static struct apic apic_x2apic_cluster = {
19277+static struct apic apic_x2apic_cluster __read_only = {
19278
19279 .name = "cluster x2apic",
19280 .probe = x2apic_cluster_probe,
19281diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
19282index 562a76d..a003c0f 100644
19283--- a/arch/x86/kernel/apic/x2apic_phys.c
19284+++ b/arch/x86/kernel/apic/x2apic_phys.c
19285@@ -89,7 +89,7 @@ static int x2apic_phys_probe(void)
19286 return apic == &apic_x2apic_phys;
19287 }
19288
19289-static struct apic apic_x2apic_phys = {
19290+static struct apic apic_x2apic_phys __read_only = {
19291
19292 .name = "physical x2apic",
19293 .probe = x2apic_phys_probe,
19294diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
19295index 1191ac1..2335fa4 100644
19296--- a/arch/x86/kernel/apic/x2apic_uv_x.c
19297+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
19298@@ -357,7 +357,7 @@ static int uv_probe(void)
19299 return apic == &apic_x2apic_uv_x;
19300 }
19301
19302-static struct apic __refdata apic_x2apic_uv_x = {
19303+static struct apic apic_x2apic_uv_x __read_only = {
19304
19305 .name = "UV large system",
19306 .probe = uv_probe,
19307diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
19308index 53a4e27..038760a 100644
19309--- a/arch/x86/kernel/apm_32.c
19310+++ b/arch/x86/kernel/apm_32.c
19311@@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
19312 * This is for buggy BIOS's that refer to (real mode) segment 0x40
19313 * even though they are called in protected mode.
19314 */
19315-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
19316+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
19317 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
19318
19319 static const char driver_version[] = "1.16ac"; /* no spaces */
19320@@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
19321 BUG_ON(cpu != 0);
19322 gdt = get_cpu_gdt_table(cpu);
19323 save_desc_40 = gdt[0x40 / 8];
19324+
19325+ pax_open_kernel();
19326 gdt[0x40 / 8] = bad_bios_desc;
19327+ pax_close_kernel();
19328
19329 apm_irq_save(flags);
19330 APM_DO_SAVE_SEGS;
19331@@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
19332 &call->esi);
19333 APM_DO_RESTORE_SEGS;
19334 apm_irq_restore(flags);
19335+
19336+ pax_open_kernel();
19337 gdt[0x40 / 8] = save_desc_40;
19338+ pax_close_kernel();
19339+
19340 put_cpu();
19341
19342 return call->eax & 0xff;
19343@@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
19344 BUG_ON(cpu != 0);
19345 gdt = get_cpu_gdt_table(cpu);
19346 save_desc_40 = gdt[0x40 / 8];
19347+
19348+ pax_open_kernel();
19349 gdt[0x40 / 8] = bad_bios_desc;
19350+ pax_close_kernel();
19351
19352 apm_irq_save(flags);
19353 APM_DO_SAVE_SEGS;
19354@@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
19355 &call->eax);
19356 APM_DO_RESTORE_SEGS;
19357 apm_irq_restore(flags);
19358+
19359+ pax_open_kernel();
19360 gdt[0x40 / 8] = save_desc_40;
19361+ pax_close_kernel();
19362+
19363 put_cpu();
19364 return error;
19365 }
19366@@ -2362,12 +2376,15 @@ static int __init apm_init(void)
19367 * code to that CPU.
19368 */
19369 gdt = get_cpu_gdt_table(0);
19370+
19371+ pax_open_kernel();
19372 set_desc_base(&gdt[APM_CS >> 3],
19373 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
19374 set_desc_base(&gdt[APM_CS_16 >> 3],
19375 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
19376 set_desc_base(&gdt[APM_DS >> 3],
19377 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
19378+ pax_close_kernel();
19379
19380 proc_create("apm", 0, NULL, &apm_file_ops);
19381
19382diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
19383index 2861082..6d4718e 100644
19384--- a/arch/x86/kernel/asm-offsets.c
19385+++ b/arch/x86/kernel/asm-offsets.c
19386@@ -33,6 +33,8 @@ void common(void) {
19387 OFFSET(TI_status, thread_info, status);
19388 OFFSET(TI_addr_limit, thread_info, addr_limit);
19389 OFFSET(TI_preempt_count, thread_info, preempt_count);
19390+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
19391+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
19392
19393 BLANK();
19394 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
19395@@ -53,8 +55,26 @@ void common(void) {
19396 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
19397 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
19398 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
19399+
19400+#ifdef CONFIG_PAX_KERNEXEC
19401+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
19402 #endif
19403
19404+#ifdef CONFIG_PAX_MEMORY_UDEREF
19405+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
19406+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
19407+#ifdef CONFIG_X86_64
19408+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
19409+#endif
19410+#endif
19411+
19412+#endif
19413+
19414+ BLANK();
19415+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
19416+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
19417+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
19418+
19419 #ifdef CONFIG_XEN
19420 BLANK();
19421 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
19422diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
19423index e7c798b..2b2019b 100644
19424--- a/arch/x86/kernel/asm-offsets_64.c
19425+++ b/arch/x86/kernel/asm-offsets_64.c
19426@@ -77,6 +77,7 @@ int main(void)
19427 BLANK();
19428 #undef ENTRY
19429
19430+ DEFINE(TSS_size, sizeof(struct tss_struct));
19431 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
19432 BLANK();
19433
19434diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
19435index 47b56a7..efc2bc6 100644
19436--- a/arch/x86/kernel/cpu/Makefile
19437+++ b/arch/x86/kernel/cpu/Makefile
19438@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
19439 CFLAGS_REMOVE_perf_event.o = -pg
19440 endif
19441
19442-# Make sure load_percpu_segment has no stackprotector
19443-nostackp := $(call cc-option, -fno-stack-protector)
19444-CFLAGS_common.o := $(nostackp)
19445-
19446 obj-y := intel_cacheinfo.o scattered.o topology.o
19447 obj-y += proc.o capflags.o powerflags.o common.o
19448 obj-y += rdrand.o
19449diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
19450index 08a0890..e557865 100644
19451--- a/arch/x86/kernel/cpu/amd.c
19452+++ b/arch/x86/kernel/cpu/amd.c
19453@@ -743,7 +743,7 @@ static void init_amd(struct cpuinfo_x86 *c)
19454 static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
19455 {
19456 /* AMD errata T13 (order #21922) */
19457- if ((c->x86 == 6)) {
19458+ if (c->x86 == 6) {
19459 /* Duron Rev A0 */
19460 if (c->x86_model == 3 && c->x86_mask == 0)
19461 size = 64;
19462diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
19463index 25eb274..3a92d93 100644
19464--- a/arch/x86/kernel/cpu/common.c
19465+++ b/arch/x86/kernel/cpu/common.c
19466@@ -88,60 +88,6 @@ static const struct cpu_dev default_cpu = {
19467
19468 static const struct cpu_dev *this_cpu = &default_cpu;
19469
19470-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
19471-#ifdef CONFIG_X86_64
19472- /*
19473- * We need valid kernel segments for data and code in long mode too
19474- * IRET will check the segment types kkeil 2000/10/28
19475- * Also sysret mandates a special GDT layout
19476- *
19477- * TLS descriptors are currently at a different place compared to i386.
19478- * Hopefully nobody expects them at a fixed place (Wine?)
19479- */
19480- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
19481- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
19482- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
19483- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
19484- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
19485- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
19486-#else
19487- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
19488- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
19489- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
19490- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
19491- /*
19492- * Segments used for calling PnP BIOS have byte granularity.
19493- * They code segments and data segments have fixed 64k limits,
19494- * the transfer segment sizes are set at run time.
19495- */
19496- /* 32-bit code */
19497- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
19498- /* 16-bit code */
19499- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
19500- /* 16-bit data */
19501- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
19502- /* 16-bit data */
19503- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
19504- /* 16-bit data */
19505- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
19506- /*
19507- * The APM segments have byte granularity and their bases
19508- * are set at run time. All have 64k limits.
19509- */
19510- /* 32-bit code */
19511- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
19512- /* 16-bit code */
19513- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
19514- /* data */
19515- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
19516-
19517- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
19518- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
19519- GDT_STACK_CANARY_INIT
19520-#endif
19521-} };
19522-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
19523-
19524 static int __init x86_xsave_setup(char *s)
19525 {
19526 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
19527@@ -288,6 +234,57 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
19528 set_in_cr4(X86_CR4_SMAP);
19529 }
19530
19531+#ifdef CONFIG_X86_64
19532+static __init int setup_disable_pcid(char *arg)
19533+{
19534+ setup_clear_cpu_cap(X86_FEATURE_PCID);
19535+
19536+#ifdef CONFIG_PAX_MEMORY_UDEREF
19537+ if (clone_pgd_mask != ~(pgdval_t)0UL)
19538+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
19539+#endif
19540+
19541+ return 1;
19542+}
19543+__setup("nopcid", setup_disable_pcid);
19544+
19545+static void setup_pcid(struct cpuinfo_x86 *c)
19546+{
19547+ if (!cpu_has(c, X86_FEATURE_PCID)) {
19548+
19549+#ifdef CONFIG_PAX_MEMORY_UDEREF
19550+ if (clone_pgd_mask != ~(pgdval_t)0UL) {
19551+ pax_open_kernel();
19552+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
19553+ pax_close_kernel();
19554+ printk("PAX: slow and weak UDEREF enabled\n");
19555+ } else
19556+ printk("PAX: UDEREF disabled\n");
19557+#endif
19558+
19559+ return;
19560+ }
19561+
19562+ printk("PAX: PCID detected\n");
19563+ set_in_cr4(X86_CR4_PCIDE);
19564+
19565+#ifdef CONFIG_PAX_MEMORY_UDEREF
19566+ pax_open_kernel();
19567+ clone_pgd_mask = ~(pgdval_t)0UL;
19568+ pax_close_kernel();
19569+ if (pax_user_shadow_base)
19570+ printk("PAX: weak UDEREF enabled\n");
19571+ else {
19572+ set_cpu_cap(c, X86_FEATURE_STRONGUDEREF);
19573+ printk("PAX: strong UDEREF enabled\n");
19574+ }
19575+#endif
19576+
19577+ if (cpu_has(c, X86_FEATURE_INVPCID))
19578+ printk("PAX: INVPCID detected\n");
19579+}
19580+#endif
19581+
19582 /*
19583 * Some CPU features depend on higher CPUID levels, which may not always
19584 * be available due to CPUID level capping or broken virtualization
19585@@ -386,7 +383,7 @@ void switch_to_new_gdt(int cpu)
19586 {
19587 struct desc_ptr gdt_descr;
19588
19589- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
19590+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
19591 gdt_descr.size = GDT_SIZE - 1;
19592 load_gdt(&gdt_descr);
19593 /* Reload the per-cpu base */
19594@@ -875,6 +872,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
19595 setup_smep(c);
19596 setup_smap(c);
19597
19598+#ifdef CONFIG_X86_64
19599+ setup_pcid(c);
19600+#endif
19601+
19602 /*
19603 * The vendor-specific functions might have changed features.
19604 * Now we do "generic changes."
19605@@ -883,6 +884,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
19606 /* Filter out anything that depends on CPUID levels we don't have */
19607 filter_cpuid_features(c, true);
19608
19609+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
19610+ setup_clear_cpu_cap(X86_FEATURE_SEP);
19611+#endif
19612+
19613 /* If the model name is still unset, do table lookup. */
19614 if (!c->x86_model_id[0]) {
19615 const char *p;
19616@@ -1070,10 +1075,12 @@ static __init int setup_disablecpuid(char *arg)
19617 }
19618 __setup("clearcpuid=", setup_disablecpuid);
19619
19620+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
19621+EXPORT_PER_CPU_SYMBOL(current_tinfo);
19622+
19623 #ifdef CONFIG_X86_64
19624-struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
19625-struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1,
19626- (unsigned long) debug_idt_table };
19627+struct desc_ptr idt_descr __read_only = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
19628+const struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) debug_idt_table };
19629
19630 DEFINE_PER_CPU_FIRST(union irq_stack_union,
19631 irq_stack_union) __aligned(PAGE_SIZE);
19632@@ -1087,7 +1094,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
19633 EXPORT_PER_CPU_SYMBOL(current_task);
19634
19635 DEFINE_PER_CPU(unsigned long, kernel_stack) =
19636- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
19637+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
19638 EXPORT_PER_CPU_SYMBOL(kernel_stack);
19639
19640 DEFINE_PER_CPU(char *, irq_stack_ptr) =
19641@@ -1232,7 +1239,7 @@ void cpu_init(void)
19642 load_ucode_ap();
19643
19644 cpu = stack_smp_processor_id();
19645- t = &per_cpu(init_tss, cpu);
19646+ t = init_tss + cpu;
19647 oist = &per_cpu(orig_ist, cpu);
19648
19649 #ifdef CONFIG_NUMA
19650@@ -1267,7 +1274,6 @@ void cpu_init(void)
19651 wrmsrl(MSR_KERNEL_GS_BASE, 0);
19652 barrier();
19653
19654- x86_configure_nx();
19655 enable_x2apic();
19656
19657 /*
19658@@ -1319,7 +1325,7 @@ void cpu_init(void)
19659 {
19660 int cpu = smp_processor_id();
19661 struct task_struct *curr = current;
19662- struct tss_struct *t = &per_cpu(init_tss, cpu);
19663+ struct tss_struct *t = init_tss + cpu;
19664 struct thread_struct *thread = &curr->thread;
19665
19666 show_ucode_info_early();
19667diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
19668index 1414c90..1159406 100644
19669--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
19670+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
19671@@ -1014,6 +1014,22 @@ static struct attribute *default_attrs[] = {
19672 };
19673
19674 #ifdef CONFIG_AMD_NB
19675+static struct attribute *default_attrs_amd_nb[] = {
19676+ &type.attr,
19677+ &level.attr,
19678+ &coherency_line_size.attr,
19679+ &physical_line_partition.attr,
19680+ &ways_of_associativity.attr,
19681+ &number_of_sets.attr,
19682+ &size.attr,
19683+ &shared_cpu_map.attr,
19684+ &shared_cpu_list.attr,
19685+ NULL,
19686+ NULL,
19687+ NULL,
19688+ NULL
19689+};
19690+
19691 static struct attribute **amd_l3_attrs(void)
19692 {
19693 static struct attribute **attrs;
19694@@ -1024,18 +1040,7 @@ static struct attribute **amd_l3_attrs(void)
19695
19696 n = ARRAY_SIZE(default_attrs);
19697
19698- if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
19699- n += 2;
19700-
19701- if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
19702- n += 1;
19703-
19704- attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
19705- if (attrs == NULL)
19706- return attrs = default_attrs;
19707-
19708- for (n = 0; default_attrs[n]; n++)
19709- attrs[n] = default_attrs[n];
19710+ attrs = default_attrs_amd_nb;
19711
19712 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
19713 attrs[n++] = &cache_disable_0.attr;
19714@@ -1086,6 +1091,13 @@ static struct kobj_type ktype_cache = {
19715 .default_attrs = default_attrs,
19716 };
19717
19718+#ifdef CONFIG_AMD_NB
19719+static struct kobj_type ktype_cache_amd_nb = {
19720+ .sysfs_ops = &sysfs_ops,
19721+ .default_attrs = default_attrs_amd_nb,
19722+};
19723+#endif
19724+
19725 static struct kobj_type ktype_percpu_entry = {
19726 .sysfs_ops = &sysfs_ops,
19727 };
19728@@ -1151,20 +1163,26 @@ static int cache_add_dev(struct device *dev)
19729 return retval;
19730 }
19731
19732+#ifdef CONFIG_AMD_NB
19733+ amd_l3_attrs();
19734+#endif
19735+
19736 for (i = 0; i < num_cache_leaves; i++) {
19737+ struct kobj_type *ktype;
19738+
19739 this_object = INDEX_KOBJECT_PTR(cpu, i);
19740 this_object->cpu = cpu;
19741 this_object->index = i;
19742
19743 this_leaf = CPUID4_INFO_IDX(cpu, i);
19744
19745- ktype_cache.default_attrs = default_attrs;
19746+ ktype = &ktype_cache;
19747 #ifdef CONFIG_AMD_NB
19748 if (this_leaf->base.nb)
19749- ktype_cache.default_attrs = amd_l3_attrs();
19750+ ktype = &ktype_cache_amd_nb;
19751 #endif
19752 retval = kobject_init_and_add(&(this_object->kobj),
19753- &ktype_cache,
19754+ ktype,
19755 per_cpu(ici_cache_kobject, cpu),
19756 "index%1lu", i);
19757 if (unlikely(retval)) {
19758diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
19759index 87a65c9..92fcce6 100644
19760--- a/arch/x86/kernel/cpu/mcheck/mce.c
19761+++ b/arch/x86/kernel/cpu/mcheck/mce.c
19762@@ -45,6 +45,7 @@
19763 #include <asm/processor.h>
19764 #include <asm/mce.h>
19765 #include <asm/msr.h>
19766+#include <asm/local.h>
19767
19768 #include "mce-internal.h"
19769
19770@@ -249,7 +250,7 @@ static void print_mce(struct mce *m)
19771 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
19772 m->cs, m->ip);
19773
19774- if (m->cs == __KERNEL_CS)
19775+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
19776 print_symbol("{%s}", m->ip);
19777 pr_cont("\n");
19778 }
19779@@ -282,10 +283,10 @@ static void print_mce(struct mce *m)
19780
19781 #define PANIC_TIMEOUT 5 /* 5 seconds */
19782
19783-static atomic_t mce_paniced;
19784+static atomic_unchecked_t mce_paniced;
19785
19786 static int fake_panic;
19787-static atomic_t mce_fake_paniced;
19788+static atomic_unchecked_t mce_fake_paniced;
19789
19790 /* Panic in progress. Enable interrupts and wait for final IPI */
19791 static void wait_for_panic(void)
19792@@ -309,7 +310,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
19793 /*
19794 * Make sure only one CPU runs in machine check panic
19795 */
19796- if (atomic_inc_return(&mce_paniced) > 1)
19797+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
19798 wait_for_panic();
19799 barrier();
19800
19801@@ -317,7 +318,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
19802 console_verbose();
19803 } else {
19804 /* Don't log too much for fake panic */
19805- if (atomic_inc_return(&mce_fake_paniced) > 1)
19806+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
19807 return;
19808 }
19809 /* First print corrected ones that are still unlogged */
19810@@ -356,7 +357,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
19811 if (!fake_panic) {
19812 if (panic_timeout == 0)
19813 panic_timeout = mca_cfg.panic_timeout;
19814- panic(msg);
19815+ panic("%s", msg);
19816 } else
19817 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
19818 }
19819@@ -686,7 +687,7 @@ static int mce_timed_out(u64 *t)
19820 * might have been modified by someone else.
19821 */
19822 rmb();
19823- if (atomic_read(&mce_paniced))
19824+ if (atomic_read_unchecked(&mce_paniced))
19825 wait_for_panic();
19826 if (!mca_cfg.monarch_timeout)
19827 goto out;
19828@@ -1657,7 +1658,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
19829 }
19830
19831 /* Call the installed machine check handler for this CPU setup. */
19832-void (*machine_check_vector)(struct pt_regs *, long error_code) =
19833+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
19834 unexpected_machine_check;
19835
19836 /*
19837@@ -1680,7 +1681,9 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
19838 return;
19839 }
19840
19841+ pax_open_kernel();
19842 machine_check_vector = do_machine_check;
19843+ pax_close_kernel();
19844
19845 __mcheck_cpu_init_generic();
19846 __mcheck_cpu_init_vendor(c);
19847@@ -1694,7 +1697,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
19848 */
19849
19850 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
19851-static int mce_chrdev_open_count; /* #times opened */
19852+static local_t mce_chrdev_open_count; /* #times opened */
19853 static int mce_chrdev_open_exclu; /* already open exclusive? */
19854
19855 static int mce_chrdev_open(struct inode *inode, struct file *file)
19856@@ -1702,7 +1705,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
19857 spin_lock(&mce_chrdev_state_lock);
19858
19859 if (mce_chrdev_open_exclu ||
19860- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
19861+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
19862 spin_unlock(&mce_chrdev_state_lock);
19863
19864 return -EBUSY;
19865@@ -1710,7 +1713,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
19866
19867 if (file->f_flags & O_EXCL)
19868 mce_chrdev_open_exclu = 1;
19869- mce_chrdev_open_count++;
19870+ local_inc(&mce_chrdev_open_count);
19871
19872 spin_unlock(&mce_chrdev_state_lock);
19873
19874@@ -1721,7 +1724,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
19875 {
19876 spin_lock(&mce_chrdev_state_lock);
19877
19878- mce_chrdev_open_count--;
19879+ local_dec(&mce_chrdev_open_count);
19880 mce_chrdev_open_exclu = 0;
19881
19882 spin_unlock(&mce_chrdev_state_lock);
19883@@ -2376,7 +2379,7 @@ static __init void mce_init_banks(void)
19884
19885 for (i = 0; i < mca_cfg.banks; i++) {
19886 struct mce_bank *b = &mce_banks[i];
19887- struct device_attribute *a = &b->attr;
19888+ device_attribute_no_const *a = &b->attr;
19889
19890 sysfs_attr_init(&a->attr);
19891 a->attr.name = b->attrname;
19892@@ -2444,7 +2447,7 @@ struct dentry *mce_get_debugfs_dir(void)
19893 static void mce_reset(void)
19894 {
19895 cpu_missing = 0;
19896- atomic_set(&mce_fake_paniced, 0);
19897+ atomic_set_unchecked(&mce_fake_paniced, 0);
19898 atomic_set(&mce_executing, 0);
19899 atomic_set(&mce_callin, 0);
19900 atomic_set(&global_nwo, 0);
19901diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
19902index 1c044b1..37a2a43 100644
19903--- a/arch/x86/kernel/cpu/mcheck/p5.c
19904+++ b/arch/x86/kernel/cpu/mcheck/p5.c
19905@@ -11,6 +11,7 @@
19906 #include <asm/processor.h>
19907 #include <asm/mce.h>
19908 #include <asm/msr.h>
19909+#include <asm/pgtable.h>
19910
19911 /* By default disabled */
19912 int mce_p5_enabled __read_mostly;
19913@@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
19914 if (!cpu_has(c, X86_FEATURE_MCE))
19915 return;
19916
19917+ pax_open_kernel();
19918 machine_check_vector = pentium_machine_check;
19919+ pax_close_kernel();
19920 /* Make sure the vector pointer is visible before we enable MCEs: */
19921 wmb();
19922
19923diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
19924index e9a701a..35317d6 100644
19925--- a/arch/x86/kernel/cpu/mcheck/winchip.c
19926+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
19927@@ -10,6 +10,7 @@
19928 #include <asm/processor.h>
19929 #include <asm/mce.h>
19930 #include <asm/msr.h>
19931+#include <asm/pgtable.h>
19932
19933 /* Machine check handler for WinChip C6: */
19934 static void winchip_machine_check(struct pt_regs *regs, long error_code)
19935@@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
19936 {
19937 u32 lo, hi;
19938
19939+ pax_open_kernel();
19940 machine_check_vector = winchip_machine_check;
19941+ pax_close_kernel();
19942 /* Make sure the vector pointer is visible before we enable MCEs: */
19943 wmb();
19944
19945diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
19946index f961de9..8a9d332 100644
19947--- a/arch/x86/kernel/cpu/mtrr/main.c
19948+++ b/arch/x86/kernel/cpu/mtrr/main.c
19949@@ -66,7 +66,7 @@ static DEFINE_MUTEX(mtrr_mutex);
19950 u64 size_or_mask, size_and_mask;
19951 static bool mtrr_aps_delayed_init;
19952
19953-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
19954+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
19955
19956 const struct mtrr_ops *mtrr_if;
19957
19958diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
19959index df5e41f..816c719 100644
19960--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
19961+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
19962@@ -25,7 +25,7 @@ struct mtrr_ops {
19963 int (*validate_add_page)(unsigned long base, unsigned long size,
19964 unsigned int type);
19965 int (*have_wrcomb)(void);
19966-};
19967+} __do_const;
19968
19969 extern int generic_get_free_region(unsigned long base, unsigned long size,
19970 int replace_reg);
19971diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
19972index a7c7305..b9705ab 100644
19973--- a/arch/x86/kernel/cpu/perf_event.c
19974+++ b/arch/x86/kernel/cpu/perf_event.c
19975@@ -1348,7 +1348,7 @@ static void __init pmu_check_apic(void)
19976 pr_info("no hardware sampling interrupt available.\n");
19977 }
19978
19979-static struct attribute_group x86_pmu_format_group = {
19980+static attribute_group_no_const x86_pmu_format_group = {
19981 .name = "format",
19982 .attrs = NULL,
19983 };
19984@@ -1447,7 +1447,7 @@ static struct attribute *events_attr[] = {
19985 NULL,
19986 };
19987
19988-static struct attribute_group x86_pmu_events_group = {
19989+static attribute_group_no_const x86_pmu_events_group = {
19990 .name = "events",
19991 .attrs = events_attr,
19992 };
19993@@ -1957,7 +1957,7 @@ static unsigned long get_segment_base(unsigned int segment)
19994 if (idx > GDT_ENTRIES)
19995 return 0;
19996
19997- desc = __this_cpu_ptr(&gdt_page.gdt[0]);
19998+ desc = get_cpu_gdt_table(smp_processor_id());
19999 }
20000
20001 return get_desc_base(desc + idx);
20002@@ -2047,7 +2047,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
20003 break;
20004
20005 perf_callchain_store(entry, frame.return_address);
20006- fp = frame.next_frame;
20007+ fp = (const void __force_user *)frame.next_frame;
20008 }
20009 }
20010
20011diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
20012index 639d128..e92d7e5 100644
20013--- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c
20014+++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
20015@@ -405,7 +405,7 @@ static void perf_iommu_del(struct perf_event *event, int flags)
20016 static __init int _init_events_attrs(struct perf_amd_iommu *perf_iommu)
20017 {
20018 struct attribute **attrs;
20019- struct attribute_group *attr_group;
20020+ attribute_group_no_const *attr_group;
20021 int i = 0, j;
20022
20023 while (amd_iommu_v2_event_descs[i].attr.attr.name)
20024diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
20025index a45d8d4..8abd32c 100644
20026--- a/arch/x86/kernel/cpu/perf_event_intel.c
20027+++ b/arch/x86/kernel/cpu/perf_event_intel.c
20028@@ -2099,10 +2099,10 @@ __init int intel_pmu_init(void)
20029 * v2 and above have a perf capabilities MSR
20030 */
20031 if (version > 1) {
20032- u64 capabilities;
20033+ u64 capabilities = x86_pmu.intel_cap.capabilities;
20034
20035- rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
20036- x86_pmu.intel_cap.capabilities = capabilities;
20037+ if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
20038+ x86_pmu.intel_cap.capabilities = capabilities;
20039 }
20040
20041 intel_ds_init();
20042diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
20043index 1fb6c72..f5fa2a3 100644
20044--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
20045+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
20046@@ -3095,7 +3095,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
20047 static int __init uncore_type_init(struct intel_uncore_type *type)
20048 {
20049 struct intel_uncore_pmu *pmus;
20050- struct attribute_group *attr_group;
20051+ attribute_group_no_const *attr_group;
20052 struct attribute **attrs;
20053 int i, j;
20054
20055diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
20056index 47b3d00c..2cf1751 100644
20057--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
20058+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
20059@@ -488,7 +488,7 @@ struct intel_uncore_box {
20060 struct uncore_event_desc {
20061 struct kobj_attribute attr;
20062 const char *config;
20063-};
20064+} __do_const;
20065
20066 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
20067 { \
20068diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
20069index 7d9481c..99c7e4b 100644
20070--- a/arch/x86/kernel/cpuid.c
20071+++ b/arch/x86/kernel/cpuid.c
20072@@ -170,7 +170,7 @@ static int cpuid_class_cpu_callback(struct notifier_block *nfb,
20073 return notifier_from_errno(err);
20074 }
20075
20076-static struct notifier_block __refdata cpuid_class_cpu_notifier =
20077+static struct notifier_block cpuid_class_cpu_notifier =
20078 {
20079 .notifier_call = cpuid_class_cpu_callback,
20080 };
20081diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
20082index 74467fe..18793d5 100644
20083--- a/arch/x86/kernel/crash.c
20084+++ b/arch/x86/kernel/crash.c
20085@@ -58,10 +58,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
20086 {
20087 #ifdef CONFIG_X86_32
20088 struct pt_regs fixed_regs;
20089-#endif
20090
20091-#ifdef CONFIG_X86_32
20092- if (!user_mode_vm(regs)) {
20093+ if (!user_mode(regs)) {
20094 crash_fixup_ss_esp(&fixed_regs, regs);
20095 regs = &fixed_regs;
20096 }
20097diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
20098index afa64ad..dce67dd 100644
20099--- a/arch/x86/kernel/crash_dump_64.c
20100+++ b/arch/x86/kernel/crash_dump_64.c
20101@@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
20102 return -ENOMEM;
20103
20104 if (userbuf) {
20105- if (copy_to_user(buf, vaddr + offset, csize)) {
20106+ if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
20107 iounmap(vaddr);
20108 return -EFAULT;
20109 }
20110diff --git a/arch/x86/kernel/doublefault.c b/arch/x86/kernel/doublefault.c
20111index 5d3fe8d..02e1429 100644
20112--- a/arch/x86/kernel/doublefault.c
20113+++ b/arch/x86/kernel/doublefault.c
20114@@ -13,7 +13,7 @@
20115
20116 #define DOUBLEFAULT_STACKSIZE (1024)
20117 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
20118-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
20119+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
20120
20121 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
20122
20123@@ -23,7 +23,7 @@ static void doublefault_fn(void)
20124 unsigned long gdt, tss;
20125
20126 native_store_gdt(&gdt_desc);
20127- gdt = gdt_desc.address;
20128+ gdt = (unsigned long)gdt_desc.address;
20129
20130 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
20131
20132@@ -60,10 +60,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
20133 /* 0x2 bit is always set */
20134 .flags = X86_EFLAGS_SF | 0x2,
20135 .sp = STACK_START,
20136- .es = __USER_DS,
20137+ .es = __KERNEL_DS,
20138 .cs = __KERNEL_CS,
20139 .ss = __KERNEL_DS,
20140- .ds = __USER_DS,
20141+ .ds = __KERNEL_DS,
20142 .fs = __KERNEL_PERCPU,
20143
20144 .__cr3 = __pa_nodebug(swapper_pg_dir),
20145diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
20146index deb6421..76bbc12 100644
20147--- a/arch/x86/kernel/dumpstack.c
20148+++ b/arch/x86/kernel/dumpstack.c
20149@@ -2,6 +2,9 @@
20150 * Copyright (C) 1991, 1992 Linus Torvalds
20151 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
20152 */
20153+#ifdef CONFIG_GRKERNSEC_HIDESYM
20154+#define __INCLUDED_BY_HIDESYM 1
20155+#endif
20156 #include <linux/kallsyms.h>
20157 #include <linux/kprobes.h>
20158 #include <linux/uaccess.h>
20159@@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
20160 static void
20161 print_ftrace_graph_addr(unsigned long addr, void *data,
20162 const struct stacktrace_ops *ops,
20163- struct thread_info *tinfo, int *graph)
20164+ struct task_struct *task, int *graph)
20165 {
20166- struct task_struct *task;
20167 unsigned long ret_addr;
20168 int index;
20169
20170 if (addr != (unsigned long)return_to_handler)
20171 return;
20172
20173- task = tinfo->task;
20174 index = task->curr_ret_stack;
20175
20176 if (!task->ret_stack || index < *graph)
20177@@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
20178 static inline void
20179 print_ftrace_graph_addr(unsigned long addr, void *data,
20180 const struct stacktrace_ops *ops,
20181- struct thread_info *tinfo, int *graph)
20182+ struct task_struct *task, int *graph)
20183 { }
20184 #endif
20185
20186@@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
20187 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
20188 */
20189
20190-static inline int valid_stack_ptr(struct thread_info *tinfo,
20191- void *p, unsigned int size, void *end)
20192+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
20193 {
20194- void *t = tinfo;
20195 if (end) {
20196 if (p < end && p >= (end-THREAD_SIZE))
20197 return 1;
20198@@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
20199 }
20200
20201 unsigned long
20202-print_context_stack(struct thread_info *tinfo,
20203+print_context_stack(struct task_struct *task, void *stack_start,
20204 unsigned long *stack, unsigned long bp,
20205 const struct stacktrace_ops *ops, void *data,
20206 unsigned long *end, int *graph)
20207 {
20208 struct stack_frame *frame = (struct stack_frame *)bp;
20209
20210- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
20211+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
20212 unsigned long addr;
20213
20214 addr = *stack;
20215@@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
20216 } else {
20217 ops->address(data, addr, 0);
20218 }
20219- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
20220+ print_ftrace_graph_addr(addr, data, ops, task, graph);
20221 }
20222 stack++;
20223 }
20224@@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
20225 EXPORT_SYMBOL_GPL(print_context_stack);
20226
20227 unsigned long
20228-print_context_stack_bp(struct thread_info *tinfo,
20229+print_context_stack_bp(struct task_struct *task, void *stack_start,
20230 unsigned long *stack, unsigned long bp,
20231 const struct stacktrace_ops *ops, void *data,
20232 unsigned long *end, int *graph)
20233@@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
20234 struct stack_frame *frame = (struct stack_frame *)bp;
20235 unsigned long *ret_addr = &frame->return_address;
20236
20237- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
20238+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
20239 unsigned long addr = *ret_addr;
20240
20241 if (!__kernel_text_address(addr))
20242@@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
20243 ops->address(data, addr, 1);
20244 frame = frame->next_frame;
20245 ret_addr = &frame->return_address;
20246- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
20247+ print_ftrace_graph_addr(addr, data, ops, task, graph);
20248 }
20249
20250 return (unsigned long)frame;
20251@@ -150,7 +149,7 @@ static int print_trace_stack(void *data, char *name)
20252 static void print_trace_address(void *data, unsigned long addr, int reliable)
20253 {
20254 touch_nmi_watchdog();
20255- printk(data);
20256+ printk("%s", (char *)data);
20257 printk_address(addr, reliable);
20258 }
20259
20260@@ -219,6 +218,8 @@ unsigned __kprobes long oops_begin(void)
20261 }
20262 EXPORT_SYMBOL_GPL(oops_begin);
20263
20264+extern void gr_handle_kernel_exploit(void);
20265+
20266 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
20267 {
20268 if (regs && kexec_should_crash(current))
20269@@ -240,7 +241,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
20270 panic("Fatal exception in interrupt");
20271 if (panic_on_oops)
20272 panic("Fatal exception");
20273- do_exit(signr);
20274+
20275+ gr_handle_kernel_exploit();
20276+
20277+ do_group_exit(signr);
20278 }
20279
20280 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
20281@@ -268,7 +272,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
20282 print_modules();
20283 show_regs(regs);
20284 #ifdef CONFIG_X86_32
20285- if (user_mode_vm(regs)) {
20286+ if (user_mode(regs)) {
20287 sp = regs->sp;
20288 ss = regs->ss & 0xffff;
20289 } else {
20290@@ -296,7 +300,7 @@ void die(const char *str, struct pt_regs *regs, long err)
20291 unsigned long flags = oops_begin();
20292 int sig = SIGSEGV;
20293
20294- if (!user_mode_vm(regs))
20295+ if (!user_mode(regs))
20296 report_bug(regs->ip, regs);
20297
20298 if (__die(str, regs, err))
20299diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
20300index f2a1770..540657f 100644
20301--- a/arch/x86/kernel/dumpstack_32.c
20302+++ b/arch/x86/kernel/dumpstack_32.c
20303@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20304 bp = stack_frame(task, regs);
20305
20306 for (;;) {
20307- struct thread_info *context;
20308+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
20309
20310- context = (struct thread_info *)
20311- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
20312- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
20313+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
20314
20315- stack = (unsigned long *)context->previous_esp;
20316- if (!stack)
20317+ if (stack_start == task_stack_page(task))
20318 break;
20319+ stack = *(unsigned long **)stack_start;
20320 if (ops->stack(data, "IRQ") < 0)
20321 break;
20322 touch_nmi_watchdog();
20323@@ -87,27 +85,28 @@ void show_regs(struct pt_regs *regs)
20324 int i;
20325
20326 show_regs_print_info(KERN_EMERG);
20327- __show_regs(regs, !user_mode_vm(regs));
20328+ __show_regs(regs, !user_mode(regs));
20329
20330 /*
20331 * When in-kernel, we also print out the stack and code at the
20332 * time of the fault..
20333 */
20334- if (!user_mode_vm(regs)) {
20335+ if (!user_mode(regs)) {
20336 unsigned int code_prologue = code_bytes * 43 / 64;
20337 unsigned int code_len = code_bytes;
20338 unsigned char c;
20339 u8 *ip;
20340+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
20341
20342 pr_emerg("Stack:\n");
20343 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
20344
20345 pr_emerg("Code:");
20346
20347- ip = (u8 *)regs->ip - code_prologue;
20348+ ip = (u8 *)regs->ip - code_prologue + cs_base;
20349 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
20350 /* try starting at IP */
20351- ip = (u8 *)regs->ip;
20352+ ip = (u8 *)regs->ip + cs_base;
20353 code_len = code_len - code_prologue + 1;
20354 }
20355 for (i = 0; i < code_len; i++, ip++) {
20356@@ -116,7 +115,7 @@ void show_regs(struct pt_regs *regs)
20357 pr_cont(" Bad EIP value.");
20358 break;
20359 }
20360- if (ip == (u8 *)regs->ip)
20361+ if (ip == (u8 *)regs->ip + cs_base)
20362 pr_cont(" <%02x>", c);
20363 else
20364 pr_cont(" %02x", c);
20365@@ -129,6 +128,7 @@ int is_valid_bugaddr(unsigned long ip)
20366 {
20367 unsigned short ud2;
20368
20369+ ip = ktla_ktva(ip);
20370 if (ip < PAGE_OFFSET)
20371 return 0;
20372 if (probe_kernel_address((unsigned short *)ip, ud2))
20373@@ -136,3 +136,15 @@ int is_valid_bugaddr(unsigned long ip)
20374
20375 return ud2 == 0x0b0f;
20376 }
20377+
20378+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
20379+void pax_check_alloca(unsigned long size)
20380+{
20381+ unsigned long sp = (unsigned long)&sp, stack_left;
20382+
20383+ /* all kernel stacks are of the same size */
20384+ stack_left = sp & (THREAD_SIZE - 1);
20385+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
20386+}
20387+EXPORT_SYMBOL(pax_check_alloca);
20388+#endif
20389diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
20390index addb207..99635fa 100644
20391--- a/arch/x86/kernel/dumpstack_64.c
20392+++ b/arch/x86/kernel/dumpstack_64.c
20393@@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20394 unsigned long *irq_stack_end =
20395 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
20396 unsigned used = 0;
20397- struct thread_info *tinfo;
20398 int graph = 0;
20399 unsigned long dummy;
20400+ void *stack_start;
20401
20402 if (!task)
20403 task = current;
20404@@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20405 * current stack address. If the stacks consist of nested
20406 * exceptions
20407 */
20408- tinfo = task_thread_info(task);
20409 for (;;) {
20410 char *id;
20411 unsigned long *estack_end;
20412+
20413 estack_end = in_exception_stack(cpu, (unsigned long)stack,
20414 &used, &id);
20415
20416@@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20417 if (ops->stack(data, id) < 0)
20418 break;
20419
20420- bp = ops->walk_stack(tinfo, stack, bp, ops,
20421+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
20422 data, estack_end, &graph);
20423 ops->stack(data, "<EOE>");
20424 /*
20425@@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20426 * second-to-last pointer (index -2 to end) in the
20427 * exception stack:
20428 */
20429+ if ((u16)estack_end[-1] != __KERNEL_DS)
20430+ goto out;
20431 stack = (unsigned long *) estack_end[-2];
20432 continue;
20433 }
20434@@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20435 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
20436 if (ops->stack(data, "IRQ") < 0)
20437 break;
20438- bp = ops->walk_stack(tinfo, stack, bp,
20439+ bp = ops->walk_stack(task, irq_stack, stack, bp,
20440 ops, data, irq_stack_end, &graph);
20441 /*
20442 * We link to the next stack (which would be
20443@@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20444 /*
20445 * This handles the process stack:
20446 */
20447- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
20448+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
20449+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
20450+out:
20451 put_cpu();
20452 }
20453 EXPORT_SYMBOL(dump_trace);
20454@@ -300,3 +304,50 @@ int is_valid_bugaddr(unsigned long ip)
20455
20456 return ud2 == 0x0b0f;
20457 }
20458+
20459+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
20460+void pax_check_alloca(unsigned long size)
20461+{
20462+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
20463+ unsigned cpu, used;
20464+ char *id;
20465+
20466+ /* check the process stack first */
20467+ stack_start = (unsigned long)task_stack_page(current);
20468+ stack_end = stack_start + THREAD_SIZE;
20469+ if (likely(stack_start <= sp && sp < stack_end)) {
20470+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
20471+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
20472+ return;
20473+ }
20474+
20475+ cpu = get_cpu();
20476+
20477+ /* check the irq stacks */
20478+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
20479+ stack_start = stack_end - IRQ_STACK_SIZE;
20480+ if (stack_start <= sp && sp < stack_end) {
20481+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
20482+ put_cpu();
20483+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
20484+ return;
20485+ }
20486+
20487+ /* check the exception stacks */
20488+ used = 0;
20489+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
20490+ stack_start = stack_end - EXCEPTION_STKSZ;
20491+ if (stack_end && stack_start <= sp && sp < stack_end) {
20492+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
20493+ put_cpu();
20494+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
20495+ return;
20496+ }
20497+
20498+ put_cpu();
20499+
20500+ /* unknown stack */
20501+ BUG();
20502+}
20503+EXPORT_SYMBOL(pax_check_alloca);
20504+#endif
20505diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
20506index d32abea..74daf4f 100644
20507--- a/arch/x86/kernel/e820.c
20508+++ b/arch/x86/kernel/e820.c
20509@@ -800,8 +800,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
20510
20511 static void early_panic(char *msg)
20512 {
20513- early_printk(msg);
20514- panic(msg);
20515+ early_printk("%s", msg);
20516+ panic("%s", msg);
20517 }
20518
20519 static int userdef __initdata;
20520diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
20521index d15f575..d692043 100644
20522--- a/arch/x86/kernel/early_printk.c
20523+++ b/arch/x86/kernel/early_printk.c
20524@@ -7,6 +7,7 @@
20525 #include <linux/pci_regs.h>
20526 #include <linux/pci_ids.h>
20527 #include <linux/errno.h>
20528+#include <linux/sched.h>
20529 #include <asm/io.h>
20530 #include <asm/processor.h>
20531 #include <asm/fcntl.h>
20532diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
20533index 2cfbc3a..b756682 100644
20534--- a/arch/x86/kernel/entry_32.S
20535+++ b/arch/x86/kernel/entry_32.S
20536@@ -177,13 +177,153 @@
20537 /*CFI_REL_OFFSET gs, PT_GS*/
20538 .endm
20539 .macro SET_KERNEL_GS reg
20540+
20541+#ifdef CONFIG_CC_STACKPROTECTOR
20542 movl $(__KERNEL_STACK_CANARY), \reg
20543+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
20544+ movl $(__USER_DS), \reg
20545+#else
20546+ xorl \reg, \reg
20547+#endif
20548+
20549 movl \reg, %gs
20550 .endm
20551
20552 #endif /* CONFIG_X86_32_LAZY_GS */
20553
20554-.macro SAVE_ALL
20555+.macro pax_enter_kernel
20556+#ifdef CONFIG_PAX_KERNEXEC
20557+ call pax_enter_kernel
20558+#endif
20559+.endm
20560+
20561+.macro pax_exit_kernel
20562+#ifdef CONFIG_PAX_KERNEXEC
20563+ call pax_exit_kernel
20564+#endif
20565+.endm
20566+
20567+#ifdef CONFIG_PAX_KERNEXEC
20568+ENTRY(pax_enter_kernel)
20569+#ifdef CONFIG_PARAVIRT
20570+ pushl %eax
20571+ pushl %ecx
20572+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
20573+ mov %eax, %esi
20574+#else
20575+ mov %cr0, %esi
20576+#endif
20577+ bts $16, %esi
20578+ jnc 1f
20579+ mov %cs, %esi
20580+ cmp $__KERNEL_CS, %esi
20581+ jz 3f
20582+ ljmp $__KERNEL_CS, $3f
20583+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
20584+2:
20585+#ifdef CONFIG_PARAVIRT
20586+ mov %esi, %eax
20587+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
20588+#else
20589+ mov %esi, %cr0
20590+#endif
20591+3:
20592+#ifdef CONFIG_PARAVIRT
20593+ popl %ecx
20594+ popl %eax
20595+#endif
20596+ ret
20597+ENDPROC(pax_enter_kernel)
20598+
20599+ENTRY(pax_exit_kernel)
20600+#ifdef CONFIG_PARAVIRT
20601+ pushl %eax
20602+ pushl %ecx
20603+#endif
20604+ mov %cs, %esi
20605+ cmp $__KERNEXEC_KERNEL_CS, %esi
20606+ jnz 2f
20607+#ifdef CONFIG_PARAVIRT
20608+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
20609+ mov %eax, %esi
20610+#else
20611+ mov %cr0, %esi
20612+#endif
20613+ btr $16, %esi
20614+ ljmp $__KERNEL_CS, $1f
20615+1:
20616+#ifdef CONFIG_PARAVIRT
20617+ mov %esi, %eax
20618+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
20619+#else
20620+ mov %esi, %cr0
20621+#endif
20622+2:
20623+#ifdef CONFIG_PARAVIRT
20624+ popl %ecx
20625+ popl %eax
20626+#endif
20627+ ret
20628+ENDPROC(pax_exit_kernel)
20629+#endif
20630+
20631+ .macro pax_erase_kstack
20632+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
20633+ call pax_erase_kstack
20634+#endif
20635+ .endm
20636+
20637+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
20638+/*
20639+ * ebp: thread_info
20640+ */
20641+ENTRY(pax_erase_kstack)
20642+ pushl %edi
20643+ pushl %ecx
20644+ pushl %eax
20645+
20646+ mov TI_lowest_stack(%ebp), %edi
20647+ mov $-0xBEEF, %eax
20648+ std
20649+
20650+1: mov %edi, %ecx
20651+ and $THREAD_SIZE_asm - 1, %ecx
20652+ shr $2, %ecx
20653+ repne scasl
20654+ jecxz 2f
20655+
20656+ cmp $2*16, %ecx
20657+ jc 2f
20658+
20659+ mov $2*16, %ecx
20660+ repe scasl
20661+ jecxz 2f
20662+ jne 1b
20663+
20664+2: cld
20665+ mov %esp, %ecx
20666+ sub %edi, %ecx
20667+
20668+ cmp $THREAD_SIZE_asm, %ecx
20669+ jb 3f
20670+ ud2
20671+3:
20672+
20673+ shr $2, %ecx
20674+ rep stosl
20675+
20676+ mov TI_task_thread_sp0(%ebp), %edi
20677+ sub $128, %edi
20678+ mov %edi, TI_lowest_stack(%ebp)
20679+
20680+ popl %eax
20681+ popl %ecx
20682+ popl %edi
20683+ ret
20684+ENDPROC(pax_erase_kstack)
20685+#endif
20686+
20687+.macro __SAVE_ALL _DS
20688 cld
20689 PUSH_GS
20690 pushl_cfi %fs
20691@@ -206,7 +346,7 @@
20692 CFI_REL_OFFSET ecx, 0
20693 pushl_cfi %ebx
20694 CFI_REL_OFFSET ebx, 0
20695- movl $(__USER_DS), %edx
20696+ movl $\_DS, %edx
20697 movl %edx, %ds
20698 movl %edx, %es
20699 movl $(__KERNEL_PERCPU), %edx
20700@@ -214,6 +354,15 @@
20701 SET_KERNEL_GS %edx
20702 .endm
20703
20704+.macro SAVE_ALL
20705+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
20706+ __SAVE_ALL __KERNEL_DS
20707+ pax_enter_kernel
20708+#else
20709+ __SAVE_ALL __USER_DS
20710+#endif
20711+.endm
20712+
20713 .macro RESTORE_INT_REGS
20714 popl_cfi %ebx
20715 CFI_RESTORE ebx
20716@@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
20717 popfl_cfi
20718 jmp syscall_exit
20719 CFI_ENDPROC
20720-END(ret_from_fork)
20721+ENDPROC(ret_from_fork)
20722
20723 ENTRY(ret_from_kernel_thread)
20724 CFI_STARTPROC
20725@@ -344,7 +493,15 @@ ret_from_intr:
20726 andl $SEGMENT_RPL_MASK, %eax
20727 #endif
20728 cmpl $USER_RPL, %eax
20729+
20730+#ifdef CONFIG_PAX_KERNEXEC
20731+ jae resume_userspace
20732+
20733+ pax_exit_kernel
20734+ jmp resume_kernel
20735+#else
20736 jb resume_kernel # not returning to v8086 or userspace
20737+#endif
20738
20739 ENTRY(resume_userspace)
20740 LOCKDEP_SYS_EXIT
20741@@ -356,8 +513,8 @@ ENTRY(resume_userspace)
20742 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
20743 # int/exception return?
20744 jne work_pending
20745- jmp restore_all
20746-END(ret_from_exception)
20747+ jmp restore_all_pax
20748+ENDPROC(ret_from_exception)
20749
20750 #ifdef CONFIG_PREEMPT
20751 ENTRY(resume_kernel)
20752@@ -372,7 +529,7 @@ need_resched:
20753 jz restore_all
20754 call preempt_schedule_irq
20755 jmp need_resched
20756-END(resume_kernel)
20757+ENDPROC(resume_kernel)
20758 #endif
20759 CFI_ENDPROC
20760 /*
20761@@ -406,30 +563,45 @@ sysenter_past_esp:
20762 /*CFI_REL_OFFSET cs, 0*/
20763 /*
20764 * Push current_thread_info()->sysenter_return to the stack.
20765- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
20766- * pushed above; +8 corresponds to copy_thread's esp0 setting.
20767 */
20768- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
20769+ pushl_cfi $0
20770 CFI_REL_OFFSET eip, 0
20771
20772 pushl_cfi %eax
20773 SAVE_ALL
20774+ GET_THREAD_INFO(%ebp)
20775+ movl TI_sysenter_return(%ebp),%ebp
20776+ movl %ebp,PT_EIP(%esp)
20777 ENABLE_INTERRUPTS(CLBR_NONE)
20778
20779 /*
20780 * Load the potential sixth argument from user stack.
20781 * Careful about security.
20782 */
20783+ movl PT_OLDESP(%esp),%ebp
20784+
20785+#ifdef CONFIG_PAX_MEMORY_UDEREF
20786+ mov PT_OLDSS(%esp),%ds
20787+1: movl %ds:(%ebp),%ebp
20788+ push %ss
20789+ pop %ds
20790+#else
20791 cmpl $__PAGE_OFFSET-3,%ebp
20792 jae syscall_fault
20793 ASM_STAC
20794 1: movl (%ebp),%ebp
20795 ASM_CLAC
20796+#endif
20797+
20798 movl %ebp,PT_EBP(%esp)
20799 _ASM_EXTABLE(1b,syscall_fault)
20800
20801 GET_THREAD_INFO(%ebp)
20802
20803+#ifdef CONFIG_PAX_RANDKSTACK
20804+ pax_erase_kstack
20805+#endif
20806+
20807 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
20808 jnz sysenter_audit
20809 sysenter_do_call:
20810@@ -444,12 +616,24 @@ sysenter_do_call:
20811 testl $_TIF_ALLWORK_MASK, %ecx
20812 jne sysexit_audit
20813 sysenter_exit:
20814+
20815+#ifdef CONFIG_PAX_RANDKSTACK
20816+ pushl_cfi %eax
20817+ movl %esp, %eax
20818+ call pax_randomize_kstack
20819+ popl_cfi %eax
20820+#endif
20821+
20822+ pax_erase_kstack
20823+
20824 /* if something modifies registers it must also disable sysexit */
20825 movl PT_EIP(%esp), %edx
20826 movl PT_OLDESP(%esp), %ecx
20827 xorl %ebp,%ebp
20828 TRACE_IRQS_ON
20829 1: mov PT_FS(%esp), %fs
20830+2: mov PT_DS(%esp), %ds
20831+3: mov PT_ES(%esp), %es
20832 PTGS_TO_GS
20833 ENABLE_INTERRUPTS_SYSEXIT
20834
20835@@ -466,6 +650,9 @@ sysenter_audit:
20836 movl %eax,%edx /* 2nd arg: syscall number */
20837 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
20838 call __audit_syscall_entry
20839+
20840+ pax_erase_kstack
20841+
20842 pushl_cfi %ebx
20843 movl PT_EAX(%esp),%eax /* reload syscall number */
20844 jmp sysenter_do_call
20845@@ -491,10 +678,16 @@ sysexit_audit:
20846
20847 CFI_ENDPROC
20848 .pushsection .fixup,"ax"
20849-2: movl $0,PT_FS(%esp)
20850+4: movl $0,PT_FS(%esp)
20851+ jmp 1b
20852+5: movl $0,PT_DS(%esp)
20853+ jmp 1b
20854+6: movl $0,PT_ES(%esp)
20855 jmp 1b
20856 .popsection
20857- _ASM_EXTABLE(1b,2b)
20858+ _ASM_EXTABLE(1b,4b)
20859+ _ASM_EXTABLE(2b,5b)
20860+ _ASM_EXTABLE(3b,6b)
20861 PTGS_TO_GS_EX
20862 ENDPROC(ia32_sysenter_target)
20863
20864@@ -509,6 +702,11 @@ ENTRY(system_call)
20865 pushl_cfi %eax # save orig_eax
20866 SAVE_ALL
20867 GET_THREAD_INFO(%ebp)
20868+
20869+#ifdef CONFIG_PAX_RANDKSTACK
20870+ pax_erase_kstack
20871+#endif
20872+
20873 # system call tracing in operation / emulation
20874 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
20875 jnz syscall_trace_entry
20876@@ -527,6 +725,15 @@ syscall_exit:
20877 testl $_TIF_ALLWORK_MASK, %ecx # current->work
20878 jne syscall_exit_work
20879
20880+restore_all_pax:
20881+
20882+#ifdef CONFIG_PAX_RANDKSTACK
20883+ movl %esp, %eax
20884+ call pax_randomize_kstack
20885+#endif
20886+
20887+ pax_erase_kstack
20888+
20889 restore_all:
20890 TRACE_IRQS_IRET
20891 restore_all_notrace:
20892@@ -583,14 +790,34 @@ ldt_ss:
20893 * compensating for the offset by changing to the ESPFIX segment with
20894 * a base address that matches for the difference.
20895 */
20896-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
20897+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
20898 mov %esp, %edx /* load kernel esp */
20899 mov PT_OLDESP(%esp), %eax /* load userspace esp */
20900 mov %dx, %ax /* eax: new kernel esp */
20901 sub %eax, %edx /* offset (low word is 0) */
20902+#ifdef CONFIG_SMP
20903+ movl PER_CPU_VAR(cpu_number), %ebx
20904+ shll $PAGE_SHIFT_asm, %ebx
20905+ addl $cpu_gdt_table, %ebx
20906+#else
20907+ movl $cpu_gdt_table, %ebx
20908+#endif
20909 shr $16, %edx
20910- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
20911- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
20912+
20913+#ifdef CONFIG_PAX_KERNEXEC
20914+ mov %cr0, %esi
20915+ btr $16, %esi
20916+ mov %esi, %cr0
20917+#endif
20918+
20919+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
20920+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
20921+
20922+#ifdef CONFIG_PAX_KERNEXEC
20923+ bts $16, %esi
20924+ mov %esi, %cr0
20925+#endif
20926+
20927 pushl_cfi $__ESPFIX_SS
20928 pushl_cfi %eax /* new kernel esp */
20929 /* Disable interrupts, but do not irqtrace this section: we
20930@@ -619,20 +846,18 @@ work_resched:
20931 movl TI_flags(%ebp), %ecx
20932 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
20933 # than syscall tracing?
20934- jz restore_all
20935+ jz restore_all_pax
20936 testb $_TIF_NEED_RESCHED, %cl
20937 jnz work_resched
20938
20939 work_notifysig: # deal with pending signals and
20940 # notify-resume requests
20941+ movl %esp, %eax
20942 #ifdef CONFIG_VM86
20943 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
20944- movl %esp, %eax
20945 jne work_notifysig_v86 # returning to kernel-space or
20946 # vm86-space
20947 1:
20948-#else
20949- movl %esp, %eax
20950 #endif
20951 TRACE_IRQS_ON
20952 ENABLE_INTERRUPTS(CLBR_NONE)
20953@@ -653,7 +878,7 @@ work_notifysig_v86:
20954 movl %eax, %esp
20955 jmp 1b
20956 #endif
20957-END(work_pending)
20958+ENDPROC(work_pending)
20959
20960 # perform syscall exit tracing
20961 ALIGN
20962@@ -661,11 +886,14 @@ syscall_trace_entry:
20963 movl $-ENOSYS,PT_EAX(%esp)
20964 movl %esp, %eax
20965 call syscall_trace_enter
20966+
20967+ pax_erase_kstack
20968+
20969 /* What it returned is what we'll actually use. */
20970 cmpl $(NR_syscalls), %eax
20971 jnae syscall_call
20972 jmp syscall_exit
20973-END(syscall_trace_entry)
20974+ENDPROC(syscall_trace_entry)
20975
20976 # perform syscall exit tracing
20977 ALIGN
20978@@ -678,21 +906,25 @@ syscall_exit_work:
20979 movl %esp, %eax
20980 call syscall_trace_leave
20981 jmp resume_userspace
20982-END(syscall_exit_work)
20983+ENDPROC(syscall_exit_work)
20984 CFI_ENDPROC
20985
20986 RING0_INT_FRAME # can't unwind into user space anyway
20987 syscall_fault:
20988+#ifdef CONFIG_PAX_MEMORY_UDEREF
20989+ push %ss
20990+ pop %ds
20991+#endif
20992 ASM_CLAC
20993 GET_THREAD_INFO(%ebp)
20994 movl $-EFAULT,PT_EAX(%esp)
20995 jmp resume_userspace
20996-END(syscall_fault)
20997+ENDPROC(syscall_fault)
20998
20999 syscall_badsys:
21000 movl $-ENOSYS,PT_EAX(%esp)
21001 jmp resume_userspace
21002-END(syscall_badsys)
21003+ENDPROC(syscall_badsys)
21004 CFI_ENDPROC
21005 /*
21006 * End of kprobes section
21007@@ -708,8 +940,15 @@ END(syscall_badsys)
21008 * normal stack and adjusts ESP with the matching offset.
21009 */
21010 /* fixup the stack */
21011- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
21012- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
21013+#ifdef CONFIG_SMP
21014+ movl PER_CPU_VAR(cpu_number), %ebx
21015+ shll $PAGE_SHIFT_asm, %ebx
21016+ addl $cpu_gdt_table, %ebx
21017+#else
21018+ movl $cpu_gdt_table, %ebx
21019+#endif
21020+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
21021+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
21022 shl $16, %eax
21023 addl %esp, %eax /* the adjusted stack pointer */
21024 pushl_cfi $__KERNEL_DS
21025@@ -762,7 +1001,7 @@ vector=vector+1
21026 .endr
21027 2: jmp common_interrupt
21028 .endr
21029-END(irq_entries_start)
21030+ENDPROC(irq_entries_start)
21031
21032 .previous
21033 END(interrupt)
21034@@ -823,7 +1062,7 @@ ENTRY(coprocessor_error)
21035 pushl_cfi $do_coprocessor_error
21036 jmp error_code
21037 CFI_ENDPROC
21038-END(coprocessor_error)
21039+ENDPROC(coprocessor_error)
21040
21041 ENTRY(simd_coprocessor_error)
21042 RING0_INT_FRAME
21043@@ -836,7 +1075,7 @@ ENTRY(simd_coprocessor_error)
21044 .section .altinstructions,"a"
21045 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
21046 .previous
21047-.section .altinstr_replacement,"ax"
21048+.section .altinstr_replacement,"a"
21049 663: pushl $do_simd_coprocessor_error
21050 664:
21051 .previous
21052@@ -845,7 +1084,7 @@ ENTRY(simd_coprocessor_error)
21053 #endif
21054 jmp error_code
21055 CFI_ENDPROC
21056-END(simd_coprocessor_error)
21057+ENDPROC(simd_coprocessor_error)
21058
21059 ENTRY(device_not_available)
21060 RING0_INT_FRAME
21061@@ -854,18 +1093,18 @@ ENTRY(device_not_available)
21062 pushl_cfi $do_device_not_available
21063 jmp error_code
21064 CFI_ENDPROC
21065-END(device_not_available)
21066+ENDPROC(device_not_available)
21067
21068 #ifdef CONFIG_PARAVIRT
21069 ENTRY(native_iret)
21070 iret
21071 _ASM_EXTABLE(native_iret, iret_exc)
21072-END(native_iret)
21073+ENDPROC(native_iret)
21074
21075 ENTRY(native_irq_enable_sysexit)
21076 sti
21077 sysexit
21078-END(native_irq_enable_sysexit)
21079+ENDPROC(native_irq_enable_sysexit)
21080 #endif
21081
21082 ENTRY(overflow)
21083@@ -875,7 +1114,7 @@ ENTRY(overflow)
21084 pushl_cfi $do_overflow
21085 jmp error_code
21086 CFI_ENDPROC
21087-END(overflow)
21088+ENDPROC(overflow)
21089
21090 ENTRY(bounds)
21091 RING0_INT_FRAME
21092@@ -884,7 +1123,7 @@ ENTRY(bounds)
21093 pushl_cfi $do_bounds
21094 jmp error_code
21095 CFI_ENDPROC
21096-END(bounds)
21097+ENDPROC(bounds)
21098
21099 ENTRY(invalid_op)
21100 RING0_INT_FRAME
21101@@ -893,7 +1132,7 @@ ENTRY(invalid_op)
21102 pushl_cfi $do_invalid_op
21103 jmp error_code
21104 CFI_ENDPROC
21105-END(invalid_op)
21106+ENDPROC(invalid_op)
21107
21108 ENTRY(coprocessor_segment_overrun)
21109 RING0_INT_FRAME
21110@@ -902,7 +1141,7 @@ ENTRY(coprocessor_segment_overrun)
21111 pushl_cfi $do_coprocessor_segment_overrun
21112 jmp error_code
21113 CFI_ENDPROC
21114-END(coprocessor_segment_overrun)
21115+ENDPROC(coprocessor_segment_overrun)
21116
21117 ENTRY(invalid_TSS)
21118 RING0_EC_FRAME
21119@@ -910,7 +1149,7 @@ ENTRY(invalid_TSS)
21120 pushl_cfi $do_invalid_TSS
21121 jmp error_code
21122 CFI_ENDPROC
21123-END(invalid_TSS)
21124+ENDPROC(invalid_TSS)
21125
21126 ENTRY(segment_not_present)
21127 RING0_EC_FRAME
21128@@ -918,7 +1157,7 @@ ENTRY(segment_not_present)
21129 pushl_cfi $do_segment_not_present
21130 jmp error_code
21131 CFI_ENDPROC
21132-END(segment_not_present)
21133+ENDPROC(segment_not_present)
21134
21135 ENTRY(stack_segment)
21136 RING0_EC_FRAME
21137@@ -926,7 +1165,7 @@ ENTRY(stack_segment)
21138 pushl_cfi $do_stack_segment
21139 jmp error_code
21140 CFI_ENDPROC
21141-END(stack_segment)
21142+ENDPROC(stack_segment)
21143
21144 ENTRY(alignment_check)
21145 RING0_EC_FRAME
21146@@ -934,7 +1173,7 @@ ENTRY(alignment_check)
21147 pushl_cfi $do_alignment_check
21148 jmp error_code
21149 CFI_ENDPROC
21150-END(alignment_check)
21151+ENDPROC(alignment_check)
21152
21153 ENTRY(divide_error)
21154 RING0_INT_FRAME
21155@@ -943,7 +1182,7 @@ ENTRY(divide_error)
21156 pushl_cfi $do_divide_error
21157 jmp error_code
21158 CFI_ENDPROC
21159-END(divide_error)
21160+ENDPROC(divide_error)
21161
21162 #ifdef CONFIG_X86_MCE
21163 ENTRY(machine_check)
21164@@ -953,7 +1192,7 @@ ENTRY(machine_check)
21165 pushl_cfi machine_check_vector
21166 jmp error_code
21167 CFI_ENDPROC
21168-END(machine_check)
21169+ENDPROC(machine_check)
21170 #endif
21171
21172 ENTRY(spurious_interrupt_bug)
21173@@ -963,7 +1202,7 @@ ENTRY(spurious_interrupt_bug)
21174 pushl_cfi $do_spurious_interrupt_bug
21175 jmp error_code
21176 CFI_ENDPROC
21177-END(spurious_interrupt_bug)
21178+ENDPROC(spurious_interrupt_bug)
21179 /*
21180 * End of kprobes section
21181 */
21182@@ -1073,7 +1312,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
21183
21184 ENTRY(mcount)
21185 ret
21186-END(mcount)
21187+ENDPROC(mcount)
21188
21189 ENTRY(ftrace_caller)
21190 cmpl $0, function_trace_stop
21191@@ -1106,7 +1345,7 @@ ftrace_graph_call:
21192 .globl ftrace_stub
21193 ftrace_stub:
21194 ret
21195-END(ftrace_caller)
21196+ENDPROC(ftrace_caller)
21197
21198 ENTRY(ftrace_regs_caller)
21199 pushf /* push flags before compare (in cs location) */
21200@@ -1207,7 +1446,7 @@ trace:
21201 popl %ecx
21202 popl %eax
21203 jmp ftrace_stub
21204-END(mcount)
21205+ENDPROC(mcount)
21206 #endif /* CONFIG_DYNAMIC_FTRACE */
21207 #endif /* CONFIG_FUNCTION_TRACER */
21208
21209@@ -1225,7 +1464,7 @@ ENTRY(ftrace_graph_caller)
21210 popl %ecx
21211 popl %eax
21212 ret
21213-END(ftrace_graph_caller)
21214+ENDPROC(ftrace_graph_caller)
21215
21216 .globl return_to_handler
21217 return_to_handler:
21218@@ -1281,15 +1520,18 @@ error_code:
21219 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
21220 REG_TO_PTGS %ecx
21221 SET_KERNEL_GS %ecx
21222- movl $(__USER_DS), %ecx
21223+ movl $(__KERNEL_DS), %ecx
21224 movl %ecx, %ds
21225 movl %ecx, %es
21226+
21227+ pax_enter_kernel
21228+
21229 TRACE_IRQS_OFF
21230 movl %esp,%eax # pt_regs pointer
21231 call *%edi
21232 jmp ret_from_exception
21233 CFI_ENDPROC
21234-END(page_fault)
21235+ENDPROC(page_fault)
21236
21237 /*
21238 * Debug traps and NMI can happen at the one SYSENTER instruction
21239@@ -1332,7 +1574,7 @@ debug_stack_correct:
21240 call do_debug
21241 jmp ret_from_exception
21242 CFI_ENDPROC
21243-END(debug)
21244+ENDPROC(debug)
21245
21246 /*
21247 * NMI is doubly nasty. It can happen _while_ we're handling
21248@@ -1370,6 +1612,9 @@ nmi_stack_correct:
21249 xorl %edx,%edx # zero error code
21250 movl %esp,%eax # pt_regs pointer
21251 call do_nmi
21252+
21253+ pax_exit_kernel
21254+
21255 jmp restore_all_notrace
21256 CFI_ENDPROC
21257
21258@@ -1406,12 +1651,15 @@ nmi_espfix_stack:
21259 FIXUP_ESPFIX_STACK # %eax == %esp
21260 xorl %edx,%edx # zero error code
21261 call do_nmi
21262+
21263+ pax_exit_kernel
21264+
21265 RESTORE_REGS
21266 lss 12+4(%esp), %esp # back to espfix stack
21267 CFI_ADJUST_CFA_OFFSET -24
21268 jmp irq_return
21269 CFI_ENDPROC
21270-END(nmi)
21271+ENDPROC(nmi)
21272
21273 ENTRY(int3)
21274 RING0_INT_FRAME
21275@@ -1424,14 +1672,14 @@ ENTRY(int3)
21276 call do_int3
21277 jmp ret_from_exception
21278 CFI_ENDPROC
21279-END(int3)
21280+ENDPROC(int3)
21281
21282 ENTRY(general_protection)
21283 RING0_EC_FRAME
21284 pushl_cfi $do_general_protection
21285 jmp error_code
21286 CFI_ENDPROC
21287-END(general_protection)
21288+ENDPROC(general_protection)
21289
21290 #ifdef CONFIG_KVM_GUEST
21291 ENTRY(async_page_fault)
21292@@ -1440,7 +1688,7 @@ ENTRY(async_page_fault)
21293 pushl_cfi $do_async_page_fault
21294 jmp error_code
21295 CFI_ENDPROC
21296-END(async_page_fault)
21297+ENDPROC(async_page_fault)
21298 #endif
21299
21300 /*
21301diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
21302index 1b69951..8430a6d 100644
21303--- a/arch/x86/kernel/entry_64.S
21304+++ b/arch/x86/kernel/entry_64.S
21305@@ -59,6 +59,8 @@
21306 #include <asm/context_tracking.h>
21307 #include <asm/smap.h>
21308 #include <linux/err.h>
21309+#include <asm/pgtable.h>
21310+#include <asm/alternative-asm.h>
21311
21312 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
21313 #include <linux/elf-em.h>
21314@@ -80,8 +82,9 @@
21315 #ifdef CONFIG_DYNAMIC_FTRACE
21316
21317 ENTRY(function_hook)
21318+ pax_force_retaddr
21319 retq
21320-END(function_hook)
21321+ENDPROC(function_hook)
21322
21323 /* skip is set if stack has been adjusted */
21324 .macro ftrace_caller_setup skip=0
21325@@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
21326 #endif
21327
21328 GLOBAL(ftrace_stub)
21329+ pax_force_retaddr
21330 retq
21331-END(ftrace_caller)
21332+ENDPROC(ftrace_caller)
21333
21334 ENTRY(ftrace_regs_caller)
21335 /* Save the current flags before compare (in SS location)*/
21336@@ -191,7 +195,7 @@ ftrace_restore_flags:
21337 popfq
21338 jmp ftrace_stub
21339
21340-END(ftrace_regs_caller)
21341+ENDPROC(ftrace_regs_caller)
21342
21343
21344 #else /* ! CONFIG_DYNAMIC_FTRACE */
21345@@ -212,6 +216,7 @@ ENTRY(function_hook)
21346 #endif
21347
21348 GLOBAL(ftrace_stub)
21349+ pax_force_retaddr
21350 retq
21351
21352 trace:
21353@@ -225,12 +230,13 @@ trace:
21354 #endif
21355 subq $MCOUNT_INSN_SIZE, %rdi
21356
21357+ pax_force_fptr ftrace_trace_function
21358 call *ftrace_trace_function
21359
21360 MCOUNT_RESTORE_FRAME
21361
21362 jmp ftrace_stub
21363-END(function_hook)
21364+ENDPROC(function_hook)
21365 #endif /* CONFIG_DYNAMIC_FTRACE */
21366 #endif /* CONFIG_FUNCTION_TRACER */
21367
21368@@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
21369
21370 MCOUNT_RESTORE_FRAME
21371
21372+ pax_force_retaddr
21373 retq
21374-END(ftrace_graph_caller)
21375+ENDPROC(ftrace_graph_caller)
21376
21377 GLOBAL(return_to_handler)
21378 subq $24, %rsp
21379@@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
21380 movq 8(%rsp), %rdx
21381 movq (%rsp), %rax
21382 addq $24, %rsp
21383+ pax_force_fptr %rdi
21384 jmp *%rdi
21385+ENDPROC(return_to_handler)
21386 #endif
21387
21388
21389@@ -284,6 +293,430 @@ ENTRY(native_usergs_sysret64)
21390 ENDPROC(native_usergs_sysret64)
21391 #endif /* CONFIG_PARAVIRT */
21392
21393+ .macro ljmpq sel, off
21394+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
21395+ .byte 0x48; ljmp *1234f(%rip)
21396+ .pushsection .rodata
21397+ .align 16
21398+ 1234: .quad \off; .word \sel
21399+ .popsection
21400+#else
21401+ pushq $\sel
21402+ pushq $\off
21403+ lretq
21404+#endif
21405+ .endm
21406+
21407+ .macro pax_enter_kernel
21408+ pax_set_fptr_mask
21409+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
21410+ call pax_enter_kernel
21411+#endif
21412+ .endm
21413+
21414+ .macro pax_exit_kernel
21415+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
21416+ call pax_exit_kernel
21417+#endif
21418+
21419+ .endm
21420+
21421+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
21422+ENTRY(pax_enter_kernel)
21423+ pushq %rdi
21424+
21425+#ifdef CONFIG_PARAVIRT
21426+ PV_SAVE_REGS(CLBR_RDI)
21427+#endif
21428+
21429+#ifdef CONFIG_PAX_KERNEXEC
21430+ GET_CR0_INTO_RDI
21431+ bts $16,%rdi
21432+ jnc 3f
21433+ mov %cs,%edi
21434+ cmp $__KERNEL_CS,%edi
21435+ jnz 2f
21436+1:
21437+#endif
21438+
21439+#ifdef CONFIG_PAX_MEMORY_UDEREF
21440+ 661: jmp 111f
21441+ .pushsection .altinstr_replacement, "a"
21442+ 662: ASM_NOP2
21443+ .popsection
21444+ .pushsection .altinstructions, "a"
21445+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
21446+ .popsection
21447+ GET_CR3_INTO_RDI
21448+ cmp $0,%dil
21449+ jnz 112f
21450+ mov $__KERNEL_DS,%edi
21451+ mov %edi,%ss
21452+ jmp 111f
21453+112: cmp $1,%dil
21454+ jz 113f
21455+ ud2
21456+113: sub $4097,%rdi
21457+ bts $63,%rdi
21458+ SET_RDI_INTO_CR3
21459+ mov $__UDEREF_KERNEL_DS,%edi
21460+ mov %edi,%ss
21461+111:
21462+#endif
21463+
21464+#ifdef CONFIG_PARAVIRT
21465+ PV_RESTORE_REGS(CLBR_RDI)
21466+#endif
21467+
21468+ popq %rdi
21469+ pax_force_retaddr
21470+ retq
21471+
21472+#ifdef CONFIG_PAX_KERNEXEC
21473+2: ljmpq __KERNEL_CS,1b
21474+3: ljmpq __KERNEXEC_KERNEL_CS,4f
21475+4: SET_RDI_INTO_CR0
21476+ jmp 1b
21477+#endif
21478+ENDPROC(pax_enter_kernel)
21479+
21480+ENTRY(pax_exit_kernel)
21481+ pushq %rdi
21482+
21483+#ifdef CONFIG_PARAVIRT
21484+ PV_SAVE_REGS(CLBR_RDI)
21485+#endif
21486+
21487+#ifdef CONFIG_PAX_KERNEXEC
21488+ mov %cs,%rdi
21489+ cmp $__KERNEXEC_KERNEL_CS,%edi
21490+ jz 2f
21491+ GET_CR0_INTO_RDI
21492+ bts $16,%rdi
21493+ jnc 4f
21494+1:
21495+#endif
21496+
21497+#ifdef CONFIG_PAX_MEMORY_UDEREF
21498+ 661: jmp 111f
21499+ .pushsection .altinstr_replacement, "a"
21500+ 662: ASM_NOP2
21501+ .popsection
21502+ .pushsection .altinstructions, "a"
21503+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
21504+ .popsection
21505+ mov %ss,%edi
21506+ cmp $__UDEREF_KERNEL_DS,%edi
21507+ jnz 111f
21508+ GET_CR3_INTO_RDI
21509+ cmp $0,%dil
21510+ jz 112f
21511+ ud2
21512+112: add $4097,%rdi
21513+ bts $63,%rdi
21514+ SET_RDI_INTO_CR3
21515+ mov $__KERNEL_DS,%edi
21516+ mov %edi,%ss
21517+111:
21518+#endif
21519+
21520+#ifdef CONFIG_PARAVIRT
21521+ PV_RESTORE_REGS(CLBR_RDI);
21522+#endif
21523+
21524+ popq %rdi
21525+ pax_force_retaddr
21526+ retq
21527+
21528+#ifdef CONFIG_PAX_KERNEXEC
21529+2: GET_CR0_INTO_RDI
21530+ btr $16,%rdi
21531+ jnc 4f
21532+ ljmpq __KERNEL_CS,3f
21533+3: SET_RDI_INTO_CR0
21534+ jmp 1b
21535+4: ud2
21536+ jmp 4b
21537+#endif
21538+ENDPROC(pax_exit_kernel)
21539+#endif
21540+
21541+ .macro pax_enter_kernel_user
21542+ pax_set_fptr_mask
21543+#ifdef CONFIG_PAX_MEMORY_UDEREF
21544+ call pax_enter_kernel_user
21545+#endif
21546+ .endm
21547+
21548+ .macro pax_exit_kernel_user
21549+#ifdef CONFIG_PAX_MEMORY_UDEREF
21550+ call pax_exit_kernel_user
21551+#endif
21552+#ifdef CONFIG_PAX_RANDKSTACK
21553+ pushq %rax
21554+ pushq %r11
21555+ call pax_randomize_kstack
21556+ popq %r11
21557+ popq %rax
21558+#endif
21559+ .endm
21560+
21561+#ifdef CONFIG_PAX_MEMORY_UDEREF
21562+ENTRY(pax_enter_kernel_user)
21563+ pushq %rdi
21564+ pushq %rbx
21565+
21566+#ifdef CONFIG_PARAVIRT
21567+ PV_SAVE_REGS(CLBR_RDI)
21568+#endif
21569+
21570+ 661: jmp 111f
21571+ .pushsection .altinstr_replacement, "a"
21572+ 662: ASM_NOP2
21573+ .popsection
21574+ .pushsection .altinstructions, "a"
21575+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
21576+ .popsection
21577+ GET_CR3_INTO_RDI
21578+ cmp $1,%dil
21579+ jnz 4f
21580+ sub $4097,%rdi
21581+ bts $63,%rdi
21582+ SET_RDI_INTO_CR3
21583+ jmp 3f
21584+111:
21585+
21586+ GET_CR3_INTO_RDI
21587+ mov %rdi,%rbx
21588+ add $__START_KERNEL_map,%rbx
21589+ sub phys_base(%rip),%rbx
21590+
21591+#ifdef CONFIG_PARAVIRT
21592+ cmpl $0, pv_info+PARAVIRT_enabled
21593+ jz 1f
21594+ pushq %rdi
21595+ i = 0
21596+ .rept USER_PGD_PTRS
21597+ mov i*8(%rbx),%rsi
21598+ mov $0,%sil
21599+ lea i*8(%rbx),%rdi
21600+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
21601+ i = i + 1
21602+ .endr
21603+ popq %rdi
21604+ jmp 2f
21605+1:
21606+#endif
21607+
21608+ i = 0
21609+ .rept USER_PGD_PTRS
21610+ movb $0,i*8(%rbx)
21611+ i = i + 1
21612+ .endr
21613+
21614+2: SET_RDI_INTO_CR3
21615+
21616+#ifdef CONFIG_PAX_KERNEXEC
21617+ GET_CR0_INTO_RDI
21618+ bts $16,%rdi
21619+ SET_RDI_INTO_CR0
21620+#endif
21621+
21622+3:
21623+
21624+#ifdef CONFIG_PARAVIRT
21625+ PV_RESTORE_REGS(CLBR_RDI)
21626+#endif
21627+
21628+ popq %rbx
21629+ popq %rdi
21630+ pax_force_retaddr
21631+ retq
21632+4: ud2
21633+ENDPROC(pax_enter_kernel_user)
21634+
21635+ENTRY(pax_exit_kernel_user)
21636+ pushq %rdi
21637+ pushq %rbx
21638+
21639+#ifdef CONFIG_PARAVIRT
21640+ PV_SAVE_REGS(CLBR_RDI)
21641+#endif
21642+
21643+ GET_CR3_INTO_RDI
21644+ 661: jmp 1f
21645+ .pushsection .altinstr_replacement, "a"
21646+ 662: ASM_NOP2
21647+ .popsection
21648+ .pushsection .altinstructions, "a"
21649+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
21650+ .popsection
21651+ cmp $0,%dil
21652+ jnz 3f
21653+ add $4097,%rdi
21654+ bts $63,%rdi
21655+ SET_RDI_INTO_CR3
21656+ jmp 2f
21657+1:
21658+
21659+ mov %rdi,%rbx
21660+
21661+#ifdef CONFIG_PAX_KERNEXEC
21662+ GET_CR0_INTO_RDI
21663+ btr $16,%rdi
21664+ jnc 3f
21665+ SET_RDI_INTO_CR0
21666+#endif
21667+
21668+ add $__START_KERNEL_map,%rbx
21669+ sub phys_base(%rip),%rbx
21670+
21671+#ifdef CONFIG_PARAVIRT
21672+ cmpl $0, pv_info+PARAVIRT_enabled
21673+ jz 1f
21674+ i = 0
21675+ .rept USER_PGD_PTRS
21676+ mov i*8(%rbx),%rsi
21677+ mov $0x67,%sil
21678+ lea i*8(%rbx),%rdi
21679+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
21680+ i = i + 1
21681+ .endr
21682+ jmp 2f
21683+1:
21684+#endif
21685+
21686+ i = 0
21687+ .rept USER_PGD_PTRS
21688+ movb $0x67,i*8(%rbx)
21689+ i = i + 1
21690+ .endr
21691+2:
21692+
21693+#ifdef CONFIG_PARAVIRT
21694+ PV_RESTORE_REGS(CLBR_RDI)
21695+#endif
21696+
21697+ popq %rbx
21698+ popq %rdi
21699+ pax_force_retaddr
21700+ retq
21701+3: ud2
21702+ENDPROC(pax_exit_kernel_user)
21703+#endif
21704+
21705+ .macro pax_enter_kernel_nmi
21706+ pax_set_fptr_mask
21707+
21708+#ifdef CONFIG_PAX_KERNEXEC
21709+ GET_CR0_INTO_RDI
21710+ bts $16,%rdi
21711+ jc 110f
21712+ SET_RDI_INTO_CR0
21713+ or $2,%ebx
21714+110:
21715+#endif
21716+
21717+#ifdef CONFIG_PAX_MEMORY_UDEREF
21718+ 661: jmp 111f
21719+ .pushsection .altinstr_replacement, "a"
21720+ 662: ASM_NOP2
21721+ .popsection
21722+ .pushsection .altinstructions, "a"
21723+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
21724+ .popsection
21725+ GET_CR3_INTO_RDI
21726+ cmp $0,%dil
21727+ jz 111f
21728+ sub $4097,%rdi
21729+ or $4,%ebx
21730+ bts $63,%rdi
21731+ SET_RDI_INTO_CR3
21732+ mov $__UDEREF_KERNEL_DS,%edi
21733+ mov %edi,%ss
21734+111:
21735+#endif
21736+ .endm
21737+
21738+ .macro pax_exit_kernel_nmi
21739+#ifdef CONFIG_PAX_KERNEXEC
21740+ btr $1,%ebx
21741+ jnc 110f
21742+ GET_CR0_INTO_RDI
21743+ btr $16,%rdi
21744+ SET_RDI_INTO_CR0
21745+110:
21746+#endif
21747+
21748+#ifdef CONFIG_PAX_MEMORY_UDEREF
21749+ btr $2,%ebx
21750+ jnc 111f
21751+ GET_CR3_INTO_RDI
21752+ add $4097,%rdi
21753+ bts $63,%rdi
21754+ SET_RDI_INTO_CR3
21755+ mov $__KERNEL_DS,%edi
21756+ mov %edi,%ss
21757+111:
21758+#endif
21759+ .endm
21760+
21761+ .macro pax_erase_kstack
21762+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21763+ call pax_erase_kstack
21764+#endif
21765+ .endm
21766+
21767+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21768+ENTRY(pax_erase_kstack)
21769+ pushq %rdi
21770+ pushq %rcx
21771+ pushq %rax
21772+ pushq %r11
21773+
21774+ GET_THREAD_INFO(%r11)
21775+ mov TI_lowest_stack(%r11), %rdi
21776+ mov $-0xBEEF, %rax
21777+ std
21778+
21779+1: mov %edi, %ecx
21780+ and $THREAD_SIZE_asm - 1, %ecx
21781+ shr $3, %ecx
21782+ repne scasq
21783+ jecxz 2f
21784+
21785+ cmp $2*8, %ecx
21786+ jc 2f
21787+
21788+ mov $2*8, %ecx
21789+ repe scasq
21790+ jecxz 2f
21791+ jne 1b
21792+
21793+2: cld
21794+ mov %esp, %ecx
21795+ sub %edi, %ecx
21796+
21797+ cmp $THREAD_SIZE_asm, %rcx
21798+ jb 3f
21799+ ud2
21800+3:
21801+
21802+ shr $3, %ecx
21803+ rep stosq
21804+
21805+ mov TI_task_thread_sp0(%r11), %rdi
21806+ sub $256, %rdi
21807+ mov %rdi, TI_lowest_stack(%r11)
21808+
21809+ popq %r11
21810+ popq %rax
21811+ popq %rcx
21812+ popq %rdi
21813+ pax_force_retaddr
21814+ ret
21815+ENDPROC(pax_erase_kstack)
21816+#endif
21817
21818 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
21819 #ifdef CONFIG_TRACE_IRQFLAGS
21820@@ -375,8 +808,8 @@ ENDPROC(native_usergs_sysret64)
21821 .endm
21822
21823 .macro UNFAKE_STACK_FRAME
21824- addq $8*6, %rsp
21825- CFI_ADJUST_CFA_OFFSET -(6*8)
21826+ addq $8*6 + ARG_SKIP, %rsp
21827+ CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
21828 .endm
21829
21830 /*
21831@@ -463,7 +896,7 @@ ENDPROC(native_usergs_sysret64)
21832 movq %rsp, %rsi
21833
21834 leaq -RBP(%rsp),%rdi /* arg1 for handler */
21835- testl $3, CS-RBP(%rsi)
21836+ testb $3, CS-RBP(%rsi)
21837 je 1f
21838 SWAPGS
21839 /*
21840@@ -498,9 +931,10 @@ ENTRY(save_rest)
21841 movq_cfi r15, R15+16
21842 movq %r11, 8(%rsp) /* return address */
21843 FIXUP_TOP_OF_STACK %r11, 16
21844+ pax_force_retaddr
21845 ret
21846 CFI_ENDPROC
21847-END(save_rest)
21848+ENDPROC(save_rest)
21849
21850 /* save complete stack frame */
21851 .pushsection .kprobes.text, "ax"
21852@@ -529,9 +963,10 @@ ENTRY(save_paranoid)
21853 js 1f /* negative -> in kernel */
21854 SWAPGS
21855 xorl %ebx,%ebx
21856-1: ret
21857+1: pax_force_retaddr_bts
21858+ ret
21859 CFI_ENDPROC
21860-END(save_paranoid)
21861+ENDPROC(save_paranoid)
21862 .popsection
21863
21864 /*
21865@@ -553,7 +988,7 @@ ENTRY(ret_from_fork)
21866
21867 RESTORE_REST
21868
21869- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
21870+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
21871 jz 1f
21872
21873 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
21874@@ -571,7 +1006,7 @@ ENTRY(ret_from_fork)
21875 RESTORE_REST
21876 jmp int_ret_from_sys_call
21877 CFI_ENDPROC
21878-END(ret_from_fork)
21879+ENDPROC(ret_from_fork)
21880
21881 /*
21882 * System call entry. Up to 6 arguments in registers are supported.
21883@@ -608,7 +1043,7 @@ END(ret_from_fork)
21884 ENTRY(system_call)
21885 CFI_STARTPROC simple
21886 CFI_SIGNAL_FRAME
21887- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
21888+ CFI_DEF_CFA rsp,0
21889 CFI_REGISTER rip,rcx
21890 /*CFI_REGISTER rflags,r11*/
21891 SWAPGS_UNSAFE_STACK
21892@@ -621,16 +1056,23 @@ GLOBAL(system_call_after_swapgs)
21893
21894 movq %rsp,PER_CPU_VAR(old_rsp)
21895 movq PER_CPU_VAR(kernel_stack),%rsp
21896+ SAVE_ARGS 8*6,0
21897+ pax_enter_kernel_user
21898+
21899+#ifdef CONFIG_PAX_RANDKSTACK
21900+ pax_erase_kstack
21901+#endif
21902+
21903 /*
21904 * No need to follow this irqs off/on section - it's straight
21905 * and short:
21906 */
21907 ENABLE_INTERRUPTS(CLBR_NONE)
21908- SAVE_ARGS 8,0
21909 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
21910 movq %rcx,RIP-ARGOFFSET(%rsp)
21911 CFI_REL_OFFSET rip,RIP-ARGOFFSET
21912- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
21913+ GET_THREAD_INFO(%rcx)
21914+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
21915 jnz tracesys
21916 system_call_fastpath:
21917 #if __SYSCALL_MASK == ~0
21918@@ -640,7 +1082,7 @@ system_call_fastpath:
21919 cmpl $__NR_syscall_max,%eax
21920 #endif
21921 ja badsys
21922- movq %r10,%rcx
21923+ movq R10-ARGOFFSET(%rsp),%rcx
21924 call *sys_call_table(,%rax,8) # XXX: rip relative
21925 movq %rax,RAX-ARGOFFSET(%rsp)
21926 /*
21927@@ -654,10 +1096,13 @@ sysret_check:
21928 LOCKDEP_SYS_EXIT
21929 DISABLE_INTERRUPTS(CLBR_NONE)
21930 TRACE_IRQS_OFF
21931- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
21932+ GET_THREAD_INFO(%rcx)
21933+ movl TI_flags(%rcx),%edx
21934 andl %edi,%edx
21935 jnz sysret_careful
21936 CFI_REMEMBER_STATE
21937+ pax_exit_kernel_user
21938+ pax_erase_kstack
21939 /*
21940 * sysretq will re-enable interrupts:
21941 */
21942@@ -709,14 +1154,18 @@ badsys:
21943 * jump back to the normal fast path.
21944 */
21945 auditsys:
21946- movq %r10,%r9 /* 6th arg: 4th syscall arg */
21947+ movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
21948 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
21949 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
21950 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
21951 movq %rax,%rsi /* 2nd arg: syscall number */
21952 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
21953 call __audit_syscall_entry
21954+
21955+ pax_erase_kstack
21956+
21957 LOAD_ARGS 0 /* reload call-clobbered registers */
21958+ pax_set_fptr_mask
21959 jmp system_call_fastpath
21960
21961 /*
21962@@ -737,7 +1186,7 @@ sysret_audit:
21963 /* Do syscall tracing */
21964 tracesys:
21965 #ifdef CONFIG_AUDITSYSCALL
21966- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
21967+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
21968 jz auditsys
21969 #endif
21970 SAVE_REST
21971@@ -745,12 +1194,16 @@ tracesys:
21972 FIXUP_TOP_OF_STACK %rdi
21973 movq %rsp,%rdi
21974 call syscall_trace_enter
21975+
21976+ pax_erase_kstack
21977+
21978 /*
21979 * Reload arg registers from stack in case ptrace changed them.
21980 * We don't reload %rax because syscall_trace_enter() returned
21981 * the value it wants us to use in the table lookup.
21982 */
21983 LOAD_ARGS ARGOFFSET, 1
21984+ pax_set_fptr_mask
21985 RESTORE_REST
21986 #if __SYSCALL_MASK == ~0
21987 cmpq $__NR_syscall_max,%rax
21988@@ -759,7 +1212,7 @@ tracesys:
21989 cmpl $__NR_syscall_max,%eax
21990 #endif
21991 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
21992- movq %r10,%rcx /* fixup for C */
21993+ movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
21994 call *sys_call_table(,%rax,8)
21995 movq %rax,RAX-ARGOFFSET(%rsp)
21996 /* Use IRET because user could have changed frame */
21997@@ -780,7 +1233,9 @@ GLOBAL(int_with_check)
21998 andl %edi,%edx
21999 jnz int_careful
22000 andl $~TS_COMPAT,TI_status(%rcx)
22001- jmp retint_swapgs
22002+ pax_exit_kernel_user
22003+ pax_erase_kstack
22004+ jmp retint_swapgs_pax
22005
22006 /* Either reschedule or signal or syscall exit tracking needed. */
22007 /* First do a reschedule test. */
22008@@ -826,7 +1281,7 @@ int_restore_rest:
22009 TRACE_IRQS_OFF
22010 jmp int_with_check
22011 CFI_ENDPROC
22012-END(system_call)
22013+ENDPROC(system_call)
22014
22015 .macro FORK_LIKE func
22016 ENTRY(stub_\func)
22017@@ -839,9 +1294,10 @@ ENTRY(stub_\func)
22018 DEFAULT_FRAME 0 8 /* offset 8: return address */
22019 call sys_\func
22020 RESTORE_TOP_OF_STACK %r11, 8
22021+ pax_force_retaddr
22022 ret $REST_SKIP /* pop extended registers */
22023 CFI_ENDPROC
22024-END(stub_\func)
22025+ENDPROC(stub_\func)
22026 .endm
22027
22028 .macro FIXED_FRAME label,func
22029@@ -851,9 +1307,10 @@ ENTRY(\label)
22030 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
22031 call \func
22032 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
22033+ pax_force_retaddr
22034 ret
22035 CFI_ENDPROC
22036-END(\label)
22037+ENDPROC(\label)
22038 .endm
22039
22040 FORK_LIKE clone
22041@@ -870,9 +1327,10 @@ ENTRY(ptregscall_common)
22042 movq_cfi_restore R12+8, r12
22043 movq_cfi_restore RBP+8, rbp
22044 movq_cfi_restore RBX+8, rbx
22045+ pax_force_retaddr
22046 ret $REST_SKIP /* pop extended registers */
22047 CFI_ENDPROC
22048-END(ptregscall_common)
22049+ENDPROC(ptregscall_common)
22050
22051 ENTRY(stub_execve)
22052 CFI_STARTPROC
22053@@ -885,7 +1343,7 @@ ENTRY(stub_execve)
22054 RESTORE_REST
22055 jmp int_ret_from_sys_call
22056 CFI_ENDPROC
22057-END(stub_execve)
22058+ENDPROC(stub_execve)
22059
22060 /*
22061 * sigreturn is special because it needs to restore all registers on return.
22062@@ -902,7 +1360,7 @@ ENTRY(stub_rt_sigreturn)
22063 RESTORE_REST
22064 jmp int_ret_from_sys_call
22065 CFI_ENDPROC
22066-END(stub_rt_sigreturn)
22067+ENDPROC(stub_rt_sigreturn)
22068
22069 #ifdef CONFIG_X86_X32_ABI
22070 ENTRY(stub_x32_rt_sigreturn)
22071@@ -916,7 +1374,7 @@ ENTRY(stub_x32_rt_sigreturn)
22072 RESTORE_REST
22073 jmp int_ret_from_sys_call
22074 CFI_ENDPROC
22075-END(stub_x32_rt_sigreturn)
22076+ENDPROC(stub_x32_rt_sigreturn)
22077
22078 ENTRY(stub_x32_execve)
22079 CFI_STARTPROC
22080@@ -930,7 +1388,7 @@ ENTRY(stub_x32_execve)
22081 RESTORE_REST
22082 jmp int_ret_from_sys_call
22083 CFI_ENDPROC
22084-END(stub_x32_execve)
22085+ENDPROC(stub_x32_execve)
22086
22087 #endif
22088
22089@@ -967,7 +1425,7 @@ vector=vector+1
22090 2: jmp common_interrupt
22091 .endr
22092 CFI_ENDPROC
22093-END(irq_entries_start)
22094+ENDPROC(irq_entries_start)
22095
22096 .previous
22097 END(interrupt)
22098@@ -987,6 +1445,16 @@ END(interrupt)
22099 subq $ORIG_RAX-RBP, %rsp
22100 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
22101 SAVE_ARGS_IRQ
22102+#ifdef CONFIG_PAX_MEMORY_UDEREF
22103+ testb $3, CS(%rdi)
22104+ jnz 1f
22105+ pax_enter_kernel
22106+ jmp 2f
22107+1: pax_enter_kernel_user
22108+2:
22109+#else
22110+ pax_enter_kernel
22111+#endif
22112 call \func
22113 .endm
22114
22115@@ -1019,7 +1487,7 @@ ret_from_intr:
22116
22117 exit_intr:
22118 GET_THREAD_INFO(%rcx)
22119- testl $3,CS-ARGOFFSET(%rsp)
22120+ testb $3,CS-ARGOFFSET(%rsp)
22121 je retint_kernel
22122
22123 /* Interrupt came from user space */
22124@@ -1041,12 +1509,16 @@ retint_swapgs: /* return to user-space */
22125 * The iretq could re-enable interrupts:
22126 */
22127 DISABLE_INTERRUPTS(CLBR_ANY)
22128+ pax_exit_kernel_user
22129+retint_swapgs_pax:
22130 TRACE_IRQS_IRETQ
22131 SWAPGS
22132 jmp restore_args
22133
22134 retint_restore_args: /* return to kernel space */
22135 DISABLE_INTERRUPTS(CLBR_ANY)
22136+ pax_exit_kernel
22137+ pax_force_retaddr (RIP-ARGOFFSET)
22138 /*
22139 * The iretq could re-enable interrupts:
22140 */
22141@@ -1129,7 +1601,7 @@ ENTRY(retint_kernel)
22142 #endif
22143
22144 CFI_ENDPROC
22145-END(common_interrupt)
22146+ENDPROC(common_interrupt)
22147 /*
22148 * End of kprobes section
22149 */
22150@@ -1147,7 +1619,7 @@ ENTRY(\sym)
22151 interrupt \do_sym
22152 jmp ret_from_intr
22153 CFI_ENDPROC
22154-END(\sym)
22155+ENDPROC(\sym)
22156 .endm
22157
22158 #ifdef CONFIG_TRACING
22159@@ -1230,12 +1702,22 @@ ENTRY(\sym)
22160 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
22161 call error_entry
22162 DEFAULT_FRAME 0
22163+#ifdef CONFIG_PAX_MEMORY_UDEREF
22164+ testb $3, CS(%rsp)
22165+ jnz 1f
22166+ pax_enter_kernel
22167+ jmp 2f
22168+1: pax_enter_kernel_user
22169+2:
22170+#else
22171+ pax_enter_kernel
22172+#endif
22173 movq %rsp,%rdi /* pt_regs pointer */
22174 xorl %esi,%esi /* no error code */
22175 call \do_sym
22176 jmp error_exit /* %ebx: no swapgs flag */
22177 CFI_ENDPROC
22178-END(\sym)
22179+ENDPROC(\sym)
22180 .endm
22181
22182 .macro paranoidzeroentry sym do_sym
22183@@ -1248,15 +1730,25 @@ ENTRY(\sym)
22184 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
22185 call save_paranoid
22186 TRACE_IRQS_OFF
22187+#ifdef CONFIG_PAX_MEMORY_UDEREF
22188+ testb $3, CS(%rsp)
22189+ jnz 1f
22190+ pax_enter_kernel
22191+ jmp 2f
22192+1: pax_enter_kernel_user
22193+2:
22194+#else
22195+ pax_enter_kernel
22196+#endif
22197 movq %rsp,%rdi /* pt_regs pointer */
22198 xorl %esi,%esi /* no error code */
22199 call \do_sym
22200 jmp paranoid_exit /* %ebx: no swapgs flag */
22201 CFI_ENDPROC
22202-END(\sym)
22203+ENDPROC(\sym)
22204 .endm
22205
22206-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
22207+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
22208 .macro paranoidzeroentry_ist sym do_sym ist
22209 ENTRY(\sym)
22210 INTR_FRAME
22211@@ -1267,14 +1759,30 @@ ENTRY(\sym)
22212 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
22213 call save_paranoid
22214 TRACE_IRQS_OFF_DEBUG
22215+#ifdef CONFIG_PAX_MEMORY_UDEREF
22216+ testb $3, CS(%rsp)
22217+ jnz 1f
22218+ pax_enter_kernel
22219+ jmp 2f
22220+1: pax_enter_kernel_user
22221+2:
22222+#else
22223+ pax_enter_kernel
22224+#endif
22225 movq %rsp,%rdi /* pt_regs pointer */
22226 xorl %esi,%esi /* no error code */
22227+#ifdef CONFIG_SMP
22228+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
22229+ lea init_tss(%r12), %r12
22230+#else
22231+ lea init_tss(%rip), %r12
22232+#endif
22233 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
22234 call \do_sym
22235 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
22236 jmp paranoid_exit /* %ebx: no swapgs flag */
22237 CFI_ENDPROC
22238-END(\sym)
22239+ENDPROC(\sym)
22240 .endm
22241
22242 .macro errorentry sym do_sym
22243@@ -1286,13 +1794,23 @@ ENTRY(\sym)
22244 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
22245 call error_entry
22246 DEFAULT_FRAME 0
22247+#ifdef CONFIG_PAX_MEMORY_UDEREF
22248+ testb $3, CS(%rsp)
22249+ jnz 1f
22250+ pax_enter_kernel
22251+ jmp 2f
22252+1: pax_enter_kernel_user
22253+2:
22254+#else
22255+ pax_enter_kernel
22256+#endif
22257 movq %rsp,%rdi /* pt_regs pointer */
22258 movq ORIG_RAX(%rsp),%rsi /* get error code */
22259 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
22260 call \do_sym
22261 jmp error_exit /* %ebx: no swapgs flag */
22262 CFI_ENDPROC
22263-END(\sym)
22264+ENDPROC(\sym)
22265 .endm
22266
22267 /* error code is on the stack already */
22268@@ -1306,13 +1824,23 @@ ENTRY(\sym)
22269 call save_paranoid
22270 DEFAULT_FRAME 0
22271 TRACE_IRQS_OFF
22272+#ifdef CONFIG_PAX_MEMORY_UDEREF
22273+ testb $3, CS(%rsp)
22274+ jnz 1f
22275+ pax_enter_kernel
22276+ jmp 2f
22277+1: pax_enter_kernel_user
22278+2:
22279+#else
22280+ pax_enter_kernel
22281+#endif
22282 movq %rsp,%rdi /* pt_regs pointer */
22283 movq ORIG_RAX(%rsp),%rsi /* get error code */
22284 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
22285 call \do_sym
22286 jmp paranoid_exit /* %ebx: no swapgs flag */
22287 CFI_ENDPROC
22288-END(\sym)
22289+ENDPROC(\sym)
22290 .endm
22291
22292 zeroentry divide_error do_divide_error
22293@@ -1342,9 +1870,10 @@ gs_change:
22294 2: mfence /* workaround */
22295 SWAPGS
22296 popfq_cfi
22297+ pax_force_retaddr
22298 ret
22299 CFI_ENDPROC
22300-END(native_load_gs_index)
22301+ENDPROC(native_load_gs_index)
22302
22303 _ASM_EXTABLE(gs_change,bad_gs)
22304 .section .fixup,"ax"
22305@@ -1372,9 +1901,10 @@ ENTRY(call_softirq)
22306 CFI_DEF_CFA_REGISTER rsp
22307 CFI_ADJUST_CFA_OFFSET -8
22308 decl PER_CPU_VAR(irq_count)
22309+ pax_force_retaddr
22310 ret
22311 CFI_ENDPROC
22312-END(call_softirq)
22313+ENDPROC(call_softirq)
22314
22315 #ifdef CONFIG_XEN
22316 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
22317@@ -1412,7 +1942,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
22318 decl PER_CPU_VAR(irq_count)
22319 jmp error_exit
22320 CFI_ENDPROC
22321-END(xen_do_hypervisor_callback)
22322+ENDPROC(xen_do_hypervisor_callback)
22323
22324 /*
22325 * Hypervisor uses this for application faults while it executes.
22326@@ -1471,7 +2001,7 @@ ENTRY(xen_failsafe_callback)
22327 SAVE_ALL
22328 jmp error_exit
22329 CFI_ENDPROC
22330-END(xen_failsafe_callback)
22331+ENDPROC(xen_failsafe_callback)
22332
22333 apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
22334 xen_hvm_callback_vector xen_evtchn_do_upcall
22335@@ -1523,18 +2053,33 @@ ENTRY(paranoid_exit)
22336 DEFAULT_FRAME
22337 DISABLE_INTERRUPTS(CLBR_NONE)
22338 TRACE_IRQS_OFF_DEBUG
22339- testl %ebx,%ebx /* swapgs needed? */
22340+ testl $1,%ebx /* swapgs needed? */
22341 jnz paranoid_restore
22342- testl $3,CS(%rsp)
22343+ testb $3,CS(%rsp)
22344 jnz paranoid_userspace
22345+#ifdef CONFIG_PAX_MEMORY_UDEREF
22346+ pax_exit_kernel
22347+ TRACE_IRQS_IRETQ 0
22348+ SWAPGS_UNSAFE_STACK
22349+ RESTORE_ALL 8
22350+ pax_force_retaddr_bts
22351+ jmp irq_return
22352+#endif
22353 paranoid_swapgs:
22354+#ifdef CONFIG_PAX_MEMORY_UDEREF
22355+ pax_exit_kernel_user
22356+#else
22357+ pax_exit_kernel
22358+#endif
22359 TRACE_IRQS_IRETQ 0
22360 SWAPGS_UNSAFE_STACK
22361 RESTORE_ALL 8
22362 jmp irq_return
22363 paranoid_restore:
22364+ pax_exit_kernel
22365 TRACE_IRQS_IRETQ_DEBUG 0
22366 RESTORE_ALL 8
22367+ pax_force_retaddr_bts
22368 jmp irq_return
22369 paranoid_userspace:
22370 GET_THREAD_INFO(%rcx)
22371@@ -1563,7 +2108,7 @@ paranoid_schedule:
22372 TRACE_IRQS_OFF
22373 jmp paranoid_userspace
22374 CFI_ENDPROC
22375-END(paranoid_exit)
22376+ENDPROC(paranoid_exit)
22377
22378 /*
22379 * Exception entry point. This expects an error code/orig_rax on the stack.
22380@@ -1590,12 +2135,13 @@ ENTRY(error_entry)
22381 movq_cfi r14, R14+8
22382 movq_cfi r15, R15+8
22383 xorl %ebx,%ebx
22384- testl $3,CS+8(%rsp)
22385+ testb $3,CS+8(%rsp)
22386 je error_kernelspace
22387 error_swapgs:
22388 SWAPGS
22389 error_sti:
22390 TRACE_IRQS_OFF
22391+ pax_force_retaddr_bts
22392 ret
22393
22394 /*
22395@@ -1622,7 +2168,7 @@ bstep_iret:
22396 movq %rcx,RIP+8(%rsp)
22397 jmp error_swapgs
22398 CFI_ENDPROC
22399-END(error_entry)
22400+ENDPROC(error_entry)
22401
22402
22403 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
22404@@ -1633,7 +2179,7 @@ ENTRY(error_exit)
22405 DISABLE_INTERRUPTS(CLBR_NONE)
22406 TRACE_IRQS_OFF
22407 GET_THREAD_INFO(%rcx)
22408- testl %eax,%eax
22409+ testl $1,%eax
22410 jne retint_kernel
22411 LOCKDEP_SYS_EXIT_IRQ
22412 movl TI_flags(%rcx),%edx
22413@@ -1642,7 +2188,7 @@ ENTRY(error_exit)
22414 jnz retint_careful
22415 jmp retint_swapgs
22416 CFI_ENDPROC
22417-END(error_exit)
22418+ENDPROC(error_exit)
22419
22420 /*
22421 * Test if a given stack is an NMI stack or not.
22422@@ -1700,9 +2246,11 @@ ENTRY(nmi)
22423 * If %cs was not the kernel segment, then the NMI triggered in user
22424 * space, which means it is definitely not nested.
22425 */
22426+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
22427+ je 1f
22428 cmpl $__KERNEL_CS, 16(%rsp)
22429 jne first_nmi
22430-
22431+1:
22432 /*
22433 * Check the special variable on the stack to see if NMIs are
22434 * executing.
22435@@ -1736,8 +2284,7 @@ nested_nmi:
22436
22437 1:
22438 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
22439- leaq -1*8(%rsp), %rdx
22440- movq %rdx, %rsp
22441+ subq $8, %rsp
22442 CFI_ADJUST_CFA_OFFSET 1*8
22443 leaq -10*8(%rsp), %rdx
22444 pushq_cfi $__KERNEL_DS
22445@@ -1755,6 +2302,7 @@ nested_nmi_out:
22446 CFI_RESTORE rdx
22447
22448 /* No need to check faults here */
22449+# pax_force_retaddr_bts
22450 INTERRUPT_RETURN
22451
22452 CFI_RESTORE_STATE
22453@@ -1871,6 +2419,8 @@ end_repeat_nmi:
22454 */
22455 movq %cr2, %r12
22456
22457+ pax_enter_kernel_nmi
22458+
22459 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
22460 movq %rsp,%rdi
22461 movq $-1,%rsi
22462@@ -1883,26 +2433,31 @@ end_repeat_nmi:
22463 movq %r12, %cr2
22464 1:
22465
22466- testl %ebx,%ebx /* swapgs needed? */
22467+ testl $1,%ebx /* swapgs needed? */
22468 jnz nmi_restore
22469 nmi_swapgs:
22470 SWAPGS_UNSAFE_STACK
22471 nmi_restore:
22472+ pax_exit_kernel_nmi
22473 /* Pop the extra iret frame at once */
22474 RESTORE_ALL 6*8
22475+ testb $3, 8(%rsp)
22476+ jnz 1f
22477+ pax_force_retaddr_bts
22478+1:
22479
22480 /* Clear the NMI executing stack variable */
22481 movq $0, 5*8(%rsp)
22482 jmp irq_return
22483 CFI_ENDPROC
22484-END(nmi)
22485+ENDPROC(nmi)
22486
22487 ENTRY(ignore_sysret)
22488 CFI_STARTPROC
22489 mov $-ENOSYS,%eax
22490 sysret
22491 CFI_ENDPROC
22492-END(ignore_sysret)
22493+ENDPROC(ignore_sysret)
22494
22495 /*
22496 * End of kprobes section
22497diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
22498index 42a392a..fbbd930 100644
22499--- a/arch/x86/kernel/ftrace.c
22500+++ b/arch/x86/kernel/ftrace.c
22501@@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
22502 {
22503 unsigned char replaced[MCOUNT_INSN_SIZE];
22504
22505+ ip = ktla_ktva(ip);
22506+
22507 /*
22508 * Note: Due to modules and __init, code can
22509 * disappear and change, we need to protect against faulting
22510@@ -227,7 +229,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
22511 unsigned char old[MCOUNT_INSN_SIZE], *new;
22512 int ret;
22513
22514- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
22515+ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
22516 new = ftrace_call_replace(ip, (unsigned long)func);
22517
22518 /* See comment above by declaration of modifying_ftrace_code */
22519@@ -238,7 +240,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
22520 /* Also update the regs callback function */
22521 if (!ret) {
22522 ip = (unsigned long)(&ftrace_regs_call);
22523- memcpy(old, &ftrace_regs_call, MCOUNT_INSN_SIZE);
22524+ memcpy(old, ktla_ktva((void *)&ftrace_regs_call), MCOUNT_INSN_SIZE);
22525 new = ftrace_call_replace(ip, (unsigned long)func);
22526 ret = ftrace_modify_code(ip, old, new);
22527 }
22528@@ -279,7 +281,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
22529 * kernel identity mapping to modify code.
22530 */
22531 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
22532- ip = (unsigned long)__va(__pa_symbol(ip));
22533+ ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
22534
22535 return probe_kernel_write((void *)ip, val, size);
22536 }
22537@@ -289,7 +291,7 @@ static int add_break(unsigned long ip, const char *old)
22538 unsigned char replaced[MCOUNT_INSN_SIZE];
22539 unsigned char brk = BREAKPOINT_INSTRUCTION;
22540
22541- if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
22542+ if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
22543 return -EFAULT;
22544
22545 /* Make sure it is what we expect it to be */
22546@@ -637,7 +639,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
22547 return ret;
22548
22549 fail_update:
22550- probe_kernel_write((void *)ip, &old_code[0], 1);
22551+ probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
22552 goto out;
22553 }
22554
22555@@ -670,6 +672,8 @@ static int ftrace_mod_jmp(unsigned long ip,
22556 {
22557 unsigned char code[MCOUNT_INSN_SIZE];
22558
22559+ ip = ktla_ktva(ip);
22560+
22561 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
22562 return -EFAULT;
22563
22564diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
22565index 55b6761..a6456fc 100644
22566--- a/arch/x86/kernel/head64.c
22567+++ b/arch/x86/kernel/head64.c
22568@@ -67,12 +67,12 @@ again:
22569 pgd = *pgd_p;
22570
22571 /*
22572- * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
22573- * critical -- __PAGE_OFFSET would point us back into the dynamic
22574+ * The use of __early_va rather than __va here is critical:
22575+ * __va would point us back into the dynamic
22576 * range and we might end up looping forever...
22577 */
22578 if (pgd)
22579- pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
22580+ pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
22581 else {
22582 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
22583 reset_early_page_tables();
22584@@ -82,13 +82,13 @@ again:
22585 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
22586 for (i = 0; i < PTRS_PER_PUD; i++)
22587 pud_p[i] = 0;
22588- *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
22589+ *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
22590 }
22591 pud_p += pud_index(address);
22592 pud = *pud_p;
22593
22594 if (pud)
22595- pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
22596+ pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
22597 else {
22598 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
22599 reset_early_page_tables();
22600@@ -98,7 +98,7 @@ again:
22601 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
22602 for (i = 0; i < PTRS_PER_PMD; i++)
22603 pmd_p[i] = 0;
22604- *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
22605+ *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
22606 }
22607 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
22608 pmd_p[pmd_index(address)] = pmd;
22609@@ -175,7 +175,6 @@ void __init x86_64_start_kernel(char * real_mode_data)
22610 if (console_loglevel == 10)
22611 early_printk("Kernel alive\n");
22612
22613- clear_page(init_level4_pgt);
22614 /* set init_level4_pgt kernel high mapping*/
22615 init_level4_pgt[511] = early_level4_pgt[511];
22616
22617diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
22618index 5dd87a8..d68b3f4 100644
22619--- a/arch/x86/kernel/head_32.S
22620+++ b/arch/x86/kernel/head_32.S
22621@@ -26,6 +26,12 @@
22622 /* Physical address */
22623 #define pa(X) ((X) - __PAGE_OFFSET)
22624
22625+#ifdef CONFIG_PAX_KERNEXEC
22626+#define ta(X) (X)
22627+#else
22628+#define ta(X) ((X) - __PAGE_OFFSET)
22629+#endif
22630+
22631 /*
22632 * References to members of the new_cpu_data structure.
22633 */
22634@@ -55,11 +61,7 @@
22635 * and small than max_low_pfn, otherwise will waste some page table entries
22636 */
22637
22638-#if PTRS_PER_PMD > 1
22639-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
22640-#else
22641-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
22642-#endif
22643+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
22644
22645 /* Number of possible pages in the lowmem region */
22646 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
22647@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
22648 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
22649
22650 /*
22651+ * Real beginning of normal "text" segment
22652+ */
22653+ENTRY(stext)
22654+ENTRY(_stext)
22655+
22656+/*
22657 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
22658 * %esi points to the real-mode code as a 32-bit pointer.
22659 * CS and DS must be 4 GB flat segments, but we don't depend on
22660@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
22661 * can.
22662 */
22663 __HEAD
22664+
22665+#ifdef CONFIG_PAX_KERNEXEC
22666+ jmp startup_32
22667+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
22668+.fill PAGE_SIZE-5,1,0xcc
22669+#endif
22670+
22671 ENTRY(startup_32)
22672 movl pa(stack_start),%ecx
22673
22674@@ -106,6 +121,59 @@ ENTRY(startup_32)
22675 2:
22676 leal -__PAGE_OFFSET(%ecx),%esp
22677
22678+#ifdef CONFIG_SMP
22679+ movl $pa(cpu_gdt_table),%edi
22680+ movl $__per_cpu_load,%eax
22681+ movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
22682+ rorl $16,%eax
22683+ movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
22684+ movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
22685+ movl $__per_cpu_end - 1,%eax
22686+ subl $__per_cpu_start,%eax
22687+ movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
22688+#endif
22689+
22690+#ifdef CONFIG_PAX_MEMORY_UDEREF
22691+ movl $NR_CPUS,%ecx
22692+ movl $pa(cpu_gdt_table),%edi
22693+1:
22694+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
22695+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
22696+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
22697+ addl $PAGE_SIZE_asm,%edi
22698+ loop 1b
22699+#endif
22700+
22701+#ifdef CONFIG_PAX_KERNEXEC
22702+ movl $pa(boot_gdt),%edi
22703+ movl $__LOAD_PHYSICAL_ADDR,%eax
22704+ movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
22705+ rorl $16,%eax
22706+ movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
22707+ movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
22708+ rorl $16,%eax
22709+
22710+ ljmp $(__BOOT_CS),$1f
22711+1:
22712+
22713+ movl $NR_CPUS,%ecx
22714+ movl $pa(cpu_gdt_table),%edi
22715+ addl $__PAGE_OFFSET,%eax
22716+1:
22717+ movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
22718+ movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
22719+ movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
22720+ movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
22721+ rorl $16,%eax
22722+ movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
22723+ movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
22724+ movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
22725+ movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
22726+ rorl $16,%eax
22727+ addl $PAGE_SIZE_asm,%edi
22728+ loop 1b
22729+#endif
22730+
22731 /*
22732 * Clear BSS first so that there are no surprises...
22733 */
22734@@ -201,8 +269,11 @@ ENTRY(startup_32)
22735 movl %eax, pa(max_pfn_mapped)
22736
22737 /* Do early initialization of the fixmap area */
22738- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
22739- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
22740+#ifdef CONFIG_COMPAT_VDSO
22741+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
22742+#else
22743+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
22744+#endif
22745 #else /* Not PAE */
22746
22747 page_pde_offset = (__PAGE_OFFSET >> 20);
22748@@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
22749 movl %eax, pa(max_pfn_mapped)
22750
22751 /* Do early initialization of the fixmap area */
22752- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
22753- movl %eax,pa(initial_page_table+0xffc)
22754+#ifdef CONFIG_COMPAT_VDSO
22755+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
22756+#else
22757+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
22758+#endif
22759 #endif
22760
22761 #ifdef CONFIG_PARAVIRT
22762@@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
22763 cmpl $num_subarch_entries, %eax
22764 jae bad_subarch
22765
22766- movl pa(subarch_entries)(,%eax,4), %eax
22767- subl $__PAGE_OFFSET, %eax
22768- jmp *%eax
22769+ jmp *pa(subarch_entries)(,%eax,4)
22770
22771 bad_subarch:
22772 WEAK(lguest_entry)
22773@@ -261,10 +333,10 @@ WEAK(xen_entry)
22774 __INITDATA
22775
22776 subarch_entries:
22777- .long default_entry /* normal x86/PC */
22778- .long lguest_entry /* lguest hypervisor */
22779- .long xen_entry /* Xen hypervisor */
22780- .long default_entry /* Moorestown MID */
22781+ .long ta(default_entry) /* normal x86/PC */
22782+ .long ta(lguest_entry) /* lguest hypervisor */
22783+ .long ta(xen_entry) /* Xen hypervisor */
22784+ .long ta(default_entry) /* Moorestown MID */
22785 num_subarch_entries = (. - subarch_entries) / 4
22786 .previous
22787 #else
22788@@ -354,6 +426,7 @@ default_entry:
22789 movl pa(mmu_cr4_features),%eax
22790 movl %eax,%cr4
22791
22792+#ifdef CONFIG_X86_PAE
22793 testb $X86_CR4_PAE, %al # check if PAE is enabled
22794 jz enable_paging
22795
22796@@ -382,6 +455,9 @@ default_entry:
22797 /* Make changes effective */
22798 wrmsr
22799
22800+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
22801+#endif
22802+
22803 enable_paging:
22804
22805 /*
22806@@ -449,14 +525,20 @@ is486:
22807 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
22808 movl %eax,%ss # after changing gdt.
22809
22810- movl $(__USER_DS),%eax # DS/ES contains default USER segment
22811+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
22812 movl %eax,%ds
22813 movl %eax,%es
22814
22815 movl $(__KERNEL_PERCPU), %eax
22816 movl %eax,%fs # set this cpu's percpu
22817
22818+#ifdef CONFIG_CC_STACKPROTECTOR
22819 movl $(__KERNEL_STACK_CANARY),%eax
22820+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
22821+ movl $(__USER_DS),%eax
22822+#else
22823+ xorl %eax,%eax
22824+#endif
22825 movl %eax,%gs
22826
22827 xorl %eax,%eax # Clear LDT
22828@@ -512,8 +594,11 @@ setup_once:
22829 * relocation. Manually set base address in stack canary
22830 * segment descriptor.
22831 */
22832- movl $gdt_page,%eax
22833+ movl $cpu_gdt_table,%eax
22834 movl $stack_canary,%ecx
22835+#ifdef CONFIG_SMP
22836+ addl $__per_cpu_load,%ecx
22837+#endif
22838 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
22839 shrl $16, %ecx
22840 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
22841@@ -544,7 +629,7 @@ ENDPROC(early_idt_handlers)
22842 /* This is global to keep gas from relaxing the jumps */
22843 ENTRY(early_idt_handler)
22844 cld
22845- cmpl $2,%ss:early_recursion_flag
22846+ cmpl $1,%ss:early_recursion_flag
22847 je hlt_loop
22848 incl %ss:early_recursion_flag
22849
22850@@ -582,8 +667,8 @@ ENTRY(early_idt_handler)
22851 pushl (20+6*4)(%esp) /* trapno */
22852 pushl $fault_msg
22853 call printk
22854-#endif
22855 call dump_stack
22856+#endif
22857 hlt_loop:
22858 hlt
22859 jmp hlt_loop
22860@@ -602,8 +687,11 @@ ENDPROC(early_idt_handler)
22861 /* This is the default interrupt "handler" :-) */
22862 ALIGN
22863 ignore_int:
22864- cld
22865 #ifdef CONFIG_PRINTK
22866+ cmpl $2,%ss:early_recursion_flag
22867+ je hlt_loop
22868+ incl %ss:early_recursion_flag
22869+ cld
22870 pushl %eax
22871 pushl %ecx
22872 pushl %edx
22873@@ -612,9 +700,6 @@ ignore_int:
22874 movl $(__KERNEL_DS),%eax
22875 movl %eax,%ds
22876 movl %eax,%es
22877- cmpl $2,early_recursion_flag
22878- je hlt_loop
22879- incl early_recursion_flag
22880 pushl 16(%esp)
22881 pushl 24(%esp)
22882 pushl 32(%esp)
22883@@ -648,29 +733,34 @@ ENTRY(setup_once_ref)
22884 /*
22885 * BSS section
22886 */
22887-__PAGE_ALIGNED_BSS
22888- .align PAGE_SIZE
22889 #ifdef CONFIG_X86_PAE
22890+.section .initial_pg_pmd,"a",@progbits
22891 initial_pg_pmd:
22892 .fill 1024*KPMDS,4,0
22893 #else
22894+.section .initial_page_table,"a",@progbits
22895 ENTRY(initial_page_table)
22896 .fill 1024,4,0
22897 #endif
22898+.section .initial_pg_fixmap,"a",@progbits
22899 initial_pg_fixmap:
22900 .fill 1024,4,0
22901+.section .empty_zero_page,"a",@progbits
22902 ENTRY(empty_zero_page)
22903 .fill 4096,1,0
22904+.section .swapper_pg_dir,"a",@progbits
22905 ENTRY(swapper_pg_dir)
22906+#ifdef CONFIG_X86_PAE
22907+ .fill 4,8,0
22908+#else
22909 .fill 1024,4,0
22910+#endif
22911
22912 /*
22913 * This starts the data section.
22914 */
22915 #ifdef CONFIG_X86_PAE
22916-__PAGE_ALIGNED_DATA
22917- /* Page-aligned for the benefit of paravirt? */
22918- .align PAGE_SIZE
22919+.section .initial_page_table,"a",@progbits
22920 ENTRY(initial_page_table)
22921 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
22922 # if KPMDS == 3
22923@@ -689,12 +779,20 @@ ENTRY(initial_page_table)
22924 # error "Kernel PMDs should be 1, 2 or 3"
22925 # endif
22926 .align PAGE_SIZE /* needs to be page-sized too */
22927+
22928+#ifdef CONFIG_PAX_PER_CPU_PGD
22929+ENTRY(cpu_pgd)
22930+ .rept 2*NR_CPUS
22931+ .fill 4,8,0
22932+ .endr
22933+#endif
22934+
22935 #endif
22936
22937 .data
22938 .balign 4
22939 ENTRY(stack_start)
22940- .long init_thread_union+THREAD_SIZE
22941+ .long init_thread_union+THREAD_SIZE-8
22942
22943 __INITRODATA
22944 int_msg:
22945@@ -722,7 +820,7 @@ fault_msg:
22946 * segment size, and 32-bit linear address value:
22947 */
22948
22949- .data
22950+.section .rodata,"a",@progbits
22951 .globl boot_gdt_descr
22952 .globl idt_descr
22953
22954@@ -731,7 +829,7 @@ fault_msg:
22955 .word 0 # 32 bit align gdt_desc.address
22956 boot_gdt_descr:
22957 .word __BOOT_DS+7
22958- .long boot_gdt - __PAGE_OFFSET
22959+ .long pa(boot_gdt)
22960
22961 .word 0 # 32-bit align idt_desc.address
22962 idt_descr:
22963@@ -742,7 +840,7 @@ idt_descr:
22964 .word 0 # 32 bit align gdt_desc.address
22965 ENTRY(early_gdt_descr)
22966 .word GDT_ENTRIES*8-1
22967- .long gdt_page /* Overwritten for secondary CPUs */
22968+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
22969
22970 /*
22971 * The boot_gdt must mirror the equivalent in setup.S and is
22972@@ -751,5 +849,65 @@ ENTRY(early_gdt_descr)
22973 .align L1_CACHE_BYTES
22974 ENTRY(boot_gdt)
22975 .fill GDT_ENTRY_BOOT_CS,8,0
22976- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
22977- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
22978+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
22979+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
22980+
22981+ .align PAGE_SIZE_asm
22982+ENTRY(cpu_gdt_table)
22983+ .rept NR_CPUS
22984+ .quad 0x0000000000000000 /* NULL descriptor */
22985+ .quad 0x0000000000000000 /* 0x0b reserved */
22986+ .quad 0x0000000000000000 /* 0x13 reserved */
22987+ .quad 0x0000000000000000 /* 0x1b reserved */
22988+
22989+#ifdef CONFIG_PAX_KERNEXEC
22990+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
22991+#else
22992+ .quad 0x0000000000000000 /* 0x20 unused */
22993+#endif
22994+
22995+ .quad 0x0000000000000000 /* 0x28 unused */
22996+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
22997+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
22998+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
22999+ .quad 0x0000000000000000 /* 0x4b reserved */
23000+ .quad 0x0000000000000000 /* 0x53 reserved */
23001+ .quad 0x0000000000000000 /* 0x5b reserved */
23002+
23003+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
23004+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
23005+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
23006+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
23007+
23008+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
23009+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
23010+
23011+ /*
23012+ * Segments used for calling PnP BIOS have byte granularity.
23013+ * The code segments and data segments have fixed 64k limits,
23014+ * the transfer segment sizes are set at run time.
23015+ */
23016+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
23017+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
23018+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
23019+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
23020+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
23021+
23022+ /*
23023+ * The APM segments have byte granularity and their bases
23024+ * are set at run time. All have 64k limits.
23025+ */
23026+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
23027+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
23028+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
23029+
23030+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
23031+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
23032+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
23033+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
23034+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
23035+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
23036+
23037+ /* Be sure this is zeroed to avoid false validations in Xen */
23038+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
23039+ .endr
23040diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
23041index e1aabdb..73dcad8 100644
23042--- a/arch/x86/kernel/head_64.S
23043+++ b/arch/x86/kernel/head_64.S
23044@@ -20,6 +20,8 @@
23045 #include <asm/processor-flags.h>
23046 #include <asm/percpu.h>
23047 #include <asm/nops.h>
23048+#include <asm/cpufeature.h>
23049+#include <asm/alternative-asm.h>
23050
23051 #ifdef CONFIG_PARAVIRT
23052 #include <asm/asm-offsets.h>
23053@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
23054 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
23055 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
23056 L3_START_KERNEL = pud_index(__START_KERNEL_map)
23057+L4_VMALLOC_START = pgd_index(VMALLOC_START)
23058+L3_VMALLOC_START = pud_index(VMALLOC_START)
23059+L4_VMALLOC_END = pgd_index(VMALLOC_END)
23060+L3_VMALLOC_END = pud_index(VMALLOC_END)
23061+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
23062+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
23063
23064 .text
23065 __HEAD
23066@@ -89,11 +97,23 @@ startup_64:
23067 * Fixup the physical addresses in the page table
23068 */
23069 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
23070+ addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
23071+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
23072+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
23073+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
23074+ addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
23075
23076- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
23077- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
23078+ addq %rbp, level3_ident_pgt + (0*8)(%rip)
23079+#ifndef CONFIG_XEN
23080+ addq %rbp, level3_ident_pgt + (1*8)(%rip)
23081+#endif
23082
23083- addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
23084+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
23085+
23086+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
23087+ addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
23088+
23089+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
23090
23091 /*
23092 * Set up the identity mapping for the switchover. These
23093@@ -177,8 +197,8 @@ ENTRY(secondary_startup_64)
23094 movq $(init_level4_pgt - __START_KERNEL_map), %rax
23095 1:
23096
23097- /* Enable PAE mode and PGE */
23098- movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
23099+ /* Enable PAE mode and PSE/PGE */
23100+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
23101 movq %rcx, %cr4
23102
23103 /* Setup early boot stage 4 level pagetables. */
23104@@ -199,10 +219,18 @@ ENTRY(secondary_startup_64)
23105 movl $MSR_EFER, %ecx
23106 rdmsr
23107 btsl $_EFER_SCE, %eax /* Enable System Call */
23108- btl $20,%edi /* No Execute supported? */
23109+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
23110 jnc 1f
23111 btsl $_EFER_NX, %eax
23112 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
23113+ leaq init_level4_pgt(%rip), %rdi
23114+#ifndef CONFIG_EFI
23115+ btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
23116+#endif
23117+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
23118+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
23119+ btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
23120+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
23121 1: wrmsr /* Make changes effective */
23122
23123 /* Setup cr0 */
23124@@ -282,6 +310,7 @@ ENTRY(secondary_startup_64)
23125 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
23126 * address given in m16:64.
23127 */
23128+ pax_set_fptr_mask
23129 movq initial_code(%rip),%rax
23130 pushq $0 # fake return address to stop unwinder
23131 pushq $__KERNEL_CS # set correct cs
23132@@ -388,7 +417,7 @@ ENTRY(early_idt_handler)
23133 call dump_stack
23134 #ifdef CONFIG_KALLSYMS
23135 leaq early_idt_ripmsg(%rip),%rdi
23136- movq 40(%rsp),%rsi # %rip again
23137+ movq 88(%rsp),%rsi # %rip again
23138 call __print_symbol
23139 #endif
23140 #endif /* EARLY_PRINTK */
23141@@ -416,6 +445,7 @@ ENDPROC(early_idt_handler)
23142 early_recursion_flag:
23143 .long 0
23144
23145+ .section .rodata,"a",@progbits
23146 #ifdef CONFIG_EARLY_PRINTK
23147 early_idt_msg:
23148 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
23149@@ -443,29 +473,52 @@ NEXT_PAGE(early_level4_pgt)
23150 NEXT_PAGE(early_dynamic_pgts)
23151 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
23152
23153- .data
23154+ .section .rodata,"a",@progbits
23155
23156-#ifndef CONFIG_XEN
23157 NEXT_PAGE(init_level4_pgt)
23158- .fill 512,8,0
23159-#else
23160-NEXT_PAGE(init_level4_pgt)
23161- .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
23162 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
23163 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
23164+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
23165+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
23166+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
23167+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
23168+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
23169+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
23170 .org init_level4_pgt + L4_START_KERNEL*8, 0
23171 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
23172 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
23173
23174+#ifdef CONFIG_PAX_PER_CPU_PGD
23175+NEXT_PAGE(cpu_pgd)
23176+ .rept 2*NR_CPUS
23177+ .fill 512,8,0
23178+ .endr
23179+#endif
23180+
23181 NEXT_PAGE(level3_ident_pgt)
23182 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
23183+#ifdef CONFIG_XEN
23184 .fill 511, 8, 0
23185+#else
23186+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
23187+ .fill 510,8,0
23188+#endif
23189+
23190+NEXT_PAGE(level3_vmalloc_start_pgt)
23191+ .fill 512,8,0
23192+
23193+NEXT_PAGE(level3_vmalloc_end_pgt)
23194+ .fill 512,8,0
23195+
23196+NEXT_PAGE(level3_vmemmap_pgt)
23197+ .fill L3_VMEMMAP_START,8,0
23198+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
23199+
23200 NEXT_PAGE(level2_ident_pgt)
23201- /* Since I easily can, map the first 1G.
23202+ /* Since I easily can, map the first 2G.
23203 * Don't set NX because code runs from these pages.
23204 */
23205- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
23206-#endif
23207+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
23208
23209 NEXT_PAGE(level3_kernel_pgt)
23210 .fill L3_START_KERNEL,8,0
23211@@ -473,6 +526,9 @@ NEXT_PAGE(level3_kernel_pgt)
23212 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
23213 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
23214
23215+NEXT_PAGE(level2_vmemmap_pgt)
23216+ .fill 512,8,0
23217+
23218 NEXT_PAGE(level2_kernel_pgt)
23219 /*
23220 * 512 MB kernel mapping. We spend a full page on this pagetable
23221@@ -488,30 +544,62 @@ NEXT_PAGE(level2_kernel_pgt)
23222 KERNEL_IMAGE_SIZE/PMD_SIZE)
23223
23224 NEXT_PAGE(level2_fixmap_pgt)
23225- .fill 506,8,0
23226- .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
23227- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
23228- .fill 5,8,0
23229+ .fill 507,8,0
23230+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
23231+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
23232+ .fill 4,8,0
23233
23234-NEXT_PAGE(level1_fixmap_pgt)
23235+NEXT_PAGE(level1_vsyscall_pgt)
23236 .fill 512,8,0
23237
23238 #undef PMDS
23239
23240- .data
23241+ .align PAGE_SIZE
23242+ENTRY(cpu_gdt_table)
23243+ .rept NR_CPUS
23244+ .quad 0x0000000000000000 /* NULL descriptor */
23245+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
23246+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
23247+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
23248+ .quad 0x00cffb000000ffff /* __USER32_CS */
23249+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
23250+ .quad 0x00affb000000ffff /* __USER_CS */
23251+
23252+#ifdef CONFIG_PAX_KERNEXEC
23253+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
23254+#else
23255+ .quad 0x0 /* unused */
23256+#endif
23257+
23258+ .quad 0,0 /* TSS */
23259+ .quad 0,0 /* LDT */
23260+ .quad 0,0,0 /* three TLS descriptors */
23261+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
23262+ /* asm/segment.h:GDT_ENTRIES must match this */
23263+
23264+#ifdef CONFIG_PAX_MEMORY_UDEREF
23265+ .quad 0x00cf93000000ffff /* __UDEREF_KERNEL_DS */
23266+#else
23267+ .quad 0x0 /* unused */
23268+#endif
23269+
23270+ /* zero the remaining page */
23271+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
23272+ .endr
23273+
23274 .align 16
23275 .globl early_gdt_descr
23276 early_gdt_descr:
23277 .word GDT_ENTRIES*8-1
23278 early_gdt_descr_base:
23279- .quad INIT_PER_CPU_VAR(gdt_page)
23280+ .quad cpu_gdt_table
23281
23282 ENTRY(phys_base)
23283 /* This must match the first entry in level2_kernel_pgt */
23284 .quad 0x0000000000000000
23285
23286 #include "../../x86/xen/xen-head.S"
23287-
23288- __PAGE_ALIGNED_BSS
23289+
23290+ .section .rodata,"a",@progbits
23291 NEXT_PAGE(empty_zero_page)
23292 .skip PAGE_SIZE
23293diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
23294index 0fa6912..b37438b 100644
23295--- a/arch/x86/kernel/i386_ksyms_32.c
23296+++ b/arch/x86/kernel/i386_ksyms_32.c
23297@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
23298 EXPORT_SYMBOL(cmpxchg8b_emu);
23299 #endif
23300
23301+EXPORT_SYMBOL_GPL(cpu_gdt_table);
23302+
23303 /* Networking helper routines. */
23304 EXPORT_SYMBOL(csum_partial_copy_generic);
23305+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
23306+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
23307
23308 EXPORT_SYMBOL(__get_user_1);
23309 EXPORT_SYMBOL(__get_user_2);
23310@@ -37,3 +41,11 @@ EXPORT_SYMBOL(strstr);
23311
23312 EXPORT_SYMBOL(csum_partial);
23313 EXPORT_SYMBOL(empty_zero_page);
23314+
23315+#ifdef CONFIG_PAX_KERNEXEC
23316+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
23317+#endif
23318+
23319+#ifdef CONFIG_PAX_PER_CPU_PGD
23320+EXPORT_SYMBOL(cpu_pgd);
23321+#endif
23322diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
23323index 5d576ab..1403a03 100644
23324--- a/arch/x86/kernel/i387.c
23325+++ b/arch/x86/kernel/i387.c
23326@@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
23327 static inline bool interrupted_user_mode(void)
23328 {
23329 struct pt_regs *regs = get_irq_regs();
23330- return regs && user_mode_vm(regs);
23331+ return regs && user_mode(regs);
23332 }
23333
23334 /*
23335diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
23336index 9a5c460..84868423 100644
23337--- a/arch/x86/kernel/i8259.c
23338+++ b/arch/x86/kernel/i8259.c
23339@@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
23340 static void make_8259A_irq(unsigned int irq)
23341 {
23342 disable_irq_nosync(irq);
23343- io_apic_irqs &= ~(1<<irq);
23344+ io_apic_irqs &= ~(1UL<<irq);
23345 irq_set_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
23346 i8259A_chip.name);
23347 enable_irq(irq);
23348@@ -209,7 +209,7 @@ spurious_8259A_irq:
23349 "spurious 8259A interrupt: IRQ%d.\n", irq);
23350 spurious_irq_mask |= irqmask;
23351 }
23352- atomic_inc(&irq_err_count);
23353+ atomic_inc_unchecked(&irq_err_count);
23354 /*
23355 * Theoretically we do not have to handle this IRQ,
23356 * but in Linux this does not cause problems and is
23357@@ -333,14 +333,16 @@ static void init_8259A(int auto_eoi)
23358 /* (slave's support for AEOI in flat mode is to be investigated) */
23359 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
23360
23361+ pax_open_kernel();
23362 if (auto_eoi)
23363 /*
23364 * In AEOI mode we just have to mask the interrupt
23365 * when acking.
23366 */
23367- i8259A_chip.irq_mask_ack = disable_8259A_irq;
23368+ *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
23369 else
23370- i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
23371+ *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
23372+ pax_close_kernel();
23373
23374 udelay(100); /* wait for 8259A to initialize */
23375
23376diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
23377index a979b5b..1d6db75 100644
23378--- a/arch/x86/kernel/io_delay.c
23379+++ b/arch/x86/kernel/io_delay.c
23380@@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
23381 * Quirk table for systems that misbehave (lock up, etc.) if port
23382 * 0x80 is used:
23383 */
23384-static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
23385+static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
23386 {
23387 .callback = dmi_io_delay_0xed_port,
23388 .ident = "Compaq Presario V6000",
23389diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
23390index 4ddaf66..6292f4e 100644
23391--- a/arch/x86/kernel/ioport.c
23392+++ b/arch/x86/kernel/ioport.c
23393@@ -6,6 +6,7 @@
23394 #include <linux/sched.h>
23395 #include <linux/kernel.h>
23396 #include <linux/capability.h>
23397+#include <linux/security.h>
23398 #include <linux/errno.h>
23399 #include <linux/types.h>
23400 #include <linux/ioport.h>
23401@@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
23402
23403 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
23404 return -EINVAL;
23405+#ifdef CONFIG_GRKERNSEC_IO
23406+ if (turn_on && grsec_disable_privio) {
23407+ gr_handle_ioperm();
23408+ return -EPERM;
23409+ }
23410+#endif
23411 if (turn_on && !capable(CAP_SYS_RAWIO))
23412 return -EPERM;
23413
23414@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
23415 * because the ->io_bitmap_max value must match the bitmap
23416 * contents:
23417 */
23418- tss = &per_cpu(init_tss, get_cpu());
23419+ tss = init_tss + get_cpu();
23420
23421 if (turn_on)
23422 bitmap_clear(t->io_bitmap_ptr, from, num);
23423@@ -103,6 +110,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
23424 return -EINVAL;
23425 /* Trying to gain more privileges? */
23426 if (level > old) {
23427+#ifdef CONFIG_GRKERNSEC_IO
23428+ if (grsec_disable_privio) {
23429+ gr_handle_iopl();
23430+ return -EPERM;
23431+ }
23432+#endif
23433 if (!capable(CAP_SYS_RAWIO))
23434 return -EPERM;
23435 }
23436diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
23437index 3a8185c..3c042ee 100644
23438--- a/arch/x86/kernel/irq.c
23439+++ b/arch/x86/kernel/irq.c
23440@@ -21,7 +21,7 @@
23441 #define CREATE_TRACE_POINTS
23442 #include <asm/trace/irq_vectors.h>
23443
23444-atomic_t irq_err_count;
23445+atomic_unchecked_t irq_err_count;
23446
23447 /* Function pointer for generic interrupt vector handling */
23448 void (*x86_platform_ipi_callback)(void) = NULL;
23449@@ -125,9 +125,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
23450 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
23451 seq_printf(p, " Machine check polls\n");
23452 #endif
23453- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
23454+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
23455 #if defined(CONFIG_X86_IO_APIC)
23456- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
23457+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
23458 #endif
23459 return 0;
23460 }
23461@@ -167,7 +167,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
23462
23463 u64 arch_irq_stat(void)
23464 {
23465- u64 sum = atomic_read(&irq_err_count);
23466+ u64 sum = atomic_read_unchecked(&irq_err_count);
23467 return sum;
23468 }
23469
23470diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
23471index 4186755..784efa0 100644
23472--- a/arch/x86/kernel/irq_32.c
23473+++ b/arch/x86/kernel/irq_32.c
23474@@ -39,7 +39,7 @@ static int check_stack_overflow(void)
23475 __asm__ __volatile__("andl %%esp,%0" :
23476 "=r" (sp) : "0" (THREAD_SIZE - 1));
23477
23478- return sp < (sizeof(struct thread_info) + STACK_WARN);
23479+ return sp < STACK_WARN;
23480 }
23481
23482 static void print_stack_overflow(void)
23483@@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
23484 * per-CPU IRQ handling contexts (thread information and stack)
23485 */
23486 union irq_ctx {
23487- struct thread_info tinfo;
23488- u32 stack[THREAD_SIZE/sizeof(u32)];
23489+ unsigned long previous_esp;
23490+ u32 stack[THREAD_SIZE/sizeof(u32)];
23491 } __attribute__((aligned(THREAD_SIZE)));
23492
23493 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
23494@@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
23495 static inline int
23496 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
23497 {
23498- union irq_ctx *curctx, *irqctx;
23499+ union irq_ctx *irqctx;
23500 u32 *isp, arg1, arg2;
23501
23502- curctx = (union irq_ctx *) current_thread_info();
23503 irqctx = __this_cpu_read(hardirq_ctx);
23504
23505 /*
23506@@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
23507 * handler) we can't do that and just have to keep using the
23508 * current stack (which is the irq stack already after all)
23509 */
23510- if (unlikely(curctx == irqctx))
23511+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
23512 return 0;
23513
23514 /* build the stack frame on the IRQ stack */
23515- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
23516- irqctx->tinfo.task = curctx->tinfo.task;
23517- irqctx->tinfo.previous_esp = current_stack_pointer;
23518+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
23519+ irqctx->previous_esp = current_stack_pointer;
23520
23521- /* Copy the preempt_count so that the [soft]irq checks work. */
23522- irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
23523+#ifdef CONFIG_PAX_MEMORY_UDEREF
23524+ __set_fs(MAKE_MM_SEG(0));
23525+#endif
23526
23527 if (unlikely(overflow))
23528 call_on_stack(print_stack_overflow, isp);
23529@@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
23530 : "0" (irq), "1" (desc), "2" (isp),
23531 "D" (desc->handle_irq)
23532 : "memory", "cc", "ecx");
23533+
23534+#ifdef CONFIG_PAX_MEMORY_UDEREF
23535+ __set_fs(current_thread_info()->addr_limit);
23536+#endif
23537+
23538 return 1;
23539 }
23540
23541@@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
23542 */
23543 void irq_ctx_init(int cpu)
23544 {
23545- union irq_ctx *irqctx;
23546-
23547 if (per_cpu(hardirq_ctx, cpu))
23548 return;
23549
23550- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
23551- THREADINFO_GFP,
23552- THREAD_SIZE_ORDER));
23553- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
23554- irqctx->tinfo.cpu = cpu;
23555- irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
23556- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
23557+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
23558+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
23559
23560- per_cpu(hardirq_ctx, cpu) = irqctx;
23561-
23562- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
23563- THREADINFO_GFP,
23564- THREAD_SIZE_ORDER));
23565- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
23566- irqctx->tinfo.cpu = cpu;
23567- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
23568-
23569- per_cpu(softirq_ctx, cpu) = irqctx;
23570+ printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
23571+ cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
23572
23573 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
23574 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
23575@@ -152,7 +141,6 @@ void irq_ctx_init(int cpu)
23576 asmlinkage void do_softirq(void)
23577 {
23578 unsigned long flags;
23579- struct thread_info *curctx;
23580 union irq_ctx *irqctx;
23581 u32 *isp;
23582
23583@@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
23584 local_irq_save(flags);
23585
23586 if (local_softirq_pending()) {
23587- curctx = current_thread_info();
23588 irqctx = __this_cpu_read(softirq_ctx);
23589- irqctx->tinfo.task = curctx->task;
23590- irqctx->tinfo.previous_esp = current_stack_pointer;
23591+ irqctx->previous_esp = current_stack_pointer;
23592
23593 /* build the stack frame on the softirq stack */
23594- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
23595+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
23596+
23597+#ifdef CONFIG_PAX_MEMORY_UDEREF
23598+ __set_fs(MAKE_MM_SEG(0));
23599+#endif
23600
23601 call_on_stack(__do_softirq, isp);
23602+
23603+#ifdef CONFIG_PAX_MEMORY_UDEREF
23604+ __set_fs(current_thread_info()->addr_limit);
23605+#endif
23606+
23607 /*
23608 * Shouldn't happen, we returned above if in_interrupt():
23609 */
23610@@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
23611 if (unlikely(!desc))
23612 return false;
23613
23614- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
23615+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
23616 if (unlikely(overflow))
23617 print_stack_overflow();
23618 desc->handle_irq(irq, desc);
23619diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
23620index d04d3ec..ea4b374 100644
23621--- a/arch/x86/kernel/irq_64.c
23622+++ b/arch/x86/kernel/irq_64.c
23623@@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
23624 u64 estack_top, estack_bottom;
23625 u64 curbase = (u64)task_stack_page(current);
23626
23627- if (user_mode_vm(regs))
23628+ if (user_mode(regs))
23629 return;
23630
23631 if (regs->sp >= curbase + sizeof(struct thread_info) +
23632diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
23633index dc1404b..bbc43e7 100644
23634--- a/arch/x86/kernel/kdebugfs.c
23635+++ b/arch/x86/kernel/kdebugfs.c
23636@@ -27,7 +27,7 @@ struct setup_data_node {
23637 u32 len;
23638 };
23639
23640-static ssize_t setup_data_read(struct file *file, char __user *user_buf,
23641+static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
23642 size_t count, loff_t *ppos)
23643 {
23644 struct setup_data_node *node = file->private_data;
23645diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
23646index 836f832..a8bda67 100644
23647--- a/arch/x86/kernel/kgdb.c
23648+++ b/arch/x86/kernel/kgdb.c
23649@@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
23650 #ifdef CONFIG_X86_32
23651 switch (regno) {
23652 case GDB_SS:
23653- if (!user_mode_vm(regs))
23654+ if (!user_mode(regs))
23655 *(unsigned long *)mem = __KERNEL_DS;
23656 break;
23657 case GDB_SP:
23658- if (!user_mode_vm(regs))
23659+ if (!user_mode(regs))
23660 *(unsigned long *)mem = kernel_stack_pointer(regs);
23661 break;
23662 case GDB_GS:
23663@@ -229,7 +229,10 @@ static void kgdb_correct_hw_break(void)
23664 bp->attr.bp_addr = breakinfo[breakno].addr;
23665 bp->attr.bp_len = breakinfo[breakno].len;
23666 bp->attr.bp_type = breakinfo[breakno].type;
23667- info->address = breakinfo[breakno].addr;
23668+ if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
23669+ info->address = ktla_ktva(breakinfo[breakno].addr);
23670+ else
23671+ info->address = breakinfo[breakno].addr;
23672 info->len = breakinfo[breakno].len;
23673 info->type = breakinfo[breakno].type;
23674 val = arch_install_hw_breakpoint(bp);
23675@@ -476,12 +479,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
23676 case 'k':
23677 /* clear the trace bit */
23678 linux_regs->flags &= ~X86_EFLAGS_TF;
23679- atomic_set(&kgdb_cpu_doing_single_step, -1);
23680+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
23681
23682 /* set the trace bit if we're stepping */
23683 if (remcomInBuffer[0] == 's') {
23684 linux_regs->flags |= X86_EFLAGS_TF;
23685- atomic_set(&kgdb_cpu_doing_single_step,
23686+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
23687 raw_smp_processor_id());
23688 }
23689
23690@@ -546,7 +549,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
23691
23692 switch (cmd) {
23693 case DIE_DEBUG:
23694- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
23695+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
23696 if (user_mode(regs))
23697 return single_step_cont(regs, args);
23698 break;
23699@@ -751,11 +754,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
23700 #endif /* CONFIG_DEBUG_RODATA */
23701
23702 bpt->type = BP_BREAKPOINT;
23703- err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
23704+ err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
23705 BREAK_INSTR_SIZE);
23706 if (err)
23707 return err;
23708- err = probe_kernel_write((char *)bpt->bpt_addr,
23709+ err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
23710 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
23711 #ifdef CONFIG_DEBUG_RODATA
23712 if (!err)
23713@@ -768,7 +771,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
23714 return -EBUSY;
23715 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
23716 BREAK_INSTR_SIZE);
23717- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
23718+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
23719 if (err)
23720 return err;
23721 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
23722@@ -793,13 +796,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
23723 if (mutex_is_locked(&text_mutex))
23724 goto knl_write;
23725 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
23726- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
23727+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
23728 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
23729 goto knl_write;
23730 return err;
23731 knl_write:
23732 #endif /* CONFIG_DEBUG_RODATA */
23733- return probe_kernel_write((char *)bpt->bpt_addr,
23734+ return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
23735 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
23736 }
23737
23738diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
23739index 211bce4..6e2580a 100644
23740--- a/arch/x86/kernel/kprobes/core.c
23741+++ b/arch/x86/kernel/kprobes/core.c
23742@@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
23743 s32 raddr;
23744 } __packed *insn;
23745
23746- insn = (struct __arch_relative_insn *)from;
23747+ insn = (struct __arch_relative_insn *)ktla_ktva(from);
23748+
23749+ pax_open_kernel();
23750 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
23751 insn->op = op;
23752+ pax_close_kernel();
23753 }
23754
23755 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
23756@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
23757 kprobe_opcode_t opcode;
23758 kprobe_opcode_t *orig_opcodes = opcodes;
23759
23760- if (search_exception_tables((unsigned long)opcodes))
23761+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
23762 return 0; /* Page fault may occur on this address. */
23763
23764 retry:
23765@@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
23766 * for the first byte, we can recover the original instruction
23767 * from it and kp->opcode.
23768 */
23769- memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
23770+ memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
23771 buf[0] = kp->opcode;
23772- return (unsigned long)buf;
23773+ return ktva_ktla((unsigned long)buf);
23774 }
23775
23776 /*
23777@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
23778 /* Another subsystem puts a breakpoint, failed to recover */
23779 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
23780 return 0;
23781+ pax_open_kernel();
23782 memcpy(dest, insn.kaddr, insn.length);
23783+ pax_close_kernel();
23784
23785 #ifdef CONFIG_X86_64
23786 if (insn_rip_relative(&insn)) {
23787@@ -359,7 +364,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
23788 return 0;
23789 }
23790 disp = (u8 *) dest + insn_offset_displacement(&insn);
23791+ pax_open_kernel();
23792 *(s32 *) disp = (s32) newdisp;
23793+ pax_close_kernel();
23794 }
23795 #endif
23796 return insn.length;
23797@@ -498,7 +505,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
23798 * nor set current_kprobe, because it doesn't use single
23799 * stepping.
23800 */
23801- regs->ip = (unsigned long)p->ainsn.insn;
23802+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
23803 preempt_enable_no_resched();
23804 return;
23805 }
23806@@ -515,9 +522,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
23807 regs->flags &= ~X86_EFLAGS_IF;
23808 /* single step inline if the instruction is an int3 */
23809 if (p->opcode == BREAKPOINT_INSTRUCTION)
23810- regs->ip = (unsigned long)p->addr;
23811+ regs->ip = ktla_ktva((unsigned long)p->addr);
23812 else
23813- regs->ip = (unsigned long)p->ainsn.insn;
23814+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
23815 }
23816
23817 /*
23818@@ -596,7 +603,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
23819 setup_singlestep(p, regs, kcb, 0);
23820 return 1;
23821 }
23822- } else if (*addr != BREAKPOINT_INSTRUCTION) {
23823+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
23824 /*
23825 * The breakpoint instruction was removed right
23826 * after we hit it. Another cpu has removed
23827@@ -642,6 +649,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
23828 " movq %rax, 152(%rsp)\n"
23829 RESTORE_REGS_STRING
23830 " popfq\n"
23831+#ifdef KERNEXEC_PLUGIN
23832+ " btsq $63,(%rsp)\n"
23833+#endif
23834 #else
23835 " pushf\n"
23836 SAVE_REGS_STRING
23837@@ -779,7 +789,7 @@ static void __kprobes
23838 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
23839 {
23840 unsigned long *tos = stack_addr(regs);
23841- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
23842+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
23843 unsigned long orig_ip = (unsigned long)p->addr;
23844 kprobe_opcode_t *insn = p->ainsn.insn;
23845
23846@@ -961,7 +971,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
23847 struct die_args *args = data;
23848 int ret = NOTIFY_DONE;
23849
23850- if (args->regs && user_mode_vm(args->regs))
23851+ if (args->regs && user_mode(args->regs))
23852 return ret;
23853
23854 switch (val) {
23855diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
23856index 76dc6f0..66bdfc3 100644
23857--- a/arch/x86/kernel/kprobes/opt.c
23858+++ b/arch/x86/kernel/kprobes/opt.c
23859@@ -79,6 +79,7 @@ found:
23860 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
23861 static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
23862 {
23863+ pax_open_kernel();
23864 #ifdef CONFIG_X86_64
23865 *addr++ = 0x48;
23866 *addr++ = 0xbf;
23867@@ -86,6 +87,7 @@ static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long v
23868 *addr++ = 0xb8;
23869 #endif
23870 *(unsigned long *)addr = val;
23871+ pax_close_kernel();
23872 }
23873
23874 static void __used __kprobes kprobes_optinsn_template_holder(void)
23875@@ -338,7 +340,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
23876 * Verify if the address gap is in 2GB range, because this uses
23877 * a relative jump.
23878 */
23879- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
23880+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
23881 if (abs(rel) > 0x7fffffff)
23882 return -ERANGE;
23883
23884@@ -353,16 +355,18 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
23885 op->optinsn.size = ret;
23886
23887 /* Copy arch-dep-instance from template */
23888- memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
23889+ pax_open_kernel();
23890+ memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
23891+ pax_close_kernel();
23892
23893 /* Set probe information */
23894 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
23895
23896 /* Set probe function call */
23897- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
23898+ synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
23899
23900 /* Set returning jmp instruction at the tail of out-of-line buffer */
23901- synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
23902+ synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
23903 (u8 *)op->kp.addr + op->optinsn.size);
23904
23905 flush_icache_range((unsigned long) buf,
23906@@ -385,7 +389,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
23907 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
23908
23909 /* Backup instructions which will be replaced by jump address */
23910- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
23911+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
23912 RELATIVE_ADDR_SIZE);
23913
23914 insn_buf[0] = RELATIVEJUMP_OPCODE;
23915@@ -483,7 +487,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
23916 /* This kprobe is really able to run optimized path. */
23917 op = container_of(p, struct optimized_kprobe, kp);
23918 /* Detour through copied instructions */
23919- regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
23920+ regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
23921 if (!reenter)
23922 reset_current_kprobe();
23923 preempt_enable_no_resched();
23924diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
23925index ebc9873..1b9724b 100644
23926--- a/arch/x86/kernel/ldt.c
23927+++ b/arch/x86/kernel/ldt.c
23928@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
23929 if (reload) {
23930 #ifdef CONFIG_SMP
23931 preempt_disable();
23932- load_LDT(pc);
23933+ load_LDT_nolock(pc);
23934 if (!cpumask_equal(mm_cpumask(current->mm),
23935 cpumask_of(smp_processor_id())))
23936 smp_call_function(flush_ldt, current->mm, 1);
23937 preempt_enable();
23938 #else
23939- load_LDT(pc);
23940+ load_LDT_nolock(pc);
23941 #endif
23942 }
23943 if (oldsize) {
23944@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
23945 return err;
23946
23947 for (i = 0; i < old->size; i++)
23948- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
23949+ write_ldt_entry(new->ldt, i, old->ldt + i);
23950 return 0;
23951 }
23952
23953@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
23954 retval = copy_ldt(&mm->context, &old_mm->context);
23955 mutex_unlock(&old_mm->context.lock);
23956 }
23957+
23958+ if (tsk == current) {
23959+ mm->context.vdso = 0;
23960+
23961+#ifdef CONFIG_X86_32
23962+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23963+ mm->context.user_cs_base = 0UL;
23964+ mm->context.user_cs_limit = ~0UL;
23965+
23966+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
23967+ cpus_clear(mm->context.cpu_user_cs_mask);
23968+#endif
23969+
23970+#endif
23971+#endif
23972+
23973+ }
23974+
23975 return retval;
23976 }
23977
23978@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
23979 }
23980 }
23981
23982+#ifdef CONFIG_PAX_SEGMEXEC
23983+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
23984+ error = -EINVAL;
23985+ goto out_unlock;
23986+ }
23987+#endif
23988+
23989 fill_ldt(&ldt, &ldt_info);
23990 if (oldmode)
23991 ldt.avl = 0;
23992diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
23993index 5b19e4d..6476a76 100644
23994--- a/arch/x86/kernel/machine_kexec_32.c
23995+++ b/arch/x86/kernel/machine_kexec_32.c
23996@@ -26,7 +26,7 @@
23997 #include <asm/cacheflush.h>
23998 #include <asm/debugreg.h>
23999
24000-static void set_idt(void *newidt, __u16 limit)
24001+static void set_idt(struct desc_struct *newidt, __u16 limit)
24002 {
24003 struct desc_ptr curidt;
24004
24005@@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
24006 }
24007
24008
24009-static void set_gdt(void *newgdt, __u16 limit)
24010+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
24011 {
24012 struct desc_ptr curgdt;
24013
24014@@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
24015 }
24016
24017 control_page = page_address(image->control_code_page);
24018- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
24019+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
24020
24021 relocate_kernel_ptr = control_page;
24022 page_list[PA_CONTROL_PAGE] = __pa(control_page);
24023diff --git a/arch/x86/kernel/microcode_core.c b/arch/x86/kernel/microcode_core.c
24024index 15c9876..0a43909 100644
24025--- a/arch/x86/kernel/microcode_core.c
24026+++ b/arch/x86/kernel/microcode_core.c
24027@@ -513,7 +513,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
24028 return NOTIFY_OK;
24029 }
24030
24031-static struct notifier_block __refdata mc_cpu_notifier = {
24032+static struct notifier_block mc_cpu_notifier = {
24033 .notifier_call = mc_cpu_callback,
24034 };
24035
24036diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
24037index 5fb2ceb..3ae90bb 100644
24038--- a/arch/x86/kernel/microcode_intel.c
24039+++ b/arch/x86/kernel/microcode_intel.c
24040@@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
24041
24042 static int get_ucode_user(void *to, const void *from, size_t n)
24043 {
24044- return copy_from_user(to, from, n);
24045+ return copy_from_user(to, (const void __force_user *)from, n);
24046 }
24047
24048 static enum ucode_state
24049 request_microcode_user(int cpu, const void __user *buf, size_t size)
24050 {
24051- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
24052+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
24053 }
24054
24055 static void microcode_fini_cpu(int cpu)
24056diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
24057index 216a4d7..228255a 100644
24058--- a/arch/x86/kernel/module.c
24059+++ b/arch/x86/kernel/module.c
24060@@ -43,15 +43,60 @@ do { \
24061 } while (0)
24062 #endif
24063
24064-void *module_alloc(unsigned long size)
24065+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
24066 {
24067- if (PAGE_ALIGN(size) > MODULES_LEN)
24068+ if (!size || PAGE_ALIGN(size) > MODULES_LEN)
24069 return NULL;
24070 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
24071- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
24072+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
24073 -1, __builtin_return_address(0));
24074 }
24075
24076+void *module_alloc(unsigned long size)
24077+{
24078+
24079+#ifdef CONFIG_PAX_KERNEXEC
24080+ return __module_alloc(size, PAGE_KERNEL);
24081+#else
24082+ return __module_alloc(size, PAGE_KERNEL_EXEC);
24083+#endif
24084+
24085+}
24086+
24087+#ifdef CONFIG_PAX_KERNEXEC
24088+#ifdef CONFIG_X86_32
24089+void *module_alloc_exec(unsigned long size)
24090+{
24091+ struct vm_struct *area;
24092+
24093+ if (size == 0)
24094+ return NULL;
24095+
24096+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
24097+ return area ? area->addr : NULL;
24098+}
24099+EXPORT_SYMBOL(module_alloc_exec);
24100+
24101+void module_free_exec(struct module *mod, void *module_region)
24102+{
24103+ vunmap(module_region);
24104+}
24105+EXPORT_SYMBOL(module_free_exec);
24106+#else
24107+void module_free_exec(struct module *mod, void *module_region)
24108+{
24109+ module_free(mod, module_region);
24110+}
24111+EXPORT_SYMBOL(module_free_exec);
24112+
24113+void *module_alloc_exec(unsigned long size)
24114+{
24115+ return __module_alloc(size, PAGE_KERNEL_RX);
24116+}
24117+EXPORT_SYMBOL(module_alloc_exec);
24118+#endif
24119+#endif
24120+
24121 #ifdef CONFIG_X86_32
24122 int apply_relocate(Elf32_Shdr *sechdrs,
24123 const char *strtab,
24124@@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
24125 unsigned int i;
24126 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
24127 Elf32_Sym *sym;
24128- uint32_t *location;
24129+ uint32_t *plocation, location;
24130
24131 DEBUGP("Applying relocate section %u to %u\n",
24132 relsec, sechdrs[relsec].sh_info);
24133 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
24134 /* This is where to make the change */
24135- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
24136- + rel[i].r_offset;
24137+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
24138+ location = (uint32_t)plocation;
24139+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
24140+ plocation = ktla_ktva((void *)plocation);
24141 /* This is the symbol it is referring to. Note that all
24142 undefined symbols have been resolved. */
24143 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
24144@@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
24145 switch (ELF32_R_TYPE(rel[i].r_info)) {
24146 case R_386_32:
24147 /* We add the value into the location given */
24148- *location += sym->st_value;
24149+ pax_open_kernel();
24150+ *plocation += sym->st_value;
24151+ pax_close_kernel();
24152 break;
24153 case R_386_PC32:
24154 /* Add the value, subtract its position */
24155- *location += sym->st_value - (uint32_t)location;
24156+ pax_open_kernel();
24157+ *plocation += sym->st_value - location;
24158+ pax_close_kernel();
24159 break;
24160 default:
24161 pr_err("%s: Unknown relocation: %u\n",
24162@@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
24163 case R_X86_64_NONE:
24164 break;
24165 case R_X86_64_64:
24166+ pax_open_kernel();
24167 *(u64 *)loc = val;
24168+ pax_close_kernel();
24169 break;
24170 case R_X86_64_32:
24171+ pax_open_kernel();
24172 *(u32 *)loc = val;
24173+ pax_close_kernel();
24174 if (val != *(u32 *)loc)
24175 goto overflow;
24176 break;
24177 case R_X86_64_32S:
24178+ pax_open_kernel();
24179 *(s32 *)loc = val;
24180+ pax_close_kernel();
24181 if ((s64)val != *(s32 *)loc)
24182 goto overflow;
24183 break;
24184 case R_X86_64_PC32:
24185 val -= (u64)loc;
24186+ pax_open_kernel();
24187 *(u32 *)loc = val;
24188+ pax_close_kernel();
24189+
24190 #if 0
24191 if ((s64)val != *(s32 *)loc)
24192 goto overflow;
24193diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
24194index 88458fa..349f7a4 100644
24195--- a/arch/x86/kernel/msr.c
24196+++ b/arch/x86/kernel/msr.c
24197@@ -233,7 +233,7 @@ static int msr_class_cpu_callback(struct notifier_block *nfb,
24198 return notifier_from_errno(err);
24199 }
24200
24201-static struct notifier_block __refdata msr_class_cpu_notifier = {
24202+static struct notifier_block msr_class_cpu_notifier = {
24203 .notifier_call = msr_class_cpu_callback,
24204 };
24205
24206diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
24207index ba77ebc..65da999 100644
24208--- a/arch/x86/kernel/nmi.c
24209+++ b/arch/x86/kernel/nmi.c
24210@@ -138,7 +138,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
24211 return handled;
24212 }
24213
24214-int __register_nmi_handler(unsigned int type, struct nmiaction *action)
24215+int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
24216 {
24217 struct nmi_desc *desc = nmi_to_desc(type);
24218 unsigned long flags;
24219@@ -162,9 +162,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
24220 * event confuses some handlers (kdump uses this flag)
24221 */
24222 if (action->flags & NMI_FLAG_FIRST)
24223- list_add_rcu(&action->list, &desc->head);
24224+ pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
24225 else
24226- list_add_tail_rcu(&action->list, &desc->head);
24227+ pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
24228
24229 spin_unlock_irqrestore(&desc->lock, flags);
24230 return 0;
24231@@ -187,7 +187,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
24232 if (!strcmp(n->name, name)) {
24233 WARN(in_nmi(),
24234 "Trying to free NMI (%s) from NMI context!\n", n->name);
24235- list_del_rcu(&n->list);
24236+ pax_list_del_rcu((struct list_head *)&n->list);
24237 break;
24238 }
24239 }
24240@@ -512,6 +512,17 @@ static inline void nmi_nesting_postprocess(void)
24241 dotraplinkage notrace __kprobes void
24242 do_nmi(struct pt_regs *regs, long error_code)
24243 {
24244+
24245+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
24246+ if (!user_mode(regs)) {
24247+ unsigned long cs = regs->cs & 0xFFFF;
24248+ unsigned long ip = ktva_ktla(regs->ip);
24249+
24250+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
24251+ regs->ip = ip;
24252+ }
24253+#endif
24254+
24255 nmi_nesting_preprocess(regs);
24256
24257 nmi_enter();
24258diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
24259index 6d9582e..f746287 100644
24260--- a/arch/x86/kernel/nmi_selftest.c
24261+++ b/arch/x86/kernel/nmi_selftest.c
24262@@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
24263 {
24264 /* trap all the unknown NMIs we may generate */
24265 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
24266- __initdata);
24267+ __initconst);
24268 }
24269
24270 static void __init cleanup_nmi_testsuite(void)
24271@@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
24272 unsigned long timeout;
24273
24274 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
24275- NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
24276+ NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
24277 nmi_fail = FAILURE;
24278 return;
24279 }
24280diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
24281index 676b8c7..870ba04 100644
24282--- a/arch/x86/kernel/paravirt-spinlocks.c
24283+++ b/arch/x86/kernel/paravirt-spinlocks.c
24284@@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
24285 arch_spin_lock(lock);
24286 }
24287
24288-struct pv_lock_ops pv_lock_ops = {
24289+struct pv_lock_ops pv_lock_ops __read_only = {
24290 #ifdef CONFIG_SMP
24291 .spin_is_locked = __ticket_spin_is_locked,
24292 .spin_is_contended = __ticket_spin_is_contended,
24293diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
24294index cd6de64..27c6af0 100644
24295--- a/arch/x86/kernel/paravirt.c
24296+++ b/arch/x86/kernel/paravirt.c
24297@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
24298 {
24299 return x;
24300 }
24301+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
24302+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
24303+#endif
24304
24305 void __init default_banner(void)
24306 {
24307@@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
24308 if (opfunc == NULL)
24309 /* If there's no function, patch it with a ud2a (BUG) */
24310 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
24311- else if (opfunc == _paravirt_nop)
24312+ else if (opfunc == (void *)_paravirt_nop)
24313 /* If the operation is a nop, then nop the callsite */
24314 ret = paravirt_patch_nop();
24315
24316 /* identity functions just return their single argument */
24317- else if (opfunc == _paravirt_ident_32)
24318+ else if (opfunc == (void *)_paravirt_ident_32)
24319 ret = paravirt_patch_ident_32(insnbuf, len);
24320- else if (opfunc == _paravirt_ident_64)
24321+ else if (opfunc == (void *)_paravirt_ident_64)
24322 ret = paravirt_patch_ident_64(insnbuf, len);
24323+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
24324+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
24325+ ret = paravirt_patch_ident_64(insnbuf, len);
24326+#endif
24327
24328 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
24329 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
24330@@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
24331 if (insn_len > len || start == NULL)
24332 insn_len = len;
24333 else
24334- memcpy(insnbuf, start, insn_len);
24335+ memcpy(insnbuf, ktla_ktva(start), insn_len);
24336
24337 return insn_len;
24338 }
24339@@ -304,7 +311,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
24340 return this_cpu_read(paravirt_lazy_mode);
24341 }
24342
24343-struct pv_info pv_info = {
24344+struct pv_info pv_info __read_only = {
24345 .name = "bare hardware",
24346 .paravirt_enabled = 0,
24347 .kernel_rpl = 0,
24348@@ -315,16 +322,16 @@ struct pv_info pv_info = {
24349 #endif
24350 };
24351
24352-struct pv_init_ops pv_init_ops = {
24353+struct pv_init_ops pv_init_ops __read_only = {
24354 .patch = native_patch,
24355 };
24356
24357-struct pv_time_ops pv_time_ops = {
24358+struct pv_time_ops pv_time_ops __read_only = {
24359 .sched_clock = native_sched_clock,
24360 .steal_clock = native_steal_clock,
24361 };
24362
24363-struct pv_irq_ops pv_irq_ops = {
24364+struct pv_irq_ops pv_irq_ops __read_only = {
24365 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
24366 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
24367 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
24368@@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
24369 #endif
24370 };
24371
24372-struct pv_cpu_ops pv_cpu_ops = {
24373+struct pv_cpu_ops pv_cpu_ops __read_only = {
24374 .cpuid = native_cpuid,
24375 .get_debugreg = native_get_debugreg,
24376 .set_debugreg = native_set_debugreg,
24377@@ -394,21 +401,26 @@ struct pv_cpu_ops pv_cpu_ops = {
24378 .end_context_switch = paravirt_nop,
24379 };
24380
24381-struct pv_apic_ops pv_apic_ops = {
24382+struct pv_apic_ops pv_apic_ops __read_only= {
24383 #ifdef CONFIG_X86_LOCAL_APIC
24384 .startup_ipi_hook = paravirt_nop,
24385 #endif
24386 };
24387
24388-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
24389+#ifdef CONFIG_X86_32
24390+#ifdef CONFIG_X86_PAE
24391+/* 64-bit pagetable entries */
24392+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
24393+#else
24394 /* 32-bit pagetable entries */
24395 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
24396+#endif
24397 #else
24398 /* 64-bit pagetable entries */
24399 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
24400 #endif
24401
24402-struct pv_mmu_ops pv_mmu_ops = {
24403+struct pv_mmu_ops pv_mmu_ops __read_only = {
24404
24405 .read_cr2 = native_read_cr2,
24406 .write_cr2 = native_write_cr2,
24407@@ -458,6 +470,7 @@ struct pv_mmu_ops pv_mmu_ops = {
24408 .make_pud = PTE_IDENT,
24409
24410 .set_pgd = native_set_pgd,
24411+ .set_pgd_batched = native_set_pgd_batched,
24412 #endif
24413 #endif /* PAGETABLE_LEVELS >= 3 */
24414
24415@@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
24416 },
24417
24418 .set_fixmap = native_set_fixmap,
24419+
24420+#ifdef CONFIG_PAX_KERNEXEC
24421+ .pax_open_kernel = native_pax_open_kernel,
24422+ .pax_close_kernel = native_pax_close_kernel,
24423+#endif
24424+
24425 };
24426
24427 EXPORT_SYMBOL_GPL(pv_time_ops);
24428diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
24429index 299d493..2ccb0ee 100644
24430--- a/arch/x86/kernel/pci-calgary_64.c
24431+++ b/arch/x86/kernel/pci-calgary_64.c
24432@@ -1339,7 +1339,7 @@ static void __init get_tce_space_from_tar(void)
24433 tce_space = be64_to_cpu(readq(target));
24434 tce_space = tce_space & TAR_SW_BITS;
24435
24436- tce_space = tce_space & (~specified_table_size);
24437+ tce_space = tce_space & (~(unsigned long)specified_table_size);
24438 info->tce_space = (u64 *)__va(tce_space);
24439 }
24440 }
24441diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
24442index 35ccf75..7a15747 100644
24443--- a/arch/x86/kernel/pci-iommu_table.c
24444+++ b/arch/x86/kernel/pci-iommu_table.c
24445@@ -2,7 +2,7 @@
24446 #include <asm/iommu_table.h>
24447 #include <linux/string.h>
24448 #include <linux/kallsyms.h>
24449-
24450+#include <linux/sched.h>
24451
24452 #define DEBUG 1
24453
24454diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
24455index 6c483ba..d10ce2f 100644
24456--- a/arch/x86/kernel/pci-swiotlb.c
24457+++ b/arch/x86/kernel/pci-swiotlb.c
24458@@ -32,7 +32,7 @@ static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
24459 void *vaddr, dma_addr_t dma_addr,
24460 struct dma_attrs *attrs)
24461 {
24462- swiotlb_free_coherent(dev, size, vaddr, dma_addr);
24463+ swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
24464 }
24465
24466 static struct dma_map_ops swiotlb_dma_ops = {
24467diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
24468index 83369e5..52b93f0 100644
24469--- a/arch/x86/kernel/process.c
24470+++ b/arch/x86/kernel/process.c
24471@@ -36,7 +36,8 @@
24472 * section. Since TSS's are completely CPU-local, we want them
24473 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
24474 */
24475-DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
24476+struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
24477+EXPORT_SYMBOL(init_tss);
24478
24479 #ifdef CONFIG_X86_64
24480 static DEFINE_PER_CPU(unsigned char, is_idle);
24481@@ -92,7 +93,7 @@ void arch_task_cache_init(void)
24482 task_xstate_cachep =
24483 kmem_cache_create("task_xstate", xstate_size,
24484 __alignof__(union thread_xstate),
24485- SLAB_PANIC | SLAB_NOTRACK, NULL);
24486+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
24487 }
24488
24489 /*
24490@@ -105,7 +106,7 @@ void exit_thread(void)
24491 unsigned long *bp = t->io_bitmap_ptr;
24492
24493 if (bp) {
24494- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
24495+ struct tss_struct *tss = init_tss + get_cpu();
24496
24497 t->io_bitmap_ptr = NULL;
24498 clear_thread_flag(TIF_IO_BITMAP);
24499@@ -125,6 +126,9 @@ void flush_thread(void)
24500 {
24501 struct task_struct *tsk = current;
24502
24503+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
24504+ loadsegment(gs, 0);
24505+#endif
24506 flush_ptrace_hw_breakpoint(tsk);
24507 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
24508 drop_init_fpu(tsk);
24509@@ -271,7 +275,7 @@ static void __exit_idle(void)
24510 void exit_idle(void)
24511 {
24512 /* idle loop has pid 0 */
24513- if (current->pid)
24514+ if (task_pid_nr(current))
24515 return;
24516 __exit_idle();
24517 }
24518@@ -327,7 +331,7 @@ bool xen_set_default_idle(void)
24519 return ret;
24520 }
24521 #endif
24522-void stop_this_cpu(void *dummy)
24523+__noreturn void stop_this_cpu(void *dummy)
24524 {
24525 local_irq_disable();
24526 /*
24527@@ -456,16 +460,37 @@ static int __init idle_setup(char *str)
24528 }
24529 early_param("idle", idle_setup);
24530
24531-unsigned long arch_align_stack(unsigned long sp)
24532+#ifdef CONFIG_PAX_RANDKSTACK
24533+void pax_randomize_kstack(struct pt_regs *regs)
24534 {
24535- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
24536- sp -= get_random_int() % 8192;
24537- return sp & ~0xf;
24538-}
24539+ struct thread_struct *thread = &current->thread;
24540+ unsigned long time;
24541
24542-unsigned long arch_randomize_brk(struct mm_struct *mm)
24543-{
24544- unsigned long range_end = mm->brk + 0x02000000;
24545- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
24546-}
24547+ if (!randomize_va_space)
24548+ return;
24549+
24550+ if (v8086_mode(regs))
24551+ return;
24552
24553+ rdtscl(time);
24554+
24555+ /* P4 seems to return a 0 LSB, ignore it */
24556+#ifdef CONFIG_MPENTIUM4
24557+ time &= 0x3EUL;
24558+ time <<= 2;
24559+#elif defined(CONFIG_X86_64)
24560+ time &= 0xFUL;
24561+ time <<= 4;
24562+#else
24563+ time &= 0x1FUL;
24564+ time <<= 3;
24565+#endif
24566+
24567+ thread->sp0 ^= time;
24568+ load_sp0(init_tss + smp_processor_id(), thread);
24569+
24570+#ifdef CONFIG_X86_64
24571+ this_cpu_write(kernel_stack, thread->sp0);
24572+#endif
24573+}
24574+#endif
24575diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
24576index f8adefc..4bce3d6 100644
24577--- a/arch/x86/kernel/process_32.c
24578+++ b/arch/x86/kernel/process_32.c
24579@@ -65,6 +65,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
24580 unsigned long thread_saved_pc(struct task_struct *tsk)
24581 {
24582 return ((unsigned long *)tsk->thread.sp)[3];
24583+//XXX return tsk->thread.eip;
24584 }
24585
24586 void __show_regs(struct pt_regs *regs, int all)
24587@@ -74,19 +75,18 @@ void __show_regs(struct pt_regs *regs, int all)
24588 unsigned long sp;
24589 unsigned short ss, gs;
24590
24591- if (user_mode_vm(regs)) {
24592+ if (user_mode(regs)) {
24593 sp = regs->sp;
24594 ss = regs->ss & 0xffff;
24595- gs = get_user_gs(regs);
24596 } else {
24597 sp = kernel_stack_pointer(regs);
24598 savesegment(ss, ss);
24599- savesegment(gs, gs);
24600 }
24601+ gs = get_user_gs(regs);
24602
24603 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
24604 (u16)regs->cs, regs->ip, regs->flags,
24605- smp_processor_id());
24606+ raw_smp_processor_id());
24607 print_symbol("EIP is at %s\n", regs->ip);
24608
24609 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
24610@@ -133,20 +133,21 @@ void release_thread(struct task_struct *dead_task)
24611 int copy_thread(unsigned long clone_flags, unsigned long sp,
24612 unsigned long arg, struct task_struct *p)
24613 {
24614- struct pt_regs *childregs = task_pt_regs(p);
24615+ struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
24616 struct task_struct *tsk;
24617 int err;
24618
24619 p->thread.sp = (unsigned long) childregs;
24620 p->thread.sp0 = (unsigned long) (childregs+1);
24621+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
24622
24623 if (unlikely(p->flags & PF_KTHREAD)) {
24624 /* kernel thread */
24625 memset(childregs, 0, sizeof(struct pt_regs));
24626 p->thread.ip = (unsigned long) ret_from_kernel_thread;
24627- task_user_gs(p) = __KERNEL_STACK_CANARY;
24628- childregs->ds = __USER_DS;
24629- childregs->es = __USER_DS;
24630+ savesegment(gs, childregs->gs);
24631+ childregs->ds = __KERNEL_DS;
24632+ childregs->es = __KERNEL_DS;
24633 childregs->fs = __KERNEL_PERCPU;
24634 childregs->bx = sp; /* function */
24635 childregs->bp = arg;
24636@@ -253,7 +254,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24637 struct thread_struct *prev = &prev_p->thread,
24638 *next = &next_p->thread;
24639 int cpu = smp_processor_id();
24640- struct tss_struct *tss = &per_cpu(init_tss, cpu);
24641+ struct tss_struct *tss = init_tss + cpu;
24642 fpu_switch_t fpu;
24643
24644 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
24645@@ -277,6 +278,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24646 */
24647 lazy_save_gs(prev->gs);
24648
24649+#ifdef CONFIG_PAX_MEMORY_UDEREF
24650+ __set_fs(task_thread_info(next_p)->addr_limit);
24651+#endif
24652+
24653 /*
24654 * Load the per-thread Thread-Local Storage descriptor.
24655 */
24656@@ -307,6 +312,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24657 */
24658 arch_end_context_switch(next_p);
24659
24660+ this_cpu_write(current_task, next_p);
24661+ this_cpu_write(current_tinfo, &next_p->tinfo);
24662+
24663 /*
24664 * Restore %gs if needed (which is common)
24665 */
24666@@ -315,8 +323,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24667
24668 switch_fpu_finish(next_p, fpu);
24669
24670- this_cpu_write(current_task, next_p);
24671-
24672 return prev_p;
24673 }
24674
24675@@ -346,4 +352,3 @@ unsigned long get_wchan(struct task_struct *p)
24676 } while (count++ < 16);
24677 return 0;
24678 }
24679-
24680diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
24681index 05646ba..0c2906d 100644
24682--- a/arch/x86/kernel/process_64.c
24683+++ b/arch/x86/kernel/process_64.c
24684@@ -158,10 +158,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
24685 struct pt_regs *childregs;
24686 struct task_struct *me = current;
24687
24688- p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
24689+ p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
24690 childregs = task_pt_regs(p);
24691 p->thread.sp = (unsigned long) childregs;
24692 p->thread.usersp = me->thread.usersp;
24693+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
24694 set_tsk_thread_flag(p, TIF_FORK);
24695 p->fpu_counter = 0;
24696 p->thread.io_bitmap_ptr = NULL;
24697@@ -172,6 +173,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
24698 p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
24699 savesegment(es, p->thread.es);
24700 savesegment(ds, p->thread.ds);
24701+ savesegment(ss, p->thread.ss);
24702+ BUG_ON(p->thread.ss == __UDEREF_KERNEL_DS);
24703 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
24704
24705 if (unlikely(p->flags & PF_KTHREAD)) {
24706@@ -280,7 +283,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24707 struct thread_struct *prev = &prev_p->thread;
24708 struct thread_struct *next = &next_p->thread;
24709 int cpu = smp_processor_id();
24710- struct tss_struct *tss = &per_cpu(init_tss, cpu);
24711+ struct tss_struct *tss = init_tss + cpu;
24712 unsigned fsindex, gsindex;
24713 fpu_switch_t fpu;
24714
24715@@ -303,6 +306,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24716 if (unlikely(next->ds | prev->ds))
24717 loadsegment(ds, next->ds);
24718
24719+ savesegment(ss, prev->ss);
24720+ if (unlikely(next->ss != prev->ss))
24721+ loadsegment(ss, next->ss);
24722
24723 /* We must save %fs and %gs before load_TLS() because
24724 * %fs and %gs may be cleared by load_TLS().
24725@@ -362,10 +368,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24726 prev->usersp = this_cpu_read(old_rsp);
24727 this_cpu_write(old_rsp, next->usersp);
24728 this_cpu_write(current_task, next_p);
24729+ this_cpu_write(current_tinfo, &next_p->tinfo);
24730
24731- this_cpu_write(kernel_stack,
24732- (unsigned long)task_stack_page(next_p) +
24733- THREAD_SIZE - KERNEL_STACK_OFFSET);
24734+ this_cpu_write(kernel_stack, next->sp0);
24735
24736 /*
24737 * Now maybe reload the debug registers and handle I/O bitmaps
24738@@ -434,12 +439,11 @@ unsigned long get_wchan(struct task_struct *p)
24739 if (!p || p == current || p->state == TASK_RUNNING)
24740 return 0;
24741 stack = (unsigned long)task_stack_page(p);
24742- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
24743+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
24744 return 0;
24745 fp = *(u64 *)(p->thread.sp);
24746 do {
24747- if (fp < (unsigned long)stack ||
24748- fp >= (unsigned long)stack+THREAD_SIZE)
24749+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
24750 return 0;
24751 ip = *(u64 *)(fp+8);
24752 if (!in_sched_functions(ip))
24753diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
24754index 7461f50..1334029 100644
24755--- a/arch/x86/kernel/ptrace.c
24756+++ b/arch/x86/kernel/ptrace.c
24757@@ -184,14 +184,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
24758 {
24759 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
24760 unsigned long sp = (unsigned long)&regs->sp;
24761- struct thread_info *tinfo;
24762
24763- if (context == (sp & ~(THREAD_SIZE - 1)))
24764+ if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
24765 return sp;
24766
24767- tinfo = (struct thread_info *)context;
24768- if (tinfo->previous_esp)
24769- return tinfo->previous_esp;
24770+ sp = *(unsigned long *)context;
24771+ if (sp)
24772+ return sp;
24773
24774 return (unsigned long)regs;
24775 }
24776@@ -588,7 +587,7 @@ static void ptrace_triggered(struct perf_event *bp,
24777 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
24778 {
24779 int i;
24780- int dr7 = 0;
24781+ unsigned long dr7 = 0;
24782 struct arch_hw_breakpoint *info;
24783
24784 for (i = 0; i < HBP_NUM; i++) {
24785@@ -822,7 +821,7 @@ long arch_ptrace(struct task_struct *child, long request,
24786 unsigned long addr, unsigned long data)
24787 {
24788 int ret;
24789- unsigned long __user *datap = (unsigned long __user *)data;
24790+ unsigned long __user *datap = (__force unsigned long __user *)data;
24791
24792 switch (request) {
24793 /* read the word at location addr in the USER area. */
24794@@ -907,14 +906,14 @@ long arch_ptrace(struct task_struct *child, long request,
24795 if ((int) addr < 0)
24796 return -EIO;
24797 ret = do_get_thread_area(child, addr,
24798- (struct user_desc __user *)data);
24799+ (__force struct user_desc __user *) data);
24800 break;
24801
24802 case PTRACE_SET_THREAD_AREA:
24803 if ((int) addr < 0)
24804 return -EIO;
24805 ret = do_set_thread_area(child, addr,
24806- (struct user_desc __user *)data, 0);
24807+ (__force struct user_desc __user *) data, 0);
24808 break;
24809 #endif
24810
24811@@ -1292,7 +1291,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
24812
24813 #ifdef CONFIG_X86_64
24814
24815-static struct user_regset x86_64_regsets[] __read_mostly = {
24816+static user_regset_no_const x86_64_regsets[] __read_only = {
24817 [REGSET_GENERAL] = {
24818 .core_note_type = NT_PRSTATUS,
24819 .n = sizeof(struct user_regs_struct) / sizeof(long),
24820@@ -1333,7 +1332,7 @@ static const struct user_regset_view user_x86_64_view = {
24821 #endif /* CONFIG_X86_64 */
24822
24823 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
24824-static struct user_regset x86_32_regsets[] __read_mostly = {
24825+static user_regset_no_const x86_32_regsets[] __read_only = {
24826 [REGSET_GENERAL] = {
24827 .core_note_type = NT_PRSTATUS,
24828 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
24829@@ -1386,7 +1385,7 @@ static const struct user_regset_view user_x86_32_view = {
24830 */
24831 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
24832
24833-void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
24834+void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
24835 {
24836 #ifdef CONFIG_X86_64
24837 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
24838@@ -1421,7 +1420,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
24839 memset(info, 0, sizeof(*info));
24840 info->si_signo = SIGTRAP;
24841 info->si_code = si_code;
24842- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
24843+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
24844 }
24845
24846 void user_single_step_siginfo(struct task_struct *tsk,
24847@@ -1450,6 +1449,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
24848 # define IS_IA32 0
24849 #endif
24850
24851+#ifdef CONFIG_GRKERNSEC_SETXID
24852+extern void gr_delayed_cred_worker(void);
24853+#endif
24854+
24855 /*
24856 * We must return the syscall number to actually look up in the table.
24857 * This can be -1L to skip running any syscall at all.
24858@@ -1460,6 +1463,11 @@ long syscall_trace_enter(struct pt_regs *regs)
24859
24860 user_exit();
24861
24862+#ifdef CONFIG_GRKERNSEC_SETXID
24863+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
24864+ gr_delayed_cred_worker();
24865+#endif
24866+
24867 /*
24868 * If we stepped into a sysenter/syscall insn, it trapped in
24869 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
24870@@ -1515,6 +1523,11 @@ void syscall_trace_leave(struct pt_regs *regs)
24871 */
24872 user_exit();
24873
24874+#ifdef CONFIG_GRKERNSEC_SETXID
24875+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
24876+ gr_delayed_cred_worker();
24877+#endif
24878+
24879 audit_syscall_exit(regs);
24880
24881 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
24882diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
24883index 2cb9470..ff1fd80 100644
24884--- a/arch/x86/kernel/pvclock.c
24885+++ b/arch/x86/kernel/pvclock.c
24886@@ -43,11 +43,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
24887 return pv_tsc_khz;
24888 }
24889
24890-static atomic64_t last_value = ATOMIC64_INIT(0);
24891+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
24892
24893 void pvclock_resume(void)
24894 {
24895- atomic64_set(&last_value, 0);
24896+ atomic64_set_unchecked(&last_value, 0);
24897 }
24898
24899 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
24900@@ -92,11 +92,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
24901 * updating at the same time, and one of them could be slightly behind,
24902 * making the assumption that last_value always go forward fail to hold.
24903 */
24904- last = atomic64_read(&last_value);
24905+ last = atomic64_read_unchecked(&last_value);
24906 do {
24907 if (ret < last)
24908 return last;
24909- last = atomic64_cmpxchg(&last_value, last, ret);
24910+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
24911 } while (unlikely(last != ret));
24912
24913 return ret;
24914diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
24915index 563ed91..b9c3313 100644
24916--- a/arch/x86/kernel/reboot.c
24917+++ b/arch/x86/kernel/reboot.c
24918@@ -68,6 +68,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
24919
24920 void __noreturn machine_real_restart(unsigned int type)
24921 {
24922+
24923+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
24924+ struct desc_struct *gdt;
24925+#endif
24926+
24927 local_irq_disable();
24928
24929 /*
24930@@ -95,7 +100,29 @@ void __noreturn machine_real_restart(unsigned int type)
24931
24932 /* Jump to the identity-mapped low memory code */
24933 #ifdef CONFIG_X86_32
24934- asm volatile("jmpl *%0" : :
24935+
24936+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
24937+ gdt = get_cpu_gdt_table(smp_processor_id());
24938+ pax_open_kernel();
24939+#ifdef CONFIG_PAX_MEMORY_UDEREF
24940+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
24941+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
24942+ loadsegment(ds, __KERNEL_DS);
24943+ loadsegment(es, __KERNEL_DS);
24944+ loadsegment(ss, __KERNEL_DS);
24945+#endif
24946+#ifdef CONFIG_PAX_KERNEXEC
24947+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
24948+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
24949+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
24950+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
24951+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
24952+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
24953+#endif
24954+ pax_close_kernel();
24955+#endif
24956+
24957+ asm volatile("ljmpl *%0" : :
24958 "rm" (real_mode_header->machine_real_restart_asm),
24959 "a" (type));
24960 #else
24961@@ -442,7 +469,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
24962 * try to force a triple fault and then cycle between hitting the keyboard
24963 * controller and doing that
24964 */
24965-static void native_machine_emergency_restart(void)
24966+static void __noreturn native_machine_emergency_restart(void)
24967 {
24968 int i;
24969 int attempt = 0;
24970@@ -551,13 +578,13 @@ void native_machine_shutdown(void)
24971 #endif
24972 }
24973
24974-static void __machine_emergency_restart(int emergency)
24975+static void __noreturn __machine_emergency_restart(int emergency)
24976 {
24977 reboot_emergency = emergency;
24978 machine_ops.emergency_restart();
24979 }
24980
24981-static void native_machine_restart(char *__unused)
24982+static void __noreturn native_machine_restart(char *__unused)
24983 {
24984 pr_notice("machine restart\n");
24985
24986@@ -566,7 +593,7 @@ static void native_machine_restart(char *__unused)
24987 __machine_emergency_restart(0);
24988 }
24989
24990-static void native_machine_halt(void)
24991+static void __noreturn native_machine_halt(void)
24992 {
24993 /* Stop other cpus and apics */
24994 machine_shutdown();
24995@@ -576,7 +603,7 @@ static void native_machine_halt(void)
24996 stop_this_cpu(NULL);
24997 }
24998
24999-static void native_machine_power_off(void)
25000+static void __noreturn native_machine_power_off(void)
25001 {
25002 if (pm_power_off) {
25003 if (!reboot_force)
25004@@ -585,9 +612,10 @@ static void native_machine_power_off(void)
25005 }
25006 /* A fallback in case there is no PM info available */
25007 tboot_shutdown(TB_SHUTDOWN_HALT);
25008+ unreachable();
25009 }
25010
25011-struct machine_ops machine_ops = {
25012+struct machine_ops machine_ops __read_only = {
25013 .power_off = native_machine_power_off,
25014 .shutdown = native_machine_shutdown,
25015 .emergency_restart = native_machine_emergency_restart,
25016diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
25017index c8e41e9..64049ef 100644
25018--- a/arch/x86/kernel/reboot_fixups_32.c
25019+++ b/arch/x86/kernel/reboot_fixups_32.c
25020@@ -57,7 +57,7 @@ struct device_fixup {
25021 unsigned int vendor;
25022 unsigned int device;
25023 void (*reboot_fixup)(struct pci_dev *);
25024-};
25025+} __do_const;
25026
25027 /*
25028 * PCI ids solely used for fixups_table go here
25029diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
25030index 3fd2c69..16ef367 100644
25031--- a/arch/x86/kernel/relocate_kernel_64.S
25032+++ b/arch/x86/kernel/relocate_kernel_64.S
25033@@ -11,6 +11,7 @@
25034 #include <asm/kexec.h>
25035 #include <asm/processor-flags.h>
25036 #include <asm/pgtable_types.h>
25037+#include <asm/alternative-asm.h>
25038
25039 /*
25040 * Must be relocatable PIC code callable as a C function
25041@@ -96,8 +97,7 @@ relocate_kernel:
25042
25043 /* jump to identity mapped page */
25044 addq $(identity_mapped - relocate_kernel), %r8
25045- pushq %r8
25046- ret
25047+ jmp *%r8
25048
25049 identity_mapped:
25050 /* set return address to 0 if not preserving context */
25051@@ -167,6 +167,7 @@ identity_mapped:
25052 xorl %r14d, %r14d
25053 xorl %r15d, %r15d
25054
25055+ pax_force_retaddr 0, 1
25056 ret
25057
25058 1:
25059diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
25060index f8ec578..0cc110a 100644
25061--- a/arch/x86/kernel/setup.c
25062+++ b/arch/x86/kernel/setup.c
25063@@ -110,6 +110,7 @@
25064 #include <asm/mce.h>
25065 #include <asm/alternative.h>
25066 #include <asm/prom.h>
25067+#include <asm/boot.h>
25068
25069 /*
25070 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
25071@@ -205,12 +206,50 @@ EXPORT_SYMBOL(boot_cpu_data);
25072 #endif
25073
25074
25075-#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
25076-unsigned long mmu_cr4_features;
25077+#ifdef CONFIG_X86_64
25078+unsigned long mmu_cr4_features __read_only = X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE;
25079+#elif defined(CONFIG_X86_PAE)
25080+unsigned long mmu_cr4_features __read_only = X86_CR4_PAE;
25081 #else
25082-unsigned long mmu_cr4_features = X86_CR4_PAE;
25083+unsigned long mmu_cr4_features __read_only;
25084 #endif
25085
25086+void set_in_cr4(unsigned long mask)
25087+{
25088+ unsigned long cr4 = read_cr4();
25089+
25090+ if ((cr4 & mask) == mask && cr4 == mmu_cr4_features)
25091+ return;
25092+
25093+ pax_open_kernel();
25094+ mmu_cr4_features |= mask;
25095+ pax_close_kernel();
25096+
25097+ if (trampoline_cr4_features)
25098+ *trampoline_cr4_features = mmu_cr4_features;
25099+ cr4 |= mask;
25100+ write_cr4(cr4);
25101+}
25102+EXPORT_SYMBOL(set_in_cr4);
25103+
25104+void clear_in_cr4(unsigned long mask)
25105+{
25106+ unsigned long cr4 = read_cr4();
25107+
25108+ if (!(cr4 & mask) && cr4 == mmu_cr4_features)
25109+ return;
25110+
25111+ pax_open_kernel();
25112+ mmu_cr4_features &= ~mask;
25113+ pax_close_kernel();
25114+
25115+ if (trampoline_cr4_features)
25116+ *trampoline_cr4_features = mmu_cr4_features;
25117+ cr4 &= ~mask;
25118+ write_cr4(cr4);
25119+}
25120+EXPORT_SYMBOL(clear_in_cr4);
25121+
25122 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
25123 int bootloader_type, bootloader_version;
25124
25125@@ -444,7 +483,7 @@ static void __init parse_setup_data(void)
25126
25127 switch (data->type) {
25128 case SETUP_E820_EXT:
25129- parse_e820_ext(data);
25130+ parse_e820_ext((struct setup_data __force_kernel *)data);
25131 break;
25132 case SETUP_DTB:
25133 add_dtb(pa_data);
25134@@ -771,7 +810,7 @@ static void __init trim_bios_range(void)
25135 * area (640->1Mb) as ram even though it is not.
25136 * take them out.
25137 */
25138- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
25139+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
25140
25141 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
25142 }
25143@@ -779,7 +818,7 @@ static void __init trim_bios_range(void)
25144 /* called before trim_bios_range() to spare extra sanitize */
25145 static void __init e820_add_kernel_range(void)
25146 {
25147- u64 start = __pa_symbol(_text);
25148+ u64 start = __pa_symbol(ktla_ktva(_text));
25149 u64 size = __pa_symbol(_end) - start;
25150
25151 /*
25152@@ -841,8 +880,12 @@ static void __init trim_low_memory_range(void)
25153
25154 void __init setup_arch(char **cmdline_p)
25155 {
25156+#ifdef CONFIG_X86_32
25157+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
25158+#else
25159 memblock_reserve(__pa_symbol(_text),
25160 (unsigned long)__bss_stop - (unsigned long)_text);
25161+#endif
25162
25163 early_reserve_initrd();
25164
25165@@ -934,14 +977,14 @@ void __init setup_arch(char **cmdline_p)
25166
25167 if (!boot_params.hdr.root_flags)
25168 root_mountflags &= ~MS_RDONLY;
25169- init_mm.start_code = (unsigned long) _text;
25170- init_mm.end_code = (unsigned long) _etext;
25171+ init_mm.start_code = ktla_ktva((unsigned long) _text);
25172+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
25173 init_mm.end_data = (unsigned long) _edata;
25174 init_mm.brk = _brk_end;
25175
25176- code_resource.start = __pa_symbol(_text);
25177- code_resource.end = __pa_symbol(_etext)-1;
25178- data_resource.start = __pa_symbol(_etext);
25179+ code_resource.start = __pa_symbol(ktla_ktva(_text));
25180+ code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
25181+ data_resource.start = __pa_symbol(_sdata);
25182 data_resource.end = __pa_symbol(_edata)-1;
25183 bss_resource.start = __pa_symbol(__bss_start);
25184 bss_resource.end = __pa_symbol(__bss_stop)-1;
25185diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
25186index 5cdff03..80fa283 100644
25187--- a/arch/x86/kernel/setup_percpu.c
25188+++ b/arch/x86/kernel/setup_percpu.c
25189@@ -21,19 +21,17 @@
25190 #include <asm/cpu.h>
25191 #include <asm/stackprotector.h>
25192
25193-DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
25194+#ifdef CONFIG_SMP
25195+DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
25196 EXPORT_PER_CPU_SYMBOL(cpu_number);
25197+#endif
25198
25199-#ifdef CONFIG_X86_64
25200 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
25201-#else
25202-#define BOOT_PERCPU_OFFSET 0
25203-#endif
25204
25205 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
25206 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
25207
25208-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
25209+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
25210 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
25211 };
25212 EXPORT_SYMBOL(__per_cpu_offset);
25213@@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
25214 {
25215 #ifdef CONFIG_NEED_MULTIPLE_NODES
25216 pg_data_t *last = NULL;
25217- unsigned int cpu;
25218+ int cpu;
25219
25220 for_each_possible_cpu(cpu) {
25221 int node = early_cpu_to_node(cpu);
25222@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
25223 {
25224 #ifdef CONFIG_X86_32
25225 struct desc_struct gdt;
25226+ unsigned long base = per_cpu_offset(cpu);
25227
25228- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
25229- 0x2 | DESCTYPE_S, 0x8);
25230- gdt.s = 1;
25231+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
25232+ 0x83 | DESCTYPE_S, 0xC);
25233 write_gdt_entry(get_cpu_gdt_table(cpu),
25234 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
25235 #endif
25236@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
25237 /* alrighty, percpu areas up and running */
25238 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
25239 for_each_possible_cpu(cpu) {
25240+#ifdef CONFIG_CC_STACKPROTECTOR
25241+#ifdef CONFIG_X86_32
25242+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
25243+#endif
25244+#endif
25245 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
25246 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
25247 per_cpu(cpu_number, cpu) = cpu;
25248@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
25249 */
25250 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
25251 #endif
25252+#ifdef CONFIG_CC_STACKPROTECTOR
25253+#ifdef CONFIG_X86_32
25254+ if (!cpu)
25255+ per_cpu(stack_canary.canary, cpu) = canary;
25256+#endif
25257+#endif
25258 /*
25259 * Up to this point, the boot CPU has been using .init.data
25260 * area. Reload any changed state for the boot CPU.
25261diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
25262index d859eea..44e17c4 100644
25263--- a/arch/x86/kernel/signal.c
25264+++ b/arch/x86/kernel/signal.c
25265@@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
25266 * Align the stack pointer according to the i386 ABI,
25267 * i.e. so that on function entry ((sp + 4) & 15) == 0.
25268 */
25269- sp = ((sp + 4) & -16ul) - 4;
25270+ sp = ((sp - 12) & -16ul) - 4;
25271 #else /* !CONFIG_X86_32 */
25272 sp = round_down(sp, 16) - 8;
25273 #endif
25274@@ -298,9 +298,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
25275 }
25276
25277 if (current->mm->context.vdso)
25278- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
25279+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
25280 else
25281- restorer = &frame->retcode;
25282+ restorer = (void __user *)&frame->retcode;
25283 if (ksig->ka.sa.sa_flags & SA_RESTORER)
25284 restorer = ksig->ka.sa.sa_restorer;
25285
25286@@ -314,7 +314,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
25287 * reasons and because gdb uses it as a signature to notice
25288 * signal handler stack frames.
25289 */
25290- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
25291+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
25292
25293 if (err)
25294 return -EFAULT;
25295@@ -361,7 +361,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
25296 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
25297
25298 /* Set up to return from userspace. */
25299- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
25300+ if (current->mm->context.vdso)
25301+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
25302+ else
25303+ restorer = (void __user *)&frame->retcode;
25304 if (ksig->ka.sa.sa_flags & SA_RESTORER)
25305 restorer = ksig->ka.sa.sa_restorer;
25306 put_user_ex(restorer, &frame->pretcode);
25307@@ -373,7 +376,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
25308 * reasons and because gdb uses it as a signature to notice
25309 * signal handler stack frames.
25310 */
25311- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
25312+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
25313 } put_user_catch(err);
25314
25315 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
25316@@ -609,7 +612,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
25317 {
25318 int usig = signr_convert(ksig->sig);
25319 sigset_t *set = sigmask_to_save();
25320- compat_sigset_t *cset = (compat_sigset_t *) set;
25321+ sigset_t sigcopy;
25322+ compat_sigset_t *cset;
25323+
25324+ sigcopy = *set;
25325+
25326+ cset = (compat_sigset_t *) &sigcopy;
25327
25328 /* Set up the stack frame */
25329 if (is_ia32_frame()) {
25330@@ -620,7 +628,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
25331 } else if (is_x32_frame()) {
25332 return x32_setup_rt_frame(ksig, cset, regs);
25333 } else {
25334- return __setup_rt_frame(ksig->sig, ksig, set, regs);
25335+ return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
25336 }
25337 }
25338
25339diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
25340index cdaa347..f5af55d 100644
25341--- a/arch/x86/kernel/smp.c
25342+++ b/arch/x86/kernel/smp.c
25343@@ -341,7 +341,7 @@ static int __init nonmi_ipi_setup(char *str)
25344
25345 __setup("nonmi_ipi", nonmi_ipi_setup);
25346
25347-struct smp_ops smp_ops = {
25348+struct smp_ops smp_ops __read_only = {
25349 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
25350 .smp_prepare_cpus = native_smp_prepare_cpus,
25351 .smp_cpus_done = native_smp_cpus_done,
25352diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
25353index aecc98a..0244a53 100644
25354--- a/arch/x86/kernel/smpboot.c
25355+++ b/arch/x86/kernel/smpboot.c
25356@@ -251,14 +251,18 @@ static void notrace start_secondary(void *unused)
25357
25358 enable_start_cpu0 = 0;
25359
25360-#ifdef CONFIG_X86_32
25361- /* switch away from the initial page table */
25362- load_cr3(swapper_pg_dir);
25363- __flush_tlb_all();
25364-#endif
25365-
25366 /* otherwise gcc will move up smp_processor_id before the cpu_init */
25367 barrier();
25368+
25369+ /* switch away from the initial page table */
25370+#ifdef CONFIG_PAX_PER_CPU_PGD
25371+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
25372+ __flush_tlb_all();
25373+#elif defined(CONFIG_X86_32)
25374+ load_cr3(swapper_pg_dir);
25375+ __flush_tlb_all();
25376+#endif
25377+
25378 /*
25379 * Check TSC synchronization with the BP:
25380 */
25381@@ -748,6 +752,7 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
25382 idle->thread.sp = (unsigned long) (((struct pt_regs *)
25383 (THREAD_SIZE + task_stack_page(idle))) - 1);
25384 per_cpu(current_task, cpu) = idle;
25385+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
25386
25387 #ifdef CONFIG_X86_32
25388 /* Stack for startup_32 can be just as for start_secondary onwards */
25389@@ -755,11 +760,13 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
25390 #else
25391 clear_tsk_thread_flag(idle, TIF_FORK);
25392 initial_gs = per_cpu_offset(cpu);
25393- per_cpu(kernel_stack, cpu) =
25394- (unsigned long)task_stack_page(idle) -
25395- KERNEL_STACK_OFFSET + THREAD_SIZE;
25396+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
25397 #endif
25398+
25399+ pax_open_kernel();
25400 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
25401+ pax_close_kernel();
25402+
25403 initial_code = (unsigned long)start_secondary;
25404 stack_start = idle->thread.sp;
25405
25406@@ -908,6 +915,15 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
25407 /* the FPU context is blank, nobody can own it */
25408 __cpu_disable_lazy_restore(cpu);
25409
25410+#ifdef CONFIG_PAX_PER_CPU_PGD
25411+ clone_pgd_range(get_cpu_pgd(cpu, kernel) + KERNEL_PGD_BOUNDARY,
25412+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25413+ KERNEL_PGD_PTRS);
25414+ clone_pgd_range(get_cpu_pgd(cpu, user) + KERNEL_PGD_BOUNDARY,
25415+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25416+ KERNEL_PGD_PTRS);
25417+#endif
25418+
25419 err = do_boot_cpu(apicid, cpu, tidle);
25420 if (err) {
25421 pr_debug("do_boot_cpu failed %d\n", err);
25422diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
25423index 9b4d51d..5d28b58 100644
25424--- a/arch/x86/kernel/step.c
25425+++ b/arch/x86/kernel/step.c
25426@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
25427 struct desc_struct *desc;
25428 unsigned long base;
25429
25430- seg &= ~7UL;
25431+ seg >>= 3;
25432
25433 mutex_lock(&child->mm->context.lock);
25434- if (unlikely((seg >> 3) >= child->mm->context.size))
25435+ if (unlikely(seg >= child->mm->context.size))
25436 addr = -1L; /* bogus selector, access would fault */
25437 else {
25438 desc = child->mm->context.ldt + seg;
25439@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
25440 addr += base;
25441 }
25442 mutex_unlock(&child->mm->context.lock);
25443- }
25444+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
25445+ addr = ktla_ktva(addr);
25446
25447 return addr;
25448 }
25449@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
25450 unsigned char opcode[15];
25451 unsigned long addr = convert_ip_to_linear(child, regs);
25452
25453+ if (addr == -EINVAL)
25454+ return 0;
25455+
25456 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
25457 for (i = 0; i < copied; i++) {
25458 switch (opcode[i]) {
25459diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
25460new file mode 100644
25461index 0000000..5877189
25462--- /dev/null
25463+++ b/arch/x86/kernel/sys_i386_32.c
25464@@ -0,0 +1,189 @@
25465+/*
25466+ * This file contains various random system calls that
25467+ * have a non-standard calling sequence on the Linux/i386
25468+ * platform.
25469+ */
25470+
25471+#include <linux/errno.h>
25472+#include <linux/sched.h>
25473+#include <linux/mm.h>
25474+#include <linux/fs.h>
25475+#include <linux/smp.h>
25476+#include <linux/sem.h>
25477+#include <linux/msg.h>
25478+#include <linux/shm.h>
25479+#include <linux/stat.h>
25480+#include <linux/syscalls.h>
25481+#include <linux/mman.h>
25482+#include <linux/file.h>
25483+#include <linux/utsname.h>
25484+#include <linux/ipc.h>
25485+#include <linux/elf.h>
25486+
25487+#include <linux/uaccess.h>
25488+#include <linux/unistd.h>
25489+
25490+#include <asm/syscalls.h>
25491+
25492+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
25493+{
25494+ unsigned long pax_task_size = TASK_SIZE;
25495+
25496+#ifdef CONFIG_PAX_SEGMEXEC
25497+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
25498+ pax_task_size = SEGMEXEC_TASK_SIZE;
25499+#endif
25500+
25501+ if (flags & MAP_FIXED)
25502+ if (len > pax_task_size || addr > pax_task_size - len)
25503+ return -EINVAL;
25504+
25505+ return 0;
25506+}
25507+
25508+/*
25509+ * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
25510+ */
25511+static unsigned long get_align_mask(void)
25512+{
25513+ if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
25514+ return 0;
25515+
25516+ if (!(current->flags & PF_RANDOMIZE))
25517+ return 0;
25518+
25519+ return va_align.mask;
25520+}
25521+
25522+unsigned long
25523+arch_get_unmapped_area(struct file *filp, unsigned long addr,
25524+ unsigned long len, unsigned long pgoff, unsigned long flags)
25525+{
25526+ struct mm_struct *mm = current->mm;
25527+ struct vm_area_struct *vma;
25528+ unsigned long pax_task_size = TASK_SIZE;
25529+ struct vm_unmapped_area_info info;
25530+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
25531+
25532+#ifdef CONFIG_PAX_SEGMEXEC
25533+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
25534+ pax_task_size = SEGMEXEC_TASK_SIZE;
25535+#endif
25536+
25537+ pax_task_size -= PAGE_SIZE;
25538+
25539+ if (len > pax_task_size)
25540+ return -ENOMEM;
25541+
25542+ if (flags & MAP_FIXED)
25543+ return addr;
25544+
25545+#ifdef CONFIG_PAX_RANDMMAP
25546+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
25547+#endif
25548+
25549+ if (addr) {
25550+ addr = PAGE_ALIGN(addr);
25551+ if (pax_task_size - len >= addr) {
25552+ vma = find_vma(mm, addr);
25553+ if (check_heap_stack_gap(vma, addr, len, offset))
25554+ return addr;
25555+ }
25556+ }
25557+
25558+ info.flags = 0;
25559+ info.length = len;
25560+ info.align_mask = filp ? get_align_mask() : 0;
25561+ info.align_offset = pgoff << PAGE_SHIFT;
25562+ info.threadstack_offset = offset;
25563+
25564+#ifdef CONFIG_PAX_PAGEEXEC
25565+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
25566+ info.low_limit = 0x00110000UL;
25567+ info.high_limit = mm->start_code;
25568+
25569+#ifdef CONFIG_PAX_RANDMMAP
25570+ if (mm->pax_flags & MF_PAX_RANDMMAP)
25571+ info.low_limit += mm->delta_mmap & 0x03FFF000UL;
25572+#endif
25573+
25574+ if (info.low_limit < info.high_limit) {
25575+ addr = vm_unmapped_area(&info);
25576+ if (!IS_ERR_VALUE(addr))
25577+ return addr;
25578+ }
25579+ } else
25580+#endif
25581+
25582+ info.low_limit = mm->mmap_base;
25583+ info.high_limit = pax_task_size;
25584+
25585+ return vm_unmapped_area(&info);
25586+}
25587+
25588+unsigned long
25589+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
25590+ const unsigned long len, const unsigned long pgoff,
25591+ const unsigned long flags)
25592+{
25593+ struct vm_area_struct *vma;
25594+ struct mm_struct *mm = current->mm;
25595+ unsigned long addr = addr0, pax_task_size = TASK_SIZE;
25596+ struct vm_unmapped_area_info info;
25597+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
25598+
25599+#ifdef CONFIG_PAX_SEGMEXEC
25600+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
25601+ pax_task_size = SEGMEXEC_TASK_SIZE;
25602+#endif
25603+
25604+ pax_task_size -= PAGE_SIZE;
25605+
25606+ /* requested length too big for entire address space */
25607+ if (len > pax_task_size)
25608+ return -ENOMEM;
25609+
25610+ if (flags & MAP_FIXED)
25611+ return addr;
25612+
25613+#ifdef CONFIG_PAX_PAGEEXEC
25614+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
25615+ goto bottomup;
25616+#endif
25617+
25618+#ifdef CONFIG_PAX_RANDMMAP
25619+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
25620+#endif
25621+
25622+ /* requesting a specific address */
25623+ if (addr) {
25624+ addr = PAGE_ALIGN(addr);
25625+ if (pax_task_size - len >= addr) {
25626+ vma = find_vma(mm, addr);
25627+ if (check_heap_stack_gap(vma, addr, len, offset))
25628+ return addr;
25629+ }
25630+ }
25631+
25632+ info.flags = VM_UNMAPPED_AREA_TOPDOWN;
25633+ info.length = len;
25634+ info.low_limit = PAGE_SIZE;
25635+ info.high_limit = mm->mmap_base;
25636+ info.align_mask = filp ? get_align_mask() : 0;
25637+ info.align_offset = pgoff << PAGE_SHIFT;
25638+ info.threadstack_offset = offset;
25639+
25640+ addr = vm_unmapped_area(&info);
25641+ if (!(addr & ~PAGE_MASK))
25642+ return addr;
25643+ VM_BUG_ON(addr != -ENOMEM);
25644+
25645+bottomup:
25646+ /*
25647+ * A failed mmap() very likely causes application failure,
25648+ * so fall back to the bottom-up function here. This scenario
25649+ * can happen with large stack limits and large mmap()
25650+ * allocations.
25651+ */
25652+ return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
25653+}
25654diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
25655index 30277e2..5664a29 100644
25656--- a/arch/x86/kernel/sys_x86_64.c
25657+++ b/arch/x86/kernel/sys_x86_64.c
25658@@ -81,8 +81,8 @@ out:
25659 return error;
25660 }
25661
25662-static void find_start_end(unsigned long flags, unsigned long *begin,
25663- unsigned long *end)
25664+static void find_start_end(struct mm_struct *mm, unsigned long flags,
25665+ unsigned long *begin, unsigned long *end)
25666 {
25667 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
25668 unsigned long new_begin;
25669@@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
25670 *begin = new_begin;
25671 }
25672 } else {
25673- *begin = current->mm->mmap_legacy_base;
25674+ *begin = mm->mmap_legacy_base;
25675 *end = TASK_SIZE;
25676 }
25677 }
25678@@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
25679 struct vm_area_struct *vma;
25680 struct vm_unmapped_area_info info;
25681 unsigned long begin, end;
25682+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
25683
25684 if (flags & MAP_FIXED)
25685 return addr;
25686
25687- find_start_end(flags, &begin, &end);
25688+ find_start_end(mm, flags, &begin, &end);
25689
25690 if (len > end)
25691 return -ENOMEM;
25692
25693+#ifdef CONFIG_PAX_RANDMMAP
25694+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
25695+#endif
25696+
25697 if (addr) {
25698 addr = PAGE_ALIGN(addr);
25699 vma = find_vma(mm, addr);
25700- if (end - len >= addr &&
25701- (!vma || addr + len <= vma->vm_start))
25702+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
25703 return addr;
25704 }
25705
25706@@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
25707 info.high_limit = end;
25708 info.align_mask = filp ? get_align_mask() : 0;
25709 info.align_offset = pgoff << PAGE_SHIFT;
25710+ info.threadstack_offset = offset;
25711 return vm_unmapped_area(&info);
25712 }
25713
25714@@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
25715 struct mm_struct *mm = current->mm;
25716 unsigned long addr = addr0;
25717 struct vm_unmapped_area_info info;
25718+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
25719
25720 /* requested length too big for entire address space */
25721 if (len > TASK_SIZE)
25722@@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
25723 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
25724 goto bottomup;
25725
25726+#ifdef CONFIG_PAX_RANDMMAP
25727+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
25728+#endif
25729+
25730 /* requesting a specific address */
25731 if (addr) {
25732 addr = PAGE_ALIGN(addr);
25733 vma = find_vma(mm, addr);
25734- if (TASK_SIZE - len >= addr &&
25735- (!vma || addr + len <= vma->vm_start))
25736+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
25737 return addr;
25738 }
25739
25740@@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
25741 info.high_limit = mm->mmap_base;
25742 info.align_mask = filp ? get_align_mask() : 0;
25743 info.align_offset = pgoff << PAGE_SHIFT;
25744+ info.threadstack_offset = offset;
25745 addr = vm_unmapped_area(&info);
25746 if (!(addr & ~PAGE_MASK))
25747 return addr;
25748diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
25749index addf7b5..f960685 100644
25750--- a/arch/x86/kernel/tboot.c
25751+++ b/arch/x86/kernel/tboot.c
25752@@ -221,7 +221,7 @@ static int tboot_setup_sleep(void)
25753
25754 void tboot_shutdown(u32 shutdown_type)
25755 {
25756- void (*shutdown)(void);
25757+ void (* __noreturn shutdown)(void);
25758
25759 if (!tboot_enabled())
25760 return;
25761@@ -243,7 +243,7 @@ void tboot_shutdown(u32 shutdown_type)
25762
25763 switch_to_tboot_pt();
25764
25765- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
25766+ shutdown = (void *)tboot->shutdown_entry;
25767 shutdown();
25768
25769 /* should not reach here */
25770@@ -301,7 +301,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
25771 return 0;
25772 }
25773
25774-static atomic_t ap_wfs_count;
25775+static atomic_unchecked_t ap_wfs_count;
25776
25777 static int tboot_wait_for_aps(int num_aps)
25778 {
25779@@ -325,9 +325,9 @@ static int tboot_cpu_callback(struct notifier_block *nfb, unsigned long action,
25780 {
25781 switch (action) {
25782 case CPU_DYING:
25783- atomic_inc(&ap_wfs_count);
25784+ atomic_inc_unchecked(&ap_wfs_count);
25785 if (num_online_cpus() == 1)
25786- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
25787+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
25788 return NOTIFY_BAD;
25789 break;
25790 }
25791@@ -413,7 +413,7 @@ static __init int tboot_late_init(void)
25792
25793 tboot_create_trampoline();
25794
25795- atomic_set(&ap_wfs_count, 0);
25796+ atomic_set_unchecked(&ap_wfs_count, 0);
25797 register_hotcpu_notifier(&tboot_cpu_notifier);
25798
25799 #ifdef CONFIG_DEBUG_FS
25800diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
25801index 24d3c91..d06b473 100644
25802--- a/arch/x86/kernel/time.c
25803+++ b/arch/x86/kernel/time.c
25804@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
25805 {
25806 unsigned long pc = instruction_pointer(regs);
25807
25808- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
25809+ if (!user_mode(regs) && in_lock_functions(pc)) {
25810 #ifdef CONFIG_FRAME_POINTER
25811- return *(unsigned long *)(regs->bp + sizeof(long));
25812+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
25813 #else
25814 unsigned long *sp =
25815 (unsigned long *)kernel_stack_pointer(regs);
25816@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
25817 * or above a saved flags. Eflags has bits 22-31 zero,
25818 * kernel addresses don't.
25819 */
25820+
25821+#ifdef CONFIG_PAX_KERNEXEC
25822+ return ktla_ktva(sp[0]);
25823+#else
25824 if (sp[0] >> 22)
25825 return sp[0];
25826 if (sp[1] >> 22)
25827 return sp[1];
25828 #endif
25829+
25830+#endif
25831 }
25832 return pc;
25833 }
25834diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
25835index f7fec09..9991981 100644
25836--- a/arch/x86/kernel/tls.c
25837+++ b/arch/x86/kernel/tls.c
25838@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
25839 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
25840 return -EINVAL;
25841
25842+#ifdef CONFIG_PAX_SEGMEXEC
25843+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
25844+ return -EINVAL;
25845+#endif
25846+
25847 set_tls_desc(p, idx, &info, 1);
25848
25849 return 0;
25850@@ -200,7 +205,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
25851
25852 if (kbuf)
25853 info = kbuf;
25854- else if (__copy_from_user(infobuf, ubuf, count))
25855+ else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
25856 return -EFAULT;
25857 else
25858 info = infobuf;
25859diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c
25860index 1c113db..287b42e 100644
25861--- a/arch/x86/kernel/tracepoint.c
25862+++ b/arch/x86/kernel/tracepoint.c
25863@@ -9,11 +9,11 @@
25864 #include <linux/atomic.h>
25865
25866 atomic_t trace_idt_ctr = ATOMIC_INIT(0);
25867-struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
25868+const struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
25869 (unsigned long) trace_idt_table };
25870
25871 /* No need to be aligned, but done to keep all IDTs defined the same way. */
25872-gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
25873+gate_desc trace_idt_table[NR_VECTORS] __page_aligned_rodata;
25874
25875 static int trace_irq_vector_refcount;
25876 static DEFINE_MUTEX(irq_vector_mutex);
25877diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
25878index 1b23a1c..910de0d 100644
25879--- a/arch/x86/kernel/traps.c
25880+++ b/arch/x86/kernel/traps.c
25881@@ -65,7 +65,7 @@
25882 #include <asm/proto.h>
25883
25884 /* No need to be aligned, but done to keep all IDTs defined the same way. */
25885-gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
25886+gate_desc debug_idt_table[NR_VECTORS] __page_aligned_rodata;
25887 #else
25888 #include <asm/processor-flags.h>
25889 #include <asm/setup.h>
25890@@ -74,7 +74,7 @@ asmlinkage int system_call(void);
25891 #endif
25892
25893 /* Must be page-aligned because the real IDT is used in a fixmap. */
25894-gate_desc idt_table[NR_VECTORS] __page_aligned_bss;
25895+gate_desc idt_table[NR_VECTORS] __page_aligned_rodata;
25896
25897 DECLARE_BITMAP(used_vectors, NR_VECTORS);
25898 EXPORT_SYMBOL_GPL(used_vectors);
25899@@ -106,11 +106,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
25900 }
25901
25902 static int __kprobes
25903-do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
25904+do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
25905 struct pt_regs *regs, long error_code)
25906 {
25907 #ifdef CONFIG_X86_32
25908- if (regs->flags & X86_VM_MASK) {
25909+ if (v8086_mode(regs)) {
25910 /*
25911 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
25912 * On nmi (interrupt 2), do_trap should not be called.
25913@@ -123,12 +123,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
25914 return -1;
25915 }
25916 #endif
25917- if (!user_mode(regs)) {
25918+ if (!user_mode_novm(regs)) {
25919 if (!fixup_exception(regs)) {
25920 tsk->thread.error_code = error_code;
25921 tsk->thread.trap_nr = trapnr;
25922+
25923+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25924+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
25925+ str = "PAX: suspicious stack segment fault";
25926+#endif
25927+
25928 die(str, regs, error_code);
25929 }
25930+
25931+#ifdef CONFIG_PAX_REFCOUNT
25932+ if (trapnr == 4)
25933+ pax_report_refcount_overflow(regs);
25934+#endif
25935+
25936 return 0;
25937 }
25938
25939@@ -136,7 +148,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
25940 }
25941
25942 static void __kprobes
25943-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
25944+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
25945 long error_code, siginfo_t *info)
25946 {
25947 struct task_struct *tsk = current;
25948@@ -160,7 +172,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
25949 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
25950 printk_ratelimit()) {
25951 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
25952- tsk->comm, tsk->pid, str,
25953+ tsk->comm, task_pid_nr(tsk), str,
25954 regs->ip, regs->sp, error_code);
25955 print_vma_addr(" in ", regs->ip);
25956 pr_cont("\n");
25957@@ -276,7 +288,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
25958 conditional_sti(regs);
25959
25960 #ifdef CONFIG_X86_32
25961- if (regs->flags & X86_VM_MASK) {
25962+ if (v8086_mode(regs)) {
25963 local_irq_enable();
25964 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
25965 goto exit;
25966@@ -284,18 +296,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
25967 #endif
25968
25969 tsk = current;
25970- if (!user_mode(regs)) {
25971+ if (!user_mode_novm(regs)) {
25972 if (fixup_exception(regs))
25973 goto exit;
25974
25975 tsk->thread.error_code = error_code;
25976 tsk->thread.trap_nr = X86_TRAP_GP;
25977 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
25978- X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
25979+ X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
25980+
25981+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25982+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
25983+ die("PAX: suspicious general protection fault", regs, error_code);
25984+ else
25985+#endif
25986+
25987 die("general protection fault", regs, error_code);
25988+ }
25989 goto exit;
25990 }
25991
25992+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
25993+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
25994+ struct mm_struct *mm = tsk->mm;
25995+ unsigned long limit;
25996+
25997+ down_write(&mm->mmap_sem);
25998+ limit = mm->context.user_cs_limit;
25999+ if (limit < TASK_SIZE) {
26000+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
26001+ up_write(&mm->mmap_sem);
26002+ return;
26003+ }
26004+ up_write(&mm->mmap_sem);
26005+ }
26006+#endif
26007+
26008 tsk->thread.error_code = error_code;
26009 tsk->thread.trap_nr = X86_TRAP_GP;
26010
26011@@ -453,7 +489,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
26012 /* It's safe to allow irq's after DR6 has been saved */
26013 preempt_conditional_sti(regs);
26014
26015- if (regs->flags & X86_VM_MASK) {
26016+ if (v8086_mode(regs)) {
26017 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
26018 X86_TRAP_DB);
26019 preempt_conditional_cli(regs);
26020@@ -468,7 +504,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
26021 * We already checked v86 mode above, so we can check for kernel mode
26022 * by just checking the CPL of CS.
26023 */
26024- if ((dr6 & DR_STEP) && !user_mode(regs)) {
26025+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
26026 tsk->thread.debugreg6 &= ~DR_STEP;
26027 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
26028 regs->flags &= ~X86_EFLAGS_TF;
26029@@ -500,7 +536,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
26030 return;
26031 conditional_sti(regs);
26032
26033- if (!user_mode_vm(regs))
26034+ if (!user_mode(regs))
26035 {
26036 if (!fixup_exception(regs)) {
26037 task->thread.error_code = error_code;
26038diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
26039index 2ed8459..7cf329f 100644
26040--- a/arch/x86/kernel/uprobes.c
26041+++ b/arch/x86/kernel/uprobes.c
26042@@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
26043 int ret = NOTIFY_DONE;
26044
26045 /* We are only interested in userspace traps */
26046- if (regs && !user_mode_vm(regs))
26047+ if (regs && !user_mode(regs))
26048 return NOTIFY_DONE;
26049
26050 switch (val) {
26051@@ -719,7 +719,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
26052
26053 if (ncopied != rasize) {
26054 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
26055- "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
26056+ "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
26057
26058 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
26059 }
26060diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
26061index b9242ba..50c5edd 100644
26062--- a/arch/x86/kernel/verify_cpu.S
26063+++ b/arch/x86/kernel/verify_cpu.S
26064@@ -20,6 +20,7 @@
26065 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
26066 * arch/x86/kernel/trampoline_64.S: secondary processor verification
26067 * arch/x86/kernel/head_32.S: processor startup
26068+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
26069 *
26070 * verify_cpu, returns the status of longmode and SSE in register %eax.
26071 * 0: Success 1: Failure
26072diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
26073index e8edcf5..27f9344 100644
26074--- a/arch/x86/kernel/vm86_32.c
26075+++ b/arch/x86/kernel/vm86_32.c
26076@@ -44,6 +44,7 @@
26077 #include <linux/ptrace.h>
26078 #include <linux/audit.h>
26079 #include <linux/stddef.h>
26080+#include <linux/grsecurity.h>
26081
26082 #include <asm/uaccess.h>
26083 #include <asm/io.h>
26084@@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
26085 do_exit(SIGSEGV);
26086 }
26087
26088- tss = &per_cpu(init_tss, get_cpu());
26089+ tss = init_tss + get_cpu();
26090 current->thread.sp0 = current->thread.saved_sp0;
26091 current->thread.sysenter_cs = __KERNEL_CS;
26092 load_sp0(tss, &current->thread);
26093@@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
26094
26095 if (tsk->thread.saved_sp0)
26096 return -EPERM;
26097+
26098+#ifdef CONFIG_GRKERNSEC_VM86
26099+ if (!capable(CAP_SYS_RAWIO)) {
26100+ gr_handle_vm86();
26101+ return -EPERM;
26102+ }
26103+#endif
26104+
26105 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
26106 offsetof(struct kernel_vm86_struct, vm86plus) -
26107 sizeof(info.regs));
26108@@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
26109 int tmp;
26110 struct vm86plus_struct __user *v86;
26111
26112+#ifdef CONFIG_GRKERNSEC_VM86
26113+ if (!capable(CAP_SYS_RAWIO)) {
26114+ gr_handle_vm86();
26115+ return -EPERM;
26116+ }
26117+#endif
26118+
26119 tsk = current;
26120 switch (cmd) {
26121 case VM86_REQUEST_IRQ:
26122@@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
26123 tsk->thread.saved_fs = info->regs32->fs;
26124 tsk->thread.saved_gs = get_user_gs(info->regs32);
26125
26126- tss = &per_cpu(init_tss, get_cpu());
26127+ tss = init_tss + get_cpu();
26128 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
26129 if (cpu_has_sep)
26130 tsk->thread.sysenter_cs = 0;
26131@@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
26132 goto cannot_handle;
26133 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
26134 goto cannot_handle;
26135- intr_ptr = (unsigned long __user *) (i << 2);
26136+ intr_ptr = (__force unsigned long __user *) (i << 2);
26137 if (get_user(segoffs, intr_ptr))
26138 goto cannot_handle;
26139 if ((segoffs >> 16) == BIOSSEG)
26140diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
26141index 10c4f30..65408b9 100644
26142--- a/arch/x86/kernel/vmlinux.lds.S
26143+++ b/arch/x86/kernel/vmlinux.lds.S
26144@@ -26,6 +26,13 @@
26145 #include <asm/page_types.h>
26146 #include <asm/cache.h>
26147 #include <asm/boot.h>
26148+#include <asm/segment.h>
26149+
26150+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26151+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
26152+#else
26153+#define __KERNEL_TEXT_OFFSET 0
26154+#endif
26155
26156 #undef i386 /* in case the preprocessor is a 32bit one */
26157
26158@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
26159
26160 PHDRS {
26161 text PT_LOAD FLAGS(5); /* R_E */
26162+#ifdef CONFIG_X86_32
26163+ module PT_LOAD FLAGS(5); /* R_E */
26164+#endif
26165+#ifdef CONFIG_XEN
26166+ rodata PT_LOAD FLAGS(5); /* R_E */
26167+#else
26168+ rodata PT_LOAD FLAGS(4); /* R__ */
26169+#endif
26170 data PT_LOAD FLAGS(6); /* RW_ */
26171-#ifdef CONFIG_X86_64
26172+ init.begin PT_LOAD FLAGS(6); /* RW_ */
26173 #ifdef CONFIG_SMP
26174 percpu PT_LOAD FLAGS(6); /* RW_ */
26175 #endif
26176+ text.init PT_LOAD FLAGS(5); /* R_E */
26177+ text.exit PT_LOAD FLAGS(5); /* R_E */
26178 init PT_LOAD FLAGS(7); /* RWE */
26179-#endif
26180 note PT_NOTE FLAGS(0); /* ___ */
26181 }
26182
26183 SECTIONS
26184 {
26185 #ifdef CONFIG_X86_32
26186- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
26187- phys_startup_32 = startup_32 - LOAD_OFFSET;
26188+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
26189 #else
26190- . = __START_KERNEL;
26191- phys_startup_64 = startup_64 - LOAD_OFFSET;
26192+ . = __START_KERNEL;
26193 #endif
26194
26195 /* Text and read-only data */
26196- .text : AT(ADDR(.text) - LOAD_OFFSET) {
26197- _text = .;
26198+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
26199 /* bootstrapping code */
26200+#ifdef CONFIG_X86_32
26201+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
26202+#else
26203+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
26204+#endif
26205+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
26206+ _text = .;
26207 HEAD_TEXT
26208 . = ALIGN(8);
26209 _stext = .;
26210@@ -104,13 +124,47 @@ SECTIONS
26211 IRQENTRY_TEXT
26212 *(.fixup)
26213 *(.gnu.warning)
26214- /* End of text section */
26215- _etext = .;
26216 } :text = 0x9090
26217
26218- NOTES :text :note
26219+ . += __KERNEL_TEXT_OFFSET;
26220
26221- EXCEPTION_TABLE(16) :text = 0x9090
26222+#ifdef CONFIG_X86_32
26223+ . = ALIGN(PAGE_SIZE);
26224+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
26225+
26226+#ifdef CONFIG_PAX_KERNEXEC
26227+ MODULES_EXEC_VADDR = .;
26228+ BYTE(0)
26229+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
26230+ . = ALIGN(HPAGE_SIZE) - 1;
26231+ MODULES_EXEC_END = .;
26232+#endif
26233+
26234+ } :module
26235+#endif
26236+
26237+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
26238+ /* End of text section */
26239+ BYTE(0)
26240+ _etext = . - __KERNEL_TEXT_OFFSET;
26241+ }
26242+
26243+#ifdef CONFIG_X86_32
26244+ . = ALIGN(PAGE_SIZE);
26245+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
26246+ . = ALIGN(PAGE_SIZE);
26247+ *(.empty_zero_page)
26248+ *(.initial_pg_fixmap)
26249+ *(.initial_pg_pmd)
26250+ *(.initial_page_table)
26251+ *(.swapper_pg_dir)
26252+ } :rodata
26253+#endif
26254+
26255+ . = ALIGN(PAGE_SIZE);
26256+ NOTES :rodata :note
26257+
26258+ EXCEPTION_TABLE(16) :rodata
26259
26260 #if defined(CONFIG_DEBUG_RODATA)
26261 /* .text should occupy whole number of pages */
26262@@ -122,16 +176,20 @@ SECTIONS
26263
26264 /* Data */
26265 .data : AT(ADDR(.data) - LOAD_OFFSET) {
26266+
26267+#ifdef CONFIG_PAX_KERNEXEC
26268+ . = ALIGN(HPAGE_SIZE);
26269+#else
26270+ . = ALIGN(PAGE_SIZE);
26271+#endif
26272+
26273 /* Start of data section */
26274 _sdata = .;
26275
26276 /* init_task */
26277 INIT_TASK_DATA(THREAD_SIZE)
26278
26279-#ifdef CONFIG_X86_32
26280- /* 32 bit has nosave before _edata */
26281 NOSAVE_DATA
26282-#endif
26283
26284 PAGE_ALIGNED_DATA(PAGE_SIZE)
26285
26286@@ -172,12 +230,19 @@ SECTIONS
26287 #endif /* CONFIG_X86_64 */
26288
26289 /* Init code and data - will be freed after init */
26290- . = ALIGN(PAGE_SIZE);
26291 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
26292+ BYTE(0)
26293+
26294+#ifdef CONFIG_PAX_KERNEXEC
26295+ . = ALIGN(HPAGE_SIZE);
26296+#else
26297+ . = ALIGN(PAGE_SIZE);
26298+#endif
26299+
26300 __init_begin = .; /* paired with __init_end */
26301- }
26302+ } :init.begin
26303
26304-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
26305+#ifdef CONFIG_SMP
26306 /*
26307 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
26308 * output PHDR, so the next output section - .init.text - should
26309@@ -186,12 +251,27 @@ SECTIONS
26310 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
26311 #endif
26312
26313- INIT_TEXT_SECTION(PAGE_SIZE)
26314-#ifdef CONFIG_X86_64
26315- :init
26316-#endif
26317+ . = ALIGN(PAGE_SIZE);
26318+ init_begin = .;
26319+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
26320+ VMLINUX_SYMBOL(_sinittext) = .;
26321+ INIT_TEXT
26322+ VMLINUX_SYMBOL(_einittext) = .;
26323+ . = ALIGN(PAGE_SIZE);
26324+ } :text.init
26325
26326- INIT_DATA_SECTION(16)
26327+ /*
26328+ * .exit.text is discard at runtime, not link time, to deal with
26329+ * references from .altinstructions and .eh_frame
26330+ */
26331+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
26332+ EXIT_TEXT
26333+ . = ALIGN(16);
26334+ } :text.exit
26335+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
26336+
26337+ . = ALIGN(PAGE_SIZE);
26338+ INIT_DATA_SECTION(16) :init
26339
26340 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
26341 __x86_cpu_dev_start = .;
26342@@ -253,19 +333,12 @@ SECTIONS
26343 }
26344
26345 . = ALIGN(8);
26346- /*
26347- * .exit.text is discard at runtime, not link time, to deal with
26348- * references from .altinstructions and .eh_frame
26349- */
26350- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
26351- EXIT_TEXT
26352- }
26353
26354 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
26355 EXIT_DATA
26356 }
26357
26358-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
26359+#ifndef CONFIG_SMP
26360 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
26361 #endif
26362
26363@@ -284,16 +357,10 @@ SECTIONS
26364 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
26365 __smp_locks = .;
26366 *(.smp_locks)
26367- . = ALIGN(PAGE_SIZE);
26368 __smp_locks_end = .;
26369+ . = ALIGN(PAGE_SIZE);
26370 }
26371
26372-#ifdef CONFIG_X86_64
26373- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
26374- NOSAVE_DATA
26375- }
26376-#endif
26377-
26378 /* BSS */
26379 . = ALIGN(PAGE_SIZE);
26380 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
26381@@ -309,6 +376,7 @@ SECTIONS
26382 __brk_base = .;
26383 . += 64 * 1024; /* 64k alignment slop space */
26384 *(.brk_reservation) /* areas brk users have reserved */
26385+ . = ALIGN(HPAGE_SIZE);
26386 __brk_limit = .;
26387 }
26388
26389@@ -335,13 +403,12 @@ SECTIONS
26390 * for the boot processor.
26391 */
26392 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
26393-INIT_PER_CPU(gdt_page);
26394 INIT_PER_CPU(irq_stack_union);
26395
26396 /*
26397 * Build-time check on the image size:
26398 */
26399-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
26400+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
26401 "kernel image bigger than KERNEL_IMAGE_SIZE");
26402
26403 #ifdef CONFIG_SMP
26404diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
26405index 1f96f93..d5c8f7a 100644
26406--- a/arch/x86/kernel/vsyscall_64.c
26407+++ b/arch/x86/kernel/vsyscall_64.c
26408@@ -56,15 +56,13 @@
26409 DEFINE_VVAR(int, vgetcpu_mode);
26410 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
26411
26412-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
26413+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
26414
26415 static int __init vsyscall_setup(char *str)
26416 {
26417 if (str) {
26418 if (!strcmp("emulate", str))
26419 vsyscall_mode = EMULATE;
26420- else if (!strcmp("native", str))
26421- vsyscall_mode = NATIVE;
26422 else if (!strcmp("none", str))
26423 vsyscall_mode = NONE;
26424 else
26425@@ -323,8 +321,7 @@ do_ret:
26426 return true;
26427
26428 sigsegv:
26429- force_sig(SIGSEGV, current);
26430- return true;
26431+ do_group_exit(SIGKILL);
26432 }
26433
26434 /*
26435@@ -377,10 +374,7 @@ void __init map_vsyscall(void)
26436 extern char __vvar_page;
26437 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
26438
26439- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
26440- vsyscall_mode == NATIVE
26441- ? PAGE_KERNEL_VSYSCALL
26442- : PAGE_KERNEL_VVAR);
26443+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
26444 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
26445 (unsigned long)VSYSCALL_START);
26446
26447diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
26448index b014d94..e775258 100644
26449--- a/arch/x86/kernel/x8664_ksyms_64.c
26450+++ b/arch/x86/kernel/x8664_ksyms_64.c
26451@@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
26452 EXPORT_SYMBOL(copy_user_generic_unrolled);
26453 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
26454 EXPORT_SYMBOL(__copy_user_nocache);
26455-EXPORT_SYMBOL(_copy_from_user);
26456-EXPORT_SYMBOL(_copy_to_user);
26457
26458 EXPORT_SYMBOL(copy_page);
26459 EXPORT_SYMBOL(clear_page);
26460@@ -66,3 +64,7 @@ EXPORT_SYMBOL(empty_zero_page);
26461 #ifndef CONFIG_PARAVIRT
26462 EXPORT_SYMBOL(native_load_gs_index);
26463 #endif
26464+
26465+#ifdef CONFIG_PAX_PER_CPU_PGD
26466+EXPORT_SYMBOL(cpu_pgd);
26467+#endif
26468diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
26469index 5f24c71..1dadf09 100644
26470--- a/arch/x86/kernel/x86_init.c
26471+++ b/arch/x86/kernel/x86_init.c
26472@@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit = {
26473 static void default_nmi_init(void) { };
26474 static int default_i8042_detect(void) { return 1; };
26475
26476-struct x86_platform_ops x86_platform = {
26477+struct x86_platform_ops x86_platform __read_only = {
26478 .calibrate_tsc = native_calibrate_tsc,
26479 .get_wallclock = mach_get_cmos_time,
26480 .set_wallclock = mach_set_rtc_mmss,
26481@@ -107,7 +107,7 @@ struct x86_platform_ops x86_platform = {
26482 };
26483
26484 EXPORT_SYMBOL_GPL(x86_platform);
26485-struct x86_msi_ops x86_msi = {
26486+struct x86_msi_ops x86_msi __read_only = {
26487 .setup_msi_irqs = native_setup_msi_irqs,
26488 .compose_msi_msg = native_compose_msi_msg,
26489 .teardown_msi_irq = native_teardown_msi_irq,
26490@@ -116,7 +116,7 @@ struct x86_msi_ops x86_msi = {
26491 .setup_hpet_msi = default_setup_hpet_msi,
26492 };
26493
26494-struct x86_io_apic_ops x86_io_apic_ops = {
26495+struct x86_io_apic_ops x86_io_apic_ops __read_only = {
26496 .init = native_io_apic_init_mappings,
26497 .read = native_io_apic_read,
26498 .write = native_io_apic_write,
26499diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
26500index 422fd82..c3687ca 100644
26501--- a/arch/x86/kernel/xsave.c
26502+++ b/arch/x86/kernel/xsave.c
26503@@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
26504 {
26505 int err;
26506
26507+ buf = (struct xsave_struct __user *)____m(buf);
26508 if (use_xsave())
26509 err = xsave_user(buf);
26510 else if (use_fxsr())
26511@@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
26512 */
26513 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
26514 {
26515+ buf = (void __user *)____m(buf);
26516 if (use_xsave()) {
26517 if ((unsigned long)buf % 64 || fx_only) {
26518 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
26519diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
26520index a20ecb5..d0e2194 100644
26521--- a/arch/x86/kvm/cpuid.c
26522+++ b/arch/x86/kvm/cpuid.c
26523@@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
26524 struct kvm_cpuid2 *cpuid,
26525 struct kvm_cpuid_entry2 __user *entries)
26526 {
26527- int r;
26528+ int r, i;
26529
26530 r = -E2BIG;
26531 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
26532 goto out;
26533 r = -EFAULT;
26534- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
26535- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
26536+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
26537 goto out;
26538+ for (i = 0; i < cpuid->nent; ++i) {
26539+ struct kvm_cpuid_entry2 cpuid_entry;
26540+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
26541+ goto out;
26542+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
26543+ }
26544 vcpu->arch.cpuid_nent = cpuid->nent;
26545 kvm_apic_set_version(vcpu);
26546 kvm_x86_ops->cpuid_update(vcpu);
26547@@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
26548 struct kvm_cpuid2 *cpuid,
26549 struct kvm_cpuid_entry2 __user *entries)
26550 {
26551- int r;
26552+ int r, i;
26553
26554 r = -E2BIG;
26555 if (cpuid->nent < vcpu->arch.cpuid_nent)
26556 goto out;
26557 r = -EFAULT;
26558- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
26559- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
26560+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
26561 goto out;
26562+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
26563+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
26564+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
26565+ goto out;
26566+ }
26567 return 0;
26568
26569 out:
26570diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
26571index afc1124..3e431f2 100644
26572--- a/arch/x86/kvm/lapic.c
26573+++ b/arch/x86/kvm/lapic.c
26574@@ -55,7 +55,7 @@
26575 #define APIC_BUS_CYCLE_NS 1
26576
26577 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
26578-#define apic_debug(fmt, arg...)
26579+#define apic_debug(fmt, arg...) do {} while (0)
26580
26581 #define APIC_LVT_NUM 6
26582 /* 14 is the version for Xeon and Pentium 8.4.8*/
26583diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
26584index 7769699..c8aca4a7f 100644
26585--- a/arch/x86/kvm/paging_tmpl.h
26586+++ b/arch/x86/kvm/paging_tmpl.h
26587@@ -208,7 +208,7 @@ retry_walk:
26588 if (unlikely(kvm_is_error_hva(host_addr)))
26589 goto error;
26590
26591- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
26592+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
26593 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
26594 goto error;
26595 walker->ptep_user[walker->level - 1] = ptep_user;
26596diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
26597index c0bc803..6837a50 100644
26598--- a/arch/x86/kvm/svm.c
26599+++ b/arch/x86/kvm/svm.c
26600@@ -3501,7 +3501,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
26601 int cpu = raw_smp_processor_id();
26602
26603 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
26604+
26605+ pax_open_kernel();
26606 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
26607+ pax_close_kernel();
26608+
26609 load_TR_desc();
26610 }
26611
26612@@ -3902,6 +3906,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
26613 #endif
26614 #endif
26615
26616+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
26617+ __set_fs(current_thread_info()->addr_limit);
26618+#endif
26619+
26620 reload_tss(vcpu);
26621
26622 local_irq_disable();
26623diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
26624index 064d0be..f5f758e 100644
26625--- a/arch/x86/kvm/vmx.c
26626+++ b/arch/x86/kvm/vmx.c
26627@@ -1311,12 +1311,12 @@ static void vmcs_write64(unsigned long field, u64 value)
26628 #endif
26629 }
26630
26631-static void vmcs_clear_bits(unsigned long field, u32 mask)
26632+static void vmcs_clear_bits(unsigned long field, unsigned long mask)
26633 {
26634 vmcs_writel(field, vmcs_readl(field) & ~mask);
26635 }
26636
26637-static void vmcs_set_bits(unsigned long field, u32 mask)
26638+static void vmcs_set_bits(unsigned long field, unsigned long mask)
26639 {
26640 vmcs_writel(field, vmcs_readl(field) | mask);
26641 }
26642@@ -1517,7 +1517,11 @@ static void reload_tss(void)
26643 struct desc_struct *descs;
26644
26645 descs = (void *)gdt->address;
26646+
26647+ pax_open_kernel();
26648 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
26649+ pax_close_kernel();
26650+
26651 load_TR_desc();
26652 }
26653
26654@@ -1741,6 +1745,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
26655 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
26656 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
26657
26658+#ifdef CONFIG_PAX_PER_CPU_PGD
26659+ vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
26660+#endif
26661+
26662 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
26663 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
26664 vmx->loaded_vmcs->cpu = cpu;
26665@@ -2940,8 +2948,11 @@ static __init int hardware_setup(void)
26666 if (!cpu_has_vmx_flexpriority())
26667 flexpriority_enabled = 0;
26668
26669- if (!cpu_has_vmx_tpr_shadow())
26670- kvm_x86_ops->update_cr8_intercept = NULL;
26671+ if (!cpu_has_vmx_tpr_shadow()) {
26672+ pax_open_kernel();
26673+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
26674+ pax_close_kernel();
26675+ }
26676
26677 if (enable_ept && !cpu_has_vmx_ept_2m_page())
26678 kvm_disable_largepages();
26679@@ -2952,13 +2963,15 @@ static __init int hardware_setup(void)
26680 if (!cpu_has_vmx_apicv())
26681 enable_apicv = 0;
26682
26683+ pax_open_kernel();
26684 if (enable_apicv)
26685- kvm_x86_ops->update_cr8_intercept = NULL;
26686+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
26687 else {
26688- kvm_x86_ops->hwapic_irr_update = NULL;
26689- kvm_x86_ops->deliver_posted_interrupt = NULL;
26690- kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
26691+ *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
26692+ *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
26693+ *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
26694 }
26695+ pax_close_kernel();
26696
26697 if (nested)
26698 nested_vmx_setup_ctls_msrs();
26699@@ -4081,7 +4094,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
26700
26701 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
26702 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
26703+
26704+#ifndef CONFIG_PAX_PER_CPU_PGD
26705 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
26706+#endif
26707
26708 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
26709 #ifdef CONFIG_X86_64
26710@@ -4103,7 +4119,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
26711 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
26712 vmx->host_idt_base = dt.address;
26713
26714- vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
26715+ vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
26716
26717 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
26718 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
26719@@ -7039,6 +7055,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
26720 "jmp 2f \n\t"
26721 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
26722 "2: "
26723+
26724+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26725+ "ljmp %[cs],$3f\n\t"
26726+ "3: "
26727+#endif
26728+
26729 /* Save guest registers, load host registers, keep flags */
26730 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
26731 "pop %0 \n\t"
26732@@ -7091,6 +7113,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
26733 #endif
26734 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
26735 [wordsize]"i"(sizeof(ulong))
26736+
26737+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26738+ ,[cs]"i"(__KERNEL_CS)
26739+#endif
26740+
26741 : "cc", "memory"
26742 #ifdef CONFIG_X86_64
26743 , "rax", "rbx", "rdi", "rsi"
26744@@ -7104,7 +7131,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
26745 if (debugctlmsr)
26746 update_debugctlmsr(debugctlmsr);
26747
26748-#ifndef CONFIG_X86_64
26749+#ifdef CONFIG_X86_32
26750 /*
26751 * The sysexit path does not restore ds/es, so we must set them to
26752 * a reasonable value ourselves.
26753@@ -7113,8 +7140,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
26754 * may be executed in interrupt context, which saves and restore segments
26755 * around it, nullifying its effect.
26756 */
26757- loadsegment(ds, __USER_DS);
26758- loadsegment(es, __USER_DS);
26759+ loadsegment(ds, __KERNEL_DS);
26760+ loadsegment(es, __KERNEL_DS);
26761+ loadsegment(ss, __KERNEL_DS);
26762+
26763+#ifdef CONFIG_PAX_KERNEXEC
26764+ loadsegment(fs, __KERNEL_PERCPU);
26765+#endif
26766+
26767+#ifdef CONFIG_PAX_MEMORY_UDEREF
26768+ __set_fs(current_thread_info()->addr_limit);
26769+#endif
26770+
26771 #endif
26772
26773 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
26774diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
26775index d21bce5..fdae9f1 100644
26776--- a/arch/x86/kvm/x86.c
26777+++ b/arch/x86/kvm/x86.c
26778@@ -1766,8 +1766,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
26779 {
26780 struct kvm *kvm = vcpu->kvm;
26781 int lm = is_long_mode(vcpu);
26782- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
26783- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
26784+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
26785+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
26786 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
26787 : kvm->arch.xen_hvm_config.blob_size_32;
26788 u32 page_num = data & ~PAGE_MASK;
26789@@ -2650,6 +2650,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
26790 if (n < msr_list.nmsrs)
26791 goto out;
26792 r = -EFAULT;
26793+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
26794+ goto out;
26795 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
26796 num_msrs_to_save * sizeof(u32)))
26797 goto out;
26798@@ -5344,7 +5346,7 @@ static struct notifier_block pvclock_gtod_notifier = {
26799 };
26800 #endif
26801
26802-int kvm_arch_init(void *opaque)
26803+int kvm_arch_init(const void *opaque)
26804 {
26805 int r;
26806 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
26807diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
26808index 6a22c19..1763f04 100644
26809--- a/arch/x86/lguest/boot.c
26810+++ b/arch/x86/lguest/boot.c
26811@@ -1201,9 +1201,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
26812 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
26813 * Launcher to reboot us.
26814 */
26815-static void lguest_restart(char *reason)
26816+static __noreturn void lguest_restart(char *reason)
26817 {
26818 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
26819+ BUG();
26820 }
26821
26822 /*G:050
26823diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
26824index 00933d5..3a64af9 100644
26825--- a/arch/x86/lib/atomic64_386_32.S
26826+++ b/arch/x86/lib/atomic64_386_32.S
26827@@ -48,6 +48,10 @@ BEGIN(read)
26828 movl (v), %eax
26829 movl 4(v), %edx
26830 RET_ENDP
26831+BEGIN(read_unchecked)
26832+ movl (v), %eax
26833+ movl 4(v), %edx
26834+RET_ENDP
26835 #undef v
26836
26837 #define v %esi
26838@@ -55,6 +59,10 @@ BEGIN(set)
26839 movl %ebx, (v)
26840 movl %ecx, 4(v)
26841 RET_ENDP
26842+BEGIN(set_unchecked)
26843+ movl %ebx, (v)
26844+ movl %ecx, 4(v)
26845+RET_ENDP
26846 #undef v
26847
26848 #define v %esi
26849@@ -70,6 +78,20 @@ RET_ENDP
26850 BEGIN(add)
26851 addl %eax, (v)
26852 adcl %edx, 4(v)
26853+
26854+#ifdef CONFIG_PAX_REFCOUNT
26855+ jno 0f
26856+ subl %eax, (v)
26857+ sbbl %edx, 4(v)
26858+ int $4
26859+0:
26860+ _ASM_EXTABLE(0b, 0b)
26861+#endif
26862+
26863+RET_ENDP
26864+BEGIN(add_unchecked)
26865+ addl %eax, (v)
26866+ adcl %edx, 4(v)
26867 RET_ENDP
26868 #undef v
26869
26870@@ -77,6 +99,24 @@ RET_ENDP
26871 BEGIN(add_return)
26872 addl (v), %eax
26873 adcl 4(v), %edx
26874+
26875+#ifdef CONFIG_PAX_REFCOUNT
26876+ into
26877+1234:
26878+ _ASM_EXTABLE(1234b, 2f)
26879+#endif
26880+
26881+ movl %eax, (v)
26882+ movl %edx, 4(v)
26883+
26884+#ifdef CONFIG_PAX_REFCOUNT
26885+2:
26886+#endif
26887+
26888+RET_ENDP
26889+BEGIN(add_return_unchecked)
26890+ addl (v), %eax
26891+ adcl 4(v), %edx
26892 movl %eax, (v)
26893 movl %edx, 4(v)
26894 RET_ENDP
26895@@ -86,6 +126,20 @@ RET_ENDP
26896 BEGIN(sub)
26897 subl %eax, (v)
26898 sbbl %edx, 4(v)
26899+
26900+#ifdef CONFIG_PAX_REFCOUNT
26901+ jno 0f
26902+ addl %eax, (v)
26903+ adcl %edx, 4(v)
26904+ int $4
26905+0:
26906+ _ASM_EXTABLE(0b, 0b)
26907+#endif
26908+
26909+RET_ENDP
26910+BEGIN(sub_unchecked)
26911+ subl %eax, (v)
26912+ sbbl %edx, 4(v)
26913 RET_ENDP
26914 #undef v
26915
26916@@ -96,6 +150,27 @@ BEGIN(sub_return)
26917 sbbl $0, %edx
26918 addl (v), %eax
26919 adcl 4(v), %edx
26920+
26921+#ifdef CONFIG_PAX_REFCOUNT
26922+ into
26923+1234:
26924+ _ASM_EXTABLE(1234b, 2f)
26925+#endif
26926+
26927+ movl %eax, (v)
26928+ movl %edx, 4(v)
26929+
26930+#ifdef CONFIG_PAX_REFCOUNT
26931+2:
26932+#endif
26933+
26934+RET_ENDP
26935+BEGIN(sub_return_unchecked)
26936+ negl %edx
26937+ negl %eax
26938+ sbbl $0, %edx
26939+ addl (v), %eax
26940+ adcl 4(v), %edx
26941 movl %eax, (v)
26942 movl %edx, 4(v)
26943 RET_ENDP
26944@@ -105,6 +180,20 @@ RET_ENDP
26945 BEGIN(inc)
26946 addl $1, (v)
26947 adcl $0, 4(v)
26948+
26949+#ifdef CONFIG_PAX_REFCOUNT
26950+ jno 0f
26951+ subl $1, (v)
26952+ sbbl $0, 4(v)
26953+ int $4
26954+0:
26955+ _ASM_EXTABLE(0b, 0b)
26956+#endif
26957+
26958+RET_ENDP
26959+BEGIN(inc_unchecked)
26960+ addl $1, (v)
26961+ adcl $0, 4(v)
26962 RET_ENDP
26963 #undef v
26964
26965@@ -114,6 +203,26 @@ BEGIN(inc_return)
26966 movl 4(v), %edx
26967 addl $1, %eax
26968 adcl $0, %edx
26969+
26970+#ifdef CONFIG_PAX_REFCOUNT
26971+ into
26972+1234:
26973+ _ASM_EXTABLE(1234b, 2f)
26974+#endif
26975+
26976+ movl %eax, (v)
26977+ movl %edx, 4(v)
26978+
26979+#ifdef CONFIG_PAX_REFCOUNT
26980+2:
26981+#endif
26982+
26983+RET_ENDP
26984+BEGIN(inc_return_unchecked)
26985+ movl (v), %eax
26986+ movl 4(v), %edx
26987+ addl $1, %eax
26988+ adcl $0, %edx
26989 movl %eax, (v)
26990 movl %edx, 4(v)
26991 RET_ENDP
26992@@ -123,6 +232,20 @@ RET_ENDP
26993 BEGIN(dec)
26994 subl $1, (v)
26995 sbbl $0, 4(v)
26996+
26997+#ifdef CONFIG_PAX_REFCOUNT
26998+ jno 0f
26999+ addl $1, (v)
27000+ adcl $0, 4(v)
27001+ int $4
27002+0:
27003+ _ASM_EXTABLE(0b, 0b)
27004+#endif
27005+
27006+RET_ENDP
27007+BEGIN(dec_unchecked)
27008+ subl $1, (v)
27009+ sbbl $0, 4(v)
27010 RET_ENDP
27011 #undef v
27012
27013@@ -132,6 +255,26 @@ BEGIN(dec_return)
27014 movl 4(v), %edx
27015 subl $1, %eax
27016 sbbl $0, %edx
27017+
27018+#ifdef CONFIG_PAX_REFCOUNT
27019+ into
27020+1234:
27021+ _ASM_EXTABLE(1234b, 2f)
27022+#endif
27023+
27024+ movl %eax, (v)
27025+ movl %edx, 4(v)
27026+
27027+#ifdef CONFIG_PAX_REFCOUNT
27028+2:
27029+#endif
27030+
27031+RET_ENDP
27032+BEGIN(dec_return_unchecked)
27033+ movl (v), %eax
27034+ movl 4(v), %edx
27035+ subl $1, %eax
27036+ sbbl $0, %edx
27037 movl %eax, (v)
27038 movl %edx, 4(v)
27039 RET_ENDP
27040@@ -143,6 +286,13 @@ BEGIN(add_unless)
27041 adcl %edx, %edi
27042 addl (v), %eax
27043 adcl 4(v), %edx
27044+
27045+#ifdef CONFIG_PAX_REFCOUNT
27046+ into
27047+1234:
27048+ _ASM_EXTABLE(1234b, 2f)
27049+#endif
27050+
27051 cmpl %eax, %ecx
27052 je 3f
27053 1:
27054@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
27055 1:
27056 addl $1, %eax
27057 adcl $0, %edx
27058+
27059+#ifdef CONFIG_PAX_REFCOUNT
27060+ into
27061+1234:
27062+ _ASM_EXTABLE(1234b, 2f)
27063+#endif
27064+
27065 movl %eax, (v)
27066 movl %edx, 4(v)
27067 movl $1, %eax
27068@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
27069 movl 4(v), %edx
27070 subl $1, %eax
27071 sbbl $0, %edx
27072+
27073+#ifdef CONFIG_PAX_REFCOUNT
27074+ into
27075+1234:
27076+ _ASM_EXTABLE(1234b, 1f)
27077+#endif
27078+
27079 js 1f
27080 movl %eax, (v)
27081 movl %edx, 4(v)
27082diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
27083index f5cc9eb..51fa319 100644
27084--- a/arch/x86/lib/atomic64_cx8_32.S
27085+++ b/arch/x86/lib/atomic64_cx8_32.S
27086@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
27087 CFI_STARTPROC
27088
27089 read64 %ecx
27090+ pax_force_retaddr
27091 ret
27092 CFI_ENDPROC
27093 ENDPROC(atomic64_read_cx8)
27094
27095+ENTRY(atomic64_read_unchecked_cx8)
27096+ CFI_STARTPROC
27097+
27098+ read64 %ecx
27099+ pax_force_retaddr
27100+ ret
27101+ CFI_ENDPROC
27102+ENDPROC(atomic64_read_unchecked_cx8)
27103+
27104 ENTRY(atomic64_set_cx8)
27105 CFI_STARTPROC
27106
27107@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
27108 cmpxchg8b (%esi)
27109 jne 1b
27110
27111+ pax_force_retaddr
27112 ret
27113 CFI_ENDPROC
27114 ENDPROC(atomic64_set_cx8)
27115
27116+ENTRY(atomic64_set_unchecked_cx8)
27117+ CFI_STARTPROC
27118+
27119+1:
27120+/* we don't need LOCK_PREFIX since aligned 64-bit writes
27121+ * are atomic on 586 and newer */
27122+ cmpxchg8b (%esi)
27123+ jne 1b
27124+
27125+ pax_force_retaddr
27126+ ret
27127+ CFI_ENDPROC
27128+ENDPROC(atomic64_set_unchecked_cx8)
27129+
27130 ENTRY(atomic64_xchg_cx8)
27131 CFI_STARTPROC
27132
27133@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
27134 cmpxchg8b (%esi)
27135 jne 1b
27136
27137+ pax_force_retaddr
27138 ret
27139 CFI_ENDPROC
27140 ENDPROC(atomic64_xchg_cx8)
27141
27142-.macro addsub_return func ins insc
27143-ENTRY(atomic64_\func\()_return_cx8)
27144+.macro addsub_return func ins insc unchecked=""
27145+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
27146 CFI_STARTPROC
27147 SAVE ebp
27148 SAVE ebx
27149@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
27150 movl %edx, %ecx
27151 \ins\()l %esi, %ebx
27152 \insc\()l %edi, %ecx
27153+
27154+.ifb \unchecked
27155+#ifdef CONFIG_PAX_REFCOUNT
27156+ into
27157+2:
27158+ _ASM_EXTABLE(2b, 3f)
27159+#endif
27160+.endif
27161+
27162 LOCK_PREFIX
27163 cmpxchg8b (%ebp)
27164 jne 1b
27165-
27166-10:
27167 movl %ebx, %eax
27168 movl %ecx, %edx
27169+
27170+.ifb \unchecked
27171+#ifdef CONFIG_PAX_REFCOUNT
27172+3:
27173+#endif
27174+.endif
27175+
27176 RESTORE edi
27177 RESTORE esi
27178 RESTORE ebx
27179 RESTORE ebp
27180+ pax_force_retaddr
27181 ret
27182 CFI_ENDPROC
27183-ENDPROC(atomic64_\func\()_return_cx8)
27184+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
27185 .endm
27186
27187 addsub_return add add adc
27188 addsub_return sub sub sbb
27189+addsub_return add add adc _unchecked
27190+addsub_return sub sub sbb _unchecked
27191
27192-.macro incdec_return func ins insc
27193-ENTRY(atomic64_\func\()_return_cx8)
27194+.macro incdec_return func ins insc unchecked=""
27195+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
27196 CFI_STARTPROC
27197 SAVE ebx
27198
27199@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
27200 movl %edx, %ecx
27201 \ins\()l $1, %ebx
27202 \insc\()l $0, %ecx
27203+
27204+.ifb \unchecked
27205+#ifdef CONFIG_PAX_REFCOUNT
27206+ into
27207+2:
27208+ _ASM_EXTABLE(2b, 3f)
27209+#endif
27210+.endif
27211+
27212 LOCK_PREFIX
27213 cmpxchg8b (%esi)
27214 jne 1b
27215
27216-10:
27217 movl %ebx, %eax
27218 movl %ecx, %edx
27219+
27220+.ifb \unchecked
27221+#ifdef CONFIG_PAX_REFCOUNT
27222+3:
27223+#endif
27224+.endif
27225+
27226 RESTORE ebx
27227+ pax_force_retaddr
27228 ret
27229 CFI_ENDPROC
27230-ENDPROC(atomic64_\func\()_return_cx8)
27231+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
27232 .endm
27233
27234 incdec_return inc add adc
27235 incdec_return dec sub sbb
27236+incdec_return inc add adc _unchecked
27237+incdec_return dec sub sbb _unchecked
27238
27239 ENTRY(atomic64_dec_if_positive_cx8)
27240 CFI_STARTPROC
27241@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
27242 movl %edx, %ecx
27243 subl $1, %ebx
27244 sbb $0, %ecx
27245+
27246+#ifdef CONFIG_PAX_REFCOUNT
27247+ into
27248+1234:
27249+ _ASM_EXTABLE(1234b, 2f)
27250+#endif
27251+
27252 js 2f
27253 LOCK_PREFIX
27254 cmpxchg8b (%esi)
27255@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
27256 movl %ebx, %eax
27257 movl %ecx, %edx
27258 RESTORE ebx
27259+ pax_force_retaddr
27260 ret
27261 CFI_ENDPROC
27262 ENDPROC(atomic64_dec_if_positive_cx8)
27263@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
27264 movl %edx, %ecx
27265 addl %ebp, %ebx
27266 adcl %edi, %ecx
27267+
27268+#ifdef CONFIG_PAX_REFCOUNT
27269+ into
27270+1234:
27271+ _ASM_EXTABLE(1234b, 3f)
27272+#endif
27273+
27274 LOCK_PREFIX
27275 cmpxchg8b (%esi)
27276 jne 1b
27277@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
27278 CFI_ADJUST_CFA_OFFSET -8
27279 RESTORE ebx
27280 RESTORE ebp
27281+ pax_force_retaddr
27282 ret
27283 4:
27284 cmpl %edx, 4(%esp)
27285@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
27286 xorl %ecx, %ecx
27287 addl $1, %ebx
27288 adcl %edx, %ecx
27289+
27290+#ifdef CONFIG_PAX_REFCOUNT
27291+ into
27292+1234:
27293+ _ASM_EXTABLE(1234b, 3f)
27294+#endif
27295+
27296 LOCK_PREFIX
27297 cmpxchg8b (%esi)
27298 jne 1b
27299@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
27300 movl $1, %eax
27301 3:
27302 RESTORE ebx
27303+ pax_force_retaddr
27304 ret
27305 CFI_ENDPROC
27306 ENDPROC(atomic64_inc_not_zero_cx8)
27307diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
27308index e78b8ee..7e173a8 100644
27309--- a/arch/x86/lib/checksum_32.S
27310+++ b/arch/x86/lib/checksum_32.S
27311@@ -29,7 +29,8 @@
27312 #include <asm/dwarf2.h>
27313 #include <asm/errno.h>
27314 #include <asm/asm.h>
27315-
27316+#include <asm/segment.h>
27317+
27318 /*
27319 * computes a partial checksum, e.g. for TCP/UDP fragments
27320 */
27321@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
27322
27323 #define ARGBASE 16
27324 #define FP 12
27325-
27326-ENTRY(csum_partial_copy_generic)
27327+
27328+ENTRY(csum_partial_copy_generic_to_user)
27329 CFI_STARTPROC
27330+
27331+#ifdef CONFIG_PAX_MEMORY_UDEREF
27332+ pushl_cfi %gs
27333+ popl_cfi %es
27334+ jmp csum_partial_copy_generic
27335+#endif
27336+
27337+ENTRY(csum_partial_copy_generic_from_user)
27338+
27339+#ifdef CONFIG_PAX_MEMORY_UDEREF
27340+ pushl_cfi %gs
27341+ popl_cfi %ds
27342+#endif
27343+
27344+ENTRY(csum_partial_copy_generic)
27345 subl $4,%esp
27346 CFI_ADJUST_CFA_OFFSET 4
27347 pushl_cfi %edi
27348@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
27349 jmp 4f
27350 SRC(1: movw (%esi), %bx )
27351 addl $2, %esi
27352-DST( movw %bx, (%edi) )
27353+DST( movw %bx, %es:(%edi) )
27354 addl $2, %edi
27355 addw %bx, %ax
27356 adcl $0, %eax
27357@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
27358 SRC(1: movl (%esi), %ebx )
27359 SRC( movl 4(%esi), %edx )
27360 adcl %ebx, %eax
27361-DST( movl %ebx, (%edi) )
27362+DST( movl %ebx, %es:(%edi) )
27363 adcl %edx, %eax
27364-DST( movl %edx, 4(%edi) )
27365+DST( movl %edx, %es:4(%edi) )
27366
27367 SRC( movl 8(%esi), %ebx )
27368 SRC( movl 12(%esi), %edx )
27369 adcl %ebx, %eax
27370-DST( movl %ebx, 8(%edi) )
27371+DST( movl %ebx, %es:8(%edi) )
27372 adcl %edx, %eax
27373-DST( movl %edx, 12(%edi) )
27374+DST( movl %edx, %es:12(%edi) )
27375
27376 SRC( movl 16(%esi), %ebx )
27377 SRC( movl 20(%esi), %edx )
27378 adcl %ebx, %eax
27379-DST( movl %ebx, 16(%edi) )
27380+DST( movl %ebx, %es:16(%edi) )
27381 adcl %edx, %eax
27382-DST( movl %edx, 20(%edi) )
27383+DST( movl %edx, %es:20(%edi) )
27384
27385 SRC( movl 24(%esi), %ebx )
27386 SRC( movl 28(%esi), %edx )
27387 adcl %ebx, %eax
27388-DST( movl %ebx, 24(%edi) )
27389+DST( movl %ebx, %es:24(%edi) )
27390 adcl %edx, %eax
27391-DST( movl %edx, 28(%edi) )
27392+DST( movl %edx, %es:28(%edi) )
27393
27394 lea 32(%esi), %esi
27395 lea 32(%edi), %edi
27396@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
27397 shrl $2, %edx # This clears CF
27398 SRC(3: movl (%esi), %ebx )
27399 adcl %ebx, %eax
27400-DST( movl %ebx, (%edi) )
27401+DST( movl %ebx, %es:(%edi) )
27402 lea 4(%esi), %esi
27403 lea 4(%edi), %edi
27404 dec %edx
27405@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
27406 jb 5f
27407 SRC( movw (%esi), %cx )
27408 leal 2(%esi), %esi
27409-DST( movw %cx, (%edi) )
27410+DST( movw %cx, %es:(%edi) )
27411 leal 2(%edi), %edi
27412 je 6f
27413 shll $16,%ecx
27414 SRC(5: movb (%esi), %cl )
27415-DST( movb %cl, (%edi) )
27416+DST( movb %cl, %es:(%edi) )
27417 6: addl %ecx, %eax
27418 adcl $0, %eax
27419 7:
27420@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
27421
27422 6001:
27423 movl ARGBASE+20(%esp), %ebx # src_err_ptr
27424- movl $-EFAULT, (%ebx)
27425+ movl $-EFAULT, %ss:(%ebx)
27426
27427 # zero the complete destination - computing the rest
27428 # is too much work
27429@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
27430
27431 6002:
27432 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
27433- movl $-EFAULT,(%ebx)
27434+ movl $-EFAULT,%ss:(%ebx)
27435 jmp 5000b
27436
27437 .previous
27438
27439+ pushl_cfi %ss
27440+ popl_cfi %ds
27441+ pushl_cfi %ss
27442+ popl_cfi %es
27443 popl_cfi %ebx
27444 CFI_RESTORE ebx
27445 popl_cfi %esi
27446@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
27447 popl_cfi %ecx # equivalent to addl $4,%esp
27448 ret
27449 CFI_ENDPROC
27450-ENDPROC(csum_partial_copy_generic)
27451+ENDPROC(csum_partial_copy_generic_to_user)
27452
27453 #else
27454
27455 /* Version for PentiumII/PPro */
27456
27457 #define ROUND1(x) \
27458+ nop; nop; nop; \
27459 SRC(movl x(%esi), %ebx ) ; \
27460 addl %ebx, %eax ; \
27461- DST(movl %ebx, x(%edi) ) ;
27462+ DST(movl %ebx, %es:x(%edi)) ;
27463
27464 #define ROUND(x) \
27465+ nop; nop; nop; \
27466 SRC(movl x(%esi), %ebx ) ; \
27467 adcl %ebx, %eax ; \
27468- DST(movl %ebx, x(%edi) ) ;
27469+ DST(movl %ebx, %es:x(%edi)) ;
27470
27471 #define ARGBASE 12
27472-
27473-ENTRY(csum_partial_copy_generic)
27474+
27475+ENTRY(csum_partial_copy_generic_to_user)
27476 CFI_STARTPROC
27477+
27478+#ifdef CONFIG_PAX_MEMORY_UDEREF
27479+ pushl_cfi %gs
27480+ popl_cfi %es
27481+ jmp csum_partial_copy_generic
27482+#endif
27483+
27484+ENTRY(csum_partial_copy_generic_from_user)
27485+
27486+#ifdef CONFIG_PAX_MEMORY_UDEREF
27487+ pushl_cfi %gs
27488+ popl_cfi %ds
27489+#endif
27490+
27491+ENTRY(csum_partial_copy_generic)
27492 pushl_cfi %ebx
27493 CFI_REL_OFFSET ebx, 0
27494 pushl_cfi %edi
27495@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
27496 subl %ebx, %edi
27497 lea -1(%esi),%edx
27498 andl $-32,%edx
27499- lea 3f(%ebx,%ebx), %ebx
27500+ lea 3f(%ebx,%ebx,2), %ebx
27501 testl %esi, %esi
27502 jmp *%ebx
27503 1: addl $64,%esi
27504@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
27505 jb 5f
27506 SRC( movw (%esi), %dx )
27507 leal 2(%esi), %esi
27508-DST( movw %dx, (%edi) )
27509+DST( movw %dx, %es:(%edi) )
27510 leal 2(%edi), %edi
27511 je 6f
27512 shll $16,%edx
27513 5:
27514 SRC( movb (%esi), %dl )
27515-DST( movb %dl, (%edi) )
27516+DST( movb %dl, %es:(%edi) )
27517 6: addl %edx, %eax
27518 adcl $0, %eax
27519 7:
27520 .section .fixup, "ax"
27521 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
27522- movl $-EFAULT, (%ebx)
27523+ movl $-EFAULT, %ss:(%ebx)
27524 # zero the complete destination (computing the rest is too much work)
27525 movl ARGBASE+8(%esp),%edi # dst
27526 movl ARGBASE+12(%esp),%ecx # len
27527@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
27528 rep; stosb
27529 jmp 7b
27530 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
27531- movl $-EFAULT, (%ebx)
27532+ movl $-EFAULT, %ss:(%ebx)
27533 jmp 7b
27534 .previous
27535
27536+#ifdef CONFIG_PAX_MEMORY_UDEREF
27537+ pushl_cfi %ss
27538+ popl_cfi %ds
27539+ pushl_cfi %ss
27540+ popl_cfi %es
27541+#endif
27542+
27543 popl_cfi %esi
27544 CFI_RESTORE esi
27545 popl_cfi %edi
27546@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
27547 CFI_RESTORE ebx
27548 ret
27549 CFI_ENDPROC
27550-ENDPROC(csum_partial_copy_generic)
27551+ENDPROC(csum_partial_copy_generic_to_user)
27552
27553 #undef ROUND
27554 #undef ROUND1
27555diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
27556index f2145cf..cea889d 100644
27557--- a/arch/x86/lib/clear_page_64.S
27558+++ b/arch/x86/lib/clear_page_64.S
27559@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
27560 movl $4096/8,%ecx
27561 xorl %eax,%eax
27562 rep stosq
27563+ pax_force_retaddr
27564 ret
27565 CFI_ENDPROC
27566 ENDPROC(clear_page_c)
27567@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
27568 movl $4096,%ecx
27569 xorl %eax,%eax
27570 rep stosb
27571+ pax_force_retaddr
27572 ret
27573 CFI_ENDPROC
27574 ENDPROC(clear_page_c_e)
27575@@ -43,6 +45,7 @@ ENTRY(clear_page)
27576 leaq 64(%rdi),%rdi
27577 jnz .Lloop
27578 nop
27579+ pax_force_retaddr
27580 ret
27581 CFI_ENDPROC
27582 .Lclear_page_end:
27583@@ -58,7 +61,7 @@ ENDPROC(clear_page)
27584
27585 #include <asm/cpufeature.h>
27586
27587- .section .altinstr_replacement,"ax"
27588+ .section .altinstr_replacement,"a"
27589 1: .byte 0xeb /* jmp <disp8> */
27590 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
27591 2: .byte 0xeb /* jmp <disp8> */
27592diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
27593index 1e572c5..2a162cd 100644
27594--- a/arch/x86/lib/cmpxchg16b_emu.S
27595+++ b/arch/x86/lib/cmpxchg16b_emu.S
27596@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
27597
27598 popf
27599 mov $1, %al
27600+ pax_force_retaddr
27601 ret
27602
27603 not_same:
27604 popf
27605 xor %al,%al
27606+ pax_force_retaddr
27607 ret
27608
27609 CFI_ENDPROC
27610diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
27611index 176cca6..1166c50 100644
27612--- a/arch/x86/lib/copy_page_64.S
27613+++ b/arch/x86/lib/copy_page_64.S
27614@@ -9,6 +9,7 @@ copy_page_rep:
27615 CFI_STARTPROC
27616 movl $4096/8, %ecx
27617 rep movsq
27618+ pax_force_retaddr
27619 ret
27620 CFI_ENDPROC
27621 ENDPROC(copy_page_rep)
27622@@ -20,12 +21,14 @@ ENDPROC(copy_page_rep)
27623
27624 ENTRY(copy_page)
27625 CFI_STARTPROC
27626- subq $2*8, %rsp
27627- CFI_ADJUST_CFA_OFFSET 2*8
27628+ subq $3*8, %rsp
27629+ CFI_ADJUST_CFA_OFFSET 3*8
27630 movq %rbx, (%rsp)
27631 CFI_REL_OFFSET rbx, 0
27632 movq %r12, 1*8(%rsp)
27633 CFI_REL_OFFSET r12, 1*8
27634+ movq %r13, 2*8(%rsp)
27635+ CFI_REL_OFFSET r13, 2*8
27636
27637 movl $(4096/64)-5, %ecx
27638 .p2align 4
27639@@ -36,7 +39,7 @@ ENTRY(copy_page)
27640 movq 0x8*2(%rsi), %rdx
27641 movq 0x8*3(%rsi), %r8
27642 movq 0x8*4(%rsi), %r9
27643- movq 0x8*5(%rsi), %r10
27644+ movq 0x8*5(%rsi), %r13
27645 movq 0x8*6(%rsi), %r11
27646 movq 0x8*7(%rsi), %r12
27647
27648@@ -47,7 +50,7 @@ ENTRY(copy_page)
27649 movq %rdx, 0x8*2(%rdi)
27650 movq %r8, 0x8*3(%rdi)
27651 movq %r9, 0x8*4(%rdi)
27652- movq %r10, 0x8*5(%rdi)
27653+ movq %r13, 0x8*5(%rdi)
27654 movq %r11, 0x8*6(%rdi)
27655 movq %r12, 0x8*7(%rdi)
27656
27657@@ -66,7 +69,7 @@ ENTRY(copy_page)
27658 movq 0x8*2(%rsi), %rdx
27659 movq 0x8*3(%rsi), %r8
27660 movq 0x8*4(%rsi), %r9
27661- movq 0x8*5(%rsi), %r10
27662+ movq 0x8*5(%rsi), %r13
27663 movq 0x8*6(%rsi), %r11
27664 movq 0x8*7(%rsi), %r12
27665
27666@@ -75,7 +78,7 @@ ENTRY(copy_page)
27667 movq %rdx, 0x8*2(%rdi)
27668 movq %r8, 0x8*3(%rdi)
27669 movq %r9, 0x8*4(%rdi)
27670- movq %r10, 0x8*5(%rdi)
27671+ movq %r13, 0x8*5(%rdi)
27672 movq %r11, 0x8*6(%rdi)
27673 movq %r12, 0x8*7(%rdi)
27674
27675@@ -87,8 +90,11 @@ ENTRY(copy_page)
27676 CFI_RESTORE rbx
27677 movq 1*8(%rsp), %r12
27678 CFI_RESTORE r12
27679- addq $2*8, %rsp
27680- CFI_ADJUST_CFA_OFFSET -2*8
27681+ movq 2*8(%rsp), %r13
27682+ CFI_RESTORE r13
27683+ addq $3*8, %rsp
27684+ CFI_ADJUST_CFA_OFFSET -3*8
27685+ pax_force_retaddr
27686 ret
27687 .Lcopy_page_end:
27688 CFI_ENDPROC
27689@@ -99,7 +105,7 @@ ENDPROC(copy_page)
27690
27691 #include <asm/cpufeature.h>
27692
27693- .section .altinstr_replacement,"ax"
27694+ .section .altinstr_replacement,"a"
27695 1: .byte 0xeb /* jmp <disp8> */
27696 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
27697 2:
27698diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
27699index a30ca15..6b3f4e1 100644
27700--- a/arch/x86/lib/copy_user_64.S
27701+++ b/arch/x86/lib/copy_user_64.S
27702@@ -18,31 +18,7 @@
27703 #include <asm/alternative-asm.h>
27704 #include <asm/asm.h>
27705 #include <asm/smap.h>
27706-
27707-/*
27708- * By placing feature2 after feature1 in altinstructions section, we logically
27709- * implement:
27710- * If CPU has feature2, jmp to alt2 is used
27711- * else if CPU has feature1, jmp to alt1 is used
27712- * else jmp to orig is used.
27713- */
27714- .macro ALTERNATIVE_JUMP feature1,feature2,orig,alt1,alt2
27715-0:
27716- .byte 0xe9 /* 32bit jump */
27717- .long \orig-1f /* by default jump to orig */
27718-1:
27719- .section .altinstr_replacement,"ax"
27720-2: .byte 0xe9 /* near jump with 32bit immediate */
27721- .long \alt1-1b /* offset */ /* or alternatively to alt1 */
27722-3: .byte 0xe9 /* near jump with 32bit immediate */
27723- .long \alt2-1b /* offset */ /* or alternatively to alt2 */
27724- .previous
27725-
27726- .section .altinstructions,"a"
27727- altinstruction_entry 0b,2b,\feature1,5,5
27728- altinstruction_entry 0b,3b,\feature2,5,5
27729- .previous
27730- .endm
27731+#include <asm/pgtable.h>
27732
27733 .macro ALIGN_DESTINATION
27734 #ifdef FIX_ALIGNMENT
27735@@ -70,52 +46,6 @@
27736 #endif
27737 .endm
27738
27739-/* Standard copy_to_user with segment limit checking */
27740-ENTRY(_copy_to_user)
27741- CFI_STARTPROC
27742- GET_THREAD_INFO(%rax)
27743- movq %rdi,%rcx
27744- addq %rdx,%rcx
27745- jc bad_to_user
27746- cmpq TI_addr_limit(%rax),%rcx
27747- ja bad_to_user
27748- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
27749- copy_user_generic_unrolled,copy_user_generic_string, \
27750- copy_user_enhanced_fast_string
27751- CFI_ENDPROC
27752-ENDPROC(_copy_to_user)
27753-
27754-/* Standard copy_from_user with segment limit checking */
27755-ENTRY(_copy_from_user)
27756- CFI_STARTPROC
27757- GET_THREAD_INFO(%rax)
27758- movq %rsi,%rcx
27759- addq %rdx,%rcx
27760- jc bad_from_user
27761- cmpq TI_addr_limit(%rax),%rcx
27762- ja bad_from_user
27763- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
27764- copy_user_generic_unrolled,copy_user_generic_string, \
27765- copy_user_enhanced_fast_string
27766- CFI_ENDPROC
27767-ENDPROC(_copy_from_user)
27768-
27769- .section .fixup,"ax"
27770- /* must zero dest */
27771-ENTRY(bad_from_user)
27772-bad_from_user:
27773- CFI_STARTPROC
27774- movl %edx,%ecx
27775- xorl %eax,%eax
27776- rep
27777- stosb
27778-bad_to_user:
27779- movl %edx,%eax
27780- ret
27781- CFI_ENDPROC
27782-ENDPROC(bad_from_user)
27783- .previous
27784-
27785 /*
27786 * copy_user_generic_unrolled - memory copy with exception handling.
27787 * This version is for CPUs like P4 that don't have efficient micro
27788@@ -131,6 +61,7 @@ ENDPROC(bad_from_user)
27789 */
27790 ENTRY(copy_user_generic_unrolled)
27791 CFI_STARTPROC
27792+ ASM_PAX_OPEN_USERLAND
27793 ASM_STAC
27794 cmpl $8,%edx
27795 jb 20f /* less then 8 bytes, go to byte copy loop */
27796@@ -141,19 +72,19 @@ ENTRY(copy_user_generic_unrolled)
27797 jz 17f
27798 1: movq (%rsi),%r8
27799 2: movq 1*8(%rsi),%r9
27800-3: movq 2*8(%rsi),%r10
27801+3: movq 2*8(%rsi),%rax
27802 4: movq 3*8(%rsi),%r11
27803 5: movq %r8,(%rdi)
27804 6: movq %r9,1*8(%rdi)
27805-7: movq %r10,2*8(%rdi)
27806+7: movq %rax,2*8(%rdi)
27807 8: movq %r11,3*8(%rdi)
27808 9: movq 4*8(%rsi),%r8
27809 10: movq 5*8(%rsi),%r9
27810-11: movq 6*8(%rsi),%r10
27811+11: movq 6*8(%rsi),%rax
27812 12: movq 7*8(%rsi),%r11
27813 13: movq %r8,4*8(%rdi)
27814 14: movq %r9,5*8(%rdi)
27815-15: movq %r10,6*8(%rdi)
27816+15: movq %rax,6*8(%rdi)
27817 16: movq %r11,7*8(%rdi)
27818 leaq 64(%rsi),%rsi
27819 leaq 64(%rdi),%rdi
27820@@ -180,6 +111,8 @@ ENTRY(copy_user_generic_unrolled)
27821 jnz 21b
27822 23: xor %eax,%eax
27823 ASM_CLAC
27824+ ASM_PAX_CLOSE_USERLAND
27825+ pax_force_retaddr
27826 ret
27827
27828 .section .fixup,"ax"
27829@@ -235,6 +168,7 @@ ENDPROC(copy_user_generic_unrolled)
27830 */
27831 ENTRY(copy_user_generic_string)
27832 CFI_STARTPROC
27833+ ASM_PAX_OPEN_USERLAND
27834 ASM_STAC
27835 andl %edx,%edx
27836 jz 4f
27837@@ -251,6 +185,8 @@ ENTRY(copy_user_generic_string)
27838 movsb
27839 4: xorl %eax,%eax
27840 ASM_CLAC
27841+ ASM_PAX_CLOSE_USERLAND
27842+ pax_force_retaddr
27843 ret
27844
27845 .section .fixup,"ax"
27846@@ -278,6 +214,7 @@ ENDPROC(copy_user_generic_string)
27847 */
27848 ENTRY(copy_user_enhanced_fast_string)
27849 CFI_STARTPROC
27850+ ASM_PAX_OPEN_USERLAND
27851 ASM_STAC
27852 andl %edx,%edx
27853 jz 2f
27854@@ -286,6 +223,8 @@ ENTRY(copy_user_enhanced_fast_string)
27855 movsb
27856 2: xorl %eax,%eax
27857 ASM_CLAC
27858+ ASM_PAX_CLOSE_USERLAND
27859+ pax_force_retaddr
27860 ret
27861
27862 .section .fixup,"ax"
27863diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
27864index 6a4f43c..55d26f2 100644
27865--- a/arch/x86/lib/copy_user_nocache_64.S
27866+++ b/arch/x86/lib/copy_user_nocache_64.S
27867@@ -8,6 +8,7 @@
27868
27869 #include <linux/linkage.h>
27870 #include <asm/dwarf2.h>
27871+#include <asm/alternative-asm.h>
27872
27873 #define FIX_ALIGNMENT 1
27874
27875@@ -16,6 +17,7 @@
27876 #include <asm/thread_info.h>
27877 #include <asm/asm.h>
27878 #include <asm/smap.h>
27879+#include <asm/pgtable.h>
27880
27881 .macro ALIGN_DESTINATION
27882 #ifdef FIX_ALIGNMENT
27883@@ -49,6 +51,16 @@
27884 */
27885 ENTRY(__copy_user_nocache)
27886 CFI_STARTPROC
27887+
27888+#ifdef CONFIG_PAX_MEMORY_UDEREF
27889+ mov pax_user_shadow_base,%rcx
27890+ cmp %rcx,%rsi
27891+ jae 1f
27892+ add %rcx,%rsi
27893+1:
27894+#endif
27895+
27896+ ASM_PAX_OPEN_USERLAND
27897 ASM_STAC
27898 cmpl $8,%edx
27899 jb 20f /* less then 8 bytes, go to byte copy loop */
27900@@ -59,19 +71,19 @@ ENTRY(__copy_user_nocache)
27901 jz 17f
27902 1: movq (%rsi),%r8
27903 2: movq 1*8(%rsi),%r9
27904-3: movq 2*8(%rsi),%r10
27905+3: movq 2*8(%rsi),%rax
27906 4: movq 3*8(%rsi),%r11
27907 5: movnti %r8,(%rdi)
27908 6: movnti %r9,1*8(%rdi)
27909-7: movnti %r10,2*8(%rdi)
27910+7: movnti %rax,2*8(%rdi)
27911 8: movnti %r11,3*8(%rdi)
27912 9: movq 4*8(%rsi),%r8
27913 10: movq 5*8(%rsi),%r9
27914-11: movq 6*8(%rsi),%r10
27915+11: movq 6*8(%rsi),%rax
27916 12: movq 7*8(%rsi),%r11
27917 13: movnti %r8,4*8(%rdi)
27918 14: movnti %r9,5*8(%rdi)
27919-15: movnti %r10,6*8(%rdi)
27920+15: movnti %rax,6*8(%rdi)
27921 16: movnti %r11,7*8(%rdi)
27922 leaq 64(%rsi),%rsi
27923 leaq 64(%rdi),%rdi
27924@@ -98,7 +110,9 @@ ENTRY(__copy_user_nocache)
27925 jnz 21b
27926 23: xorl %eax,%eax
27927 ASM_CLAC
27928+ ASM_PAX_CLOSE_USERLAND
27929 sfence
27930+ pax_force_retaddr
27931 ret
27932
27933 .section .fixup,"ax"
27934diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
27935index 2419d5f..953ee51 100644
27936--- a/arch/x86/lib/csum-copy_64.S
27937+++ b/arch/x86/lib/csum-copy_64.S
27938@@ -9,6 +9,7 @@
27939 #include <asm/dwarf2.h>
27940 #include <asm/errno.h>
27941 #include <asm/asm.h>
27942+#include <asm/alternative-asm.h>
27943
27944 /*
27945 * Checksum copy with exception handling.
27946@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
27947 CFI_RESTORE rbp
27948 addq $7*8, %rsp
27949 CFI_ADJUST_CFA_OFFSET -7*8
27950+ pax_force_retaddr 0, 1
27951 ret
27952 CFI_RESTORE_STATE
27953
27954diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
27955index 7609e0e..b449b98 100644
27956--- a/arch/x86/lib/csum-wrappers_64.c
27957+++ b/arch/x86/lib/csum-wrappers_64.c
27958@@ -53,10 +53,12 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
27959 len -= 2;
27960 }
27961 }
27962+ pax_open_userland();
27963 stac();
27964- isum = csum_partial_copy_generic((__force const void *)src,
27965+ isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
27966 dst, len, isum, errp, NULL);
27967 clac();
27968+ pax_close_userland();
27969 if (unlikely(*errp))
27970 goto out_err;
27971
27972@@ -110,10 +112,12 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
27973 }
27974
27975 *errp = 0;
27976+ pax_open_userland();
27977 stac();
27978- ret = csum_partial_copy_generic(src, (void __force *)dst,
27979+ ret = csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
27980 len, isum, NULL, errp);
27981 clac();
27982+ pax_close_userland();
27983 return ret;
27984 }
27985 EXPORT_SYMBOL(csum_partial_copy_to_user);
27986diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
27987index a451235..1daa956 100644
27988--- a/arch/x86/lib/getuser.S
27989+++ b/arch/x86/lib/getuser.S
27990@@ -33,17 +33,40 @@
27991 #include <asm/thread_info.h>
27992 #include <asm/asm.h>
27993 #include <asm/smap.h>
27994+#include <asm/segment.h>
27995+#include <asm/pgtable.h>
27996+#include <asm/alternative-asm.h>
27997+
27998+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
27999+#define __copyuser_seg gs;
28000+#else
28001+#define __copyuser_seg
28002+#endif
28003
28004 .text
28005 ENTRY(__get_user_1)
28006 CFI_STARTPROC
28007+
28008+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28009 GET_THREAD_INFO(%_ASM_DX)
28010 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
28011 jae bad_get_user
28012 ASM_STAC
28013-1: movzbl (%_ASM_AX),%edx
28014+
28015+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28016+ mov pax_user_shadow_base,%_ASM_DX
28017+ cmp %_ASM_DX,%_ASM_AX
28018+ jae 1234f
28019+ add %_ASM_DX,%_ASM_AX
28020+1234:
28021+#endif
28022+
28023+#endif
28024+
28025+1: __copyuser_seg movzbl (%_ASM_AX),%edx
28026 xor %eax,%eax
28027 ASM_CLAC
28028+ pax_force_retaddr
28029 ret
28030 CFI_ENDPROC
28031 ENDPROC(__get_user_1)
28032@@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
28033 ENTRY(__get_user_2)
28034 CFI_STARTPROC
28035 add $1,%_ASM_AX
28036+
28037+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28038 jc bad_get_user
28039 GET_THREAD_INFO(%_ASM_DX)
28040 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
28041 jae bad_get_user
28042 ASM_STAC
28043-2: movzwl -1(%_ASM_AX),%edx
28044+
28045+#if defined(CONFIG_X86_64) && defined(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+#endif
28054+
28055+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
28056 xor %eax,%eax
28057 ASM_CLAC
28058+ pax_force_retaddr
28059 ret
28060 CFI_ENDPROC
28061 ENDPROC(__get_user_2)
28062@@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
28063 ENTRY(__get_user_4)
28064 CFI_STARTPROC
28065 add $3,%_ASM_AX
28066+
28067+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28068 jc bad_get_user
28069 GET_THREAD_INFO(%_ASM_DX)
28070 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
28071 jae bad_get_user
28072 ASM_STAC
28073-3: movl -3(%_ASM_AX),%edx
28074+
28075+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28076+ mov pax_user_shadow_base,%_ASM_DX
28077+ cmp %_ASM_DX,%_ASM_AX
28078+ jae 1234f
28079+ add %_ASM_DX,%_ASM_AX
28080+1234:
28081+#endif
28082+
28083+#endif
28084+
28085+3: __copyuser_seg movl -3(%_ASM_AX),%edx
28086 xor %eax,%eax
28087 ASM_CLAC
28088+ pax_force_retaddr
28089 ret
28090 CFI_ENDPROC
28091 ENDPROC(__get_user_4)
28092@@ -86,10 +137,20 @@ ENTRY(__get_user_8)
28093 GET_THREAD_INFO(%_ASM_DX)
28094 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
28095 jae bad_get_user
28096+
28097+#ifdef CONFIG_PAX_MEMORY_UDEREF
28098+ mov pax_user_shadow_base,%_ASM_DX
28099+ cmp %_ASM_DX,%_ASM_AX
28100+ jae 1234f
28101+ add %_ASM_DX,%_ASM_AX
28102+1234:
28103+#endif
28104+
28105 ASM_STAC
28106 4: movq -7(%_ASM_AX),%rdx
28107 xor %eax,%eax
28108 ASM_CLAC
28109+ pax_force_retaddr
28110 ret
28111 #else
28112 add $7,%_ASM_AX
28113@@ -98,10 +159,11 @@ ENTRY(__get_user_8)
28114 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
28115 jae bad_get_user_8
28116 ASM_STAC
28117-4: movl -7(%_ASM_AX),%edx
28118-5: movl -3(%_ASM_AX),%ecx
28119+4: __copyuser_seg movl -7(%_ASM_AX),%edx
28120+5: __copyuser_seg movl -3(%_ASM_AX),%ecx
28121 xor %eax,%eax
28122 ASM_CLAC
28123+ pax_force_retaddr
28124 ret
28125 #endif
28126 CFI_ENDPROC
28127@@ -113,6 +175,7 @@ bad_get_user:
28128 xor %edx,%edx
28129 mov $(-EFAULT),%_ASM_AX
28130 ASM_CLAC
28131+ pax_force_retaddr
28132 ret
28133 CFI_ENDPROC
28134 END(bad_get_user)
28135@@ -124,6 +187,7 @@ bad_get_user_8:
28136 xor %ecx,%ecx
28137 mov $(-EFAULT),%_ASM_AX
28138 ASM_CLAC
28139+ pax_force_retaddr
28140 ret
28141 CFI_ENDPROC
28142 END(bad_get_user_8)
28143diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
28144index 54fcffe..7be149e 100644
28145--- a/arch/x86/lib/insn.c
28146+++ b/arch/x86/lib/insn.c
28147@@ -20,8 +20,10 @@
28148
28149 #ifdef __KERNEL__
28150 #include <linux/string.h>
28151+#include <asm/pgtable_types.h>
28152 #else
28153 #include <string.h>
28154+#define ktla_ktva(addr) addr
28155 #endif
28156 #include <asm/inat.h>
28157 #include <asm/insn.h>
28158@@ -53,8 +55,8 @@
28159 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
28160 {
28161 memset(insn, 0, sizeof(*insn));
28162- insn->kaddr = kaddr;
28163- insn->next_byte = kaddr;
28164+ insn->kaddr = ktla_ktva(kaddr);
28165+ insn->next_byte = ktla_ktva(kaddr);
28166 insn->x86_64 = x86_64 ? 1 : 0;
28167 insn->opnd_bytes = 4;
28168 if (x86_64)
28169diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
28170index 05a95e7..326f2fa 100644
28171--- a/arch/x86/lib/iomap_copy_64.S
28172+++ b/arch/x86/lib/iomap_copy_64.S
28173@@ -17,6 +17,7 @@
28174
28175 #include <linux/linkage.h>
28176 #include <asm/dwarf2.h>
28177+#include <asm/alternative-asm.h>
28178
28179 /*
28180 * override generic version in lib/iomap_copy.c
28181@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
28182 CFI_STARTPROC
28183 movl %edx,%ecx
28184 rep movsd
28185+ pax_force_retaddr
28186 ret
28187 CFI_ENDPROC
28188 ENDPROC(__iowrite32_copy)
28189diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
28190index 56313a3..9b59269 100644
28191--- a/arch/x86/lib/memcpy_64.S
28192+++ b/arch/x86/lib/memcpy_64.S
28193@@ -24,7 +24,7 @@
28194 * This gets patched over the unrolled variant (below) via the
28195 * alternative instructions framework:
28196 */
28197- .section .altinstr_replacement, "ax", @progbits
28198+ .section .altinstr_replacement, "a", @progbits
28199 .Lmemcpy_c:
28200 movq %rdi, %rax
28201 movq %rdx, %rcx
28202@@ -33,6 +33,7 @@
28203 rep movsq
28204 movl %edx, %ecx
28205 rep movsb
28206+ pax_force_retaddr
28207 ret
28208 .Lmemcpy_e:
28209 .previous
28210@@ -44,11 +45,12 @@
28211 * This gets patched over the unrolled variant (below) via the
28212 * alternative instructions framework:
28213 */
28214- .section .altinstr_replacement, "ax", @progbits
28215+ .section .altinstr_replacement, "a", @progbits
28216 .Lmemcpy_c_e:
28217 movq %rdi, %rax
28218 movq %rdx, %rcx
28219 rep movsb
28220+ pax_force_retaddr
28221 ret
28222 .Lmemcpy_e_e:
28223 .previous
28224@@ -76,13 +78,13 @@ ENTRY(memcpy)
28225 */
28226 movq 0*8(%rsi), %r8
28227 movq 1*8(%rsi), %r9
28228- movq 2*8(%rsi), %r10
28229+ movq 2*8(%rsi), %rcx
28230 movq 3*8(%rsi), %r11
28231 leaq 4*8(%rsi), %rsi
28232
28233 movq %r8, 0*8(%rdi)
28234 movq %r9, 1*8(%rdi)
28235- movq %r10, 2*8(%rdi)
28236+ movq %rcx, 2*8(%rdi)
28237 movq %r11, 3*8(%rdi)
28238 leaq 4*8(%rdi), %rdi
28239 jae .Lcopy_forward_loop
28240@@ -105,12 +107,12 @@ ENTRY(memcpy)
28241 subq $0x20, %rdx
28242 movq -1*8(%rsi), %r8
28243 movq -2*8(%rsi), %r9
28244- movq -3*8(%rsi), %r10
28245+ movq -3*8(%rsi), %rcx
28246 movq -4*8(%rsi), %r11
28247 leaq -4*8(%rsi), %rsi
28248 movq %r8, -1*8(%rdi)
28249 movq %r9, -2*8(%rdi)
28250- movq %r10, -3*8(%rdi)
28251+ movq %rcx, -3*8(%rdi)
28252 movq %r11, -4*8(%rdi)
28253 leaq -4*8(%rdi), %rdi
28254 jae .Lcopy_backward_loop
28255@@ -130,12 +132,13 @@ ENTRY(memcpy)
28256 */
28257 movq 0*8(%rsi), %r8
28258 movq 1*8(%rsi), %r9
28259- movq -2*8(%rsi, %rdx), %r10
28260+ movq -2*8(%rsi, %rdx), %rcx
28261 movq -1*8(%rsi, %rdx), %r11
28262 movq %r8, 0*8(%rdi)
28263 movq %r9, 1*8(%rdi)
28264- movq %r10, -2*8(%rdi, %rdx)
28265+ movq %rcx, -2*8(%rdi, %rdx)
28266 movq %r11, -1*8(%rdi, %rdx)
28267+ pax_force_retaddr
28268 retq
28269 .p2align 4
28270 .Lless_16bytes:
28271@@ -148,6 +151,7 @@ ENTRY(memcpy)
28272 movq -1*8(%rsi, %rdx), %r9
28273 movq %r8, 0*8(%rdi)
28274 movq %r9, -1*8(%rdi, %rdx)
28275+ pax_force_retaddr
28276 retq
28277 .p2align 4
28278 .Lless_8bytes:
28279@@ -161,6 +165,7 @@ ENTRY(memcpy)
28280 movl -4(%rsi, %rdx), %r8d
28281 movl %ecx, (%rdi)
28282 movl %r8d, -4(%rdi, %rdx)
28283+ pax_force_retaddr
28284 retq
28285 .p2align 4
28286 .Lless_3bytes:
28287@@ -179,6 +184,7 @@ ENTRY(memcpy)
28288 movb %cl, (%rdi)
28289
28290 .Lend:
28291+ pax_force_retaddr
28292 retq
28293 CFI_ENDPROC
28294 ENDPROC(memcpy)
28295diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
28296index 65268a6..5aa7815 100644
28297--- a/arch/x86/lib/memmove_64.S
28298+++ b/arch/x86/lib/memmove_64.S
28299@@ -61,13 +61,13 @@ ENTRY(memmove)
28300 5:
28301 sub $0x20, %rdx
28302 movq 0*8(%rsi), %r11
28303- movq 1*8(%rsi), %r10
28304+ movq 1*8(%rsi), %rcx
28305 movq 2*8(%rsi), %r9
28306 movq 3*8(%rsi), %r8
28307 leaq 4*8(%rsi), %rsi
28308
28309 movq %r11, 0*8(%rdi)
28310- movq %r10, 1*8(%rdi)
28311+ movq %rcx, 1*8(%rdi)
28312 movq %r9, 2*8(%rdi)
28313 movq %r8, 3*8(%rdi)
28314 leaq 4*8(%rdi), %rdi
28315@@ -81,10 +81,10 @@ ENTRY(memmove)
28316 4:
28317 movq %rdx, %rcx
28318 movq -8(%rsi, %rdx), %r11
28319- lea -8(%rdi, %rdx), %r10
28320+ lea -8(%rdi, %rdx), %r9
28321 shrq $3, %rcx
28322 rep movsq
28323- movq %r11, (%r10)
28324+ movq %r11, (%r9)
28325 jmp 13f
28326 .Lmemmove_end_forward:
28327
28328@@ -95,14 +95,14 @@ ENTRY(memmove)
28329 7:
28330 movq %rdx, %rcx
28331 movq (%rsi), %r11
28332- movq %rdi, %r10
28333+ movq %rdi, %r9
28334 leaq -8(%rsi, %rdx), %rsi
28335 leaq -8(%rdi, %rdx), %rdi
28336 shrq $3, %rcx
28337 std
28338 rep movsq
28339 cld
28340- movq %r11, (%r10)
28341+ movq %r11, (%r9)
28342 jmp 13f
28343
28344 /*
28345@@ -127,13 +127,13 @@ ENTRY(memmove)
28346 8:
28347 subq $0x20, %rdx
28348 movq -1*8(%rsi), %r11
28349- movq -2*8(%rsi), %r10
28350+ movq -2*8(%rsi), %rcx
28351 movq -3*8(%rsi), %r9
28352 movq -4*8(%rsi), %r8
28353 leaq -4*8(%rsi), %rsi
28354
28355 movq %r11, -1*8(%rdi)
28356- movq %r10, -2*8(%rdi)
28357+ movq %rcx, -2*8(%rdi)
28358 movq %r9, -3*8(%rdi)
28359 movq %r8, -4*8(%rdi)
28360 leaq -4*8(%rdi), %rdi
28361@@ -151,11 +151,11 @@ ENTRY(memmove)
28362 * Move data from 16 bytes to 31 bytes.
28363 */
28364 movq 0*8(%rsi), %r11
28365- movq 1*8(%rsi), %r10
28366+ movq 1*8(%rsi), %rcx
28367 movq -2*8(%rsi, %rdx), %r9
28368 movq -1*8(%rsi, %rdx), %r8
28369 movq %r11, 0*8(%rdi)
28370- movq %r10, 1*8(%rdi)
28371+ movq %rcx, 1*8(%rdi)
28372 movq %r9, -2*8(%rdi, %rdx)
28373 movq %r8, -1*8(%rdi, %rdx)
28374 jmp 13f
28375@@ -167,9 +167,9 @@ ENTRY(memmove)
28376 * Move data from 8 bytes to 15 bytes.
28377 */
28378 movq 0*8(%rsi), %r11
28379- movq -1*8(%rsi, %rdx), %r10
28380+ movq -1*8(%rsi, %rdx), %r9
28381 movq %r11, 0*8(%rdi)
28382- movq %r10, -1*8(%rdi, %rdx)
28383+ movq %r9, -1*8(%rdi, %rdx)
28384 jmp 13f
28385 10:
28386 cmpq $4, %rdx
28387@@ -178,9 +178,9 @@ ENTRY(memmove)
28388 * Move data from 4 bytes to 7 bytes.
28389 */
28390 movl (%rsi), %r11d
28391- movl -4(%rsi, %rdx), %r10d
28392+ movl -4(%rsi, %rdx), %r9d
28393 movl %r11d, (%rdi)
28394- movl %r10d, -4(%rdi, %rdx)
28395+ movl %r9d, -4(%rdi, %rdx)
28396 jmp 13f
28397 11:
28398 cmp $2, %rdx
28399@@ -189,9 +189,9 @@ ENTRY(memmove)
28400 * Move data from 2 bytes to 3 bytes.
28401 */
28402 movw (%rsi), %r11w
28403- movw -2(%rsi, %rdx), %r10w
28404+ movw -2(%rsi, %rdx), %r9w
28405 movw %r11w, (%rdi)
28406- movw %r10w, -2(%rdi, %rdx)
28407+ movw %r9w, -2(%rdi, %rdx)
28408 jmp 13f
28409 12:
28410 cmp $1, %rdx
28411@@ -202,14 +202,16 @@ ENTRY(memmove)
28412 movb (%rsi), %r11b
28413 movb %r11b, (%rdi)
28414 13:
28415+ pax_force_retaddr
28416 retq
28417 CFI_ENDPROC
28418
28419- .section .altinstr_replacement,"ax"
28420+ .section .altinstr_replacement,"a"
28421 .Lmemmove_begin_forward_efs:
28422 /* Forward moving data. */
28423 movq %rdx, %rcx
28424 rep movsb
28425+ pax_force_retaddr
28426 retq
28427 .Lmemmove_end_forward_efs:
28428 .previous
28429diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
28430index 2dcb380..50a78bc 100644
28431--- a/arch/x86/lib/memset_64.S
28432+++ b/arch/x86/lib/memset_64.S
28433@@ -16,7 +16,7 @@
28434 *
28435 * rax original destination
28436 */
28437- .section .altinstr_replacement, "ax", @progbits
28438+ .section .altinstr_replacement, "a", @progbits
28439 .Lmemset_c:
28440 movq %rdi,%r9
28441 movq %rdx,%rcx
28442@@ -30,6 +30,7 @@
28443 movl %edx,%ecx
28444 rep stosb
28445 movq %r9,%rax
28446+ pax_force_retaddr
28447 ret
28448 .Lmemset_e:
28449 .previous
28450@@ -45,13 +46,14 @@
28451 *
28452 * rax original destination
28453 */
28454- .section .altinstr_replacement, "ax", @progbits
28455+ .section .altinstr_replacement, "a", @progbits
28456 .Lmemset_c_e:
28457 movq %rdi,%r9
28458 movb %sil,%al
28459 movq %rdx,%rcx
28460 rep stosb
28461 movq %r9,%rax
28462+ pax_force_retaddr
28463 ret
28464 .Lmemset_e_e:
28465 .previous
28466@@ -59,7 +61,7 @@
28467 ENTRY(memset)
28468 ENTRY(__memset)
28469 CFI_STARTPROC
28470- movq %rdi,%r10
28471+ movq %rdi,%r11
28472
28473 /* expand byte value */
28474 movzbl %sil,%ecx
28475@@ -117,7 +119,8 @@ ENTRY(__memset)
28476 jnz .Lloop_1
28477
28478 .Lende:
28479- movq %r10,%rax
28480+ movq %r11,%rax
28481+ pax_force_retaddr
28482 ret
28483
28484 CFI_RESTORE_STATE
28485diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
28486index c9f2d9b..e7fd2c0 100644
28487--- a/arch/x86/lib/mmx_32.c
28488+++ b/arch/x86/lib/mmx_32.c
28489@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
28490 {
28491 void *p;
28492 int i;
28493+ unsigned long cr0;
28494
28495 if (unlikely(in_interrupt()))
28496 return __memcpy(to, from, len);
28497@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
28498 kernel_fpu_begin();
28499
28500 __asm__ __volatile__ (
28501- "1: prefetch (%0)\n" /* This set is 28 bytes */
28502- " prefetch 64(%0)\n"
28503- " prefetch 128(%0)\n"
28504- " prefetch 192(%0)\n"
28505- " prefetch 256(%0)\n"
28506+ "1: prefetch (%1)\n" /* This set is 28 bytes */
28507+ " prefetch 64(%1)\n"
28508+ " prefetch 128(%1)\n"
28509+ " prefetch 192(%1)\n"
28510+ " prefetch 256(%1)\n"
28511 "2: \n"
28512 ".section .fixup, \"ax\"\n"
28513- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28514+ "3: \n"
28515+
28516+#ifdef CONFIG_PAX_KERNEXEC
28517+ " movl %%cr0, %0\n"
28518+ " movl %0, %%eax\n"
28519+ " andl $0xFFFEFFFF, %%eax\n"
28520+ " movl %%eax, %%cr0\n"
28521+#endif
28522+
28523+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28524+
28525+#ifdef CONFIG_PAX_KERNEXEC
28526+ " movl %0, %%cr0\n"
28527+#endif
28528+
28529 " jmp 2b\n"
28530 ".previous\n"
28531 _ASM_EXTABLE(1b, 3b)
28532- : : "r" (from));
28533+ : "=&r" (cr0) : "r" (from) : "ax");
28534
28535 for ( ; i > 5; i--) {
28536 __asm__ __volatile__ (
28537- "1: prefetch 320(%0)\n"
28538- "2: movq (%0), %%mm0\n"
28539- " movq 8(%0), %%mm1\n"
28540- " movq 16(%0), %%mm2\n"
28541- " movq 24(%0), %%mm3\n"
28542- " movq %%mm0, (%1)\n"
28543- " movq %%mm1, 8(%1)\n"
28544- " movq %%mm2, 16(%1)\n"
28545- " movq %%mm3, 24(%1)\n"
28546- " movq 32(%0), %%mm0\n"
28547- " movq 40(%0), %%mm1\n"
28548- " movq 48(%0), %%mm2\n"
28549- " movq 56(%0), %%mm3\n"
28550- " movq %%mm0, 32(%1)\n"
28551- " movq %%mm1, 40(%1)\n"
28552- " movq %%mm2, 48(%1)\n"
28553- " movq %%mm3, 56(%1)\n"
28554+ "1: prefetch 320(%1)\n"
28555+ "2: movq (%1), %%mm0\n"
28556+ " movq 8(%1), %%mm1\n"
28557+ " movq 16(%1), %%mm2\n"
28558+ " movq 24(%1), %%mm3\n"
28559+ " movq %%mm0, (%2)\n"
28560+ " movq %%mm1, 8(%2)\n"
28561+ " movq %%mm2, 16(%2)\n"
28562+ " movq %%mm3, 24(%2)\n"
28563+ " movq 32(%1), %%mm0\n"
28564+ " movq 40(%1), %%mm1\n"
28565+ " movq 48(%1), %%mm2\n"
28566+ " movq 56(%1), %%mm3\n"
28567+ " movq %%mm0, 32(%2)\n"
28568+ " movq %%mm1, 40(%2)\n"
28569+ " movq %%mm2, 48(%2)\n"
28570+ " movq %%mm3, 56(%2)\n"
28571 ".section .fixup, \"ax\"\n"
28572- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28573+ "3:\n"
28574+
28575+#ifdef CONFIG_PAX_KERNEXEC
28576+ " movl %%cr0, %0\n"
28577+ " movl %0, %%eax\n"
28578+ " andl $0xFFFEFFFF, %%eax\n"
28579+ " movl %%eax, %%cr0\n"
28580+#endif
28581+
28582+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28583+
28584+#ifdef CONFIG_PAX_KERNEXEC
28585+ " movl %0, %%cr0\n"
28586+#endif
28587+
28588 " jmp 2b\n"
28589 ".previous\n"
28590 _ASM_EXTABLE(1b, 3b)
28591- : : "r" (from), "r" (to) : "memory");
28592+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
28593
28594 from += 64;
28595 to += 64;
28596@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
28597 static void fast_copy_page(void *to, void *from)
28598 {
28599 int i;
28600+ unsigned long cr0;
28601
28602 kernel_fpu_begin();
28603
28604@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
28605 * but that is for later. -AV
28606 */
28607 __asm__ __volatile__(
28608- "1: prefetch (%0)\n"
28609- " prefetch 64(%0)\n"
28610- " prefetch 128(%0)\n"
28611- " prefetch 192(%0)\n"
28612- " prefetch 256(%0)\n"
28613+ "1: prefetch (%1)\n"
28614+ " prefetch 64(%1)\n"
28615+ " prefetch 128(%1)\n"
28616+ " prefetch 192(%1)\n"
28617+ " prefetch 256(%1)\n"
28618 "2: \n"
28619 ".section .fixup, \"ax\"\n"
28620- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28621+ "3: \n"
28622+
28623+#ifdef CONFIG_PAX_KERNEXEC
28624+ " movl %%cr0, %0\n"
28625+ " movl %0, %%eax\n"
28626+ " andl $0xFFFEFFFF, %%eax\n"
28627+ " movl %%eax, %%cr0\n"
28628+#endif
28629+
28630+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28631+
28632+#ifdef CONFIG_PAX_KERNEXEC
28633+ " movl %0, %%cr0\n"
28634+#endif
28635+
28636 " jmp 2b\n"
28637 ".previous\n"
28638- _ASM_EXTABLE(1b, 3b) : : "r" (from));
28639+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
28640
28641 for (i = 0; i < (4096-320)/64; i++) {
28642 __asm__ __volatile__ (
28643- "1: prefetch 320(%0)\n"
28644- "2: movq (%0), %%mm0\n"
28645- " movntq %%mm0, (%1)\n"
28646- " movq 8(%0), %%mm1\n"
28647- " movntq %%mm1, 8(%1)\n"
28648- " movq 16(%0), %%mm2\n"
28649- " movntq %%mm2, 16(%1)\n"
28650- " movq 24(%0), %%mm3\n"
28651- " movntq %%mm3, 24(%1)\n"
28652- " movq 32(%0), %%mm4\n"
28653- " movntq %%mm4, 32(%1)\n"
28654- " movq 40(%0), %%mm5\n"
28655- " movntq %%mm5, 40(%1)\n"
28656- " movq 48(%0), %%mm6\n"
28657- " movntq %%mm6, 48(%1)\n"
28658- " movq 56(%0), %%mm7\n"
28659- " movntq %%mm7, 56(%1)\n"
28660+ "1: prefetch 320(%1)\n"
28661+ "2: movq (%1), %%mm0\n"
28662+ " movntq %%mm0, (%2)\n"
28663+ " movq 8(%1), %%mm1\n"
28664+ " movntq %%mm1, 8(%2)\n"
28665+ " movq 16(%1), %%mm2\n"
28666+ " movntq %%mm2, 16(%2)\n"
28667+ " movq 24(%1), %%mm3\n"
28668+ " movntq %%mm3, 24(%2)\n"
28669+ " movq 32(%1), %%mm4\n"
28670+ " movntq %%mm4, 32(%2)\n"
28671+ " movq 40(%1), %%mm5\n"
28672+ " movntq %%mm5, 40(%2)\n"
28673+ " movq 48(%1), %%mm6\n"
28674+ " movntq %%mm6, 48(%2)\n"
28675+ " movq 56(%1), %%mm7\n"
28676+ " movntq %%mm7, 56(%2)\n"
28677 ".section .fixup, \"ax\"\n"
28678- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28679+ "3:\n"
28680+
28681+#ifdef CONFIG_PAX_KERNEXEC
28682+ " movl %%cr0, %0\n"
28683+ " movl %0, %%eax\n"
28684+ " andl $0xFFFEFFFF, %%eax\n"
28685+ " movl %%eax, %%cr0\n"
28686+#endif
28687+
28688+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28689+
28690+#ifdef CONFIG_PAX_KERNEXEC
28691+ " movl %0, %%cr0\n"
28692+#endif
28693+
28694 " jmp 2b\n"
28695 ".previous\n"
28696- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
28697+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
28698
28699 from += 64;
28700 to += 64;
28701@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
28702 static void fast_copy_page(void *to, void *from)
28703 {
28704 int i;
28705+ unsigned long cr0;
28706
28707 kernel_fpu_begin();
28708
28709 __asm__ __volatile__ (
28710- "1: prefetch (%0)\n"
28711- " prefetch 64(%0)\n"
28712- " prefetch 128(%0)\n"
28713- " prefetch 192(%0)\n"
28714- " prefetch 256(%0)\n"
28715+ "1: prefetch (%1)\n"
28716+ " prefetch 64(%1)\n"
28717+ " prefetch 128(%1)\n"
28718+ " prefetch 192(%1)\n"
28719+ " prefetch 256(%1)\n"
28720 "2: \n"
28721 ".section .fixup, \"ax\"\n"
28722- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28723+ "3: \n"
28724+
28725+#ifdef CONFIG_PAX_KERNEXEC
28726+ " movl %%cr0, %0\n"
28727+ " movl %0, %%eax\n"
28728+ " andl $0xFFFEFFFF, %%eax\n"
28729+ " movl %%eax, %%cr0\n"
28730+#endif
28731+
28732+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28733+
28734+#ifdef CONFIG_PAX_KERNEXEC
28735+ " movl %0, %%cr0\n"
28736+#endif
28737+
28738 " jmp 2b\n"
28739 ".previous\n"
28740- _ASM_EXTABLE(1b, 3b) : : "r" (from));
28741+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
28742
28743 for (i = 0; i < 4096/64; i++) {
28744 __asm__ __volatile__ (
28745- "1: prefetch 320(%0)\n"
28746- "2: movq (%0), %%mm0\n"
28747- " movq 8(%0), %%mm1\n"
28748- " movq 16(%0), %%mm2\n"
28749- " movq 24(%0), %%mm3\n"
28750- " movq %%mm0, (%1)\n"
28751- " movq %%mm1, 8(%1)\n"
28752- " movq %%mm2, 16(%1)\n"
28753- " movq %%mm3, 24(%1)\n"
28754- " movq 32(%0), %%mm0\n"
28755- " movq 40(%0), %%mm1\n"
28756- " movq 48(%0), %%mm2\n"
28757- " movq 56(%0), %%mm3\n"
28758- " movq %%mm0, 32(%1)\n"
28759- " movq %%mm1, 40(%1)\n"
28760- " movq %%mm2, 48(%1)\n"
28761- " movq %%mm3, 56(%1)\n"
28762+ "1: prefetch 320(%1)\n"
28763+ "2: movq (%1), %%mm0\n"
28764+ " movq 8(%1), %%mm1\n"
28765+ " movq 16(%1), %%mm2\n"
28766+ " movq 24(%1), %%mm3\n"
28767+ " movq %%mm0, (%2)\n"
28768+ " movq %%mm1, 8(%2)\n"
28769+ " movq %%mm2, 16(%2)\n"
28770+ " movq %%mm3, 24(%2)\n"
28771+ " movq 32(%1), %%mm0\n"
28772+ " movq 40(%1), %%mm1\n"
28773+ " movq 48(%1), %%mm2\n"
28774+ " movq 56(%1), %%mm3\n"
28775+ " movq %%mm0, 32(%2)\n"
28776+ " movq %%mm1, 40(%2)\n"
28777+ " movq %%mm2, 48(%2)\n"
28778+ " movq %%mm3, 56(%2)\n"
28779 ".section .fixup, \"ax\"\n"
28780- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28781+ "3:\n"
28782+
28783+#ifdef CONFIG_PAX_KERNEXEC
28784+ " movl %%cr0, %0\n"
28785+ " movl %0, %%eax\n"
28786+ " andl $0xFFFEFFFF, %%eax\n"
28787+ " movl %%eax, %%cr0\n"
28788+#endif
28789+
28790+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28791+
28792+#ifdef CONFIG_PAX_KERNEXEC
28793+ " movl %0, %%cr0\n"
28794+#endif
28795+
28796 " jmp 2b\n"
28797 ".previous\n"
28798 _ASM_EXTABLE(1b, 3b)
28799- : : "r" (from), "r" (to) : "memory");
28800+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
28801
28802 from += 64;
28803 to += 64;
28804diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
28805index f6d13ee..aca5f0b 100644
28806--- a/arch/x86/lib/msr-reg.S
28807+++ b/arch/x86/lib/msr-reg.S
28808@@ -3,6 +3,7 @@
28809 #include <asm/dwarf2.h>
28810 #include <asm/asm.h>
28811 #include <asm/msr.h>
28812+#include <asm/alternative-asm.h>
28813
28814 #ifdef CONFIG_X86_64
28815 /*
28816@@ -16,7 +17,7 @@ ENTRY(\op\()_safe_regs)
28817 CFI_STARTPROC
28818 pushq_cfi %rbx
28819 pushq_cfi %rbp
28820- movq %rdi, %r10 /* Save pointer */
28821+ movq %rdi, %r9 /* Save pointer */
28822 xorl %r11d, %r11d /* Return value */
28823 movl (%rdi), %eax
28824 movl 4(%rdi), %ecx
28825@@ -27,16 +28,17 @@ ENTRY(\op\()_safe_regs)
28826 movl 28(%rdi), %edi
28827 CFI_REMEMBER_STATE
28828 1: \op
28829-2: movl %eax, (%r10)
28830+2: movl %eax, (%r9)
28831 movl %r11d, %eax /* Return value */
28832- movl %ecx, 4(%r10)
28833- movl %edx, 8(%r10)
28834- movl %ebx, 12(%r10)
28835- movl %ebp, 20(%r10)
28836- movl %esi, 24(%r10)
28837- movl %edi, 28(%r10)
28838+ movl %ecx, 4(%r9)
28839+ movl %edx, 8(%r9)
28840+ movl %ebx, 12(%r9)
28841+ movl %ebp, 20(%r9)
28842+ movl %esi, 24(%r9)
28843+ movl %edi, 28(%r9)
28844 popq_cfi %rbp
28845 popq_cfi %rbx
28846+ pax_force_retaddr
28847 ret
28848 3:
28849 CFI_RESTORE_STATE
28850diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
28851index fc6ba17..d4d989d 100644
28852--- a/arch/x86/lib/putuser.S
28853+++ b/arch/x86/lib/putuser.S
28854@@ -16,7 +16,9 @@
28855 #include <asm/errno.h>
28856 #include <asm/asm.h>
28857 #include <asm/smap.h>
28858-
28859+#include <asm/segment.h>
28860+#include <asm/pgtable.h>
28861+#include <asm/alternative-asm.h>
28862
28863 /*
28864 * __put_user_X
28865@@ -30,57 +32,125 @@
28866 * as they get called from within inline assembly.
28867 */
28868
28869-#define ENTER CFI_STARTPROC ; \
28870- GET_THREAD_INFO(%_ASM_BX)
28871-#define EXIT ASM_CLAC ; \
28872- ret ; \
28873+#define ENTER CFI_STARTPROC
28874+#define EXIT ASM_CLAC ; \
28875+ pax_force_retaddr ; \
28876+ ret ; \
28877 CFI_ENDPROC
28878
28879+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28880+#define _DEST %_ASM_CX,%_ASM_BX
28881+#else
28882+#define _DEST %_ASM_CX
28883+#endif
28884+
28885+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
28886+#define __copyuser_seg gs;
28887+#else
28888+#define __copyuser_seg
28889+#endif
28890+
28891 .text
28892 ENTRY(__put_user_1)
28893 ENTER
28894+
28895+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28896+ GET_THREAD_INFO(%_ASM_BX)
28897 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
28898 jae bad_put_user
28899 ASM_STAC
28900-1: movb %al,(%_ASM_CX)
28901+
28902+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28903+ mov pax_user_shadow_base,%_ASM_BX
28904+ cmp %_ASM_BX,%_ASM_CX
28905+ jb 1234f
28906+ xor %ebx,%ebx
28907+1234:
28908+#endif
28909+
28910+#endif
28911+
28912+1: __copyuser_seg movb %al,(_DEST)
28913 xor %eax,%eax
28914 EXIT
28915 ENDPROC(__put_user_1)
28916
28917 ENTRY(__put_user_2)
28918 ENTER
28919+
28920+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28921+ GET_THREAD_INFO(%_ASM_BX)
28922 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
28923 sub $1,%_ASM_BX
28924 cmp %_ASM_BX,%_ASM_CX
28925 jae bad_put_user
28926 ASM_STAC
28927-2: movw %ax,(%_ASM_CX)
28928+
28929+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28930+ mov pax_user_shadow_base,%_ASM_BX
28931+ cmp %_ASM_BX,%_ASM_CX
28932+ jb 1234f
28933+ xor %ebx,%ebx
28934+1234:
28935+#endif
28936+
28937+#endif
28938+
28939+2: __copyuser_seg movw %ax,(_DEST)
28940 xor %eax,%eax
28941 EXIT
28942 ENDPROC(__put_user_2)
28943
28944 ENTRY(__put_user_4)
28945 ENTER
28946+
28947+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28948+ GET_THREAD_INFO(%_ASM_BX)
28949 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
28950 sub $3,%_ASM_BX
28951 cmp %_ASM_BX,%_ASM_CX
28952 jae bad_put_user
28953 ASM_STAC
28954-3: movl %eax,(%_ASM_CX)
28955+
28956+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28957+ mov pax_user_shadow_base,%_ASM_BX
28958+ cmp %_ASM_BX,%_ASM_CX
28959+ jb 1234f
28960+ xor %ebx,%ebx
28961+1234:
28962+#endif
28963+
28964+#endif
28965+
28966+3: __copyuser_seg movl %eax,(_DEST)
28967 xor %eax,%eax
28968 EXIT
28969 ENDPROC(__put_user_4)
28970
28971 ENTRY(__put_user_8)
28972 ENTER
28973+
28974+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28975+ GET_THREAD_INFO(%_ASM_BX)
28976 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
28977 sub $7,%_ASM_BX
28978 cmp %_ASM_BX,%_ASM_CX
28979 jae bad_put_user
28980 ASM_STAC
28981-4: mov %_ASM_AX,(%_ASM_CX)
28982+
28983+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28984+ mov pax_user_shadow_base,%_ASM_BX
28985+ cmp %_ASM_BX,%_ASM_CX
28986+ jb 1234f
28987+ xor %ebx,%ebx
28988+1234:
28989+#endif
28990+
28991+#endif
28992+
28993+4: __copyuser_seg mov %_ASM_AX,(_DEST)
28994 #ifdef CONFIG_X86_32
28995-5: movl %edx,4(%_ASM_CX)
28996+5: __copyuser_seg movl %edx,4(_DEST)
28997 #endif
28998 xor %eax,%eax
28999 EXIT
29000diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
29001index 1cad221..de671ee 100644
29002--- a/arch/x86/lib/rwlock.S
29003+++ b/arch/x86/lib/rwlock.S
29004@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
29005 FRAME
29006 0: LOCK_PREFIX
29007 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
29008+
29009+#ifdef CONFIG_PAX_REFCOUNT
29010+ jno 1234f
29011+ LOCK_PREFIX
29012+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
29013+ int $4
29014+1234:
29015+ _ASM_EXTABLE(1234b, 1234b)
29016+#endif
29017+
29018 1: rep; nop
29019 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
29020 jne 1b
29021 LOCK_PREFIX
29022 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
29023+
29024+#ifdef CONFIG_PAX_REFCOUNT
29025+ jno 1234f
29026+ LOCK_PREFIX
29027+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
29028+ int $4
29029+1234:
29030+ _ASM_EXTABLE(1234b, 1234b)
29031+#endif
29032+
29033 jnz 0b
29034 ENDFRAME
29035+ pax_force_retaddr
29036 ret
29037 CFI_ENDPROC
29038 END(__write_lock_failed)
29039@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
29040 FRAME
29041 0: LOCK_PREFIX
29042 READ_LOCK_SIZE(inc) (%__lock_ptr)
29043+
29044+#ifdef CONFIG_PAX_REFCOUNT
29045+ jno 1234f
29046+ LOCK_PREFIX
29047+ READ_LOCK_SIZE(dec) (%__lock_ptr)
29048+ int $4
29049+1234:
29050+ _ASM_EXTABLE(1234b, 1234b)
29051+#endif
29052+
29053 1: rep; nop
29054 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
29055 js 1b
29056 LOCK_PREFIX
29057 READ_LOCK_SIZE(dec) (%__lock_ptr)
29058+
29059+#ifdef CONFIG_PAX_REFCOUNT
29060+ jno 1234f
29061+ LOCK_PREFIX
29062+ READ_LOCK_SIZE(inc) (%__lock_ptr)
29063+ int $4
29064+1234:
29065+ _ASM_EXTABLE(1234b, 1234b)
29066+#endif
29067+
29068 js 0b
29069 ENDFRAME
29070+ pax_force_retaddr
29071 ret
29072 CFI_ENDPROC
29073 END(__read_lock_failed)
29074diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
29075index 5dff5f0..cadebf4 100644
29076--- a/arch/x86/lib/rwsem.S
29077+++ b/arch/x86/lib/rwsem.S
29078@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
29079 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
29080 CFI_RESTORE __ASM_REG(dx)
29081 restore_common_regs
29082+ pax_force_retaddr
29083 ret
29084 CFI_ENDPROC
29085 ENDPROC(call_rwsem_down_read_failed)
29086@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
29087 movq %rax,%rdi
29088 call rwsem_down_write_failed
29089 restore_common_regs
29090+ pax_force_retaddr
29091 ret
29092 CFI_ENDPROC
29093 ENDPROC(call_rwsem_down_write_failed)
29094@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
29095 movq %rax,%rdi
29096 call rwsem_wake
29097 restore_common_regs
29098-1: ret
29099+1: pax_force_retaddr
29100+ ret
29101 CFI_ENDPROC
29102 ENDPROC(call_rwsem_wake)
29103
29104@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
29105 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
29106 CFI_RESTORE __ASM_REG(dx)
29107 restore_common_regs
29108+ pax_force_retaddr
29109 ret
29110 CFI_ENDPROC
29111 ENDPROC(call_rwsem_downgrade_wake)
29112diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
29113index a63efd6..ccecad8 100644
29114--- a/arch/x86/lib/thunk_64.S
29115+++ b/arch/x86/lib/thunk_64.S
29116@@ -8,6 +8,7 @@
29117 #include <linux/linkage.h>
29118 #include <asm/dwarf2.h>
29119 #include <asm/calling.h>
29120+#include <asm/alternative-asm.h>
29121
29122 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
29123 .macro THUNK name, func, put_ret_addr_in_rdi=0
29124@@ -41,5 +42,6 @@
29125 SAVE_ARGS
29126 restore:
29127 RESTORE_ARGS
29128+ pax_force_retaddr
29129 ret
29130 CFI_ENDPROC
29131diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
29132index 3eb18ac..6890bc3 100644
29133--- a/arch/x86/lib/usercopy_32.c
29134+++ b/arch/x86/lib/usercopy_32.c
29135@@ -42,11 +42,13 @@ do { \
29136 int __d0; \
29137 might_fault(); \
29138 __asm__ __volatile__( \
29139+ __COPYUSER_SET_ES \
29140 ASM_STAC "\n" \
29141 "0: rep; stosl\n" \
29142 " movl %2,%0\n" \
29143 "1: rep; stosb\n" \
29144 "2: " ASM_CLAC "\n" \
29145+ __COPYUSER_RESTORE_ES \
29146 ".section .fixup,\"ax\"\n" \
29147 "3: lea 0(%2,%0,4),%0\n" \
29148 " jmp 2b\n" \
29149@@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
29150
29151 #ifdef CONFIG_X86_INTEL_USERCOPY
29152 static unsigned long
29153-__copy_user_intel(void __user *to, const void *from, unsigned long size)
29154+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
29155 {
29156 int d0, d1;
29157 __asm__ __volatile__(
29158@@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
29159 " .align 2,0x90\n"
29160 "3: movl 0(%4), %%eax\n"
29161 "4: movl 4(%4), %%edx\n"
29162- "5: movl %%eax, 0(%3)\n"
29163- "6: movl %%edx, 4(%3)\n"
29164+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
29165+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
29166 "7: movl 8(%4), %%eax\n"
29167 "8: movl 12(%4),%%edx\n"
29168- "9: movl %%eax, 8(%3)\n"
29169- "10: movl %%edx, 12(%3)\n"
29170+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
29171+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
29172 "11: movl 16(%4), %%eax\n"
29173 "12: movl 20(%4), %%edx\n"
29174- "13: movl %%eax, 16(%3)\n"
29175- "14: movl %%edx, 20(%3)\n"
29176+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
29177+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
29178 "15: movl 24(%4), %%eax\n"
29179 "16: movl 28(%4), %%edx\n"
29180- "17: movl %%eax, 24(%3)\n"
29181- "18: movl %%edx, 28(%3)\n"
29182+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
29183+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
29184 "19: movl 32(%4), %%eax\n"
29185 "20: movl 36(%4), %%edx\n"
29186- "21: movl %%eax, 32(%3)\n"
29187- "22: movl %%edx, 36(%3)\n"
29188+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
29189+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
29190 "23: movl 40(%4), %%eax\n"
29191 "24: movl 44(%4), %%edx\n"
29192- "25: movl %%eax, 40(%3)\n"
29193- "26: movl %%edx, 44(%3)\n"
29194+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
29195+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
29196 "27: movl 48(%4), %%eax\n"
29197 "28: movl 52(%4), %%edx\n"
29198- "29: movl %%eax, 48(%3)\n"
29199- "30: movl %%edx, 52(%3)\n"
29200+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
29201+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
29202 "31: movl 56(%4), %%eax\n"
29203 "32: movl 60(%4), %%edx\n"
29204- "33: movl %%eax, 56(%3)\n"
29205- "34: movl %%edx, 60(%3)\n"
29206+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
29207+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
29208 " addl $-64, %0\n"
29209 " addl $64, %4\n"
29210 " addl $64, %3\n"
29211@@ -149,10 +151,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
29212 " shrl $2, %0\n"
29213 " andl $3, %%eax\n"
29214 " cld\n"
29215+ __COPYUSER_SET_ES
29216 "99: rep; movsl\n"
29217 "36: movl %%eax, %0\n"
29218 "37: rep; movsb\n"
29219 "100:\n"
29220+ __COPYUSER_RESTORE_ES
29221 ".section .fixup,\"ax\"\n"
29222 "101: lea 0(%%eax,%0,4),%0\n"
29223 " jmp 100b\n"
29224@@ -202,46 +206,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
29225 }
29226
29227 static unsigned long
29228+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
29229+{
29230+ int d0, d1;
29231+ __asm__ __volatile__(
29232+ " .align 2,0x90\n"
29233+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
29234+ " cmpl $67, %0\n"
29235+ " jbe 3f\n"
29236+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
29237+ " .align 2,0x90\n"
29238+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
29239+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
29240+ "5: movl %%eax, 0(%3)\n"
29241+ "6: movl %%edx, 4(%3)\n"
29242+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
29243+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
29244+ "9: movl %%eax, 8(%3)\n"
29245+ "10: movl %%edx, 12(%3)\n"
29246+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
29247+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
29248+ "13: movl %%eax, 16(%3)\n"
29249+ "14: movl %%edx, 20(%3)\n"
29250+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
29251+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
29252+ "17: movl %%eax, 24(%3)\n"
29253+ "18: movl %%edx, 28(%3)\n"
29254+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
29255+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
29256+ "21: movl %%eax, 32(%3)\n"
29257+ "22: movl %%edx, 36(%3)\n"
29258+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
29259+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
29260+ "25: movl %%eax, 40(%3)\n"
29261+ "26: movl %%edx, 44(%3)\n"
29262+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
29263+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
29264+ "29: movl %%eax, 48(%3)\n"
29265+ "30: movl %%edx, 52(%3)\n"
29266+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
29267+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
29268+ "33: movl %%eax, 56(%3)\n"
29269+ "34: movl %%edx, 60(%3)\n"
29270+ " addl $-64, %0\n"
29271+ " addl $64, %4\n"
29272+ " addl $64, %3\n"
29273+ " cmpl $63, %0\n"
29274+ " ja 1b\n"
29275+ "35: movl %0, %%eax\n"
29276+ " shrl $2, %0\n"
29277+ " andl $3, %%eax\n"
29278+ " cld\n"
29279+ "99: rep; "__copyuser_seg" movsl\n"
29280+ "36: movl %%eax, %0\n"
29281+ "37: rep; "__copyuser_seg" movsb\n"
29282+ "100:\n"
29283+ ".section .fixup,\"ax\"\n"
29284+ "101: lea 0(%%eax,%0,4),%0\n"
29285+ " jmp 100b\n"
29286+ ".previous\n"
29287+ _ASM_EXTABLE(1b,100b)
29288+ _ASM_EXTABLE(2b,100b)
29289+ _ASM_EXTABLE(3b,100b)
29290+ _ASM_EXTABLE(4b,100b)
29291+ _ASM_EXTABLE(5b,100b)
29292+ _ASM_EXTABLE(6b,100b)
29293+ _ASM_EXTABLE(7b,100b)
29294+ _ASM_EXTABLE(8b,100b)
29295+ _ASM_EXTABLE(9b,100b)
29296+ _ASM_EXTABLE(10b,100b)
29297+ _ASM_EXTABLE(11b,100b)
29298+ _ASM_EXTABLE(12b,100b)
29299+ _ASM_EXTABLE(13b,100b)
29300+ _ASM_EXTABLE(14b,100b)
29301+ _ASM_EXTABLE(15b,100b)
29302+ _ASM_EXTABLE(16b,100b)
29303+ _ASM_EXTABLE(17b,100b)
29304+ _ASM_EXTABLE(18b,100b)
29305+ _ASM_EXTABLE(19b,100b)
29306+ _ASM_EXTABLE(20b,100b)
29307+ _ASM_EXTABLE(21b,100b)
29308+ _ASM_EXTABLE(22b,100b)
29309+ _ASM_EXTABLE(23b,100b)
29310+ _ASM_EXTABLE(24b,100b)
29311+ _ASM_EXTABLE(25b,100b)
29312+ _ASM_EXTABLE(26b,100b)
29313+ _ASM_EXTABLE(27b,100b)
29314+ _ASM_EXTABLE(28b,100b)
29315+ _ASM_EXTABLE(29b,100b)
29316+ _ASM_EXTABLE(30b,100b)
29317+ _ASM_EXTABLE(31b,100b)
29318+ _ASM_EXTABLE(32b,100b)
29319+ _ASM_EXTABLE(33b,100b)
29320+ _ASM_EXTABLE(34b,100b)
29321+ _ASM_EXTABLE(35b,100b)
29322+ _ASM_EXTABLE(36b,100b)
29323+ _ASM_EXTABLE(37b,100b)
29324+ _ASM_EXTABLE(99b,101b)
29325+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
29326+ : "1"(to), "2"(from), "0"(size)
29327+ : "eax", "edx", "memory");
29328+ return size;
29329+}
29330+
29331+static unsigned long __size_overflow(3)
29332 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
29333 {
29334 int d0, d1;
29335 __asm__ __volatile__(
29336 " .align 2,0x90\n"
29337- "0: movl 32(%4), %%eax\n"
29338+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
29339 " cmpl $67, %0\n"
29340 " jbe 2f\n"
29341- "1: movl 64(%4), %%eax\n"
29342+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
29343 " .align 2,0x90\n"
29344- "2: movl 0(%4), %%eax\n"
29345- "21: movl 4(%4), %%edx\n"
29346+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
29347+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
29348 " movl %%eax, 0(%3)\n"
29349 " movl %%edx, 4(%3)\n"
29350- "3: movl 8(%4), %%eax\n"
29351- "31: movl 12(%4),%%edx\n"
29352+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
29353+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
29354 " movl %%eax, 8(%3)\n"
29355 " movl %%edx, 12(%3)\n"
29356- "4: movl 16(%4), %%eax\n"
29357- "41: movl 20(%4), %%edx\n"
29358+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
29359+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
29360 " movl %%eax, 16(%3)\n"
29361 " movl %%edx, 20(%3)\n"
29362- "10: movl 24(%4), %%eax\n"
29363- "51: movl 28(%4), %%edx\n"
29364+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
29365+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
29366 " movl %%eax, 24(%3)\n"
29367 " movl %%edx, 28(%3)\n"
29368- "11: movl 32(%4), %%eax\n"
29369- "61: movl 36(%4), %%edx\n"
29370+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
29371+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
29372 " movl %%eax, 32(%3)\n"
29373 " movl %%edx, 36(%3)\n"
29374- "12: movl 40(%4), %%eax\n"
29375- "71: movl 44(%4), %%edx\n"
29376+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
29377+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
29378 " movl %%eax, 40(%3)\n"
29379 " movl %%edx, 44(%3)\n"
29380- "13: movl 48(%4), %%eax\n"
29381- "81: movl 52(%4), %%edx\n"
29382+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
29383+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
29384 " movl %%eax, 48(%3)\n"
29385 " movl %%edx, 52(%3)\n"
29386- "14: movl 56(%4), %%eax\n"
29387- "91: movl 60(%4), %%edx\n"
29388+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
29389+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
29390 " movl %%eax, 56(%3)\n"
29391 " movl %%edx, 60(%3)\n"
29392 " addl $-64, %0\n"
29393@@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
29394 " shrl $2, %0\n"
29395 " andl $3, %%eax\n"
29396 " cld\n"
29397- "6: rep; movsl\n"
29398+ "6: rep; "__copyuser_seg" movsl\n"
29399 " movl %%eax,%0\n"
29400- "7: rep; movsb\n"
29401+ "7: rep; "__copyuser_seg" movsb\n"
29402 "8:\n"
29403 ".section .fixup,\"ax\"\n"
29404 "9: lea 0(%%eax,%0,4),%0\n"
29405@@ -298,48 +406,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
29406 * hyoshiok@miraclelinux.com
29407 */
29408
29409-static unsigned long __copy_user_zeroing_intel_nocache(void *to,
29410+static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
29411 const void __user *from, unsigned long size)
29412 {
29413 int d0, d1;
29414
29415 __asm__ __volatile__(
29416 " .align 2,0x90\n"
29417- "0: movl 32(%4), %%eax\n"
29418+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
29419 " cmpl $67, %0\n"
29420 " jbe 2f\n"
29421- "1: movl 64(%4), %%eax\n"
29422+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
29423 " .align 2,0x90\n"
29424- "2: movl 0(%4), %%eax\n"
29425- "21: movl 4(%4), %%edx\n"
29426+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
29427+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
29428 " movnti %%eax, 0(%3)\n"
29429 " movnti %%edx, 4(%3)\n"
29430- "3: movl 8(%4), %%eax\n"
29431- "31: movl 12(%4),%%edx\n"
29432+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
29433+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
29434 " movnti %%eax, 8(%3)\n"
29435 " movnti %%edx, 12(%3)\n"
29436- "4: movl 16(%4), %%eax\n"
29437- "41: movl 20(%4), %%edx\n"
29438+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
29439+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
29440 " movnti %%eax, 16(%3)\n"
29441 " movnti %%edx, 20(%3)\n"
29442- "10: movl 24(%4), %%eax\n"
29443- "51: movl 28(%4), %%edx\n"
29444+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
29445+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
29446 " movnti %%eax, 24(%3)\n"
29447 " movnti %%edx, 28(%3)\n"
29448- "11: movl 32(%4), %%eax\n"
29449- "61: movl 36(%4), %%edx\n"
29450+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
29451+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
29452 " movnti %%eax, 32(%3)\n"
29453 " movnti %%edx, 36(%3)\n"
29454- "12: movl 40(%4), %%eax\n"
29455- "71: movl 44(%4), %%edx\n"
29456+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
29457+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
29458 " movnti %%eax, 40(%3)\n"
29459 " movnti %%edx, 44(%3)\n"
29460- "13: movl 48(%4), %%eax\n"
29461- "81: movl 52(%4), %%edx\n"
29462+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
29463+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
29464 " movnti %%eax, 48(%3)\n"
29465 " movnti %%edx, 52(%3)\n"
29466- "14: movl 56(%4), %%eax\n"
29467- "91: movl 60(%4), %%edx\n"
29468+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
29469+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
29470 " movnti %%eax, 56(%3)\n"
29471 " movnti %%edx, 60(%3)\n"
29472 " addl $-64, %0\n"
29473@@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
29474 " shrl $2, %0\n"
29475 " andl $3, %%eax\n"
29476 " cld\n"
29477- "6: rep; movsl\n"
29478+ "6: rep; "__copyuser_seg" movsl\n"
29479 " movl %%eax,%0\n"
29480- "7: rep; movsb\n"
29481+ "7: rep; "__copyuser_seg" movsb\n"
29482 "8:\n"
29483 ".section .fixup,\"ax\"\n"
29484 "9: lea 0(%%eax,%0,4),%0\n"
29485@@ -392,48 +500,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
29486 return size;
29487 }
29488
29489-static unsigned long __copy_user_intel_nocache(void *to,
29490+static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
29491 const void __user *from, unsigned long size)
29492 {
29493 int d0, d1;
29494
29495 __asm__ __volatile__(
29496 " .align 2,0x90\n"
29497- "0: movl 32(%4), %%eax\n"
29498+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
29499 " cmpl $67, %0\n"
29500 " jbe 2f\n"
29501- "1: movl 64(%4), %%eax\n"
29502+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
29503 " .align 2,0x90\n"
29504- "2: movl 0(%4), %%eax\n"
29505- "21: movl 4(%4), %%edx\n"
29506+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
29507+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
29508 " movnti %%eax, 0(%3)\n"
29509 " movnti %%edx, 4(%3)\n"
29510- "3: movl 8(%4), %%eax\n"
29511- "31: movl 12(%4),%%edx\n"
29512+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
29513+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
29514 " movnti %%eax, 8(%3)\n"
29515 " movnti %%edx, 12(%3)\n"
29516- "4: movl 16(%4), %%eax\n"
29517- "41: movl 20(%4), %%edx\n"
29518+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
29519+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
29520 " movnti %%eax, 16(%3)\n"
29521 " movnti %%edx, 20(%3)\n"
29522- "10: movl 24(%4), %%eax\n"
29523- "51: movl 28(%4), %%edx\n"
29524+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
29525+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
29526 " movnti %%eax, 24(%3)\n"
29527 " movnti %%edx, 28(%3)\n"
29528- "11: movl 32(%4), %%eax\n"
29529- "61: movl 36(%4), %%edx\n"
29530+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
29531+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
29532 " movnti %%eax, 32(%3)\n"
29533 " movnti %%edx, 36(%3)\n"
29534- "12: movl 40(%4), %%eax\n"
29535- "71: movl 44(%4), %%edx\n"
29536+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
29537+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
29538 " movnti %%eax, 40(%3)\n"
29539 " movnti %%edx, 44(%3)\n"
29540- "13: movl 48(%4), %%eax\n"
29541- "81: movl 52(%4), %%edx\n"
29542+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
29543+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
29544 " movnti %%eax, 48(%3)\n"
29545 " movnti %%edx, 52(%3)\n"
29546- "14: movl 56(%4), %%eax\n"
29547- "91: movl 60(%4), %%edx\n"
29548+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
29549+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
29550 " movnti %%eax, 56(%3)\n"
29551 " movnti %%edx, 60(%3)\n"
29552 " addl $-64, %0\n"
29553@@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
29554 " shrl $2, %0\n"
29555 " andl $3, %%eax\n"
29556 " cld\n"
29557- "6: rep; movsl\n"
29558+ "6: rep; "__copyuser_seg" movsl\n"
29559 " movl %%eax,%0\n"
29560- "7: rep; movsb\n"
29561+ "7: rep; "__copyuser_seg" movsb\n"
29562 "8:\n"
29563 ".section .fixup,\"ax\"\n"
29564 "9: lea 0(%%eax,%0,4),%0\n"
29565@@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
29566 */
29567 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
29568 unsigned long size);
29569-unsigned long __copy_user_intel(void __user *to, const void *from,
29570+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
29571+ unsigned long size);
29572+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
29573 unsigned long size);
29574 unsigned long __copy_user_zeroing_intel_nocache(void *to,
29575 const void __user *from, unsigned long size);
29576 #endif /* CONFIG_X86_INTEL_USERCOPY */
29577
29578 /* Generic arbitrary sized copy. */
29579-#define __copy_user(to, from, size) \
29580+#define __copy_user(to, from, size, prefix, set, restore) \
29581 do { \
29582 int __d0, __d1, __d2; \
29583 __asm__ __volatile__( \
29584+ set \
29585 " cmp $7,%0\n" \
29586 " jbe 1f\n" \
29587 " movl %1,%0\n" \
29588 " negl %0\n" \
29589 " andl $7,%0\n" \
29590 " subl %0,%3\n" \
29591- "4: rep; movsb\n" \
29592+ "4: rep; "prefix"movsb\n" \
29593 " movl %3,%0\n" \
29594 " shrl $2,%0\n" \
29595 " andl $3,%3\n" \
29596 " .align 2,0x90\n" \
29597- "0: rep; movsl\n" \
29598+ "0: rep; "prefix"movsl\n" \
29599 " movl %3,%0\n" \
29600- "1: rep; movsb\n" \
29601+ "1: rep; "prefix"movsb\n" \
29602 "2:\n" \
29603+ restore \
29604 ".section .fixup,\"ax\"\n" \
29605 "5: addl %3,%0\n" \
29606 " jmp 2b\n" \
29607@@ -538,14 +650,14 @@ do { \
29608 " negl %0\n" \
29609 " andl $7,%0\n" \
29610 " subl %0,%3\n" \
29611- "4: rep; movsb\n" \
29612+ "4: rep; "__copyuser_seg"movsb\n" \
29613 " movl %3,%0\n" \
29614 " shrl $2,%0\n" \
29615 " andl $3,%3\n" \
29616 " .align 2,0x90\n" \
29617- "0: rep; movsl\n" \
29618+ "0: rep; "__copyuser_seg"movsl\n" \
29619 " movl %3,%0\n" \
29620- "1: rep; movsb\n" \
29621+ "1: rep; "__copyuser_seg"movsb\n" \
29622 "2:\n" \
29623 ".section .fixup,\"ax\"\n" \
29624 "5: addl %3,%0\n" \
29625@@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
29626 {
29627 stac();
29628 if (movsl_is_ok(to, from, n))
29629- __copy_user(to, from, n);
29630+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
29631 else
29632- n = __copy_user_intel(to, from, n);
29633+ n = __generic_copy_to_user_intel(to, from, n);
29634 clac();
29635 return n;
29636 }
29637@@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
29638 {
29639 stac();
29640 if (movsl_is_ok(to, from, n))
29641- __copy_user(to, from, n);
29642+ __copy_user(to, from, n, __copyuser_seg, "", "");
29643 else
29644- n = __copy_user_intel((void __user *)to,
29645- (const void *)from, n);
29646+ n = __generic_copy_from_user_intel(to, from, n);
29647 clac();
29648 return n;
29649 }
29650@@ -632,60 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
29651 if (n > 64 && cpu_has_xmm2)
29652 n = __copy_user_intel_nocache(to, from, n);
29653 else
29654- __copy_user(to, from, n);
29655+ __copy_user(to, from, n, __copyuser_seg, "", "");
29656 #else
29657- __copy_user(to, from, n);
29658+ __copy_user(to, from, n, __copyuser_seg, "", "");
29659 #endif
29660 clac();
29661 return n;
29662 }
29663 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
29664
29665-/**
29666- * copy_to_user: - Copy a block of data into user space.
29667- * @to: Destination address, in user space.
29668- * @from: Source address, in kernel space.
29669- * @n: Number of bytes to copy.
29670- *
29671- * Context: User context only. This function may sleep.
29672- *
29673- * Copy data from kernel space to user space.
29674- *
29675- * Returns number of bytes that could not be copied.
29676- * On success, this will be zero.
29677- */
29678-unsigned long
29679-copy_to_user(void __user *to, const void *from, unsigned long n)
29680+#ifdef CONFIG_PAX_MEMORY_UDEREF
29681+void __set_fs(mm_segment_t x)
29682 {
29683- if (access_ok(VERIFY_WRITE, to, n))
29684- n = __copy_to_user(to, from, n);
29685- return n;
29686+ switch (x.seg) {
29687+ case 0:
29688+ loadsegment(gs, 0);
29689+ break;
29690+ case TASK_SIZE_MAX:
29691+ loadsegment(gs, __USER_DS);
29692+ break;
29693+ case -1UL:
29694+ loadsegment(gs, __KERNEL_DS);
29695+ break;
29696+ default:
29697+ BUG();
29698+ }
29699 }
29700-EXPORT_SYMBOL(copy_to_user);
29701+EXPORT_SYMBOL(__set_fs);
29702
29703-/**
29704- * copy_from_user: - Copy a block of data from user space.
29705- * @to: Destination address, in kernel space.
29706- * @from: Source address, in user space.
29707- * @n: Number of bytes to copy.
29708- *
29709- * Context: User context only. This function may sleep.
29710- *
29711- * Copy data from user space to kernel space.
29712- *
29713- * Returns number of bytes that could not be copied.
29714- * On success, this will be zero.
29715- *
29716- * If some data could not be copied, this function will pad the copied
29717- * data to the requested size using zero bytes.
29718- */
29719-unsigned long
29720-_copy_from_user(void *to, const void __user *from, unsigned long n)
29721+void set_fs(mm_segment_t x)
29722 {
29723- if (access_ok(VERIFY_READ, from, n))
29724- n = __copy_from_user(to, from, n);
29725- else
29726- memset(to, 0, n);
29727- return n;
29728+ current_thread_info()->addr_limit = x;
29729+ __set_fs(x);
29730 }
29731-EXPORT_SYMBOL(_copy_from_user);
29732+EXPORT_SYMBOL(set_fs);
29733+#endif
29734diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
29735index 906fea3..0194a18 100644
29736--- a/arch/x86/lib/usercopy_64.c
29737+++ b/arch/x86/lib/usercopy_64.c
29738@@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
29739 might_fault();
29740 /* no memory constraint because it doesn't change any memory gcc knows
29741 about */
29742+ pax_open_userland();
29743 stac();
29744 asm volatile(
29745 " testq %[size8],%[size8]\n"
29746@@ -39,9 +40,10 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
29747 _ASM_EXTABLE(0b,3b)
29748 _ASM_EXTABLE(1b,2b)
29749 : [size8] "=&c"(size), [dst] "=&D" (__d0)
29750- : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
29751+ : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
29752 [zero] "r" (0UL), [eight] "r" (8UL));
29753 clac();
29754+ pax_close_userland();
29755 return size;
29756 }
29757 EXPORT_SYMBOL(__clear_user);
29758@@ -54,12 +56,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
29759 }
29760 EXPORT_SYMBOL(clear_user);
29761
29762-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
29763+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
29764 {
29765- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
29766- return copy_user_generic((__force void *)to, (__force void *)from, len);
29767- }
29768- return len;
29769+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
29770+ return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
29771+ return len;
29772 }
29773 EXPORT_SYMBOL(copy_in_user);
29774
29775@@ -69,11 +70,13 @@ EXPORT_SYMBOL(copy_in_user);
29776 * it is not necessary to optimize tail handling.
29777 */
29778 unsigned long
29779-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
29780+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
29781 {
29782 char c;
29783 unsigned zero_len;
29784
29785+ clac();
29786+ pax_close_userland();
29787 for (; len; --len, to++) {
29788 if (__get_user_nocheck(c, from++, sizeof(char)))
29789 break;
29790@@ -84,6 +87,5 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
29791 for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
29792 if (__put_user_nocheck(c, to++, sizeof(char)))
29793 break;
29794- clac();
29795 return len;
29796 }
29797diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
29798index 23d8e5f..9ccc13a 100644
29799--- a/arch/x86/mm/Makefile
29800+++ b/arch/x86/mm/Makefile
29801@@ -28,3 +28,7 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o
29802 obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
29803
29804 obj-$(CONFIG_MEMTEST) += memtest.o
29805+
29806+quote:="
29807+obj-$(CONFIG_X86_64) += uderef_64.o
29808+CFLAGS_uderef_64.o := $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
29809diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
29810index 903ec1e..c4166b2 100644
29811--- a/arch/x86/mm/extable.c
29812+++ b/arch/x86/mm/extable.c
29813@@ -6,12 +6,24 @@
29814 static inline unsigned long
29815 ex_insn_addr(const struct exception_table_entry *x)
29816 {
29817- return (unsigned long)&x->insn + x->insn;
29818+ unsigned long reloc = 0;
29819+
29820+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
29821+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
29822+#endif
29823+
29824+ return (unsigned long)&x->insn + x->insn + reloc;
29825 }
29826 static inline unsigned long
29827 ex_fixup_addr(const struct exception_table_entry *x)
29828 {
29829- return (unsigned long)&x->fixup + x->fixup;
29830+ unsigned long reloc = 0;
29831+
29832+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
29833+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
29834+#endif
29835+
29836+ return (unsigned long)&x->fixup + x->fixup + reloc;
29837 }
29838
29839 int fixup_exception(struct pt_regs *regs)
29840@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
29841 unsigned long new_ip;
29842
29843 #ifdef CONFIG_PNPBIOS
29844- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
29845+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
29846 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
29847 extern u32 pnp_bios_is_utter_crap;
29848 pnp_bios_is_utter_crap = 1;
29849@@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
29850 i += 4;
29851 p->fixup -= i;
29852 i += 4;
29853+
29854+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
29855+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
29856+ p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
29857+ p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
29858+#endif
29859+
29860 }
29861 }
29862
29863diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
29864index 654be4a..a4a3da1 100644
29865--- a/arch/x86/mm/fault.c
29866+++ b/arch/x86/mm/fault.c
29867@@ -14,11 +14,18 @@
29868 #include <linux/hugetlb.h> /* hstate_index_to_shift */
29869 #include <linux/prefetch.h> /* prefetchw */
29870 #include <linux/context_tracking.h> /* exception_enter(), ... */
29871+#include <linux/unistd.h>
29872+#include <linux/compiler.h>
29873
29874 #include <asm/traps.h> /* dotraplinkage, ... */
29875 #include <asm/pgalloc.h> /* pgd_*(), ... */
29876 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
29877 #include <asm/fixmap.h> /* VSYSCALL_START */
29878+#include <asm/tlbflush.h>
29879+
29880+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29881+#include <asm/stacktrace.h>
29882+#endif
29883
29884 /*
29885 * Page fault error code bits:
29886@@ -56,7 +63,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
29887 int ret = 0;
29888
29889 /* kprobe_running() needs smp_processor_id() */
29890- if (kprobes_built_in() && !user_mode_vm(regs)) {
29891+ if (kprobes_built_in() && !user_mode(regs)) {
29892 preempt_disable();
29893 if (kprobe_running() && kprobe_fault_handler(regs, 14))
29894 ret = 1;
29895@@ -117,7 +124,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
29896 return !instr_lo || (instr_lo>>1) == 1;
29897 case 0x00:
29898 /* Prefetch instruction is 0x0F0D or 0x0F18 */
29899- if (probe_kernel_address(instr, opcode))
29900+ if (user_mode(regs)) {
29901+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
29902+ return 0;
29903+ } else if (probe_kernel_address(instr, opcode))
29904 return 0;
29905
29906 *prefetch = (instr_lo == 0xF) &&
29907@@ -151,7 +161,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
29908 while (instr < max_instr) {
29909 unsigned char opcode;
29910
29911- if (probe_kernel_address(instr, opcode))
29912+ if (user_mode(regs)) {
29913+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
29914+ break;
29915+ } else if (probe_kernel_address(instr, opcode))
29916 break;
29917
29918 instr++;
29919@@ -182,6 +195,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
29920 force_sig_info(si_signo, &info, tsk);
29921 }
29922
29923+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
29924+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
29925+#endif
29926+
29927+#ifdef CONFIG_PAX_EMUTRAMP
29928+static int pax_handle_fetch_fault(struct pt_regs *regs);
29929+#endif
29930+
29931+#ifdef CONFIG_PAX_PAGEEXEC
29932+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
29933+{
29934+ pgd_t *pgd;
29935+ pud_t *pud;
29936+ pmd_t *pmd;
29937+
29938+ pgd = pgd_offset(mm, address);
29939+ if (!pgd_present(*pgd))
29940+ return NULL;
29941+ pud = pud_offset(pgd, address);
29942+ if (!pud_present(*pud))
29943+ return NULL;
29944+ pmd = pmd_offset(pud, address);
29945+ if (!pmd_present(*pmd))
29946+ return NULL;
29947+ return pmd;
29948+}
29949+#endif
29950+
29951 DEFINE_SPINLOCK(pgd_lock);
29952 LIST_HEAD(pgd_list);
29953
29954@@ -232,10 +273,27 @@ void vmalloc_sync_all(void)
29955 for (address = VMALLOC_START & PMD_MASK;
29956 address >= TASK_SIZE && address < FIXADDR_TOP;
29957 address += PMD_SIZE) {
29958+
29959+#ifdef CONFIG_PAX_PER_CPU_PGD
29960+ unsigned long cpu;
29961+#else
29962 struct page *page;
29963+#endif
29964
29965 spin_lock(&pgd_lock);
29966+
29967+#ifdef CONFIG_PAX_PER_CPU_PGD
29968+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
29969+ pgd_t *pgd = get_cpu_pgd(cpu, user);
29970+ pmd_t *ret;
29971+
29972+ ret = vmalloc_sync_one(pgd, address);
29973+ if (!ret)
29974+ break;
29975+ pgd = get_cpu_pgd(cpu, kernel);
29976+#else
29977 list_for_each_entry(page, &pgd_list, lru) {
29978+ pgd_t *pgd;
29979 spinlock_t *pgt_lock;
29980 pmd_t *ret;
29981
29982@@ -243,8 +301,14 @@ void vmalloc_sync_all(void)
29983 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
29984
29985 spin_lock(pgt_lock);
29986- ret = vmalloc_sync_one(page_address(page), address);
29987+ pgd = page_address(page);
29988+#endif
29989+
29990+ ret = vmalloc_sync_one(pgd, address);
29991+
29992+#ifndef CONFIG_PAX_PER_CPU_PGD
29993 spin_unlock(pgt_lock);
29994+#endif
29995
29996 if (!ret)
29997 break;
29998@@ -278,6 +342,12 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
29999 * an interrupt in the middle of a task switch..
30000 */
30001 pgd_paddr = read_cr3();
30002+
30003+#ifdef CONFIG_PAX_PER_CPU_PGD
30004+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (pgd_paddr & __PHYSICAL_MASK));
30005+ vmalloc_sync_one(__va(pgd_paddr + PAGE_SIZE), address);
30006+#endif
30007+
30008 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
30009 if (!pmd_k)
30010 return -1;
30011@@ -373,11 +443,25 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
30012 * happen within a race in page table update. In the later
30013 * case just flush:
30014 */
30015- pgd = pgd_offset(current->active_mm, address);
30016+
30017 pgd_ref = pgd_offset_k(address);
30018 if (pgd_none(*pgd_ref))
30019 return -1;
30020
30021+#ifdef CONFIG_PAX_PER_CPU_PGD
30022+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (read_cr3() & __PHYSICAL_MASK));
30023+ pgd = pgd_offset_cpu(smp_processor_id(), user, address);
30024+ if (pgd_none(*pgd)) {
30025+ set_pgd(pgd, *pgd_ref);
30026+ arch_flush_lazy_mmu_mode();
30027+ } else {
30028+ BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
30029+ }
30030+ pgd = pgd_offset_cpu(smp_processor_id(), kernel, address);
30031+#else
30032+ pgd = pgd_offset(current->active_mm, address);
30033+#endif
30034+
30035 if (pgd_none(*pgd)) {
30036 set_pgd(pgd, *pgd_ref);
30037 arch_flush_lazy_mmu_mode();
30038@@ -543,7 +627,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
30039 static int is_errata100(struct pt_regs *regs, unsigned long address)
30040 {
30041 #ifdef CONFIG_X86_64
30042- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
30043+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
30044 return 1;
30045 #endif
30046 return 0;
30047@@ -570,7 +654,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
30048 }
30049
30050 static const char nx_warning[] = KERN_CRIT
30051-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
30052+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
30053
30054 static void
30055 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
30056@@ -579,15 +663,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
30057 if (!oops_may_print())
30058 return;
30059
30060- if (error_code & PF_INSTR) {
30061+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
30062 unsigned int level;
30063
30064 pte_t *pte = lookup_address(address, &level);
30065
30066 if (pte && pte_present(*pte) && !pte_exec(*pte))
30067- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
30068+ printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
30069 }
30070
30071+#ifdef CONFIG_PAX_KERNEXEC
30072+ if (init_mm.start_code <= address && address < init_mm.end_code) {
30073+ if (current->signal->curr_ip)
30074+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
30075+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
30076+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
30077+ else
30078+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
30079+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
30080+ }
30081+#endif
30082+
30083 printk(KERN_ALERT "BUG: unable to handle kernel ");
30084 if (address < PAGE_SIZE)
30085 printk(KERN_CONT "NULL pointer dereference");
30086@@ -750,6 +846,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
30087 return;
30088 }
30089 #endif
30090+
30091+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
30092+ if (pax_is_fetch_fault(regs, error_code, address)) {
30093+
30094+#ifdef CONFIG_PAX_EMUTRAMP
30095+ switch (pax_handle_fetch_fault(regs)) {
30096+ case 2:
30097+ return;
30098+ }
30099+#endif
30100+
30101+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
30102+ do_group_exit(SIGKILL);
30103+ }
30104+#endif
30105+
30106 /* Kernel addresses are always protection faults: */
30107 if (address >= TASK_SIZE)
30108 error_code |= PF_PROT;
30109@@ -835,7 +947,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
30110 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
30111 printk(KERN_ERR
30112 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
30113- tsk->comm, tsk->pid, address);
30114+ tsk->comm, task_pid_nr(tsk), address);
30115 code = BUS_MCEERR_AR;
30116 }
30117 #endif
30118@@ -898,6 +1010,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
30119 return 1;
30120 }
30121
30122+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
30123+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
30124+{
30125+ pte_t *pte;
30126+ pmd_t *pmd;
30127+ spinlock_t *ptl;
30128+ unsigned char pte_mask;
30129+
30130+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
30131+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
30132+ return 0;
30133+
30134+ /* PaX: it's our fault, let's handle it if we can */
30135+
30136+ /* PaX: take a look at read faults before acquiring any locks */
30137+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
30138+ /* instruction fetch attempt from a protected page in user mode */
30139+ up_read(&mm->mmap_sem);
30140+
30141+#ifdef CONFIG_PAX_EMUTRAMP
30142+ switch (pax_handle_fetch_fault(regs)) {
30143+ case 2:
30144+ return 1;
30145+ }
30146+#endif
30147+
30148+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
30149+ do_group_exit(SIGKILL);
30150+ }
30151+
30152+ pmd = pax_get_pmd(mm, address);
30153+ if (unlikely(!pmd))
30154+ return 0;
30155+
30156+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
30157+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
30158+ pte_unmap_unlock(pte, ptl);
30159+ return 0;
30160+ }
30161+
30162+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
30163+ /* write attempt to a protected page in user mode */
30164+ pte_unmap_unlock(pte, ptl);
30165+ return 0;
30166+ }
30167+
30168+#ifdef CONFIG_SMP
30169+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
30170+#else
30171+ if (likely(address > get_limit(regs->cs)))
30172+#endif
30173+ {
30174+ set_pte(pte, pte_mkread(*pte));
30175+ __flush_tlb_one(address);
30176+ pte_unmap_unlock(pte, ptl);
30177+ up_read(&mm->mmap_sem);
30178+ return 1;
30179+ }
30180+
30181+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
30182+
30183+ /*
30184+ * PaX: fill DTLB with user rights and retry
30185+ */
30186+ __asm__ __volatile__ (
30187+ "orb %2,(%1)\n"
30188+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
30189+/*
30190+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
30191+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
30192+ * page fault when examined during a TLB load attempt. this is true not only
30193+ * for PTEs holding a non-present entry but also present entries that will
30194+ * raise a page fault (such as those set up by PaX, or the copy-on-write
30195+ * mechanism). in effect it means that we do *not* need to flush the TLBs
30196+ * for our target pages since their PTEs are simply not in the TLBs at all.
30197+
30198+ * the best thing in omitting it is that we gain around 15-20% speed in the
30199+ * fast path of the page fault handler and can get rid of tracing since we
30200+ * can no longer flush unintended entries.
30201+ */
30202+ "invlpg (%0)\n"
30203+#endif
30204+ __copyuser_seg"testb $0,(%0)\n"
30205+ "xorb %3,(%1)\n"
30206+ :
30207+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
30208+ : "memory", "cc");
30209+ pte_unmap_unlock(pte, ptl);
30210+ up_read(&mm->mmap_sem);
30211+ return 1;
30212+}
30213+#endif
30214+
30215 /*
30216 * Handle a spurious fault caused by a stale TLB entry.
30217 *
30218@@ -964,6 +1169,9 @@ int show_unhandled_signals = 1;
30219 static inline int
30220 access_error(unsigned long error_code, struct vm_area_struct *vma)
30221 {
30222+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
30223+ return 1;
30224+
30225 if (error_code & PF_WRITE) {
30226 /* write, present and write, not present: */
30227 if (unlikely(!(vma->vm_flags & VM_WRITE)))
30228@@ -992,7 +1200,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
30229 if (error_code & PF_USER)
30230 return false;
30231
30232- if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
30233+ if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
30234 return false;
30235
30236 return true;
30237@@ -1008,18 +1216,33 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
30238 {
30239 struct vm_area_struct *vma;
30240 struct task_struct *tsk;
30241- unsigned long address;
30242 struct mm_struct *mm;
30243 int fault;
30244 int write = error_code & PF_WRITE;
30245 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
30246 (write ? FAULT_FLAG_WRITE : 0);
30247
30248- tsk = current;
30249- mm = tsk->mm;
30250-
30251 /* Get the faulting address: */
30252- address = read_cr2();
30253+ unsigned long address = read_cr2();
30254+
30255+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30256+ if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
30257+ if (!search_exception_tables(regs->ip)) {
30258+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
30259+ bad_area_nosemaphore(regs, error_code, address);
30260+ return;
30261+ }
30262+ if (address < pax_user_shadow_base) {
30263+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
30264+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
30265+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
30266+ } else
30267+ address -= pax_user_shadow_base;
30268+ }
30269+#endif
30270+
30271+ tsk = current;
30272+ mm = tsk->mm;
30273
30274 /*
30275 * Detect and handle instructions that would cause a page fault for
30276@@ -1080,7 +1303,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
30277 * User-mode registers count as a user access even for any
30278 * potential system fault or CPU buglet:
30279 */
30280- if (user_mode_vm(regs)) {
30281+ if (user_mode(regs)) {
30282 local_irq_enable();
30283 error_code |= PF_USER;
30284 } else {
30285@@ -1142,6 +1365,11 @@ retry:
30286 might_sleep();
30287 }
30288
30289+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
30290+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
30291+ return;
30292+#endif
30293+
30294 vma = find_vma(mm, address);
30295 if (unlikely(!vma)) {
30296 bad_area(regs, error_code, address);
30297@@ -1153,18 +1381,24 @@ retry:
30298 bad_area(regs, error_code, address);
30299 return;
30300 }
30301- if (error_code & PF_USER) {
30302- /*
30303- * Accessing the stack below %sp is always a bug.
30304- * The large cushion allows instructions like enter
30305- * and pusha to work. ("enter $65535, $31" pushes
30306- * 32 pointers and then decrements %sp by 65535.)
30307- */
30308- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
30309- bad_area(regs, error_code, address);
30310- return;
30311- }
30312+ /*
30313+ * Accessing the stack below %sp is always a bug.
30314+ * The large cushion allows instructions like enter
30315+ * and pusha to work. ("enter $65535, $31" pushes
30316+ * 32 pointers and then decrements %sp by 65535.)
30317+ */
30318+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
30319+ bad_area(regs, error_code, address);
30320+ return;
30321 }
30322+
30323+#ifdef CONFIG_PAX_SEGMEXEC
30324+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
30325+ bad_area(regs, error_code, address);
30326+ return;
30327+ }
30328+#endif
30329+
30330 if (unlikely(expand_stack(vma, address))) {
30331 bad_area(regs, error_code, address);
30332 return;
30333@@ -1230,3 +1464,292 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
30334 __do_page_fault(regs, error_code);
30335 exception_exit(prev_state);
30336 }
30337+
30338+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
30339+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
30340+{
30341+ struct mm_struct *mm = current->mm;
30342+ unsigned long ip = regs->ip;
30343+
30344+ if (v8086_mode(regs))
30345+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
30346+
30347+#ifdef CONFIG_PAX_PAGEEXEC
30348+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
30349+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
30350+ return true;
30351+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
30352+ return true;
30353+ return false;
30354+ }
30355+#endif
30356+
30357+#ifdef CONFIG_PAX_SEGMEXEC
30358+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
30359+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
30360+ return true;
30361+ return false;
30362+ }
30363+#endif
30364+
30365+ return false;
30366+}
30367+#endif
30368+
30369+#ifdef CONFIG_PAX_EMUTRAMP
30370+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
30371+{
30372+ int err;
30373+
30374+ do { /* PaX: libffi trampoline emulation */
30375+ unsigned char mov, jmp;
30376+ unsigned int addr1, addr2;
30377+
30378+#ifdef CONFIG_X86_64
30379+ if ((regs->ip + 9) >> 32)
30380+ break;
30381+#endif
30382+
30383+ err = get_user(mov, (unsigned char __user *)regs->ip);
30384+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
30385+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
30386+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
30387+
30388+ if (err)
30389+ break;
30390+
30391+ if (mov == 0xB8 && jmp == 0xE9) {
30392+ regs->ax = addr1;
30393+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
30394+ return 2;
30395+ }
30396+ } while (0);
30397+
30398+ do { /* PaX: gcc trampoline emulation #1 */
30399+ unsigned char mov1, mov2;
30400+ unsigned short jmp;
30401+ unsigned int addr1, addr2;
30402+
30403+#ifdef CONFIG_X86_64
30404+ if ((regs->ip + 11) >> 32)
30405+ break;
30406+#endif
30407+
30408+ err = get_user(mov1, (unsigned char __user *)regs->ip);
30409+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
30410+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
30411+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
30412+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
30413+
30414+ if (err)
30415+ break;
30416+
30417+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
30418+ regs->cx = addr1;
30419+ regs->ax = addr2;
30420+ regs->ip = addr2;
30421+ return 2;
30422+ }
30423+ } while (0);
30424+
30425+ do { /* PaX: gcc trampoline emulation #2 */
30426+ unsigned char mov, jmp;
30427+ unsigned int addr1, addr2;
30428+
30429+#ifdef CONFIG_X86_64
30430+ if ((regs->ip + 9) >> 32)
30431+ break;
30432+#endif
30433+
30434+ err = get_user(mov, (unsigned char __user *)regs->ip);
30435+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
30436+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
30437+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
30438+
30439+ if (err)
30440+ break;
30441+
30442+ if (mov == 0xB9 && jmp == 0xE9) {
30443+ regs->cx = addr1;
30444+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
30445+ return 2;
30446+ }
30447+ } while (0);
30448+
30449+ return 1; /* PaX in action */
30450+}
30451+
30452+#ifdef CONFIG_X86_64
30453+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
30454+{
30455+ int err;
30456+
30457+ do { /* PaX: libffi trampoline emulation */
30458+ unsigned short mov1, mov2, jmp1;
30459+ unsigned char stcclc, 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(stcclc, (unsigned char __user *)(regs->ip + 20));
30467+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
30468+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
30469+
30470+ if (err)
30471+ break;
30472+
30473+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
30474+ regs->r11 = addr1;
30475+ regs->r10 = addr2;
30476+ if (stcclc == 0xF8)
30477+ regs->flags &= ~X86_EFLAGS_CF;
30478+ else
30479+ regs->flags |= X86_EFLAGS_CF;
30480+ regs->ip = addr1;
30481+ return 2;
30482+ }
30483+ } while (0);
30484+
30485+ do { /* PaX: gcc trampoline emulation #1 */
30486+ unsigned short mov1, mov2, jmp1;
30487+ unsigned char jmp2;
30488+ unsigned int addr1;
30489+ unsigned long addr2;
30490+
30491+ err = get_user(mov1, (unsigned short __user *)regs->ip);
30492+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
30493+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
30494+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
30495+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
30496+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
30497+
30498+ if (err)
30499+ break;
30500+
30501+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
30502+ regs->r11 = addr1;
30503+ regs->r10 = addr2;
30504+ regs->ip = addr1;
30505+ return 2;
30506+ }
30507+ } while (0);
30508+
30509+ do { /* PaX: gcc trampoline emulation #2 */
30510+ unsigned short mov1, mov2, jmp1;
30511+ unsigned char jmp2;
30512+ unsigned long addr1, addr2;
30513+
30514+ err = get_user(mov1, (unsigned short __user *)regs->ip);
30515+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
30516+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
30517+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
30518+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
30519+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
30520+
30521+ if (err)
30522+ break;
30523+
30524+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
30525+ regs->r11 = addr1;
30526+ regs->r10 = addr2;
30527+ regs->ip = addr1;
30528+ return 2;
30529+ }
30530+ } while (0);
30531+
30532+ return 1; /* PaX in action */
30533+}
30534+#endif
30535+
30536+/*
30537+ * PaX: decide what to do with offenders (regs->ip = fault address)
30538+ *
30539+ * returns 1 when task should be killed
30540+ * 2 when gcc trampoline was detected
30541+ */
30542+static int pax_handle_fetch_fault(struct pt_regs *regs)
30543+{
30544+ if (v8086_mode(regs))
30545+ return 1;
30546+
30547+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
30548+ return 1;
30549+
30550+#ifdef CONFIG_X86_32
30551+ return pax_handle_fetch_fault_32(regs);
30552+#else
30553+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
30554+ return pax_handle_fetch_fault_32(regs);
30555+ else
30556+ return pax_handle_fetch_fault_64(regs);
30557+#endif
30558+}
30559+#endif
30560+
30561+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
30562+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
30563+{
30564+ long i;
30565+
30566+ printk(KERN_ERR "PAX: bytes at PC: ");
30567+ for (i = 0; i < 20; i++) {
30568+ unsigned char c;
30569+ if (get_user(c, (unsigned char __force_user *)pc+i))
30570+ printk(KERN_CONT "?? ");
30571+ else
30572+ printk(KERN_CONT "%02x ", c);
30573+ }
30574+ printk("\n");
30575+
30576+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
30577+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
30578+ unsigned long c;
30579+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
30580+#ifdef CONFIG_X86_32
30581+ printk(KERN_CONT "???????? ");
30582+#else
30583+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
30584+ printk(KERN_CONT "???????? ???????? ");
30585+ else
30586+ printk(KERN_CONT "???????????????? ");
30587+#endif
30588+ } else {
30589+#ifdef CONFIG_X86_64
30590+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
30591+ printk(KERN_CONT "%08x ", (unsigned int)c);
30592+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
30593+ } else
30594+#endif
30595+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
30596+ }
30597+ }
30598+ printk("\n");
30599+}
30600+#endif
30601+
30602+/**
30603+ * probe_kernel_write(): safely attempt to write to a location
30604+ * @dst: address to write to
30605+ * @src: pointer to the data that shall be written
30606+ * @size: size of the data chunk
30607+ *
30608+ * Safely write to address @dst from the buffer at @src. If a kernel fault
30609+ * happens, handle that and return -EFAULT.
30610+ */
30611+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
30612+{
30613+ long ret;
30614+ mm_segment_t old_fs = get_fs();
30615+
30616+ set_fs(KERNEL_DS);
30617+ pagefault_disable();
30618+ pax_open_kernel();
30619+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
30620+ pax_close_kernel();
30621+ pagefault_enable();
30622+ set_fs(old_fs);
30623+
30624+ return ret ? -EFAULT : 0;
30625+}
30626diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
30627index dd74e46..7d26398 100644
30628--- a/arch/x86/mm/gup.c
30629+++ b/arch/x86/mm/gup.c
30630@@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
30631 addr = start;
30632 len = (unsigned long) nr_pages << PAGE_SHIFT;
30633 end = start + len;
30634- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
30635+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
30636 (void __user *)start, len)))
30637 return 0;
30638
30639diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
30640index 4500142..53a363c 100644
30641--- a/arch/x86/mm/highmem_32.c
30642+++ b/arch/x86/mm/highmem_32.c
30643@@ -45,7 +45,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
30644 idx = type + KM_TYPE_NR*smp_processor_id();
30645 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
30646 BUG_ON(!pte_none(*(kmap_pte-idx)));
30647+
30648+ pax_open_kernel();
30649 set_pte(kmap_pte-idx, mk_pte(page, prot));
30650+ pax_close_kernel();
30651+
30652 arch_flush_lazy_mmu_mode();
30653
30654 return (void *)vaddr;
30655diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
30656index 7e73e8c..11d3b86 100644
30657--- a/arch/x86/mm/hugetlbpage.c
30658+++ b/arch/x86/mm/hugetlbpage.c
30659@@ -84,23 +84,30 @@ int pud_huge(pud_t pud)
30660 #ifdef HAVE_ARCH_HUGETLB_UNMAPPED_AREA
30661 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
30662 unsigned long addr, unsigned long len,
30663- unsigned long pgoff, unsigned long flags)
30664+ unsigned long pgoff, unsigned long flags, unsigned long offset)
30665 {
30666 struct hstate *h = hstate_file(file);
30667 struct vm_unmapped_area_info info;
30668-
30669+
30670 info.flags = 0;
30671 info.length = len;
30672 info.low_limit = TASK_UNMAPPED_BASE;
30673+
30674+#ifdef CONFIG_PAX_RANDMMAP
30675+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
30676+ info.low_limit += current->mm->delta_mmap;
30677+#endif
30678+
30679 info.high_limit = TASK_SIZE;
30680 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
30681 info.align_offset = 0;
30682+ info.threadstack_offset = offset;
30683 return vm_unmapped_area(&info);
30684 }
30685
30686 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
30687 unsigned long addr0, unsigned long len,
30688- unsigned long pgoff, unsigned long flags)
30689+ unsigned long pgoff, unsigned long flags, unsigned long offset)
30690 {
30691 struct hstate *h = hstate_file(file);
30692 struct vm_unmapped_area_info info;
30693@@ -112,6 +119,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
30694 info.high_limit = current->mm->mmap_base;
30695 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
30696 info.align_offset = 0;
30697+ info.threadstack_offset = offset;
30698 addr = vm_unmapped_area(&info);
30699
30700 /*
30701@@ -124,6 +132,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
30702 VM_BUG_ON(addr != -ENOMEM);
30703 info.flags = 0;
30704 info.low_limit = TASK_UNMAPPED_BASE;
30705+
30706+#ifdef CONFIG_PAX_RANDMMAP
30707+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
30708+ info.low_limit += current->mm->delta_mmap;
30709+#endif
30710+
30711 info.high_limit = TASK_SIZE;
30712 addr = vm_unmapped_area(&info);
30713 }
30714@@ -138,10 +152,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
30715 struct hstate *h = hstate_file(file);
30716 struct mm_struct *mm = current->mm;
30717 struct vm_area_struct *vma;
30718+ unsigned long pax_task_size = TASK_SIZE;
30719+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
30720
30721 if (len & ~huge_page_mask(h))
30722 return -EINVAL;
30723- if (len > TASK_SIZE)
30724+
30725+#ifdef CONFIG_PAX_SEGMEXEC
30726+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
30727+ pax_task_size = SEGMEXEC_TASK_SIZE;
30728+#endif
30729+
30730+ pax_task_size -= PAGE_SIZE;
30731+
30732+ if (len > pax_task_size)
30733 return -ENOMEM;
30734
30735 if (flags & MAP_FIXED) {
30736@@ -150,19 +174,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
30737 return addr;
30738 }
30739
30740+#ifdef CONFIG_PAX_RANDMMAP
30741+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
30742+#endif
30743+
30744 if (addr) {
30745 addr = ALIGN(addr, huge_page_size(h));
30746 vma = find_vma(mm, addr);
30747- if (TASK_SIZE - len >= addr &&
30748- (!vma || addr + len <= vma->vm_start))
30749+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
30750 return addr;
30751 }
30752 if (mm->get_unmapped_area == arch_get_unmapped_area)
30753 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
30754- pgoff, flags);
30755+ pgoff, flags, offset);
30756 else
30757 return hugetlb_get_unmapped_area_topdown(file, addr, len,
30758- pgoff, flags);
30759+ pgoff, flags, offset);
30760 }
30761
30762 #endif /*HAVE_ARCH_HUGETLB_UNMAPPED_AREA*/
30763diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
30764index 04664cd..dae6e5d 100644
30765--- a/arch/x86/mm/init.c
30766+++ b/arch/x86/mm/init.c
30767@@ -4,6 +4,7 @@
30768 #include <linux/swap.h>
30769 #include <linux/memblock.h>
30770 #include <linux/bootmem.h> /* for max_low_pfn */
30771+#include <linux/tboot.h>
30772
30773 #include <asm/cacheflush.h>
30774 #include <asm/e820.h>
30775@@ -17,6 +18,8 @@
30776 #include <asm/proto.h>
30777 #include <asm/dma.h> /* for MAX_DMA_PFN */
30778 #include <asm/microcode.h>
30779+#include <asm/desc.h>
30780+#include <asm/bios_ebda.h>
30781
30782 #include "mm_internal.h"
30783
30784@@ -465,7 +468,18 @@ void __init init_mem_mapping(void)
30785 early_ioremap_page_table_range_init();
30786 #endif
30787
30788+#ifdef CONFIG_PAX_PER_CPU_PGD
30789+ clone_pgd_range(get_cpu_pgd(0, kernel) + KERNEL_PGD_BOUNDARY,
30790+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
30791+ KERNEL_PGD_PTRS);
30792+ clone_pgd_range(get_cpu_pgd(0, user) + KERNEL_PGD_BOUNDARY,
30793+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
30794+ KERNEL_PGD_PTRS);
30795+ load_cr3(get_cpu_pgd(0, kernel));
30796+#else
30797 load_cr3(swapper_pg_dir);
30798+#endif
30799+
30800 __flush_tlb_all();
30801
30802 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
30803@@ -481,10 +495,40 @@ void __init init_mem_mapping(void)
30804 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
30805 * mmio resources as well as potential bios/acpi data regions.
30806 */
30807+
30808+#ifdef CONFIG_GRKERNSEC_KMEM
30809+static unsigned int ebda_start __read_only;
30810+static unsigned int ebda_end __read_only;
30811+#endif
30812+
30813 int devmem_is_allowed(unsigned long pagenr)
30814 {
30815- if (pagenr < 256)
30816+#ifdef CONFIG_GRKERNSEC_KMEM
30817+ /* allow BDA */
30818+ if (!pagenr)
30819 return 1;
30820+ /* allow EBDA */
30821+ if (pagenr >= ebda_start && pagenr < ebda_end)
30822+ return 1;
30823+ /* if tboot is in use, allow access to its hardcoded serial log range */
30824+ if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
30825+ return 1;
30826+#else
30827+ if (!pagenr)
30828+ return 1;
30829+#ifdef CONFIG_VM86
30830+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
30831+ return 1;
30832+#endif
30833+#endif
30834+
30835+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
30836+ return 1;
30837+#ifdef CONFIG_GRKERNSEC_KMEM
30838+ /* throw out everything else below 1MB */
30839+ if (pagenr <= 256)
30840+ return 0;
30841+#endif
30842 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
30843 return 0;
30844 if (!page_is_ram(pagenr))
30845@@ -530,8 +574,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
30846 #endif
30847 }
30848
30849+#ifdef CONFIG_GRKERNSEC_KMEM
30850+static inline void gr_init_ebda(void)
30851+{
30852+ unsigned int ebda_addr;
30853+ unsigned int ebda_size = 0;
30854+
30855+ ebda_addr = get_bios_ebda();
30856+ if (ebda_addr) {
30857+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
30858+ ebda_size <<= 10;
30859+ }
30860+ if (ebda_addr && ebda_size) {
30861+ ebda_start = ebda_addr >> PAGE_SHIFT;
30862+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
30863+ } else {
30864+ ebda_start = 0x9f000 >> PAGE_SHIFT;
30865+ ebda_end = 0xa0000 >> PAGE_SHIFT;
30866+ }
30867+}
30868+#else
30869+static inline void gr_init_ebda(void) { }
30870+#endif
30871+
30872 void free_initmem(void)
30873 {
30874+#ifdef CONFIG_PAX_KERNEXEC
30875+#ifdef CONFIG_X86_32
30876+ /* PaX: limit KERNEL_CS to actual size */
30877+ unsigned long addr, limit;
30878+ struct desc_struct d;
30879+ int cpu;
30880+#else
30881+ pgd_t *pgd;
30882+ pud_t *pud;
30883+ pmd_t *pmd;
30884+ unsigned long addr, end;
30885+#endif
30886+#endif
30887+
30888+ gr_init_ebda();
30889+
30890+#ifdef CONFIG_PAX_KERNEXEC
30891+#ifdef CONFIG_X86_32
30892+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
30893+ limit = (limit - 1UL) >> PAGE_SHIFT;
30894+
30895+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
30896+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
30897+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
30898+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
30899+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
30900+ }
30901+
30902+ /* PaX: make KERNEL_CS read-only */
30903+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
30904+ if (!paravirt_enabled())
30905+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
30906+/*
30907+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
30908+ pgd = pgd_offset_k(addr);
30909+ pud = pud_offset(pgd, addr);
30910+ pmd = pmd_offset(pud, addr);
30911+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
30912+ }
30913+*/
30914+#ifdef CONFIG_X86_PAE
30915+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
30916+/*
30917+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
30918+ pgd = pgd_offset_k(addr);
30919+ pud = pud_offset(pgd, addr);
30920+ pmd = pmd_offset(pud, addr);
30921+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
30922+ }
30923+*/
30924+#endif
30925+
30926+#ifdef CONFIG_MODULES
30927+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
30928+#endif
30929+
30930+#else
30931+ /* PaX: make kernel code/rodata read-only, rest non-executable */
30932+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
30933+ pgd = pgd_offset_k(addr);
30934+ pud = pud_offset(pgd, addr);
30935+ pmd = pmd_offset(pud, addr);
30936+ if (!pmd_present(*pmd))
30937+ continue;
30938+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
30939+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
30940+ else
30941+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
30942+ }
30943+
30944+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
30945+ end = addr + KERNEL_IMAGE_SIZE;
30946+ for (; addr < end; addr += PMD_SIZE) {
30947+ pgd = pgd_offset_k(addr);
30948+ pud = pud_offset(pgd, addr);
30949+ pmd = pmd_offset(pud, addr);
30950+ if (!pmd_present(*pmd))
30951+ continue;
30952+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
30953+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
30954+ }
30955+#endif
30956+
30957+ flush_tlb_all();
30958+#endif
30959+
30960 free_init_pages("unused kernel",
30961 (unsigned long)(&__init_begin),
30962 (unsigned long)(&__init_end));
30963diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
30964index 4287f1f..3b99c71 100644
30965--- a/arch/x86/mm/init_32.c
30966+++ b/arch/x86/mm/init_32.c
30967@@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
30968 bool __read_mostly __vmalloc_start_set = false;
30969
30970 /*
30971- * Creates a middle page table and puts a pointer to it in the
30972- * given global directory entry. This only returns the gd entry
30973- * in non-PAE compilation mode, since the middle layer is folded.
30974- */
30975-static pmd_t * __init one_md_table_init(pgd_t *pgd)
30976-{
30977- pud_t *pud;
30978- pmd_t *pmd_table;
30979-
30980-#ifdef CONFIG_X86_PAE
30981- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
30982- pmd_table = (pmd_t *)alloc_low_page();
30983- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
30984- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
30985- pud = pud_offset(pgd, 0);
30986- BUG_ON(pmd_table != pmd_offset(pud, 0));
30987-
30988- return pmd_table;
30989- }
30990-#endif
30991- pud = pud_offset(pgd, 0);
30992- pmd_table = pmd_offset(pud, 0);
30993-
30994- return pmd_table;
30995-}
30996-
30997-/*
30998 * Create a page table and place a pointer to it in a middle page
30999 * directory entry:
31000 */
31001@@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
31002 pte_t *page_table = (pte_t *)alloc_low_page();
31003
31004 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
31005+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31006+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
31007+#else
31008 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
31009+#endif
31010 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
31011 }
31012
31013 return pte_offset_kernel(pmd, 0);
31014 }
31015
31016+static pmd_t * __init one_md_table_init(pgd_t *pgd)
31017+{
31018+ pud_t *pud;
31019+ pmd_t *pmd_table;
31020+
31021+ pud = pud_offset(pgd, 0);
31022+ pmd_table = pmd_offset(pud, 0);
31023+
31024+ return pmd_table;
31025+}
31026+
31027 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
31028 {
31029 int pgd_idx = pgd_index(vaddr);
31030@@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
31031 int pgd_idx, pmd_idx;
31032 unsigned long vaddr;
31033 pgd_t *pgd;
31034+ pud_t *pud;
31035 pmd_t *pmd;
31036 pte_t *pte = NULL;
31037 unsigned long count = page_table_range_init_count(start, end);
31038@@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
31039 pgd = pgd_base + pgd_idx;
31040
31041 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
31042- pmd = one_md_table_init(pgd);
31043- pmd = pmd + pmd_index(vaddr);
31044+ pud = pud_offset(pgd, vaddr);
31045+ pmd = pmd_offset(pud, vaddr);
31046+
31047+#ifdef CONFIG_X86_PAE
31048+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
31049+#endif
31050+
31051 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
31052 pmd++, pmd_idx++) {
31053 pte = page_table_kmap_check(one_page_table_init(pmd),
31054@@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
31055 }
31056 }
31057
31058-static inline int is_kernel_text(unsigned long addr)
31059+static inline int is_kernel_text(unsigned long start, unsigned long end)
31060 {
31061- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
31062- return 1;
31063- return 0;
31064+ if ((start > ktla_ktva((unsigned long)_etext) ||
31065+ end <= ktla_ktva((unsigned long)_stext)) &&
31066+ (start > ktla_ktva((unsigned long)_einittext) ||
31067+ end <= ktla_ktva((unsigned long)_sinittext)) &&
31068+
31069+#ifdef CONFIG_ACPI_SLEEP
31070+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
31071+#endif
31072+
31073+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
31074+ return 0;
31075+ return 1;
31076 }
31077
31078 /*
31079@@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
31080 unsigned long last_map_addr = end;
31081 unsigned long start_pfn, end_pfn;
31082 pgd_t *pgd_base = swapper_pg_dir;
31083- int pgd_idx, pmd_idx, pte_ofs;
31084+ unsigned int pgd_idx, pmd_idx, pte_ofs;
31085 unsigned long pfn;
31086 pgd_t *pgd;
31087+ pud_t *pud;
31088 pmd_t *pmd;
31089 pte_t *pte;
31090 unsigned pages_2m, pages_4k;
31091@@ -291,8 +295,13 @@ repeat:
31092 pfn = start_pfn;
31093 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
31094 pgd = pgd_base + pgd_idx;
31095- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
31096- pmd = one_md_table_init(pgd);
31097+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
31098+ pud = pud_offset(pgd, 0);
31099+ pmd = pmd_offset(pud, 0);
31100+
31101+#ifdef CONFIG_X86_PAE
31102+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
31103+#endif
31104
31105 if (pfn >= end_pfn)
31106 continue;
31107@@ -304,14 +313,13 @@ repeat:
31108 #endif
31109 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
31110 pmd++, pmd_idx++) {
31111- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
31112+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
31113
31114 /*
31115 * Map with big pages if possible, otherwise
31116 * create normal page tables:
31117 */
31118 if (use_pse) {
31119- unsigned int addr2;
31120 pgprot_t prot = PAGE_KERNEL_LARGE;
31121 /*
31122 * first pass will use the same initial
31123@@ -322,11 +330,7 @@ repeat:
31124 _PAGE_PSE);
31125
31126 pfn &= PMD_MASK >> PAGE_SHIFT;
31127- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
31128- PAGE_OFFSET + PAGE_SIZE-1;
31129-
31130- if (is_kernel_text(addr) ||
31131- is_kernel_text(addr2))
31132+ if (is_kernel_text(address, address + PMD_SIZE))
31133 prot = PAGE_KERNEL_LARGE_EXEC;
31134
31135 pages_2m++;
31136@@ -343,7 +347,7 @@ repeat:
31137 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
31138 pte += pte_ofs;
31139 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
31140- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
31141+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
31142 pgprot_t prot = PAGE_KERNEL;
31143 /*
31144 * first pass will use the same initial
31145@@ -351,7 +355,7 @@ repeat:
31146 */
31147 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
31148
31149- if (is_kernel_text(addr))
31150+ if (is_kernel_text(address, address + PAGE_SIZE))
31151 prot = PAGE_KERNEL_EXEC;
31152
31153 pages_4k++;
31154@@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
31155
31156 pud = pud_offset(pgd, va);
31157 pmd = pmd_offset(pud, va);
31158- if (!pmd_present(*pmd))
31159+ if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
31160 break;
31161
31162 /* should not be large page here */
31163@@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
31164
31165 static void __init pagetable_init(void)
31166 {
31167- pgd_t *pgd_base = swapper_pg_dir;
31168-
31169- permanent_kmaps_init(pgd_base);
31170+ permanent_kmaps_init(swapper_pg_dir);
31171 }
31172
31173-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
31174+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
31175 EXPORT_SYMBOL_GPL(__supported_pte_mask);
31176
31177 /* user-defined highmem size */
31178@@ -787,10 +789,10 @@ void __init mem_init(void)
31179 ((unsigned long)&__init_end -
31180 (unsigned long)&__init_begin) >> 10,
31181
31182- (unsigned long)&_etext, (unsigned long)&_edata,
31183- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
31184+ (unsigned long)&_sdata, (unsigned long)&_edata,
31185+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
31186
31187- (unsigned long)&_text, (unsigned long)&_etext,
31188+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
31189 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
31190
31191 /*
31192@@ -880,6 +882,7 @@ void set_kernel_text_rw(void)
31193 if (!kernel_set_to_readonly)
31194 return;
31195
31196+ start = ktla_ktva(start);
31197 pr_debug("Set kernel text: %lx - %lx for read write\n",
31198 start, start+size);
31199
31200@@ -894,6 +897,7 @@ void set_kernel_text_ro(void)
31201 if (!kernel_set_to_readonly)
31202 return;
31203
31204+ start = ktla_ktva(start);
31205 pr_debug("Set kernel text: %lx - %lx for read only\n",
31206 start, start+size);
31207
31208@@ -922,6 +926,7 @@ void mark_rodata_ro(void)
31209 unsigned long start = PFN_ALIGN(_text);
31210 unsigned long size = PFN_ALIGN(_etext) - start;
31211
31212+ start = ktla_ktva(start);
31213 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
31214 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
31215 size >> 10);
31216diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
31217index 104d56a..62ba13f 100644
31218--- a/arch/x86/mm/init_64.c
31219+++ b/arch/x86/mm/init_64.c
31220@@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
31221 * around without checking the pgd every time.
31222 */
31223
31224-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
31225+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
31226 EXPORT_SYMBOL_GPL(__supported_pte_mask);
31227
31228 int force_personality32;
31229@@ -184,12 +184,29 @@ void sync_global_pgds(unsigned long start, unsigned long end)
31230
31231 for (address = start; address <= end; address += PGDIR_SIZE) {
31232 const pgd_t *pgd_ref = pgd_offset_k(address);
31233+
31234+#ifdef CONFIG_PAX_PER_CPU_PGD
31235+ unsigned long cpu;
31236+#else
31237 struct page *page;
31238+#endif
31239
31240 if (pgd_none(*pgd_ref))
31241 continue;
31242
31243 spin_lock(&pgd_lock);
31244+
31245+#ifdef CONFIG_PAX_PER_CPU_PGD
31246+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
31247+ pgd_t *pgd = pgd_offset_cpu(cpu, user, address);
31248+
31249+ if (pgd_none(*pgd))
31250+ set_pgd(pgd, *pgd_ref);
31251+ else
31252+ BUG_ON(pgd_page_vaddr(*pgd)
31253+ != pgd_page_vaddr(*pgd_ref));
31254+ pgd = pgd_offset_cpu(cpu, kernel, address);
31255+#else
31256 list_for_each_entry(page, &pgd_list, lru) {
31257 pgd_t *pgd;
31258 spinlock_t *pgt_lock;
31259@@ -198,6 +215,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
31260 /* the pgt_lock only for Xen */
31261 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
31262 spin_lock(pgt_lock);
31263+#endif
31264
31265 if (pgd_none(*pgd))
31266 set_pgd(pgd, *pgd_ref);
31267@@ -205,7 +223,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
31268 BUG_ON(pgd_page_vaddr(*pgd)
31269 != pgd_page_vaddr(*pgd_ref));
31270
31271+#ifndef CONFIG_PAX_PER_CPU_PGD
31272 spin_unlock(pgt_lock);
31273+#endif
31274+
31275 }
31276 spin_unlock(&pgd_lock);
31277 }
31278@@ -238,7 +259,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
31279 {
31280 if (pgd_none(*pgd)) {
31281 pud_t *pud = (pud_t *)spp_getpage();
31282- pgd_populate(&init_mm, pgd, pud);
31283+ pgd_populate_kernel(&init_mm, pgd, pud);
31284 if (pud != pud_offset(pgd, 0))
31285 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
31286 pud, pud_offset(pgd, 0));
31287@@ -250,7 +271,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
31288 {
31289 if (pud_none(*pud)) {
31290 pmd_t *pmd = (pmd_t *) spp_getpage();
31291- pud_populate(&init_mm, pud, pmd);
31292+ pud_populate_kernel(&init_mm, pud, pmd);
31293 if (pmd != pmd_offset(pud, 0))
31294 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
31295 pmd, pmd_offset(pud, 0));
31296@@ -279,7 +300,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
31297 pmd = fill_pmd(pud, vaddr);
31298 pte = fill_pte(pmd, vaddr);
31299
31300+ pax_open_kernel();
31301 set_pte(pte, new_pte);
31302+ pax_close_kernel();
31303
31304 /*
31305 * It's enough to flush this one mapping.
31306@@ -338,14 +361,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
31307 pgd = pgd_offset_k((unsigned long)__va(phys));
31308 if (pgd_none(*pgd)) {
31309 pud = (pud_t *) spp_getpage();
31310- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
31311- _PAGE_USER));
31312+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
31313 }
31314 pud = pud_offset(pgd, (unsigned long)__va(phys));
31315 if (pud_none(*pud)) {
31316 pmd = (pmd_t *) spp_getpage();
31317- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
31318- _PAGE_USER));
31319+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
31320 }
31321 pmd = pmd_offset(pud, phys);
31322 BUG_ON(!pmd_none(*pmd));
31323@@ -586,7 +607,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
31324 prot);
31325
31326 spin_lock(&init_mm.page_table_lock);
31327- pud_populate(&init_mm, pud, pmd);
31328+ pud_populate_kernel(&init_mm, pud, pmd);
31329 spin_unlock(&init_mm.page_table_lock);
31330 }
31331 __flush_tlb_all();
31332@@ -627,7 +648,7 @@ kernel_physical_mapping_init(unsigned long start,
31333 page_size_mask);
31334
31335 spin_lock(&init_mm.page_table_lock);
31336- pgd_populate(&init_mm, pgd, pud);
31337+ pgd_populate_kernel(&init_mm, pgd, pud);
31338 spin_unlock(&init_mm.page_table_lock);
31339 pgd_changed = true;
31340 }
31341@@ -1188,8 +1209,8 @@ int kern_addr_valid(unsigned long addr)
31342 static struct vm_area_struct gate_vma = {
31343 .vm_start = VSYSCALL_START,
31344 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
31345- .vm_page_prot = PAGE_READONLY_EXEC,
31346- .vm_flags = VM_READ | VM_EXEC
31347+ .vm_page_prot = PAGE_READONLY,
31348+ .vm_flags = VM_READ
31349 };
31350
31351 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
31352@@ -1223,7 +1244,7 @@ int in_gate_area_no_mm(unsigned long addr)
31353
31354 const char *arch_vma_name(struct vm_area_struct *vma)
31355 {
31356- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
31357+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
31358 return "[vdso]";
31359 if (vma == &gate_vma)
31360 return "[vsyscall]";
31361diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
31362index 7b179b4..6bd17777 100644
31363--- a/arch/x86/mm/iomap_32.c
31364+++ b/arch/x86/mm/iomap_32.c
31365@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
31366 type = kmap_atomic_idx_push();
31367 idx = type + KM_TYPE_NR * smp_processor_id();
31368 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
31369+
31370+ pax_open_kernel();
31371 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
31372+ pax_close_kernel();
31373+
31374 arch_flush_lazy_mmu_mode();
31375
31376 return (void *)vaddr;
31377diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
31378index 0215e2c..1c62dab 100644
31379--- a/arch/x86/mm/ioremap.c
31380+++ b/arch/x86/mm/ioremap.c
31381@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
31382 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
31383 int is_ram = page_is_ram(pfn);
31384
31385- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
31386+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
31387 return NULL;
31388 WARN_ON_ONCE(is_ram);
31389 }
31390@@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
31391 *
31392 * Caller must ensure there is only one unmapping for the same pointer.
31393 */
31394-void iounmap(volatile void __iomem *addr)
31395+void iounmap(const volatile void __iomem *addr)
31396 {
31397 struct vm_struct *p, *o;
31398
31399@@ -310,6 +310,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
31400
31401 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
31402 if (page_is_ram(start >> PAGE_SHIFT))
31403+#ifdef CONFIG_HIGHMEM
31404+ if ((start >> PAGE_SHIFT) < max_low_pfn)
31405+#endif
31406 return __va(phys);
31407
31408 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
31409@@ -322,6 +325,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
31410 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
31411 {
31412 if (page_is_ram(phys >> PAGE_SHIFT))
31413+#ifdef CONFIG_HIGHMEM
31414+ if ((phys >> PAGE_SHIFT) < max_low_pfn)
31415+#endif
31416 return;
31417
31418 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
31419@@ -339,7 +345,7 @@ static int __init early_ioremap_debug_setup(char *str)
31420 early_param("early_ioremap_debug", early_ioremap_debug_setup);
31421
31422 static __initdata int after_paging_init;
31423-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
31424+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
31425
31426 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
31427 {
31428@@ -376,8 +382,7 @@ void __init early_ioremap_init(void)
31429 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
31430
31431 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
31432- memset(bm_pte, 0, sizeof(bm_pte));
31433- pmd_populate_kernel(&init_mm, pmd, bm_pte);
31434+ pmd_populate_user(&init_mm, pmd, bm_pte);
31435
31436 /*
31437 * The boot-ioremap range spans multiple pmds, for which
31438diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
31439index d87dd6d..bf3fa66 100644
31440--- a/arch/x86/mm/kmemcheck/kmemcheck.c
31441+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
31442@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
31443 * memory (e.g. tracked pages)? For now, we need this to avoid
31444 * invoking kmemcheck for PnP BIOS calls.
31445 */
31446- if (regs->flags & X86_VM_MASK)
31447+ if (v8086_mode(regs))
31448 return false;
31449- if (regs->cs != __KERNEL_CS)
31450+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
31451 return false;
31452
31453 pte = kmemcheck_pte_lookup(address);
31454diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
31455index 25e7e13..1964579 100644
31456--- a/arch/x86/mm/mmap.c
31457+++ b/arch/x86/mm/mmap.c
31458@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
31459 * Leave an at least ~128 MB hole with possible stack randomization.
31460 */
31461 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
31462-#define MAX_GAP (TASK_SIZE/6*5)
31463+#define MAX_GAP (pax_task_size/6*5)
31464
31465 static int mmap_is_legacy(void)
31466 {
31467@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
31468 return rnd << PAGE_SHIFT;
31469 }
31470
31471-static unsigned long mmap_base(void)
31472+static unsigned long mmap_base(struct mm_struct *mm)
31473 {
31474 unsigned long gap = rlimit(RLIMIT_STACK);
31475+ unsigned long pax_task_size = TASK_SIZE;
31476+
31477+#ifdef CONFIG_PAX_SEGMEXEC
31478+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
31479+ pax_task_size = SEGMEXEC_TASK_SIZE;
31480+#endif
31481
31482 if (gap < MIN_GAP)
31483 gap = MIN_GAP;
31484 else if (gap > MAX_GAP)
31485 gap = MAX_GAP;
31486
31487- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
31488+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
31489 }
31490
31491 /*
31492 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
31493 * does, but not when emulating X86_32
31494 */
31495-static unsigned long mmap_legacy_base(void)
31496+static unsigned long mmap_legacy_base(struct mm_struct *mm)
31497 {
31498- if (mmap_is_ia32())
31499+ if (mmap_is_ia32()) {
31500+
31501+#ifdef CONFIG_PAX_SEGMEXEC
31502+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
31503+ return SEGMEXEC_TASK_UNMAPPED_BASE;
31504+ else
31505+#endif
31506+
31507 return TASK_UNMAPPED_BASE;
31508- else
31509+ } else
31510 return TASK_UNMAPPED_BASE + mmap_rnd();
31511 }
31512
31513@@ -112,8 +125,15 @@ static unsigned long mmap_legacy_base(void)
31514 */
31515 void arch_pick_mmap_layout(struct mm_struct *mm)
31516 {
31517- mm->mmap_legacy_base = mmap_legacy_base();
31518- mm->mmap_base = mmap_base();
31519+ mm->mmap_legacy_base = mmap_legacy_base(mm);
31520+ mm->mmap_base = mmap_base(mm);
31521+
31522+#ifdef CONFIG_PAX_RANDMMAP
31523+ if (mm->pax_flags & MF_PAX_RANDMMAP) {
31524+ mm->mmap_legacy_base += mm->delta_mmap;
31525+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
31526+ }
31527+#endif
31528
31529 if (mmap_is_legacy()) {
31530 mm->mmap_base = mm->mmap_legacy_base;
31531diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
31532index 0057a7a..95c7edd 100644
31533--- a/arch/x86/mm/mmio-mod.c
31534+++ b/arch/x86/mm/mmio-mod.c
31535@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
31536 break;
31537 default:
31538 {
31539- unsigned char *ip = (unsigned char *)instptr;
31540+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
31541 my_trace->opcode = MMIO_UNKNOWN_OP;
31542 my_trace->width = 0;
31543 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
31544@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
31545 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
31546 void __iomem *addr)
31547 {
31548- static atomic_t next_id;
31549+ static atomic_unchecked_t next_id;
31550 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
31551 /* These are page-unaligned. */
31552 struct mmiotrace_map map = {
31553@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
31554 .private = trace
31555 },
31556 .phys = offset,
31557- .id = atomic_inc_return(&next_id)
31558+ .id = atomic_inc_return_unchecked(&next_id)
31559 };
31560 map.map_id = trace->id;
31561
31562@@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
31563 ioremap_trace_core(offset, size, addr);
31564 }
31565
31566-static void iounmap_trace_core(volatile void __iomem *addr)
31567+static void iounmap_trace_core(const volatile void __iomem *addr)
31568 {
31569 struct mmiotrace_map map = {
31570 .phys = 0,
31571@@ -328,7 +328,7 @@ not_enabled:
31572 }
31573 }
31574
31575-void mmiotrace_iounmap(volatile void __iomem *addr)
31576+void mmiotrace_iounmap(const volatile void __iomem *addr)
31577 {
31578 might_sleep();
31579 if (is_enabled()) /* recheck and proper locking in *_core() */
31580diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
31581index 8bf93ba..dbcd670 100644
31582--- a/arch/x86/mm/numa.c
31583+++ b/arch/x86/mm/numa.c
31584@@ -474,7 +474,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
31585 return true;
31586 }
31587
31588-static int __init numa_register_memblks(struct numa_meminfo *mi)
31589+static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
31590 {
31591 unsigned long uninitialized_var(pfn_align);
31592 int i, nid;
31593diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
31594index d0b1773..4c3327c 100644
31595--- a/arch/x86/mm/pageattr-test.c
31596+++ b/arch/x86/mm/pageattr-test.c
31597@@ -36,7 +36,7 @@ enum {
31598
31599 static int pte_testbit(pte_t pte)
31600 {
31601- return pte_flags(pte) & _PAGE_UNUSED1;
31602+ return pte_flags(pte) & _PAGE_CPA_TEST;
31603 }
31604
31605 struct split_state {
31606diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
31607index bb32480..75f2f5e 100644
31608--- a/arch/x86/mm/pageattr.c
31609+++ b/arch/x86/mm/pageattr.c
31610@@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
31611 */
31612 #ifdef CONFIG_PCI_BIOS
31613 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
31614- pgprot_val(forbidden) |= _PAGE_NX;
31615+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
31616 #endif
31617
31618 /*
31619@@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
31620 * Does not cover __inittext since that is gone later on. On
31621 * 64bit we do not enforce !NX on the low mapping
31622 */
31623- if (within(address, (unsigned long)_text, (unsigned long)_etext))
31624- pgprot_val(forbidden) |= _PAGE_NX;
31625+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
31626+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
31627
31628+#ifdef CONFIG_DEBUG_RODATA
31629 /*
31630 * The .rodata section needs to be read-only. Using the pfn
31631 * catches all aliases.
31632@@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
31633 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
31634 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
31635 pgprot_val(forbidden) |= _PAGE_RW;
31636+#endif
31637
31638 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
31639 /*
31640@@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
31641 }
31642 #endif
31643
31644+#ifdef CONFIG_PAX_KERNEXEC
31645+ if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
31646+ pgprot_val(forbidden) |= _PAGE_RW;
31647+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
31648+ }
31649+#endif
31650+
31651 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
31652
31653 return prot;
31654@@ -400,23 +409,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
31655 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
31656 {
31657 /* change init_mm */
31658+ pax_open_kernel();
31659 set_pte_atomic(kpte, pte);
31660+
31661 #ifdef CONFIG_X86_32
31662 if (!SHARED_KERNEL_PMD) {
31663+
31664+#ifdef CONFIG_PAX_PER_CPU_PGD
31665+ unsigned long cpu;
31666+#else
31667 struct page *page;
31668+#endif
31669
31670+#ifdef CONFIG_PAX_PER_CPU_PGD
31671+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
31672+ pgd_t *pgd = get_cpu_pgd(cpu, kernel);
31673+#else
31674 list_for_each_entry(page, &pgd_list, lru) {
31675- pgd_t *pgd;
31676+ pgd_t *pgd = (pgd_t *)page_address(page);
31677+#endif
31678+
31679 pud_t *pud;
31680 pmd_t *pmd;
31681
31682- pgd = (pgd_t *)page_address(page) + pgd_index(address);
31683+ pgd += pgd_index(address);
31684 pud = pud_offset(pgd, address);
31685 pmd = pmd_offset(pud, address);
31686 set_pte_atomic((pte_t *)pmd, pte);
31687 }
31688 }
31689 #endif
31690+ pax_close_kernel();
31691 }
31692
31693 static int
31694diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
31695index 6574388..87e9bef 100644
31696--- a/arch/x86/mm/pat.c
31697+++ b/arch/x86/mm/pat.c
31698@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
31699
31700 if (!entry) {
31701 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
31702- current->comm, current->pid, start, end - 1);
31703+ current->comm, task_pid_nr(current), start, end - 1);
31704 return -EINVAL;
31705 }
31706
31707@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31708
31709 while (cursor < to) {
31710 if (!devmem_is_allowed(pfn)) {
31711- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
31712- current->comm, from, to - 1);
31713+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
31714+ current->comm, from, to - 1, cursor);
31715 return 0;
31716 }
31717 cursor += PAGE_SIZE;
31718@@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
31719 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
31720 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
31721 "for [mem %#010Lx-%#010Lx]\n",
31722- current->comm, current->pid,
31723+ current->comm, task_pid_nr(current),
31724 cattr_name(flags),
31725 base, (unsigned long long)(base + size-1));
31726 return -EINVAL;
31727@@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
31728 flags = lookup_memtype(paddr);
31729 if (want_flags != flags) {
31730 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
31731- current->comm, current->pid,
31732+ current->comm, task_pid_nr(current),
31733 cattr_name(want_flags),
31734 (unsigned long long)paddr,
31735 (unsigned long long)(paddr + size - 1),
31736@@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
31737 free_memtype(paddr, paddr + size);
31738 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
31739 " for [mem %#010Lx-%#010Lx], got %s\n",
31740- current->comm, current->pid,
31741+ current->comm, task_pid_nr(current),
31742 cattr_name(want_flags),
31743 (unsigned long long)paddr,
31744 (unsigned long long)(paddr + size - 1),
31745diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
31746index 415f6c4..d319983 100644
31747--- a/arch/x86/mm/pat_rbtree.c
31748+++ b/arch/x86/mm/pat_rbtree.c
31749@@ -160,7 +160,7 @@ success:
31750
31751 failure:
31752 printk(KERN_INFO "%s:%d conflicting memory types "
31753- "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
31754+ "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
31755 end, cattr_name(found_type), cattr_name(match->type));
31756 return -EBUSY;
31757 }
31758diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
31759index 9f0614d..92ae64a 100644
31760--- a/arch/x86/mm/pf_in.c
31761+++ b/arch/x86/mm/pf_in.c
31762@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
31763 int i;
31764 enum reason_type rv = OTHERS;
31765
31766- p = (unsigned char *)ins_addr;
31767+ p = (unsigned char *)ktla_ktva(ins_addr);
31768 p += skip_prefix(p, &prf);
31769 p += get_opcode(p, &opcode);
31770
31771@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
31772 struct prefix_bits prf;
31773 int i;
31774
31775- p = (unsigned char *)ins_addr;
31776+ p = (unsigned char *)ktla_ktva(ins_addr);
31777 p += skip_prefix(p, &prf);
31778 p += get_opcode(p, &opcode);
31779
31780@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
31781 struct prefix_bits prf;
31782 int i;
31783
31784- p = (unsigned char *)ins_addr;
31785+ p = (unsigned char *)ktla_ktva(ins_addr);
31786 p += skip_prefix(p, &prf);
31787 p += get_opcode(p, &opcode);
31788
31789@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
31790 struct prefix_bits prf;
31791 int i;
31792
31793- p = (unsigned char *)ins_addr;
31794+ p = (unsigned char *)ktla_ktva(ins_addr);
31795 p += skip_prefix(p, &prf);
31796 p += get_opcode(p, &opcode);
31797 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
31798@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
31799 struct prefix_bits prf;
31800 int i;
31801
31802- p = (unsigned char *)ins_addr;
31803+ p = (unsigned char *)ktla_ktva(ins_addr);
31804 p += skip_prefix(p, &prf);
31805 p += get_opcode(p, &opcode);
31806 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
31807diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
31808index dfa537a..fd45c64 100644
31809--- a/arch/x86/mm/pgtable.c
31810+++ b/arch/x86/mm/pgtable.c
31811@@ -91,10 +91,67 @@ static inline void pgd_list_del(pgd_t *pgd)
31812 list_del(&page->lru);
31813 }
31814
31815-#define UNSHARED_PTRS_PER_PGD \
31816- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
31817+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31818+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
31819
31820+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
31821+{
31822+ unsigned int count = USER_PGD_PTRS;
31823
31824+ if (!pax_user_shadow_base)
31825+ return;
31826+
31827+ while (count--)
31828+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
31829+}
31830+#endif
31831+
31832+#ifdef CONFIG_PAX_PER_CPU_PGD
31833+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
31834+{
31835+ unsigned int count = USER_PGD_PTRS;
31836+
31837+ while (count--) {
31838+ pgd_t pgd;
31839+
31840+#ifdef CONFIG_X86_64
31841+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
31842+#else
31843+ pgd = *src++;
31844+#endif
31845+
31846+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31847+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
31848+#endif
31849+
31850+ *dst++ = pgd;
31851+ }
31852+
31853+}
31854+#endif
31855+
31856+#ifdef CONFIG_X86_64
31857+#define pxd_t pud_t
31858+#define pyd_t pgd_t
31859+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
31860+#define pxd_free(mm, pud) pud_free((mm), (pud))
31861+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
31862+#define pyd_offset(mm, address) pgd_offset((mm), (address))
31863+#define PYD_SIZE PGDIR_SIZE
31864+#else
31865+#define pxd_t pmd_t
31866+#define pyd_t pud_t
31867+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
31868+#define pxd_free(mm, pud) pmd_free((mm), (pud))
31869+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
31870+#define pyd_offset(mm, address) pud_offset((mm), (address))
31871+#define PYD_SIZE PUD_SIZE
31872+#endif
31873+
31874+#ifdef CONFIG_PAX_PER_CPU_PGD
31875+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
31876+static inline void pgd_dtor(pgd_t *pgd) {}
31877+#else
31878 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
31879 {
31880 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
31881@@ -135,6 +192,7 @@ static void pgd_dtor(pgd_t *pgd)
31882 pgd_list_del(pgd);
31883 spin_unlock(&pgd_lock);
31884 }
31885+#endif
31886
31887 /*
31888 * List of all pgd's needed for non-PAE so it can invalidate entries
31889@@ -147,7 +205,7 @@ static void pgd_dtor(pgd_t *pgd)
31890 * -- nyc
31891 */
31892
31893-#ifdef CONFIG_X86_PAE
31894+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
31895 /*
31896 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
31897 * updating the top-level pagetable entries to guarantee the
31898@@ -159,7 +217,7 @@ static void pgd_dtor(pgd_t *pgd)
31899 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
31900 * and initialize the kernel pmds here.
31901 */
31902-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
31903+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
31904
31905 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
31906 {
31907@@ -177,36 +235,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
31908 */
31909 flush_tlb_mm(mm);
31910 }
31911+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
31912+#define PREALLOCATED_PXDS USER_PGD_PTRS
31913 #else /* !CONFIG_X86_PAE */
31914
31915 /* No need to prepopulate any pagetable entries in non-PAE modes. */
31916-#define PREALLOCATED_PMDS 0
31917+#define PREALLOCATED_PXDS 0
31918
31919 #endif /* CONFIG_X86_PAE */
31920
31921-static void free_pmds(pmd_t *pmds[])
31922+static void free_pxds(pxd_t *pxds[])
31923 {
31924 int i;
31925
31926- for(i = 0; i < PREALLOCATED_PMDS; i++)
31927- if (pmds[i])
31928- free_page((unsigned long)pmds[i]);
31929+ for(i = 0; i < PREALLOCATED_PXDS; i++)
31930+ if (pxds[i])
31931+ free_page((unsigned long)pxds[i]);
31932 }
31933
31934-static int preallocate_pmds(pmd_t *pmds[])
31935+static int preallocate_pxds(pxd_t *pxds[])
31936 {
31937 int i;
31938 bool failed = false;
31939
31940- for(i = 0; i < PREALLOCATED_PMDS; i++) {
31941- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
31942- if (pmd == NULL)
31943+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
31944+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
31945+ if (pxd == NULL)
31946 failed = true;
31947- pmds[i] = pmd;
31948+ pxds[i] = pxd;
31949 }
31950
31951 if (failed) {
31952- free_pmds(pmds);
31953+ free_pxds(pxds);
31954 return -ENOMEM;
31955 }
31956
31957@@ -219,49 +279,52 @@ static int preallocate_pmds(pmd_t *pmds[])
31958 * preallocate which never got a corresponding vma will need to be
31959 * freed manually.
31960 */
31961-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
31962+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
31963 {
31964 int i;
31965
31966- for(i = 0; i < PREALLOCATED_PMDS; i++) {
31967+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
31968 pgd_t pgd = pgdp[i];
31969
31970 if (pgd_val(pgd) != 0) {
31971- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
31972+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
31973
31974- pgdp[i] = native_make_pgd(0);
31975+ set_pgd(pgdp + i, native_make_pgd(0));
31976
31977- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
31978- pmd_free(mm, pmd);
31979+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
31980+ pxd_free(mm, pxd);
31981 }
31982 }
31983 }
31984
31985-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
31986+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
31987 {
31988- pud_t *pud;
31989+ pyd_t *pyd;
31990 int i;
31991
31992- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
31993+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
31994 return;
31995
31996- pud = pud_offset(pgd, 0);
31997-
31998- for (i = 0; i < PREALLOCATED_PMDS; i++, pud++) {
31999- pmd_t *pmd = pmds[i];
32000+#ifdef CONFIG_X86_64
32001+ pyd = pyd_offset(mm, 0L);
32002+#else
32003+ pyd = pyd_offset(pgd, 0L);
32004+#endif
32005
32006+ for (i = 0; i < PREALLOCATED_PXDS; i++, pyd++) {
32007+ pxd_t *pxd = pxds[i];
32008 if (i >= KERNEL_PGD_BOUNDARY)
32009- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
32010- sizeof(pmd_t) * PTRS_PER_PMD);
32011+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
32012+ sizeof(pxd_t) * PTRS_PER_PMD);
32013
32014- pud_populate(mm, pud, pmd);
32015+ pyd_populate(mm, pyd, pxd);
32016 }
32017 }
32018
32019 pgd_t *pgd_alloc(struct mm_struct *mm)
32020 {
32021 pgd_t *pgd;
32022- pmd_t *pmds[PREALLOCATED_PMDS];
32023+ pxd_t *pxds[PREALLOCATED_PXDS];
32024
32025 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
32026
32027@@ -270,11 +333,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
32028
32029 mm->pgd = pgd;
32030
32031- if (preallocate_pmds(pmds) != 0)
32032+ if (preallocate_pxds(pxds) != 0)
32033 goto out_free_pgd;
32034
32035 if (paravirt_pgd_alloc(mm) != 0)
32036- goto out_free_pmds;
32037+ goto out_free_pxds;
32038
32039 /*
32040 * Make sure that pre-populating the pmds is atomic with
32041@@ -284,14 +347,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
32042 spin_lock(&pgd_lock);
32043
32044 pgd_ctor(mm, pgd);
32045- pgd_prepopulate_pmd(mm, pgd, pmds);
32046+ pgd_prepopulate_pxd(mm, pgd, pxds);
32047
32048 spin_unlock(&pgd_lock);
32049
32050 return pgd;
32051
32052-out_free_pmds:
32053- free_pmds(pmds);
32054+out_free_pxds:
32055+ free_pxds(pxds);
32056 out_free_pgd:
32057 free_page((unsigned long)pgd);
32058 out:
32059@@ -300,7 +363,7 @@ out:
32060
32061 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
32062 {
32063- pgd_mop_up_pmds(mm, pgd);
32064+ pgd_mop_up_pxds(mm, pgd);
32065 pgd_dtor(pgd);
32066 paravirt_pgd_free(mm, pgd);
32067 free_page((unsigned long)pgd);
32068diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
32069index a69bcb8..19068ab 100644
32070--- a/arch/x86/mm/pgtable_32.c
32071+++ b/arch/x86/mm/pgtable_32.c
32072@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
32073 return;
32074 }
32075 pte = pte_offset_kernel(pmd, vaddr);
32076+
32077+ pax_open_kernel();
32078 if (pte_val(pteval))
32079 set_pte_at(&init_mm, vaddr, pte, pteval);
32080 else
32081 pte_clear(&init_mm, vaddr, pte);
32082+ pax_close_kernel();
32083
32084 /*
32085 * It's enough to flush this one mapping.
32086diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
32087index e666cbb..61788c45 100644
32088--- a/arch/x86/mm/physaddr.c
32089+++ b/arch/x86/mm/physaddr.c
32090@@ -10,7 +10,7 @@
32091 #ifdef CONFIG_X86_64
32092
32093 #ifdef CONFIG_DEBUG_VIRTUAL
32094-unsigned long __phys_addr(unsigned long x)
32095+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
32096 {
32097 unsigned long y = x - __START_KERNEL_map;
32098
32099@@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
32100 #else
32101
32102 #ifdef CONFIG_DEBUG_VIRTUAL
32103-unsigned long __phys_addr(unsigned long x)
32104+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
32105 {
32106 unsigned long phys_addr = x - PAGE_OFFSET;
32107 /* VMALLOC_* aren't constants */
32108diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
32109index 90555bf..f5f1828 100644
32110--- a/arch/x86/mm/setup_nx.c
32111+++ b/arch/x86/mm/setup_nx.c
32112@@ -5,8 +5,10 @@
32113 #include <asm/pgtable.h>
32114 #include <asm/proto.h>
32115
32116+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
32117 static int disable_nx;
32118
32119+#ifndef CONFIG_PAX_PAGEEXEC
32120 /*
32121 * noexec = on|off
32122 *
32123@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
32124 return 0;
32125 }
32126 early_param("noexec", noexec_setup);
32127+#endif
32128+
32129+#endif
32130
32131 void x86_configure_nx(void)
32132 {
32133+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
32134 if (cpu_has_nx && !disable_nx)
32135 __supported_pte_mask |= _PAGE_NX;
32136 else
32137+#endif
32138 __supported_pte_mask &= ~_PAGE_NX;
32139 }
32140
32141diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
32142index 282375f..e03a98f 100644
32143--- a/arch/x86/mm/tlb.c
32144+++ b/arch/x86/mm/tlb.c
32145@@ -48,7 +48,11 @@ void leave_mm(int cpu)
32146 BUG();
32147 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
32148 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
32149+
32150+#ifndef CONFIG_PAX_PER_CPU_PGD
32151 load_cr3(swapper_pg_dir);
32152+#endif
32153+
32154 }
32155 }
32156 EXPORT_SYMBOL_GPL(leave_mm);
32157diff --git a/arch/x86/mm/uderef_64.c b/arch/x86/mm/uderef_64.c
32158new file mode 100644
32159index 0000000..dace51c
32160--- /dev/null
32161+++ b/arch/x86/mm/uderef_64.c
32162@@ -0,0 +1,37 @@
32163+#include <linux/mm.h>
32164+#include <asm/pgtable.h>
32165+#include <asm/uaccess.h>
32166+
32167+#ifdef CONFIG_PAX_MEMORY_UDEREF
32168+/* PaX: due to the special call convention these functions must
32169+ * - remain leaf functions under all configurations,
32170+ * - never be called directly, only dereferenced from the wrappers.
32171+ */
32172+void __pax_open_userland(void)
32173+{
32174+ unsigned int cpu;
32175+
32176+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
32177+ return;
32178+
32179+ cpu = raw_get_cpu();
32180+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_KERNEL);
32181+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
32182+ raw_put_cpu_no_resched();
32183+}
32184+EXPORT_SYMBOL(__pax_open_userland);
32185+
32186+void __pax_close_userland(void)
32187+{
32188+ unsigned int cpu;
32189+
32190+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
32191+ return;
32192+
32193+ cpu = raw_get_cpu();
32194+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_USER);
32195+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
32196+ raw_put_cpu_no_resched();
32197+}
32198+EXPORT_SYMBOL(__pax_close_userland);
32199+#endif
32200diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
32201index 877b9a1..a8ecf42 100644
32202--- a/arch/x86/net/bpf_jit.S
32203+++ b/arch/x86/net/bpf_jit.S
32204@@ -9,6 +9,7 @@
32205 */
32206 #include <linux/linkage.h>
32207 #include <asm/dwarf2.h>
32208+#include <asm/alternative-asm.h>
32209
32210 /*
32211 * Calling convention :
32212@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
32213 jle bpf_slow_path_word
32214 mov (SKBDATA,%rsi),%eax
32215 bswap %eax /* ntohl() */
32216+ pax_force_retaddr
32217 ret
32218
32219 sk_load_half:
32220@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
32221 jle bpf_slow_path_half
32222 movzwl (SKBDATA,%rsi),%eax
32223 rol $8,%ax # ntohs()
32224+ pax_force_retaddr
32225 ret
32226
32227 sk_load_byte:
32228@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
32229 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
32230 jle bpf_slow_path_byte
32231 movzbl (SKBDATA,%rsi),%eax
32232+ pax_force_retaddr
32233 ret
32234
32235 /**
32236@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
32237 movzbl (SKBDATA,%rsi),%ebx
32238 and $15,%bl
32239 shl $2,%bl
32240+ pax_force_retaddr
32241 ret
32242
32243 /* rsi contains offset and can be scratched */
32244@@ -109,6 +114,7 @@ bpf_slow_path_word:
32245 js bpf_error
32246 mov -12(%rbp),%eax
32247 bswap %eax
32248+ pax_force_retaddr
32249 ret
32250
32251 bpf_slow_path_half:
32252@@ -117,12 +123,14 @@ bpf_slow_path_half:
32253 mov -12(%rbp),%ax
32254 rol $8,%ax
32255 movzwl %ax,%eax
32256+ pax_force_retaddr
32257 ret
32258
32259 bpf_slow_path_byte:
32260 bpf_slow_path_common(1)
32261 js bpf_error
32262 movzbl -12(%rbp),%eax
32263+ pax_force_retaddr
32264 ret
32265
32266 bpf_slow_path_byte_msh:
32267@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
32268 and $15,%al
32269 shl $2,%al
32270 xchg %eax,%ebx
32271+ pax_force_retaddr
32272 ret
32273
32274 #define sk_negative_common(SIZE) \
32275@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
32276 sk_negative_common(4)
32277 mov (%rax), %eax
32278 bswap %eax
32279+ pax_force_retaddr
32280 ret
32281
32282 bpf_slow_path_half_neg:
32283@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
32284 mov (%rax),%ax
32285 rol $8,%ax
32286 movzwl %ax,%eax
32287+ pax_force_retaddr
32288 ret
32289
32290 bpf_slow_path_byte_neg:
32291@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
32292 .globl sk_load_byte_negative_offset
32293 sk_negative_common(1)
32294 movzbl (%rax), %eax
32295+ pax_force_retaddr
32296 ret
32297
32298 bpf_slow_path_byte_msh_neg:
32299@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
32300 and $15,%al
32301 shl $2,%al
32302 xchg %eax,%ebx
32303+ pax_force_retaddr
32304 ret
32305
32306 bpf_error:
32307@@ -197,4 +210,5 @@ bpf_error:
32308 xor %eax,%eax
32309 mov -8(%rbp),%rbx
32310 leaveq
32311+ pax_force_retaddr
32312 ret
32313diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
32314index 79c216a..08d39cc 100644
32315--- a/arch/x86/net/bpf_jit_comp.c
32316+++ b/arch/x86/net/bpf_jit_comp.c
32317@@ -50,13 +50,90 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
32318 return ptr + len;
32319 }
32320
32321+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32322+#define MAX_INSTR_CODE_SIZE 96
32323+#else
32324+#define MAX_INSTR_CODE_SIZE 64
32325+#endif
32326+
32327 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
32328
32329 #define EMIT1(b1) EMIT(b1, 1)
32330 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
32331 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
32332 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
32333+
32334+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32335+/* original constant will appear in ecx */
32336+#define DILUTE_CONST_SEQUENCE(_off, _key) \
32337+do { \
32338+ /* mov ecx, randkey */ \
32339+ EMIT1(0xb9); \
32340+ EMIT(_key, 4); \
32341+ /* xor ecx, randkey ^ off */ \
32342+ EMIT2(0x81, 0xf1); \
32343+ EMIT((_key) ^ (_off), 4); \
32344+} while (0)
32345+
32346+#define EMIT1_off32(b1, _off) \
32347+do { \
32348+ switch (b1) { \
32349+ case 0x05: /* add eax, imm32 */ \
32350+ case 0x2d: /* sub eax, imm32 */ \
32351+ case 0x25: /* and eax, imm32 */ \
32352+ case 0x0d: /* or eax, imm32 */ \
32353+ case 0xb8: /* mov eax, imm32 */ \
32354+ case 0x35: /* xor eax, imm32 */ \
32355+ case 0x3d: /* cmp eax, imm32 */ \
32356+ case 0xa9: /* test eax, imm32 */ \
32357+ DILUTE_CONST_SEQUENCE(_off, randkey); \
32358+ EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
32359+ break; \
32360+ case 0xbb: /* mov ebx, imm32 */ \
32361+ DILUTE_CONST_SEQUENCE(_off, randkey); \
32362+ /* mov ebx, ecx */ \
32363+ EMIT2(0x89, 0xcb); \
32364+ break; \
32365+ case 0xbe: /* mov esi, imm32 */ \
32366+ DILUTE_CONST_SEQUENCE(_off, randkey); \
32367+ /* mov esi, ecx */ \
32368+ EMIT2(0x89, 0xce); \
32369+ break; \
32370+ case 0xe8: /* call rel imm32, always to known funcs */ \
32371+ EMIT1(b1); \
32372+ EMIT(_off, 4); \
32373+ break; \
32374+ case 0xe9: /* jmp rel imm32 */ \
32375+ EMIT1(b1); \
32376+ EMIT(_off, 4); \
32377+ /* prevent fall-through, we're not called if off = 0 */ \
32378+ EMIT(0xcccccccc, 4); \
32379+ EMIT(0xcccccccc, 4); \
32380+ break; \
32381+ default: \
32382+ BUILD_BUG(); \
32383+ } \
32384+} while (0)
32385+
32386+#define EMIT2_off32(b1, b2, _off) \
32387+do { \
32388+ if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
32389+ EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
32390+ EMIT(randkey, 4); \
32391+ EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
32392+ EMIT((_off) - randkey, 4); \
32393+ } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
32394+ DILUTE_CONST_SEQUENCE(_off, randkey); \
32395+ /* imul eax, ecx */ \
32396+ EMIT3(0x0f, 0xaf, 0xc1); \
32397+ } else { \
32398+ BUILD_BUG(); \
32399+ } \
32400+} while (0)
32401+#else
32402 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
32403+#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
32404+#endif
32405
32406 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
32407 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
32408@@ -91,6 +168,24 @@ do { \
32409 #define X86_JBE 0x76
32410 #define X86_JA 0x77
32411
32412+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32413+#define APPEND_FLOW_VERIFY() \
32414+do { \
32415+ /* mov ecx, randkey */ \
32416+ EMIT1(0xb9); \
32417+ EMIT(randkey, 4); \
32418+ /* cmp ecx, randkey */ \
32419+ EMIT2(0x81, 0xf9); \
32420+ EMIT(randkey, 4); \
32421+ /* jz after 8 int 3s */ \
32422+ EMIT2(0x74, 0x08); \
32423+ EMIT(0xcccccccc, 4); \
32424+ EMIT(0xcccccccc, 4); \
32425+} while (0)
32426+#else
32427+#define APPEND_FLOW_VERIFY() do { } while (0)
32428+#endif
32429+
32430 #define EMIT_COND_JMP(op, offset) \
32431 do { \
32432 if (is_near(offset)) \
32433@@ -98,6 +193,7 @@ do { \
32434 else { \
32435 EMIT2(0x0f, op + 0x10); \
32436 EMIT(offset, 4); /* jxx .+off32 */ \
32437+ APPEND_FLOW_VERIFY(); \
32438 } \
32439 } while (0)
32440
32441@@ -145,55 +241,54 @@ static int pkt_type_offset(void)
32442 return -1;
32443 }
32444
32445-struct bpf_binary_header {
32446- unsigned int pages;
32447- /* Note : for security reasons, bpf code will follow a randomly
32448- * sized amount of int3 instructions
32449- */
32450- u8 image[];
32451-};
32452-
32453-static struct bpf_binary_header *bpf_alloc_binary(unsigned int proglen,
32454+/* Note : for security reasons, bpf code will follow a randomly
32455+ * sized amount of int3 instructions
32456+ */
32457+static u8 *bpf_alloc_binary(unsigned int proglen,
32458 u8 **image_ptr)
32459 {
32460 unsigned int sz, hole;
32461- struct bpf_binary_header *header;
32462+ u8 *header;
32463
32464 /* Most of BPF filters are really small,
32465 * but if some of them fill a page, allow at least
32466 * 128 extra bytes to insert a random section of int3
32467 */
32468- sz = round_up(proglen + sizeof(*header) + 128, PAGE_SIZE);
32469- header = module_alloc(sz);
32470+ sz = round_up(proglen + 128, PAGE_SIZE);
32471+ header = module_alloc_exec(sz);
32472 if (!header)
32473 return NULL;
32474
32475+ pax_open_kernel();
32476 memset(header, 0xcc, sz); /* fill whole space with int3 instructions */
32477+ pax_close_kernel();
32478
32479- header->pages = sz / PAGE_SIZE;
32480- hole = sz - (proglen + sizeof(*header));
32481+ hole = PAGE_SIZE - (proglen & ~PAGE_MASK);
32482
32483 /* insert a random number of int3 instructions before BPF code */
32484- *image_ptr = &header->image[prandom_u32() % hole];
32485+ *image_ptr = &header[prandom_u32() % hole];
32486 return header;
32487 }
32488
32489 void bpf_jit_compile(struct sk_filter *fp)
32490 {
32491- u8 temp[64];
32492+ u8 temp[MAX_INSTR_CODE_SIZE];
32493 u8 *prog;
32494 unsigned int proglen, oldproglen = 0;
32495 int ilen, i;
32496 int t_offset, f_offset;
32497 u8 t_op, f_op, seen = 0, pass;
32498 u8 *image = NULL;
32499- struct bpf_binary_header *header = NULL;
32500+ u8 *header = NULL;
32501 u8 *func;
32502 int pc_ret0 = -1; /* bpf index of first RET #0 instruction (if any) */
32503 unsigned int cleanup_addr; /* epilogue code offset */
32504 unsigned int *addrs;
32505 const struct sock_filter *filter = fp->insns;
32506 int flen = fp->len;
32507+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32508+ unsigned int randkey;
32509+#endif
32510
32511 if (!bpf_jit_enable)
32512 return;
32513@@ -202,11 +297,15 @@ void bpf_jit_compile(struct sk_filter *fp)
32514 if (addrs == NULL)
32515 return;
32516
32517+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32518+ randkey = get_random_int();
32519+#endif
32520+
32521 /* Before first pass, make a rough estimation of addrs[]
32522- * each bpf instruction is translated to less than 64 bytes
32523+ * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
32524 */
32525 for (proglen = 0, i = 0; i < flen; i++) {
32526- proglen += 64;
32527+ proglen += MAX_INSTR_CODE_SIZE;
32528 addrs[i] = proglen;
32529 }
32530 cleanup_addr = proglen; /* epilogue address */
32531@@ -317,10 +416,8 @@ void bpf_jit_compile(struct sk_filter *fp)
32532 case BPF_S_ALU_MUL_K: /* A *= K */
32533 if (is_imm8(K))
32534 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
32535- else {
32536- EMIT2(0x69, 0xc0); /* imul imm32,%eax */
32537- EMIT(K, 4);
32538- }
32539+ else
32540+ EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
32541 break;
32542 case BPF_S_ALU_DIV_X: /* A /= X; */
32543 seen |= SEEN_XREG;
32544@@ -360,13 +457,23 @@ void bpf_jit_compile(struct sk_filter *fp)
32545 break;
32546 case BPF_S_ALU_MOD_K: /* A %= K; */
32547 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
32548+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32549+ DILUTE_CONST_SEQUENCE(K, randkey);
32550+#else
32551 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
32552+#endif
32553 EMIT2(0xf7, 0xf1); /* div %ecx */
32554 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
32555 break;
32556 case BPF_S_ALU_DIV_K: /* A = reciprocal_divide(A, K); */
32557+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32558+ DILUTE_CONST_SEQUENCE(K, randkey);
32559+ // imul rax, rcx
32560+ EMIT4(0x48, 0x0f, 0xaf, 0xc1);
32561+#else
32562 EMIT3(0x48, 0x69, 0xc0); /* imul imm32,%rax,%rax */
32563 EMIT(K, 4);
32564+#endif
32565 EMIT4(0x48, 0xc1, 0xe8, 0x20); /* shr $0x20,%rax */
32566 break;
32567 case BPF_S_ALU_AND_X:
32568@@ -637,8 +744,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
32569 if (is_imm8(K)) {
32570 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
32571 } else {
32572- EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
32573- EMIT(K, 4);
32574+ EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
32575 }
32576 } else {
32577 EMIT2(0x89,0xde); /* mov %ebx,%esi */
32578@@ -728,10 +834,12 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
32579 if (unlikely(proglen + ilen > oldproglen)) {
32580 pr_err("bpb_jit_compile fatal error\n");
32581 kfree(addrs);
32582- module_free(NULL, header);
32583+ module_free_exec(NULL, image);
32584 return;
32585 }
32586+ pax_open_kernel();
32587 memcpy(image + proglen, temp, ilen);
32588+ pax_close_kernel();
32589 }
32590 proglen += ilen;
32591 addrs[i] = proglen;
32592@@ -764,7 +872,6 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
32593
32594 if (image) {
32595 bpf_flush_icache(header, image + proglen);
32596- set_memory_ro((unsigned long)header, header->pages);
32597 fp->bpf_func = (void *)image;
32598 }
32599 out:
32600@@ -776,9 +883,7 @@ void bpf_jit_free(struct sk_filter *fp)
32601 {
32602 if (fp->bpf_func != sk_run_filter) {
32603 unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
32604- struct bpf_binary_header *header = (void *)addr;
32605-
32606- set_memory_rw(addr, header->pages);
32607- module_free(NULL, header);
32608+ set_memory_rw(addr, 1);
32609+ module_free_exec(NULL, (void *)addr);
32610 }
32611 }
32612diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
32613index d6aa6e8..266395a 100644
32614--- a/arch/x86/oprofile/backtrace.c
32615+++ b/arch/x86/oprofile/backtrace.c
32616@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
32617 struct stack_frame_ia32 *fp;
32618 unsigned long bytes;
32619
32620- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
32621+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
32622 if (bytes != sizeof(bufhead))
32623 return NULL;
32624
32625- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
32626+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
32627
32628 oprofile_add_trace(bufhead[0].return_address);
32629
32630@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
32631 struct stack_frame bufhead[2];
32632 unsigned long bytes;
32633
32634- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
32635+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
32636 if (bytes != sizeof(bufhead))
32637 return NULL;
32638
32639@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
32640 {
32641 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
32642
32643- if (!user_mode_vm(regs)) {
32644+ if (!user_mode(regs)) {
32645 unsigned long stack = kernel_stack_pointer(regs);
32646 if (depth)
32647 dump_trace(NULL, regs, (unsigned long *)stack, 0,
32648diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
32649index 48768df..ba9143c 100644
32650--- a/arch/x86/oprofile/nmi_int.c
32651+++ b/arch/x86/oprofile/nmi_int.c
32652@@ -23,6 +23,7 @@
32653 #include <asm/nmi.h>
32654 #include <asm/msr.h>
32655 #include <asm/apic.h>
32656+#include <asm/pgtable.h>
32657
32658 #include "op_counter.h"
32659 #include "op_x86_model.h"
32660@@ -774,8 +775,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
32661 if (ret)
32662 return ret;
32663
32664- if (!model->num_virt_counters)
32665- model->num_virt_counters = model->num_counters;
32666+ if (!model->num_virt_counters) {
32667+ pax_open_kernel();
32668+ *(unsigned int *)&model->num_virt_counters = model->num_counters;
32669+ pax_close_kernel();
32670+ }
32671
32672 mux_init(ops);
32673
32674diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
32675index b2b9443..be58856 100644
32676--- a/arch/x86/oprofile/op_model_amd.c
32677+++ b/arch/x86/oprofile/op_model_amd.c
32678@@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
32679 num_counters = AMD64_NUM_COUNTERS;
32680 }
32681
32682- op_amd_spec.num_counters = num_counters;
32683- op_amd_spec.num_controls = num_counters;
32684- op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
32685+ pax_open_kernel();
32686+ *(unsigned int *)&op_amd_spec.num_counters = num_counters;
32687+ *(unsigned int *)&op_amd_spec.num_controls = num_counters;
32688+ *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
32689+ pax_close_kernel();
32690
32691 return 0;
32692 }
32693diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
32694index d90528e..0127e2b 100644
32695--- a/arch/x86/oprofile/op_model_ppro.c
32696+++ b/arch/x86/oprofile/op_model_ppro.c
32697@@ -19,6 +19,7 @@
32698 #include <asm/msr.h>
32699 #include <asm/apic.h>
32700 #include <asm/nmi.h>
32701+#include <asm/pgtable.h>
32702
32703 #include "op_x86_model.h"
32704 #include "op_counter.h"
32705@@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
32706
32707 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
32708
32709- op_arch_perfmon_spec.num_counters = num_counters;
32710- op_arch_perfmon_spec.num_controls = num_counters;
32711+ pax_open_kernel();
32712+ *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
32713+ *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
32714+ pax_close_kernel();
32715 }
32716
32717 static int arch_perfmon_init(struct oprofile_operations *ignore)
32718diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
32719index 71e8a67..6a313bb 100644
32720--- a/arch/x86/oprofile/op_x86_model.h
32721+++ b/arch/x86/oprofile/op_x86_model.h
32722@@ -52,7 +52,7 @@ struct op_x86_model_spec {
32723 void (*switch_ctrl)(struct op_x86_model_spec const *model,
32724 struct op_msrs const * const msrs);
32725 #endif
32726-};
32727+} __do_const;
32728
32729 struct op_counter_config;
32730
32731diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
32732index 372e9b8..e775a6c 100644
32733--- a/arch/x86/pci/irq.c
32734+++ b/arch/x86/pci/irq.c
32735@@ -50,7 +50,7 @@ struct irq_router {
32736 struct irq_router_handler {
32737 u16 vendor;
32738 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
32739-};
32740+} __do_const;
32741
32742 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
32743 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
32744@@ -794,7 +794,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
32745 return 0;
32746 }
32747
32748-static __initdata struct irq_router_handler pirq_routers[] = {
32749+static __initconst const struct irq_router_handler pirq_routers[] = {
32750 { PCI_VENDOR_ID_INTEL, intel_router_probe },
32751 { PCI_VENDOR_ID_AL, ali_router_probe },
32752 { PCI_VENDOR_ID_ITE, ite_router_probe },
32753@@ -821,7 +821,7 @@ static struct pci_dev *pirq_router_dev;
32754 static void __init pirq_find_router(struct irq_router *r)
32755 {
32756 struct irq_routing_table *rt = pirq_table;
32757- struct irq_router_handler *h;
32758+ const struct irq_router_handler *h;
32759
32760 #ifdef CONFIG_PCI_BIOS
32761 if (!rt->signature) {
32762@@ -1094,7 +1094,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
32763 return 0;
32764 }
32765
32766-static struct dmi_system_id __initdata pciirq_dmi_table[] = {
32767+static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
32768 {
32769 .callback = fix_broken_hp_bios_irq9,
32770 .ident = "HP Pavilion N5400 Series Laptop",
32771diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
32772index 6eb18c4..20d83de 100644
32773--- a/arch/x86/pci/mrst.c
32774+++ b/arch/x86/pci/mrst.c
32775@@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
32776 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
32777 pci_mmcfg_late_init();
32778 pcibios_enable_irq = mrst_pci_irq_enable;
32779- pci_root_ops = pci_mrst_ops;
32780+ pax_open_kernel();
32781+ memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
32782+ pax_close_kernel();
32783 pci_soc_mode = 1;
32784 /* Continue with standard init */
32785 return 1;
32786diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
32787index c77b24a..c979855 100644
32788--- a/arch/x86/pci/pcbios.c
32789+++ b/arch/x86/pci/pcbios.c
32790@@ -79,7 +79,7 @@ union bios32 {
32791 static struct {
32792 unsigned long address;
32793 unsigned short segment;
32794-} bios32_indirect = { 0, __KERNEL_CS };
32795+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
32796
32797 /*
32798 * Returns the entry point for the given service, NULL on error
32799@@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
32800 unsigned long length; /* %ecx */
32801 unsigned long entry; /* %edx */
32802 unsigned long flags;
32803+ struct desc_struct d, *gdt;
32804
32805 local_irq_save(flags);
32806- __asm__("lcall *(%%edi); cld"
32807+
32808+ gdt = get_cpu_gdt_table(smp_processor_id());
32809+
32810+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
32811+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
32812+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
32813+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
32814+
32815+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
32816 : "=a" (return_code),
32817 "=b" (address),
32818 "=c" (length),
32819 "=d" (entry)
32820 : "0" (service),
32821 "1" (0),
32822- "D" (&bios32_indirect));
32823+ "D" (&bios32_indirect),
32824+ "r"(__PCIBIOS_DS)
32825+ : "memory");
32826+
32827+ pax_open_kernel();
32828+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
32829+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
32830+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
32831+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
32832+ pax_close_kernel();
32833+
32834 local_irq_restore(flags);
32835
32836 switch (return_code) {
32837- case 0:
32838- return address + entry;
32839- case 0x80: /* Not present */
32840- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
32841- return 0;
32842- default: /* Shouldn't happen */
32843- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
32844- service, return_code);
32845+ case 0: {
32846+ int cpu;
32847+ unsigned char flags;
32848+
32849+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
32850+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
32851+ printk(KERN_WARNING "bios32_service: not valid\n");
32852 return 0;
32853+ }
32854+ address = address + PAGE_OFFSET;
32855+ length += 16UL; /* some BIOSs underreport this... */
32856+ flags = 4;
32857+ if (length >= 64*1024*1024) {
32858+ length >>= PAGE_SHIFT;
32859+ flags |= 8;
32860+ }
32861+
32862+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
32863+ gdt = get_cpu_gdt_table(cpu);
32864+ pack_descriptor(&d, address, length, 0x9b, flags);
32865+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
32866+ pack_descriptor(&d, address, length, 0x93, flags);
32867+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
32868+ }
32869+ return entry;
32870+ }
32871+ case 0x80: /* Not present */
32872+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
32873+ return 0;
32874+ default: /* Shouldn't happen */
32875+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
32876+ service, return_code);
32877+ return 0;
32878 }
32879 }
32880
32881 static struct {
32882 unsigned long address;
32883 unsigned short segment;
32884-} pci_indirect = { 0, __KERNEL_CS };
32885+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
32886
32887-static int pci_bios_present;
32888+static int pci_bios_present __read_only;
32889
32890 static int check_pcibios(void)
32891 {
32892@@ -131,11 +174,13 @@ static int check_pcibios(void)
32893 unsigned long flags, pcibios_entry;
32894
32895 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
32896- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
32897+ pci_indirect.address = pcibios_entry;
32898
32899 local_irq_save(flags);
32900- __asm__(
32901- "lcall *(%%edi); cld\n\t"
32902+ __asm__("movw %w6, %%ds\n\t"
32903+ "lcall *%%ss:(%%edi); cld\n\t"
32904+ "push %%ss\n\t"
32905+ "pop %%ds\n\t"
32906 "jc 1f\n\t"
32907 "xor %%ah, %%ah\n"
32908 "1:"
32909@@ -144,7 +189,8 @@ static int check_pcibios(void)
32910 "=b" (ebx),
32911 "=c" (ecx)
32912 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
32913- "D" (&pci_indirect)
32914+ "D" (&pci_indirect),
32915+ "r" (__PCIBIOS_DS)
32916 : "memory");
32917 local_irq_restore(flags);
32918
32919@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32920
32921 switch (len) {
32922 case 1:
32923- __asm__("lcall *(%%esi); cld\n\t"
32924+ __asm__("movw %w6, %%ds\n\t"
32925+ "lcall *%%ss:(%%esi); cld\n\t"
32926+ "push %%ss\n\t"
32927+ "pop %%ds\n\t"
32928 "jc 1f\n\t"
32929 "xor %%ah, %%ah\n"
32930 "1:"
32931@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32932 : "1" (PCIBIOS_READ_CONFIG_BYTE),
32933 "b" (bx),
32934 "D" ((long)reg),
32935- "S" (&pci_indirect));
32936+ "S" (&pci_indirect),
32937+ "r" (__PCIBIOS_DS));
32938 /*
32939 * Zero-extend the result beyond 8 bits, do not trust the
32940 * BIOS having done it:
32941@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32942 *value &= 0xff;
32943 break;
32944 case 2:
32945- __asm__("lcall *(%%esi); cld\n\t"
32946+ __asm__("movw %w6, %%ds\n\t"
32947+ "lcall *%%ss:(%%esi); cld\n\t"
32948+ "push %%ss\n\t"
32949+ "pop %%ds\n\t"
32950 "jc 1f\n\t"
32951 "xor %%ah, %%ah\n"
32952 "1:"
32953@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32954 : "1" (PCIBIOS_READ_CONFIG_WORD),
32955 "b" (bx),
32956 "D" ((long)reg),
32957- "S" (&pci_indirect));
32958+ "S" (&pci_indirect),
32959+ "r" (__PCIBIOS_DS));
32960 /*
32961 * Zero-extend the result beyond 16 bits, do not trust the
32962 * BIOS having done it:
32963@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32964 *value &= 0xffff;
32965 break;
32966 case 4:
32967- __asm__("lcall *(%%esi); cld\n\t"
32968+ __asm__("movw %w6, %%ds\n\t"
32969+ "lcall *%%ss:(%%esi); cld\n\t"
32970+ "push %%ss\n\t"
32971+ "pop %%ds\n\t"
32972 "jc 1f\n\t"
32973 "xor %%ah, %%ah\n"
32974 "1:"
32975@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32976 : "1" (PCIBIOS_READ_CONFIG_DWORD),
32977 "b" (bx),
32978 "D" ((long)reg),
32979- "S" (&pci_indirect));
32980+ "S" (&pci_indirect),
32981+ "r" (__PCIBIOS_DS));
32982 break;
32983 }
32984
32985@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
32986
32987 switch (len) {
32988 case 1:
32989- __asm__("lcall *(%%esi); cld\n\t"
32990+ __asm__("movw %w6, %%ds\n\t"
32991+ "lcall *%%ss:(%%esi); cld\n\t"
32992+ "push %%ss\n\t"
32993+ "pop %%ds\n\t"
32994 "jc 1f\n\t"
32995 "xor %%ah, %%ah\n"
32996 "1:"
32997@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
32998 "c" (value),
32999 "b" (bx),
33000 "D" ((long)reg),
33001- "S" (&pci_indirect));
33002+ "S" (&pci_indirect),
33003+ "r" (__PCIBIOS_DS));
33004 break;
33005 case 2:
33006- __asm__("lcall *(%%esi); cld\n\t"
33007+ __asm__("movw %w6, %%ds\n\t"
33008+ "lcall *%%ss:(%%esi); cld\n\t"
33009+ "push %%ss\n\t"
33010+ "pop %%ds\n\t"
33011 "jc 1f\n\t"
33012 "xor %%ah, %%ah\n"
33013 "1:"
33014@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
33015 "c" (value),
33016 "b" (bx),
33017 "D" ((long)reg),
33018- "S" (&pci_indirect));
33019+ "S" (&pci_indirect),
33020+ "r" (__PCIBIOS_DS));
33021 break;
33022 case 4:
33023- __asm__("lcall *(%%esi); cld\n\t"
33024+ __asm__("movw %w6, %%ds\n\t"
33025+ "lcall *%%ss:(%%esi); cld\n\t"
33026+ "push %%ss\n\t"
33027+ "pop %%ds\n\t"
33028 "jc 1f\n\t"
33029 "xor %%ah, %%ah\n"
33030 "1:"
33031@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
33032 "c" (value),
33033 "b" (bx),
33034 "D" ((long)reg),
33035- "S" (&pci_indirect));
33036+ "S" (&pci_indirect),
33037+ "r" (__PCIBIOS_DS));
33038 break;
33039 }
33040
33041@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
33042
33043 DBG("PCI: Fetching IRQ routing table... ");
33044 __asm__("push %%es\n\t"
33045+ "movw %w8, %%ds\n\t"
33046 "push %%ds\n\t"
33047 "pop %%es\n\t"
33048- "lcall *(%%esi); cld\n\t"
33049+ "lcall *%%ss:(%%esi); cld\n\t"
33050 "pop %%es\n\t"
33051+ "push %%ss\n\t"
33052+ "pop %%ds\n"
33053 "jc 1f\n\t"
33054 "xor %%ah, %%ah\n"
33055 "1:"
33056@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
33057 "1" (0),
33058 "D" ((long) &opt),
33059 "S" (&pci_indirect),
33060- "m" (opt)
33061+ "m" (opt),
33062+ "r" (__PCIBIOS_DS)
33063 : "memory");
33064 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
33065 if (ret & 0xff00)
33066@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
33067 {
33068 int ret;
33069
33070- __asm__("lcall *(%%esi); cld\n\t"
33071+ __asm__("movw %w5, %%ds\n\t"
33072+ "lcall *%%ss:(%%esi); cld\n\t"
33073+ "push %%ss\n\t"
33074+ "pop %%ds\n"
33075 "jc 1f\n\t"
33076 "xor %%ah, %%ah\n"
33077 "1:"
33078@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
33079 : "0" (PCIBIOS_SET_PCI_HW_INT),
33080 "b" ((dev->bus->number << 8) | dev->devfn),
33081 "c" ((irq << 8) | (pin + 10)),
33082- "S" (&pci_indirect));
33083+ "S" (&pci_indirect),
33084+ "r" (__PCIBIOS_DS));
33085 return !(ret & 0xff00);
33086 }
33087 EXPORT_SYMBOL(pcibios_set_irq_routing);
33088diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
33089index 40e4469..d915bf9 100644
33090--- a/arch/x86/platform/efi/efi_32.c
33091+++ b/arch/x86/platform/efi/efi_32.c
33092@@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
33093 {
33094 struct desc_ptr gdt_descr;
33095
33096+#ifdef CONFIG_PAX_KERNEXEC
33097+ struct desc_struct d;
33098+#endif
33099+
33100 local_irq_save(efi_rt_eflags);
33101
33102 load_cr3(initial_page_table);
33103 __flush_tlb_all();
33104
33105+#ifdef CONFIG_PAX_KERNEXEC
33106+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
33107+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
33108+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
33109+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
33110+#endif
33111+
33112 gdt_descr.address = __pa(get_cpu_gdt_table(0));
33113 gdt_descr.size = GDT_SIZE - 1;
33114 load_gdt(&gdt_descr);
33115@@ -58,11 +69,24 @@ void efi_call_phys_epilog(void)
33116 {
33117 struct desc_ptr gdt_descr;
33118
33119+#ifdef CONFIG_PAX_KERNEXEC
33120+ struct desc_struct d;
33121+
33122+ memset(&d, 0, sizeof d);
33123+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
33124+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
33125+#endif
33126+
33127 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
33128 gdt_descr.size = GDT_SIZE - 1;
33129 load_gdt(&gdt_descr);
33130
33131+#ifdef CONFIG_PAX_PER_CPU_PGD
33132+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
33133+#else
33134 load_cr3(swapper_pg_dir);
33135+#endif
33136+
33137 __flush_tlb_all();
33138
33139 local_irq_restore(efi_rt_eflags);
33140diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
33141index 39a0e7f1..872396e 100644
33142--- a/arch/x86/platform/efi/efi_64.c
33143+++ b/arch/x86/platform/efi/efi_64.c
33144@@ -76,6 +76,11 @@ void __init efi_call_phys_prelog(void)
33145 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
33146 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
33147 }
33148+
33149+#ifdef CONFIG_PAX_PER_CPU_PGD
33150+ load_cr3(swapper_pg_dir);
33151+#endif
33152+
33153 __flush_tlb_all();
33154 }
33155
33156@@ -89,6 +94,11 @@ void __init efi_call_phys_epilog(void)
33157 for (pgd = 0; pgd < n_pgds; pgd++)
33158 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
33159 kfree(save_pgd);
33160+
33161+#ifdef CONFIG_PAX_PER_CPU_PGD
33162+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
33163+#endif
33164+
33165 __flush_tlb_all();
33166 local_irq_restore(efi_flags);
33167 early_code_mapping_set_exec(0);
33168diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
33169index fbe66e6..eae5e38 100644
33170--- a/arch/x86/platform/efi/efi_stub_32.S
33171+++ b/arch/x86/platform/efi/efi_stub_32.S
33172@@ -6,7 +6,9 @@
33173 */
33174
33175 #include <linux/linkage.h>
33176+#include <linux/init.h>
33177 #include <asm/page_types.h>
33178+#include <asm/segment.h>
33179
33180 /*
33181 * efi_call_phys(void *, ...) is a function with variable parameters.
33182@@ -20,7 +22,7 @@
33183 * service functions will comply with gcc calling convention, too.
33184 */
33185
33186-.text
33187+__INIT
33188 ENTRY(efi_call_phys)
33189 /*
33190 * 0. The function can only be called in Linux kernel. So CS has been
33191@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
33192 * The mapping of lower virtual memory has been created in prelog and
33193 * epilog.
33194 */
33195- movl $1f, %edx
33196- subl $__PAGE_OFFSET, %edx
33197- jmp *%edx
33198+#ifdef CONFIG_PAX_KERNEXEC
33199+ movl $(__KERNEXEC_EFI_DS), %edx
33200+ mov %edx, %ds
33201+ mov %edx, %es
33202+ mov %edx, %ss
33203+ addl $2f,(1f)
33204+ ljmp *(1f)
33205+
33206+__INITDATA
33207+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
33208+.previous
33209+
33210+2:
33211+ subl $2b,(1b)
33212+#else
33213+ jmp 1f-__PAGE_OFFSET
33214 1:
33215+#endif
33216
33217 /*
33218 * 2. Now on the top of stack is the return
33219@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
33220 * parameter 2, ..., param n. To make things easy, we save the return
33221 * address of efi_call_phys in a global variable.
33222 */
33223- popl %edx
33224- movl %edx, saved_return_addr
33225- /* get the function pointer into ECX*/
33226- popl %ecx
33227- movl %ecx, efi_rt_function_ptr
33228- movl $2f, %edx
33229- subl $__PAGE_OFFSET, %edx
33230- pushl %edx
33231+ popl (saved_return_addr)
33232+ popl (efi_rt_function_ptr)
33233
33234 /*
33235 * 3. Clear PG bit in %CR0.
33236@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
33237 /*
33238 * 5. Call the physical function.
33239 */
33240- jmp *%ecx
33241+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
33242
33243-2:
33244 /*
33245 * 6. After EFI runtime service returns, control will return to
33246 * following instruction. We'd better readjust stack pointer first.
33247@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
33248 movl %cr0, %edx
33249 orl $0x80000000, %edx
33250 movl %edx, %cr0
33251- jmp 1f
33252-1:
33253+
33254 /*
33255 * 8. Now restore the virtual mode from flat mode by
33256 * adding EIP with PAGE_OFFSET.
33257 */
33258- movl $1f, %edx
33259- jmp *%edx
33260+#ifdef CONFIG_PAX_KERNEXEC
33261+ movl $(__KERNEL_DS), %edx
33262+ mov %edx, %ds
33263+ mov %edx, %es
33264+ mov %edx, %ss
33265+ ljmp $(__KERNEL_CS),$1f
33266+#else
33267+ jmp 1f+__PAGE_OFFSET
33268+#endif
33269 1:
33270
33271 /*
33272 * 9. Balance the stack. And because EAX contain the return value,
33273 * we'd better not clobber it.
33274 */
33275- leal efi_rt_function_ptr, %edx
33276- movl (%edx), %ecx
33277- pushl %ecx
33278+ pushl (efi_rt_function_ptr)
33279
33280 /*
33281- * 10. Push the saved return address onto the stack and return.
33282+ * 10. Return to the saved return address.
33283 */
33284- leal saved_return_addr, %edx
33285- movl (%edx), %ecx
33286- pushl %ecx
33287- ret
33288+ jmpl *(saved_return_addr)
33289 ENDPROC(efi_call_phys)
33290 .previous
33291
33292-.data
33293+__INITDATA
33294 saved_return_addr:
33295 .long 0
33296 efi_rt_function_ptr:
33297diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
33298index 4c07cca..2c8427d 100644
33299--- a/arch/x86/platform/efi/efi_stub_64.S
33300+++ b/arch/x86/platform/efi/efi_stub_64.S
33301@@ -7,6 +7,7 @@
33302 */
33303
33304 #include <linux/linkage.h>
33305+#include <asm/alternative-asm.h>
33306
33307 #define SAVE_XMM \
33308 mov %rsp, %rax; \
33309@@ -40,6 +41,7 @@ ENTRY(efi_call0)
33310 call *%rdi
33311 addq $32, %rsp
33312 RESTORE_XMM
33313+ pax_force_retaddr 0, 1
33314 ret
33315 ENDPROC(efi_call0)
33316
33317@@ -50,6 +52,7 @@ ENTRY(efi_call1)
33318 call *%rdi
33319 addq $32, %rsp
33320 RESTORE_XMM
33321+ pax_force_retaddr 0, 1
33322 ret
33323 ENDPROC(efi_call1)
33324
33325@@ -60,6 +63,7 @@ ENTRY(efi_call2)
33326 call *%rdi
33327 addq $32, %rsp
33328 RESTORE_XMM
33329+ pax_force_retaddr 0, 1
33330 ret
33331 ENDPROC(efi_call2)
33332
33333@@ -71,6 +75,7 @@ ENTRY(efi_call3)
33334 call *%rdi
33335 addq $32, %rsp
33336 RESTORE_XMM
33337+ pax_force_retaddr 0, 1
33338 ret
33339 ENDPROC(efi_call3)
33340
33341@@ -83,6 +88,7 @@ ENTRY(efi_call4)
33342 call *%rdi
33343 addq $32, %rsp
33344 RESTORE_XMM
33345+ pax_force_retaddr 0, 1
33346 ret
33347 ENDPROC(efi_call4)
33348
33349@@ -96,6 +102,7 @@ ENTRY(efi_call5)
33350 call *%rdi
33351 addq $48, %rsp
33352 RESTORE_XMM
33353+ pax_force_retaddr 0, 1
33354 ret
33355 ENDPROC(efi_call5)
33356
33357@@ -112,5 +119,6 @@ ENTRY(efi_call6)
33358 call *%rdi
33359 addq $48, %rsp
33360 RESTORE_XMM
33361+ pax_force_retaddr 0, 1
33362 ret
33363 ENDPROC(efi_call6)
33364diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
33365index 47fe66f..6206449 100644
33366--- a/arch/x86/platform/mrst/mrst.c
33367+++ b/arch/x86/platform/mrst/mrst.c
33368@@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
33369 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
33370 int sfi_mrtc_num;
33371
33372-static void mrst_power_off(void)
33373+static __noreturn void mrst_power_off(void)
33374 {
33375+ BUG();
33376 }
33377
33378-static void mrst_reboot(void)
33379+static __noreturn void mrst_reboot(void)
33380 {
33381 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
33382+ BUG();
33383 }
33384
33385 /* parse all the mtimer info to a static mtimer array */
33386diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
33387index d6ee929..3637cb5 100644
33388--- a/arch/x86/platform/olpc/olpc_dt.c
33389+++ b/arch/x86/platform/olpc/olpc_dt.c
33390@@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
33391 return res;
33392 }
33393
33394-static struct of_pdt_ops prom_olpc_ops __initdata = {
33395+static struct of_pdt_ops prom_olpc_ops __initconst = {
33396 .nextprop = olpc_dt_nextprop,
33397 .getproplen = olpc_dt_getproplen,
33398 .getproperty = olpc_dt_getproperty,
33399diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
33400index 1cf5b30..fd45732 100644
33401--- a/arch/x86/power/cpu.c
33402+++ b/arch/x86/power/cpu.c
33403@@ -137,11 +137,8 @@ static void do_fpu_end(void)
33404 static void fix_processor_context(void)
33405 {
33406 int cpu = smp_processor_id();
33407- struct tss_struct *t = &per_cpu(init_tss, cpu);
33408-#ifdef CONFIG_X86_64
33409- struct desc_struct *desc = get_cpu_gdt_table(cpu);
33410- tss_desc tss;
33411-#endif
33412+ struct tss_struct *t = init_tss + cpu;
33413+
33414 set_tss_desc(cpu, t); /*
33415 * This just modifies memory; should not be
33416 * necessary. But... This is necessary, because
33417@@ -150,10 +147,6 @@ static void fix_processor_context(void)
33418 */
33419
33420 #ifdef CONFIG_X86_64
33421- memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
33422- tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
33423- write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
33424-
33425 syscall_init(); /* This sets MSR_*STAR and related */
33426 #endif
33427 load_TR_desc(); /* This does ltr */
33428diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
33429index a44f457..9140171 100644
33430--- a/arch/x86/realmode/init.c
33431+++ b/arch/x86/realmode/init.c
33432@@ -70,7 +70,13 @@ void __init setup_real_mode(void)
33433 __va(real_mode_header->trampoline_header);
33434
33435 #ifdef CONFIG_X86_32
33436- trampoline_header->start = __pa_symbol(startup_32_smp);
33437+ trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
33438+
33439+#ifdef CONFIG_PAX_KERNEXEC
33440+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
33441+#endif
33442+
33443+ trampoline_header->boot_cs = __BOOT_CS;
33444 trampoline_header->gdt_limit = __BOOT_DS + 7;
33445 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
33446 #else
33447@@ -86,7 +92,7 @@ void __init setup_real_mode(void)
33448 *trampoline_cr4_features = read_cr4();
33449
33450 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
33451- trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
33452+ trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
33453 trampoline_pgd[511] = init_level4_pgt[511].pgd;
33454 #endif
33455 }
33456diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
33457index 8869287..d577672 100644
33458--- a/arch/x86/realmode/rm/Makefile
33459+++ b/arch/x86/realmode/rm/Makefile
33460@@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
33461 $(call cc-option, -fno-unit-at-a-time)) \
33462 $(call cc-option, -fno-stack-protector) \
33463 $(call cc-option, -mpreferred-stack-boundary=2)
33464+ifdef CONSTIFY_PLUGIN
33465+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
33466+endif
33467 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
33468 GCOV_PROFILE := n
33469diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
33470index a28221d..93c40f1 100644
33471--- a/arch/x86/realmode/rm/header.S
33472+++ b/arch/x86/realmode/rm/header.S
33473@@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
33474 #endif
33475 /* APM/BIOS reboot */
33476 .long pa_machine_real_restart_asm
33477-#ifdef CONFIG_X86_64
33478+#ifdef CONFIG_X86_32
33479+ .long __KERNEL_CS
33480+#else
33481 .long __KERNEL32_CS
33482 #endif
33483 END(real_mode_header)
33484diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
33485index c1b2791..f9e31c7 100644
33486--- a/arch/x86/realmode/rm/trampoline_32.S
33487+++ b/arch/x86/realmode/rm/trampoline_32.S
33488@@ -25,6 +25,12 @@
33489 #include <asm/page_types.h>
33490 #include "realmode.h"
33491
33492+#ifdef CONFIG_PAX_KERNEXEC
33493+#define ta(X) (X)
33494+#else
33495+#define ta(X) (pa_ ## X)
33496+#endif
33497+
33498 .text
33499 .code16
33500
33501@@ -39,8 +45,6 @@ ENTRY(trampoline_start)
33502
33503 cli # We should be safe anyway
33504
33505- movl tr_start, %eax # where we need to go
33506-
33507 movl $0xA5A5A5A5, trampoline_status
33508 # write marker for master knows we're running
33509
33510@@ -56,7 +60,7 @@ ENTRY(trampoline_start)
33511 movw $1, %dx # protected mode (PE) bit
33512 lmsw %dx # into protected mode
33513
33514- ljmpl $__BOOT_CS, $pa_startup_32
33515+ ljmpl *(trampoline_header)
33516
33517 .section ".text32","ax"
33518 .code32
33519@@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
33520 .balign 8
33521 GLOBAL(trampoline_header)
33522 tr_start: .space 4
33523- tr_gdt_pad: .space 2
33524+ tr_boot_cs: .space 2
33525 tr_gdt: .space 6
33526 END(trampoline_header)
33527
33528diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
33529index bb360dc..d0fd8f8 100644
33530--- a/arch/x86/realmode/rm/trampoline_64.S
33531+++ b/arch/x86/realmode/rm/trampoline_64.S
33532@@ -94,6 +94,7 @@ ENTRY(startup_32)
33533 movl %edx, %gs
33534
33535 movl pa_tr_cr4, %eax
33536+ andl $~X86_CR4_PCIDE, %eax
33537 movl %eax, %cr4 # Enable PAE mode
33538
33539 # Setup trampoline 4 level pagetables
33540@@ -107,7 +108,7 @@ ENTRY(startup_32)
33541 wrmsr
33542
33543 # Enable paging and in turn activate Long Mode
33544- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
33545+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
33546 movl %eax, %cr0
33547
33548 /*
33549diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
33550index e812034..c747134 100644
33551--- a/arch/x86/tools/Makefile
33552+++ b/arch/x86/tools/Makefile
33553@@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
33554
33555 $(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
33556
33557-HOST_EXTRACFLAGS += -I$(srctree)/tools/include
33558+HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
33559 hostprogs-y += relocs
33560 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
33561 relocs: $(obj)/relocs
33562diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
33563index f7bab68..b6d9886 100644
33564--- a/arch/x86/tools/relocs.c
33565+++ b/arch/x86/tools/relocs.c
33566@@ -1,5 +1,7 @@
33567 /* This is included from relocs_32/64.c */
33568
33569+#include "../../../include/generated/autoconf.h"
33570+
33571 #define ElfW(type) _ElfW(ELF_BITS, type)
33572 #define _ElfW(bits, type) __ElfW(bits, type)
33573 #define __ElfW(bits, type) Elf##bits##_##type
33574@@ -11,6 +13,7 @@
33575 #define Elf_Sym ElfW(Sym)
33576
33577 static Elf_Ehdr ehdr;
33578+static Elf_Phdr *phdr;
33579
33580 struct relocs {
33581 uint32_t *offset;
33582@@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
33583 }
33584 }
33585
33586+static void read_phdrs(FILE *fp)
33587+{
33588+ unsigned int i;
33589+
33590+ phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
33591+ if (!phdr) {
33592+ die("Unable to allocate %d program headers\n",
33593+ ehdr.e_phnum);
33594+ }
33595+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
33596+ die("Seek to %d failed: %s\n",
33597+ ehdr.e_phoff, strerror(errno));
33598+ }
33599+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
33600+ die("Cannot read ELF program headers: %s\n",
33601+ strerror(errno));
33602+ }
33603+ for(i = 0; i < ehdr.e_phnum; i++) {
33604+ phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
33605+ phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
33606+ phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
33607+ phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
33608+ phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
33609+ phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
33610+ phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
33611+ phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
33612+ }
33613+
33614+}
33615+
33616 static void read_shdrs(FILE *fp)
33617 {
33618- int i;
33619+ unsigned int i;
33620 Elf_Shdr shdr;
33621
33622 secs = calloc(ehdr.e_shnum, sizeof(struct section));
33623@@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
33624
33625 static void read_strtabs(FILE *fp)
33626 {
33627- int i;
33628+ unsigned int i;
33629 for (i = 0; i < ehdr.e_shnum; i++) {
33630 struct section *sec = &secs[i];
33631 if (sec->shdr.sh_type != SHT_STRTAB) {
33632@@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
33633
33634 static void read_symtabs(FILE *fp)
33635 {
33636- int i,j;
33637+ unsigned int i,j;
33638 for (i = 0; i < ehdr.e_shnum; i++) {
33639 struct section *sec = &secs[i];
33640 if (sec->shdr.sh_type != SHT_SYMTAB) {
33641@@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
33642 }
33643
33644
33645-static void read_relocs(FILE *fp)
33646+static void read_relocs(FILE *fp, int use_real_mode)
33647 {
33648- int i,j;
33649+ unsigned int i,j;
33650+ uint32_t base;
33651+
33652 for (i = 0; i < ehdr.e_shnum; i++) {
33653 struct section *sec = &secs[i];
33654 if (sec->shdr.sh_type != SHT_REL_TYPE) {
33655@@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
33656 die("Cannot read symbol table: %s\n",
33657 strerror(errno));
33658 }
33659+ base = 0;
33660+
33661+#ifdef CONFIG_X86_32
33662+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
33663+ if (phdr[j].p_type != PT_LOAD )
33664+ continue;
33665+ 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)
33666+ continue;
33667+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
33668+ break;
33669+ }
33670+#endif
33671+
33672 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
33673 Elf_Rel *rel = &sec->reltab[j];
33674- rel->r_offset = elf_addr_to_cpu(rel->r_offset);
33675+ rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
33676 rel->r_info = elf_xword_to_cpu(rel->r_info);
33677 #if (SHT_REL_TYPE == SHT_RELA)
33678 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
33679@@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
33680
33681 static void print_absolute_symbols(void)
33682 {
33683- int i;
33684+ unsigned int i;
33685 const char *format;
33686
33687 if (ELF_BITS == 64)
33688@@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
33689 for (i = 0; i < ehdr.e_shnum; i++) {
33690 struct section *sec = &secs[i];
33691 char *sym_strtab;
33692- int j;
33693+ unsigned int j;
33694
33695 if (sec->shdr.sh_type != SHT_SYMTAB) {
33696 continue;
33697@@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
33698
33699 static void print_absolute_relocs(void)
33700 {
33701- int i, printed = 0;
33702+ unsigned int i, printed = 0;
33703 const char *format;
33704
33705 if (ELF_BITS == 64)
33706@@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
33707 struct section *sec_applies, *sec_symtab;
33708 char *sym_strtab;
33709 Elf_Sym *sh_symtab;
33710- int j;
33711+ unsigned int j;
33712 if (sec->shdr.sh_type != SHT_REL_TYPE) {
33713 continue;
33714 }
33715@@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
33716 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
33717 Elf_Sym *sym, const char *symname))
33718 {
33719- int i;
33720+ unsigned int i;
33721 /* Walk through the relocations */
33722 for (i = 0; i < ehdr.e_shnum; i++) {
33723 char *sym_strtab;
33724 Elf_Sym *sh_symtab;
33725 struct section *sec_applies, *sec_symtab;
33726- int j;
33727+ unsigned int j;
33728 struct section *sec = &secs[i];
33729
33730 if (sec->shdr.sh_type != SHT_REL_TYPE) {
33731@@ -812,6 +860,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
33732 {
33733 unsigned r_type = ELF32_R_TYPE(rel->r_info);
33734 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
33735+ char *sym_strtab = sec->link->link->strtab;
33736+
33737+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
33738+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
33739+ return 0;
33740+
33741+#ifdef CONFIG_PAX_KERNEXEC
33742+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
33743+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
33744+ return 0;
33745+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
33746+ return 0;
33747+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
33748+ return 0;
33749+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
33750+ return 0;
33751+#endif
33752
33753 switch (r_type) {
33754 case R_386_NONE:
33755@@ -950,7 +1015,7 @@ static int write32_as_text(uint32_t v, FILE *f)
33756
33757 static void emit_relocs(int as_text, int use_real_mode)
33758 {
33759- int i;
33760+ unsigned int i;
33761 int (*write_reloc)(uint32_t, FILE *) = write32;
33762 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
33763 const char *symname);
33764@@ -1026,10 +1091,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
33765 {
33766 regex_init(use_real_mode);
33767 read_ehdr(fp);
33768+ read_phdrs(fp);
33769 read_shdrs(fp);
33770 read_strtabs(fp);
33771 read_symtabs(fp);
33772- read_relocs(fp);
33773+ read_relocs(fp, use_real_mode);
33774 if (ELF_BITS == 64)
33775 percpu_init();
33776 if (show_absolute_syms) {
33777diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
33778index 80ffa5b..a33bd15 100644
33779--- a/arch/x86/um/tls_32.c
33780+++ b/arch/x86/um/tls_32.c
33781@@ -260,7 +260,7 @@ out:
33782 if (unlikely(task == current &&
33783 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
33784 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
33785- "without flushed TLS.", current->pid);
33786+ "without flushed TLS.", task_pid_nr(current));
33787 }
33788
33789 return 0;
33790diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
33791index fd14be1..e3c79c0 100644
33792--- a/arch/x86/vdso/Makefile
33793+++ b/arch/x86/vdso/Makefile
33794@@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
33795 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
33796 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
33797
33798-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
33799+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
33800 GCOV_PROFILE := n
33801
33802 #
33803diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
33804index d6bfb87..876ee18 100644
33805--- a/arch/x86/vdso/vdso32-setup.c
33806+++ b/arch/x86/vdso/vdso32-setup.c
33807@@ -25,6 +25,7 @@
33808 #include <asm/tlbflush.h>
33809 #include <asm/vdso.h>
33810 #include <asm/proto.h>
33811+#include <asm/mman.h>
33812
33813 enum {
33814 VDSO_DISABLED = 0,
33815@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
33816 void enable_sep_cpu(void)
33817 {
33818 int cpu = get_cpu();
33819- struct tss_struct *tss = &per_cpu(init_tss, cpu);
33820+ struct tss_struct *tss = init_tss + cpu;
33821
33822 if (!boot_cpu_has(X86_FEATURE_SEP)) {
33823 put_cpu();
33824@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
33825 gate_vma.vm_start = FIXADDR_USER_START;
33826 gate_vma.vm_end = FIXADDR_USER_END;
33827 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
33828- gate_vma.vm_page_prot = __P101;
33829+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
33830
33831 return 0;
33832 }
33833@@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
33834 if (compat)
33835 addr = VDSO_HIGH_BASE;
33836 else {
33837- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
33838+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
33839 if (IS_ERR_VALUE(addr)) {
33840 ret = addr;
33841 goto up_fail;
33842 }
33843 }
33844
33845- current->mm->context.vdso = (void *)addr;
33846+ current->mm->context.vdso = addr;
33847
33848 if (compat_uses_vma || !compat) {
33849 /*
33850@@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
33851 }
33852
33853 current_thread_info()->sysenter_return =
33854- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
33855+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
33856
33857 up_fail:
33858 if (ret)
33859- current->mm->context.vdso = NULL;
33860+ current->mm->context.vdso = 0;
33861
33862 up_write(&mm->mmap_sem);
33863
33864@@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
33865
33866 const char *arch_vma_name(struct vm_area_struct *vma)
33867 {
33868- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
33869+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
33870 return "[vdso]";
33871+
33872+#ifdef CONFIG_PAX_SEGMEXEC
33873+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
33874+ return "[vdso]";
33875+#endif
33876+
33877 return NULL;
33878 }
33879
33880@@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
33881 * Check to see if the corresponding task was created in compat vdso
33882 * mode.
33883 */
33884- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
33885+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
33886 return &gate_vma;
33887 return NULL;
33888 }
33889diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
33890index 431e875..cbb23f3 100644
33891--- a/arch/x86/vdso/vma.c
33892+++ b/arch/x86/vdso/vma.c
33893@@ -16,8 +16,6 @@
33894 #include <asm/vdso.h>
33895 #include <asm/page.h>
33896
33897-unsigned int __read_mostly vdso_enabled = 1;
33898-
33899 extern char vdso_start[], vdso_end[];
33900 extern unsigned short vdso_sync_cpuid;
33901
33902@@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
33903 * unaligned here as a result of stack start randomization.
33904 */
33905 addr = PAGE_ALIGN(addr);
33906- addr = align_vdso_addr(addr);
33907
33908 return addr;
33909 }
33910@@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
33911 unsigned size)
33912 {
33913 struct mm_struct *mm = current->mm;
33914- unsigned long addr;
33915+ unsigned long addr = 0;
33916 int ret;
33917
33918- if (!vdso_enabled)
33919- return 0;
33920-
33921 down_write(&mm->mmap_sem);
33922+
33923+#ifdef CONFIG_PAX_RANDMMAP
33924+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
33925+#endif
33926+
33927 addr = vdso_addr(mm->start_stack, size);
33928+ addr = align_vdso_addr(addr);
33929 addr = get_unmapped_area(NULL, addr, size, 0, 0);
33930 if (IS_ERR_VALUE(addr)) {
33931 ret = addr;
33932 goto up_fail;
33933 }
33934
33935- current->mm->context.vdso = (void *)addr;
33936+ mm->context.vdso = addr;
33937
33938 ret = install_special_mapping(mm, addr, size,
33939 VM_READ|VM_EXEC|
33940 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
33941 pages);
33942- if (ret) {
33943- current->mm->context.vdso = NULL;
33944- goto up_fail;
33945- }
33946+ if (ret)
33947+ mm->context.vdso = 0;
33948
33949 up_fail:
33950 up_write(&mm->mmap_sem);
33951@@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
33952 vdsox32_size);
33953 }
33954 #endif
33955-
33956-static __init int vdso_setup(char *s)
33957-{
33958- vdso_enabled = simple_strtoul(s, NULL, 0);
33959- return 0;
33960-}
33961-__setup("vdso=", vdso_setup);
33962diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
33963index 193097e..7590269 100644
33964--- a/arch/x86/xen/enlighten.c
33965+++ b/arch/x86/xen/enlighten.c
33966@@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
33967
33968 struct shared_info xen_dummy_shared_info;
33969
33970-void *xen_initial_gdt;
33971-
33972 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
33973 __read_mostly int xen_have_vector_callback;
33974 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
33975@@ -542,8 +540,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
33976 {
33977 unsigned long va = dtr->address;
33978 unsigned int size = dtr->size + 1;
33979- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
33980- unsigned long frames[pages];
33981+ unsigned long frames[65536 / PAGE_SIZE];
33982 int f;
33983
33984 /*
33985@@ -591,8 +588,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
33986 {
33987 unsigned long va = dtr->address;
33988 unsigned int size = dtr->size + 1;
33989- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
33990- unsigned long frames[pages];
33991+ unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
33992 int f;
33993
33994 /*
33995@@ -600,7 +596,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
33996 * 8-byte entries, or 16 4k pages..
33997 */
33998
33999- BUG_ON(size > 65536);
34000+ BUG_ON(size > GDT_SIZE);
34001 BUG_ON(va & ~PAGE_MASK);
34002
34003 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
34004@@ -985,7 +981,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
34005 return 0;
34006 }
34007
34008-static void set_xen_basic_apic_ops(void)
34009+static void __init set_xen_basic_apic_ops(void)
34010 {
34011 apic->read = xen_apic_read;
34012 apic->write = xen_apic_write;
34013@@ -1290,30 +1286,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
34014 #endif
34015 };
34016
34017-static void xen_reboot(int reason)
34018+static __noreturn void xen_reboot(int reason)
34019 {
34020 struct sched_shutdown r = { .reason = reason };
34021
34022- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
34023- BUG();
34024+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
34025+ BUG();
34026 }
34027
34028-static void xen_restart(char *msg)
34029+static __noreturn void xen_restart(char *msg)
34030 {
34031 xen_reboot(SHUTDOWN_reboot);
34032 }
34033
34034-static void xen_emergency_restart(void)
34035+static __noreturn void xen_emergency_restart(void)
34036 {
34037 xen_reboot(SHUTDOWN_reboot);
34038 }
34039
34040-static void xen_machine_halt(void)
34041+static __noreturn void xen_machine_halt(void)
34042 {
34043 xen_reboot(SHUTDOWN_poweroff);
34044 }
34045
34046-static void xen_machine_power_off(void)
34047+static __noreturn void xen_machine_power_off(void)
34048 {
34049 if (pm_power_off)
34050 pm_power_off();
34051@@ -1464,7 +1460,17 @@ asmlinkage void __init xen_start_kernel(void)
34052 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
34053
34054 /* Work out if we support NX */
34055- x86_configure_nx();
34056+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
34057+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
34058+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
34059+ unsigned l, h;
34060+
34061+ __supported_pte_mask |= _PAGE_NX;
34062+ rdmsr(MSR_EFER, l, h);
34063+ l |= EFER_NX;
34064+ wrmsr(MSR_EFER, l, h);
34065+ }
34066+#endif
34067
34068 xen_setup_features();
34069
34070@@ -1495,13 +1501,6 @@ asmlinkage void __init xen_start_kernel(void)
34071
34072 machine_ops = xen_machine_ops;
34073
34074- /*
34075- * The only reliable way to retain the initial address of the
34076- * percpu gdt_page is to remember it here, so we can go and
34077- * mark it RW later, when the initial percpu area is freed.
34078- */
34079- xen_initial_gdt = &per_cpu(gdt_page, 0);
34080-
34081 xen_smp_init();
34082
34083 #ifdef CONFIG_ACPI_NUMA
34084diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
34085index fdc3ba2..3daee39 100644
34086--- a/arch/x86/xen/mmu.c
34087+++ b/arch/x86/xen/mmu.c
34088@@ -1894,6 +1894,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
34089 /* L3_k[510] -> level2_kernel_pgt
34090 * L3_i[511] -> level2_fixmap_pgt */
34091 convert_pfn_mfn(level3_kernel_pgt);
34092+ convert_pfn_mfn(level3_vmalloc_start_pgt);
34093+ convert_pfn_mfn(level3_vmalloc_end_pgt);
34094+ convert_pfn_mfn(level3_vmemmap_pgt);
34095
34096 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
34097 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
34098@@ -1923,8 +1926,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
34099 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
34100 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
34101 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
34102+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
34103+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
34104+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
34105 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
34106 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
34107+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
34108 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
34109 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
34110
34111@@ -2108,6 +2115,7 @@ static void __init xen_post_allocator_init(void)
34112 pv_mmu_ops.set_pud = xen_set_pud;
34113 #if PAGETABLE_LEVELS == 4
34114 pv_mmu_ops.set_pgd = xen_set_pgd;
34115+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
34116 #endif
34117
34118 /* This will work as long as patching hasn't happened yet
34119@@ -2186,6 +2194,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
34120 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
34121 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
34122 .set_pgd = xen_set_pgd_hyper,
34123+ .set_pgd_batched = xen_set_pgd_hyper,
34124
34125 .alloc_pud = xen_alloc_pmd_init,
34126 .release_pud = xen_release_pmd_init,
34127diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
34128index b81c88e..2cbe7b8 100644
34129--- a/arch/x86/xen/smp.c
34130+++ b/arch/x86/xen/smp.c
34131@@ -272,11 +272,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
34132 {
34133 BUG_ON(smp_processor_id() != 0);
34134 native_smp_prepare_boot_cpu();
34135-
34136- /* We've switched to the "real" per-cpu gdt, so make sure the
34137- old memory can be recycled */
34138- make_lowmem_page_readwrite(xen_initial_gdt);
34139-
34140 xen_filter_cpu_maps();
34141 xen_setup_vcpu_info_placement();
34142 }
34143@@ -346,7 +341,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
34144 ctxt->user_regs.ss = __KERNEL_DS;
34145 #ifdef CONFIG_X86_32
34146 ctxt->user_regs.fs = __KERNEL_PERCPU;
34147- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
34148+ savesegment(gs, ctxt->user_regs.gs);
34149 #else
34150 ctxt->gs_base_kernel = per_cpu_offset(cpu);
34151 #endif
34152@@ -356,8 +351,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
34153
34154 {
34155 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
34156- ctxt->user_regs.ds = __USER_DS;
34157- ctxt->user_regs.es = __USER_DS;
34158+ ctxt->user_regs.ds = __KERNEL_DS;
34159+ ctxt->user_regs.es = __KERNEL_DS;
34160
34161 xen_copy_trap_info(ctxt->trap_ctxt);
34162
34163@@ -402,13 +397,12 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle)
34164 int rc;
34165
34166 per_cpu(current_task, cpu) = idle;
34167+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
34168 #ifdef CONFIG_X86_32
34169 irq_ctx_init(cpu);
34170 #else
34171 clear_tsk_thread_flag(idle, TIF_FORK);
34172- per_cpu(kernel_stack, cpu) =
34173- (unsigned long)task_stack_page(idle) -
34174- KERNEL_STACK_OFFSET + THREAD_SIZE;
34175+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
34176 #endif
34177 xen_setup_runstate_info(cpu);
34178 xen_setup_timer(cpu);
34179@@ -678,7 +672,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
34180
34181 void __init xen_smp_init(void)
34182 {
34183- smp_ops = xen_smp_ops;
34184+ memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
34185 xen_fill_possible_map();
34186 xen_init_spinlocks();
34187 }
34188diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
34189index 33ca6e4..0ded929 100644
34190--- a/arch/x86/xen/xen-asm_32.S
34191+++ b/arch/x86/xen/xen-asm_32.S
34192@@ -84,14 +84,14 @@ ENTRY(xen_iret)
34193 ESP_OFFSET=4 # bytes pushed onto stack
34194
34195 /*
34196- * Store vcpu_info pointer for easy access. Do it this way to
34197- * avoid having to reload %fs
34198+ * Store vcpu_info pointer for easy access.
34199 */
34200 #ifdef CONFIG_SMP
34201- GET_THREAD_INFO(%eax)
34202- movl %ss:TI_cpu(%eax), %eax
34203- movl %ss:__per_cpu_offset(,%eax,4), %eax
34204- mov %ss:xen_vcpu(%eax), %eax
34205+ push %fs
34206+ mov $(__KERNEL_PERCPU), %eax
34207+ mov %eax, %fs
34208+ mov PER_CPU_VAR(xen_vcpu), %eax
34209+ pop %fs
34210 #else
34211 movl %ss:xen_vcpu, %eax
34212 #endif
34213diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
34214index 7faed58..ba4427c 100644
34215--- a/arch/x86/xen/xen-head.S
34216+++ b/arch/x86/xen/xen-head.S
34217@@ -19,6 +19,17 @@ ENTRY(startup_xen)
34218 #ifdef CONFIG_X86_32
34219 mov %esi,xen_start_info
34220 mov $init_thread_union+THREAD_SIZE,%esp
34221+#ifdef CONFIG_SMP
34222+ movl $cpu_gdt_table,%edi
34223+ movl $__per_cpu_load,%eax
34224+ movw %ax,__KERNEL_PERCPU + 2(%edi)
34225+ rorl $16,%eax
34226+ movb %al,__KERNEL_PERCPU + 4(%edi)
34227+ movb %ah,__KERNEL_PERCPU + 7(%edi)
34228+ movl $__per_cpu_end - 1,%eax
34229+ subl $__per_cpu_start,%eax
34230+ movw %ax,__KERNEL_PERCPU + 0(%edi)
34231+#endif
34232 #else
34233 mov %rsi,xen_start_info
34234 mov $init_thread_union+THREAD_SIZE,%rsp
34235diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
34236index 86782c5..fa272c8 100644
34237--- a/arch/x86/xen/xen-ops.h
34238+++ b/arch/x86/xen/xen-ops.h
34239@@ -10,8 +10,6 @@
34240 extern const char xen_hypervisor_callback[];
34241 extern const char xen_failsafe_callback[];
34242
34243-extern void *xen_initial_gdt;
34244-
34245 struct trap_info;
34246 void xen_copy_trap_info(struct trap_info *traps);
34247
34248diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
34249index 525bd3d..ef888b1 100644
34250--- a/arch/xtensa/variants/dc232b/include/variant/core.h
34251+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
34252@@ -119,9 +119,9 @@
34253 ----------------------------------------------------------------------*/
34254
34255 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
34256-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
34257 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
34258 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
34259+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
34260
34261 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
34262 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
34263diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
34264index 2f33760..835e50a 100644
34265--- a/arch/xtensa/variants/fsf/include/variant/core.h
34266+++ b/arch/xtensa/variants/fsf/include/variant/core.h
34267@@ -11,6 +11,7 @@
34268 #ifndef _XTENSA_CORE_H
34269 #define _XTENSA_CORE_H
34270
34271+#include <linux/const.h>
34272
34273 /****************************************************************************
34274 Parameters Useful for Any Code, USER or PRIVILEGED
34275@@ -112,9 +113,9 @@
34276 ----------------------------------------------------------------------*/
34277
34278 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
34279-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
34280 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
34281 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
34282+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
34283
34284 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
34285 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
34286diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
34287index af00795..2bb8105 100644
34288--- a/arch/xtensa/variants/s6000/include/variant/core.h
34289+++ b/arch/xtensa/variants/s6000/include/variant/core.h
34290@@ -11,6 +11,7 @@
34291 #ifndef _XTENSA_CORE_CONFIGURATION_H
34292 #define _XTENSA_CORE_CONFIGURATION_H
34293
34294+#include <linux/const.h>
34295
34296 /****************************************************************************
34297 Parameters Useful for Any Code, USER or PRIVILEGED
34298@@ -118,9 +119,9 @@
34299 ----------------------------------------------------------------------*/
34300
34301 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
34302-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
34303 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
34304 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
34305+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
34306
34307 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
34308 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
34309diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
34310index 290792a..416f287 100644
34311--- a/block/blk-cgroup.c
34312+++ b/block/blk-cgroup.c
34313@@ -808,7 +808,7 @@ static void blkcg_css_free(struct cgroup *cgroup)
34314
34315 static struct cgroup_subsys_state *blkcg_css_alloc(struct cgroup *cgroup)
34316 {
34317- static atomic64_t id_seq = ATOMIC64_INIT(0);
34318+ static atomic64_unchecked_t id_seq = ATOMIC64_INIT(0);
34319 struct blkcg *blkcg;
34320 struct cgroup *parent = cgroup->parent;
34321
34322@@ -823,7 +823,7 @@ static struct cgroup_subsys_state *blkcg_css_alloc(struct cgroup *cgroup)
34323
34324 blkcg->cfq_weight = CFQ_WEIGHT_DEFAULT;
34325 blkcg->cfq_leaf_weight = CFQ_WEIGHT_DEFAULT;
34326- blkcg->id = atomic64_inc_return(&id_seq); /* root is 0, start from 1 */
34327+ blkcg->id = atomic64_inc_return_unchecked(&id_seq); /* root is 0, start from 1 */
34328 done:
34329 spin_lock_init(&blkcg->lock);
34330 INIT_RADIX_TREE(&blkcg->blkg_tree, GFP_ATOMIC);
34331diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
34332index 4b8d9b54..a7178c0 100644
34333--- a/block/blk-iopoll.c
34334+++ b/block/blk-iopoll.c
34335@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
34336 }
34337 EXPORT_SYMBOL(blk_iopoll_complete);
34338
34339-static void blk_iopoll_softirq(struct softirq_action *h)
34340+static __latent_entropy void blk_iopoll_softirq(void)
34341 {
34342 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
34343 int rearm = 0, budget = blk_iopoll_budget;
34344diff --git a/block/blk-map.c b/block/blk-map.c
34345index 623e1cd..ca1e109 100644
34346--- a/block/blk-map.c
34347+++ b/block/blk-map.c
34348@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
34349 if (!len || !kbuf)
34350 return -EINVAL;
34351
34352- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
34353+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
34354 if (do_copy)
34355 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
34356 else
34357diff --git a/block/blk-softirq.c b/block/blk-softirq.c
34358index ec9e606..3f38839 100644
34359--- a/block/blk-softirq.c
34360+++ b/block/blk-softirq.c
34361@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
34362 * Softirq action handler - move entries to local list and loop over them
34363 * while passing them to the queue registered handler.
34364 */
34365-static void blk_done_softirq(struct softirq_action *h)
34366+static __latent_entropy void blk_done_softirq(void)
34367 {
34368 struct list_head *cpu_list, local_list;
34369
34370diff --git a/block/bsg.c b/block/bsg.c
34371index 420a5a9..23834aa 100644
34372--- a/block/bsg.c
34373+++ b/block/bsg.c
34374@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
34375 struct sg_io_v4 *hdr, struct bsg_device *bd,
34376 fmode_t has_write_perm)
34377 {
34378+ unsigned char tmpcmd[sizeof(rq->__cmd)];
34379+ unsigned char *cmdptr;
34380+
34381 if (hdr->request_len > BLK_MAX_CDB) {
34382 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
34383 if (!rq->cmd)
34384 return -ENOMEM;
34385- }
34386+ cmdptr = rq->cmd;
34387+ } else
34388+ cmdptr = tmpcmd;
34389
34390- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
34391+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
34392 hdr->request_len))
34393 return -EFAULT;
34394
34395+ if (cmdptr != rq->cmd)
34396+ memcpy(rq->cmd, cmdptr, hdr->request_len);
34397+
34398 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
34399 if (blk_verify_command(rq->cmd, has_write_perm))
34400 return -EPERM;
34401diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
34402index 7e5d474..0cf0017 100644
34403--- a/block/compat_ioctl.c
34404+++ b/block/compat_ioctl.c
34405@@ -341,7 +341,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
34406 err |= __get_user(f->spec1, &uf->spec1);
34407 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
34408 err |= __get_user(name, &uf->name);
34409- f->name = compat_ptr(name);
34410+ f->name = (void __force_kernel *)compat_ptr(name);
34411 if (err) {
34412 err = -EFAULT;
34413 goto out;
34414diff --git a/block/genhd.c b/block/genhd.c
34415index dadf42b..48dc887 100644
34416--- a/block/genhd.c
34417+++ b/block/genhd.c
34418@@ -467,21 +467,24 @@ static char *bdevt_str(dev_t devt, char *buf)
34419
34420 /*
34421 * Register device numbers dev..(dev+range-1)
34422- * range must be nonzero
34423+ * Noop if @range is zero.
34424 * The hash chain is sorted on range, so that subranges can override.
34425 */
34426 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
34427 struct kobject *(*probe)(dev_t, int *, void *),
34428 int (*lock)(dev_t, void *), void *data)
34429 {
34430- kobj_map(bdev_map, devt, range, module, probe, lock, data);
34431+ if (range)
34432+ kobj_map(bdev_map, devt, range, module, probe, lock, data);
34433 }
34434
34435 EXPORT_SYMBOL(blk_register_region);
34436
34437+/* undo blk_register_region(), noop if @range is zero */
34438 void blk_unregister_region(dev_t devt, unsigned long range)
34439 {
34440- kobj_unmap(bdev_map, devt, range);
34441+ if (range)
34442+ kobj_unmap(bdev_map, devt, range);
34443 }
34444
34445 EXPORT_SYMBOL(blk_unregister_region);
34446diff --git a/block/partitions/efi.c b/block/partitions/efi.c
34447index c85fc89..51e690b 100644
34448--- a/block/partitions/efi.c
34449+++ b/block/partitions/efi.c
34450@@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
34451 if (!gpt)
34452 return NULL;
34453
34454+ if (!le32_to_cpu(gpt->num_partition_entries))
34455+ return NULL;
34456+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
34457+ if (!pte)
34458+ return NULL;
34459+
34460 count = le32_to_cpu(gpt->num_partition_entries) *
34461 le32_to_cpu(gpt->sizeof_partition_entry);
34462- if (!count)
34463- return NULL;
34464- pte = kmalloc(count, GFP_KERNEL);
34465- if (!pte)
34466- return NULL;
34467-
34468 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
34469 (u8 *) pte,
34470 count) < count) {
34471diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
34472index a5ffcc9..3cedc9c 100644
34473--- a/block/scsi_ioctl.c
34474+++ b/block/scsi_ioctl.c
34475@@ -224,8 +224,20 @@ EXPORT_SYMBOL(blk_verify_command);
34476 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
34477 struct sg_io_hdr *hdr, fmode_t mode)
34478 {
34479- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
34480+ unsigned char tmpcmd[sizeof(rq->__cmd)];
34481+ unsigned char *cmdptr;
34482+
34483+ if (rq->cmd != rq->__cmd)
34484+ cmdptr = rq->cmd;
34485+ else
34486+ cmdptr = tmpcmd;
34487+
34488+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
34489 return -EFAULT;
34490+
34491+ if (cmdptr != rq->cmd)
34492+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
34493+
34494 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
34495 return -EPERM;
34496
34497@@ -434,6 +446,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
34498 int err;
34499 unsigned int in_len, out_len, bytes, opcode, cmdlen;
34500 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
34501+ unsigned char tmpcmd[sizeof(rq->__cmd)];
34502+ unsigned char *cmdptr;
34503
34504 if (!sic)
34505 return -EINVAL;
34506@@ -467,9 +481,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
34507 */
34508 err = -EFAULT;
34509 rq->cmd_len = cmdlen;
34510- if (copy_from_user(rq->cmd, sic->data, cmdlen))
34511+
34512+ if (rq->cmd != rq->__cmd)
34513+ cmdptr = rq->cmd;
34514+ else
34515+ cmdptr = tmpcmd;
34516+
34517+ if (copy_from_user(cmdptr, sic->data, cmdlen))
34518 goto error;
34519
34520+ if (rq->cmd != cmdptr)
34521+ memcpy(rq->cmd, cmdptr, cmdlen);
34522+
34523 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
34524 goto error;
34525
34526diff --git a/crypto/cryptd.c b/crypto/cryptd.c
34527index 7bdd61b..afec999 100644
34528--- a/crypto/cryptd.c
34529+++ b/crypto/cryptd.c
34530@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
34531
34532 struct cryptd_blkcipher_request_ctx {
34533 crypto_completion_t complete;
34534-};
34535+} __no_const;
34536
34537 struct cryptd_hash_ctx {
34538 struct crypto_shash *child;
34539@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
34540
34541 struct cryptd_aead_request_ctx {
34542 crypto_completion_t complete;
34543-};
34544+} __no_const;
34545
34546 static void cryptd_queue_worker(struct work_struct *work);
34547
34548diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
34549index f8c920c..ab2cb5a 100644
34550--- a/crypto/pcrypt.c
34551+++ b/crypto/pcrypt.c
34552@@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
34553 int ret;
34554
34555 pinst->kobj.kset = pcrypt_kset;
34556- ret = kobject_add(&pinst->kobj, NULL, name);
34557+ ret = kobject_add(&pinst->kobj, NULL, "%s", name);
34558 if (!ret)
34559 kobject_uevent(&pinst->kobj, KOBJ_ADD);
34560
34561diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
34562index f220d64..d359ad6 100644
34563--- a/drivers/acpi/apei/apei-internal.h
34564+++ b/drivers/acpi/apei/apei-internal.h
34565@@ -20,7 +20,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
34566 struct apei_exec_ins_type {
34567 u32 flags;
34568 apei_exec_ins_func_t run;
34569-};
34570+} __do_const;
34571
34572 struct apei_exec_context {
34573 u32 ip;
34574diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
34575index 33dc6a0..4b24b47 100644
34576--- a/drivers/acpi/apei/cper.c
34577+++ b/drivers/acpi/apei/cper.c
34578@@ -39,12 +39,12 @@
34579 */
34580 u64 cper_next_record_id(void)
34581 {
34582- static atomic64_t seq;
34583+ static atomic64_unchecked_t seq;
34584
34585- if (!atomic64_read(&seq))
34586- atomic64_set(&seq, ((u64)get_seconds()) << 32);
34587+ if (!atomic64_read_unchecked(&seq))
34588+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
34589
34590- return atomic64_inc_return(&seq);
34591+ return atomic64_inc_return_unchecked(&seq);
34592 }
34593 EXPORT_SYMBOL_GPL(cper_next_record_id);
34594
34595diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
34596index ec9b57d..9682b3a 100644
34597--- a/drivers/acpi/apei/ghes.c
34598+++ b/drivers/acpi/apei/ghes.c
34599@@ -478,7 +478,7 @@ static void __ghes_print_estatus(const char *pfx,
34600 const struct acpi_hest_generic *generic,
34601 const struct acpi_hest_generic_status *estatus)
34602 {
34603- static atomic_t seqno;
34604+ static atomic_unchecked_t seqno;
34605 unsigned int curr_seqno;
34606 char pfx_seq[64];
34607
34608@@ -489,7 +489,7 @@ static void __ghes_print_estatus(const char *pfx,
34609 else
34610 pfx = KERN_ERR;
34611 }
34612- curr_seqno = atomic_inc_return(&seqno);
34613+ curr_seqno = atomic_inc_return_unchecked(&seqno);
34614 snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
34615 printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
34616 pfx_seq, generic->header.source_id);
34617diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
34618index be60399..778b33e8 100644
34619--- a/drivers/acpi/bgrt.c
34620+++ b/drivers/acpi/bgrt.c
34621@@ -87,8 +87,10 @@ static int __init bgrt_init(void)
34622 return -ENODEV;
34623
34624 sysfs_bin_attr_init(&image_attr);
34625- image_attr.private = bgrt_image;
34626- image_attr.size = bgrt_image_size;
34627+ pax_open_kernel();
34628+ *(void **)&image_attr.private = bgrt_image;
34629+ *(size_t *)&image_attr.size = bgrt_image_size;
34630+ pax_close_kernel();
34631
34632 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
34633 if (!bgrt_kobj)
34634diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
34635index cb96296..b81293b 100644
34636--- a/drivers/acpi/blacklist.c
34637+++ b/drivers/acpi/blacklist.c
34638@@ -52,7 +52,7 @@ struct acpi_blacklist_item {
34639 u32 is_critical_error;
34640 };
34641
34642-static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
34643+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
34644
34645 /*
34646 * POLICY: If *anything* doesn't work, put it on the blacklist.
34647@@ -193,7 +193,7 @@ static int __init dmi_disable_osi_win7(const struct dmi_system_id *d)
34648 return 0;
34649 }
34650
34651-static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
34652+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
34653 {
34654 .callback = dmi_disable_osi_vista,
34655 .ident = "Fujitsu Siemens",
34656diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
34657index f98dd00..7b69865 100644
34658--- a/drivers/acpi/processor_idle.c
34659+++ b/drivers/acpi/processor_idle.c
34660@@ -992,7 +992,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
34661 {
34662 int i, count = CPUIDLE_DRIVER_STATE_START;
34663 struct acpi_processor_cx *cx;
34664- struct cpuidle_state *state;
34665+ cpuidle_state_no_const *state;
34666 struct cpuidle_driver *drv = &acpi_idle_driver;
34667
34668 if (!pr->flags.power_setup_done)
34669diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
34670index 05306a5..733d1f0 100644
34671--- a/drivers/acpi/sysfs.c
34672+++ b/drivers/acpi/sysfs.c
34673@@ -423,11 +423,11 @@ static u32 num_counters;
34674 static struct attribute **all_attrs;
34675 static u32 acpi_gpe_count;
34676
34677-static struct attribute_group interrupt_stats_attr_group = {
34678+static attribute_group_no_const interrupt_stats_attr_group = {
34679 .name = "interrupts",
34680 };
34681
34682-static struct kobj_attribute *counter_attrs;
34683+static kobj_attribute_no_const *counter_attrs;
34684
34685 static void delete_gpe_attr_array(void)
34686 {
34687diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
34688index acfd0f7..e5acb08 100644
34689--- a/drivers/ata/libahci.c
34690+++ b/drivers/ata/libahci.c
34691@@ -1231,7 +1231,7 @@ int ahci_kick_engine(struct ata_port *ap)
34692 }
34693 EXPORT_SYMBOL_GPL(ahci_kick_engine);
34694
34695-static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
34696+static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
34697 struct ata_taskfile *tf, int is_cmd, u16 flags,
34698 unsigned long timeout_msec)
34699 {
34700diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
34701index c24354d..335c975 100644
34702--- a/drivers/ata/libata-core.c
34703+++ b/drivers/ata/libata-core.c
34704@@ -98,7 +98,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
34705 static void ata_dev_xfermask(struct ata_device *dev);
34706 static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
34707
34708-atomic_t ata_print_id = ATOMIC_INIT(0);
34709+atomic_unchecked_t ata_print_id = ATOMIC_INIT(0);
34710
34711 struct ata_force_param {
34712 const char *name;
34713@@ -4792,7 +4792,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
34714 struct ata_port *ap;
34715 unsigned int tag;
34716
34717- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
34718+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
34719 ap = qc->ap;
34720
34721 qc->flags = 0;
34722@@ -4808,7 +4808,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
34723 struct ata_port *ap;
34724 struct ata_link *link;
34725
34726- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
34727+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
34728 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
34729 ap = qc->ap;
34730 link = qc->dev->link;
34731@@ -5927,6 +5927,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
34732 return;
34733
34734 spin_lock(&lock);
34735+ pax_open_kernel();
34736
34737 for (cur = ops->inherits; cur; cur = cur->inherits) {
34738 void **inherit = (void **)cur;
34739@@ -5940,8 +5941,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
34740 if (IS_ERR(*pp))
34741 *pp = NULL;
34742
34743- ops->inherits = NULL;
34744+ *(struct ata_port_operations **)&ops->inherits = NULL;
34745
34746+ pax_close_kernel();
34747 spin_unlock(&lock);
34748 }
34749
34750@@ -6134,7 +6136,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
34751
34752 /* give ports names and add SCSI hosts */
34753 for (i = 0; i < host->n_ports; i++) {
34754- host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
34755+ host->ports[i]->print_id = atomic_inc_return_unchecked(&ata_print_id);
34756 host->ports[i]->local_port_no = i + 1;
34757 }
34758
34759diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
34760index b1e880a..8cf82e1 100644
34761--- a/drivers/ata/libata-scsi.c
34762+++ b/drivers/ata/libata-scsi.c
34763@@ -4104,7 +4104,7 @@ int ata_sas_port_init(struct ata_port *ap)
34764
34765 if (rc)
34766 return rc;
34767- ap->print_id = atomic_inc_return(&ata_print_id);
34768+ ap->print_id = atomic_inc_return_unchecked(&ata_print_id);
34769 return 0;
34770 }
34771 EXPORT_SYMBOL_GPL(ata_sas_port_init);
34772diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
34773index 577d902b..cb4781e 100644
34774--- a/drivers/ata/libata.h
34775+++ b/drivers/ata/libata.h
34776@@ -53,7 +53,7 @@ enum {
34777 ATA_DNXFER_QUIET = (1 << 31),
34778 };
34779
34780-extern atomic_t ata_print_id;
34781+extern atomic_unchecked_t ata_print_id;
34782 extern int atapi_passthru16;
34783 extern int libata_fua;
34784 extern int libata_noacpi;
34785diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
34786index 848ed32..132f39d 100644
34787--- a/drivers/ata/pata_arasan_cf.c
34788+++ b/drivers/ata/pata_arasan_cf.c
34789@@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
34790 /* Handle platform specific quirks */
34791 if (quirk) {
34792 if (quirk & CF_BROKEN_PIO) {
34793- ap->ops->set_piomode = NULL;
34794+ pax_open_kernel();
34795+ *(void **)&ap->ops->set_piomode = NULL;
34796+ pax_close_kernel();
34797 ap->pio_mask = 0;
34798 }
34799 if (quirk & CF_BROKEN_MWDMA)
34800diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
34801index f9b983a..887b9d8 100644
34802--- a/drivers/atm/adummy.c
34803+++ b/drivers/atm/adummy.c
34804@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
34805 vcc->pop(vcc, skb);
34806 else
34807 dev_kfree_skb_any(skb);
34808- atomic_inc(&vcc->stats->tx);
34809+ atomic_inc_unchecked(&vcc->stats->tx);
34810
34811 return 0;
34812 }
34813diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
34814index 62a7607..cc4be104 100644
34815--- a/drivers/atm/ambassador.c
34816+++ b/drivers/atm/ambassador.c
34817@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
34818 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
34819
34820 // VC layer stats
34821- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
34822+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
34823
34824 // free the descriptor
34825 kfree (tx_descr);
34826@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
34827 dump_skb ("<<<", vc, skb);
34828
34829 // VC layer stats
34830- atomic_inc(&atm_vcc->stats->rx);
34831+ atomic_inc_unchecked(&atm_vcc->stats->rx);
34832 __net_timestamp(skb);
34833 // end of our responsibility
34834 atm_vcc->push (atm_vcc, skb);
34835@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
34836 } else {
34837 PRINTK (KERN_INFO, "dropped over-size frame");
34838 // should we count this?
34839- atomic_inc(&atm_vcc->stats->rx_drop);
34840+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
34841 }
34842
34843 } else {
34844@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
34845 }
34846
34847 if (check_area (skb->data, skb->len)) {
34848- atomic_inc(&atm_vcc->stats->tx_err);
34849+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
34850 return -ENOMEM; // ?
34851 }
34852
34853diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
34854index 0e3f8f9..765a7a5 100644
34855--- a/drivers/atm/atmtcp.c
34856+++ b/drivers/atm/atmtcp.c
34857@@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
34858 if (vcc->pop) vcc->pop(vcc,skb);
34859 else dev_kfree_skb(skb);
34860 if (dev_data) return 0;
34861- atomic_inc(&vcc->stats->tx_err);
34862+ atomic_inc_unchecked(&vcc->stats->tx_err);
34863 return -ENOLINK;
34864 }
34865 size = skb->len+sizeof(struct atmtcp_hdr);
34866@@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
34867 if (!new_skb) {
34868 if (vcc->pop) vcc->pop(vcc,skb);
34869 else dev_kfree_skb(skb);
34870- atomic_inc(&vcc->stats->tx_err);
34871+ atomic_inc_unchecked(&vcc->stats->tx_err);
34872 return -ENOBUFS;
34873 }
34874 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
34875@@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
34876 if (vcc->pop) vcc->pop(vcc,skb);
34877 else dev_kfree_skb(skb);
34878 out_vcc->push(out_vcc,new_skb);
34879- atomic_inc(&vcc->stats->tx);
34880- atomic_inc(&out_vcc->stats->rx);
34881+ atomic_inc_unchecked(&vcc->stats->tx);
34882+ atomic_inc_unchecked(&out_vcc->stats->rx);
34883 return 0;
34884 }
34885
34886@@ -299,7 +299,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
34887 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
34888 read_unlock(&vcc_sklist_lock);
34889 if (!out_vcc) {
34890- atomic_inc(&vcc->stats->tx_err);
34891+ atomic_inc_unchecked(&vcc->stats->tx_err);
34892 goto done;
34893 }
34894 skb_pull(skb,sizeof(struct atmtcp_hdr));
34895@@ -311,8 +311,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
34896 __net_timestamp(new_skb);
34897 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
34898 out_vcc->push(out_vcc,new_skb);
34899- atomic_inc(&vcc->stats->tx);
34900- atomic_inc(&out_vcc->stats->rx);
34901+ atomic_inc_unchecked(&vcc->stats->tx);
34902+ atomic_inc_unchecked(&out_vcc->stats->rx);
34903 done:
34904 if (vcc->pop) vcc->pop(vcc,skb);
34905 else dev_kfree_skb(skb);
34906diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
34907index b1955ba..b179940 100644
34908--- a/drivers/atm/eni.c
34909+++ b/drivers/atm/eni.c
34910@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
34911 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
34912 vcc->dev->number);
34913 length = 0;
34914- atomic_inc(&vcc->stats->rx_err);
34915+ atomic_inc_unchecked(&vcc->stats->rx_err);
34916 }
34917 else {
34918 length = ATM_CELL_SIZE-1; /* no HEC */
34919@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
34920 size);
34921 }
34922 eff = length = 0;
34923- atomic_inc(&vcc->stats->rx_err);
34924+ atomic_inc_unchecked(&vcc->stats->rx_err);
34925 }
34926 else {
34927 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
34928@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
34929 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
34930 vcc->dev->number,vcc->vci,length,size << 2,descr);
34931 length = eff = 0;
34932- atomic_inc(&vcc->stats->rx_err);
34933+ atomic_inc_unchecked(&vcc->stats->rx_err);
34934 }
34935 }
34936 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
34937@@ -767,7 +767,7 @@ rx_dequeued++;
34938 vcc->push(vcc,skb);
34939 pushed++;
34940 }
34941- atomic_inc(&vcc->stats->rx);
34942+ atomic_inc_unchecked(&vcc->stats->rx);
34943 }
34944 wake_up(&eni_dev->rx_wait);
34945 }
34946@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
34947 PCI_DMA_TODEVICE);
34948 if (vcc->pop) vcc->pop(vcc,skb);
34949 else dev_kfree_skb_irq(skb);
34950- atomic_inc(&vcc->stats->tx);
34951+ atomic_inc_unchecked(&vcc->stats->tx);
34952 wake_up(&eni_dev->tx_wait);
34953 dma_complete++;
34954 }
34955diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
34956index b41c948..a002b17 100644
34957--- a/drivers/atm/firestream.c
34958+++ b/drivers/atm/firestream.c
34959@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
34960 }
34961 }
34962
34963- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
34964+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
34965
34966 fs_dprintk (FS_DEBUG_TXMEM, "i");
34967 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
34968@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
34969 #endif
34970 skb_put (skb, qe->p1 & 0xffff);
34971 ATM_SKB(skb)->vcc = atm_vcc;
34972- atomic_inc(&atm_vcc->stats->rx);
34973+ atomic_inc_unchecked(&atm_vcc->stats->rx);
34974 __net_timestamp(skb);
34975 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
34976 atm_vcc->push (atm_vcc, skb);
34977@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
34978 kfree (pe);
34979 }
34980 if (atm_vcc)
34981- atomic_inc(&atm_vcc->stats->rx_drop);
34982+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
34983 break;
34984 case 0x1f: /* Reassembly abort: no buffers. */
34985 /* Silently increment error counter. */
34986 if (atm_vcc)
34987- atomic_inc(&atm_vcc->stats->rx_drop);
34988+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
34989 break;
34990 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
34991 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
34992diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
34993index 204814e..cede831 100644
34994--- a/drivers/atm/fore200e.c
34995+++ b/drivers/atm/fore200e.c
34996@@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
34997 #endif
34998 /* check error condition */
34999 if (*entry->status & STATUS_ERROR)
35000- atomic_inc(&vcc->stats->tx_err);
35001+ atomic_inc_unchecked(&vcc->stats->tx_err);
35002 else
35003- atomic_inc(&vcc->stats->tx);
35004+ atomic_inc_unchecked(&vcc->stats->tx);
35005 }
35006 }
35007
35008@@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
35009 if (skb == NULL) {
35010 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
35011
35012- atomic_inc(&vcc->stats->rx_drop);
35013+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35014 return -ENOMEM;
35015 }
35016
35017@@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
35018
35019 dev_kfree_skb_any(skb);
35020
35021- atomic_inc(&vcc->stats->rx_drop);
35022+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35023 return -ENOMEM;
35024 }
35025
35026 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
35027
35028 vcc->push(vcc, skb);
35029- atomic_inc(&vcc->stats->rx);
35030+ atomic_inc_unchecked(&vcc->stats->rx);
35031
35032 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
35033
35034@@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
35035 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
35036 fore200e->atm_dev->number,
35037 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
35038- atomic_inc(&vcc->stats->rx_err);
35039+ atomic_inc_unchecked(&vcc->stats->rx_err);
35040 }
35041 }
35042
35043@@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
35044 goto retry_here;
35045 }
35046
35047- atomic_inc(&vcc->stats->tx_err);
35048+ atomic_inc_unchecked(&vcc->stats->tx_err);
35049
35050 fore200e->tx_sat++;
35051 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
35052diff --git a/drivers/atm/he.c b/drivers/atm/he.c
35053index 507362a..a845e57 100644
35054--- a/drivers/atm/he.c
35055+++ b/drivers/atm/he.c
35056@@ -1698,7 +1698,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
35057
35058 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
35059 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
35060- atomic_inc(&vcc->stats->rx_drop);
35061+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35062 goto return_host_buffers;
35063 }
35064
35065@@ -1725,7 +1725,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
35066 RBRQ_LEN_ERR(he_dev->rbrq_head)
35067 ? "LEN_ERR" : "",
35068 vcc->vpi, vcc->vci);
35069- atomic_inc(&vcc->stats->rx_err);
35070+ atomic_inc_unchecked(&vcc->stats->rx_err);
35071 goto return_host_buffers;
35072 }
35073
35074@@ -1777,7 +1777,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
35075 vcc->push(vcc, skb);
35076 spin_lock(&he_dev->global_lock);
35077
35078- atomic_inc(&vcc->stats->rx);
35079+ atomic_inc_unchecked(&vcc->stats->rx);
35080
35081 return_host_buffers:
35082 ++pdus_assembled;
35083@@ -2103,7 +2103,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
35084 tpd->vcc->pop(tpd->vcc, tpd->skb);
35085 else
35086 dev_kfree_skb_any(tpd->skb);
35087- atomic_inc(&tpd->vcc->stats->tx_err);
35088+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
35089 }
35090 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
35091 return;
35092@@ -2515,7 +2515,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35093 vcc->pop(vcc, skb);
35094 else
35095 dev_kfree_skb_any(skb);
35096- atomic_inc(&vcc->stats->tx_err);
35097+ atomic_inc_unchecked(&vcc->stats->tx_err);
35098 return -EINVAL;
35099 }
35100
35101@@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35102 vcc->pop(vcc, skb);
35103 else
35104 dev_kfree_skb_any(skb);
35105- atomic_inc(&vcc->stats->tx_err);
35106+ atomic_inc_unchecked(&vcc->stats->tx_err);
35107 return -EINVAL;
35108 }
35109 #endif
35110@@ -2538,7 +2538,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35111 vcc->pop(vcc, skb);
35112 else
35113 dev_kfree_skb_any(skb);
35114- atomic_inc(&vcc->stats->tx_err);
35115+ atomic_inc_unchecked(&vcc->stats->tx_err);
35116 spin_unlock_irqrestore(&he_dev->global_lock, flags);
35117 return -ENOMEM;
35118 }
35119@@ -2580,7 +2580,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35120 vcc->pop(vcc, skb);
35121 else
35122 dev_kfree_skb_any(skb);
35123- atomic_inc(&vcc->stats->tx_err);
35124+ atomic_inc_unchecked(&vcc->stats->tx_err);
35125 spin_unlock_irqrestore(&he_dev->global_lock, flags);
35126 return -ENOMEM;
35127 }
35128@@ -2611,7 +2611,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35129 __enqueue_tpd(he_dev, tpd, cid);
35130 spin_unlock_irqrestore(&he_dev->global_lock, flags);
35131
35132- atomic_inc(&vcc->stats->tx);
35133+ atomic_inc_unchecked(&vcc->stats->tx);
35134
35135 return 0;
35136 }
35137diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
35138index 1dc0519..1aadaf7 100644
35139--- a/drivers/atm/horizon.c
35140+++ b/drivers/atm/horizon.c
35141@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
35142 {
35143 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
35144 // VC layer stats
35145- atomic_inc(&vcc->stats->rx);
35146+ atomic_inc_unchecked(&vcc->stats->rx);
35147 __net_timestamp(skb);
35148 // end of our responsibility
35149 vcc->push (vcc, skb);
35150@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
35151 dev->tx_iovec = NULL;
35152
35153 // VC layer stats
35154- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
35155+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
35156
35157 // free the skb
35158 hrz_kfree_skb (skb);
35159diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
35160index 272f009..a18ba55 100644
35161--- a/drivers/atm/idt77252.c
35162+++ b/drivers/atm/idt77252.c
35163@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
35164 else
35165 dev_kfree_skb(skb);
35166
35167- atomic_inc(&vcc->stats->tx);
35168+ atomic_inc_unchecked(&vcc->stats->tx);
35169 }
35170
35171 atomic_dec(&scq->used);
35172@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35173 if ((sb = dev_alloc_skb(64)) == NULL) {
35174 printk("%s: Can't allocate buffers for aal0.\n",
35175 card->name);
35176- atomic_add(i, &vcc->stats->rx_drop);
35177+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
35178 break;
35179 }
35180 if (!atm_charge(vcc, sb->truesize)) {
35181 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
35182 card->name);
35183- atomic_add(i - 1, &vcc->stats->rx_drop);
35184+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
35185 dev_kfree_skb(sb);
35186 break;
35187 }
35188@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35189 ATM_SKB(sb)->vcc = vcc;
35190 __net_timestamp(sb);
35191 vcc->push(vcc, sb);
35192- atomic_inc(&vcc->stats->rx);
35193+ atomic_inc_unchecked(&vcc->stats->rx);
35194
35195 cell += ATM_CELL_PAYLOAD;
35196 }
35197@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35198 "(CDC: %08x)\n",
35199 card->name, len, rpp->len, readl(SAR_REG_CDC));
35200 recycle_rx_pool_skb(card, rpp);
35201- atomic_inc(&vcc->stats->rx_err);
35202+ atomic_inc_unchecked(&vcc->stats->rx_err);
35203 return;
35204 }
35205 if (stat & SAR_RSQE_CRC) {
35206 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
35207 recycle_rx_pool_skb(card, rpp);
35208- atomic_inc(&vcc->stats->rx_err);
35209+ atomic_inc_unchecked(&vcc->stats->rx_err);
35210 return;
35211 }
35212 if (skb_queue_len(&rpp->queue) > 1) {
35213@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35214 RXPRINTK("%s: Can't alloc RX skb.\n",
35215 card->name);
35216 recycle_rx_pool_skb(card, rpp);
35217- atomic_inc(&vcc->stats->rx_err);
35218+ atomic_inc_unchecked(&vcc->stats->rx_err);
35219 return;
35220 }
35221 if (!atm_charge(vcc, skb->truesize)) {
35222@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35223 __net_timestamp(skb);
35224
35225 vcc->push(vcc, skb);
35226- atomic_inc(&vcc->stats->rx);
35227+ atomic_inc_unchecked(&vcc->stats->rx);
35228
35229 return;
35230 }
35231@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35232 __net_timestamp(skb);
35233
35234 vcc->push(vcc, skb);
35235- atomic_inc(&vcc->stats->rx);
35236+ atomic_inc_unchecked(&vcc->stats->rx);
35237
35238 if (skb->truesize > SAR_FB_SIZE_3)
35239 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
35240@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
35241 if (vcc->qos.aal != ATM_AAL0) {
35242 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
35243 card->name, vpi, vci);
35244- atomic_inc(&vcc->stats->rx_drop);
35245+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35246 goto drop;
35247 }
35248
35249 if ((sb = dev_alloc_skb(64)) == NULL) {
35250 printk("%s: Can't allocate buffers for AAL0.\n",
35251 card->name);
35252- atomic_inc(&vcc->stats->rx_err);
35253+ atomic_inc_unchecked(&vcc->stats->rx_err);
35254 goto drop;
35255 }
35256
35257@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
35258 ATM_SKB(sb)->vcc = vcc;
35259 __net_timestamp(sb);
35260 vcc->push(vcc, sb);
35261- atomic_inc(&vcc->stats->rx);
35262+ atomic_inc_unchecked(&vcc->stats->rx);
35263
35264 drop:
35265 skb_pull(queue, 64);
35266@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
35267
35268 if (vc == NULL) {
35269 printk("%s: NULL connection in send().\n", card->name);
35270- atomic_inc(&vcc->stats->tx_err);
35271+ atomic_inc_unchecked(&vcc->stats->tx_err);
35272 dev_kfree_skb(skb);
35273 return -EINVAL;
35274 }
35275 if (!test_bit(VCF_TX, &vc->flags)) {
35276 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
35277- atomic_inc(&vcc->stats->tx_err);
35278+ atomic_inc_unchecked(&vcc->stats->tx_err);
35279 dev_kfree_skb(skb);
35280 return -EINVAL;
35281 }
35282@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
35283 break;
35284 default:
35285 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
35286- atomic_inc(&vcc->stats->tx_err);
35287+ atomic_inc_unchecked(&vcc->stats->tx_err);
35288 dev_kfree_skb(skb);
35289 return -EINVAL;
35290 }
35291
35292 if (skb_shinfo(skb)->nr_frags != 0) {
35293 printk("%s: No scatter-gather yet.\n", card->name);
35294- atomic_inc(&vcc->stats->tx_err);
35295+ atomic_inc_unchecked(&vcc->stats->tx_err);
35296 dev_kfree_skb(skb);
35297 return -EINVAL;
35298 }
35299@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
35300
35301 err = queue_skb(card, vc, skb, oam);
35302 if (err) {
35303- atomic_inc(&vcc->stats->tx_err);
35304+ atomic_inc_unchecked(&vcc->stats->tx_err);
35305 dev_kfree_skb(skb);
35306 return err;
35307 }
35308@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
35309 skb = dev_alloc_skb(64);
35310 if (!skb) {
35311 printk("%s: Out of memory in send_oam().\n", card->name);
35312- atomic_inc(&vcc->stats->tx_err);
35313+ atomic_inc_unchecked(&vcc->stats->tx_err);
35314 return -ENOMEM;
35315 }
35316 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
35317diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
35318index 4217f29..88f547a 100644
35319--- a/drivers/atm/iphase.c
35320+++ b/drivers/atm/iphase.c
35321@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
35322 status = (u_short) (buf_desc_ptr->desc_mode);
35323 if (status & (RX_CER | RX_PTE | RX_OFL))
35324 {
35325- atomic_inc(&vcc->stats->rx_err);
35326+ atomic_inc_unchecked(&vcc->stats->rx_err);
35327 IF_ERR(printk("IA: bad packet, dropping it");)
35328 if (status & RX_CER) {
35329 IF_ERR(printk(" cause: packet CRC error\n");)
35330@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
35331 len = dma_addr - buf_addr;
35332 if (len > iadev->rx_buf_sz) {
35333 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
35334- atomic_inc(&vcc->stats->rx_err);
35335+ atomic_inc_unchecked(&vcc->stats->rx_err);
35336 goto out_free_desc;
35337 }
35338
35339@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
35340 ia_vcc = INPH_IA_VCC(vcc);
35341 if (ia_vcc == NULL)
35342 {
35343- atomic_inc(&vcc->stats->rx_err);
35344+ atomic_inc_unchecked(&vcc->stats->rx_err);
35345 atm_return(vcc, skb->truesize);
35346 dev_kfree_skb_any(skb);
35347 goto INCR_DLE;
35348@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
35349 if ((length > iadev->rx_buf_sz) || (length >
35350 (skb->len - sizeof(struct cpcs_trailer))))
35351 {
35352- atomic_inc(&vcc->stats->rx_err);
35353+ atomic_inc_unchecked(&vcc->stats->rx_err);
35354 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
35355 length, skb->len);)
35356 atm_return(vcc, skb->truesize);
35357@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
35358
35359 IF_RX(printk("rx_dle_intr: skb push");)
35360 vcc->push(vcc,skb);
35361- atomic_inc(&vcc->stats->rx);
35362+ atomic_inc_unchecked(&vcc->stats->rx);
35363 iadev->rx_pkt_cnt++;
35364 }
35365 INCR_DLE:
35366@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
35367 {
35368 struct k_sonet_stats *stats;
35369 stats = &PRIV(_ia_dev[board])->sonet_stats;
35370- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
35371- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
35372- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
35373- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
35374- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
35375- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
35376- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
35377- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
35378- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
35379+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
35380+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
35381+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
35382+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
35383+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
35384+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
35385+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
35386+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
35387+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
35388 }
35389 ia_cmds.status = 0;
35390 break;
35391@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
35392 if ((desc == 0) || (desc > iadev->num_tx_desc))
35393 {
35394 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
35395- atomic_inc(&vcc->stats->tx);
35396+ atomic_inc_unchecked(&vcc->stats->tx);
35397 if (vcc->pop)
35398 vcc->pop(vcc, skb);
35399 else
35400@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
35401 ATM_DESC(skb) = vcc->vci;
35402 skb_queue_tail(&iadev->tx_dma_q, skb);
35403
35404- atomic_inc(&vcc->stats->tx);
35405+ atomic_inc_unchecked(&vcc->stats->tx);
35406 iadev->tx_pkt_cnt++;
35407 /* Increment transaction counter */
35408 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
35409
35410 #if 0
35411 /* add flow control logic */
35412- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
35413+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
35414 if (iavcc->vc_desc_cnt > 10) {
35415 vcc->tx_quota = vcc->tx_quota * 3 / 4;
35416 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
35417diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
35418index fa7d701..1e404c7 100644
35419--- a/drivers/atm/lanai.c
35420+++ b/drivers/atm/lanai.c
35421@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
35422 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
35423 lanai_endtx(lanai, lvcc);
35424 lanai_free_skb(lvcc->tx.atmvcc, skb);
35425- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
35426+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
35427 }
35428
35429 /* Try to fill the buffer - don't call unless there is backlog */
35430@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
35431 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
35432 __net_timestamp(skb);
35433 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
35434- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
35435+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
35436 out:
35437 lvcc->rx.buf.ptr = end;
35438 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
35439@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
35440 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
35441 "vcc %d\n", lanai->number, (unsigned int) s, vci);
35442 lanai->stats.service_rxnotaal5++;
35443- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
35444+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
35445 return 0;
35446 }
35447 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
35448@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
35449 int bytes;
35450 read_unlock(&vcc_sklist_lock);
35451 DPRINTK("got trashed rx pdu on vci %d\n", vci);
35452- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
35453+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
35454 lvcc->stats.x.aal5.service_trash++;
35455 bytes = (SERVICE_GET_END(s) * 16) -
35456 (((unsigned long) lvcc->rx.buf.ptr) -
35457@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
35458 }
35459 if (s & SERVICE_STREAM) {
35460 read_unlock(&vcc_sklist_lock);
35461- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
35462+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
35463 lvcc->stats.x.aal5.service_stream++;
35464 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
35465 "PDU on VCI %d!\n", lanai->number, vci);
35466@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
35467 return 0;
35468 }
35469 DPRINTK("got rx crc error on vci %d\n", vci);
35470- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
35471+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
35472 lvcc->stats.x.aal5.service_rxcrc++;
35473 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
35474 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
35475diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
35476index 6587dc2..149833d 100644
35477--- a/drivers/atm/nicstar.c
35478+++ b/drivers/atm/nicstar.c
35479@@ -1641,7 +1641,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
35480 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
35481 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
35482 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@@ -1649,7 +1649,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
35489 if (!vc->tx) {
35490 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
35491 card->index);
35492- atomic_inc(&vcc->stats->tx_err);
35493+ atomic_inc_unchecked(&vcc->stats->tx_err);
35494 dev_kfree_skb_any(skb);
35495 return -EINVAL;
35496 }
35497@@ -1657,14 +1657,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
35498 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
35499 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
35500 card->index);
35501- atomic_inc(&vcc->stats->tx_err);
35502+ atomic_inc_unchecked(&vcc->stats->tx_err);
35503 dev_kfree_skb_any(skb);
35504 return -EINVAL;
35505 }
35506
35507 if (skb_shinfo(skb)->nr_frags != 0) {
35508 printk("nicstar%d: No scatter-gather yet.\n", card->index);
35509- atomic_inc(&vcc->stats->tx_err);
35510+ atomic_inc_unchecked(&vcc->stats->tx_err);
35511 dev_kfree_skb_any(skb);
35512 return -EINVAL;
35513 }
35514@@ -1712,11 +1712,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
35515 }
35516
35517 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
35518- atomic_inc(&vcc->stats->tx_err);
35519+ atomic_inc_unchecked(&vcc->stats->tx_err);
35520 dev_kfree_skb_any(skb);
35521 return -EIO;
35522 }
35523- atomic_inc(&vcc->stats->tx);
35524+ atomic_inc_unchecked(&vcc->stats->tx);
35525
35526 return 0;
35527 }
35528@@ -2033,14 +2033,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35529 printk
35530 ("nicstar%d: Can't allocate buffers for aal0.\n",
35531 card->index);
35532- atomic_add(i, &vcc->stats->rx_drop);
35533+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
35534 break;
35535 }
35536 if (!atm_charge(vcc, sb->truesize)) {
35537 RXPRINTK
35538 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
35539 card->index);
35540- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
35541+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
35542 dev_kfree_skb_any(sb);
35543 break;
35544 }
35545@@ -2055,7 +2055,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35546 ATM_SKB(sb)->vcc = vcc;
35547 __net_timestamp(sb);
35548 vcc->push(vcc, sb);
35549- atomic_inc(&vcc->stats->rx);
35550+ atomic_inc_unchecked(&vcc->stats->rx);
35551 cell += ATM_CELL_PAYLOAD;
35552 }
35553
35554@@ -2072,7 +2072,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35555 if (iovb == NULL) {
35556 printk("nicstar%d: Out of iovec buffers.\n",
35557 card->index);
35558- atomic_inc(&vcc->stats->rx_drop);
35559+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35560 recycle_rx_buf(card, skb);
35561 return;
35562 }
35563@@ -2096,7 +2096,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35564 small or large buffer itself. */
35565 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
35566 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
35567- atomic_inc(&vcc->stats->rx_err);
35568+ atomic_inc_unchecked(&vcc->stats->rx_err);
35569 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
35570 NS_MAX_IOVECS);
35571 NS_PRV_IOVCNT(iovb) = 0;
35572@@ -2116,7 +2116,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35573 ("nicstar%d: Expected a small buffer, and this is not one.\n",
35574 card->index);
35575 which_list(card, skb);
35576- atomic_inc(&vcc->stats->rx_err);
35577+ atomic_inc_unchecked(&vcc->stats->rx_err);
35578 recycle_rx_buf(card, skb);
35579 vc->rx_iov = NULL;
35580 recycle_iov_buf(card, iovb);
35581@@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35582 ("nicstar%d: Expected a large buffer, and this is not one.\n",
35583 card->index);
35584 which_list(card, skb);
35585- atomic_inc(&vcc->stats->rx_err);
35586+ atomic_inc_unchecked(&vcc->stats->rx_err);
35587 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
35588 NS_PRV_IOVCNT(iovb));
35589 vc->rx_iov = NULL;
35590@@ -2152,7 +2152,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35591 printk(" - PDU size mismatch.\n");
35592 else
35593 printk(".\n");
35594- atomic_inc(&vcc->stats->rx_err);
35595+ atomic_inc_unchecked(&vcc->stats->rx_err);
35596 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
35597 NS_PRV_IOVCNT(iovb));
35598 vc->rx_iov = NULL;
35599@@ -2166,7 +2166,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35600 /* skb points to a small buffer */
35601 if (!atm_charge(vcc, skb->truesize)) {
35602 push_rxbufs(card, skb);
35603- atomic_inc(&vcc->stats->rx_drop);
35604+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35605 } else {
35606 skb_put(skb, len);
35607 dequeue_sm_buf(card, skb);
35608@@ -2176,7 +2176,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35609 ATM_SKB(skb)->vcc = vcc;
35610 __net_timestamp(skb);
35611 vcc->push(vcc, skb);
35612- atomic_inc(&vcc->stats->rx);
35613+ atomic_inc_unchecked(&vcc->stats->rx);
35614 }
35615 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
35616 struct sk_buff *sb;
35617@@ -2187,7 +2187,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35618 if (len <= NS_SMBUFSIZE) {
35619 if (!atm_charge(vcc, sb->truesize)) {
35620 push_rxbufs(card, sb);
35621- atomic_inc(&vcc->stats->rx_drop);
35622+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35623 } else {
35624 skb_put(sb, len);
35625 dequeue_sm_buf(card, sb);
35626@@ -2197,7 +2197,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35627 ATM_SKB(sb)->vcc = vcc;
35628 __net_timestamp(sb);
35629 vcc->push(vcc, sb);
35630- atomic_inc(&vcc->stats->rx);
35631+ atomic_inc_unchecked(&vcc->stats->rx);
35632 }
35633
35634 push_rxbufs(card, skb);
35635@@ -2206,7 +2206,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35636
35637 if (!atm_charge(vcc, skb->truesize)) {
35638 push_rxbufs(card, skb);
35639- atomic_inc(&vcc->stats->rx_drop);
35640+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35641 } else {
35642 dequeue_lg_buf(card, skb);
35643 #ifdef NS_USE_DESTRUCTORS
35644@@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35645 ATM_SKB(skb)->vcc = vcc;
35646 __net_timestamp(skb);
35647 vcc->push(vcc, skb);
35648- atomic_inc(&vcc->stats->rx);
35649+ atomic_inc_unchecked(&vcc->stats->rx);
35650 }
35651
35652 push_rxbufs(card, sb);
35653@@ -2240,7 +2240,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35654 printk
35655 ("nicstar%d: Out of huge buffers.\n",
35656 card->index);
35657- atomic_inc(&vcc->stats->rx_drop);
35658+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35659 recycle_iovec_rx_bufs(card,
35660 (struct iovec *)
35661 iovb->data,
35662@@ -2291,7 +2291,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35663 card->hbpool.count++;
35664 } else
35665 dev_kfree_skb_any(hb);
35666- atomic_inc(&vcc->stats->rx_drop);
35667+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35668 } else {
35669 /* Copy the small buffer to the huge buffer */
35670 sb = (struct sk_buff *)iov->iov_base;
35671@@ -2328,7 +2328,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35672 #endif /* NS_USE_DESTRUCTORS */
35673 __net_timestamp(hb);
35674 vcc->push(vcc, hb);
35675- atomic_inc(&vcc->stats->rx);
35676+ atomic_inc_unchecked(&vcc->stats->rx);
35677 }
35678 }
35679
35680diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
35681index 32784d1..4a8434a 100644
35682--- a/drivers/atm/solos-pci.c
35683+++ b/drivers/atm/solos-pci.c
35684@@ -838,7 +838,7 @@ void solos_bh(unsigned long card_arg)
35685 }
35686 atm_charge(vcc, skb->truesize);
35687 vcc->push(vcc, skb);
35688- atomic_inc(&vcc->stats->rx);
35689+ atomic_inc_unchecked(&vcc->stats->rx);
35690 break;
35691
35692 case PKT_STATUS:
35693@@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
35694 vcc = SKB_CB(oldskb)->vcc;
35695
35696 if (vcc) {
35697- atomic_inc(&vcc->stats->tx);
35698+ atomic_inc_unchecked(&vcc->stats->tx);
35699 solos_pop(vcc, oldskb);
35700 } else {
35701 dev_kfree_skb_irq(oldskb);
35702diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
35703index 0215934..ce9f5b1 100644
35704--- a/drivers/atm/suni.c
35705+++ b/drivers/atm/suni.c
35706@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
35707
35708
35709 #define ADD_LIMITED(s,v) \
35710- atomic_add((v),&stats->s); \
35711- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
35712+ atomic_add_unchecked((v),&stats->s); \
35713+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
35714
35715
35716 static void suni_hz(unsigned long from_timer)
35717diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
35718index 5120a96..e2572bd 100644
35719--- a/drivers/atm/uPD98402.c
35720+++ b/drivers/atm/uPD98402.c
35721@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
35722 struct sonet_stats tmp;
35723 int error = 0;
35724
35725- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
35726+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
35727 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
35728 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
35729 if (zero && !error) {
35730@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
35731
35732
35733 #define ADD_LIMITED(s,v) \
35734- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
35735- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
35736- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
35737+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
35738+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
35739+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
35740
35741
35742 static void stat_event(struct atm_dev *dev)
35743@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
35744 if (reason & uPD98402_INT_PFM) stat_event(dev);
35745 if (reason & uPD98402_INT_PCO) {
35746 (void) GET(PCOCR); /* clear interrupt cause */
35747- atomic_add(GET(HECCT),
35748+ atomic_add_unchecked(GET(HECCT),
35749 &PRIV(dev)->sonet_stats.uncorr_hcs);
35750 }
35751 if ((reason & uPD98402_INT_RFO) &&
35752@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
35753 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
35754 uPD98402_INT_LOS),PIMR); /* enable them */
35755 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
35756- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
35757- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
35758- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
35759+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
35760+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
35761+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
35762 return 0;
35763 }
35764
35765diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
35766index 969c3c2..9b72956 100644
35767--- a/drivers/atm/zatm.c
35768+++ b/drivers/atm/zatm.c
35769@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
35770 }
35771 if (!size) {
35772 dev_kfree_skb_irq(skb);
35773- if (vcc) atomic_inc(&vcc->stats->rx_err);
35774+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
35775 continue;
35776 }
35777 if (!atm_charge(vcc,skb->truesize)) {
35778@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
35779 skb->len = size;
35780 ATM_SKB(skb)->vcc = vcc;
35781 vcc->push(vcc,skb);
35782- atomic_inc(&vcc->stats->rx);
35783+ atomic_inc_unchecked(&vcc->stats->rx);
35784 }
35785 zout(pos & 0xffff,MTA(mbx));
35786 #if 0 /* probably a stupid idea */
35787@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
35788 skb_queue_head(&zatm_vcc->backlog,skb);
35789 break;
35790 }
35791- atomic_inc(&vcc->stats->tx);
35792+ atomic_inc_unchecked(&vcc->stats->tx);
35793 wake_up(&zatm_vcc->tx_wait);
35794 }
35795
35796diff --git a/drivers/base/bus.c b/drivers/base/bus.c
35797index d414331..b4dd4ba 100644
35798--- a/drivers/base/bus.c
35799+++ b/drivers/base/bus.c
35800@@ -1163,7 +1163,7 @@ int subsys_interface_register(struct subsys_interface *sif)
35801 return -EINVAL;
35802
35803 mutex_lock(&subsys->p->mutex);
35804- list_add_tail(&sif->node, &subsys->p->interfaces);
35805+ pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
35806 if (sif->add_dev) {
35807 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
35808 while ((dev = subsys_dev_iter_next(&iter)))
35809@@ -1188,7 +1188,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
35810 subsys = sif->subsys;
35811
35812 mutex_lock(&subsys->p->mutex);
35813- list_del_init(&sif->node);
35814+ pax_list_del_init((struct list_head *)&sif->node);
35815 if (sif->remove_dev) {
35816 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
35817 while ((dev = subsys_dev_iter_next(&iter)))
35818diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
35819index 7413d06..79155fa 100644
35820--- a/drivers/base/devtmpfs.c
35821+++ b/drivers/base/devtmpfs.c
35822@@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
35823 if (!thread)
35824 return 0;
35825
35826- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
35827+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
35828 if (err)
35829 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
35830 else
35831@@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
35832 *err = sys_unshare(CLONE_NEWNS);
35833 if (*err)
35834 goto out;
35835- *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
35836+ *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
35837 if (*err)
35838 goto out;
35839- sys_chdir("/.."); /* will traverse into overmounted root */
35840- sys_chroot(".");
35841+ sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
35842+ sys_chroot((char __force_user *)".");
35843 complete(&setup_done);
35844 while (1) {
35845 spin_lock(&req_lock);
35846diff --git a/drivers/base/node.c b/drivers/base/node.c
35847index 7616a77c..8f57f51 100644
35848--- a/drivers/base/node.c
35849+++ b/drivers/base/node.c
35850@@ -626,7 +626,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
35851 struct node_attr {
35852 struct device_attribute attr;
35853 enum node_states state;
35854-};
35855+} __do_const;
35856
35857 static ssize_t show_node_state(struct device *dev,
35858 struct device_attribute *attr, char *buf)
35859diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
35860index bfb8955..42c9b9a 100644
35861--- a/drivers/base/power/domain.c
35862+++ b/drivers/base/power/domain.c
35863@@ -1850,7 +1850,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
35864 {
35865 struct cpuidle_driver *cpuidle_drv;
35866 struct gpd_cpu_data *cpu_data;
35867- struct cpuidle_state *idle_state;
35868+ cpuidle_state_no_const *idle_state;
35869 int ret = 0;
35870
35871 if (IS_ERR_OR_NULL(genpd) || state < 0)
35872@@ -1918,7 +1918,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
35873 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
35874 {
35875 struct gpd_cpu_data *cpu_data;
35876- struct cpuidle_state *idle_state;
35877+ cpuidle_state_no_const *idle_state;
35878 int ret = 0;
35879
35880 if (IS_ERR_OR_NULL(genpd))
35881diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
35882index a53ebd2..8f73eeb 100644
35883--- a/drivers/base/power/sysfs.c
35884+++ b/drivers/base/power/sysfs.c
35885@@ -185,7 +185,7 @@ static ssize_t rtpm_status_show(struct device *dev,
35886 return -EIO;
35887 }
35888 }
35889- return sprintf(buf, p);
35890+ return sprintf(buf, "%s", p);
35891 }
35892
35893 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
35894diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
35895index 2d56f41..8830f19 100644
35896--- a/drivers/base/power/wakeup.c
35897+++ b/drivers/base/power/wakeup.c
35898@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
35899 * They need to be modified together atomically, so it's better to use one
35900 * atomic variable to hold them both.
35901 */
35902-static atomic_t combined_event_count = ATOMIC_INIT(0);
35903+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
35904
35905 #define IN_PROGRESS_BITS (sizeof(int) * 4)
35906 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
35907
35908 static void split_counters(unsigned int *cnt, unsigned int *inpr)
35909 {
35910- unsigned int comb = atomic_read(&combined_event_count);
35911+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
35912
35913 *cnt = (comb >> IN_PROGRESS_BITS);
35914 *inpr = comb & MAX_IN_PROGRESS;
35915@@ -395,7 +395,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
35916 ws->start_prevent_time = ws->last_time;
35917
35918 /* Increment the counter of events in progress. */
35919- cec = atomic_inc_return(&combined_event_count);
35920+ cec = atomic_inc_return_unchecked(&combined_event_count);
35921
35922 trace_wakeup_source_activate(ws->name, cec);
35923 }
35924@@ -521,7 +521,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
35925 * Increment the counter of registered wakeup events and decrement the
35926 * couter of wakeup events in progress simultaneously.
35927 */
35928- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
35929+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
35930 trace_wakeup_source_deactivate(ws->name, cec);
35931
35932 split_counters(&cnt, &inpr);
35933diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
35934index e8d11b6..7b1b36f 100644
35935--- a/drivers/base/syscore.c
35936+++ b/drivers/base/syscore.c
35937@@ -21,7 +21,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
35938 void register_syscore_ops(struct syscore_ops *ops)
35939 {
35940 mutex_lock(&syscore_ops_lock);
35941- list_add_tail(&ops->node, &syscore_ops_list);
35942+ pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
35943 mutex_unlock(&syscore_ops_lock);
35944 }
35945 EXPORT_SYMBOL_GPL(register_syscore_ops);
35946@@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
35947 void unregister_syscore_ops(struct syscore_ops *ops)
35948 {
35949 mutex_lock(&syscore_ops_lock);
35950- list_del(&ops->node);
35951+ pax_list_del((struct list_head *)&ops->node);
35952 mutex_unlock(&syscore_ops_lock);
35953 }
35954 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
35955diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
35956index 62b6c2c..002d10f 100644
35957--- a/drivers/block/cciss.c
35958+++ b/drivers/block/cciss.c
35959@@ -1189,6 +1189,7 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
35960 int err;
35961 u32 cp;
35962
35963+ memset(&arg64, 0, sizeof(arg64));
35964 err = 0;
35965 err |=
35966 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
35967@@ -3010,7 +3011,7 @@ static void start_io(ctlr_info_t *h)
35968 while (!list_empty(&h->reqQ)) {
35969 c = list_entry(h->reqQ.next, CommandList_struct, list);
35970 /* can't do anything if fifo is full */
35971- if ((h->access.fifo_full(h))) {
35972+ if ((h->access->fifo_full(h))) {
35973 dev_warn(&h->pdev->dev, "fifo full\n");
35974 break;
35975 }
35976@@ -3020,7 +3021,7 @@ static void start_io(ctlr_info_t *h)
35977 h->Qdepth--;
35978
35979 /* Tell the controller execute command */
35980- h->access.submit_command(h, c);
35981+ h->access->submit_command(h, c);
35982
35983 /* Put job onto the completed Q */
35984 addQ(&h->cmpQ, c);
35985@@ -3446,17 +3447,17 @@ startio:
35986
35987 static inline unsigned long get_next_completion(ctlr_info_t *h)
35988 {
35989- return h->access.command_completed(h);
35990+ return h->access->command_completed(h);
35991 }
35992
35993 static inline int interrupt_pending(ctlr_info_t *h)
35994 {
35995- return h->access.intr_pending(h);
35996+ return h->access->intr_pending(h);
35997 }
35998
35999 static inline long interrupt_not_for_us(ctlr_info_t *h)
36000 {
36001- return ((h->access.intr_pending(h) == 0) ||
36002+ return ((h->access->intr_pending(h) == 0) ||
36003 (h->interrupts_enabled == 0));
36004 }
36005
36006@@ -3489,7 +3490,7 @@ static inline u32 next_command(ctlr_info_t *h)
36007 u32 a;
36008
36009 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
36010- return h->access.command_completed(h);
36011+ return h->access->command_completed(h);
36012
36013 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
36014 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
36015@@ -4046,7 +4047,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
36016 trans_support & CFGTBL_Trans_use_short_tags);
36017
36018 /* Change the access methods to the performant access methods */
36019- h->access = SA5_performant_access;
36020+ h->access = &SA5_performant_access;
36021 h->transMethod = CFGTBL_Trans_Performant;
36022
36023 return;
36024@@ -4319,7 +4320,7 @@ static int cciss_pci_init(ctlr_info_t *h)
36025 if (prod_index < 0)
36026 return -ENODEV;
36027 h->product_name = products[prod_index].product_name;
36028- h->access = *(products[prod_index].access);
36029+ h->access = products[prod_index].access;
36030
36031 if (cciss_board_disabled(h)) {
36032 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
36033@@ -5051,7 +5052,7 @@ reinit_after_soft_reset:
36034 }
36035
36036 /* make sure the board interrupts are off */
36037- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36038+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36039 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
36040 if (rc)
36041 goto clean2;
36042@@ -5101,7 +5102,7 @@ reinit_after_soft_reset:
36043 * fake ones to scoop up any residual completions.
36044 */
36045 spin_lock_irqsave(&h->lock, flags);
36046- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36047+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36048 spin_unlock_irqrestore(&h->lock, flags);
36049 free_irq(h->intr[h->intr_mode], h);
36050 rc = cciss_request_irq(h, cciss_msix_discard_completions,
36051@@ -5121,9 +5122,9 @@ reinit_after_soft_reset:
36052 dev_info(&h->pdev->dev, "Board READY.\n");
36053 dev_info(&h->pdev->dev,
36054 "Waiting for stale completions to drain.\n");
36055- h->access.set_intr_mask(h, CCISS_INTR_ON);
36056+ h->access->set_intr_mask(h, CCISS_INTR_ON);
36057 msleep(10000);
36058- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36059+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36060
36061 rc = controller_reset_failed(h->cfgtable);
36062 if (rc)
36063@@ -5146,7 +5147,7 @@ reinit_after_soft_reset:
36064 cciss_scsi_setup(h);
36065
36066 /* Turn the interrupts on so we can service requests */
36067- h->access.set_intr_mask(h, CCISS_INTR_ON);
36068+ h->access->set_intr_mask(h, CCISS_INTR_ON);
36069
36070 /* Get the firmware version */
36071 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
36072@@ -5218,7 +5219,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
36073 kfree(flush_buf);
36074 if (return_code != IO_OK)
36075 dev_warn(&h->pdev->dev, "Error flushing cache\n");
36076- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36077+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36078 free_irq(h->intr[h->intr_mode], h);
36079 }
36080
36081diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
36082index 7fda30e..eb5dfe0 100644
36083--- a/drivers/block/cciss.h
36084+++ b/drivers/block/cciss.h
36085@@ -101,7 +101,7 @@ struct ctlr_info
36086 /* information about each logical volume */
36087 drive_info_struct *drv[CISS_MAX_LUN];
36088
36089- struct access_method access;
36090+ struct access_method *access;
36091
36092 /* queue and queue Info */
36093 struct list_head reqQ;
36094diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
36095index 639d26b..fd6ad1f 100644
36096--- a/drivers/block/cpqarray.c
36097+++ b/drivers/block/cpqarray.c
36098@@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
36099 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
36100 goto Enomem4;
36101 }
36102- hba[i]->access.set_intr_mask(hba[i], 0);
36103+ hba[i]->access->set_intr_mask(hba[i], 0);
36104 if (request_irq(hba[i]->intr, do_ida_intr,
36105 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
36106 {
36107@@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
36108 add_timer(&hba[i]->timer);
36109
36110 /* Enable IRQ now that spinlock and rate limit timer are set up */
36111- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
36112+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
36113
36114 for(j=0; j<NWD; j++) {
36115 struct gendisk *disk = ida_gendisk[i][j];
36116@@ -694,7 +694,7 @@ DBGINFO(
36117 for(i=0; i<NR_PRODUCTS; i++) {
36118 if (board_id == products[i].board_id) {
36119 c->product_name = products[i].product_name;
36120- c->access = *(products[i].access);
36121+ c->access = products[i].access;
36122 break;
36123 }
36124 }
36125@@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
36126 hba[ctlr]->intr = intr;
36127 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
36128 hba[ctlr]->product_name = products[j].product_name;
36129- hba[ctlr]->access = *(products[j].access);
36130+ hba[ctlr]->access = products[j].access;
36131 hba[ctlr]->ctlr = ctlr;
36132 hba[ctlr]->board_id = board_id;
36133 hba[ctlr]->pci_dev = NULL; /* not PCI */
36134@@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
36135
36136 while((c = h->reqQ) != NULL) {
36137 /* Can't do anything if we're busy */
36138- if (h->access.fifo_full(h) == 0)
36139+ if (h->access->fifo_full(h) == 0)
36140 return;
36141
36142 /* Get the first entry from the request Q */
36143@@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
36144 h->Qdepth--;
36145
36146 /* Tell the controller to do our bidding */
36147- h->access.submit_command(h, c);
36148+ h->access->submit_command(h, c);
36149
36150 /* Get onto the completion Q */
36151 addQ(&h->cmpQ, c);
36152@@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
36153 unsigned long flags;
36154 __u32 a,a1;
36155
36156- istat = h->access.intr_pending(h);
36157+ istat = h->access->intr_pending(h);
36158 /* Is this interrupt for us? */
36159 if (istat == 0)
36160 return IRQ_NONE;
36161@@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
36162 */
36163 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
36164 if (istat & FIFO_NOT_EMPTY) {
36165- while((a = h->access.command_completed(h))) {
36166+ while((a = h->access->command_completed(h))) {
36167 a1 = a; a &= ~3;
36168 if ((c = h->cmpQ) == NULL)
36169 {
36170@@ -1193,6 +1193,7 @@ out_passthru:
36171 ida_pci_info_struct pciinfo;
36172
36173 if (!arg) return -EINVAL;
36174+ memset(&pciinfo, 0, sizeof(pciinfo));
36175 pciinfo.bus = host->pci_dev->bus->number;
36176 pciinfo.dev_fn = host->pci_dev->devfn;
36177 pciinfo.board_id = host->board_id;
36178@@ -1447,11 +1448,11 @@ static int sendcmd(
36179 /*
36180 * Disable interrupt
36181 */
36182- info_p->access.set_intr_mask(info_p, 0);
36183+ info_p->access->set_intr_mask(info_p, 0);
36184 /* Make sure there is room in the command FIFO */
36185 /* Actually it should be completely empty at this time. */
36186 for (i = 200000; i > 0; i--) {
36187- temp = info_p->access.fifo_full(info_p);
36188+ temp = info_p->access->fifo_full(info_p);
36189 if (temp != 0) {
36190 break;
36191 }
36192@@ -1464,7 +1465,7 @@ DBG(
36193 /*
36194 * Send the cmd
36195 */
36196- info_p->access.submit_command(info_p, c);
36197+ info_p->access->submit_command(info_p, c);
36198 complete = pollcomplete(ctlr);
36199
36200 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
36201@@ -1547,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
36202 * we check the new geometry. Then turn interrupts back on when
36203 * we're done.
36204 */
36205- host->access.set_intr_mask(host, 0);
36206+ host->access->set_intr_mask(host, 0);
36207 getgeometry(ctlr);
36208- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
36209+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
36210
36211 for(i=0; i<NWD; i++) {
36212 struct gendisk *disk = ida_gendisk[ctlr][i];
36213@@ -1589,7 +1590,7 @@ static int pollcomplete(int ctlr)
36214 /* Wait (up to 2 seconds) for a command to complete */
36215
36216 for (i = 200000; i > 0; i--) {
36217- done = hba[ctlr]->access.command_completed(hba[ctlr]);
36218+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
36219 if (done == 0) {
36220 udelay(10); /* a short fixed delay */
36221 } else
36222diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
36223index be73e9d..7fbf140 100644
36224--- a/drivers/block/cpqarray.h
36225+++ b/drivers/block/cpqarray.h
36226@@ -99,7 +99,7 @@ struct ctlr_info {
36227 drv_info_t drv[NWD];
36228 struct proc_dir_entry *proc;
36229
36230- struct access_method access;
36231+ struct access_method *access;
36232
36233 cmdlist_t *reqQ;
36234 cmdlist_t *cmpQ;
36235diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
36236index 2d7f608..11245fe 100644
36237--- a/drivers/block/drbd/drbd_int.h
36238+++ b/drivers/block/drbd/drbd_int.h
36239@@ -582,7 +582,7 @@ struct drbd_epoch {
36240 struct drbd_tconn *tconn;
36241 struct list_head list;
36242 unsigned int barrier_nr;
36243- atomic_t epoch_size; /* increased on every request added. */
36244+ atomic_unchecked_t epoch_size; /* increased on every request added. */
36245 atomic_t active; /* increased on every req. added, and dec on every finished. */
36246 unsigned long flags;
36247 };
36248@@ -1022,7 +1022,7 @@ struct drbd_conf {
36249 unsigned int al_tr_number;
36250 int al_tr_cycle;
36251 wait_queue_head_t seq_wait;
36252- atomic_t packet_seq;
36253+ atomic_unchecked_t packet_seq;
36254 unsigned int peer_seq;
36255 spinlock_t peer_seq_lock;
36256 unsigned int minor;
36257@@ -1572,7 +1572,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
36258 char __user *uoptval;
36259 int err;
36260
36261- uoptval = (char __user __force *)optval;
36262+ uoptval = (char __force_user *)optval;
36263
36264 set_fs(KERNEL_DS);
36265 if (level == SOL_SOCKET)
36266diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
36267index 55635ed..40e837c 100644
36268--- a/drivers/block/drbd/drbd_main.c
36269+++ b/drivers/block/drbd/drbd_main.c
36270@@ -1317,7 +1317,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packet cmd,
36271 p->sector = sector;
36272 p->block_id = block_id;
36273 p->blksize = blksize;
36274- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
36275+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
36276 return drbd_send_command(mdev, sock, cmd, sizeof(*p), NULL, 0);
36277 }
36278
36279@@ -1619,7 +1619,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
36280 return -EIO;
36281 p->sector = cpu_to_be64(req->i.sector);
36282 p->block_id = (unsigned long)req;
36283- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
36284+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
36285 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
36286 if (mdev->state.conn >= C_SYNC_SOURCE &&
36287 mdev->state.conn <= C_PAUSED_SYNC_T)
36288@@ -2574,8 +2574,8 @@ void conn_destroy(struct kref *kref)
36289 {
36290 struct drbd_tconn *tconn = container_of(kref, struct drbd_tconn, kref);
36291
36292- if (atomic_read(&tconn->current_epoch->epoch_size) != 0)
36293- conn_err(tconn, "epoch_size:%d\n", atomic_read(&tconn->current_epoch->epoch_size));
36294+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size) != 0)
36295+ conn_err(tconn, "epoch_size:%d\n", atomic_read_unchecked(&tconn->current_epoch->epoch_size));
36296 kfree(tconn->current_epoch);
36297
36298 idr_destroy(&tconn->volumes);
36299diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
36300index 8cc1e64..ba7ffa9 100644
36301--- a/drivers/block/drbd/drbd_nl.c
36302+++ b/drivers/block/drbd/drbd_nl.c
36303@@ -3440,7 +3440,7 @@ out:
36304
36305 void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
36306 {
36307- static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
36308+ static atomic_unchecked_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
36309 struct sk_buff *msg;
36310 struct drbd_genlmsghdr *d_out;
36311 unsigned seq;
36312@@ -3453,7 +3453,7 @@ void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
36313 return;
36314 }
36315
36316- seq = atomic_inc_return(&drbd_genl_seq);
36317+ seq = atomic_inc_return_unchecked(&drbd_genl_seq);
36318 msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
36319 if (!msg)
36320 goto failed;
36321diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
36322index cc29cd3..d4b058b 100644
36323--- a/drivers/block/drbd/drbd_receiver.c
36324+++ b/drivers/block/drbd/drbd_receiver.c
36325@@ -834,7 +834,7 @@ int drbd_connected(struct drbd_conf *mdev)
36326 {
36327 int err;
36328
36329- atomic_set(&mdev->packet_seq, 0);
36330+ atomic_set_unchecked(&mdev->packet_seq, 0);
36331 mdev->peer_seq = 0;
36332
36333 mdev->state_mutex = mdev->tconn->agreed_pro_version < 100 ?
36334@@ -1193,7 +1193,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
36335 do {
36336 next_epoch = NULL;
36337
36338- epoch_size = atomic_read(&epoch->epoch_size);
36339+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
36340
36341 switch (ev & ~EV_CLEANUP) {
36342 case EV_PUT:
36343@@ -1233,7 +1233,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
36344 rv = FE_DESTROYED;
36345 } else {
36346 epoch->flags = 0;
36347- atomic_set(&epoch->epoch_size, 0);
36348+ atomic_set_unchecked(&epoch->epoch_size, 0);
36349 /* atomic_set(&epoch->active, 0); is already zero */
36350 if (rv == FE_STILL_LIVE)
36351 rv = FE_RECYCLED;
36352@@ -1451,7 +1451,7 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
36353 conn_wait_active_ee_empty(tconn);
36354 drbd_flush(tconn);
36355
36356- if (atomic_read(&tconn->current_epoch->epoch_size)) {
36357+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
36358 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
36359 if (epoch)
36360 break;
36361@@ -1464,11 +1464,11 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
36362 }
36363
36364 epoch->flags = 0;
36365- atomic_set(&epoch->epoch_size, 0);
36366+ atomic_set_unchecked(&epoch->epoch_size, 0);
36367 atomic_set(&epoch->active, 0);
36368
36369 spin_lock(&tconn->epoch_lock);
36370- if (atomic_read(&tconn->current_epoch->epoch_size)) {
36371+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
36372 list_add(&epoch->list, &tconn->current_epoch->list);
36373 tconn->current_epoch = epoch;
36374 tconn->epochs++;
36375@@ -2172,7 +2172,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
36376
36377 err = wait_for_and_update_peer_seq(mdev, peer_seq);
36378 drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size);
36379- atomic_inc(&tconn->current_epoch->epoch_size);
36380+ atomic_inc_unchecked(&tconn->current_epoch->epoch_size);
36381 err2 = drbd_drain_block(mdev, pi->size);
36382 if (!err)
36383 err = err2;
36384@@ -2206,7 +2206,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
36385
36386 spin_lock(&tconn->epoch_lock);
36387 peer_req->epoch = tconn->current_epoch;
36388- atomic_inc(&peer_req->epoch->epoch_size);
36389+ atomic_inc_unchecked(&peer_req->epoch->epoch_size);
36390 atomic_inc(&peer_req->epoch->active);
36391 spin_unlock(&tconn->epoch_lock);
36392
36393@@ -4347,7 +4347,7 @@ struct data_cmd {
36394 int expect_payload;
36395 size_t pkt_size;
36396 int (*fn)(struct drbd_tconn *, struct packet_info *);
36397-};
36398+} __do_const;
36399
36400 static struct data_cmd drbd_cmd_handler[] = {
36401 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
36402@@ -4467,7 +4467,7 @@ static void conn_disconnect(struct drbd_tconn *tconn)
36403 if (!list_empty(&tconn->current_epoch->list))
36404 conn_err(tconn, "ASSERTION FAILED: tconn->current_epoch->list not empty\n");
36405 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
36406- atomic_set(&tconn->current_epoch->epoch_size, 0);
36407+ atomic_set_unchecked(&tconn->current_epoch->epoch_size, 0);
36408 tconn->send.seen_any_write_yet = false;
36409
36410 conn_info(tconn, "Connection closed\n");
36411@@ -5223,7 +5223,7 @@ static int tconn_finish_peer_reqs(struct drbd_tconn *tconn)
36412 struct asender_cmd {
36413 size_t pkt_size;
36414 int (*fn)(struct drbd_tconn *tconn, struct packet_info *);
36415-};
36416+} __do_const;
36417
36418 static struct asender_cmd asender_tbl[] = {
36419 [P_PING] = { 0, got_Ping },
36420diff --git a/drivers/block/loop.c b/drivers/block/loop.c
36421index 40e7155..df5c79a 100644
36422--- a/drivers/block/loop.c
36423+++ b/drivers/block/loop.c
36424@@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
36425
36426 file_start_write(file);
36427 set_fs(get_ds());
36428- bw = file->f_op->write(file, buf, len, &pos);
36429+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
36430 set_fs(old_fs);
36431 file_end_write(file);
36432 if (likely(bw == len))
36433diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
36434index f5d0ea1..c62380a 100644
36435--- a/drivers/block/pktcdvd.c
36436+++ b/drivers/block/pktcdvd.c
36437@@ -84,7 +84,7 @@
36438 #define MAX_SPEED 0xffff
36439
36440 #define ZONE(sector, pd) (((sector) + (pd)->offset) & \
36441- ~(sector_t)((pd)->settings.size - 1))
36442+ ~(sector_t)((pd)->settings.size - 1UL))
36443
36444 static DEFINE_MUTEX(pktcdvd_mutex);
36445 static struct pktcdvd_device *pkt_devs[MAX_WRITERS];
36446diff --git a/drivers/bus/arm-cci.c b/drivers/bus/arm-cci.c
36447index 7332889..9ece19e 100644
36448--- a/drivers/bus/arm-cci.c
36449+++ b/drivers/bus/arm-cci.c
36450@@ -419,7 +419,7 @@ static int __init cci_probe(void)
36451
36452 nb_cci_ports = cci_config->nb_ace + cci_config->nb_ace_lite;
36453
36454- ports = kcalloc(sizeof(*ports), nb_cci_ports, GFP_KERNEL);
36455+ ports = kcalloc(nb_cci_ports, sizeof(*ports), GFP_KERNEL);
36456 if (!ports)
36457 return -ENOMEM;
36458
36459diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
36460index 8a3aff7..d7538c2 100644
36461--- a/drivers/cdrom/cdrom.c
36462+++ b/drivers/cdrom/cdrom.c
36463@@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
36464 ENSURE(reset, CDC_RESET);
36465 ENSURE(generic_packet, CDC_GENERIC_PACKET);
36466 cdi->mc_flags = 0;
36467- cdo->n_minors = 0;
36468 cdi->options = CDO_USE_FFLAGS;
36469
36470 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
36471@@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
36472 else
36473 cdi->cdda_method = CDDA_OLD;
36474
36475- if (!cdo->generic_packet)
36476- cdo->generic_packet = cdrom_dummy_generic_packet;
36477+ if (!cdo->generic_packet) {
36478+ pax_open_kernel();
36479+ *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
36480+ pax_close_kernel();
36481+ }
36482
36483 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
36484 mutex_lock(&cdrom_mutex);
36485@@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
36486 if (cdi->exit)
36487 cdi->exit(cdi);
36488
36489- cdi->ops->n_minors--;
36490 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
36491 }
36492
36493@@ -2107,7 +2108,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
36494 */
36495 nr = nframes;
36496 do {
36497- cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
36498+ cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
36499 if (cgc.buffer)
36500 break;
36501
36502@@ -3429,7 +3430,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
36503 struct cdrom_device_info *cdi;
36504 int ret;
36505
36506- ret = scnprintf(info + *pos, max_size - *pos, header);
36507+ ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
36508 if (!ret)
36509 return 1;
36510
36511diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
36512index 5980cb9..6d7bd7e 100644
36513--- a/drivers/cdrom/gdrom.c
36514+++ b/drivers/cdrom/gdrom.c
36515@@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
36516 .audio_ioctl = gdrom_audio_ioctl,
36517 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
36518 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
36519- .n_minors = 1,
36520 };
36521
36522 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
36523diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
36524index 1421997..33f5d6d 100644
36525--- a/drivers/char/Kconfig
36526+++ b/drivers/char/Kconfig
36527@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
36528
36529 config DEVKMEM
36530 bool "/dev/kmem virtual device support"
36531- default y
36532+ default n
36533+ depends on !GRKERNSEC_KMEM
36534 help
36535 Say Y here if you want to support the /dev/kmem device. The
36536 /dev/kmem device is rarely used, but can be used for certain
36537@@ -570,6 +571,7 @@ config DEVPORT
36538 bool
36539 depends on !M68K
36540 depends on ISA || PCI
36541+ depends on !GRKERNSEC_KMEM
36542 default y
36543
36544 source "drivers/s390/char/Kconfig"
36545diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
36546index a48e05b..6bac831 100644
36547--- a/drivers/char/agp/compat_ioctl.c
36548+++ b/drivers/char/agp/compat_ioctl.c
36549@@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
36550 return -ENOMEM;
36551 }
36552
36553- if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
36554+ if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
36555 sizeof(*usegment) * ureserve.seg_count)) {
36556 kfree(usegment);
36557 kfree(ksegment);
36558diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
36559index 1b19239..b87b143 100644
36560--- a/drivers/char/agp/frontend.c
36561+++ b/drivers/char/agp/frontend.c
36562@@ -819,7 +819,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
36563 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
36564 return -EFAULT;
36565
36566- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
36567+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
36568 return -EFAULT;
36569
36570 client = agp_find_client_by_pid(reserve.pid);
36571@@ -849,7 +849,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
36572 if (segment == NULL)
36573 return -ENOMEM;
36574
36575- if (copy_from_user(segment, (void __user *) reserve.seg_list,
36576+ if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
36577 sizeof(struct agp_segment) * reserve.seg_count)) {
36578 kfree(segment);
36579 return -EFAULT;
36580diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
36581index 4f94375..413694e 100644
36582--- a/drivers/char/genrtc.c
36583+++ b/drivers/char/genrtc.c
36584@@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
36585 switch (cmd) {
36586
36587 case RTC_PLL_GET:
36588+ memset(&pll, 0, sizeof(pll));
36589 if (get_rtc_pll(&pll))
36590 return -EINVAL;
36591 else
36592diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
36593index 448ce5e..3a76625 100644
36594--- a/drivers/char/hpet.c
36595+++ b/drivers/char/hpet.c
36596@@ -559,7 +559,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
36597 }
36598
36599 static int
36600-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
36601+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
36602 struct hpet_info *info)
36603 {
36604 struct hpet_timer __iomem *timer;
36605diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
36606index 86fe45c..c0ea948 100644
36607--- a/drivers/char/hw_random/intel-rng.c
36608+++ b/drivers/char/hw_random/intel-rng.c
36609@@ -314,7 +314,7 @@ PFX "RNG, try using the 'no_fwh_detect' option.\n";
36610
36611 if (no_fwh_detect)
36612 return -ENODEV;
36613- printk(warning);
36614+ printk("%s", warning);
36615 return -EBUSY;
36616 }
36617
36618diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
36619index 4445fa1..7c6de37 100644
36620--- a/drivers/char/ipmi/ipmi_msghandler.c
36621+++ b/drivers/char/ipmi/ipmi_msghandler.c
36622@@ -420,7 +420,7 @@ struct ipmi_smi {
36623 struct proc_dir_entry *proc_dir;
36624 char proc_dir_name[10];
36625
36626- atomic_t stats[IPMI_NUM_STATS];
36627+ atomic_unchecked_t stats[IPMI_NUM_STATS];
36628
36629 /*
36630 * run_to_completion duplicate of smb_info, smi_info
36631@@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
36632
36633
36634 #define ipmi_inc_stat(intf, stat) \
36635- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
36636+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
36637 #define ipmi_get_stat(intf, stat) \
36638- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
36639+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
36640
36641 static int is_lan_addr(struct ipmi_addr *addr)
36642 {
36643@@ -2883,7 +2883,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
36644 INIT_LIST_HEAD(&intf->cmd_rcvrs);
36645 init_waitqueue_head(&intf->waitq);
36646 for (i = 0; i < IPMI_NUM_STATS; i++)
36647- atomic_set(&intf->stats[i], 0);
36648+ atomic_set_unchecked(&intf->stats[i], 0);
36649
36650 intf->proc_dir = NULL;
36651
36652diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
36653index af4b23f..79806fc 100644
36654--- a/drivers/char/ipmi/ipmi_si_intf.c
36655+++ b/drivers/char/ipmi/ipmi_si_intf.c
36656@@ -275,7 +275,7 @@ struct smi_info {
36657 unsigned char slave_addr;
36658
36659 /* Counters and things for the proc filesystem. */
36660- atomic_t stats[SI_NUM_STATS];
36661+ atomic_unchecked_t stats[SI_NUM_STATS];
36662
36663 struct task_struct *thread;
36664
36665@@ -284,9 +284,9 @@ struct smi_info {
36666 };
36667
36668 #define smi_inc_stat(smi, stat) \
36669- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
36670+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
36671 #define smi_get_stat(smi, stat) \
36672- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
36673+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
36674
36675 #define SI_MAX_PARMS 4
36676
36677@@ -3258,7 +3258,7 @@ static int try_smi_init(struct smi_info *new_smi)
36678 atomic_set(&new_smi->req_events, 0);
36679 new_smi->run_to_completion = 0;
36680 for (i = 0; i < SI_NUM_STATS; i++)
36681- atomic_set(&new_smi->stats[i], 0);
36682+ atomic_set_unchecked(&new_smi->stats[i], 0);
36683
36684 new_smi->interrupt_disabled = 1;
36685 atomic_set(&new_smi->stop_operation, 0);
36686diff --git a/drivers/char/mem.c b/drivers/char/mem.c
36687index f895a8c..2bc9147 100644
36688--- a/drivers/char/mem.c
36689+++ b/drivers/char/mem.c
36690@@ -18,6 +18,7 @@
36691 #include <linux/raw.h>
36692 #include <linux/tty.h>
36693 #include <linux/capability.h>
36694+#include <linux/security.h>
36695 #include <linux/ptrace.h>
36696 #include <linux/device.h>
36697 #include <linux/highmem.h>
36698@@ -37,6 +38,10 @@
36699
36700 #define DEVPORT_MINOR 4
36701
36702+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
36703+extern const struct file_operations grsec_fops;
36704+#endif
36705+
36706 static inline unsigned long size_inside_page(unsigned long start,
36707 unsigned long size)
36708 {
36709@@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
36710
36711 while (cursor < to) {
36712 if (!devmem_is_allowed(pfn)) {
36713+#ifdef CONFIG_GRKERNSEC_KMEM
36714+ gr_handle_mem_readwrite(from, to);
36715+#else
36716 printk(KERN_INFO
36717 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
36718 current->comm, from, to);
36719+#endif
36720 return 0;
36721 }
36722 cursor += PAGE_SIZE;
36723@@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
36724 }
36725 return 1;
36726 }
36727+#elif defined(CONFIG_GRKERNSEC_KMEM)
36728+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
36729+{
36730+ return 0;
36731+}
36732 #else
36733 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
36734 {
36735@@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
36736
36737 while (count > 0) {
36738 unsigned long remaining;
36739+ char *temp;
36740
36741 sz = size_inside_page(p, count);
36742
36743@@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
36744 if (!ptr)
36745 return -EFAULT;
36746
36747- remaining = copy_to_user(buf, ptr, sz);
36748+#ifdef CONFIG_PAX_USERCOPY
36749+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
36750+ if (!temp) {
36751+ unxlate_dev_mem_ptr(p, ptr);
36752+ return -ENOMEM;
36753+ }
36754+ memcpy(temp, ptr, sz);
36755+#else
36756+ temp = ptr;
36757+#endif
36758+
36759+ remaining = copy_to_user(buf, temp, sz);
36760+
36761+#ifdef CONFIG_PAX_USERCOPY
36762+ kfree(temp);
36763+#endif
36764+
36765 unxlate_dev_mem_ptr(p, ptr);
36766 if (remaining)
36767 return -EFAULT;
36768@@ -364,9 +395,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
36769 size_t count, loff_t *ppos)
36770 {
36771 unsigned long p = *ppos;
36772- ssize_t low_count, read, sz;
36773+ ssize_t low_count, read, sz, err = 0;
36774 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
36775- int err = 0;
36776
36777 read = 0;
36778 if (p < (unsigned long) high_memory) {
36779@@ -388,6 +418,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
36780 }
36781 #endif
36782 while (low_count > 0) {
36783+ char *temp;
36784+
36785 sz = size_inside_page(p, low_count);
36786
36787 /*
36788@@ -397,7 +429,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
36789 */
36790 kbuf = xlate_dev_kmem_ptr((char *)p);
36791
36792- if (copy_to_user(buf, kbuf, sz))
36793+#ifdef CONFIG_PAX_USERCOPY
36794+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
36795+ if (!temp)
36796+ return -ENOMEM;
36797+ memcpy(temp, kbuf, sz);
36798+#else
36799+ temp = kbuf;
36800+#endif
36801+
36802+ err = copy_to_user(buf, temp, sz);
36803+
36804+#ifdef CONFIG_PAX_USERCOPY
36805+ kfree(temp);
36806+#endif
36807+
36808+ if (err)
36809 return -EFAULT;
36810 buf += sz;
36811 p += sz;
36812@@ -822,6 +869,9 @@ static const struct memdev {
36813 #ifdef CONFIG_PRINTK
36814 [11] = { "kmsg", 0644, &kmsg_fops, NULL },
36815 #endif
36816+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
36817+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
36818+#endif
36819 };
36820
36821 static int memory_open(struct inode *inode, struct file *filp)
36822@@ -893,7 +943,7 @@ static int __init chr_dev_init(void)
36823 continue;
36824
36825 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
36826- NULL, devlist[minor].name);
36827+ NULL, "%s", devlist[minor].name);
36828 }
36829
36830 return tty_init();
36831diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
36832index 9df78e2..01ba9ae 100644
36833--- a/drivers/char/nvram.c
36834+++ b/drivers/char/nvram.c
36835@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
36836
36837 spin_unlock_irq(&rtc_lock);
36838
36839- if (copy_to_user(buf, contents, tmp - contents))
36840+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
36841 return -EFAULT;
36842
36843 *ppos = i;
36844diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
36845index 5c5cc00..ac9edb7 100644
36846--- a/drivers/char/pcmcia/synclink_cs.c
36847+++ b/drivers/char/pcmcia/synclink_cs.c
36848@@ -2345,9 +2345,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
36849
36850 if (debug_level >= DEBUG_LEVEL_INFO)
36851 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
36852- __FILE__, __LINE__, info->device_name, port->count);
36853+ __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
36854
36855- WARN_ON(!port->count);
36856+ WARN_ON(!atomic_read(&port->count));
36857
36858 if (tty_port_close_start(port, tty, filp) == 0)
36859 goto cleanup;
36860@@ -2365,7 +2365,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
36861 cleanup:
36862 if (debug_level >= DEBUG_LEVEL_INFO)
36863 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
36864- tty->driver->name, port->count);
36865+ tty->driver->name, atomic_read(&port->count));
36866 }
36867
36868 /* Wait until the transmitter is empty.
36869@@ -2507,7 +2507,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
36870
36871 if (debug_level >= DEBUG_LEVEL_INFO)
36872 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
36873- __FILE__, __LINE__, tty->driver->name, port->count);
36874+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
36875
36876 /* If port is closing, signal caller to try again */
36877 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
36878@@ -2527,11 +2527,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
36879 goto cleanup;
36880 }
36881 spin_lock(&port->lock);
36882- port->count++;
36883+ atomic_inc(&port->count);
36884 spin_unlock(&port->lock);
36885 spin_unlock_irqrestore(&info->netlock, flags);
36886
36887- if (port->count == 1) {
36888+ if (atomic_read(&port->count) == 1) {
36889 /* 1st open on this device, init hardware */
36890 retval = startup(info, tty);
36891 if (retval < 0)
36892@@ -3920,7 +3920,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
36893 unsigned short new_crctype;
36894
36895 /* return error if TTY interface open */
36896- if (info->port.count)
36897+ if (atomic_read(&info->port.count))
36898 return -EBUSY;
36899
36900 switch (encoding)
36901@@ -4024,7 +4024,7 @@ static int hdlcdev_open(struct net_device *dev)
36902
36903 /* arbitrate between network and tty opens */
36904 spin_lock_irqsave(&info->netlock, flags);
36905- if (info->port.count != 0 || info->netcount != 0) {
36906+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
36907 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
36908 spin_unlock_irqrestore(&info->netlock, flags);
36909 return -EBUSY;
36910@@ -4114,7 +4114,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
36911 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
36912
36913 /* return error if TTY interface open */
36914- if (info->port.count)
36915+ if (atomic_read(&info->port.count))
36916 return -EBUSY;
36917
36918 if (cmd != SIOCWANDEV)
36919diff --git a/drivers/char/random.c b/drivers/char/random.c
36920index 0d91fe5..f8e37b0 100644
36921--- a/drivers/char/random.c
36922+++ b/drivers/char/random.c
36923@@ -272,8 +272,13 @@
36924 /*
36925 * Configuration information
36926 */
36927+#ifdef CONFIG_GRKERNSEC_RANDNET
36928+#define INPUT_POOL_WORDS 512
36929+#define OUTPUT_POOL_WORDS 128
36930+#else
36931 #define INPUT_POOL_WORDS 128
36932 #define OUTPUT_POOL_WORDS 32
36933+#endif
36934 #define SEC_XFER_SIZE 512
36935 #define EXTRACT_SIZE 10
36936
36937@@ -313,10 +318,17 @@ static struct poolinfo {
36938 int poolwords;
36939 int tap1, tap2, tap3, tap4, tap5;
36940 } poolinfo_table[] = {
36941+#ifdef CONFIG_GRKERNSEC_RANDNET
36942+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
36943+ { 512, 411, 308, 208, 104, 1 },
36944+ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
36945+ { 128, 103, 76, 51, 25, 1 },
36946+#else
36947 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
36948 { 128, 103, 76, 51, 25, 1 },
36949 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
36950 { 32, 26, 20, 14, 7, 1 },
36951+#endif
36952 #if 0
36953 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
36954 { 2048, 1638, 1231, 819, 411, 1 },
36955@@ -524,8 +536,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
36956 input_rotate += i ? 7 : 14;
36957 }
36958
36959- ACCESS_ONCE(r->input_rotate) = input_rotate;
36960- ACCESS_ONCE(r->add_ptr) = i;
36961+ ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
36962+ ACCESS_ONCE_RW(r->add_ptr) = i;
36963 smp_wmb();
36964
36965 if (out)
36966@@ -1032,7 +1044,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
36967
36968 extract_buf(r, tmp);
36969 i = min_t(int, nbytes, EXTRACT_SIZE);
36970- if (copy_to_user(buf, tmp, i)) {
36971+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
36972 ret = -EFAULT;
36973 break;
36974 }
36975@@ -1368,7 +1380,7 @@ EXPORT_SYMBOL(generate_random_uuid);
36976 #include <linux/sysctl.h>
36977
36978 static int min_read_thresh = 8, min_write_thresh;
36979-static int max_read_thresh = INPUT_POOL_WORDS * 32;
36980+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
36981 static int max_write_thresh = INPUT_POOL_WORDS * 32;
36982 static char sysctl_bootid[16];
36983
36984@@ -1384,7 +1396,7 @@ static char sysctl_bootid[16];
36985 static int proc_do_uuid(struct ctl_table *table, int write,
36986 void __user *buffer, size_t *lenp, loff_t *ppos)
36987 {
36988- struct ctl_table fake_table;
36989+ ctl_table_no_const fake_table;
36990 unsigned char buf[64], tmp_uuid[16], *uuid;
36991
36992 uuid = table->data;
36993diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
36994index bf2349db..5456d53 100644
36995--- a/drivers/char/sonypi.c
36996+++ b/drivers/char/sonypi.c
36997@@ -54,6 +54,7 @@
36998
36999 #include <asm/uaccess.h>
37000 #include <asm/io.h>
37001+#include <asm/local.h>
37002
37003 #include <linux/sonypi.h>
37004
37005@@ -490,7 +491,7 @@ static struct sonypi_device {
37006 spinlock_t fifo_lock;
37007 wait_queue_head_t fifo_proc_list;
37008 struct fasync_struct *fifo_async;
37009- int open_count;
37010+ local_t open_count;
37011 int model;
37012 struct input_dev *input_jog_dev;
37013 struct input_dev *input_key_dev;
37014@@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
37015 static int sonypi_misc_release(struct inode *inode, struct file *file)
37016 {
37017 mutex_lock(&sonypi_device.lock);
37018- sonypi_device.open_count--;
37019+ local_dec(&sonypi_device.open_count);
37020 mutex_unlock(&sonypi_device.lock);
37021 return 0;
37022 }
37023@@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
37024 {
37025 mutex_lock(&sonypi_device.lock);
37026 /* Flush input queue on first open */
37027- if (!sonypi_device.open_count)
37028+ if (!local_read(&sonypi_device.open_count))
37029 kfifo_reset(&sonypi_device.fifo);
37030- sonypi_device.open_count++;
37031+ local_inc(&sonypi_device.open_count);
37032 mutex_unlock(&sonypi_device.lock);
37033
37034 return 0;
37035diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
37036index 64420b3..5c40b56 100644
37037--- a/drivers/char/tpm/tpm_acpi.c
37038+++ b/drivers/char/tpm/tpm_acpi.c
37039@@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
37040 virt = acpi_os_map_memory(start, len);
37041 if (!virt) {
37042 kfree(log->bios_event_log);
37043+ log->bios_event_log = NULL;
37044 printk("%s: ERROR - Unable to map memory\n", __func__);
37045 return -EIO;
37046 }
37047
37048- memcpy_fromio(log->bios_event_log, virt, len);
37049+ memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
37050
37051 acpi_os_unmap_memory(virt, len);
37052 return 0;
37053diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
37054index 84ddc55..1d32f1e 100644
37055--- a/drivers/char/tpm/tpm_eventlog.c
37056+++ b/drivers/char/tpm/tpm_eventlog.c
37057@@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
37058 event = addr;
37059
37060 if ((event->event_type == 0 && event->event_size == 0) ||
37061- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
37062+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
37063 return NULL;
37064
37065 return addr;
37066@@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
37067 return NULL;
37068
37069 if ((event->event_type == 0 && event->event_size == 0) ||
37070- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
37071+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
37072 return NULL;
37073
37074 (*pos)++;
37075@@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
37076 int i;
37077
37078 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
37079- seq_putc(m, data[i]);
37080+ if (!seq_putc(m, data[i]))
37081+ return -EFAULT;
37082
37083 return 0;
37084 }
37085diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
37086index fc45567..fa2a590 100644
37087--- a/drivers/char/virtio_console.c
37088+++ b/drivers/char/virtio_console.c
37089@@ -682,7 +682,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
37090 if (to_user) {
37091 ssize_t ret;
37092
37093- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
37094+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
37095 if (ret)
37096 return -EFAULT;
37097 } else {
37098@@ -785,7 +785,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
37099 if (!port_has_data(port) && !port->host_connected)
37100 return 0;
37101
37102- return fill_readbuf(port, ubuf, count, true);
37103+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
37104 }
37105
37106 static int wait_port_writable(struct port *port, bool nonblock)
37107diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
37108index a33f46f..a720eed 100644
37109--- a/drivers/clk/clk-composite.c
37110+++ b/drivers/clk/clk-composite.c
37111@@ -122,7 +122,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
37112 struct clk *clk;
37113 struct clk_init_data init;
37114 struct clk_composite *composite;
37115- struct clk_ops *clk_composite_ops;
37116+ clk_ops_no_const *clk_composite_ops;
37117
37118 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
37119 if (!composite) {
37120diff --git a/drivers/clk/socfpga/clk.c b/drivers/clk/socfpga/clk.c
37121index 5bb848c..f1d4fc9 100644
37122--- a/drivers/clk/socfpga/clk.c
37123+++ b/drivers/clk/socfpga/clk.c
37124@@ -22,6 +22,7 @@
37125 #include <linux/clk-provider.h>
37126 #include <linux/io.h>
37127 #include <linux/of.h>
37128+#include <asm/pgtable.h>
37129
37130 /* Clock Manager offsets */
37131 #define CLKMGR_CTRL 0x0
37132@@ -152,8 +153,10 @@ static __init struct clk *socfpga_clk_init(struct device_node *node,
37133 streq(clk_name, "periph_pll") ||
37134 streq(clk_name, "sdram_pll")) {
37135 socfpga_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
37136- clk_pll_ops.enable = clk_gate_ops.enable;
37137- clk_pll_ops.disable = clk_gate_ops.disable;
37138+ pax_open_kernel();
37139+ *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
37140+ *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
37141+ pax_close_kernel();
37142 }
37143
37144 clk = clk_register(NULL, &socfpga_clk->hw.hw);
37145@@ -244,7 +247,7 @@ static unsigned long socfpga_clk_recalc_rate(struct clk_hw *hwclk,
37146 return parent_rate / div;
37147 }
37148
37149-static struct clk_ops gateclk_ops = {
37150+static clk_ops_no_const gateclk_ops __read_only = {
37151 .recalc_rate = socfpga_clk_recalc_rate,
37152 .get_parent = socfpga_clk_get_parent,
37153 .set_parent = socfpga_clk_set_parent,
37154diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
37155index 3926402..37b580d 100644
37156--- a/drivers/cpufreq/acpi-cpufreq.c
37157+++ b/drivers/cpufreq/acpi-cpufreq.c
37158@@ -173,7 +173,7 @@ static ssize_t show_global_boost(struct kobject *kobj,
37159 return sprintf(buf, "%u\n", boost_enabled);
37160 }
37161
37162-static struct global_attr global_boost = __ATTR(boost, 0644,
37163+static global_attr_no_const global_boost = __ATTR(boost, 0644,
37164 show_global_boost,
37165 store_global_boost);
37166
37167@@ -722,8 +722,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
37168 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
37169 per_cpu(acfreq_data, cpu) = data;
37170
37171- if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
37172- acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
37173+ if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
37174+ pax_open_kernel();
37175+ *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
37176+ pax_close_kernel();
37177+ }
37178
37179 result = acpi_processor_register_performance(data->acpi_data, cpu);
37180 if (result)
37181@@ -851,7 +854,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
37182 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
37183 break;
37184 case ACPI_ADR_SPACE_FIXED_HARDWARE:
37185- acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
37186+ pax_open_kernel();
37187+ *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
37188+ pax_close_kernel();
37189 policy->cur = get_cur_freq_on_cpu(cpu);
37190 break;
37191 default:
37192@@ -862,8 +867,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
37193 acpi_processor_notify_smm(THIS_MODULE);
37194
37195 /* Check for APERF/MPERF support in hardware */
37196- if (boot_cpu_has(X86_FEATURE_APERFMPERF))
37197- acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf;
37198+ if (boot_cpu_has(X86_FEATURE_APERFMPERF)) {
37199+ pax_open_kernel();
37200+ *(void **)&acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf;
37201+ pax_close_kernel();
37202+ }
37203
37204 pr_debug("CPU%u - ACPI performance management activated.\n", cpu);
37205 for (i = 0; i < perf->state_count; i++)
37206diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
37207index f0a5e2b..0a7ee46 100644
37208--- a/drivers/cpufreq/cpufreq.c
37209+++ b/drivers/cpufreq/cpufreq.c
37210@@ -1959,7 +1959,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
37211 return NOTIFY_OK;
37212 }
37213
37214-static struct notifier_block __refdata cpufreq_cpu_notifier = {
37215+static struct notifier_block cpufreq_cpu_notifier = {
37216 .notifier_call = cpufreq_cpu_callback,
37217 };
37218
37219@@ -1991,8 +1991,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
37220
37221 pr_debug("trying to register driver %s\n", driver_data->name);
37222
37223- if (driver_data->setpolicy)
37224- driver_data->flags |= CPUFREQ_CONST_LOOPS;
37225+ if (driver_data->setpolicy) {
37226+ pax_open_kernel();
37227+ *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
37228+ pax_close_kernel();
37229+ }
37230
37231 write_lock_irqsave(&cpufreq_driver_lock, flags);
37232 if (cpufreq_driver) {
37233diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
37234index e59afaa..a53a3ff 100644
37235--- a/drivers/cpufreq/cpufreq_governor.c
37236+++ b/drivers/cpufreq/cpufreq_governor.c
37237@@ -191,7 +191,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
37238 struct dbs_data *dbs_data;
37239 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
37240 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
37241- struct od_ops *od_ops = NULL;
37242+ const struct od_ops *od_ops = NULL;
37243 struct od_dbs_tuners *od_tuners = NULL;
37244 struct cs_dbs_tuners *cs_tuners = NULL;
37245 struct cpu_dbs_common_info *cpu_cdbs;
37246@@ -257,7 +257,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
37247
37248 if ((cdata->governor == GOV_CONSERVATIVE) &&
37249 (!policy->governor->initialized)) {
37250- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
37251+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
37252
37253 cpufreq_register_notifier(cs_ops->notifier_block,
37254 CPUFREQ_TRANSITION_NOTIFIER);
37255@@ -277,7 +277,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
37256
37257 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
37258 (policy->governor->initialized == 1)) {
37259- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
37260+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
37261
37262 cpufreq_unregister_notifier(cs_ops->notifier_block,
37263 CPUFREQ_TRANSITION_NOTIFIER);
37264diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
37265index d5f12b4..eb30af1 100644
37266--- a/drivers/cpufreq/cpufreq_governor.h
37267+++ b/drivers/cpufreq/cpufreq_governor.h
37268@@ -204,7 +204,7 @@ struct common_dbs_data {
37269 void (*exit)(struct dbs_data *dbs_data);
37270
37271 /* Governor specific ops, see below */
37272- void *gov_ops;
37273+ const void *gov_ops;
37274 };
37275
37276 /* Governer Per policy data */
37277@@ -224,7 +224,7 @@ struct od_ops {
37278 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
37279 unsigned int freq_next, unsigned int relation);
37280 void (*freq_increase)(struct cpufreq_policy *p, unsigned int freq);
37281-};
37282+} __no_const;
37283
37284 struct cs_ops {
37285 struct notifier_block *notifier_block;
37286diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
37287index c087347..989aa2e 100644
37288--- a/drivers/cpufreq/cpufreq_ondemand.c
37289+++ b/drivers/cpufreq/cpufreq_ondemand.c
37290@@ -560,7 +560,7 @@ static void od_exit(struct dbs_data *dbs_data)
37291
37292 define_get_cpu_dbs_routines(od_cpu_dbs_info);
37293
37294-static struct od_ops od_ops = {
37295+static struct od_ops od_ops __read_only = {
37296 .powersave_bias_init_cpu = ondemand_powersave_bias_init_cpu,
37297 .powersave_bias_target = generic_powersave_bias_target,
37298 .freq_increase = dbs_freq_increase,
37299@@ -615,14 +615,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
37300 (struct cpufreq_policy *, unsigned int, unsigned int),
37301 unsigned int powersave_bias)
37302 {
37303- od_ops.powersave_bias_target = f;
37304+ pax_open_kernel();
37305+ *(void **)&od_ops.powersave_bias_target = f;
37306+ pax_close_kernel();
37307 od_set_powersave_bias(powersave_bias);
37308 }
37309 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
37310
37311 void od_unregister_powersave_bias_handler(void)
37312 {
37313- od_ops.powersave_bias_target = generic_powersave_bias_target;
37314+ pax_open_kernel();
37315+ *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
37316+ pax_close_kernel();
37317 od_set_powersave_bias(0);
37318 }
37319 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
37320diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
37321index d37568c..fbb19a1 100644
37322--- a/drivers/cpufreq/cpufreq_stats.c
37323+++ b/drivers/cpufreq/cpufreq_stats.c
37324@@ -365,7 +365,7 @@ static int cpufreq_stat_cpu_callback(struct notifier_block *nfb,
37325 }
37326
37327 /* priority=1 so this will get called before cpufreq_remove_dev */
37328-static struct notifier_block cpufreq_stat_cpu_notifier __refdata = {
37329+static struct notifier_block cpufreq_stat_cpu_notifier = {
37330 .notifier_call = cpufreq_stat_cpu_callback,
37331 .priority = 1,
37332 };
37333diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
37334index 9ee7817..17b658e 100644
37335--- a/drivers/cpufreq/p4-clockmod.c
37336+++ b/drivers/cpufreq/p4-clockmod.c
37337@@ -160,10 +160,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
37338 case 0x0F: /* Core Duo */
37339 case 0x16: /* Celeron Core */
37340 case 0x1C: /* Atom */
37341- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37342+ pax_open_kernel();
37343+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37344+ pax_close_kernel();
37345 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
37346 case 0x0D: /* Pentium M (Dothan) */
37347- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37348+ pax_open_kernel();
37349+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37350+ pax_close_kernel();
37351 /* fall through */
37352 case 0x09: /* Pentium M (Banias) */
37353 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
37354@@ -175,7 +179,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
37355
37356 /* on P-4s, the TSC runs with constant frequency independent whether
37357 * throttling is active or not. */
37358- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37359+ pax_open_kernel();
37360+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37361+ pax_close_kernel();
37362
37363 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
37364 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
37365diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
37366index 880ee29..2445bc6 100644
37367--- a/drivers/cpufreq/sparc-us3-cpufreq.c
37368+++ b/drivers/cpufreq/sparc-us3-cpufreq.c
37369@@ -18,14 +18,12 @@
37370 #include <asm/head.h>
37371 #include <asm/timer.h>
37372
37373-static struct cpufreq_driver *cpufreq_us3_driver;
37374-
37375 struct us3_freq_percpu_info {
37376 struct cpufreq_frequency_table table[4];
37377 };
37378
37379 /* Indexed by cpu number. */
37380-static struct us3_freq_percpu_info *us3_freq_table;
37381+static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
37382
37383 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
37384 * in the Safari config register.
37385@@ -186,12 +184,25 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
37386
37387 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
37388 {
37389- if (cpufreq_us3_driver)
37390- us3_set_cpu_divider_index(policy, 0);
37391+ us3_set_cpu_divider_index(policy->cpu, 0);
37392
37393 return 0;
37394 }
37395
37396+static int __init us3_freq_init(void);
37397+static void __exit us3_freq_exit(void);
37398+
37399+static struct cpufreq_driver cpufreq_us3_driver = {
37400+ .init = us3_freq_cpu_init,
37401+ .verify = us3_freq_verify,
37402+ .target = us3_freq_target,
37403+ .get = us3_freq_get,
37404+ .exit = us3_freq_cpu_exit,
37405+ .owner = THIS_MODULE,
37406+ .name = "UltraSPARC-III",
37407+
37408+};
37409+
37410 static int __init us3_freq_init(void)
37411 {
37412 unsigned long manuf, impl, ver;
37413@@ -208,57 +219,15 @@ static int __init us3_freq_init(void)
37414 (impl == CHEETAH_IMPL ||
37415 impl == CHEETAH_PLUS_IMPL ||
37416 impl == JAGUAR_IMPL ||
37417- impl == PANTHER_IMPL)) {
37418- struct cpufreq_driver *driver;
37419-
37420- ret = -ENOMEM;
37421- driver = kzalloc(sizeof(struct cpufreq_driver), GFP_KERNEL);
37422- if (!driver)
37423- goto err_out;
37424-
37425- us3_freq_table = kzalloc(
37426- (NR_CPUS * sizeof(struct us3_freq_percpu_info)),
37427- GFP_KERNEL);
37428- if (!us3_freq_table)
37429- goto err_out;
37430-
37431- driver->init = us3_freq_cpu_init;
37432- driver->verify = us3_freq_verify;
37433- driver->target = us3_freq_target;
37434- driver->get = us3_freq_get;
37435- driver->exit = us3_freq_cpu_exit;
37436- driver->owner = THIS_MODULE,
37437- strcpy(driver->name, "UltraSPARC-III");
37438-
37439- cpufreq_us3_driver = driver;
37440- ret = cpufreq_register_driver(driver);
37441- if (ret)
37442- goto err_out;
37443-
37444- return 0;
37445-
37446-err_out:
37447- if (driver) {
37448- kfree(driver);
37449- cpufreq_us3_driver = NULL;
37450- }
37451- kfree(us3_freq_table);
37452- us3_freq_table = NULL;
37453- return ret;
37454- }
37455+ impl == PANTHER_IMPL))
37456+ return cpufreq_register_driver(&cpufreq_us3_driver);
37457
37458 return -ENODEV;
37459 }
37460
37461 static void __exit us3_freq_exit(void)
37462 {
37463- if (cpufreq_us3_driver) {
37464- cpufreq_unregister_driver(cpufreq_us3_driver);
37465- kfree(cpufreq_us3_driver);
37466- cpufreq_us3_driver = NULL;
37467- kfree(us3_freq_table);
37468- us3_freq_table = NULL;
37469- }
37470+ cpufreq_unregister_driver(&cpufreq_us3_driver);
37471 }
37472
37473 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
37474diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
37475index 0915e71..53376ed 100644
37476--- a/drivers/cpufreq/speedstep-centrino.c
37477+++ b/drivers/cpufreq/speedstep-centrino.c
37478@@ -353,8 +353,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
37479 !cpu_has(cpu, X86_FEATURE_EST))
37480 return -ENODEV;
37481
37482- if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
37483- centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
37484+ if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
37485+ pax_open_kernel();
37486+ *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
37487+ pax_close_kernel();
37488+ }
37489
37490 if (policy->cpu != 0)
37491 return -ENODEV;
37492diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c
37493index fdc432f..98e64e2 100644
37494--- a/drivers/cpuidle/cpuidle.c
37495+++ b/drivers/cpuidle/cpuidle.c
37496@@ -254,7 +254,7 @@ static int poll_idle(struct cpuidle_device *dev,
37497
37498 static void poll_idle_init(struct cpuidle_driver *drv)
37499 {
37500- struct cpuidle_state *state = &drv->states[0];
37501+ cpuidle_state_no_const *state = &drv->states[0];
37502
37503 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
37504 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
37505diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
37506index ea2f8e7..70ac501 100644
37507--- a/drivers/cpuidle/governor.c
37508+++ b/drivers/cpuidle/governor.c
37509@@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
37510 mutex_lock(&cpuidle_lock);
37511 if (__cpuidle_find_governor(gov->name) == NULL) {
37512 ret = 0;
37513- list_add_tail(&gov->governor_list, &cpuidle_governors);
37514+ pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
37515 if (!cpuidle_curr_governor ||
37516 cpuidle_curr_governor->rating < gov->rating)
37517 cpuidle_switch_governor(gov);
37518@@ -135,7 +135,7 @@ void cpuidle_unregister_governor(struct cpuidle_governor *gov)
37519 new_gov = cpuidle_replace_governor(gov->rating);
37520 cpuidle_switch_governor(new_gov);
37521 }
37522- list_del(&gov->governor_list);
37523+ pax_list_del((struct list_head *)&gov->governor_list);
37524 mutex_unlock(&cpuidle_lock);
37525 }
37526
37527diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
37528index 428754a..8bdf9cc 100644
37529--- a/drivers/cpuidle/sysfs.c
37530+++ b/drivers/cpuidle/sysfs.c
37531@@ -131,7 +131,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
37532 NULL
37533 };
37534
37535-static struct attribute_group cpuidle_attr_group = {
37536+static attribute_group_no_const cpuidle_attr_group = {
37537 .attrs = cpuidle_default_attrs,
37538 .name = "cpuidle",
37539 };
37540diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
37541index 12fea3e..1e28f47 100644
37542--- a/drivers/crypto/hifn_795x.c
37543+++ b/drivers/crypto/hifn_795x.c
37544@@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
37545 MODULE_PARM_DESC(hifn_pll_ref,
37546 "PLL reference clock (pci[freq] or ext[freq], default ext)");
37547
37548-static atomic_t hifn_dev_number;
37549+static atomic_unchecked_t hifn_dev_number;
37550
37551 #define ACRYPTO_OP_DECRYPT 0
37552 #define ACRYPTO_OP_ENCRYPT 1
37553@@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
37554 goto err_out_disable_pci_device;
37555
37556 snprintf(name, sizeof(name), "hifn%d",
37557- atomic_inc_return(&hifn_dev_number)-1);
37558+ atomic_inc_return_unchecked(&hifn_dev_number)-1);
37559
37560 err = pci_request_regions(pdev, name);
37561 if (err)
37562diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
37563index e94e619..f7e249c 100644
37564--- a/drivers/devfreq/devfreq.c
37565+++ b/drivers/devfreq/devfreq.c
37566@@ -607,7 +607,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
37567 goto err_out;
37568 }
37569
37570- list_add(&governor->node, &devfreq_governor_list);
37571+ pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
37572
37573 list_for_each_entry(devfreq, &devfreq_list, node) {
37574 int ret = 0;
37575@@ -695,7 +695,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
37576 }
37577 }
37578
37579- list_del(&governor->node);
37580+ pax_list_del((struct list_head *)&governor->node);
37581 err_out:
37582 mutex_unlock(&devfreq_list_lock);
37583
37584diff --git a/drivers/dma/sh/shdma.c b/drivers/dma/sh/shdma.c
37585index 5039fbc..841169f 100644
37586--- a/drivers/dma/sh/shdma.c
37587+++ b/drivers/dma/sh/shdma.c
37588@@ -488,7 +488,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
37589 return ret;
37590 }
37591
37592-static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
37593+static struct notifier_block sh_dmae_nmi_notifier = {
37594 .notifier_call = sh_dmae_nmi_handler,
37595
37596 /* Run before NMI debug handler and KGDB */
37597diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
37598index 211021d..201d47f 100644
37599--- a/drivers/edac/edac_device.c
37600+++ b/drivers/edac/edac_device.c
37601@@ -474,9 +474,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
37602 */
37603 int edac_device_alloc_index(void)
37604 {
37605- static atomic_t device_indexes = ATOMIC_INIT(0);
37606+ static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
37607
37608- return atomic_inc_return(&device_indexes) - 1;
37609+ return atomic_inc_return_unchecked(&device_indexes) - 1;
37610 }
37611 EXPORT_SYMBOL_GPL(edac_device_alloc_index);
37612
37613diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
37614index e7c32c4..6397af1 100644
37615--- a/drivers/edac/edac_mc_sysfs.c
37616+++ b/drivers/edac/edac_mc_sysfs.c
37617@@ -148,7 +148,7 @@ static const char * const edac_caps[] = {
37618 struct dev_ch_attribute {
37619 struct device_attribute attr;
37620 int channel;
37621-};
37622+} __do_const;
37623
37624 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
37625 struct dev_ch_attribute dev_attr_legacy_##_name = \
37626@@ -1005,14 +1005,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
37627 }
37628
37629 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
37630+ pax_open_kernel();
37631 if (mci->get_sdram_scrub_rate) {
37632- dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
37633- dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
37634+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
37635+ *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
37636 }
37637 if (mci->set_sdram_scrub_rate) {
37638- dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
37639- dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
37640+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
37641+ *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
37642 }
37643+ pax_close_kernel();
37644 err = device_create_file(&mci->dev,
37645 &dev_attr_sdram_scrub_rate);
37646 if (err) {
37647diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
37648index dd370f9..0281629 100644
37649--- a/drivers/edac/edac_pci.c
37650+++ b/drivers/edac/edac_pci.c
37651@@ -29,7 +29,7 @@
37652
37653 static DEFINE_MUTEX(edac_pci_ctls_mutex);
37654 static LIST_HEAD(edac_pci_list);
37655-static atomic_t pci_indexes = ATOMIC_INIT(0);
37656+static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
37657
37658 /*
37659 * edac_pci_alloc_ctl_info
37660@@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
37661 */
37662 int edac_pci_alloc_index(void)
37663 {
37664- return atomic_inc_return(&pci_indexes) - 1;
37665+ return atomic_inc_return_unchecked(&pci_indexes) - 1;
37666 }
37667 EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
37668
37669diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
37670index e8658e4..22746d6 100644
37671--- a/drivers/edac/edac_pci_sysfs.c
37672+++ b/drivers/edac/edac_pci_sysfs.c
37673@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
37674 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
37675 static int edac_pci_poll_msec = 1000; /* one second workq period */
37676
37677-static atomic_t pci_parity_count = ATOMIC_INIT(0);
37678-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
37679+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
37680+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
37681
37682 static struct kobject *edac_pci_top_main_kobj;
37683 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
37684@@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
37685 void *value;
37686 ssize_t(*show) (void *, char *);
37687 ssize_t(*store) (void *, const char *, size_t);
37688-};
37689+} __do_const;
37690
37691 /* Set of show/store abstract level functions for PCI Parity object */
37692 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
37693@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37694 edac_printk(KERN_CRIT, EDAC_PCI,
37695 "Signaled System Error on %s\n",
37696 pci_name(dev));
37697- atomic_inc(&pci_nonparity_count);
37698+ atomic_inc_unchecked(&pci_nonparity_count);
37699 }
37700
37701 if (status & (PCI_STATUS_PARITY)) {
37702@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37703 "Master Data Parity Error on %s\n",
37704 pci_name(dev));
37705
37706- atomic_inc(&pci_parity_count);
37707+ atomic_inc_unchecked(&pci_parity_count);
37708 }
37709
37710 if (status & (PCI_STATUS_DETECTED_PARITY)) {
37711@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37712 "Detected Parity Error on %s\n",
37713 pci_name(dev));
37714
37715- atomic_inc(&pci_parity_count);
37716+ atomic_inc_unchecked(&pci_parity_count);
37717 }
37718 }
37719
37720@@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37721 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
37722 "Signaled System Error on %s\n",
37723 pci_name(dev));
37724- atomic_inc(&pci_nonparity_count);
37725+ atomic_inc_unchecked(&pci_nonparity_count);
37726 }
37727
37728 if (status & (PCI_STATUS_PARITY)) {
37729@@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37730 "Master Data Parity Error on "
37731 "%s\n", pci_name(dev));
37732
37733- atomic_inc(&pci_parity_count);
37734+ atomic_inc_unchecked(&pci_parity_count);
37735 }
37736
37737 if (status & (PCI_STATUS_DETECTED_PARITY)) {
37738@@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37739 "Detected Parity Error on %s\n",
37740 pci_name(dev));
37741
37742- atomic_inc(&pci_parity_count);
37743+ atomic_inc_unchecked(&pci_parity_count);
37744 }
37745 }
37746 }
37747@@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
37748 if (!check_pci_errors)
37749 return;
37750
37751- before_count = atomic_read(&pci_parity_count);
37752+ before_count = atomic_read_unchecked(&pci_parity_count);
37753
37754 /* scan all PCI devices looking for a Parity Error on devices and
37755 * bridges.
37756@@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
37757 /* Only if operator has selected panic on PCI Error */
37758 if (edac_pci_get_panic_on_pe()) {
37759 /* If the count is different 'after' from 'before' */
37760- if (before_count != atomic_read(&pci_parity_count))
37761+ if (before_count != atomic_read_unchecked(&pci_parity_count))
37762 panic("EDAC: PCI Parity Error");
37763 }
37764 }
37765diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
37766index 51b7e3a..aa8a3e8 100644
37767--- a/drivers/edac/mce_amd.h
37768+++ b/drivers/edac/mce_amd.h
37769@@ -77,7 +77,7 @@ struct amd_decoder_ops {
37770 bool (*mc0_mce)(u16, u8);
37771 bool (*mc1_mce)(u16, u8);
37772 bool (*mc2_mce)(u16, u8);
37773-};
37774+} __no_const;
37775
37776 void amd_report_gart_errors(bool);
37777 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
37778diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
37779index 57ea7f4..af06b76 100644
37780--- a/drivers/firewire/core-card.c
37781+++ b/drivers/firewire/core-card.c
37782@@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
37783 const struct fw_card_driver *driver,
37784 struct device *device)
37785 {
37786- static atomic_t index = ATOMIC_INIT(-1);
37787+ static atomic_unchecked_t index = ATOMIC_INIT(-1);
37788
37789- card->index = atomic_inc_return(&index);
37790+ card->index = atomic_inc_return_unchecked(&index);
37791 card->driver = driver;
37792 card->device = device;
37793 card->current_tlabel = 0;
37794@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
37795
37796 void fw_core_remove_card(struct fw_card *card)
37797 {
37798- struct fw_card_driver dummy_driver = dummy_driver_template;
37799+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
37800
37801 card->driver->update_phy_reg(card, 4,
37802 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
37803diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
37804index de4aa40..49ab1f2 100644
37805--- a/drivers/firewire/core-device.c
37806+++ b/drivers/firewire/core-device.c
37807@@ -253,7 +253,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
37808 struct config_rom_attribute {
37809 struct device_attribute attr;
37810 u32 key;
37811-};
37812+} __do_const;
37813
37814 static ssize_t show_immediate(struct device *dev,
37815 struct device_attribute *dattr, char *buf)
37816diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
37817index 28a94c7..58da63a 100644
37818--- a/drivers/firewire/core-transaction.c
37819+++ b/drivers/firewire/core-transaction.c
37820@@ -38,6 +38,7 @@
37821 #include <linux/timer.h>
37822 #include <linux/types.h>
37823 #include <linux/workqueue.h>
37824+#include <linux/sched.h>
37825
37826 #include <asm/byteorder.h>
37827
37828diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
37829index 515a42c..5ecf3ba 100644
37830--- a/drivers/firewire/core.h
37831+++ b/drivers/firewire/core.h
37832@@ -111,6 +111,7 @@ struct fw_card_driver {
37833
37834 int (*stop_iso)(struct fw_iso_context *ctx);
37835 };
37836+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
37837
37838 void fw_card_initialize(struct fw_card *card,
37839 const struct fw_card_driver *driver, struct device *device);
37840diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
37841index 94a58a0..f5eba42 100644
37842--- a/drivers/firmware/dmi-id.c
37843+++ b/drivers/firmware/dmi-id.c
37844@@ -16,7 +16,7 @@
37845 struct dmi_device_attribute{
37846 struct device_attribute dev_attr;
37847 int field;
37848-};
37849+} __do_const;
37850 #define to_dmi_dev_attr(_dev_attr) \
37851 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
37852
37853diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
37854index 232fa8f..386c255 100644
37855--- a/drivers/firmware/dmi_scan.c
37856+++ b/drivers/firmware/dmi_scan.c
37857@@ -504,11 +504,6 @@ void __init dmi_scan_machine(void)
37858 }
37859 }
37860 else {
37861- /*
37862- * no iounmap() for that ioremap(); it would be a no-op, but
37863- * it's so early in setup that sucker gets confused into doing
37864- * what it shouldn't if we actually call it.
37865- */
37866 p = dmi_ioremap(0xF0000, 0x10000);
37867 if (p == NULL)
37868 goto error;
37869@@ -806,7 +801,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
37870 if (buf == NULL)
37871 return -1;
37872
37873- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
37874+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
37875
37876 iounmap(buf);
37877 return 0;
37878diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
37879index 5145fa3..0d3babd 100644
37880--- a/drivers/firmware/efi/efi.c
37881+++ b/drivers/firmware/efi/efi.c
37882@@ -65,14 +65,16 @@ static struct attribute_group efi_subsys_attr_group = {
37883 };
37884
37885 static struct efivars generic_efivars;
37886-static struct efivar_operations generic_ops;
37887+static efivar_operations_no_const generic_ops __read_only;
37888
37889 static int generic_ops_register(void)
37890 {
37891- generic_ops.get_variable = efi.get_variable;
37892- generic_ops.set_variable = efi.set_variable;
37893- generic_ops.get_next_variable = efi.get_next_variable;
37894- generic_ops.query_variable_store = efi_query_variable_store;
37895+ pax_open_kernel();
37896+ *(void **)&generic_ops.get_variable = efi.get_variable;
37897+ *(void **)&generic_ops.set_variable = efi.set_variable;
37898+ *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
37899+ *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
37900+ pax_close_kernel();
37901
37902 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
37903 }
37904diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
37905index 8a7432a..28fb839 100644
37906--- a/drivers/firmware/efi/efivars.c
37907+++ b/drivers/firmware/efi/efivars.c
37908@@ -452,7 +452,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
37909 static int
37910 create_efivars_bin_attributes(void)
37911 {
37912- struct bin_attribute *attr;
37913+ bin_attribute_no_const *attr;
37914 int error;
37915
37916 /* new_var */
37917diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
37918index 2a90ba6..07f3733 100644
37919--- a/drivers/firmware/google/memconsole.c
37920+++ b/drivers/firmware/google/memconsole.c
37921@@ -147,7 +147,9 @@ static int __init memconsole_init(void)
37922 if (!found_memconsole())
37923 return -ENODEV;
37924
37925- memconsole_bin_attr.size = memconsole_length;
37926+ pax_open_kernel();
37927+ *(size_t *)&memconsole_bin_attr.size = memconsole_length;
37928+ pax_close_kernel();
37929
37930 ret = sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
37931
37932diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
37933index 2729e3d..f9deca1 100644
37934--- a/drivers/gpio/gpio-ich.c
37935+++ b/drivers/gpio/gpio-ich.c
37936@@ -71,7 +71,7 @@ struct ichx_desc {
37937 /* Some chipsets have quirks, let these use their own request/get */
37938 int (*request)(struct gpio_chip *chip, unsigned offset);
37939 int (*get)(struct gpio_chip *chip, unsigned offset);
37940-};
37941+} __do_const;
37942
37943 static struct {
37944 spinlock_t lock;
37945diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
37946index 9902732..64b62dd 100644
37947--- a/drivers/gpio/gpio-vr41xx.c
37948+++ b/drivers/gpio/gpio-vr41xx.c
37949@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
37950 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
37951 maskl, pendl, maskh, pendh);
37952
37953- atomic_inc(&irq_err_count);
37954+ atomic_inc_unchecked(&irq_err_count);
37955
37956 return -EINVAL;
37957 }
37958diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
37959index 6a64749..0767a9f 100644
37960--- a/drivers/gpu/drm/drm_crtc_helper.c
37961+++ b/drivers/gpu/drm/drm_crtc_helper.c
37962@@ -322,7 +322,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
37963 struct drm_crtc *tmp;
37964 int crtc_mask = 1;
37965
37966- WARN(!crtc, "checking null crtc?\n");
37967+ BUG_ON(!crtc);
37968
37969 dev = crtc->dev;
37970
37971diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
37972index 99fcd7c..13cf6c5 100644
37973--- a/drivers/gpu/drm/drm_drv.c
37974+++ b/drivers/gpu/drm/drm_drv.c
37975@@ -307,7 +307,7 @@ module_exit(drm_core_exit);
37976 /**
37977 * Copy and IOCTL return string to user space
37978 */
37979-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
37980+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
37981 {
37982 int len;
37983
37984@@ -377,7 +377,7 @@ long drm_ioctl(struct file *filp,
37985 struct drm_file *file_priv = filp->private_data;
37986 struct drm_device *dev;
37987 const struct drm_ioctl_desc *ioctl = NULL;
37988- drm_ioctl_t *func;
37989+ drm_ioctl_no_const_t func;
37990 unsigned int nr = DRM_IOCTL_NR(cmd);
37991 int retcode = -EINVAL;
37992 char stack_kdata[128];
37993@@ -390,7 +390,7 @@ long drm_ioctl(struct file *filp,
37994 return -ENODEV;
37995
37996 atomic_inc(&dev->ioctl_count);
37997- atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
37998+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
37999 ++file_priv->ioctl_count;
38000
38001 if ((nr >= DRM_CORE_IOCTL_COUNT) &&
38002diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
38003index 3a24385..4e426e0 100644
38004--- a/drivers/gpu/drm/drm_fops.c
38005+++ b/drivers/gpu/drm/drm_fops.c
38006@@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
38007 }
38008
38009 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
38010- atomic_set(&dev->counts[i], 0);
38011+ atomic_set_unchecked(&dev->counts[i], 0);
38012
38013 dev->sigdata.lock = NULL;
38014
38015@@ -135,7 +135,7 @@ int drm_open(struct inode *inode, struct file *filp)
38016 if (drm_device_is_unplugged(dev))
38017 return -ENODEV;
38018
38019- if (!dev->open_count++)
38020+ if (local_inc_return(&dev->open_count) == 1)
38021 need_setup = 1;
38022 mutex_lock(&dev->struct_mutex);
38023 old_imapping = inode->i_mapping;
38024@@ -151,7 +151,7 @@ int drm_open(struct inode *inode, struct file *filp)
38025 retcode = drm_open_helper(inode, filp, dev);
38026 if (retcode)
38027 goto err_undo;
38028- atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
38029+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
38030 if (need_setup) {
38031 retcode = drm_setup(dev);
38032 if (retcode)
38033@@ -166,7 +166,7 @@ err_undo:
38034 iput(container_of(dev->dev_mapping, struct inode, i_data));
38035 dev->dev_mapping = old_mapping;
38036 mutex_unlock(&dev->struct_mutex);
38037- dev->open_count--;
38038+ local_dec(&dev->open_count);
38039 return retcode;
38040 }
38041 EXPORT_SYMBOL(drm_open);
38042@@ -456,7 +456,7 @@ int drm_release(struct inode *inode, struct file *filp)
38043
38044 mutex_lock(&drm_global_mutex);
38045
38046- DRM_DEBUG("open_count = %d\n", dev->open_count);
38047+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
38048
38049 if (dev->driver->preclose)
38050 dev->driver->preclose(dev, file_priv);
38051@@ -465,10 +465,10 @@ int drm_release(struct inode *inode, struct file *filp)
38052 * Begin inline drm_release
38053 */
38054
38055- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
38056+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
38057 task_pid_nr(current),
38058 (long)old_encode_dev(file_priv->minor->device),
38059- dev->open_count);
38060+ local_read(&dev->open_count));
38061
38062 /* Release any auth tokens that might point to this file_priv,
38063 (do that under the drm_global_mutex) */
38064@@ -565,8 +565,8 @@ int drm_release(struct inode *inode, struct file *filp)
38065 * End inline drm_release
38066 */
38067
38068- atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
38069- if (!--dev->open_count) {
38070+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
38071+ if (local_dec_and_test(&dev->open_count)) {
38072 if (atomic_read(&dev->ioctl_count)) {
38073 DRM_ERROR("Device busy: %d\n",
38074 atomic_read(&dev->ioctl_count));
38075diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
38076index f731116..629842c 100644
38077--- a/drivers/gpu/drm/drm_global.c
38078+++ b/drivers/gpu/drm/drm_global.c
38079@@ -36,7 +36,7 @@
38080 struct drm_global_item {
38081 struct mutex mutex;
38082 void *object;
38083- int refcount;
38084+ atomic_t refcount;
38085 };
38086
38087 static struct drm_global_item glob[DRM_GLOBAL_NUM];
38088@@ -49,7 +49,7 @@ void drm_global_init(void)
38089 struct drm_global_item *item = &glob[i];
38090 mutex_init(&item->mutex);
38091 item->object = NULL;
38092- item->refcount = 0;
38093+ atomic_set(&item->refcount, 0);
38094 }
38095 }
38096
38097@@ -59,7 +59,7 @@ void drm_global_release(void)
38098 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
38099 struct drm_global_item *item = &glob[i];
38100 BUG_ON(item->object != NULL);
38101- BUG_ON(item->refcount != 0);
38102+ BUG_ON(atomic_read(&item->refcount) != 0);
38103 }
38104 }
38105
38106@@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
38107 void *object;
38108
38109 mutex_lock(&item->mutex);
38110- if (item->refcount == 0) {
38111+ if (atomic_read(&item->refcount) == 0) {
38112 item->object = kzalloc(ref->size, GFP_KERNEL);
38113 if (unlikely(item->object == NULL)) {
38114 ret = -ENOMEM;
38115@@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
38116 goto out_err;
38117
38118 }
38119- ++item->refcount;
38120+ atomic_inc(&item->refcount);
38121 ref->object = item->object;
38122 object = item->object;
38123 mutex_unlock(&item->mutex);
38124@@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
38125 struct drm_global_item *item = &glob[ref->global_type];
38126
38127 mutex_lock(&item->mutex);
38128- BUG_ON(item->refcount == 0);
38129+ BUG_ON(atomic_read(&item->refcount) == 0);
38130 BUG_ON(ref->object != item->object);
38131- if (--item->refcount == 0) {
38132+ if (atomic_dec_and_test(&item->refcount)) {
38133 ref->release(ref);
38134 item->object = NULL;
38135 }
38136diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
38137index d4b20ce..77a8d41 100644
38138--- a/drivers/gpu/drm/drm_info.c
38139+++ b/drivers/gpu/drm/drm_info.c
38140@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
38141 struct drm_local_map *map;
38142 struct drm_map_list *r_list;
38143
38144- /* Hardcoded from _DRM_FRAME_BUFFER,
38145- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
38146- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
38147- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
38148+ static const char * const types[] = {
38149+ [_DRM_FRAME_BUFFER] = "FB",
38150+ [_DRM_REGISTERS] = "REG",
38151+ [_DRM_SHM] = "SHM",
38152+ [_DRM_AGP] = "AGP",
38153+ [_DRM_SCATTER_GATHER] = "SG",
38154+ [_DRM_CONSISTENT] = "PCI",
38155+ [_DRM_GEM] = "GEM" };
38156 const char *type;
38157 int i;
38158
38159@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
38160 map = r_list->map;
38161 if (!map)
38162 continue;
38163- if (map->type < 0 || map->type > 5)
38164+ if (map->type >= ARRAY_SIZE(types))
38165 type = "??";
38166 else
38167 type = types[map->type];
38168@@ -253,7 +257,11 @@ int drm_vma_info(struct seq_file *m, void *data)
38169 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
38170 vma->vm_flags & VM_LOCKED ? 'l' : '-',
38171 vma->vm_flags & VM_IO ? 'i' : '-',
38172+#ifdef CONFIG_GRKERNSEC_HIDESYM
38173+ 0);
38174+#else
38175 vma->vm_pgoff);
38176+#endif
38177
38178 #if defined(__i386__)
38179 pgprot = pgprot_val(vma->vm_page_prot);
38180diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
38181index 2f4c434..dd12cd2 100644
38182--- a/drivers/gpu/drm/drm_ioc32.c
38183+++ b/drivers/gpu/drm/drm_ioc32.c
38184@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
38185 request = compat_alloc_user_space(nbytes);
38186 if (!access_ok(VERIFY_WRITE, request, nbytes))
38187 return -EFAULT;
38188- list = (struct drm_buf_desc *) (request + 1);
38189+ list = (struct drm_buf_desc __user *) (request + 1);
38190
38191 if (__put_user(count, &request->count)
38192 || __put_user(list, &request->list))
38193@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
38194 request = compat_alloc_user_space(nbytes);
38195 if (!access_ok(VERIFY_WRITE, request, nbytes))
38196 return -EFAULT;
38197- list = (struct drm_buf_pub *) (request + 1);
38198+ list = (struct drm_buf_pub __user *) (request + 1);
38199
38200 if (__put_user(count, &request->count)
38201 || __put_user(list, &request->list))
38202@@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
38203 return 0;
38204 }
38205
38206-drm_ioctl_compat_t *drm_compat_ioctls[] = {
38207+drm_ioctl_compat_t drm_compat_ioctls[] = {
38208 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
38209 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
38210 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
38211@@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
38212 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38213 {
38214 unsigned int nr = DRM_IOCTL_NR(cmd);
38215- drm_ioctl_compat_t *fn;
38216 int ret;
38217
38218 /* Assume that ioctls without an explicit compat routine will just
38219@@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38220 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
38221 return drm_ioctl(filp, cmd, arg);
38222
38223- fn = drm_compat_ioctls[nr];
38224-
38225- if (fn != NULL)
38226- ret = (*fn) (filp, cmd, arg);
38227+ if (drm_compat_ioctls[nr] != NULL)
38228+ ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
38229 else
38230 ret = drm_ioctl(filp, cmd, arg);
38231
38232diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
38233index ffd7a7b..a64643e 100644
38234--- a/drivers/gpu/drm/drm_ioctl.c
38235+++ b/drivers/gpu/drm/drm_ioctl.c
38236@@ -265,7 +265,7 @@ int drm_getstats(struct drm_device *dev, void *data,
38237 stats->data[i].value =
38238 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
38239 else
38240- stats->data[i].value = atomic_read(&dev->counts[i]);
38241+ stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
38242 stats->data[i].type = dev->types[i];
38243 }
38244
38245diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
38246index d752c96..fe08455 100644
38247--- a/drivers/gpu/drm/drm_lock.c
38248+++ b/drivers/gpu/drm/drm_lock.c
38249@@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
38250 if (drm_lock_take(&master->lock, lock->context)) {
38251 master->lock.file_priv = file_priv;
38252 master->lock.lock_time = jiffies;
38253- atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
38254+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
38255 break; /* Got lock */
38256 }
38257
38258@@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
38259 return -EINVAL;
38260 }
38261
38262- atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
38263+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
38264
38265 if (drm_lock_free(&master->lock, lock->context)) {
38266 /* FIXME: Should really bail out here. */
38267diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
38268index 327ca19..684d3c0 100644
38269--- a/drivers/gpu/drm/drm_stub.c
38270+++ b/drivers/gpu/drm/drm_stub.c
38271@@ -495,7 +495,7 @@ void drm_unplug_dev(struct drm_device *dev)
38272
38273 drm_device_set_unplugged(dev);
38274
38275- if (dev->open_count == 0) {
38276+ if (local_read(&dev->open_count) == 0) {
38277 drm_put_dev(dev);
38278 }
38279 mutex_unlock(&drm_global_mutex);
38280diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
38281index 2290b3b..22056a1 100644
38282--- a/drivers/gpu/drm/drm_sysfs.c
38283+++ b/drivers/gpu/drm/drm_sysfs.c
38284@@ -524,7 +524,7 @@ EXPORT_SYMBOL(drm_sysfs_hotplug_event);
38285 int drm_sysfs_device_add(struct drm_minor *minor)
38286 {
38287 int err;
38288- char *minor_str;
38289+ const char *minor_str;
38290
38291 minor->kdev.parent = minor->dev->dev;
38292
38293diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
38294index ada49ed..29275a0 100644
38295--- a/drivers/gpu/drm/i810/i810_dma.c
38296+++ b/drivers/gpu/drm/i810/i810_dma.c
38297@@ -945,8 +945,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
38298 dma->buflist[vertex->idx],
38299 vertex->discard, vertex->used);
38300
38301- atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
38302- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
38303+ atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
38304+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
38305 sarea_priv->last_enqueue = dev_priv->counter - 1;
38306 sarea_priv->last_dispatch = (int)hw_status[5];
38307
38308@@ -1106,8 +1106,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
38309 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
38310 mc->last_render);
38311
38312- atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
38313- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
38314+ atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
38315+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
38316 sarea_priv->last_enqueue = dev_priv->counter - 1;
38317 sarea_priv->last_dispatch = (int)hw_status[5];
38318
38319diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
38320index 6e0acad..93c8289 100644
38321--- a/drivers/gpu/drm/i810/i810_drv.h
38322+++ b/drivers/gpu/drm/i810/i810_drv.h
38323@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
38324 int page_flipping;
38325
38326 wait_queue_head_t irq_queue;
38327- atomic_t irq_received;
38328- atomic_t irq_emitted;
38329+ atomic_unchecked_t irq_received;
38330+ atomic_unchecked_t irq_emitted;
38331
38332 int front_offset;
38333 } drm_i810_private_t;
38334diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
38335index 47d6c74..279123f 100644
38336--- a/drivers/gpu/drm/i915/i915_debugfs.c
38337+++ b/drivers/gpu/drm/i915/i915_debugfs.c
38338@@ -541,7 +541,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
38339 I915_READ(GTIMR));
38340 }
38341 seq_printf(m, "Interrupts received: %d\n",
38342- atomic_read(&dev_priv->irq_received));
38343+ atomic_read_unchecked(&dev_priv->irq_received));
38344 for_each_ring(ring, dev_priv, i) {
38345 if (IS_GEN6(dev) || IS_GEN7(dev)) {
38346 seq_printf(m,
38347diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
38348index f466980..8f2883f 100644
38349--- a/drivers/gpu/drm/i915/i915_dma.c
38350+++ b/drivers/gpu/drm/i915/i915_dma.c
38351@@ -1260,7 +1260,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
38352 bool can_switch;
38353
38354 spin_lock(&dev->count_lock);
38355- can_switch = (dev->open_count == 0);
38356+ can_switch = (local_read(&dev->open_count) == 0);
38357 spin_unlock(&dev->count_lock);
38358 return can_switch;
38359 }
38360diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
38361index 2f09e80..077876d 100644
38362--- a/drivers/gpu/drm/i915/i915_drv.h
38363+++ b/drivers/gpu/drm/i915/i915_drv.h
38364@@ -1028,7 +1028,7 @@ typedef struct drm_i915_private {
38365 drm_dma_handle_t *status_page_dmah;
38366 struct resource mch_res;
38367
38368- atomic_t irq_received;
38369+ atomic_unchecked_t irq_received;
38370
38371 /* protects the irq masks */
38372 spinlock_t irq_lock;
38373diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
38374index 87a3227..cd13d8f 100644
38375--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
38376+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
38377@@ -727,9 +727,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
38378
38379 static int
38380 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
38381- int count)
38382+ unsigned int count)
38383 {
38384- int i;
38385+ unsigned int i;
38386 int relocs_total = 0;
38387 int relocs_max = INT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
38388
38389diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
38390index 3c59584..500f2e9 100644
38391--- a/drivers/gpu/drm/i915/i915_ioc32.c
38392+++ b/drivers/gpu/drm/i915/i915_ioc32.c
38393@@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
38394 (unsigned long)request);
38395 }
38396
38397-static drm_ioctl_compat_t *i915_compat_ioctls[] = {
38398+static drm_ioctl_compat_t i915_compat_ioctls[] = {
38399 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
38400 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
38401 [DRM_I915_GETPARAM] = compat_i915_getparam,
38402@@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
38403 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38404 {
38405 unsigned int nr = DRM_IOCTL_NR(cmd);
38406- drm_ioctl_compat_t *fn = NULL;
38407 int ret;
38408
38409 if (nr < DRM_COMMAND_BASE)
38410 return drm_compat_ioctl(filp, cmd, arg);
38411
38412- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
38413- fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
38414-
38415- if (fn != NULL)
38416+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
38417+ drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
38418 ret = (*fn) (filp, cmd, arg);
38419- else
38420+ } else
38421 ret = drm_ioctl(filp, cmd, arg);
38422
38423 return ret;
38424diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
38425index 46d46ba..6e49848 100644
38426--- a/drivers/gpu/drm/i915/i915_irq.c
38427+++ b/drivers/gpu/drm/i915/i915_irq.c
38428@@ -975,7 +975,7 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
38429 int pipe;
38430 u32 pipe_stats[I915_MAX_PIPES];
38431
38432- atomic_inc(&dev_priv->irq_received);
38433+ atomic_inc_unchecked(&dev_priv->irq_received);
38434
38435 while (true) {
38436 iir = I915_READ(VLV_IIR);
38437@@ -1192,7 +1192,7 @@ static irqreturn_t ivybridge_irq_handler(int irq, void *arg)
38438 irqreturn_t ret = IRQ_NONE;
38439 int i;
38440
38441- atomic_inc(&dev_priv->irq_received);
38442+ atomic_inc_unchecked(&dev_priv->irq_received);
38443
38444 /* We get interrupts on unclaimed registers, so check for this before we
38445 * do any I915_{READ,WRITE}. */
38446@@ -1312,7 +1312,7 @@ static irqreturn_t ironlake_irq_handler(int irq, void *arg)
38447 int ret = IRQ_NONE;
38448 u32 de_iir, gt_iir, de_ier, pm_iir, sde_ier;
38449
38450- atomic_inc(&dev_priv->irq_received);
38451+ atomic_inc_unchecked(&dev_priv->irq_received);
38452
38453 /* disable master interrupt before clearing iir */
38454 de_ier = I915_READ(DEIER);
38455@@ -2617,7 +2617,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
38456 {
38457 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38458
38459- atomic_set(&dev_priv->irq_received, 0);
38460+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38461
38462 I915_WRITE(HWSTAM, 0xeffe);
38463
38464@@ -2639,7 +2639,7 @@ static void ivybridge_irq_preinstall(struct drm_device *dev)
38465 {
38466 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38467
38468- atomic_set(&dev_priv->irq_received, 0);
38469+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38470
38471 I915_WRITE(HWSTAM, 0xeffe);
38472
38473@@ -2667,7 +2667,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
38474 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38475 int pipe;
38476
38477- atomic_set(&dev_priv->irq_received, 0);
38478+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38479
38480 /* VLV magic */
38481 I915_WRITE(VLV_IMR, 0);
38482@@ -2979,7 +2979,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
38483 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38484 int pipe;
38485
38486- atomic_set(&dev_priv->irq_received, 0);
38487+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38488
38489 for_each_pipe(pipe)
38490 I915_WRITE(PIPESTAT(pipe), 0);
38491@@ -3058,7 +3058,7 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg)
38492 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
38493 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
38494
38495- atomic_inc(&dev_priv->irq_received);
38496+ atomic_inc_unchecked(&dev_priv->irq_received);
38497
38498 iir = I915_READ16(IIR);
38499 if (iir == 0)
38500@@ -3133,7 +3133,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
38501 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38502 int pipe;
38503
38504- atomic_set(&dev_priv->irq_received, 0);
38505+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38506
38507 if (I915_HAS_HOTPLUG(dev)) {
38508 I915_WRITE(PORT_HOTPLUG_EN, 0);
38509@@ -3232,7 +3232,7 @@ static irqreturn_t i915_irq_handler(int irq, void *arg)
38510 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
38511 int pipe, ret = IRQ_NONE;
38512
38513- atomic_inc(&dev_priv->irq_received);
38514+ atomic_inc_unchecked(&dev_priv->irq_received);
38515
38516 iir = I915_READ(IIR);
38517 do {
38518@@ -3356,7 +3356,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
38519 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38520 int pipe;
38521
38522- atomic_set(&dev_priv->irq_received, 0);
38523+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38524
38525 I915_WRITE(PORT_HOTPLUG_EN, 0);
38526 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
38527@@ -3465,7 +3465,7 @@ static irqreturn_t i965_irq_handler(int irq, void *arg)
38528 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
38529 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
38530
38531- atomic_inc(&dev_priv->irq_received);
38532+ atomic_inc_unchecked(&dev_priv->irq_received);
38533
38534 iir = I915_READ(IIR);
38535
38536diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
38537index bedf15a..d02d1e6 100644
38538--- a/drivers/gpu/drm/i915/intel_display.c
38539+++ b/drivers/gpu/drm/i915/intel_display.c
38540@@ -9424,13 +9424,13 @@ struct intel_quirk {
38541 int subsystem_vendor;
38542 int subsystem_device;
38543 void (*hook)(struct drm_device *dev);
38544-};
38545+} __do_const;
38546
38547 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
38548 struct intel_dmi_quirk {
38549 void (*hook)(struct drm_device *dev);
38550 const struct dmi_system_id (*dmi_id_list)[];
38551-};
38552+} __do_const;
38553
38554 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
38555 {
38556@@ -9438,18 +9438,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
38557 return 1;
38558 }
38559
38560-static const struct intel_dmi_quirk intel_dmi_quirks[] = {
38561+static const struct dmi_system_id intel_dmi_quirks_table[] = {
38562 {
38563- .dmi_id_list = &(const struct dmi_system_id[]) {
38564- {
38565- .callback = intel_dmi_reverse_brightness,
38566- .ident = "NCR Corporation",
38567- .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
38568- DMI_MATCH(DMI_PRODUCT_NAME, ""),
38569- },
38570- },
38571- { } /* terminating entry */
38572+ .callback = intel_dmi_reverse_brightness,
38573+ .ident = "NCR Corporation",
38574+ .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
38575+ DMI_MATCH(DMI_PRODUCT_NAME, ""),
38576 },
38577+ },
38578+ { } /* terminating entry */
38579+};
38580+
38581+static const struct intel_dmi_quirk intel_dmi_quirks[] = {
38582+ {
38583+ .dmi_id_list = &intel_dmi_quirks_table,
38584 .hook = quirk_invert_brightness,
38585 },
38586 };
38587diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
38588index 54558a0..2d97005 100644
38589--- a/drivers/gpu/drm/mga/mga_drv.h
38590+++ b/drivers/gpu/drm/mga/mga_drv.h
38591@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
38592 u32 clear_cmd;
38593 u32 maccess;
38594
38595- atomic_t vbl_received; /**< Number of vblanks received. */
38596+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
38597 wait_queue_head_t fence_queue;
38598- atomic_t last_fence_retired;
38599+ atomic_unchecked_t last_fence_retired;
38600 u32 next_fence_to_post;
38601
38602 unsigned int fb_cpp;
38603diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
38604index 709e90d..89a1c0d 100644
38605--- a/drivers/gpu/drm/mga/mga_ioc32.c
38606+++ b/drivers/gpu/drm/mga/mga_ioc32.c
38607@@ -189,7 +189,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
38608 return 0;
38609 }
38610
38611-drm_ioctl_compat_t *mga_compat_ioctls[] = {
38612+drm_ioctl_compat_t mga_compat_ioctls[] = {
38613 [DRM_MGA_INIT] = compat_mga_init,
38614 [DRM_MGA_GETPARAM] = compat_mga_getparam,
38615 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
38616@@ -207,18 +207,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
38617 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38618 {
38619 unsigned int nr = DRM_IOCTL_NR(cmd);
38620- drm_ioctl_compat_t *fn = NULL;
38621 int ret;
38622
38623 if (nr < DRM_COMMAND_BASE)
38624 return drm_compat_ioctl(filp, cmd, arg);
38625
38626- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
38627- fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
38628-
38629- if (fn != NULL)
38630+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
38631+ drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
38632 ret = (*fn) (filp, cmd, arg);
38633- else
38634+ } else
38635 ret = drm_ioctl(filp, cmd, arg);
38636
38637 return ret;
38638diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
38639index 598c281..60d590e 100644
38640--- a/drivers/gpu/drm/mga/mga_irq.c
38641+++ b/drivers/gpu/drm/mga/mga_irq.c
38642@@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
38643 if (crtc != 0)
38644 return 0;
38645
38646- return atomic_read(&dev_priv->vbl_received);
38647+ return atomic_read_unchecked(&dev_priv->vbl_received);
38648 }
38649
38650
38651@@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
38652 /* VBLANK interrupt */
38653 if (status & MGA_VLINEPEN) {
38654 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
38655- atomic_inc(&dev_priv->vbl_received);
38656+ atomic_inc_unchecked(&dev_priv->vbl_received);
38657 drm_handle_vblank(dev, 0);
38658 handled = 1;
38659 }
38660@@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
38661 if ((prim_start & ~0x03) != (prim_end & ~0x03))
38662 MGA_WRITE(MGA_PRIMEND, prim_end);
38663
38664- atomic_inc(&dev_priv->last_fence_retired);
38665+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
38666 DRM_WAKEUP(&dev_priv->fence_queue);
38667 handled = 1;
38668 }
38669@@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
38670 * using fences.
38671 */
38672 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
38673- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
38674+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
38675 - *sequence) <= (1 << 23)));
38676
38677 *sequence = cur_fence;
38678diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
38679index 3e72876..d1c15ad 100644
38680--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
38681+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
38682@@ -965,7 +965,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
38683 struct bit_table {
38684 const char id;
38685 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
38686-};
38687+} __no_const;
38688
38689 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
38690
38691diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
38692index 41ff7e0..fa854ef 100644
38693--- a/drivers/gpu/drm/nouveau/nouveau_drm.h
38694+++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
38695@@ -92,7 +92,6 @@ struct nouveau_drm {
38696 struct drm_global_reference mem_global_ref;
38697 struct ttm_bo_global_ref bo_global_ref;
38698 struct ttm_bo_device bdev;
38699- atomic_t validate_sequence;
38700 int (*move)(struct nouveau_channel *,
38701 struct ttm_buffer_object *,
38702 struct ttm_mem_reg *, struct ttm_mem_reg *);
38703diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
38704index 08214bc..9208577 100644
38705--- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
38706+++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
38707@@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
38708 unsigned long arg)
38709 {
38710 unsigned int nr = DRM_IOCTL_NR(cmd);
38711- drm_ioctl_compat_t *fn = NULL;
38712+ drm_ioctl_compat_t fn = NULL;
38713 int ret;
38714
38715 if (nr < DRM_COMMAND_BASE)
38716diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
38717index 25d3495..d81aaf6 100644
38718--- a/drivers/gpu/drm/nouveau/nouveau_vga.c
38719+++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
38720@@ -62,7 +62,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
38721 bool can_switch;
38722
38723 spin_lock(&dev->count_lock);
38724- can_switch = (dev->open_count == 0);
38725+ can_switch = (local_read(&dev->open_count) == 0);
38726 spin_unlock(&dev->count_lock);
38727 return can_switch;
38728 }
38729diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
38730index 1dfd84c..104896c 100644
38731--- a/drivers/gpu/drm/qxl/qxl_ttm.c
38732+++ b/drivers/gpu/drm/qxl/qxl_ttm.c
38733@@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
38734 }
38735 }
38736
38737-static struct vm_operations_struct qxl_ttm_vm_ops;
38738+static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
38739 static const struct vm_operations_struct *ttm_vm_ops;
38740
38741 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
38742@@ -147,8 +147,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
38743 return r;
38744 if (unlikely(ttm_vm_ops == NULL)) {
38745 ttm_vm_ops = vma->vm_ops;
38746+ pax_open_kernel();
38747 qxl_ttm_vm_ops = *ttm_vm_ops;
38748 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
38749+ pax_close_kernel();
38750 }
38751 vma->vm_ops = &qxl_ttm_vm_ops;
38752 return 0;
38753@@ -556,25 +558,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
38754 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
38755 {
38756 #if defined(CONFIG_DEBUG_FS)
38757- static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
38758- static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
38759- unsigned i;
38760+ static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
38761+ {
38762+ .name = "qxl_mem_mm",
38763+ .show = &qxl_mm_dump_table,
38764+ },
38765+ {
38766+ .name = "qxl_surf_mm",
38767+ .show = &qxl_mm_dump_table,
38768+ }
38769+ };
38770
38771- for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
38772- if (i == 0)
38773- sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
38774- else
38775- sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
38776- qxl_mem_types_list[i].name = qxl_mem_types_names[i];
38777- qxl_mem_types_list[i].show = &qxl_mm_dump_table;
38778- qxl_mem_types_list[i].driver_features = 0;
38779- if (i == 0)
38780- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
38781- else
38782- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
38783+ pax_open_kernel();
38784+ *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
38785+ *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
38786+ pax_close_kernel();
38787
38788- }
38789- return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
38790+ return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
38791 #else
38792 return 0;
38793 #endif
38794diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
38795index d4660cf..70dbe65 100644
38796--- a/drivers/gpu/drm/r128/r128_cce.c
38797+++ b/drivers/gpu/drm/r128/r128_cce.c
38798@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
38799
38800 /* GH: Simple idle check.
38801 */
38802- atomic_set(&dev_priv->idle_count, 0);
38803+ atomic_set_unchecked(&dev_priv->idle_count, 0);
38804
38805 /* We don't support anything other than bus-mastering ring mode,
38806 * but the ring can be in either AGP or PCI space for the ring
38807diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
38808index 930c71b..499aded 100644
38809--- a/drivers/gpu/drm/r128/r128_drv.h
38810+++ b/drivers/gpu/drm/r128/r128_drv.h
38811@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
38812 int is_pci;
38813 unsigned long cce_buffers_offset;
38814
38815- atomic_t idle_count;
38816+ atomic_unchecked_t idle_count;
38817
38818 int page_flipping;
38819 int current_page;
38820 u32 crtc_offset;
38821 u32 crtc_offset_cntl;
38822
38823- atomic_t vbl_received;
38824+ atomic_unchecked_t vbl_received;
38825
38826 u32 color_fmt;
38827 unsigned int front_offset;
38828diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
38829index a954c54..9cc595c 100644
38830--- a/drivers/gpu/drm/r128/r128_ioc32.c
38831+++ b/drivers/gpu/drm/r128/r128_ioc32.c
38832@@ -177,7 +177,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
38833 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
38834 }
38835
38836-drm_ioctl_compat_t *r128_compat_ioctls[] = {
38837+drm_ioctl_compat_t r128_compat_ioctls[] = {
38838 [DRM_R128_INIT] = compat_r128_init,
38839 [DRM_R128_DEPTH] = compat_r128_depth,
38840 [DRM_R128_STIPPLE] = compat_r128_stipple,
38841@@ -196,18 +196,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
38842 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38843 {
38844 unsigned int nr = DRM_IOCTL_NR(cmd);
38845- drm_ioctl_compat_t *fn = NULL;
38846 int ret;
38847
38848 if (nr < DRM_COMMAND_BASE)
38849 return drm_compat_ioctl(filp, cmd, arg);
38850
38851- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
38852- fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
38853-
38854- if (fn != NULL)
38855+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
38856+ drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
38857 ret = (*fn) (filp, cmd, arg);
38858- else
38859+ } else
38860 ret = drm_ioctl(filp, cmd, arg);
38861
38862 return ret;
38863diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
38864index 2ea4f09..d391371 100644
38865--- a/drivers/gpu/drm/r128/r128_irq.c
38866+++ b/drivers/gpu/drm/r128/r128_irq.c
38867@@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
38868 if (crtc != 0)
38869 return 0;
38870
38871- return atomic_read(&dev_priv->vbl_received);
38872+ return atomic_read_unchecked(&dev_priv->vbl_received);
38873 }
38874
38875 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
38876@@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
38877 /* VBLANK interrupt */
38878 if (status & R128_CRTC_VBLANK_INT) {
38879 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
38880- atomic_inc(&dev_priv->vbl_received);
38881+ atomic_inc_unchecked(&dev_priv->vbl_received);
38882 drm_handle_vblank(dev, 0);
38883 return IRQ_HANDLED;
38884 }
38885diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
38886index 19bb7e6..de7e2a2 100644
38887--- a/drivers/gpu/drm/r128/r128_state.c
38888+++ b/drivers/gpu/drm/r128/r128_state.c
38889@@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
38890
38891 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
38892 {
38893- if (atomic_read(&dev_priv->idle_count) == 0)
38894+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
38895 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
38896 else
38897- atomic_set(&dev_priv->idle_count, 0);
38898+ atomic_set_unchecked(&dev_priv->idle_count, 0);
38899 }
38900
38901 #endif
38902diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
38903index af85299..ed9ac8d 100644
38904--- a/drivers/gpu/drm/radeon/mkregtable.c
38905+++ b/drivers/gpu/drm/radeon/mkregtable.c
38906@@ -624,14 +624,14 @@ static int parser_auth(struct table *t, const char *filename)
38907 regex_t mask_rex;
38908 regmatch_t match[4];
38909 char buf[1024];
38910- size_t end;
38911+ long end;
38912 int len;
38913 int done = 0;
38914 int r;
38915 unsigned o;
38916 struct offset *offset;
38917 char last_reg_s[10];
38918- int last_reg;
38919+ unsigned long last_reg;
38920
38921 if (regcomp
38922 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
38923diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
38924index 63398ae..669e045 100644
38925--- a/drivers/gpu/drm/radeon/radeon_device.c
38926+++ b/drivers/gpu/drm/radeon/radeon_device.c
38927@@ -1105,7 +1105,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
38928 bool can_switch;
38929
38930 spin_lock(&dev->count_lock);
38931- can_switch = (dev->open_count == 0);
38932+ can_switch = (local_read(&dev->open_count) == 0);
38933 spin_unlock(&dev->count_lock);
38934 return can_switch;
38935 }
38936diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
38937index b369d42..8dd04eb 100644
38938--- a/drivers/gpu/drm/radeon/radeon_drv.h
38939+++ b/drivers/gpu/drm/radeon/radeon_drv.h
38940@@ -258,7 +258,7 @@ typedef struct drm_radeon_private {
38941
38942 /* SW interrupt */
38943 wait_queue_head_t swi_queue;
38944- atomic_t swi_emitted;
38945+ atomic_unchecked_t swi_emitted;
38946 int vblank_crtc;
38947 uint32_t irq_enable_reg;
38948 uint32_t r500_disp_irq_reg;
38949diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
38950index c180df8..5fd8186 100644
38951--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
38952+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
38953@@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
38954 request = compat_alloc_user_space(sizeof(*request));
38955 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
38956 || __put_user(req32.param, &request->param)
38957- || __put_user((void __user *)(unsigned long)req32.value,
38958+ || __put_user((unsigned long)req32.value,
38959 &request->value))
38960 return -EFAULT;
38961
38962@@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
38963 #define compat_radeon_cp_setparam NULL
38964 #endif /* X86_64 || IA64 */
38965
38966-static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
38967+static drm_ioctl_compat_t radeon_compat_ioctls[] = {
38968 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
38969 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
38970 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
38971@@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
38972 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38973 {
38974 unsigned int nr = DRM_IOCTL_NR(cmd);
38975- drm_ioctl_compat_t *fn = NULL;
38976 int ret;
38977
38978 if (nr < DRM_COMMAND_BASE)
38979 return drm_compat_ioctl(filp, cmd, arg);
38980
38981- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
38982- fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
38983-
38984- if (fn != NULL)
38985+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
38986+ drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
38987 ret = (*fn) (filp, cmd, arg);
38988- else
38989+ } else
38990 ret = drm_ioctl(filp, cmd, arg);
38991
38992 return ret;
38993diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
38994index 8d68e97..9dcfed8 100644
38995--- a/drivers/gpu/drm/radeon/radeon_irq.c
38996+++ b/drivers/gpu/drm/radeon/radeon_irq.c
38997@@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
38998 unsigned int ret;
38999 RING_LOCALS;
39000
39001- atomic_inc(&dev_priv->swi_emitted);
39002- ret = atomic_read(&dev_priv->swi_emitted);
39003+ atomic_inc_unchecked(&dev_priv->swi_emitted);
39004+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
39005
39006 BEGIN_RING(4);
39007 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
39008@@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
39009 drm_radeon_private_t *dev_priv =
39010 (drm_radeon_private_t *) dev->dev_private;
39011
39012- atomic_set(&dev_priv->swi_emitted, 0);
39013+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
39014 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
39015
39016 dev->max_vblank_count = 0x001fffff;
39017diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
39018index 4d20910..6726b6d 100644
39019--- a/drivers/gpu/drm/radeon/radeon_state.c
39020+++ b/drivers/gpu/drm/radeon/radeon_state.c
39021@@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
39022 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
39023 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
39024
39025- if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
39026+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
39027 sarea_priv->nbox * sizeof(depth_boxes[0])))
39028 return -EFAULT;
39029
39030@@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
39031 {
39032 drm_radeon_private_t *dev_priv = dev->dev_private;
39033 drm_radeon_getparam_t *param = data;
39034- int value;
39035+ int value = 0;
39036
39037 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
39038
39039diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
39040index 6c0ce89..57a2529 100644
39041--- a/drivers/gpu/drm/radeon/radeon_ttm.c
39042+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
39043@@ -782,7 +782,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
39044 man->size = size >> PAGE_SHIFT;
39045 }
39046
39047-static struct vm_operations_struct radeon_ttm_vm_ops;
39048+static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
39049 static const struct vm_operations_struct *ttm_vm_ops = NULL;
39050
39051 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
39052@@ -823,8 +823,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
39053 }
39054 if (unlikely(ttm_vm_ops == NULL)) {
39055 ttm_vm_ops = vma->vm_ops;
39056+ pax_open_kernel();
39057 radeon_ttm_vm_ops = *ttm_vm_ops;
39058 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
39059+ pax_close_kernel();
39060 }
39061 vma->vm_ops = &radeon_ttm_vm_ops;
39062 return 0;
39063@@ -853,38 +855,33 @@ static int radeon_mm_dump_table(struct seq_file *m, void *data)
39064 static int radeon_ttm_debugfs_init(struct radeon_device *rdev)
39065 {
39066 #if defined(CONFIG_DEBUG_FS)
39067- static struct drm_info_list radeon_mem_types_list[RADEON_DEBUGFS_MEM_TYPES+2];
39068- static char radeon_mem_types_names[RADEON_DEBUGFS_MEM_TYPES+2][32];
39069+ static struct drm_info_list radeon_mem_types_list[RADEON_DEBUGFS_MEM_TYPES+2] = {
39070+ {
39071+ .name = "radeon_vram_mm",
39072+ .show = &radeon_mm_dump_table,
39073+ },
39074+ {
39075+ .name = "radeon_gtt_mm",
39076+ .show = &radeon_mm_dump_table,
39077+ },
39078+ {
39079+ .name = "ttm_page_pool",
39080+ .show = &ttm_page_alloc_debugfs,
39081+ },
39082+ {
39083+ .name = "ttm_dma_page_pool",
39084+ .show = &ttm_dma_page_alloc_debugfs,
39085+ },
39086+ };
39087 unsigned i;
39088
39089- for (i = 0; i < RADEON_DEBUGFS_MEM_TYPES; i++) {
39090- if (i == 0)
39091- sprintf(radeon_mem_types_names[i], "radeon_vram_mm");
39092- else
39093- sprintf(radeon_mem_types_names[i], "radeon_gtt_mm");
39094- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
39095- radeon_mem_types_list[i].show = &radeon_mm_dump_table;
39096- radeon_mem_types_list[i].driver_features = 0;
39097- if (i == 0)
39098- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
39099- else
39100- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
39101-
39102- }
39103- /* Add ttm page pool to debugfs */
39104- sprintf(radeon_mem_types_names[i], "ttm_page_pool");
39105- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
39106- radeon_mem_types_list[i].show = &ttm_page_alloc_debugfs;
39107- radeon_mem_types_list[i].driver_features = 0;
39108- radeon_mem_types_list[i++].data = NULL;
39109+ pax_open_kernel();
39110+ *(void **)&radeon_mem_types_list[0].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
39111+ *(void **)&radeon_mem_types_list[1].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
39112+ pax_close_kernel();
39113 #ifdef CONFIG_SWIOTLB
39114- if (swiotlb_nr_tbl()) {
39115- sprintf(radeon_mem_types_names[i], "ttm_dma_page_pool");
39116- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
39117- radeon_mem_types_list[i].show = &ttm_dma_page_alloc_debugfs;
39118- radeon_mem_types_list[i].driver_features = 0;
39119- radeon_mem_types_list[i++].data = NULL;
39120- }
39121+ if (swiotlb_nr_tbl())
39122+ i++;
39123 #endif
39124 return radeon_debugfs_add_files(rdev, radeon_mem_types_list, i);
39125
39126diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
39127index d8ddfb3..609de1d 100644
39128--- a/drivers/gpu/drm/radeon/rs690.c
39129+++ b/drivers/gpu/drm/radeon/rs690.c
39130@@ -345,9 +345,11 @@ static void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
39131 if (max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
39132 rdev->pm.sideport_bandwidth.full)
39133 max_bandwidth = rdev->pm.sideport_bandwidth;
39134- read_delay_latency.full = dfixed_const(370 * 800 * 1000);
39135+ read_delay_latency.full = dfixed_const(800 * 1000);
39136 read_delay_latency.full = dfixed_div(read_delay_latency,
39137 rdev->pm.igp_sideport_mclk);
39138+ a.full = dfixed_const(370);
39139+ read_delay_latency.full = dfixed_mul(read_delay_latency, a);
39140 } else {
39141 if (max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
39142 rdev->pm.k8_bandwidth.full)
39143diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
39144index dbc2def..0a9f710 100644
39145--- a/drivers/gpu/drm/ttm/ttm_memory.c
39146+++ b/drivers/gpu/drm/ttm/ttm_memory.c
39147@@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
39148 zone->glob = glob;
39149 glob->zone_kernel = zone;
39150 ret = kobject_init_and_add(
39151- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
39152+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
39153 if (unlikely(ret != 0)) {
39154 kobject_put(&zone->kobj);
39155 return ret;
39156@@ -347,7 +347,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
39157 zone->glob = glob;
39158 glob->zone_dma32 = zone;
39159 ret = kobject_init_and_add(
39160- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
39161+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
39162 if (unlikely(ret != 0)) {
39163 kobject_put(&zone->kobj);
39164 return ret;
39165diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
39166index bd2a3b4..122d9ad 100644
39167--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
39168+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
39169@@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
39170 static int ttm_pool_mm_shrink(struct shrinker *shrink,
39171 struct shrink_control *sc)
39172 {
39173- static atomic_t start_pool = ATOMIC_INIT(0);
39174+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
39175 unsigned i;
39176- unsigned pool_offset = atomic_add_return(1, &start_pool);
39177+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
39178 struct ttm_page_pool *pool;
39179 int shrink_pages = sc->nr_to_scan;
39180
39181diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
39182index 97e9d61..bf23c461 100644
39183--- a/drivers/gpu/drm/udl/udl_fb.c
39184+++ b/drivers/gpu/drm/udl/udl_fb.c
39185@@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
39186 fb_deferred_io_cleanup(info);
39187 kfree(info->fbdefio);
39188 info->fbdefio = NULL;
39189- info->fbops->fb_mmap = udl_fb_mmap;
39190 }
39191
39192 pr_warn("released /dev/fb%d user=%d count=%d\n",
39193diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
39194index 893a650..6190d3b 100644
39195--- a/drivers/gpu/drm/via/via_drv.h
39196+++ b/drivers/gpu/drm/via/via_drv.h
39197@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
39198 typedef uint32_t maskarray_t[5];
39199
39200 typedef struct drm_via_irq {
39201- atomic_t irq_received;
39202+ atomic_unchecked_t irq_received;
39203 uint32_t pending_mask;
39204 uint32_t enable_mask;
39205 wait_queue_head_t irq_queue;
39206@@ -75,7 +75,7 @@ typedef struct drm_via_private {
39207 struct timeval last_vblank;
39208 int last_vblank_valid;
39209 unsigned usec_per_vblank;
39210- atomic_t vbl_received;
39211+ atomic_unchecked_t vbl_received;
39212 drm_via_state_t hc_state;
39213 char pci_buf[VIA_PCI_BUF_SIZE];
39214 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
39215diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
39216index ac98964..5dbf512 100644
39217--- a/drivers/gpu/drm/via/via_irq.c
39218+++ b/drivers/gpu/drm/via/via_irq.c
39219@@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
39220 if (crtc != 0)
39221 return 0;
39222
39223- return atomic_read(&dev_priv->vbl_received);
39224+ return atomic_read_unchecked(&dev_priv->vbl_received);
39225 }
39226
39227 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
39228@@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
39229
39230 status = VIA_READ(VIA_REG_INTERRUPT);
39231 if (status & VIA_IRQ_VBLANK_PENDING) {
39232- atomic_inc(&dev_priv->vbl_received);
39233- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
39234+ atomic_inc_unchecked(&dev_priv->vbl_received);
39235+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
39236 do_gettimeofday(&cur_vblank);
39237 if (dev_priv->last_vblank_valid) {
39238 dev_priv->usec_per_vblank =
39239@@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
39240 dev_priv->last_vblank = cur_vblank;
39241 dev_priv->last_vblank_valid = 1;
39242 }
39243- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
39244+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
39245 DRM_DEBUG("US per vblank is: %u\n",
39246 dev_priv->usec_per_vblank);
39247 }
39248@@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
39249
39250 for (i = 0; i < dev_priv->num_irqs; ++i) {
39251 if (status & cur_irq->pending_mask) {
39252- atomic_inc(&cur_irq->irq_received);
39253+ atomic_inc_unchecked(&cur_irq->irq_received);
39254 DRM_WAKEUP(&cur_irq->irq_queue);
39255 handled = 1;
39256 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
39257@@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
39258 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
39259 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
39260 masks[irq][4]));
39261- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
39262+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
39263 } else {
39264 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
39265 (((cur_irq_sequence =
39266- atomic_read(&cur_irq->irq_received)) -
39267+ atomic_read_unchecked(&cur_irq->irq_received)) -
39268 *sequence) <= (1 << 23)));
39269 }
39270 *sequence = cur_irq_sequence;
39271@@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
39272 }
39273
39274 for (i = 0; i < dev_priv->num_irqs; ++i) {
39275- atomic_set(&cur_irq->irq_received, 0);
39276+ atomic_set_unchecked(&cur_irq->irq_received, 0);
39277 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
39278 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
39279 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
39280@@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
39281 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
39282 case VIA_IRQ_RELATIVE:
39283 irqwait->request.sequence +=
39284- atomic_read(&cur_irq->irq_received);
39285+ atomic_read_unchecked(&cur_irq->irq_received);
39286 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
39287 case VIA_IRQ_ABSOLUTE:
39288 break;
39289diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
39290index 13aeda7..4a952d1 100644
39291--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
39292+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
39293@@ -290,7 +290,7 @@ struct vmw_private {
39294 * Fencing and IRQs.
39295 */
39296
39297- atomic_t marker_seq;
39298+ atomic_unchecked_t marker_seq;
39299 wait_queue_head_t fence_queue;
39300 wait_queue_head_t fifo_queue;
39301 int fence_queue_waiters; /* Protected by hw_mutex */
39302diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
39303index 3eb1486..0a47ee9 100644
39304--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
39305+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
39306@@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
39307 (unsigned int) min,
39308 (unsigned int) fifo->capabilities);
39309
39310- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
39311+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
39312 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
39313 vmw_marker_queue_init(&fifo->marker_queue);
39314 return vmw_fifo_send_fence(dev_priv, &dummy);
39315@@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
39316 if (reserveable)
39317 iowrite32(bytes, fifo_mem +
39318 SVGA_FIFO_RESERVED);
39319- return fifo_mem + (next_cmd >> 2);
39320+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
39321 } else {
39322 need_bounce = true;
39323 }
39324@@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
39325
39326 fm = vmw_fifo_reserve(dev_priv, bytes);
39327 if (unlikely(fm == NULL)) {
39328- *seqno = atomic_read(&dev_priv->marker_seq);
39329+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
39330 ret = -ENOMEM;
39331 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
39332 false, 3*HZ);
39333@@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
39334 }
39335
39336 do {
39337- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
39338+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
39339 } while (*seqno == 0);
39340
39341 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
39342diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
39343index c509d40..3b640c3 100644
39344--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
39345+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
39346@@ -138,7 +138,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
39347 int ret;
39348
39349 num_clips = arg->num_clips;
39350- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
39351+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
39352
39353 if (unlikely(num_clips == 0))
39354 return 0;
39355@@ -222,7 +222,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
39356 int ret;
39357
39358 num_clips = arg->num_clips;
39359- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
39360+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
39361
39362 if (unlikely(num_clips == 0))
39363 return 0;
39364diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
39365index 4640adb..e1384ed 100644
39366--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
39367+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
39368@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
39369 * emitted. Then the fence is stale and signaled.
39370 */
39371
39372- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
39373+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
39374 > VMW_FENCE_WRAP);
39375
39376 return ret;
39377@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
39378
39379 if (fifo_idle)
39380 down_read(&fifo_state->rwsem);
39381- signal_seq = atomic_read(&dev_priv->marker_seq);
39382+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
39383 ret = 0;
39384
39385 for (;;) {
39386diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
39387index 8a8725c2..afed796 100644
39388--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
39389+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
39390@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
39391 while (!vmw_lag_lt(queue, us)) {
39392 spin_lock(&queue->lock);
39393 if (list_empty(&queue->head))
39394- seqno = atomic_read(&dev_priv->marker_seq);
39395+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
39396 else {
39397 marker = list_first_entry(&queue->head,
39398 struct vmw_marker, head);
39399diff --git a/drivers/gpu/host1x/drm/dc.c b/drivers/gpu/host1x/drm/dc.c
39400index 5360e5a..c2c0d26 100644
39401--- a/drivers/gpu/host1x/drm/dc.c
39402+++ b/drivers/gpu/host1x/drm/dc.c
39403@@ -1004,7 +1004,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
39404 }
39405
39406 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
39407- dc->debugfs_files[i].data = dc;
39408+ *(void **)&dc->debugfs_files[i].data = dc;
39409
39410 err = drm_debugfs_create_files(dc->debugfs_files,
39411 ARRAY_SIZE(debugfs_files),
39412diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
39413index ee75486..65621fd 100644
39414--- a/drivers/hid/hid-core.c
39415+++ b/drivers/hid/hid-core.c
39416@@ -2351,7 +2351,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
39417
39418 int hid_add_device(struct hid_device *hdev)
39419 {
39420- static atomic_t id = ATOMIC_INIT(0);
39421+ static atomic_unchecked_t id = ATOMIC_INIT(0);
39422 int ret;
39423
39424 if (WARN_ON(hdev->status & HID_STAT_ADDED))
39425@@ -2385,7 +2385,7 @@ int hid_add_device(struct hid_device *hdev)
39426 /* XXX hack, any other cleaner solution after the driver core
39427 * is converted to allow more than 20 bytes as the device name? */
39428 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
39429- hdev->vendor, hdev->product, atomic_inc_return(&id));
39430+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
39431
39432 hid_debug_register(hdev, dev_name(&hdev->dev));
39433 ret = device_add(&hdev->dev);
39434diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
39435index c13fb5b..55a3802 100644
39436--- a/drivers/hid/hid-wiimote-debug.c
39437+++ b/drivers/hid/hid-wiimote-debug.c
39438@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
39439 else if (size == 0)
39440 return -EIO;
39441
39442- if (copy_to_user(u, buf, size))
39443+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
39444 return -EFAULT;
39445
39446 *off += size;
39447diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
39448index fc307e0..2b255e8 100644
39449--- a/drivers/hid/uhid.c
39450+++ b/drivers/hid/uhid.c
39451@@ -47,7 +47,7 @@ struct uhid_device {
39452 struct mutex report_lock;
39453 wait_queue_head_t report_wait;
39454 atomic_t report_done;
39455- atomic_t report_id;
39456+ atomic_unchecked_t report_id;
39457 struct uhid_event report_buf;
39458 };
39459
39460@@ -187,7 +187,7 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum,
39461
39462 spin_lock_irqsave(&uhid->qlock, flags);
39463 ev->type = UHID_FEATURE;
39464- ev->u.feature.id = atomic_inc_return(&uhid->report_id);
39465+ ev->u.feature.id = atomic_inc_return_unchecked(&uhid->report_id);
39466 ev->u.feature.rnum = rnum;
39467 ev->u.feature.rtype = report_type;
39468
39469@@ -471,7 +471,7 @@ static int uhid_dev_feature_answer(struct uhid_device *uhid,
39470 spin_lock_irqsave(&uhid->qlock, flags);
39471
39472 /* id for old report; drop it silently */
39473- if (atomic_read(&uhid->report_id) != ev->u.feature_answer.id)
39474+ if (atomic_read_unchecked(&uhid->report_id) != ev->u.feature_answer.id)
39475 goto unlock;
39476 if (atomic_read(&uhid->report_done))
39477 goto unlock;
39478diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
39479index 6de6c98..18319e9 100644
39480--- a/drivers/hv/channel.c
39481+++ b/drivers/hv/channel.c
39482@@ -406,8 +406,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
39483 int ret = 0;
39484 int t;
39485
39486- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
39487- atomic_inc(&vmbus_connection.next_gpadl_handle);
39488+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
39489+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
39490
39491 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
39492 if (ret)
39493diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
39494index 88f4096..e50452e 100644
39495--- a/drivers/hv/hv.c
39496+++ b/drivers/hv/hv.c
39497@@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
39498 u64 output_address = (output) ? virt_to_phys(output) : 0;
39499 u32 output_address_hi = output_address >> 32;
39500 u32 output_address_lo = output_address & 0xFFFFFFFF;
39501- void *hypercall_page = hv_context.hypercall_page;
39502+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
39503
39504 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
39505 "=a"(hv_status_lo) : "d" (control_hi),
39506diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
39507index deb5c25..ed2d4fd 100644
39508--- a/drivers/hv/hv_balloon.c
39509+++ b/drivers/hv/hv_balloon.c
39510@@ -464,7 +464,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
39511
39512 module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
39513 MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
39514-static atomic_t trans_id = ATOMIC_INIT(0);
39515+static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
39516
39517 static int dm_ring_size = (5 * PAGE_SIZE);
39518
39519@@ -825,7 +825,7 @@ static void hot_add_req(struct work_struct *dummy)
39520 memset(&resp, 0, sizeof(struct dm_hot_add_response));
39521 resp.hdr.type = DM_MEM_HOT_ADD_RESPONSE;
39522 resp.hdr.size = sizeof(struct dm_hot_add_response);
39523- resp.hdr.trans_id = atomic_inc_return(&trans_id);
39524+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
39525
39526 #ifdef CONFIG_MEMORY_HOTPLUG
39527 pg_start = dm->ha_wrk.ha_page_range.finfo.start_page;
39528@@ -960,7 +960,7 @@ static void post_status(struct hv_dynmem_device *dm)
39529 memset(&status, 0, sizeof(struct dm_status));
39530 status.hdr.type = DM_STATUS_REPORT;
39531 status.hdr.size = sizeof(struct dm_status);
39532- status.hdr.trans_id = atomic_inc_return(&trans_id);
39533+ status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
39534
39535 /*
39536 * The host expects the guest to report free memory.
39537@@ -980,7 +980,7 @@ static void post_status(struct hv_dynmem_device *dm)
39538 * send the status. This can happen if we were interrupted
39539 * after we picked our transaction ID.
39540 */
39541- if (status.hdr.trans_id != atomic_read(&trans_id))
39542+ if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
39543 return;
39544
39545 vmbus_sendpacket(dm->dev->channel, &status,
39546@@ -1081,7 +1081,7 @@ static void balloon_up(struct work_struct *dummy)
39547 bl_resp = (struct dm_balloon_response *)send_buffer;
39548 memset(send_buffer, 0, PAGE_SIZE);
39549 bl_resp->hdr.type = DM_BALLOON_RESPONSE;
39550- bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
39551+ bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
39552 bl_resp->hdr.size = sizeof(struct dm_balloon_response);
39553 bl_resp->more_pages = 1;
39554
39555@@ -1152,7 +1152,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
39556
39557 memset(&resp, 0, sizeof(struct dm_unballoon_response));
39558 resp.hdr.type = DM_UNBALLOON_RESPONSE;
39559- resp.hdr.trans_id = atomic_inc_return(&trans_id);
39560+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
39561 resp.hdr.size = sizeof(struct dm_unballoon_response);
39562
39563 vmbus_sendpacket(dm_device.dev->channel, &resp,
39564@@ -1215,7 +1215,7 @@ static void version_resp(struct hv_dynmem_device *dm,
39565 memset(&version_req, 0, sizeof(struct dm_version_request));
39566 version_req.hdr.type = DM_VERSION_REQUEST;
39567 version_req.hdr.size = sizeof(struct dm_version_request);
39568- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
39569+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
39570 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
39571 version_req.is_last_attempt = 1;
39572
39573@@ -1385,7 +1385,7 @@ static int balloon_probe(struct hv_device *dev,
39574 memset(&version_req, 0, sizeof(struct dm_version_request));
39575 version_req.hdr.type = DM_VERSION_REQUEST;
39576 version_req.hdr.size = sizeof(struct dm_version_request);
39577- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
39578+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
39579 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
39580 version_req.is_last_attempt = 0;
39581
39582@@ -1416,7 +1416,7 @@ static int balloon_probe(struct hv_device *dev,
39583 memset(&cap_msg, 0, sizeof(struct dm_capabilities));
39584 cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
39585 cap_msg.hdr.size = sizeof(struct dm_capabilities);
39586- cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
39587+ cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
39588
39589 cap_msg.caps.cap_bits.balloon = 1;
39590 cap_msg.caps.cap_bits.hot_add = 1;
39591diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
39592index d84918f..7f38f9f 100644
39593--- a/drivers/hv/hyperv_vmbus.h
39594+++ b/drivers/hv/hyperv_vmbus.h
39595@@ -595,7 +595,7 @@ enum vmbus_connect_state {
39596 struct vmbus_connection {
39597 enum vmbus_connect_state conn_state;
39598
39599- atomic_t next_gpadl_handle;
39600+ atomic_unchecked_t next_gpadl_handle;
39601
39602 /*
39603 * Represents channel interrupts. Each bit position represents a
39604diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
39605index e8e071f..5b4b245 100644
39606--- a/drivers/hv/vmbus_drv.c
39607+++ b/drivers/hv/vmbus_drv.c
39608@@ -672,10 +672,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
39609 {
39610 int ret = 0;
39611
39612- static atomic_t device_num = ATOMIC_INIT(0);
39613+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
39614
39615 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
39616- atomic_inc_return(&device_num));
39617+ atomic_inc_return_unchecked(&device_num));
39618
39619 child_device_obj->device.bus = &hv_bus;
39620 child_device_obj->device.parent = &hv_acpi_dev->dev;
39621diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
39622index 6351aba..dc4aaf4 100644
39623--- a/drivers/hwmon/acpi_power_meter.c
39624+++ b/drivers/hwmon/acpi_power_meter.c
39625@@ -117,7 +117,7 @@ struct sensor_template {
39626 struct device_attribute *devattr,
39627 const char *buf, size_t count);
39628 int index;
39629-};
39630+} __do_const;
39631
39632 /* Averaging interval */
39633 static int update_avg_interval(struct acpi_power_meter_resource *resource)
39634@@ -629,7 +629,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
39635 struct sensor_template *attrs)
39636 {
39637 struct device *dev = &resource->acpi_dev->dev;
39638- struct sensor_device_attribute *sensors =
39639+ sensor_device_attribute_no_const *sensors =
39640 &resource->sensors[resource->num_sensors];
39641 int res = 0;
39642
39643diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
39644index 62c2e32..8f2859a 100644
39645--- a/drivers/hwmon/applesmc.c
39646+++ b/drivers/hwmon/applesmc.c
39647@@ -1084,7 +1084,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
39648 {
39649 struct applesmc_node_group *grp;
39650 struct applesmc_dev_attr *node;
39651- struct attribute *attr;
39652+ attribute_no_const *attr;
39653 int ret, i;
39654
39655 for (grp = groups; grp->format; grp++) {
39656diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
39657index b25c643..a13460d 100644
39658--- a/drivers/hwmon/asus_atk0110.c
39659+++ b/drivers/hwmon/asus_atk0110.c
39660@@ -152,10 +152,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
39661 struct atk_sensor_data {
39662 struct list_head list;
39663 struct atk_data *data;
39664- struct device_attribute label_attr;
39665- struct device_attribute input_attr;
39666- struct device_attribute limit1_attr;
39667- struct device_attribute limit2_attr;
39668+ device_attribute_no_const label_attr;
39669+ device_attribute_no_const input_attr;
39670+ device_attribute_no_const limit1_attr;
39671+ device_attribute_no_const limit2_attr;
39672 char label_attr_name[ATTR_NAME_SIZE];
39673 char input_attr_name[ATTR_NAME_SIZE];
39674 char limit1_attr_name[ATTR_NAME_SIZE];
39675@@ -275,7 +275,7 @@ static ssize_t atk_name_show(struct device *dev,
39676 static struct device_attribute atk_name_attr =
39677 __ATTR(name, 0444, atk_name_show, NULL);
39678
39679-static void atk_init_attribute(struct device_attribute *attr, char *name,
39680+static void atk_init_attribute(device_attribute_no_const *attr, char *name,
39681 sysfs_show_func show)
39682 {
39683 sysfs_attr_init(&attr->attr);
39684diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
39685index 2e5e2dc..5208b31 100644
39686--- a/drivers/hwmon/coretemp.c
39687+++ b/drivers/hwmon/coretemp.c
39688@@ -785,7 +785,7 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
39689 return NOTIFY_OK;
39690 }
39691
39692-static struct notifier_block coretemp_cpu_notifier __refdata = {
39693+static struct notifier_block coretemp_cpu_notifier = {
39694 .notifier_call = coretemp_cpu_callback,
39695 };
39696
39697diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
39698index 1429f6e..ee03d59 100644
39699--- a/drivers/hwmon/ibmaem.c
39700+++ b/drivers/hwmon/ibmaem.c
39701@@ -926,7 +926,7 @@ static int aem_register_sensors(struct aem_data *data,
39702 struct aem_rw_sensor_template *rw)
39703 {
39704 struct device *dev = &data->pdev->dev;
39705- struct sensor_device_attribute *sensors = data->sensors;
39706+ sensor_device_attribute_no_const *sensors = data->sensors;
39707 int err;
39708
39709 /* Set up read-only sensors */
39710diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
39711index 708081b..fe2d4ab 100644
39712--- a/drivers/hwmon/iio_hwmon.c
39713+++ b/drivers/hwmon/iio_hwmon.c
39714@@ -73,7 +73,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
39715 {
39716 struct device *dev = &pdev->dev;
39717 struct iio_hwmon_state *st;
39718- struct sensor_device_attribute *a;
39719+ sensor_device_attribute_no_const *a;
39720 int ret, i;
39721 int in_i = 1, temp_i = 1, curr_i = 1;
39722 enum iio_chan_type type;
39723diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
39724index 9add6092..ee7ba3f 100644
39725--- a/drivers/hwmon/pmbus/pmbus_core.c
39726+++ b/drivers/hwmon/pmbus/pmbus_core.c
39727@@ -781,7 +781,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
39728 return 0;
39729 }
39730
39731-static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
39732+static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
39733 const char *name,
39734 umode_t mode,
39735 ssize_t (*show)(struct device *dev,
39736@@ -798,7 +798,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
39737 dev_attr->store = store;
39738 }
39739
39740-static void pmbus_attr_init(struct sensor_device_attribute *a,
39741+static void pmbus_attr_init(sensor_device_attribute_no_const *a,
39742 const char *name,
39743 umode_t mode,
39744 ssize_t (*show)(struct device *dev,
39745@@ -820,7 +820,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
39746 u16 reg, u8 mask)
39747 {
39748 struct pmbus_boolean *boolean;
39749- struct sensor_device_attribute *a;
39750+ sensor_device_attribute_no_const *a;
39751
39752 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
39753 if (!boolean)
39754@@ -845,7 +845,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
39755 bool update, bool readonly)
39756 {
39757 struct pmbus_sensor *sensor;
39758- struct device_attribute *a;
39759+ device_attribute_no_const *a;
39760
39761 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
39762 if (!sensor)
39763@@ -876,7 +876,7 @@ static int pmbus_add_label(struct pmbus_data *data,
39764 const char *lstring, int index)
39765 {
39766 struct pmbus_label *label;
39767- struct device_attribute *a;
39768+ device_attribute_no_const *a;
39769
39770 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
39771 if (!label)
39772diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
39773index 2507f90..1645765 100644
39774--- a/drivers/hwmon/sht15.c
39775+++ b/drivers/hwmon/sht15.c
39776@@ -169,7 +169,7 @@ struct sht15_data {
39777 int supply_uv;
39778 bool supply_uv_valid;
39779 struct work_struct update_supply_work;
39780- atomic_t interrupt_handled;
39781+ atomic_unchecked_t interrupt_handled;
39782 };
39783
39784 /**
39785@@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
39786 ret = gpio_direction_input(data->pdata->gpio_data);
39787 if (ret)
39788 return ret;
39789- atomic_set(&data->interrupt_handled, 0);
39790+ atomic_set_unchecked(&data->interrupt_handled, 0);
39791
39792 enable_irq(gpio_to_irq(data->pdata->gpio_data));
39793 if (gpio_get_value(data->pdata->gpio_data) == 0) {
39794 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
39795 /* Only relevant if the interrupt hasn't occurred. */
39796- if (!atomic_read(&data->interrupt_handled))
39797+ if (!atomic_read_unchecked(&data->interrupt_handled))
39798 schedule_work(&data->read_work);
39799 }
39800 ret = wait_event_timeout(data->wait_queue,
39801@@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
39802
39803 /* First disable the interrupt */
39804 disable_irq_nosync(irq);
39805- atomic_inc(&data->interrupt_handled);
39806+ atomic_inc_unchecked(&data->interrupt_handled);
39807 /* Then schedule a reading work struct */
39808 if (data->state != SHT15_READING_NOTHING)
39809 schedule_work(&data->read_work);
39810@@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
39811 * If not, then start the interrupt again - care here as could
39812 * have gone low in meantime so verify it hasn't!
39813 */
39814- atomic_set(&data->interrupt_handled, 0);
39815+ atomic_set_unchecked(&data->interrupt_handled, 0);
39816 enable_irq(gpio_to_irq(data->pdata->gpio_data));
39817 /* If still not occurred or another handler was scheduled */
39818 if (gpio_get_value(data->pdata->gpio_data)
39819- || atomic_read(&data->interrupt_handled))
39820+ || atomic_read_unchecked(&data->interrupt_handled))
39821 return;
39822 }
39823
39824diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
39825index 38944e9..ae9e5ed 100644
39826--- a/drivers/hwmon/via-cputemp.c
39827+++ b/drivers/hwmon/via-cputemp.c
39828@@ -296,7 +296,7 @@ static int via_cputemp_cpu_callback(struct notifier_block *nfb,
39829 return NOTIFY_OK;
39830 }
39831
39832-static struct notifier_block via_cputemp_cpu_notifier __refdata = {
39833+static struct notifier_block via_cputemp_cpu_notifier = {
39834 .notifier_call = via_cputemp_cpu_callback,
39835 };
39836
39837diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
39838index 07f01ac..d79ad3d 100644
39839--- a/drivers/i2c/busses/i2c-amd756-s4882.c
39840+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
39841@@ -43,7 +43,7 @@
39842 extern struct i2c_adapter amd756_smbus;
39843
39844 static struct i2c_adapter *s4882_adapter;
39845-static struct i2c_algorithm *s4882_algo;
39846+static i2c_algorithm_no_const *s4882_algo;
39847
39848 /* Wrapper access functions for multiplexed SMBus */
39849 static DEFINE_MUTEX(amd756_lock);
39850diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
39851index 2ca268d..c6acbdf 100644
39852--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
39853+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
39854@@ -41,7 +41,7 @@
39855 extern struct i2c_adapter *nforce2_smbus;
39856
39857 static struct i2c_adapter *s4985_adapter;
39858-static struct i2c_algorithm *s4985_algo;
39859+static i2c_algorithm_no_const *s4985_algo;
39860
39861 /* Wrapper access functions for multiplexed SMBus */
39862 static DEFINE_MUTEX(nforce2_lock);
39863diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
39864index c3ccdea..5b3dc1a 100644
39865--- a/drivers/i2c/i2c-dev.c
39866+++ b/drivers/i2c/i2c-dev.c
39867@@ -271,7 +271,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
39868 break;
39869 }
39870
39871- data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
39872+ data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
39873 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
39874 if (IS_ERR(rdwr_pa[i].buf)) {
39875 res = PTR_ERR(rdwr_pa[i].buf);
39876diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
39877index 0b510ba..4fbb5085 100644
39878--- a/drivers/ide/ide-cd.c
39879+++ b/drivers/ide/ide-cd.c
39880@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
39881 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
39882 if ((unsigned long)buf & alignment
39883 || blk_rq_bytes(rq) & q->dma_pad_mask
39884- || object_is_on_stack(buf))
39885+ || object_starts_on_stack(buf))
39886 drive->dma = 0;
39887 }
39888 }
39889diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
39890index e145931..08bfc59 100644
39891--- a/drivers/iio/industrialio-core.c
39892+++ b/drivers/iio/industrialio-core.c
39893@@ -506,7 +506,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
39894 }
39895
39896 static
39897-int __iio_device_attr_init(struct device_attribute *dev_attr,
39898+int __iio_device_attr_init(device_attribute_no_const *dev_attr,
39899 const char *postfix,
39900 struct iio_chan_spec const *chan,
39901 ssize_t (*readfunc)(struct device *dev,
39902diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
39903index 784b97c..c9ceadf 100644
39904--- a/drivers/infiniband/core/cm.c
39905+++ b/drivers/infiniband/core/cm.c
39906@@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
39907
39908 struct cm_counter_group {
39909 struct kobject obj;
39910- atomic_long_t counter[CM_ATTR_COUNT];
39911+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
39912 };
39913
39914 struct cm_counter_attribute {
39915@@ -1395,7 +1395,7 @@ static void cm_dup_req_handler(struct cm_work *work,
39916 struct ib_mad_send_buf *msg = NULL;
39917 int ret;
39918
39919- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
39920+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
39921 counter[CM_REQ_COUNTER]);
39922
39923 /* Quick state check to discard duplicate REQs. */
39924@@ -1779,7 +1779,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
39925 if (!cm_id_priv)
39926 return;
39927
39928- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
39929+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
39930 counter[CM_REP_COUNTER]);
39931 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
39932 if (ret)
39933@@ -1946,7 +1946,7 @@ static int cm_rtu_handler(struct cm_work *work)
39934 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
39935 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
39936 spin_unlock_irq(&cm_id_priv->lock);
39937- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
39938+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
39939 counter[CM_RTU_COUNTER]);
39940 goto out;
39941 }
39942@@ -2129,7 +2129,7 @@ static int cm_dreq_handler(struct cm_work *work)
39943 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
39944 dreq_msg->local_comm_id);
39945 if (!cm_id_priv) {
39946- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
39947+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
39948 counter[CM_DREQ_COUNTER]);
39949 cm_issue_drep(work->port, work->mad_recv_wc);
39950 return -EINVAL;
39951@@ -2154,7 +2154,7 @@ static int cm_dreq_handler(struct cm_work *work)
39952 case IB_CM_MRA_REP_RCVD:
39953 break;
39954 case IB_CM_TIMEWAIT:
39955- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
39956+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
39957 counter[CM_DREQ_COUNTER]);
39958 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
39959 goto unlock;
39960@@ -2168,7 +2168,7 @@ static int cm_dreq_handler(struct cm_work *work)
39961 cm_free_msg(msg);
39962 goto deref;
39963 case IB_CM_DREQ_RCVD:
39964- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
39965+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
39966 counter[CM_DREQ_COUNTER]);
39967 goto unlock;
39968 default:
39969@@ -2535,7 +2535,7 @@ static int cm_mra_handler(struct cm_work *work)
39970 ib_modify_mad(cm_id_priv->av.port->mad_agent,
39971 cm_id_priv->msg, timeout)) {
39972 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
39973- atomic_long_inc(&work->port->
39974+ atomic_long_inc_unchecked(&work->port->
39975 counter_group[CM_RECV_DUPLICATES].
39976 counter[CM_MRA_COUNTER]);
39977 goto out;
39978@@ -2544,7 +2544,7 @@ static int cm_mra_handler(struct cm_work *work)
39979 break;
39980 case IB_CM_MRA_REQ_RCVD:
39981 case IB_CM_MRA_REP_RCVD:
39982- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
39983+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
39984 counter[CM_MRA_COUNTER]);
39985 /* fall through */
39986 default:
39987@@ -2706,7 +2706,7 @@ static int cm_lap_handler(struct cm_work *work)
39988 case IB_CM_LAP_IDLE:
39989 break;
39990 case IB_CM_MRA_LAP_SENT:
39991- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
39992+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
39993 counter[CM_LAP_COUNTER]);
39994 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
39995 goto unlock;
39996@@ -2722,7 +2722,7 @@ static int cm_lap_handler(struct cm_work *work)
39997 cm_free_msg(msg);
39998 goto deref;
39999 case IB_CM_LAP_RCVD:
40000- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40001+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40002 counter[CM_LAP_COUNTER]);
40003 goto unlock;
40004 default:
40005@@ -3006,7 +3006,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
40006 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
40007 if (cur_cm_id_priv) {
40008 spin_unlock_irq(&cm.lock);
40009- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40010+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40011 counter[CM_SIDR_REQ_COUNTER]);
40012 goto out; /* Duplicate message. */
40013 }
40014@@ -3218,10 +3218,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
40015 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
40016 msg->retries = 1;
40017
40018- atomic_long_add(1 + msg->retries,
40019+ atomic_long_add_unchecked(1 + msg->retries,
40020 &port->counter_group[CM_XMIT].counter[attr_index]);
40021 if (msg->retries)
40022- atomic_long_add(msg->retries,
40023+ atomic_long_add_unchecked(msg->retries,
40024 &port->counter_group[CM_XMIT_RETRIES].
40025 counter[attr_index]);
40026
40027@@ -3431,7 +3431,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
40028 }
40029
40030 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
40031- atomic_long_inc(&port->counter_group[CM_RECV].
40032+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
40033 counter[attr_id - CM_ATTR_ID_OFFSET]);
40034
40035 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
40036@@ -3636,7 +3636,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
40037 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
40038
40039 return sprintf(buf, "%ld\n",
40040- atomic_long_read(&group->counter[cm_attr->index]));
40041+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
40042 }
40043
40044 static const struct sysfs_ops cm_counter_ops = {
40045diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
40046index 9f5ad7c..588cd84 100644
40047--- a/drivers/infiniband/core/fmr_pool.c
40048+++ b/drivers/infiniband/core/fmr_pool.c
40049@@ -98,8 +98,8 @@ struct ib_fmr_pool {
40050
40051 struct task_struct *thread;
40052
40053- atomic_t req_ser;
40054- atomic_t flush_ser;
40055+ atomic_unchecked_t req_ser;
40056+ atomic_unchecked_t flush_ser;
40057
40058 wait_queue_head_t force_wait;
40059 };
40060@@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
40061 struct ib_fmr_pool *pool = pool_ptr;
40062
40063 do {
40064- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
40065+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
40066 ib_fmr_batch_release(pool);
40067
40068- atomic_inc(&pool->flush_ser);
40069+ atomic_inc_unchecked(&pool->flush_ser);
40070 wake_up_interruptible(&pool->force_wait);
40071
40072 if (pool->flush_function)
40073@@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
40074 }
40075
40076 set_current_state(TASK_INTERRUPTIBLE);
40077- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
40078+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
40079 !kthread_should_stop())
40080 schedule();
40081 __set_current_state(TASK_RUNNING);
40082@@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
40083 pool->dirty_watermark = params->dirty_watermark;
40084 pool->dirty_len = 0;
40085 spin_lock_init(&pool->pool_lock);
40086- atomic_set(&pool->req_ser, 0);
40087- atomic_set(&pool->flush_ser, 0);
40088+ atomic_set_unchecked(&pool->req_ser, 0);
40089+ atomic_set_unchecked(&pool->flush_ser, 0);
40090 init_waitqueue_head(&pool->force_wait);
40091
40092 pool->thread = kthread_run(ib_fmr_cleanup_thread,
40093@@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
40094 }
40095 spin_unlock_irq(&pool->pool_lock);
40096
40097- serial = atomic_inc_return(&pool->req_ser);
40098+ serial = atomic_inc_return_unchecked(&pool->req_ser);
40099 wake_up_process(pool->thread);
40100
40101 if (wait_event_interruptible(pool->force_wait,
40102- atomic_read(&pool->flush_ser) - serial >= 0))
40103+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
40104 return -EINTR;
40105
40106 return 0;
40107@@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
40108 } else {
40109 list_add_tail(&fmr->list, &pool->dirty_list);
40110 if (++pool->dirty_len >= pool->dirty_watermark) {
40111- atomic_inc(&pool->req_ser);
40112+ atomic_inc_unchecked(&pool->req_ser);
40113 wake_up_process(pool->thread);
40114 }
40115 }
40116diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
40117index 4cb8eb2..146bf60 100644
40118--- a/drivers/infiniband/hw/cxgb4/mem.c
40119+++ b/drivers/infiniband/hw/cxgb4/mem.c
40120@@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
40121 int err;
40122 struct fw_ri_tpte tpt;
40123 u32 stag_idx;
40124- static atomic_t key;
40125+ static atomic_unchecked_t key;
40126
40127 if (c4iw_fatal_error(rdev))
40128 return -EIO;
40129@@ -266,7 +266,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
40130 if (rdev->stats.stag.cur > rdev->stats.stag.max)
40131 rdev->stats.stag.max = rdev->stats.stag.cur;
40132 mutex_unlock(&rdev->stats.lock);
40133- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
40134+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
40135 }
40136 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
40137 __func__, stag_state, type, pdid, stag_idx);
40138diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
40139index 79b3dbc..96e5fcc 100644
40140--- a/drivers/infiniband/hw/ipath/ipath_rc.c
40141+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
40142@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
40143 struct ib_atomic_eth *ateth;
40144 struct ipath_ack_entry *e;
40145 u64 vaddr;
40146- atomic64_t *maddr;
40147+ atomic64_unchecked_t *maddr;
40148 u64 sdata;
40149 u32 rkey;
40150 u8 next;
40151@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
40152 IB_ACCESS_REMOTE_ATOMIC)))
40153 goto nack_acc_unlck;
40154 /* Perform atomic OP and save result. */
40155- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
40156+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
40157 sdata = be64_to_cpu(ateth->swap_data);
40158 e = &qp->s_ack_queue[qp->r_head_ack_queue];
40159 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
40160- (u64) atomic64_add_return(sdata, maddr) - sdata :
40161+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
40162 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
40163 be64_to_cpu(ateth->compare_data),
40164 sdata);
40165diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
40166index 1f95bba..9530f87 100644
40167--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
40168+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
40169@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
40170 unsigned long flags;
40171 struct ib_wc wc;
40172 u64 sdata;
40173- atomic64_t *maddr;
40174+ atomic64_unchecked_t *maddr;
40175 enum ib_wc_status send_status;
40176
40177 /*
40178@@ -382,11 +382,11 @@ again:
40179 IB_ACCESS_REMOTE_ATOMIC)))
40180 goto acc_err;
40181 /* Perform atomic OP and save result. */
40182- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
40183+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
40184 sdata = wqe->wr.wr.atomic.compare_add;
40185 *(u64 *) sqp->s_sge.sge.vaddr =
40186 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
40187- (u64) atomic64_add_return(sdata, maddr) - sdata :
40188+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
40189 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
40190 sdata, wqe->wr.wr.atomic.swap);
40191 goto send_comp;
40192diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
40193index f2a3f48..673ec79 100644
40194--- a/drivers/infiniband/hw/mlx4/mad.c
40195+++ b/drivers/infiniband/hw/mlx4/mad.c
40196@@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
40197
40198 __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
40199 {
40200- return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
40201+ return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
40202 cpu_to_be64(0xff00000000000000LL);
40203 }
40204
40205diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
40206index 25b2cdf..099ff97 100644
40207--- a/drivers/infiniband/hw/mlx4/mcg.c
40208+++ b/drivers/infiniband/hw/mlx4/mcg.c
40209@@ -1040,7 +1040,7 @@ int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
40210 {
40211 char name[20];
40212
40213- atomic_set(&ctx->tid, 0);
40214+ atomic_set_unchecked(&ctx->tid, 0);
40215 sprintf(name, "mlx4_ib_mcg%d", ctx->port);
40216 ctx->mcg_wq = create_singlethread_workqueue(name);
40217 if (!ctx->mcg_wq)
40218diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
40219index f61ec26..ebf72cf 100644
40220--- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
40221+++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
40222@@ -398,7 +398,7 @@ struct mlx4_ib_demux_ctx {
40223 struct list_head mcg_mgid0_list;
40224 struct workqueue_struct *mcg_wq;
40225 struct mlx4_ib_demux_pv_ctx **tun;
40226- atomic_t tid;
40227+ atomic_unchecked_t tid;
40228 int flushing; /* flushing the work queue */
40229 };
40230
40231diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
40232index 9d3e5c1..d9afe4a 100644
40233--- a/drivers/infiniband/hw/mthca/mthca_cmd.c
40234+++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
40235@@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
40236 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
40237 }
40238
40239-int mthca_QUERY_FW(struct mthca_dev *dev)
40240+int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
40241 {
40242 struct mthca_mailbox *mailbox;
40243 u32 *outbox;
40244diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
40245index ed9a989..e0c5871 100644
40246--- a/drivers/infiniband/hw/mthca/mthca_mr.c
40247+++ b/drivers/infiniband/hw/mthca/mthca_mr.c
40248@@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
40249 return key;
40250 }
40251
40252-int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
40253+int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
40254 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
40255 {
40256 struct mthca_mailbox *mailbox;
40257diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
40258index 4291410..d2ab1fb 100644
40259--- a/drivers/infiniband/hw/nes/nes.c
40260+++ b/drivers/infiniband/hw/nes/nes.c
40261@@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
40262 LIST_HEAD(nes_adapter_list);
40263 static LIST_HEAD(nes_dev_list);
40264
40265-atomic_t qps_destroyed;
40266+atomic_unchecked_t qps_destroyed;
40267
40268 static unsigned int ee_flsh_adapter;
40269 static unsigned int sysfs_nonidx_addr;
40270@@ -269,7 +269,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
40271 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
40272 struct nes_adapter *nesadapter = nesdev->nesadapter;
40273
40274- atomic_inc(&qps_destroyed);
40275+ atomic_inc_unchecked(&qps_destroyed);
40276
40277 /* Free the control structures */
40278
40279diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
40280index 33cc589..3bd6538 100644
40281--- a/drivers/infiniband/hw/nes/nes.h
40282+++ b/drivers/infiniband/hw/nes/nes.h
40283@@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
40284 extern unsigned int wqm_quanta;
40285 extern struct list_head nes_adapter_list;
40286
40287-extern atomic_t cm_connects;
40288-extern atomic_t cm_accepts;
40289-extern atomic_t cm_disconnects;
40290-extern atomic_t cm_closes;
40291-extern atomic_t cm_connecteds;
40292-extern atomic_t cm_connect_reqs;
40293-extern atomic_t cm_rejects;
40294-extern atomic_t mod_qp_timouts;
40295-extern atomic_t qps_created;
40296-extern atomic_t qps_destroyed;
40297-extern atomic_t sw_qps_destroyed;
40298+extern atomic_unchecked_t cm_connects;
40299+extern atomic_unchecked_t cm_accepts;
40300+extern atomic_unchecked_t cm_disconnects;
40301+extern atomic_unchecked_t cm_closes;
40302+extern atomic_unchecked_t cm_connecteds;
40303+extern atomic_unchecked_t cm_connect_reqs;
40304+extern atomic_unchecked_t cm_rejects;
40305+extern atomic_unchecked_t mod_qp_timouts;
40306+extern atomic_unchecked_t qps_created;
40307+extern atomic_unchecked_t qps_destroyed;
40308+extern atomic_unchecked_t sw_qps_destroyed;
40309 extern u32 mh_detected;
40310 extern u32 mh_pauses_sent;
40311 extern u32 cm_packets_sent;
40312@@ -196,16 +196,16 @@ extern u32 cm_packets_created;
40313 extern u32 cm_packets_received;
40314 extern u32 cm_packets_dropped;
40315 extern u32 cm_packets_retrans;
40316-extern atomic_t cm_listens_created;
40317-extern atomic_t cm_listens_destroyed;
40318+extern atomic_unchecked_t cm_listens_created;
40319+extern atomic_unchecked_t cm_listens_destroyed;
40320 extern u32 cm_backlog_drops;
40321-extern atomic_t cm_loopbacks;
40322-extern atomic_t cm_nodes_created;
40323-extern atomic_t cm_nodes_destroyed;
40324-extern atomic_t cm_accel_dropped_pkts;
40325-extern atomic_t cm_resets_recvd;
40326-extern atomic_t pau_qps_created;
40327-extern atomic_t pau_qps_destroyed;
40328+extern atomic_unchecked_t cm_loopbacks;
40329+extern atomic_unchecked_t cm_nodes_created;
40330+extern atomic_unchecked_t cm_nodes_destroyed;
40331+extern atomic_unchecked_t cm_accel_dropped_pkts;
40332+extern atomic_unchecked_t cm_resets_recvd;
40333+extern atomic_unchecked_t pau_qps_created;
40334+extern atomic_unchecked_t pau_qps_destroyed;
40335
40336 extern u32 int_mod_timer_init;
40337 extern u32 int_mod_cq_depth_256;
40338diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
40339index 24b9f1a..00fd004 100644
40340--- a/drivers/infiniband/hw/nes/nes_cm.c
40341+++ b/drivers/infiniband/hw/nes/nes_cm.c
40342@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
40343 u32 cm_packets_retrans;
40344 u32 cm_packets_created;
40345 u32 cm_packets_received;
40346-atomic_t cm_listens_created;
40347-atomic_t cm_listens_destroyed;
40348+atomic_unchecked_t cm_listens_created;
40349+atomic_unchecked_t cm_listens_destroyed;
40350 u32 cm_backlog_drops;
40351-atomic_t cm_loopbacks;
40352-atomic_t cm_nodes_created;
40353-atomic_t cm_nodes_destroyed;
40354-atomic_t cm_accel_dropped_pkts;
40355-atomic_t cm_resets_recvd;
40356+atomic_unchecked_t cm_loopbacks;
40357+atomic_unchecked_t cm_nodes_created;
40358+atomic_unchecked_t cm_nodes_destroyed;
40359+atomic_unchecked_t cm_accel_dropped_pkts;
40360+atomic_unchecked_t cm_resets_recvd;
40361
40362 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
40363 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
40364@@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
40365
40366 static struct nes_cm_core *g_cm_core;
40367
40368-atomic_t cm_connects;
40369-atomic_t cm_accepts;
40370-atomic_t cm_disconnects;
40371-atomic_t cm_closes;
40372-atomic_t cm_connecteds;
40373-atomic_t cm_connect_reqs;
40374-atomic_t cm_rejects;
40375+atomic_unchecked_t cm_connects;
40376+atomic_unchecked_t cm_accepts;
40377+atomic_unchecked_t cm_disconnects;
40378+atomic_unchecked_t cm_closes;
40379+atomic_unchecked_t cm_connecteds;
40380+atomic_unchecked_t cm_connect_reqs;
40381+atomic_unchecked_t cm_rejects;
40382
40383 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
40384 {
40385@@ -1272,7 +1272,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
40386 kfree(listener);
40387 listener = NULL;
40388 ret = 0;
40389- atomic_inc(&cm_listens_destroyed);
40390+ atomic_inc_unchecked(&cm_listens_destroyed);
40391 } else {
40392 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
40393 }
40394@@ -1466,7 +1466,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
40395 cm_node->rem_mac);
40396
40397 add_hte_node(cm_core, cm_node);
40398- atomic_inc(&cm_nodes_created);
40399+ atomic_inc_unchecked(&cm_nodes_created);
40400
40401 return cm_node;
40402 }
40403@@ -1524,7 +1524,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
40404 }
40405
40406 atomic_dec(&cm_core->node_cnt);
40407- atomic_inc(&cm_nodes_destroyed);
40408+ atomic_inc_unchecked(&cm_nodes_destroyed);
40409 nesqp = cm_node->nesqp;
40410 if (nesqp) {
40411 nesqp->cm_node = NULL;
40412@@ -1588,7 +1588,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
40413
40414 static void drop_packet(struct sk_buff *skb)
40415 {
40416- atomic_inc(&cm_accel_dropped_pkts);
40417+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
40418 dev_kfree_skb_any(skb);
40419 }
40420
40421@@ -1651,7 +1651,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
40422 {
40423
40424 int reset = 0; /* whether to send reset in case of err.. */
40425- atomic_inc(&cm_resets_recvd);
40426+ atomic_inc_unchecked(&cm_resets_recvd);
40427 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
40428 " refcnt=%d\n", cm_node, cm_node->state,
40429 atomic_read(&cm_node->ref_count));
40430@@ -2292,7 +2292,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
40431 rem_ref_cm_node(cm_node->cm_core, cm_node);
40432 return NULL;
40433 }
40434- atomic_inc(&cm_loopbacks);
40435+ atomic_inc_unchecked(&cm_loopbacks);
40436 loopbackremotenode->loopbackpartner = cm_node;
40437 loopbackremotenode->tcp_cntxt.rcv_wscale =
40438 NES_CM_DEFAULT_RCV_WND_SCALE;
40439@@ -2567,7 +2567,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
40440 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
40441 else {
40442 rem_ref_cm_node(cm_core, cm_node);
40443- atomic_inc(&cm_accel_dropped_pkts);
40444+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
40445 dev_kfree_skb_any(skb);
40446 }
40447 break;
40448@@ -2875,7 +2875,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
40449
40450 if ((cm_id) && (cm_id->event_handler)) {
40451 if (issue_disconn) {
40452- atomic_inc(&cm_disconnects);
40453+ atomic_inc_unchecked(&cm_disconnects);
40454 cm_event.event = IW_CM_EVENT_DISCONNECT;
40455 cm_event.status = disconn_status;
40456 cm_event.local_addr = cm_id->local_addr;
40457@@ -2897,7 +2897,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
40458 }
40459
40460 if (issue_close) {
40461- atomic_inc(&cm_closes);
40462+ atomic_inc_unchecked(&cm_closes);
40463 nes_disconnect(nesqp, 1);
40464
40465 cm_id->provider_data = nesqp;
40466@@ -3033,7 +3033,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
40467
40468 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
40469 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
40470- atomic_inc(&cm_accepts);
40471+ atomic_inc_unchecked(&cm_accepts);
40472
40473 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
40474 netdev_refcnt_read(nesvnic->netdev));
40475@@ -3228,7 +3228,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
40476 struct nes_cm_core *cm_core;
40477 u8 *start_buff;
40478
40479- atomic_inc(&cm_rejects);
40480+ atomic_inc_unchecked(&cm_rejects);
40481 cm_node = (struct nes_cm_node *)cm_id->provider_data;
40482 loopback = cm_node->loopbackpartner;
40483 cm_core = cm_node->cm_core;
40484@@ -3288,7 +3288,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
40485 ntohl(cm_id->local_addr.sin_addr.s_addr),
40486 ntohs(cm_id->local_addr.sin_port));
40487
40488- atomic_inc(&cm_connects);
40489+ atomic_inc_unchecked(&cm_connects);
40490 nesqp->active_conn = 1;
40491
40492 /* cache the cm_id in the qp */
40493@@ -3398,7 +3398,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
40494 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
40495 return err;
40496 }
40497- atomic_inc(&cm_listens_created);
40498+ atomic_inc_unchecked(&cm_listens_created);
40499 }
40500
40501 cm_id->add_ref(cm_id);
40502@@ -3499,7 +3499,7 @@ static void cm_event_connected(struct nes_cm_event *event)
40503
40504 if (nesqp->destroyed)
40505 return;
40506- atomic_inc(&cm_connecteds);
40507+ atomic_inc_unchecked(&cm_connecteds);
40508 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
40509 " local port 0x%04X. jiffies = %lu.\n",
40510 nesqp->hwqp.qp_id,
40511@@ -3679,7 +3679,7 @@ static void cm_event_reset(struct nes_cm_event *event)
40512
40513 cm_id->add_ref(cm_id);
40514 ret = cm_id->event_handler(cm_id, &cm_event);
40515- atomic_inc(&cm_closes);
40516+ atomic_inc_unchecked(&cm_closes);
40517 cm_event.event = IW_CM_EVENT_CLOSE;
40518 cm_event.status = 0;
40519 cm_event.provider_data = cm_id->provider_data;
40520@@ -3715,7 +3715,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
40521 return;
40522 cm_id = cm_node->cm_id;
40523
40524- atomic_inc(&cm_connect_reqs);
40525+ atomic_inc_unchecked(&cm_connect_reqs);
40526 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
40527 cm_node, cm_id, jiffies);
40528
40529@@ -3755,7 +3755,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
40530 return;
40531 cm_id = cm_node->cm_id;
40532
40533- atomic_inc(&cm_connect_reqs);
40534+ atomic_inc_unchecked(&cm_connect_reqs);
40535 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
40536 cm_node, cm_id, jiffies);
40537
40538diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
40539index 4166452..fc952c3 100644
40540--- a/drivers/infiniband/hw/nes/nes_mgt.c
40541+++ b/drivers/infiniband/hw/nes/nes_mgt.c
40542@@ -40,8 +40,8 @@
40543 #include "nes.h"
40544 #include "nes_mgt.h"
40545
40546-atomic_t pau_qps_created;
40547-atomic_t pau_qps_destroyed;
40548+atomic_unchecked_t pau_qps_created;
40549+atomic_unchecked_t pau_qps_destroyed;
40550
40551 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
40552 {
40553@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
40554 {
40555 struct sk_buff *skb;
40556 unsigned long flags;
40557- atomic_inc(&pau_qps_destroyed);
40558+ atomic_inc_unchecked(&pau_qps_destroyed);
40559
40560 /* Free packets that have not yet been forwarded */
40561 /* Lock is acquired by skb_dequeue when removing the skb */
40562@@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
40563 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
40564 skb_queue_head_init(&nesqp->pau_list);
40565 spin_lock_init(&nesqp->pau_lock);
40566- atomic_inc(&pau_qps_created);
40567+ atomic_inc_unchecked(&pau_qps_created);
40568 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
40569 }
40570
40571diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
40572index 49eb511..a774366 100644
40573--- a/drivers/infiniband/hw/nes/nes_nic.c
40574+++ b/drivers/infiniband/hw/nes/nes_nic.c
40575@@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
40576 target_stat_values[++index] = mh_detected;
40577 target_stat_values[++index] = mh_pauses_sent;
40578 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
40579- target_stat_values[++index] = atomic_read(&cm_connects);
40580- target_stat_values[++index] = atomic_read(&cm_accepts);
40581- target_stat_values[++index] = atomic_read(&cm_disconnects);
40582- target_stat_values[++index] = atomic_read(&cm_connecteds);
40583- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
40584- target_stat_values[++index] = atomic_read(&cm_rejects);
40585- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
40586- target_stat_values[++index] = atomic_read(&qps_created);
40587- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
40588- target_stat_values[++index] = atomic_read(&qps_destroyed);
40589- target_stat_values[++index] = atomic_read(&cm_closes);
40590+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
40591+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
40592+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
40593+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
40594+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
40595+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
40596+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
40597+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
40598+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
40599+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
40600+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
40601 target_stat_values[++index] = cm_packets_sent;
40602 target_stat_values[++index] = cm_packets_bounced;
40603 target_stat_values[++index] = cm_packets_created;
40604 target_stat_values[++index] = cm_packets_received;
40605 target_stat_values[++index] = cm_packets_dropped;
40606 target_stat_values[++index] = cm_packets_retrans;
40607- target_stat_values[++index] = atomic_read(&cm_listens_created);
40608- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
40609+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
40610+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
40611 target_stat_values[++index] = cm_backlog_drops;
40612- target_stat_values[++index] = atomic_read(&cm_loopbacks);
40613- target_stat_values[++index] = atomic_read(&cm_nodes_created);
40614- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
40615- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
40616- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
40617+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
40618+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
40619+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
40620+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
40621+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
40622 target_stat_values[++index] = nesadapter->free_4kpbl;
40623 target_stat_values[++index] = nesadapter->free_256pbl;
40624 target_stat_values[++index] = int_mod_timer_init;
40625 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
40626 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
40627 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
40628- target_stat_values[++index] = atomic_read(&pau_qps_created);
40629- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
40630+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
40631+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
40632 }
40633
40634 /**
40635diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
40636index 5b53ca5..443da3c 100644
40637--- a/drivers/infiniband/hw/nes/nes_verbs.c
40638+++ b/drivers/infiniband/hw/nes/nes_verbs.c
40639@@ -46,9 +46,9 @@
40640
40641 #include <rdma/ib_umem.h>
40642
40643-atomic_t mod_qp_timouts;
40644-atomic_t qps_created;
40645-atomic_t sw_qps_destroyed;
40646+atomic_unchecked_t mod_qp_timouts;
40647+atomic_unchecked_t qps_created;
40648+atomic_unchecked_t sw_qps_destroyed;
40649
40650 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
40651
40652@@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
40653 if (init_attr->create_flags)
40654 return ERR_PTR(-EINVAL);
40655
40656- atomic_inc(&qps_created);
40657+ atomic_inc_unchecked(&qps_created);
40658 switch (init_attr->qp_type) {
40659 case IB_QPT_RC:
40660 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
40661@@ -1466,7 +1466,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
40662 struct iw_cm_event cm_event;
40663 int ret = 0;
40664
40665- atomic_inc(&sw_qps_destroyed);
40666+ atomic_inc_unchecked(&sw_qps_destroyed);
40667 nesqp->destroyed = 1;
40668
40669 /* Blow away the connection if it exists. */
40670diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
40671index 4a9af79..b993f75 100644
40672--- a/drivers/infiniband/hw/qib/qib.h
40673+++ b/drivers/infiniband/hw/qib/qib.h
40674@@ -52,6 +52,7 @@
40675 #include <linux/kref.h>
40676 #include <linux/sched.h>
40677 #include <linux/kthread.h>
40678+#include <linux/slab.h>
40679
40680 #include "qib_common.h"
40681 #include "qib_verbs.h"
40682diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
40683index da739d9..da1c7f4 100644
40684--- a/drivers/input/gameport/gameport.c
40685+++ b/drivers/input/gameport/gameport.c
40686@@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
40687 */
40688 static void gameport_init_port(struct gameport *gameport)
40689 {
40690- static atomic_t gameport_no = ATOMIC_INIT(0);
40691+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
40692
40693 __module_get(THIS_MODULE);
40694
40695 mutex_init(&gameport->drv_mutex);
40696 device_initialize(&gameport->dev);
40697 dev_set_name(&gameport->dev, "gameport%lu",
40698- (unsigned long)atomic_inc_return(&gameport_no) - 1);
40699+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
40700 gameport->dev.bus = &gameport_bus;
40701 gameport->dev.release = gameport_release_port;
40702 if (gameport->parent)
40703diff --git a/drivers/input/input.c b/drivers/input/input.c
40704index c044699..174d71a 100644
40705--- a/drivers/input/input.c
40706+++ b/drivers/input/input.c
40707@@ -2019,7 +2019,7 @@ static void devm_input_device_unregister(struct device *dev, void *res)
40708 */
40709 int input_register_device(struct input_dev *dev)
40710 {
40711- static atomic_t input_no = ATOMIC_INIT(0);
40712+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
40713 struct input_devres *devres = NULL;
40714 struct input_handler *handler;
40715 unsigned int packet_size;
40716@@ -2074,7 +2074,7 @@ int input_register_device(struct input_dev *dev)
40717 dev->setkeycode = input_default_setkeycode;
40718
40719 dev_set_name(&dev->dev, "input%ld",
40720- (unsigned long) atomic_inc_return(&input_no) - 1);
40721+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
40722
40723 error = device_add(&dev->dev);
40724 if (error)
40725diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
40726index 04c69af..5f92d00 100644
40727--- a/drivers/input/joystick/sidewinder.c
40728+++ b/drivers/input/joystick/sidewinder.c
40729@@ -30,6 +30,7 @@
40730 #include <linux/kernel.h>
40731 #include <linux/module.h>
40732 #include <linux/slab.h>
40733+#include <linux/sched.h>
40734 #include <linux/init.h>
40735 #include <linux/input.h>
40736 #include <linux/gameport.h>
40737diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
40738index 75e3b10..fb390fd 100644
40739--- a/drivers/input/joystick/xpad.c
40740+++ b/drivers/input/joystick/xpad.c
40741@@ -736,7 +736,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
40742
40743 static int xpad_led_probe(struct usb_xpad *xpad)
40744 {
40745- static atomic_t led_seq = ATOMIC_INIT(0);
40746+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
40747 long led_no;
40748 struct xpad_led *led;
40749 struct led_classdev *led_cdev;
40750@@ -749,7 +749,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
40751 if (!led)
40752 return -ENOMEM;
40753
40754- led_no = (long)atomic_inc_return(&led_seq) - 1;
40755+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
40756
40757 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
40758 led->xpad = xpad;
40759diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
40760index e204f26..8459f15 100644
40761--- a/drivers/input/misc/ims-pcu.c
40762+++ b/drivers/input/misc/ims-pcu.c
40763@@ -1621,7 +1621,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
40764
40765 static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
40766 {
40767- static atomic_t device_no = ATOMIC_INIT(0);
40768+ static atomic_unchecked_t device_no = ATOMIC_INIT(0);
40769
40770 const struct ims_pcu_device_info *info;
40771 u8 device_id;
40772@@ -1653,7 +1653,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
40773 }
40774
40775 /* Device appears to be operable, complete initialization */
40776- pcu->device_no = atomic_inc_return(&device_no) - 1;
40777+ pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
40778
40779 error = ims_pcu_setup_backlight(pcu);
40780 if (error)
40781diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
40782index 2f0b39d..7370f13 100644
40783--- a/drivers/input/mouse/psmouse.h
40784+++ b/drivers/input/mouse/psmouse.h
40785@@ -116,7 +116,7 @@ struct psmouse_attribute {
40786 ssize_t (*set)(struct psmouse *psmouse, void *data,
40787 const char *buf, size_t count);
40788 bool protect;
40789-};
40790+} __do_const;
40791 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
40792
40793 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
40794diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
40795index 4c842c3..590b0bf 100644
40796--- a/drivers/input/mousedev.c
40797+++ b/drivers/input/mousedev.c
40798@@ -738,7 +738,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
40799
40800 spin_unlock_irq(&client->packet_lock);
40801
40802- if (copy_to_user(buffer, data, count))
40803+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
40804 return -EFAULT;
40805
40806 return count;
40807diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
40808index 25fc597..558bf3b3 100644
40809--- a/drivers/input/serio/serio.c
40810+++ b/drivers/input/serio/serio.c
40811@@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
40812 */
40813 static void serio_init_port(struct serio *serio)
40814 {
40815- static atomic_t serio_no = ATOMIC_INIT(0);
40816+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
40817
40818 __module_get(THIS_MODULE);
40819
40820@@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
40821 mutex_init(&serio->drv_mutex);
40822 device_initialize(&serio->dev);
40823 dev_set_name(&serio->dev, "serio%ld",
40824- (long)atomic_inc_return(&serio_no) - 1);
40825+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
40826 serio->dev.bus = &serio_bus;
40827 serio->dev.release = serio_release_port;
40828 serio->dev.groups = serio_device_attr_groups;
40829diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
40830index 59df2e7..8f1cafb 100644
40831--- a/drivers/input/serio/serio_raw.c
40832+++ b/drivers/input/serio/serio_raw.c
40833@@ -293,7 +293,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
40834
40835 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
40836 {
40837- static atomic_t serio_raw_no = ATOMIC_INIT(0);
40838+ static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
40839 struct serio_raw *serio_raw;
40840 int err;
40841
40842@@ -304,7 +304,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
40843 }
40844
40845 snprintf(serio_raw->name, sizeof(serio_raw->name),
40846- "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
40847+ "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
40848 kref_init(&serio_raw->kref);
40849 INIT_LIST_HEAD(&serio_raw->client_list);
40850 init_waitqueue_head(&serio_raw->wait);
40851diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
40852index fbe9ca7..dbee61d 100644
40853--- a/drivers/iommu/iommu.c
40854+++ b/drivers/iommu/iommu.c
40855@@ -583,7 +583,7 @@ static struct notifier_block iommu_bus_nb = {
40856 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
40857 {
40858 bus_register_notifier(bus, &iommu_bus_nb);
40859- bus_for_each_dev(bus, NULL, ops, add_iommu_group);
40860+ bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
40861 }
40862
40863 /**
40864diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
40865index 39f81ae..2660096 100644
40866--- a/drivers/iommu/irq_remapping.c
40867+++ b/drivers/iommu/irq_remapping.c
40868@@ -356,7 +356,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
40869 void panic_if_irq_remap(const char *msg)
40870 {
40871 if (irq_remapping_enabled)
40872- panic(msg);
40873+ panic("%s", msg);
40874 }
40875
40876 static void ir_ack_apic_edge(struct irq_data *data)
40877@@ -377,10 +377,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
40878
40879 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
40880 {
40881- chip->irq_print_chip = ir_print_prefix;
40882- chip->irq_ack = ir_ack_apic_edge;
40883- chip->irq_eoi = ir_ack_apic_level;
40884- chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
40885+ pax_open_kernel();
40886+ *(void **)&chip->irq_print_chip = ir_print_prefix;
40887+ *(void **)&chip->irq_ack = ir_ack_apic_edge;
40888+ *(void **)&chip->irq_eoi = ir_ack_apic_level;
40889+ *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
40890+ pax_close_kernel();
40891 }
40892
40893 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
40894diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
40895index ee7c503..5d4ce08 100644
40896--- a/drivers/irqchip/irq-gic.c
40897+++ b/drivers/irqchip/irq-gic.c
40898@@ -84,7 +84,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
40899 * Supported arch specific GIC irq extension.
40900 * Default make them NULL.
40901 */
40902-struct irq_chip gic_arch_extn = {
40903+irq_chip_no_const gic_arch_extn = {
40904 .irq_eoi = NULL,
40905 .irq_mask = NULL,
40906 .irq_unmask = NULL,
40907@@ -333,7 +333,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
40908 chained_irq_exit(chip, desc);
40909 }
40910
40911-static struct irq_chip gic_chip = {
40912+static irq_chip_no_const gic_chip __read_only = {
40913 .name = "GIC",
40914 .irq_mask = gic_mask_irq,
40915 .irq_unmask = gic_unmask_irq,
40916diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
40917index ac6f72b..81150f2 100644
40918--- a/drivers/isdn/capi/capi.c
40919+++ b/drivers/isdn/capi/capi.c
40920@@ -81,8 +81,8 @@ struct capiminor {
40921
40922 struct capi20_appl *ap;
40923 u32 ncci;
40924- atomic_t datahandle;
40925- atomic_t msgid;
40926+ atomic_unchecked_t datahandle;
40927+ atomic_unchecked_t msgid;
40928
40929 struct tty_port port;
40930 int ttyinstop;
40931@@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
40932 capimsg_setu16(s, 2, mp->ap->applid);
40933 capimsg_setu8 (s, 4, CAPI_DATA_B3);
40934 capimsg_setu8 (s, 5, CAPI_RESP);
40935- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
40936+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
40937 capimsg_setu32(s, 8, mp->ncci);
40938 capimsg_setu16(s, 12, datahandle);
40939 }
40940@@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
40941 mp->outbytes -= len;
40942 spin_unlock_bh(&mp->outlock);
40943
40944- datahandle = atomic_inc_return(&mp->datahandle);
40945+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
40946 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
40947 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
40948 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
40949 capimsg_setu16(skb->data, 2, mp->ap->applid);
40950 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
40951 capimsg_setu8 (skb->data, 5, CAPI_REQ);
40952- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
40953+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
40954 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
40955 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
40956 capimsg_setu16(skb->data, 16, len); /* Data length */
40957diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
40958index 600c79b..3752bab 100644
40959--- a/drivers/isdn/gigaset/interface.c
40960+++ b/drivers/isdn/gigaset/interface.c
40961@@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
40962 }
40963 tty->driver_data = cs;
40964
40965- ++cs->port.count;
40966+ atomic_inc(&cs->port.count);
40967
40968- if (cs->port.count == 1) {
40969+ if (atomic_read(&cs->port.count) == 1) {
40970 tty_port_tty_set(&cs->port, tty);
40971 cs->port.low_latency = 1;
40972 }
40973@@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
40974
40975 if (!cs->connected)
40976 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
40977- else if (!cs->port.count)
40978+ else if (!atomic_read(&cs->port.count))
40979 dev_warn(cs->dev, "%s: device not opened\n", __func__);
40980- else if (!--cs->port.count)
40981+ else if (!atomic_dec_return(&cs->port.count))
40982 tty_port_tty_set(&cs->port, NULL);
40983
40984 mutex_unlock(&cs->mutex);
40985diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
40986index d0a41cb..f0cdb8c 100644
40987--- a/drivers/isdn/gigaset/usb-gigaset.c
40988+++ b/drivers/isdn/gigaset/usb-gigaset.c
40989@@ -547,7 +547,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
40990 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
40991 memcpy(cs->hw.usb->bchars, buf, 6);
40992 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
40993- 0, 0, &buf, 6, 2000);
40994+ 0, 0, buf, 6, 2000);
40995 }
40996
40997 static void gigaset_freebcshw(struct bc_state *bcs)
40998diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
40999index 4d9b195..455075c 100644
41000--- a/drivers/isdn/hardware/avm/b1.c
41001+++ b/drivers/isdn/hardware/avm/b1.c
41002@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
41003 }
41004 if (left) {
41005 if (t4file->user) {
41006- if (copy_from_user(buf, dp, left))
41007+ if (left > sizeof buf || copy_from_user(buf, dp, left))
41008 return -EFAULT;
41009 } else {
41010 memcpy(buf, dp, left);
41011@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
41012 }
41013 if (left) {
41014 if (config->user) {
41015- if (copy_from_user(buf, dp, left))
41016+ if (left > sizeof buf || copy_from_user(buf, dp, left))
41017 return -EFAULT;
41018 } else {
41019 memcpy(buf, dp, left);
41020diff --git a/drivers/isdn/hisax/amd7930_fn.c b/drivers/isdn/hisax/amd7930_fn.c
41021index 1063bab..36817e0 100644
41022--- a/drivers/isdn/hisax/amd7930_fn.c
41023+++ b/drivers/isdn/hisax/amd7930_fn.c
41024@@ -314,7 +314,7 @@ Amd7930_empty_Dfifo(struct IsdnCardState *cs, int flag)
41025
41026 t += sprintf(t, "Amd7930: empty_Dfifo cnt: %d |", cs->rcvidx);
41027 QuickHex(t, cs->rcvbuf, cs->rcvidx);
41028- debugl1(cs, cs->dlog);
41029+ debugl1(cs, "%s", cs->dlog);
41030 }
41031 /* moves received data in sk-buffer */
41032 memcpy(skb_put(skb, cs->rcvidx), cs->rcvbuf, cs->rcvidx);
41033@@ -406,7 +406,7 @@ Amd7930_fill_Dfifo(struct IsdnCardState *cs)
41034
41035 t += sprintf(t, "Amd7930: fill_Dfifo cnt: %d |", count);
41036 QuickHex(t, deb_ptr, count);
41037- debugl1(cs, cs->dlog);
41038+ debugl1(cs, "%s", cs->dlog);
41039 }
41040 /* AMD interrupts on */
41041 AmdIrqOn(cs);
41042diff --git a/drivers/isdn/hisax/avm_pci.c b/drivers/isdn/hisax/avm_pci.c
41043index ee9b9a0..d1427bd 100644
41044--- a/drivers/isdn/hisax/avm_pci.c
41045+++ b/drivers/isdn/hisax/avm_pci.c
41046@@ -285,7 +285,7 @@ hdlc_empty_fifo(struct BCState *bcs, int count)
41047 t += sprintf(t, "hdlc_empty_fifo %c cnt %d",
41048 bcs->channel ? 'B' : 'A', count);
41049 QuickHex(t, p, count);
41050- debugl1(cs, bcs->blog);
41051+ debugl1(cs, "%s", bcs->blog);
41052 }
41053 }
41054
41055@@ -345,7 +345,7 @@ hdlc_fill_fifo(struct BCState *bcs)
41056 t += sprintf(t, "hdlc_fill_fifo %c cnt %d",
41057 bcs->channel ? 'B' : 'A', count);
41058 QuickHex(t, p, count);
41059- debugl1(cs, bcs->blog);
41060+ debugl1(cs, "%s", bcs->blog);
41061 }
41062 }
41063
41064diff --git a/drivers/isdn/hisax/config.c b/drivers/isdn/hisax/config.c
41065index bf04d2a..b33f53b 100644
41066--- a/drivers/isdn/hisax/config.c
41067+++ b/drivers/isdn/hisax/config.c
41068@@ -1896,7 +1896,7 @@ static void EChannel_proc_rcv(struct hisax_d_if *d_if)
41069 ptr--;
41070 *ptr++ = '\n';
41071 *ptr = 0;
41072- HiSax_putstatus(cs, NULL, cs->dlog);
41073+ HiSax_putstatus(cs, NULL, "%s", cs->dlog);
41074 } else
41075 HiSax_putstatus(cs, "LogEcho: ",
41076 "warning Frame too big (%d)",
41077diff --git a/drivers/isdn/hisax/diva.c b/drivers/isdn/hisax/diva.c
41078index 8d0cf6e..4fc90de 100644
41079--- a/drivers/isdn/hisax/diva.c
41080+++ b/drivers/isdn/hisax/diva.c
41081@@ -427,7 +427,7 @@ Memhscx_empty_fifo(struct BCState *bcs, int count)
41082 t += sprintf(t, "hscx_empty_fifo %c cnt %d",
41083 bcs->hw.hscx.hscx ? 'B' : 'A', count);
41084 QuickHex(t, ptr, count);
41085- debugl1(cs, bcs->blog);
41086+ debugl1(cs, "%s", bcs->blog);
41087 }
41088 }
41089
41090@@ -469,7 +469,7 @@ Memhscx_fill_fifo(struct BCState *bcs)
41091 t += sprintf(t, "hscx_fill_fifo %c cnt %d",
41092 bcs->hw.hscx.hscx ? 'B' : 'A', count);
41093 QuickHex(t, ptr, count);
41094- debugl1(cs, bcs->blog);
41095+ debugl1(cs, "%s", bcs->blog);
41096 }
41097 }
41098
41099diff --git a/drivers/isdn/hisax/elsa.c b/drivers/isdn/hisax/elsa.c
41100index 1df6f9a..2be1c8a 100644
41101--- a/drivers/isdn/hisax/elsa.c
41102+++ b/drivers/isdn/hisax/elsa.c
41103@@ -535,7 +535,7 @@ check_arcofi(struct IsdnCardState *cs)
41104 t = tmp;
41105 t += sprintf(tmp, "Arcofi data");
41106 QuickHex(t, p, cs->dc.isac.mon_rxp);
41107- debugl1(cs, tmp);
41108+ debugl1(cs, "%s", tmp);
41109 if ((cs->dc.isac.mon_rxp == 2) && (cs->dc.isac.mon_rx[0] == 0xa0)) {
41110 switch (cs->dc.isac.mon_rx[1]) {
41111 case 0x80:
41112diff --git a/drivers/isdn/hisax/elsa_ser.c b/drivers/isdn/hisax/elsa_ser.c
41113index d4c98d3..3f84dd8 100644
41114--- a/drivers/isdn/hisax/elsa_ser.c
41115+++ b/drivers/isdn/hisax/elsa_ser.c
41116@@ -344,7 +344,7 @@ static inline void receive_chars(struct IsdnCardState *cs,
41117
41118 t += sprintf(t, "modem read cnt %d", cs->hw.elsa.rcvcnt);
41119 QuickHex(t, cs->hw.elsa.rcvbuf, cs->hw.elsa.rcvcnt);
41120- debugl1(cs, tmp);
41121+ debugl1(cs, "%s", tmp);
41122 }
41123 cs->hw.elsa.rcvcnt = 0;
41124 }
41125diff --git a/drivers/isdn/hisax/hfc_pci.c b/drivers/isdn/hisax/hfc_pci.c
41126index 3ccd724..497bd02 100644
41127--- a/drivers/isdn/hisax/hfc_pci.c
41128+++ b/drivers/isdn/hisax/hfc_pci.c
41129@@ -901,7 +901,7 @@ Begin:
41130 ptr--;
41131 *ptr++ = '\n';
41132 *ptr = 0;
41133- HiSax_putstatus(cs, NULL, cs->dlog);
41134+ HiSax_putstatus(cs, NULL, "%s", cs->dlog);
41135 } else
41136 HiSax_putstatus(cs, "LogEcho: ", "warning Frame too big (%d)", total - 3);
41137 }
41138diff --git a/drivers/isdn/hisax/hfc_sx.c b/drivers/isdn/hisax/hfc_sx.c
41139index dc4574f..fa1fefd 100644
41140--- a/drivers/isdn/hisax/hfc_sx.c
41141+++ b/drivers/isdn/hisax/hfc_sx.c
41142@@ -674,7 +674,7 @@ receive_emsg(struct IsdnCardState *cs)
41143 ptr--;
41144 *ptr++ = '\n';
41145 *ptr = 0;
41146- HiSax_putstatus(cs, NULL, cs->dlog);
41147+ HiSax_putstatus(cs, NULL, "%s", cs->dlog);
41148 } else
41149 HiSax_putstatus(cs, "LogEcho: ", "warning Frame too big (%d)", skb->len);
41150 }
41151diff --git a/drivers/isdn/hisax/hscx_irq.c b/drivers/isdn/hisax/hscx_irq.c
41152index f398d48..a8d6188 100644
41153--- a/drivers/isdn/hisax/hscx_irq.c
41154+++ b/drivers/isdn/hisax/hscx_irq.c
41155@@ -75,7 +75,7 @@ hscx_empty_fifo(struct BCState *bcs, int count)
41156 t += sprintf(t, "hscx_empty_fifo %c cnt %d",
41157 bcs->hw.hscx.hscx ? 'B' : 'A', count);
41158 QuickHex(t, ptr, count);
41159- debugl1(cs, bcs->blog);
41160+ debugl1(cs, "%s", bcs->blog);
41161 }
41162 }
41163
41164@@ -115,7 +115,7 @@ hscx_fill_fifo(struct BCState *bcs)
41165 t += sprintf(t, "hscx_fill_fifo %c cnt %d",
41166 bcs->hw.hscx.hscx ? 'B' : 'A', count);
41167 QuickHex(t, ptr, count);
41168- debugl1(cs, bcs->blog);
41169+ debugl1(cs, "%s", bcs->blog);
41170 }
41171 }
41172
41173diff --git a/drivers/isdn/hisax/icc.c b/drivers/isdn/hisax/icc.c
41174index db5321f..51dae91 100644
41175--- a/drivers/isdn/hisax/icc.c
41176+++ b/drivers/isdn/hisax/icc.c
41177@@ -134,7 +134,7 @@ icc_empty_fifo(struct IsdnCardState *cs, int count)
41178
41179 t += sprintf(t, "icc_empty_fifo cnt %d", count);
41180 QuickHex(t, ptr, count);
41181- debugl1(cs, cs->dlog);
41182+ debugl1(cs, "%s", cs->dlog);
41183 }
41184 }
41185
41186@@ -176,7 +176,7 @@ icc_fill_fifo(struct IsdnCardState *cs)
41187
41188 t += sprintf(t, "icc_fill_fifo cnt %d", count);
41189 QuickHex(t, ptr, count);
41190- debugl1(cs, cs->dlog);
41191+ debugl1(cs, "%s", cs->dlog);
41192 }
41193 }
41194
41195diff --git a/drivers/isdn/hisax/ipacx.c b/drivers/isdn/hisax/ipacx.c
41196index 74feb5c..5faa5de 100644
41197--- a/drivers/isdn/hisax/ipacx.c
41198+++ b/drivers/isdn/hisax/ipacx.c
41199@@ -260,7 +260,7 @@ dch_empty_fifo(struct IsdnCardState *cs, int count)
41200
41201 t += sprintf(t, "dch_empty_fifo() cnt %d", count);
41202 QuickHex(t, ptr, count);
41203- debugl1(cs, cs->dlog);
41204+ debugl1(cs, "%s", cs->dlog);
41205 }
41206 }
41207
41208@@ -307,7 +307,7 @@ dch_fill_fifo(struct IsdnCardState *cs)
41209
41210 t += sprintf(t, "dch_fill_fifo() cnt %d", count);
41211 QuickHex(t, ptr, count);
41212- debugl1(cs, cs->dlog);
41213+ debugl1(cs, "%s", cs->dlog);
41214 }
41215 }
41216
41217@@ -539,7 +539,7 @@ bch_empty_fifo(struct BCState *bcs, int count)
41218
41219 t += sprintf(t, "bch_empty_fifo() B-%d cnt %d", hscx, count);
41220 QuickHex(t, ptr, count);
41221- debugl1(cs, bcs->blog);
41222+ debugl1(cs, "%s", bcs->blog);
41223 }
41224 }
41225
41226@@ -582,7 +582,7 @@ bch_fill_fifo(struct BCState *bcs)
41227
41228 t += sprintf(t, "chb_fill_fifo() B-%d cnt %d", hscx, count);
41229 QuickHex(t, ptr, count);
41230- debugl1(cs, bcs->blog);
41231+ debugl1(cs, "%s", bcs->blog);
41232 }
41233 }
41234
41235diff --git a/drivers/isdn/hisax/isac.c b/drivers/isdn/hisax/isac.c
41236index a365ccc..7fdf78f 100644
41237--- a/drivers/isdn/hisax/isac.c
41238+++ b/drivers/isdn/hisax/isac.c
41239@@ -137,7 +137,7 @@ isac_empty_fifo(struct IsdnCardState *cs, int count)
41240
41241 t += sprintf(t, "isac_empty_fifo cnt %d", count);
41242 QuickHex(t, ptr, count);
41243- debugl1(cs, cs->dlog);
41244+ debugl1(cs, "%s", cs->dlog);
41245 }
41246 }
41247
41248@@ -179,7 +179,7 @@ isac_fill_fifo(struct IsdnCardState *cs)
41249
41250 t += sprintf(t, "isac_fill_fifo cnt %d", count);
41251 QuickHex(t, ptr, count);
41252- debugl1(cs, cs->dlog);
41253+ debugl1(cs, "%s", cs->dlog);
41254 }
41255 }
41256
41257diff --git a/drivers/isdn/hisax/isar.c b/drivers/isdn/hisax/isar.c
41258index 7fdf347..f4956c7 100644
41259--- a/drivers/isdn/hisax/isar.c
41260+++ b/drivers/isdn/hisax/isar.c
41261@@ -74,7 +74,7 @@ sendmsg(struct IsdnCardState *cs, u_char his, u_char creg, u_char len,
41262 t = tmp;
41263 t += sprintf(t, "sendmbox cnt %d", len);
41264 QuickHex(t, &msg[len-i], (i > 64) ? 64 : i);
41265- debugl1(cs, tmp);
41266+ debugl1(cs, "%s", tmp);
41267 i -= 64;
41268 }
41269 }
41270@@ -105,7 +105,7 @@ rcv_mbox(struct IsdnCardState *cs, struct isar_reg *ireg, u_char *msg)
41271 t = tmp;
41272 t += sprintf(t, "rcv_mbox cnt %d", ireg->clsb);
41273 QuickHex(t, &msg[ireg->clsb - i], (i > 64) ? 64 : i);
41274- debugl1(cs, tmp);
41275+ debugl1(cs, "%s", tmp);
41276 i -= 64;
41277 }
41278 }
41279@@ -1248,7 +1248,7 @@ isar_int_main(struct IsdnCardState *cs)
41280 tp += sprintf(debbuf, "msg iis(%x) msb(%x)",
41281 ireg->iis, ireg->cmsb);
41282 QuickHex(tp, (u_char *)ireg->par, ireg->clsb);
41283- debugl1(cs, debbuf);
41284+ debugl1(cs, "%s", debbuf);
41285 }
41286 break;
41287 case ISAR_IIS_INVMSG:
41288diff --git a/drivers/isdn/hisax/jade.c b/drivers/isdn/hisax/jade.c
41289index f946c58..e2ae787 100644
41290--- a/drivers/isdn/hisax/jade.c
41291+++ b/drivers/isdn/hisax/jade.c
41292@@ -81,10 +81,7 @@ modejade(struct BCState *bcs, int mode, int bc)
41293 int jade = bcs->hw.hscx.hscx;
41294
41295 if (cs->debug & L1_DEB_HSCX) {
41296- char tmp[40];
41297- sprintf(tmp, "jade %c mode %d ichan %d",
41298- 'A' + jade, mode, bc);
41299- debugl1(cs, tmp);
41300+ debugl1(cs, "jade %c mode %d ichan %d", 'A' + jade, mode, bc);
41301 }
41302 bcs->mode = mode;
41303 bcs->channel = bc;
41304@@ -257,23 +254,18 @@ void
41305 clear_pending_jade_ints(struct IsdnCardState *cs)
41306 {
41307 int val;
41308- char tmp[64];
41309
41310 cs->BC_Write_Reg(cs, 0, jade_HDLC_IMR, 0x00);
41311 cs->BC_Write_Reg(cs, 1, jade_HDLC_IMR, 0x00);
41312
41313 val = cs->BC_Read_Reg(cs, 1, jade_HDLC_ISR);
41314- sprintf(tmp, "jade B ISTA %x", val);
41315- debugl1(cs, tmp);
41316+ debugl1(cs, "jade B ISTA %x", val);
41317 val = cs->BC_Read_Reg(cs, 0, jade_HDLC_ISR);
41318- sprintf(tmp, "jade A ISTA %x", val);
41319- debugl1(cs, tmp);
41320+ debugl1(cs, "jade A ISTA %x", val);
41321 val = cs->BC_Read_Reg(cs, 1, jade_HDLC_STAR);
41322- sprintf(tmp, "jade B STAR %x", val);
41323- debugl1(cs, tmp);
41324+ debugl1(cs, "jade B STAR %x", val);
41325 val = cs->BC_Read_Reg(cs, 0, jade_HDLC_STAR);
41326- sprintf(tmp, "jade A STAR %x", val);
41327- debugl1(cs, tmp);
41328+ debugl1(cs, "jade A STAR %x", val);
41329 /* Unmask ints */
41330 cs->BC_Write_Reg(cs, 0, jade_HDLC_IMR, 0xF8);
41331 cs->BC_Write_Reg(cs, 1, jade_HDLC_IMR, 0xF8);
41332diff --git a/drivers/isdn/hisax/jade_irq.c b/drivers/isdn/hisax/jade_irq.c
41333index f521fc8..b930da9 100644
41334--- a/drivers/isdn/hisax/jade_irq.c
41335+++ b/drivers/isdn/hisax/jade_irq.c
41336@@ -65,7 +65,7 @@ jade_empty_fifo(struct BCState *bcs, int count)
41337 t += sprintf(t, "jade_empty_fifo %c cnt %d",
41338 bcs->hw.hscx.hscx ? 'B' : 'A', count);
41339 QuickHex(t, ptr, count);
41340- debugl1(cs, bcs->blog);
41341+ debugl1(cs, "%s", bcs->blog);
41342 }
41343 }
41344
41345@@ -105,7 +105,7 @@ jade_fill_fifo(struct BCState *bcs)
41346 t += sprintf(t, "jade_fill_fifo %c cnt %d",
41347 bcs->hw.hscx.hscx ? 'B' : 'A', count);
41348 QuickHex(t, ptr, count);
41349- debugl1(cs, bcs->blog);
41350+ debugl1(cs, "%s", bcs->blog);
41351 }
41352 }
41353
41354diff --git a/drivers/isdn/hisax/l3_1tr6.c b/drivers/isdn/hisax/l3_1tr6.c
41355index 4c1bca5..875402e 100644
41356--- a/drivers/isdn/hisax/l3_1tr6.c
41357+++ b/drivers/isdn/hisax/l3_1tr6.c
41358@@ -63,7 +63,7 @@ l3_1tr6_error(struct l3_process *pc, u_char *msg, struct sk_buff *skb)
41359 {
41360 dev_kfree_skb(skb);
41361 if (pc->st->l3.debug & L3_DEB_WARN)
41362- l3_debug(pc->st, msg);
41363+ l3_debug(pc->st, "%s", msg);
41364 l3_1tr6_release_req(pc, 0, NULL);
41365 }
41366
41367@@ -161,7 +161,6 @@ l3_1tr6_setup(struct l3_process *pc, u_char pr, void *arg)
41368 {
41369 u_char *p;
41370 int bcfound = 0;
41371- char tmp[80];
41372 struct sk_buff *skb = arg;
41373
41374 /* Channel Identification */
41375@@ -214,10 +213,9 @@ l3_1tr6_setup(struct l3_process *pc, u_char pr, void *arg)
41376 /* Signal all services, linklevel takes care of Service-Indicator */
41377 if (bcfound) {
41378 if ((pc->para.setup.si1 != 7) && (pc->st->l3.debug & L3_DEB_WARN)) {
41379- sprintf(tmp, "non-digital call: %s -> %s",
41380+ l3_debug(pc->st, "non-digital call: %s -> %s",
41381 pc->para.setup.phone,
41382 pc->para.setup.eazmsn);
41383- l3_debug(pc->st, tmp);
41384 }
41385 newl3state(pc, 6);
41386 pc->st->l3.l3l4(pc->st, CC_SETUP | INDICATION, pc);
41387@@ -301,7 +299,7 @@ l3_1tr6_info(struct l3_process *pc, u_char pr, void *arg)
41388 {
41389 u_char *p;
41390 int i, tmpcharge = 0;
41391- char a_charge[8], tmp[32];
41392+ char a_charge[8];
41393 struct sk_buff *skb = arg;
41394
41395 p = skb->data;
41396@@ -316,8 +314,8 @@ l3_1tr6_info(struct l3_process *pc, u_char pr, void *arg)
41397 pc->st->l3.l3l4(pc->st, CC_CHARGE | INDICATION, pc);
41398 }
41399 if (pc->st->l3.debug & L3_DEB_CHARGE) {
41400- sprintf(tmp, "charging info %d", pc->para.chargeinfo);
41401- l3_debug(pc->st, tmp);
41402+ l3_debug(pc->st, "charging info %d",
41403+ pc->para.chargeinfo);
41404 }
41405 } else if (pc->st->l3.debug & L3_DEB_CHARGE)
41406 l3_debug(pc->st, "charging info not found");
41407@@ -399,7 +397,7 @@ l3_1tr6_disc(struct l3_process *pc, u_char pr, void *arg)
41408 struct sk_buff *skb = arg;
41409 u_char *p;
41410 int i, tmpcharge = 0;
41411- char a_charge[8], tmp[32];
41412+ char a_charge[8];
41413
41414 StopAllL3Timer(pc);
41415 p = skb->data;
41416@@ -414,8 +412,8 @@ l3_1tr6_disc(struct l3_process *pc, u_char pr, void *arg)
41417 pc->st->l3.l3l4(pc->st, CC_CHARGE | INDICATION, pc);
41418 }
41419 if (pc->st->l3.debug & L3_DEB_CHARGE) {
41420- sprintf(tmp, "charging info %d", pc->para.chargeinfo);
41421- l3_debug(pc->st, tmp);
41422+ l3_debug(pc->st, "charging info %d",
41423+ pc->para.chargeinfo);
41424 }
41425 } else if (pc->st->l3.debug & L3_DEB_CHARGE)
41426 l3_debug(pc->st, "charging info not found");
41427@@ -746,7 +744,6 @@ up1tr6(struct PStack *st, int pr, void *arg)
41428 int i, mt, cr;
41429 struct l3_process *proc;
41430 struct sk_buff *skb = arg;
41431- char tmp[80];
41432
41433 switch (pr) {
41434 case (DL_DATA | INDICATION):
41435@@ -762,26 +759,23 @@ up1tr6(struct PStack *st, int pr, void *arg)
41436 }
41437 if (skb->len < 4) {
41438 if (st->l3.debug & L3_DEB_PROTERR) {
41439- sprintf(tmp, "up1tr6 len only %d", skb->len);
41440- l3_debug(st, tmp);
41441+ l3_debug(st, "up1tr6 len only %d", skb->len);
41442 }
41443 dev_kfree_skb(skb);
41444 return;
41445 }
41446 if ((skb->data[0] & 0xfe) != PROTO_DIS_N0) {
41447 if (st->l3.debug & L3_DEB_PROTERR) {
41448- sprintf(tmp, "up1tr6%sunexpected discriminator %x message len %d",
41449+ l3_debug(st, "up1tr6%sunexpected discriminator %x message len %d",
41450 (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ",
41451 skb->data[0], skb->len);
41452- l3_debug(st, tmp);
41453 }
41454 dev_kfree_skb(skb);
41455 return;
41456 }
41457 if (skb->data[1] != 1) {
41458 if (st->l3.debug & L3_DEB_PROTERR) {
41459- sprintf(tmp, "up1tr6 CR len not 1");
41460- l3_debug(st, tmp);
41461+ l3_debug(st, "up1tr6 CR len not 1");
41462 }
41463 dev_kfree_skb(skb);
41464 return;
41465@@ -791,9 +785,8 @@ up1tr6(struct PStack *st, int pr, void *arg)
41466 if (skb->data[0] == PROTO_DIS_N0) {
41467 dev_kfree_skb(skb);
41468 if (st->l3.debug & L3_DEB_STATE) {
41469- sprintf(tmp, "up1tr6%s N0 mt %x unhandled",
41470+ l3_debug(st, "up1tr6%s N0 mt %x unhandled",
41471 (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ", mt);
41472- l3_debug(st, tmp);
41473 }
41474 } else if (skb->data[0] == PROTO_DIS_N1) {
41475 if (!(proc = getl3proc(st, cr))) {
41476@@ -801,8 +794,7 @@ up1tr6(struct PStack *st, int pr, void *arg)
41477 if (cr < 128) {
41478 if (!(proc = new_l3_process(st, cr))) {
41479 if (st->l3.debug & L3_DEB_PROTERR) {
41480- sprintf(tmp, "up1tr6 no roc mem");
41481- l3_debug(st, tmp);
41482+ l3_debug(st, "up1tr6 no roc mem");
41483 }
41484 dev_kfree_skb(skb);
41485 return;
41486@@ -821,8 +813,7 @@ up1tr6(struct PStack *st, int pr, void *arg)
41487 } else {
41488 if (!(proc = new_l3_process(st, cr))) {
41489 if (st->l3.debug & L3_DEB_PROTERR) {
41490- sprintf(tmp, "up1tr6 no roc mem");
41491- l3_debug(st, tmp);
41492+ l3_debug(st, "up1tr6 no roc mem");
41493 }
41494 dev_kfree_skb(skb);
41495 return;
41496@@ -837,18 +828,16 @@ up1tr6(struct PStack *st, int pr, void *arg)
41497 if (i == ARRAY_SIZE(datastln1)) {
41498 dev_kfree_skb(skb);
41499 if (st->l3.debug & L3_DEB_STATE) {
41500- sprintf(tmp, "up1tr6%sstate %d mt %x unhandled",
41501+ l3_debug(st, "up1tr6%sstate %d mt %x unhandled",
41502 (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ",
41503 proc->state, mt);
41504- l3_debug(st, tmp);
41505 }
41506 return;
41507 } else {
41508 if (st->l3.debug & L3_DEB_STATE) {
41509- sprintf(tmp, "up1tr6%sstate %d mt %x",
41510+ l3_debug(st, "up1tr6%sstate %d mt %x",
41511 (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ",
41512 proc->state, mt);
41513- l3_debug(st, tmp);
41514 }
41515 datastln1[i].rout(proc, pr, skb);
41516 }
41517@@ -861,7 +850,6 @@ down1tr6(struct PStack *st, int pr, void *arg)
41518 int i, cr;
41519 struct l3_process *proc;
41520 struct Channel *chan;
41521- char tmp[80];
41522
41523 if ((DL_ESTABLISH | REQUEST) == pr) {
41524 l3_msg(st, pr, NULL);
41525@@ -888,15 +876,13 @@ down1tr6(struct PStack *st, int pr, void *arg)
41526 break;
41527 if (i == ARRAY_SIZE(downstl)) {
41528 if (st->l3.debug & L3_DEB_STATE) {
41529- sprintf(tmp, "down1tr6 state %d prim %d unhandled",
41530+ l3_debug(st, "down1tr6 state %d prim %d unhandled",
41531 proc->state, pr);
41532- l3_debug(st, tmp);
41533 }
41534 } else {
41535 if (st->l3.debug & L3_DEB_STATE) {
41536- sprintf(tmp, "down1tr6 state %d prim %d",
41537+ l3_debug(st, "down1tr6 state %d prim %d",
41538 proc->state, pr);
41539- l3_debug(st, tmp);
41540 }
41541 downstl[i].rout(proc, pr, arg);
41542 }
41543diff --git a/drivers/isdn/hisax/netjet.c b/drivers/isdn/hisax/netjet.c
41544index b646eed..233e432 100644
41545--- a/drivers/isdn/hisax/netjet.c
41546+++ b/drivers/isdn/hisax/netjet.c
41547@@ -176,7 +176,7 @@ static void printframe(struct IsdnCardState *cs, u_char *buf, int count, char *s
41548 else
41549 j = i;
41550 QuickHex(t, p, j);
41551- debugl1(cs, tmp);
41552+ debugl1(cs, "%s", tmp);
41553 p += j;
41554 i -= j;
41555 t = tmp;
41556diff --git a/drivers/isdn/hisax/q931.c b/drivers/isdn/hisax/q931.c
41557index 041bf52..af1b020 100644
41558--- a/drivers/isdn/hisax/q931.c
41559+++ b/drivers/isdn/hisax/q931.c
41560@@ -1179,7 +1179,7 @@ LogFrame(struct IsdnCardState *cs, u_char *buf, int size)
41561 dp--;
41562 *dp++ = '\n';
41563 *dp = 0;
41564- HiSax_putstatus(cs, NULL, cs->dlog);
41565+ HiSax_putstatus(cs, NULL, "%s", cs->dlog);
41566 } else
41567 HiSax_putstatus(cs, "LogFrame: ", "warning Frame too big (%d)", size);
41568 }
41569@@ -1246,7 +1246,7 @@ dlogframe(struct IsdnCardState *cs, struct sk_buff *skb, int dir)
41570 }
41571 if (finish) {
41572 *dp = 0;
41573- HiSax_putstatus(cs, NULL, cs->dlog);
41574+ HiSax_putstatus(cs, NULL, "%s", cs->dlog);
41575 return;
41576 }
41577 if ((0xfe & buf[0]) == PROTO_DIS_N0) { /* 1TR6 */
41578@@ -1509,5 +1509,5 @@ dlogframe(struct IsdnCardState *cs, struct sk_buff *skb, int dir)
41579 dp += sprintf(dp, "Unknown protocol %x!", buf[0]);
41580 }
41581 *dp = 0;
41582- HiSax_putstatus(cs, NULL, cs->dlog);
41583+ HiSax_putstatus(cs, NULL, "%s", cs->dlog);
41584 }
41585diff --git a/drivers/isdn/hisax/w6692.c b/drivers/isdn/hisax/w6692.c
41586index d8cac69..a858955 100644
41587--- a/drivers/isdn/hisax/w6692.c
41588+++ b/drivers/isdn/hisax/w6692.c
41589@@ -154,7 +154,7 @@ W6692_empty_fifo(struct IsdnCardState *cs, int count)
41590
41591 t += sprintf(t, "W6692_empty_fifo cnt %d", count);
41592 QuickHex(t, ptr, count);
41593- debugl1(cs, cs->dlog);
41594+ debugl1(cs, "%s", cs->dlog);
41595 }
41596 }
41597
41598@@ -196,7 +196,7 @@ W6692_fill_fifo(struct IsdnCardState *cs)
41599
41600 t += sprintf(t, "W6692_fill_fifo cnt %d", count);
41601 QuickHex(t, ptr, count);
41602- debugl1(cs, cs->dlog);
41603+ debugl1(cs, "%s", cs->dlog);
41604 }
41605 }
41606
41607@@ -226,7 +226,7 @@ W6692B_empty_fifo(struct BCState *bcs, int count)
41608 t += sprintf(t, "W6692B_empty_fifo %c cnt %d",
41609 bcs->channel + '1', count);
41610 QuickHex(t, ptr, count);
41611- debugl1(cs, bcs->blog);
41612+ debugl1(cs, "%s", bcs->blog);
41613 }
41614 }
41615
41616@@ -264,7 +264,7 @@ W6692B_fill_fifo(struct BCState *bcs)
41617 t += sprintf(t, "W6692B_fill_fifo %c cnt %d",
41618 bcs->channel + '1', count);
41619 QuickHex(t, ptr, count);
41620- debugl1(cs, bcs->blog);
41621+ debugl1(cs, "%s", bcs->blog);
41622 }
41623 }
41624
41625diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
41626index 9bb12ba..d4262f7 100644
41627--- a/drivers/isdn/i4l/isdn_common.c
41628+++ b/drivers/isdn/i4l/isdn_common.c
41629@@ -1651,6 +1651,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
41630 } else
41631 return -EINVAL;
41632 case IIOCDBGVAR:
41633+ if (!capable(CAP_SYS_RAWIO))
41634+ return -EPERM;
41635 if (arg) {
41636 if (copy_to_user(argp, &dev, sizeof(ulong)))
41637 return -EFAULT;
41638diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
41639index 3c5f249..5fac4d0 100644
41640--- a/drivers/isdn/i4l/isdn_tty.c
41641+++ b/drivers/isdn/i4l/isdn_tty.c
41642@@ -1508,9 +1508,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
41643
41644 #ifdef ISDN_DEBUG_MODEM_OPEN
41645 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
41646- port->count);
41647+ atomic_read(&port->count));
41648 #endif
41649- port->count++;
41650+ atomic_inc(&port->count);
41651 port->tty = tty;
41652 /*
41653 * Start up serial port
41654@@ -1554,7 +1554,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
41655 #endif
41656 return;
41657 }
41658- if ((tty->count == 1) && (port->count != 1)) {
41659+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
41660 /*
41661 * Uh, oh. tty->count is 1, which means that the tty
41662 * structure will be freed. Info->count should always
41663@@ -1563,15 +1563,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
41664 * serial port won't be shutdown.
41665 */
41666 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
41667- "info->count is %d\n", port->count);
41668- port->count = 1;
41669+ "info->count is %d\n", atomic_read(&port->count));
41670+ atomic_set(&port->count, 1);
41671 }
41672- if (--port->count < 0) {
41673+ if (atomic_dec_return(&port->count) < 0) {
41674 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
41675- info->line, port->count);
41676- port->count = 0;
41677+ info->line, atomic_read(&port->count));
41678+ atomic_set(&port->count, 0);
41679 }
41680- if (port->count) {
41681+ if (atomic_read(&port->count)) {
41682 #ifdef ISDN_DEBUG_MODEM_OPEN
41683 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
41684 #endif
41685@@ -1625,7 +1625,7 @@ isdn_tty_hangup(struct tty_struct *tty)
41686 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
41687 return;
41688 isdn_tty_shutdown(info);
41689- port->count = 0;
41690+ atomic_set(&port->count, 0);
41691 port->flags &= ~ASYNC_NORMAL_ACTIVE;
41692 port->tty = NULL;
41693 wake_up_interruptible(&port->open_wait);
41694@@ -1970,7 +1970,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
41695 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
41696 modem_info *info = &dev->mdm.info[i];
41697
41698- if (info->port.count == 0)
41699+ if (atomic_read(&info->port.count) == 0)
41700 continue;
41701 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
41702 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
41703diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
41704index e74df7c..03a03ba 100644
41705--- a/drivers/isdn/icn/icn.c
41706+++ b/drivers/isdn/icn/icn.c
41707@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
41708 if (count > len)
41709 count = len;
41710 if (user) {
41711- if (copy_from_user(msg, buf, count))
41712+ if (count > sizeof msg || copy_from_user(msg, buf, count))
41713 return -EFAULT;
41714 } else
41715 memcpy(msg, buf, count);
41716diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
41717index 6a8405d..0bd1c7e 100644
41718--- a/drivers/leds/leds-clevo-mail.c
41719+++ b/drivers/leds/leds-clevo-mail.c
41720@@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
41721 * detected as working, but in reality it is not) as low as
41722 * possible.
41723 */
41724-static struct dmi_system_id __initdata clevo_mail_led_dmi_table[] = {
41725+static const struct dmi_system_id __initconst clevo_mail_led_dmi_table[] = {
41726 {
41727 .callback = clevo_mail_led_dmi_callback,
41728 .ident = "Clevo D410J",
41729diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
41730index 64e204e..c6bf189 100644
41731--- a/drivers/leds/leds-ss4200.c
41732+++ b/drivers/leds/leds-ss4200.c
41733@@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
41734 * detected as working, but in reality it is not) as low as
41735 * possible.
41736 */
41737-static struct dmi_system_id __initdata nas_led_whitelist[] = {
41738+static const struct dmi_system_id __initconst nas_led_whitelist[] = {
41739 {
41740 .callback = ss4200_led_dmi_callback,
41741 .ident = "Intel SS4200-E",
41742diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
41743index 0bf1e4e..b4bf44e 100644
41744--- a/drivers/lguest/core.c
41745+++ b/drivers/lguest/core.c
41746@@ -97,9 +97,17 @@ static __init int map_switcher(void)
41747 * The end address needs +1 because __get_vm_area allocates an
41748 * extra guard page, so we need space for that.
41749 */
41750+
41751+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
41752+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
41753+ VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
41754+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
41755+#else
41756 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
41757 VM_ALLOC, switcher_addr, switcher_addr
41758 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
41759+#endif
41760+
41761 if (!switcher_vma) {
41762 err = -ENOMEM;
41763 printk("lguest: could not map switcher pages high\n");
41764@@ -124,7 +132,7 @@ static __init int map_switcher(void)
41765 * Now the Switcher is mapped at the right address, we can't fail!
41766 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
41767 */
41768- memcpy(switcher_vma->addr, start_switcher_text,
41769+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
41770 end_switcher_text - start_switcher_text);
41771
41772 printk(KERN_INFO "lguest: mapped switcher at %p\n",
41773diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
41774index a35d8d1..59fb772 100644
41775--- a/drivers/lguest/page_tables.c
41776+++ b/drivers/lguest/page_tables.c
41777@@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
41778 /*:*/
41779
41780 #ifdef CONFIG_X86_PAE
41781-static void release_pmd(pmd_t *spmd)
41782+static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
41783 {
41784 /* If the entry's not present, there's nothing to release. */
41785 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
41786diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
41787index 5169239..47cb4db 100644
41788--- a/drivers/lguest/x86/core.c
41789+++ b/drivers/lguest/x86/core.c
41790@@ -59,7 +59,7 @@ static struct {
41791 /* Offset from where switcher.S was compiled to where we've copied it */
41792 static unsigned long switcher_offset(void)
41793 {
41794- return switcher_addr - (unsigned long)start_switcher_text;
41795+ return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
41796 }
41797
41798 /* This cpu's struct lguest_pages (after the Switcher text page) */
41799@@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
41800 * These copies are pretty cheap, so we do them unconditionally: */
41801 /* Save the current Host top-level page directory.
41802 */
41803+
41804+#ifdef CONFIG_PAX_PER_CPU_PGD
41805+ pages->state.host_cr3 = read_cr3();
41806+#else
41807 pages->state.host_cr3 = __pa(current->mm->pgd);
41808+#endif
41809+
41810 /*
41811 * Set up the Guest's page tables to see this CPU's pages (and no
41812 * other CPU's pages).
41813@@ -475,7 +481,7 @@ void __init lguest_arch_host_init(void)
41814 * compiled-in switcher code and the high-mapped copy we just made.
41815 */
41816 for (i = 0; i < IDT_ENTRIES; i++)
41817- default_idt_entries[i] += switcher_offset();
41818+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
41819
41820 /*
41821 * Set up the Switcher's per-cpu areas.
41822@@ -558,7 +564,7 @@ void __init lguest_arch_host_init(void)
41823 * it will be undisturbed when we switch. To change %cs and jump we
41824 * need this structure to feed to Intel's "lcall" instruction.
41825 */
41826- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
41827+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
41828 lguest_entry.segment = LGUEST_CS;
41829
41830 /*
41831diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
41832index 40634b0..4f5855e 100644
41833--- a/drivers/lguest/x86/switcher_32.S
41834+++ b/drivers/lguest/x86/switcher_32.S
41835@@ -87,6 +87,7 @@
41836 #include <asm/page.h>
41837 #include <asm/segment.h>
41838 #include <asm/lguest.h>
41839+#include <asm/processor-flags.h>
41840
41841 // We mark the start of the code to copy
41842 // It's placed in .text tho it's never run here
41843@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
41844 // Changes type when we load it: damn Intel!
41845 // For after we switch over our page tables
41846 // That entry will be read-only: we'd crash.
41847+
41848+#ifdef CONFIG_PAX_KERNEXEC
41849+ mov %cr0, %edx
41850+ xor $X86_CR0_WP, %edx
41851+ mov %edx, %cr0
41852+#endif
41853+
41854 movl $(GDT_ENTRY_TSS*8), %edx
41855 ltr %dx
41856
41857@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
41858 // Let's clear it again for our return.
41859 // The GDT descriptor of the Host
41860 // Points to the table after two "size" bytes
41861- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
41862+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
41863 // Clear "used" from type field (byte 5, bit 2)
41864- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
41865+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
41866+
41867+#ifdef CONFIG_PAX_KERNEXEC
41868+ mov %cr0, %eax
41869+ xor $X86_CR0_WP, %eax
41870+ mov %eax, %cr0
41871+#endif
41872
41873 // Once our page table's switched, the Guest is live!
41874 // The Host fades as we run this final step.
41875@@ -295,13 +309,12 @@ deliver_to_host:
41876 // I consulted gcc, and it gave
41877 // These instructions, which I gladly credit:
41878 leal (%edx,%ebx,8), %eax
41879- movzwl (%eax),%edx
41880- movl 4(%eax), %eax
41881- xorw %ax, %ax
41882- orl %eax, %edx
41883+ movl 4(%eax), %edx
41884+ movw (%eax), %dx
41885 // Now the address of the handler's in %edx
41886 // We call it now: its "iret" drops us home.
41887- jmp *%edx
41888+ ljmp $__KERNEL_CS, $1f
41889+1: jmp *%edx
41890
41891 // Every interrupt can come to us here
41892 // But we must truly tell each apart.
41893diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
41894index 0003992..854bbce 100644
41895--- a/drivers/md/bcache/closure.h
41896+++ b/drivers/md/bcache/closure.h
41897@@ -622,7 +622,7 @@ static inline void closure_wake_up(struct closure_waitlist *list)
41898 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
41899 struct workqueue_struct *wq)
41900 {
41901- BUG_ON(object_is_on_stack(cl));
41902+ BUG_ON(object_starts_on_stack(cl));
41903 closure_set_ip(cl);
41904 cl->fn = fn;
41905 cl->wq = wq;
41906diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
41907index 547c4c5..5be1de4 100644
41908--- a/drivers/md/bcache/super.c
41909+++ b/drivers/md/bcache/super.c
41910@@ -1644,7 +1644,7 @@ err_unlock_gc:
41911 err:
41912 closure_sync(&op.cl);
41913 /* XXX: test this, it's broken */
41914- bch_cache_set_error(c, err);
41915+ bch_cache_set_error(c, "%s", err);
41916 }
41917
41918 static bool can_attach_cache(struct cache *ca, struct cache_set *c)
41919diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
41920index a7fd821..9dcf6c3 100644
41921--- a/drivers/md/bitmap.c
41922+++ b/drivers/md/bitmap.c
41923@@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
41924 chunk_kb ? "KB" : "B");
41925 if (bitmap->storage.file) {
41926 seq_printf(seq, ", file: ");
41927- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
41928+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
41929 }
41930
41931 seq_printf(seq, "\n");
41932diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
41933index f1b7586..a49c4bd 100644
41934--- a/drivers/md/dm-ioctl.c
41935+++ b/drivers/md/dm-ioctl.c
41936@@ -1739,7 +1739,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
41937 cmd == DM_LIST_VERSIONS_CMD)
41938 return 0;
41939
41940- if ((cmd == DM_DEV_CREATE_CMD)) {
41941+ if (cmd == DM_DEV_CREATE_CMD) {
41942 if (!*param->name) {
41943 DMWARN("name not supplied when creating device");
41944 return -EINVAL;
41945diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
41946index 699b5be..eac0a15 100644
41947--- a/drivers/md/dm-raid1.c
41948+++ b/drivers/md/dm-raid1.c
41949@@ -40,7 +40,7 @@ enum dm_raid1_error {
41950
41951 struct mirror {
41952 struct mirror_set *ms;
41953- atomic_t error_count;
41954+ atomic_unchecked_t error_count;
41955 unsigned long error_type;
41956 struct dm_dev *dev;
41957 sector_t offset;
41958@@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
41959 struct mirror *m;
41960
41961 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
41962- if (!atomic_read(&m->error_count))
41963+ if (!atomic_read_unchecked(&m->error_count))
41964 return m;
41965
41966 return NULL;
41967@@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
41968 * simple way to tell if a device has encountered
41969 * errors.
41970 */
41971- atomic_inc(&m->error_count);
41972+ atomic_inc_unchecked(&m->error_count);
41973
41974 if (test_and_set_bit(error_type, &m->error_type))
41975 return;
41976@@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
41977 struct mirror *m = get_default_mirror(ms);
41978
41979 do {
41980- if (likely(!atomic_read(&m->error_count)))
41981+ if (likely(!atomic_read_unchecked(&m->error_count)))
41982 return m;
41983
41984 if (m-- == ms->mirror)
41985@@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
41986 {
41987 struct mirror *default_mirror = get_default_mirror(m->ms);
41988
41989- return !atomic_read(&default_mirror->error_count);
41990+ return !atomic_read_unchecked(&default_mirror->error_count);
41991 }
41992
41993 static int mirror_available(struct mirror_set *ms, struct bio *bio)
41994@@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
41995 */
41996 if (likely(region_in_sync(ms, region, 1)))
41997 m = choose_mirror(ms, bio->bi_sector);
41998- else if (m && atomic_read(&m->error_count))
41999+ else if (m && atomic_read_unchecked(&m->error_count))
42000 m = NULL;
42001
42002 if (likely(m))
42003@@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
42004 }
42005
42006 ms->mirror[mirror].ms = ms;
42007- atomic_set(&(ms->mirror[mirror].error_count), 0);
42008+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
42009 ms->mirror[mirror].error_type = 0;
42010 ms->mirror[mirror].offset = offset;
42011
42012@@ -1340,7 +1340,7 @@ static void mirror_resume(struct dm_target *ti)
42013 */
42014 static char device_status_char(struct mirror *m)
42015 {
42016- if (!atomic_read(&(m->error_count)))
42017+ if (!atomic_read_unchecked(&(m->error_count)))
42018 return 'A';
42019
42020 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
42021diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
42022index d907ca6..cfb8384 100644
42023--- a/drivers/md/dm-stripe.c
42024+++ b/drivers/md/dm-stripe.c
42025@@ -20,7 +20,7 @@ struct stripe {
42026 struct dm_dev *dev;
42027 sector_t physical_start;
42028
42029- atomic_t error_count;
42030+ atomic_unchecked_t error_count;
42031 };
42032
42033 struct stripe_c {
42034@@ -185,7 +185,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
42035 kfree(sc);
42036 return r;
42037 }
42038- atomic_set(&(sc->stripe[i].error_count), 0);
42039+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
42040 }
42041
42042 ti->private = sc;
42043@@ -326,7 +326,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
42044 DMEMIT("%d ", sc->stripes);
42045 for (i = 0; i < sc->stripes; i++) {
42046 DMEMIT("%s ", sc->stripe[i].dev->name);
42047- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
42048+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
42049 'D' : 'A';
42050 }
42051 buffer[i] = '\0';
42052@@ -371,8 +371,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
42053 */
42054 for (i = 0; i < sc->stripes; i++)
42055 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
42056- atomic_inc(&(sc->stripe[i].error_count));
42057- if (atomic_read(&(sc->stripe[i].error_count)) <
42058+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
42059+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
42060 DM_IO_ERROR_THRESHOLD)
42061 schedule_work(&sc->trigger_event);
42062 }
42063diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
42064index f221812..aca962b 100644
42065--- a/drivers/md/dm-table.c
42066+++ b/drivers/md/dm-table.c
42067@@ -354,7 +354,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
42068 if (!dev_size)
42069 return 0;
42070
42071- if ((start >= dev_size) || (start + len > dev_size)) {
42072+ if ((start >= dev_size) || (len > dev_size - start)) {
42073 DMWARN("%s: %s too small for target: "
42074 "start=%llu, len=%llu, dev_size=%llu",
42075 dm_device_name(ti->table->md), bdevname(bdev, b),
42076diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
42077index 60bce43..9b997d0 100644
42078--- a/drivers/md/dm-thin-metadata.c
42079+++ b/drivers/md/dm-thin-metadata.c
42080@@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
42081 {
42082 pmd->info.tm = pmd->tm;
42083 pmd->info.levels = 2;
42084- pmd->info.value_type.context = pmd->data_sm;
42085+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
42086 pmd->info.value_type.size = sizeof(__le64);
42087 pmd->info.value_type.inc = data_block_inc;
42088 pmd->info.value_type.dec = data_block_dec;
42089@@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
42090
42091 pmd->bl_info.tm = pmd->tm;
42092 pmd->bl_info.levels = 1;
42093- pmd->bl_info.value_type.context = pmd->data_sm;
42094+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
42095 pmd->bl_info.value_type.size = sizeof(__le64);
42096 pmd->bl_info.value_type.inc = data_block_inc;
42097 pmd->bl_info.value_type.dec = data_block_dec;
42098diff --git a/drivers/md/dm.c b/drivers/md/dm.c
42099index 9e39d2b..fb879a7 100644
42100--- a/drivers/md/dm.c
42101+++ b/drivers/md/dm.c
42102@@ -178,9 +178,9 @@ struct mapped_device {
42103 /*
42104 * Event handling.
42105 */
42106- atomic_t event_nr;
42107+ atomic_unchecked_t event_nr;
42108 wait_queue_head_t eventq;
42109- atomic_t uevent_seq;
42110+ atomic_unchecked_t uevent_seq;
42111 struct list_head uevent_list;
42112 spinlock_t uevent_lock; /* Protect access to uevent_list */
42113
42114@@ -1916,8 +1916,8 @@ static struct mapped_device *alloc_dev(int minor)
42115 spin_lock_init(&md->deferred_lock);
42116 atomic_set(&md->holders, 1);
42117 atomic_set(&md->open_count, 0);
42118- atomic_set(&md->event_nr, 0);
42119- atomic_set(&md->uevent_seq, 0);
42120+ atomic_set_unchecked(&md->event_nr, 0);
42121+ atomic_set_unchecked(&md->uevent_seq, 0);
42122 INIT_LIST_HEAD(&md->uevent_list);
42123 spin_lock_init(&md->uevent_lock);
42124
42125@@ -2068,7 +2068,7 @@ static void event_callback(void *context)
42126
42127 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
42128
42129- atomic_inc(&md->event_nr);
42130+ atomic_inc_unchecked(&md->event_nr);
42131 wake_up(&md->eventq);
42132 }
42133
42134@@ -2716,18 +2716,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
42135
42136 uint32_t dm_next_uevent_seq(struct mapped_device *md)
42137 {
42138- return atomic_add_return(1, &md->uevent_seq);
42139+ return atomic_add_return_unchecked(1, &md->uevent_seq);
42140 }
42141
42142 uint32_t dm_get_event_nr(struct mapped_device *md)
42143 {
42144- return atomic_read(&md->event_nr);
42145+ return atomic_read_unchecked(&md->event_nr);
42146 }
42147
42148 int dm_wait_event(struct mapped_device *md, int event_nr)
42149 {
42150 return wait_event_interruptible(md->eventq,
42151- (event_nr != atomic_read(&md->event_nr)));
42152+ (event_nr != atomic_read_unchecked(&md->event_nr)));
42153 }
42154
42155 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
42156diff --git a/drivers/md/md.c b/drivers/md/md.c
42157index 9f13e13..411a5b8 100644
42158--- a/drivers/md/md.c
42159+++ b/drivers/md/md.c
42160@@ -234,10 +234,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
42161 * start build, activate spare
42162 */
42163 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
42164-static atomic_t md_event_count;
42165+static atomic_unchecked_t md_event_count;
42166 void md_new_event(struct mddev *mddev)
42167 {
42168- atomic_inc(&md_event_count);
42169+ atomic_inc_unchecked(&md_event_count);
42170 wake_up(&md_event_waiters);
42171 }
42172 EXPORT_SYMBOL_GPL(md_new_event);
42173@@ -247,7 +247,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
42174 */
42175 static void md_new_event_inintr(struct mddev *mddev)
42176 {
42177- atomic_inc(&md_event_count);
42178+ atomic_inc_unchecked(&md_event_count);
42179 wake_up(&md_event_waiters);
42180 }
42181
42182@@ -1502,7 +1502,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
42183 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
42184 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
42185 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
42186- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
42187+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
42188
42189 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
42190 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
42191@@ -1746,7 +1746,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
42192 else
42193 sb->resync_offset = cpu_to_le64(0);
42194
42195- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
42196+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
42197
42198 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
42199 sb->size = cpu_to_le64(mddev->dev_sectors);
42200@@ -2751,7 +2751,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
42201 static ssize_t
42202 errors_show(struct md_rdev *rdev, char *page)
42203 {
42204- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
42205+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
42206 }
42207
42208 static ssize_t
42209@@ -2760,7 +2760,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
42210 char *e;
42211 unsigned long n = simple_strtoul(buf, &e, 10);
42212 if (*buf && (*e == 0 || *e == '\n')) {
42213- atomic_set(&rdev->corrected_errors, n);
42214+ atomic_set_unchecked(&rdev->corrected_errors, n);
42215 return len;
42216 }
42217 return -EINVAL;
42218@@ -3208,8 +3208,8 @@ int md_rdev_init(struct md_rdev *rdev)
42219 rdev->sb_loaded = 0;
42220 rdev->bb_page = NULL;
42221 atomic_set(&rdev->nr_pending, 0);
42222- atomic_set(&rdev->read_errors, 0);
42223- atomic_set(&rdev->corrected_errors, 0);
42224+ atomic_set_unchecked(&rdev->read_errors, 0);
42225+ atomic_set_unchecked(&rdev->corrected_errors, 0);
42226
42227 INIT_LIST_HEAD(&rdev->same_set);
42228 init_waitqueue_head(&rdev->blocked_wait);
42229@@ -7024,7 +7024,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
42230
42231 spin_unlock(&pers_lock);
42232 seq_printf(seq, "\n");
42233- seq->poll_event = atomic_read(&md_event_count);
42234+ seq->poll_event = atomic_read_unchecked(&md_event_count);
42235 return 0;
42236 }
42237 if (v == (void*)2) {
42238@@ -7127,7 +7127,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
42239 return error;
42240
42241 seq = file->private_data;
42242- seq->poll_event = atomic_read(&md_event_count);
42243+ seq->poll_event = atomic_read_unchecked(&md_event_count);
42244 return error;
42245 }
42246
42247@@ -7141,7 +7141,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
42248 /* always allow read */
42249 mask = POLLIN | POLLRDNORM;
42250
42251- if (seq->poll_event != atomic_read(&md_event_count))
42252+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
42253 mask |= POLLERR | POLLPRI;
42254 return mask;
42255 }
42256@@ -7185,7 +7185,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
42257 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
42258 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
42259 (int)part_stat_read(&disk->part0, sectors[1]) -
42260- atomic_read(&disk->sync_io);
42261+ atomic_read_unchecked(&disk->sync_io);
42262 /* sync IO will cause sync_io to increase before the disk_stats
42263 * as sync_io is counted when a request starts, and
42264 * disk_stats is counted when it completes.
42265diff --git a/drivers/md/md.h b/drivers/md/md.h
42266index 20f02c0..fd8c821 100644
42267--- a/drivers/md/md.h
42268+++ b/drivers/md/md.h
42269@@ -94,13 +94,13 @@ struct md_rdev {
42270 * only maintained for arrays that
42271 * support hot removal
42272 */
42273- atomic_t read_errors; /* number of consecutive read errors that
42274+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
42275 * we have tried to ignore.
42276 */
42277 struct timespec last_read_error; /* monotonic time since our
42278 * last read error
42279 */
42280- atomic_t corrected_errors; /* number of corrected read errors,
42281+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
42282 * for reporting to userspace and storing
42283 * in superblock.
42284 */
42285@@ -442,7 +442,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
42286
42287 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
42288 {
42289- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
42290+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
42291 }
42292
42293 struct md_personality
42294diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
42295index 3e6d115..ffecdeb 100644
42296--- a/drivers/md/persistent-data/dm-space-map.h
42297+++ b/drivers/md/persistent-data/dm-space-map.h
42298@@ -71,6 +71,7 @@ struct dm_space_map {
42299 dm_sm_threshold_fn fn,
42300 void *context);
42301 };
42302+typedef struct dm_space_map __no_const dm_space_map_no_const;
42303
42304 /*----------------------------------------------------------------*/
42305
42306diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
42307index d60412c..8d4c982 100644
42308--- a/drivers/md/raid1.c
42309+++ b/drivers/md/raid1.c
42310@@ -1823,7 +1823,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
42311 if (r1_sync_page_io(rdev, sect, s,
42312 bio->bi_io_vec[idx].bv_page,
42313 READ) != 0)
42314- atomic_add(s, &rdev->corrected_errors);
42315+ atomic_add_unchecked(s, &rdev->corrected_errors);
42316 }
42317 sectors -= s;
42318 sect += s;
42319@@ -2050,7 +2050,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
42320 test_bit(In_sync, &rdev->flags)) {
42321 if (r1_sync_page_io(rdev, sect, s,
42322 conf->tmppage, READ)) {
42323- atomic_add(s, &rdev->corrected_errors);
42324+ atomic_add_unchecked(s, &rdev->corrected_errors);
42325 printk(KERN_INFO
42326 "md/raid1:%s: read error corrected "
42327 "(%d sectors at %llu on %s)\n",
42328diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
42329index df7b0a0..a257495 100644
42330--- a/drivers/md/raid10.c
42331+++ b/drivers/md/raid10.c
42332@@ -1962,7 +1962,7 @@ static void end_sync_read(struct bio *bio, int error)
42333 /* The write handler will notice the lack of
42334 * R10BIO_Uptodate and record any errors etc
42335 */
42336- atomic_add(r10_bio->sectors,
42337+ atomic_add_unchecked(r10_bio->sectors,
42338 &conf->mirrors[d].rdev->corrected_errors);
42339
42340 /* for reconstruct, we always reschedule after a read.
42341@@ -2320,7 +2320,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
42342 {
42343 struct timespec cur_time_mon;
42344 unsigned long hours_since_last;
42345- unsigned int read_errors = atomic_read(&rdev->read_errors);
42346+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
42347
42348 ktime_get_ts(&cur_time_mon);
42349
42350@@ -2342,9 +2342,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
42351 * overflowing the shift of read_errors by hours_since_last.
42352 */
42353 if (hours_since_last >= 8 * sizeof(read_errors))
42354- atomic_set(&rdev->read_errors, 0);
42355+ atomic_set_unchecked(&rdev->read_errors, 0);
42356 else
42357- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
42358+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
42359 }
42360
42361 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
42362@@ -2398,8 +2398,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
42363 return;
42364
42365 check_decay_read_errors(mddev, rdev);
42366- atomic_inc(&rdev->read_errors);
42367- if (atomic_read(&rdev->read_errors) > max_read_errors) {
42368+ atomic_inc_unchecked(&rdev->read_errors);
42369+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
42370 char b[BDEVNAME_SIZE];
42371 bdevname(rdev->bdev, b);
42372
42373@@ -2407,7 +2407,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
42374 "md/raid10:%s: %s: Raid device exceeded "
42375 "read_error threshold [cur %d:max %d]\n",
42376 mdname(mddev), b,
42377- atomic_read(&rdev->read_errors), max_read_errors);
42378+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
42379 printk(KERN_NOTICE
42380 "md/raid10:%s: %s: Failing raid device\n",
42381 mdname(mddev), b);
42382@@ -2562,7 +2562,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
42383 sect +
42384 choose_data_offset(r10_bio, rdev)),
42385 bdevname(rdev->bdev, b));
42386- atomic_add(s, &rdev->corrected_errors);
42387+ atomic_add_unchecked(s, &rdev->corrected_errors);
42388 }
42389
42390 rdev_dec_pending(rdev, mddev);
42391diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
42392index 78ea443..7d57513 100644
42393--- a/drivers/md/raid5.c
42394+++ b/drivers/md/raid5.c
42395@@ -1764,21 +1764,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
42396 mdname(conf->mddev), STRIPE_SECTORS,
42397 (unsigned long long)s,
42398 bdevname(rdev->bdev, b));
42399- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
42400+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
42401 clear_bit(R5_ReadError, &sh->dev[i].flags);
42402 clear_bit(R5_ReWrite, &sh->dev[i].flags);
42403 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
42404 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
42405
42406- if (atomic_read(&rdev->read_errors))
42407- atomic_set(&rdev->read_errors, 0);
42408+ if (atomic_read_unchecked(&rdev->read_errors))
42409+ atomic_set_unchecked(&rdev->read_errors, 0);
42410 } else {
42411 const char *bdn = bdevname(rdev->bdev, b);
42412 int retry = 0;
42413 int set_bad = 0;
42414
42415 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
42416- atomic_inc(&rdev->read_errors);
42417+ atomic_inc_unchecked(&rdev->read_errors);
42418 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
42419 printk_ratelimited(
42420 KERN_WARNING
42421@@ -1806,7 +1806,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
42422 mdname(conf->mddev),
42423 (unsigned long long)s,
42424 bdn);
42425- } else if (atomic_read(&rdev->read_errors)
42426+ } else if (atomic_read_unchecked(&rdev->read_errors)
42427 > conf->max_nr_stripes)
42428 printk(KERN_WARNING
42429 "md/raid:%s: Too many read errors, failing device %s.\n",
42430diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
42431index 401ef64..836e563 100644
42432--- a/drivers/media/dvb-core/dvbdev.c
42433+++ b/drivers/media/dvb-core/dvbdev.c
42434@@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
42435 const struct dvb_device *template, void *priv, int type)
42436 {
42437 struct dvb_device *dvbdev;
42438- struct file_operations *dvbdevfops;
42439+ file_operations_no_const *dvbdevfops;
42440 struct device *clsdev;
42441 int minor;
42442 int id;
42443diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
42444index 9b6c3bb..baeb5c7 100644
42445--- a/drivers/media/dvb-frontends/dib3000.h
42446+++ b/drivers/media/dvb-frontends/dib3000.h
42447@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
42448 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
42449 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
42450 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
42451-};
42452+} __no_const;
42453
42454 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
42455 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
42456diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
42457index ecf21d9..b992428d 100644
42458--- a/drivers/media/pci/cx88/cx88-video.c
42459+++ b/drivers/media/pci/cx88/cx88-video.c
42460@@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
42461
42462 /* ------------------------------------------------------------------ */
42463
42464-static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42465-static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42466-static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42467+static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42468+static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42469+static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42470
42471 module_param_array(video_nr, int, NULL, 0444);
42472 module_param_array(vbi_nr, int, NULL, 0444);
42473diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
42474index c08ae3e..eb59af1 100644
42475--- a/drivers/media/pci/ivtv/ivtv-driver.c
42476+++ b/drivers/media/pci/ivtv/ivtv-driver.c
42477@@ -83,7 +83,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
42478 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
42479
42480 /* ivtv instance counter */
42481-static atomic_t ivtv_instance = ATOMIC_INIT(0);
42482+static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
42483
42484 /* Parameter declarations */
42485 static int cardtype[IVTV_MAX_CARDS];
42486diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
42487index dfd0a21..6bbb465 100644
42488--- a/drivers/media/platform/omap/omap_vout.c
42489+++ b/drivers/media/platform/omap/omap_vout.c
42490@@ -63,7 +63,6 @@ enum omap_vout_channels {
42491 OMAP_VIDEO2,
42492 };
42493
42494-static struct videobuf_queue_ops video_vbq_ops;
42495 /* Variables configurable through module params*/
42496 static u32 video1_numbuffers = 3;
42497 static u32 video2_numbuffers = 3;
42498@@ -1014,6 +1013,12 @@ static int omap_vout_open(struct file *file)
42499 {
42500 struct videobuf_queue *q;
42501 struct omap_vout_device *vout = NULL;
42502+ static struct videobuf_queue_ops video_vbq_ops = {
42503+ .buf_setup = omap_vout_buffer_setup,
42504+ .buf_prepare = omap_vout_buffer_prepare,
42505+ .buf_release = omap_vout_buffer_release,
42506+ .buf_queue = omap_vout_buffer_queue,
42507+ };
42508
42509 vout = video_drvdata(file);
42510 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
42511@@ -1031,10 +1036,6 @@ static int omap_vout_open(struct file *file)
42512 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
42513
42514 q = &vout->vbq;
42515- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
42516- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
42517- video_vbq_ops.buf_release = omap_vout_buffer_release;
42518- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
42519 spin_lock_init(&vout->vbq_lock);
42520
42521 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
42522diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
42523index 04e6490..2df65bf 100644
42524--- a/drivers/media/platform/s5p-tv/mixer.h
42525+++ b/drivers/media/platform/s5p-tv/mixer.h
42526@@ -156,7 +156,7 @@ struct mxr_layer {
42527 /** layer index (unique identifier) */
42528 int idx;
42529 /** callbacks for layer methods */
42530- struct mxr_layer_ops ops;
42531+ struct mxr_layer_ops *ops;
42532 /** format array */
42533 const struct mxr_format **fmt_array;
42534 /** size of format array */
42535diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
42536index b93a21f..2535195 100644
42537--- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
42538+++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
42539@@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
42540 {
42541 struct mxr_layer *layer;
42542 int ret;
42543- struct mxr_layer_ops ops = {
42544+ static struct mxr_layer_ops ops = {
42545 .release = mxr_graph_layer_release,
42546 .buffer_set = mxr_graph_buffer_set,
42547 .stream_set = mxr_graph_stream_set,
42548diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
42549index b713403..53cb5ad 100644
42550--- a/drivers/media/platform/s5p-tv/mixer_reg.c
42551+++ b/drivers/media/platform/s5p-tv/mixer_reg.c
42552@@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
42553 layer->update_buf = next;
42554 }
42555
42556- layer->ops.buffer_set(layer, layer->update_buf);
42557+ layer->ops->buffer_set(layer, layer->update_buf);
42558
42559 if (done && done != layer->shadow_buf)
42560 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
42561diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
42562index 641b1f0..49cff30 100644
42563--- a/drivers/media/platform/s5p-tv/mixer_video.c
42564+++ b/drivers/media/platform/s5p-tv/mixer_video.c
42565@@ -210,7 +210,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
42566 layer->geo.src.height = layer->geo.src.full_height;
42567
42568 mxr_geometry_dump(mdev, &layer->geo);
42569- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
42570+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
42571 mxr_geometry_dump(mdev, &layer->geo);
42572 }
42573
42574@@ -228,7 +228,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
42575 layer->geo.dst.full_width = mbus_fmt.width;
42576 layer->geo.dst.full_height = mbus_fmt.height;
42577 layer->geo.dst.field = mbus_fmt.field;
42578- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
42579+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
42580
42581 mxr_geometry_dump(mdev, &layer->geo);
42582 }
42583@@ -334,7 +334,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
42584 /* set source size to highest accepted value */
42585 geo->src.full_width = max(geo->dst.full_width, pix->width);
42586 geo->src.full_height = max(geo->dst.full_height, pix->height);
42587- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
42588+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
42589 mxr_geometry_dump(mdev, &layer->geo);
42590 /* set cropping to total visible screen */
42591 geo->src.width = pix->width;
42592@@ -342,12 +342,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
42593 geo->src.x_offset = 0;
42594 geo->src.y_offset = 0;
42595 /* assure consistency of geometry */
42596- layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
42597+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
42598 mxr_geometry_dump(mdev, &layer->geo);
42599 /* set full size to lowest possible value */
42600 geo->src.full_width = 0;
42601 geo->src.full_height = 0;
42602- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
42603+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
42604 mxr_geometry_dump(mdev, &layer->geo);
42605
42606 /* returning results */
42607@@ -474,7 +474,7 @@ static int mxr_s_selection(struct file *file, void *fh,
42608 target->width = s->r.width;
42609 target->height = s->r.height;
42610
42611- layer->ops.fix_geometry(layer, stage, s->flags);
42612+ layer->ops->fix_geometry(layer, stage, s->flags);
42613
42614 /* retrieve update selection rectangle */
42615 res.left = target->x_offset;
42616@@ -955,13 +955,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
42617 mxr_output_get(mdev);
42618
42619 mxr_layer_update_output(layer);
42620- layer->ops.format_set(layer);
42621+ layer->ops->format_set(layer);
42622 /* enabling layer in hardware */
42623 spin_lock_irqsave(&layer->enq_slock, flags);
42624 layer->state = MXR_LAYER_STREAMING;
42625 spin_unlock_irqrestore(&layer->enq_slock, flags);
42626
42627- layer->ops.stream_set(layer, MXR_ENABLE);
42628+ layer->ops->stream_set(layer, MXR_ENABLE);
42629 mxr_streamer_get(mdev);
42630
42631 return 0;
42632@@ -1031,7 +1031,7 @@ static int stop_streaming(struct vb2_queue *vq)
42633 spin_unlock_irqrestore(&layer->enq_slock, flags);
42634
42635 /* disabling layer in hardware */
42636- layer->ops.stream_set(layer, MXR_DISABLE);
42637+ layer->ops->stream_set(layer, MXR_DISABLE);
42638 /* remove one streamer */
42639 mxr_streamer_put(mdev);
42640 /* allow changes in output configuration */
42641@@ -1070,8 +1070,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
42642
42643 void mxr_layer_release(struct mxr_layer *layer)
42644 {
42645- if (layer->ops.release)
42646- layer->ops.release(layer);
42647+ if (layer->ops->release)
42648+ layer->ops->release(layer);
42649 }
42650
42651 void mxr_base_layer_release(struct mxr_layer *layer)
42652@@ -1097,7 +1097,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
42653
42654 layer->mdev = mdev;
42655 layer->idx = idx;
42656- layer->ops = *ops;
42657+ layer->ops = ops;
42658
42659 spin_lock_init(&layer->enq_slock);
42660 INIT_LIST_HEAD(&layer->enq_list);
42661diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
42662index 3d13a63..da31bf1 100644
42663--- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
42664+++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
42665@@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
42666 {
42667 struct mxr_layer *layer;
42668 int ret;
42669- struct mxr_layer_ops ops = {
42670+ static struct mxr_layer_ops ops = {
42671 .release = mxr_vp_layer_release,
42672 .buffer_set = mxr_vp_buffer_set,
42673 .stream_set = mxr_vp_stream_set,
42674diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
42675index 545c04c..a14bded 100644
42676--- a/drivers/media/radio/radio-cadet.c
42677+++ b/drivers/media/radio/radio-cadet.c
42678@@ -324,6 +324,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
42679 unsigned char readbuf[RDS_BUFFER];
42680 int i = 0;
42681
42682+ if (count > RDS_BUFFER)
42683+ return -EFAULT;
42684 mutex_lock(&dev->lock);
42685 if (dev->rdsstat == 0)
42686 cadet_start_rds(dev);
42687@@ -339,7 +341,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
42688 while (i < count && dev->rdsin != dev->rdsout)
42689 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
42690
42691- if (i && copy_to_user(data, readbuf, i))
42692+ if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
42693 i = -EFAULT;
42694 unlock:
42695 mutex_unlock(&dev->lock);
42696diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
42697index bd4d3a7..ffc0b9d 100644
42698--- a/drivers/media/radio/radio-maxiradio.c
42699+++ b/drivers/media/radio/radio-maxiradio.c
42700@@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
42701 /* TEA5757 pin mappings */
42702 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
42703
42704-static atomic_t maxiradio_instance = ATOMIC_INIT(0);
42705+static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
42706
42707 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
42708 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
42709diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
42710index 8fa18ab..caee70f 100644
42711--- a/drivers/media/radio/radio-shark.c
42712+++ b/drivers/media/radio/radio-shark.c
42713@@ -79,7 +79,7 @@ struct shark_device {
42714 u32 last_val;
42715 };
42716
42717-static atomic_t shark_instance = ATOMIC_INIT(0);
42718+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
42719
42720 static void shark_write_val(struct snd_tea575x *tea, u32 val)
42721 {
42722diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
42723index 9fb6697..f167415 100644
42724--- a/drivers/media/radio/radio-shark2.c
42725+++ b/drivers/media/radio/radio-shark2.c
42726@@ -74,7 +74,7 @@ struct shark_device {
42727 u8 *transfer_buffer;
42728 };
42729
42730-static atomic_t shark_instance = ATOMIC_INIT(0);
42731+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
42732
42733 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
42734 {
42735diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
42736index 9c9084c..a9e8dfb 100644
42737--- a/drivers/media/radio/radio-si476x.c
42738+++ b/drivers/media/radio/radio-si476x.c
42739@@ -1445,7 +1445,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
42740 struct si476x_radio *radio;
42741 struct v4l2_ctrl *ctrl;
42742
42743- static atomic_t instance = ATOMIC_INIT(0);
42744+ static atomic_unchecked_t instance = ATOMIC_INIT(0);
42745
42746 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
42747 if (!radio)
42748diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
42749index 1cf382a..c22998c 100644
42750--- a/drivers/media/rc/rc-main.c
42751+++ b/drivers/media/rc/rc-main.c
42752@@ -1030,7 +1030,7 @@ EXPORT_SYMBOL_GPL(rc_free_device);
42753 int rc_register_device(struct rc_dev *dev)
42754 {
42755 static bool raw_init = false; /* raw decoders loaded? */
42756- static atomic_t devno = ATOMIC_INIT(0);
42757+ static atomic_unchecked_t devno = ATOMIC_INIT(0);
42758 struct rc_map *rc_map;
42759 const char *path;
42760 int rc;
42761@@ -1061,7 +1061,7 @@ int rc_register_device(struct rc_dev *dev)
42762 */
42763 mutex_lock(&dev->lock);
42764
42765- dev->devno = (unsigned long)(atomic_inc_return(&devno) - 1);
42766+ dev->devno = (unsigned long)(atomic_inc_return_unchecked(&devno) - 1);
42767 dev_set_name(&dev->dev, "rc%ld", dev->devno);
42768 dev_set_drvdata(&dev->dev, dev);
42769 rc = device_add(&dev->dev);
42770diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
42771index 3940bb0..fb3952a 100644
42772--- a/drivers/media/usb/dvb-usb/cxusb.c
42773+++ b/drivers/media/usb/dvb-usb/cxusb.c
42774@@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
42775
42776 struct dib0700_adapter_state {
42777 int (*set_param_save) (struct dvb_frontend *);
42778-};
42779+} __no_const;
42780
42781 static int dib7070_set_param_override(struct dvb_frontend *fe)
42782 {
42783diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
42784index 6e237b6..dc25556 100644
42785--- a/drivers/media/usb/dvb-usb/dw2102.c
42786+++ b/drivers/media/usb/dvb-usb/dw2102.c
42787@@ -118,7 +118,7 @@ struct su3000_state {
42788
42789 struct s6x0_state {
42790 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
42791-};
42792+} __no_const;
42793
42794 /* debug */
42795 static int dvb_usb_dw2102_debug;
42796diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
42797index 8f7a6a4..59502dd 100644
42798--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
42799+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
42800@@ -326,7 +326,7 @@ struct v4l2_buffer32 {
42801 __u32 reserved;
42802 };
42803
42804-static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
42805+static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
42806 enum v4l2_memory memory)
42807 {
42808 void __user *up_pln;
42809@@ -355,7 +355,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
42810 return 0;
42811 }
42812
42813-static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
42814+static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
42815 enum v4l2_memory memory)
42816 {
42817 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
42818@@ -772,7 +772,7 @@ static int put_v4l2_subdev_edid32(struct v4l2_subdev_edid *kp, struct v4l2_subde
42819 put_user(kp->start_block, &up->start_block) ||
42820 put_user(kp->blocks, &up->blocks) ||
42821 put_user(tmp, &up->edid) ||
42822- copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
42823+ copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
42824 return -EFAULT;
42825 return 0;
42826 }
42827diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
42828index 02d1b63..5fd6b16 100644
42829--- a/drivers/media/v4l2-core/v4l2-device.c
42830+++ b/drivers/media/v4l2-core/v4l2-device.c
42831@@ -75,9 +75,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
42832 EXPORT_SYMBOL_GPL(v4l2_device_put);
42833
42834 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
42835- atomic_t *instance)
42836+ atomic_unchecked_t *instance)
42837 {
42838- int num = atomic_inc_return(instance) - 1;
42839+ int num = atomic_inc_return_unchecked(instance) - 1;
42840 int len = strlen(basename);
42841
42842 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
42843diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
42844index 68e6b5e..d8b923e 100644
42845--- a/drivers/media/v4l2-core/v4l2-ioctl.c
42846+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
42847@@ -1939,7 +1939,8 @@ struct v4l2_ioctl_info {
42848 struct file *file, void *fh, void *p);
42849 } u;
42850 void (*debug)(const void *arg, bool write_only);
42851-};
42852+} __do_const;
42853+typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
42854
42855 /* This control needs a priority check */
42856 #define INFO_FL_PRIO (1 << 0)
42857@@ -2120,7 +2121,7 @@ static long __video_do_ioctl(struct file *file,
42858 struct video_device *vfd = video_devdata(file);
42859 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
42860 bool write_only = false;
42861- struct v4l2_ioctl_info default_info;
42862+ v4l2_ioctl_info_no_const default_info;
42863 const struct v4l2_ioctl_info *info;
42864 void *fh = file->private_data;
42865 struct v4l2_fh *vfh = NULL;
42866@@ -2194,7 +2195,7 @@ done:
42867 }
42868
42869 static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
42870- void * __user *user_ptr, void ***kernel_ptr)
42871+ void __user **user_ptr, void ***kernel_ptr)
42872 {
42873 int ret = 0;
42874
42875@@ -2210,7 +2211,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
42876 ret = -EINVAL;
42877 break;
42878 }
42879- *user_ptr = (void __user *)buf->m.planes;
42880+ *user_ptr = (void __force_user *)buf->m.planes;
42881 *kernel_ptr = (void *)&buf->m.planes;
42882 *array_size = sizeof(struct v4l2_plane) * buf->length;
42883 ret = 1;
42884@@ -2245,7 +2246,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
42885 ret = -EINVAL;
42886 break;
42887 }
42888- *user_ptr = (void __user *)ctrls->controls;
42889+ *user_ptr = (void __force_user *)ctrls->controls;
42890 *kernel_ptr = (void *)&ctrls->controls;
42891 *array_size = sizeof(struct v4l2_ext_control)
42892 * ctrls->count;
42893diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
42894index 767ff4d..c69d259 100644
42895--- a/drivers/message/fusion/mptbase.c
42896+++ b/drivers/message/fusion/mptbase.c
42897@@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
42898 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
42899 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
42900
42901+#ifdef CONFIG_GRKERNSEC_HIDESYM
42902+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
42903+#else
42904 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
42905 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
42906+#endif
42907+
42908 /*
42909 * Rounding UP to nearest 4-kB boundary here...
42910 */
42911@@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
42912 ioc->facts.GlobalCredits);
42913
42914 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
42915+#ifdef CONFIG_GRKERNSEC_HIDESYM
42916+ NULL, NULL);
42917+#else
42918 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
42919+#endif
42920 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
42921 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
42922 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
42923diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
42924index dd239bd..689c4f7 100644
42925--- a/drivers/message/fusion/mptsas.c
42926+++ b/drivers/message/fusion/mptsas.c
42927@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
42928 return 0;
42929 }
42930
42931+static inline void
42932+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
42933+{
42934+ if (phy_info->port_details) {
42935+ phy_info->port_details->rphy = rphy;
42936+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
42937+ ioc->name, rphy));
42938+ }
42939+
42940+ if (rphy) {
42941+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
42942+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
42943+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
42944+ ioc->name, rphy, rphy->dev.release));
42945+ }
42946+}
42947+
42948 /* no mutex */
42949 static void
42950 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
42951@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
42952 return NULL;
42953 }
42954
42955-static inline void
42956-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
42957-{
42958- if (phy_info->port_details) {
42959- phy_info->port_details->rphy = rphy;
42960- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
42961- ioc->name, rphy));
42962- }
42963-
42964- if (rphy) {
42965- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
42966- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
42967- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
42968- ioc->name, rphy, rphy->dev.release));
42969- }
42970-}
42971-
42972 static inline struct sas_port *
42973 mptsas_get_port(struct mptsas_phyinfo *phy_info)
42974 {
42975diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
42976index 727819c..ad74694 100644
42977--- a/drivers/message/fusion/mptscsih.c
42978+++ b/drivers/message/fusion/mptscsih.c
42979@@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
42980
42981 h = shost_priv(SChost);
42982
42983- if (h) {
42984- if (h->info_kbuf == NULL)
42985- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
42986- return h->info_kbuf;
42987- h->info_kbuf[0] = '\0';
42988+ if (!h)
42989+ return NULL;
42990
42991- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
42992- h->info_kbuf[size-1] = '\0';
42993- }
42994+ if (h->info_kbuf == NULL)
42995+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
42996+ return h->info_kbuf;
42997+ h->info_kbuf[0] = '\0';
42998+
42999+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
43000+ h->info_kbuf[size-1] = '\0';
43001
43002 return h->info_kbuf;
43003 }
43004diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
43005index b7d87cd..9890039 100644
43006--- a/drivers/message/i2o/i2o_proc.c
43007+++ b/drivers/message/i2o/i2o_proc.c
43008@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
43009 "Array Controller Device"
43010 };
43011
43012-static char *chtostr(char *tmp, u8 *chars, int n)
43013-{
43014- tmp[0] = 0;
43015- return strncat(tmp, (char *)chars, n);
43016-}
43017-
43018 static int i2o_report_query_status(struct seq_file *seq, int block_status,
43019 char *group)
43020 {
43021@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
43022 } *result;
43023
43024 i2o_exec_execute_ddm_table ddm_table;
43025- char tmp[28 + 1];
43026
43027 result = kmalloc(sizeof(*result), GFP_KERNEL);
43028 if (!result)
43029@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
43030
43031 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
43032 seq_printf(seq, "%-#8x", ddm_table.module_id);
43033- seq_printf(seq, "%-29s",
43034- chtostr(tmp, ddm_table.module_name_version, 28));
43035+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
43036 seq_printf(seq, "%9d ", ddm_table.data_size);
43037 seq_printf(seq, "%8d", ddm_table.code_size);
43038
43039@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
43040
43041 i2o_driver_result_table *result;
43042 i2o_driver_store_table *dst;
43043- char tmp[28 + 1];
43044
43045 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
43046 if (result == NULL)
43047@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
43048
43049 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
43050 seq_printf(seq, "%-#8x", dst->module_id);
43051- seq_printf(seq, "%-29s",
43052- chtostr(tmp, dst->module_name_version, 28));
43053- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
43054+ seq_printf(seq, "%-.28s", dst->module_name_version);
43055+ seq_printf(seq, "%-.8s", dst->date);
43056 seq_printf(seq, "%8d ", dst->module_size);
43057 seq_printf(seq, "%8d ", dst->mpb_size);
43058 seq_printf(seq, "0x%04x", dst->module_flags);
43059@@ -1250,7 +1240,6 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
43060 // == (allow) 512d bytes (max)
43061 static u16 *work16 = (u16 *) work32;
43062 int token;
43063- char tmp[16 + 1];
43064
43065 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
43066
43067@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
43068 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
43069 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
43070 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
43071- seq_printf(seq, "Vendor info : %s\n",
43072- chtostr(tmp, (u8 *) (work32 + 2), 16));
43073- seq_printf(seq, "Product info : %s\n",
43074- chtostr(tmp, (u8 *) (work32 + 6), 16));
43075- seq_printf(seq, "Description : %s\n",
43076- chtostr(tmp, (u8 *) (work32 + 10), 16));
43077- seq_printf(seq, "Product rev. : %s\n",
43078- chtostr(tmp, (u8 *) (work32 + 14), 8));
43079+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
43080+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
43081+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
43082+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
43083
43084 seq_printf(seq, "Serial number : ");
43085 print_serial_number(seq, (u8 *) (work32 + 16),
43086@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
43087 u8 pad[256]; // allow up to 256 byte (max) serial number
43088 } result;
43089
43090- char tmp[24 + 1];
43091-
43092 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
43093
43094 if (token < 0) {
43095@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
43096 }
43097
43098 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
43099- seq_printf(seq, "Module name : %s\n",
43100- chtostr(tmp, result.module_name, 24));
43101- seq_printf(seq, "Module revision : %s\n",
43102- chtostr(tmp, result.module_rev, 8));
43103+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
43104+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
43105
43106 seq_printf(seq, "Serial number : ");
43107 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
43108@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
43109 u8 instance_number[4];
43110 } result;
43111
43112- char tmp[64 + 1];
43113-
43114 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
43115
43116 if (token < 0) {
43117@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
43118 return 0;
43119 }
43120
43121- seq_printf(seq, "Device name : %s\n",
43122- chtostr(tmp, result.device_name, 64));
43123- seq_printf(seq, "Service name : %s\n",
43124- chtostr(tmp, result.service_name, 64));
43125- seq_printf(seq, "Physical name : %s\n",
43126- chtostr(tmp, result.physical_location, 64));
43127- seq_printf(seq, "Instance number : %s\n",
43128- chtostr(tmp, result.instance_number, 4));
43129+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
43130+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
43131+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
43132+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
43133
43134 return 0;
43135 }
43136diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
43137index a8c08f3..155fe3d 100644
43138--- a/drivers/message/i2o/iop.c
43139+++ b/drivers/message/i2o/iop.c
43140@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
43141
43142 spin_lock_irqsave(&c->context_list_lock, flags);
43143
43144- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
43145- atomic_inc(&c->context_list_counter);
43146+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
43147+ atomic_inc_unchecked(&c->context_list_counter);
43148
43149- entry->context = atomic_read(&c->context_list_counter);
43150+ entry->context = atomic_read_unchecked(&c->context_list_counter);
43151
43152 list_add(&entry->list, &c->context_list);
43153
43154@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
43155
43156 #if BITS_PER_LONG == 64
43157 spin_lock_init(&c->context_list_lock);
43158- atomic_set(&c->context_list_counter, 0);
43159+ atomic_set_unchecked(&c->context_list_counter, 0);
43160 INIT_LIST_HEAD(&c->context_list);
43161 #endif
43162
43163diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
43164index fcbb2e9..2635e11 100644
43165--- a/drivers/mfd/janz-cmodio.c
43166+++ b/drivers/mfd/janz-cmodio.c
43167@@ -13,6 +13,7 @@
43168
43169 #include <linux/kernel.h>
43170 #include <linux/module.h>
43171+#include <linux/slab.h>
43172 #include <linux/init.h>
43173 #include <linux/pci.h>
43174 #include <linux/interrupt.h>
43175diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
43176index 9aa6d1e..1631bfc 100644
43177--- a/drivers/mfd/twl4030-irq.c
43178+++ b/drivers/mfd/twl4030-irq.c
43179@@ -35,6 +35,7 @@
43180 #include <linux/of.h>
43181 #include <linux/irqdomain.h>
43182 #include <linux/i2c/twl.h>
43183+#include <asm/pgtable.h>
43184
43185 #include "twl-core.h"
43186
43187@@ -726,10 +727,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
43188 * Install an irq handler for each of the SIH modules;
43189 * clone dummy irq_chip since PIH can't *do* anything
43190 */
43191- twl4030_irq_chip = dummy_irq_chip;
43192- twl4030_irq_chip.name = "twl4030";
43193+ pax_open_kernel();
43194+ memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
43195+ *(const char **)&twl4030_irq_chip.name = "twl4030";
43196
43197- twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
43198+ *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
43199+ pax_close_kernel();
43200
43201 for (i = irq_base; i < irq_end; i++) {
43202 irq_set_chip_and_handler(i, &twl4030_irq_chip,
43203diff --git a/drivers/mfd/twl6030-irq.c b/drivers/mfd/twl6030-irq.c
43204index 277a8db..0e0b754 100644
43205--- a/drivers/mfd/twl6030-irq.c
43206+++ b/drivers/mfd/twl6030-irq.c
43207@@ -387,10 +387,12 @@ int twl6030_init_irq(struct device *dev, int irq_num)
43208 * install an irq handler for each of the modules;
43209 * clone dummy irq_chip since PIH can't *do* anything
43210 */
43211- twl6030_irq_chip = dummy_irq_chip;
43212- twl6030_irq_chip.name = "twl6030";
43213- twl6030_irq_chip.irq_set_type = NULL;
43214- twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake;
43215+ pax_open_kernel();
43216+ memcpy((void *)&twl6030_irq_chip, &dummy_irq_chip, sizeof twl6030_irq_chip);
43217+ *(const char **)&twl6030_irq_chip.name = "twl6030";
43218+ *(void **)&twl6030_irq_chip.irq_set_type = NULL;
43219+ *(void **)&twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake;
43220+ pax_close_kernel();
43221
43222 for (i = irq_base; i < irq_end; i++) {
43223 irq_set_chip_and_handler(i, &twl6030_irq_chip,
43224diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
43225index f32550a..e3e52a2 100644
43226--- a/drivers/misc/c2port/core.c
43227+++ b/drivers/misc/c2port/core.c
43228@@ -920,7 +920,9 @@ struct c2port_device *c2port_device_register(char *name,
43229 mutex_init(&c2dev->mutex);
43230
43231 /* Create binary file */
43232- c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
43233+ pax_open_kernel();
43234+ *(size_t *)&c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
43235+ pax_close_kernel();
43236 ret = device_create_bin_file(c2dev->dev, &c2port_bin_attrs);
43237 if (unlikely(ret))
43238 goto error_device_create_bin_file;
43239diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
43240index 36f5d52..32311c3 100644
43241--- a/drivers/misc/kgdbts.c
43242+++ b/drivers/misc/kgdbts.c
43243@@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
43244 char before[BREAK_INSTR_SIZE];
43245 char after[BREAK_INSTR_SIZE];
43246
43247- probe_kernel_read(before, (char *)kgdbts_break_test,
43248+ probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
43249 BREAK_INSTR_SIZE);
43250 init_simple_test();
43251 ts.tst = plant_and_detach_test;
43252@@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
43253 /* Activate test with initial breakpoint */
43254 if (!is_early)
43255 kgdb_breakpoint();
43256- probe_kernel_read(after, (char *)kgdbts_break_test,
43257+ probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
43258 BREAK_INSTR_SIZE);
43259 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
43260 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
43261diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
43262index 036effe..b3a6336 100644
43263--- a/drivers/misc/lis3lv02d/lis3lv02d.c
43264+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
43265@@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
43266 * the lid is closed. This leads to interrupts as soon as a little move
43267 * is done.
43268 */
43269- atomic_inc(&lis3->count);
43270+ atomic_inc_unchecked(&lis3->count);
43271
43272 wake_up_interruptible(&lis3->misc_wait);
43273 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
43274@@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
43275 if (lis3->pm_dev)
43276 pm_runtime_get_sync(lis3->pm_dev);
43277
43278- atomic_set(&lis3->count, 0);
43279+ atomic_set_unchecked(&lis3->count, 0);
43280 return 0;
43281 }
43282
43283@@ -616,7 +616,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
43284 add_wait_queue(&lis3->misc_wait, &wait);
43285 while (true) {
43286 set_current_state(TASK_INTERRUPTIBLE);
43287- data = atomic_xchg(&lis3->count, 0);
43288+ data = atomic_xchg_unchecked(&lis3->count, 0);
43289 if (data)
43290 break;
43291
43292@@ -657,7 +657,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
43293 struct lis3lv02d, miscdev);
43294
43295 poll_wait(file, &lis3->misc_wait, wait);
43296- if (atomic_read(&lis3->count))
43297+ if (atomic_read_unchecked(&lis3->count))
43298 return POLLIN | POLLRDNORM;
43299 return 0;
43300 }
43301diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
43302index c439c82..1f20f57 100644
43303--- a/drivers/misc/lis3lv02d/lis3lv02d.h
43304+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
43305@@ -297,7 +297,7 @@ struct lis3lv02d {
43306 struct input_polled_dev *idev; /* input device */
43307 struct platform_device *pdev; /* platform device */
43308 struct regulator_bulk_data regulators[2];
43309- atomic_t count; /* interrupt count after last read */
43310+ atomic_unchecked_t count; /* interrupt count after last read */
43311 union axis_conversion ac; /* hw -> logical axis */
43312 int mapped_btns[3];
43313
43314diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
43315index 2f30bad..c4c13d0 100644
43316--- a/drivers/misc/sgi-gru/gruhandles.c
43317+++ b/drivers/misc/sgi-gru/gruhandles.c
43318@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
43319 unsigned long nsec;
43320
43321 nsec = CLKS2NSEC(clks);
43322- atomic_long_inc(&mcs_op_statistics[op].count);
43323- atomic_long_add(nsec, &mcs_op_statistics[op].total);
43324+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
43325+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
43326 if (mcs_op_statistics[op].max < nsec)
43327 mcs_op_statistics[op].max = nsec;
43328 }
43329diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
43330index 4f76359..cdfcb2e 100644
43331--- a/drivers/misc/sgi-gru/gruprocfs.c
43332+++ b/drivers/misc/sgi-gru/gruprocfs.c
43333@@ -32,9 +32,9 @@
43334
43335 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
43336
43337-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
43338+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
43339 {
43340- unsigned long val = atomic_long_read(v);
43341+ unsigned long val = atomic_long_read_unchecked(v);
43342
43343 seq_printf(s, "%16lu %s\n", val, id);
43344 }
43345@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
43346
43347 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
43348 for (op = 0; op < mcsop_last; op++) {
43349- count = atomic_long_read(&mcs_op_statistics[op].count);
43350- total = atomic_long_read(&mcs_op_statistics[op].total);
43351+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
43352+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
43353 max = mcs_op_statistics[op].max;
43354 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
43355 count ? total / count : 0, max);
43356diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
43357index 5c3ce24..4915ccb 100644
43358--- a/drivers/misc/sgi-gru/grutables.h
43359+++ b/drivers/misc/sgi-gru/grutables.h
43360@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
43361 * GRU statistics.
43362 */
43363 struct gru_stats_s {
43364- atomic_long_t vdata_alloc;
43365- atomic_long_t vdata_free;
43366- atomic_long_t gts_alloc;
43367- atomic_long_t gts_free;
43368- atomic_long_t gms_alloc;
43369- atomic_long_t gms_free;
43370- atomic_long_t gts_double_allocate;
43371- atomic_long_t assign_context;
43372- atomic_long_t assign_context_failed;
43373- atomic_long_t free_context;
43374- atomic_long_t load_user_context;
43375- atomic_long_t load_kernel_context;
43376- atomic_long_t lock_kernel_context;
43377- atomic_long_t unlock_kernel_context;
43378- atomic_long_t steal_user_context;
43379- atomic_long_t steal_kernel_context;
43380- atomic_long_t steal_context_failed;
43381- atomic_long_t nopfn;
43382- atomic_long_t asid_new;
43383- atomic_long_t asid_next;
43384- atomic_long_t asid_wrap;
43385- atomic_long_t asid_reuse;
43386- atomic_long_t intr;
43387- atomic_long_t intr_cbr;
43388- atomic_long_t intr_tfh;
43389- atomic_long_t intr_spurious;
43390- atomic_long_t intr_mm_lock_failed;
43391- atomic_long_t call_os;
43392- atomic_long_t call_os_wait_queue;
43393- atomic_long_t user_flush_tlb;
43394- atomic_long_t user_unload_context;
43395- atomic_long_t user_exception;
43396- atomic_long_t set_context_option;
43397- atomic_long_t check_context_retarget_intr;
43398- atomic_long_t check_context_unload;
43399- atomic_long_t tlb_dropin;
43400- atomic_long_t tlb_preload_page;
43401- atomic_long_t tlb_dropin_fail_no_asid;
43402- atomic_long_t tlb_dropin_fail_upm;
43403- atomic_long_t tlb_dropin_fail_invalid;
43404- atomic_long_t tlb_dropin_fail_range_active;
43405- atomic_long_t tlb_dropin_fail_idle;
43406- atomic_long_t tlb_dropin_fail_fmm;
43407- atomic_long_t tlb_dropin_fail_no_exception;
43408- atomic_long_t tfh_stale_on_fault;
43409- atomic_long_t mmu_invalidate_range;
43410- atomic_long_t mmu_invalidate_page;
43411- atomic_long_t flush_tlb;
43412- atomic_long_t flush_tlb_gru;
43413- atomic_long_t flush_tlb_gru_tgh;
43414- atomic_long_t flush_tlb_gru_zero_asid;
43415+ atomic_long_unchecked_t vdata_alloc;
43416+ atomic_long_unchecked_t vdata_free;
43417+ atomic_long_unchecked_t gts_alloc;
43418+ atomic_long_unchecked_t gts_free;
43419+ atomic_long_unchecked_t gms_alloc;
43420+ atomic_long_unchecked_t gms_free;
43421+ atomic_long_unchecked_t gts_double_allocate;
43422+ atomic_long_unchecked_t assign_context;
43423+ atomic_long_unchecked_t assign_context_failed;
43424+ atomic_long_unchecked_t free_context;
43425+ atomic_long_unchecked_t load_user_context;
43426+ atomic_long_unchecked_t load_kernel_context;
43427+ atomic_long_unchecked_t lock_kernel_context;
43428+ atomic_long_unchecked_t unlock_kernel_context;
43429+ atomic_long_unchecked_t steal_user_context;
43430+ atomic_long_unchecked_t steal_kernel_context;
43431+ atomic_long_unchecked_t steal_context_failed;
43432+ atomic_long_unchecked_t nopfn;
43433+ atomic_long_unchecked_t asid_new;
43434+ atomic_long_unchecked_t asid_next;
43435+ atomic_long_unchecked_t asid_wrap;
43436+ atomic_long_unchecked_t asid_reuse;
43437+ atomic_long_unchecked_t intr;
43438+ atomic_long_unchecked_t intr_cbr;
43439+ atomic_long_unchecked_t intr_tfh;
43440+ atomic_long_unchecked_t intr_spurious;
43441+ atomic_long_unchecked_t intr_mm_lock_failed;
43442+ atomic_long_unchecked_t call_os;
43443+ atomic_long_unchecked_t call_os_wait_queue;
43444+ atomic_long_unchecked_t user_flush_tlb;
43445+ atomic_long_unchecked_t user_unload_context;
43446+ atomic_long_unchecked_t user_exception;
43447+ atomic_long_unchecked_t set_context_option;
43448+ atomic_long_unchecked_t check_context_retarget_intr;
43449+ atomic_long_unchecked_t check_context_unload;
43450+ atomic_long_unchecked_t tlb_dropin;
43451+ atomic_long_unchecked_t tlb_preload_page;
43452+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
43453+ atomic_long_unchecked_t tlb_dropin_fail_upm;
43454+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
43455+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
43456+ atomic_long_unchecked_t tlb_dropin_fail_idle;
43457+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
43458+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
43459+ atomic_long_unchecked_t tfh_stale_on_fault;
43460+ atomic_long_unchecked_t mmu_invalidate_range;
43461+ atomic_long_unchecked_t mmu_invalidate_page;
43462+ atomic_long_unchecked_t flush_tlb;
43463+ atomic_long_unchecked_t flush_tlb_gru;
43464+ atomic_long_unchecked_t flush_tlb_gru_tgh;
43465+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
43466
43467- atomic_long_t copy_gpa;
43468- atomic_long_t read_gpa;
43469+ atomic_long_unchecked_t copy_gpa;
43470+ atomic_long_unchecked_t read_gpa;
43471
43472- atomic_long_t mesq_receive;
43473- atomic_long_t mesq_receive_none;
43474- atomic_long_t mesq_send;
43475- atomic_long_t mesq_send_failed;
43476- atomic_long_t mesq_noop;
43477- atomic_long_t mesq_send_unexpected_error;
43478- atomic_long_t mesq_send_lb_overflow;
43479- atomic_long_t mesq_send_qlimit_reached;
43480- atomic_long_t mesq_send_amo_nacked;
43481- atomic_long_t mesq_send_put_nacked;
43482- atomic_long_t mesq_page_overflow;
43483- atomic_long_t mesq_qf_locked;
43484- atomic_long_t mesq_qf_noop_not_full;
43485- atomic_long_t mesq_qf_switch_head_failed;
43486- atomic_long_t mesq_qf_unexpected_error;
43487- atomic_long_t mesq_noop_unexpected_error;
43488- atomic_long_t mesq_noop_lb_overflow;
43489- atomic_long_t mesq_noop_qlimit_reached;
43490- atomic_long_t mesq_noop_amo_nacked;
43491- atomic_long_t mesq_noop_put_nacked;
43492- atomic_long_t mesq_noop_page_overflow;
43493+ atomic_long_unchecked_t mesq_receive;
43494+ atomic_long_unchecked_t mesq_receive_none;
43495+ atomic_long_unchecked_t mesq_send;
43496+ atomic_long_unchecked_t mesq_send_failed;
43497+ atomic_long_unchecked_t mesq_noop;
43498+ atomic_long_unchecked_t mesq_send_unexpected_error;
43499+ atomic_long_unchecked_t mesq_send_lb_overflow;
43500+ atomic_long_unchecked_t mesq_send_qlimit_reached;
43501+ atomic_long_unchecked_t mesq_send_amo_nacked;
43502+ atomic_long_unchecked_t mesq_send_put_nacked;
43503+ atomic_long_unchecked_t mesq_page_overflow;
43504+ atomic_long_unchecked_t mesq_qf_locked;
43505+ atomic_long_unchecked_t mesq_qf_noop_not_full;
43506+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
43507+ atomic_long_unchecked_t mesq_qf_unexpected_error;
43508+ atomic_long_unchecked_t mesq_noop_unexpected_error;
43509+ atomic_long_unchecked_t mesq_noop_lb_overflow;
43510+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
43511+ atomic_long_unchecked_t mesq_noop_amo_nacked;
43512+ atomic_long_unchecked_t mesq_noop_put_nacked;
43513+ atomic_long_unchecked_t mesq_noop_page_overflow;
43514
43515 };
43516
43517@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
43518 tghop_invalidate, mcsop_last};
43519
43520 struct mcs_op_statistic {
43521- atomic_long_t count;
43522- atomic_long_t total;
43523+ atomic_long_unchecked_t count;
43524+ atomic_long_unchecked_t total;
43525 unsigned long max;
43526 };
43527
43528@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
43529
43530 #define STAT(id) do { \
43531 if (gru_options & OPT_STATS) \
43532- atomic_long_inc(&gru_stats.id); \
43533+ atomic_long_inc_unchecked(&gru_stats.id); \
43534 } while (0)
43535
43536 #ifdef CONFIG_SGI_GRU_DEBUG
43537diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
43538index c862cd4..0d176fe 100644
43539--- a/drivers/misc/sgi-xp/xp.h
43540+++ b/drivers/misc/sgi-xp/xp.h
43541@@ -288,7 +288,7 @@ struct xpc_interface {
43542 xpc_notify_func, void *);
43543 void (*received) (short, int, void *);
43544 enum xp_retval (*partid_to_nasids) (short, void *);
43545-};
43546+} __no_const;
43547
43548 extern struct xpc_interface xpc_interface;
43549
43550diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
43551index b94d5f7..7f494c5 100644
43552--- a/drivers/misc/sgi-xp/xpc.h
43553+++ b/drivers/misc/sgi-xp/xpc.h
43554@@ -835,6 +835,7 @@ struct xpc_arch_operations {
43555 void (*received_payload) (struct xpc_channel *, void *);
43556 void (*notify_senders_of_disconnect) (struct xpc_channel *);
43557 };
43558+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
43559
43560 /* struct xpc_partition act_state values (for XPC HB) */
43561
43562@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
43563 /* found in xpc_main.c */
43564 extern struct device *xpc_part;
43565 extern struct device *xpc_chan;
43566-extern struct xpc_arch_operations xpc_arch_ops;
43567+extern xpc_arch_operations_no_const xpc_arch_ops;
43568 extern int xpc_disengage_timelimit;
43569 extern int xpc_disengage_timedout;
43570 extern int xpc_activate_IRQ_rcvd;
43571diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
43572index 82dc574..8539ab2 100644
43573--- a/drivers/misc/sgi-xp/xpc_main.c
43574+++ b/drivers/misc/sgi-xp/xpc_main.c
43575@@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
43576 .notifier_call = xpc_system_die,
43577 };
43578
43579-struct xpc_arch_operations xpc_arch_ops;
43580+xpc_arch_operations_no_const xpc_arch_ops;
43581
43582 /*
43583 * Timer function to enforce the timelimit on the partition disengage.
43584@@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
43585
43586 if (((die_args->trapnr == X86_TRAP_MF) ||
43587 (die_args->trapnr == X86_TRAP_XF)) &&
43588- !user_mode_vm(die_args->regs))
43589+ !user_mode(die_args->regs))
43590 xpc_die_deactivate();
43591
43592 break;
43593diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
43594index 837fc73..acb5862 100644
43595--- a/drivers/mmc/core/mmc_ops.c
43596+++ b/drivers/mmc/core/mmc_ops.c
43597@@ -213,7 +213,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
43598 void *data_buf;
43599 int is_on_stack;
43600
43601- is_on_stack = object_is_on_stack(buf);
43602+ is_on_stack = object_starts_on_stack(buf);
43603 if (is_on_stack) {
43604 /*
43605 * dma onto stack is unsafe/nonportable, but callers to this
43606diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
43607index 81b2994..dce857e 100644
43608--- a/drivers/mmc/host/dw_mmc.h
43609+++ b/drivers/mmc/host/dw_mmc.h
43610@@ -203,5 +203,5 @@ struct dw_mci_drv_data {
43611 void (*prepare_command)(struct dw_mci *host, u32 *cmdr);
43612 void (*set_ios)(struct dw_mci *host, struct mmc_ios *ios);
43613 int (*parse_dt)(struct dw_mci *host);
43614-};
43615+} __do_const;
43616 #endif /* _DW_MMC_H_ */
43617diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
43618index c3785ed..1984c44 100644
43619--- a/drivers/mmc/host/mmci.c
43620+++ b/drivers/mmc/host/mmci.c
43621@@ -1482,7 +1482,9 @@ static int mmci_probe(struct amba_device *dev,
43622 }
43623
43624 if (variant->busy_detect) {
43625- mmci_ops.card_busy = mmci_card_busy;
43626+ pax_open_kernel();
43627+ *(void **)&mmci_ops.card_busy = mmci_card_busy;
43628+ pax_close_kernel();
43629 mmci_write_datactrlreg(host, MCI_ST_DPSM_BUSYMODE);
43630 }
43631
43632diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
43633index 926aaf6..8e153e2 100644
43634--- a/drivers/mmc/host/sdhci-s3c.c
43635+++ b/drivers/mmc/host/sdhci-s3c.c
43636@@ -664,9 +664,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
43637 * we can use overriding functions instead of default.
43638 */
43639 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
43640- sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
43641- sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
43642- sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
43643+ pax_open_kernel();
43644+ *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
43645+ *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
43646+ *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
43647+ pax_close_kernel();
43648 }
43649
43650 /* It supports additional host capabilities if needed */
43651diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
43652index 0c8bb6b..6f35deb 100644
43653--- a/drivers/mtd/nand/denali.c
43654+++ b/drivers/mtd/nand/denali.c
43655@@ -24,6 +24,7 @@
43656 #include <linux/slab.h>
43657 #include <linux/mtd/mtd.h>
43658 #include <linux/module.h>
43659+#include <linux/slab.h>
43660
43661 #include "denali.h"
43662
43663diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
43664index 51b9d6a..52af9a7 100644
43665--- a/drivers/mtd/nftlmount.c
43666+++ b/drivers/mtd/nftlmount.c
43667@@ -24,6 +24,7 @@
43668 #include <asm/errno.h>
43669 #include <linux/delay.h>
43670 #include <linux/slab.h>
43671+#include <linux/sched.h>
43672 #include <linux/mtd/mtd.h>
43673 #include <linux/mtd/nand.h>
43674 #include <linux/mtd/nftl.h>
43675diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
43676index f9d5615..99dd95f 100644
43677--- a/drivers/mtd/sm_ftl.c
43678+++ b/drivers/mtd/sm_ftl.c
43679@@ -56,7 +56,7 @@ ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
43680 #define SM_CIS_VENDOR_OFFSET 0x59
43681 struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
43682 {
43683- struct attribute_group *attr_group;
43684+ attribute_group_no_const *attr_group;
43685 struct attribute **attributes;
43686 struct sm_sysfs_attribute *vendor_attribute;
43687
43688diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
43689index e48cb33..72e73fc 100644
43690--- a/drivers/net/bonding/bond_main.c
43691+++ b/drivers/net/bonding/bond_main.c
43692@@ -4832,7 +4832,7 @@ static unsigned int bond_get_num_tx_queues(void)
43693 return tx_queues;
43694 }
43695
43696-static struct rtnl_link_ops bond_link_ops __read_mostly = {
43697+static struct rtnl_link_ops bond_link_ops = {
43698 .kind = "bond",
43699 .priv_size = sizeof(struct bonding),
43700 .setup = bond_setup,
43701@@ -4957,8 +4957,8 @@ static void __exit bonding_exit(void)
43702
43703 bond_destroy_debugfs();
43704
43705- rtnl_link_unregister(&bond_link_ops);
43706 unregister_pernet_subsys(&bond_net_ops);
43707+ rtnl_link_unregister(&bond_link_ops);
43708
43709 #ifdef CONFIG_NET_POLL_CONTROLLER
43710 /*
43711diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
43712index e1d2643..7f4133b 100644
43713--- a/drivers/net/ethernet/8390/ax88796.c
43714+++ b/drivers/net/ethernet/8390/ax88796.c
43715@@ -872,9 +872,11 @@ static int ax_probe(struct platform_device *pdev)
43716 if (ax->plat->reg_offsets)
43717 ei_local->reg_offset = ax->plat->reg_offsets;
43718 else {
43719+ resource_size_t _mem_size = mem_size;
43720+ do_div(_mem_size, 0x18);
43721 ei_local->reg_offset = ax->reg_offsets;
43722 for (ret = 0; ret < 0x18; ret++)
43723- ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
43724+ ax->reg_offsets[ret] = _mem_size * ret;
43725 }
43726
43727 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
43728diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
43729index c07a6d0..ca88c45 100644
43730--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
43731+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
43732@@ -1137,7 +1137,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
43733 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
43734 {
43735 /* RX_MODE controlling object */
43736- bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
43737+ bnx2x_init_rx_mode_obj(bp);
43738
43739 /* multicast configuration controlling object */
43740 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
43741diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
43742index 8f03c98..dd0ef10 100644
43743--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
43744+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
43745@@ -2345,15 +2345,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
43746 return rc;
43747 }
43748
43749-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
43750- struct bnx2x_rx_mode_obj *o)
43751+void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
43752 {
43753 if (CHIP_IS_E1x(bp)) {
43754- o->wait_comp = bnx2x_empty_rx_mode_wait;
43755- o->config_rx_mode = bnx2x_set_rx_mode_e1x;
43756+ bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
43757+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
43758 } else {
43759- o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
43760- o->config_rx_mode = bnx2x_set_rx_mode_e2;
43761+ bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
43762+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
43763 }
43764 }
43765
43766diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
43767index 798dfe9..05d0a44 100644
43768--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
43769+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
43770@@ -1311,8 +1311,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
43771
43772 /********************* RX MODE ****************/
43773
43774-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
43775- struct bnx2x_rx_mode_obj *o);
43776+void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
43777
43778 /**
43779 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
43780diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
43781index cd63d11..b67dd78 100644
43782--- a/drivers/net/ethernet/broadcom/tg3.h
43783+++ b/drivers/net/ethernet/broadcom/tg3.h
43784@@ -147,6 +147,7 @@
43785 #define CHIPREV_ID_5750_A0 0x4000
43786 #define CHIPREV_ID_5750_A1 0x4001
43787 #define CHIPREV_ID_5750_A3 0x4003
43788+#define CHIPREV_ID_5750_C1 0x4201
43789 #define CHIPREV_ID_5750_C2 0x4202
43790 #define CHIPREV_ID_5752_A0_HW 0x5000
43791 #define CHIPREV_ID_5752_A0 0x6000
43792diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
43793index 8cffcdf..aadf043 100644
43794--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
43795+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
43796@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
43797 */
43798 struct l2t_skb_cb {
43799 arp_failure_handler_func arp_failure_handler;
43800-};
43801+} __no_const;
43802
43803 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
43804
43805diff --git a/drivers/net/ethernet/chelsio/cxgb3/sge.c b/drivers/net/ethernet/chelsio/cxgb3/sge.c
43806index 9c89dc8..725ecc3 100644
43807--- a/drivers/net/ethernet/chelsio/cxgb3/sge.c
43808+++ b/drivers/net/ethernet/chelsio/cxgb3/sge.c
43809@@ -1599,7 +1599,7 @@ static void write_ofld_wr(struct adapter *adap, struct sk_buff *skb,
43810 flits = skb_transport_offset(skb) / 8;
43811 sgp = ndesc == 1 ? (struct sg_ent *)&d->flit[flits] : sgl;
43812 sgl_flits = make_sgl(skb, sgp, skb_transport_header(skb),
43813- skb->tail - skb->transport_header,
43814+ skb_tail_pointer(skb) - skb_transport_header(skb),
43815 adap->pdev);
43816 if (need_skb_unmap()) {
43817 setup_deferred_unmapping(skb, adap->pdev, sgp, sgl_flits);
43818diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
43819index 4c83003..2a2a5b9 100644
43820--- a/drivers/net/ethernet/dec/tulip/de4x5.c
43821+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
43822@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
43823 for (i=0; i<ETH_ALEN; i++) {
43824 tmp.addr[i] = dev->dev_addr[i];
43825 }
43826- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
43827+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
43828 break;
43829
43830 case DE4X5_SET_HWADDR: /* Set the hardware address */
43831@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
43832 spin_lock_irqsave(&lp->lock, flags);
43833 memcpy(&statbuf, &lp->pktStats, ioc->len);
43834 spin_unlock_irqrestore(&lp->lock, flags);
43835- if (copy_to_user(ioc->data, &statbuf, ioc->len))
43836+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
43837 return -EFAULT;
43838 break;
43839 }
43840diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
43841index 3d91a5e..1014702 100644
43842--- a/drivers/net/ethernet/emulex/benet/be_main.c
43843+++ b/drivers/net/ethernet/emulex/benet/be_main.c
43844@@ -469,7 +469,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
43845
43846 if (wrapped)
43847 newacc += 65536;
43848- ACCESS_ONCE(*acc) = newacc;
43849+ ACCESS_ONCE_RW(*acc) = newacc;
43850 }
43851
43852 void populate_erx_stats(struct be_adapter *adapter,
43853diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
43854index 934e1ae..b262e6b 100644
43855--- a/drivers/net/ethernet/faraday/ftgmac100.c
43856+++ b/drivers/net/ethernet/faraday/ftgmac100.c
43857@@ -31,6 +31,8 @@
43858 #include <linux/netdevice.h>
43859 #include <linux/phy.h>
43860 #include <linux/platform_device.h>
43861+#include <linux/interrupt.h>
43862+#include <linux/irqreturn.h>
43863 #include <net/ip.h>
43864
43865 #include "ftgmac100.h"
43866diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
43867index 4658f4c..407d155 100644
43868--- a/drivers/net/ethernet/faraday/ftmac100.c
43869+++ b/drivers/net/ethernet/faraday/ftmac100.c
43870@@ -31,6 +31,8 @@
43871 #include <linux/module.h>
43872 #include <linux/netdevice.h>
43873 #include <linux/platform_device.h>
43874+#include <linux/interrupt.h>
43875+#include <linux/irqreturn.h>
43876
43877 #include "ftmac100.h"
43878
43879diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
43880index 331987d..3be1135 100644
43881--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
43882+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
43883@@ -776,7 +776,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
43884 }
43885
43886 /* update the base incval used to calculate frequency adjustment */
43887- ACCESS_ONCE(adapter->base_incval) = incval;
43888+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
43889 smp_mb();
43890
43891 /* need lock to prevent incorrect read while modifying cyclecounter */
43892diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
43893index fbe5363..266b4e3 100644
43894--- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
43895+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
43896@@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
43897 struct __vxge_hw_fifo *fifo;
43898 struct vxge_hw_fifo_config *config;
43899 u32 txdl_size, txdl_per_memblock;
43900- struct vxge_hw_mempool_cbs fifo_mp_callback;
43901+ static struct vxge_hw_mempool_cbs fifo_mp_callback = {
43902+ .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
43903+ };
43904+
43905 struct __vxge_hw_virtualpath *vpath;
43906
43907 if ((vp == NULL) || (attr == NULL)) {
43908@@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
43909 goto exit;
43910 }
43911
43912- fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
43913-
43914 fifo->mempool =
43915 __vxge_hw_mempool_create(vpath->hldev,
43916 fifo->config->memblock_size,
43917diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
43918index 345d987..af69721 100644
43919--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
43920+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
43921@@ -2011,7 +2011,9 @@ int qlcnic_83xx_config_default_opmode(struct qlcnic_adapter *adapter)
43922 op_mode = QLC_83XX_DEFAULT_OPMODE;
43923
43924 if (op_mode == QLC_83XX_DEFAULT_OPMODE) {
43925- adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
43926+ pax_open_kernel();
43927+ *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
43928+ pax_close_kernel();
43929 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
43930 } else {
43931 return -EIO;
43932diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
43933index 599d1fd..59868fe 100644
43934--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
43935+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
43936@@ -191,17 +191,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
43937 case QLCNIC_NON_PRIV_FUNC:
43938 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
43939 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
43940- nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
43941+ pax_open_kernel();
43942+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
43943+ pax_close_kernel();
43944 break;
43945 case QLCNIC_PRIV_FUNC:
43946 ahw->op_mode = QLCNIC_PRIV_FUNC;
43947 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
43948- nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
43949+ pax_open_kernel();
43950+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
43951+ pax_close_kernel();
43952 break;
43953 case QLCNIC_MGMT_FUNC:
43954 ahw->op_mode = QLCNIC_MGMT_FUNC;
43955 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
43956- nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
43957+ pax_open_kernel();
43958+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
43959+ pax_close_kernel();
43960 break;
43961 default:
43962 dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
43963diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
43964index 85e5c97..76f97ec 100644
43965--- a/drivers/net/ethernet/realtek/r8169.c
43966+++ b/drivers/net/ethernet/realtek/r8169.c
43967@@ -759,22 +759,22 @@ struct rtl8169_private {
43968 struct mdio_ops {
43969 void (*write)(struct rtl8169_private *, int, int);
43970 int (*read)(struct rtl8169_private *, int);
43971- } mdio_ops;
43972+ } __no_const mdio_ops;
43973
43974 struct pll_power_ops {
43975 void (*down)(struct rtl8169_private *);
43976 void (*up)(struct rtl8169_private *);
43977- } pll_power_ops;
43978+ } __no_const pll_power_ops;
43979
43980 struct jumbo_ops {
43981 void (*enable)(struct rtl8169_private *);
43982 void (*disable)(struct rtl8169_private *);
43983- } jumbo_ops;
43984+ } __no_const jumbo_ops;
43985
43986 struct csi_ops {
43987 void (*write)(struct rtl8169_private *, int, int);
43988 u32 (*read)(struct rtl8169_private *, int);
43989- } csi_ops;
43990+ } __no_const csi_ops;
43991
43992 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
43993 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
43994diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
43995index b495394..0748c54 100644
43996--- a/drivers/net/ethernet/sfc/ptp.c
43997+++ b/drivers/net/ethernet/sfc/ptp.c
43998@@ -535,7 +535,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
43999 (u32)((u64)ptp->start.dma_addr >> 32));
44000
44001 /* Clear flag that signals MC ready */
44002- ACCESS_ONCE(*start) = 0;
44003+ ACCESS_ONCE_RW(*start) = 0;
44004 efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
44005 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
44006
44007diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
44008index 50617c5..b13724c 100644
44009--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
44010+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
44011@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
44012
44013 writel(value, ioaddr + MMC_CNTRL);
44014
44015- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
44016- MMC_CNTRL, value);
44017+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
44018+// MMC_CNTRL, value);
44019 }
44020
44021 /* To mask all all interrupts.*/
44022diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
44023index e6fe0d8..2b7d752 100644
44024--- a/drivers/net/hyperv/hyperv_net.h
44025+++ b/drivers/net/hyperv/hyperv_net.h
44026@@ -101,7 +101,7 @@ struct rndis_device {
44027
44028 enum rndis_device_state state;
44029 bool link_state;
44030- atomic_t new_req_id;
44031+ atomic_unchecked_t new_req_id;
44032
44033 spinlock_t request_lock;
44034 struct list_head req_list;
44035diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
44036index 0775f0a..d4fb316 100644
44037--- a/drivers/net/hyperv/rndis_filter.c
44038+++ b/drivers/net/hyperv/rndis_filter.c
44039@@ -104,7 +104,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
44040 * template
44041 */
44042 set = &rndis_msg->msg.set_req;
44043- set->req_id = atomic_inc_return(&dev->new_req_id);
44044+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
44045
44046 /* Add to the request list */
44047 spin_lock_irqsave(&dev->request_lock, flags);
44048@@ -752,7 +752,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
44049
44050 /* Setup the rndis set */
44051 halt = &request->request_msg.msg.halt_req;
44052- halt->req_id = atomic_inc_return(&dev->new_req_id);
44053+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
44054
44055 /* Ignore return since this msg is optional. */
44056 rndis_filter_send_request(dev, request);
44057diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
44058index bf0d55e..82bcfbd1 100644
44059--- a/drivers/net/ieee802154/fakehard.c
44060+++ b/drivers/net/ieee802154/fakehard.c
44061@@ -364,7 +364,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
44062 phy->transmit_power = 0xbf;
44063
44064 dev->netdev_ops = &fake_ops;
44065- dev->ml_priv = &fake_mlme;
44066+ dev->ml_priv = (void *)&fake_mlme;
44067
44068 priv = netdev_priv(dev);
44069 priv->phy = phy;
44070diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
44071index 16b43bf..ead0c35 100644
44072--- a/drivers/net/macvlan.c
44073+++ b/drivers/net/macvlan.c
44074@@ -934,13 +934,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
44075 int macvlan_link_register(struct rtnl_link_ops *ops)
44076 {
44077 /* common fields */
44078- ops->priv_size = sizeof(struct macvlan_dev);
44079- ops->validate = macvlan_validate;
44080- ops->maxtype = IFLA_MACVLAN_MAX;
44081- ops->policy = macvlan_policy;
44082- ops->changelink = macvlan_changelink;
44083- ops->get_size = macvlan_get_size;
44084- ops->fill_info = macvlan_fill_info;
44085+ pax_open_kernel();
44086+ *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
44087+ *(void **)&ops->validate = macvlan_validate;
44088+ *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
44089+ *(const void **)&ops->policy = macvlan_policy;
44090+ *(void **)&ops->changelink = macvlan_changelink;
44091+ *(void **)&ops->get_size = macvlan_get_size;
44092+ *(void **)&ops->fill_info = macvlan_fill_info;
44093+ pax_close_kernel();
44094
44095 return rtnl_link_register(ops);
44096 };
44097@@ -996,7 +998,7 @@ static int macvlan_device_event(struct notifier_block *unused,
44098 return NOTIFY_DONE;
44099 }
44100
44101-static struct notifier_block macvlan_notifier_block __read_mostly = {
44102+static struct notifier_block macvlan_notifier_block = {
44103 .notifier_call = macvlan_device_event,
44104 };
44105
44106diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
44107index ea53abb..2e4d087 100644
44108--- a/drivers/net/macvtap.c
44109+++ b/drivers/net/macvtap.c
44110@@ -1286,7 +1286,7 @@ static int macvtap_device_event(struct notifier_block *unused,
44111 return NOTIFY_DONE;
44112 }
44113
44114-static struct notifier_block macvtap_notifier_block __read_mostly = {
44115+static struct notifier_block macvtap_notifier_block = {
44116 .notifier_call = macvtap_device_event,
44117 };
44118
44119diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
44120index daec9b0..6428fcb 100644
44121--- a/drivers/net/phy/mdio-bitbang.c
44122+++ b/drivers/net/phy/mdio-bitbang.c
44123@@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
44124 struct mdiobb_ctrl *ctrl = bus->priv;
44125
44126 module_put(ctrl->ops->owner);
44127+ mdiobus_unregister(bus);
44128 mdiobus_free(bus);
44129 }
44130 EXPORT_SYMBOL(free_mdio_bitbang);
44131diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
44132index 72ff14b..11d442d 100644
44133--- a/drivers/net/ppp/ppp_generic.c
44134+++ b/drivers/net/ppp/ppp_generic.c
44135@@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
44136 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
44137 struct ppp_stats stats;
44138 struct ppp_comp_stats cstats;
44139- char *vers;
44140
44141 switch (cmd) {
44142 case SIOCGPPPSTATS:
44143@@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
44144 break;
44145
44146 case SIOCGPPPVER:
44147- vers = PPP_VERSION;
44148- if (copy_to_user(addr, vers, strlen(vers) + 1))
44149+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
44150 break;
44151 err = 0;
44152 break;
44153diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
44154index 1252d9c..80e660b 100644
44155--- a/drivers/net/slip/slhc.c
44156+++ b/drivers/net/slip/slhc.c
44157@@ -488,7 +488,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
44158 register struct tcphdr *thp;
44159 register struct iphdr *ip;
44160 register struct cstate *cs;
44161- int len, hdrlen;
44162+ long len, hdrlen;
44163 unsigned char *cp = icp;
44164
44165 /* We've got a compressed packet; read the change byte */
44166diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
44167index bff7e0b..7315137 100644
44168--- a/drivers/net/team/team.c
44169+++ b/drivers/net/team/team.c
44170@@ -2702,7 +2702,7 @@ static int team_device_event(struct notifier_block *unused,
44171 return NOTIFY_DONE;
44172 }
44173
44174-static struct notifier_block team_notifier_block __read_mostly = {
44175+static struct notifier_block team_notifier_block = {
44176 .notifier_call = team_device_event,
44177 };
44178
44179diff --git a/drivers/net/tun.c b/drivers/net/tun.c
44180index 71af122..b3c20f3 100644
44181--- a/drivers/net/tun.c
44182+++ b/drivers/net/tun.c
44183@@ -1691,11 +1691,11 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
44184 INIT_LIST_HEAD(&tun->disabled);
44185 err = tun_attach(tun, file);
44186 if (err < 0)
44187- goto err_free_dev;
44188+ goto err_free_flow;
44189
44190 err = register_netdevice(tun->dev);
44191 if (err < 0)
44192- goto err_free_dev;
44193+ goto err_detach;
44194
44195 if (device_create_file(&tun->dev->dev, &dev_attr_tun_flags) ||
44196 device_create_file(&tun->dev->dev, &dev_attr_owner) ||
44197@@ -1739,7 +1739,12 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
44198 strcpy(ifr->ifr_name, tun->dev->name);
44199 return 0;
44200
44201- err_free_dev:
44202+err_detach:
44203+ tun_detach_all(dev);
44204+err_free_flow:
44205+ tun_flow_uninit(tun);
44206+ security_tun_dev_free_security(tun->security);
44207+err_free_dev:
44208 free_netdev(dev);
44209 return err;
44210 }
44211@@ -1869,7 +1874,7 @@ unlock:
44212 }
44213
44214 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
44215- unsigned long arg, int ifreq_len)
44216+ unsigned long arg, size_t ifreq_len)
44217 {
44218 struct tun_file *tfile = file->private_data;
44219 struct tun_struct *tun;
44220@@ -1881,6 +1886,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
44221 int vnet_hdr_sz;
44222 int ret;
44223
44224+ if (ifreq_len > sizeof ifr)
44225+ return -EFAULT;
44226+
44227 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
44228 if (copy_from_user(&ifr, argp, ifreq_len))
44229 return -EFAULT;
44230diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
44231index 86292e6..8d34433 100644
44232--- a/drivers/net/usb/hso.c
44233+++ b/drivers/net/usb/hso.c
44234@@ -71,7 +71,7 @@
44235 #include <asm/byteorder.h>
44236 #include <linux/serial_core.h>
44237 #include <linux/serial.h>
44238-
44239+#include <asm/local.h>
44240
44241 #define MOD_AUTHOR "Option Wireless"
44242 #define MOD_DESCRIPTION "USB High Speed Option driver"
44243@@ -1180,7 +1180,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
44244 struct urb *urb;
44245
44246 urb = serial->rx_urb[0];
44247- if (serial->port.count > 0) {
44248+ if (atomic_read(&serial->port.count) > 0) {
44249 count = put_rxbuf_data(urb, serial);
44250 if (count == -1)
44251 return;
44252@@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
44253 DUMP1(urb->transfer_buffer, urb->actual_length);
44254
44255 /* Anyone listening? */
44256- if (serial->port.count == 0)
44257+ if (atomic_read(&serial->port.count) == 0)
44258 return;
44259
44260 if (status == 0) {
44261@@ -1298,8 +1298,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
44262 tty_port_tty_set(&serial->port, tty);
44263
44264 /* check for port already opened, if not set the termios */
44265- serial->port.count++;
44266- if (serial->port.count == 1) {
44267+ if (atomic_inc_return(&serial->port.count) == 1) {
44268 serial->rx_state = RX_IDLE;
44269 /* Force default termio settings */
44270 _hso_serial_set_termios(tty, NULL);
44271@@ -1311,7 +1310,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
44272 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
44273 if (result) {
44274 hso_stop_serial_device(serial->parent);
44275- serial->port.count--;
44276+ atomic_dec(&serial->port.count);
44277 kref_put(&serial->parent->ref, hso_serial_ref_free);
44278 }
44279 } else {
44280@@ -1348,10 +1347,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
44281
44282 /* reset the rts and dtr */
44283 /* do the actual close */
44284- serial->port.count--;
44285+ atomic_dec(&serial->port.count);
44286
44287- if (serial->port.count <= 0) {
44288- serial->port.count = 0;
44289+ if (atomic_read(&serial->port.count) <= 0) {
44290+ atomic_set(&serial->port.count, 0);
44291 tty_port_tty_set(&serial->port, NULL);
44292 if (!usb_gone)
44293 hso_stop_serial_device(serial->parent);
44294@@ -1427,7 +1426,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
44295
44296 /* the actual setup */
44297 spin_lock_irqsave(&serial->serial_lock, flags);
44298- if (serial->port.count)
44299+ if (atomic_read(&serial->port.count))
44300 _hso_serial_set_termios(tty, old);
44301 else
44302 tty->termios = *old;
44303@@ -1886,7 +1885,7 @@ static void intr_callback(struct urb *urb)
44304 D1("Pending read interrupt on port %d\n", i);
44305 spin_lock(&serial->serial_lock);
44306 if (serial->rx_state == RX_IDLE &&
44307- serial->port.count > 0) {
44308+ atomic_read(&serial->port.count) > 0) {
44309 /* Setup and send a ctrl req read on
44310 * port i */
44311 if (!serial->rx_urb_filled[0]) {
44312@@ -3062,7 +3061,7 @@ static int hso_resume(struct usb_interface *iface)
44313 /* Start all serial ports */
44314 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
44315 if (serial_table[i] && (serial_table[i]->interface == iface)) {
44316- if (dev2ser(serial_table[i])->port.count) {
44317+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
44318 result =
44319 hso_start_serial_device(serial_table[i], GFP_NOIO);
44320 hso_kick_transmit(dev2ser(serial_table[i]));
44321diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
44322index a79e9d3..78cd4fa 100644
44323--- a/drivers/net/usb/sierra_net.c
44324+++ b/drivers/net/usb/sierra_net.c
44325@@ -52,7 +52,7 @@ static const char driver_name[] = "sierra_net";
44326 /* atomic counter partially included in MAC address to make sure 2 devices
44327 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
44328 */
44329-static atomic_t iface_counter = ATOMIC_INIT(0);
44330+static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
44331
44332 /*
44333 * SYNC Timer Delay definition used to set the expiry time
44334@@ -698,7 +698,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
44335 dev->net->netdev_ops = &sierra_net_device_ops;
44336
44337 /* change MAC addr to include, ifacenum, and to be unique */
44338- dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
44339+ dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
44340 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
44341
44342 /* we will have to manufacture ethernet headers, prepare template */
44343diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
44344index 767f7af..8162b9d 100644
44345--- a/drivers/net/vxlan.c
44346+++ b/drivers/net/vxlan.c
44347@@ -1868,7 +1868,7 @@ nla_put_failure:
44348 return -EMSGSIZE;
44349 }
44350
44351-static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
44352+static struct rtnl_link_ops vxlan_link_ops = {
44353 .kind = "vxlan",
44354 .maxtype = IFLA_VXLAN_MAX,
44355 .policy = vxlan_policy,
44356diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
44357index 0b60295..b8bfa5b 100644
44358--- a/drivers/net/wimax/i2400m/rx.c
44359+++ b/drivers/net/wimax/i2400m/rx.c
44360@@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
44361 if (i2400m->rx_roq == NULL)
44362 goto error_roq_alloc;
44363
44364- rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
44365+ rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
44366 GFP_KERNEL);
44367 if (rd == NULL) {
44368 result = -ENOMEM;
44369diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
44370index 34c8a33..3261fdc 100644
44371--- a/drivers/net/wireless/at76c50x-usb.c
44372+++ b/drivers/net/wireless/at76c50x-usb.c
44373@@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
44374 }
44375
44376 /* Convert timeout from the DFU status to jiffies */
44377-static inline unsigned long at76_get_timeout(struct dfu_status *s)
44378+static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
44379 {
44380 return msecs_to_jiffies((s->poll_timeout[2] << 16)
44381 | (s->poll_timeout[1] << 8)
44382diff --git a/drivers/net/wireless/ath/ath10k/core.c b/drivers/net/wireless/ath/ath10k/core.c
44383index 2b3426b..1f564be 100644
44384--- a/drivers/net/wireless/ath/ath10k/core.c
44385+++ b/drivers/net/wireless/ath/ath10k/core.c
44386@@ -507,7 +507,9 @@ EXPORT_SYMBOL(ath10k_core_destroy);
44387
44388 int ath10k_core_register(struct ath10k *ar)
44389 {
44390- struct ath10k_htc_ops htc_ops;
44391+ static struct ath10k_htc_ops htc_ops = {
44392+ .target_send_suspend_complete = ath10k_send_suspend_complete,
44393+ };
44394 struct bmi_target_info target_info;
44395 int status;
44396
44397@@ -536,8 +538,6 @@ int ath10k_core_register(struct ath10k *ar)
44398 if (status)
44399 goto err;
44400
44401- htc_ops.target_send_suspend_complete = ath10k_send_suspend_complete;
44402-
44403 ar->htc = ath10k_htc_create(ar, &htc_ops);
44404 if (IS_ERR(ar->htc)) {
44405 status = PTR_ERR(ar->htc);
44406diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
44407index 74363c9..237b926 100644
44408--- a/drivers/net/wireless/ath/ath10k/htc.c
44409+++ b/drivers/net/wireless/ath/ath10k/htc.c
44410@@ -963,7 +963,10 @@ void ath10k_htc_stop(struct ath10k_htc *htc)
44411 struct ath10k_htc *ath10k_htc_create(struct ath10k *ar,
44412 struct ath10k_htc_ops *htc_ops)
44413 {
44414- struct ath10k_hif_cb htc_callbacks;
44415+ static struct ath10k_hif_cb htc_callbacks = {
44416+ .rx_completion = ath10k_htc_rx_completion_handler,
44417+ .tx_completion = ath10k_htc_tx_completion_handler,
44418+ };
44419 struct ath10k_htc_ep *ep = NULL;
44420 struct ath10k_htc *htc = NULL;
44421
44422@@ -979,8 +982,6 @@ struct ath10k_htc *ath10k_htc_create(struct ath10k *ar,
44423 ath10k_htc_reset_endpoint_states(htc);
44424
44425 /* setup HIF layer callbacks */
44426- htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
44427- htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
44428 htc->ar = ar;
44429
44430 /* Get HIF default pipe for HTC message exchange */
44431diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
44432index 8d78253..bebbb68 100644
44433--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
44434+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
44435@@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44436 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
44437 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
44438
44439- ACCESS_ONCE(ads->ds_link) = i->link;
44440- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
44441+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
44442+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
44443
44444 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
44445 ctl6 = SM(i->keytype, AR_EncrType);
44446@@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44447
44448 if ((i->is_first || i->is_last) &&
44449 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
44450- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
44451+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
44452 | set11nTries(i->rates, 1)
44453 | set11nTries(i->rates, 2)
44454 | set11nTries(i->rates, 3)
44455 | (i->dur_update ? AR_DurUpdateEna : 0)
44456 | SM(0, AR_BurstDur);
44457
44458- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
44459+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
44460 | set11nRate(i->rates, 1)
44461 | set11nRate(i->rates, 2)
44462 | set11nRate(i->rates, 3);
44463 } else {
44464- ACCESS_ONCE(ads->ds_ctl2) = 0;
44465- ACCESS_ONCE(ads->ds_ctl3) = 0;
44466+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
44467+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
44468 }
44469
44470 if (!i->is_first) {
44471- ACCESS_ONCE(ads->ds_ctl0) = 0;
44472- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
44473- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
44474+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
44475+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
44476+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
44477 return;
44478 }
44479
44480@@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44481 break;
44482 }
44483
44484- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
44485+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
44486 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
44487 | SM(i->txpower, AR_XmitPower)
44488 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
44489@@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44490 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
44491 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
44492
44493- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
44494- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
44495+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
44496+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
44497
44498 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
44499 return;
44500
44501- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
44502+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
44503 | set11nPktDurRTSCTS(i->rates, 1);
44504
44505- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
44506+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
44507 | set11nPktDurRTSCTS(i->rates, 3);
44508
44509- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
44510+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
44511 | set11nRateFlags(i->rates, 1)
44512 | set11nRateFlags(i->rates, 2)
44513 | set11nRateFlags(i->rates, 3)
44514diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
44515index 5163abd..3ada4c2 100644
44516--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
44517+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
44518@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44519 (i->qcu << AR_TxQcuNum_S) | desc_len;
44520
44521 checksum += val;
44522- ACCESS_ONCE(ads->info) = val;
44523+ ACCESS_ONCE_RW(ads->info) = val;
44524
44525 checksum += i->link;
44526- ACCESS_ONCE(ads->link) = i->link;
44527+ ACCESS_ONCE_RW(ads->link) = i->link;
44528
44529 checksum += i->buf_addr[0];
44530- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
44531+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
44532 checksum += i->buf_addr[1];
44533- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
44534+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
44535 checksum += i->buf_addr[2];
44536- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
44537+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
44538 checksum += i->buf_addr[3];
44539- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
44540+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
44541
44542 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
44543- ACCESS_ONCE(ads->ctl3) = val;
44544+ ACCESS_ONCE_RW(ads->ctl3) = val;
44545 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
44546- ACCESS_ONCE(ads->ctl5) = val;
44547+ ACCESS_ONCE_RW(ads->ctl5) = val;
44548 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
44549- ACCESS_ONCE(ads->ctl7) = val;
44550+ ACCESS_ONCE_RW(ads->ctl7) = val;
44551 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
44552- ACCESS_ONCE(ads->ctl9) = val;
44553+ ACCESS_ONCE_RW(ads->ctl9) = val;
44554
44555 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
44556- ACCESS_ONCE(ads->ctl10) = checksum;
44557+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
44558
44559 if (i->is_first || i->is_last) {
44560- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
44561+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
44562 | set11nTries(i->rates, 1)
44563 | set11nTries(i->rates, 2)
44564 | set11nTries(i->rates, 3)
44565 | (i->dur_update ? AR_DurUpdateEna : 0)
44566 | SM(0, AR_BurstDur);
44567
44568- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
44569+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
44570 | set11nRate(i->rates, 1)
44571 | set11nRate(i->rates, 2)
44572 | set11nRate(i->rates, 3);
44573 } else {
44574- ACCESS_ONCE(ads->ctl13) = 0;
44575- ACCESS_ONCE(ads->ctl14) = 0;
44576+ ACCESS_ONCE_RW(ads->ctl13) = 0;
44577+ ACCESS_ONCE_RW(ads->ctl14) = 0;
44578 }
44579
44580 ads->ctl20 = 0;
44581@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44582
44583 ctl17 = SM(i->keytype, AR_EncrType);
44584 if (!i->is_first) {
44585- ACCESS_ONCE(ads->ctl11) = 0;
44586- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
44587- ACCESS_ONCE(ads->ctl15) = 0;
44588- ACCESS_ONCE(ads->ctl16) = 0;
44589- ACCESS_ONCE(ads->ctl17) = ctl17;
44590- ACCESS_ONCE(ads->ctl18) = 0;
44591- ACCESS_ONCE(ads->ctl19) = 0;
44592+ ACCESS_ONCE_RW(ads->ctl11) = 0;
44593+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
44594+ ACCESS_ONCE_RW(ads->ctl15) = 0;
44595+ ACCESS_ONCE_RW(ads->ctl16) = 0;
44596+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
44597+ ACCESS_ONCE_RW(ads->ctl18) = 0;
44598+ ACCESS_ONCE_RW(ads->ctl19) = 0;
44599 return;
44600 }
44601
44602- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
44603+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
44604 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
44605 | SM(i->txpower, AR_XmitPower)
44606 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
44607@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44608 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
44609 ctl12 |= SM(val, AR_PAPRDChainMask);
44610
44611- ACCESS_ONCE(ads->ctl12) = ctl12;
44612- ACCESS_ONCE(ads->ctl17) = ctl17;
44613+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
44614+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
44615
44616- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
44617+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
44618 | set11nPktDurRTSCTS(i->rates, 1);
44619
44620- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
44621+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
44622 | set11nPktDurRTSCTS(i->rates, 3);
44623
44624- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
44625+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
44626 | set11nRateFlags(i->rates, 1)
44627 | set11nRateFlags(i->rates, 2)
44628 | set11nRateFlags(i->rates, 3)
44629 | SM(i->rtscts_rate, AR_RTSCTSRate);
44630
44631- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
44632+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
44633 }
44634
44635 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
44636diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
44637index cd74b3a..6a28d24 100644
44638--- a/drivers/net/wireless/ath/ath9k/hw.h
44639+++ b/drivers/net/wireless/ath/ath9k/hw.h
44640@@ -652,7 +652,7 @@ struct ath_hw_private_ops {
44641
44642 /* ANI */
44643 void (*ani_cache_ini_regs)(struct ath_hw *ah);
44644-};
44645+} __no_const;
44646
44647 /**
44648 * struct ath_spec_scan - parameters for Atheros spectral scan
44649@@ -721,7 +721,7 @@ struct ath_hw_ops {
44650 struct ath_spec_scan *param);
44651 void (*spectral_scan_trigger)(struct ath_hw *ah);
44652 void (*spectral_scan_wait)(struct ath_hw *ah);
44653-};
44654+} __no_const;
44655
44656 struct ath_nf_limits {
44657 s16 max;
44658diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
44659index 9581d07..84f6a76 100644
44660--- a/drivers/net/wireless/iwlegacy/3945-mac.c
44661+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
44662@@ -3639,7 +3639,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
44663 */
44664 if (il3945_mod_params.disable_hw_scan) {
44665 D_INFO("Disabling hw_scan\n");
44666- il3945_mac_ops.hw_scan = NULL;
44667+ pax_open_kernel();
44668+ *(void **)&il3945_mac_ops.hw_scan = NULL;
44669+ pax_close_kernel();
44670 }
44671
44672 D_INFO("*** LOAD DRIVER ***\n");
44673diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
44674index d532948..e0d8bb1 100644
44675--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
44676+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
44677@@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
44678 {
44679 struct iwl_priv *priv = file->private_data;
44680 char buf[64];
44681- int buf_size;
44682+ size_t buf_size;
44683 u32 offset, len;
44684
44685 memset(buf, 0, sizeof(buf));
44686@@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
44687 struct iwl_priv *priv = file->private_data;
44688
44689 char buf[8];
44690- int buf_size;
44691+ size_t buf_size;
44692 u32 reset_flag;
44693
44694 memset(buf, 0, sizeof(buf));
44695@@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
44696 {
44697 struct iwl_priv *priv = file->private_data;
44698 char buf[8];
44699- int buf_size;
44700+ size_t buf_size;
44701 int ht40;
44702
44703 memset(buf, 0, sizeof(buf));
44704@@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
44705 {
44706 struct iwl_priv *priv = file->private_data;
44707 char buf[8];
44708- int buf_size;
44709+ size_t buf_size;
44710 int value;
44711
44712 memset(buf, 0, sizeof(buf));
44713@@ -698,10 +698,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
44714 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
44715 DEBUGFS_READ_FILE_OPS(current_sleep_command);
44716
44717-static const char *fmt_value = " %-30s %10u\n";
44718-static const char *fmt_hex = " %-30s 0x%02X\n";
44719-static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
44720-static const char *fmt_header =
44721+static const char fmt_value[] = " %-30s %10u\n";
44722+static const char fmt_hex[] = " %-30s 0x%02X\n";
44723+static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
44724+static const char fmt_header[] =
44725 "%-32s current cumulative delta max\n";
44726
44727 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
44728@@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
44729 {
44730 struct iwl_priv *priv = file->private_data;
44731 char buf[8];
44732- int buf_size;
44733+ size_t buf_size;
44734 int clear;
44735
44736 memset(buf, 0, sizeof(buf));
44737@@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
44738 {
44739 struct iwl_priv *priv = file->private_data;
44740 char buf[8];
44741- int buf_size;
44742+ size_t buf_size;
44743 int trace;
44744
44745 memset(buf, 0, sizeof(buf));
44746@@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
44747 {
44748 struct iwl_priv *priv = file->private_data;
44749 char buf[8];
44750- int buf_size;
44751+ size_t buf_size;
44752 int missed;
44753
44754 memset(buf, 0, sizeof(buf));
44755@@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
44756
44757 struct iwl_priv *priv = file->private_data;
44758 char buf[8];
44759- int buf_size;
44760+ size_t buf_size;
44761 int plcp;
44762
44763 memset(buf, 0, sizeof(buf));
44764@@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
44765
44766 struct iwl_priv *priv = file->private_data;
44767 char buf[8];
44768- int buf_size;
44769+ size_t buf_size;
44770 int flush;
44771
44772 memset(buf, 0, sizeof(buf));
44773@@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
44774
44775 struct iwl_priv *priv = file->private_data;
44776 char buf[8];
44777- int buf_size;
44778+ size_t buf_size;
44779 int rts;
44780
44781 if (!priv->cfg->ht_params)
44782@@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
44783 {
44784 struct iwl_priv *priv = file->private_data;
44785 char buf[8];
44786- int buf_size;
44787+ size_t buf_size;
44788
44789 memset(buf, 0, sizeof(buf));
44790 buf_size = min(count, sizeof(buf) - 1);
44791@@ -2254,7 +2254,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
44792 struct iwl_priv *priv = file->private_data;
44793 u32 event_log_flag;
44794 char buf[8];
44795- int buf_size;
44796+ size_t buf_size;
44797
44798 /* check that the interface is up */
44799 if (!iwl_is_ready(priv))
44800@@ -2308,7 +2308,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
44801 struct iwl_priv *priv = file->private_data;
44802 char buf[8];
44803 u32 calib_disabled;
44804- int buf_size;
44805+ size_t buf_size;
44806
44807 memset(buf, 0, sizeof(buf));
44808 buf_size = min(count, sizeof(buf) - 1);
44809diff --git a/drivers/net/wireless/iwlwifi/dvm/main.c b/drivers/net/wireless/iwlwifi/dvm/main.c
44810index 1531a4f..21d2641 100644
44811--- a/drivers/net/wireless/iwlwifi/dvm/main.c
44812+++ b/drivers/net/wireless/iwlwifi/dvm/main.c
44813@@ -1180,7 +1180,7 @@ static void iwl_option_config(struct iwl_priv *priv)
44814 static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
44815 {
44816 struct iwl_nvm_data *data = priv->nvm_data;
44817- char *debug_msg;
44818+ static const char debug_msg[] = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
44819
44820 if (data->sku_cap_11n_enable &&
44821 !priv->cfg->ht_params) {
44822@@ -1194,7 +1194,6 @@ static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
44823 return -EINVAL;
44824 }
44825
44826- debug_msg = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
44827 IWL_DEBUG_INFO(priv, debug_msg,
44828 data->sku_cap_band_24GHz_enable ? "" : "NOT", "enabled",
44829 data->sku_cap_band_52GHz_enable ? "" : "NOT", "enabled",
44830diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
44831index 390e2f0..75cfbaf 100644
44832--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
44833+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
44834@@ -1350,7 +1350,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
44835 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
44836
44837 char buf[8];
44838- int buf_size;
44839+ size_t buf_size;
44840 u32 reset_flag;
44841
44842 memset(buf, 0, sizeof(buf));
44843@@ -1371,7 +1371,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
44844 {
44845 struct iwl_trans *trans = file->private_data;
44846 char buf[8];
44847- int buf_size;
44848+ size_t buf_size;
44849 int csr;
44850
44851 memset(buf, 0, sizeof(buf));
44852diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
44853index cb34c78..9fec0dc 100644
44854--- a/drivers/net/wireless/mac80211_hwsim.c
44855+++ b/drivers/net/wireless/mac80211_hwsim.c
44856@@ -2195,25 +2195,19 @@ static int __init init_mac80211_hwsim(void)
44857
44858 if (channels > 1) {
44859 hwsim_if_comb.num_different_channels = channels;
44860- mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
44861- mac80211_hwsim_ops.cancel_hw_scan =
44862- mac80211_hwsim_cancel_hw_scan;
44863- mac80211_hwsim_ops.sw_scan_start = NULL;
44864- mac80211_hwsim_ops.sw_scan_complete = NULL;
44865- mac80211_hwsim_ops.remain_on_channel =
44866- mac80211_hwsim_roc;
44867- mac80211_hwsim_ops.cancel_remain_on_channel =
44868- mac80211_hwsim_croc;
44869- mac80211_hwsim_ops.add_chanctx =
44870- mac80211_hwsim_add_chanctx;
44871- mac80211_hwsim_ops.remove_chanctx =
44872- mac80211_hwsim_remove_chanctx;
44873- mac80211_hwsim_ops.change_chanctx =
44874- mac80211_hwsim_change_chanctx;
44875- mac80211_hwsim_ops.assign_vif_chanctx =
44876- mac80211_hwsim_assign_vif_chanctx;
44877- mac80211_hwsim_ops.unassign_vif_chanctx =
44878- mac80211_hwsim_unassign_vif_chanctx;
44879+ pax_open_kernel();
44880+ *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
44881+ *(void **)&mac80211_hwsim_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
44882+ *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
44883+ *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
44884+ *(void **)&mac80211_hwsim_ops.remain_on_channel = mac80211_hwsim_roc;
44885+ *(void **)&mac80211_hwsim_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
44886+ *(void **)&mac80211_hwsim_ops.add_chanctx = mac80211_hwsim_add_chanctx;
44887+ *(void **)&mac80211_hwsim_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
44888+ *(void **)&mac80211_hwsim_ops.change_chanctx = mac80211_hwsim_change_chanctx;
44889+ *(void **)&mac80211_hwsim_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
44890+ *(void **)&mac80211_hwsim_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
44891+ pax_close_kernel();
44892 }
44893
44894 spin_lock_init(&hwsim_radio_lock);
44895diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
44896index 8169a85..7fa3b47 100644
44897--- a/drivers/net/wireless/rndis_wlan.c
44898+++ b/drivers/net/wireless/rndis_wlan.c
44899@@ -1238,7 +1238,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
44900
44901 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
44902
44903- if (rts_threshold < 0 || rts_threshold > 2347)
44904+ if (rts_threshold > 2347)
44905 rts_threshold = 2347;
44906
44907 tmp = cpu_to_le32(rts_threshold);
44908diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
44909index ee3fc57..ed5ddc9 100644
44910--- a/drivers/net/wireless/rt2x00/rt2x00.h
44911+++ b/drivers/net/wireless/rt2x00/rt2x00.h
44912@@ -386,7 +386,7 @@ struct rt2x00_intf {
44913 * for hardware which doesn't support hardware
44914 * sequence counting.
44915 */
44916- atomic_t seqno;
44917+ atomic_unchecked_t seqno;
44918 };
44919
44920 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
44921diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
44922index aa95c6c..a59dd67 100644
44923--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
44924+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
44925@@ -252,9 +252,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
44926 * sequence counter given by mac80211.
44927 */
44928 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
44929- seqno = atomic_add_return(0x10, &intf->seqno);
44930+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
44931 else
44932- seqno = atomic_read(&intf->seqno);
44933+ seqno = atomic_read_unchecked(&intf->seqno);
44934
44935 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
44936 hdr->seq_ctrl |= cpu_to_le16(seqno);
44937diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
44938index e2b3d9c..67a5184 100644
44939--- a/drivers/net/wireless/ti/wl1251/sdio.c
44940+++ b/drivers/net/wireless/ti/wl1251/sdio.c
44941@@ -271,13 +271,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
44942
44943 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
44944
44945- wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
44946- wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
44947+ pax_open_kernel();
44948+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
44949+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
44950+ pax_close_kernel();
44951
44952 wl1251_info("using dedicated interrupt line");
44953 } else {
44954- wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
44955- wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
44956+ pax_open_kernel();
44957+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
44958+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
44959+ pax_close_kernel();
44960
44961 wl1251_info("using SDIO interrupt");
44962 }
44963diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
44964index 1c627da..69f7d17 100644
44965--- a/drivers/net/wireless/ti/wl12xx/main.c
44966+++ b/drivers/net/wireless/ti/wl12xx/main.c
44967@@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
44968 sizeof(wl->conf.mem));
44969
44970 /* read data preparation is only needed by wl127x */
44971- wl->ops->prepare_read = wl127x_prepare_read;
44972+ pax_open_kernel();
44973+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
44974+ pax_close_kernel();
44975
44976 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
44977 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
44978@@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
44979 sizeof(wl->conf.mem));
44980
44981 /* read data preparation is only needed by wl127x */
44982- wl->ops->prepare_read = wl127x_prepare_read;
44983+ pax_open_kernel();
44984+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
44985+ pax_close_kernel();
44986
44987 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
44988 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
44989diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
44990index 7aa0eb8..5a9ef38 100644
44991--- a/drivers/net/wireless/ti/wl18xx/main.c
44992+++ b/drivers/net/wireless/ti/wl18xx/main.c
44993@@ -1730,8 +1730,10 @@ static int wl18xx_setup(struct wl1271 *wl)
44994 }
44995
44996 if (!checksum_param) {
44997- wl18xx_ops.set_rx_csum = NULL;
44998- wl18xx_ops.init_vif = NULL;
44999+ pax_open_kernel();
45000+ *(void **)&wl18xx_ops.set_rx_csum = NULL;
45001+ *(void **)&wl18xx_ops.init_vif = NULL;
45002+ pax_close_kernel();
45003 }
45004
45005 /* Enable 11a Band only if we have 5G antennas */
45006diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
45007index 7ef0b4a..ff65c28 100644
45008--- a/drivers/net/wireless/zd1211rw/zd_usb.c
45009+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
45010@@ -386,7 +386,7 @@ static inline void handle_regs_int(struct urb *urb)
45011 {
45012 struct zd_usb *usb = urb->context;
45013 struct zd_usb_interrupt *intr = &usb->intr;
45014- int len;
45015+ unsigned int len;
45016 u16 int_num;
45017
45018 ZD_ASSERT(in_interrupt());
45019diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
45020index d93b2b6..ae50401 100644
45021--- a/drivers/oprofile/buffer_sync.c
45022+++ b/drivers/oprofile/buffer_sync.c
45023@@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
45024 if (cookie == NO_COOKIE)
45025 offset = pc;
45026 if (cookie == INVALID_COOKIE) {
45027- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
45028+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
45029 offset = pc;
45030 }
45031 if (cookie != last_cookie) {
45032@@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
45033 /* add userspace sample */
45034
45035 if (!mm) {
45036- atomic_inc(&oprofile_stats.sample_lost_no_mm);
45037+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
45038 return 0;
45039 }
45040
45041 cookie = lookup_dcookie(mm, s->eip, &offset);
45042
45043 if (cookie == INVALID_COOKIE) {
45044- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
45045+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
45046 return 0;
45047 }
45048
45049@@ -552,7 +552,7 @@ void sync_buffer(int cpu)
45050 /* ignore backtraces if failed to add a sample */
45051 if (state == sb_bt_start) {
45052 state = sb_bt_ignore;
45053- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
45054+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
45055 }
45056 }
45057 release_mm(mm);
45058diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
45059index c0cc4e7..44d4e54 100644
45060--- a/drivers/oprofile/event_buffer.c
45061+++ b/drivers/oprofile/event_buffer.c
45062@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
45063 }
45064
45065 if (buffer_pos == buffer_size) {
45066- atomic_inc(&oprofile_stats.event_lost_overflow);
45067+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
45068 return;
45069 }
45070
45071diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
45072index ed2c3ec..deda85a 100644
45073--- a/drivers/oprofile/oprof.c
45074+++ b/drivers/oprofile/oprof.c
45075@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
45076 if (oprofile_ops.switch_events())
45077 return;
45078
45079- atomic_inc(&oprofile_stats.multiplex_counter);
45080+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
45081 start_switch_worker();
45082 }
45083
45084diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
45085index 84a208d..d61b0a1 100644
45086--- a/drivers/oprofile/oprofile_files.c
45087+++ b/drivers/oprofile/oprofile_files.c
45088@@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
45089
45090 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
45091
45092-static ssize_t timeout_read(struct file *file, char __user *buf,
45093+static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
45094 size_t count, loff_t *offset)
45095 {
45096 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
45097diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
45098index 917d28e..d62d981 100644
45099--- a/drivers/oprofile/oprofile_stats.c
45100+++ b/drivers/oprofile/oprofile_stats.c
45101@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
45102 cpu_buf->sample_invalid_eip = 0;
45103 }
45104
45105- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
45106- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
45107- atomic_set(&oprofile_stats.event_lost_overflow, 0);
45108- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
45109- atomic_set(&oprofile_stats.multiplex_counter, 0);
45110+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
45111+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
45112+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
45113+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
45114+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
45115 }
45116
45117
45118diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
45119index 38b6fc0..b5cbfce 100644
45120--- a/drivers/oprofile/oprofile_stats.h
45121+++ b/drivers/oprofile/oprofile_stats.h
45122@@ -13,11 +13,11 @@
45123 #include <linux/atomic.h>
45124
45125 struct oprofile_stat_struct {
45126- atomic_t sample_lost_no_mm;
45127- atomic_t sample_lost_no_mapping;
45128- atomic_t bt_lost_no_mapping;
45129- atomic_t event_lost_overflow;
45130- atomic_t multiplex_counter;
45131+ atomic_unchecked_t sample_lost_no_mm;
45132+ atomic_unchecked_t sample_lost_no_mapping;
45133+ atomic_unchecked_t bt_lost_no_mapping;
45134+ atomic_unchecked_t event_lost_overflow;
45135+ atomic_unchecked_t multiplex_counter;
45136 };
45137
45138 extern struct oprofile_stat_struct oprofile_stats;
45139diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
45140index 7c12d9c..558bf3bb 100644
45141--- a/drivers/oprofile/oprofilefs.c
45142+++ b/drivers/oprofile/oprofilefs.c
45143@@ -190,7 +190,7 @@ static const struct file_operations atomic_ro_fops = {
45144
45145
45146 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
45147- char const *name, atomic_t *val)
45148+ char const *name, atomic_unchecked_t *val)
45149 {
45150 return __oprofilefs_create_file(sb, root, name,
45151 &atomic_ro_fops, 0444, val);
45152diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
45153index 61be1d9..dec05d7 100644
45154--- a/drivers/oprofile/timer_int.c
45155+++ b/drivers/oprofile/timer_int.c
45156@@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
45157 return NOTIFY_OK;
45158 }
45159
45160-static struct notifier_block __refdata oprofile_cpu_notifier = {
45161+static struct notifier_block oprofile_cpu_notifier = {
45162 .notifier_call = oprofile_cpu_notify,
45163 };
45164
45165diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
45166index 92ed045..62d39bd7 100644
45167--- a/drivers/parport/procfs.c
45168+++ b/drivers/parport/procfs.c
45169@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
45170
45171 *ppos += len;
45172
45173- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
45174+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
45175 }
45176
45177 #ifdef CONFIG_PARPORT_1284
45178@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
45179
45180 *ppos += len;
45181
45182- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
45183+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
45184 }
45185 #endif /* IEEE1284.3 support. */
45186
45187diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
45188index c35e8ad..fc33beb 100644
45189--- a/drivers/pci/hotplug/acpiphp_ibm.c
45190+++ b/drivers/pci/hotplug/acpiphp_ibm.c
45191@@ -464,7 +464,9 @@ static int __init ibm_acpiphp_init(void)
45192 goto init_cleanup;
45193 }
45194
45195- ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
45196+ pax_open_kernel();
45197+ *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
45198+ pax_close_kernel();
45199 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
45200
45201 return retval;
45202diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
45203index a6a71c4..c91097b 100644
45204--- a/drivers/pci/hotplug/cpcihp_generic.c
45205+++ b/drivers/pci/hotplug/cpcihp_generic.c
45206@@ -73,7 +73,6 @@ static u16 port;
45207 static unsigned int enum_bit;
45208 static u8 enum_mask;
45209
45210-static struct cpci_hp_controller_ops generic_hpc_ops;
45211 static struct cpci_hp_controller generic_hpc;
45212
45213 static int __init validate_parameters(void)
45214@@ -139,6 +138,10 @@ static int query_enum(void)
45215 return ((value & enum_mask) == enum_mask);
45216 }
45217
45218+static struct cpci_hp_controller_ops generic_hpc_ops = {
45219+ .query_enum = query_enum,
45220+};
45221+
45222 static int __init cpcihp_generic_init(void)
45223 {
45224 int status;
45225@@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
45226 pci_dev_put(dev);
45227
45228 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
45229- generic_hpc_ops.query_enum = query_enum;
45230 generic_hpc.ops = &generic_hpc_ops;
45231
45232 status = cpci_hp_register_controller(&generic_hpc);
45233diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
45234index 449b4bb..257e2e8 100644
45235--- a/drivers/pci/hotplug/cpcihp_zt5550.c
45236+++ b/drivers/pci/hotplug/cpcihp_zt5550.c
45237@@ -59,7 +59,6 @@
45238 /* local variables */
45239 static bool debug;
45240 static bool poll;
45241-static struct cpci_hp_controller_ops zt5550_hpc_ops;
45242 static struct cpci_hp_controller zt5550_hpc;
45243
45244 /* Primary cPCI bus bridge device */
45245@@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
45246 return 0;
45247 }
45248
45249+static struct cpci_hp_controller_ops zt5550_hpc_ops = {
45250+ .query_enum = zt5550_hc_query_enum,
45251+};
45252+
45253 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
45254 {
45255 int status;
45256@@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
45257 dbg("returned from zt5550_hc_config");
45258
45259 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
45260- zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
45261 zt5550_hpc.ops = &zt5550_hpc_ops;
45262 if(!poll) {
45263 zt5550_hpc.irq = hc_dev->irq;
45264 zt5550_hpc.irq_flags = IRQF_SHARED;
45265 zt5550_hpc.dev_id = hc_dev;
45266
45267- zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
45268- zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
45269- zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
45270+ pax_open_kernel();
45271+ *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
45272+ *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
45273+ *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
45274+ pax_open_kernel();
45275 } else {
45276 info("using ENUM# polling mode");
45277 }
45278diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
45279index 76ba8a1..20ca857 100644
45280--- a/drivers/pci/hotplug/cpqphp_nvram.c
45281+++ b/drivers/pci/hotplug/cpqphp_nvram.c
45282@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
45283
45284 void compaq_nvram_init (void __iomem *rom_start)
45285 {
45286+
45287+#ifndef CONFIG_PAX_KERNEXEC
45288 if (rom_start) {
45289 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
45290 }
45291+#endif
45292+
45293 dbg("int15 entry = %p\n", compaq_int15_entry_point);
45294
45295 /* initialize our int15 lock */
45296diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
45297index ec20f74..c1d961e 100644
45298--- a/drivers/pci/hotplug/pci_hotplug_core.c
45299+++ b/drivers/pci/hotplug/pci_hotplug_core.c
45300@@ -441,8 +441,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
45301 return -EINVAL;
45302 }
45303
45304- slot->ops->owner = owner;
45305- slot->ops->mod_name = mod_name;
45306+ pax_open_kernel();
45307+ *(struct module **)&slot->ops->owner = owner;
45308+ *(const char **)&slot->ops->mod_name = mod_name;
45309+ pax_close_kernel();
45310
45311 mutex_lock(&pci_hp_mutex);
45312 /*
45313diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
45314index 7d72c5e..edce02c 100644
45315--- a/drivers/pci/hotplug/pciehp_core.c
45316+++ b/drivers/pci/hotplug/pciehp_core.c
45317@@ -91,7 +91,7 @@ static int init_slot(struct controller *ctrl)
45318 struct slot *slot = ctrl->slot;
45319 struct hotplug_slot *hotplug = NULL;
45320 struct hotplug_slot_info *info = NULL;
45321- struct hotplug_slot_ops *ops = NULL;
45322+ hotplug_slot_ops_no_const *ops = NULL;
45323 char name[SLOT_NAME_SIZE];
45324 int retval = -ENOMEM;
45325
45326diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
45327index c0dbe1f..94cf3d8 100644
45328--- a/drivers/pci/pci-sysfs.c
45329+++ b/drivers/pci/pci-sysfs.c
45330@@ -1073,7 +1073,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
45331 {
45332 /* allocate attribute structure, piggyback attribute name */
45333 int name_len = write_combine ? 13 : 10;
45334- struct bin_attribute *res_attr;
45335+ bin_attribute_no_const *res_attr;
45336 int retval;
45337
45338 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
45339@@ -1258,7 +1258,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
45340 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
45341 {
45342 int retval;
45343- struct bin_attribute *attr;
45344+ bin_attribute_no_const *attr;
45345
45346 /* If the device has VPD, try to expose it in sysfs. */
45347 if (dev->vpd) {
45348@@ -1305,7 +1305,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
45349 {
45350 int retval;
45351 int rom_size = 0;
45352- struct bin_attribute *attr;
45353+ bin_attribute_no_const *attr;
45354
45355 if (!sysfs_initialized)
45356 return -EACCES;
45357diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
45358index d1182c4..2a138ec 100644
45359--- a/drivers/pci/pci.h
45360+++ b/drivers/pci/pci.h
45361@@ -92,7 +92,7 @@ struct pci_vpd_ops {
45362 struct pci_vpd {
45363 unsigned int len;
45364 const struct pci_vpd_ops *ops;
45365- struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
45366+ bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
45367 };
45368
45369 int pci_vpd_pci22_init(struct pci_dev *dev);
45370diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
45371index 403a443..034e050 100644
45372--- a/drivers/pci/pcie/aspm.c
45373+++ b/drivers/pci/pcie/aspm.c
45374@@ -27,9 +27,9 @@
45375 #define MODULE_PARAM_PREFIX "pcie_aspm."
45376
45377 /* Note: those are not register definitions */
45378-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
45379-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
45380-#define ASPM_STATE_L1 (4) /* L1 state */
45381+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
45382+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
45383+#define ASPM_STATE_L1 (4U) /* L1 state */
45384 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
45385 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
45386
45387diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
45388index 46ada5c..20da716 100644
45389--- a/drivers/pci/probe.c
45390+++ b/drivers/pci/probe.c
45391@@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
45392 struct pci_bus_region region, inverted_region;
45393 bool bar_too_big = false, bar_disabled = false;
45394
45395- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
45396+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
45397
45398 /* No printks while decoding is disabled! */
45399 if (!dev->mmio_always_on) {
45400diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
45401index cdc7836..528635c 100644
45402--- a/drivers/pci/proc.c
45403+++ b/drivers/pci/proc.c
45404@@ -434,7 +434,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
45405 static int __init pci_proc_init(void)
45406 {
45407 struct pci_dev *dev = NULL;
45408+
45409+#ifdef CONFIG_GRKERNSEC_PROC_ADD
45410+#ifdef CONFIG_GRKERNSEC_PROC_USER
45411+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
45412+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
45413+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
45414+#endif
45415+#else
45416 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
45417+#endif
45418 proc_create("devices", 0, proc_bus_pci_dir,
45419 &proc_bus_pci_dev_operations);
45420 proc_initialized = 1;
45421diff --git a/drivers/platform/x86/chromeos_laptop.c b/drivers/platform/x86/chromeos_laptop.c
45422index 3e5b4497..dcdfb70 100644
45423--- a/drivers/platform/x86/chromeos_laptop.c
45424+++ b/drivers/platform/x86/chromeos_laptop.c
45425@@ -301,7 +301,7 @@ static int __init setup_tsl2563_als(const struct dmi_system_id *id)
45426 return 0;
45427 }
45428
45429-static struct dmi_system_id __initdata chromeos_laptop_dmi_table[] = {
45430+static struct dmi_system_id __initconst chromeos_laptop_dmi_table[] = {
45431 {
45432 .ident = "Samsung Series 5 550 - Touchpad",
45433 .matches = {
45434diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
45435index 62f8030..c7f2a45 100644
45436--- a/drivers/platform/x86/msi-laptop.c
45437+++ b/drivers/platform/x86/msi-laptop.c
45438@@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
45439
45440 if (!quirks->ec_read_only) {
45441 /* allow userland write sysfs file */
45442- dev_attr_bluetooth.store = store_bluetooth;
45443- dev_attr_wlan.store = store_wlan;
45444- dev_attr_threeg.store = store_threeg;
45445- dev_attr_bluetooth.attr.mode |= S_IWUSR;
45446- dev_attr_wlan.attr.mode |= S_IWUSR;
45447- dev_attr_threeg.attr.mode |= S_IWUSR;
45448+ pax_open_kernel();
45449+ *(void **)&dev_attr_bluetooth.store = store_bluetooth;
45450+ *(void **)&dev_attr_wlan.store = store_wlan;
45451+ *(void **)&dev_attr_threeg.store = store_threeg;
45452+ *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
45453+ *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
45454+ *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
45455+ pax_close_kernel();
45456 }
45457
45458 /* disable hardware control by fn key */
45459diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
45460index 3a1b6bf..b453930 100644
45461--- a/drivers/platform/x86/sony-laptop.c
45462+++ b/drivers/platform/x86/sony-laptop.c
45463@@ -2486,7 +2486,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
45464 }
45465
45466 /* High speed charging function */
45467-static struct device_attribute *hsc_handle;
45468+static device_attribute_no_const *hsc_handle;
45469
45470 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
45471 struct device_attribute *attr,
45472diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
45473index 54d31c0..3f896d3 100644
45474--- a/drivers/platform/x86/thinkpad_acpi.c
45475+++ b/drivers/platform/x86/thinkpad_acpi.c
45476@@ -2093,7 +2093,7 @@ static int hotkey_mask_get(void)
45477 return 0;
45478 }
45479
45480-void static hotkey_mask_warn_incomplete_mask(void)
45481+static void hotkey_mask_warn_incomplete_mask(void)
45482 {
45483 /* log only what the user can fix... */
45484 const u32 wantedmask = hotkey_driver_mask &
45485@@ -2324,11 +2324,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
45486 }
45487 }
45488
45489-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45490- struct tp_nvram_state *newn,
45491- const u32 event_mask)
45492-{
45493-
45494 #define TPACPI_COMPARE_KEY(__scancode, __member) \
45495 do { \
45496 if ((event_mask & (1 << __scancode)) && \
45497@@ -2342,36 +2337,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45498 tpacpi_hotkey_send_key(__scancode); \
45499 } while (0)
45500
45501- void issue_volchange(const unsigned int oldvol,
45502- const unsigned int newvol)
45503- {
45504- unsigned int i = oldvol;
45505+static void issue_volchange(const unsigned int oldvol,
45506+ const unsigned int newvol,
45507+ const u32 event_mask)
45508+{
45509+ unsigned int i = oldvol;
45510
45511- while (i > newvol) {
45512- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
45513- i--;
45514- }
45515- while (i < newvol) {
45516- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
45517- i++;
45518- }
45519+ while (i > newvol) {
45520+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
45521+ i--;
45522 }
45523+ while (i < newvol) {
45524+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
45525+ i++;
45526+ }
45527+}
45528
45529- void issue_brightnesschange(const unsigned int oldbrt,
45530- const unsigned int newbrt)
45531- {
45532- unsigned int i = oldbrt;
45533+static void issue_brightnesschange(const unsigned int oldbrt,
45534+ const unsigned int newbrt,
45535+ const u32 event_mask)
45536+{
45537+ unsigned int i = oldbrt;
45538
45539- while (i > newbrt) {
45540- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
45541- i--;
45542- }
45543- while (i < newbrt) {
45544- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
45545- i++;
45546- }
45547+ while (i > newbrt) {
45548+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
45549+ i--;
45550+ }
45551+ while (i < newbrt) {
45552+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
45553+ i++;
45554 }
45555+}
45556
45557+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45558+ struct tp_nvram_state *newn,
45559+ const u32 event_mask)
45560+{
45561 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
45562 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
45563 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
45564@@ -2405,7 +2406,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45565 oldn->volume_level != newn->volume_level) {
45566 /* recently muted, or repeated mute keypress, or
45567 * multiple presses ending in mute */
45568- issue_volchange(oldn->volume_level, newn->volume_level);
45569+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
45570 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
45571 }
45572 } else {
45573@@ -2415,7 +2416,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45574 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
45575 }
45576 if (oldn->volume_level != newn->volume_level) {
45577- issue_volchange(oldn->volume_level, newn->volume_level);
45578+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
45579 } else if (oldn->volume_toggle != newn->volume_toggle) {
45580 /* repeated vol up/down keypress at end of scale ? */
45581 if (newn->volume_level == 0)
45582@@ -2428,7 +2429,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45583 /* handle brightness */
45584 if (oldn->brightness_level != newn->brightness_level) {
45585 issue_brightnesschange(oldn->brightness_level,
45586- newn->brightness_level);
45587+ newn->brightness_level,
45588+ event_mask);
45589 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
45590 /* repeated key presses that didn't change state */
45591 if (newn->brightness_level == 0)
45592@@ -2437,10 +2439,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45593 && !tp_features.bright_unkfw)
45594 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
45595 }
45596+}
45597
45598 #undef TPACPI_COMPARE_KEY
45599 #undef TPACPI_MAY_SEND_KEY
45600-}
45601
45602 /*
45603 * Polling driver
45604diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
45605index 769d265..a3a05ca 100644
45606--- a/drivers/pnp/pnpbios/bioscalls.c
45607+++ b/drivers/pnp/pnpbios/bioscalls.c
45608@@ -58,7 +58,7 @@ do { \
45609 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
45610 } while(0)
45611
45612-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
45613+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
45614 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
45615
45616 /*
45617@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
45618
45619 cpu = get_cpu();
45620 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
45621+
45622+ pax_open_kernel();
45623 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
45624+ pax_close_kernel();
45625
45626 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
45627 spin_lock_irqsave(&pnp_bios_lock, flags);
45628@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
45629 :"memory");
45630 spin_unlock_irqrestore(&pnp_bios_lock, flags);
45631
45632+ pax_open_kernel();
45633 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
45634+ pax_close_kernel();
45635+
45636 put_cpu();
45637
45638 /* If we get here and this is set then the PnP BIOS faulted on us. */
45639@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
45640 return status;
45641 }
45642
45643-void pnpbios_calls_init(union pnp_bios_install_struct *header)
45644+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
45645 {
45646 int i;
45647
45648@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
45649 pnp_bios_callpoint.offset = header->fields.pm16offset;
45650 pnp_bios_callpoint.segment = PNP_CS16;
45651
45652+ pax_open_kernel();
45653+
45654 for_each_possible_cpu(i) {
45655 struct desc_struct *gdt = get_cpu_gdt_table(i);
45656 if (!gdt)
45657@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
45658 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
45659 (unsigned long)__va(header->fields.pm16dseg));
45660 }
45661+
45662+ pax_close_kernel();
45663 }
45664diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
45665index d95e101..67f0c3f 100644
45666--- a/drivers/pnp/resource.c
45667+++ b/drivers/pnp/resource.c
45668@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
45669 return 1;
45670
45671 /* check if the resource is valid */
45672- if (*irq < 0 || *irq > 15)
45673+ if (*irq > 15)
45674 return 0;
45675
45676 /* check if the resource is reserved */
45677@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
45678 return 1;
45679
45680 /* check if the resource is valid */
45681- if (*dma < 0 || *dma == 4 || *dma > 7)
45682+ if (*dma == 4 || *dma > 7)
45683 return 0;
45684
45685 /* check if the resource is reserved */
45686diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
45687index 0c52e2a..3421ab7 100644
45688--- a/drivers/power/pda_power.c
45689+++ b/drivers/power/pda_power.c
45690@@ -37,7 +37,11 @@ static int polling;
45691
45692 #if IS_ENABLED(CONFIG_USB_PHY)
45693 static struct usb_phy *transceiver;
45694-static struct notifier_block otg_nb;
45695+static int otg_handle_notification(struct notifier_block *nb,
45696+ unsigned long event, void *unused);
45697+static struct notifier_block otg_nb = {
45698+ .notifier_call = otg_handle_notification
45699+};
45700 #endif
45701
45702 static struct regulator *ac_draw;
45703@@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
45704
45705 #if IS_ENABLED(CONFIG_USB_PHY)
45706 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
45707- otg_nb.notifier_call = otg_handle_notification;
45708 ret = usb_register_notifier(transceiver, &otg_nb);
45709 if (ret) {
45710 dev_err(dev, "failure to register otg notifier\n");
45711diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
45712index cc439fd..8fa30df 100644
45713--- a/drivers/power/power_supply.h
45714+++ b/drivers/power/power_supply.h
45715@@ -16,12 +16,12 @@ struct power_supply;
45716
45717 #ifdef CONFIG_SYSFS
45718
45719-extern void power_supply_init_attrs(struct device_type *dev_type);
45720+extern void power_supply_init_attrs(void);
45721 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
45722
45723 #else
45724
45725-static inline void power_supply_init_attrs(struct device_type *dev_type) {}
45726+static inline void power_supply_init_attrs(void) {}
45727 #define power_supply_uevent NULL
45728
45729 #endif /* CONFIG_SYSFS */
45730diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
45731index 3b2d5df..3207114 100644
45732--- a/drivers/power/power_supply_core.c
45733+++ b/drivers/power/power_supply_core.c
45734@@ -24,7 +24,10 @@
45735 struct class *power_supply_class;
45736 EXPORT_SYMBOL_GPL(power_supply_class);
45737
45738-static struct device_type power_supply_dev_type;
45739+extern const struct attribute_group *power_supply_attr_groups[];
45740+static struct device_type power_supply_dev_type = {
45741+ .groups = power_supply_attr_groups,
45742+};
45743
45744 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
45745 struct power_supply *supply)
45746@@ -558,7 +561,7 @@ static int __init power_supply_class_init(void)
45747 return PTR_ERR(power_supply_class);
45748
45749 power_supply_class->dev_uevent = power_supply_uevent;
45750- power_supply_init_attrs(&power_supply_dev_type);
45751+ power_supply_init_attrs();
45752
45753 return 0;
45754 }
45755diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
45756index 29178f7..c65f324 100644
45757--- a/drivers/power/power_supply_sysfs.c
45758+++ b/drivers/power/power_supply_sysfs.c
45759@@ -230,17 +230,15 @@ static struct attribute_group power_supply_attr_group = {
45760 .is_visible = power_supply_attr_is_visible,
45761 };
45762
45763-static const struct attribute_group *power_supply_attr_groups[] = {
45764+const struct attribute_group *power_supply_attr_groups[] = {
45765 &power_supply_attr_group,
45766 NULL,
45767 };
45768
45769-void power_supply_init_attrs(struct device_type *dev_type)
45770+void power_supply_init_attrs(void)
45771 {
45772 int i;
45773
45774- dev_type->groups = power_supply_attr_groups;
45775-
45776 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
45777 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
45778 }
45779diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
45780index 288c75a..065bc84 100644
45781--- a/drivers/regulator/core.c
45782+++ b/drivers/regulator/core.c
45783@@ -3544,7 +3544,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
45784 {
45785 const struct regulation_constraints *constraints = NULL;
45786 const struct regulator_init_data *init_data;
45787- static atomic_t regulator_no = ATOMIC_INIT(0);
45788+ static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
45789 struct regulator_dev *rdev;
45790 struct device *dev;
45791 int ret, i;
45792@@ -3614,7 +3614,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
45793 rdev->dev.of_node = config->of_node;
45794 rdev->dev.parent = dev;
45795 dev_set_name(&rdev->dev, "regulator.%d",
45796- atomic_inc_return(&regulator_no) - 1);
45797+ atomic_inc_return_unchecked(&regulator_no) - 1);
45798 ret = device_register(&rdev->dev);
45799 if (ret != 0) {
45800 put_device(&rdev->dev);
45801diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
45802index d428ef9..fdc0357 100644
45803--- a/drivers/regulator/max8660.c
45804+++ b/drivers/regulator/max8660.c
45805@@ -333,8 +333,10 @@ static int max8660_probe(struct i2c_client *client,
45806 max8660->shadow_regs[MAX8660_OVER1] = 5;
45807 } else {
45808 /* Otherwise devices can be toggled via software */
45809- max8660_dcdc_ops.enable = max8660_dcdc_enable;
45810- max8660_dcdc_ops.disable = max8660_dcdc_disable;
45811+ pax_open_kernel();
45812+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
45813+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
45814+ pax_close_kernel();
45815 }
45816
45817 /*
45818diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
45819index 0c5195a..637a453d 100644
45820--- a/drivers/regulator/max8973-regulator.c
45821+++ b/drivers/regulator/max8973-regulator.c
45822@@ -406,9 +406,11 @@ static int max8973_probe(struct i2c_client *client,
45823 if (!pdata || !pdata->enable_ext_control) {
45824 max->desc.enable_reg = MAX8973_VOUT;
45825 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
45826- max->ops.enable = regulator_enable_regmap;
45827- max->ops.disable = regulator_disable_regmap;
45828- max->ops.is_enabled = regulator_is_enabled_regmap;
45829+ pax_open_kernel();
45830+ *(void **)&max->ops.enable = regulator_enable_regmap;
45831+ *(void **)&max->ops.disable = regulator_disable_regmap;
45832+ *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
45833+ pax_close_kernel();
45834 }
45835
45836 if (pdata) {
45837diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
45838index 1037e07..e64dea1 100644
45839--- a/drivers/regulator/mc13892-regulator.c
45840+++ b/drivers/regulator/mc13892-regulator.c
45841@@ -582,10 +582,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
45842 }
45843 mc13xxx_unlock(mc13892);
45844
45845- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
45846+ pax_open_kernel();
45847+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
45848 = mc13892_vcam_set_mode;
45849- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
45850+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
45851 = mc13892_vcam_get_mode;
45852+ pax_close_kernel();
45853
45854 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
45855 ARRAY_SIZE(mc13892_regulators));
45856diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
45857index be06d71..264aee9 100644
45858--- a/drivers/rtc/rtc-cmos.c
45859+++ b/drivers/rtc/rtc-cmos.c
45860@@ -731,7 +731,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
45861 hpet_rtc_timer_init();
45862
45863 /* export at least the first block of NVRAM */
45864- nvram.size = address_space - NVRAM_OFFSET;
45865+ pax_open_kernel();
45866+ *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
45867+ pax_close_kernel();
45868 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
45869 if (retval < 0) {
45870 dev_dbg(dev, "can't create nvram file? %d\n", retval);
45871diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
45872index d049393..bb20be0 100644
45873--- a/drivers/rtc/rtc-dev.c
45874+++ b/drivers/rtc/rtc-dev.c
45875@@ -16,6 +16,7 @@
45876 #include <linux/module.h>
45877 #include <linux/rtc.h>
45878 #include <linux/sched.h>
45879+#include <linux/grsecurity.h>
45880 #include "rtc-core.h"
45881
45882 static dev_t rtc_devt;
45883@@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
45884 if (copy_from_user(&tm, uarg, sizeof(tm)))
45885 return -EFAULT;
45886
45887+ gr_log_timechange();
45888+
45889 return rtc_set_time(rtc, &tm);
45890
45891 case RTC_PIE_ON:
45892diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
45893index ca18fd1..055e42d 100644
45894--- a/drivers/rtc/rtc-ds1307.c
45895+++ b/drivers/rtc/rtc-ds1307.c
45896@@ -107,7 +107,7 @@ struct ds1307 {
45897 u8 offset; /* register's offset */
45898 u8 regs[11];
45899 u16 nvram_offset;
45900- struct bin_attribute *nvram;
45901+ bin_attribute_no_const *nvram;
45902 enum ds_type type;
45903 unsigned long flags;
45904 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
45905diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
45906index fcb0329..d77b7f2 100644
45907--- a/drivers/rtc/rtc-m48t59.c
45908+++ b/drivers/rtc/rtc-m48t59.c
45909@@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
45910 if (IS_ERR(m48t59->rtc))
45911 return PTR_ERR(m48t59->rtc);
45912
45913- m48t59_nvram_attr.size = pdata->offset;
45914+ pax_open_kernel();
45915+ *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
45916+ pax_close_kernel();
45917
45918 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
45919 if (ret)
45920diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
45921index e693af6..2e525b6 100644
45922--- a/drivers/scsi/bfa/bfa_fcpim.h
45923+++ b/drivers/scsi/bfa/bfa_fcpim.h
45924@@ -36,7 +36,7 @@ struct bfa_iotag_s {
45925
45926 struct bfa_itn_s {
45927 bfa_isr_func_t isr;
45928-};
45929+} __no_const;
45930
45931 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
45932 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
45933diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
45934index 90814fe..4384138 100644
45935--- a/drivers/scsi/bfa/bfa_ioc.h
45936+++ b/drivers/scsi/bfa/bfa_ioc.h
45937@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
45938 bfa_ioc_disable_cbfn_t disable_cbfn;
45939 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
45940 bfa_ioc_reset_cbfn_t reset_cbfn;
45941-};
45942+} __no_const;
45943
45944 /*
45945 * IOC event notification mechanism.
45946@@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
45947 void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
45948 enum bfi_ioc_state fwstate);
45949 enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
45950-};
45951+} __no_const;
45952
45953 /*
45954 * Queue element to wait for room in request queue. FIFO order is
45955diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
45956index c9382d6..6619864 100644
45957--- a/drivers/scsi/fcoe/fcoe_sysfs.c
45958+++ b/drivers/scsi/fcoe/fcoe_sysfs.c
45959@@ -33,8 +33,8 @@
45960 */
45961 #include "libfcoe.h"
45962
45963-static atomic_t ctlr_num;
45964-static atomic_t fcf_num;
45965+static atomic_unchecked_t ctlr_num;
45966+static atomic_unchecked_t fcf_num;
45967
45968 /*
45969 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
45970@@ -681,7 +681,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
45971 if (!ctlr)
45972 goto out;
45973
45974- ctlr->id = atomic_inc_return(&ctlr_num) - 1;
45975+ ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
45976 ctlr->f = f;
45977 ctlr->mode = FIP_CONN_TYPE_FABRIC;
45978 INIT_LIST_HEAD(&ctlr->fcfs);
45979@@ -898,7 +898,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
45980 fcf->dev.parent = &ctlr->dev;
45981 fcf->dev.bus = &fcoe_bus_type;
45982 fcf->dev.type = &fcoe_fcf_device_type;
45983- fcf->id = atomic_inc_return(&fcf_num) - 1;
45984+ fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
45985 fcf->state = FCOE_FCF_STATE_UNKNOWN;
45986
45987 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
45988@@ -934,8 +934,8 @@ int __init fcoe_sysfs_setup(void)
45989 {
45990 int error;
45991
45992- atomic_set(&ctlr_num, 0);
45993- atomic_set(&fcf_num, 0);
45994+ atomic_set_unchecked(&ctlr_num, 0);
45995+ atomic_set_unchecked(&fcf_num, 0);
45996
45997 error = bus_register(&fcoe_bus_type);
45998 if (error)
45999diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
46000index df0c3c7..b00e1d0 100644
46001--- a/drivers/scsi/hosts.c
46002+++ b/drivers/scsi/hosts.c
46003@@ -42,7 +42,7 @@
46004 #include "scsi_logging.h"
46005
46006
46007-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
46008+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
46009
46010
46011 static void scsi_host_cls_release(struct device *dev)
46012@@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
46013 * subtract one because we increment first then return, but we need to
46014 * know what the next host number was before increment
46015 */
46016- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
46017+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
46018 shost->dma_channel = 0xff;
46019
46020 /* These three are default values which can be overridden */
46021diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
46022index 7f4f790..b75b92a 100644
46023--- a/drivers/scsi/hpsa.c
46024+++ b/drivers/scsi/hpsa.c
46025@@ -554,7 +554,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
46026 unsigned long flags;
46027
46028 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
46029- return h->access.command_completed(h, q);
46030+ return h->access->command_completed(h, q);
46031
46032 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
46033 a = rq->head[rq->current_entry];
46034@@ -3422,7 +3422,7 @@ static void start_io(struct ctlr_info *h)
46035 while (!list_empty(&h->reqQ)) {
46036 c = list_entry(h->reqQ.next, struct CommandList, list);
46037 /* can't do anything if fifo is full */
46038- if ((h->access.fifo_full(h))) {
46039+ if ((h->access->fifo_full(h))) {
46040 dev_warn(&h->pdev->dev, "fifo full\n");
46041 break;
46042 }
46043@@ -3444,7 +3444,7 @@ static void start_io(struct ctlr_info *h)
46044
46045 /* Tell the controller execute command */
46046 spin_unlock_irqrestore(&h->lock, flags);
46047- h->access.submit_command(h, c);
46048+ h->access->submit_command(h, c);
46049 spin_lock_irqsave(&h->lock, flags);
46050 }
46051 spin_unlock_irqrestore(&h->lock, flags);
46052@@ -3452,17 +3452,17 @@ static void start_io(struct ctlr_info *h)
46053
46054 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
46055 {
46056- return h->access.command_completed(h, q);
46057+ return h->access->command_completed(h, q);
46058 }
46059
46060 static inline bool interrupt_pending(struct ctlr_info *h)
46061 {
46062- return h->access.intr_pending(h);
46063+ return h->access->intr_pending(h);
46064 }
46065
46066 static inline long interrupt_not_for_us(struct ctlr_info *h)
46067 {
46068- return (h->access.intr_pending(h) == 0) ||
46069+ return (h->access->intr_pending(h) == 0) ||
46070 (h->interrupts_enabled == 0);
46071 }
46072
46073@@ -4364,7 +4364,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
46074 if (prod_index < 0)
46075 return -ENODEV;
46076 h->product_name = products[prod_index].product_name;
46077- h->access = *(products[prod_index].access);
46078+ h->access = products[prod_index].access;
46079
46080 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
46081 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
46082@@ -4646,7 +4646,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
46083
46084 assert_spin_locked(&lockup_detector_lock);
46085 remove_ctlr_from_lockup_detector_list(h);
46086- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46087+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46088 spin_lock_irqsave(&h->lock, flags);
46089 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
46090 spin_unlock_irqrestore(&h->lock, flags);
46091@@ -4823,7 +4823,7 @@ reinit_after_soft_reset:
46092 }
46093
46094 /* make sure the board interrupts are off */
46095- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46096+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46097
46098 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
46099 goto clean2;
46100@@ -4857,7 +4857,7 @@ reinit_after_soft_reset:
46101 * fake ones to scoop up any residual completions.
46102 */
46103 spin_lock_irqsave(&h->lock, flags);
46104- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46105+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46106 spin_unlock_irqrestore(&h->lock, flags);
46107 free_irqs(h);
46108 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
46109@@ -4876,9 +4876,9 @@ reinit_after_soft_reset:
46110 dev_info(&h->pdev->dev, "Board READY.\n");
46111 dev_info(&h->pdev->dev,
46112 "Waiting for stale completions to drain.\n");
46113- h->access.set_intr_mask(h, HPSA_INTR_ON);
46114+ h->access->set_intr_mask(h, HPSA_INTR_ON);
46115 msleep(10000);
46116- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46117+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46118
46119 rc = controller_reset_failed(h->cfgtable);
46120 if (rc)
46121@@ -4899,7 +4899,7 @@ reinit_after_soft_reset:
46122 }
46123
46124 /* Turn the interrupts on so we can service requests */
46125- h->access.set_intr_mask(h, HPSA_INTR_ON);
46126+ h->access->set_intr_mask(h, HPSA_INTR_ON);
46127
46128 hpsa_hba_inquiry(h);
46129 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
46130@@ -4954,7 +4954,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
46131 * To write all data in the battery backed cache to disks
46132 */
46133 hpsa_flush_cache(h);
46134- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46135+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46136 hpsa_free_irqs_and_disable_msix(h);
46137 }
46138
46139@@ -5122,7 +5122,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
46140 return;
46141 }
46142 /* Change the access methods to the performant access methods */
46143- h->access = SA5_performant_access;
46144+ h->access = &SA5_performant_access;
46145 h->transMethod = CFGTBL_Trans_Performant;
46146 }
46147
46148diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
46149index 9816479..c5d4e97 100644
46150--- a/drivers/scsi/hpsa.h
46151+++ b/drivers/scsi/hpsa.h
46152@@ -79,7 +79,7 @@ struct ctlr_info {
46153 unsigned int msix_vector;
46154 unsigned int msi_vector;
46155 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
46156- struct access_method access;
46157+ struct access_method *access;
46158
46159 /* queue and queue Info */
46160 struct list_head reqQ;
46161diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
46162index 5879929..32b241d 100644
46163--- a/drivers/scsi/libfc/fc_exch.c
46164+++ b/drivers/scsi/libfc/fc_exch.c
46165@@ -100,12 +100,12 @@ struct fc_exch_mgr {
46166 u16 pool_max_index;
46167
46168 struct {
46169- atomic_t no_free_exch;
46170- atomic_t no_free_exch_xid;
46171- atomic_t xid_not_found;
46172- atomic_t xid_busy;
46173- atomic_t seq_not_found;
46174- atomic_t non_bls_resp;
46175+ atomic_unchecked_t no_free_exch;
46176+ atomic_unchecked_t no_free_exch_xid;
46177+ atomic_unchecked_t xid_not_found;
46178+ atomic_unchecked_t xid_busy;
46179+ atomic_unchecked_t seq_not_found;
46180+ atomic_unchecked_t non_bls_resp;
46181 } stats;
46182 };
46183
46184@@ -736,7 +736,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
46185 /* allocate memory for exchange */
46186 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
46187 if (!ep) {
46188- atomic_inc(&mp->stats.no_free_exch);
46189+ atomic_inc_unchecked(&mp->stats.no_free_exch);
46190 goto out;
46191 }
46192 memset(ep, 0, sizeof(*ep));
46193@@ -797,7 +797,7 @@ out:
46194 return ep;
46195 err:
46196 spin_unlock_bh(&pool->lock);
46197- atomic_inc(&mp->stats.no_free_exch_xid);
46198+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
46199 mempool_free(ep, mp->ep_pool);
46200 return NULL;
46201 }
46202@@ -940,7 +940,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
46203 xid = ntohs(fh->fh_ox_id); /* we originated exch */
46204 ep = fc_exch_find(mp, xid);
46205 if (!ep) {
46206- atomic_inc(&mp->stats.xid_not_found);
46207+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46208 reject = FC_RJT_OX_ID;
46209 goto out;
46210 }
46211@@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
46212 ep = fc_exch_find(mp, xid);
46213 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
46214 if (ep) {
46215- atomic_inc(&mp->stats.xid_busy);
46216+ atomic_inc_unchecked(&mp->stats.xid_busy);
46217 reject = FC_RJT_RX_ID;
46218 goto rel;
46219 }
46220@@ -981,7 +981,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
46221 }
46222 xid = ep->xid; /* get our XID */
46223 } else if (!ep) {
46224- atomic_inc(&mp->stats.xid_not_found);
46225+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46226 reject = FC_RJT_RX_ID; /* XID not found */
46227 goto out;
46228 }
46229@@ -998,7 +998,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
46230 } else {
46231 sp = &ep->seq;
46232 if (sp->id != fh->fh_seq_id) {
46233- atomic_inc(&mp->stats.seq_not_found);
46234+ atomic_inc_unchecked(&mp->stats.seq_not_found);
46235 if (f_ctl & FC_FC_END_SEQ) {
46236 /*
46237 * Update sequence_id based on incoming last
46238@@ -1448,22 +1448,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
46239
46240 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
46241 if (!ep) {
46242- atomic_inc(&mp->stats.xid_not_found);
46243+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46244 goto out;
46245 }
46246 if (ep->esb_stat & ESB_ST_COMPLETE) {
46247- atomic_inc(&mp->stats.xid_not_found);
46248+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46249 goto rel;
46250 }
46251 if (ep->rxid == FC_XID_UNKNOWN)
46252 ep->rxid = ntohs(fh->fh_rx_id);
46253 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
46254- atomic_inc(&mp->stats.xid_not_found);
46255+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46256 goto rel;
46257 }
46258 if (ep->did != ntoh24(fh->fh_s_id) &&
46259 ep->did != FC_FID_FLOGI) {
46260- atomic_inc(&mp->stats.xid_not_found);
46261+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46262 goto rel;
46263 }
46264 sof = fr_sof(fp);
46265@@ -1472,7 +1472,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
46266 sp->ssb_stat |= SSB_ST_RESP;
46267 sp->id = fh->fh_seq_id;
46268 } else if (sp->id != fh->fh_seq_id) {
46269- atomic_inc(&mp->stats.seq_not_found);
46270+ atomic_inc_unchecked(&mp->stats.seq_not_found);
46271 goto rel;
46272 }
46273
46274@@ -1536,9 +1536,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
46275 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
46276
46277 if (!sp)
46278- atomic_inc(&mp->stats.xid_not_found);
46279+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46280 else
46281- atomic_inc(&mp->stats.non_bls_resp);
46282+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
46283
46284 fc_frame_free(fp);
46285 }
46286@@ -2185,13 +2185,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
46287
46288 list_for_each_entry(ema, &lport->ema_list, ema_list) {
46289 mp = ema->mp;
46290- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
46291+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
46292 st->fc_no_free_exch_xid +=
46293- atomic_read(&mp->stats.no_free_exch_xid);
46294- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
46295- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
46296- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
46297- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
46298+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
46299+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
46300+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
46301+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
46302+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
46303 }
46304 }
46305 EXPORT_SYMBOL(fc_exch_update_stats);
46306diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
46307index 161c98e..6d563b3 100644
46308--- a/drivers/scsi/libsas/sas_ata.c
46309+++ b/drivers/scsi/libsas/sas_ata.c
46310@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
46311 .postreset = ata_std_postreset,
46312 .error_handler = ata_std_error_handler,
46313 .post_internal_cmd = sas_ata_post_internal,
46314- .qc_defer = ata_std_qc_defer,
46315+ .qc_defer = ata_std_qc_defer,
46316 .qc_prep = ata_noop_qc_prep,
46317 .qc_issue = sas_ata_qc_issue,
46318 .qc_fill_rtf = sas_ata_qc_fill_rtf,
46319diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
46320index 93f222d..73e977b 100644
46321--- a/drivers/scsi/lpfc/lpfc.h
46322+++ b/drivers/scsi/lpfc/lpfc.h
46323@@ -431,7 +431,7 @@ struct lpfc_vport {
46324 struct dentry *debug_nodelist;
46325 struct dentry *vport_debugfs_root;
46326 struct lpfc_debugfs_trc *disc_trc;
46327- atomic_t disc_trc_cnt;
46328+ atomic_unchecked_t disc_trc_cnt;
46329 #endif
46330 uint8_t stat_data_enabled;
46331 uint8_t stat_data_blocked;
46332@@ -865,8 +865,8 @@ struct lpfc_hba {
46333 struct timer_list fabric_block_timer;
46334 unsigned long bit_flags;
46335 #define FABRIC_COMANDS_BLOCKED 0
46336- atomic_t num_rsrc_err;
46337- atomic_t num_cmd_success;
46338+ atomic_unchecked_t num_rsrc_err;
46339+ atomic_unchecked_t num_cmd_success;
46340 unsigned long last_rsrc_error_time;
46341 unsigned long last_ramp_down_time;
46342 unsigned long last_ramp_up_time;
46343@@ -902,7 +902,7 @@ struct lpfc_hba {
46344
46345 struct dentry *debug_slow_ring_trc;
46346 struct lpfc_debugfs_trc *slow_ring_trc;
46347- atomic_t slow_ring_trc_cnt;
46348+ atomic_unchecked_t slow_ring_trc_cnt;
46349 /* iDiag debugfs sub-directory */
46350 struct dentry *idiag_root;
46351 struct dentry *idiag_pci_cfg;
46352diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
46353index 60084e6..0e2e700 100644
46354--- a/drivers/scsi/lpfc/lpfc_debugfs.c
46355+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
46356@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
46357
46358 #include <linux/debugfs.h>
46359
46360-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
46361+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
46362 static unsigned long lpfc_debugfs_start_time = 0L;
46363
46364 /* iDiag */
46365@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
46366 lpfc_debugfs_enable = 0;
46367
46368 len = 0;
46369- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
46370+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
46371 (lpfc_debugfs_max_disc_trc - 1);
46372 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
46373 dtp = vport->disc_trc + i;
46374@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
46375 lpfc_debugfs_enable = 0;
46376
46377 len = 0;
46378- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
46379+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
46380 (lpfc_debugfs_max_slow_ring_trc - 1);
46381 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
46382 dtp = phba->slow_ring_trc + i;
46383@@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
46384 !vport || !vport->disc_trc)
46385 return;
46386
46387- index = atomic_inc_return(&vport->disc_trc_cnt) &
46388+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
46389 (lpfc_debugfs_max_disc_trc - 1);
46390 dtp = vport->disc_trc + index;
46391 dtp->fmt = fmt;
46392 dtp->data1 = data1;
46393 dtp->data2 = data2;
46394 dtp->data3 = data3;
46395- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
46396+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
46397 dtp->jif = jiffies;
46398 #endif
46399 return;
46400@@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
46401 !phba || !phba->slow_ring_trc)
46402 return;
46403
46404- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
46405+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
46406 (lpfc_debugfs_max_slow_ring_trc - 1);
46407 dtp = phba->slow_ring_trc + index;
46408 dtp->fmt = fmt;
46409 dtp->data1 = data1;
46410 dtp->data2 = data2;
46411 dtp->data3 = data3;
46412- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
46413+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
46414 dtp->jif = jiffies;
46415 #endif
46416 return;
46417@@ -4168,7 +4168,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
46418 "slow_ring buffer\n");
46419 goto debug_failed;
46420 }
46421- atomic_set(&phba->slow_ring_trc_cnt, 0);
46422+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
46423 memset(phba->slow_ring_trc, 0,
46424 (sizeof(struct lpfc_debugfs_trc) *
46425 lpfc_debugfs_max_slow_ring_trc));
46426@@ -4214,7 +4214,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
46427 "buffer\n");
46428 goto debug_failed;
46429 }
46430- atomic_set(&vport->disc_trc_cnt, 0);
46431+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
46432
46433 snprintf(name, sizeof(name), "discovery_trace");
46434 vport->debug_disc_trc =
46435diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
46436index e0b20fa..30c2c0d 100644
46437--- a/drivers/scsi/lpfc/lpfc_init.c
46438+++ b/drivers/scsi/lpfc/lpfc_init.c
46439@@ -10936,8 +10936,10 @@ lpfc_init(void)
46440 "misc_register returned with status %d", error);
46441
46442 if (lpfc_enable_npiv) {
46443- lpfc_transport_functions.vport_create = lpfc_vport_create;
46444- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
46445+ pax_open_kernel();
46446+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
46447+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
46448+ pax_close_kernel();
46449 }
46450 lpfc_transport_template =
46451 fc_attach_transport(&lpfc_transport_functions);
46452diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
46453index 243de1d..f40e3e5 100644
46454--- a/drivers/scsi/lpfc/lpfc_scsi.c
46455+++ b/drivers/scsi/lpfc/lpfc_scsi.c
46456@@ -353,7 +353,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
46457 uint32_t evt_posted;
46458
46459 spin_lock_irqsave(&phba->hbalock, flags);
46460- atomic_inc(&phba->num_rsrc_err);
46461+ atomic_inc_unchecked(&phba->num_rsrc_err);
46462 phba->last_rsrc_error_time = jiffies;
46463
46464 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
46465@@ -394,7 +394,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
46466 unsigned long flags;
46467 struct lpfc_hba *phba = vport->phba;
46468 uint32_t evt_posted;
46469- atomic_inc(&phba->num_cmd_success);
46470+ atomic_inc_unchecked(&phba->num_cmd_success);
46471
46472 if (vport->cfg_lun_queue_depth <= queue_depth)
46473 return;
46474@@ -438,8 +438,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
46475 unsigned long num_rsrc_err, num_cmd_success;
46476 int i;
46477
46478- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
46479- num_cmd_success = atomic_read(&phba->num_cmd_success);
46480+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
46481+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
46482
46483 /*
46484 * The error and success command counters are global per
46485@@ -467,8 +467,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
46486 }
46487 }
46488 lpfc_destroy_vport_work_array(phba, vports);
46489- atomic_set(&phba->num_rsrc_err, 0);
46490- atomic_set(&phba->num_cmd_success, 0);
46491+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
46492+ atomic_set_unchecked(&phba->num_cmd_success, 0);
46493 }
46494
46495 /**
46496@@ -502,8 +502,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
46497 }
46498 }
46499 lpfc_destroy_vport_work_array(phba, vports);
46500- atomic_set(&phba->num_rsrc_err, 0);
46501- atomic_set(&phba->num_cmd_success, 0);
46502+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
46503+ atomic_set_unchecked(&phba->num_cmd_success, 0);
46504 }
46505
46506 /**
46507diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
46508index 1eb7b028..b2a6080 100644
46509--- a/drivers/scsi/pmcraid.c
46510+++ b/drivers/scsi/pmcraid.c
46511@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
46512 res->scsi_dev = scsi_dev;
46513 scsi_dev->hostdata = res;
46514 res->change_detected = 0;
46515- atomic_set(&res->read_failures, 0);
46516- atomic_set(&res->write_failures, 0);
46517+ atomic_set_unchecked(&res->read_failures, 0);
46518+ atomic_set_unchecked(&res->write_failures, 0);
46519 rc = 0;
46520 }
46521 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
46522@@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
46523
46524 /* If this was a SCSI read/write command keep count of errors */
46525 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
46526- atomic_inc(&res->read_failures);
46527+ atomic_inc_unchecked(&res->read_failures);
46528 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
46529- atomic_inc(&res->write_failures);
46530+ atomic_inc_unchecked(&res->write_failures);
46531
46532 if (!RES_IS_GSCSI(res->cfg_entry) &&
46533 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
46534@@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
46535 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
46536 * hrrq_id assigned here in queuecommand
46537 */
46538- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
46539+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
46540 pinstance->num_hrrq;
46541 cmd->cmd_done = pmcraid_io_done;
46542
46543@@ -3846,7 +3846,7 @@ static long pmcraid_ioctl_passthrough(
46544 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
46545 * hrrq_id assigned here in queuecommand
46546 */
46547- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
46548+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
46549 pinstance->num_hrrq;
46550
46551 if (request_size) {
46552@@ -4483,7 +4483,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
46553
46554 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
46555 /* add resources only after host is added into system */
46556- if (!atomic_read(&pinstance->expose_resources))
46557+ if (!atomic_read_unchecked(&pinstance->expose_resources))
46558 return;
46559
46560 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
46561@@ -5310,8 +5310,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
46562 init_waitqueue_head(&pinstance->reset_wait_q);
46563
46564 atomic_set(&pinstance->outstanding_cmds, 0);
46565- atomic_set(&pinstance->last_message_id, 0);
46566- atomic_set(&pinstance->expose_resources, 0);
46567+ atomic_set_unchecked(&pinstance->last_message_id, 0);
46568+ atomic_set_unchecked(&pinstance->expose_resources, 0);
46569
46570 INIT_LIST_HEAD(&pinstance->free_res_q);
46571 INIT_LIST_HEAD(&pinstance->used_res_q);
46572@@ -6024,7 +6024,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
46573 /* Schedule worker thread to handle CCN and take care of adding and
46574 * removing devices to OS
46575 */
46576- atomic_set(&pinstance->expose_resources, 1);
46577+ atomic_set_unchecked(&pinstance->expose_resources, 1);
46578 schedule_work(&pinstance->worker_q);
46579 return rc;
46580
46581diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
46582index e1d150f..6c6df44 100644
46583--- a/drivers/scsi/pmcraid.h
46584+++ b/drivers/scsi/pmcraid.h
46585@@ -748,7 +748,7 @@ struct pmcraid_instance {
46586 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
46587
46588 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
46589- atomic_t last_message_id;
46590+ atomic_unchecked_t last_message_id;
46591
46592 /* configuration table */
46593 struct pmcraid_config_table *cfg_table;
46594@@ -777,7 +777,7 @@ struct pmcraid_instance {
46595 atomic_t outstanding_cmds;
46596
46597 /* should add/delete resources to mid-layer now ?*/
46598- atomic_t expose_resources;
46599+ atomic_unchecked_t expose_resources;
46600
46601
46602
46603@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
46604 struct pmcraid_config_table_entry_ext cfg_entry_ext;
46605 };
46606 struct scsi_device *scsi_dev; /* Link scsi_device structure */
46607- atomic_t read_failures; /* count of failed READ commands */
46608- atomic_t write_failures; /* count of failed WRITE commands */
46609+ atomic_unchecked_t read_failures; /* count of failed READ commands */
46610+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
46611
46612 /* To indicate add/delete/modify during CCN */
46613 u8 change_detected;
46614diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
46615index d7a99ae..801df70 100644
46616--- a/drivers/scsi/qla2xxx/qla_attr.c
46617+++ b/drivers/scsi/qla2xxx/qla_attr.c
46618@@ -2004,7 +2004,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
46619 return 0;
46620 }
46621
46622-struct fc_function_template qla2xxx_transport_functions = {
46623+fc_function_template_no_const qla2xxx_transport_functions = {
46624
46625 .show_host_node_name = 1,
46626 .show_host_port_name = 1,
46627@@ -2051,7 +2051,7 @@ struct fc_function_template qla2xxx_transport_functions = {
46628 .bsg_timeout = qla24xx_bsg_timeout,
46629 };
46630
46631-struct fc_function_template qla2xxx_transport_vport_functions = {
46632+fc_function_template_no_const qla2xxx_transport_vport_functions = {
46633
46634 .show_host_node_name = 1,
46635 .show_host_port_name = 1,
46636diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
46637index 2d98232..a84298e 100644
46638--- a/drivers/scsi/qla2xxx/qla_gbl.h
46639+++ b/drivers/scsi/qla2xxx/qla_gbl.h
46640@@ -528,8 +528,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
46641 struct device_attribute;
46642 extern struct device_attribute *qla2x00_host_attrs[];
46643 struct fc_function_template;
46644-extern struct fc_function_template qla2xxx_transport_functions;
46645-extern struct fc_function_template qla2xxx_transport_vport_functions;
46646+extern fc_function_template_no_const qla2xxx_transport_functions;
46647+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
46648 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
46649 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
46650 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
46651diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
46652index 3e21e9f..426ba79 100644
46653--- a/drivers/scsi/qla2xxx/qla_os.c
46654+++ b/drivers/scsi/qla2xxx/qla_os.c
46655@@ -1570,8 +1570,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
46656 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
46657 /* Ok, a 64bit DMA mask is applicable. */
46658 ha->flags.enable_64bit_addressing = 1;
46659- ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
46660- ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
46661+ pax_open_kernel();
46662+ *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
46663+ *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
46664+ pax_close_kernel();
46665 return;
46666 }
46667 }
46668diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
46669index ddf16a8..80f4dd0 100644
46670--- a/drivers/scsi/qla4xxx/ql4_def.h
46671+++ b/drivers/scsi/qla4xxx/ql4_def.h
46672@@ -291,7 +291,7 @@ struct ddb_entry {
46673 * (4000 only) */
46674 atomic_t relogin_timer; /* Max Time to wait for
46675 * relogin to complete */
46676- atomic_t relogin_retry_count; /* Num of times relogin has been
46677+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
46678 * retried */
46679 uint32_t default_time2wait; /* Default Min time between
46680 * relogins (+aens) */
46681diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
46682index b246b3c..897004d 100644
46683--- a/drivers/scsi/qla4xxx/ql4_os.c
46684+++ b/drivers/scsi/qla4xxx/ql4_os.c
46685@@ -2971,12 +2971,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
46686 */
46687 if (!iscsi_is_session_online(cls_sess)) {
46688 /* Reset retry relogin timer */
46689- atomic_inc(&ddb_entry->relogin_retry_count);
46690+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
46691 DEBUG2(ql4_printk(KERN_INFO, ha,
46692 "%s: index[%d] relogin timed out-retrying"
46693 " relogin (%d), retry (%d)\n", __func__,
46694 ddb_entry->fw_ddb_index,
46695- atomic_read(&ddb_entry->relogin_retry_count),
46696+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
46697 ddb_entry->default_time2wait + 4));
46698 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
46699 atomic_set(&ddb_entry->retry_relogin_timer,
46700@@ -5081,7 +5081,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
46701
46702 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
46703 atomic_set(&ddb_entry->relogin_timer, 0);
46704- atomic_set(&ddb_entry->relogin_retry_count, 0);
46705+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
46706 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
46707 ddb_entry->default_relogin_timeout =
46708 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
46709diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
46710index eaa808e..95f8841 100644
46711--- a/drivers/scsi/scsi.c
46712+++ b/drivers/scsi/scsi.c
46713@@ -661,7 +661,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
46714 unsigned long timeout;
46715 int rtn = 0;
46716
46717- atomic_inc(&cmd->device->iorequest_cnt);
46718+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
46719
46720 /* check if the device is still usable */
46721 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
46722diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
46723index 124392f..75eb43e 100644
46724--- a/drivers/scsi/scsi_lib.c
46725+++ b/drivers/scsi/scsi_lib.c
46726@@ -1474,7 +1474,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
46727 shost = sdev->host;
46728 scsi_init_cmd_errh(cmd);
46729 cmd->result = DID_NO_CONNECT << 16;
46730- atomic_inc(&cmd->device->iorequest_cnt);
46731+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
46732
46733 /*
46734 * SCSI request completion path will do scsi_device_unbusy(),
46735@@ -1500,9 +1500,9 @@ static void scsi_softirq_done(struct request *rq)
46736
46737 INIT_LIST_HEAD(&cmd->eh_entry);
46738
46739- atomic_inc(&cmd->device->iodone_cnt);
46740+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
46741 if (cmd->result)
46742- atomic_inc(&cmd->device->ioerr_cnt);
46743+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
46744
46745 disposition = scsi_decide_disposition(cmd);
46746 if (disposition != SUCCESS &&
46747diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
46748index 7e50061..71db7a6 100644
46749--- a/drivers/scsi/scsi_sysfs.c
46750+++ b/drivers/scsi/scsi_sysfs.c
46751@@ -687,7 +687,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
46752 char *buf) \
46753 { \
46754 struct scsi_device *sdev = to_scsi_device(dev); \
46755- unsigned long long count = atomic_read(&sdev->field); \
46756+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
46757 return snprintf(buf, 20, "0x%llx\n", count); \
46758 } \
46759 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
46760diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
46761index 84a1fdf..693b0d6 100644
46762--- a/drivers/scsi/scsi_tgt_lib.c
46763+++ b/drivers/scsi/scsi_tgt_lib.c
46764@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
46765 int err;
46766
46767 dprintk("%lx %u\n", uaddr, len);
46768- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
46769+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
46770 if (err) {
46771 /*
46772 * TODO: need to fixup sg_tablesize, max_segment_size,
46773diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
46774index 4628fd5..a94a1c2 100644
46775--- a/drivers/scsi/scsi_transport_fc.c
46776+++ b/drivers/scsi/scsi_transport_fc.c
46777@@ -497,7 +497,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
46778 * Netlink Infrastructure
46779 */
46780
46781-static atomic_t fc_event_seq;
46782+static atomic_unchecked_t fc_event_seq;
46783
46784 /**
46785 * fc_get_event_number - Obtain the next sequential FC event number
46786@@ -510,7 +510,7 @@ static atomic_t fc_event_seq;
46787 u32
46788 fc_get_event_number(void)
46789 {
46790- return atomic_add_return(1, &fc_event_seq);
46791+ return atomic_add_return_unchecked(1, &fc_event_seq);
46792 }
46793 EXPORT_SYMBOL(fc_get_event_number);
46794
46795@@ -654,7 +654,7 @@ static __init int fc_transport_init(void)
46796 {
46797 int error;
46798
46799- atomic_set(&fc_event_seq, 0);
46800+ atomic_set_unchecked(&fc_event_seq, 0);
46801
46802 error = transport_class_register(&fc_host_class);
46803 if (error)
46804@@ -844,7 +844,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
46805 char *cp;
46806
46807 *val = simple_strtoul(buf, &cp, 0);
46808- if ((*cp && (*cp != '\n')) || (*val < 0))
46809+ if (*cp && (*cp != '\n'))
46810 return -EINVAL;
46811 /*
46812 * Check for overflow; dev_loss_tmo is u32
46813diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
46814index abf7c40..c3240ed 100644
46815--- a/drivers/scsi/scsi_transport_iscsi.c
46816+++ b/drivers/scsi/scsi_transport_iscsi.c
46817@@ -80,7 +80,7 @@ struct iscsi_internal {
46818 struct transport_container session_cont;
46819 };
46820
46821-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
46822+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
46823 static struct workqueue_struct *iscsi_eh_timer_workq;
46824
46825 static DEFINE_IDA(iscsi_sess_ida);
46826@@ -1738,7 +1738,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
46827 int err;
46828
46829 ihost = shost->shost_data;
46830- session->sid = atomic_add_return(1, &iscsi_session_nr);
46831+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
46832
46833 if (target_id == ISCSI_MAX_TARGET) {
46834 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
46835@@ -3956,7 +3956,7 @@ static __init int iscsi_transport_init(void)
46836 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
46837 ISCSI_TRANSPORT_VERSION);
46838
46839- atomic_set(&iscsi_session_nr, 0);
46840+ atomic_set_unchecked(&iscsi_session_nr, 0);
46841
46842 err = class_register(&iscsi_transport_class);
46843 if (err)
46844diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
46845index f379c7f..e8fc69c 100644
46846--- a/drivers/scsi/scsi_transport_srp.c
46847+++ b/drivers/scsi/scsi_transport_srp.c
46848@@ -33,7 +33,7 @@
46849 #include "scsi_transport_srp_internal.h"
46850
46851 struct srp_host_attrs {
46852- atomic_t next_port_id;
46853+ atomic_unchecked_t next_port_id;
46854 };
46855 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
46856
46857@@ -61,7 +61,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
46858 struct Scsi_Host *shost = dev_to_shost(dev);
46859 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
46860
46861- atomic_set(&srp_host->next_port_id, 0);
46862+ atomic_set_unchecked(&srp_host->next_port_id, 0);
46863 return 0;
46864 }
46865
46866@@ -210,7 +210,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
46867 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
46868 rport->roles = ids->roles;
46869
46870- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
46871+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
46872 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
46873
46874 transport_setup_device(&rport->dev);
46875diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
46876index 2783dd7..d20395b 100644
46877--- a/drivers/scsi/sd.c
46878+++ b/drivers/scsi/sd.c
46879@@ -2933,7 +2933,7 @@ static int sd_probe(struct device *dev)
46880 sdkp->disk = gd;
46881 sdkp->index = index;
46882 atomic_set(&sdkp->openers, 0);
46883- atomic_set(&sdkp->device->ioerr_cnt, 0);
46884+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
46885
46886 if (!sdp->request_queue->rq_timeout) {
46887 if (sdp->type != TYPE_MOD)
46888diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
46889index df5e961..df6b97f 100644
46890--- a/drivers/scsi/sg.c
46891+++ b/drivers/scsi/sg.c
46892@@ -1102,7 +1102,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
46893 sdp->disk->disk_name,
46894 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
46895 NULL,
46896- (char *)arg);
46897+ (char __user *)arg);
46898 case BLKTRACESTART:
46899 return blk_trace_startstop(sdp->device->request_queue, 1);
46900 case BLKTRACESTOP:
46901diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
46902index 978dda2..cb19aa0 100644
46903--- a/drivers/spi/spi.c
46904+++ b/drivers/spi/spi.c
46905@@ -1631,7 +1631,7 @@ int spi_bus_unlock(struct spi_master *master)
46906 EXPORT_SYMBOL_GPL(spi_bus_unlock);
46907
46908 /* portable code must never pass more than 32 bytes */
46909-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
46910+#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
46911
46912 static u8 *buf;
46913
46914diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
46915index ee3a57f..18368c1 100644
46916--- a/drivers/staging/android/timed_output.c
46917+++ b/drivers/staging/android/timed_output.c
46918@@ -25,7 +25,7 @@
46919 #include "timed_output.h"
46920
46921 static struct class *timed_output_class;
46922-static atomic_t device_count;
46923+static atomic_unchecked_t device_count;
46924
46925 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
46926 char *buf)
46927@@ -59,7 +59,7 @@ static int create_timed_output_class(void)
46928 timed_output_class = class_create(THIS_MODULE, "timed_output");
46929 if (IS_ERR(timed_output_class))
46930 return PTR_ERR(timed_output_class);
46931- atomic_set(&device_count, 0);
46932+ atomic_set_unchecked(&device_count, 0);
46933 }
46934
46935 return 0;
46936@@ -76,7 +76,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
46937 if (ret < 0)
46938 return ret;
46939
46940- tdev->index = atomic_inc_return(&device_count);
46941+ tdev->index = atomic_inc_return_unchecked(&device_count);
46942 tdev->dev = device_create(timed_output_class, NULL,
46943 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
46944 if (IS_ERR(tdev->dev))
46945diff --git a/drivers/staging/media/solo6x10/solo6x10-core.c b/drivers/staging/media/solo6x10/solo6x10-core.c
46946index 3675020..e80d92c 100644
46947--- a/drivers/staging/media/solo6x10/solo6x10-core.c
46948+++ b/drivers/staging/media/solo6x10/solo6x10-core.c
46949@@ -434,7 +434,7 @@ static void solo_device_release(struct device *dev)
46950
46951 static int solo_sysfs_init(struct solo_dev *solo_dev)
46952 {
46953- struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
46954+ bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
46955 struct device *dev = &solo_dev->dev;
46956 const char *driver;
46957 int i;
46958diff --git a/drivers/staging/media/solo6x10/solo6x10-p2m.c b/drivers/staging/media/solo6x10/solo6x10-p2m.c
46959index 3335941..2b26186 100644
46960--- a/drivers/staging/media/solo6x10/solo6x10-p2m.c
46961+++ b/drivers/staging/media/solo6x10/solo6x10-p2m.c
46962@@ -77,7 +77,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
46963
46964 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
46965 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
46966- p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
46967+ p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
46968 if (p2m_id < 0)
46969 p2m_id = -p2m_id;
46970 }
46971diff --git a/drivers/staging/media/solo6x10/solo6x10.h b/drivers/staging/media/solo6x10/solo6x10.h
46972index 6f91d2e..3f011d2 100644
46973--- a/drivers/staging/media/solo6x10/solo6x10.h
46974+++ b/drivers/staging/media/solo6x10/solo6x10.h
46975@@ -238,7 +238,7 @@ struct solo_dev {
46976
46977 /* P2M DMA Engine */
46978 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
46979- atomic_t p2m_count;
46980+ atomic_unchecked_t p2m_count;
46981 int p2m_jiffies;
46982 unsigned int p2m_timeouts;
46983
46984diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
46985index 34afc16..ffe44dd 100644
46986--- a/drivers/staging/octeon/ethernet-rx.c
46987+++ b/drivers/staging/octeon/ethernet-rx.c
46988@@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
46989 /* Increment RX stats for virtual ports */
46990 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
46991 #ifdef CONFIG_64BIT
46992- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
46993- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
46994+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
46995+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
46996 #else
46997- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
46998- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
46999+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
47000+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
47001 #endif
47002 }
47003 netif_receive_skb(skb);
47004@@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
47005 dev->name);
47006 */
47007 #ifdef CONFIG_64BIT
47008- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
47009+ atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
47010 #else
47011- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
47012+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
47013 #endif
47014 dev_kfree_skb_irq(skb);
47015 }
47016diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
47017index c3a90e7..023619a 100644
47018--- a/drivers/staging/octeon/ethernet.c
47019+++ b/drivers/staging/octeon/ethernet.c
47020@@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
47021 * since the RX tasklet also increments it.
47022 */
47023 #ifdef CONFIG_64BIT
47024- atomic64_add(rx_status.dropped_packets,
47025- (atomic64_t *)&priv->stats.rx_dropped);
47026+ atomic64_add_unchecked(rx_status.dropped_packets,
47027+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
47028 #else
47029- atomic_add(rx_status.dropped_packets,
47030- (atomic_t *)&priv->stats.rx_dropped);
47031+ atomic_add_unchecked(rx_status.dropped_packets,
47032+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
47033 #endif
47034 }
47035
47036diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
47037index dc23395..cf7e9b1 100644
47038--- a/drivers/staging/rtl8712/rtl871x_io.h
47039+++ b/drivers/staging/rtl8712/rtl871x_io.h
47040@@ -108,7 +108,7 @@ struct _io_ops {
47041 u8 *pmem);
47042 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
47043 u8 *pmem);
47044-};
47045+} __no_const;
47046
47047 struct io_req {
47048 struct list_head list;
47049diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
47050index 1f5088b..0e59820 100644
47051--- a/drivers/staging/sbe-2t3e3/netdev.c
47052+++ b/drivers/staging/sbe-2t3e3/netdev.c
47053@@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
47054 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
47055
47056 if (rlen)
47057- if (copy_to_user(data, &resp, rlen))
47058+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
47059 return -EFAULT;
47060
47061 return 0;
47062diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
47063index a863a98..d272795 100644
47064--- a/drivers/staging/usbip/vhci.h
47065+++ b/drivers/staging/usbip/vhci.h
47066@@ -83,7 +83,7 @@ struct vhci_hcd {
47067 unsigned resuming:1;
47068 unsigned long re_timeout;
47069
47070- atomic_t seqnum;
47071+ atomic_unchecked_t seqnum;
47072
47073 /*
47074 * NOTE:
47075diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
47076index d7974cb..d78076b 100644
47077--- a/drivers/staging/usbip/vhci_hcd.c
47078+++ b/drivers/staging/usbip/vhci_hcd.c
47079@@ -441,7 +441,7 @@ static void vhci_tx_urb(struct urb *urb)
47080
47081 spin_lock(&vdev->priv_lock);
47082
47083- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
47084+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
47085 if (priv->seqnum == 0xffff)
47086 dev_info(&urb->dev->dev, "seqnum max\n");
47087
47088@@ -687,7 +687,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
47089 return -ENOMEM;
47090 }
47091
47092- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
47093+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
47094 if (unlink->seqnum == 0xffff)
47095 pr_info("seqnum max\n");
47096
47097@@ -891,7 +891,7 @@ static int vhci_start(struct usb_hcd *hcd)
47098 vdev->rhport = rhport;
47099 }
47100
47101- atomic_set(&vhci->seqnum, 0);
47102+ atomic_set_unchecked(&vhci->seqnum, 0);
47103 spin_lock_init(&vhci->lock);
47104
47105 hcd->power_budget = 0; /* no limit */
47106diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
47107index d07fcb5..358e1e1 100644
47108--- a/drivers/staging/usbip/vhci_rx.c
47109+++ b/drivers/staging/usbip/vhci_rx.c
47110@@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
47111 if (!urb) {
47112 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
47113 pr_info("max seqnum %d\n",
47114- atomic_read(&the_controller->seqnum));
47115+ atomic_read_unchecked(&the_controller->seqnum));
47116 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
47117 return;
47118 }
47119diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
47120index 57a08c5..5b4bb7c 100644
47121--- a/drivers/staging/vt6655/hostap.c
47122+++ b/drivers/staging/vt6655/hostap.c
47123@@ -69,14 +69,13 @@ static int msglevel = MSG_LEVEL_INFO;
47124 *
47125 */
47126
47127+static net_device_ops_no_const apdev_netdev_ops;
47128+
47129 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
47130 {
47131 PSDevice apdev_priv;
47132 struct net_device *dev = pDevice->dev;
47133 int ret;
47134- const struct net_device_ops apdev_netdev_ops = {
47135- .ndo_start_xmit = pDevice->tx_80211,
47136- };
47137
47138 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
47139
47140@@ -88,6 +87,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
47141 *apdev_priv = *pDevice;
47142 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
47143
47144+ /* only half broken now */
47145+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
47146 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
47147
47148 pDevice->apdev->type = ARPHRD_IEEE80211;
47149diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
47150index c699a30..b90a5fd 100644
47151--- a/drivers/staging/vt6656/hostap.c
47152+++ b/drivers/staging/vt6656/hostap.c
47153@@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
47154 *
47155 */
47156
47157+static net_device_ops_no_const apdev_netdev_ops;
47158+
47159 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
47160 {
47161 struct vnt_private *apdev_priv;
47162 struct net_device *dev = pDevice->dev;
47163 int ret;
47164- const struct net_device_ops apdev_netdev_ops = {
47165- .ndo_start_xmit = pDevice->tx_80211,
47166- };
47167
47168 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
47169
47170@@ -79,6 +78,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
47171 *apdev_priv = *pDevice;
47172 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
47173
47174+ /* only half broken now */
47175+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
47176 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
47177
47178 pDevice->apdev->type = ARPHRD_IEEE80211;
47179diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
47180index d128ce2..fc1f9a1 100644
47181--- a/drivers/staging/zcache/tmem.h
47182+++ b/drivers/staging/zcache/tmem.h
47183@@ -225,7 +225,7 @@ struct tmem_pamops {
47184 bool (*is_remote)(void *);
47185 int (*replace_in_obj)(void *, struct tmem_obj *);
47186 #endif
47187-};
47188+} __no_const;
47189 extern void tmem_register_pamops(struct tmem_pamops *m);
47190
47191 /* memory allocation methods provided by the host implementation */
47192@@ -234,7 +234,7 @@ struct tmem_hostops {
47193 void (*obj_free)(struct tmem_obj *, struct tmem_pool *);
47194 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
47195 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
47196-};
47197+} __no_const;
47198 extern void tmem_register_hostops(struct tmem_hostops *m);
47199
47200 /* core tmem accessor functions */
47201diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
47202index e51b09a..5ebac31 100644
47203--- a/drivers/target/sbp/sbp_target.c
47204+++ b/drivers/target/sbp/sbp_target.c
47205@@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
47206
47207 #define SESSION_MAINTENANCE_INTERVAL HZ
47208
47209-static atomic_t login_id = ATOMIC_INIT(0);
47210+static atomic_unchecked_t login_id = ATOMIC_INIT(0);
47211
47212 static void session_maintenance_work(struct work_struct *);
47213 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
47214@@ -444,7 +444,7 @@ static void sbp_management_request_login(
47215 login->lun = se_lun;
47216 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
47217 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
47218- login->login_id = atomic_inc_return(&login_id);
47219+ login->login_id = atomic_inc_return_unchecked(&login_id);
47220
47221 login->tgt_agt = sbp_target_agent_register(login);
47222 if (IS_ERR(login->tgt_agt)) {
47223diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
47224index 8f4142f..b127f7d 100644
47225--- a/drivers/target/target_core_device.c
47226+++ b/drivers/target/target_core_device.c
47227@@ -1400,7 +1400,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
47228 spin_lock_init(&dev->se_port_lock);
47229 spin_lock_init(&dev->se_tmr_lock);
47230 spin_lock_init(&dev->qf_cmd_lock);
47231- atomic_set(&dev->dev_ordered_id, 0);
47232+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
47233 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
47234 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
47235 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
47236diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
47237index d8e49d7..6fcfdec 100644
47238--- a/drivers/target/target_core_transport.c
47239+++ b/drivers/target/target_core_transport.c
47240@@ -1080,7 +1080,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
47241 * Used to determine when ORDERED commands should go from
47242 * Dormant to Active status.
47243 */
47244- cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
47245+ cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
47246 smp_mb__after_atomic_inc();
47247 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
47248 cmd->se_ordered_id, cmd->sam_task_attr,
47249diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
47250index 33f83fe..d80f8e1 100644
47251--- a/drivers/tty/cyclades.c
47252+++ b/drivers/tty/cyclades.c
47253@@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
47254 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
47255 info->port.count);
47256 #endif
47257- info->port.count++;
47258+ atomic_inc(&info->port.count);
47259 #ifdef CY_DEBUG_COUNT
47260 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
47261- current->pid, info->port.count);
47262+ current->pid, atomic_read(&info->port.count));
47263 #endif
47264
47265 /*
47266@@ -3972,7 +3972,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
47267 for (j = 0; j < cy_card[i].nports; j++) {
47268 info = &cy_card[i].ports[j];
47269
47270- if (info->port.count) {
47271+ if (atomic_read(&info->port.count)) {
47272 /* XXX is the ldisc num worth this? */
47273 struct tty_struct *tty;
47274 struct tty_ldisc *ld;
47275diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
47276index eb255e8..f637a57 100644
47277--- a/drivers/tty/hvc/hvc_console.c
47278+++ b/drivers/tty/hvc/hvc_console.c
47279@@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
47280
47281 spin_lock_irqsave(&hp->port.lock, flags);
47282 /* Check and then increment for fast path open. */
47283- if (hp->port.count++ > 0) {
47284+ if (atomic_inc_return(&hp->port.count) > 1) {
47285 spin_unlock_irqrestore(&hp->port.lock, flags);
47286 hvc_kick();
47287 return 0;
47288@@ -388,7 +388,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
47289
47290 spin_lock_irqsave(&hp->port.lock, flags);
47291
47292- if (--hp->port.count == 0) {
47293+ if (atomic_dec_return(&hp->port.count) == 0) {
47294 spin_unlock_irqrestore(&hp->port.lock, flags);
47295 /* We are done with the tty pointer now. */
47296 tty_port_tty_set(&hp->port, NULL);
47297@@ -406,9 +406,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
47298 */
47299 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
47300 } else {
47301- if (hp->port.count < 0)
47302+ if (atomic_read(&hp->port.count) < 0)
47303 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
47304- hp->vtermno, hp->port.count);
47305+ hp->vtermno, atomic_read(&hp->port.count));
47306 spin_unlock_irqrestore(&hp->port.lock, flags);
47307 }
47308 }
47309@@ -438,12 +438,12 @@ static void hvc_hangup(struct tty_struct *tty)
47310 * open->hangup case this can be called after the final close so prevent
47311 * that from happening for now.
47312 */
47313- if (hp->port.count <= 0) {
47314+ if (atomic_read(&hp->port.count) <= 0) {
47315 spin_unlock_irqrestore(&hp->port.lock, flags);
47316 return;
47317 }
47318
47319- hp->port.count = 0;
47320+ atomic_set(&hp->port.count, 0);
47321 spin_unlock_irqrestore(&hp->port.lock, flags);
47322 tty_port_tty_set(&hp->port, NULL);
47323
47324@@ -491,7 +491,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
47325 return -EPIPE;
47326
47327 /* FIXME what's this (unprotected) check for? */
47328- if (hp->port.count <= 0)
47329+ if (atomic_read(&hp->port.count) <= 0)
47330 return -EIO;
47331
47332 spin_lock_irqsave(&hp->lock, flags);
47333diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
47334index 81e939e..95ead10 100644
47335--- a/drivers/tty/hvc/hvcs.c
47336+++ b/drivers/tty/hvc/hvcs.c
47337@@ -83,6 +83,7 @@
47338 #include <asm/hvcserver.h>
47339 #include <asm/uaccess.h>
47340 #include <asm/vio.h>
47341+#include <asm/local.h>
47342
47343 /*
47344 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
47345@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
47346
47347 spin_lock_irqsave(&hvcsd->lock, flags);
47348
47349- if (hvcsd->port.count > 0) {
47350+ if (atomic_read(&hvcsd->port.count) > 0) {
47351 spin_unlock_irqrestore(&hvcsd->lock, flags);
47352 printk(KERN_INFO "HVCS: vterm state unchanged. "
47353 "The hvcs device node is still in use.\n");
47354@@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
47355 }
47356 }
47357
47358- hvcsd->port.count = 0;
47359+ atomic_set(&hvcsd->port.count, 0);
47360 hvcsd->port.tty = tty;
47361 tty->driver_data = hvcsd;
47362
47363@@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
47364 unsigned long flags;
47365
47366 spin_lock_irqsave(&hvcsd->lock, flags);
47367- hvcsd->port.count++;
47368+ atomic_inc(&hvcsd->port.count);
47369 hvcsd->todo_mask |= HVCS_SCHED_READ;
47370 spin_unlock_irqrestore(&hvcsd->lock, flags);
47371
47372@@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
47373 hvcsd = tty->driver_data;
47374
47375 spin_lock_irqsave(&hvcsd->lock, flags);
47376- if (--hvcsd->port.count == 0) {
47377+ if (atomic_dec_and_test(&hvcsd->port.count)) {
47378
47379 vio_disable_interrupts(hvcsd->vdev);
47380
47381@@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
47382
47383 free_irq(irq, hvcsd);
47384 return;
47385- } else if (hvcsd->port.count < 0) {
47386+ } else if (atomic_read(&hvcsd->port.count) < 0) {
47387 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
47388 " is missmanaged.\n",
47389- hvcsd->vdev->unit_address, hvcsd->port.count);
47390+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
47391 }
47392
47393 spin_unlock_irqrestore(&hvcsd->lock, flags);
47394@@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
47395
47396 spin_lock_irqsave(&hvcsd->lock, flags);
47397 /* Preserve this so that we know how many kref refs to put */
47398- temp_open_count = hvcsd->port.count;
47399+ temp_open_count = atomic_read(&hvcsd->port.count);
47400
47401 /*
47402 * Don't kref put inside the spinlock because the destruction
47403@@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
47404 tty->driver_data = NULL;
47405 hvcsd->port.tty = NULL;
47406
47407- hvcsd->port.count = 0;
47408+ atomic_set(&hvcsd->port.count, 0);
47409
47410 /* This will drop any buffered data on the floor which is OK in a hangup
47411 * scenario. */
47412@@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
47413 * the middle of a write operation? This is a crummy place to do this
47414 * but we want to keep it all in the spinlock.
47415 */
47416- if (hvcsd->port.count <= 0) {
47417+ if (atomic_read(&hvcsd->port.count) <= 0) {
47418 spin_unlock_irqrestore(&hvcsd->lock, flags);
47419 return -ENODEV;
47420 }
47421@@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
47422 {
47423 struct hvcs_struct *hvcsd = tty->driver_data;
47424
47425- if (!hvcsd || hvcsd->port.count <= 0)
47426+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
47427 return 0;
47428
47429 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
47430diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
47431index 4190199..48f2920 100644
47432--- a/drivers/tty/hvc/hvsi.c
47433+++ b/drivers/tty/hvc/hvsi.c
47434@@ -85,7 +85,7 @@ struct hvsi_struct {
47435 int n_outbuf;
47436 uint32_t vtermno;
47437 uint32_t virq;
47438- atomic_t seqno; /* HVSI packet sequence number */
47439+ atomic_unchecked_t seqno; /* HVSI packet sequence number */
47440 uint16_t mctrl;
47441 uint8_t state; /* HVSI protocol state */
47442 uint8_t flags;
47443@@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
47444
47445 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
47446 packet.hdr.len = sizeof(struct hvsi_query_response);
47447- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47448+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47449 packet.verb = VSV_SEND_VERSION_NUMBER;
47450 packet.u.version = HVSI_VERSION;
47451 packet.query_seqno = query_seqno+1;
47452@@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
47453
47454 packet.hdr.type = VS_QUERY_PACKET_HEADER;
47455 packet.hdr.len = sizeof(struct hvsi_query);
47456- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47457+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47458 packet.verb = verb;
47459
47460 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
47461@@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
47462 int wrote;
47463
47464 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
47465- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47466+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47467 packet.hdr.len = sizeof(struct hvsi_control);
47468 packet.verb = VSV_SET_MODEM_CTL;
47469 packet.mask = HVSI_TSDTR;
47470@@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
47471 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
47472
47473 packet.hdr.type = VS_DATA_PACKET_HEADER;
47474- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47475+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47476 packet.hdr.len = count + sizeof(struct hvsi_header);
47477 memcpy(&packet.data, buf, count);
47478
47479@@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
47480 struct hvsi_control packet __ALIGNED__;
47481
47482 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
47483- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47484+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47485 packet.hdr.len = 6;
47486 packet.verb = VSV_CLOSE_PROTOCOL;
47487
47488diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
47489index ac27671..0f627ee 100644
47490--- a/drivers/tty/hvc/hvsi_lib.c
47491+++ b/drivers/tty/hvc/hvsi_lib.c
47492@@ -9,7 +9,7 @@
47493
47494 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
47495 {
47496- packet->seqno = atomic_inc_return(&pv->seqno);
47497+ packet->seqno = atomic_inc_return_unchecked(&pv->seqno);
47498
47499 /* Assumes that always succeeds, works in practice */
47500 return pv->put_chars(pv->termno, (char *)packet, packet->len);
47501@@ -21,7 +21,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
47502
47503 /* Reset state */
47504 pv->established = 0;
47505- atomic_set(&pv->seqno, 0);
47506+ atomic_set_unchecked(&pv->seqno, 0);
47507
47508 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
47509
47510@@ -265,7 +265,7 @@ int hvsilib_read_mctrl(struct hvsi_priv *pv)
47511 pv->mctrl_update = 0;
47512 q.hdr.type = VS_QUERY_PACKET_HEADER;
47513 q.hdr.len = sizeof(struct hvsi_query);
47514- q.hdr.seqno = atomic_inc_return(&pv->seqno);
47515+ q.hdr.seqno = atomic_inc_return_unchecked(&pv->seqno);
47516 q.verb = VSV_SEND_MODEM_CTL_STATUS;
47517 rc = hvsi_send_packet(pv, &q.hdr);
47518 if (rc <= 0) {
47519diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
47520index 8fd72ff..34a0bed 100644
47521--- a/drivers/tty/ipwireless/tty.c
47522+++ b/drivers/tty/ipwireless/tty.c
47523@@ -29,6 +29,7 @@
47524 #include <linux/tty_driver.h>
47525 #include <linux/tty_flip.h>
47526 #include <linux/uaccess.h>
47527+#include <asm/local.h>
47528
47529 #include "tty.h"
47530 #include "network.h"
47531@@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
47532 mutex_unlock(&tty->ipw_tty_mutex);
47533 return -ENODEV;
47534 }
47535- if (tty->port.count == 0)
47536+ if (atomic_read(&tty->port.count) == 0)
47537 tty->tx_bytes_queued = 0;
47538
47539- tty->port.count++;
47540+ atomic_inc(&tty->port.count);
47541
47542 tty->port.tty = linux_tty;
47543 linux_tty->driver_data = tty;
47544@@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
47545
47546 static void do_ipw_close(struct ipw_tty *tty)
47547 {
47548- tty->port.count--;
47549-
47550- if (tty->port.count == 0) {
47551+ if (atomic_dec_return(&tty->port.count) == 0) {
47552 struct tty_struct *linux_tty = tty->port.tty;
47553
47554 if (linux_tty != NULL) {
47555@@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
47556 return;
47557
47558 mutex_lock(&tty->ipw_tty_mutex);
47559- if (tty->port.count == 0) {
47560+ if (atomic_read(&tty->port.count) == 0) {
47561 mutex_unlock(&tty->ipw_tty_mutex);
47562 return;
47563 }
47564@@ -164,7 +163,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
47565
47566 mutex_lock(&tty->ipw_tty_mutex);
47567
47568- if (!tty->port.count) {
47569+ if (!atomic_read(&tty->port.count)) {
47570 mutex_unlock(&tty->ipw_tty_mutex);
47571 return;
47572 }
47573@@ -206,7 +205,7 @@ static int ipw_write(struct tty_struct *linux_tty,
47574 return -ENODEV;
47575
47576 mutex_lock(&tty->ipw_tty_mutex);
47577- if (!tty->port.count) {
47578+ if (!atomic_read(&tty->port.count)) {
47579 mutex_unlock(&tty->ipw_tty_mutex);
47580 return -EINVAL;
47581 }
47582@@ -246,7 +245,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
47583 if (!tty)
47584 return -ENODEV;
47585
47586- if (!tty->port.count)
47587+ if (!atomic_read(&tty->port.count))
47588 return -EINVAL;
47589
47590 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
47591@@ -288,7 +287,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
47592 if (!tty)
47593 return 0;
47594
47595- if (!tty->port.count)
47596+ if (!atomic_read(&tty->port.count))
47597 return 0;
47598
47599 return tty->tx_bytes_queued;
47600@@ -369,7 +368,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
47601 if (!tty)
47602 return -ENODEV;
47603
47604- if (!tty->port.count)
47605+ if (!atomic_read(&tty->port.count))
47606 return -EINVAL;
47607
47608 return get_control_lines(tty);
47609@@ -385,7 +384,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
47610 if (!tty)
47611 return -ENODEV;
47612
47613- if (!tty->port.count)
47614+ if (!atomic_read(&tty->port.count))
47615 return -EINVAL;
47616
47617 return set_control_lines(tty, set, clear);
47618@@ -399,7 +398,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
47619 if (!tty)
47620 return -ENODEV;
47621
47622- if (!tty->port.count)
47623+ if (!atomic_read(&tty->port.count))
47624 return -EINVAL;
47625
47626 /* FIXME: Exactly how is the tty object locked here .. */
47627@@ -555,7 +554,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
47628 * are gone */
47629 mutex_lock(&ttyj->ipw_tty_mutex);
47630 }
47631- while (ttyj->port.count)
47632+ while (atomic_read(&ttyj->port.count))
47633 do_ipw_close(ttyj);
47634 ipwireless_disassociate_network_ttys(network,
47635 ttyj->channel_idx);
47636diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
47637index 1deaca4..c8582d4 100644
47638--- a/drivers/tty/moxa.c
47639+++ b/drivers/tty/moxa.c
47640@@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
47641 }
47642
47643 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
47644- ch->port.count++;
47645+ atomic_inc(&ch->port.count);
47646 tty->driver_data = ch;
47647 tty_port_tty_set(&ch->port, tty);
47648 mutex_lock(&ch->port.mutex);
47649diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
47650index 6422390..49003ac8 100644
47651--- a/drivers/tty/n_gsm.c
47652+++ b/drivers/tty/n_gsm.c
47653@@ -1632,7 +1632,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
47654 spin_lock_init(&dlci->lock);
47655 mutex_init(&dlci->mutex);
47656 dlci->fifo = &dlci->_fifo;
47657- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
47658+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
47659 kfree(dlci);
47660 return NULL;
47661 }
47662@@ -2932,7 +2932,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
47663 struct gsm_dlci *dlci = tty->driver_data;
47664 struct tty_port *port = &dlci->port;
47665
47666- port->count++;
47667+ atomic_inc(&port->count);
47668 dlci_get(dlci);
47669 dlci_get(dlci->gsm->dlci[0]);
47670 mux_get(dlci->gsm);
47671diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
47672index 4bf0fc0..433bd58 100644
47673--- a/drivers/tty/n_tty.c
47674+++ b/drivers/tty/n_tty.c
47675@@ -2217,6 +2217,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
47676 {
47677 *ops = tty_ldisc_N_TTY;
47678 ops->owner = NULL;
47679- ops->refcount = ops->flags = 0;
47680+ atomic_set(&ops->refcount, 0);
47681+ ops->flags = 0;
47682 }
47683 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
47684diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
47685index abfd990..5ab5da9 100644
47686--- a/drivers/tty/pty.c
47687+++ b/drivers/tty/pty.c
47688@@ -796,8 +796,10 @@ static void __init unix98_pty_init(void)
47689 panic("Couldn't register Unix98 pts driver");
47690
47691 /* Now create the /dev/ptmx special device */
47692+ pax_open_kernel();
47693 tty_default_fops(&ptmx_fops);
47694- ptmx_fops.open = ptmx_open;
47695+ *(void **)&ptmx_fops.open = ptmx_open;
47696+ pax_close_kernel();
47697
47698 cdev_init(&ptmx_cdev, &ptmx_fops);
47699 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
47700diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
47701index 354564e..fe50d9a 100644
47702--- a/drivers/tty/rocket.c
47703+++ b/drivers/tty/rocket.c
47704@@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
47705 tty->driver_data = info;
47706 tty_port_tty_set(port, tty);
47707
47708- if (port->count++ == 0) {
47709+ if (atomic_inc_return(&port->count) == 1) {
47710 atomic_inc(&rp_num_ports_open);
47711
47712 #ifdef ROCKET_DEBUG_OPEN
47713@@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
47714 #endif
47715 }
47716 #ifdef ROCKET_DEBUG_OPEN
47717- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
47718+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
47719 #endif
47720
47721 /*
47722@@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
47723 spin_unlock_irqrestore(&info->port.lock, flags);
47724 return;
47725 }
47726- if (info->port.count)
47727+ if (atomic_read(&info->port.count))
47728 atomic_dec(&rp_num_ports_open);
47729 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
47730 spin_unlock_irqrestore(&info->port.lock, flags);
47731diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
47732index e2520ab..034e20b 100644
47733--- a/drivers/tty/serial/ioc4_serial.c
47734+++ b/drivers/tty/serial/ioc4_serial.c
47735@@ -437,7 +437,7 @@ struct ioc4_soft {
47736 } is_intr_info[MAX_IOC4_INTR_ENTS];
47737
47738 /* Number of entries active in the above array */
47739- atomic_t is_num_intrs;
47740+ atomic_unchecked_t is_num_intrs;
47741 } is_intr_type[IOC4_NUM_INTR_TYPES];
47742
47743 /* is_ir_lock must be held while
47744@@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
47745 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
47746 || (type == IOC4_OTHER_INTR_TYPE)));
47747
47748- i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
47749+ i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
47750 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
47751
47752 /* Save off the lower level interrupt handler */
47753@@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
47754
47755 soft = arg;
47756 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
47757- num_intrs = (int)atomic_read(
47758+ num_intrs = (int)atomic_read_unchecked(
47759 &soft->is_intr_type[intr_type].is_num_intrs);
47760
47761 this_mir = this_ir = pending_intrs(soft, intr_type);
47762diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
47763index 1002054..dd644a8 100644
47764--- a/drivers/tty/serial/kgdboc.c
47765+++ b/drivers/tty/serial/kgdboc.c
47766@@ -24,8 +24,9 @@
47767 #define MAX_CONFIG_LEN 40
47768
47769 static struct kgdb_io kgdboc_io_ops;
47770+static struct kgdb_io kgdboc_io_ops_console;
47771
47772-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
47773+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
47774 static int configured = -1;
47775
47776 static char config[MAX_CONFIG_LEN];
47777@@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
47778 kgdboc_unregister_kbd();
47779 if (configured == 1)
47780 kgdb_unregister_io_module(&kgdboc_io_ops);
47781+ else if (configured == 2)
47782+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
47783 }
47784
47785 static int configure_kgdboc(void)
47786@@ -160,13 +163,13 @@ static int configure_kgdboc(void)
47787 int err;
47788 char *cptr = config;
47789 struct console *cons;
47790+ int is_console = 0;
47791
47792 err = kgdboc_option_setup(config);
47793 if (err || !strlen(config) || isspace(config[0]))
47794 goto noconfig;
47795
47796 err = -ENODEV;
47797- kgdboc_io_ops.is_console = 0;
47798 kgdb_tty_driver = NULL;
47799
47800 kgdboc_use_kms = 0;
47801@@ -187,7 +190,7 @@ static int configure_kgdboc(void)
47802 int idx;
47803 if (cons->device && cons->device(cons, &idx) == p &&
47804 idx == tty_line) {
47805- kgdboc_io_ops.is_console = 1;
47806+ is_console = 1;
47807 break;
47808 }
47809 cons = cons->next;
47810@@ -197,7 +200,13 @@ static int configure_kgdboc(void)
47811 kgdb_tty_line = tty_line;
47812
47813 do_register:
47814- err = kgdb_register_io_module(&kgdboc_io_ops);
47815+ if (is_console) {
47816+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
47817+ configured = 2;
47818+ } else {
47819+ err = kgdb_register_io_module(&kgdboc_io_ops);
47820+ configured = 1;
47821+ }
47822 if (err)
47823 goto noconfig;
47824
47825@@ -205,8 +214,6 @@ do_register:
47826 if (err)
47827 goto nmi_con_failed;
47828
47829- configured = 1;
47830-
47831 return 0;
47832
47833 nmi_con_failed:
47834@@ -223,7 +230,7 @@ noconfig:
47835 static int __init init_kgdboc(void)
47836 {
47837 /* Already configured? */
47838- if (configured == 1)
47839+ if (configured >= 1)
47840 return 0;
47841
47842 return configure_kgdboc();
47843@@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
47844 if (config[len - 1] == '\n')
47845 config[len - 1] = '\0';
47846
47847- if (configured == 1)
47848+ if (configured >= 1)
47849 cleanup_kgdboc();
47850
47851 /* Go and configure with the new params. */
47852@@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
47853 .post_exception = kgdboc_post_exp_handler,
47854 };
47855
47856+static struct kgdb_io kgdboc_io_ops_console = {
47857+ .name = "kgdboc",
47858+ .read_char = kgdboc_get_char,
47859+ .write_char = kgdboc_put_char,
47860+ .pre_exception = kgdboc_pre_exp_handler,
47861+ .post_exception = kgdboc_post_exp_handler,
47862+ .is_console = 1
47863+};
47864+
47865 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
47866 /* This is only available if kgdboc is a built in for early debugging */
47867 static int __init kgdboc_early_init(char *opt)
47868diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
47869index 2c6cfb3..048274e 100644
47870--- a/drivers/tty/serial/msm_serial.c
47871+++ b/drivers/tty/serial/msm_serial.c
47872@@ -857,7 +857,7 @@ static struct uart_driver msm_uart_driver = {
47873 .cons = MSM_CONSOLE,
47874 };
47875
47876-static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
47877+static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
47878
47879 static int __init msm_serial_probe(struct platform_device *pdev)
47880 {
47881@@ -867,7 +867,7 @@ static int __init msm_serial_probe(struct platform_device *pdev)
47882 int irq;
47883
47884 if (pdev->id == -1)
47885- pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
47886+ pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
47887
47888 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
47889 return -ENXIO;
47890diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
47891index 376079b..d8de7aa 100644
47892--- a/drivers/tty/serial/samsung.c
47893+++ b/drivers/tty/serial/samsung.c
47894@@ -453,11 +453,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
47895 }
47896 }
47897
47898+static int s3c64xx_serial_startup(struct uart_port *port);
47899 static int s3c24xx_serial_startup(struct uart_port *port)
47900 {
47901 struct s3c24xx_uart_port *ourport = to_ourport(port);
47902 int ret;
47903
47904+ /* Startup sequence is different for s3c64xx and higher SoC's */
47905+ if (s3c24xx_serial_has_interrupt_mask(port))
47906+ return s3c64xx_serial_startup(port);
47907+
47908 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
47909 port->mapbase, port->membase);
47910
47911@@ -1124,10 +1129,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
47912 /* setup info for port */
47913 port->dev = &platdev->dev;
47914
47915- /* Startup sequence is different for s3c64xx and higher SoC's */
47916- if (s3c24xx_serial_has_interrupt_mask(port))
47917- s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
47918-
47919 port->uartclk = 1;
47920
47921 if (cfg->uart_flags & UPF_CONS_FLOW) {
47922diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
47923index 28cdd28..56f1d60 100644
47924--- a/drivers/tty/serial/serial_core.c
47925+++ b/drivers/tty/serial/serial_core.c
47926@@ -1448,7 +1448,7 @@ static void uart_hangup(struct tty_struct *tty)
47927 uart_flush_buffer(tty);
47928 uart_shutdown(tty, state);
47929 spin_lock_irqsave(&port->lock, flags);
47930- port->count = 0;
47931+ atomic_set(&port->count, 0);
47932 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
47933 spin_unlock_irqrestore(&port->lock, flags);
47934 tty_port_tty_set(port, NULL);
47935@@ -1544,7 +1544,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
47936 goto end;
47937 }
47938
47939- port->count++;
47940+ atomic_inc(&port->count);
47941 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
47942 retval = -ENXIO;
47943 goto err_dec_count;
47944@@ -1572,7 +1572,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
47945 /*
47946 * Make sure the device is in D0 state.
47947 */
47948- if (port->count == 1)
47949+ if (atomic_read(&port->count) == 1)
47950 uart_change_pm(state, UART_PM_STATE_ON);
47951
47952 /*
47953@@ -1590,7 +1590,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
47954 end:
47955 return retval;
47956 err_dec_count:
47957- port->count--;
47958+ atomic_inc(&port->count);
47959 mutex_unlock(&port->mutex);
47960 goto end;
47961 }
47962diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
47963index 8eaf1ab..85c030d 100644
47964--- a/drivers/tty/synclink.c
47965+++ b/drivers/tty/synclink.c
47966@@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
47967
47968 if (debug_level >= DEBUG_LEVEL_INFO)
47969 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
47970- __FILE__,__LINE__, info->device_name, info->port.count);
47971+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
47972
47973 if (tty_port_close_start(&info->port, tty, filp) == 0)
47974 goto cleanup;
47975@@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
47976 cleanup:
47977 if (debug_level >= DEBUG_LEVEL_INFO)
47978 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
47979- tty->driver->name, info->port.count);
47980+ tty->driver->name, atomic_read(&info->port.count));
47981
47982 } /* end of mgsl_close() */
47983
47984@@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
47985
47986 mgsl_flush_buffer(tty);
47987 shutdown(info);
47988-
47989- info->port.count = 0;
47990+
47991+ atomic_set(&info->port.count, 0);
47992 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
47993 info->port.tty = NULL;
47994
47995@@ -3297,12 +3297,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
47996
47997 if (debug_level >= DEBUG_LEVEL_INFO)
47998 printk("%s(%d):block_til_ready before block on %s count=%d\n",
47999- __FILE__,__LINE__, tty->driver->name, port->count );
48000+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48001
48002 spin_lock_irqsave(&info->irq_spinlock, flags);
48003 if (!tty_hung_up_p(filp)) {
48004 extra_count = true;
48005- port->count--;
48006+ atomic_dec(&port->count);
48007 }
48008 spin_unlock_irqrestore(&info->irq_spinlock, flags);
48009 port->blocked_open++;
48010@@ -3331,7 +3331,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
48011
48012 if (debug_level >= DEBUG_LEVEL_INFO)
48013 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
48014- __FILE__,__LINE__, tty->driver->name, port->count );
48015+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48016
48017 tty_unlock(tty);
48018 schedule();
48019@@ -3343,12 +3343,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
48020
48021 /* FIXME: Racy on hangup during close wait */
48022 if (extra_count)
48023- port->count++;
48024+ atomic_inc(&port->count);
48025 port->blocked_open--;
48026
48027 if (debug_level >= DEBUG_LEVEL_INFO)
48028 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
48029- __FILE__,__LINE__, tty->driver->name, port->count );
48030+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48031
48032 if (!retval)
48033 port->flags |= ASYNC_NORMAL_ACTIVE;
48034@@ -3400,7 +3400,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
48035
48036 if (debug_level >= DEBUG_LEVEL_INFO)
48037 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
48038- __FILE__,__LINE__,tty->driver->name, info->port.count);
48039+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
48040
48041 /* If port is closing, signal caller to try again */
48042 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
48043@@ -3419,10 +3419,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
48044 spin_unlock_irqrestore(&info->netlock, flags);
48045 goto cleanup;
48046 }
48047- info->port.count++;
48048+ atomic_inc(&info->port.count);
48049 spin_unlock_irqrestore(&info->netlock, flags);
48050
48051- if (info->port.count == 1) {
48052+ if (atomic_read(&info->port.count) == 1) {
48053 /* 1st open on this device, init hardware */
48054 retval = startup(info);
48055 if (retval < 0)
48056@@ -3446,8 +3446,8 @@ cleanup:
48057 if (retval) {
48058 if (tty->count == 1)
48059 info->port.tty = NULL; /* tty layer will release tty struct */
48060- if(info->port.count)
48061- info->port.count--;
48062+ if (atomic_read(&info->port.count))
48063+ atomic_dec(&info->port.count);
48064 }
48065
48066 return retval;
48067@@ -7665,7 +7665,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
48068 unsigned short new_crctype;
48069
48070 /* return error if TTY interface open */
48071- if (info->port.count)
48072+ if (atomic_read(&info->port.count))
48073 return -EBUSY;
48074
48075 switch (encoding)
48076@@ -7760,7 +7760,7 @@ static int hdlcdev_open(struct net_device *dev)
48077
48078 /* arbitrate between network and tty opens */
48079 spin_lock_irqsave(&info->netlock, flags);
48080- if (info->port.count != 0 || info->netcount != 0) {
48081+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
48082 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
48083 spin_unlock_irqrestore(&info->netlock, flags);
48084 return -EBUSY;
48085@@ -7846,7 +7846,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48086 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
48087
48088 /* return error if TTY interface open */
48089- if (info->port.count)
48090+ if (atomic_read(&info->port.count))
48091 return -EBUSY;
48092
48093 if (cmd != SIOCWANDEV)
48094diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
48095index 1abf946..1ee34fc 100644
48096--- a/drivers/tty/synclink_gt.c
48097+++ b/drivers/tty/synclink_gt.c
48098@@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
48099 tty->driver_data = info;
48100 info->port.tty = tty;
48101
48102- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
48103+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
48104
48105 /* If port is closing, signal caller to try again */
48106 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
48107@@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
48108 mutex_unlock(&info->port.mutex);
48109 goto cleanup;
48110 }
48111- info->port.count++;
48112+ atomic_inc(&info->port.count);
48113 spin_unlock_irqrestore(&info->netlock, flags);
48114
48115- if (info->port.count == 1) {
48116+ if (atomic_read(&info->port.count) == 1) {
48117 /* 1st open on this device, init hardware */
48118 retval = startup(info);
48119 if (retval < 0) {
48120@@ -715,8 +715,8 @@ cleanup:
48121 if (retval) {
48122 if (tty->count == 1)
48123 info->port.tty = NULL; /* tty layer will release tty struct */
48124- if(info->port.count)
48125- info->port.count--;
48126+ if(atomic_read(&info->port.count))
48127+ atomic_dec(&info->port.count);
48128 }
48129
48130 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
48131@@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
48132
48133 if (sanity_check(info, tty->name, "close"))
48134 return;
48135- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
48136+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
48137
48138 if (tty_port_close_start(&info->port, tty, filp) == 0)
48139 goto cleanup;
48140@@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
48141 tty_port_close_end(&info->port, tty);
48142 info->port.tty = NULL;
48143 cleanup:
48144- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
48145+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
48146 }
48147
48148 static void hangup(struct tty_struct *tty)
48149@@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
48150 shutdown(info);
48151
48152 spin_lock_irqsave(&info->port.lock, flags);
48153- info->port.count = 0;
48154+ atomic_set(&info->port.count, 0);
48155 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
48156 info->port.tty = NULL;
48157 spin_unlock_irqrestore(&info->port.lock, flags);
48158@@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
48159 unsigned short new_crctype;
48160
48161 /* return error if TTY interface open */
48162- if (info->port.count)
48163+ if (atomic_read(&info->port.count))
48164 return -EBUSY;
48165
48166 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
48167@@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
48168
48169 /* arbitrate between network and tty opens */
48170 spin_lock_irqsave(&info->netlock, flags);
48171- if (info->port.count != 0 || info->netcount != 0) {
48172+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
48173 DBGINFO(("%s hdlc_open busy\n", dev->name));
48174 spin_unlock_irqrestore(&info->netlock, flags);
48175 return -EBUSY;
48176@@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48177 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
48178
48179 /* return error if TTY interface open */
48180- if (info->port.count)
48181+ if (atomic_read(&info->port.count))
48182 return -EBUSY;
48183
48184 if (cmd != SIOCWANDEV)
48185@@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
48186 if (port == NULL)
48187 continue;
48188 spin_lock(&port->lock);
48189- if ((port->port.count || port->netcount) &&
48190+ if ((atomic_read(&port->port.count) || port->netcount) &&
48191 port->pending_bh && !port->bh_running &&
48192 !port->bh_requested) {
48193 DBGISR(("%s bh queued\n", port->device_name));
48194@@ -3302,7 +3302,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48195 spin_lock_irqsave(&info->lock, flags);
48196 if (!tty_hung_up_p(filp)) {
48197 extra_count = true;
48198- port->count--;
48199+ atomic_dec(&port->count);
48200 }
48201 spin_unlock_irqrestore(&info->lock, flags);
48202 port->blocked_open++;
48203@@ -3339,7 +3339,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48204 remove_wait_queue(&port->open_wait, &wait);
48205
48206 if (extra_count)
48207- port->count++;
48208+ atomic_inc(&port->count);
48209 port->blocked_open--;
48210
48211 if (!retval)
48212diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
48213index dc6e969..5dc8786 100644
48214--- a/drivers/tty/synclinkmp.c
48215+++ b/drivers/tty/synclinkmp.c
48216@@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
48217
48218 if (debug_level >= DEBUG_LEVEL_INFO)
48219 printk("%s(%d):%s open(), old ref count = %d\n",
48220- __FILE__,__LINE__,tty->driver->name, info->port.count);
48221+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
48222
48223 /* If port is closing, signal caller to try again */
48224 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
48225@@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
48226 spin_unlock_irqrestore(&info->netlock, flags);
48227 goto cleanup;
48228 }
48229- info->port.count++;
48230+ atomic_inc(&info->port.count);
48231 spin_unlock_irqrestore(&info->netlock, flags);
48232
48233- if (info->port.count == 1) {
48234+ if (atomic_read(&info->port.count) == 1) {
48235 /* 1st open on this device, init hardware */
48236 retval = startup(info);
48237 if (retval < 0)
48238@@ -796,8 +796,8 @@ cleanup:
48239 if (retval) {
48240 if (tty->count == 1)
48241 info->port.tty = NULL; /* tty layer will release tty struct */
48242- if(info->port.count)
48243- info->port.count--;
48244+ if(atomic_read(&info->port.count))
48245+ atomic_dec(&info->port.count);
48246 }
48247
48248 return retval;
48249@@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
48250
48251 if (debug_level >= DEBUG_LEVEL_INFO)
48252 printk("%s(%d):%s close() entry, count=%d\n",
48253- __FILE__,__LINE__, info->device_name, info->port.count);
48254+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
48255
48256 if (tty_port_close_start(&info->port, tty, filp) == 0)
48257 goto cleanup;
48258@@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
48259 cleanup:
48260 if (debug_level >= DEBUG_LEVEL_INFO)
48261 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
48262- tty->driver->name, info->port.count);
48263+ tty->driver->name, atomic_read(&info->port.count));
48264 }
48265
48266 /* Called by tty_hangup() when a hangup is signaled.
48267@@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
48268 shutdown(info);
48269
48270 spin_lock_irqsave(&info->port.lock, flags);
48271- info->port.count = 0;
48272+ atomic_set(&info->port.count, 0);
48273 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
48274 info->port.tty = NULL;
48275 spin_unlock_irqrestore(&info->port.lock, flags);
48276@@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
48277 unsigned short new_crctype;
48278
48279 /* return error if TTY interface open */
48280- if (info->port.count)
48281+ if (atomic_read(&info->port.count))
48282 return -EBUSY;
48283
48284 switch (encoding)
48285@@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
48286
48287 /* arbitrate between network and tty opens */
48288 spin_lock_irqsave(&info->netlock, flags);
48289- if (info->port.count != 0 || info->netcount != 0) {
48290+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
48291 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
48292 spin_unlock_irqrestore(&info->netlock, flags);
48293 return -EBUSY;
48294@@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48295 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
48296
48297 /* return error if TTY interface open */
48298- if (info->port.count)
48299+ if (atomic_read(&info->port.count))
48300 return -EBUSY;
48301
48302 if (cmd != SIOCWANDEV)
48303@@ -2620,7 +2620,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
48304 * do not request bottom half processing if the
48305 * device is not open in a normal mode.
48306 */
48307- if ( port && (port->port.count || port->netcount) &&
48308+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
48309 port->pending_bh && !port->bh_running &&
48310 !port->bh_requested ) {
48311 if ( debug_level >= DEBUG_LEVEL_ISR )
48312@@ -3318,12 +3318,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48313
48314 if (debug_level >= DEBUG_LEVEL_INFO)
48315 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
48316- __FILE__,__LINE__, tty->driver->name, port->count );
48317+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48318
48319 spin_lock_irqsave(&info->lock, flags);
48320 if (!tty_hung_up_p(filp)) {
48321 extra_count = true;
48322- port->count--;
48323+ atomic_dec(&port->count);
48324 }
48325 spin_unlock_irqrestore(&info->lock, flags);
48326 port->blocked_open++;
48327@@ -3352,7 +3352,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48328
48329 if (debug_level >= DEBUG_LEVEL_INFO)
48330 printk("%s(%d):%s block_til_ready() count=%d\n",
48331- __FILE__,__LINE__, tty->driver->name, port->count );
48332+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48333
48334 tty_unlock(tty);
48335 schedule();
48336@@ -3363,12 +3363,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48337 remove_wait_queue(&port->open_wait, &wait);
48338
48339 if (extra_count)
48340- port->count++;
48341+ atomic_inc(&port->count);
48342 port->blocked_open--;
48343
48344 if (debug_level >= DEBUG_LEVEL_INFO)
48345 printk("%s(%d):%s block_til_ready() after, count=%d\n",
48346- __FILE__,__LINE__, tty->driver->name, port->count );
48347+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48348
48349 if (!retval)
48350 port->flags |= ASYNC_NORMAL_ACTIVE;
48351diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
48352index d5cc3ac..3263411 100644
48353--- a/drivers/tty/sysrq.c
48354+++ b/drivers/tty/sysrq.c
48355@@ -1033,7 +1033,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
48356 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
48357 size_t count, loff_t *ppos)
48358 {
48359- if (count) {
48360+ if (count && capable(CAP_SYS_ADMIN)) {
48361 char c;
48362
48363 if (get_user(c, buf))
48364diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
48365index 20689b9..7fd3a31 100644
48366--- a/drivers/tty/tty_io.c
48367+++ b/drivers/tty/tty_io.c
48368@@ -3468,7 +3468,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
48369
48370 void tty_default_fops(struct file_operations *fops)
48371 {
48372- *fops = tty_fops;
48373+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
48374 }
48375
48376 /*
48377diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
48378index 1afe192..73d2c20 100644
48379--- a/drivers/tty/tty_ldisc.c
48380+++ b/drivers/tty/tty_ldisc.c
48381@@ -66,7 +66,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
48382 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
48383 tty_ldiscs[disc] = new_ldisc;
48384 new_ldisc->num = disc;
48385- new_ldisc->refcount = 0;
48386+ atomic_set(&new_ldisc->refcount, 0);
48387 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
48388
48389 return ret;
48390@@ -94,7 +94,7 @@ int tty_unregister_ldisc(int disc)
48391 return -EINVAL;
48392
48393 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
48394- if (tty_ldiscs[disc]->refcount)
48395+ if (atomic_read(&tty_ldiscs[disc]->refcount))
48396 ret = -EBUSY;
48397 else
48398 tty_ldiscs[disc] = NULL;
48399@@ -115,7 +115,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
48400 if (ldops) {
48401 ret = ERR_PTR(-EAGAIN);
48402 if (try_module_get(ldops->owner)) {
48403- ldops->refcount++;
48404+ atomic_inc(&ldops->refcount);
48405 ret = ldops;
48406 }
48407 }
48408@@ -128,7 +128,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
48409 unsigned long flags;
48410
48411 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
48412- ldops->refcount--;
48413+ atomic_dec(&ldops->refcount);
48414 module_put(ldops->owner);
48415 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
48416 }
48417@@ -196,7 +196,7 @@ static inline void tty_ldisc_put(struct tty_ldisc *ld)
48418 /* unreleased reader reference(s) will cause this WARN */
48419 WARN_ON(!atomic_dec_and_test(&ld->users));
48420
48421- ld->ops->refcount--;
48422+ atomic_dec(&ld->ops->refcount);
48423 module_put(ld->ops->owner);
48424 kfree(ld);
48425 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
48426diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
48427index f597e88..b7f68ed 100644
48428--- a/drivers/tty/tty_port.c
48429+++ b/drivers/tty/tty_port.c
48430@@ -232,7 +232,7 @@ void tty_port_hangup(struct tty_port *port)
48431 unsigned long flags;
48432
48433 spin_lock_irqsave(&port->lock, flags);
48434- port->count = 0;
48435+ atomic_set(&port->count, 0);
48436 port->flags &= ~ASYNC_NORMAL_ACTIVE;
48437 tty = port->tty;
48438 if (tty)
48439@@ -390,7 +390,7 @@ int tty_port_block_til_ready(struct tty_port *port,
48440 /* The port lock protects the port counts */
48441 spin_lock_irqsave(&port->lock, flags);
48442 if (!tty_hung_up_p(filp))
48443- port->count--;
48444+ atomic_dec(&port->count);
48445 port->blocked_open++;
48446 spin_unlock_irqrestore(&port->lock, flags);
48447
48448@@ -432,7 +432,7 @@ int tty_port_block_til_ready(struct tty_port *port,
48449 we must not mess that up further */
48450 spin_lock_irqsave(&port->lock, flags);
48451 if (!tty_hung_up_p(filp))
48452- port->count++;
48453+ atomic_inc(&port->count);
48454 port->blocked_open--;
48455 if (retval == 0)
48456 port->flags |= ASYNC_NORMAL_ACTIVE;
48457@@ -466,19 +466,19 @@ int tty_port_close_start(struct tty_port *port,
48458 return 0;
48459 }
48460
48461- if (tty->count == 1 && port->count != 1) {
48462+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
48463 printk(KERN_WARNING
48464 "tty_port_close_start: tty->count = 1 port count = %d.\n",
48465- port->count);
48466- port->count = 1;
48467+ atomic_read(&port->count));
48468+ atomic_set(&port->count, 1);
48469 }
48470- if (--port->count < 0) {
48471+ if (atomic_dec_return(&port->count) < 0) {
48472 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
48473- port->count);
48474- port->count = 0;
48475+ atomic_read(&port->count));
48476+ atomic_set(&port->count, 0);
48477 }
48478
48479- if (port->count) {
48480+ if (atomic_read(&port->count)) {
48481 spin_unlock_irqrestore(&port->lock, flags);
48482 if (port->ops->drop)
48483 port->ops->drop(port);
48484@@ -564,7 +564,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
48485 {
48486 spin_lock_irq(&port->lock);
48487 if (!tty_hung_up_p(filp))
48488- ++port->count;
48489+ atomic_inc(&port->count);
48490 spin_unlock_irq(&port->lock);
48491 tty_port_tty_set(port, tty);
48492
48493diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
48494index a9af1b9a..1e08e7f 100644
48495--- a/drivers/tty/vt/keyboard.c
48496+++ b/drivers/tty/vt/keyboard.c
48497@@ -647,6 +647,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
48498 kbd->kbdmode == VC_OFF) &&
48499 value != KVAL(K_SAK))
48500 return; /* SAK is allowed even in raw mode */
48501+
48502+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48503+ {
48504+ void *func = fn_handler[value];
48505+ if (func == fn_show_state || func == fn_show_ptregs ||
48506+ func == fn_show_mem)
48507+ return;
48508+ }
48509+#endif
48510+
48511 fn_handler[value](vc);
48512 }
48513
48514@@ -1795,9 +1805,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
48515 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
48516 return -EFAULT;
48517
48518- if (!capable(CAP_SYS_TTY_CONFIG))
48519- perm = 0;
48520-
48521 switch (cmd) {
48522 case KDGKBENT:
48523 /* Ensure another thread doesn't free it under us */
48524@@ -1812,6 +1819,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
48525 spin_unlock_irqrestore(&kbd_event_lock, flags);
48526 return put_user(val, &user_kbe->kb_value);
48527 case KDSKBENT:
48528+ if (!capable(CAP_SYS_TTY_CONFIG))
48529+ perm = 0;
48530+
48531 if (!perm)
48532 return -EPERM;
48533 if (!i && v == K_NOSUCHMAP) {
48534@@ -1902,9 +1912,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
48535 int i, j, k;
48536 int ret;
48537
48538- if (!capable(CAP_SYS_TTY_CONFIG))
48539- perm = 0;
48540-
48541 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
48542 if (!kbs) {
48543 ret = -ENOMEM;
48544@@ -1938,6 +1945,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
48545 kfree(kbs);
48546 return ((p && *p) ? -EOVERFLOW : 0);
48547 case KDSKBSENT:
48548+ if (!capable(CAP_SYS_TTY_CONFIG))
48549+ perm = 0;
48550+
48551 if (!perm) {
48552 ret = -EPERM;
48553 goto reterr;
48554diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
48555index 3b96f18..026a9bf 100644
48556--- a/drivers/uio/uio.c
48557+++ b/drivers/uio/uio.c
48558@@ -25,6 +25,7 @@
48559 #include <linux/kobject.h>
48560 #include <linux/cdev.h>
48561 #include <linux/uio_driver.h>
48562+#include <asm/local.h>
48563
48564 #define UIO_MAX_DEVICES (1U << MINORBITS)
48565
48566@@ -32,10 +33,10 @@ struct uio_device {
48567 struct module *owner;
48568 struct device *dev;
48569 int minor;
48570- atomic_t event;
48571+ atomic_unchecked_t event;
48572 struct fasync_struct *async_queue;
48573 wait_queue_head_t wait;
48574- int vma_count;
48575+ local_t vma_count;
48576 struct uio_info *info;
48577 struct kobject *map_dir;
48578 struct kobject *portio_dir;
48579@@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
48580 struct device_attribute *attr, char *buf)
48581 {
48582 struct uio_device *idev = dev_get_drvdata(dev);
48583- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
48584+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
48585 }
48586
48587 static struct device_attribute uio_class_attributes[] = {
48588@@ -398,7 +399,7 @@ void uio_event_notify(struct uio_info *info)
48589 {
48590 struct uio_device *idev = info->uio_dev;
48591
48592- atomic_inc(&idev->event);
48593+ atomic_inc_unchecked(&idev->event);
48594 wake_up_interruptible(&idev->wait);
48595 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
48596 }
48597@@ -451,7 +452,7 @@ static int uio_open(struct inode *inode, struct file *filep)
48598 }
48599
48600 listener->dev = idev;
48601- listener->event_count = atomic_read(&idev->event);
48602+ listener->event_count = atomic_read_unchecked(&idev->event);
48603 filep->private_data = listener;
48604
48605 if (idev->info->open) {
48606@@ -502,7 +503,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
48607 return -EIO;
48608
48609 poll_wait(filep, &idev->wait, wait);
48610- if (listener->event_count != atomic_read(&idev->event))
48611+ if (listener->event_count != atomic_read_unchecked(&idev->event))
48612 return POLLIN | POLLRDNORM;
48613 return 0;
48614 }
48615@@ -527,7 +528,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
48616 do {
48617 set_current_state(TASK_INTERRUPTIBLE);
48618
48619- event_count = atomic_read(&idev->event);
48620+ event_count = atomic_read_unchecked(&idev->event);
48621 if (event_count != listener->event_count) {
48622 if (copy_to_user(buf, &event_count, count))
48623 retval = -EFAULT;
48624@@ -596,13 +597,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
48625 static void uio_vma_open(struct vm_area_struct *vma)
48626 {
48627 struct uio_device *idev = vma->vm_private_data;
48628- idev->vma_count++;
48629+ local_inc(&idev->vma_count);
48630 }
48631
48632 static void uio_vma_close(struct vm_area_struct *vma)
48633 {
48634 struct uio_device *idev = vma->vm_private_data;
48635- idev->vma_count--;
48636+ local_dec(&idev->vma_count);
48637 }
48638
48639 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
48640@@ -809,7 +810,7 @@ int __uio_register_device(struct module *owner,
48641 idev->owner = owner;
48642 idev->info = info;
48643 init_waitqueue_head(&idev->wait);
48644- atomic_set(&idev->event, 0);
48645+ atomic_set_unchecked(&idev->event, 0);
48646
48647 ret = uio_get_minor(idev);
48648 if (ret)
48649diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
48650index 8a7eb77..c00402f 100644
48651--- a/drivers/usb/atm/cxacru.c
48652+++ b/drivers/usb/atm/cxacru.c
48653@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
48654 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
48655 if (ret < 2)
48656 return -EINVAL;
48657- if (index < 0 || index > 0x7f)
48658+ if (index > 0x7f)
48659 return -EINVAL;
48660 pos += tmp;
48661
48662diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
48663index 5e0d33a..cc10579 100644
48664--- a/drivers/usb/atm/usbatm.c
48665+++ b/drivers/usb/atm/usbatm.c
48666@@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
48667 if (printk_ratelimit())
48668 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
48669 __func__, vpi, vci);
48670- atomic_inc(&vcc->stats->rx_err);
48671+ atomic_inc_unchecked(&vcc->stats->rx_err);
48672 return;
48673 }
48674
48675@@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
48676 if (length > ATM_MAX_AAL5_PDU) {
48677 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
48678 __func__, length, vcc);
48679- atomic_inc(&vcc->stats->rx_err);
48680+ atomic_inc_unchecked(&vcc->stats->rx_err);
48681 goto out;
48682 }
48683
48684@@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
48685 if (sarb->len < pdu_length) {
48686 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
48687 __func__, pdu_length, sarb->len, vcc);
48688- atomic_inc(&vcc->stats->rx_err);
48689+ atomic_inc_unchecked(&vcc->stats->rx_err);
48690 goto out;
48691 }
48692
48693 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
48694 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
48695 __func__, vcc);
48696- atomic_inc(&vcc->stats->rx_err);
48697+ atomic_inc_unchecked(&vcc->stats->rx_err);
48698 goto out;
48699 }
48700
48701@@ -389,7 +389,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
48702 if (printk_ratelimit())
48703 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
48704 __func__, length);
48705- atomic_inc(&vcc->stats->rx_drop);
48706+ atomic_inc_unchecked(&vcc->stats->rx_drop);
48707 goto out;
48708 }
48709
48710@@ -417,7 +417,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
48711
48712 vcc->push(vcc, skb);
48713
48714- atomic_inc(&vcc->stats->rx);
48715+ atomic_inc_unchecked(&vcc->stats->rx);
48716 out:
48717 skb_trim(sarb, 0);
48718 }
48719@@ -623,7 +623,7 @@ static void usbatm_tx_process(unsigned long data)
48720 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
48721
48722 usbatm_pop(vcc, skb);
48723- atomic_inc(&vcc->stats->tx);
48724+ atomic_inc_unchecked(&vcc->stats->tx);
48725
48726 skb = skb_dequeue(&instance->sndqueue);
48727 }
48728@@ -779,11 +779,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
48729 if (!left--)
48730 return sprintf(page,
48731 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
48732- atomic_read(&atm_dev->stats.aal5.tx),
48733- atomic_read(&atm_dev->stats.aal5.tx_err),
48734- atomic_read(&atm_dev->stats.aal5.rx),
48735- atomic_read(&atm_dev->stats.aal5.rx_err),
48736- atomic_read(&atm_dev->stats.aal5.rx_drop));
48737+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
48738+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
48739+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
48740+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
48741+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
48742
48743 if (!left--) {
48744 if (instance->disconnected)
48745diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
48746index 2a3bbdf..91d72cf 100644
48747--- a/drivers/usb/core/devices.c
48748+++ b/drivers/usb/core/devices.c
48749@@ -126,7 +126,7 @@ static const char format_endpt[] =
48750 * time it gets called.
48751 */
48752 static struct device_connect_event {
48753- atomic_t count;
48754+ atomic_unchecked_t count;
48755 wait_queue_head_t wait;
48756 } device_event = {
48757 .count = ATOMIC_INIT(1),
48758@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
48759
48760 void usbfs_conn_disc_event(void)
48761 {
48762- atomic_add(2, &device_event.count);
48763+ atomic_add_unchecked(2, &device_event.count);
48764 wake_up(&device_event.wait);
48765 }
48766
48767@@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
48768
48769 poll_wait(file, &device_event.wait, wait);
48770
48771- event_count = atomic_read(&device_event.count);
48772+ event_count = atomic_read_unchecked(&device_event.count);
48773 if (file->f_version != event_count) {
48774 file->f_version = event_count;
48775 return POLLIN | POLLRDNORM;
48776diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
48777index 014dc99..4d25fd7 100644
48778--- a/drivers/usb/core/hcd.c
48779+++ b/drivers/usb/core/hcd.c
48780@@ -1551,7 +1551,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
48781 */
48782 usb_get_urb(urb);
48783 atomic_inc(&urb->use_count);
48784- atomic_inc(&urb->dev->urbnum);
48785+ atomic_inc_unchecked(&urb->dev->urbnum);
48786 usbmon_urb_submit(&hcd->self, urb);
48787
48788 /* NOTE requirements on root-hub callers (usbfs and the hub
48789@@ -1578,7 +1578,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
48790 urb->hcpriv = NULL;
48791 INIT_LIST_HEAD(&urb->urb_list);
48792 atomic_dec(&urb->use_count);
48793- atomic_dec(&urb->dev->urbnum);
48794+ atomic_dec_unchecked(&urb->dev->urbnum);
48795 if (atomic_read(&urb->reject))
48796 wake_up(&usb_kill_urb_queue);
48797 usb_put_urb(urb);
48798diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
48799index 17c3785..deffb11 100644
48800--- a/drivers/usb/core/hub.c
48801+++ b/drivers/usb/core/hub.c
48802@@ -27,6 +27,7 @@
48803 #include <linux/freezer.h>
48804 #include <linux/random.h>
48805 #include <linux/pm_qos.h>
48806+#include <linux/grsecurity.h>
48807
48808 #include <asm/uaccess.h>
48809 #include <asm/byteorder.h>
48810@@ -4421,6 +4422,10 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
48811 goto done;
48812 return;
48813 }
48814+
48815+ if (gr_handle_new_usb())
48816+ goto done;
48817+
48818 if (hub_is_superspeed(hub->hdev))
48819 unit_load = 150;
48820 else
48821diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
48822index e7ee1e4..1dfc9ea4 100644
48823--- a/drivers/usb/core/message.c
48824+++ b/drivers/usb/core/message.c
48825@@ -129,7 +129,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
48826 * method can wait for it to complete. Since you don't have a handle on the
48827 * URB used, you can't cancel the request.
48828 */
48829-int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
48830+int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
48831 __u8 requesttype, __u16 value, __u16 index, void *data,
48832 __u16 size, int timeout)
48833 {
48834diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
48835index d9284b9..17023c7 100644
48836--- a/drivers/usb/core/sysfs.c
48837+++ b/drivers/usb/core/sysfs.c
48838@@ -239,7 +239,7 @@ show_urbnum(struct device *dev, struct device_attribute *attr, char *buf)
48839 struct usb_device *udev;
48840
48841 udev = to_usb_device(dev);
48842- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
48843+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
48844 }
48845 static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL);
48846
48847diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
48848index 7dad603..350f7a9 100644
48849--- a/drivers/usb/core/usb.c
48850+++ b/drivers/usb/core/usb.c
48851@@ -422,7 +422,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
48852 set_dev_node(&dev->dev, dev_to_node(bus->controller));
48853 dev->state = USB_STATE_ATTACHED;
48854 dev->lpm_disable_count = 1;
48855- atomic_set(&dev->urbnum, 0);
48856+ atomic_set_unchecked(&dev->urbnum, 0);
48857
48858 INIT_LIST_HEAD(&dev->ep0.urb_list);
48859 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
48860diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
48861index 14d28d6..5f511ac 100644
48862--- a/drivers/usb/dwc3/gadget.c
48863+++ b/drivers/usb/dwc3/gadget.c
48864@@ -550,8 +550,6 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
48865 if (!usb_endpoint_xfer_isoc(desc))
48866 return 0;
48867
48868- memset(&trb_link, 0, sizeof(trb_link));
48869-
48870 /* Link TRB for ISOC. The HWO bit is never reset */
48871 trb_st_hw = &dep->trb_pool[0];
48872
48873diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
48874index 5e29dde..eca992f 100644
48875--- a/drivers/usb/early/ehci-dbgp.c
48876+++ b/drivers/usb/early/ehci-dbgp.c
48877@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
48878
48879 #ifdef CONFIG_KGDB
48880 static struct kgdb_io kgdbdbgp_io_ops;
48881-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
48882+static struct kgdb_io kgdbdbgp_io_ops_console;
48883+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
48884 #else
48885 #define dbgp_kgdb_mode (0)
48886 #endif
48887@@ -1047,6 +1048,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
48888 .write_char = kgdbdbgp_write_char,
48889 };
48890
48891+static struct kgdb_io kgdbdbgp_io_ops_console = {
48892+ .name = "kgdbdbgp",
48893+ .read_char = kgdbdbgp_read_char,
48894+ .write_char = kgdbdbgp_write_char,
48895+ .is_console = 1
48896+};
48897+
48898 static int kgdbdbgp_wait_time;
48899
48900 static int __init kgdbdbgp_parse_config(char *str)
48901@@ -1062,8 +1070,10 @@ static int __init kgdbdbgp_parse_config(char *str)
48902 ptr++;
48903 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
48904 }
48905- kgdb_register_io_module(&kgdbdbgp_io_ops);
48906- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
48907+ if (early_dbgp_console.index != -1)
48908+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
48909+ else
48910+ kgdb_register_io_module(&kgdbdbgp_io_ops);
48911
48912 return 0;
48913 }
48914diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
48915index b369292..9f3ba40 100644
48916--- a/drivers/usb/gadget/u_serial.c
48917+++ b/drivers/usb/gadget/u_serial.c
48918@@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
48919 spin_lock_irq(&port->port_lock);
48920
48921 /* already open? Great. */
48922- if (port->port.count) {
48923+ if (atomic_read(&port->port.count)) {
48924 status = 0;
48925- port->port.count++;
48926+ atomic_inc(&port->port.count);
48927
48928 /* currently opening/closing? wait ... */
48929 } else if (port->openclose) {
48930@@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
48931 tty->driver_data = port;
48932 port->port.tty = tty;
48933
48934- port->port.count = 1;
48935+ atomic_set(&port->port.count, 1);
48936 port->openclose = false;
48937
48938 /* if connected, start the I/O stream */
48939@@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
48940
48941 spin_lock_irq(&port->port_lock);
48942
48943- if (port->port.count != 1) {
48944- if (port->port.count == 0)
48945+ if (atomic_read(&port->port.count) != 1) {
48946+ if (atomic_read(&port->port.count) == 0)
48947 WARN_ON(1);
48948 else
48949- --port->port.count;
48950+ atomic_dec(&port->port.count);
48951 goto exit;
48952 }
48953
48954@@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
48955 * and sleep if necessary
48956 */
48957 port->openclose = true;
48958- port->port.count = 0;
48959+ atomic_set(&port->port.count, 0);
48960
48961 gser = port->port_usb;
48962 if (gser && gser->disconnect)
48963@@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
48964 int cond;
48965
48966 spin_lock_irq(&port->port_lock);
48967- cond = (port->port.count == 0) && !port->openclose;
48968+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
48969 spin_unlock_irq(&port->port_lock);
48970 return cond;
48971 }
48972@@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
48973 /* if it's already open, start I/O ... and notify the serial
48974 * protocol about open/close status (connect/disconnect).
48975 */
48976- if (port->port.count) {
48977+ if (atomic_read(&port->port.count)) {
48978 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
48979 gs_start_io(port);
48980 if (gser->connect)
48981@@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
48982
48983 port->port_usb = NULL;
48984 gser->ioport = NULL;
48985- if (port->port.count > 0 || port->openclose) {
48986+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
48987 wake_up_interruptible(&port->drain_wait);
48988 if (port->port.tty)
48989 tty_hangup(port->port.tty);
48990@@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
48991
48992 /* finally, free any unused/unusable I/O buffers */
48993 spin_lock_irqsave(&port->port_lock, flags);
48994- if (port->port.count == 0 && !port->openclose)
48995+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
48996 gs_buf_free(&port->port_write_buf);
48997 gs_free_requests(gser->out, &port->read_pool, NULL);
48998 gs_free_requests(gser->out, &port->read_queue, NULL);
48999diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
49000index ba6a5d6..f88f7f3 100644
49001--- a/drivers/usb/misc/appledisplay.c
49002+++ b/drivers/usb/misc/appledisplay.c
49003@@ -83,7 +83,7 @@ struct appledisplay {
49004 spinlock_t lock;
49005 };
49006
49007-static atomic_t count_displays = ATOMIC_INIT(0);
49008+static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
49009 static struct workqueue_struct *wq;
49010
49011 static void appledisplay_complete(struct urb *urb)
49012@@ -281,7 +281,7 @@ static int appledisplay_probe(struct usb_interface *iface,
49013
49014 /* Register backlight device */
49015 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
49016- atomic_inc_return(&count_displays) - 1);
49017+ atomic_inc_return_unchecked(&count_displays) - 1);
49018 memset(&props, 0, sizeof(struct backlight_properties));
49019 props.type = BACKLIGHT_RAW;
49020 props.max_brightness = 0xff;
49021diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
49022index afb50ea..7b0b1cf 100644
49023--- a/drivers/usb/serial/console.c
49024+++ b/drivers/usb/serial/console.c
49025@@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
49026
49027 info->port = port;
49028
49029- ++port->port.count;
49030+ atomic_inc(&port->port.count);
49031 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
49032 if (serial->type->set_termios) {
49033 /*
49034@@ -174,7 +174,7 @@ static int usb_console_setup(struct console *co, char *options)
49035 }
49036 /* Now that any required fake tty operations are completed restore
49037 * the tty port count */
49038- --port->port.count;
49039+ atomic_dec(&port->port.count);
49040 /* The console is special in terms of closing the device so
49041 * indicate this port is now acting as a system console. */
49042 port->port.console = 1;
49043@@ -187,7 +187,7 @@ static int usb_console_setup(struct console *co, char *options)
49044 free_tty:
49045 kfree(tty);
49046 reset_open_count:
49047- port->port.count = 0;
49048+ atomic_set(&port->port.count, 0);
49049 usb_autopm_put_interface(serial->interface);
49050 error_get_interface:
49051 usb_serial_put(serial);
49052diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
49053index 75f70f0..d467e1a 100644
49054--- a/drivers/usb/storage/usb.h
49055+++ b/drivers/usb/storage/usb.h
49056@@ -63,7 +63,7 @@ struct us_unusual_dev {
49057 __u8 useProtocol;
49058 __u8 useTransport;
49059 int (*initFunction)(struct us_data *);
49060-};
49061+} __do_const;
49062
49063
49064 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
49065diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
49066index d6bea3e..60b250e 100644
49067--- a/drivers/usb/wusbcore/wa-hc.h
49068+++ b/drivers/usb/wusbcore/wa-hc.h
49069@@ -192,7 +192,7 @@ struct wahc {
49070 struct list_head xfer_delayed_list;
49071 spinlock_t xfer_list_lock;
49072 struct work_struct xfer_work;
49073- atomic_t xfer_id_count;
49074+ atomic_unchecked_t xfer_id_count;
49075 };
49076
49077
49078@@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
49079 INIT_LIST_HEAD(&wa->xfer_delayed_list);
49080 spin_lock_init(&wa->xfer_list_lock);
49081 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
49082- atomic_set(&wa->xfer_id_count, 1);
49083+ atomic_set_unchecked(&wa->xfer_id_count, 1);
49084 }
49085
49086 /**
49087diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
49088index d3493ca..0c33b7e 100644
49089--- a/drivers/usb/wusbcore/wa-xfer.c
49090+++ b/drivers/usb/wusbcore/wa-xfer.c
49091@@ -297,7 +297,7 @@ out:
49092 */
49093 static void wa_xfer_id_init(struct wa_xfer *xfer)
49094 {
49095- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
49096+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
49097 }
49098
49099 /*
49100diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
49101index 842f450..d1d7409 100644
49102--- a/drivers/vfio/vfio.c
49103+++ b/drivers/vfio/vfio.c
49104@@ -488,7 +488,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
49105 return 0;
49106
49107 /* TODO Prevent device auto probing */
49108- WARN("Device %s added to live group %d!\n", dev_name(dev),
49109+ WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
49110 iommu_group_id(group->iommu_group));
49111
49112 return 0;
49113diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
49114index 5174eba..86e764a 100644
49115--- a/drivers/vhost/vringh.c
49116+++ b/drivers/vhost/vringh.c
49117@@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
49118
49119 static inline int putu16_kern(u16 *p, u16 val)
49120 {
49121- ACCESS_ONCE(*p) = val;
49122+ ACCESS_ONCE_RW(*p) = val;
49123 return 0;
49124 }
49125
49126diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
49127index a4dfe8c..297ddd9 100644
49128--- a/drivers/video/aty/aty128fb.c
49129+++ b/drivers/video/aty/aty128fb.c
49130@@ -149,7 +149,7 @@ enum {
49131 };
49132
49133 /* Must match above enum */
49134-static char * const r128_family[] = {
49135+static const char * const r128_family[] = {
49136 "AGP",
49137 "PCI",
49138 "PRO AGP",
49139diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
49140index 9b0f12c..024673d 100644
49141--- a/drivers/video/aty/atyfb_base.c
49142+++ b/drivers/video/aty/atyfb_base.c
49143@@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
49144 par->accel_flags = var->accel_flags; /* hack */
49145
49146 if (var->accel_flags) {
49147- info->fbops->fb_sync = atyfb_sync;
49148+ pax_open_kernel();
49149+ *(void **)&info->fbops->fb_sync = atyfb_sync;
49150+ pax_close_kernel();
49151 info->flags &= ~FBINFO_HWACCEL_DISABLED;
49152 } else {
49153- info->fbops->fb_sync = NULL;
49154+ pax_open_kernel();
49155+ *(void **)&info->fbops->fb_sync = NULL;
49156+ pax_close_kernel();
49157 info->flags |= FBINFO_HWACCEL_DISABLED;
49158 }
49159
49160diff --git a/drivers/video/aty/mach64_cursor.c b/drivers/video/aty/mach64_cursor.c
49161index 95ec042..e6affdd 100644
49162--- a/drivers/video/aty/mach64_cursor.c
49163+++ b/drivers/video/aty/mach64_cursor.c
49164@@ -7,6 +7,7 @@
49165 #include <linux/string.h>
49166
49167 #include <asm/io.h>
49168+#include <asm/pgtable.h>
49169
49170 #ifdef __sparc__
49171 #include <asm/fbio.h>
49172@@ -208,7 +209,9 @@ int aty_init_cursor(struct fb_info *info)
49173 info->sprite.buf_align = 16; /* and 64 lines tall. */
49174 info->sprite.flags = FB_PIXMAP_IO;
49175
49176- info->fbops->fb_cursor = atyfb_cursor;
49177+ pax_open_kernel();
49178+ *(void **)&info->fbops->fb_cursor = atyfb_cursor;
49179+ pax_close_kernel();
49180
49181 return 0;
49182 }
49183diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
49184index bca6ccc..252107e 100644
49185--- a/drivers/video/backlight/kb3886_bl.c
49186+++ b/drivers/video/backlight/kb3886_bl.c
49187@@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
49188 static unsigned long kb3886bl_flags;
49189 #define KB3886BL_SUSPENDED 0x01
49190
49191-static struct dmi_system_id __initdata kb3886bl_device_table[] = {
49192+static const struct dmi_system_id __initconst kb3886bl_device_table[] = {
49193 {
49194 .ident = "Sahara Touch-iT",
49195 .matches = {
49196diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c
49197index 900aa4e..6d49418 100644
49198--- a/drivers/video/fb_defio.c
49199+++ b/drivers/video/fb_defio.c
49200@@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
49201
49202 BUG_ON(!fbdefio);
49203 mutex_init(&fbdefio->lock);
49204- info->fbops->fb_mmap = fb_deferred_io_mmap;
49205+ pax_open_kernel();
49206+ *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
49207+ pax_close_kernel();
49208 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
49209 INIT_LIST_HEAD(&fbdefio->pagelist);
49210 if (fbdefio->delay == 0) /* set a default of 1 s */
49211@@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
49212 page->mapping = NULL;
49213 }
49214
49215- info->fbops->fb_mmap = NULL;
49216+ *(void **)&info->fbops->fb_mmap = NULL;
49217 mutex_destroy(&fbdefio->lock);
49218 }
49219 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
49220diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
49221index 5c3960d..15cf8fc 100644
49222--- a/drivers/video/fbcmap.c
49223+++ b/drivers/video/fbcmap.c
49224@@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
49225 rc = -ENODEV;
49226 goto out;
49227 }
49228- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
49229- !info->fbops->fb_setcmap)) {
49230+ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
49231 rc = -EINVAL;
49232 goto out1;
49233 }
49234diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
49235index 36e1fe2..c744820 100644
49236--- a/drivers/video/fbmem.c
49237+++ b/drivers/video/fbmem.c
49238@@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
49239 image->dx += image->width + 8;
49240 }
49241 } else if (rotate == FB_ROTATE_UD) {
49242- for (x = 0; x < num && image->dx >= 0; x++) {
49243+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
49244 info->fbops->fb_imageblit(info, image);
49245 image->dx -= image->width + 8;
49246 }
49247@@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
49248 image->dy += image->height + 8;
49249 }
49250 } else if (rotate == FB_ROTATE_CCW) {
49251- for (x = 0; x < num && image->dy >= 0; x++) {
49252+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
49253 info->fbops->fb_imageblit(info, image);
49254 image->dy -= image->height + 8;
49255 }
49256@@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
49257 return -EFAULT;
49258 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
49259 return -EINVAL;
49260- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
49261+ if (con2fb.framebuffer >= FB_MAX)
49262 return -EINVAL;
49263 if (!registered_fb[con2fb.framebuffer])
49264 request_module("fb%d", con2fb.framebuffer);
49265diff --git a/drivers/video/hyperv_fb.c b/drivers/video/hyperv_fb.c
49266index d4d2c5f..ebbd113 100644
49267--- a/drivers/video/hyperv_fb.c
49268+++ b/drivers/video/hyperv_fb.c
49269@@ -233,7 +233,7 @@ static uint screen_fb_size;
49270 static inline int synthvid_send(struct hv_device *hdev,
49271 struct synthvid_msg *msg)
49272 {
49273- static atomic64_t request_id = ATOMIC64_INIT(0);
49274+ static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
49275 int ret;
49276
49277 msg->pipe_hdr.type = PIPE_MSG_DATA;
49278@@ -241,7 +241,7 @@ static inline int synthvid_send(struct hv_device *hdev,
49279
49280 ret = vmbus_sendpacket(hdev->channel, msg,
49281 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
49282- atomic64_inc_return(&request_id),
49283+ atomic64_inc_return_unchecked(&request_id),
49284 VM_PKT_DATA_INBAND, 0);
49285
49286 if (ret)
49287diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
49288index 7672d2e..b56437f 100644
49289--- a/drivers/video/i810/i810_accel.c
49290+++ b/drivers/video/i810/i810_accel.c
49291@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
49292 }
49293 }
49294 printk("ringbuffer lockup!!!\n");
49295+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
49296 i810_report_error(mmio);
49297 par->dev_flags |= LOCKUP;
49298 info->pixmap.scan_align = 1;
49299diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
49300index 285d552..eafa544 100644
49301--- a/drivers/video/logo/logo_linux_clut224.ppm
49302+++ b/drivers/video/logo/logo_linux_clut224.ppm
49303@@ -1,883 +1,1123 @@
49304 P3
49305 80 80
49306 255
49307-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49308-0 0 0 0 0 0 0 0 0 0 0 0 11 15 17 33 49 54 59 85 92 73 97 106
49309-83 116 129 105 131 142 115 114 122 74 88 93 20 29 31 0 0 0 0 0 0 0 0 0
49310-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49311-0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 6 6 6 10 10 10 10 10 10
49312-10 10 10 6 6 6 6 6 6 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0
49313-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49314-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49315-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49316-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49317-
49318-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49319-0 0 0 0 0 0 2 3 3 17 23 26 50 67 72 73 97 106 59 85 92 73 97 106
49320-105 131 142 124 127 131 105 131 142 105 131 142 53 75 83 6 8 8 0 0 0 0 0 0
49321-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49322-0 0 0 6 6 6 10 10 10 14 14 14 22 22 22 26 26 26 30 30 30 34 34 34
49323-30 30 30 30 30 30 26 26 26 18 18 18 14 14 14 10 10 10 6 6 6 0 0 0
49324-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49325-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49326-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49327-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49328-
49329-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0
49330-0 0 0 1 1 1 26 35 39 59 85 92 59 85 92 59 85 92 29 43 47 53 75 83
49331-108 122 132 132 98 104 108 122 132 105 131 142 101 101 101 43 45 48 6 8 8 0 0 0
49332-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49333-6 6 6 14 14 14 26 26 26 42 42 42 54 54 54 66 66 66 78 78 78 78 78 78
49334-78 78 78 74 74 74 66 66 66 54 54 54 42 42 42 26 26 26 18 18 18 10 10 10
49335-6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49336-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49337-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49338-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49339-
49340-0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0
49341-11 15 17 27 40 45 59 85 92 59 85 92 27 40 45 31 45 49 73 97 106 93 121 133
49342-108 122 132 108 122 132 105 131 142 108 122 132 105 131 142 73 97 106 26 35 39 0 0 0
49343-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
49344-22 22 22 42 42 42 66 66 66 86 86 86 66 66 66 38 38 38 38 38 38 22 22 22
49345-26 26 26 34 34 34 54 54 54 66 66 66 86 86 86 70 70 70 46 46 46 26 26 26
49346-14 14 14 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49347-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49348-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49349-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49350-
49351-0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 7 12 13 21 31 35 42 59 64
49352-53 75 83 53 75 83 50 67 72 42 59 64 32 40 45 42 59 64 73 97 106 116 116 116
49353-132 98 104 116 116 116 108 122 132 117 104 110 105 131 142 83 116 129 50 67 72 7 12 13
49354-1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10 26 26 26
49355-50 50 50 82 82 82 58 58 58 6 6 6 2 2 6 2 2 6 2 2 6 2 2 6
49356-2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 54 54 54 86 86 86 66 66 66
49357-38 38 38 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49358-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49359-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49360-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49361-
49362-0 0 0 1 1 1 6 8 8 15 22 25 26 35 39 36 54 60 53 75 83 59 85 92
49363-59 85 92 48 63 69 15 22 25 12 17 20 52 67 79 94 94 94 132 98 104 132 98 104
49364-117 104 110 108 122 132 108 122 132 115 114 122 105 131 142 77 105 114 59 85 92 36 54 60
49365-7 12 13 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 22 22 22 50 50 50
49366-78 78 78 34 34 34 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49367-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 70 70 70
49368-78 78 78 46 46 46 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0
49369-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49370-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49371-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49372-
49373-0 0 0 15 22 25 29 43 47 36 54 60 42 59 64 42 59 64 48 63 69 21 31 35
49374-6 8 8 29 43 47 36 50 56 43 45 48 79 78 84 132 98 104 165 78 79 132 98 104
49375-108 122 132 117 104 110 117 104 110 108 122 132 77 105 114 73 97 106 95 131 149 78 102 129
49376-36 50 56 0 0 0 0 0 0 0 0 0 6 6 6 18 18 18 42 42 42 82 82 82
49377-26 26 26 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49378-2 2 6 2 2 6 2 2 6 14 14 14 46 46 46 34 34 34 6 6 6 2 2 6
49379-42 42 42 78 78 78 42 42 42 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0
49380-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49381-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49382-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49383-
49384-27 40 45 53 75 83 48 63 69 24 31 37 6 8 12 0 0 0 18 25 28 26 35 39
49385-12 17 20 26 35 39 65 78 84 112 81 86 152 81 83 137 83 86 132 98 104 117 104 110
49386-117 104 110 132 98 104 132 98 104 115 114 122 73 97 106 53 75 83 95 131 149 93 124 152
49387-68 78 128 15 22 25 0 0 0 0 0 0 10 10 10 30 30 30 66 66 66 58 58 58
49388-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49389-2 2 6 2 2 6 2 2 6 26 26 26 86 86 86 101 101 101 46 46 46 10 10 10
49390-2 2 6 58 58 58 70 70 70 34 34 34 10 10 10 0 0 0 0 0 0 0 0 0
49391-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49392-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49393-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49394-
49395-36 50 56 21 30 33 4 7 7 0 0 0 1 1 1 17 12 12 69 31 31 68 59 64
49396-57 59 63 21 31 35 32 40 45 86 73 69 152 81 83 152 81 83 117 104 110 132 98 104
49397-152 81 83 132 98 104 108 122 132 77 105 114 77 105 114 93 121 133 95 131 149 93 124 152
49398-95 131 149 53 75 83 11 15 17 0 0 0 14 14 14 42 42 42 86 86 86 10 10 10
49399-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49400-2 2 6 2 2 6 2 2 6 30 30 30 94 94 94 94 94 94 58 58 58 26 26 26
49401-2 2 6 6 6 6 78 78 78 54 54 54 22 22 22 6 6 6 0 0 0 0 0 0
49402-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49403-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49404-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49405-
49406-17 23 26 2 3 3 0 0 0 17 12 12 69 31 31 123 55 55 123 55 55 152 81 83
49407-86 73 69 17 23 26 7 12 13 45 54 57 101 101 101 137 83 86 132 98 104 132 98 104
49408-137 83 86 117 104 110 77 105 114 42 59 64 50 67 72 78 102 129 91 117 157 91 117 157
49409-95 131 149 83 116 129 40 48 73 6 6 6 22 22 22 62 62 62 62 62 62 2 2 6
49410-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49411-2 2 6 2 2 6 2 2 6 26 26 26 54 54 54 38 38 38 18 18 18 10 10 10
49412-2 2 6 2 2 6 34 34 34 82 82 82 38 38 38 14 14 14 0 0 0 0 0 0
49413-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49414-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49415-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49416-
49417-1 1 1 1 2 2 2 3 3 28 12 12 123 55 55 174 79 79 174 79 79 174 79 79
49418-152 81 83 68 59 64 26 35 39 27 40 45 79 78 84 137 83 86 165 78 79 137 83 86
49419-94 94 94 48 63 69 36 50 56 50 67 72 73 97 106 93 121 133 93 124 152 93 124 152
49420-95 131 149 91 118 149 78 102 129 27 40 45 30 30 30 78 78 78 30 30 30 2 2 6
49421-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49422-2 2 6 2 2 6 2 2 6 10 10 10 10 10 10 2 2 6 2 2 6 2 2 6
49423-2 2 6 2 2 6 2 2 6 78 78 78 50 50 50 18 18 18 6 6 6 0 0 0
49424-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49425-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49426-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49427-
49428-4 5 3 24 53 24 19 31 15 8 7 3 90 61 47 165 78 79 174 79 79 174 79 79
49429-174 79 79 137 83 86 60 52 57 7 12 13 17 23 26 70 70 70 132 98 104 112 81 86
49430-79 78 84 31 45 49 15 22 25 53 75 83 91 118 149 86 106 160 91 117 157 93 124 152
49431-91 117 157 93 124 152 95 131 149 53 75 83 50 50 50 86 86 86 14 14 14 2 2 6
49432-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49433-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49434-2 2 6 2 2 6 2 2 6 54 54 54 66 66 66 26 26 26 6 6 6 0 0 0
49435-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49436-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49437-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49438-
49439-19 31 15 34 76 34 34 76 34 19 31 15 28 12 12 123 55 55 174 79 79 174 79 79
49440-174 79 79 165 78 79 112 81 86 32 40 45 15 22 25 38 53 58 65 78 84 29 31 32
49441-21 30 33 42 59 64 60 80 103 78 102 129 87 112 149 84 96 162 91 117 157 93 124 152
49442-91 117 157 93 124 152 93 121 133 59 85 92 57 68 71 82 85 86 2 2 6 2 2 6
49443-2 2 6 6 6 6 10 10 10 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49444-2 2 6 2 2 6 2 2 6 6 6 6 14 14 14 10 10 10 2 2 6 2 2 6
49445-2 2 6 2 2 6 2 2 6 18 18 18 82 82 82 34 34 34 10 10 10 0 0 0
49446-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49447-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49448-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49449-
49450-34 76 34 40 89 40 40 89 40 34 76 34 8 15 6 48 26 18 123 55 55 174 79 79
49451-174 79 79 174 79 79 137 83 86 68 59 64 32 40 45 21 30 33 31 45 49 21 31 35
49452-12 17 20 48 63 69 78 102 129 81 88 166 84 96 162 91 117 157 93 124 152 91 117 157
49453-93 124 152 95 131 149 83 116 129 59 85 92 57 68 71 86 86 86 2 2 6 2 2 6
49454-6 6 6 6 6 6 22 22 22 34 34 34 6 6 6 2 2 6 2 2 6 2 2 6
49455-2 2 6 2 2 6 18 18 18 34 34 34 10 10 10 50 50 50 22 22 22 2 2 6
49456-2 2 6 2 2 6 2 2 6 10 10 10 86 86 86 42 42 42 14 14 14 0 0 0
49457-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49458-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49459-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49460-
49461-40 89 40 40 89 40 40 89 40 40 89 40 24 53 24 6 6 6 69 31 31 123 55 55
49462-123 55 55 90 61 47 69 31 31 36 32 33 21 31 35 7 12 13 18 25 28 48 63 69
49463-60 80 103 68 78 128 84 101 153 84 96 162 84 96 162 91 117 157 91 117 157 84 96 162
49464-91 117 157 73 97 106 48 63 69 50 67 72 57 59 63 86 86 86 2 2 6 2 2 6
49465-38 38 38 116 116 116 94 94 94 22 22 22 22 22 22 2 2 6 2 2 6 2 2 6
49466-14 14 14 86 86 86 124 131 137 170 170 170 151 151 151 38 38 38 26 26 26 6 6 6
49467-2 2 6 2 2 6 2 2 6 2 2 6 86 86 86 46 46 46 14 14 14 0 0 0
49468-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49469-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49470-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49471-
49472-34 76 34 40 89 40 40 89 40 40 89 40 34 76 34 19 31 15 17 12 12 48 26 18
49473-48 26 18 8 7 3 10 10 22 23 29 47 51 61 92 42 59 64 21 30 33 34 45 54
49474-68 78 128 81 88 166 81 82 173 86 106 160 86 106 160 84 96 162 86 106 160 87 112 149
49475-91 118 149 77 105 114 52 67 79 32 40 45 50 50 50 86 86 86 2 2 6 14 14 14
49476-124 131 137 198 198 198 195 195 195 116 116 116 10 10 10 2 2 6 2 2 6 6 6 6
49477-101 98 89 187 187 187 210 210 210 218 218 218 214 214 214 124 131 137 14 14 14 6 6 6
49478-2 2 6 2 2 6 2 2 6 2 2 6 86 86 86 50 50 50 18 18 18 6 6 6
49479-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49480-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49481-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49482-
49483-19 31 15 34 76 34 40 89 40 40 89 40 40 89 40 24 53 24 8 7 3 0 0 0
49484-6 8 12 28 32 52 51 61 92 54 54 122 74 77 160 68 78 128 26 35 39 6 8 8
49485-34 45 54 68 78 128 84 96 162 86 106 160 86 106 160 81 88 166 84 96 162 87 112 149
49486-73 97 106 36 50 56 33 49 54 18 18 18 46 46 46 86 86 86 2 2 6 54 54 54
49487-218 218 218 195 195 195 226 226 226 246 246 246 58 58 58 2 2 6 2 2 6 30 30 30
49488-210 210 210 253 253 253 170 170 170 124 127 131 221 221 221 234 234 234 74 74 74 2 2 6
49489-2 2 6 2 2 6 2 2 6 2 2 6 70 70 70 58 58 58 22 22 22 6 6 6
49490-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49491-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49492-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49493-
49494-4 5 3 24 53 24 40 89 40 40 89 40 34 76 34 12 22 15 4 5 3 4 5 3
49495-13 17 26 54 54 122 78 78 174 78 78 174 78 78 174 74 77 160 51 61 92 21 31 35
49496-26 35 39 53 75 83 84 101 153 81 82 173 81 88 166 84 101 153 60 80 103 60 80 103
49497-53 75 83 38 53 58 42 59 64 22 22 22 46 46 46 82 82 82 2 2 6 106 106 106
49498-170 170 170 26 26 26 86 86 86 226 226 226 124 127 131 10 10 10 14 14 14 46 46 46
49499-231 231 231 190 190 190 6 6 6 70 70 70 90 90 90 238 238 238 151 151 151 2 2 6
49500-2 2 6 2 2 6 2 2 6 2 2 6 70 70 70 58 58 58 22 22 22 6 6 6
49501-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49502-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49503-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49504-
49505-1 2 2 8 15 6 24 53 24 34 76 34 19 31 15 8 15 6 63 55 20 63 55 20
49506-18 18 18 40 48 73 74 77 160 78 78 174 78 78 174 81 82 173 74 77 160 52 67 79
49507-17 23 26 21 31 35 60 80 103 81 88 166 74 77 160 78 102 129 36 54 60 12 17 20
49508-42 59 64 48 63 69 21 31 35 18 18 18 42 42 42 86 86 86 6 6 6 116 116 116
49509-106 106 106 6 6 6 70 70 70 151 151 151 124 127 131 18 18 18 38 38 38 54 54 54
49510-221 221 221 106 106 106 2 2 6 14 14 14 46 46 46 190 190 190 198 198 198 2 2 6
49511-2 2 6 2 2 6 2 2 6 2 2 6 74 74 74 62 62 62 22 22 22 6 6 6
49512-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49513-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49514-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49515-
49516-11 15 17 0 0 0 12 22 15 19 31 15 8 15 6 63 55 20 149 139 69 149 139 69
49517-63 55 20 10 10 22 54 54 122 78 78 174 78 78 174 78 78 174 81 82 173 68 78 128
49518-24 31 37 6 6 6 36 50 56 60 80 103 51 61 92 42 59 64 36 50 56 31 45 49
49519-29 43 47 27 40 45 6 8 8 14 14 14 42 42 42 94 94 94 14 14 14 101 101 101
49520-124 127 131 2 2 6 18 18 18 116 116 116 106 107 48 121 92 8 121 92 8 98 70 6
49521-170 170 170 106 106 106 2 2 6 2 2 6 2 2 6 195 195 195 195 195 195 6 6 6
49522-2 2 6 2 2 6 2 2 6 2 2 6 74 74 74 62 62 62 22 22 22 6 6 6
49523-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49524-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49525-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49526-
49527-26 35 39 3 5 6 1 1 1 2 3 3 35 31 12 133 118 54 175 176 80 175 176 80
49528-133 118 54 35 31 12 23 29 47 54 54 122 78 78 174 78 78 174 74 77 160 68 78 128
49529-51 61 92 31 45 49 26 35 39 36 50 56 29 43 47 7 12 13 21 30 33 42 59 64
49530-18 25 28 7 12 13 1 1 1 10 10 10 38 38 38 90 90 90 14 14 14 58 58 58
49531-210 210 210 26 26 26 62 42 6 154 114 10 226 170 11 237 188 10 220 174 15 184 138 11
49532-220 174 15 174 140 55 35 31 12 2 2 6 70 70 70 246 246 246 124 131 137 2 2 6
49533-2 2 6 2 2 6 2 2 6 2 2 6 70 70 70 66 66 66 26 26 26 6 6 6
49534-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49535-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49536-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49537-
49538-27 40 45 17 23 26 2 3 3 1 1 1 56 77 35 165 152 80 175 176 80 175 176 80
49539-175 176 80 106 107 48 22 22 22 28 32 52 54 54 122 54 54 122 51 61 92 28 32 52
49540-20 27 34 31 45 49 11 15 17 7 12 13 36 50 56 31 45 49 29 43 47 36 50 56
49541-6 8 8 0 0 0 0 0 0 10 10 10 38 38 38 86 86 86 14 14 14 10 10 10
49542-195 195 195 198 179 130 192 133 9 220 174 15 239 182 13 237 188 10 232 195 16 239 207 25
49543-237 201 50 241 208 19 232 195 16 184 138 11 198 179 130 208 206 196 42 42 42 2 2 6
49544-2 2 6 2 2 6 2 2 6 2 2 6 50 50 50 74 74 74 30 30 30 6 6 6
49545-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49546-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49547-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49548-
49549-15 22 25 26 35 39 15 22 25 0 0 0 35 31 12 133 118 54 175 176 80 175 176 80
49550-175 176 80 165 152 80 56 77 35 6 8 12 23 29 47 13 17 26 2 2 6 0 0 0
49551-1 2 2 26 35 39 26 35 39 26 35 39 42 59 64 42 59 64 20 29 31 6 8 8
49552-0 0 0 0 0 0 0 0 0 10 10 10 34 34 34 86 86 86 14 14 14 2 2 6
49553-121 92 8 192 133 9 219 162 10 239 182 13 237 188 10 232 195 16 241 208 19 237 201 50
49554-237 201 50 239 207 25 241 208 19 241 208 19 241 208 19 230 187 11 121 92 8 2 2 6
49555-2 2 6 2 2 6 2 2 6 2 2 6 50 50 50 82 82 82 34 34 34 10 10 10
49556-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49557-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49558-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49559-
49560-1 2 2 15 22 25 31 45 49 6 8 12 4 5 3 63 55 20 149 139 69 175 176 80
49561-175 176 80 175 176 80 106 107 48 20 16 6 1 1 1 0 0 0 2 3 3 11 15 17
49562-21 30 33 36 50 56 36 50 56 24 31 37 15 22 25 6 8 8 0 0 0 0 0 0
49563-0 0 0 0 0 0 0 0 0 10 10 10 34 34 34 82 82 82 30 30 30 62 42 6
49564-180 123 7 206 145 10 230 174 11 239 182 13 237 188 10 238 202 15 241 208 19 237 201 50
49565-239 207 25 241 208 19 241 208 19 241 208 19 230 187 11 220 174 15 184 138 11 6 6 6
49566-2 2 6 2 2 6 2 2 6 2 2 6 26 26 26 94 94 94 42 42 42 14 14 14
49567-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49568-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49569-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49570-
49571-0 0 0 1 2 2 29 43 47 26 35 39 3 5 6 8 7 3 106 107 48 165 152 80
49572-175 176 80 149 139 69 63 55 20 4 5 3 2 3 3 12 17 20 26 35 39 26 35 39
49573-17 23 26 7 12 13 6 8 8 3 5 6 1 2 2 0 0 0 0 0 0 0 0 0
49574-0 0 0 0 0 0 0 0 0 10 10 10 30 30 30 78 78 78 50 50 50 104 69 6
49575-192 133 9 216 158 10 236 178 12 237 188 10 232 195 16 241 208 19 237 201 50 237 201 50
49576-241 208 19 241 208 19 241 208 19 204 160 10 200 144 11 216 158 10 156 118 10 2 2 6
49577-2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 90 90 90 54 54 54 18 18 18
49578-6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49579-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49580-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49581-
49582-0 0 0 0 0 0 12 17 20 27 40 45 18 25 28 1 1 1 35 31 12 106 107 48
49583-149 139 69 56 77 35 8 7 3 1 2 2 12 17 20 26 35 39 21 31 35 11 15 17
49584-3 5 6 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49585-0 0 0 0 0 0 0 0 0 10 10 10 30 30 30 78 78 78 46 46 46 22 22 22
49586-137 92 6 204 160 10 239 182 13 237 188 10 238 202 15 241 208 19 241 208 19 241 208 19
49587-241 208 19 204 160 10 184 138 11 210 150 10 216 158 10 210 150 10 98 70 6 2 2 6
49588-6 6 6 54 54 54 14 14 14 2 2 6 2 2 6 62 62 62 74 74 74 30 30 30
49589-10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49590-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49591-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49592-
49593-0 0 0 0 0 0 1 1 1 15 22 25 33 49 54 12 17 20 2 3 3 35 31 12
49594-56 77 35 20 16 6 1 1 1 18 25 28 21 31 35 11 15 17 1 1 1 0 0 0
49595-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49596-0 0 0 0 0 0 0 0 0 10 10 10 34 34 34 78 78 78 50 50 50 6 6 6
49597-88 55 22 139 102 15 190 146 13 230 187 11 239 207 25 232 195 16 220 174 15 190 146 13
49598-171 120 8 192 133 9 210 150 10 213 154 11 185 146 40 165 152 80 101 98 89 2 2 6
49599-2 2 6 78 78 78 116 116 116 58 58 58 2 2 6 22 22 22 90 90 90 46 46 46
49600-18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49601-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49602-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49603-
49604-0 0 0 0 0 0 0 0 0 1 1 1 27 40 45 29 43 47 3 5 6 2 3 3
49605-8 7 3 1 1 1 17 23 26 31 45 49 15 22 25 0 0 0 0 0 0 0 0 0
49606-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49607-0 0 0 0 0 0 0 0 0 10 10 10 38 38 38 86 86 86 50 50 50 6 6 6
49608-124 127 131 168 158 138 156 107 11 171 120 8 204 160 10 184 138 11 197 138 11 200 144 11
49609-206 145 10 206 145 10 197 138 11 198 179 130 195 195 195 198 198 198 170 170 170 14 14 14
49610-2 2 6 22 22 22 116 116 116 116 116 116 22 22 22 2 2 6 74 74 74 70 70 70
49611-30 30 30 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49612-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49613-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49614-
49615-0 0 0 0 0 0 0 0 0 0 0 0 11 15 17 31 45 49 26 35 39 3 5 6
49616-0 0 0 7 12 13 27 40 45 18 25 28 0 0 0 0 0 0 0 0 0 0 0 0
49617-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49618-0 0 0 0 0 0 6 6 6 18 18 18 50 50 50 101 101 101 26 26 26 10 10 10
49619-124 131 137 190 190 190 168 158 138 156 107 11 197 138 11 200 144 11 197 138 11 192 133 9
49620-180 123 7 185 146 40 198 179 130 187 187 187 202 202 202 221 221 221 214 214 214 66 66 66
49621-2 2 6 2 2 6 50 50 50 62 62 62 6 6 6 2 2 6 10 10 10 90 90 90
49622-50 50 50 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49623-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49624-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49625-
49626-0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 15 22 25 36 54 60 18 25 28
49627-0 0 0 21 30 33 27 40 45 2 3 3 0 0 0 0 0 0 0 0 0 0 0 0
49628-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49629-0 0 0 0 0 0 10 10 10 34 34 34 74 74 74 74 74 74 2 2 6 6 6 6
49630-151 151 151 198 198 198 190 190 190 168 158 138 148 132 55 156 107 11 156 107 11 169 125 40
49631-168 158 138 187 187 187 190 190 190 210 210 210 246 246 246 253 253 253 253 253 253 180 180 180
49632-6 6 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 62 62 62
49633-74 74 74 34 34 34 14 14 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49634-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49635-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49636-
49637-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 27 40 45 35 52 58
49638-18 25 28 35 52 58 17 23 26 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49639-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49640-0 0 0 10 10 10 22 22 22 54 54 54 94 94 94 18 18 18 2 2 6 46 46 46
49641-234 234 234 221 221 221 190 190 190 190 190 190 190 190 190 187 187 187 187 187 187 190 190 190
49642-190 190 190 195 195 195 214 214 214 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
49643-82 82 82 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 14 14 14
49644-86 86 86 54 54 54 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0
49645-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49646-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49647-
49648-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7 12 13 33 49 54
49649-52 72 81 36 54 60 6 8 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49650-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49651-6 6 6 18 18 18 46 46 46 90 90 90 46 46 46 18 18 18 6 6 6 180 180 180
49652-253 253 253 246 246 246 202 202 202 190 190 190 190 190 190 190 190 190 190 190 190 190 190 190
49653-202 202 202 231 231 231 250 250 250 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49654-202 202 202 14 14 14 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49655-42 42 42 86 86 86 42 42 42 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0
49656-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49657-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49658-
49659-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 12 17 20
49660-36 54 60 29 43 47 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49661-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
49662-14 14 14 38 38 38 74 74 74 66 66 66 2 2 6 6 6 6 90 90 90 250 250 250
49663-253 253 253 253 253 253 238 238 238 198 198 198 190 190 190 190 190 190 195 195 195 221 221 221
49664-246 246 246 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49665-253 253 253 82 82 82 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49666-2 2 6 78 78 78 70 70 70 34 34 34 14 14 14 6 6 6 0 0 0 0 0 0
49667-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49668-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49669-
49670-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49671-21 30 33 35 52 58 6 8 12 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49672-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 14 14 14
49673-34 34 34 66 66 66 78 78 78 6 6 6 2 2 6 18 18 18 218 218 218 253 253 253
49674-253 253 253 253 253 253 253 253 253 246 246 246 226 226 226 231 231 231 246 246 246 253 253 253
49675-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49676-253 253 253 180 180 180 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49677-2 2 6 18 18 18 90 90 90 62 62 62 30 30 30 10 10 10 0 0 0 0 0 0
49678-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49679-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49680-
49681-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49682-12 17 20 36 54 60 29 43 47 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49683-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10 26 26 26
49684-58 58 58 90 90 90 18 18 18 2 2 6 2 2 6 106 106 106 253 253 253 253 253 253
49685-253 253 253 253 253 253 253 253 253 253 253 253 250 250 250 253 253 253 253 253 253 253 253 253
49686-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49687-253 253 253 231 231 231 18 18 18 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49688-2 2 6 2 2 6 18 18 18 94 94 94 54 54 54 26 26 26 10 10 10 0 0 0
49689-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49690-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49691-
49692-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49693-0 0 0 21 30 33 35 52 58 6 8 12 0 0 0 0 0 0 0 0 0 0 0 0
49694-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 22 22 22 50 50 50
49695-90 90 90 26 26 26 2 2 6 2 2 6 14 14 14 195 195 195 250 250 250 253 253 253
49696-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49697-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49698-250 250 250 242 242 242 54 54 54 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49699-2 2 6 2 2 6 2 2 6 38 38 38 86 86 86 50 50 50 22 22 22 6 6 6
49700-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49701-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49702-
49703-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49704-0 0 0 0 0 0 12 17 20 36 54 60 29 43 47 0 0 0 0 0 0 0 0 0
49705-0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 14 14 14 38 38 38 82 82 82
49706-34 34 34 2 2 6 2 2 6 2 2 6 42 42 42 195 195 195 246 246 246 253 253 253
49707-253 253 253 253 253 253 253 253 253 250 250 250 242 242 242 242 242 242 250 250 250 253 253 253
49708-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 250 250 250 246 246 246 238 238 238
49709-226 226 226 231 231 231 101 101 101 6 6 6 2 2 6 2 2 6 2 2 6 2 2 6
49710-2 2 6 2 2 6 2 2 6 2 2 6 38 38 38 82 82 82 42 42 42 14 14 14
49711-6 6 6 0 0 0 0 0 0 0 0 0 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-
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 21 30 33 35 52 58 6 8 12 0 0 0 0 0 0
49716-0 0 0 0 0 0 0 0 0 0 0 0 10 10 10 26 26 26 62 62 62 66 66 66
49717-2 2 6 2 2 6 2 2 6 6 6 6 70 70 70 170 170 170 202 202 202 234 234 234
49718-246 246 246 250 250 250 250 250 250 238 238 238 226 226 226 231 231 231 238 238 238 250 250 250
49719-250 250 250 250 250 250 246 246 246 231 231 231 214 214 214 202 202 202 202 202 202 202 202 202
49720-198 198 198 202 202 202 180 180 180 18 18 18 2 2 6 2 2 6 2 2 6 2 2 6
49721-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 62 62 62 66 66 66 30 30 30
49722-10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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-
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 12 17 20 36 54 60 29 43 47 0 0 0 0 0 0
49727-0 0 0 0 0 0 0 0 0 0 0 0 14 14 14 42 42 42 82 82 82 18 18 18
49728-2 2 6 2 2 6 2 2 6 10 10 10 94 94 94 180 180 180 218 218 218 242 242 242
49729-250 250 250 253 253 253 253 253 253 250 250 250 234 234 234 253 253 253 253 253 253 253 253 253
49730-253 253 253 253 253 253 253 253 253 246 246 246 238 238 238 226 226 226 210 210 210 202 202 202
49731-195 195 195 195 195 195 210 210 210 151 151 151 6 6 6 14 14 14 50 50 50 14 14 14
49732-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 86 86 86 46 46 46
49733-18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49734-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49735-
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 21 30 33 35 52 58 6 8 12 0 0 0
49738-0 0 0 0 0 0 0 0 0 6 6 6 22 22 22 54 54 54 70 70 70 2 2 6
49739-2 2 6 10 10 10 2 2 6 22 22 22 170 170 170 231 231 231 250 250 250 253 253 253
49740-253 253 253 253 253 253 253 253 253 250 250 250 242 242 242 253 253 253 253 253 253 253 253 253
49741-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 246 246 246
49742-231 231 231 202 202 202 198 198 198 226 226 226 94 94 94 2 2 6 6 6 6 38 38 38
49743-30 30 30 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 62 62 62 66 66 66
49744-26 26 26 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49745-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49746-
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 6 8 8 33 49 54 29 43 47 6 8 12
49749-0 0 0 0 0 0 0 0 0 10 10 10 30 30 30 74 74 74 50 50 50 2 2 6
49750-26 26 26 26 26 26 2 2 6 106 106 106 238 238 238 253 253 253 253 253 253 253 253 253
49751-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49752-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49753-253 253 253 246 246 246 218 218 218 202 202 202 210 210 210 14 14 14 2 2 6 2 2 6
49754-30 30 30 22 22 22 2 2 6 2 2 6 2 2 6 2 2 6 18 18 18 86 86 86
49755-42 42 42 14 14 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49756-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49757-
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 12 17 20 33 49 54 17 23 26
49760-0 0 0 0 0 0 0 0 0 14 14 14 42 42 42 90 90 90 22 22 22 2 2 6
49761-42 42 42 2 2 6 18 18 18 218 218 218 253 253 253 253 253 253 253 253 253 253 253 253
49762-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49763-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49764-253 253 253 253 253 253 250 250 250 221 221 221 218 218 218 101 101 101 2 2 6 14 14 14
49765-18 18 18 38 38 38 10 10 10 2 2 6 2 2 6 2 2 6 2 2 6 78 78 78
49766-58 58 58 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49767-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49768-
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 15 22 25 36 54 60
49771-0 0 0 0 0 0 0 0 0 18 18 18 54 54 54 82 82 82 2 2 6 26 26 26
49772-22 22 22 2 2 6 124 127 131 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49773-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49774-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49775-253 253 253 253 253 253 253 253 253 250 250 250 238 238 238 198 198 198 6 6 6 38 38 38
49776-58 58 58 26 26 26 38 38 38 2 2 6 2 2 6 2 2 6 2 2 6 46 46 46
49777-78 78 78 30 30 30 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49778-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49779-
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 21 30 33
49782-36 54 60 0 0 0 0 0 0 30 30 30 74 74 74 58 58 58 2 2 6 42 42 42
49783-2 2 6 22 22 22 231 231 231 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49784-253 253 253 253 253 253 253 253 253 250 250 250 253 253 253 253 253 253 253 253 253 253 253 253
49785-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49786-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 246 246 246 46 46 46 38 38 38
49787-42 42 42 14 14 14 38 38 38 14 14 14 2 2 6 2 2 6 2 2 6 6 6 6
49788-86 86 86 46 46 46 14 14 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49789-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49790-
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-36 54 60 0 0 0 0 0 0 42 42 42 90 90 90 18 18 18 18 18 18 26 26 26
49794-2 2 6 116 116 116 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49795-253 253 253 253 253 253 250 250 250 238 238 238 253 253 253 253 253 253 253 253 253 253 253 253
49796-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49797-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 94 94 94 6 6 6
49798-2 2 6 2 2 6 10 10 10 34 34 34 2 2 6 2 2 6 2 2 6 2 2 6
49799-74 74 74 58 58 58 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0
49800-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49801-
49802-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49803-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49804-0 0 0 36 54 60 26 26 26 66 66 66 82 82 82 2 2 6 38 38 38 6 6 6
49805-14 14 14 210 210 210 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49806-253 253 253 253 253 253 246 246 246 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
49807-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49808-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 151 151 151 2 2 6
49809-2 2 6 2 2 6 2 2 6 46 46 46 2 2 6 2 2 6 2 2 6 2 2 6
49810-42 42 42 74 74 74 30 30 30 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0
49811-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49812-
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-6 6 6 36 54 60 21 30 33 90 90 90 26 26 26 6 6 6 42 42 42 2 2 6
49816-74 74 74 250 250 250 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49817-253 253 253 253 253 253 242 242 242 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
49818-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49819-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 180 180 180 2 2 6
49820-2 2 6 2 2 6 2 2 6 46 46 46 2 2 6 2 2 6 2 2 6 2 2 6
49821-10 10 10 86 86 86 38 38 38 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0
49822-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49823-
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-10 10 10 26 26 26 36 54 60 82 82 82 2 2 6 22 22 22 18 18 18 2 2 6
49827-151 151 151 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49828-253 253 253 253 253 253 234 234 234 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
49829-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49830-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 202 202 202 2 2 6
49831-2 2 6 2 2 6 2 2 6 38 38 38 2 2 6 2 2 6 2 2 6 2 2 6
49832-6 6 6 86 86 86 46 46 46 14 14 14 0 0 0 0 0 0 0 0 0 0 0 0
49833-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49834-
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 6 6 6
49837-18 18 18 46 46 46 86 86 86 36 54 60 2 2 6 34 34 34 10 10 10 6 6 6
49838-210 210 210 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49839-253 253 253 253 253 253 234 234 234 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
49840-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49841-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 221 221 221 6 6 6
49842-2 2 6 2 2 6 6 6 6 30 30 30 2 2 6 2 2 6 2 2 6 2 2 6
49843-2 2 6 82 82 82 54 54 54 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0
49844-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49845-
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 10 10 10
49848-26 26 26 66 66 66 62 62 62 2 2 6 2 2 6 38 38 38 10 10 10 26 26 26
49849-238 238 238 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49850-253 253 253 253 253 253 231 231 231 238 238 238 253 253 253 253 253 253 253 253 253 253 253 253
49851-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49852-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 231 231 231 6 6 6
49853-2 2 6 2 2 6 10 10 10 30 30 30 2 2 6 2 2 6 2 2 6 2 2 6
49854-2 2 6 66 66 66 58 58 58 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0
49855-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49856-
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 10 10 10
49859-38 38 38 78 78 78 6 6 6 2 2 6 2 2 6 46 46 46 14 14 14 42 42 42
49860-246 246 246 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49861-253 253 253 253 253 253 231 231 231 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
49862-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49863-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 234 234 234 10 10 10
49864-2 2 6 2 2 6 22 22 22 14 14 14 2 2 6 2 2 6 2 2 6 2 2 6
49865-2 2 6 66 66 66 62 62 62 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0
49866-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49867-
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 6 6 6 18 18 18
49870-50 50 50 74 74 74 2 2 6 2 2 6 14 14 14 70 70 70 34 34 34 62 62 62
49871-250 250 250 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49872-253 253 253 253 253 253 231 231 231 246 246 246 253 253 253 253 253 253 253 253 253 253 253 253
49873-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49874-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 234 234 234 14 14 14
49875-2 2 6 2 2 6 30 30 30 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49876-2 2 6 66 66 66 62 62 62 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0
49877-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49878-
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 6 6 6 18 18 18
49881-54 54 54 62 62 62 2 2 6 2 2 6 2 2 6 30 30 30 46 46 46 70 70 70
49882-250 250 250 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49883-253 253 253 253 253 253 231 231 231 246 246 246 253 253 253 253 253 253 253 253 253 253 253 253
49884-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49885-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 226 226 226 10 10 10
49886-2 2 6 6 6 6 30 30 30 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49887-2 2 6 66 66 66 58 58 58 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0
49888-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49889-
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 6 6 6 22 22 22
49892-58 58 58 62 62 62 2 2 6 2 2 6 2 2 6 2 2 6 30 30 30 78 78 78
49893-250 250 250 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49894-253 253 253 253 253 253 231 231 231 246 246 246 253 253 253 253 253 253 253 253 253 253 253 253
49895-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49896-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 202 202 202 2 2 6
49897-22 22 22 34 34 34 20 16 6 22 22 22 26 26 26 18 18 18 6 6 6 2 2 6
49898-2 2 6 82 82 82 54 54 54 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0
49899-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49900-
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 6 6 6 26 26 26
49903-62 62 62 106 106 106 63 55 20 184 138 11 204 160 10 121 92 8 6 6 6 62 62 62
49904-238 238 238 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49905-253 253 253 253 253 253 231 231 231 246 246 246 253 253 253 253 253 253 253 253 253 253 253 253
49906-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49907-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 151 151 151 18 18 18
49908-14 14 14 2 2 6 2 2 6 2 2 6 6 6 6 18 18 18 66 66 66 38 38 38
49909-6 6 6 94 94 94 50 50 50 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0
49910-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49911-
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 6 6 6 10 10 10 10 10 10 18 18 18 38 38 38
49914-78 78 78 138 132 106 216 158 10 242 186 14 246 190 14 246 190 14 156 118 10 10 10 10
49915-90 90 90 238 238 238 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49916-253 253 253 253 253 253 231 231 231 250 250 250 253 253 253 253 253 253 253 253 253 253 253 253
49917-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49918-253 253 253 253 253 253 253 253 253 246 230 190 214 187 87 214 187 87 185 146 40 35 31 12
49919-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 38 38 38 46 46 46
49920-26 26 26 106 106 106 54 54 54 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0
49921-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49922-
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 6 6 6 14 14 14 22 22 22 30 30 30 38 38 38 50 50 50 70 70 70
49925-106 106 106 185 146 40 226 170 11 242 186 14 246 190 14 246 190 14 246 190 14 154 114 10
49926-6 6 6 74 74 74 226 226 226 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49927-253 253 253 253 253 253 231 231 231 250 250 250 253 253 253 253 253 253 253 253 253 253 253 253
49928-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49929-253 253 253 253 253 253 253 253 253 237 201 50 241 196 14 241 208 19 232 195 16 35 31 12
49930-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 30 30 30 26 26 26
49931-204 160 10 165 152 80 66 66 66 26 26 26 6 6 6 0 0 0 0 0 0 0 0 0
49932-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49933-
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-6 6 6 18 18 18 38 38 38 58 58 58 78 78 78 86 86 86 101 101 101 124 127 131
49936-174 140 55 210 150 10 234 174 13 246 186 14 246 190 14 246 190 14 246 190 14 237 188 10
49937-98 70 6 2 2 6 46 46 46 198 198 198 253 253 253 253 253 253 253 253 253 253 253 253
49938-253 253 253 253 253 253 234 234 234 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
49939-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49940-253 253 253 253 253 253 253 253 253 214 187 87 242 186 14 241 196 14 204 160 10 20 16 6
49941-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 121 92 8
49942-238 202 15 232 195 16 82 82 82 34 34 34 10 10 10 0 0 0 0 0 0 0 0 0
49943-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49944-
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-14 14 14 38 38 38 70 70 70 148 132 55 185 146 40 200 144 11 197 138 11 197 138 11
49947-213 154 11 226 170 11 242 186 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
49948-220 174 15 35 31 12 2 2 6 22 22 22 151 151 151 250 250 250 253 253 253 253 253 253
49949-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49950-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49951-253 253 253 250 250 250 242 242 242 214 187 87 239 182 13 237 188 10 213 154 11 35 31 12
49952-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 62 42 6 220 174 15
49953-237 188 10 237 188 10 113 101 86 42 42 42 14 14 14 0 0 0 0 0 0 0 0 0
49954-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49955-
49956-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
49957-22 22 22 54 54 54 148 132 55 213 154 11 226 170 11 230 174 11 226 170 11 226 170 11
49958-236 178 12 242 186 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
49959-241 196 14 184 138 11 10 10 10 2 2 6 6 6 6 116 116 116 242 242 242 253 253 253
49960-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49961-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49962-253 253 253 231 231 231 198 198 198 213 164 39 236 178 12 236 178 12 210 150 10 137 92 6
49963-20 16 6 2 2 6 2 2 6 2 2 6 6 6 6 62 42 6 200 144 11 236 178 12
49964-239 182 13 239 182 13 124 112 88 58 58 58 22 22 22 6 6 6 0 0 0 0 0 0
49965-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49966-
49967-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
49968-30 30 30 70 70 70 169 125 40 226 170 11 239 182 13 242 186 14 242 186 14 246 186 14
49969-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
49970-246 190 14 232 195 16 98 70 6 2 2 6 2 2 6 2 2 6 66 66 66 221 221 221
49971-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49972-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49973-253 253 253 202 202 202 198 198 198 213 164 39 230 174 11 230 174 11 216 158 10 192 133 9
49974-163 110 8 120 80 7 98 70 6 120 80 7 167 114 7 197 138 11 226 170 11 239 182 13
49975-242 186 14 242 186 14 165 152 80 78 78 78 34 34 34 14 14 14 6 6 6 0 0 0
49976-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49977-
49978-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
49979-30 30 30 78 78 78 185 146 40 226 170 11 239 182 13 246 190 14 246 190 14 246 190 14
49980-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
49981-246 190 14 241 196 14 204 160 10 20 16 6 2 2 6 2 2 6 2 2 6 38 38 38
49982-218 218 218 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49983-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49984-250 250 250 202 202 202 198 198 198 213 164 39 226 170 11 236 178 12 224 166 10 210 150 10
49985-200 144 11 197 138 11 192 133 9 197 138 11 210 150 10 226 170 11 242 186 14 246 190 14
49986-246 190 14 246 186 14 220 174 15 124 112 88 62 62 62 30 30 30 14 14 14 6 6 6
49987-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49988-
49989-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
49990-30 30 30 78 78 78 174 140 55 224 166 10 239 182 13 246 190 14 246 190 14 246 190 14
49991-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
49992-246 190 14 246 190 14 241 196 14 139 102 15 2 2 6 2 2 6 2 2 6 2 2 6
49993-78 78 78 250 250 250 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49994-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
49995-250 250 250 214 214 214 198 198 198 185 146 40 219 162 10 236 178 12 234 174 13 224 166 10
49996-216 158 10 213 154 11 213 154 11 216 158 10 226 170 11 239 182 13 246 190 14 246 190 14
49997-246 190 14 246 190 14 242 186 14 213 164 39 101 101 101 58 58 58 30 30 30 14 14 14
49998-6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49999-
50000-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
50001-30 30 30 74 74 74 174 140 55 216 158 10 236 178 12 246 190 14 246 190 14 246 190 14
50002-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50003-246 190 14 246 190 14 241 196 14 230 187 11 62 42 6 2 2 6 2 2 6 2 2 6
50004-22 22 22 238 238 238 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50005-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50006-253 253 253 226 226 226 187 187 187 169 125 40 216 158 10 236 178 12 239 182 13 236 178 12
50007-230 174 11 226 170 11 226 170 11 230 174 11 236 178 12 242 186 14 246 190 14 246 190 14
50008-246 190 14 246 190 14 246 186 14 239 182 13 213 164 39 106 106 106 66 66 66 34 34 34
50009-14 14 14 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50010-
50011-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50012-26 26 26 70 70 70 149 139 69 213 154 11 236 178 12 246 190 14 246 190 14 246 190 14
50013-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50014-246 190 14 246 190 14 246 190 14 241 196 14 190 146 13 20 16 6 2 2 6 2 2 6
50015-46 46 46 246 246 246 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50016-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50017-253 253 253 221 221 221 86 86 86 156 107 11 216 158 10 236 178 12 242 186 14 246 186 14
50018-242 186 14 239 182 13 239 182 13 242 186 14 242 186 14 246 186 14 246 190 14 246 190 14
50019-246 190 14 246 190 14 246 190 14 246 190 14 242 186 14 220 174 15 149 139 69 66 66 66
50020-30 30 30 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50021-
50022-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50023-26 26 26 70 70 70 149 139 69 210 150 10 236 178 12 246 190 14 246 190 14 246 190 14
50024-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50025-246 190 14 246 190 14 246 190 14 246 190 14 232 195 16 121 92 8 34 34 34 106 106 106
50026-221 221 221 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50027-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50028-242 242 242 82 82 82 20 16 6 163 110 8 216 158 10 236 178 12 242 186 14 246 190 14
50029-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50030-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 242 186 14 149 139 69
50031-46 46 46 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50032-
50033-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
50034-30 30 30 78 78 78 149 139 69 210 150 10 236 178 12 246 186 14 246 190 14 246 190 14
50035-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50036-246 190 14 246 190 14 246 190 14 246 190 14 241 196 14 220 174 15 198 179 130 253 253 253
50037-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50038-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 218 218 218
50039-58 58 58 2 2 6 20 16 6 167 114 7 216 158 10 236 178 12 246 186 14 246 190 14
50040-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50041-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 186 14 242 186 14 185 146 40
50042-54 54 54 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50043-
50044-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 14 14 14
50045-38 38 38 86 86 86 169 125 40 213 154 11 236 178 12 246 186 14 246 190 14 246 190 14
50046-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50047-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 232 195 16 190 146 13 214 214 214
50048-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50049-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 250 250 250 170 170 170 26 26 26
50050-2 2 6 2 2 6 35 31 12 163 110 8 219 162 10 239 182 13 246 186 14 246 190 14
50051-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50052-246 190 14 246 190 14 246 190 14 246 190 14 246 186 14 236 178 12 224 166 10 149 139 69
50053-46 46 46 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50054-
50055-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 18 18 18
50056-50 50 50 113 101 86 192 133 9 224 166 10 242 186 14 246 190 14 246 190 14 246 190 14
50057-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50058-246 190 14 246 190 14 246 190 14 246 190 14 242 186 14 230 187 11 204 160 10 133 118 54
50059-226 226 226 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50060-253 253 253 253 253 253 253 253 253 253 253 253 198 198 198 66 66 66 2 2 6 2 2 6
50061-2 2 6 2 2 6 62 42 6 156 107 11 219 162 10 239 182 13 246 186 14 246 190 14
50062-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50063-246 190 14 246 190 14 246 190 14 242 186 14 234 174 13 213 154 11 148 132 55 66 66 66
50064-30 30 30 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50065-
50066-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 22 22 22
50067-58 58 58 148 132 55 206 145 10 234 174 13 242 186 14 246 186 14 246 190 14 246 190 14
50068-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50069-246 190 14 246 190 14 246 190 14 246 190 14 246 186 14 236 178 12 204 160 10 163 110 8
50070-62 42 6 124 131 137 218 218 218 250 250 250 253 253 253 253 253 253 253 253 253 250 250 250
50071-242 242 242 210 210 210 151 151 151 66 66 66 6 6 6 2 2 6 2 2 6 2 2 6
50072-2 2 6 2 2 6 62 42 6 163 110 8 216 158 10 236 178 12 246 190 14 246 190 14
50073-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50074-246 190 14 239 182 13 230 174 11 216 158 10 185 146 40 124 112 88 70 70 70 38 38 38
50075-18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50076-
50077-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 22 22 22
50078-62 62 62 169 125 40 206 145 10 224 166 10 236 178 12 239 182 13 242 186 14 242 186 14
50079-246 186 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50080-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 236 178 12 216 158 10 171 120 8
50081-85 57 6 2 2 6 6 6 6 30 30 30 54 54 54 62 62 62 50 50 50 38 38 38
50082-14 14 14 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50083-2 2 6 6 6 6 85 57 6 167 114 7 213 154 11 236 178 12 246 190 14 246 190 14
50084-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 242 186 14 239 182 13 239 182 13
50085-230 174 11 210 150 10 174 140 55 124 112 88 82 82 82 54 54 54 34 34 34 18 18 18
50086-6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50087-
50088-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 18 18 18
50089-50 50 50 169 125 40 192 133 9 200 144 11 216 158 10 219 162 10 224 166 10 226 170 11
50090-230 174 11 236 178 12 239 182 13 239 182 13 242 186 14 246 186 14 246 190 14 246 190 14
50091-246 190 14 246 190 14 246 190 14 246 190 14 246 186 14 230 174 11 210 150 10 163 110 8
50092-104 69 6 10 10 10 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50093-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50094-2 2 6 6 6 6 85 57 6 167 114 7 206 145 10 230 174 11 242 186 14 246 190 14
50095-246 190 14 246 190 14 246 186 14 242 186 14 239 182 13 230 174 11 224 166 10 213 154 11
50096-169 125 40 124 112 88 86 86 86 58 58 58 38 38 38 22 22 22 10 10 10 6 6 6
50097-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50098-
50099-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 14 14 14
50100-34 34 34 70 70 70 133 118 54 169 125 40 167 114 7 180 123 7 192 133 9 197 138 11
50101-200 144 11 206 145 10 213 154 11 219 162 10 224 166 10 230 174 11 239 182 13 242 186 14
50102-246 186 14 246 186 14 246 186 14 246 186 14 239 182 13 216 158 10 184 138 11 152 99 6
50103-104 69 6 20 16 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50104-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50105-2 2 6 6 6 6 85 57 6 152 99 6 192 133 9 219 162 10 236 178 12 239 182 13
50106-246 186 14 242 186 14 239 182 13 236 178 12 224 166 10 206 145 10 192 133 9 148 132 55
50107-94 94 94 62 62 62 42 42 42 22 22 22 14 14 14 6 6 6 0 0 0 0 0 0
50108-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50109-
50110-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50111-18 18 18 34 34 34 58 58 58 78 78 78 101 98 89 124 112 88 133 118 54 156 107 11
50112-163 110 8 167 114 7 171 120 8 180 123 7 184 138 11 197 138 11 210 150 10 219 162 10
50113-226 170 11 236 178 12 236 178 12 234 174 13 219 162 10 197 138 11 163 110 8 134 84 6
50114-85 57 6 10 10 10 2 2 6 2 2 6 18 18 18 38 38 38 38 38 38 38 38 38
50115-38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 26 26 26 2 2 6
50116-2 2 6 6 6 6 62 42 6 137 92 6 171 120 8 200 144 11 219 162 10 230 174 11
50117-234 174 13 230 174 11 219 162 10 210 150 10 192 133 9 163 110 8 124 112 88 82 82 82
50118-50 50 50 30 30 30 14 14 14 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0
50119-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50120-
50121-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50122-6 6 6 14 14 14 22 22 22 34 34 34 42 42 42 58 58 58 74 74 74 86 86 86
50123-101 98 89 113 101 86 133 118 54 121 92 8 137 92 6 152 99 6 163 110 8 180 123 7
50124-184 138 11 197 138 11 206 145 10 200 144 11 180 123 7 156 107 11 134 84 6 104 69 6
50125-62 42 6 54 54 54 106 106 106 101 98 89 86 86 86 82 82 82 78 78 78 78 78 78
50126-78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 82 82 82 86 86 86 94 94 94
50127-106 106 106 101 101 101 90 61 47 120 80 7 156 107 11 180 123 7 192 133 9 200 144 11
50128-206 145 10 200 144 11 192 133 9 171 120 8 139 102 15 113 101 86 70 70 70 42 42 42
50129-22 22 22 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50130-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50131-
50132-0 0 0 0 0 0 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 6 6 6 10 10 10 14 14 14 22 22 22 30 30 30 38 38 38
50134-50 50 50 62 62 62 74 74 74 90 90 90 101 98 89 113 101 86 121 92 8 120 80 7
50135-137 92 6 152 99 6 152 99 6 152 99 6 134 84 6 120 80 7 98 70 6 88 55 22
50136-101 98 89 82 82 82 58 58 58 46 46 46 38 38 38 34 34 34 34 34 34 34 34 34
50137-34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 38 38 38 42 42 42
50138-54 54 54 82 82 82 94 86 71 85 57 6 134 84 6 156 107 11 167 114 7 171 120 8
50139-171 120 8 167 114 7 152 99 6 121 92 8 101 98 89 62 62 62 34 34 34 18 18 18
50140-6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50141-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50142-
50143-0 0 0 0 0 0 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 6 6 6 6 6 6 10 10 10
50145-18 18 18 22 22 22 30 30 30 42 42 42 50 50 50 66 66 66 86 86 86 101 98 89
50146-94 86 71 98 70 6 104 69 6 104 69 6 104 69 6 85 57 6 88 55 22 90 90 90
50147-62 62 62 38 38 38 22 22 22 14 14 14 10 10 10 10 10 10 10 10 10 10 10 10
50148-10 10 10 10 10 10 6 6 6 10 10 10 10 10 10 10 10 10 10 10 10 14 14 14
50149-22 22 22 42 42 42 70 70 70 94 86 71 85 57 6 104 69 6 120 80 7 137 92 6
50150-134 84 6 120 80 7 94 86 71 86 86 86 58 58 58 30 30 30 14 14 14 6 6 6
50151-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50152-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50153-
50154-0 0 0 0 0 0 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-0 0 0 6 6 6 10 10 10 14 14 14 18 18 18 26 26 26 38 38 38 54 54 54
50157-70 70 70 86 86 86 94 86 71 94 86 71 94 86 71 86 86 86 74 74 74 50 50 50
50158-30 30 30 14 14 14 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50159-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50160-6 6 6 18 18 18 34 34 34 58 58 58 82 82 82 94 86 71 94 86 71 94 86 71
50161-94 86 71 94 86 71 74 74 74 50 50 50 26 26 26 14 14 14 6 6 6 0 0 0
50162-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50163-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50164-
50165-0 0 0 0 0 0 0 0 0 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-0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 6 6 6 14 14 14 18 18 18
50168-30 30 30 38 38 38 46 46 46 54 54 54 50 50 50 42 42 42 30 30 30 18 18 18
50169-10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50170-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50171-0 0 0 6 6 6 14 14 14 26 26 26 38 38 38 50 50 50 58 58 58 58 58 58
50172-54 54 54 42 42 42 30 30 30 18 18 18 10 10 10 0 0 0 0 0 0 0 0 0
50173-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50174-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50175-
50176-0 0 0 0 0 0 0 0 0 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-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50179-6 6 6 10 10 10 14 14 14 18 18 18 18 18 18 14 14 14 10 10 10 6 6 6
50180-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50181-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50182-0 0 0 0 0 0 0 0 0 6 6 6 14 14 14 18 18 18 22 22 22 22 22 22
50183-18 18 18 14 14 14 10 10 10 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0
50184-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50185-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50186-
50187+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50188+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50189+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50190+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50191+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50192+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50193+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50194+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50195+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50196+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50197+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50198+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50199+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50200+4 4 4 4 4 4
50201+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50202+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50203+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50204+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50205+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50206+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50207+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50208+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50209+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50210+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50211+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50212+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50213+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50214+4 4 4 4 4 4
50215+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50216+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50217+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50218+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50219+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50220+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50221+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50222+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50223+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50224+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50225+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50226+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50227+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50228+4 4 4 4 4 4
50229+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50230+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50231+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50232+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50233+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50234+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50235+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50236+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50237+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50238+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50239+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50240+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50241+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50242+4 4 4 4 4 4
50243+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50244+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50245+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50246+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50247+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50248+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50249+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50250+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50251+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50252+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50253+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50254+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50255+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50256+4 4 4 4 4 4
50257+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50258+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50259+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50260+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50261+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50262+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50263+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50264+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50265+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50266+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50267+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50268+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50269+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50270+4 4 4 4 4 4
50271+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50272+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50273+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50274+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50275+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
50276+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
50277+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50278+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50279+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50280+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
50281+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
50282+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
50283+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50284+4 4 4 4 4 4
50285+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50286+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50287+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50288+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50289+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
50290+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
50291+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50292+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50293+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50294+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
50295+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
50296+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
50297+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50298+4 4 4 4 4 4
50299+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50300+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50301+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50302+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50303+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
50304+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
50305+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
50306+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50307+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50308+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
50309+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
50310+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
50311+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
50312+4 4 4 4 4 4
50313+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50314+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50315+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50316+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
50317+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
50318+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
50319+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
50320+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50321+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
50322+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
50323+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
50324+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
50325+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
50326+4 4 4 4 4 4
50327+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50328+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50329+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50330+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
50331+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
50332+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
50333+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
50334+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
50335+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
50336+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
50337+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
50338+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
50339+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
50340+4 4 4 4 4 4
50341+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50342+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50343+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
50344+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
50345+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
50346+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
50347+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
50348+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
50349+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
50350+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
50351+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
50352+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
50353+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
50354+4 4 4 4 4 4
50355+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50356+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50357+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
50358+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
50359+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
50360+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
50361+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
50362+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
50363+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
50364+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
50365+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
50366+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
50367+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
50368+4 4 4 4 4 4
50369+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50370+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50371+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
50372+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
50373+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
50374+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
50375+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
50376+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
50377+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
50378+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
50379+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
50380+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
50381+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
50382+4 4 4 4 4 4
50383+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50384+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50385+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
50386+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
50387+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
50388+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
50389+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
50390+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
50391+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
50392+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
50393+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
50394+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
50395+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
50396+4 4 4 4 4 4
50397+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50398+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50399+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
50400+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
50401+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
50402+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
50403+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
50404+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
50405+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
50406+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
50407+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
50408+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
50409+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
50410+4 4 4 4 4 4
50411+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50412+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
50413+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
50414+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
50415+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
50416+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
50417+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
50418+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
50419+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
50420+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
50421+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
50422+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
50423+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
50424+4 4 4 4 4 4
50425+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50426+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
50427+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
50428+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
50429+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
50430+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
50431+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
50432+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
50433+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
50434+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
50435+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
50436+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
50437+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
50438+0 0 0 4 4 4
50439+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
50440+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
50441+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
50442+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
50443+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
50444+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
50445+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
50446+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
50447+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
50448+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
50449+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
50450+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
50451+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
50452+2 0 0 0 0 0
50453+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
50454+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
50455+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
50456+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
50457+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
50458+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
50459+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
50460+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
50461+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
50462+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
50463+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
50464+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
50465+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
50466+37 38 37 0 0 0
50467+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
50468+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
50469+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
50470+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
50471+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
50472+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
50473+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
50474+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
50475+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
50476+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
50477+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
50478+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
50479+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
50480+85 115 134 4 0 0
50481+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
50482+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
50483+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
50484+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
50485+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
50486+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
50487+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
50488+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
50489+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
50490+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
50491+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
50492+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
50493+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
50494+60 73 81 4 0 0
50495+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
50496+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
50497+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
50498+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
50499+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
50500+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
50501+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
50502+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
50503+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
50504+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
50505+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
50506+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
50507+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
50508+16 19 21 4 0 0
50509+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
50510+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
50511+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
50512+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
50513+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
50514+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
50515+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
50516+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
50517+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
50518+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
50519+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
50520+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
50521+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
50522+4 0 0 4 3 3
50523+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
50524+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
50525+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
50526+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
50527+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
50528+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
50529+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
50530+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
50531+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
50532+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
50533+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
50534+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
50535+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
50536+3 2 2 4 4 4
50537+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
50538+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
50539+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
50540+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
50541+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
50542+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
50543+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50544+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
50545+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
50546+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
50547+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
50548+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
50549+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
50550+4 4 4 4 4 4
50551+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
50552+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
50553+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
50554+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
50555+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
50556+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
50557+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
50558+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
50559+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
50560+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
50561+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
50562+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
50563+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
50564+4 4 4 4 4 4
50565+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
50566+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
50567+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
50568+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
50569+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
50570+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
50571+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
50572+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
50573+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
50574+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
50575+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
50576+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
50577+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
50578+5 5 5 5 5 5
50579+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
50580+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
50581+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
50582+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
50583+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
50584+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
50585+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
50586+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
50587+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
50588+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
50589+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
50590+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
50591+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
50592+5 5 5 4 4 4
50593+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
50594+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
50595+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
50596+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
50597+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
50598+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
50599+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
50600+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
50601+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
50602+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
50603+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
50604+4 0 0 4 0 0 5 5 5 5 5 5 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
50607+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
50608+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
50609+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
50610+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
50611+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
50612+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
50613+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
50614+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
50615+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
50616+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
50617+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
50618+3 3 3 5 5 5 6 6 6 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
50621+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
50622+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
50623+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
50624+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
50625+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
50626+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
50627+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
50628+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
50629+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
50630+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
50631+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 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
50635+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
50636+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
50637+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
50638+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
50639+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
50640+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
50641+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
50642+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
50643+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
50644+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
50645+6 6 6 4 0 0 4 0 0 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
50649+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
50650+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
50651+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
50652+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
50653+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
50654+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
50655+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
50656+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
50657+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
50658+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
50659+4 0 0 4 3 3 5 5 5 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
50663+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
50664+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
50665+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
50666+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
50667+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
50668+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
50669+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
50670+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
50671+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
50672+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
50673+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
50674+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50675+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50676+4 4 4 4 4 4
50677+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
50678+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
50679+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
50680+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
50681+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
50682+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
50683+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
50684+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
50685+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
50686+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
50687+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
50688+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50689+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50690+4 4 4 4 4 4
50691+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
50692+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
50693+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
50694+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
50695+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
50696+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
50697+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
50698+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
50699+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
50700+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
50701+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50702+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50703+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50704+4 4 4 4 4 4
50705+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
50706+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
50707+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
50708+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
50709+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
50710+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
50711+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
50712+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
50713+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
50714+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
50715+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50716+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50717+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50718+4 4 4 4 4 4
50719+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
50720+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
50721+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
50722+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
50723+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
50724+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
50725+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
50726+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
50727+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
50728+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
50729+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50730+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50731+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50732+4 4 4 4 4 4
50733+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
50734+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
50735+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
50736+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
50737+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
50738+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
50739+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
50740+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
50741+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
50742+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
50743+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50744+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50745+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50746+4 4 4 4 4 4
50747+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
50748+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
50749+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
50750+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
50751+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
50752+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
50753+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
50754+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
50755+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
50756+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
50757+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50758+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50759+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50760+4 4 4 4 4 4
50761+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
50762+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
50763+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
50764+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
50765+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
50766+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
50767+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
50768+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
50769+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
50770+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
50771+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50772+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50773+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50774+4 4 4 4 4 4
50775+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
50776+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
50777+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
50778+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
50779+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
50780+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
50781+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
50782+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
50783+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
50784+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
50785+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50786+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50787+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50788+4 4 4 4 4 4
50789+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
50790+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
50791+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
50792+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
50793+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
50794+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
50795+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
50796+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
50797+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
50798+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
50799+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50800+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50801+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50802+4 4 4 4 4 4
50803+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
50804+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
50805+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
50806+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
50807+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
50808+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
50809+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
50810+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
50811+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
50812+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
50813+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50814+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50815+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50816+4 4 4 4 4 4
50817+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
50818+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
50819+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
50820+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
50821+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
50822+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
50823+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
50824+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
50825+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
50826+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
50827+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50828+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50829+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50830+4 4 4 4 4 4
50831+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
50832+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
50833+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
50834+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
50835+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
50836+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
50837+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
50838+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
50839+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
50840+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
50841+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50842+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50843+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50844+4 4 4 4 4 4
50845+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
50846+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
50847+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
50848+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
50849+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
50850+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
50851+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
50852+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
50853+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
50854+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
50855+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50856+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50857+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50858+4 4 4 4 4 4
50859+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
50860+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
50861+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
50862+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
50863+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
50864+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
50865+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
50866+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
50867+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
50868+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
50869+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50870+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50871+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50872+4 4 4 4 4 4
50873+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
50874+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
50875+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
50876+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
50877+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
50878+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
50879+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
50880+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
50881+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
50882+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
50883+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50884+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50885+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50886+4 4 4 4 4 4
50887+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
50888+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
50889+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
50890+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
50891+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
50892+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
50893+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
50894+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
50895+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
50896+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
50897+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50898+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50899+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50900+4 4 4 4 4 4
50901+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
50902+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
50903+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
50904+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
50905+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
50906+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
50907+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
50908+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
50909+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
50910+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
50911+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50912+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50913+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50914+4 4 4 4 4 4
50915+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
50916+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
50917+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
50918+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
50919+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
50920+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
50921+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
50922+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
50923+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
50924+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
50925+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50926+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50927+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50928+4 4 4 4 4 4
50929+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
50930+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
50931+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
50932+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
50933+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
50934+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
50935+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
50936+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
50937+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
50938+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
50939+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50940+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50941+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50942+4 4 4 4 4 4
50943+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
50944+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
50945+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
50946+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
50947+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
50948+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
50949+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
50950+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
50951+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
50952+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
50953+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
50954+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50955+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50956+4 4 4 4 4 4
50957+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
50958+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
50959+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
50960+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
50961+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
50962+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
50963+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
50964+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
50965+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
50966+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
50967+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50968+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50969+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50970+4 4 4 4 4 4
50971+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
50972+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
50973+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
50974+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
50975+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
50976+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
50977+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50978+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
50979+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
50980+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
50981+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
50982+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50983+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50984+4 4 4 4 4 4
50985+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
50986+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
50987+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
50988+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
50989+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
50990+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
50991+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
50992+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
50993+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
50994+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
50995+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50996+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50997+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50998+4 4 4 4 4 4
50999+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
51000+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
51001+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
51002+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
51003+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
51004+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
51005+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
51006+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
51007+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
51008+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
51009+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51010+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51011+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51012+4 4 4 4 4 4
51013+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
51014+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
51015+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
51016+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
51017+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
51018+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
51019+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
51020+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
51021+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
51022+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
51023+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51024+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51025+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51026+4 4 4 4 4 4
51027+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
51028+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
51029+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
51030+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
51031+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
51032+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
51033+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
51034+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
51035+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
51036+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
51037+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51038+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51039+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51040+4 4 4 4 4 4
51041+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
51042+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
51043+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
51044+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
51045+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
51046+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
51047+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
51048+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
51049+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
51050+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
51051+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51052+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51053+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51054+4 4 4 4 4 4
51055+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
51056+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
51057+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
51058+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
51059+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
51060+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
51061+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
51062+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
51063+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
51064+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51065+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51066+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51067+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51068+4 4 4 4 4 4
51069+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
51070+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
51071+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
51072+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
51073+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
51074+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
51075+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
51076+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
51077+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
51078+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51079+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51080+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51081+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51082+4 4 4 4 4 4
51083+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
51084+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
51085+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
51086+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
51087+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
51088+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
51089+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
51090+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
51091+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51092+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51093+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51094+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51095+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51096+4 4 4 4 4 4
51097+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
51098+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
51099+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
51100+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
51101+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
51102+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
51103+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
51104+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
51105+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51106+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51107+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51108+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51109+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51110+4 4 4 4 4 4
51111+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
51112+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
51113+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
51114+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
51115+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
51116+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
51117+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
51118+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
51119+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51120+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51121+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51122+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51123+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51124+4 4 4 4 4 4
51125+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
51126+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
51127+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
51128+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
51129+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
51130+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
51131+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
51132+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
51133+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51134+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51135+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51136+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51137+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51138+4 4 4 4 4 4
51139+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51140+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
51141+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
51142+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
51143+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
51144+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
51145+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
51146+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
51147+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51148+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51149+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51150+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51151+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51152+4 4 4 4 4 4
51153+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51154+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
51155+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
51156+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
51157+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
51158+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
51159+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
51160+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
51161+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51162+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51163+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51164+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51165+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51166+4 4 4 4 4 4
51167+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51168+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51169+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
51170+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
51171+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
51172+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
51173+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
51174+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
51175+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51176+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51177+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51178+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51179+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51180+4 4 4 4 4 4
51181+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51182+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51183+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
51184+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
51185+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
51186+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
51187+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
51188+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51189+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51190+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51191+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51192+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51193+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51194+4 4 4 4 4 4
51195+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51196+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51197+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51198+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
51199+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
51200+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
51201+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
51202+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51203+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51204+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51205+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51206+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51207+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51208+4 4 4 4 4 4
51209+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51210+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51211+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51212+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
51213+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
51214+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
51215+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
51216+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51217+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51218+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51219+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51220+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51221+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51222+4 4 4 4 4 4
51223+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51224+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51225+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51226+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
51227+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
51228+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
51229+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
51230+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51231+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51232+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51233+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51234+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51235+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51236+4 4 4 4 4 4
51237+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51238+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51239+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51240+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
51241+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
51242+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
51243+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51244+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51245+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51246+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51247+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51248+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51249+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51250+4 4 4 4 4 4
51251+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51252+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51253+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51254+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51255+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
51256+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
51257+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
51258+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51259+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51260+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51261+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51262+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51263+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51264+4 4 4 4 4 4
51265+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51266+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51267+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51268+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51269+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
51270+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
51271+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51272+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51273+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51274+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51275+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51276+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51277+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51278+4 4 4 4 4 4
51279+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51280+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51281+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51282+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51283+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
51284+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
51285+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51286+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51287+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51288+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51289+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51290+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51291+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51292+4 4 4 4 4 4
51293+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51294+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51295+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51296+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51297+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
51298+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
51299+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51300+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51301+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51302+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51303+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51304+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51305+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51306+4 4 4 4 4 4
51307diff --git a/drivers/video/mb862xx/mb862xxfb_accel.c b/drivers/video/mb862xx/mb862xxfb_accel.c
51308index fe92eed..106e085 100644
51309--- a/drivers/video/mb862xx/mb862xxfb_accel.c
51310+++ b/drivers/video/mb862xx/mb862xxfb_accel.c
51311@@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
51312 struct mb862xxfb_par *par = info->par;
51313
51314 if (info->var.bits_per_pixel == 32) {
51315- info->fbops->fb_fillrect = cfb_fillrect;
51316- info->fbops->fb_copyarea = cfb_copyarea;
51317- info->fbops->fb_imageblit = cfb_imageblit;
51318+ pax_open_kernel();
51319+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
51320+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
51321+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
51322+ pax_close_kernel();
51323 } else {
51324 outreg(disp, GC_L0EM, 3);
51325- info->fbops->fb_fillrect = mb86290fb_fillrect;
51326- info->fbops->fb_copyarea = mb86290fb_copyarea;
51327- info->fbops->fb_imageblit = mb86290fb_imageblit;
51328+ pax_open_kernel();
51329+ *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
51330+ *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
51331+ *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
51332+ pax_close_kernel();
51333 }
51334 outreg(draw, GDC_REG_DRAW_BASE, 0);
51335 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
51336diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
51337index ff22871..b129bed 100644
51338--- a/drivers/video/nvidia/nvidia.c
51339+++ b/drivers/video/nvidia/nvidia.c
51340@@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
51341 info->fix.line_length = (info->var.xres_virtual *
51342 info->var.bits_per_pixel) >> 3;
51343 if (info->var.accel_flags) {
51344- info->fbops->fb_imageblit = nvidiafb_imageblit;
51345- info->fbops->fb_fillrect = nvidiafb_fillrect;
51346- info->fbops->fb_copyarea = nvidiafb_copyarea;
51347- info->fbops->fb_sync = nvidiafb_sync;
51348+ pax_open_kernel();
51349+ *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
51350+ *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
51351+ *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
51352+ *(void **)&info->fbops->fb_sync = nvidiafb_sync;
51353+ pax_close_kernel();
51354 info->pixmap.scan_align = 4;
51355 info->flags &= ~FBINFO_HWACCEL_DISABLED;
51356 info->flags |= FBINFO_READS_FAST;
51357 NVResetGraphics(info);
51358 } else {
51359- info->fbops->fb_imageblit = cfb_imageblit;
51360- info->fbops->fb_fillrect = cfb_fillrect;
51361- info->fbops->fb_copyarea = cfb_copyarea;
51362- info->fbops->fb_sync = NULL;
51363+ pax_open_kernel();
51364+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
51365+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
51366+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
51367+ *(void **)&info->fbops->fb_sync = NULL;
51368+ pax_close_kernel();
51369 info->pixmap.scan_align = 1;
51370 info->flags |= FBINFO_HWACCEL_DISABLED;
51371 info->flags &= ~FBINFO_READS_FAST;
51372@@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
51373 info->pixmap.size = 8 * 1024;
51374 info->pixmap.flags = FB_PIXMAP_SYSTEM;
51375
51376- if (!hwcur)
51377- info->fbops->fb_cursor = NULL;
51378+ if (!hwcur) {
51379+ pax_open_kernel();
51380+ *(void **)&info->fbops->fb_cursor = NULL;
51381+ pax_close_kernel();
51382+ }
51383
51384 info->var.accel_flags = (!noaccel);
51385
51386diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
51387index 05c2dc3..ea1f391 100644
51388--- a/drivers/video/s1d13xxxfb.c
51389+++ b/drivers/video/s1d13xxxfb.c
51390@@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
51391
51392 switch(prod_id) {
51393 case S1D13506_PROD_ID: /* activate acceleration */
51394- s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
51395- s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
51396+ pax_open_kernel();
51397+ *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
51398+ *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
51399+ pax_close_kernel();
51400 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
51401 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
51402 break;
51403diff --git a/drivers/video/smscufx.c b/drivers/video/smscufx.c
51404index e188ada..aac63c8 100644
51405--- a/drivers/video/smscufx.c
51406+++ b/drivers/video/smscufx.c
51407@@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
51408 fb_deferred_io_cleanup(info);
51409 kfree(info->fbdefio);
51410 info->fbdefio = NULL;
51411- info->fbops->fb_mmap = ufx_ops_mmap;
51412+ pax_open_kernel();
51413+ *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
51414+ pax_close_kernel();
51415 }
51416
51417 pr_debug("released /dev/fb%d user=%d count=%d",
51418diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
51419index d2e5bc3..4cb05d1 100644
51420--- a/drivers/video/udlfb.c
51421+++ b/drivers/video/udlfb.c
51422@@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
51423 dlfb_urb_completion(urb);
51424
51425 error:
51426- atomic_add(bytes_sent, &dev->bytes_sent);
51427- atomic_add(bytes_identical, &dev->bytes_identical);
51428- atomic_add(width*height*2, &dev->bytes_rendered);
51429+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
51430+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
51431+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
51432 end_cycles = get_cycles();
51433- atomic_add(((unsigned int) ((end_cycles - start_cycles)
51434+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
51435 >> 10)), /* Kcycles */
51436 &dev->cpu_kcycles_used);
51437
51438@@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
51439 dlfb_urb_completion(urb);
51440
51441 error:
51442- atomic_add(bytes_sent, &dev->bytes_sent);
51443- atomic_add(bytes_identical, &dev->bytes_identical);
51444- atomic_add(bytes_rendered, &dev->bytes_rendered);
51445+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
51446+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
51447+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
51448 end_cycles = get_cycles();
51449- atomic_add(((unsigned int) ((end_cycles - start_cycles)
51450+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
51451 >> 10)), /* Kcycles */
51452 &dev->cpu_kcycles_used);
51453 }
51454@@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
51455 fb_deferred_io_cleanup(info);
51456 kfree(info->fbdefio);
51457 info->fbdefio = NULL;
51458- info->fbops->fb_mmap = dlfb_ops_mmap;
51459+ pax_open_kernel();
51460+ *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
51461+ pax_close_kernel();
51462 }
51463
51464 pr_warn("released /dev/fb%d user=%d count=%d\n",
51465@@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
51466 struct fb_info *fb_info = dev_get_drvdata(fbdev);
51467 struct dlfb_data *dev = fb_info->par;
51468 return snprintf(buf, PAGE_SIZE, "%u\n",
51469- atomic_read(&dev->bytes_rendered));
51470+ atomic_read_unchecked(&dev->bytes_rendered));
51471 }
51472
51473 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
51474@@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
51475 struct fb_info *fb_info = dev_get_drvdata(fbdev);
51476 struct dlfb_data *dev = fb_info->par;
51477 return snprintf(buf, PAGE_SIZE, "%u\n",
51478- atomic_read(&dev->bytes_identical));
51479+ atomic_read_unchecked(&dev->bytes_identical));
51480 }
51481
51482 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
51483@@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
51484 struct fb_info *fb_info = dev_get_drvdata(fbdev);
51485 struct dlfb_data *dev = fb_info->par;
51486 return snprintf(buf, PAGE_SIZE, "%u\n",
51487- atomic_read(&dev->bytes_sent));
51488+ atomic_read_unchecked(&dev->bytes_sent));
51489 }
51490
51491 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
51492@@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
51493 struct fb_info *fb_info = dev_get_drvdata(fbdev);
51494 struct dlfb_data *dev = fb_info->par;
51495 return snprintf(buf, PAGE_SIZE, "%u\n",
51496- atomic_read(&dev->cpu_kcycles_used));
51497+ atomic_read_unchecked(&dev->cpu_kcycles_used));
51498 }
51499
51500 static ssize_t edid_show(
51501@@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
51502 struct fb_info *fb_info = dev_get_drvdata(fbdev);
51503 struct dlfb_data *dev = fb_info->par;
51504
51505- atomic_set(&dev->bytes_rendered, 0);
51506- atomic_set(&dev->bytes_identical, 0);
51507- atomic_set(&dev->bytes_sent, 0);
51508- atomic_set(&dev->cpu_kcycles_used, 0);
51509+ atomic_set_unchecked(&dev->bytes_rendered, 0);
51510+ atomic_set_unchecked(&dev->bytes_identical, 0);
51511+ atomic_set_unchecked(&dev->bytes_sent, 0);
51512+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
51513
51514 return count;
51515 }
51516diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
51517index 7aec6f3..e3b2d55 100644
51518--- a/drivers/video/uvesafb.c
51519+++ b/drivers/video/uvesafb.c
51520@@ -19,6 +19,7 @@
51521 #include <linux/io.h>
51522 #include <linux/mutex.h>
51523 #include <linux/slab.h>
51524+#include <linux/moduleloader.h>
51525 #include <video/edid.h>
51526 #include <video/uvesafb.h>
51527 #ifdef CONFIG_X86
51528@@ -566,10 +567,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
51529 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
51530 par->pmi_setpal = par->ypan = 0;
51531 } else {
51532+
51533+#ifdef CONFIG_PAX_KERNEXEC
51534+#ifdef CONFIG_MODULES
51535+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
51536+#endif
51537+ if (!par->pmi_code) {
51538+ par->pmi_setpal = par->ypan = 0;
51539+ return 0;
51540+ }
51541+#endif
51542+
51543 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
51544 + task->t.regs.edi);
51545+
51546+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
51547+ pax_open_kernel();
51548+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
51549+ pax_close_kernel();
51550+
51551+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
51552+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
51553+#else
51554 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
51555 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
51556+#endif
51557+
51558 printk(KERN_INFO "uvesafb: protected mode interface info at "
51559 "%04x:%04x\n",
51560 (u16)task->t.regs.es, (u16)task->t.regs.edi);
51561@@ -814,13 +837,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
51562 par->ypan = ypan;
51563
51564 if (par->pmi_setpal || par->ypan) {
51565+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
51566 if (__supported_pte_mask & _PAGE_NX) {
51567 par->pmi_setpal = par->ypan = 0;
51568 printk(KERN_WARNING "uvesafb: NX protection is active, "
51569 "better not use the PMI.\n");
51570- } else {
51571+ } else
51572+#endif
51573 uvesafb_vbe_getpmi(task, par);
51574- }
51575 }
51576 #else
51577 /* The protected mode interface is not available on non-x86. */
51578@@ -1454,8 +1478,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
51579 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
51580
51581 /* Disable blanking if the user requested so. */
51582- if (!blank)
51583- info->fbops->fb_blank = NULL;
51584+ if (!blank) {
51585+ pax_open_kernel();
51586+ *(void **)&info->fbops->fb_blank = NULL;
51587+ pax_close_kernel();
51588+ }
51589
51590 /*
51591 * Find out how much IO memory is required for the mode with
51592@@ -1531,8 +1558,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
51593 info->flags = FBINFO_FLAG_DEFAULT |
51594 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
51595
51596- if (!par->ypan)
51597- info->fbops->fb_pan_display = NULL;
51598+ if (!par->ypan) {
51599+ pax_open_kernel();
51600+ *(void **)&info->fbops->fb_pan_display = NULL;
51601+ pax_close_kernel();
51602+ }
51603 }
51604
51605 static void uvesafb_init_mtrr(struct fb_info *info)
51606@@ -1796,6 +1826,11 @@ out:
51607 if (par->vbe_modes)
51608 kfree(par->vbe_modes);
51609
51610+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
51611+ if (par->pmi_code)
51612+ module_free_exec(NULL, par->pmi_code);
51613+#endif
51614+
51615 framebuffer_release(info);
51616 return err;
51617 }
51618@@ -1823,6 +1858,12 @@ static int uvesafb_remove(struct platform_device *dev)
51619 kfree(par->vbe_state_orig);
51620 if (par->vbe_state_saved)
51621 kfree(par->vbe_state_saved);
51622+
51623+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
51624+ if (par->pmi_code)
51625+ module_free_exec(NULL, par->pmi_code);
51626+#endif
51627+
51628 }
51629
51630 framebuffer_release(info);
51631diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
51632index 501b340..d80aa17 100644
51633--- a/drivers/video/vesafb.c
51634+++ b/drivers/video/vesafb.c
51635@@ -9,6 +9,7 @@
51636 */
51637
51638 #include <linux/module.h>
51639+#include <linux/moduleloader.h>
51640 #include <linux/kernel.h>
51641 #include <linux/errno.h>
51642 #include <linux/string.h>
51643@@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
51644 static int vram_total __initdata; /* Set total amount of memory */
51645 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
51646 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
51647-static void (*pmi_start)(void) __read_mostly;
51648-static void (*pmi_pal) (void) __read_mostly;
51649+static void (*pmi_start)(void) __read_only;
51650+static void (*pmi_pal) (void) __read_only;
51651 static int depth __read_mostly;
51652 static int vga_compat __read_mostly;
51653 /* --------------------------------------------------------------------- */
51654@@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
51655 unsigned int size_vmode;
51656 unsigned int size_remap;
51657 unsigned int size_total;
51658+ void *pmi_code = NULL;
51659
51660 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
51661 return -ENODEV;
51662@@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
51663 size_remap = size_total;
51664 vesafb_fix.smem_len = size_remap;
51665
51666-#ifndef __i386__
51667- screen_info.vesapm_seg = 0;
51668-#endif
51669-
51670 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
51671 printk(KERN_WARNING
51672 "vesafb: cannot reserve video memory at 0x%lx\n",
51673@@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
51674 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
51675 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
51676
51677+#ifdef __i386__
51678+
51679+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
51680+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
51681+ if (!pmi_code)
51682+#elif !defined(CONFIG_PAX_KERNEXEC)
51683+ if (0)
51684+#endif
51685+
51686+#endif
51687+ screen_info.vesapm_seg = 0;
51688+
51689 if (screen_info.vesapm_seg) {
51690- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
51691- screen_info.vesapm_seg,screen_info.vesapm_off);
51692+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
51693+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
51694 }
51695
51696 if (screen_info.vesapm_seg < 0xc000)
51697@@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
51698
51699 if (ypan || pmi_setpal) {
51700 unsigned short *pmi_base;
51701+
51702 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
51703- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
51704- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
51705+
51706+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
51707+ pax_open_kernel();
51708+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
51709+#else
51710+ pmi_code = pmi_base;
51711+#endif
51712+
51713+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
51714+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
51715+
51716+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
51717+ pmi_start = ktva_ktla(pmi_start);
51718+ pmi_pal = ktva_ktla(pmi_pal);
51719+ pax_close_kernel();
51720+#endif
51721+
51722 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
51723 if (pmi_base[3]) {
51724 printk(KERN_INFO "vesafb: pmi: ports = ");
51725@@ -472,8 +498,11 @@ static int __init vesafb_probe(struct platform_device *dev)
51726 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
51727 (ypan ? FBINFO_HWACCEL_YPAN : 0);
51728
51729- if (!ypan)
51730- info->fbops->fb_pan_display = NULL;
51731+ if (!ypan) {
51732+ pax_open_kernel();
51733+ *(void **)&info->fbops->fb_pan_display = NULL;
51734+ pax_close_kernel();
51735+ }
51736
51737 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
51738 err = -ENOMEM;
51739@@ -488,6 +517,11 @@ static int __init vesafb_probe(struct platform_device *dev)
51740 info->node, info->fix.id);
51741 return 0;
51742 err:
51743+
51744+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
51745+ module_free_exec(NULL, pmi_code);
51746+#endif
51747+
51748 if (info->screen_base)
51749 iounmap(info->screen_base);
51750 framebuffer_release(info);
51751diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
51752index 88714ae..16c2e11 100644
51753--- a/drivers/video/via/via_clock.h
51754+++ b/drivers/video/via/via_clock.h
51755@@ -56,7 +56,7 @@ struct via_clock {
51756
51757 void (*set_engine_pll_state)(u8 state);
51758 void (*set_engine_pll)(struct via_pll_config config);
51759-};
51760+} __no_const;
51761
51762
51763 static inline u32 get_pll_internal_frequency(u32 ref_freq,
51764diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
51765index fef20db..d28b1ab 100644
51766--- a/drivers/xen/xenfs/xenstored.c
51767+++ b/drivers/xen/xenfs/xenstored.c
51768@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
51769 static int xsd_kva_open(struct inode *inode, struct file *file)
51770 {
51771 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
51772+#ifdef CONFIG_GRKERNSEC_HIDESYM
51773+ NULL);
51774+#else
51775 xen_store_interface);
51776+#endif
51777+
51778 if (!file->private_data)
51779 return -ENOMEM;
51780 return 0;
51781diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
51782index 9ff073f..05cef23 100644
51783--- a/fs/9p/vfs_addr.c
51784+++ b/fs/9p/vfs_addr.c
51785@@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
51786
51787 retval = v9fs_file_write_internal(inode,
51788 v9inode->writeback_fid,
51789- (__force const char __user *)buffer,
51790+ (const char __force_user *)buffer,
51791 len, &offset, 0);
51792 if (retval > 0)
51793 retval = 0;
51794diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
51795index 25b018e..b941525 100644
51796--- a/fs/9p/vfs_inode.c
51797+++ b/fs/9p/vfs_inode.c
51798@@ -1312,7 +1312,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
51799 void
51800 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
51801 {
51802- char *s = nd_get_link(nd);
51803+ const char *s = nd_get_link(nd);
51804
51805 p9_debug(P9_DEBUG_VFS, " %s %s\n",
51806 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
51807diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
51808index 370b24c..ff0be7b 100644
51809--- a/fs/Kconfig.binfmt
51810+++ b/fs/Kconfig.binfmt
51811@@ -103,7 +103,7 @@ config HAVE_AOUT
51812
51813 config BINFMT_AOUT
51814 tristate "Kernel support for a.out and ECOFF binaries"
51815- depends on HAVE_AOUT
51816+ depends on HAVE_AOUT && BROKEN
51817 ---help---
51818 A.out (Assembler.OUTput) is a set of formats for libraries and
51819 executables used in the earliest versions of UNIX. Linux used
51820diff --git a/fs/afs/inode.c b/fs/afs/inode.c
51821index 789bc25..fafaeea 100644
51822--- a/fs/afs/inode.c
51823+++ b/fs/afs/inode.c
51824@@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
51825 struct afs_vnode *vnode;
51826 struct super_block *sb;
51827 struct inode *inode;
51828- static atomic_t afs_autocell_ino;
51829+ static atomic_unchecked_t afs_autocell_ino;
51830
51831 _enter("{%x:%u},%*.*s,",
51832 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
51833@@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
51834 data.fid.unique = 0;
51835 data.fid.vnode = 0;
51836
51837- inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
51838+ inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
51839 afs_iget5_autocell_test, afs_iget5_set,
51840 &data);
51841 if (!inode) {
51842diff --git a/fs/aio.c b/fs/aio.c
51843index 9b5ca11..c530886 100644
51844--- a/fs/aio.c
51845+++ b/fs/aio.c
51846@@ -162,7 +162,7 @@ static int aio_setup_ring(struct kioctx *ctx)
51847 size += sizeof(struct io_event) * nr_events;
51848 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
51849
51850- if (nr_pages < 0)
51851+ if (nr_pages <= 0)
51852 return -EINVAL;
51853
51854 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
51855@@ -952,6 +952,7 @@ static ssize_t aio_rw_vect_retry(struct kiocb *iocb, int rw, aio_rw_op *rw_op)
51856 static ssize_t aio_setup_vectored_rw(int rw, struct kiocb *kiocb, bool compat)
51857 {
51858 ssize_t ret;
51859+ struct iovec iovstack;
51860
51861 kiocb->ki_nr_segs = kiocb->ki_nbytes;
51862
51863@@ -959,17 +960,22 @@ static ssize_t aio_setup_vectored_rw(int rw, struct kiocb *kiocb, bool compat)
51864 if (compat)
51865 ret = compat_rw_copy_check_uvector(rw,
51866 (struct compat_iovec __user *)kiocb->ki_buf,
51867- kiocb->ki_nr_segs, 1, &kiocb->ki_inline_vec,
51868+ kiocb->ki_nr_segs, 1, &iovstack,
51869 &kiocb->ki_iovec);
51870 else
51871 #endif
51872 ret = rw_copy_check_uvector(rw,
51873 (struct iovec __user *)kiocb->ki_buf,
51874- kiocb->ki_nr_segs, 1, &kiocb->ki_inline_vec,
51875+ kiocb->ki_nr_segs, 1, &iovstack,
51876 &kiocb->ki_iovec);
51877 if (ret < 0)
51878 return ret;
51879
51880+ if (kiocb->ki_iovec == &iovstack) {
51881+ kiocb->ki_inline_vec = iovstack;
51882+ kiocb->ki_iovec = &kiocb->ki_inline_vec;
51883+ }
51884+
51885 /* ki_nbytes now reflect bytes instead of segs */
51886 kiocb->ki_nbytes = ret;
51887 return 0;
51888diff --git a/fs/attr.c b/fs/attr.c
51889index 1449adb..a2038c2 100644
51890--- a/fs/attr.c
51891+++ b/fs/attr.c
51892@@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
51893 unsigned long limit;
51894
51895 limit = rlimit(RLIMIT_FSIZE);
51896+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
51897 if (limit != RLIM_INFINITY && offset > limit)
51898 goto out_sig;
51899 if (offset > inode->i_sb->s_maxbytes)
51900diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
51901index 3db70da..7aeec5b 100644
51902--- a/fs/autofs4/waitq.c
51903+++ b/fs/autofs4/waitq.c
51904@@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
51905 {
51906 unsigned long sigpipe, flags;
51907 mm_segment_t fs;
51908- const char *data = (const char *)addr;
51909+ const char __user *data = (const char __force_user *)addr;
51910 ssize_t wr = 0;
51911
51912 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
51913@@ -346,6 +346,10 @@ static int validate_request(struct autofs_wait_queue **wait,
51914 return 1;
51915 }
51916
51917+#ifdef CONFIG_GRKERNSEC_HIDESYM
51918+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
51919+#endif
51920+
51921 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
51922 enum autofs_notify notify)
51923 {
51924@@ -379,7 +383,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
51925
51926 /* If this is a direct mount request create a dummy name */
51927 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
51928+#ifdef CONFIG_GRKERNSEC_HIDESYM
51929+ /* this name does get written to userland via autofs4_write() */
51930+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
51931+#else
51932 qstr.len = sprintf(name, "%p", dentry);
51933+#endif
51934 else {
51935 qstr.len = autofs4_getpath(sbi, dentry, &name);
51936 if (!qstr.len) {
51937diff --git a/fs/befs/endian.h b/fs/befs/endian.h
51938index 2722387..c8dd2a7 100644
51939--- a/fs/befs/endian.h
51940+++ b/fs/befs/endian.h
51941@@ -11,7 +11,7 @@
51942
51943 #include <asm/byteorder.h>
51944
51945-static inline u64
51946+static inline u64 __intentional_overflow(-1)
51947 fs64_to_cpu(const struct super_block *sb, fs64 n)
51948 {
51949 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
51950@@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
51951 return (__force fs64)cpu_to_be64(n);
51952 }
51953
51954-static inline u32
51955+static inline u32 __intentional_overflow(-1)
51956 fs32_to_cpu(const struct super_block *sb, fs32 n)
51957 {
51958 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
51959diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
51960index e9c75e2..1baece1 100644
51961--- a/fs/befs/linuxvfs.c
51962+++ b/fs/befs/linuxvfs.c
51963@@ -514,7 +514,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
51964 {
51965 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
51966 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
51967- char *link = nd_get_link(nd);
51968+ const char *link = nd_get_link(nd);
51969 if (!IS_ERR(link))
51970 kfree(link);
51971 }
51972diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
51973index 89dec7f..361b0d75 100644
51974--- a/fs/binfmt_aout.c
51975+++ b/fs/binfmt_aout.c
51976@@ -16,6 +16,7 @@
51977 #include <linux/string.h>
51978 #include <linux/fs.h>
51979 #include <linux/file.h>
51980+#include <linux/security.h>
51981 #include <linux/stat.h>
51982 #include <linux/fcntl.h>
51983 #include <linux/ptrace.h>
51984@@ -59,6 +60,8 @@ static int aout_core_dump(struct coredump_params *cprm)
51985 #endif
51986 # define START_STACK(u) ((void __user *)u.start_stack)
51987
51988+ memset(&dump, 0, sizeof(dump));
51989+
51990 fs = get_fs();
51991 set_fs(KERNEL_DS);
51992 has_dumped = 1;
51993@@ -69,10 +72,12 @@ static int aout_core_dump(struct coredump_params *cprm)
51994
51995 /* If the size of the dump file exceeds the rlimit, then see what would happen
51996 if we wrote the stack, but not the data area. */
51997+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
51998 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
51999 dump.u_dsize = 0;
52000
52001 /* Make sure we have enough room to write the stack and data areas. */
52002+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
52003 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
52004 dump.u_ssize = 0;
52005
52006@@ -233,6 +238,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
52007 rlim = rlimit(RLIMIT_DATA);
52008 if (rlim >= RLIM_INFINITY)
52009 rlim = ~0;
52010+
52011+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
52012 if (ex.a_data + ex.a_bss > rlim)
52013 return -ENOMEM;
52014
52015@@ -265,6 +272,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
52016
52017 install_exec_creds(bprm);
52018
52019+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
52020+ current->mm->pax_flags = 0UL;
52021+#endif
52022+
52023+#ifdef CONFIG_PAX_PAGEEXEC
52024+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
52025+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
52026+
52027+#ifdef CONFIG_PAX_EMUTRAMP
52028+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
52029+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
52030+#endif
52031+
52032+#ifdef CONFIG_PAX_MPROTECT
52033+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
52034+ current->mm->pax_flags |= MF_PAX_MPROTECT;
52035+#endif
52036+
52037+ }
52038+#endif
52039+
52040 if (N_MAGIC(ex) == OMAGIC) {
52041 unsigned long text_addr, map_size;
52042 loff_t pos;
52043@@ -322,7 +350,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
52044 }
52045
52046 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
52047- PROT_READ | PROT_WRITE | PROT_EXEC,
52048+ PROT_READ | PROT_WRITE,
52049 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
52050 fd_offset + ex.a_text);
52051 if (error != N_DATADDR(ex)) {
52052diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
52053index 100edcc..244db37 100644
52054--- a/fs/binfmt_elf.c
52055+++ b/fs/binfmt_elf.c
52056@@ -34,6 +34,7 @@
52057 #include <linux/utsname.h>
52058 #include <linux/coredump.h>
52059 #include <linux/sched.h>
52060+#include <linux/xattr.h>
52061 #include <asm/uaccess.h>
52062 #include <asm/param.h>
52063 #include <asm/page.h>
52064@@ -60,6 +61,14 @@ static int elf_core_dump(struct coredump_params *cprm);
52065 #define elf_core_dump NULL
52066 #endif
52067
52068+#ifdef CONFIG_PAX_MPROTECT
52069+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
52070+#endif
52071+
52072+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
52073+static void elf_handle_mmap(struct file *file);
52074+#endif
52075+
52076 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
52077 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
52078 #else
52079@@ -79,6 +88,15 @@ static struct linux_binfmt elf_format = {
52080 .load_binary = load_elf_binary,
52081 .load_shlib = load_elf_library,
52082 .core_dump = elf_core_dump,
52083+
52084+#ifdef CONFIG_PAX_MPROTECT
52085+ .handle_mprotect= elf_handle_mprotect,
52086+#endif
52087+
52088+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
52089+ .handle_mmap = elf_handle_mmap,
52090+#endif
52091+
52092 .min_coredump = ELF_EXEC_PAGESIZE,
52093 };
52094
52095@@ -86,6 +104,8 @@ static struct linux_binfmt elf_format = {
52096
52097 static int set_brk(unsigned long start, unsigned long end)
52098 {
52099+ unsigned long e = end;
52100+
52101 start = ELF_PAGEALIGN(start);
52102 end = ELF_PAGEALIGN(end);
52103 if (end > start) {
52104@@ -94,7 +114,7 @@ static int set_brk(unsigned long start, unsigned long end)
52105 if (BAD_ADDR(addr))
52106 return addr;
52107 }
52108- current->mm->start_brk = current->mm->brk = end;
52109+ current->mm->start_brk = current->mm->brk = e;
52110 return 0;
52111 }
52112
52113@@ -155,12 +175,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
52114 elf_addr_t __user *u_rand_bytes;
52115 const char *k_platform = ELF_PLATFORM;
52116 const char *k_base_platform = ELF_BASE_PLATFORM;
52117- unsigned char k_rand_bytes[16];
52118+ u32 k_rand_bytes[4];
52119 int items;
52120 elf_addr_t *elf_info;
52121 int ei_index = 0;
52122 const struct cred *cred = current_cred();
52123 struct vm_area_struct *vma;
52124+ unsigned long saved_auxv[AT_VECTOR_SIZE];
52125
52126 /*
52127 * In some cases (e.g. Hyper-Threading), we want to avoid L1
52128@@ -202,8 +223,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
52129 * Generate 16 random bytes for userspace PRNG seeding.
52130 */
52131 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
52132- u_rand_bytes = (elf_addr_t __user *)
52133- STACK_ALLOC(p, sizeof(k_rand_bytes));
52134+ prandom_seed(k_rand_bytes[0] ^ prandom_u32());
52135+ prandom_seed(k_rand_bytes[1] ^ prandom_u32());
52136+ prandom_seed(k_rand_bytes[2] ^ prandom_u32());
52137+ prandom_seed(k_rand_bytes[3] ^ prandom_u32());
52138+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
52139+ u_rand_bytes = (elf_addr_t __user *) p;
52140 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
52141 return -EFAULT;
52142
52143@@ -318,9 +343,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
52144 return -EFAULT;
52145 current->mm->env_end = p;
52146
52147+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
52148+
52149 /* Put the elf_info on the stack in the right place. */
52150 sp = (elf_addr_t __user *)envp + 1;
52151- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
52152+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
52153 return -EFAULT;
52154 return 0;
52155 }
52156@@ -388,15 +415,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
52157 an ELF header */
52158
52159 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
52160- struct file *interpreter, unsigned long *interp_map_addr,
52161- unsigned long no_base)
52162+ struct file *interpreter, unsigned long no_base)
52163 {
52164 struct elf_phdr *elf_phdata;
52165 struct elf_phdr *eppnt;
52166- unsigned long load_addr = 0;
52167+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
52168 int load_addr_set = 0;
52169 unsigned long last_bss = 0, elf_bss = 0;
52170- unsigned long error = ~0UL;
52171+ unsigned long error = -EINVAL;
52172 unsigned long total_size;
52173 int retval, i, size;
52174
52175@@ -442,6 +468,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
52176 goto out_close;
52177 }
52178
52179+#ifdef CONFIG_PAX_SEGMEXEC
52180+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
52181+ pax_task_size = SEGMEXEC_TASK_SIZE;
52182+#endif
52183+
52184 eppnt = elf_phdata;
52185 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
52186 if (eppnt->p_type == PT_LOAD) {
52187@@ -465,8 +496,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
52188 map_addr = elf_map(interpreter, load_addr + vaddr,
52189 eppnt, elf_prot, elf_type, total_size);
52190 total_size = 0;
52191- if (!*interp_map_addr)
52192- *interp_map_addr = map_addr;
52193 error = map_addr;
52194 if (BAD_ADDR(map_addr))
52195 goto out_close;
52196@@ -485,8 +514,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
52197 k = load_addr + eppnt->p_vaddr;
52198 if (BAD_ADDR(k) ||
52199 eppnt->p_filesz > eppnt->p_memsz ||
52200- eppnt->p_memsz > TASK_SIZE ||
52201- TASK_SIZE - eppnt->p_memsz < k) {
52202+ eppnt->p_memsz > pax_task_size ||
52203+ pax_task_size - eppnt->p_memsz < k) {
52204 error = -ENOMEM;
52205 goto out_close;
52206 }
52207@@ -525,9 +554,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
52208 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
52209
52210 /* Map the last of the bss segment */
52211- error = vm_brk(elf_bss, last_bss - elf_bss);
52212- if (BAD_ADDR(error))
52213- goto out_close;
52214+ if (last_bss > elf_bss) {
52215+ error = vm_brk(elf_bss, last_bss - elf_bss);
52216+ if (BAD_ADDR(error))
52217+ goto out_close;
52218+ }
52219 }
52220
52221 error = load_addr;
52222@@ -538,6 +569,315 @@ out:
52223 return error;
52224 }
52225
52226+#ifdef CONFIG_PAX_PT_PAX_FLAGS
52227+#ifdef CONFIG_PAX_SOFTMODE
52228+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
52229+{
52230+ unsigned long pax_flags = 0UL;
52231+
52232+#ifdef CONFIG_PAX_PAGEEXEC
52233+ if (elf_phdata->p_flags & PF_PAGEEXEC)
52234+ pax_flags |= MF_PAX_PAGEEXEC;
52235+#endif
52236+
52237+#ifdef CONFIG_PAX_SEGMEXEC
52238+ if (elf_phdata->p_flags & PF_SEGMEXEC)
52239+ pax_flags |= MF_PAX_SEGMEXEC;
52240+#endif
52241+
52242+#ifdef CONFIG_PAX_EMUTRAMP
52243+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
52244+ pax_flags |= MF_PAX_EMUTRAMP;
52245+#endif
52246+
52247+#ifdef CONFIG_PAX_MPROTECT
52248+ if (elf_phdata->p_flags & PF_MPROTECT)
52249+ pax_flags |= MF_PAX_MPROTECT;
52250+#endif
52251+
52252+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
52253+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
52254+ pax_flags |= MF_PAX_RANDMMAP;
52255+#endif
52256+
52257+ return pax_flags;
52258+}
52259+#endif
52260+
52261+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
52262+{
52263+ unsigned long pax_flags = 0UL;
52264+
52265+#ifdef CONFIG_PAX_PAGEEXEC
52266+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
52267+ pax_flags |= MF_PAX_PAGEEXEC;
52268+#endif
52269+
52270+#ifdef CONFIG_PAX_SEGMEXEC
52271+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
52272+ pax_flags |= MF_PAX_SEGMEXEC;
52273+#endif
52274+
52275+#ifdef CONFIG_PAX_EMUTRAMP
52276+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
52277+ pax_flags |= MF_PAX_EMUTRAMP;
52278+#endif
52279+
52280+#ifdef CONFIG_PAX_MPROTECT
52281+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
52282+ pax_flags |= MF_PAX_MPROTECT;
52283+#endif
52284+
52285+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
52286+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
52287+ pax_flags |= MF_PAX_RANDMMAP;
52288+#endif
52289+
52290+ return pax_flags;
52291+}
52292+#endif
52293+
52294+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
52295+#ifdef CONFIG_PAX_SOFTMODE
52296+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
52297+{
52298+ unsigned long pax_flags = 0UL;
52299+
52300+#ifdef CONFIG_PAX_PAGEEXEC
52301+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
52302+ pax_flags |= MF_PAX_PAGEEXEC;
52303+#endif
52304+
52305+#ifdef CONFIG_PAX_SEGMEXEC
52306+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
52307+ pax_flags |= MF_PAX_SEGMEXEC;
52308+#endif
52309+
52310+#ifdef CONFIG_PAX_EMUTRAMP
52311+ if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
52312+ pax_flags |= MF_PAX_EMUTRAMP;
52313+#endif
52314+
52315+#ifdef CONFIG_PAX_MPROTECT
52316+ if (pax_flags_softmode & MF_PAX_MPROTECT)
52317+ pax_flags |= MF_PAX_MPROTECT;
52318+#endif
52319+
52320+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
52321+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
52322+ pax_flags |= MF_PAX_RANDMMAP;
52323+#endif
52324+
52325+ return pax_flags;
52326+}
52327+#endif
52328+
52329+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
52330+{
52331+ unsigned long pax_flags = 0UL;
52332+
52333+#ifdef CONFIG_PAX_PAGEEXEC
52334+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
52335+ pax_flags |= MF_PAX_PAGEEXEC;
52336+#endif
52337+
52338+#ifdef CONFIG_PAX_SEGMEXEC
52339+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
52340+ pax_flags |= MF_PAX_SEGMEXEC;
52341+#endif
52342+
52343+#ifdef CONFIG_PAX_EMUTRAMP
52344+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
52345+ pax_flags |= MF_PAX_EMUTRAMP;
52346+#endif
52347+
52348+#ifdef CONFIG_PAX_MPROTECT
52349+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
52350+ pax_flags |= MF_PAX_MPROTECT;
52351+#endif
52352+
52353+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
52354+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
52355+ pax_flags |= MF_PAX_RANDMMAP;
52356+#endif
52357+
52358+ return pax_flags;
52359+}
52360+#endif
52361+
52362+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
52363+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
52364+{
52365+ unsigned long pax_flags = 0UL;
52366+
52367+#ifdef CONFIG_PAX_EI_PAX
52368+
52369+#ifdef CONFIG_PAX_PAGEEXEC
52370+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
52371+ pax_flags |= MF_PAX_PAGEEXEC;
52372+#endif
52373+
52374+#ifdef CONFIG_PAX_SEGMEXEC
52375+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
52376+ pax_flags |= MF_PAX_SEGMEXEC;
52377+#endif
52378+
52379+#ifdef CONFIG_PAX_EMUTRAMP
52380+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
52381+ pax_flags |= MF_PAX_EMUTRAMP;
52382+#endif
52383+
52384+#ifdef CONFIG_PAX_MPROTECT
52385+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
52386+ pax_flags |= MF_PAX_MPROTECT;
52387+#endif
52388+
52389+#ifdef CONFIG_PAX_ASLR
52390+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
52391+ pax_flags |= MF_PAX_RANDMMAP;
52392+#endif
52393+
52394+#else
52395+
52396+#ifdef CONFIG_PAX_PAGEEXEC
52397+ pax_flags |= MF_PAX_PAGEEXEC;
52398+#endif
52399+
52400+#ifdef CONFIG_PAX_SEGMEXEC
52401+ pax_flags |= MF_PAX_SEGMEXEC;
52402+#endif
52403+
52404+#ifdef CONFIG_PAX_MPROTECT
52405+ pax_flags |= MF_PAX_MPROTECT;
52406+#endif
52407+
52408+#ifdef CONFIG_PAX_RANDMMAP
52409+ if (randomize_va_space)
52410+ pax_flags |= MF_PAX_RANDMMAP;
52411+#endif
52412+
52413+#endif
52414+
52415+ return pax_flags;
52416+}
52417+
52418+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
52419+{
52420+
52421+#ifdef CONFIG_PAX_PT_PAX_FLAGS
52422+ unsigned long i;
52423+
52424+ for (i = 0UL; i < elf_ex->e_phnum; i++)
52425+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
52426+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
52427+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
52428+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
52429+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
52430+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
52431+ return ~0UL;
52432+
52433+#ifdef CONFIG_PAX_SOFTMODE
52434+ if (pax_softmode)
52435+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
52436+ else
52437+#endif
52438+
52439+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
52440+ break;
52441+ }
52442+#endif
52443+
52444+ return ~0UL;
52445+}
52446+
52447+static unsigned long pax_parse_xattr_pax(struct file * const file)
52448+{
52449+
52450+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
52451+ ssize_t xattr_size, i;
52452+ unsigned char xattr_value[sizeof("pemrs") - 1];
52453+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
52454+
52455+ xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
52456+ if (xattr_size <= 0 || xattr_size > sizeof xattr_value)
52457+ return ~0UL;
52458+
52459+ for (i = 0; i < xattr_size; i++)
52460+ switch (xattr_value[i]) {
52461+ default:
52462+ return ~0UL;
52463+
52464+#define parse_flag(option1, option2, flag) \
52465+ case option1: \
52466+ if (pax_flags_hardmode & MF_PAX_##flag) \
52467+ return ~0UL; \
52468+ pax_flags_hardmode |= MF_PAX_##flag; \
52469+ break; \
52470+ case option2: \
52471+ if (pax_flags_softmode & MF_PAX_##flag) \
52472+ return ~0UL; \
52473+ pax_flags_softmode |= MF_PAX_##flag; \
52474+ break;
52475+
52476+ parse_flag('p', 'P', PAGEEXEC);
52477+ parse_flag('e', 'E', EMUTRAMP);
52478+ parse_flag('m', 'M', MPROTECT);
52479+ parse_flag('r', 'R', RANDMMAP);
52480+ parse_flag('s', 'S', SEGMEXEC);
52481+
52482+#undef parse_flag
52483+ }
52484+
52485+ if (pax_flags_hardmode & pax_flags_softmode)
52486+ return ~0UL;
52487+
52488+#ifdef CONFIG_PAX_SOFTMODE
52489+ if (pax_softmode)
52490+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
52491+ else
52492+#endif
52493+
52494+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
52495+#else
52496+ return ~0UL;
52497+#endif
52498+
52499+}
52500+
52501+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
52502+{
52503+ unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
52504+
52505+ pax_flags = pax_parse_ei_pax(elf_ex);
52506+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
52507+ xattr_pax_flags = pax_parse_xattr_pax(file);
52508+
52509+ if (pt_pax_flags == ~0UL)
52510+ pt_pax_flags = xattr_pax_flags;
52511+ else if (xattr_pax_flags == ~0UL)
52512+ xattr_pax_flags = pt_pax_flags;
52513+ if (pt_pax_flags != xattr_pax_flags)
52514+ return -EINVAL;
52515+ if (pt_pax_flags != ~0UL)
52516+ pax_flags = pt_pax_flags;
52517+
52518+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
52519+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
52520+ if ((__supported_pte_mask & _PAGE_NX))
52521+ pax_flags &= ~MF_PAX_SEGMEXEC;
52522+ else
52523+ pax_flags &= ~MF_PAX_PAGEEXEC;
52524+ }
52525+#endif
52526+
52527+ if (0 > pax_check_flags(&pax_flags))
52528+ return -EINVAL;
52529+
52530+ current->mm->pax_flags = pax_flags;
52531+ return 0;
52532+}
52533+#endif
52534+
52535 /*
52536 * These are the functions used to load ELF style executables and shared
52537 * libraries. There is no binary dependent code anywhere else.
52538@@ -554,6 +894,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
52539 {
52540 unsigned int random_variable = 0;
52541
52542+#ifdef CONFIG_PAX_RANDUSTACK
52543+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
52544+ return stack_top - current->mm->delta_stack;
52545+#endif
52546+
52547 if ((current->flags & PF_RANDOMIZE) &&
52548 !(current->personality & ADDR_NO_RANDOMIZE)) {
52549 random_variable = get_random_int() & STACK_RND_MASK;
52550@@ -572,7 +917,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
52551 unsigned long load_addr = 0, load_bias = 0;
52552 int load_addr_set = 0;
52553 char * elf_interpreter = NULL;
52554- unsigned long error;
52555+ unsigned long error = 0;
52556 struct elf_phdr *elf_ppnt, *elf_phdata;
52557 unsigned long elf_bss, elf_brk;
52558 int retval, i;
52559@@ -582,12 +927,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
52560 unsigned long start_code, end_code, start_data, end_data;
52561 unsigned long reloc_func_desc __maybe_unused = 0;
52562 int executable_stack = EXSTACK_DEFAULT;
52563- unsigned long def_flags = 0;
52564 struct pt_regs *regs = current_pt_regs();
52565 struct {
52566 struct elfhdr elf_ex;
52567 struct elfhdr interp_elf_ex;
52568 } *loc;
52569+ unsigned long pax_task_size = TASK_SIZE;
52570
52571 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
52572 if (!loc) {
52573@@ -723,11 +1068,81 @@ static int load_elf_binary(struct linux_binprm *bprm)
52574 goto out_free_dentry;
52575
52576 /* OK, This is the point of no return */
52577- current->mm->def_flags = def_flags;
52578+
52579+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
52580+ current->mm->pax_flags = 0UL;
52581+#endif
52582+
52583+#ifdef CONFIG_PAX_DLRESOLVE
52584+ current->mm->call_dl_resolve = 0UL;
52585+#endif
52586+
52587+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
52588+ current->mm->call_syscall = 0UL;
52589+#endif
52590+
52591+#ifdef CONFIG_PAX_ASLR
52592+ current->mm->delta_mmap = 0UL;
52593+ current->mm->delta_stack = 0UL;
52594+#endif
52595+
52596+ current->mm->def_flags = 0;
52597+
52598+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
52599+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
52600+ send_sig(SIGKILL, current, 0);
52601+ goto out_free_dentry;
52602+ }
52603+#endif
52604+
52605+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
52606+ pax_set_initial_flags(bprm);
52607+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
52608+ if (pax_set_initial_flags_func)
52609+ (pax_set_initial_flags_func)(bprm);
52610+#endif
52611+
52612+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
52613+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
52614+ current->mm->context.user_cs_limit = PAGE_SIZE;
52615+ current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
52616+ }
52617+#endif
52618+
52619+#ifdef CONFIG_PAX_SEGMEXEC
52620+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
52621+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
52622+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
52623+ pax_task_size = SEGMEXEC_TASK_SIZE;
52624+ current->mm->def_flags |= VM_NOHUGEPAGE;
52625+ }
52626+#endif
52627+
52628+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
52629+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
52630+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
52631+ put_cpu();
52632+ }
52633+#endif
52634
52635 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
52636 may depend on the personality. */
52637 SET_PERSONALITY(loc->elf_ex);
52638+
52639+#ifdef CONFIG_PAX_ASLR
52640+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
52641+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
52642+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
52643+ }
52644+#endif
52645+
52646+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
52647+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
52648+ executable_stack = EXSTACK_DISABLE_X;
52649+ current->personality &= ~READ_IMPLIES_EXEC;
52650+ } else
52651+#endif
52652+
52653 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
52654 current->personality |= READ_IMPLIES_EXEC;
52655
52656@@ -817,6 +1232,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
52657 #else
52658 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
52659 #endif
52660+
52661+#ifdef CONFIG_PAX_RANDMMAP
52662+ /* PaX: randomize base address at the default exe base if requested */
52663+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
52664+#ifdef CONFIG_SPARC64
52665+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
52666+#else
52667+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
52668+#endif
52669+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
52670+ elf_flags |= MAP_FIXED;
52671+ }
52672+#endif
52673+
52674 }
52675
52676 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
52677@@ -849,9 +1278,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
52678 * allowed task size. Note that p_filesz must always be
52679 * <= p_memsz so it is only necessary to check p_memsz.
52680 */
52681- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
52682- elf_ppnt->p_memsz > TASK_SIZE ||
52683- TASK_SIZE - elf_ppnt->p_memsz < k) {
52684+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
52685+ elf_ppnt->p_memsz > pax_task_size ||
52686+ pax_task_size - elf_ppnt->p_memsz < k) {
52687 /* set_brk can never work. Avoid overflows. */
52688 send_sig(SIGKILL, current, 0);
52689 retval = -EINVAL;
52690@@ -890,17 +1319,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
52691 goto out_free_dentry;
52692 }
52693 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
52694- send_sig(SIGSEGV, current, 0);
52695- retval = -EFAULT; /* Nobody gets to see this, but.. */
52696- goto out_free_dentry;
52697+ /*
52698+ * This bss-zeroing can fail if the ELF
52699+ * file specifies odd protections. So
52700+ * we don't check the return value
52701+ */
52702 }
52703
52704+#ifdef CONFIG_PAX_RANDMMAP
52705+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
52706+ unsigned long start, size, flags;
52707+ vm_flags_t vm_flags;
52708+
52709+ start = ELF_PAGEALIGN(elf_brk);
52710+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
52711+ flags = MAP_FIXED | MAP_PRIVATE;
52712+ vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
52713+
52714+ down_write(&current->mm->mmap_sem);
52715+ start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
52716+ retval = -ENOMEM;
52717+ if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
52718+// if (current->personality & ADDR_NO_RANDOMIZE)
52719+// vm_flags |= VM_READ | VM_MAYREAD;
52720+ start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
52721+ retval = IS_ERR_VALUE(start) ? start : 0;
52722+ }
52723+ up_write(&current->mm->mmap_sem);
52724+ if (retval == 0)
52725+ retval = set_brk(start + size, start + size + PAGE_SIZE);
52726+ if (retval < 0) {
52727+ send_sig(SIGKILL, current, 0);
52728+ goto out_free_dentry;
52729+ }
52730+ }
52731+#endif
52732+
52733 if (elf_interpreter) {
52734- unsigned long interp_map_addr = 0;
52735-
52736 elf_entry = load_elf_interp(&loc->interp_elf_ex,
52737 interpreter,
52738- &interp_map_addr,
52739 load_bias);
52740 if (!IS_ERR((void *)elf_entry)) {
52741 /*
52742@@ -1122,7 +1579,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
52743 * Decide what to dump of a segment, part, all or none.
52744 */
52745 static unsigned long vma_dump_size(struct vm_area_struct *vma,
52746- unsigned long mm_flags)
52747+ unsigned long mm_flags, long signr)
52748 {
52749 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
52750
52751@@ -1160,7 +1617,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
52752 if (vma->vm_file == NULL)
52753 return 0;
52754
52755- if (FILTER(MAPPED_PRIVATE))
52756+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
52757 goto whole;
52758
52759 /*
52760@@ -1385,9 +1842,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
52761 {
52762 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
52763 int i = 0;
52764- do
52765+ do {
52766 i += 2;
52767- while (auxv[i - 2] != AT_NULL);
52768+ } while (auxv[i - 2] != AT_NULL);
52769 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
52770 }
52771
52772@@ -1396,7 +1853,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
52773 {
52774 mm_segment_t old_fs = get_fs();
52775 set_fs(KERNEL_DS);
52776- copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
52777+ copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
52778 set_fs(old_fs);
52779 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
52780 }
52781@@ -2017,14 +2474,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
52782 }
52783
52784 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
52785- unsigned long mm_flags)
52786+ struct coredump_params *cprm)
52787 {
52788 struct vm_area_struct *vma;
52789 size_t size = 0;
52790
52791 for (vma = first_vma(current, gate_vma); vma != NULL;
52792 vma = next_vma(vma, gate_vma))
52793- size += vma_dump_size(vma, mm_flags);
52794+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
52795 return size;
52796 }
52797
52798@@ -2117,7 +2574,7 @@ static int elf_core_dump(struct coredump_params *cprm)
52799
52800 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
52801
52802- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
52803+ offset += elf_core_vma_data_size(gate_vma, cprm);
52804 offset += elf_core_extra_data_size();
52805 e_shoff = offset;
52806
52807@@ -2131,10 +2588,12 @@ static int elf_core_dump(struct coredump_params *cprm)
52808 offset = dataoff;
52809
52810 size += sizeof(*elf);
52811+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
52812 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
52813 goto end_coredump;
52814
52815 size += sizeof(*phdr4note);
52816+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
52817 if (size > cprm->limit
52818 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
52819 goto end_coredump;
52820@@ -2148,7 +2607,7 @@ static int elf_core_dump(struct coredump_params *cprm)
52821 phdr.p_offset = offset;
52822 phdr.p_vaddr = vma->vm_start;
52823 phdr.p_paddr = 0;
52824- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
52825+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
52826 phdr.p_memsz = vma->vm_end - vma->vm_start;
52827 offset += phdr.p_filesz;
52828 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
52829@@ -2159,6 +2618,7 @@ static int elf_core_dump(struct coredump_params *cprm)
52830 phdr.p_align = ELF_EXEC_PAGESIZE;
52831
52832 size += sizeof(phdr);
52833+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
52834 if (size > cprm->limit
52835 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
52836 goto end_coredump;
52837@@ -2183,7 +2643,7 @@ static int elf_core_dump(struct coredump_params *cprm)
52838 unsigned long addr;
52839 unsigned long end;
52840
52841- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
52842+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
52843
52844 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
52845 struct page *page;
52846@@ -2192,6 +2652,7 @@ static int elf_core_dump(struct coredump_params *cprm)
52847 page = get_dump_page(addr);
52848 if (page) {
52849 void *kaddr = kmap(page);
52850+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
52851 stop = ((size += PAGE_SIZE) > cprm->limit) ||
52852 !dump_write(cprm->file, kaddr,
52853 PAGE_SIZE);
52854@@ -2209,6 +2670,7 @@ static int elf_core_dump(struct coredump_params *cprm)
52855
52856 if (e_phnum == PN_XNUM) {
52857 size += sizeof(*shdr4extnum);
52858+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
52859 if (size > cprm->limit
52860 || !dump_write(cprm->file, shdr4extnum,
52861 sizeof(*shdr4extnum)))
52862@@ -2229,6 +2691,167 @@ out:
52863
52864 #endif /* CONFIG_ELF_CORE */
52865
52866+#ifdef CONFIG_PAX_MPROTECT
52867+/* PaX: non-PIC ELF libraries need relocations on their executable segments
52868+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
52869+ * we'll remove VM_MAYWRITE for good on RELRO segments.
52870+ *
52871+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
52872+ * basis because we want to allow the common case and not the special ones.
52873+ */
52874+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
52875+{
52876+ struct elfhdr elf_h;
52877+ struct elf_phdr elf_p;
52878+ unsigned long i;
52879+ unsigned long oldflags;
52880+ bool is_textrel_rw, is_textrel_rx, is_relro;
52881+
52882+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
52883+ return;
52884+
52885+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
52886+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
52887+
52888+#ifdef CONFIG_PAX_ELFRELOCS
52889+ /* possible TEXTREL */
52890+ is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
52891+ is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
52892+#else
52893+ is_textrel_rw = false;
52894+ is_textrel_rx = false;
52895+#endif
52896+
52897+ /* possible RELRO */
52898+ is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
52899+
52900+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
52901+ return;
52902+
52903+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
52904+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
52905+
52906+#ifdef CONFIG_PAX_ETEXECRELOCS
52907+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
52908+#else
52909+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
52910+#endif
52911+
52912+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
52913+ !elf_check_arch(&elf_h) ||
52914+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
52915+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
52916+ return;
52917+
52918+ for (i = 0UL; i < elf_h.e_phnum; i++) {
52919+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
52920+ return;
52921+ switch (elf_p.p_type) {
52922+ case PT_DYNAMIC:
52923+ if (!is_textrel_rw && !is_textrel_rx)
52924+ continue;
52925+ i = 0UL;
52926+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
52927+ elf_dyn dyn;
52928+
52929+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
52930+ break;
52931+ if (dyn.d_tag == DT_NULL)
52932+ break;
52933+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
52934+ gr_log_textrel(vma);
52935+ if (is_textrel_rw)
52936+ vma->vm_flags |= VM_MAYWRITE;
52937+ else
52938+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
52939+ vma->vm_flags &= ~VM_MAYWRITE;
52940+ break;
52941+ }
52942+ i++;
52943+ }
52944+ is_textrel_rw = false;
52945+ is_textrel_rx = false;
52946+ continue;
52947+
52948+ case PT_GNU_RELRO:
52949+ if (!is_relro)
52950+ continue;
52951+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
52952+ vma->vm_flags &= ~VM_MAYWRITE;
52953+ is_relro = false;
52954+ continue;
52955+
52956+#ifdef CONFIG_PAX_PT_PAX_FLAGS
52957+ case PT_PAX_FLAGS: {
52958+ const char *msg_mprotect = "", *msg_emutramp = "";
52959+ char *buffer_lib, *buffer_exe;
52960+
52961+ if (elf_p.p_flags & PF_NOMPROTECT)
52962+ msg_mprotect = "MPROTECT disabled";
52963+
52964+#ifdef CONFIG_PAX_EMUTRAMP
52965+ if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
52966+ msg_emutramp = "EMUTRAMP enabled";
52967+#endif
52968+
52969+ if (!msg_mprotect[0] && !msg_emutramp[0])
52970+ continue;
52971+
52972+ if (!printk_ratelimit())
52973+ continue;
52974+
52975+ buffer_lib = (char *)__get_free_page(GFP_KERNEL);
52976+ buffer_exe = (char *)__get_free_page(GFP_KERNEL);
52977+ if (buffer_lib && buffer_exe) {
52978+ char *path_lib, *path_exe;
52979+
52980+ path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
52981+ path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
52982+
52983+ pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
52984+ (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
52985+
52986+ }
52987+ free_page((unsigned long)buffer_exe);
52988+ free_page((unsigned long)buffer_lib);
52989+ continue;
52990+ }
52991+#endif
52992+
52993+ }
52994+ }
52995+}
52996+#endif
52997+
52998+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
52999+
53000+extern int grsec_enable_log_rwxmaps;
53001+
53002+static void elf_handle_mmap(struct file *file)
53003+{
53004+ struct elfhdr elf_h;
53005+ struct elf_phdr elf_p;
53006+ unsigned long i;
53007+
53008+ if (!grsec_enable_log_rwxmaps)
53009+ return;
53010+
53011+ if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
53012+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
53013+ (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
53014+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
53015+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
53016+ return;
53017+
53018+ for (i = 0UL; i < elf_h.e_phnum; i++) {
53019+ if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
53020+ return;
53021+ if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
53022+ gr_log_ptgnustack(file);
53023+ }
53024+}
53025+#endif
53026+
53027 static int __init init_elf_binfmt(void)
53028 {
53029 register_binfmt(&elf_format);
53030diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
53031index d50bbe5..af3b649 100644
53032--- a/fs/binfmt_flat.c
53033+++ b/fs/binfmt_flat.c
53034@@ -566,7 +566,9 @@ static int load_flat_file(struct linux_binprm * bprm,
53035 realdatastart = (unsigned long) -ENOMEM;
53036 printk("Unable to allocate RAM for process data, errno %d\n",
53037 (int)-realdatastart);
53038+ down_write(&current->mm->mmap_sem);
53039 vm_munmap(textpos, text_len);
53040+ up_write(&current->mm->mmap_sem);
53041 ret = realdatastart;
53042 goto err;
53043 }
53044@@ -590,8 +592,10 @@ static int load_flat_file(struct linux_binprm * bprm,
53045 }
53046 if (IS_ERR_VALUE(result)) {
53047 printk("Unable to read data+bss, errno %d\n", (int)-result);
53048+ down_write(&current->mm->mmap_sem);
53049 vm_munmap(textpos, text_len);
53050 vm_munmap(realdatastart, len);
53051+ up_write(&current->mm->mmap_sem);
53052 ret = result;
53053 goto err;
53054 }
53055@@ -653,8 +657,10 @@ static int load_flat_file(struct linux_binprm * bprm,
53056 }
53057 if (IS_ERR_VALUE(result)) {
53058 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
53059+ down_write(&current->mm->mmap_sem);
53060 vm_munmap(textpos, text_len + data_len + extra +
53061 MAX_SHARED_LIBS * sizeof(unsigned long));
53062+ up_write(&current->mm->mmap_sem);
53063 ret = result;
53064 goto err;
53065 }
53066diff --git a/fs/bio.c b/fs/bio.c
53067index c5eae72..599e3cf 100644
53068--- a/fs/bio.c
53069+++ b/fs/bio.c
53070@@ -1106,7 +1106,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
53071 /*
53072 * Overflow, abort
53073 */
53074- if (end < start)
53075+ if (end < start || end - start > INT_MAX - nr_pages)
53076 return ERR_PTR(-EINVAL);
53077
53078 nr_pages += end - start;
53079@@ -1240,7 +1240,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
53080 /*
53081 * Overflow, abort
53082 */
53083- if (end < start)
53084+ if (end < start || end - start > INT_MAX - nr_pages)
53085 return ERR_PTR(-EINVAL);
53086
53087 nr_pages += end - start;
53088@@ -1502,7 +1502,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
53089 const int read = bio_data_dir(bio) == READ;
53090 struct bio_map_data *bmd = bio->bi_private;
53091 int i;
53092- char *p = bmd->sgvecs[0].iov_base;
53093+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
53094
53095 bio_for_each_segment_all(bvec, bio, i) {
53096 char *addr = page_address(bvec->bv_page);
53097diff --git a/fs/block_dev.c b/fs/block_dev.c
53098index c7bda5c..2121e94 100644
53099--- a/fs/block_dev.c
53100+++ b/fs/block_dev.c
53101@@ -637,7 +637,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
53102 else if (bdev->bd_contains == bdev)
53103 return true; /* is a whole device which isn't held */
53104
53105- else if (whole->bd_holder == bd_may_claim)
53106+ else if (whole->bd_holder == (void *)bd_may_claim)
53107 return true; /* is a partition of a device that is being partitioned */
53108 else if (whole->bd_holder != NULL)
53109 return false; /* is a partition of a held device */
53110diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
53111index ed50460..fe84385 100644
53112--- a/fs/btrfs/ctree.c
53113+++ b/fs/btrfs/ctree.c
53114@@ -1076,9 +1076,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
53115 free_extent_buffer(buf);
53116 add_root_to_dirty_list(root);
53117 } else {
53118- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
53119- parent_start = parent->start;
53120- else
53121+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
53122+ if (parent)
53123+ parent_start = parent->start;
53124+ else
53125+ parent_start = 0;
53126+ } else
53127 parent_start = 0;
53128
53129 WARN_ON(trans->transid != btrfs_header_generation(parent));
53130diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
53131index 3755109..e3d457f 100644
53132--- a/fs/btrfs/delayed-inode.c
53133+++ b/fs/btrfs/delayed-inode.c
53134@@ -458,7 +458,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
53135
53136 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
53137 {
53138- int seq = atomic_inc_return(&delayed_root->items_seq);
53139+ int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
53140 if ((atomic_dec_return(&delayed_root->items) <
53141 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
53142 waitqueue_active(&delayed_root->wait))
53143@@ -1377,7 +1377,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
53144 static int refs_newer(struct btrfs_delayed_root *delayed_root,
53145 int seq, int count)
53146 {
53147- int val = atomic_read(&delayed_root->items_seq);
53148+ int val = atomic_read_unchecked(&delayed_root->items_seq);
53149
53150 if (val < seq || val >= seq + count)
53151 return 1;
53152@@ -1394,7 +1394,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
53153 if (atomic_read(&delayed_root->items) < BTRFS_DELAYED_BACKGROUND)
53154 return;
53155
53156- seq = atomic_read(&delayed_root->items_seq);
53157+ seq = atomic_read_unchecked(&delayed_root->items_seq);
53158
53159 if (atomic_read(&delayed_root->items) >= BTRFS_DELAYED_WRITEBACK) {
53160 int ret;
53161diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
53162index a4b38f9..f86a509 100644
53163--- a/fs/btrfs/delayed-inode.h
53164+++ b/fs/btrfs/delayed-inode.h
53165@@ -43,7 +43,7 @@ struct btrfs_delayed_root {
53166 */
53167 struct list_head prepare_list;
53168 atomic_t items; /* for delayed items */
53169- atomic_t items_seq; /* for delayed items */
53170+ atomic_unchecked_t items_seq; /* for delayed items */
53171 int nodes; /* for delayed nodes */
53172 wait_queue_head_t wait;
53173 };
53174@@ -87,7 +87,7 @@ static inline void btrfs_init_delayed_root(
53175 struct btrfs_delayed_root *delayed_root)
53176 {
53177 atomic_set(&delayed_root->items, 0);
53178- atomic_set(&delayed_root->items_seq, 0);
53179+ atomic_set_unchecked(&delayed_root->items_seq, 0);
53180 delayed_root->nodes = 0;
53181 spin_lock_init(&delayed_root->lock);
53182 init_waitqueue_head(&delayed_root->wait);
53183diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
53184index 9877a2a..7ebf9ab 100644
53185--- a/fs/btrfs/ioctl.c
53186+++ b/fs/btrfs/ioctl.c
53187@@ -3097,9 +3097,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
53188 for (i = 0; i < num_types; i++) {
53189 struct btrfs_space_info *tmp;
53190
53191+ /* Don't copy in more than we allocated */
53192 if (!slot_count)
53193 break;
53194
53195+ slot_count--;
53196+
53197 info = NULL;
53198 rcu_read_lock();
53199 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
53200@@ -3121,10 +3124,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
53201 memcpy(dest, &space, sizeof(space));
53202 dest++;
53203 space_args.total_spaces++;
53204- slot_count--;
53205 }
53206- if (!slot_count)
53207- break;
53208 }
53209 up_read(&info->groups_sem);
53210 }
53211diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
53212index 8eb6191..eda91e2 100644
53213--- a/fs/btrfs/super.c
53214+++ b/fs/btrfs/super.c
53215@@ -264,7 +264,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
53216 function, line, errstr);
53217 return;
53218 }
53219- ACCESS_ONCE(trans->transaction->aborted) = errno;
53220+ ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
53221 /* Wake up anybody who may be waiting on this transaction */
53222 wake_up(&root->fs_info->transaction_wait);
53223 wake_up(&root->fs_info->transaction_blocked_wait);
53224diff --git a/fs/buffer.c b/fs/buffer.c
53225index 4d74335..b0df7f9 100644
53226--- a/fs/buffer.c
53227+++ b/fs/buffer.c
53228@@ -3416,7 +3416,7 @@ void __init buffer_init(void)
53229 bh_cachep = kmem_cache_create("buffer_head",
53230 sizeof(struct buffer_head), 0,
53231 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
53232- SLAB_MEM_SPREAD),
53233+ SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
53234 NULL);
53235
53236 /*
53237diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
53238index 622f469..e8d2d55 100644
53239--- a/fs/cachefiles/bind.c
53240+++ b/fs/cachefiles/bind.c
53241@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
53242 args);
53243
53244 /* start by checking things over */
53245- ASSERT(cache->fstop_percent >= 0 &&
53246- cache->fstop_percent < cache->fcull_percent &&
53247+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
53248 cache->fcull_percent < cache->frun_percent &&
53249 cache->frun_percent < 100);
53250
53251- ASSERT(cache->bstop_percent >= 0 &&
53252- cache->bstop_percent < cache->bcull_percent &&
53253+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
53254 cache->bcull_percent < cache->brun_percent &&
53255 cache->brun_percent < 100);
53256
53257diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
53258index 0a1467b..6a53245 100644
53259--- a/fs/cachefiles/daemon.c
53260+++ b/fs/cachefiles/daemon.c
53261@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
53262 if (n > buflen)
53263 return -EMSGSIZE;
53264
53265- if (copy_to_user(_buffer, buffer, n) != 0)
53266+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
53267 return -EFAULT;
53268
53269 return n;
53270@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
53271 if (test_bit(CACHEFILES_DEAD, &cache->flags))
53272 return -EIO;
53273
53274- if (datalen < 0 || datalen > PAGE_SIZE - 1)
53275+ if (datalen > PAGE_SIZE - 1)
53276 return -EOPNOTSUPP;
53277
53278 /* drag the command string into the kernel so we can parse it */
53279@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
53280 if (args[0] != '%' || args[1] != '\0')
53281 return -EINVAL;
53282
53283- if (fstop < 0 || fstop >= cache->fcull_percent)
53284+ if (fstop >= cache->fcull_percent)
53285 return cachefiles_daemon_range_error(cache, args);
53286
53287 cache->fstop_percent = fstop;
53288@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
53289 if (args[0] != '%' || args[1] != '\0')
53290 return -EINVAL;
53291
53292- if (bstop < 0 || bstop >= cache->bcull_percent)
53293+ if (bstop >= cache->bcull_percent)
53294 return cachefiles_daemon_range_error(cache, args);
53295
53296 cache->bstop_percent = bstop;
53297diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
53298index 4938251..7e01445 100644
53299--- a/fs/cachefiles/internal.h
53300+++ b/fs/cachefiles/internal.h
53301@@ -59,7 +59,7 @@ struct cachefiles_cache {
53302 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
53303 struct rb_root active_nodes; /* active nodes (can't be culled) */
53304 rwlock_t active_lock; /* lock for active_nodes */
53305- atomic_t gravecounter; /* graveyard uniquifier */
53306+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
53307 unsigned frun_percent; /* when to stop culling (% files) */
53308 unsigned fcull_percent; /* when to start culling (% files) */
53309 unsigned fstop_percent; /* when to stop allocating (% files) */
53310@@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
53311 * proc.c
53312 */
53313 #ifdef CONFIG_CACHEFILES_HISTOGRAM
53314-extern atomic_t cachefiles_lookup_histogram[HZ];
53315-extern atomic_t cachefiles_mkdir_histogram[HZ];
53316-extern atomic_t cachefiles_create_histogram[HZ];
53317+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
53318+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
53319+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
53320
53321 extern int __init cachefiles_proc_init(void);
53322 extern void cachefiles_proc_cleanup(void);
53323 static inline
53324-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
53325+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
53326 {
53327 unsigned long jif = jiffies - start_jif;
53328 if (jif >= HZ)
53329 jif = HZ - 1;
53330- atomic_inc(&histogram[jif]);
53331+ atomic_inc_unchecked(&histogram[jif]);
53332 }
53333
53334 #else
53335diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
53336index 25badd1..d70d918 100644
53337--- a/fs/cachefiles/namei.c
53338+++ b/fs/cachefiles/namei.c
53339@@ -317,7 +317,7 @@ try_again:
53340 /* first step is to make up a grave dentry in the graveyard */
53341 sprintf(nbuffer, "%08x%08x",
53342 (uint32_t) get_seconds(),
53343- (uint32_t) atomic_inc_return(&cache->gravecounter));
53344+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
53345
53346 /* do the multiway lock magic */
53347 trap = lock_rename(cache->graveyard, dir);
53348diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
53349index eccd339..4c1d995 100644
53350--- a/fs/cachefiles/proc.c
53351+++ b/fs/cachefiles/proc.c
53352@@ -14,9 +14,9 @@
53353 #include <linux/seq_file.h>
53354 #include "internal.h"
53355
53356-atomic_t cachefiles_lookup_histogram[HZ];
53357-atomic_t cachefiles_mkdir_histogram[HZ];
53358-atomic_t cachefiles_create_histogram[HZ];
53359+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
53360+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
53361+atomic_unchecked_t cachefiles_create_histogram[HZ];
53362
53363 /*
53364 * display the latency histogram
53365@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
53366 return 0;
53367 default:
53368 index = (unsigned long) v - 3;
53369- x = atomic_read(&cachefiles_lookup_histogram[index]);
53370- y = atomic_read(&cachefiles_mkdir_histogram[index]);
53371- z = atomic_read(&cachefiles_create_histogram[index]);
53372+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
53373+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
53374+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
53375 if (x == 0 && y == 0 && z == 0)
53376 return 0;
53377
53378diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
53379index ebaff36..7e3ea26 100644
53380--- a/fs/cachefiles/rdwr.c
53381+++ b/fs/cachefiles/rdwr.c
53382@@ -950,7 +950,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
53383 old_fs = get_fs();
53384 set_fs(KERNEL_DS);
53385 ret = file->f_op->write(
53386- file, (const void __user *) data, len, &pos);
53387+ file, (const void __force_user *) data, len, &pos);
53388 set_fs(old_fs);
53389 kunmap(page);
53390 file_end_write(file);
53391diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
53392index a40ceda..f43d17c 100644
53393--- a/fs/ceph/dir.c
53394+++ b/fs/ceph/dir.c
53395@@ -240,7 +240,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
53396 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
53397 struct ceph_mds_client *mdsc = fsc->mdsc;
53398 unsigned frag = fpos_frag(ctx->pos);
53399- int off = fpos_off(ctx->pos);
53400+ unsigned int off = fpos_off(ctx->pos);
53401 int err;
53402 u32 ftype;
53403 struct ceph_mds_reply_info_parsed *rinfo;
53404diff --git a/fs/ceph/super.c b/fs/ceph/super.c
53405index 6627b26..634ec4b 100644
53406--- a/fs/ceph/super.c
53407+++ b/fs/ceph/super.c
53408@@ -839,7 +839,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
53409 /*
53410 * construct our own bdi so we can control readahead, etc.
53411 */
53412-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
53413+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
53414
53415 static int ceph_register_bdi(struct super_block *sb,
53416 struct ceph_fs_client *fsc)
53417@@ -856,7 +856,7 @@ static int ceph_register_bdi(struct super_block *sb,
53418 default_backing_dev_info.ra_pages;
53419
53420 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
53421- atomic_long_inc_return(&bdi_seq));
53422+ atomic_long_inc_return_unchecked(&bdi_seq));
53423 if (!err)
53424 sb->s_bdi = &fsc->backing_dev_info;
53425 return err;
53426diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
53427index f3ac415..3d2420c 100644
53428--- a/fs/cifs/cifs_debug.c
53429+++ b/fs/cifs/cifs_debug.c
53430@@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
53431
53432 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
53433 #ifdef CONFIG_CIFS_STATS2
53434- atomic_set(&totBufAllocCount, 0);
53435- atomic_set(&totSmBufAllocCount, 0);
53436+ atomic_set_unchecked(&totBufAllocCount, 0);
53437+ atomic_set_unchecked(&totSmBufAllocCount, 0);
53438 #endif /* CONFIG_CIFS_STATS2 */
53439 spin_lock(&cifs_tcp_ses_lock);
53440 list_for_each(tmp1, &cifs_tcp_ses_list) {
53441@@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
53442 tcon = list_entry(tmp3,
53443 struct cifs_tcon,
53444 tcon_list);
53445- atomic_set(&tcon->num_smbs_sent, 0);
53446+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
53447 if (server->ops->clear_stats)
53448 server->ops->clear_stats(tcon);
53449 }
53450@@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
53451 smBufAllocCount.counter, cifs_min_small);
53452 #ifdef CONFIG_CIFS_STATS2
53453 seq_printf(m, "Total Large %d Small %d Allocations\n",
53454- atomic_read(&totBufAllocCount),
53455- atomic_read(&totSmBufAllocCount));
53456+ atomic_read_unchecked(&totBufAllocCount),
53457+ atomic_read_unchecked(&totSmBufAllocCount));
53458 #endif /* CONFIG_CIFS_STATS2 */
53459
53460 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
53461@@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
53462 if (tcon->need_reconnect)
53463 seq_puts(m, "\tDISCONNECTED ");
53464 seq_printf(m, "\nSMBs: %d",
53465- atomic_read(&tcon->num_smbs_sent));
53466+ atomic_read_unchecked(&tcon->num_smbs_sent));
53467 if (server->ops->print_stats)
53468 server->ops->print_stats(m, tcon);
53469 }
53470diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
53471index 85ea98d..b3ed4d6 100644
53472--- a/fs/cifs/cifsfs.c
53473+++ b/fs/cifs/cifsfs.c
53474@@ -1037,7 +1037,7 @@ cifs_init_request_bufs(void)
53475 */
53476 cifs_req_cachep = kmem_cache_create("cifs_request",
53477 CIFSMaxBufSize + max_hdr_size, 0,
53478- SLAB_HWCACHE_ALIGN, NULL);
53479+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
53480 if (cifs_req_cachep == NULL)
53481 return -ENOMEM;
53482
53483@@ -1064,7 +1064,7 @@ cifs_init_request_bufs(void)
53484 efficient to alloc 1 per page off the slab compared to 17K (5page)
53485 alloc of large cifs buffers even when page debugging is on */
53486 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
53487- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
53488+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
53489 NULL);
53490 if (cifs_sm_req_cachep == NULL) {
53491 mempool_destroy(cifs_req_poolp);
53492@@ -1149,8 +1149,8 @@ init_cifs(void)
53493 atomic_set(&bufAllocCount, 0);
53494 atomic_set(&smBufAllocCount, 0);
53495 #ifdef CONFIG_CIFS_STATS2
53496- atomic_set(&totBufAllocCount, 0);
53497- atomic_set(&totSmBufAllocCount, 0);
53498+ atomic_set_unchecked(&totBufAllocCount, 0);
53499+ atomic_set_unchecked(&totSmBufAllocCount, 0);
53500 #endif /* CONFIG_CIFS_STATS2 */
53501
53502 atomic_set(&midCount, 0);
53503diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
53504index 52ca861..47f309c 100644
53505--- a/fs/cifs/cifsglob.h
53506+++ b/fs/cifs/cifsglob.h
53507@@ -756,35 +756,35 @@ struct cifs_tcon {
53508 __u16 Flags; /* optional support bits */
53509 enum statusEnum tidStatus;
53510 #ifdef CONFIG_CIFS_STATS
53511- atomic_t num_smbs_sent;
53512+ atomic_unchecked_t num_smbs_sent;
53513 union {
53514 struct {
53515- atomic_t num_writes;
53516- atomic_t num_reads;
53517- atomic_t num_flushes;
53518- atomic_t num_oplock_brks;
53519- atomic_t num_opens;
53520- atomic_t num_closes;
53521- atomic_t num_deletes;
53522- atomic_t num_mkdirs;
53523- atomic_t num_posixopens;
53524- atomic_t num_posixmkdirs;
53525- atomic_t num_rmdirs;
53526- atomic_t num_renames;
53527- atomic_t num_t2renames;
53528- atomic_t num_ffirst;
53529- atomic_t num_fnext;
53530- atomic_t num_fclose;
53531- atomic_t num_hardlinks;
53532- atomic_t num_symlinks;
53533- atomic_t num_locks;
53534- atomic_t num_acl_get;
53535- atomic_t num_acl_set;
53536+ atomic_unchecked_t num_writes;
53537+ atomic_unchecked_t num_reads;
53538+ atomic_unchecked_t num_flushes;
53539+ atomic_unchecked_t num_oplock_brks;
53540+ atomic_unchecked_t num_opens;
53541+ atomic_unchecked_t num_closes;
53542+ atomic_unchecked_t num_deletes;
53543+ atomic_unchecked_t num_mkdirs;
53544+ atomic_unchecked_t num_posixopens;
53545+ atomic_unchecked_t num_posixmkdirs;
53546+ atomic_unchecked_t num_rmdirs;
53547+ atomic_unchecked_t num_renames;
53548+ atomic_unchecked_t num_t2renames;
53549+ atomic_unchecked_t num_ffirst;
53550+ atomic_unchecked_t num_fnext;
53551+ atomic_unchecked_t num_fclose;
53552+ atomic_unchecked_t num_hardlinks;
53553+ atomic_unchecked_t num_symlinks;
53554+ atomic_unchecked_t num_locks;
53555+ atomic_unchecked_t num_acl_get;
53556+ atomic_unchecked_t num_acl_set;
53557 } cifs_stats;
53558 #ifdef CONFIG_CIFS_SMB2
53559 struct {
53560- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
53561- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
53562+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
53563+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
53564 } smb2_stats;
53565 #endif /* CONFIG_CIFS_SMB2 */
53566 } stats;
53567@@ -1096,7 +1096,7 @@ convert_delimiter(char *path, char delim)
53568 }
53569
53570 #ifdef CONFIG_CIFS_STATS
53571-#define cifs_stats_inc atomic_inc
53572+#define cifs_stats_inc atomic_inc_unchecked
53573
53574 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
53575 unsigned int bytes)
53576@@ -1461,8 +1461,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
53577 /* Various Debug counters */
53578 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
53579 #ifdef CONFIG_CIFS_STATS2
53580-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
53581-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
53582+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
53583+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
53584 #endif
53585 GLOBAL_EXTERN atomic_t smBufAllocCount;
53586 GLOBAL_EXTERN atomic_t midCount;
53587diff --git a/fs/cifs/link.c b/fs/cifs/link.c
53588index 562044f..4af6a17 100644
53589--- a/fs/cifs/link.c
53590+++ b/fs/cifs/link.c
53591@@ -638,7 +638,7 @@ symlink_exit:
53592
53593 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
53594 {
53595- char *p = nd_get_link(nd);
53596+ const char *p = nd_get_link(nd);
53597 if (!IS_ERR(p))
53598 kfree(p);
53599 }
53600diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
53601index f7d4b22..1254377 100644
53602--- a/fs/cifs/misc.c
53603+++ b/fs/cifs/misc.c
53604@@ -169,7 +169,7 @@ cifs_buf_get(void)
53605 memset(ret_buf, 0, buf_size + 3);
53606 atomic_inc(&bufAllocCount);
53607 #ifdef CONFIG_CIFS_STATS2
53608- atomic_inc(&totBufAllocCount);
53609+ atomic_inc_unchecked(&totBufAllocCount);
53610 #endif /* CONFIG_CIFS_STATS2 */
53611 }
53612
53613@@ -204,7 +204,7 @@ cifs_small_buf_get(void)
53614 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
53615 atomic_inc(&smBufAllocCount);
53616 #ifdef CONFIG_CIFS_STATS2
53617- atomic_inc(&totSmBufAllocCount);
53618+ atomic_inc_unchecked(&totSmBufAllocCount);
53619 #endif /* CONFIG_CIFS_STATS2 */
53620
53621 }
53622diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
53623index 6094397..51e576f 100644
53624--- a/fs/cifs/smb1ops.c
53625+++ b/fs/cifs/smb1ops.c
53626@@ -590,27 +590,27 @@ static void
53627 cifs_clear_stats(struct cifs_tcon *tcon)
53628 {
53629 #ifdef CONFIG_CIFS_STATS
53630- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
53631- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
53632- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
53633- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
53634- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
53635- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
53636- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
53637- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
53638- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
53639- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
53640- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
53641- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
53642- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
53643- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
53644- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
53645- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
53646- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
53647- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
53648- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
53649- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
53650- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
53651+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
53652+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
53653+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
53654+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
53655+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
53656+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
53657+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
53658+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
53659+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
53660+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
53661+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
53662+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
53663+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
53664+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
53665+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
53666+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
53667+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
53668+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
53669+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
53670+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
53671+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
53672 #endif
53673 }
53674
53675@@ -619,36 +619,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
53676 {
53677 #ifdef CONFIG_CIFS_STATS
53678 seq_printf(m, " Oplocks breaks: %d",
53679- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
53680+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
53681 seq_printf(m, "\nReads: %d Bytes: %llu",
53682- atomic_read(&tcon->stats.cifs_stats.num_reads),
53683+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
53684 (long long)(tcon->bytes_read));
53685 seq_printf(m, "\nWrites: %d Bytes: %llu",
53686- atomic_read(&tcon->stats.cifs_stats.num_writes),
53687+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
53688 (long long)(tcon->bytes_written));
53689 seq_printf(m, "\nFlushes: %d",
53690- atomic_read(&tcon->stats.cifs_stats.num_flushes));
53691+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
53692 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
53693- atomic_read(&tcon->stats.cifs_stats.num_locks),
53694- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
53695- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
53696+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
53697+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
53698+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
53699 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
53700- atomic_read(&tcon->stats.cifs_stats.num_opens),
53701- atomic_read(&tcon->stats.cifs_stats.num_closes),
53702- atomic_read(&tcon->stats.cifs_stats.num_deletes));
53703+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
53704+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
53705+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
53706 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
53707- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
53708- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
53709+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
53710+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
53711 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
53712- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
53713- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
53714+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
53715+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
53716 seq_printf(m, "\nRenames: %d T2 Renames %d",
53717- atomic_read(&tcon->stats.cifs_stats.num_renames),
53718- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
53719+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
53720+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
53721 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
53722- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
53723- atomic_read(&tcon->stats.cifs_stats.num_fnext),
53724- atomic_read(&tcon->stats.cifs_stats.num_fclose));
53725+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
53726+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
53727+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
53728 #endif
53729 }
53730
53731diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
53732index f259e6c..ca948ff 100644
53733--- a/fs/cifs/smb2ops.c
53734+++ b/fs/cifs/smb2ops.c
53735@@ -281,8 +281,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
53736 #ifdef CONFIG_CIFS_STATS
53737 int i;
53738 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
53739- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
53740- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
53741+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
53742+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
53743 }
53744 #endif
53745 }
53746@@ -310,65 +310,65 @@ static void
53747 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
53748 {
53749 #ifdef CONFIG_CIFS_STATS
53750- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
53751- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
53752+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
53753+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
53754 seq_printf(m, "\nNegotiates: %d sent %d failed",
53755- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
53756- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
53757+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
53758+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
53759 seq_printf(m, "\nSessionSetups: %d sent %d failed",
53760- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
53761- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
53762+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
53763+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
53764 seq_printf(m, "\nLogoffs: %d sent %d failed",
53765- atomic_read(&sent[SMB2_LOGOFF_HE]),
53766- atomic_read(&failed[SMB2_LOGOFF_HE]));
53767+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
53768+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
53769 seq_printf(m, "\nTreeConnects: %d sent %d failed",
53770- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
53771- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
53772+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
53773+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
53774 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
53775- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
53776- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
53777+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
53778+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
53779 seq_printf(m, "\nCreates: %d sent %d failed",
53780- atomic_read(&sent[SMB2_CREATE_HE]),
53781- atomic_read(&failed[SMB2_CREATE_HE]));
53782+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
53783+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
53784 seq_printf(m, "\nCloses: %d sent %d failed",
53785- atomic_read(&sent[SMB2_CLOSE_HE]),
53786- atomic_read(&failed[SMB2_CLOSE_HE]));
53787+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
53788+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
53789 seq_printf(m, "\nFlushes: %d sent %d failed",
53790- atomic_read(&sent[SMB2_FLUSH_HE]),
53791- atomic_read(&failed[SMB2_FLUSH_HE]));
53792+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
53793+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
53794 seq_printf(m, "\nReads: %d sent %d failed",
53795- atomic_read(&sent[SMB2_READ_HE]),
53796- atomic_read(&failed[SMB2_READ_HE]));
53797+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
53798+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
53799 seq_printf(m, "\nWrites: %d sent %d failed",
53800- atomic_read(&sent[SMB2_WRITE_HE]),
53801- atomic_read(&failed[SMB2_WRITE_HE]));
53802+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
53803+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
53804 seq_printf(m, "\nLocks: %d sent %d failed",
53805- atomic_read(&sent[SMB2_LOCK_HE]),
53806- atomic_read(&failed[SMB2_LOCK_HE]));
53807+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
53808+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
53809 seq_printf(m, "\nIOCTLs: %d sent %d failed",
53810- atomic_read(&sent[SMB2_IOCTL_HE]),
53811- atomic_read(&failed[SMB2_IOCTL_HE]));
53812+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
53813+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
53814 seq_printf(m, "\nCancels: %d sent %d failed",
53815- atomic_read(&sent[SMB2_CANCEL_HE]),
53816- atomic_read(&failed[SMB2_CANCEL_HE]));
53817+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
53818+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
53819 seq_printf(m, "\nEchos: %d sent %d failed",
53820- atomic_read(&sent[SMB2_ECHO_HE]),
53821- atomic_read(&failed[SMB2_ECHO_HE]));
53822+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
53823+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
53824 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
53825- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
53826- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
53827+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
53828+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
53829 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
53830- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
53831- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
53832+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
53833+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
53834 seq_printf(m, "\nQueryInfos: %d sent %d failed",
53835- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
53836- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
53837+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
53838+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
53839 seq_printf(m, "\nSetInfos: %d sent %d failed",
53840- atomic_read(&sent[SMB2_SET_INFO_HE]),
53841- atomic_read(&failed[SMB2_SET_INFO_HE]));
53842+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
53843+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
53844 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
53845- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
53846- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
53847+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
53848+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
53849 #endif
53850 }
53851
53852diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
53853index abc9c28..3fdae28 100644
53854--- a/fs/cifs/smb2pdu.c
53855+++ b/fs/cifs/smb2pdu.c
53856@@ -1946,8 +1946,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
53857 default:
53858 cifs_dbg(VFS, "info level %u isn't supported\n",
53859 srch_inf->info_level);
53860- rc = -EINVAL;
53861- goto qdir_exit;
53862+ return -EINVAL;
53863 }
53864
53865 req->FileIndex = cpu_to_le32(index);
53866diff --git a/fs/coda/cache.c b/fs/coda/cache.c
53867index 1da168c..8bc7ff6 100644
53868--- a/fs/coda/cache.c
53869+++ b/fs/coda/cache.c
53870@@ -24,7 +24,7 @@
53871 #include "coda_linux.h"
53872 #include "coda_cache.h"
53873
53874-static atomic_t permission_epoch = ATOMIC_INIT(0);
53875+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
53876
53877 /* replace or extend an acl cache hit */
53878 void coda_cache_enter(struct inode *inode, int mask)
53879@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
53880 struct coda_inode_info *cii = ITOC(inode);
53881
53882 spin_lock(&cii->c_lock);
53883- cii->c_cached_epoch = atomic_read(&permission_epoch);
53884+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
53885 if (!uid_eq(cii->c_uid, current_fsuid())) {
53886 cii->c_uid = current_fsuid();
53887 cii->c_cached_perm = mask;
53888@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
53889 {
53890 struct coda_inode_info *cii = ITOC(inode);
53891 spin_lock(&cii->c_lock);
53892- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
53893+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
53894 spin_unlock(&cii->c_lock);
53895 }
53896
53897 /* remove all acl caches */
53898 void coda_cache_clear_all(struct super_block *sb)
53899 {
53900- atomic_inc(&permission_epoch);
53901+ atomic_inc_unchecked(&permission_epoch);
53902 }
53903
53904
53905@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
53906 spin_lock(&cii->c_lock);
53907 hit = (mask & cii->c_cached_perm) == mask &&
53908 uid_eq(cii->c_uid, current_fsuid()) &&
53909- cii->c_cached_epoch == atomic_read(&permission_epoch);
53910+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
53911 spin_unlock(&cii->c_lock);
53912
53913 return hit;
53914diff --git a/fs/compat.c b/fs/compat.c
53915index 6af20de..fec3fbb 100644
53916--- a/fs/compat.c
53917+++ b/fs/compat.c
53918@@ -54,7 +54,7 @@
53919 #include <asm/ioctls.h>
53920 #include "internal.h"
53921
53922-int compat_log = 1;
53923+int compat_log = 0;
53924
53925 int compat_printk(const char *fmt, ...)
53926 {
53927@@ -488,7 +488,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
53928
53929 set_fs(KERNEL_DS);
53930 /* The __user pointer cast is valid because of the set_fs() */
53931- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
53932+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
53933 set_fs(oldfs);
53934 /* truncating is ok because it's a user address */
53935 if (!ret)
53936@@ -546,7 +546,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
53937 goto out;
53938
53939 ret = -EINVAL;
53940- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
53941+ if (nr_segs > UIO_MAXIOV)
53942 goto out;
53943 if (nr_segs > fast_segs) {
53944 ret = -ENOMEM;
53945@@ -834,6 +834,7 @@ struct compat_old_linux_dirent {
53946 struct compat_readdir_callback {
53947 struct dir_context ctx;
53948 struct compat_old_linux_dirent __user *dirent;
53949+ struct file * file;
53950 int result;
53951 };
53952
53953@@ -851,6 +852,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
53954 buf->result = -EOVERFLOW;
53955 return -EOVERFLOW;
53956 }
53957+
53958+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
53959+ return 0;
53960+
53961 buf->result++;
53962 dirent = buf->dirent;
53963 if (!access_ok(VERIFY_WRITE, dirent,
53964@@ -882,6 +887,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
53965 if (!f.file)
53966 return -EBADF;
53967
53968+ buf.file = f.file;
53969 error = iterate_dir(f.file, &buf.ctx);
53970 if (buf.result)
53971 error = buf.result;
53972@@ -901,6 +907,7 @@ struct compat_getdents_callback {
53973 struct dir_context ctx;
53974 struct compat_linux_dirent __user *current_dir;
53975 struct compat_linux_dirent __user *previous;
53976+ struct file * file;
53977 int count;
53978 int error;
53979 };
53980@@ -922,6 +929,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
53981 buf->error = -EOVERFLOW;
53982 return -EOVERFLOW;
53983 }
53984+
53985+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
53986+ return 0;
53987+
53988 dirent = buf->previous;
53989 if (dirent) {
53990 if (__put_user(offset, &dirent->d_off))
53991@@ -967,6 +978,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
53992 if (!f.file)
53993 return -EBADF;
53994
53995+ buf.file = f.file;
53996 error = iterate_dir(f.file, &buf.ctx);
53997 if (error >= 0)
53998 error = buf.error;
53999@@ -987,6 +999,7 @@ struct compat_getdents_callback64 {
54000 struct dir_context ctx;
54001 struct linux_dirent64 __user *current_dir;
54002 struct linux_dirent64 __user *previous;
54003+ struct file * file;
54004 int count;
54005 int error;
54006 };
54007@@ -1003,6 +1016,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
54008 buf->error = -EINVAL; /* only used if we fail.. */
54009 if (reclen > buf->count)
54010 return -EINVAL;
54011+
54012+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
54013+ return 0;
54014+
54015 dirent = buf->previous;
54016
54017 if (dirent) {
54018@@ -1052,6 +1069,7 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
54019 if (!f.file)
54020 return -EBADF;
54021
54022+ buf.file = f.file;
54023 error = iterate_dir(f.file, &buf.ctx);
54024 if (error >= 0)
54025 error = buf.error;
54026diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
54027index a81147e..20bf2b5 100644
54028--- a/fs/compat_binfmt_elf.c
54029+++ b/fs/compat_binfmt_elf.c
54030@@ -30,11 +30,13 @@
54031 #undef elf_phdr
54032 #undef elf_shdr
54033 #undef elf_note
54034+#undef elf_dyn
54035 #undef elf_addr_t
54036 #define elfhdr elf32_hdr
54037 #define elf_phdr elf32_phdr
54038 #define elf_shdr elf32_shdr
54039 #define elf_note elf32_note
54040+#define elf_dyn Elf32_Dyn
54041 #define elf_addr_t Elf32_Addr
54042
54043 /*
54044diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
54045index 5d19acf..9ab093b 100644
54046--- a/fs/compat_ioctl.c
54047+++ b/fs/compat_ioctl.c
54048@@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
54049 return -EFAULT;
54050 if (__get_user(udata, &ss32->iomem_base))
54051 return -EFAULT;
54052- ss.iomem_base = compat_ptr(udata);
54053+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
54054 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
54055 __get_user(ss.port_high, &ss32->port_high))
54056 return -EFAULT;
54057@@ -702,8 +702,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
54058 for (i = 0; i < nmsgs; i++) {
54059 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
54060 return -EFAULT;
54061- if (get_user(datap, &umsgs[i].buf) ||
54062- put_user(compat_ptr(datap), &tmsgs[i].buf))
54063+ if (get_user(datap, (u8 __user * __user *)&umsgs[i].buf) ||
54064+ put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
54065 return -EFAULT;
54066 }
54067 return sys_ioctl(fd, cmd, (unsigned long)tdata);
54068@@ -796,7 +796,7 @@ static int compat_ioctl_preallocate(struct file *file,
54069 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
54070 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
54071 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
54072- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
54073+ copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
54074 return -EFAULT;
54075
54076 return ioctl_preallocate(file, p);
54077@@ -1616,8 +1616,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
54078 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
54079 {
54080 unsigned int a, b;
54081- a = *(unsigned int *)p;
54082- b = *(unsigned int *)q;
54083+ a = *(const unsigned int *)p;
54084+ b = *(const unsigned int *)q;
54085 if (a > b)
54086 return 1;
54087 if (a < b)
54088diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
54089index 277bd1b..f312c9e 100644
54090--- a/fs/configfs/dir.c
54091+++ b/fs/configfs/dir.c
54092@@ -1546,7 +1546,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
54093 }
54094 for (p = q->next; p != &parent_sd->s_children; p = p->next) {
54095 struct configfs_dirent *next;
54096- const char *name;
54097+ const unsigned char * name;
54098+ char d_name[sizeof(next->s_dentry->d_iname)];
54099 int len;
54100 struct inode *inode = NULL;
54101
54102@@ -1555,7 +1556,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
54103 continue;
54104
54105 name = configfs_get_name(next);
54106- len = strlen(name);
54107+ if (next->s_dentry && name == next->s_dentry->d_iname) {
54108+ len = next->s_dentry->d_name.len;
54109+ memcpy(d_name, name, len);
54110+ name = d_name;
54111+ } else
54112+ len = strlen(name);
54113
54114 /*
54115 * We'll have a dentry and an inode for
54116diff --git a/fs/coredump.c b/fs/coredump.c
54117index 72f816d..1ba8eff 100644
54118--- a/fs/coredump.c
54119+++ b/fs/coredump.c
54120@@ -433,8 +433,8 @@ static void wait_for_dump_helpers(struct file *file)
54121 struct pipe_inode_info *pipe = file->private_data;
54122
54123 pipe_lock(pipe);
54124- pipe->readers++;
54125- pipe->writers--;
54126+ atomic_inc(&pipe->readers);
54127+ atomic_dec(&pipe->writers);
54128 wake_up_interruptible_sync(&pipe->wait);
54129 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
54130 pipe_unlock(pipe);
54131@@ -443,11 +443,11 @@ static void wait_for_dump_helpers(struct file *file)
54132 * We actually want wait_event_freezable() but then we need
54133 * to clear TIF_SIGPENDING and improve dump_interrupted().
54134 */
54135- wait_event_interruptible(pipe->wait, pipe->readers == 1);
54136+ wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
54137
54138 pipe_lock(pipe);
54139- pipe->readers--;
54140- pipe->writers++;
54141+ atomic_dec(&pipe->readers);
54142+ atomic_inc(&pipe->writers);
54143 pipe_unlock(pipe);
54144 }
54145
54146@@ -494,7 +494,8 @@ void do_coredump(siginfo_t *siginfo)
54147 struct files_struct *displaced;
54148 bool need_nonrelative = false;
54149 bool core_dumped = false;
54150- static atomic_t core_dump_count = ATOMIC_INIT(0);
54151+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
54152+ long signr = siginfo->si_signo;
54153 struct coredump_params cprm = {
54154 .siginfo = siginfo,
54155 .regs = signal_pt_regs(),
54156@@ -507,7 +508,10 @@ void do_coredump(siginfo_t *siginfo)
54157 .mm_flags = mm->flags,
54158 };
54159
54160- audit_core_dumps(siginfo->si_signo);
54161+ audit_core_dumps(signr);
54162+
54163+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
54164+ gr_handle_brute_attach(cprm.mm_flags);
54165
54166 binfmt = mm->binfmt;
54167 if (!binfmt || !binfmt->core_dump)
54168@@ -531,7 +535,7 @@ void do_coredump(siginfo_t *siginfo)
54169 need_nonrelative = true;
54170 }
54171
54172- retval = coredump_wait(siginfo->si_signo, &core_state);
54173+ retval = coredump_wait(signr, &core_state);
54174 if (retval < 0)
54175 goto fail_creds;
54176
54177@@ -574,7 +578,7 @@ void do_coredump(siginfo_t *siginfo)
54178 }
54179 cprm.limit = RLIM_INFINITY;
54180
54181- dump_count = atomic_inc_return(&core_dump_count);
54182+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
54183 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
54184 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
54185 task_tgid_vnr(current), current->comm);
54186@@ -606,6 +610,8 @@ void do_coredump(siginfo_t *siginfo)
54187 } else {
54188 struct inode *inode;
54189
54190+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
54191+
54192 if (cprm.limit < binfmt->min_coredump)
54193 goto fail_unlock;
54194
54195@@ -664,7 +670,7 @@ close_fail:
54196 filp_close(cprm.file, NULL);
54197 fail_dropcount:
54198 if (ispipe)
54199- atomic_dec(&core_dump_count);
54200+ atomic_dec_unchecked(&core_dump_count);
54201 fail_unlock:
54202 kfree(cn.corename);
54203 coredump_finish(mm, core_dumped);
54204@@ -684,7 +690,7 @@ int dump_write(struct file *file, const void *addr, int nr)
54205 {
54206 return !dump_interrupted() &&
54207 access_ok(VERIFY_READ, addr, nr) &&
54208- file->f_op->write(file, addr, nr, &file->f_pos) == nr;
54209+ file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
54210 }
54211 EXPORT_SYMBOL(dump_write);
54212
54213diff --git a/fs/dcache.c b/fs/dcache.c
54214index b949af8..5978926 100644
54215--- a/fs/dcache.c
54216+++ b/fs/dcache.c
54217@@ -3073,7 +3073,8 @@ void __init vfs_caches_init(unsigned long mempages)
54218 mempages -= reserve;
54219
54220 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
54221- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
54222+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
54223+ SLAB_NO_SANITIZE, NULL);
54224
54225 dcache_init();
54226 inode_init();
54227diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
54228index c7c83ff..bda9461 100644
54229--- a/fs/debugfs/inode.c
54230+++ b/fs/debugfs/inode.c
54231@@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
54232 */
54233 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
54234 {
54235+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
54236+ return __create_file(name, S_IFDIR | S_IRWXU,
54237+#else
54238 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
54239+#endif
54240 parent, NULL, NULL);
54241 }
54242 EXPORT_SYMBOL_GPL(debugfs_create_dir);
54243diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
54244index 67e9b63..a9adb68 100644
54245--- a/fs/ecryptfs/inode.c
54246+++ b/fs/ecryptfs/inode.c
54247@@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
54248 old_fs = get_fs();
54249 set_fs(get_ds());
54250 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
54251- (char __user *)lower_buf,
54252+ (char __force_user *)lower_buf,
54253 PATH_MAX);
54254 set_fs(old_fs);
54255 if (rc < 0)
54256@@ -706,7 +706,7 @@ out:
54257 static void
54258 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
54259 {
54260- char *buf = nd_get_link(nd);
54261+ const char *buf = nd_get_link(nd);
54262 if (!IS_ERR(buf)) {
54263 /* Free the char* */
54264 kfree(buf);
54265diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
54266index e4141f2..d8263e8 100644
54267--- a/fs/ecryptfs/miscdev.c
54268+++ b/fs/ecryptfs/miscdev.c
54269@@ -304,7 +304,7 @@ check_list:
54270 goto out_unlock_msg_ctx;
54271 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
54272 if (msg_ctx->msg) {
54273- if (copy_to_user(&buf[i], packet_length, packet_length_size))
54274+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
54275 goto out_unlock_msg_ctx;
54276 i += packet_length_size;
54277 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
54278diff --git a/fs/exec.c b/fs/exec.c
54279index fd774c7..1c6a7bf 100644
54280--- a/fs/exec.c
54281+++ b/fs/exec.c
54282@@ -55,8 +55,20 @@
54283 #include <linux/pipe_fs_i.h>
54284 #include <linux/oom.h>
54285 #include <linux/compat.h>
54286+#include <linux/random.h>
54287+#include <linux/seq_file.h>
54288+#include <linux/coredump.h>
54289+#include <linux/mman.h>
54290+
54291+#ifdef CONFIG_PAX_REFCOUNT
54292+#include <linux/kallsyms.h>
54293+#include <linux/kdebug.h>
54294+#endif
54295+
54296+#include <trace/events/fs.h>
54297
54298 #include <asm/uaccess.h>
54299+#include <asm/sections.h>
54300 #include <asm/mmu_context.h>
54301 #include <asm/tlb.h>
54302
54303@@ -66,17 +78,32 @@
54304
54305 #include <trace/events/sched.h>
54306
54307+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
54308+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
54309+{
54310+ 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");
54311+}
54312+#endif
54313+
54314+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
54315+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
54316+EXPORT_SYMBOL(pax_set_initial_flags_func);
54317+#endif
54318+
54319 int suid_dumpable = 0;
54320
54321 static LIST_HEAD(formats);
54322 static DEFINE_RWLOCK(binfmt_lock);
54323
54324+extern int gr_process_kernel_exec_ban(void);
54325+extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
54326+
54327 void __register_binfmt(struct linux_binfmt * fmt, int insert)
54328 {
54329 BUG_ON(!fmt);
54330 write_lock(&binfmt_lock);
54331- insert ? list_add(&fmt->lh, &formats) :
54332- list_add_tail(&fmt->lh, &formats);
54333+ insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
54334+ pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
54335 write_unlock(&binfmt_lock);
54336 }
54337
54338@@ -85,7 +112,7 @@ EXPORT_SYMBOL(__register_binfmt);
54339 void unregister_binfmt(struct linux_binfmt * fmt)
54340 {
54341 write_lock(&binfmt_lock);
54342- list_del(&fmt->lh);
54343+ pax_list_del((struct list_head *)&fmt->lh);
54344 write_unlock(&binfmt_lock);
54345 }
54346
54347@@ -181,18 +208,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
54348 int write)
54349 {
54350 struct page *page;
54351- int ret;
54352
54353-#ifdef CONFIG_STACK_GROWSUP
54354- if (write) {
54355- ret = expand_downwards(bprm->vma, pos);
54356- if (ret < 0)
54357- return NULL;
54358- }
54359-#endif
54360- ret = get_user_pages(current, bprm->mm, pos,
54361- 1, write, 1, &page, NULL);
54362- if (ret <= 0)
54363+ if (0 > expand_downwards(bprm->vma, pos))
54364+ return NULL;
54365+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
54366 return NULL;
54367
54368 if (write) {
54369@@ -208,6 +227,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
54370 if (size <= ARG_MAX)
54371 return page;
54372
54373+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54374+ // only allow 512KB for argv+env on suid/sgid binaries
54375+ // to prevent easy ASLR exhaustion
54376+ if (((!uid_eq(bprm->cred->euid, current_euid())) ||
54377+ (!gid_eq(bprm->cred->egid, current_egid()))) &&
54378+ (size > (512 * 1024))) {
54379+ put_page(page);
54380+ return NULL;
54381+ }
54382+#endif
54383+
54384 /*
54385 * Limit to 1/4-th the stack size for the argv+env strings.
54386 * This ensures that:
54387@@ -267,6 +297,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
54388 vma->vm_end = STACK_TOP_MAX;
54389 vma->vm_start = vma->vm_end - PAGE_SIZE;
54390 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
54391+
54392+#ifdef CONFIG_PAX_SEGMEXEC
54393+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
54394+#endif
54395+
54396 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
54397 INIT_LIST_HEAD(&vma->anon_vma_chain);
54398
54399@@ -277,6 +312,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
54400 mm->stack_vm = mm->total_vm = 1;
54401 up_write(&mm->mmap_sem);
54402 bprm->p = vma->vm_end - sizeof(void *);
54403+
54404+#ifdef CONFIG_PAX_RANDUSTACK
54405+ if (randomize_va_space)
54406+ bprm->p ^= prandom_u32() & ~PAGE_MASK;
54407+#endif
54408+
54409 return 0;
54410 err:
54411 up_write(&mm->mmap_sem);
54412@@ -397,7 +438,7 @@ struct user_arg_ptr {
54413 } ptr;
54414 };
54415
54416-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
54417+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
54418 {
54419 const char __user *native;
54420
54421@@ -406,14 +447,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
54422 compat_uptr_t compat;
54423
54424 if (get_user(compat, argv.ptr.compat + nr))
54425- return ERR_PTR(-EFAULT);
54426+ return (const char __force_user *)ERR_PTR(-EFAULT);
54427
54428 return compat_ptr(compat);
54429 }
54430 #endif
54431
54432 if (get_user(native, argv.ptr.native + nr))
54433- return ERR_PTR(-EFAULT);
54434+ return (const char __force_user *)ERR_PTR(-EFAULT);
54435
54436 return native;
54437 }
54438@@ -432,7 +473,7 @@ static int count(struct user_arg_ptr argv, int max)
54439 if (!p)
54440 break;
54441
54442- if (IS_ERR(p))
54443+ if (IS_ERR((const char __force_kernel *)p))
54444 return -EFAULT;
54445
54446 if (i >= max)
54447@@ -467,7 +508,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
54448
54449 ret = -EFAULT;
54450 str = get_user_arg_ptr(argv, argc);
54451- if (IS_ERR(str))
54452+ if (IS_ERR((const char __force_kernel *)str))
54453 goto out;
54454
54455 len = strnlen_user(str, MAX_ARG_STRLEN);
54456@@ -549,7 +590,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
54457 int r;
54458 mm_segment_t oldfs = get_fs();
54459 struct user_arg_ptr argv = {
54460- .ptr.native = (const char __user *const __user *)__argv,
54461+ .ptr.native = (const char __force_user * const __force_user *)__argv,
54462 };
54463
54464 set_fs(KERNEL_DS);
54465@@ -584,7 +625,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
54466 unsigned long new_end = old_end - shift;
54467 struct mmu_gather tlb;
54468
54469- BUG_ON(new_start > new_end);
54470+ if (new_start >= new_end || new_start < mmap_min_addr)
54471+ return -ENOMEM;
54472
54473 /*
54474 * ensure there are no vmas between where we want to go
54475@@ -593,6 +635,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
54476 if (vma != find_vma(mm, new_start))
54477 return -EFAULT;
54478
54479+#ifdef CONFIG_PAX_SEGMEXEC
54480+ BUG_ON(pax_find_mirror_vma(vma));
54481+#endif
54482+
54483 /*
54484 * cover the whole range: [new_start, old_end)
54485 */
54486@@ -673,10 +719,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
54487 stack_top = arch_align_stack(stack_top);
54488 stack_top = PAGE_ALIGN(stack_top);
54489
54490- if (unlikely(stack_top < mmap_min_addr) ||
54491- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
54492- return -ENOMEM;
54493-
54494 stack_shift = vma->vm_end - stack_top;
54495
54496 bprm->p -= stack_shift;
54497@@ -688,8 +730,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
54498 bprm->exec -= stack_shift;
54499
54500 down_write(&mm->mmap_sem);
54501+
54502+ /* Move stack pages down in memory. */
54503+ if (stack_shift) {
54504+ ret = shift_arg_pages(vma, stack_shift);
54505+ if (ret)
54506+ goto out_unlock;
54507+ }
54508+
54509 vm_flags = VM_STACK_FLAGS;
54510
54511+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
54512+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
54513+ vm_flags &= ~VM_EXEC;
54514+
54515+#ifdef CONFIG_PAX_MPROTECT
54516+ if (mm->pax_flags & MF_PAX_MPROTECT)
54517+ vm_flags &= ~VM_MAYEXEC;
54518+#endif
54519+
54520+ }
54521+#endif
54522+
54523 /*
54524 * Adjust stack execute permissions; explicitly enable for
54525 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
54526@@ -708,13 +770,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
54527 goto out_unlock;
54528 BUG_ON(prev != vma);
54529
54530- /* Move stack pages down in memory. */
54531- if (stack_shift) {
54532- ret = shift_arg_pages(vma, stack_shift);
54533- if (ret)
54534- goto out_unlock;
54535- }
54536-
54537 /* mprotect_fixup is overkill to remove the temporary stack flags */
54538 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
54539
54540@@ -738,6 +793,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
54541 #endif
54542 current->mm->start_stack = bprm->p;
54543 ret = expand_stack(vma, stack_base);
54544+
54545+#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
54546+ if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
54547+ unsigned long size;
54548+ vm_flags_t vm_flags;
54549+
54550+ size = STACK_TOP - vma->vm_end;
54551+ vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
54552+
54553+ ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
54554+
54555+#ifdef CONFIG_X86
54556+ if (!ret) {
54557+ size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
54558+ ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
54559+ }
54560+#endif
54561+
54562+ }
54563+#endif
54564+
54565 if (ret)
54566 ret = -EFAULT;
54567
54568@@ -774,6 +850,8 @@ struct file *open_exec(const char *name)
54569
54570 fsnotify_open(file);
54571
54572+ trace_open_exec(name);
54573+
54574 err = deny_write_access(file);
54575 if (err)
54576 goto exit;
54577@@ -797,7 +875,7 @@ int kernel_read(struct file *file, loff_t offset,
54578 old_fs = get_fs();
54579 set_fs(get_ds());
54580 /* The cast to a user pointer is valid due to the set_fs() */
54581- result = vfs_read(file, (void __user *)addr, count, &pos);
54582+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
54583 set_fs(old_fs);
54584 return result;
54585 }
54586@@ -1253,7 +1331,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
54587 }
54588 rcu_read_unlock();
54589
54590- if (p->fs->users > n_fs) {
54591+ if (atomic_read(&p->fs->users) > n_fs) {
54592 bprm->unsafe |= LSM_UNSAFE_SHARE;
54593 } else {
54594 res = -EAGAIN;
54595@@ -1453,6 +1531,31 @@ int search_binary_handler(struct linux_binprm *bprm)
54596
54597 EXPORT_SYMBOL(search_binary_handler);
54598
54599+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54600+static DEFINE_PER_CPU(u64, exec_counter);
54601+static int __init init_exec_counters(void)
54602+{
54603+ unsigned int cpu;
54604+
54605+ for_each_possible_cpu(cpu) {
54606+ per_cpu(exec_counter, cpu) = (u64)cpu;
54607+ }
54608+
54609+ return 0;
54610+}
54611+early_initcall(init_exec_counters);
54612+static inline void increment_exec_counter(void)
54613+{
54614+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
54615+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
54616+}
54617+#else
54618+static inline void increment_exec_counter(void) {}
54619+#endif
54620+
54621+extern void gr_handle_exec_args(struct linux_binprm *bprm,
54622+ struct user_arg_ptr argv);
54623+
54624 /*
54625 * sys_execve() executes a new program.
54626 */
54627@@ -1460,12 +1563,19 @@ static int do_execve_common(const char *filename,
54628 struct user_arg_ptr argv,
54629 struct user_arg_ptr envp)
54630 {
54631+#ifdef CONFIG_GRKERNSEC
54632+ struct file *old_exec_file;
54633+ struct acl_subject_label *old_acl;
54634+ struct rlimit old_rlim[RLIM_NLIMITS];
54635+#endif
54636 struct linux_binprm *bprm;
54637 struct file *file;
54638 struct files_struct *displaced;
54639 bool clear_in_exec;
54640 int retval;
54641
54642+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
54643+
54644 /*
54645 * We move the actual failure in case of RLIMIT_NPROC excess from
54646 * set*uid() to execve() because too many poorly written programs
54647@@ -1506,12 +1616,22 @@ static int do_execve_common(const char *filename,
54648 if (IS_ERR(file))
54649 goto out_unmark;
54650
54651+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
54652+ retval = -EPERM;
54653+ goto out_file;
54654+ }
54655+
54656 sched_exec();
54657
54658 bprm->file = file;
54659 bprm->filename = filename;
54660 bprm->interp = filename;
54661
54662+ if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
54663+ retval = -EACCES;
54664+ goto out_file;
54665+ }
54666+
54667 retval = bprm_mm_init(bprm);
54668 if (retval)
54669 goto out_file;
54670@@ -1528,24 +1648,70 @@ static int do_execve_common(const char *filename,
54671 if (retval < 0)
54672 goto out;
54673
54674+#ifdef CONFIG_GRKERNSEC
54675+ old_acl = current->acl;
54676+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
54677+ old_exec_file = current->exec_file;
54678+ get_file(file);
54679+ current->exec_file = file;
54680+#endif
54681+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54682+ /* limit suid stack to 8MB
54683+ * we saved the old limits above and will restore them if this exec fails
54684+ */
54685+ if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
54686+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
54687+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
54688+#endif
54689+
54690+ if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
54691+ retval = -EPERM;
54692+ goto out_fail;
54693+ }
54694+
54695+ if (!gr_tpe_allow(file)) {
54696+ retval = -EACCES;
54697+ goto out_fail;
54698+ }
54699+
54700+ if (gr_check_crash_exec(file)) {
54701+ retval = -EACCES;
54702+ goto out_fail;
54703+ }
54704+
54705+ retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
54706+ bprm->unsafe);
54707+ if (retval < 0)
54708+ goto out_fail;
54709+
54710 retval = copy_strings_kernel(1, &bprm->filename, bprm);
54711 if (retval < 0)
54712- goto out;
54713+ goto out_fail;
54714
54715 bprm->exec = bprm->p;
54716 retval = copy_strings(bprm->envc, envp, bprm);
54717 if (retval < 0)
54718- goto out;
54719+ goto out_fail;
54720
54721 retval = copy_strings(bprm->argc, argv, bprm);
54722 if (retval < 0)
54723- goto out;
54724+ goto out_fail;
54725+
54726+ gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
54727+
54728+ gr_handle_exec_args(bprm, argv);
54729
54730 retval = search_binary_handler(bprm);
54731 if (retval < 0)
54732- goto out;
54733+ goto out_fail;
54734+#ifdef CONFIG_GRKERNSEC
54735+ if (old_exec_file)
54736+ fput(old_exec_file);
54737+#endif
54738
54739 /* execve succeeded */
54740+
54741+ increment_exec_counter();
54742 current->fs->in_exec = 0;
54743 current->in_execve = 0;
54744 acct_update_integrals(current);
54745@@ -1554,6 +1720,14 @@ static int do_execve_common(const char *filename,
54746 put_files_struct(displaced);
54747 return retval;
54748
54749+out_fail:
54750+#ifdef CONFIG_GRKERNSEC
54751+ current->acl = old_acl;
54752+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
54753+ fput(current->exec_file);
54754+ current->exec_file = old_exec_file;
54755+#endif
54756+
54757 out:
54758 if (bprm->mm) {
54759 acct_arg_size(bprm, 0);
54760@@ -1702,3 +1876,287 @@ asmlinkage long compat_sys_execve(const char __user * filename,
54761 return error;
54762 }
54763 #endif
54764+
54765+int pax_check_flags(unsigned long *flags)
54766+{
54767+ int retval = 0;
54768+
54769+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
54770+ if (*flags & MF_PAX_SEGMEXEC)
54771+ {
54772+ *flags &= ~MF_PAX_SEGMEXEC;
54773+ retval = -EINVAL;
54774+ }
54775+#endif
54776+
54777+ if ((*flags & MF_PAX_PAGEEXEC)
54778+
54779+#ifdef CONFIG_PAX_PAGEEXEC
54780+ && (*flags & MF_PAX_SEGMEXEC)
54781+#endif
54782+
54783+ )
54784+ {
54785+ *flags &= ~MF_PAX_PAGEEXEC;
54786+ retval = -EINVAL;
54787+ }
54788+
54789+ if ((*flags & MF_PAX_MPROTECT)
54790+
54791+#ifdef CONFIG_PAX_MPROTECT
54792+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
54793+#endif
54794+
54795+ )
54796+ {
54797+ *flags &= ~MF_PAX_MPROTECT;
54798+ retval = -EINVAL;
54799+ }
54800+
54801+ if ((*flags & MF_PAX_EMUTRAMP)
54802+
54803+#ifdef CONFIG_PAX_EMUTRAMP
54804+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
54805+#endif
54806+
54807+ )
54808+ {
54809+ *flags &= ~MF_PAX_EMUTRAMP;
54810+ retval = -EINVAL;
54811+ }
54812+
54813+ return retval;
54814+}
54815+
54816+EXPORT_SYMBOL(pax_check_flags);
54817+
54818+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
54819+char *pax_get_path(const struct path *path, char *buf, int buflen)
54820+{
54821+ char *pathname = d_path(path, buf, buflen);
54822+
54823+ if (IS_ERR(pathname))
54824+ goto toolong;
54825+
54826+ pathname = mangle_path(buf, pathname, "\t\n\\");
54827+ if (!pathname)
54828+ goto toolong;
54829+
54830+ *pathname = 0;
54831+ return buf;
54832+
54833+toolong:
54834+ return "<path too long>";
54835+}
54836+EXPORT_SYMBOL(pax_get_path);
54837+
54838+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
54839+{
54840+ struct task_struct *tsk = current;
54841+ struct mm_struct *mm = current->mm;
54842+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
54843+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
54844+ char *path_exec = NULL;
54845+ char *path_fault = NULL;
54846+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
54847+ siginfo_t info = { };
54848+
54849+ if (buffer_exec && buffer_fault) {
54850+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
54851+
54852+ down_read(&mm->mmap_sem);
54853+ vma = mm->mmap;
54854+ while (vma && (!vma_exec || !vma_fault)) {
54855+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
54856+ vma_exec = vma;
54857+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
54858+ vma_fault = vma;
54859+ vma = vma->vm_next;
54860+ }
54861+ if (vma_exec)
54862+ path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
54863+ if (vma_fault) {
54864+ start = vma_fault->vm_start;
54865+ end = vma_fault->vm_end;
54866+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
54867+ if (vma_fault->vm_file)
54868+ path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
54869+ else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
54870+ path_fault = "<heap>";
54871+ else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
54872+ path_fault = "<stack>";
54873+ else
54874+ path_fault = "<anonymous mapping>";
54875+ }
54876+ up_read(&mm->mmap_sem);
54877+ }
54878+ if (tsk->signal->curr_ip)
54879+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
54880+ else
54881+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
54882+ 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),
54883+ from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
54884+ free_page((unsigned long)buffer_exec);
54885+ free_page((unsigned long)buffer_fault);
54886+ pax_report_insns(regs, pc, sp);
54887+ info.si_signo = SIGKILL;
54888+ info.si_errno = 0;
54889+ info.si_code = SI_KERNEL;
54890+ info.si_pid = 0;
54891+ info.si_uid = 0;
54892+ do_coredump(&info);
54893+}
54894+#endif
54895+
54896+#ifdef CONFIG_PAX_REFCOUNT
54897+void pax_report_refcount_overflow(struct pt_regs *regs)
54898+{
54899+ if (current->signal->curr_ip)
54900+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
54901+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
54902+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
54903+ else
54904+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
54905+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
54906+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
54907+ preempt_disable();
54908+ show_regs(regs);
54909+ preempt_enable();
54910+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
54911+}
54912+#endif
54913+
54914+#ifdef CONFIG_PAX_USERCOPY
54915+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
54916+static noinline int check_stack_object(const void *obj, unsigned long len)
54917+{
54918+ const void * const stack = task_stack_page(current);
54919+ const void * const stackend = stack + THREAD_SIZE;
54920+
54921+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
54922+ const void *frame = NULL;
54923+ const void *oldframe;
54924+#endif
54925+
54926+ if (obj + len < obj)
54927+ return -1;
54928+
54929+ if (obj + len <= stack || stackend <= obj)
54930+ return 0;
54931+
54932+ if (obj < stack || stackend < obj + len)
54933+ return -1;
54934+
54935+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
54936+ oldframe = __builtin_frame_address(1);
54937+ if (oldframe)
54938+ frame = __builtin_frame_address(2);
54939+ /*
54940+ low ----------------------------------------------> high
54941+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
54942+ ^----------------^
54943+ allow copies only within here
54944+ */
54945+ while (stack <= frame && frame < stackend) {
54946+ /* if obj + len extends past the last frame, this
54947+ check won't pass and the next frame will be 0,
54948+ causing us to bail out and correctly report
54949+ the copy as invalid
54950+ */
54951+ if (obj + len <= frame)
54952+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
54953+ oldframe = frame;
54954+ frame = *(const void * const *)frame;
54955+ }
54956+ return -1;
54957+#else
54958+ return 1;
54959+#endif
54960+}
54961+
54962+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
54963+{
54964+ if (current->signal->curr_ip)
54965+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
54966+ &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
54967+ else
54968+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
54969+ to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
54970+ dump_stack();
54971+ gr_handle_kernel_exploit();
54972+ do_group_exit(SIGKILL);
54973+}
54974+#endif
54975+
54976+#ifdef CONFIG_PAX_USERCOPY
54977+static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
54978+{
54979+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
54980+ unsigned long textlow = ktla_ktva((unsigned long)_stext);
54981+#ifdef CONFIG_MODULES
54982+ unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
54983+#else
54984+ unsigned long texthigh = ktla_ktva((unsigned long)_etext);
54985+#endif
54986+
54987+#else
54988+ unsigned long textlow = (unsigned long)_stext;
54989+ unsigned long texthigh = (unsigned long)_etext;
54990+#endif
54991+
54992+ if (high <= textlow || low > texthigh)
54993+ return false;
54994+ else
54995+ return true;
54996+}
54997+#endif
54998+
54999+void __check_object_size(const void *ptr, unsigned long n, bool to_user)
55000+{
55001+
55002+#ifdef CONFIG_PAX_USERCOPY
55003+ const char *type;
55004+
55005+ if (!n)
55006+ return;
55007+
55008+ type = check_heap_object(ptr, n);
55009+ if (!type) {
55010+ int ret = check_stack_object(ptr, n);
55011+ if (ret == 1 || ret == 2)
55012+ return;
55013+ if (ret == 0) {
55014+ if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
55015+ type = "<kernel text>";
55016+ else
55017+ return;
55018+ } else
55019+ type = "<process stack>";
55020+ }
55021+
55022+ pax_report_usercopy(ptr, n, to_user, type);
55023+#endif
55024+
55025+}
55026+EXPORT_SYMBOL(__check_object_size);
55027+
55028+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
55029+void pax_track_stack(void)
55030+{
55031+ unsigned long sp = (unsigned long)&sp;
55032+ if (sp < current_thread_info()->lowest_stack &&
55033+ sp > (unsigned long)task_stack_page(current))
55034+ current_thread_info()->lowest_stack = sp;
55035+}
55036+EXPORT_SYMBOL(pax_track_stack);
55037+#endif
55038+
55039+#ifdef CONFIG_PAX_SIZE_OVERFLOW
55040+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
55041+{
55042+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
55043+ dump_stack();
55044+ do_group_exit(SIGKILL);
55045+}
55046+EXPORT_SYMBOL(report_size_overflow);
55047+#endif
55048diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
55049index 9f9992b..8b59411 100644
55050--- a/fs/ext2/balloc.c
55051+++ b/fs/ext2/balloc.c
55052@@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
55053
55054 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
55055 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
55056- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
55057+ if (free_blocks < root_blocks + 1 &&
55058 !uid_eq(sbi->s_resuid, current_fsuid()) &&
55059 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
55060- !in_group_p (sbi->s_resgid))) {
55061+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
55062 return 0;
55063 }
55064 return 1;
55065diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
55066index 22548f5..41521d8 100644
55067--- a/fs/ext3/balloc.c
55068+++ b/fs/ext3/balloc.c
55069@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
55070
55071 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
55072 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
55073- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
55074+ if (free_blocks < root_blocks + 1 &&
55075 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
55076 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
55077- !in_group_p (sbi->s_resgid))) {
55078+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
55079 return 0;
55080 }
55081 return 1;
55082diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
55083index ddd715e..c772f88 100644
55084--- a/fs/ext4/balloc.c
55085+++ b/fs/ext4/balloc.c
55086@@ -528,8 +528,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
55087 /* Hm, nope. Are (enough) root reserved clusters available? */
55088 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
55089 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
55090- capable(CAP_SYS_RESOURCE) ||
55091- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
55092+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
55093+ capable_nolog(CAP_SYS_RESOURCE)) {
55094
55095 if (free_clusters >= (nclusters + dirty_clusters +
55096 resv_clusters))
55097diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
55098index 0ab26fb..b6ecb39 100644
55099--- a/fs/ext4/ext4.h
55100+++ b/fs/ext4/ext4.h
55101@@ -1247,19 +1247,19 @@ struct ext4_sb_info {
55102 unsigned long s_mb_last_start;
55103
55104 /* stats for buddy allocator */
55105- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
55106- atomic_t s_bal_success; /* we found long enough chunks */
55107- atomic_t s_bal_allocated; /* in blocks */
55108- atomic_t s_bal_ex_scanned; /* total extents scanned */
55109- atomic_t s_bal_goals; /* goal hits */
55110- atomic_t s_bal_breaks; /* too long searches */
55111- atomic_t s_bal_2orders; /* 2^order hits */
55112+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
55113+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
55114+ atomic_unchecked_t s_bal_allocated; /* in blocks */
55115+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
55116+ atomic_unchecked_t s_bal_goals; /* goal hits */
55117+ atomic_unchecked_t s_bal_breaks; /* too long searches */
55118+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
55119 spinlock_t s_bal_lock;
55120 unsigned long s_mb_buddies_generated;
55121 unsigned long long s_mb_generation_time;
55122- atomic_t s_mb_lost_chunks;
55123- atomic_t s_mb_preallocated;
55124- atomic_t s_mb_discarded;
55125+ atomic_unchecked_t s_mb_lost_chunks;
55126+ atomic_unchecked_t s_mb_preallocated;
55127+ atomic_unchecked_t s_mb_discarded;
55128 atomic_t s_lock_busy;
55129
55130 /* locality groups */
55131diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
55132index 4bbbf13b..dcceaeb 100644
55133--- a/fs/ext4/mballoc.c
55134+++ b/fs/ext4/mballoc.c
55135@@ -1865,7 +1865,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
55136 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
55137
55138 if (EXT4_SB(sb)->s_mb_stats)
55139- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
55140+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
55141
55142 break;
55143 }
55144@@ -2171,7 +2171,7 @@ repeat:
55145 ac->ac_status = AC_STATUS_CONTINUE;
55146 ac->ac_flags |= EXT4_MB_HINT_FIRST;
55147 cr = 3;
55148- atomic_inc(&sbi->s_mb_lost_chunks);
55149+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
55150 goto repeat;
55151 }
55152 }
55153@@ -2679,25 +2679,25 @@ int ext4_mb_release(struct super_block *sb)
55154 if (sbi->s_mb_stats) {
55155 ext4_msg(sb, KERN_INFO,
55156 "mballoc: %u blocks %u reqs (%u success)",
55157- atomic_read(&sbi->s_bal_allocated),
55158- atomic_read(&sbi->s_bal_reqs),
55159- atomic_read(&sbi->s_bal_success));
55160+ atomic_read_unchecked(&sbi->s_bal_allocated),
55161+ atomic_read_unchecked(&sbi->s_bal_reqs),
55162+ atomic_read_unchecked(&sbi->s_bal_success));
55163 ext4_msg(sb, KERN_INFO,
55164 "mballoc: %u extents scanned, %u goal hits, "
55165 "%u 2^N hits, %u breaks, %u lost",
55166- atomic_read(&sbi->s_bal_ex_scanned),
55167- atomic_read(&sbi->s_bal_goals),
55168- atomic_read(&sbi->s_bal_2orders),
55169- atomic_read(&sbi->s_bal_breaks),
55170- atomic_read(&sbi->s_mb_lost_chunks));
55171+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
55172+ atomic_read_unchecked(&sbi->s_bal_goals),
55173+ atomic_read_unchecked(&sbi->s_bal_2orders),
55174+ atomic_read_unchecked(&sbi->s_bal_breaks),
55175+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
55176 ext4_msg(sb, KERN_INFO,
55177 "mballoc: %lu generated and it took %Lu",
55178 sbi->s_mb_buddies_generated,
55179 sbi->s_mb_generation_time);
55180 ext4_msg(sb, KERN_INFO,
55181 "mballoc: %u preallocated, %u discarded",
55182- atomic_read(&sbi->s_mb_preallocated),
55183- atomic_read(&sbi->s_mb_discarded));
55184+ atomic_read_unchecked(&sbi->s_mb_preallocated),
55185+ atomic_read_unchecked(&sbi->s_mb_discarded));
55186 }
55187
55188 free_percpu(sbi->s_locality_groups);
55189@@ -3151,16 +3151,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
55190 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
55191
55192 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
55193- atomic_inc(&sbi->s_bal_reqs);
55194- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
55195+ atomic_inc_unchecked(&sbi->s_bal_reqs);
55196+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
55197 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
55198- atomic_inc(&sbi->s_bal_success);
55199- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
55200+ atomic_inc_unchecked(&sbi->s_bal_success);
55201+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
55202 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
55203 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
55204- atomic_inc(&sbi->s_bal_goals);
55205+ atomic_inc_unchecked(&sbi->s_bal_goals);
55206 if (ac->ac_found > sbi->s_mb_max_to_scan)
55207- atomic_inc(&sbi->s_bal_breaks);
55208+ atomic_inc_unchecked(&sbi->s_bal_breaks);
55209 }
55210
55211 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
55212@@ -3560,7 +3560,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
55213 trace_ext4_mb_new_inode_pa(ac, pa);
55214
55215 ext4_mb_use_inode_pa(ac, pa);
55216- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
55217+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
55218
55219 ei = EXT4_I(ac->ac_inode);
55220 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
55221@@ -3620,7 +3620,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
55222 trace_ext4_mb_new_group_pa(ac, pa);
55223
55224 ext4_mb_use_group_pa(ac, pa);
55225- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
55226+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
55227
55228 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
55229 lg = ac->ac_lg;
55230@@ -3709,7 +3709,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
55231 * from the bitmap and continue.
55232 */
55233 }
55234- atomic_add(free, &sbi->s_mb_discarded);
55235+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
55236
55237 return err;
55238 }
55239@@ -3727,7 +3727,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
55240 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
55241 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
55242 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
55243- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
55244+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
55245 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
55246
55247 return 0;
55248diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
55249index 214461e..3614c89 100644
55250--- a/fs/ext4/mmp.c
55251+++ b/fs/ext4/mmp.c
55252@@ -113,7 +113,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
55253 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
55254 const char *function, unsigned int line, const char *msg)
55255 {
55256- __ext4_warning(sb, function, line, msg);
55257+ __ext4_warning(sb, function, line, "%s", msg);
55258 __ext4_warning(sb, function, line,
55259 "MMP failure info: last update time: %llu, last update "
55260 "node: %s, last update device: %s\n",
55261diff --git a/fs/ext4/super.c b/fs/ext4/super.c
55262index b59373b..f41c2b5 100644
55263--- a/fs/ext4/super.c
55264+++ b/fs/ext4/super.c
55265@@ -1254,7 +1254,7 @@ static ext4_fsblk_t get_sb_block(void **data)
55266 }
55267
55268 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
55269-static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
55270+static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
55271 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
55272
55273 #ifdef CONFIG_QUOTA
55274@@ -2394,7 +2394,7 @@ struct ext4_attr {
55275 int offset;
55276 int deprecated_val;
55277 } u;
55278-};
55279+} __do_const;
55280
55281 static int parse_strtoull(const char *buf,
55282 unsigned long long max, unsigned long long *value)
55283diff --git a/fs/fcntl.c b/fs/fcntl.c
55284index 65343c3..9969dcf 100644
55285--- a/fs/fcntl.c
55286+++ b/fs/fcntl.c
55287@@ -107,6 +107,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
55288 if (err)
55289 return err;
55290
55291+ if (gr_handle_chroot_fowner(pid, type))
55292+ return -ENOENT;
55293+ if (gr_check_protected_task_fowner(pid, type))
55294+ return -EACCES;
55295+
55296 f_modown(filp, pid, type, force);
55297 return 0;
55298 }
55299diff --git a/fs/fhandle.c b/fs/fhandle.c
55300index 999ff5c..41f4109 100644
55301--- a/fs/fhandle.c
55302+++ b/fs/fhandle.c
55303@@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
55304 } else
55305 retval = 0;
55306 /* copy the mount id */
55307- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
55308- sizeof(*mnt_id)) ||
55309+ if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
55310 copy_to_user(ufh, handle,
55311 sizeof(struct file_handle) + handle_bytes))
55312 retval = -EFAULT;
55313diff --git a/fs/file.c b/fs/file.c
55314index 4a78f98..9447397 100644
55315--- a/fs/file.c
55316+++ b/fs/file.c
55317@@ -16,6 +16,7 @@
55318 #include <linux/slab.h>
55319 #include <linux/vmalloc.h>
55320 #include <linux/file.h>
55321+#include <linux/security.h>
55322 #include <linux/fdtable.h>
55323 #include <linux/bitops.h>
55324 #include <linux/interrupt.h>
55325@@ -828,6 +829,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
55326 if (!file)
55327 return __close_fd(files, fd);
55328
55329+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
55330 if (fd >= rlimit(RLIMIT_NOFILE))
55331 return -EBADF;
55332
55333@@ -854,6 +856,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
55334 if (unlikely(oldfd == newfd))
55335 return -EINVAL;
55336
55337+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
55338 if (newfd >= rlimit(RLIMIT_NOFILE))
55339 return -EBADF;
55340
55341@@ -909,6 +912,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
55342 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
55343 {
55344 int err;
55345+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
55346 if (from >= rlimit(RLIMIT_NOFILE))
55347 return -EINVAL;
55348 err = alloc_fd(from, flags);
55349diff --git a/fs/filesystems.c b/fs/filesystems.c
55350index 92567d9..fcd8cbf 100644
55351--- a/fs/filesystems.c
55352+++ b/fs/filesystems.c
55353@@ -273,7 +273,11 @@ struct file_system_type *get_fs_type(const char *name)
55354 int len = dot ? dot - name : strlen(name);
55355
55356 fs = __get_fs_type(name, len);
55357+#ifdef CONFIG_GRKERNSEC_MODHARDEN
55358+ if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
55359+#else
55360 if (!fs && (request_module("fs-%.*s", len, name) == 0))
55361+#endif
55362 fs = __get_fs_type(name, len);
55363
55364 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
55365diff --git a/fs/fs_struct.c b/fs/fs_struct.c
55366index d8ac61d..79a36f0 100644
55367--- a/fs/fs_struct.c
55368+++ b/fs/fs_struct.c
55369@@ -4,6 +4,7 @@
55370 #include <linux/path.h>
55371 #include <linux/slab.h>
55372 #include <linux/fs_struct.h>
55373+#include <linux/grsecurity.h>
55374 #include "internal.h"
55375
55376 /*
55377@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
55378 write_seqcount_begin(&fs->seq);
55379 old_root = fs->root;
55380 fs->root = *path;
55381+ gr_set_chroot_entries(current, path);
55382 write_seqcount_end(&fs->seq);
55383 spin_unlock(&fs->lock);
55384 if (old_root.dentry)
55385@@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
55386 int hits = 0;
55387 spin_lock(&fs->lock);
55388 write_seqcount_begin(&fs->seq);
55389+ /* this root replacement is only done by pivot_root,
55390+ leave grsec's chroot tagging alone for this task
55391+ so that a pivoted root isn't treated as a chroot
55392+ */
55393 hits += replace_path(&fs->root, old_root, new_root);
55394 hits += replace_path(&fs->pwd, old_root, new_root);
55395 write_seqcount_end(&fs->seq);
55396@@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
55397 task_lock(tsk);
55398 spin_lock(&fs->lock);
55399 tsk->fs = NULL;
55400- kill = !--fs->users;
55401+ gr_clear_chroot_entries(tsk);
55402+ kill = !atomic_dec_return(&fs->users);
55403 spin_unlock(&fs->lock);
55404 task_unlock(tsk);
55405 if (kill)
55406@@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
55407 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
55408 /* We don't need to lock fs - think why ;-) */
55409 if (fs) {
55410- fs->users = 1;
55411+ atomic_set(&fs->users, 1);
55412 fs->in_exec = 0;
55413 spin_lock_init(&fs->lock);
55414 seqcount_init(&fs->seq);
55415@@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
55416 spin_lock(&old->lock);
55417 fs->root = old->root;
55418 path_get(&fs->root);
55419+ /* instead of calling gr_set_chroot_entries here,
55420+ we call it from every caller of this function
55421+ */
55422 fs->pwd = old->pwd;
55423 path_get(&fs->pwd);
55424 spin_unlock(&old->lock);
55425@@ -139,8 +149,9 @@ int unshare_fs_struct(void)
55426
55427 task_lock(current);
55428 spin_lock(&fs->lock);
55429- kill = !--fs->users;
55430+ kill = !atomic_dec_return(&fs->users);
55431 current->fs = new_fs;
55432+ gr_set_chroot_entries(current, &new_fs->root);
55433 spin_unlock(&fs->lock);
55434 task_unlock(current);
55435
55436@@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
55437
55438 int current_umask(void)
55439 {
55440- return current->fs->umask;
55441+ return current->fs->umask | gr_acl_umask();
55442 }
55443 EXPORT_SYMBOL(current_umask);
55444
55445 /* to be mentioned only in INIT_TASK */
55446 struct fs_struct init_fs = {
55447- .users = 1,
55448+ .users = ATOMIC_INIT(1),
55449 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
55450 .seq = SEQCNT_ZERO,
55451 .umask = 0022,
55452diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
55453index 0e91a3c..6c6d2e0 100644
55454--- a/fs/fscache/cookie.c
55455+++ b/fs/fscache/cookie.c
55456@@ -19,7 +19,7 @@
55457
55458 struct kmem_cache *fscache_cookie_jar;
55459
55460-static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
55461+static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
55462
55463 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
55464 static int fscache_alloc_object(struct fscache_cache *cache,
55465@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
55466 parent ? (char *) parent->def->name : "<no-parent>",
55467 def->name, netfs_data);
55468
55469- fscache_stat(&fscache_n_acquires);
55470+ fscache_stat_unchecked(&fscache_n_acquires);
55471
55472 /* if there's no parent cookie, then we don't create one here either */
55473 if (!parent) {
55474- fscache_stat(&fscache_n_acquires_null);
55475+ fscache_stat_unchecked(&fscache_n_acquires_null);
55476 _leave(" [no parent]");
55477 return NULL;
55478 }
55479@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
55480 /* allocate and initialise a cookie */
55481 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
55482 if (!cookie) {
55483- fscache_stat(&fscache_n_acquires_oom);
55484+ fscache_stat_unchecked(&fscache_n_acquires_oom);
55485 _leave(" [ENOMEM]");
55486 return NULL;
55487 }
55488@@ -114,13 +114,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
55489
55490 switch (cookie->def->type) {
55491 case FSCACHE_COOKIE_TYPE_INDEX:
55492- fscache_stat(&fscache_n_cookie_index);
55493+ fscache_stat_unchecked(&fscache_n_cookie_index);
55494 break;
55495 case FSCACHE_COOKIE_TYPE_DATAFILE:
55496- fscache_stat(&fscache_n_cookie_data);
55497+ fscache_stat_unchecked(&fscache_n_cookie_data);
55498 break;
55499 default:
55500- fscache_stat(&fscache_n_cookie_special);
55501+ fscache_stat_unchecked(&fscache_n_cookie_special);
55502 break;
55503 }
55504
55505@@ -131,13 +131,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
55506 if (fscache_acquire_non_index_cookie(cookie) < 0) {
55507 atomic_dec(&parent->n_children);
55508 __fscache_cookie_put(cookie);
55509- fscache_stat(&fscache_n_acquires_nobufs);
55510+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
55511 _leave(" = NULL");
55512 return NULL;
55513 }
55514 }
55515
55516- fscache_stat(&fscache_n_acquires_ok);
55517+ fscache_stat_unchecked(&fscache_n_acquires_ok);
55518 _leave(" = %p", cookie);
55519 return cookie;
55520 }
55521@@ -173,7 +173,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
55522 cache = fscache_select_cache_for_object(cookie->parent);
55523 if (!cache) {
55524 up_read(&fscache_addremove_sem);
55525- fscache_stat(&fscache_n_acquires_no_cache);
55526+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
55527 _leave(" = -ENOMEDIUM [no cache]");
55528 return -ENOMEDIUM;
55529 }
55530@@ -259,14 +259,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
55531 object = cache->ops->alloc_object(cache, cookie);
55532 fscache_stat_d(&fscache_n_cop_alloc_object);
55533 if (IS_ERR(object)) {
55534- fscache_stat(&fscache_n_object_no_alloc);
55535+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
55536 ret = PTR_ERR(object);
55537 goto error;
55538 }
55539
55540- fscache_stat(&fscache_n_object_alloc);
55541+ fscache_stat_unchecked(&fscache_n_object_alloc);
55542
55543- object->debug_id = atomic_inc_return(&fscache_object_debug_id);
55544+ object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
55545
55546 _debug("ALLOC OBJ%x: %s {%lx}",
55547 object->debug_id, cookie->def->name, object->events);
55548@@ -380,7 +380,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
55549
55550 _enter("{%s}", cookie->def->name);
55551
55552- fscache_stat(&fscache_n_invalidates);
55553+ fscache_stat_unchecked(&fscache_n_invalidates);
55554
55555 /* Only permit invalidation of data files. Invalidating an index will
55556 * require the caller to release all its attachments to the tree rooted
55557@@ -438,10 +438,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
55558 {
55559 struct fscache_object *object;
55560
55561- fscache_stat(&fscache_n_updates);
55562+ fscache_stat_unchecked(&fscache_n_updates);
55563
55564 if (!cookie) {
55565- fscache_stat(&fscache_n_updates_null);
55566+ fscache_stat_unchecked(&fscache_n_updates_null);
55567 _leave(" [no cookie]");
55568 return;
55569 }
55570@@ -473,12 +473,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
55571 {
55572 struct fscache_object *object;
55573
55574- fscache_stat(&fscache_n_relinquishes);
55575+ fscache_stat_unchecked(&fscache_n_relinquishes);
55576 if (retire)
55577- fscache_stat(&fscache_n_relinquishes_retire);
55578+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
55579
55580 if (!cookie) {
55581- fscache_stat(&fscache_n_relinquishes_null);
55582+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
55583 _leave(" [no cookie]");
55584 return;
55585 }
55586diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
55587index 12d505b..86473a3 100644
55588--- a/fs/fscache/internal.h
55589+++ b/fs/fscache/internal.h
55590@@ -147,101 +147,101 @@ extern void fscache_proc_cleanup(void);
55591 * stats.c
55592 */
55593 #ifdef CONFIG_FSCACHE_STATS
55594-extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
55595-extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
55596+extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
55597+extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
55598
55599-extern atomic_t fscache_n_op_pend;
55600-extern atomic_t fscache_n_op_run;
55601-extern atomic_t fscache_n_op_enqueue;
55602-extern atomic_t fscache_n_op_deferred_release;
55603-extern atomic_t fscache_n_op_release;
55604-extern atomic_t fscache_n_op_gc;
55605-extern atomic_t fscache_n_op_cancelled;
55606-extern atomic_t fscache_n_op_rejected;
55607+extern atomic_unchecked_t fscache_n_op_pend;
55608+extern atomic_unchecked_t fscache_n_op_run;
55609+extern atomic_unchecked_t fscache_n_op_enqueue;
55610+extern atomic_unchecked_t fscache_n_op_deferred_release;
55611+extern atomic_unchecked_t fscache_n_op_release;
55612+extern atomic_unchecked_t fscache_n_op_gc;
55613+extern atomic_unchecked_t fscache_n_op_cancelled;
55614+extern atomic_unchecked_t fscache_n_op_rejected;
55615
55616-extern atomic_t fscache_n_attr_changed;
55617-extern atomic_t fscache_n_attr_changed_ok;
55618-extern atomic_t fscache_n_attr_changed_nobufs;
55619-extern atomic_t fscache_n_attr_changed_nomem;
55620-extern atomic_t fscache_n_attr_changed_calls;
55621+extern atomic_unchecked_t fscache_n_attr_changed;
55622+extern atomic_unchecked_t fscache_n_attr_changed_ok;
55623+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
55624+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
55625+extern atomic_unchecked_t fscache_n_attr_changed_calls;
55626
55627-extern atomic_t fscache_n_allocs;
55628-extern atomic_t fscache_n_allocs_ok;
55629-extern atomic_t fscache_n_allocs_wait;
55630-extern atomic_t fscache_n_allocs_nobufs;
55631-extern atomic_t fscache_n_allocs_intr;
55632-extern atomic_t fscache_n_allocs_object_dead;
55633-extern atomic_t fscache_n_alloc_ops;
55634-extern atomic_t fscache_n_alloc_op_waits;
55635+extern atomic_unchecked_t fscache_n_allocs;
55636+extern atomic_unchecked_t fscache_n_allocs_ok;
55637+extern atomic_unchecked_t fscache_n_allocs_wait;
55638+extern atomic_unchecked_t fscache_n_allocs_nobufs;
55639+extern atomic_unchecked_t fscache_n_allocs_intr;
55640+extern atomic_unchecked_t fscache_n_allocs_object_dead;
55641+extern atomic_unchecked_t fscache_n_alloc_ops;
55642+extern atomic_unchecked_t fscache_n_alloc_op_waits;
55643
55644-extern atomic_t fscache_n_retrievals;
55645-extern atomic_t fscache_n_retrievals_ok;
55646-extern atomic_t fscache_n_retrievals_wait;
55647-extern atomic_t fscache_n_retrievals_nodata;
55648-extern atomic_t fscache_n_retrievals_nobufs;
55649-extern atomic_t fscache_n_retrievals_intr;
55650-extern atomic_t fscache_n_retrievals_nomem;
55651-extern atomic_t fscache_n_retrievals_object_dead;
55652-extern atomic_t fscache_n_retrieval_ops;
55653-extern atomic_t fscache_n_retrieval_op_waits;
55654+extern atomic_unchecked_t fscache_n_retrievals;
55655+extern atomic_unchecked_t fscache_n_retrievals_ok;
55656+extern atomic_unchecked_t fscache_n_retrievals_wait;
55657+extern atomic_unchecked_t fscache_n_retrievals_nodata;
55658+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
55659+extern atomic_unchecked_t fscache_n_retrievals_intr;
55660+extern atomic_unchecked_t fscache_n_retrievals_nomem;
55661+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
55662+extern atomic_unchecked_t fscache_n_retrieval_ops;
55663+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
55664
55665-extern atomic_t fscache_n_stores;
55666-extern atomic_t fscache_n_stores_ok;
55667-extern atomic_t fscache_n_stores_again;
55668-extern atomic_t fscache_n_stores_nobufs;
55669-extern atomic_t fscache_n_stores_oom;
55670-extern atomic_t fscache_n_store_ops;
55671-extern atomic_t fscache_n_store_calls;
55672-extern atomic_t fscache_n_store_pages;
55673-extern atomic_t fscache_n_store_radix_deletes;
55674-extern atomic_t fscache_n_store_pages_over_limit;
55675+extern atomic_unchecked_t fscache_n_stores;
55676+extern atomic_unchecked_t fscache_n_stores_ok;
55677+extern atomic_unchecked_t fscache_n_stores_again;
55678+extern atomic_unchecked_t fscache_n_stores_nobufs;
55679+extern atomic_unchecked_t fscache_n_stores_oom;
55680+extern atomic_unchecked_t fscache_n_store_ops;
55681+extern atomic_unchecked_t fscache_n_store_calls;
55682+extern atomic_unchecked_t fscache_n_store_pages;
55683+extern atomic_unchecked_t fscache_n_store_radix_deletes;
55684+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
55685
55686-extern atomic_t fscache_n_store_vmscan_not_storing;
55687-extern atomic_t fscache_n_store_vmscan_gone;
55688-extern atomic_t fscache_n_store_vmscan_busy;
55689-extern atomic_t fscache_n_store_vmscan_cancelled;
55690-extern atomic_t fscache_n_store_vmscan_wait;
55691+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
55692+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
55693+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
55694+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
55695+extern atomic_unchecked_t fscache_n_store_vmscan_wait;
55696
55697-extern atomic_t fscache_n_marks;
55698-extern atomic_t fscache_n_uncaches;
55699+extern atomic_unchecked_t fscache_n_marks;
55700+extern atomic_unchecked_t fscache_n_uncaches;
55701
55702-extern atomic_t fscache_n_acquires;
55703-extern atomic_t fscache_n_acquires_null;
55704-extern atomic_t fscache_n_acquires_no_cache;
55705-extern atomic_t fscache_n_acquires_ok;
55706-extern atomic_t fscache_n_acquires_nobufs;
55707-extern atomic_t fscache_n_acquires_oom;
55708+extern atomic_unchecked_t fscache_n_acquires;
55709+extern atomic_unchecked_t fscache_n_acquires_null;
55710+extern atomic_unchecked_t fscache_n_acquires_no_cache;
55711+extern atomic_unchecked_t fscache_n_acquires_ok;
55712+extern atomic_unchecked_t fscache_n_acquires_nobufs;
55713+extern atomic_unchecked_t fscache_n_acquires_oom;
55714
55715-extern atomic_t fscache_n_invalidates;
55716-extern atomic_t fscache_n_invalidates_run;
55717+extern atomic_unchecked_t fscache_n_invalidates;
55718+extern atomic_unchecked_t fscache_n_invalidates_run;
55719
55720-extern atomic_t fscache_n_updates;
55721-extern atomic_t fscache_n_updates_null;
55722-extern atomic_t fscache_n_updates_run;
55723+extern atomic_unchecked_t fscache_n_updates;
55724+extern atomic_unchecked_t fscache_n_updates_null;
55725+extern atomic_unchecked_t fscache_n_updates_run;
55726
55727-extern atomic_t fscache_n_relinquishes;
55728-extern atomic_t fscache_n_relinquishes_null;
55729-extern atomic_t fscache_n_relinquishes_waitcrt;
55730-extern atomic_t fscache_n_relinquishes_retire;
55731+extern atomic_unchecked_t fscache_n_relinquishes;
55732+extern atomic_unchecked_t fscache_n_relinquishes_null;
55733+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
55734+extern atomic_unchecked_t fscache_n_relinquishes_retire;
55735
55736-extern atomic_t fscache_n_cookie_index;
55737-extern atomic_t fscache_n_cookie_data;
55738-extern atomic_t fscache_n_cookie_special;
55739+extern atomic_unchecked_t fscache_n_cookie_index;
55740+extern atomic_unchecked_t fscache_n_cookie_data;
55741+extern atomic_unchecked_t fscache_n_cookie_special;
55742
55743-extern atomic_t fscache_n_object_alloc;
55744-extern atomic_t fscache_n_object_no_alloc;
55745-extern atomic_t fscache_n_object_lookups;
55746-extern atomic_t fscache_n_object_lookups_negative;
55747-extern atomic_t fscache_n_object_lookups_positive;
55748-extern atomic_t fscache_n_object_lookups_timed_out;
55749-extern atomic_t fscache_n_object_created;
55750-extern atomic_t fscache_n_object_avail;
55751-extern atomic_t fscache_n_object_dead;
55752+extern atomic_unchecked_t fscache_n_object_alloc;
55753+extern atomic_unchecked_t fscache_n_object_no_alloc;
55754+extern atomic_unchecked_t fscache_n_object_lookups;
55755+extern atomic_unchecked_t fscache_n_object_lookups_negative;
55756+extern atomic_unchecked_t fscache_n_object_lookups_positive;
55757+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
55758+extern atomic_unchecked_t fscache_n_object_created;
55759+extern atomic_unchecked_t fscache_n_object_avail;
55760+extern atomic_unchecked_t fscache_n_object_dead;
55761
55762-extern atomic_t fscache_n_checkaux_none;
55763-extern atomic_t fscache_n_checkaux_okay;
55764-extern atomic_t fscache_n_checkaux_update;
55765-extern atomic_t fscache_n_checkaux_obsolete;
55766+extern atomic_unchecked_t fscache_n_checkaux_none;
55767+extern atomic_unchecked_t fscache_n_checkaux_okay;
55768+extern atomic_unchecked_t fscache_n_checkaux_update;
55769+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
55770
55771 extern atomic_t fscache_n_cop_alloc_object;
55772 extern atomic_t fscache_n_cop_lookup_object;
55773@@ -266,6 +266,11 @@ static inline void fscache_stat(atomic_t *stat)
55774 atomic_inc(stat);
55775 }
55776
55777+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
55778+{
55779+ atomic_inc_unchecked(stat);
55780+}
55781+
55782 static inline void fscache_stat_d(atomic_t *stat)
55783 {
55784 atomic_dec(stat);
55785@@ -278,6 +283,7 @@ extern const struct file_operations fscache_stats_fops;
55786
55787 #define __fscache_stat(stat) (NULL)
55788 #define fscache_stat(stat) do {} while (0)
55789+#define fscache_stat_unchecked(stat) do {} while (0)
55790 #define fscache_stat_d(stat) do {} while (0)
55791 #endif
55792
55793diff --git a/fs/fscache/object.c b/fs/fscache/object.c
55794index 86d75a6..5f3d7a0 100644
55795--- a/fs/fscache/object.c
55796+++ b/fs/fscache/object.c
55797@@ -451,7 +451,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
55798 _debug("LOOKUP \"%s\" in \"%s\"",
55799 cookie->def->name, object->cache->tag->name);
55800
55801- fscache_stat(&fscache_n_object_lookups);
55802+ fscache_stat_unchecked(&fscache_n_object_lookups);
55803 fscache_stat(&fscache_n_cop_lookup_object);
55804 ret = object->cache->ops->lookup_object(object);
55805 fscache_stat_d(&fscache_n_cop_lookup_object);
55806@@ -461,7 +461,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
55807 if (ret == -ETIMEDOUT) {
55808 /* probably stuck behind another object, so move this one to
55809 * the back of the queue */
55810- fscache_stat(&fscache_n_object_lookups_timed_out);
55811+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
55812 _leave(" [timeout]");
55813 return NO_TRANSIT;
55814 }
55815@@ -489,7 +489,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
55816 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
55817
55818 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
55819- fscache_stat(&fscache_n_object_lookups_negative);
55820+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
55821
55822 /* Allow write requests to begin stacking up and read requests to begin
55823 * returning ENODATA.
55824@@ -523,7 +523,7 @@ void fscache_obtained_object(struct fscache_object *object)
55825 /* if we were still looking up, then we must have a positive lookup
55826 * result, in which case there may be data available */
55827 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
55828- fscache_stat(&fscache_n_object_lookups_positive);
55829+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
55830
55831 /* We do (presumably) have data */
55832 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
55833@@ -534,7 +534,7 @@ void fscache_obtained_object(struct fscache_object *object)
55834 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
55835 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
55836 } else {
55837- fscache_stat(&fscache_n_object_created);
55838+ fscache_stat_unchecked(&fscache_n_object_created);
55839 }
55840
55841 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
55842@@ -570,7 +570,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
55843 fscache_stat_d(&fscache_n_cop_lookup_complete);
55844
55845 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
55846- fscache_stat(&fscache_n_object_avail);
55847+ fscache_stat_unchecked(&fscache_n_object_avail);
55848
55849 _leave("");
55850 return transit_to(JUMPSTART_DEPS);
55851@@ -716,7 +716,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
55852
55853 /* this just shifts the object release to the work processor */
55854 fscache_put_object(object);
55855- fscache_stat(&fscache_n_object_dead);
55856+ fscache_stat_unchecked(&fscache_n_object_dead);
55857
55858 _leave("");
55859 return transit_to(OBJECT_DEAD);
55860@@ -881,7 +881,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
55861 enum fscache_checkaux result;
55862
55863 if (!object->cookie->def->check_aux) {
55864- fscache_stat(&fscache_n_checkaux_none);
55865+ fscache_stat_unchecked(&fscache_n_checkaux_none);
55866 return FSCACHE_CHECKAUX_OKAY;
55867 }
55868
55869@@ -890,17 +890,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
55870 switch (result) {
55871 /* entry okay as is */
55872 case FSCACHE_CHECKAUX_OKAY:
55873- fscache_stat(&fscache_n_checkaux_okay);
55874+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
55875 break;
55876
55877 /* entry requires update */
55878 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
55879- fscache_stat(&fscache_n_checkaux_update);
55880+ fscache_stat_unchecked(&fscache_n_checkaux_update);
55881 break;
55882
55883 /* entry requires deletion */
55884 case FSCACHE_CHECKAUX_OBSOLETE:
55885- fscache_stat(&fscache_n_checkaux_obsolete);
55886+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
55887 break;
55888
55889 default:
55890@@ -986,7 +986,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
55891 {
55892 const struct fscache_state *s;
55893
55894- fscache_stat(&fscache_n_invalidates_run);
55895+ fscache_stat_unchecked(&fscache_n_invalidates_run);
55896 fscache_stat(&fscache_n_cop_invalidate_object);
55897 s = _fscache_invalidate_object(object, event);
55898 fscache_stat_d(&fscache_n_cop_invalidate_object);
55899@@ -1001,7 +1001,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
55900 {
55901 _enter("{OBJ%x},%d", object->debug_id, event);
55902
55903- fscache_stat(&fscache_n_updates_run);
55904+ fscache_stat_unchecked(&fscache_n_updates_run);
55905 fscache_stat(&fscache_n_cop_update_object);
55906 object->cache->ops->update_object(object);
55907 fscache_stat_d(&fscache_n_cop_update_object);
55908diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
55909index 318071a..379938b 100644
55910--- a/fs/fscache/operation.c
55911+++ b/fs/fscache/operation.c
55912@@ -17,7 +17,7 @@
55913 #include <linux/slab.h>
55914 #include "internal.h"
55915
55916-atomic_t fscache_op_debug_id;
55917+atomic_unchecked_t fscache_op_debug_id;
55918 EXPORT_SYMBOL(fscache_op_debug_id);
55919
55920 /**
55921@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
55922 ASSERTCMP(atomic_read(&op->usage), >, 0);
55923 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
55924
55925- fscache_stat(&fscache_n_op_enqueue);
55926+ fscache_stat_unchecked(&fscache_n_op_enqueue);
55927 switch (op->flags & FSCACHE_OP_TYPE) {
55928 case FSCACHE_OP_ASYNC:
55929 _debug("queue async");
55930@@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
55931 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
55932 if (op->processor)
55933 fscache_enqueue_operation(op);
55934- fscache_stat(&fscache_n_op_run);
55935+ fscache_stat_unchecked(&fscache_n_op_run);
55936 }
55937
55938 /*
55939@@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
55940 if (object->n_in_progress > 0) {
55941 atomic_inc(&op->usage);
55942 list_add_tail(&op->pend_link, &object->pending_ops);
55943- fscache_stat(&fscache_n_op_pend);
55944+ fscache_stat_unchecked(&fscache_n_op_pend);
55945 } else if (!list_empty(&object->pending_ops)) {
55946 atomic_inc(&op->usage);
55947 list_add_tail(&op->pend_link, &object->pending_ops);
55948- fscache_stat(&fscache_n_op_pend);
55949+ fscache_stat_unchecked(&fscache_n_op_pend);
55950 fscache_start_operations(object);
55951 } else {
55952 ASSERTCMP(object->n_in_progress, ==, 0);
55953@@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
55954 object->n_exclusive++; /* reads and writes must wait */
55955 atomic_inc(&op->usage);
55956 list_add_tail(&op->pend_link, &object->pending_ops);
55957- fscache_stat(&fscache_n_op_pend);
55958+ fscache_stat_unchecked(&fscache_n_op_pend);
55959 ret = 0;
55960 } else {
55961 /* If we're in any other state, there must have been an I/O
55962@@ -212,11 +212,11 @@ int fscache_submit_op(struct fscache_object *object,
55963 if (object->n_exclusive > 0) {
55964 atomic_inc(&op->usage);
55965 list_add_tail(&op->pend_link, &object->pending_ops);
55966- fscache_stat(&fscache_n_op_pend);
55967+ fscache_stat_unchecked(&fscache_n_op_pend);
55968 } else if (!list_empty(&object->pending_ops)) {
55969 atomic_inc(&op->usage);
55970 list_add_tail(&op->pend_link, &object->pending_ops);
55971- fscache_stat(&fscache_n_op_pend);
55972+ fscache_stat_unchecked(&fscache_n_op_pend);
55973 fscache_start_operations(object);
55974 } else {
55975 ASSERTCMP(object->n_exclusive, ==, 0);
55976@@ -228,10 +228,10 @@ int fscache_submit_op(struct fscache_object *object,
55977 object->n_ops++;
55978 atomic_inc(&op->usage);
55979 list_add_tail(&op->pend_link, &object->pending_ops);
55980- fscache_stat(&fscache_n_op_pend);
55981+ fscache_stat_unchecked(&fscache_n_op_pend);
55982 ret = 0;
55983 } else if (fscache_object_is_dying(object)) {
55984- fscache_stat(&fscache_n_op_rejected);
55985+ fscache_stat_unchecked(&fscache_n_op_rejected);
55986 op->state = FSCACHE_OP_ST_CANCELLED;
55987 ret = -ENOBUFS;
55988 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
55989@@ -310,7 +310,7 @@ int fscache_cancel_op(struct fscache_operation *op,
55990 ret = -EBUSY;
55991 if (op->state == FSCACHE_OP_ST_PENDING) {
55992 ASSERT(!list_empty(&op->pend_link));
55993- fscache_stat(&fscache_n_op_cancelled);
55994+ fscache_stat_unchecked(&fscache_n_op_cancelled);
55995 list_del_init(&op->pend_link);
55996 if (do_cancel)
55997 do_cancel(op);
55998@@ -342,7 +342,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
55999 while (!list_empty(&object->pending_ops)) {
56000 op = list_entry(object->pending_ops.next,
56001 struct fscache_operation, pend_link);
56002- fscache_stat(&fscache_n_op_cancelled);
56003+ fscache_stat_unchecked(&fscache_n_op_cancelled);
56004 list_del_init(&op->pend_link);
56005
56006 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
56007@@ -414,7 +414,7 @@ void fscache_put_operation(struct fscache_operation *op)
56008 op->state, ==, FSCACHE_OP_ST_CANCELLED);
56009 op->state = FSCACHE_OP_ST_DEAD;
56010
56011- fscache_stat(&fscache_n_op_release);
56012+ fscache_stat_unchecked(&fscache_n_op_release);
56013
56014 if (op->release) {
56015 op->release(op);
56016@@ -433,7 +433,7 @@ void fscache_put_operation(struct fscache_operation *op)
56017 * lock, and defer it otherwise */
56018 if (!spin_trylock(&object->lock)) {
56019 _debug("defer put");
56020- fscache_stat(&fscache_n_op_deferred_release);
56021+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
56022
56023 cache = object->cache;
56024 spin_lock(&cache->op_gc_list_lock);
56025@@ -486,7 +486,7 @@ void fscache_operation_gc(struct work_struct *work)
56026
56027 _debug("GC DEFERRED REL OBJ%x OP%x",
56028 object->debug_id, op->debug_id);
56029- fscache_stat(&fscache_n_op_gc);
56030+ fscache_stat_unchecked(&fscache_n_op_gc);
56031
56032 ASSERTCMP(atomic_read(&op->usage), ==, 0);
56033 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
56034diff --git a/fs/fscache/page.c b/fs/fscache/page.c
56035index d479ab3..727a7f2 100644
56036--- a/fs/fscache/page.c
56037+++ b/fs/fscache/page.c
56038@@ -61,7 +61,7 @@ try_again:
56039 val = radix_tree_lookup(&cookie->stores, page->index);
56040 if (!val) {
56041 rcu_read_unlock();
56042- fscache_stat(&fscache_n_store_vmscan_not_storing);
56043+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
56044 __fscache_uncache_page(cookie, page);
56045 return true;
56046 }
56047@@ -91,11 +91,11 @@ try_again:
56048 spin_unlock(&cookie->stores_lock);
56049
56050 if (xpage) {
56051- fscache_stat(&fscache_n_store_vmscan_cancelled);
56052- fscache_stat(&fscache_n_store_radix_deletes);
56053+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
56054+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
56055 ASSERTCMP(xpage, ==, page);
56056 } else {
56057- fscache_stat(&fscache_n_store_vmscan_gone);
56058+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
56059 }
56060
56061 wake_up_bit(&cookie->flags, 0);
56062@@ -110,11 +110,11 @@ page_busy:
56063 * sleeping on memory allocation, so we may need to impose a timeout
56064 * too. */
56065 if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
56066- fscache_stat(&fscache_n_store_vmscan_busy);
56067+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
56068 return false;
56069 }
56070
56071- fscache_stat(&fscache_n_store_vmscan_wait);
56072+ fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
56073 __fscache_wait_on_page_write(cookie, page);
56074 gfp &= ~__GFP_WAIT;
56075 goto try_again;
56076@@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
56077 FSCACHE_COOKIE_STORING_TAG);
56078 if (!radix_tree_tag_get(&cookie->stores, page->index,
56079 FSCACHE_COOKIE_PENDING_TAG)) {
56080- fscache_stat(&fscache_n_store_radix_deletes);
56081+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
56082 xpage = radix_tree_delete(&cookie->stores, page->index);
56083 }
56084 spin_unlock(&cookie->stores_lock);
56085@@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
56086
56087 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
56088
56089- fscache_stat(&fscache_n_attr_changed_calls);
56090+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
56091
56092 if (fscache_object_is_active(object) &&
56093 fscache_use_cookie(object)) {
56094@@ -189,11 +189,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
56095
56096 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
56097
56098- fscache_stat(&fscache_n_attr_changed);
56099+ fscache_stat_unchecked(&fscache_n_attr_changed);
56100
56101 op = kzalloc(sizeof(*op), GFP_KERNEL);
56102 if (!op) {
56103- fscache_stat(&fscache_n_attr_changed_nomem);
56104+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
56105 _leave(" = -ENOMEM");
56106 return -ENOMEM;
56107 }
56108@@ -211,7 +211,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
56109 if (fscache_submit_exclusive_op(object, op) < 0)
56110 goto nobufs;
56111 spin_unlock(&cookie->lock);
56112- fscache_stat(&fscache_n_attr_changed_ok);
56113+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
56114 fscache_put_operation(op);
56115 _leave(" = 0");
56116 return 0;
56117@@ -219,7 +219,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
56118 nobufs:
56119 spin_unlock(&cookie->lock);
56120 kfree(op);
56121- fscache_stat(&fscache_n_attr_changed_nobufs);
56122+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
56123 _leave(" = %d", -ENOBUFS);
56124 return -ENOBUFS;
56125 }
56126@@ -258,7 +258,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
56127 /* allocate a retrieval operation and attempt to submit it */
56128 op = kzalloc(sizeof(*op), GFP_NOIO);
56129 if (!op) {
56130- fscache_stat(&fscache_n_retrievals_nomem);
56131+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
56132 return NULL;
56133 }
56134
56135@@ -289,13 +289,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
56136 return 0;
56137 }
56138
56139- fscache_stat(&fscache_n_retrievals_wait);
56140+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
56141
56142 jif = jiffies;
56143 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
56144 fscache_wait_bit_interruptible,
56145 TASK_INTERRUPTIBLE) != 0) {
56146- fscache_stat(&fscache_n_retrievals_intr);
56147+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
56148 _leave(" = -ERESTARTSYS");
56149 return -ERESTARTSYS;
56150 }
56151@@ -324,8 +324,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
56152 */
56153 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
56154 struct fscache_retrieval *op,
56155- atomic_t *stat_op_waits,
56156- atomic_t *stat_object_dead)
56157+ atomic_unchecked_t *stat_op_waits,
56158+ atomic_unchecked_t *stat_object_dead)
56159 {
56160 int ret;
56161
56162@@ -333,7 +333,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
56163 goto check_if_dead;
56164
56165 _debug(">>> WT");
56166- fscache_stat(stat_op_waits);
56167+ fscache_stat_unchecked(stat_op_waits);
56168 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
56169 fscache_wait_bit_interruptible,
56170 TASK_INTERRUPTIBLE) != 0) {
56171@@ -350,14 +350,14 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
56172
56173 check_if_dead:
56174 if (op->op.state == FSCACHE_OP_ST_CANCELLED) {
56175- fscache_stat(stat_object_dead);
56176+ fscache_stat_unchecked(stat_object_dead);
56177 _leave(" = -ENOBUFS [cancelled]");
56178 return -ENOBUFS;
56179 }
56180 if (unlikely(fscache_object_is_dead(object))) {
56181 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->op.state);
56182 fscache_cancel_op(&op->op, fscache_do_cancel_retrieval);
56183- fscache_stat(stat_object_dead);
56184+ fscache_stat_unchecked(stat_object_dead);
56185 return -ENOBUFS;
56186 }
56187 return 0;
56188@@ -384,7 +384,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
56189
56190 _enter("%p,%p,,,", cookie, page);
56191
56192- fscache_stat(&fscache_n_retrievals);
56193+ fscache_stat_unchecked(&fscache_n_retrievals);
56194
56195 if (hlist_empty(&cookie->backing_objects))
56196 goto nobufs;
56197@@ -424,7 +424,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
56198 goto nobufs_unlock_dec;
56199 spin_unlock(&cookie->lock);
56200
56201- fscache_stat(&fscache_n_retrieval_ops);
56202+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
56203
56204 /* pin the netfs read context in case we need to do the actual netfs
56205 * read because we've encountered a cache read failure */
56206@@ -454,15 +454,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
56207
56208 error:
56209 if (ret == -ENOMEM)
56210- fscache_stat(&fscache_n_retrievals_nomem);
56211+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
56212 else if (ret == -ERESTARTSYS)
56213- fscache_stat(&fscache_n_retrievals_intr);
56214+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
56215 else if (ret == -ENODATA)
56216- fscache_stat(&fscache_n_retrievals_nodata);
56217+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
56218 else if (ret < 0)
56219- fscache_stat(&fscache_n_retrievals_nobufs);
56220+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
56221 else
56222- fscache_stat(&fscache_n_retrievals_ok);
56223+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
56224
56225 fscache_put_retrieval(op);
56226 _leave(" = %d", ret);
56227@@ -475,7 +475,7 @@ nobufs_unlock:
56228 atomic_dec(&cookie->n_active);
56229 kfree(op);
56230 nobufs:
56231- fscache_stat(&fscache_n_retrievals_nobufs);
56232+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
56233 _leave(" = -ENOBUFS");
56234 return -ENOBUFS;
56235 }
56236@@ -513,7 +513,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
56237
56238 _enter("%p,,%d,,,", cookie, *nr_pages);
56239
56240- fscache_stat(&fscache_n_retrievals);
56241+ fscache_stat_unchecked(&fscache_n_retrievals);
56242
56243 if (hlist_empty(&cookie->backing_objects))
56244 goto nobufs;
56245@@ -549,7 +549,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
56246 goto nobufs_unlock_dec;
56247 spin_unlock(&cookie->lock);
56248
56249- fscache_stat(&fscache_n_retrieval_ops);
56250+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
56251
56252 /* pin the netfs read context in case we need to do the actual netfs
56253 * read because we've encountered a cache read failure */
56254@@ -579,15 +579,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
56255
56256 error:
56257 if (ret == -ENOMEM)
56258- fscache_stat(&fscache_n_retrievals_nomem);
56259+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
56260 else if (ret == -ERESTARTSYS)
56261- fscache_stat(&fscache_n_retrievals_intr);
56262+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
56263 else if (ret == -ENODATA)
56264- fscache_stat(&fscache_n_retrievals_nodata);
56265+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
56266 else if (ret < 0)
56267- fscache_stat(&fscache_n_retrievals_nobufs);
56268+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
56269 else
56270- fscache_stat(&fscache_n_retrievals_ok);
56271+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
56272
56273 fscache_put_retrieval(op);
56274 _leave(" = %d", ret);
56275@@ -600,7 +600,7 @@ nobufs_unlock:
56276 atomic_dec(&cookie->n_active);
56277 kfree(op);
56278 nobufs:
56279- fscache_stat(&fscache_n_retrievals_nobufs);
56280+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
56281 _leave(" = -ENOBUFS");
56282 return -ENOBUFS;
56283 }
56284@@ -624,7 +624,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
56285
56286 _enter("%p,%p,,,", cookie, page);
56287
56288- fscache_stat(&fscache_n_allocs);
56289+ fscache_stat_unchecked(&fscache_n_allocs);
56290
56291 if (hlist_empty(&cookie->backing_objects))
56292 goto nobufs;
56293@@ -656,7 +656,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
56294 goto nobufs_unlock;
56295 spin_unlock(&cookie->lock);
56296
56297- fscache_stat(&fscache_n_alloc_ops);
56298+ fscache_stat_unchecked(&fscache_n_alloc_ops);
56299
56300 ret = fscache_wait_for_retrieval_activation(
56301 object, op,
56302@@ -672,11 +672,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
56303
56304 error:
56305 if (ret == -ERESTARTSYS)
56306- fscache_stat(&fscache_n_allocs_intr);
56307+ fscache_stat_unchecked(&fscache_n_allocs_intr);
56308 else if (ret < 0)
56309- fscache_stat(&fscache_n_allocs_nobufs);
56310+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
56311 else
56312- fscache_stat(&fscache_n_allocs_ok);
56313+ fscache_stat_unchecked(&fscache_n_allocs_ok);
56314
56315 fscache_put_retrieval(op);
56316 _leave(" = %d", ret);
56317@@ -687,7 +687,7 @@ nobufs_unlock:
56318 atomic_dec(&cookie->n_active);
56319 kfree(op);
56320 nobufs:
56321- fscache_stat(&fscache_n_allocs_nobufs);
56322+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
56323 _leave(" = -ENOBUFS");
56324 return -ENOBUFS;
56325 }
56326@@ -747,7 +747,7 @@ static void fscache_write_op(struct fscache_operation *_op)
56327
56328 spin_lock(&cookie->stores_lock);
56329
56330- fscache_stat(&fscache_n_store_calls);
56331+ fscache_stat_unchecked(&fscache_n_store_calls);
56332
56333 /* find a page to store */
56334 page = NULL;
56335@@ -758,7 +758,7 @@ static void fscache_write_op(struct fscache_operation *_op)
56336 page = results[0];
56337 _debug("gang %d [%lx]", n, page->index);
56338 if (page->index > op->store_limit) {
56339- fscache_stat(&fscache_n_store_pages_over_limit);
56340+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
56341 goto superseded;
56342 }
56343
56344@@ -770,7 +770,7 @@ static void fscache_write_op(struct fscache_operation *_op)
56345 spin_unlock(&cookie->stores_lock);
56346 spin_unlock(&object->lock);
56347
56348- fscache_stat(&fscache_n_store_pages);
56349+ fscache_stat_unchecked(&fscache_n_store_pages);
56350 fscache_stat(&fscache_n_cop_write_page);
56351 ret = object->cache->ops->write_page(op, page);
56352 fscache_stat_d(&fscache_n_cop_write_page);
56353@@ -873,7 +873,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
56354 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
56355 ASSERT(PageFsCache(page));
56356
56357- fscache_stat(&fscache_n_stores);
56358+ fscache_stat_unchecked(&fscache_n_stores);
56359
56360 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
56361 _leave(" = -ENOBUFS [invalidating]");
56362@@ -931,7 +931,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
56363 spin_unlock(&cookie->stores_lock);
56364 spin_unlock(&object->lock);
56365
56366- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
56367+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
56368 op->store_limit = object->store_limit;
56369
56370 atomic_inc(&cookie->n_active);
56371@@ -940,8 +940,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
56372
56373 spin_unlock(&cookie->lock);
56374 radix_tree_preload_end();
56375- fscache_stat(&fscache_n_store_ops);
56376- fscache_stat(&fscache_n_stores_ok);
56377+ fscache_stat_unchecked(&fscache_n_store_ops);
56378+ fscache_stat_unchecked(&fscache_n_stores_ok);
56379
56380 /* the work queue now carries its own ref on the object */
56381 fscache_put_operation(&op->op);
56382@@ -949,14 +949,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
56383 return 0;
56384
56385 already_queued:
56386- fscache_stat(&fscache_n_stores_again);
56387+ fscache_stat_unchecked(&fscache_n_stores_again);
56388 already_pending:
56389 spin_unlock(&cookie->stores_lock);
56390 spin_unlock(&object->lock);
56391 spin_unlock(&cookie->lock);
56392 radix_tree_preload_end();
56393 kfree(op);
56394- fscache_stat(&fscache_n_stores_ok);
56395+ fscache_stat_unchecked(&fscache_n_stores_ok);
56396 _leave(" = 0");
56397 return 0;
56398
56399@@ -976,14 +976,14 @@ nobufs:
56400 spin_unlock(&cookie->lock);
56401 radix_tree_preload_end();
56402 kfree(op);
56403- fscache_stat(&fscache_n_stores_nobufs);
56404+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
56405 _leave(" = -ENOBUFS");
56406 return -ENOBUFS;
56407
56408 nomem_free:
56409 kfree(op);
56410 nomem:
56411- fscache_stat(&fscache_n_stores_oom);
56412+ fscache_stat_unchecked(&fscache_n_stores_oom);
56413 _leave(" = -ENOMEM");
56414 return -ENOMEM;
56415 }
56416@@ -1001,7 +1001,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
56417 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
56418 ASSERTCMP(page, !=, NULL);
56419
56420- fscache_stat(&fscache_n_uncaches);
56421+ fscache_stat_unchecked(&fscache_n_uncaches);
56422
56423 /* cache withdrawal may beat us to it */
56424 if (!PageFsCache(page))
56425@@ -1052,7 +1052,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
56426 struct fscache_cookie *cookie = op->op.object->cookie;
56427
56428 #ifdef CONFIG_FSCACHE_STATS
56429- atomic_inc(&fscache_n_marks);
56430+ atomic_inc_unchecked(&fscache_n_marks);
56431 #endif
56432
56433 _debug("- mark %p{%lx}", page, page->index);
56434diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
56435index 40d13c7..ddf52b9 100644
56436--- a/fs/fscache/stats.c
56437+++ b/fs/fscache/stats.c
56438@@ -18,99 +18,99 @@
56439 /*
56440 * operation counters
56441 */
56442-atomic_t fscache_n_op_pend;
56443-atomic_t fscache_n_op_run;
56444-atomic_t fscache_n_op_enqueue;
56445-atomic_t fscache_n_op_requeue;
56446-atomic_t fscache_n_op_deferred_release;
56447-atomic_t fscache_n_op_release;
56448-atomic_t fscache_n_op_gc;
56449-atomic_t fscache_n_op_cancelled;
56450-atomic_t fscache_n_op_rejected;
56451+atomic_unchecked_t fscache_n_op_pend;
56452+atomic_unchecked_t fscache_n_op_run;
56453+atomic_unchecked_t fscache_n_op_enqueue;
56454+atomic_unchecked_t fscache_n_op_requeue;
56455+atomic_unchecked_t fscache_n_op_deferred_release;
56456+atomic_unchecked_t fscache_n_op_release;
56457+atomic_unchecked_t fscache_n_op_gc;
56458+atomic_unchecked_t fscache_n_op_cancelled;
56459+atomic_unchecked_t fscache_n_op_rejected;
56460
56461-atomic_t fscache_n_attr_changed;
56462-atomic_t fscache_n_attr_changed_ok;
56463-atomic_t fscache_n_attr_changed_nobufs;
56464-atomic_t fscache_n_attr_changed_nomem;
56465-atomic_t fscache_n_attr_changed_calls;
56466+atomic_unchecked_t fscache_n_attr_changed;
56467+atomic_unchecked_t fscache_n_attr_changed_ok;
56468+atomic_unchecked_t fscache_n_attr_changed_nobufs;
56469+atomic_unchecked_t fscache_n_attr_changed_nomem;
56470+atomic_unchecked_t fscache_n_attr_changed_calls;
56471
56472-atomic_t fscache_n_allocs;
56473-atomic_t fscache_n_allocs_ok;
56474-atomic_t fscache_n_allocs_wait;
56475-atomic_t fscache_n_allocs_nobufs;
56476-atomic_t fscache_n_allocs_intr;
56477-atomic_t fscache_n_allocs_object_dead;
56478-atomic_t fscache_n_alloc_ops;
56479-atomic_t fscache_n_alloc_op_waits;
56480+atomic_unchecked_t fscache_n_allocs;
56481+atomic_unchecked_t fscache_n_allocs_ok;
56482+atomic_unchecked_t fscache_n_allocs_wait;
56483+atomic_unchecked_t fscache_n_allocs_nobufs;
56484+atomic_unchecked_t fscache_n_allocs_intr;
56485+atomic_unchecked_t fscache_n_allocs_object_dead;
56486+atomic_unchecked_t fscache_n_alloc_ops;
56487+atomic_unchecked_t fscache_n_alloc_op_waits;
56488
56489-atomic_t fscache_n_retrievals;
56490-atomic_t fscache_n_retrievals_ok;
56491-atomic_t fscache_n_retrievals_wait;
56492-atomic_t fscache_n_retrievals_nodata;
56493-atomic_t fscache_n_retrievals_nobufs;
56494-atomic_t fscache_n_retrievals_intr;
56495-atomic_t fscache_n_retrievals_nomem;
56496-atomic_t fscache_n_retrievals_object_dead;
56497-atomic_t fscache_n_retrieval_ops;
56498-atomic_t fscache_n_retrieval_op_waits;
56499+atomic_unchecked_t fscache_n_retrievals;
56500+atomic_unchecked_t fscache_n_retrievals_ok;
56501+atomic_unchecked_t fscache_n_retrievals_wait;
56502+atomic_unchecked_t fscache_n_retrievals_nodata;
56503+atomic_unchecked_t fscache_n_retrievals_nobufs;
56504+atomic_unchecked_t fscache_n_retrievals_intr;
56505+atomic_unchecked_t fscache_n_retrievals_nomem;
56506+atomic_unchecked_t fscache_n_retrievals_object_dead;
56507+atomic_unchecked_t fscache_n_retrieval_ops;
56508+atomic_unchecked_t fscache_n_retrieval_op_waits;
56509
56510-atomic_t fscache_n_stores;
56511-atomic_t fscache_n_stores_ok;
56512-atomic_t fscache_n_stores_again;
56513-atomic_t fscache_n_stores_nobufs;
56514-atomic_t fscache_n_stores_oom;
56515-atomic_t fscache_n_store_ops;
56516-atomic_t fscache_n_store_calls;
56517-atomic_t fscache_n_store_pages;
56518-atomic_t fscache_n_store_radix_deletes;
56519-atomic_t fscache_n_store_pages_over_limit;
56520+atomic_unchecked_t fscache_n_stores;
56521+atomic_unchecked_t fscache_n_stores_ok;
56522+atomic_unchecked_t fscache_n_stores_again;
56523+atomic_unchecked_t fscache_n_stores_nobufs;
56524+atomic_unchecked_t fscache_n_stores_oom;
56525+atomic_unchecked_t fscache_n_store_ops;
56526+atomic_unchecked_t fscache_n_store_calls;
56527+atomic_unchecked_t fscache_n_store_pages;
56528+atomic_unchecked_t fscache_n_store_radix_deletes;
56529+atomic_unchecked_t fscache_n_store_pages_over_limit;
56530
56531-atomic_t fscache_n_store_vmscan_not_storing;
56532-atomic_t fscache_n_store_vmscan_gone;
56533-atomic_t fscache_n_store_vmscan_busy;
56534-atomic_t fscache_n_store_vmscan_cancelled;
56535-atomic_t fscache_n_store_vmscan_wait;
56536+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
56537+atomic_unchecked_t fscache_n_store_vmscan_gone;
56538+atomic_unchecked_t fscache_n_store_vmscan_busy;
56539+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
56540+atomic_unchecked_t fscache_n_store_vmscan_wait;
56541
56542-atomic_t fscache_n_marks;
56543-atomic_t fscache_n_uncaches;
56544+atomic_unchecked_t fscache_n_marks;
56545+atomic_unchecked_t fscache_n_uncaches;
56546
56547-atomic_t fscache_n_acquires;
56548-atomic_t fscache_n_acquires_null;
56549-atomic_t fscache_n_acquires_no_cache;
56550-atomic_t fscache_n_acquires_ok;
56551-atomic_t fscache_n_acquires_nobufs;
56552-atomic_t fscache_n_acquires_oom;
56553+atomic_unchecked_t fscache_n_acquires;
56554+atomic_unchecked_t fscache_n_acquires_null;
56555+atomic_unchecked_t fscache_n_acquires_no_cache;
56556+atomic_unchecked_t fscache_n_acquires_ok;
56557+atomic_unchecked_t fscache_n_acquires_nobufs;
56558+atomic_unchecked_t fscache_n_acquires_oom;
56559
56560-atomic_t fscache_n_invalidates;
56561-atomic_t fscache_n_invalidates_run;
56562+atomic_unchecked_t fscache_n_invalidates;
56563+atomic_unchecked_t fscache_n_invalidates_run;
56564
56565-atomic_t fscache_n_updates;
56566-atomic_t fscache_n_updates_null;
56567-atomic_t fscache_n_updates_run;
56568+atomic_unchecked_t fscache_n_updates;
56569+atomic_unchecked_t fscache_n_updates_null;
56570+atomic_unchecked_t fscache_n_updates_run;
56571
56572-atomic_t fscache_n_relinquishes;
56573-atomic_t fscache_n_relinquishes_null;
56574-atomic_t fscache_n_relinquishes_waitcrt;
56575-atomic_t fscache_n_relinquishes_retire;
56576+atomic_unchecked_t fscache_n_relinquishes;
56577+atomic_unchecked_t fscache_n_relinquishes_null;
56578+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
56579+atomic_unchecked_t fscache_n_relinquishes_retire;
56580
56581-atomic_t fscache_n_cookie_index;
56582-atomic_t fscache_n_cookie_data;
56583-atomic_t fscache_n_cookie_special;
56584+atomic_unchecked_t fscache_n_cookie_index;
56585+atomic_unchecked_t fscache_n_cookie_data;
56586+atomic_unchecked_t fscache_n_cookie_special;
56587
56588-atomic_t fscache_n_object_alloc;
56589-atomic_t fscache_n_object_no_alloc;
56590-atomic_t fscache_n_object_lookups;
56591-atomic_t fscache_n_object_lookups_negative;
56592-atomic_t fscache_n_object_lookups_positive;
56593-atomic_t fscache_n_object_lookups_timed_out;
56594-atomic_t fscache_n_object_created;
56595-atomic_t fscache_n_object_avail;
56596-atomic_t fscache_n_object_dead;
56597+atomic_unchecked_t fscache_n_object_alloc;
56598+atomic_unchecked_t fscache_n_object_no_alloc;
56599+atomic_unchecked_t fscache_n_object_lookups;
56600+atomic_unchecked_t fscache_n_object_lookups_negative;
56601+atomic_unchecked_t fscache_n_object_lookups_positive;
56602+atomic_unchecked_t fscache_n_object_lookups_timed_out;
56603+atomic_unchecked_t fscache_n_object_created;
56604+atomic_unchecked_t fscache_n_object_avail;
56605+atomic_unchecked_t fscache_n_object_dead;
56606
56607-atomic_t fscache_n_checkaux_none;
56608-atomic_t fscache_n_checkaux_okay;
56609-atomic_t fscache_n_checkaux_update;
56610-atomic_t fscache_n_checkaux_obsolete;
56611+atomic_unchecked_t fscache_n_checkaux_none;
56612+atomic_unchecked_t fscache_n_checkaux_okay;
56613+atomic_unchecked_t fscache_n_checkaux_update;
56614+atomic_unchecked_t fscache_n_checkaux_obsolete;
56615
56616 atomic_t fscache_n_cop_alloc_object;
56617 atomic_t fscache_n_cop_lookup_object;
56618@@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
56619 seq_puts(m, "FS-Cache statistics\n");
56620
56621 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
56622- atomic_read(&fscache_n_cookie_index),
56623- atomic_read(&fscache_n_cookie_data),
56624- atomic_read(&fscache_n_cookie_special));
56625+ atomic_read_unchecked(&fscache_n_cookie_index),
56626+ atomic_read_unchecked(&fscache_n_cookie_data),
56627+ atomic_read_unchecked(&fscache_n_cookie_special));
56628
56629 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
56630- atomic_read(&fscache_n_object_alloc),
56631- atomic_read(&fscache_n_object_no_alloc),
56632- atomic_read(&fscache_n_object_avail),
56633- atomic_read(&fscache_n_object_dead));
56634+ atomic_read_unchecked(&fscache_n_object_alloc),
56635+ atomic_read_unchecked(&fscache_n_object_no_alloc),
56636+ atomic_read_unchecked(&fscache_n_object_avail),
56637+ atomic_read_unchecked(&fscache_n_object_dead));
56638 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
56639- atomic_read(&fscache_n_checkaux_none),
56640- atomic_read(&fscache_n_checkaux_okay),
56641- atomic_read(&fscache_n_checkaux_update),
56642- atomic_read(&fscache_n_checkaux_obsolete));
56643+ atomic_read_unchecked(&fscache_n_checkaux_none),
56644+ atomic_read_unchecked(&fscache_n_checkaux_okay),
56645+ atomic_read_unchecked(&fscache_n_checkaux_update),
56646+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
56647
56648 seq_printf(m, "Pages : mrk=%u unc=%u\n",
56649- atomic_read(&fscache_n_marks),
56650- atomic_read(&fscache_n_uncaches));
56651+ atomic_read_unchecked(&fscache_n_marks),
56652+ atomic_read_unchecked(&fscache_n_uncaches));
56653
56654 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
56655 " oom=%u\n",
56656- atomic_read(&fscache_n_acquires),
56657- atomic_read(&fscache_n_acquires_null),
56658- atomic_read(&fscache_n_acquires_no_cache),
56659- atomic_read(&fscache_n_acquires_ok),
56660- atomic_read(&fscache_n_acquires_nobufs),
56661- atomic_read(&fscache_n_acquires_oom));
56662+ atomic_read_unchecked(&fscache_n_acquires),
56663+ atomic_read_unchecked(&fscache_n_acquires_null),
56664+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
56665+ atomic_read_unchecked(&fscache_n_acquires_ok),
56666+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
56667+ atomic_read_unchecked(&fscache_n_acquires_oom));
56668
56669 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
56670- atomic_read(&fscache_n_object_lookups),
56671- atomic_read(&fscache_n_object_lookups_negative),
56672- atomic_read(&fscache_n_object_lookups_positive),
56673- atomic_read(&fscache_n_object_created),
56674- atomic_read(&fscache_n_object_lookups_timed_out));
56675+ atomic_read_unchecked(&fscache_n_object_lookups),
56676+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
56677+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
56678+ atomic_read_unchecked(&fscache_n_object_created),
56679+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
56680
56681 seq_printf(m, "Invals : n=%u run=%u\n",
56682- atomic_read(&fscache_n_invalidates),
56683- atomic_read(&fscache_n_invalidates_run));
56684+ atomic_read_unchecked(&fscache_n_invalidates),
56685+ atomic_read_unchecked(&fscache_n_invalidates_run));
56686
56687 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
56688- atomic_read(&fscache_n_updates),
56689- atomic_read(&fscache_n_updates_null),
56690- atomic_read(&fscache_n_updates_run));
56691+ atomic_read_unchecked(&fscache_n_updates),
56692+ atomic_read_unchecked(&fscache_n_updates_null),
56693+ atomic_read_unchecked(&fscache_n_updates_run));
56694
56695 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
56696- atomic_read(&fscache_n_relinquishes),
56697- atomic_read(&fscache_n_relinquishes_null),
56698- atomic_read(&fscache_n_relinquishes_waitcrt),
56699- atomic_read(&fscache_n_relinquishes_retire));
56700+ atomic_read_unchecked(&fscache_n_relinquishes),
56701+ atomic_read_unchecked(&fscache_n_relinquishes_null),
56702+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
56703+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
56704
56705 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
56706- atomic_read(&fscache_n_attr_changed),
56707- atomic_read(&fscache_n_attr_changed_ok),
56708- atomic_read(&fscache_n_attr_changed_nobufs),
56709- atomic_read(&fscache_n_attr_changed_nomem),
56710- atomic_read(&fscache_n_attr_changed_calls));
56711+ atomic_read_unchecked(&fscache_n_attr_changed),
56712+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
56713+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
56714+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
56715+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
56716
56717 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
56718- atomic_read(&fscache_n_allocs),
56719- atomic_read(&fscache_n_allocs_ok),
56720- atomic_read(&fscache_n_allocs_wait),
56721- atomic_read(&fscache_n_allocs_nobufs),
56722- atomic_read(&fscache_n_allocs_intr));
56723+ atomic_read_unchecked(&fscache_n_allocs),
56724+ atomic_read_unchecked(&fscache_n_allocs_ok),
56725+ atomic_read_unchecked(&fscache_n_allocs_wait),
56726+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
56727+ atomic_read_unchecked(&fscache_n_allocs_intr));
56728 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
56729- atomic_read(&fscache_n_alloc_ops),
56730- atomic_read(&fscache_n_alloc_op_waits),
56731- atomic_read(&fscache_n_allocs_object_dead));
56732+ atomic_read_unchecked(&fscache_n_alloc_ops),
56733+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
56734+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
56735
56736 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
56737 " int=%u oom=%u\n",
56738- atomic_read(&fscache_n_retrievals),
56739- atomic_read(&fscache_n_retrievals_ok),
56740- atomic_read(&fscache_n_retrievals_wait),
56741- atomic_read(&fscache_n_retrievals_nodata),
56742- atomic_read(&fscache_n_retrievals_nobufs),
56743- atomic_read(&fscache_n_retrievals_intr),
56744- atomic_read(&fscache_n_retrievals_nomem));
56745+ atomic_read_unchecked(&fscache_n_retrievals),
56746+ atomic_read_unchecked(&fscache_n_retrievals_ok),
56747+ atomic_read_unchecked(&fscache_n_retrievals_wait),
56748+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
56749+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
56750+ atomic_read_unchecked(&fscache_n_retrievals_intr),
56751+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
56752 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
56753- atomic_read(&fscache_n_retrieval_ops),
56754- atomic_read(&fscache_n_retrieval_op_waits),
56755- atomic_read(&fscache_n_retrievals_object_dead));
56756+ atomic_read_unchecked(&fscache_n_retrieval_ops),
56757+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
56758+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
56759
56760 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
56761- atomic_read(&fscache_n_stores),
56762- atomic_read(&fscache_n_stores_ok),
56763- atomic_read(&fscache_n_stores_again),
56764- atomic_read(&fscache_n_stores_nobufs),
56765- atomic_read(&fscache_n_stores_oom));
56766+ atomic_read_unchecked(&fscache_n_stores),
56767+ atomic_read_unchecked(&fscache_n_stores_ok),
56768+ atomic_read_unchecked(&fscache_n_stores_again),
56769+ atomic_read_unchecked(&fscache_n_stores_nobufs),
56770+ atomic_read_unchecked(&fscache_n_stores_oom));
56771 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
56772- atomic_read(&fscache_n_store_ops),
56773- atomic_read(&fscache_n_store_calls),
56774- atomic_read(&fscache_n_store_pages),
56775- atomic_read(&fscache_n_store_radix_deletes),
56776- atomic_read(&fscache_n_store_pages_over_limit));
56777+ atomic_read_unchecked(&fscache_n_store_ops),
56778+ atomic_read_unchecked(&fscache_n_store_calls),
56779+ atomic_read_unchecked(&fscache_n_store_pages),
56780+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
56781+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
56782
56783 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
56784- atomic_read(&fscache_n_store_vmscan_not_storing),
56785- atomic_read(&fscache_n_store_vmscan_gone),
56786- atomic_read(&fscache_n_store_vmscan_busy),
56787- atomic_read(&fscache_n_store_vmscan_cancelled),
56788- atomic_read(&fscache_n_store_vmscan_wait));
56789+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
56790+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
56791+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
56792+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
56793+ atomic_read_unchecked(&fscache_n_store_vmscan_wait));
56794
56795 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
56796- atomic_read(&fscache_n_op_pend),
56797- atomic_read(&fscache_n_op_run),
56798- atomic_read(&fscache_n_op_enqueue),
56799- atomic_read(&fscache_n_op_cancelled),
56800- atomic_read(&fscache_n_op_rejected));
56801+ atomic_read_unchecked(&fscache_n_op_pend),
56802+ atomic_read_unchecked(&fscache_n_op_run),
56803+ atomic_read_unchecked(&fscache_n_op_enqueue),
56804+ atomic_read_unchecked(&fscache_n_op_cancelled),
56805+ atomic_read_unchecked(&fscache_n_op_rejected));
56806 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
56807- atomic_read(&fscache_n_op_deferred_release),
56808- atomic_read(&fscache_n_op_release),
56809- atomic_read(&fscache_n_op_gc));
56810+ atomic_read_unchecked(&fscache_n_op_deferred_release),
56811+ atomic_read_unchecked(&fscache_n_op_release),
56812+ atomic_read_unchecked(&fscache_n_op_gc));
56813
56814 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
56815 atomic_read(&fscache_n_cop_alloc_object),
56816diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
56817index aef34b1..59bfd7b 100644
56818--- a/fs/fuse/cuse.c
56819+++ b/fs/fuse/cuse.c
56820@@ -600,10 +600,12 @@ static int __init cuse_init(void)
56821 INIT_LIST_HEAD(&cuse_conntbl[i]);
56822
56823 /* inherit and extend fuse_dev_operations */
56824- cuse_channel_fops = fuse_dev_operations;
56825- cuse_channel_fops.owner = THIS_MODULE;
56826- cuse_channel_fops.open = cuse_channel_open;
56827- cuse_channel_fops.release = cuse_channel_release;
56828+ pax_open_kernel();
56829+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
56830+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
56831+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
56832+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
56833+ pax_close_kernel();
56834
56835 cuse_class = class_create(THIS_MODULE, "cuse");
56836 if (IS_ERR(cuse_class))
56837diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
56838index 1d55f94..088da65 100644
56839--- a/fs/fuse/dev.c
56840+++ b/fs/fuse/dev.c
56841@@ -1339,7 +1339,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
56842 ret = 0;
56843 pipe_lock(pipe);
56844
56845- if (!pipe->readers) {
56846+ if (!atomic_read(&pipe->readers)) {
56847 send_sig(SIGPIPE, current, 0);
56848 if (!ret)
56849 ret = -EPIPE;
56850@@ -1364,7 +1364,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
56851 page_nr++;
56852 ret += buf->len;
56853
56854- if (pipe->files)
56855+ if (atomic_read(&pipe->files))
56856 do_wakeup = 1;
56857 }
56858
56859diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
56860index 8fec28f..cd40dba 100644
56861--- a/fs/fuse/dir.c
56862+++ b/fs/fuse/dir.c
56863@@ -1437,7 +1437,7 @@ static char *read_link(struct dentry *dentry)
56864 return link;
56865 }
56866
56867-static void free_link(char *link)
56868+static void free_link(const char *link)
56869 {
56870 if (!IS_ERR(link))
56871 free_page((unsigned long) link);
56872diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
56873index 64915ee..6bed500 100644
56874--- a/fs/gfs2/inode.c
56875+++ b/fs/gfs2/inode.c
56876@@ -1506,7 +1506,7 @@ out:
56877
56878 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
56879 {
56880- char *s = nd_get_link(nd);
56881+ const char *s = nd_get_link(nd);
56882 if (!IS_ERR(s))
56883 kfree(s);
56884 }
56885diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
56886index d19b30a..ef89c36 100644
56887--- a/fs/hugetlbfs/inode.c
56888+++ b/fs/hugetlbfs/inode.c
56889@@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
56890 struct mm_struct *mm = current->mm;
56891 struct vm_area_struct *vma;
56892 struct hstate *h = hstate_file(file);
56893+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
56894 struct vm_unmapped_area_info info;
56895
56896 if (len & ~huge_page_mask(h))
56897@@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
56898 return addr;
56899 }
56900
56901+#ifdef CONFIG_PAX_RANDMMAP
56902+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
56903+#endif
56904+
56905 if (addr) {
56906 addr = ALIGN(addr, huge_page_size(h));
56907 vma = find_vma(mm, addr);
56908- if (TASK_SIZE - len >= addr &&
56909- (!vma || addr + len <= vma->vm_start))
56910+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
56911 return addr;
56912 }
56913
56914 info.flags = 0;
56915 info.length = len;
56916 info.low_limit = TASK_UNMAPPED_BASE;
56917+
56918+#ifdef CONFIG_PAX_RANDMMAP
56919+ if (mm->pax_flags & MF_PAX_RANDMMAP)
56920+ info.low_limit += mm->delta_mmap;
56921+#endif
56922+
56923 info.high_limit = TASK_SIZE;
56924 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
56925 info.align_offset = 0;
56926@@ -908,7 +918,7 @@ static struct file_system_type hugetlbfs_fs_type = {
56927 };
56928 MODULE_ALIAS_FS("hugetlbfs");
56929
56930-static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
56931+struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
56932
56933 static int can_do_hugetlb_shm(void)
56934 {
56935diff --git a/fs/inode.c b/fs/inode.c
56936index d6dfb09..602e77e 100644
56937--- a/fs/inode.c
56938+++ b/fs/inode.c
56939@@ -880,8 +880,8 @@ unsigned int get_next_ino(void)
56940
56941 #ifdef CONFIG_SMP
56942 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
56943- static atomic_t shared_last_ino;
56944- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
56945+ static atomic_unchecked_t shared_last_ino;
56946+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
56947
56948 res = next - LAST_INO_BATCH;
56949 }
56950diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
56951index 4a6cf28..d3a29d3 100644
56952--- a/fs/jffs2/erase.c
56953+++ b/fs/jffs2/erase.c
56954@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
56955 struct jffs2_unknown_node marker = {
56956 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
56957 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
56958- .totlen = cpu_to_je32(c->cleanmarker_size)
56959+ .totlen = cpu_to_je32(c->cleanmarker_size),
56960+ .hdr_crc = cpu_to_je32(0)
56961 };
56962
56963 jffs2_prealloc_raw_node_refs(c, jeb, 1);
56964diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
56965index a6597d6..41b30ec 100644
56966--- a/fs/jffs2/wbuf.c
56967+++ b/fs/jffs2/wbuf.c
56968@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
56969 {
56970 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
56971 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
56972- .totlen = constant_cpu_to_je32(8)
56973+ .totlen = constant_cpu_to_je32(8),
56974+ .hdr_crc = constant_cpu_to_je32(0)
56975 };
56976
56977 /*
56978diff --git a/fs/jfs/super.c b/fs/jfs/super.c
56979index 6669aa2..36b033d 100644
56980--- a/fs/jfs/super.c
56981+++ b/fs/jfs/super.c
56982@@ -882,7 +882,7 @@ static int __init init_jfs_fs(void)
56983
56984 jfs_inode_cachep =
56985 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
56986- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
56987+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
56988 init_once);
56989 if (jfs_inode_cachep == NULL)
56990 return -ENOMEM;
56991diff --git a/fs/libfs.c b/fs/libfs.c
56992index 3a3a9b5..3a9b074 100644
56993--- a/fs/libfs.c
56994+++ b/fs/libfs.c
56995@@ -150,6 +150,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
56996
56997 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
56998 struct dentry *next = list_entry(p, struct dentry, d_u.d_child);
56999+ char d_name[sizeof(next->d_iname)];
57000+ const unsigned char *name;
57001+
57002 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
57003 if (!simple_positive(next)) {
57004 spin_unlock(&next->d_lock);
57005@@ -158,7 +161,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
57006
57007 spin_unlock(&next->d_lock);
57008 spin_unlock(&dentry->d_lock);
57009- if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
57010+ name = next->d_name.name;
57011+ if (name == next->d_iname) {
57012+ memcpy(d_name, name, next->d_name.len);
57013+ name = d_name;
57014+ }
57015+ if (!dir_emit(ctx, name, next->d_name.len,
57016 next->d_inode->i_ino, dt_type(next->d_inode)))
57017 return 0;
57018 spin_lock(&dentry->d_lock);
57019diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
57020index acd3947..1f896e2 100644
57021--- a/fs/lockd/clntproc.c
57022+++ b/fs/lockd/clntproc.c
57023@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
57024 /*
57025 * Cookie counter for NLM requests
57026 */
57027-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
57028+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
57029
57030 void nlmclnt_next_cookie(struct nlm_cookie *c)
57031 {
57032- u32 cookie = atomic_inc_return(&nlm_cookie);
57033+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
57034
57035 memcpy(c->data, &cookie, 4);
57036 c->len=4;
57037diff --git a/fs/locks.c b/fs/locks.c
57038index b27a300..4156d0b 100644
57039--- a/fs/locks.c
57040+++ b/fs/locks.c
57041@@ -2183,16 +2183,16 @@ void locks_remove_flock(struct file *filp)
57042 return;
57043
57044 if (filp->f_op && filp->f_op->flock) {
57045- struct file_lock fl = {
57046+ struct file_lock flock = {
57047 .fl_pid = current->tgid,
57048 .fl_file = filp,
57049 .fl_flags = FL_FLOCK,
57050 .fl_type = F_UNLCK,
57051 .fl_end = OFFSET_MAX,
57052 };
57053- filp->f_op->flock(filp, F_SETLKW, &fl);
57054- if (fl.fl_ops && fl.fl_ops->fl_release_private)
57055- fl.fl_ops->fl_release_private(&fl);
57056+ filp->f_op->flock(filp, F_SETLKW, &flock);
57057+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
57058+ flock.fl_ops->fl_release_private(&flock);
57059 }
57060
57061 spin_lock(&inode->i_lock);
57062diff --git a/fs/namei.c b/fs/namei.c
57063index 7720fbd..7934bb2 100644
57064--- a/fs/namei.c
57065+++ b/fs/namei.c
57066@@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
57067 if (ret != -EACCES)
57068 return ret;
57069
57070+#ifdef CONFIG_GRKERNSEC
57071+ /* we'll block if we have to log due to a denied capability use */
57072+ if (mask & MAY_NOT_BLOCK)
57073+ return -ECHILD;
57074+#endif
57075+
57076 if (S_ISDIR(inode->i_mode)) {
57077 /* DACs are overridable for directories */
57078- if (inode_capable(inode, CAP_DAC_OVERRIDE))
57079- return 0;
57080 if (!(mask & MAY_WRITE))
57081- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
57082+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
57083+ inode_capable(inode, CAP_DAC_READ_SEARCH))
57084 return 0;
57085+ if (inode_capable(inode, CAP_DAC_OVERRIDE))
57086+ return 0;
57087 return -EACCES;
57088 }
57089 /*
57090+ * Searching includes executable on directories, else just read.
57091+ */
57092+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
57093+ if (mask == MAY_READ)
57094+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
57095+ inode_capable(inode, CAP_DAC_READ_SEARCH))
57096+ return 0;
57097+
57098+ /*
57099 * Read/write DACs are always overridable.
57100 * Executable DACs are overridable when there is
57101 * at least one exec bit set.
57102@@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
57103 if (inode_capable(inode, CAP_DAC_OVERRIDE))
57104 return 0;
57105
57106- /*
57107- * Searching includes executable on directories, else just read.
57108- */
57109- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
57110- if (mask == MAY_READ)
57111- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
57112- return 0;
57113-
57114 return -EACCES;
57115 }
57116
57117@@ -820,7 +828,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
57118 {
57119 struct dentry *dentry = link->dentry;
57120 int error;
57121- char *s;
57122+ const char *s;
57123
57124 BUG_ON(nd->flags & LOOKUP_RCU);
57125
57126@@ -841,6 +849,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
57127 if (error)
57128 goto out_put_nd_path;
57129
57130+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
57131+ dentry->d_inode, dentry, nd->path.mnt)) {
57132+ error = -EACCES;
57133+ goto out_put_nd_path;
57134+ }
57135+
57136 nd->last_type = LAST_BIND;
57137 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
57138 error = PTR_ERR(*p);
57139@@ -1588,6 +1602,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
57140 if (res)
57141 break;
57142 res = walk_component(nd, path, LOOKUP_FOLLOW);
57143+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
57144+ res = -EACCES;
57145 put_link(nd, &link, cookie);
57146 } while (res > 0);
57147
57148@@ -1686,7 +1702,7 @@ EXPORT_SYMBOL(full_name_hash);
57149 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
57150 {
57151 unsigned long a, b, adata, bdata, mask, hash, len;
57152- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
57153+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
57154
57155 hash = a = 0;
57156 len = -sizeof(unsigned long);
57157@@ -1967,6 +1983,8 @@ static int path_lookupat(int dfd, const char *name,
57158 if (err)
57159 break;
57160 err = lookup_last(nd, &path);
57161+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
57162+ err = -EACCES;
57163 put_link(nd, &link, cookie);
57164 }
57165 }
57166@@ -1974,6 +1992,13 @@ static int path_lookupat(int dfd, const char *name,
57167 if (!err)
57168 err = complete_walk(nd);
57169
57170+ if (!err && !(nd->flags & LOOKUP_PARENT)) {
57171+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
57172+ path_put(&nd->path);
57173+ err = -ENOENT;
57174+ }
57175+ }
57176+
57177 if (!err && nd->flags & LOOKUP_DIRECTORY) {
57178 if (!can_lookup(nd->inode)) {
57179 path_put(&nd->path);
57180@@ -2001,8 +2026,15 @@ static int filename_lookup(int dfd, struct filename *name,
57181 retval = path_lookupat(dfd, name->name,
57182 flags | LOOKUP_REVAL, nd);
57183
57184- if (likely(!retval))
57185+ if (likely(!retval)) {
57186 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
57187+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
57188+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
57189+ path_put(&nd->path);
57190+ return -ENOENT;
57191+ }
57192+ }
57193+ }
57194 return retval;
57195 }
57196
57197@@ -2380,6 +2412,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
57198 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
57199 return -EPERM;
57200
57201+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
57202+ return -EPERM;
57203+ if (gr_handle_rawio(inode))
57204+ return -EPERM;
57205+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
57206+ return -EACCES;
57207+
57208 return 0;
57209 }
57210
57211@@ -2601,7 +2640,7 @@ looked_up:
57212 * cleared otherwise prior to returning.
57213 */
57214 static int lookup_open(struct nameidata *nd, struct path *path,
57215- struct file *file,
57216+ struct path *link, struct file *file,
57217 const struct open_flags *op,
57218 bool got_write, int *opened)
57219 {
57220@@ -2636,6 +2675,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
57221 /* Negative dentry, just create the file */
57222 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
57223 umode_t mode = op->mode;
57224+
57225+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
57226+ error = -EACCES;
57227+ goto out_dput;
57228+ }
57229+
57230+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
57231+ error = -EACCES;
57232+ goto out_dput;
57233+ }
57234+
57235 if (!IS_POSIXACL(dir->d_inode))
57236 mode &= ~current_umask();
57237 /*
57238@@ -2657,6 +2707,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
57239 nd->flags & LOOKUP_EXCL);
57240 if (error)
57241 goto out_dput;
57242+ else
57243+ gr_handle_create(dentry, nd->path.mnt);
57244 }
57245 out_no_open:
57246 path->dentry = dentry;
57247@@ -2671,7 +2723,7 @@ out_dput:
57248 /*
57249 * Handle the last step of open()
57250 */
57251-static int do_last(struct nameidata *nd, struct path *path,
57252+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
57253 struct file *file, const struct open_flags *op,
57254 int *opened, struct filename *name)
57255 {
57256@@ -2721,6 +2773,15 @@ static int do_last(struct nameidata *nd, struct path *path,
57257 if (error)
57258 return error;
57259
57260+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
57261+ error = -ENOENT;
57262+ goto out;
57263+ }
57264+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
57265+ error = -EACCES;
57266+ goto out;
57267+ }
57268+
57269 audit_inode(name, dir, LOOKUP_PARENT);
57270 error = -EISDIR;
57271 /* trailing slashes? */
57272@@ -2740,7 +2801,7 @@ retry_lookup:
57273 */
57274 }
57275 mutex_lock(&dir->d_inode->i_mutex);
57276- error = lookup_open(nd, path, file, op, got_write, opened);
57277+ error = lookup_open(nd, path, link, file, op, got_write, opened);
57278 mutex_unlock(&dir->d_inode->i_mutex);
57279
57280 if (error <= 0) {
57281@@ -2764,11 +2825,28 @@ retry_lookup:
57282 goto finish_open_created;
57283 }
57284
57285+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
57286+ error = -ENOENT;
57287+ goto exit_dput;
57288+ }
57289+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
57290+ error = -EACCES;
57291+ goto exit_dput;
57292+ }
57293+
57294 /*
57295 * create/update audit record if it already exists.
57296 */
57297- if (path->dentry->d_inode)
57298+ if (path->dentry->d_inode) {
57299+ /* only check if O_CREAT is specified, all other checks need to go
57300+ into may_open */
57301+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
57302+ error = -EACCES;
57303+ goto exit_dput;
57304+ }
57305+
57306 audit_inode(name, path->dentry, 0);
57307+ }
57308
57309 /*
57310 * If atomic_open() acquired write access it is dropped now due to
57311@@ -2809,6 +2887,11 @@ finish_lookup:
57312 }
57313 }
57314 BUG_ON(inode != path->dentry->d_inode);
57315+ /* if we're resolving a symlink to another symlink */
57316+ if (link && gr_handle_symlink_owner(link, inode)) {
57317+ error = -EACCES;
57318+ goto out;
57319+ }
57320 return 1;
57321 }
57322
57323@@ -2818,7 +2901,6 @@ finish_lookup:
57324 save_parent.dentry = nd->path.dentry;
57325 save_parent.mnt = mntget(path->mnt);
57326 nd->path.dentry = path->dentry;
57327-
57328 }
57329 nd->inode = inode;
57330 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
57331@@ -2828,7 +2910,18 @@ finish_open:
57332 path_put(&save_parent);
57333 return error;
57334 }
57335+
57336+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
57337+ error = -ENOENT;
57338+ goto out;
57339+ }
57340+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
57341+ error = -EACCES;
57342+ goto out;
57343+ }
57344+
57345 audit_inode(name, nd->path.dentry, 0);
57346+
57347 error = -EISDIR;
57348 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
57349 goto out;
57350@@ -2991,7 +3084,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
57351 if (unlikely(error))
57352 goto out;
57353
57354- error = do_last(nd, &path, file, op, &opened, pathname);
57355+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
57356 while (unlikely(error > 0)) { /* trailing symlink */
57357 struct path link = path;
57358 void *cookie;
57359@@ -3009,7 +3102,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
57360 error = follow_link(&link, nd, &cookie);
57361 if (unlikely(error))
57362 break;
57363- error = do_last(nd, &path, file, op, &opened, pathname);
57364+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
57365 put_link(nd, &link, cookie);
57366 }
57367 out:
57368@@ -3109,8 +3202,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
57369 goto unlock;
57370
57371 error = -EEXIST;
57372- if (dentry->d_inode)
57373+ if (dentry->d_inode) {
57374+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
57375+ error = -ENOENT;
57376+ }
57377 goto fail;
57378+ }
57379 /*
57380 * Special case - lookup gave negative, but... we had foo/bar/
57381 * From the vfs_mknod() POV we just have a negative dentry -
57382@@ -3162,6 +3259,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
57383 }
57384 EXPORT_SYMBOL(user_path_create);
57385
57386+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
57387+{
57388+ struct filename *tmp = getname(pathname);
57389+ struct dentry *res;
57390+ if (IS_ERR(tmp))
57391+ return ERR_CAST(tmp);
57392+ res = kern_path_create(dfd, tmp->name, path, lookup_flags);
57393+ if (IS_ERR(res))
57394+ putname(tmp);
57395+ else
57396+ *to = tmp;
57397+ return res;
57398+}
57399+
57400 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
57401 {
57402 int error = may_create(dir, dentry);
57403@@ -3224,6 +3335,17 @@ retry:
57404
57405 if (!IS_POSIXACL(path.dentry->d_inode))
57406 mode &= ~current_umask();
57407+
57408+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
57409+ error = -EPERM;
57410+ goto out;
57411+ }
57412+
57413+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
57414+ error = -EACCES;
57415+ goto out;
57416+ }
57417+
57418 error = security_path_mknod(&path, dentry, mode, dev);
57419 if (error)
57420 goto out;
57421@@ -3240,6 +3362,8 @@ retry:
57422 break;
57423 }
57424 out:
57425+ if (!error)
57426+ gr_handle_create(dentry, path.mnt);
57427 done_path_create(&path, dentry);
57428 if (retry_estale(error, lookup_flags)) {
57429 lookup_flags |= LOOKUP_REVAL;
57430@@ -3292,9 +3416,16 @@ retry:
57431
57432 if (!IS_POSIXACL(path.dentry->d_inode))
57433 mode &= ~current_umask();
57434+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
57435+ error = -EACCES;
57436+ goto out;
57437+ }
57438 error = security_path_mkdir(&path, dentry, mode);
57439 if (!error)
57440 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
57441+ if (!error)
57442+ gr_handle_create(dentry, path.mnt);
57443+out:
57444 done_path_create(&path, dentry);
57445 if (retry_estale(error, lookup_flags)) {
57446 lookup_flags |= LOOKUP_REVAL;
57447@@ -3375,6 +3506,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
57448 struct filename *name;
57449 struct dentry *dentry;
57450 struct nameidata nd;
57451+ ino_t saved_ino = 0;
57452+ dev_t saved_dev = 0;
57453 unsigned int lookup_flags = 0;
57454 retry:
57455 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
57456@@ -3407,10 +3540,21 @@ retry:
57457 error = -ENOENT;
57458 goto exit3;
57459 }
57460+
57461+ saved_ino = dentry->d_inode->i_ino;
57462+ saved_dev = gr_get_dev_from_dentry(dentry);
57463+
57464+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
57465+ error = -EACCES;
57466+ goto exit3;
57467+ }
57468+
57469 error = security_path_rmdir(&nd.path, dentry);
57470 if (error)
57471 goto exit3;
57472 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
57473+ if (!error && (saved_dev || saved_ino))
57474+ gr_handle_delete(saved_ino, saved_dev);
57475 exit3:
57476 dput(dentry);
57477 exit2:
57478@@ -3476,6 +3620,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
57479 struct dentry *dentry;
57480 struct nameidata nd;
57481 struct inode *inode = NULL;
57482+ ino_t saved_ino = 0;
57483+ dev_t saved_dev = 0;
57484 unsigned int lookup_flags = 0;
57485 retry:
57486 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
57487@@ -3502,10 +3648,22 @@ retry:
57488 if (!inode)
57489 goto slashes;
57490 ihold(inode);
57491+
57492+ if (inode->i_nlink <= 1) {
57493+ saved_ino = inode->i_ino;
57494+ saved_dev = gr_get_dev_from_dentry(dentry);
57495+ }
57496+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
57497+ error = -EACCES;
57498+ goto exit2;
57499+ }
57500+
57501 error = security_path_unlink(&nd.path, dentry);
57502 if (error)
57503 goto exit2;
57504 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
57505+ if (!error && (saved_ino || saved_dev))
57506+ gr_handle_delete(saved_ino, saved_dev);
57507 exit2:
57508 dput(dentry);
57509 }
57510@@ -3583,9 +3741,17 @@ retry:
57511 if (IS_ERR(dentry))
57512 goto out_putname;
57513
57514+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
57515+ error = -EACCES;
57516+ goto out;
57517+ }
57518+
57519 error = security_path_symlink(&path, dentry, from->name);
57520 if (!error)
57521 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
57522+ if (!error)
57523+ gr_handle_create(dentry, path.mnt);
57524+out:
57525 done_path_create(&path, dentry);
57526 if (retry_estale(error, lookup_flags)) {
57527 lookup_flags |= LOOKUP_REVAL;
57528@@ -3665,6 +3831,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
57529 {
57530 struct dentry *new_dentry;
57531 struct path old_path, new_path;
57532+ struct filename *to = NULL;
57533 int how = 0;
57534 int error;
57535
57536@@ -3688,7 +3855,7 @@ retry:
57537 if (error)
57538 return error;
57539
57540- new_dentry = user_path_create(newdfd, newname, &new_path,
57541+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
57542 (how & LOOKUP_REVAL));
57543 error = PTR_ERR(new_dentry);
57544 if (IS_ERR(new_dentry))
57545@@ -3700,11 +3867,28 @@ retry:
57546 error = may_linkat(&old_path);
57547 if (unlikely(error))
57548 goto out_dput;
57549+
57550+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
57551+ old_path.dentry->d_inode,
57552+ old_path.dentry->d_inode->i_mode, to)) {
57553+ error = -EACCES;
57554+ goto out_dput;
57555+ }
57556+
57557+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
57558+ old_path.dentry, old_path.mnt, to)) {
57559+ error = -EACCES;
57560+ goto out_dput;
57561+ }
57562+
57563 error = security_path_link(old_path.dentry, &new_path, new_dentry);
57564 if (error)
57565 goto out_dput;
57566 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
57567+ if (!error)
57568+ gr_handle_create(new_dentry, new_path.mnt);
57569 out_dput:
57570+ putname(to);
57571 done_path_create(&new_path, new_dentry);
57572 if (retry_estale(error, how)) {
57573 how |= LOOKUP_REVAL;
57574@@ -3950,12 +4134,21 @@ retry:
57575 if (new_dentry == trap)
57576 goto exit5;
57577
57578+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
57579+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
57580+ to);
57581+ if (error)
57582+ goto exit5;
57583+
57584 error = security_path_rename(&oldnd.path, old_dentry,
57585 &newnd.path, new_dentry);
57586 if (error)
57587 goto exit5;
57588 error = vfs_rename(old_dir->d_inode, old_dentry,
57589 new_dir->d_inode, new_dentry);
57590+ if (!error)
57591+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
57592+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
57593 exit5:
57594 dput(new_dentry);
57595 exit4:
57596@@ -3987,6 +4180,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
57597
57598 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
57599 {
57600+ char tmpbuf[64];
57601+ const char *newlink;
57602 int len;
57603
57604 len = PTR_ERR(link);
57605@@ -3996,7 +4191,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
57606 len = strlen(link);
57607 if (len > (unsigned) buflen)
57608 len = buflen;
57609- if (copy_to_user(buffer, link, len))
57610+
57611+ if (len < sizeof(tmpbuf)) {
57612+ memcpy(tmpbuf, link, len);
57613+ newlink = tmpbuf;
57614+ } else
57615+ newlink = link;
57616+
57617+ if (copy_to_user(buffer, newlink, len))
57618 len = -EFAULT;
57619 out:
57620 return len;
57621diff --git a/fs/namespace.c b/fs/namespace.c
57622index a45ba4f..b4c7d07 100644
57623--- a/fs/namespace.c
57624+++ b/fs/namespace.c
57625@@ -1265,6 +1265,9 @@ static int do_umount(struct mount *mnt, int flags)
57626 if (!(sb->s_flags & MS_RDONLY))
57627 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
57628 up_write(&sb->s_umount);
57629+
57630+ gr_log_remount(mnt->mnt_devname, retval);
57631+
57632 return retval;
57633 }
57634
57635@@ -1283,6 +1286,9 @@ static int do_umount(struct mount *mnt, int flags)
57636 }
57637 br_write_unlock(&vfsmount_lock);
57638 namespace_unlock();
57639+
57640+ gr_log_unmount(mnt->mnt_devname, retval);
57641+
57642 return retval;
57643 }
57644
57645@@ -1302,7 +1308,7 @@ static inline bool may_mount(void)
57646 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
57647 */
57648
57649-SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
57650+SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
57651 {
57652 struct path path;
57653 struct mount *mnt;
57654@@ -1342,7 +1348,7 @@ out:
57655 /*
57656 * The 2.0 compatible umount. No flags.
57657 */
57658-SYSCALL_DEFINE1(oldumount, char __user *, name)
57659+SYSCALL_DEFINE1(oldumount, const char __user *, name)
57660 {
57661 return sys_umount(name, 0);
57662 }
57663@@ -2313,6 +2319,16 @@ long do_mount(const char *dev_name, const char *dir_name,
57664 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
57665 MS_STRICTATIME);
57666
57667+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
57668+ retval = -EPERM;
57669+ goto dput_out;
57670+ }
57671+
57672+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
57673+ retval = -EPERM;
57674+ goto dput_out;
57675+ }
57676+
57677 if (flags & MS_REMOUNT)
57678 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
57679 data_page);
57680@@ -2327,6 +2343,9 @@ long do_mount(const char *dev_name, const char *dir_name,
57681 dev_name, data_page);
57682 dput_out:
57683 path_put(&path);
57684+
57685+ gr_log_mount(dev_name, dir_name, retval);
57686+
57687 return retval;
57688 }
57689
57690@@ -2344,7 +2363,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
57691 * number incrementing at 10Ghz will take 12,427 years to wrap which
57692 * is effectively never, so we can ignore the possibility.
57693 */
57694-static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
57695+static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
57696
57697 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
57698 {
57699@@ -2359,7 +2378,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
57700 kfree(new_ns);
57701 return ERR_PTR(ret);
57702 }
57703- new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
57704+ new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
57705 atomic_set(&new_ns->count, 1);
57706 new_ns->root = NULL;
57707 INIT_LIST_HEAD(&new_ns->list);
57708@@ -2373,7 +2392,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
57709 * Allocate a new namespace structure and populate it with contents
57710 * copied from the namespace of the passed in task structure.
57711 */
57712-static struct mnt_namespace *dup_mnt_ns(struct mnt_namespace *mnt_ns,
57713+static __latent_entropy struct mnt_namespace *dup_mnt_ns(struct mnt_namespace *mnt_ns,
57714 struct user_namespace *user_ns, struct fs_struct *fs)
57715 {
57716 struct mnt_namespace *new_ns;
57717@@ -2500,8 +2519,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
57718 }
57719 EXPORT_SYMBOL(mount_subtree);
57720
57721-SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
57722- char __user *, type, unsigned long, flags, void __user *, data)
57723+SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
57724+ const char __user *, type, unsigned long, flags, void __user *, data)
57725 {
57726 int ret;
57727 char *kernel_type;
57728@@ -2614,6 +2633,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
57729 if (error)
57730 goto out2;
57731
57732+ if (gr_handle_chroot_pivot()) {
57733+ error = -EPERM;
57734+ goto out2;
57735+ }
57736+
57737 get_fs_root(current->fs, &root);
57738 old_mp = lock_mount(&old);
57739 error = PTR_ERR(old_mp);
57740@@ -2864,7 +2888,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
57741 !nsown_capable(CAP_SYS_ADMIN))
57742 return -EPERM;
57743
57744- if (fs->users != 1)
57745+ if (atomic_read(&fs->users) != 1)
57746 return -EINVAL;
57747
57748 get_mnt_ns(mnt_ns);
57749diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
57750index f4ccfe6..a5cf064 100644
57751--- a/fs/nfs/callback_xdr.c
57752+++ b/fs/nfs/callback_xdr.c
57753@@ -51,7 +51,7 @@ struct callback_op {
57754 callback_decode_arg_t decode_args;
57755 callback_encode_res_t encode_res;
57756 long res_maxsize;
57757-};
57758+} __do_const;
57759
57760 static struct callback_op callback_ops[];
57761
57762diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
57763index 941246f..17d8724 100644
57764--- a/fs/nfs/inode.c
57765+++ b/fs/nfs/inode.c
57766@@ -1138,16 +1138,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
57767 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
57768 }
57769
57770-static atomic_long_t nfs_attr_generation_counter;
57771+static atomic_long_unchecked_t nfs_attr_generation_counter;
57772
57773 static unsigned long nfs_read_attr_generation_counter(void)
57774 {
57775- return atomic_long_read(&nfs_attr_generation_counter);
57776+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
57777 }
57778
57779 unsigned long nfs_inc_attr_generation_counter(void)
57780 {
57781- return atomic_long_inc_return(&nfs_attr_generation_counter);
57782+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
57783 }
57784
57785 void nfs_fattr_init(struct nfs_fattr *fattr)
57786diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
57787index 419572f..5414a23 100644
57788--- a/fs/nfsd/nfs4proc.c
57789+++ b/fs/nfsd/nfs4proc.c
57790@@ -1168,7 +1168,7 @@ struct nfsd4_operation {
57791 nfsd4op_rsize op_rsize_bop;
57792 stateid_getter op_get_currentstateid;
57793 stateid_setter op_set_currentstateid;
57794-};
57795+} __do_const;
57796
57797 static struct nfsd4_operation nfsd4_ops[];
57798
57799diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
57800index c2a4701..fd80e29 100644
57801--- a/fs/nfsd/nfs4xdr.c
57802+++ b/fs/nfsd/nfs4xdr.c
57803@@ -1498,7 +1498,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
57804
57805 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
57806
57807-static nfsd4_dec nfsd4_dec_ops[] = {
57808+static const nfsd4_dec nfsd4_dec_ops[] = {
57809 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
57810 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
57811 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
57812@@ -1538,7 +1538,7 @@ static nfsd4_dec nfsd4_dec_ops[] = {
57813 [OP_RELEASE_LOCKOWNER] = (nfsd4_dec)nfsd4_decode_release_lockowner,
57814 };
57815
57816-static nfsd4_dec nfsd41_dec_ops[] = {
57817+static const nfsd4_dec nfsd41_dec_ops[] = {
57818 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
57819 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
57820 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
57821@@ -1600,7 +1600,7 @@ static nfsd4_dec nfsd41_dec_ops[] = {
57822 };
57823
57824 struct nfsd4_minorversion_ops {
57825- nfsd4_dec *decoders;
57826+ const nfsd4_dec *decoders;
57827 int nops;
57828 };
57829
57830diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
57831index e76244e..9fe8f2f1 100644
57832--- a/fs/nfsd/nfscache.c
57833+++ b/fs/nfsd/nfscache.c
57834@@ -526,14 +526,17 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
57835 {
57836 struct svc_cacherep *rp = rqstp->rq_cacherep;
57837 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
57838- int len;
57839+ long len;
57840 size_t bufsize = 0;
57841
57842 if (!rp)
57843 return;
57844
57845- len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
57846- len >>= 2;
57847+ if (statp) {
57848+ len = (char*)statp - (char*)resv->iov_base;
57849+ len = resv->iov_len - len;
57850+ len >>= 2;
57851+ }
57852
57853 /* Don't cache excessive amounts of data and XDR failures */
57854 if (!statp || len > (256 >> 2)) {
57855diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
57856index c827acb..b253b77 100644
57857--- a/fs/nfsd/vfs.c
57858+++ b/fs/nfsd/vfs.c
57859@@ -968,7 +968,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
57860 } else {
57861 oldfs = get_fs();
57862 set_fs(KERNEL_DS);
57863- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
57864+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
57865 set_fs(oldfs);
57866 }
57867
57868@@ -1055,7 +1055,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
57869
57870 /* Write the data. */
57871 oldfs = get_fs(); set_fs(KERNEL_DS);
57872- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
57873+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
57874 set_fs(oldfs);
57875 if (host_err < 0)
57876 goto out_nfserr;
57877@@ -1601,7 +1601,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
57878 */
57879
57880 oldfs = get_fs(); set_fs(KERNEL_DS);
57881- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
57882+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
57883 set_fs(oldfs);
57884
57885 if (host_err < 0)
57886diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
57887index fea6bd5..8ee9d81 100644
57888--- a/fs/nls/nls_base.c
57889+++ b/fs/nls/nls_base.c
57890@@ -234,20 +234,22 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
57891
57892 int register_nls(struct nls_table * nls)
57893 {
57894- struct nls_table ** tmp = &tables;
57895+ struct nls_table *tmp = tables;
57896
57897 if (nls->next)
57898 return -EBUSY;
57899
57900 spin_lock(&nls_lock);
57901- while (*tmp) {
57902- if (nls == *tmp) {
57903+ while (tmp) {
57904+ if (nls == tmp) {
57905 spin_unlock(&nls_lock);
57906 return -EBUSY;
57907 }
57908- tmp = &(*tmp)->next;
57909+ tmp = tmp->next;
57910 }
57911- nls->next = tables;
57912+ pax_open_kernel();
57913+ *(struct nls_table **)&nls->next = tables;
57914+ pax_close_kernel();
57915 tables = nls;
57916 spin_unlock(&nls_lock);
57917 return 0;
57918@@ -255,12 +257,14 @@ int register_nls(struct nls_table * nls)
57919
57920 int unregister_nls(struct nls_table * nls)
57921 {
57922- struct nls_table ** tmp = &tables;
57923+ struct nls_table * const * tmp = &tables;
57924
57925 spin_lock(&nls_lock);
57926 while (*tmp) {
57927 if (nls == *tmp) {
57928- *tmp = nls->next;
57929+ pax_open_kernel();
57930+ *(struct nls_table **)tmp = nls->next;
57931+ pax_close_kernel();
57932 spin_unlock(&nls_lock);
57933 return 0;
57934 }
57935diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
57936index 7424929..35f6be5 100644
57937--- a/fs/nls/nls_euc-jp.c
57938+++ b/fs/nls/nls_euc-jp.c
57939@@ -561,8 +561,10 @@ static int __init init_nls_euc_jp(void)
57940 p_nls = load_nls("cp932");
57941
57942 if (p_nls) {
57943- table.charset2upper = p_nls->charset2upper;
57944- table.charset2lower = p_nls->charset2lower;
57945+ pax_open_kernel();
57946+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
57947+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
57948+ pax_close_kernel();
57949 return register_nls(&table);
57950 }
57951
57952diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
57953index e7bc1d7..06bd4bb 100644
57954--- a/fs/nls/nls_koi8-ru.c
57955+++ b/fs/nls/nls_koi8-ru.c
57956@@ -63,8 +63,10 @@ static int __init init_nls_koi8_ru(void)
57957 p_nls = load_nls("koi8-u");
57958
57959 if (p_nls) {
57960- table.charset2upper = p_nls->charset2upper;
57961- table.charset2lower = p_nls->charset2lower;
57962+ pax_open_kernel();
57963+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
57964+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
57965+ pax_close_kernel();
57966 return register_nls(&table);
57967 }
57968
57969diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
57970index e44cb64..4807084 100644
57971--- a/fs/notify/fanotify/fanotify_user.c
57972+++ b/fs/notify/fanotify/fanotify_user.c
57973@@ -253,8 +253,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
57974
57975 fd = fanotify_event_metadata.fd;
57976 ret = -EFAULT;
57977- if (copy_to_user(buf, &fanotify_event_metadata,
57978- fanotify_event_metadata.event_len))
57979+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
57980+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
57981 goto out_close_fd;
57982
57983 ret = prepare_for_access_response(group, event, fd);
57984diff --git a/fs/notify/notification.c b/fs/notify/notification.c
57985index 7b51b05..5ea5ef6 100644
57986--- a/fs/notify/notification.c
57987+++ b/fs/notify/notification.c
57988@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
57989 * get set to 0 so it will never get 'freed'
57990 */
57991 static struct fsnotify_event *q_overflow_event;
57992-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
57993+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
57994
57995 /**
57996 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
57997@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
57998 */
57999 u32 fsnotify_get_cookie(void)
58000 {
58001- return atomic_inc_return(&fsnotify_sync_cookie);
58002+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
58003 }
58004 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
58005
58006diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
58007index 9e38daf..5727cae 100644
58008--- a/fs/ntfs/dir.c
58009+++ b/fs/ntfs/dir.c
58010@@ -1310,7 +1310,7 @@ find_next_index_buffer:
58011 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
58012 ~(s64)(ndir->itype.index.block_size - 1)));
58013 /* Bounds checks. */
58014- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
58015+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
58016 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
58017 "inode 0x%lx or driver bug.", vdir->i_ino);
58018 goto err_out;
58019diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
58020index c5670b8..d590213 100644
58021--- a/fs/ntfs/file.c
58022+++ b/fs/ntfs/file.c
58023@@ -1282,7 +1282,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
58024 char *addr;
58025 size_t total = 0;
58026 unsigned len;
58027- int left;
58028+ unsigned left;
58029
58030 do {
58031 len = PAGE_CACHE_SIZE - ofs;
58032diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
58033index 82650d5..db37dcf 100644
58034--- a/fs/ntfs/super.c
58035+++ b/fs/ntfs/super.c
58036@@ -685,7 +685,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
58037 if (!silent)
58038 ntfs_error(sb, "Primary boot sector is invalid.");
58039 } else if (!silent)
58040- ntfs_error(sb, read_err_str, "primary");
58041+ ntfs_error(sb, read_err_str, "%s", "primary");
58042 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
58043 if (bh_primary)
58044 brelse(bh_primary);
58045@@ -701,7 +701,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
58046 goto hotfix_primary_boot_sector;
58047 brelse(bh_backup);
58048 } else if (!silent)
58049- ntfs_error(sb, read_err_str, "backup");
58050+ ntfs_error(sb, read_err_str, "%s", "backup");
58051 /* Try to read NT3.51- backup boot sector. */
58052 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
58053 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
58054@@ -712,7 +712,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
58055 "sector.");
58056 brelse(bh_backup);
58057 } else if (!silent)
58058- ntfs_error(sb, read_err_str, "backup");
58059+ ntfs_error(sb, read_err_str, "%s", "backup");
58060 /* We failed. Cleanup and return. */
58061 if (bh_primary)
58062 brelse(bh_primary);
58063diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
58064index aebeacd..0dcdd26 100644
58065--- a/fs/ocfs2/localalloc.c
58066+++ b/fs/ocfs2/localalloc.c
58067@@ -1278,7 +1278,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
58068 goto bail;
58069 }
58070
58071- atomic_inc(&osb->alloc_stats.moves);
58072+ atomic_inc_unchecked(&osb->alloc_stats.moves);
58073
58074 bail:
58075 if (handle)
58076diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
58077index 3a90347..c40bef8 100644
58078--- a/fs/ocfs2/ocfs2.h
58079+++ b/fs/ocfs2/ocfs2.h
58080@@ -235,11 +235,11 @@ enum ocfs2_vol_state
58081
58082 struct ocfs2_alloc_stats
58083 {
58084- atomic_t moves;
58085- atomic_t local_data;
58086- atomic_t bitmap_data;
58087- atomic_t bg_allocs;
58088- atomic_t bg_extends;
58089+ atomic_unchecked_t moves;
58090+ atomic_unchecked_t local_data;
58091+ atomic_unchecked_t bitmap_data;
58092+ atomic_unchecked_t bg_allocs;
58093+ atomic_unchecked_t bg_extends;
58094 };
58095
58096 enum ocfs2_local_alloc_state
58097diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
58098index 5397c07..54afc55 100644
58099--- a/fs/ocfs2/suballoc.c
58100+++ b/fs/ocfs2/suballoc.c
58101@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
58102 mlog_errno(status);
58103 goto bail;
58104 }
58105- atomic_inc(&osb->alloc_stats.bg_extends);
58106+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
58107
58108 /* You should never ask for this much metadata */
58109 BUG_ON(bits_wanted >
58110@@ -2000,7 +2000,7 @@ int ocfs2_claim_metadata(handle_t *handle,
58111 mlog_errno(status);
58112 goto bail;
58113 }
58114- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
58115+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
58116
58117 *suballoc_loc = res.sr_bg_blkno;
58118 *suballoc_bit_start = res.sr_bit_offset;
58119@@ -2164,7 +2164,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
58120 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
58121 res->sr_bits);
58122
58123- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
58124+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
58125
58126 BUG_ON(res->sr_bits != 1);
58127
58128@@ -2206,7 +2206,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
58129 mlog_errno(status);
58130 goto bail;
58131 }
58132- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
58133+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
58134
58135 BUG_ON(res.sr_bits != 1);
58136
58137@@ -2310,7 +2310,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
58138 cluster_start,
58139 num_clusters);
58140 if (!status)
58141- atomic_inc(&osb->alloc_stats.local_data);
58142+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
58143 } else {
58144 if (min_clusters > (osb->bitmap_cpg - 1)) {
58145 /* The only paths asking for contiguousness
58146@@ -2336,7 +2336,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
58147 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
58148 res.sr_bg_blkno,
58149 res.sr_bit_offset);
58150- atomic_inc(&osb->alloc_stats.bitmap_data);
58151+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
58152 *num_clusters = res.sr_bits;
58153 }
58154 }
58155diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
58156index 121da2d..a0232bc 100644
58157--- a/fs/ocfs2/super.c
58158+++ b/fs/ocfs2/super.c
58159@@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
58160 "%10s => GlobalAllocs: %d LocalAllocs: %d "
58161 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
58162 "Stats",
58163- atomic_read(&osb->alloc_stats.bitmap_data),
58164- atomic_read(&osb->alloc_stats.local_data),
58165- atomic_read(&osb->alloc_stats.bg_allocs),
58166- atomic_read(&osb->alloc_stats.moves),
58167- atomic_read(&osb->alloc_stats.bg_extends));
58168+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
58169+ atomic_read_unchecked(&osb->alloc_stats.local_data),
58170+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
58171+ atomic_read_unchecked(&osb->alloc_stats.moves),
58172+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
58173
58174 out += snprintf(buf + out, len - out,
58175 "%10s => State: %u Descriptor: %llu Size: %u bits "
58176@@ -2121,11 +2121,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
58177 spin_lock_init(&osb->osb_xattr_lock);
58178 ocfs2_init_steal_slots(osb);
58179
58180- atomic_set(&osb->alloc_stats.moves, 0);
58181- atomic_set(&osb->alloc_stats.local_data, 0);
58182- atomic_set(&osb->alloc_stats.bitmap_data, 0);
58183- atomic_set(&osb->alloc_stats.bg_allocs, 0);
58184- atomic_set(&osb->alloc_stats.bg_extends, 0);
58185+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
58186+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
58187+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
58188+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
58189+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
58190
58191 /* Copy the blockcheck stats from the superblock probe */
58192 osb->osb_ecc_stats = *stats;
58193diff --git a/fs/open.c b/fs/open.c
58194index 7931f76..7b03f3b 100644
58195--- a/fs/open.c
58196+++ b/fs/open.c
58197@@ -32,6 +32,8 @@
58198 #include <linux/dnotify.h>
58199 #include <linux/compat.h>
58200
58201+#define CREATE_TRACE_POINTS
58202+#include <trace/events/fs.h>
58203 #include "internal.h"
58204
58205 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
58206@@ -102,6 +104,8 @@ long vfs_truncate(struct path *path, loff_t length)
58207 error = locks_verify_truncate(inode, NULL, length);
58208 if (!error)
58209 error = security_path_truncate(path);
58210+ if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
58211+ error = -EACCES;
58212 if (!error)
58213 error = do_truncate(path->dentry, length, 0, NULL);
58214
58215@@ -186,6 +190,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
58216 error = locks_verify_truncate(inode, f.file, length);
58217 if (!error)
58218 error = security_path_truncate(&f.file->f_path);
58219+ if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
58220+ error = -EACCES;
58221 if (!error)
58222 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
58223 sb_end_write(inode->i_sb);
58224@@ -360,6 +366,9 @@ retry:
58225 if (__mnt_is_readonly(path.mnt))
58226 res = -EROFS;
58227
58228+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
58229+ res = -EACCES;
58230+
58231 out_path_release:
58232 path_put(&path);
58233 if (retry_estale(res, lookup_flags)) {
58234@@ -391,6 +400,8 @@ retry:
58235 if (error)
58236 goto dput_and_out;
58237
58238+ gr_log_chdir(path.dentry, path.mnt);
58239+
58240 set_fs_pwd(current->fs, &path);
58241
58242 dput_and_out:
58243@@ -420,6 +431,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
58244 goto out_putf;
58245
58246 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
58247+
58248+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
58249+ error = -EPERM;
58250+
58251+ if (!error)
58252+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
58253+
58254 if (!error)
58255 set_fs_pwd(current->fs, &f.file->f_path);
58256 out_putf:
58257@@ -449,7 +467,13 @@ retry:
58258 if (error)
58259 goto dput_and_out;
58260
58261+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
58262+ goto dput_and_out;
58263+
58264 set_fs_root(current->fs, &path);
58265+
58266+ gr_handle_chroot_chdir(&path);
58267+
58268 error = 0;
58269 dput_and_out:
58270 path_put(&path);
58271@@ -471,6 +495,16 @@ static int chmod_common(struct path *path, umode_t mode)
58272 if (error)
58273 return error;
58274 mutex_lock(&inode->i_mutex);
58275+
58276+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
58277+ error = -EACCES;
58278+ goto out_unlock;
58279+ }
58280+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
58281+ error = -EACCES;
58282+ goto out_unlock;
58283+ }
58284+
58285 error = security_path_chmod(path, mode);
58286 if (error)
58287 goto out_unlock;
58288@@ -531,6 +565,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
58289 uid = make_kuid(current_user_ns(), user);
58290 gid = make_kgid(current_user_ns(), group);
58291
58292+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
58293+ return -EACCES;
58294+
58295 newattrs.ia_valid = ATTR_CTIME;
58296 if (user != (uid_t) -1) {
58297 if (!uid_valid(uid))
58298@@ -960,6 +997,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
58299 } else {
58300 fsnotify_open(f);
58301 fd_install(fd, f);
58302+ trace_do_sys_open(tmp->name, flags, mode);
58303 }
58304 }
58305 putname(tmp);
58306diff --git a/fs/pipe.c b/fs/pipe.c
58307index d2c45e1..009fe1c 100644
58308--- a/fs/pipe.c
58309+++ b/fs/pipe.c
58310@@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
58311
58312 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
58313 {
58314- if (pipe->files)
58315+ if (atomic_read(&pipe->files))
58316 mutex_lock_nested(&pipe->mutex, subclass);
58317 }
58318
58319@@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
58320
58321 void pipe_unlock(struct pipe_inode_info *pipe)
58322 {
58323- if (pipe->files)
58324+ if (atomic_read(&pipe->files))
58325 mutex_unlock(&pipe->mutex);
58326 }
58327 EXPORT_SYMBOL(pipe_unlock);
58328@@ -449,9 +449,9 @@ redo:
58329 }
58330 if (bufs) /* More to do? */
58331 continue;
58332- if (!pipe->writers)
58333+ if (!atomic_read(&pipe->writers))
58334 break;
58335- if (!pipe->waiting_writers) {
58336+ if (!atomic_read(&pipe->waiting_writers)) {
58337 /* syscall merging: Usually we must not sleep
58338 * if O_NONBLOCK is set, or if we got some data.
58339 * But if a writer sleeps in kernel space, then
58340@@ -513,7 +513,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
58341 ret = 0;
58342 __pipe_lock(pipe);
58343
58344- if (!pipe->readers) {
58345+ if (!atomic_read(&pipe->readers)) {
58346 send_sig(SIGPIPE, current, 0);
58347 ret = -EPIPE;
58348 goto out;
58349@@ -562,7 +562,7 @@ redo1:
58350 for (;;) {
58351 int bufs;
58352
58353- if (!pipe->readers) {
58354+ if (!atomic_read(&pipe->readers)) {
58355 send_sig(SIGPIPE, current, 0);
58356 if (!ret)
58357 ret = -EPIPE;
58358@@ -653,9 +653,9 @@ redo2:
58359 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
58360 do_wakeup = 0;
58361 }
58362- pipe->waiting_writers++;
58363+ atomic_inc(&pipe->waiting_writers);
58364 pipe_wait(pipe);
58365- pipe->waiting_writers--;
58366+ atomic_dec(&pipe->waiting_writers);
58367 }
58368 out:
58369 __pipe_unlock(pipe);
58370@@ -709,7 +709,7 @@ pipe_poll(struct file *filp, poll_table *wait)
58371 mask = 0;
58372 if (filp->f_mode & FMODE_READ) {
58373 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
58374- if (!pipe->writers && filp->f_version != pipe->w_counter)
58375+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
58376 mask |= POLLHUP;
58377 }
58378
58379@@ -719,7 +719,7 @@ pipe_poll(struct file *filp, poll_table *wait)
58380 * Most Unices do not set POLLERR for FIFOs but on Linux they
58381 * behave exactly like pipes for poll().
58382 */
58383- if (!pipe->readers)
58384+ if (!atomic_read(&pipe->readers))
58385 mask |= POLLERR;
58386 }
58387
58388@@ -734,17 +734,17 @@ pipe_release(struct inode *inode, struct file *file)
58389
58390 __pipe_lock(pipe);
58391 if (file->f_mode & FMODE_READ)
58392- pipe->readers--;
58393+ atomic_dec(&pipe->readers);
58394 if (file->f_mode & FMODE_WRITE)
58395- pipe->writers--;
58396+ atomic_dec(&pipe->writers);
58397
58398- if (pipe->readers || pipe->writers) {
58399+ if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
58400 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
58401 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
58402 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
58403 }
58404 spin_lock(&inode->i_lock);
58405- if (!--pipe->files) {
58406+ if (atomic_dec_and_test(&pipe->files)) {
58407 inode->i_pipe = NULL;
58408 kill = 1;
58409 }
58410@@ -811,7 +811,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
58411 kfree(pipe);
58412 }
58413
58414-static struct vfsmount *pipe_mnt __read_mostly;
58415+struct vfsmount *pipe_mnt __read_mostly;
58416
58417 /*
58418 * pipefs_dname() is called from d_path().
58419@@ -841,8 +841,9 @@ static struct inode * get_pipe_inode(void)
58420 goto fail_iput;
58421
58422 inode->i_pipe = pipe;
58423- pipe->files = 2;
58424- pipe->readers = pipe->writers = 1;
58425+ atomic_set(&pipe->files, 2);
58426+ atomic_set(&pipe->readers, 1);
58427+ atomic_set(&pipe->writers, 1);
58428 inode->i_fop = &pipefifo_fops;
58429
58430 /*
58431@@ -1022,17 +1023,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
58432 spin_lock(&inode->i_lock);
58433 if (inode->i_pipe) {
58434 pipe = inode->i_pipe;
58435- pipe->files++;
58436+ atomic_inc(&pipe->files);
58437 spin_unlock(&inode->i_lock);
58438 } else {
58439 spin_unlock(&inode->i_lock);
58440 pipe = alloc_pipe_info();
58441 if (!pipe)
58442 return -ENOMEM;
58443- pipe->files = 1;
58444+ atomic_set(&pipe->files, 1);
58445 spin_lock(&inode->i_lock);
58446 if (unlikely(inode->i_pipe)) {
58447- inode->i_pipe->files++;
58448+ atomic_inc(&inode->i_pipe->files);
58449 spin_unlock(&inode->i_lock);
58450 free_pipe_info(pipe);
58451 pipe = inode->i_pipe;
58452@@ -1057,10 +1058,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
58453 * opened, even when there is no process writing the FIFO.
58454 */
58455 pipe->r_counter++;
58456- if (pipe->readers++ == 0)
58457+ if (atomic_inc_return(&pipe->readers) == 1)
58458 wake_up_partner(pipe);
58459
58460- if (!is_pipe && !pipe->writers) {
58461+ if (!is_pipe && !atomic_read(&pipe->writers)) {
58462 if ((filp->f_flags & O_NONBLOCK)) {
58463 /* suppress POLLHUP until we have
58464 * seen a writer */
58465@@ -1079,14 +1080,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
58466 * errno=ENXIO when there is no process reading the FIFO.
58467 */
58468 ret = -ENXIO;
58469- if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
58470+ if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
58471 goto err;
58472
58473 pipe->w_counter++;
58474- if (!pipe->writers++)
58475+ if (atomic_inc_return(&pipe->writers) == 1)
58476 wake_up_partner(pipe);
58477
58478- if (!is_pipe && !pipe->readers) {
58479+ if (!is_pipe && !atomic_read(&pipe->readers)) {
58480 if (wait_for_partner(pipe, &pipe->r_counter))
58481 goto err_wr;
58482 }
58483@@ -1100,11 +1101,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
58484 * the process can at least talk to itself.
58485 */
58486
58487- pipe->readers++;
58488- pipe->writers++;
58489+ atomic_inc(&pipe->readers);
58490+ atomic_inc(&pipe->writers);
58491 pipe->r_counter++;
58492 pipe->w_counter++;
58493- if (pipe->readers == 1 || pipe->writers == 1)
58494+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
58495 wake_up_partner(pipe);
58496 break;
58497
58498@@ -1118,20 +1119,20 @@ static int fifo_open(struct inode *inode, struct file *filp)
58499 return 0;
58500
58501 err_rd:
58502- if (!--pipe->readers)
58503+ if (atomic_dec_and_test(&pipe->readers))
58504 wake_up_interruptible(&pipe->wait);
58505 ret = -ERESTARTSYS;
58506 goto err;
58507
58508 err_wr:
58509- if (!--pipe->writers)
58510+ if (atomic_dec_and_test(&pipe->writers))
58511 wake_up_interruptible(&pipe->wait);
58512 ret = -ERESTARTSYS;
58513 goto err;
58514
58515 err:
58516 spin_lock(&inode->i_lock);
58517- if (!--pipe->files) {
58518+ if (atomic_dec_and_test(&pipe->files)) {
58519 inode->i_pipe = NULL;
58520 kill = 1;
58521 }
58522diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
58523index 15af622..0e9f4467 100644
58524--- a/fs/proc/Kconfig
58525+++ b/fs/proc/Kconfig
58526@@ -30,12 +30,12 @@ config PROC_FS
58527
58528 config PROC_KCORE
58529 bool "/proc/kcore support" if !ARM
58530- depends on PROC_FS && MMU
58531+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
58532
58533 config PROC_VMCORE
58534 bool "/proc/vmcore support"
58535- depends on PROC_FS && CRASH_DUMP
58536- default y
58537+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
58538+ default n
58539 help
58540 Exports the dump image of crashed kernel in ELF format.
58541
58542@@ -59,8 +59,8 @@ config PROC_SYSCTL
58543 limited in memory.
58544
58545 config PROC_PAGE_MONITOR
58546- default y
58547- depends on PROC_FS && MMU
58548+ default n
58549+ depends on PROC_FS && MMU && !GRKERNSEC
58550 bool "Enable /proc page monitoring" if EXPERT
58551 help
58552 Various /proc files exist to monitor process memory utilization:
58553diff --git a/fs/proc/array.c b/fs/proc/array.c
58554index cbd0f1b..adec3f0 100644
58555--- a/fs/proc/array.c
58556+++ b/fs/proc/array.c
58557@@ -60,6 +60,7 @@
58558 #include <linux/tty.h>
58559 #include <linux/string.h>
58560 #include <linux/mman.h>
58561+#include <linux/grsecurity.h>
58562 #include <linux/proc_fs.h>
58563 #include <linux/ioport.h>
58564 #include <linux/uaccess.h>
58565@@ -363,6 +364,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
58566 seq_putc(m, '\n');
58567 }
58568
58569+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
58570+static inline void task_pax(struct seq_file *m, struct task_struct *p)
58571+{
58572+ if (p->mm)
58573+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
58574+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
58575+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
58576+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
58577+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
58578+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
58579+ else
58580+ seq_printf(m, "PaX:\t-----\n");
58581+}
58582+#endif
58583+
58584 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
58585 struct pid *pid, struct task_struct *task)
58586 {
58587@@ -381,9 +397,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
58588 task_cpus_allowed(m, task);
58589 cpuset_task_status_allowed(m, task);
58590 task_context_switch_counts(m, task);
58591+
58592+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
58593+ task_pax(m, task);
58594+#endif
58595+
58596+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
58597+ task_grsec_rbac(m, task);
58598+#endif
58599+
58600 return 0;
58601 }
58602
58603+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58604+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
58605+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
58606+ _mm->pax_flags & MF_PAX_SEGMEXEC))
58607+#endif
58608+
58609 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
58610 struct pid *pid, struct task_struct *task, int whole)
58611 {
58612@@ -405,6 +436,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
58613 char tcomm[sizeof(task->comm)];
58614 unsigned long flags;
58615
58616+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58617+ if (current->exec_id != m->exec_id) {
58618+ gr_log_badprocpid("stat");
58619+ return 0;
58620+ }
58621+#endif
58622+
58623 state = *get_task_state(task);
58624 vsize = eip = esp = 0;
58625 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
58626@@ -476,6 +514,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
58627 gtime = task_gtime(task);
58628 }
58629
58630+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58631+ if (PAX_RAND_FLAGS(mm)) {
58632+ eip = 0;
58633+ esp = 0;
58634+ wchan = 0;
58635+ }
58636+#endif
58637+#ifdef CONFIG_GRKERNSEC_HIDESYM
58638+ wchan = 0;
58639+ eip =0;
58640+ esp =0;
58641+#endif
58642+
58643 /* scale priority and nice values from timeslices to -20..20 */
58644 /* to make it look like a "normal" Unix priority/nice value */
58645 priority = task_prio(task);
58646@@ -512,9 +563,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
58647 seq_put_decimal_ull(m, ' ', vsize);
58648 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
58649 seq_put_decimal_ull(m, ' ', rsslim);
58650+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58651+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
58652+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
58653+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
58654+#else
58655 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
58656 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
58657 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
58658+#endif
58659 seq_put_decimal_ull(m, ' ', esp);
58660 seq_put_decimal_ull(m, ' ', eip);
58661 /* The signal information here is obsolete.
58662@@ -536,7 +593,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
58663 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
58664 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
58665
58666- if (mm && permitted) {
58667+ if (mm && permitted
58668+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58669+ && !PAX_RAND_FLAGS(mm)
58670+#endif
58671+ ) {
58672 seq_put_decimal_ull(m, ' ', mm->start_data);
58673 seq_put_decimal_ull(m, ' ', mm->end_data);
58674 seq_put_decimal_ull(m, ' ', mm->start_brk);
58675@@ -574,8 +635,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
58676 struct pid *pid, struct task_struct *task)
58677 {
58678 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
58679- struct mm_struct *mm = get_task_mm(task);
58680+ struct mm_struct *mm;
58681
58682+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58683+ if (current->exec_id != m->exec_id) {
58684+ gr_log_badprocpid("statm");
58685+ return 0;
58686+ }
58687+#endif
58688+ mm = get_task_mm(task);
58689 if (mm) {
58690 size = task_statm(mm, &shared, &text, &data, &resident);
58691 mmput(mm);
58692@@ -598,6 +666,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
58693 return 0;
58694 }
58695
58696+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
58697+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
58698+{
58699+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
58700+}
58701+#endif
58702+
58703 #ifdef CONFIG_CHECKPOINT_RESTORE
58704 static struct pid *
58705 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
58706diff --git a/fs/proc/base.c b/fs/proc/base.c
58707index 1485e38..8ad4236 100644
58708--- a/fs/proc/base.c
58709+++ b/fs/proc/base.c
58710@@ -113,6 +113,14 @@ struct pid_entry {
58711 union proc_op op;
58712 };
58713
58714+struct getdents_callback {
58715+ struct linux_dirent __user * current_dir;
58716+ struct linux_dirent __user * previous;
58717+ struct file * file;
58718+ int count;
58719+ int error;
58720+};
58721+
58722 #define NOD(NAME, MODE, IOP, FOP, OP) { \
58723 .name = (NAME), \
58724 .len = sizeof(NAME) - 1, \
58725@@ -210,6 +218,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
58726 if (!mm->arg_end)
58727 goto out_mm; /* Shh! No looking before we're done */
58728
58729+ if (gr_acl_handle_procpidmem(task))
58730+ goto out_mm;
58731+
58732 len = mm->arg_end - mm->arg_start;
58733
58734 if (len > PAGE_SIZE)
58735@@ -237,12 +248,28 @@ out:
58736 return res;
58737 }
58738
58739+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58740+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
58741+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
58742+ _mm->pax_flags & MF_PAX_SEGMEXEC))
58743+#endif
58744+
58745 static int proc_pid_auxv(struct task_struct *task, char *buffer)
58746 {
58747 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
58748 int res = PTR_ERR(mm);
58749 if (mm && !IS_ERR(mm)) {
58750 unsigned int nwords = 0;
58751+
58752+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58753+ /* allow if we're currently ptracing this task */
58754+ if (PAX_RAND_FLAGS(mm) &&
58755+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
58756+ mmput(mm);
58757+ return 0;
58758+ }
58759+#endif
58760+
58761 do {
58762 nwords += 2;
58763 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
58764@@ -256,7 +283,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
58765 }
58766
58767
58768-#ifdef CONFIG_KALLSYMS
58769+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
58770 /*
58771 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
58772 * Returns the resolved symbol. If that fails, simply return the address.
58773@@ -295,7 +322,7 @@ static void unlock_trace(struct task_struct *task)
58774 mutex_unlock(&task->signal->cred_guard_mutex);
58775 }
58776
58777-#ifdef CONFIG_STACKTRACE
58778+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
58779
58780 #define MAX_STACK_TRACE_DEPTH 64
58781
58782@@ -518,7 +545,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
58783 return count;
58784 }
58785
58786-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
58787+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
58788 static int proc_pid_syscall(struct task_struct *task, char *buffer)
58789 {
58790 long nr;
58791@@ -547,7 +574,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
58792 /************************************************************************/
58793
58794 /* permission checks */
58795-static int proc_fd_access_allowed(struct inode *inode)
58796+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
58797 {
58798 struct task_struct *task;
58799 int allowed = 0;
58800@@ -557,7 +584,10 @@ static int proc_fd_access_allowed(struct inode *inode)
58801 */
58802 task = get_proc_task(inode);
58803 if (task) {
58804- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
58805+ if (log)
58806+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
58807+ else
58808+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
58809 put_task_struct(task);
58810 }
58811 return allowed;
58812@@ -588,10 +618,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
58813 struct task_struct *task,
58814 int hide_pid_min)
58815 {
58816+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
58817+ return false;
58818+
58819+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
58820+ rcu_read_lock();
58821+ {
58822+ const struct cred *tmpcred = current_cred();
58823+ const struct cred *cred = __task_cred(task);
58824+
58825+ if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
58826+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
58827+ || in_group_p(grsec_proc_gid)
58828+#endif
58829+ ) {
58830+ rcu_read_unlock();
58831+ return true;
58832+ }
58833+ }
58834+ rcu_read_unlock();
58835+
58836+ if (!pid->hide_pid)
58837+ return false;
58838+#endif
58839+
58840 if (pid->hide_pid < hide_pid_min)
58841 return true;
58842 if (in_group_p(pid->pid_gid))
58843 return true;
58844+
58845 return ptrace_may_access(task, PTRACE_MODE_READ);
58846 }
58847
58848@@ -609,7 +664,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
58849 put_task_struct(task);
58850
58851 if (!has_perms) {
58852+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
58853+ {
58854+#else
58855 if (pid->hide_pid == 2) {
58856+#endif
58857 /*
58858 * Let's make getdents(), stat(), and open()
58859 * consistent with each other. If a process
58860@@ -707,6 +766,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
58861 if (!task)
58862 return -ESRCH;
58863
58864+ if (gr_acl_handle_procpidmem(task)) {
58865+ put_task_struct(task);
58866+ return -EPERM;
58867+ }
58868+
58869 mm = mm_access(task, mode);
58870 put_task_struct(task);
58871
58872@@ -722,6 +786,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
58873
58874 file->private_data = mm;
58875
58876+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58877+ file->f_version = current->exec_id;
58878+#endif
58879+
58880 return 0;
58881 }
58882
58883@@ -743,6 +811,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
58884 ssize_t copied;
58885 char *page;
58886
58887+#ifdef CONFIG_GRKERNSEC
58888+ if (write)
58889+ return -EPERM;
58890+#endif
58891+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58892+ if (file->f_version != current->exec_id) {
58893+ gr_log_badprocpid("mem");
58894+ return 0;
58895+ }
58896+#endif
58897+
58898 if (!mm)
58899 return 0;
58900
58901@@ -755,7 +834,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
58902 goto free;
58903
58904 while (count > 0) {
58905- int this_len = min_t(int, count, PAGE_SIZE);
58906+ ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
58907
58908 if (write && copy_from_user(page, buf, this_len)) {
58909 copied = -EFAULT;
58910@@ -847,6 +926,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
58911 if (!mm)
58912 return 0;
58913
58914+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58915+ if (file->f_version != current->exec_id) {
58916+ gr_log_badprocpid("environ");
58917+ return 0;
58918+ }
58919+#endif
58920+
58921 page = (char *)__get_free_page(GFP_TEMPORARY);
58922 if (!page)
58923 return -ENOMEM;
58924@@ -856,7 +942,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
58925 goto free;
58926 while (count > 0) {
58927 size_t this_len, max_len;
58928- int retval;
58929+ ssize_t retval;
58930
58931 if (src >= (mm->env_end - mm->env_start))
58932 break;
58933@@ -1461,7 +1547,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
58934 int error = -EACCES;
58935
58936 /* Are we allowed to snoop on the tasks file descriptors? */
58937- if (!proc_fd_access_allowed(inode))
58938+ if (!proc_fd_access_allowed(inode, 0))
58939 goto out;
58940
58941 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
58942@@ -1505,8 +1591,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
58943 struct path path;
58944
58945 /* Are we allowed to snoop on the tasks file descriptors? */
58946- if (!proc_fd_access_allowed(inode))
58947- goto out;
58948+ /* logging this is needed for learning on chromium to work properly,
58949+ but we don't want to flood the logs from 'ps' which does a readlink
58950+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
58951+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
58952+ */
58953+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
58954+ if (!proc_fd_access_allowed(inode,0))
58955+ goto out;
58956+ } else {
58957+ if (!proc_fd_access_allowed(inode,1))
58958+ goto out;
58959+ }
58960
58961 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
58962 if (error)
58963@@ -1556,7 +1652,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
58964 rcu_read_lock();
58965 cred = __task_cred(task);
58966 inode->i_uid = cred->euid;
58967+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
58968+ inode->i_gid = grsec_proc_gid;
58969+#else
58970 inode->i_gid = cred->egid;
58971+#endif
58972 rcu_read_unlock();
58973 }
58974 security_task_to_inode(task, inode);
58975@@ -1592,10 +1692,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
58976 return -ENOENT;
58977 }
58978 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
58979+#ifdef CONFIG_GRKERNSEC_PROC_USER
58980+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
58981+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
58982+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
58983+#endif
58984 task_dumpable(task)) {
58985 cred = __task_cred(task);
58986 stat->uid = cred->euid;
58987+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
58988+ stat->gid = grsec_proc_gid;
58989+#else
58990 stat->gid = cred->egid;
58991+#endif
58992 }
58993 }
58994 rcu_read_unlock();
58995@@ -1633,11 +1742,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
58996
58997 if (task) {
58998 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
58999+#ifdef CONFIG_GRKERNSEC_PROC_USER
59000+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
59001+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59002+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
59003+#endif
59004 task_dumpable(task)) {
59005 rcu_read_lock();
59006 cred = __task_cred(task);
59007 inode->i_uid = cred->euid;
59008+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
59009+ inode->i_gid = grsec_proc_gid;
59010+#else
59011 inode->i_gid = cred->egid;
59012+#endif
59013 rcu_read_unlock();
59014 } else {
59015 inode->i_uid = GLOBAL_ROOT_UID;
59016@@ -2166,6 +2284,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
59017 if (!task)
59018 goto out_no_task;
59019
59020+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
59021+ goto out;
59022+
59023 /*
59024 * Yes, it does not scale. And it should not. Don't add
59025 * new entries into /proc/<tgid>/ without very good reasons.
59026@@ -2196,6 +2317,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
59027 if (!task)
59028 return -ENOENT;
59029
59030+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
59031+ goto out;
59032+
59033 if (!dir_emit_dots(file, ctx))
59034 goto out;
59035
59036@@ -2585,7 +2709,7 @@ static const struct pid_entry tgid_base_stuff[] = {
59037 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
59038 #endif
59039 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
59040-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
59041+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
59042 INF("syscall", S_IRUGO, proc_pid_syscall),
59043 #endif
59044 INF("cmdline", S_IRUGO, proc_pid_cmdline),
59045@@ -2610,10 +2734,10 @@ static const struct pid_entry tgid_base_stuff[] = {
59046 #ifdef CONFIG_SECURITY
59047 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
59048 #endif
59049-#ifdef CONFIG_KALLSYMS
59050+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59051 INF("wchan", S_IRUGO, proc_pid_wchan),
59052 #endif
59053-#ifdef CONFIG_STACKTRACE
59054+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59055 ONE("stack", S_IRUGO, proc_pid_stack),
59056 #endif
59057 #ifdef CONFIG_SCHEDSTATS
59058@@ -2647,6 +2771,9 @@ static const struct pid_entry tgid_base_stuff[] = {
59059 #ifdef CONFIG_HARDWALL
59060 INF("hardwall", S_IRUGO, proc_pid_hardwall),
59061 #endif
59062+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
59063+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
59064+#endif
59065 #ifdef CONFIG_USER_NS
59066 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
59067 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
59068@@ -2777,7 +2904,14 @@ static int proc_pid_instantiate(struct inode *dir,
59069 if (!inode)
59070 goto out;
59071
59072+#ifdef CONFIG_GRKERNSEC_PROC_USER
59073+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
59074+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59075+ inode->i_gid = grsec_proc_gid;
59076+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
59077+#else
59078 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
59079+#endif
59080 inode->i_op = &proc_tgid_base_inode_operations;
59081 inode->i_fop = &proc_tgid_base_operations;
59082 inode->i_flags|=S_IMMUTABLE;
59083@@ -2815,7 +2949,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
59084 if (!task)
59085 goto out;
59086
59087+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
59088+ goto out_put_task;
59089+
59090 result = proc_pid_instantiate(dir, dentry, task, NULL);
59091+out_put_task:
59092 put_task_struct(task);
59093 out:
59094 return ERR_PTR(result);
59095@@ -2921,7 +3059,7 @@ static const struct pid_entry tid_base_stuff[] = {
59096 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
59097 #endif
59098 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
59099-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
59100+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
59101 INF("syscall", S_IRUGO, proc_pid_syscall),
59102 #endif
59103 INF("cmdline", S_IRUGO, proc_pid_cmdline),
59104@@ -2948,10 +3086,10 @@ static const struct pid_entry tid_base_stuff[] = {
59105 #ifdef CONFIG_SECURITY
59106 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
59107 #endif
59108-#ifdef CONFIG_KALLSYMS
59109+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59110 INF("wchan", S_IRUGO, proc_pid_wchan),
59111 #endif
59112-#ifdef CONFIG_STACKTRACE
59113+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59114 ONE("stack", S_IRUGO, proc_pid_stack),
59115 #endif
59116 #ifdef CONFIG_SCHEDSTATS
59117diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
59118index 82676e3..5f8518a 100644
59119--- a/fs/proc/cmdline.c
59120+++ b/fs/proc/cmdline.c
59121@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
59122
59123 static int __init proc_cmdline_init(void)
59124 {
59125+#ifdef CONFIG_GRKERNSEC_PROC_ADD
59126+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
59127+#else
59128 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
59129+#endif
59130 return 0;
59131 }
59132 module_init(proc_cmdline_init);
59133diff --git a/fs/proc/devices.c b/fs/proc/devices.c
59134index b143471..bb105e5 100644
59135--- a/fs/proc/devices.c
59136+++ b/fs/proc/devices.c
59137@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
59138
59139 static int __init proc_devices_init(void)
59140 {
59141+#ifdef CONFIG_GRKERNSEC_PROC_ADD
59142+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
59143+#else
59144 proc_create("devices", 0, NULL, &proc_devinfo_operations);
59145+#endif
59146 return 0;
59147 }
59148 module_init(proc_devices_init);
59149diff --git a/fs/proc/fd.c b/fs/proc/fd.c
59150index 0ff80f9..a1d7500 100644
59151--- a/fs/proc/fd.c
59152+++ b/fs/proc/fd.c
59153@@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
59154 if (!task)
59155 return -ENOENT;
59156
59157- files = get_files_struct(task);
59158+ if (!gr_acl_handle_procpidmem(task))
59159+ files = get_files_struct(task);
59160 put_task_struct(task);
59161
59162 if (files) {
59163@@ -283,11 +284,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
59164 */
59165 int proc_fd_permission(struct inode *inode, int mask)
59166 {
59167+ struct task_struct *task;
59168 int rv = generic_permission(inode, mask);
59169- if (rv == 0)
59170- return 0;
59171+
59172 if (task_pid(current) == proc_pid(inode))
59173 rv = 0;
59174+
59175+ task = get_proc_task(inode);
59176+ if (task == NULL)
59177+ return rv;
59178+
59179+ if (gr_acl_handle_procpidmem(task))
59180+ rv = -EACCES;
59181+
59182+ put_task_struct(task);
59183+
59184 return rv;
59185 }
59186
59187diff --git a/fs/proc/inode.c b/fs/proc/inode.c
59188index 073aea6..0630370 100644
59189--- a/fs/proc/inode.c
59190+++ b/fs/proc/inode.c
59191@@ -23,11 +23,17 @@
59192 #include <linux/slab.h>
59193 #include <linux/mount.h>
59194 #include <linux/magic.h>
59195+#include <linux/grsecurity.h>
59196
59197 #include <asm/uaccess.h>
59198
59199 #include "internal.h"
59200
59201+#ifdef CONFIG_PROC_SYSCTL
59202+extern const struct inode_operations proc_sys_inode_operations;
59203+extern const struct inode_operations proc_sys_dir_operations;
59204+#endif
59205+
59206 static void proc_evict_inode(struct inode *inode)
59207 {
59208 struct proc_dir_entry *de;
59209@@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
59210 ns = PROC_I(inode)->ns.ns;
59211 if (ns_ops && ns)
59212 ns_ops->put(ns);
59213+
59214+#ifdef CONFIG_PROC_SYSCTL
59215+ if (inode->i_op == &proc_sys_inode_operations ||
59216+ inode->i_op == &proc_sys_dir_operations)
59217+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
59218+#endif
59219+
59220 }
59221
59222 static struct kmem_cache * proc_inode_cachep;
59223@@ -385,7 +398,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
59224 if (de->mode) {
59225 inode->i_mode = de->mode;
59226 inode->i_uid = de->uid;
59227+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
59228+ inode->i_gid = grsec_proc_gid;
59229+#else
59230 inode->i_gid = de->gid;
59231+#endif
59232 }
59233 if (de->size)
59234 inode->i_size = de->size;
59235diff --git a/fs/proc/internal.h b/fs/proc/internal.h
59236index 651d09a..60c73ae 100644
59237--- a/fs/proc/internal.h
59238+++ b/fs/proc/internal.h
59239@@ -155,6 +155,9 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
59240 struct pid *, struct task_struct *);
59241 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
59242 struct pid *, struct task_struct *);
59243+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
59244+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
59245+#endif
59246
59247 /*
59248 * base.c
59249diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
59250index 06ea155..9a798c7 100644
59251--- a/fs/proc/kcore.c
59252+++ b/fs/proc/kcore.c
59253@@ -484,9 +484,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
59254 * the addresses in the elf_phdr on our list.
59255 */
59256 start = kc_offset_to_vaddr(*fpos - elf_buflen);
59257- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
59258+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
59259+ if (tsz > buflen)
59260 tsz = buflen;
59261-
59262+
59263 while (buflen) {
59264 struct kcore_list *m;
59265
59266@@ -515,20 +516,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
59267 kfree(elf_buf);
59268 } else {
59269 if (kern_addr_valid(start)) {
59270- unsigned long n;
59271+ char *elf_buf;
59272+ mm_segment_t oldfs;
59273
59274- n = copy_to_user(buffer, (char *)start, tsz);
59275- /*
59276- * We cannot distinguish between fault on source
59277- * and fault on destination. When this happens
59278- * we clear too and hope it will trigger the
59279- * EFAULT again.
59280- */
59281- if (n) {
59282- if (clear_user(buffer + tsz - n,
59283- n))
59284+ elf_buf = kmalloc(tsz, GFP_KERNEL);
59285+ if (!elf_buf)
59286+ return -ENOMEM;
59287+ oldfs = get_fs();
59288+ set_fs(KERNEL_DS);
59289+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
59290+ set_fs(oldfs);
59291+ if (copy_to_user(buffer, elf_buf, tsz)) {
59292+ kfree(elf_buf);
59293 return -EFAULT;
59294+ }
59295 }
59296+ set_fs(oldfs);
59297+ kfree(elf_buf);
59298 } else {
59299 if (clear_user(buffer, tsz))
59300 return -EFAULT;
59301@@ -548,6 +552,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
59302
59303 static int open_kcore(struct inode *inode, struct file *filp)
59304 {
59305+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
59306+ return -EPERM;
59307+#endif
59308 if (!capable(CAP_SYS_RAWIO))
59309 return -EPERM;
59310 if (kcore_need_update)
59311diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
59312index 5aa847a..f77c8d4 100644
59313--- a/fs/proc/meminfo.c
59314+++ b/fs/proc/meminfo.c
59315@@ -159,7 +159,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
59316 vmi.used >> 10,
59317 vmi.largest_chunk >> 10
59318 #ifdef CONFIG_MEMORY_FAILURE
59319- ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
59320+ ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
59321 #endif
59322 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
59323 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
59324diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
59325index ccfd99b..1b7e255 100644
59326--- a/fs/proc/nommu.c
59327+++ b/fs/proc/nommu.c
59328@@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
59329 if (len < 1)
59330 len = 1;
59331 seq_printf(m, "%*c", len, ' ');
59332- seq_path(m, &file->f_path, "");
59333+ seq_path(m, &file->f_path, "\n\\");
59334 }
59335
59336 seq_putc(m, '\n');
59337diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
59338index 4677bb7..408e936 100644
59339--- a/fs/proc/proc_net.c
59340+++ b/fs/proc/proc_net.c
59341@@ -23,6 +23,7 @@
59342 #include <linux/nsproxy.h>
59343 #include <net/net_namespace.h>
59344 #include <linux/seq_file.h>
59345+#include <linux/grsecurity.h>
59346
59347 #include "internal.h"
59348
59349@@ -109,6 +110,17 @@ static struct net *get_proc_task_net(struct inode *dir)
59350 struct task_struct *task;
59351 struct nsproxy *ns;
59352 struct net *net = NULL;
59353+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59354+ const struct cred *cred = current_cred();
59355+#endif
59356+
59357+#ifdef CONFIG_GRKERNSEC_PROC_USER
59358+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
59359+ return net;
59360+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59361+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
59362+ return net;
59363+#endif
59364
59365 rcu_read_lock();
59366 task = pid_task(proc_pid(dir), PIDTYPE_PID);
59367diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
59368index 7129046..f2779c6 100644
59369--- a/fs/proc/proc_sysctl.c
59370+++ b/fs/proc/proc_sysctl.c
59371@@ -13,11 +13,15 @@
59372 #include <linux/module.h>
59373 #include "internal.h"
59374
59375+extern int gr_handle_chroot_sysctl(const int op);
59376+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
59377+ const int op);
59378+
59379 static const struct dentry_operations proc_sys_dentry_operations;
59380 static const struct file_operations proc_sys_file_operations;
59381-static const struct inode_operations proc_sys_inode_operations;
59382+const struct inode_operations proc_sys_inode_operations;
59383 static const struct file_operations proc_sys_dir_file_operations;
59384-static const struct inode_operations proc_sys_dir_operations;
59385+const struct inode_operations proc_sys_dir_operations;
59386
59387 void proc_sys_poll_notify(struct ctl_table_poll *poll)
59388 {
59389@@ -467,6 +471,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
59390
59391 err = NULL;
59392 d_set_d_op(dentry, &proc_sys_dentry_operations);
59393+
59394+ gr_handle_proc_create(dentry, inode);
59395+
59396 d_add(dentry, inode);
59397
59398 out:
59399@@ -482,6 +489,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
59400 struct inode *inode = file_inode(filp);
59401 struct ctl_table_header *head = grab_header(inode);
59402 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
59403+ int op = write ? MAY_WRITE : MAY_READ;
59404 ssize_t error;
59405 size_t res;
59406
59407@@ -493,7 +501,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
59408 * and won't be until we finish.
59409 */
59410 error = -EPERM;
59411- if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
59412+ if (sysctl_perm(head, table, op))
59413 goto out;
59414
59415 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
59416@@ -501,6 +509,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
59417 if (!table->proc_handler)
59418 goto out;
59419
59420+#ifdef CONFIG_GRKERNSEC
59421+ error = -EPERM;
59422+ if (gr_handle_chroot_sysctl(op))
59423+ goto out;
59424+ dget(filp->f_path.dentry);
59425+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
59426+ dput(filp->f_path.dentry);
59427+ goto out;
59428+ }
59429+ dput(filp->f_path.dentry);
59430+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
59431+ goto out;
59432+ if (write && !capable(CAP_SYS_ADMIN))
59433+ goto out;
59434+#endif
59435+
59436 /* careful: calling conventions are nasty here */
59437 res = count;
59438 error = table->proc_handler(table, write, buf, &res, ppos);
59439@@ -598,6 +622,9 @@ static bool proc_sys_fill_cache(struct file *file,
59440 return false;
59441 } else {
59442 d_set_d_op(child, &proc_sys_dentry_operations);
59443+
59444+ gr_handle_proc_create(child, inode);
59445+
59446 d_add(child, inode);
59447 }
59448 } else {
59449@@ -641,6 +668,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
59450 if ((*pos)++ < ctx->pos)
59451 return true;
59452
59453+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
59454+ return 0;
59455+
59456 if (unlikely(S_ISLNK(table->mode)))
59457 res = proc_sys_link_fill_cache(file, ctx, head, table);
59458 else
59459@@ -734,6 +764,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
59460 if (IS_ERR(head))
59461 return PTR_ERR(head);
59462
59463+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
59464+ return -ENOENT;
59465+
59466 generic_fillattr(inode, stat);
59467 if (table)
59468 stat->mode = (stat->mode & S_IFMT) | table->mode;
59469@@ -756,13 +789,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
59470 .llseek = generic_file_llseek,
59471 };
59472
59473-static const struct inode_operations proc_sys_inode_operations = {
59474+const struct inode_operations proc_sys_inode_operations = {
59475 .permission = proc_sys_permission,
59476 .setattr = proc_sys_setattr,
59477 .getattr = proc_sys_getattr,
59478 };
59479
59480-static const struct inode_operations proc_sys_dir_operations = {
59481+const struct inode_operations proc_sys_dir_operations = {
59482 .lookup = proc_sys_lookup,
59483 .permission = proc_sys_permission,
59484 .setattr = proc_sys_setattr,
59485@@ -839,7 +872,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
59486 static struct ctl_dir *new_dir(struct ctl_table_set *set,
59487 const char *name, int namelen)
59488 {
59489- struct ctl_table *table;
59490+ ctl_table_no_const *table;
59491 struct ctl_dir *new;
59492 struct ctl_node *node;
59493 char *new_name;
59494@@ -851,7 +884,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
59495 return NULL;
59496
59497 node = (struct ctl_node *)(new + 1);
59498- table = (struct ctl_table *)(node + 1);
59499+ table = (ctl_table_no_const *)(node + 1);
59500 new_name = (char *)(table + 2);
59501 memcpy(new_name, name, namelen);
59502 new_name[namelen] = '\0';
59503@@ -1020,7 +1053,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
59504 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
59505 struct ctl_table_root *link_root)
59506 {
59507- struct ctl_table *link_table, *entry, *link;
59508+ ctl_table_no_const *link_table, *link;
59509+ struct ctl_table *entry;
59510 struct ctl_table_header *links;
59511 struct ctl_node *node;
59512 char *link_name;
59513@@ -1043,7 +1077,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
59514 return NULL;
59515
59516 node = (struct ctl_node *)(links + 1);
59517- link_table = (struct ctl_table *)(node + nr_entries);
59518+ link_table = (ctl_table_no_const *)(node + nr_entries);
59519 link_name = (char *)&link_table[nr_entries + 1];
59520
59521 for (link = link_table, entry = table; entry->procname; link++, entry++) {
59522@@ -1291,8 +1325,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
59523 struct ctl_table_header ***subheader, struct ctl_table_set *set,
59524 struct ctl_table *table)
59525 {
59526- struct ctl_table *ctl_table_arg = NULL;
59527- struct ctl_table *entry, *files;
59528+ ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
59529+ struct ctl_table *entry;
59530 int nr_files = 0;
59531 int nr_dirs = 0;
59532 int err = -ENOMEM;
59533@@ -1304,10 +1338,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
59534 nr_files++;
59535 }
59536
59537- files = table;
59538 /* If there are mixed files and directories we need a new table */
59539 if (nr_dirs && nr_files) {
59540- struct ctl_table *new;
59541+ ctl_table_no_const *new;
59542 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
59543 GFP_KERNEL);
59544 if (!files)
59545@@ -1325,7 +1358,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
59546 /* Register everything except a directory full of subdirectories */
59547 if (nr_files || !nr_dirs) {
59548 struct ctl_table_header *header;
59549- header = __register_sysctl_table(set, path, files);
59550+ header = __register_sysctl_table(set, path, files ? files : table);
59551 if (!header) {
59552 kfree(ctl_table_arg);
59553 goto out;
59554diff --git a/fs/proc/root.c b/fs/proc/root.c
59555index 0e0e83c..005ba6a 100644
59556--- a/fs/proc/root.c
59557+++ b/fs/proc/root.c
59558@@ -183,7 +183,15 @@ void __init proc_root_init(void)
59559 #ifdef CONFIG_PROC_DEVICETREE
59560 proc_device_tree_init();
59561 #endif
59562+#ifdef CONFIG_GRKERNSEC_PROC_ADD
59563+#ifdef CONFIG_GRKERNSEC_PROC_USER
59564+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
59565+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59566+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
59567+#endif
59568+#else
59569 proc_mkdir("bus", NULL);
59570+#endif
59571 proc_sys_init();
59572 }
59573
59574diff --git a/fs/proc/self.c b/fs/proc/self.c
59575index 6b6a993..807cccc 100644
59576--- a/fs/proc/self.c
59577+++ b/fs/proc/self.c
59578@@ -39,7 +39,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
59579 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
59580 void *cookie)
59581 {
59582- char *s = nd_get_link(nd);
59583+ const char *s = nd_get_link(nd);
59584 if (!IS_ERR(s))
59585 kfree(s);
59586 }
59587diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
59588index 107d026..c715aeb 100644
59589--- a/fs/proc/task_mmu.c
59590+++ b/fs/proc/task_mmu.c
59591@@ -12,12 +12,19 @@
59592 #include <linux/swap.h>
59593 #include <linux/swapops.h>
59594 #include <linux/mmu_notifier.h>
59595+#include <linux/grsecurity.h>
59596
59597 #include <asm/elf.h>
59598 #include <asm/uaccess.h>
59599 #include <asm/tlbflush.h>
59600 #include "internal.h"
59601
59602+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59603+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
59604+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
59605+ _mm->pax_flags & MF_PAX_SEGMEXEC))
59606+#endif
59607+
59608 void task_mem(struct seq_file *m, struct mm_struct *mm)
59609 {
59610 unsigned long data, text, lib, swap;
59611@@ -53,8 +60,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
59612 "VmExe:\t%8lu kB\n"
59613 "VmLib:\t%8lu kB\n"
59614 "VmPTE:\t%8lu kB\n"
59615- "VmSwap:\t%8lu kB\n",
59616- hiwater_vm << (PAGE_SHIFT-10),
59617+ "VmSwap:\t%8lu kB\n"
59618+
59619+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
59620+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
59621+#endif
59622+
59623+ ,hiwater_vm << (PAGE_SHIFT-10),
59624 total_vm << (PAGE_SHIFT-10),
59625 mm->locked_vm << (PAGE_SHIFT-10),
59626 mm->pinned_vm << (PAGE_SHIFT-10),
59627@@ -63,7 +75,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
59628 data << (PAGE_SHIFT-10),
59629 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
59630 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
59631- swap << (PAGE_SHIFT-10));
59632+ swap << (PAGE_SHIFT-10)
59633+
59634+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
59635+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59636+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
59637+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
59638+#else
59639+ , mm->context.user_cs_base
59640+ , mm->context.user_cs_limit
59641+#endif
59642+#endif
59643+
59644+ );
59645 }
59646
59647 unsigned long task_vsize(struct mm_struct *mm)
59648@@ -278,13 +302,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
59649 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
59650 }
59651
59652- /* We don't show the stack guard page in /proc/maps */
59653+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59654+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
59655+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
59656+#else
59657 start = vma->vm_start;
59658- if (stack_guard_page_start(vma, start))
59659- start += PAGE_SIZE;
59660 end = vma->vm_end;
59661- if (stack_guard_page_end(vma, end))
59662- end -= PAGE_SIZE;
59663+#endif
59664
59665 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
59666 start,
59667@@ -293,7 +317,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
59668 flags & VM_WRITE ? 'w' : '-',
59669 flags & VM_EXEC ? 'x' : '-',
59670 flags & VM_MAYSHARE ? 's' : 'p',
59671+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59672+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
59673+#else
59674 pgoff,
59675+#endif
59676 MAJOR(dev), MINOR(dev), ino, &len);
59677
59678 /*
59679@@ -302,7 +330,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
59680 */
59681 if (file) {
59682 pad_len_spaces(m, len);
59683- seq_path(m, &file->f_path, "\n");
59684+ seq_path(m, &file->f_path, "\n\\");
59685 goto done;
59686 }
59687
59688@@ -328,8 +356,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
59689 * Thread stack in /proc/PID/task/TID/maps or
59690 * the main process stack.
59691 */
59692- if (!is_pid || (vma->vm_start <= mm->start_stack &&
59693- vma->vm_end >= mm->start_stack)) {
59694+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
59695+ (vma->vm_start <= mm->start_stack &&
59696+ vma->vm_end >= mm->start_stack)) {
59697 name = "[stack]";
59698 } else {
59699 /* Thread stack in /proc/PID/maps */
59700@@ -353,6 +382,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
59701 struct proc_maps_private *priv = m->private;
59702 struct task_struct *task = priv->task;
59703
59704+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59705+ if (current->exec_id != m->exec_id) {
59706+ gr_log_badprocpid("maps");
59707+ return 0;
59708+ }
59709+#endif
59710+
59711 show_map_vma(m, vma, is_pid);
59712
59713 if (m->count < m->size) /* vma is copied successfully */
59714@@ -590,12 +626,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
59715 .private = &mss,
59716 };
59717
59718+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59719+ if (current->exec_id != m->exec_id) {
59720+ gr_log_badprocpid("smaps");
59721+ return 0;
59722+ }
59723+#endif
59724 memset(&mss, 0, sizeof mss);
59725- mss.vma = vma;
59726- /* mmap_sem is held in m_start */
59727- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
59728- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
59729-
59730+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59731+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
59732+#endif
59733+ mss.vma = vma;
59734+ /* mmap_sem is held in m_start */
59735+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
59736+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
59737+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59738+ }
59739+#endif
59740 show_map_vma(m, vma, is_pid);
59741
59742 seq_printf(m,
59743@@ -613,7 +660,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
59744 "KernelPageSize: %8lu kB\n"
59745 "MMUPageSize: %8lu kB\n"
59746 "Locked: %8lu kB\n",
59747+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59748+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
59749+#else
59750 (vma->vm_end - vma->vm_start) >> 10,
59751+#endif
59752 mss.resident >> 10,
59753 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
59754 mss.shared_clean >> 10,
59755@@ -1362,6 +1413,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
59756 int n;
59757 char buffer[50];
59758
59759+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59760+ if (current->exec_id != m->exec_id) {
59761+ gr_log_badprocpid("numa_maps");
59762+ return 0;
59763+ }
59764+#endif
59765+
59766 if (!mm)
59767 return 0;
59768
59769@@ -1379,11 +1437,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
59770 mpol_to_str(buffer, sizeof(buffer), pol);
59771 mpol_cond_put(pol);
59772
59773+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59774+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
59775+#else
59776 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
59777+#endif
59778
59779 if (file) {
59780 seq_printf(m, " file=");
59781- seq_path(m, &file->f_path, "\n\t= ");
59782+ seq_path(m, &file->f_path, "\n\t\\= ");
59783 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
59784 seq_printf(m, " heap");
59785 } else {
59786diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
59787index 56123a6..5a2f6ec 100644
59788--- a/fs/proc/task_nommu.c
59789+++ b/fs/proc/task_nommu.c
59790@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
59791 else
59792 bytes += kobjsize(mm);
59793
59794- if (current->fs && current->fs->users > 1)
59795+ if (current->fs && atomic_read(&current->fs->users) > 1)
59796 sbytes += kobjsize(current->fs);
59797 else
59798 bytes += kobjsize(current->fs);
59799@@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
59800
59801 if (file) {
59802 pad_len_spaces(m, len);
59803- seq_path(m, &file->f_path, "");
59804+ seq_path(m, &file->f_path, "\n\\");
59805 } else if (mm) {
59806 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
59807
59808diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
59809index a1a16eb..6be46ed 100644
59810--- a/fs/proc/vmcore.c
59811+++ b/fs/proc/vmcore.c
59812@@ -104,9 +104,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
59813 nr_bytes = count;
59814
59815 /* If pfn is not ram, return zeros for sparse dump files */
59816- if (pfn_is_ram(pfn) == 0)
59817- memset(buf, 0, nr_bytes);
59818- else {
59819+ if (pfn_is_ram(pfn) == 0) {
59820+ if (userbuf) {
59821+ if (clear_user((char __force_user *)buf, nr_bytes))
59822+ return -EFAULT;
59823+ } else
59824+ memset(buf, 0, nr_bytes);
59825+ } else {
59826 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
59827 offset, userbuf);
59828 if (tmp < 0)
59829@@ -178,7 +182,7 @@ static ssize_t read_vmcore(struct file *file, char __user *buffer,
59830 if (*fpos < m->offset + m->size) {
59831 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
59832 start = m->paddr + *fpos - m->offset;
59833- tmp = read_from_oldmem(buffer, tsz, &start, 1);
59834+ tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, 1);
59835 if (tmp < 0)
59836 return tmp;
59837 buflen -= tsz;
59838diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
59839index b00fcc9..e0c6381 100644
59840--- a/fs/qnx6/qnx6.h
59841+++ b/fs/qnx6/qnx6.h
59842@@ -74,7 +74,7 @@ enum {
59843 BYTESEX_BE,
59844 };
59845
59846-static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
59847+static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
59848 {
59849 if (sbi->s_bytesex == BYTESEX_LE)
59850 return le64_to_cpu((__force __le64)n);
59851@@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
59852 return (__force __fs64)cpu_to_be64(n);
59853 }
59854
59855-static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
59856+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
59857 {
59858 if (sbi->s_bytesex == BYTESEX_LE)
59859 return le32_to_cpu((__force __le32)n);
59860diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
59861index 16e8abb..2dcf914 100644
59862--- a/fs/quota/netlink.c
59863+++ b/fs/quota/netlink.c
59864@@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
59865 void quota_send_warning(struct kqid qid, dev_t dev,
59866 const char warntype)
59867 {
59868- static atomic_t seq;
59869+ static atomic_unchecked_t seq;
59870 struct sk_buff *skb;
59871 void *msg_head;
59872 int ret;
59873@@ -49,7 +49,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
59874 "VFS: Not enough memory to send quota warning.\n");
59875 return;
59876 }
59877- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
59878+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
59879 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
59880 if (!msg_head) {
59881 printk(KERN_ERR
59882diff --git a/fs/read_write.c b/fs/read_write.c
59883index 122a384..0b7ecf2 100644
59884--- a/fs/read_write.c
59885+++ b/fs/read_write.c
59886@@ -440,7 +440,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
59887
59888 old_fs = get_fs();
59889 set_fs(get_ds());
59890- p = (__force const char __user *)buf;
59891+ p = (const char __force_user *)buf;
59892 if (count > MAX_RW_COUNT)
59893 count = MAX_RW_COUNT;
59894 if (file->f_op->write)
59895diff --git a/fs/readdir.c b/fs/readdir.c
59896index 93d71e5..6a14be8 100644
59897--- a/fs/readdir.c
59898+++ b/fs/readdir.c
59899@@ -17,6 +17,7 @@
59900 #include <linux/security.h>
59901 #include <linux/syscalls.h>
59902 #include <linux/unistd.h>
59903+#include <linux/namei.h>
59904
59905 #include <asm/uaccess.h>
59906
59907@@ -69,6 +70,7 @@ struct old_linux_dirent {
59908 struct readdir_callback {
59909 struct dir_context ctx;
59910 struct old_linux_dirent __user * dirent;
59911+ struct file * file;
59912 int result;
59913 };
59914
59915@@ -86,6 +88,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
59916 buf->result = -EOVERFLOW;
59917 return -EOVERFLOW;
59918 }
59919+
59920+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
59921+ return 0;
59922+
59923 buf->result++;
59924 dirent = buf->dirent;
59925 if (!access_ok(VERIFY_WRITE, dirent,
59926@@ -117,6 +123,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
59927 if (!f.file)
59928 return -EBADF;
59929
59930+ buf.file = f.file;
59931 error = iterate_dir(f.file, &buf.ctx);
59932 if (buf.result)
59933 error = buf.result;
59934@@ -142,6 +149,7 @@ struct getdents_callback {
59935 struct dir_context ctx;
59936 struct linux_dirent __user * current_dir;
59937 struct linux_dirent __user * previous;
59938+ struct file * file;
59939 int count;
59940 int error;
59941 };
59942@@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
59943 buf->error = -EOVERFLOW;
59944 return -EOVERFLOW;
59945 }
59946+
59947+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
59948+ return 0;
59949+
59950 dirent = buf->previous;
59951 if (dirent) {
59952 if (__put_user(offset, &dirent->d_off))
59953@@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
59954 if (!f.file)
59955 return -EBADF;
59956
59957+ buf.file = f.file;
59958 error = iterate_dir(f.file, &buf.ctx);
59959 if (error >= 0)
59960 error = buf.error;
59961@@ -226,6 +239,7 @@ struct getdents_callback64 {
59962 struct dir_context ctx;
59963 struct linux_dirent64 __user * current_dir;
59964 struct linux_dirent64 __user * previous;
59965+ struct file *file;
59966 int count;
59967 int error;
59968 };
59969@@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
59970 buf->error = -EINVAL; /* only used if we fail.. */
59971 if (reclen > buf->count)
59972 return -EINVAL;
59973+
59974+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
59975+ return 0;
59976+
59977 dirent = buf->previous;
59978 if (dirent) {
59979 if (__put_user(offset, &dirent->d_off))
59980@@ -288,6 +306,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
59981 if (!f.file)
59982 return -EBADF;
59983
59984+ buf.file = f.file;
59985 error = iterate_dir(f.file, &buf.ctx);
59986 if (error >= 0)
59987 error = buf.error;
59988diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
59989index 2b7882b..1c5ef48 100644
59990--- a/fs/reiserfs/do_balan.c
59991+++ b/fs/reiserfs/do_balan.c
59992@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
59993 return;
59994 }
59995
59996- atomic_inc(&(fs_generation(tb->tb_sb)));
59997+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
59998 do_balance_starts(tb);
59999
60000 /* balance leaf returns 0 except if combining L R and S into
60001diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
60002index a958444..42b2323 100644
60003--- a/fs/reiserfs/procfs.c
60004+++ b/fs/reiserfs/procfs.c
60005@@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
60006 "SMALL_TAILS " : "NO_TAILS ",
60007 replay_only(sb) ? "REPLAY_ONLY " : "",
60008 convert_reiserfs(sb) ? "CONV " : "",
60009- atomic_read(&r->s_generation_counter),
60010+ atomic_read_unchecked(&r->s_generation_counter),
60011 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
60012 SF(s_do_balance), SF(s_unneeded_left_neighbor),
60013 SF(s_good_search_by_key_reada), SF(s_bmaps),
60014diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
60015index 3df5ce6..8c0f4b0 100644
60016--- a/fs/reiserfs/reiserfs.h
60017+++ b/fs/reiserfs/reiserfs.h
60018@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
60019 /* Comment? -Hans */
60020 wait_queue_head_t s_wait;
60021 /* To be obsoleted soon by per buffer seals.. -Hans */
60022- atomic_t s_generation_counter; // increased by one every time the
60023+ atomic_unchecked_t s_generation_counter; // increased by one every time the
60024 // tree gets re-balanced
60025 unsigned long s_properties; /* File system properties. Currently holds
60026 on-disk FS format */
60027@@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
60028 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
60029
60030 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
60031-#define get_generation(s) atomic_read (&fs_generation(s))
60032+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
60033 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
60034 #define __fs_changed(gen,s) (gen != get_generation (s))
60035 #define fs_changed(gen,s) \
60036diff --git a/fs/select.c b/fs/select.c
60037index 35d4adc7..d6c60db 100644
60038--- a/fs/select.c
60039+++ b/fs/select.c
60040@@ -20,6 +20,7 @@
60041 #include <linux/export.h>
60042 #include <linux/slab.h>
60043 #include <linux/poll.h>
60044+#include <linux/security.h>
60045 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
60046 #include <linux/file.h>
60047 #include <linux/fdtable.h>
60048@@ -881,6 +882,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
60049 struct poll_list *walk = head;
60050 unsigned long todo = nfds;
60051
60052+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
60053 if (nfds > rlimit(RLIMIT_NOFILE))
60054 return -EINVAL;
60055
60056diff --git a/fs/seq_file.c b/fs/seq_file.c
60057index 3135c25..d0395dd 100644
60058--- a/fs/seq_file.c
60059+++ b/fs/seq_file.c
60060@@ -10,6 +10,7 @@
60061 #include <linux/seq_file.h>
60062 #include <linux/slab.h>
60063 #include <linux/cred.h>
60064+#include <linux/sched.h>
60065
60066 #include <asm/uaccess.h>
60067 #include <asm/page.h>
60068@@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
60069 #ifdef CONFIG_USER_NS
60070 p->user_ns = file->f_cred->user_ns;
60071 #endif
60072+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60073+ p->exec_id = current->exec_id;
60074+#endif
60075
60076 /*
60077 * Wrappers around seq_open(e.g. swaps_open) need to be
60078@@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
60079 return 0;
60080 }
60081 if (!m->buf) {
60082- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
60083+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
60084 if (!m->buf)
60085 return -ENOMEM;
60086 }
60087@@ -136,7 +140,7 @@ static int traverse(struct seq_file *m, loff_t offset)
60088 Eoverflow:
60089 m->op->stop(m, p);
60090 kfree(m->buf);
60091- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
60092+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
60093 return !m->buf ? -ENOMEM : -EAGAIN;
60094 }
60095
60096@@ -191,7 +195,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
60097
60098 /* grab buffer if we didn't have one */
60099 if (!m->buf) {
60100- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
60101+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
60102 if (!m->buf)
60103 goto Enomem;
60104 }
60105@@ -232,7 +236,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
60106 goto Fill;
60107 m->op->stop(m, p);
60108 kfree(m->buf);
60109- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
60110+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
60111 if (!m->buf)
60112 goto Enomem;
60113 m->count = 0;
60114@@ -581,7 +585,7 @@ static void single_stop(struct seq_file *p, void *v)
60115 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
60116 void *data)
60117 {
60118- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
60119+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
60120 int res = -ENOMEM;
60121
60122 if (op) {
60123diff --git a/fs/splice.c b/fs/splice.c
60124index 3b7ee65..87fc2e4 100644
60125--- a/fs/splice.c
60126+++ b/fs/splice.c
60127@@ -196,7 +196,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
60128 pipe_lock(pipe);
60129
60130 for (;;) {
60131- if (!pipe->readers) {
60132+ if (!atomic_read(&pipe->readers)) {
60133 send_sig(SIGPIPE, current, 0);
60134 if (!ret)
60135 ret = -EPIPE;
60136@@ -219,7 +219,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
60137 page_nr++;
60138 ret += buf->len;
60139
60140- if (pipe->files)
60141+ if (atomic_read(&pipe->files))
60142 do_wakeup = 1;
60143
60144 if (!--spd->nr_pages)
60145@@ -250,9 +250,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
60146 do_wakeup = 0;
60147 }
60148
60149- pipe->waiting_writers++;
60150+ atomic_inc(&pipe->waiting_writers);
60151 pipe_wait(pipe);
60152- pipe->waiting_writers--;
60153+ atomic_dec(&pipe->waiting_writers);
60154 }
60155
60156 pipe_unlock(pipe);
60157@@ -565,7 +565,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
60158 old_fs = get_fs();
60159 set_fs(get_ds());
60160 /* The cast to a user pointer is valid due to the set_fs() */
60161- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
60162+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
60163 set_fs(old_fs);
60164
60165 return res;
60166@@ -580,7 +580,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
60167 old_fs = get_fs();
60168 set_fs(get_ds());
60169 /* The cast to a user pointer is valid due to the set_fs() */
60170- res = vfs_write(file, (__force const char __user *)buf, count, &pos);
60171+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
60172 set_fs(old_fs);
60173
60174 return res;
60175@@ -633,7 +633,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
60176 goto err;
60177
60178 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
60179- vec[i].iov_base = (void __user *) page_address(page);
60180+ vec[i].iov_base = (void __force_user *) page_address(page);
60181 vec[i].iov_len = this_len;
60182 spd.pages[i] = page;
60183 spd.nr_pages++;
60184@@ -829,7 +829,7 @@ int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_desc *sd,
60185 ops->release(pipe, buf);
60186 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
60187 pipe->nrbufs--;
60188- if (pipe->files)
60189+ if (atomic_read(&pipe->files))
60190 sd->need_wakeup = true;
60191 }
60192
60193@@ -854,10 +854,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
60194 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
60195 {
60196 while (!pipe->nrbufs) {
60197- if (!pipe->writers)
60198+ if (!atomic_read(&pipe->writers))
60199 return 0;
60200
60201- if (!pipe->waiting_writers && sd->num_spliced)
60202+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
60203 return 0;
60204
60205 if (sd->flags & SPLICE_F_NONBLOCK)
60206@@ -1179,7 +1179,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
60207 * out of the pipe right after the splice_to_pipe(). So set
60208 * PIPE_READERS appropriately.
60209 */
60210- pipe->readers = 1;
60211+ atomic_set(&pipe->readers, 1);
60212
60213 current->splice_pipe = pipe;
60214 }
60215@@ -1475,6 +1475,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
60216
60217 partial[buffers].offset = off;
60218 partial[buffers].len = plen;
60219+ partial[buffers].private = 0;
60220
60221 off = 0;
60222 len -= plen;
60223@@ -1777,9 +1778,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
60224 ret = -ERESTARTSYS;
60225 break;
60226 }
60227- if (!pipe->writers)
60228+ if (!atomic_read(&pipe->writers))
60229 break;
60230- if (!pipe->waiting_writers) {
60231+ if (!atomic_read(&pipe->waiting_writers)) {
60232 if (flags & SPLICE_F_NONBLOCK) {
60233 ret = -EAGAIN;
60234 break;
60235@@ -1811,7 +1812,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
60236 pipe_lock(pipe);
60237
60238 while (pipe->nrbufs >= pipe->buffers) {
60239- if (!pipe->readers) {
60240+ if (!atomic_read(&pipe->readers)) {
60241 send_sig(SIGPIPE, current, 0);
60242 ret = -EPIPE;
60243 break;
60244@@ -1824,9 +1825,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
60245 ret = -ERESTARTSYS;
60246 break;
60247 }
60248- pipe->waiting_writers++;
60249+ atomic_inc(&pipe->waiting_writers);
60250 pipe_wait(pipe);
60251- pipe->waiting_writers--;
60252+ atomic_dec(&pipe->waiting_writers);
60253 }
60254
60255 pipe_unlock(pipe);
60256@@ -1862,14 +1863,14 @@ retry:
60257 pipe_double_lock(ipipe, opipe);
60258
60259 do {
60260- if (!opipe->readers) {
60261+ if (!atomic_read(&opipe->readers)) {
60262 send_sig(SIGPIPE, current, 0);
60263 if (!ret)
60264 ret = -EPIPE;
60265 break;
60266 }
60267
60268- if (!ipipe->nrbufs && !ipipe->writers)
60269+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
60270 break;
60271
60272 /*
60273@@ -1966,7 +1967,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
60274 pipe_double_lock(ipipe, opipe);
60275
60276 do {
60277- if (!opipe->readers) {
60278+ if (!atomic_read(&opipe->readers)) {
60279 send_sig(SIGPIPE, current, 0);
60280 if (!ret)
60281 ret = -EPIPE;
60282@@ -2011,7 +2012,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
60283 * return EAGAIN if we have the potential of some data in the
60284 * future, otherwise just return 0
60285 */
60286- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
60287+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
60288 ret = -EAGAIN;
60289
60290 pipe_unlock(ipipe);
60291diff --git a/fs/stat.c b/fs/stat.c
60292index 04ce1ac..a13dd1e 100644
60293--- a/fs/stat.c
60294+++ b/fs/stat.c
60295@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
60296 stat->gid = inode->i_gid;
60297 stat->rdev = inode->i_rdev;
60298 stat->size = i_size_read(inode);
60299- stat->atime = inode->i_atime;
60300- stat->mtime = inode->i_mtime;
60301+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
60302+ stat->atime = inode->i_ctime;
60303+ stat->mtime = inode->i_ctime;
60304+ } else {
60305+ stat->atime = inode->i_atime;
60306+ stat->mtime = inode->i_mtime;
60307+ }
60308 stat->ctime = inode->i_ctime;
60309 stat->blksize = (1 << inode->i_blkbits);
60310 stat->blocks = inode->i_blocks;
60311@@ -46,8 +51,14 @@ int vfs_getattr(struct path *path, struct kstat *stat)
60312 if (retval)
60313 return retval;
60314
60315- if (inode->i_op->getattr)
60316- return inode->i_op->getattr(path->mnt, path->dentry, stat);
60317+ if (inode->i_op->getattr) {
60318+ retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
60319+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
60320+ stat->atime = stat->ctime;
60321+ stat->mtime = stat->ctime;
60322+ }
60323+ return retval;
60324+ }
60325
60326 generic_fillattr(inode, stat);
60327 return 0;
60328diff --git a/fs/sysfs/bin.c b/fs/sysfs/bin.c
60329index 15c68f9..36a8b3e 100644
60330--- a/fs/sysfs/bin.c
60331+++ b/fs/sysfs/bin.c
60332@@ -235,13 +235,13 @@ static int bin_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
60333 return ret;
60334 }
60335
60336-static int bin_access(struct vm_area_struct *vma, unsigned long addr,
60337- void *buf, int len, int write)
60338+static ssize_t bin_access(struct vm_area_struct *vma, unsigned long addr,
60339+ void *buf, size_t len, int write)
60340 {
60341 struct file *file = vma->vm_file;
60342 struct bin_buffer *bb = file->private_data;
60343 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
60344- int ret;
60345+ ssize_t ret;
60346
60347 if (!bb->vm_ops)
60348 return -EINVAL;
60349diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
60350index e068e74..92edeb8 100644
60351--- a/fs/sysfs/dir.c
60352+++ b/fs/sysfs/dir.c
60353@@ -40,7 +40,7 @@ static DEFINE_IDA(sysfs_ino_ida);
60354 *
60355 * Returns 31 bit hash of ns + name (so it fits in an off_t )
60356 */
60357-static unsigned int sysfs_name_hash(const void *ns, const char *name)
60358+static unsigned int sysfs_name_hash(const void *ns, const unsigned char *name)
60359 {
60360 unsigned long hash = init_name_hash();
60361 unsigned int len = strlen(name);
60362@@ -679,6 +679,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
60363 struct sysfs_dirent *sd;
60364 int rc;
60365
60366+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
60367+ const char *parent_name = parent_sd->s_name;
60368+
60369+ mode = S_IFDIR | S_IRWXU;
60370+
60371+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
60372+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
60373+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
60374+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
60375+ mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
60376+#endif
60377+
60378 /* allocate */
60379 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
60380 if (!sd)
60381diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
60382index d2bb7ed..fe8c331 100644
60383--- a/fs/sysfs/file.c
60384+++ b/fs/sysfs/file.c
60385@@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
60386
60387 struct sysfs_open_dirent {
60388 atomic_t refcnt;
60389- atomic_t event;
60390+ atomic_unchecked_t event;
60391 wait_queue_head_t poll;
60392 struct list_head buffers; /* goes through sysfs_buffer.list */
60393 };
60394@@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
60395 if (!sysfs_get_active(attr_sd))
60396 return -ENODEV;
60397
60398- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
60399+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
60400 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
60401
60402 sysfs_put_active(attr_sd);
60403@@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
60404 return -ENOMEM;
60405
60406 atomic_set(&new_od->refcnt, 0);
60407- atomic_set(&new_od->event, 1);
60408+ atomic_set_unchecked(&new_od->event, 1);
60409 init_waitqueue_head(&new_od->poll);
60410 INIT_LIST_HEAD(&new_od->buffers);
60411 goto retry;
60412@@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
60413
60414 sysfs_put_active(attr_sd);
60415
60416- if (buffer->event != atomic_read(&od->event))
60417+ if (buffer->event != atomic_read_unchecked(&od->event))
60418 goto trigger;
60419
60420 return DEFAULT_POLLMASK;
60421@@ -452,7 +452,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
60422 if (!WARN_ON(sysfs_type(sd) != SYSFS_KOBJ_ATTR)) {
60423 od = sd->s_attr.open;
60424 if (od) {
60425- atomic_inc(&od->event);
60426+ atomic_inc_unchecked(&od->event);
60427 wake_up_interruptible(&od->poll);
60428 }
60429 }
60430diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
60431index 8c940df..25b733e 100644
60432--- a/fs/sysfs/symlink.c
60433+++ b/fs/sysfs/symlink.c
60434@@ -305,7 +305,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
60435
60436 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
60437 {
60438- char *page = nd_get_link(nd);
60439+ const char *page = nd_get_link(nd);
60440 if (!IS_ERR(page))
60441 free_page((unsigned long)page);
60442 }
60443diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
60444index 69d4889..a810bd4 100644
60445--- a/fs/sysv/sysv.h
60446+++ b/fs/sysv/sysv.h
60447@@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
60448 #endif
60449 }
60450
60451-static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
60452+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
60453 {
60454 if (sbi->s_bytesex == BYTESEX_PDP)
60455 return PDP_swab((__force __u32)n);
60456diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
60457index e18b988..f1d4ad0f 100644
60458--- a/fs/ubifs/io.c
60459+++ b/fs/ubifs/io.c
60460@@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
60461 return err;
60462 }
60463
60464-int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
60465+int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
60466 {
60467 int err;
60468
60469diff --git a/fs/udf/misc.c b/fs/udf/misc.c
60470index c175b4d..8f36a16 100644
60471--- a/fs/udf/misc.c
60472+++ b/fs/udf/misc.c
60473@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
60474
60475 u8 udf_tag_checksum(const struct tag *t)
60476 {
60477- u8 *data = (u8 *)t;
60478+ const u8 *data = (const u8 *)t;
60479 u8 checksum = 0;
60480 int i;
60481 for (i = 0; i < sizeof(struct tag); ++i)
60482diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
60483index 8d974c4..b82f6ec 100644
60484--- a/fs/ufs/swab.h
60485+++ b/fs/ufs/swab.h
60486@@ -22,7 +22,7 @@ enum {
60487 BYTESEX_BE
60488 };
60489
60490-static inline u64
60491+static inline u64 __intentional_overflow(-1)
60492 fs64_to_cpu(struct super_block *sbp, __fs64 n)
60493 {
60494 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
60495@@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
60496 return (__force __fs64)cpu_to_be64(n);
60497 }
60498
60499-static inline u32
60500+static inline u32 __intentional_overflow(-1)
60501 fs32_to_cpu(struct super_block *sbp, __fs32 n)
60502 {
60503 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
60504diff --git a/fs/utimes.c b/fs/utimes.c
60505index f4fb7ec..3fe03c0 100644
60506--- a/fs/utimes.c
60507+++ b/fs/utimes.c
60508@@ -1,6 +1,7 @@
60509 #include <linux/compiler.h>
60510 #include <linux/file.h>
60511 #include <linux/fs.h>
60512+#include <linux/security.h>
60513 #include <linux/linkage.h>
60514 #include <linux/mount.h>
60515 #include <linux/namei.h>
60516@@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
60517 goto mnt_drop_write_and_out;
60518 }
60519 }
60520+
60521+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
60522+ error = -EACCES;
60523+ goto mnt_drop_write_and_out;
60524+ }
60525+
60526 mutex_lock(&inode->i_mutex);
60527 error = notify_change(path->dentry, &newattrs);
60528 mutex_unlock(&inode->i_mutex);
60529diff --git a/fs/xattr.c b/fs/xattr.c
60530index 3377dff..4d074d9 100644
60531--- a/fs/xattr.c
60532+++ b/fs/xattr.c
60533@@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
60534 return rc;
60535 }
60536
60537+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
60538+ssize_t
60539+pax_getxattr(struct dentry *dentry, void *value, size_t size)
60540+{
60541+ struct inode *inode = dentry->d_inode;
60542+ ssize_t error;
60543+
60544+ error = inode_permission(inode, MAY_EXEC);
60545+ if (error)
60546+ return error;
60547+
60548+ if (inode->i_op->getxattr)
60549+ error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
60550+ else
60551+ error = -EOPNOTSUPP;
60552+
60553+ return error;
60554+}
60555+EXPORT_SYMBOL(pax_getxattr);
60556+#endif
60557+
60558 ssize_t
60559 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
60560 {
60561@@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
60562 * Extended attribute SET operations
60563 */
60564 static long
60565-setxattr(struct dentry *d, const char __user *name, const void __user *value,
60566+setxattr(struct path *path, const char __user *name, const void __user *value,
60567 size_t size, int flags)
60568 {
60569 int error;
60570@@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
60571 posix_acl_fix_xattr_from_user(kvalue, size);
60572 }
60573
60574- error = vfs_setxattr(d, kname, kvalue, size, flags);
60575+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
60576+ error = -EACCES;
60577+ goto out;
60578+ }
60579+
60580+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
60581 out:
60582 if (vvalue)
60583 vfree(vvalue);
60584@@ -377,7 +403,7 @@ retry:
60585 return error;
60586 error = mnt_want_write(path.mnt);
60587 if (!error) {
60588- error = setxattr(path.dentry, name, value, size, flags);
60589+ error = setxattr(&path, name, value, size, flags);
60590 mnt_drop_write(path.mnt);
60591 }
60592 path_put(&path);
60593@@ -401,7 +427,7 @@ retry:
60594 return error;
60595 error = mnt_want_write(path.mnt);
60596 if (!error) {
60597- error = setxattr(path.dentry, name, value, size, flags);
60598+ error = setxattr(&path, name, value, size, flags);
60599 mnt_drop_write(path.mnt);
60600 }
60601 path_put(&path);
60602@@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
60603 const void __user *,value, size_t, size, int, flags)
60604 {
60605 struct fd f = fdget(fd);
60606- struct dentry *dentry;
60607 int error = -EBADF;
60608
60609 if (!f.file)
60610 return error;
60611- dentry = f.file->f_path.dentry;
60612- audit_inode(NULL, dentry, 0);
60613+ audit_inode(NULL, f.file->f_path.dentry, 0);
60614 error = mnt_want_write_file(f.file);
60615 if (!error) {
60616- error = setxattr(dentry, name, value, size, flags);
60617+ error = setxattr(&f.file->f_path, name, value, size, flags);
60618 mnt_drop_write_file(f.file);
60619 }
60620 fdput(f);
60621diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
60622index 9fbea87..6b19972 100644
60623--- a/fs/xattr_acl.c
60624+++ b/fs/xattr_acl.c
60625@@ -76,8 +76,8 @@ struct posix_acl *
60626 posix_acl_from_xattr(struct user_namespace *user_ns,
60627 const void *value, size_t size)
60628 {
60629- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
60630- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
60631+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
60632+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
60633 int count;
60634 struct posix_acl *acl;
60635 struct posix_acl_entry *acl_e;
60636diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
60637index 05c698c..6b918af 100644
60638--- a/fs/xfs/xfs_bmap.c
60639+++ b/fs/xfs/xfs_bmap.c
60640@@ -765,7 +765,7 @@ xfs_bmap_validate_ret(
60641
60642 #else
60643 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
60644-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
60645+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
60646 #endif /* DEBUG */
60647
60648 /*
60649diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
60650index 97676a3..399a75d 100644
60651--- a/fs/xfs/xfs_dir2_sf.c
60652+++ b/fs/xfs/xfs_dir2_sf.c
60653@@ -848,7 +848,12 @@ xfs_dir2_sf_getdents(
60654
60655 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
60656 ctx->pos = off & 0x7fffffff;
60657- if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen,
60658+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
60659+ char name[sfep->namelen];
60660+ memcpy(name, sfep->name, sfep->namelen);
60661+ if (!dir_emit(ctx, name, sfep->namelen, ino, DT_UNKNOWN))
60662+ return 0;
60663+ } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen,
60664 ino, DT_UNKNOWN))
60665 return 0;
60666 sfep = xfs_dir2_sf_nextentry(sfp, sfep);
60667diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
60668index 6e2bca5..6ce80d3 100644
60669--- a/fs/xfs/xfs_ioctl.c
60670+++ b/fs/xfs/xfs_ioctl.c
60671@@ -127,7 +127,7 @@ xfs_find_handle(
60672 }
60673
60674 error = -EFAULT;
60675- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
60676+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
60677 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
60678 goto out_put;
60679
60680diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
60681index 96dda62..d6c6a52 100644
60682--- a/fs/xfs/xfs_iops.c
60683+++ b/fs/xfs/xfs_iops.c
60684@@ -395,7 +395,7 @@ xfs_vn_put_link(
60685 struct nameidata *nd,
60686 void *p)
60687 {
60688- char *s = nd_get_link(nd);
60689+ const char *s = nd_get_link(nd);
60690
60691 if (!IS_ERR(s))
60692 kfree(s);
60693diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
60694new file mode 100644
60695index 0000000..0fd7c82
60696--- /dev/null
60697+++ b/grsecurity/Kconfig
60698@@ -0,0 +1,1080 @@
60699+#
60700+# grecurity configuration
60701+#
60702+menu "Memory Protections"
60703+depends on GRKERNSEC
60704+
60705+config GRKERNSEC_KMEM
60706+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
60707+ default y if GRKERNSEC_CONFIG_AUTO
60708+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
60709+ help
60710+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
60711+ be written to or read from to modify or leak the contents of the running
60712+ kernel. /dev/port will also not be allowed to be opened and support
60713+ for /dev/cpu/*/msr will be removed. If you have module
60714+ support disabled, enabling this will close up five ways that are
60715+ currently used to insert malicious code into the running kernel.
60716+
60717+ Even with all these features enabled, we still highly recommend that
60718+ you use the RBAC system, as it is still possible for an attacker to
60719+ modify the running kernel through privileged I/O granted by ioperm/iopl.
60720+
60721+ If you are not using XFree86, you may be able to stop this additional
60722+ case by enabling the 'Disable privileged I/O' option. Though nothing
60723+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
60724+ but only to video memory, which is the only writing we allow in this
60725+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
60726+ not be allowed to mprotect it with PROT_WRITE later.
60727+ Enabling this feature will prevent the "cpupower" and "powertop" tools
60728+ from working.
60729+
60730+ It is highly recommended that you say Y here if you meet all the
60731+ conditions above.
60732+
60733+config GRKERNSEC_VM86
60734+ bool "Restrict VM86 mode"
60735+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
60736+ depends on X86_32
60737+
60738+ help
60739+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
60740+ make use of a special execution mode on 32bit x86 processors called
60741+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
60742+ video cards and will still work with this option enabled. The purpose
60743+ of the option is to prevent exploitation of emulation errors in
60744+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
60745+ Nearly all users should be able to enable this option.
60746+
60747+config GRKERNSEC_IO
60748+ bool "Disable privileged I/O"
60749+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
60750+ depends on X86
60751+ select RTC_CLASS
60752+ select RTC_INTF_DEV
60753+ select RTC_DRV_CMOS
60754+
60755+ help
60756+ If you say Y here, all ioperm and iopl calls will return an error.
60757+ Ioperm and iopl can be used to modify the running kernel.
60758+ Unfortunately, some programs need this access to operate properly,
60759+ the most notable of which are XFree86 and hwclock. hwclock can be
60760+ remedied by having RTC support in the kernel, so real-time
60761+ clock support is enabled if this option is enabled, to ensure
60762+ that hwclock operates correctly. XFree86 still will not
60763+ operate correctly with this option enabled, so DO NOT CHOOSE Y
60764+ IF YOU USE XFree86. If you use XFree86 and you still want to
60765+ protect your kernel against modification, use the RBAC system.
60766+
60767+config GRKERNSEC_JIT_HARDEN
60768+ bool "Harden BPF JIT against spray attacks"
60769+ default y if GRKERNSEC_CONFIG_AUTO
60770+ depends on BPF_JIT
60771+ help
60772+ If you say Y here, the native code generated by the kernel's Berkeley
60773+ Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
60774+ attacks that attempt to fit attacker-beneficial instructions in
60775+ 32bit immediate fields of JIT-generated native instructions. The
60776+ attacker will generally aim to cause an unintended instruction sequence
60777+ of JIT-generated native code to execute by jumping into the middle of
60778+ a generated instruction. This feature effectively randomizes the 32bit
60779+ immediate constants present in the generated code to thwart such attacks.
60780+
60781+ If you're using KERNEXEC, it's recommended that you enable this option
60782+ to supplement the hardening of the kernel.
60783+
60784+config GRKERNSEC_PERF_HARDEN
60785+ bool "Disable unprivileged PERF_EVENTS usage by default"
60786+ default y if GRKERNSEC_CONFIG_AUTO
60787+ depends on PERF_EVENTS
60788+ help
60789+ If you say Y here, the range of acceptable values for the
60790+ /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
60791+ default to a new value: 3. When the sysctl is set to this value, no
60792+ unprivileged use of the PERF_EVENTS syscall interface will be permitted.
60793+
60794+ Though PERF_EVENTS can be used legitimately for performance monitoring
60795+ and low-level application profiling, it is forced on regardless of
60796+ configuration, has been at fault for several vulnerabilities, and
60797+ creates new opportunities for side channels and other information leaks.
60798+
60799+ This feature puts PERF_EVENTS into a secure default state and permits
60800+ the administrator to change out of it temporarily if unprivileged
60801+ application profiling is needed.
60802+
60803+config GRKERNSEC_RAND_THREADSTACK
60804+ bool "Insert random gaps between thread stacks"
60805+ default y if GRKERNSEC_CONFIG_AUTO
60806+ depends on PAX_RANDMMAP && !PPC
60807+ help
60808+ If you say Y here, a random-sized gap will be enforced between allocated
60809+ thread stacks. Glibc's NPTL and other threading libraries that
60810+ pass MAP_STACK to the kernel for thread stack allocation are supported.
60811+ The implementation currently provides 8 bits of entropy for the gap.
60812+
60813+ Many distributions do not compile threaded remote services with the
60814+ -fstack-check argument to GCC, causing the variable-sized stack-based
60815+ allocator, alloca(), to not probe the stack on allocation. This
60816+ permits an unbounded alloca() to skip over any guard page and potentially
60817+ modify another thread's stack reliably. An enforced random gap
60818+ reduces the reliability of such an attack and increases the chance
60819+ that such a read/write to another thread's stack instead lands in
60820+ an unmapped area, causing a crash and triggering grsecurity's
60821+ anti-bruteforcing logic.
60822+
60823+config GRKERNSEC_PROC_MEMMAP
60824+ bool "Harden ASLR against information leaks and entropy reduction"
60825+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
60826+ depends on PAX_NOEXEC || PAX_ASLR
60827+ help
60828+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
60829+ give no information about the addresses of its mappings if
60830+ PaX features that rely on random addresses are enabled on the task.
60831+ In addition to sanitizing this information and disabling other
60832+ dangerous sources of information, this option causes reads of sensitive
60833+ /proc/<pid> entries where the file descriptor was opened in a different
60834+ task than the one performing the read. Such attempts are logged.
60835+ This option also limits argv/env strings for suid/sgid binaries
60836+ to 512KB to prevent a complete exhaustion of the stack entropy provided
60837+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
60838+ binaries to prevent alternative mmap layouts from being abused.
60839+
60840+ If you use PaX it is essential that you say Y here as it closes up
60841+ several holes that make full ASLR useless locally.
60842+
60843+config GRKERNSEC_BRUTE
60844+ bool "Deter exploit bruteforcing"
60845+ default y if GRKERNSEC_CONFIG_AUTO
60846+ help
60847+ If you say Y here, attempts to bruteforce exploits against forking
60848+ daemons such as apache or sshd, as well as against suid/sgid binaries
60849+ will be deterred. When a child of a forking daemon is killed by PaX
60850+ or crashes due to an illegal instruction or other suspicious signal,
60851+ the parent process will be delayed 30 seconds upon every subsequent
60852+ fork until the administrator is able to assess the situation and
60853+ restart the daemon.
60854+ In the suid/sgid case, the attempt is logged, the user has all their
60855+ existing instances of the suid/sgid binary terminated and will
60856+ be unable to execute any suid/sgid binaries for 15 minutes.
60857+
60858+ It is recommended that you also enable signal logging in the auditing
60859+ section so that logs are generated when a process triggers a suspicious
60860+ signal.
60861+ If the sysctl option is enabled, a sysctl option with name
60862+ "deter_bruteforce" is created.
60863+
60864+
60865+config GRKERNSEC_MODHARDEN
60866+ bool "Harden module auto-loading"
60867+ default y if GRKERNSEC_CONFIG_AUTO
60868+ depends on MODULES
60869+ help
60870+ If you say Y here, module auto-loading in response to use of some
60871+ feature implemented by an unloaded module will be restricted to
60872+ root users. Enabling this option helps defend against attacks
60873+ by unprivileged users who abuse the auto-loading behavior to
60874+ cause a vulnerable module to load that is then exploited.
60875+
60876+ If this option prevents a legitimate use of auto-loading for a
60877+ non-root user, the administrator can execute modprobe manually
60878+ with the exact name of the module mentioned in the alert log.
60879+ Alternatively, the administrator can add the module to the list
60880+ of modules loaded at boot by modifying init scripts.
60881+
60882+ Modification of init scripts will most likely be needed on
60883+ Ubuntu servers with encrypted home directory support enabled,
60884+ as the first non-root user logging in will cause the ecb(aes),
60885+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
60886+
60887+config GRKERNSEC_HIDESYM
60888+ bool "Hide kernel symbols"
60889+ default y if GRKERNSEC_CONFIG_AUTO
60890+ select PAX_USERCOPY_SLABS
60891+ help
60892+ If you say Y here, getting information on loaded modules, and
60893+ displaying all kernel symbols through a syscall will be restricted
60894+ to users with CAP_SYS_MODULE. For software compatibility reasons,
60895+ /proc/kallsyms will be restricted to the root user. The RBAC
60896+ system can hide that entry even from root.
60897+
60898+ This option also prevents leaking of kernel addresses through
60899+ several /proc entries.
60900+
60901+ Note that this option is only effective provided the following
60902+ conditions are met:
60903+ 1) The kernel using grsecurity is not precompiled by some distribution
60904+ 2) You have also enabled GRKERNSEC_DMESG
60905+ 3) You are using the RBAC system and hiding other files such as your
60906+ kernel image and System.map. Alternatively, enabling this option
60907+ causes the permissions on /boot, /lib/modules, and the kernel
60908+ source directory to change at compile time to prevent
60909+ reading by non-root users.
60910+ If the above conditions are met, this option will aid in providing a
60911+ useful protection against local kernel exploitation of overflows
60912+ and arbitrary read/write vulnerabilities.
60913+
60914+ It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
60915+ in addition to this feature.
60916+
60917+config GRKERNSEC_KERN_LOCKOUT
60918+ bool "Active kernel exploit response"
60919+ default y if GRKERNSEC_CONFIG_AUTO
60920+ depends on X86 || ARM || PPC || SPARC
60921+ help
60922+ If you say Y here, when a PaX alert is triggered due to suspicious
60923+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
60924+ or an OOPS occurs due to bad memory accesses, instead of just
60925+ terminating the offending process (and potentially allowing
60926+ a subsequent exploit from the same user), we will take one of two
60927+ actions:
60928+ If the user was root, we will panic the system
60929+ If the user was non-root, we will log the attempt, terminate
60930+ all processes owned by the user, then prevent them from creating
60931+ any new processes until the system is restarted
60932+ This deters repeated kernel exploitation/bruteforcing attempts
60933+ and is useful for later forensics.
60934+
60935+endmenu
60936+menu "Role Based Access Control Options"
60937+depends on GRKERNSEC
60938+
60939+config GRKERNSEC_RBAC_DEBUG
60940+ bool
60941+
60942+config GRKERNSEC_NO_RBAC
60943+ bool "Disable RBAC system"
60944+ help
60945+ If you say Y here, the /dev/grsec device will be removed from the kernel,
60946+ preventing the RBAC system from being enabled. You should only say Y
60947+ here if you have no intention of using the RBAC system, so as to prevent
60948+ an attacker with root access from misusing the RBAC system to hide files
60949+ and processes when loadable module support and /dev/[k]mem have been
60950+ locked down.
60951+
60952+config GRKERNSEC_ACL_HIDEKERN
60953+ bool "Hide kernel processes"
60954+ help
60955+ If you say Y here, all kernel threads will be hidden to all
60956+ processes but those whose subject has the "view hidden processes"
60957+ flag.
60958+
60959+config GRKERNSEC_ACL_MAXTRIES
60960+ int "Maximum tries before password lockout"
60961+ default 3
60962+ help
60963+ This option enforces the maximum number of times a user can attempt
60964+ to authorize themselves with the grsecurity RBAC system before being
60965+ denied the ability to attempt authorization again for a specified time.
60966+ The lower the number, the harder it will be to brute-force a password.
60967+
60968+config GRKERNSEC_ACL_TIMEOUT
60969+ int "Time to wait after max password tries, in seconds"
60970+ default 30
60971+ help
60972+ This option specifies the time the user must wait after attempting to
60973+ authorize to the RBAC system with the maximum number of invalid
60974+ passwords. The higher the number, the harder it will be to brute-force
60975+ a password.
60976+
60977+endmenu
60978+menu "Filesystem Protections"
60979+depends on GRKERNSEC
60980+
60981+config GRKERNSEC_PROC
60982+ bool "Proc restrictions"
60983+ default y if GRKERNSEC_CONFIG_AUTO
60984+ help
60985+ If you say Y here, the permissions of the /proc filesystem
60986+ will be altered to enhance system security and privacy. You MUST
60987+ choose either a user only restriction or a user and group restriction.
60988+ Depending upon the option you choose, you can either restrict users to
60989+ see only the processes they themselves run, or choose a group that can
60990+ view all processes and files normally restricted to root if you choose
60991+ the "restrict to user only" option. NOTE: If you're running identd or
60992+ ntpd as a non-root user, you will have to run it as the group you
60993+ specify here.
60994+
60995+config GRKERNSEC_PROC_USER
60996+ bool "Restrict /proc to user only"
60997+ depends on GRKERNSEC_PROC
60998+ help
60999+ If you say Y here, non-root users will only be able to view their own
61000+ processes, and restricts them from viewing network-related information,
61001+ and viewing kernel symbol and module information.
61002+
61003+config GRKERNSEC_PROC_USERGROUP
61004+ bool "Allow special group"
61005+ default y if GRKERNSEC_CONFIG_AUTO
61006+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
61007+ help
61008+ If you say Y here, you will be able to select a group that will be
61009+ able to view all processes and network-related information. If you've
61010+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
61011+ remain hidden. This option is useful if you want to run identd as
61012+ a non-root user. The group you select may also be chosen at boot time
61013+ via "grsec_proc_gid=" on the kernel commandline.
61014+
61015+config GRKERNSEC_PROC_GID
61016+ int "GID for special group"
61017+ depends on GRKERNSEC_PROC_USERGROUP
61018+ default 1001
61019+
61020+config GRKERNSEC_PROC_ADD
61021+ bool "Additional restrictions"
61022+ default y if GRKERNSEC_CONFIG_AUTO
61023+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
61024+ help
61025+ If you say Y here, additional restrictions will be placed on
61026+ /proc that keep normal users from viewing device information and
61027+ slabinfo information that could be useful for exploits.
61028+
61029+config GRKERNSEC_LINK
61030+ bool "Linking restrictions"
61031+ default y if GRKERNSEC_CONFIG_AUTO
61032+ help
61033+ If you say Y here, /tmp race exploits will be prevented, since users
61034+ will no longer be able to follow symlinks owned by other users in
61035+ world-writable +t directories (e.g. /tmp), unless the owner of the
61036+ symlink is the owner of the directory. users will also not be
61037+ able to hardlink to files they do not own. If the sysctl option is
61038+ enabled, a sysctl option with name "linking_restrictions" is created.
61039+
61040+config GRKERNSEC_SYMLINKOWN
61041+ bool "Kernel-enforced SymlinksIfOwnerMatch"
61042+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
61043+ help
61044+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
61045+ that prevents it from being used as a security feature. As Apache
61046+ verifies the symlink by performing a stat() against the target of
61047+ the symlink before it is followed, an attacker can setup a symlink
61048+ to point to a same-owned file, then replace the symlink with one
61049+ that targets another user's file just after Apache "validates" the
61050+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
61051+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
61052+ will be in place for the group you specify. If the sysctl option
61053+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
61054+ created.
61055+
61056+config GRKERNSEC_SYMLINKOWN_GID
61057+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
61058+ depends on GRKERNSEC_SYMLINKOWN
61059+ default 1006
61060+ help
61061+ Setting this GID determines what group kernel-enforced
61062+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
61063+ is enabled, a sysctl option with name "symlinkown_gid" is created.
61064+
61065+config GRKERNSEC_FIFO
61066+ bool "FIFO restrictions"
61067+ default y if GRKERNSEC_CONFIG_AUTO
61068+ help
61069+ If you say Y here, users will not be able to write to FIFOs they don't
61070+ own in world-writable +t directories (e.g. /tmp), unless the owner of
61071+ the FIFO is the same owner of the directory it's held in. If the sysctl
61072+ option is enabled, a sysctl option with name "fifo_restrictions" is
61073+ created.
61074+
61075+config GRKERNSEC_SYSFS_RESTRICT
61076+ bool "Sysfs/debugfs restriction"
61077+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
61078+ depends on SYSFS
61079+ help
61080+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
61081+ any filesystem normally mounted under it (e.g. debugfs) will be
61082+ mostly accessible only by root. These filesystems generally provide access
61083+ to hardware and debug information that isn't appropriate for unprivileged
61084+ users of the system. Sysfs and debugfs have also become a large source
61085+ of new vulnerabilities, ranging from infoleaks to local compromise.
61086+ There has been very little oversight with an eye toward security involved
61087+ in adding new exporters of information to these filesystems, so their
61088+ use is discouraged.
61089+ For reasons of compatibility, a few directories have been whitelisted
61090+ for access by non-root users:
61091+ /sys/fs/selinux
61092+ /sys/fs/fuse
61093+ /sys/devices/system/cpu
61094+
61095+config GRKERNSEC_ROFS
61096+ bool "Runtime read-only mount protection"
61097+ depends on SYSCTL
61098+ help
61099+ If you say Y here, a sysctl option with name "romount_protect" will
61100+ be created. By setting this option to 1 at runtime, filesystems
61101+ will be protected in the following ways:
61102+ * No new writable mounts will be allowed
61103+ * Existing read-only mounts won't be able to be remounted read/write
61104+ * Write operations will be denied on all block devices
61105+ This option acts independently of grsec_lock: once it is set to 1,
61106+ it cannot be turned off. Therefore, please be mindful of the resulting
61107+ behavior if this option is enabled in an init script on a read-only
61108+ filesystem. This feature is mainly intended for secure embedded systems.
61109+
61110+config GRKERNSEC_DEVICE_SIDECHANNEL
61111+ bool "Eliminate stat/notify-based device sidechannels"
61112+ default y if GRKERNSEC_CONFIG_AUTO
61113+ help
61114+ If you say Y here, timing analyses on block or character
61115+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
61116+ will be thwarted for unprivileged users. If a process without
61117+ CAP_MKNOD stats such a device, the last access and last modify times
61118+ will match the device's create time. No access or modify events
61119+ will be triggered through inotify/dnotify/fanotify for such devices.
61120+ This feature will prevent attacks that may at a minimum
61121+ allow an attacker to determine the administrator's password length.
61122+
61123+config GRKERNSEC_CHROOT
61124+ bool "Chroot jail restrictions"
61125+ default y if GRKERNSEC_CONFIG_AUTO
61126+ help
61127+ If you say Y here, you will be able to choose several options that will
61128+ make breaking out of a chrooted jail much more difficult. If you
61129+ encounter no software incompatibilities with the following options, it
61130+ is recommended that you enable each one.
61131+
61132+config GRKERNSEC_CHROOT_MOUNT
61133+ bool "Deny mounts"
61134+ default y if GRKERNSEC_CONFIG_AUTO
61135+ depends on GRKERNSEC_CHROOT
61136+ help
61137+ If you say Y here, processes inside a chroot will not be able to
61138+ mount or remount filesystems. If the sysctl option is enabled, a
61139+ sysctl option with name "chroot_deny_mount" is created.
61140+
61141+config GRKERNSEC_CHROOT_DOUBLE
61142+ bool "Deny double-chroots"
61143+ default y if GRKERNSEC_CONFIG_AUTO
61144+ depends on GRKERNSEC_CHROOT
61145+ help
61146+ If you say Y here, processes inside a chroot will not be able to chroot
61147+ again outside the chroot. This is a widely used method of breaking
61148+ out of a chroot jail and should not be allowed. If the sysctl
61149+ option is enabled, a sysctl option with name
61150+ "chroot_deny_chroot" is created.
61151+
61152+config GRKERNSEC_CHROOT_PIVOT
61153+ bool "Deny pivot_root in chroot"
61154+ default y if GRKERNSEC_CONFIG_AUTO
61155+ depends on GRKERNSEC_CHROOT
61156+ help
61157+ If you say Y here, processes inside a chroot will not be able to use
61158+ a function called pivot_root() that was introduced in Linux 2.3.41. It
61159+ works similar to chroot in that it changes the root filesystem. This
61160+ function could be misused in a chrooted process to attempt to break out
61161+ of the chroot, and therefore should not be allowed. If the sysctl
61162+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
61163+ created.
61164+
61165+config GRKERNSEC_CHROOT_CHDIR
61166+ bool "Enforce chdir(\"/\") on all chroots"
61167+ default y if GRKERNSEC_CONFIG_AUTO
61168+ depends on GRKERNSEC_CHROOT
61169+ help
61170+ If you say Y here, the current working directory of all newly-chrooted
61171+ applications will be set to the the root directory of the chroot.
61172+ The man page on chroot(2) states:
61173+ Note that this call does not change the current working
61174+ directory, so that `.' can be outside the tree rooted at
61175+ `/'. In particular, the super-user can escape from a
61176+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
61177+
61178+ It is recommended that you say Y here, since it's not known to break
61179+ any software. If the sysctl option is enabled, a sysctl option with
61180+ name "chroot_enforce_chdir" is created.
61181+
61182+config GRKERNSEC_CHROOT_CHMOD
61183+ bool "Deny (f)chmod +s"
61184+ default y if GRKERNSEC_CONFIG_AUTO
61185+ depends on GRKERNSEC_CHROOT
61186+ help
61187+ If you say Y here, processes inside a chroot will not be able to chmod
61188+ or fchmod files to make them have suid or sgid bits. This protects
61189+ against another published method of breaking a chroot. If the sysctl
61190+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
61191+ created.
61192+
61193+config GRKERNSEC_CHROOT_FCHDIR
61194+ bool "Deny fchdir out of chroot"
61195+ default y if GRKERNSEC_CONFIG_AUTO
61196+ depends on GRKERNSEC_CHROOT
61197+ help
61198+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
61199+ to a file descriptor of the chrooting process that points to a directory
61200+ outside the filesystem will be stopped. If the sysctl option
61201+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
61202+
61203+config GRKERNSEC_CHROOT_MKNOD
61204+ bool "Deny mknod"
61205+ default y if GRKERNSEC_CONFIG_AUTO
61206+ depends on GRKERNSEC_CHROOT
61207+ help
61208+ If you say Y here, processes inside a chroot will not be allowed to
61209+ mknod. The problem with using mknod inside a chroot is that it
61210+ would allow an attacker to create a device entry that is the same
61211+ as one on the physical root of your system, which could range from
61212+ anything from the console device to a device for your harddrive (which
61213+ they could then use to wipe the drive or steal data). It is recommended
61214+ that you say Y here, unless you run into software incompatibilities.
61215+ If the sysctl option is enabled, a sysctl option with name
61216+ "chroot_deny_mknod" is created.
61217+
61218+config GRKERNSEC_CHROOT_SHMAT
61219+ bool "Deny shmat() out of chroot"
61220+ default y if GRKERNSEC_CONFIG_AUTO
61221+ depends on GRKERNSEC_CHROOT
61222+ help
61223+ If you say Y here, processes inside a chroot will not be able to attach
61224+ to shared memory segments that were created outside of the chroot jail.
61225+ It is recommended that you say Y here. If the sysctl option is enabled,
61226+ a sysctl option with name "chroot_deny_shmat" is created.
61227+
61228+config GRKERNSEC_CHROOT_UNIX
61229+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
61230+ default y if GRKERNSEC_CONFIG_AUTO
61231+ depends on GRKERNSEC_CHROOT
61232+ help
61233+ If you say Y here, processes inside a chroot will not be able to
61234+ connect to abstract (meaning not belonging to a filesystem) Unix
61235+ domain sockets that were bound outside of a chroot. It is recommended
61236+ that you say Y here. If the sysctl option is enabled, a sysctl option
61237+ with name "chroot_deny_unix" is created.
61238+
61239+config GRKERNSEC_CHROOT_FINDTASK
61240+ bool "Protect outside processes"
61241+ default y if GRKERNSEC_CONFIG_AUTO
61242+ depends on GRKERNSEC_CHROOT
61243+ help
61244+ If you say Y here, processes inside a chroot will not be able to
61245+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
61246+ getsid, or view any process outside of the chroot. If the sysctl
61247+ option is enabled, a sysctl option with name "chroot_findtask" is
61248+ created.
61249+
61250+config GRKERNSEC_CHROOT_NICE
61251+ bool "Restrict priority changes"
61252+ default y if GRKERNSEC_CONFIG_AUTO
61253+ depends on GRKERNSEC_CHROOT
61254+ help
61255+ If you say Y here, processes inside a chroot will not be able to raise
61256+ the priority of processes in the chroot, or alter the priority of
61257+ processes outside the chroot. This provides more security than simply
61258+ removing CAP_SYS_NICE from the process' capability set. If the
61259+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
61260+ is created.
61261+
61262+config GRKERNSEC_CHROOT_SYSCTL
61263+ bool "Deny sysctl writes"
61264+ default y if GRKERNSEC_CONFIG_AUTO
61265+ depends on GRKERNSEC_CHROOT
61266+ help
61267+ If you say Y here, an attacker in a chroot will not be able to
61268+ write to sysctl entries, either by sysctl(2) or through a /proc
61269+ interface. It is strongly recommended that you say Y here. If the
61270+ sysctl option is enabled, a sysctl option with name
61271+ "chroot_deny_sysctl" is created.
61272+
61273+config GRKERNSEC_CHROOT_CAPS
61274+ bool "Capability restrictions"
61275+ default y if GRKERNSEC_CONFIG_AUTO
61276+ depends on GRKERNSEC_CHROOT
61277+ help
61278+ If you say Y here, the capabilities on all processes within a
61279+ chroot jail will be lowered to stop module insertion, raw i/o,
61280+ system and net admin tasks, rebooting the system, modifying immutable
61281+ files, modifying IPC owned by another, and changing the system time.
61282+ This is left an option because it can break some apps. Disable this
61283+ if your chrooted apps are having problems performing those kinds of
61284+ tasks. If the sysctl option is enabled, a sysctl option with
61285+ name "chroot_caps" is created.
61286+
61287+config GRKERNSEC_CHROOT_INITRD
61288+ bool "Exempt initrd tasks from restrictions"
61289+ default y if GRKERNSEC_CONFIG_AUTO
61290+ depends on GRKERNSEC_CHROOT && BLK_DEV_RAM
61291+ help
61292+ If you say Y here, tasks started prior to init will be exempted from
61293+ grsecurity's chroot restrictions. This option is mainly meant to
61294+ resolve Plymouth's performing privileged operations unnecessarily
61295+ in a chroot.
61296+
61297+endmenu
61298+menu "Kernel Auditing"
61299+depends on GRKERNSEC
61300+
61301+config GRKERNSEC_AUDIT_GROUP
61302+ bool "Single group for auditing"
61303+ help
61304+ If you say Y here, the exec and chdir logging features will only operate
61305+ on a group you specify. This option is recommended if you only want to
61306+ watch certain users instead of having a large amount of logs from the
61307+ entire system. If the sysctl option is enabled, a sysctl option with
61308+ name "audit_group" is created.
61309+
61310+config GRKERNSEC_AUDIT_GID
61311+ int "GID for auditing"
61312+ depends on GRKERNSEC_AUDIT_GROUP
61313+ default 1007
61314+
61315+config GRKERNSEC_EXECLOG
61316+ bool "Exec logging"
61317+ help
61318+ If you say Y here, all execve() calls will be logged (since the
61319+ other exec*() calls are frontends to execve(), all execution
61320+ will be logged). Useful for shell-servers that like to keep track
61321+ of their users. If the sysctl option is enabled, a sysctl option with
61322+ name "exec_logging" is created.
61323+ WARNING: This option when enabled will produce a LOT of logs, especially
61324+ on an active system.
61325+
61326+config GRKERNSEC_RESLOG
61327+ bool "Resource logging"
61328+ default y if GRKERNSEC_CONFIG_AUTO
61329+ help
61330+ If you say Y here, all attempts to overstep resource limits will
61331+ be logged with the resource name, the requested size, and the current
61332+ limit. It is highly recommended that you say Y here. If the sysctl
61333+ option is enabled, a sysctl option with name "resource_logging" is
61334+ created. If the RBAC system is enabled, the sysctl value is ignored.
61335+
61336+config GRKERNSEC_CHROOT_EXECLOG
61337+ bool "Log execs within chroot"
61338+ help
61339+ If you say Y here, all executions inside a chroot jail will be logged
61340+ to syslog. This can cause a large amount of logs if certain
61341+ applications (eg. djb's daemontools) are installed on the system, and
61342+ is therefore left as an option. If the sysctl option is enabled, a
61343+ sysctl option with name "chroot_execlog" is created.
61344+
61345+config GRKERNSEC_AUDIT_PTRACE
61346+ bool "Ptrace logging"
61347+ help
61348+ If you say Y here, all attempts to attach to a process via ptrace
61349+ will be logged. If the sysctl option is enabled, a sysctl option
61350+ with name "audit_ptrace" is created.
61351+
61352+config GRKERNSEC_AUDIT_CHDIR
61353+ bool "Chdir logging"
61354+ help
61355+ If you say Y here, all chdir() calls will be logged. If the sysctl
61356+ option is enabled, a sysctl option with name "audit_chdir" is created.
61357+
61358+config GRKERNSEC_AUDIT_MOUNT
61359+ bool "(Un)Mount logging"
61360+ help
61361+ If you say Y here, all mounts and unmounts will be logged. If the
61362+ sysctl option is enabled, a sysctl option with name "audit_mount" is
61363+ created.
61364+
61365+config GRKERNSEC_SIGNAL
61366+ bool "Signal logging"
61367+ default y if GRKERNSEC_CONFIG_AUTO
61368+ help
61369+ If you say Y here, certain important signals will be logged, such as
61370+ SIGSEGV, which will as a result inform you of when a error in a program
61371+ occurred, which in some cases could mean a possible exploit attempt.
61372+ If the sysctl option is enabled, a sysctl option with name
61373+ "signal_logging" is created.
61374+
61375+config GRKERNSEC_FORKFAIL
61376+ bool "Fork failure logging"
61377+ help
61378+ If you say Y here, all failed fork() attempts will be logged.
61379+ This could suggest a fork bomb, or someone attempting to overstep
61380+ their process limit. If the sysctl option is enabled, a sysctl option
61381+ with name "forkfail_logging" is created.
61382+
61383+config GRKERNSEC_TIME
61384+ bool "Time change logging"
61385+ default y if GRKERNSEC_CONFIG_AUTO
61386+ help
61387+ If you say Y here, any changes of the system clock will be logged.
61388+ If the sysctl option is enabled, a sysctl option with name
61389+ "timechange_logging" is created.
61390+
61391+config GRKERNSEC_PROC_IPADDR
61392+ bool "/proc/<pid>/ipaddr support"
61393+ default y if GRKERNSEC_CONFIG_AUTO
61394+ help
61395+ If you say Y here, a new entry will be added to each /proc/<pid>
61396+ directory that contains the IP address of the person using the task.
61397+ The IP is carried across local TCP and AF_UNIX stream sockets.
61398+ This information can be useful for IDS/IPSes to perform remote response
61399+ to a local attack. The entry is readable by only the owner of the
61400+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
61401+ the RBAC system), and thus does not create privacy concerns.
61402+
61403+config GRKERNSEC_RWXMAP_LOG
61404+ bool 'Denied RWX mmap/mprotect logging'
61405+ default y if GRKERNSEC_CONFIG_AUTO
61406+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
61407+ help
61408+ If you say Y here, calls to mmap() and mprotect() with explicit
61409+ usage of PROT_WRITE and PROT_EXEC together will be logged when
61410+ denied by the PAX_MPROTECT feature. This feature will also
61411+ log other problematic scenarios that can occur when PAX_MPROTECT
61412+ is enabled on a binary, like textrels and PT_GNU_STACK. If the
61413+ sysctl option is enabled, a sysctl option with name "rwxmap_logging"
61414+ is created.
61415+
61416+endmenu
61417+
61418+menu "Executable Protections"
61419+depends on GRKERNSEC
61420+
61421+config GRKERNSEC_DMESG
61422+ bool "Dmesg(8) restriction"
61423+ default y if GRKERNSEC_CONFIG_AUTO
61424+ help
61425+ If you say Y here, non-root users will not be able to use dmesg(8)
61426+ to view the contents of the kernel's circular log buffer.
61427+ The kernel's log buffer often contains kernel addresses and other
61428+ identifying information useful to an attacker in fingerprinting a
61429+ system for a targeted exploit.
61430+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
61431+ created.
61432+
61433+config GRKERNSEC_HARDEN_PTRACE
61434+ bool "Deter ptrace-based process snooping"
61435+ default y if GRKERNSEC_CONFIG_AUTO
61436+ help
61437+ If you say Y here, TTY sniffers and other malicious monitoring
61438+ programs implemented through ptrace will be defeated. If you
61439+ have been using the RBAC system, this option has already been
61440+ enabled for several years for all users, with the ability to make
61441+ fine-grained exceptions.
61442+
61443+ This option only affects the ability of non-root users to ptrace
61444+ processes that are not a descendent of the ptracing process.
61445+ This means that strace ./binary and gdb ./binary will still work,
61446+ but attaching to arbitrary processes will not. If the sysctl
61447+ option is enabled, a sysctl option with name "harden_ptrace" is
61448+ created.
61449+
61450+config GRKERNSEC_PTRACE_READEXEC
61451+ bool "Require read access to ptrace sensitive binaries"
61452+ default y if GRKERNSEC_CONFIG_AUTO
61453+ help
61454+ If you say Y here, unprivileged users will not be able to ptrace unreadable
61455+ binaries. This option is useful in environments that
61456+ remove the read bits (e.g. file mode 4711) from suid binaries to
61457+ prevent infoleaking of their contents. This option adds
61458+ consistency to the use of that file mode, as the binary could normally
61459+ be read out when run without privileges while ptracing.
61460+
61461+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
61462+ is created.
61463+
61464+config GRKERNSEC_SETXID
61465+ bool "Enforce consistent multithreaded privileges"
61466+ default y if GRKERNSEC_CONFIG_AUTO
61467+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
61468+ help
61469+ If you say Y here, a change from a root uid to a non-root uid
61470+ in a multithreaded application will cause the resulting uids,
61471+ gids, supplementary groups, and capabilities in that thread
61472+ to be propagated to the other threads of the process. In most
61473+ cases this is unnecessary, as glibc will emulate this behavior
61474+ on behalf of the application. Other libcs do not act in the
61475+ same way, allowing the other threads of the process to continue
61476+ running with root privileges. If the sysctl option is enabled,
61477+ a sysctl option with name "consistent_setxid" is created.
61478+
61479+config GRKERNSEC_TPE
61480+ bool "Trusted Path Execution (TPE)"
61481+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
61482+ help
61483+ If you say Y here, you will be able to choose a gid to add to the
61484+ supplementary groups of users you want to mark as "untrusted."
61485+ These users will not be able to execute any files that are not in
61486+ root-owned directories writable only by root. If the sysctl option
61487+ is enabled, a sysctl option with name "tpe" is created.
61488+
61489+config GRKERNSEC_TPE_ALL
61490+ bool "Partially restrict all non-root users"
61491+ depends on GRKERNSEC_TPE
61492+ help
61493+ If you say Y here, all non-root users will be covered under
61494+ a weaker TPE restriction. This is separate from, and in addition to,
61495+ the main TPE options that you have selected elsewhere. Thus, if a
61496+ "trusted" GID is chosen, this restriction applies to even that GID.
61497+ Under this restriction, all non-root users will only be allowed to
61498+ execute files in directories they own that are not group or
61499+ world-writable, or in directories owned by root and writable only by
61500+ root. If the sysctl option is enabled, a sysctl option with name
61501+ "tpe_restrict_all" is created.
61502+
61503+config GRKERNSEC_TPE_INVERT
61504+ bool "Invert GID option"
61505+ depends on GRKERNSEC_TPE
61506+ help
61507+ If you say Y here, the group you specify in the TPE configuration will
61508+ decide what group TPE restrictions will be *disabled* for. This
61509+ option is useful if you want TPE restrictions to be applied to most
61510+ users on the system. If the sysctl option is enabled, a sysctl option
61511+ with name "tpe_invert" is created. Unlike other sysctl options, this
61512+ entry will default to on for backward-compatibility.
61513+
61514+config GRKERNSEC_TPE_GID
61515+ int
61516+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
61517+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
61518+
61519+config GRKERNSEC_TPE_UNTRUSTED_GID
61520+ int "GID for TPE-untrusted users"
61521+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
61522+ default 1005
61523+ help
61524+ Setting this GID determines what group TPE restrictions will be
61525+ *enabled* for. If the sysctl option is enabled, a sysctl option
61526+ with name "tpe_gid" is created.
61527+
61528+config GRKERNSEC_TPE_TRUSTED_GID
61529+ int "GID for TPE-trusted users"
61530+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
61531+ default 1005
61532+ help
61533+ Setting this GID determines what group TPE restrictions will be
61534+ *disabled* for. If the sysctl option is enabled, a sysctl option
61535+ with name "tpe_gid" is created.
61536+
61537+endmenu
61538+menu "Network Protections"
61539+depends on GRKERNSEC
61540+
61541+config GRKERNSEC_RANDNET
61542+ bool "Larger entropy pools"
61543+ default y if GRKERNSEC_CONFIG_AUTO
61544+ help
61545+ If you say Y here, the entropy pools used for many features of Linux
61546+ and grsecurity will be doubled in size. Since several grsecurity
61547+ features use additional randomness, it is recommended that you say Y
61548+ here. Saying Y here has a similar effect as modifying
61549+ /proc/sys/kernel/random/poolsize.
61550+
61551+config GRKERNSEC_BLACKHOLE
61552+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
61553+ default y if GRKERNSEC_CONFIG_AUTO
61554+ depends on NET
61555+ help
61556+ If you say Y here, neither TCP resets nor ICMP
61557+ destination-unreachable packets will be sent in response to packets
61558+ sent to ports for which no associated listening process exists.
61559+ This feature supports both IPV4 and IPV6 and exempts the
61560+ loopback interface from blackholing. Enabling this feature
61561+ makes a host more resilient to DoS attacks and reduces network
61562+ visibility against scanners.
61563+
61564+ The blackhole feature as-implemented is equivalent to the FreeBSD
61565+ blackhole feature, as it prevents RST responses to all packets, not
61566+ just SYNs. Under most application behavior this causes no
61567+ problems, but applications (like haproxy) may not close certain
61568+ connections in a way that cleanly terminates them on the remote
61569+ end, leaving the remote host in LAST_ACK state. Because of this
61570+ side-effect and to prevent intentional LAST_ACK DoSes, this
61571+ feature also adds automatic mitigation against such attacks.
61572+ The mitigation drastically reduces the amount of time a socket
61573+ can spend in LAST_ACK state. If you're using haproxy and not
61574+ all servers it connects to have this option enabled, consider
61575+ disabling this feature on the haproxy host.
61576+
61577+ If the sysctl option is enabled, two sysctl options with names
61578+ "ip_blackhole" and "lastack_retries" will be created.
61579+ While "ip_blackhole" takes the standard zero/non-zero on/off
61580+ toggle, "lastack_retries" uses the same kinds of values as
61581+ "tcp_retries1" and "tcp_retries2". The default value of 4
61582+ prevents a socket from lasting more than 45 seconds in LAST_ACK
61583+ state.
61584+
61585+config GRKERNSEC_NO_SIMULT_CONNECT
61586+ bool "Disable TCP Simultaneous Connect"
61587+ default y if GRKERNSEC_CONFIG_AUTO
61588+ depends on NET
61589+ help
61590+ If you say Y here, a feature by Willy Tarreau will be enabled that
61591+ removes a weakness in Linux's strict implementation of TCP that
61592+ allows two clients to connect to each other without either entering
61593+ a listening state. The weakness allows an attacker to easily prevent
61594+ a client from connecting to a known server provided the source port
61595+ for the connection is guessed correctly.
61596+
61597+ As the weakness could be used to prevent an antivirus or IPS from
61598+ fetching updates, or prevent an SSL gateway from fetching a CRL,
61599+ it should be eliminated by enabling this option. Though Linux is
61600+ one of few operating systems supporting simultaneous connect, it
61601+ has no legitimate use in practice and is rarely supported by firewalls.
61602+
61603+config GRKERNSEC_SOCKET
61604+ bool "Socket restrictions"
61605+ depends on NET
61606+ help
61607+ If you say Y here, you will be able to choose from several options.
61608+ If you assign a GID on your system and add it to the supplementary
61609+ groups of users you want to restrict socket access to, this patch
61610+ will perform up to three things, based on the option(s) you choose.
61611+
61612+config GRKERNSEC_SOCKET_ALL
61613+ bool "Deny any sockets to group"
61614+ depends on GRKERNSEC_SOCKET
61615+ help
61616+ If you say Y here, you will be able to choose a GID of whose users will
61617+ be unable to connect to other hosts from your machine or run server
61618+ applications from your machine. If the sysctl option is enabled, a
61619+ sysctl option with name "socket_all" is created.
61620+
61621+config GRKERNSEC_SOCKET_ALL_GID
61622+ int "GID to deny all sockets for"
61623+ depends on GRKERNSEC_SOCKET_ALL
61624+ default 1004
61625+ help
61626+ Here you can choose the GID to disable socket access for. Remember to
61627+ add the users you want socket access disabled for to the GID
61628+ specified here. If the sysctl option is enabled, a sysctl option
61629+ with name "socket_all_gid" is created.
61630+
61631+config GRKERNSEC_SOCKET_CLIENT
61632+ bool "Deny client sockets to group"
61633+ depends on GRKERNSEC_SOCKET
61634+ help
61635+ If you say Y here, you will be able to choose a GID of whose users will
61636+ be unable to connect to other hosts from your machine, but will be
61637+ able to run servers. If this option is enabled, all users in the group
61638+ you specify will have to use passive mode when initiating ftp transfers
61639+ from the shell on your machine. If the sysctl option is enabled, a
61640+ sysctl option with name "socket_client" is created.
61641+
61642+config GRKERNSEC_SOCKET_CLIENT_GID
61643+ int "GID to deny client sockets for"
61644+ depends on GRKERNSEC_SOCKET_CLIENT
61645+ default 1003
61646+ help
61647+ Here you can choose the GID to disable client socket access for.
61648+ Remember to add the users you want client socket access disabled for to
61649+ the GID specified here. If the sysctl option is enabled, a sysctl
61650+ option with name "socket_client_gid" is created.
61651+
61652+config GRKERNSEC_SOCKET_SERVER
61653+ bool "Deny server sockets to group"
61654+ depends on GRKERNSEC_SOCKET
61655+ help
61656+ If you say Y here, you will be able to choose a GID of whose users will
61657+ be unable to run server applications from your machine. If the sysctl
61658+ option is enabled, a sysctl option with name "socket_server" is created.
61659+
61660+config GRKERNSEC_SOCKET_SERVER_GID
61661+ int "GID to deny server sockets for"
61662+ depends on GRKERNSEC_SOCKET_SERVER
61663+ default 1002
61664+ help
61665+ Here you can choose the GID to disable server socket access for.
61666+ Remember to add the users you want server socket access disabled for to
61667+ the GID specified here. If the sysctl option is enabled, a sysctl
61668+ option with name "socket_server_gid" is created.
61669+
61670+endmenu
61671+
61672+menu "Physical Protections"
61673+depends on GRKERNSEC
61674+
61675+config GRKERNSEC_DENYUSB
61676+ bool "Deny new USB connections after toggle"
61677+ default y if GRKERNSEC_CONFIG_AUTO
61678+ depends on SYSCTL && USB_SUPPORT
61679+ help
61680+ If you say Y here, a new sysctl option with name "deny_new_usb"
61681+ will be created. Setting its value to 1 will prevent any new
61682+ USB devices from being recognized by the OS. Any attempted USB
61683+ device insertion will be logged. This option is intended to be
61684+ used against custom USB devices designed to exploit vulnerabilities
61685+ in various USB device drivers.
61686+
61687+ For greatest effectiveness, this sysctl should be set after any
61688+ relevant init scripts. This option is safe to enable in distros
61689+ as each user can choose whether or not to toggle the sysctl.
61690+
61691+config GRKERNSEC_DENYUSB_FORCE
61692+ bool "Reject all USB devices not connected at boot"
61693+ select USB
61694+ depends on GRKERNSEC_DENYUSB
61695+ help
61696+ If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
61697+ that doesn't involve a sysctl entry. This option should only be
61698+ enabled if you're sure you want to deny all new USB connections
61699+ at runtime and don't want to modify init scripts. This should not
61700+ be enabled by distros. It forces the core USB code to be built
61701+ into the kernel image so that all devices connected at boot time
61702+ can be recognized and new USB device connections can be prevented
61703+ prior to init running.
61704+
61705+endmenu
61706+
61707+menu "Sysctl Support"
61708+depends on GRKERNSEC && SYSCTL
61709+
61710+config GRKERNSEC_SYSCTL
61711+ bool "Sysctl support"
61712+ default y if GRKERNSEC_CONFIG_AUTO
61713+ help
61714+ If you say Y here, you will be able to change the options that
61715+ grsecurity runs with at bootup, without having to recompile your
61716+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
61717+ to enable (1) or disable (0) various features. All the sysctl entries
61718+ are mutable until the "grsec_lock" entry is set to a non-zero value.
61719+ All features enabled in the kernel configuration are disabled at boot
61720+ if you do not say Y to the "Turn on features by default" option.
61721+ All options should be set at startup, and the grsec_lock entry should
61722+ be set to a non-zero value after all the options are set.
61723+ *THIS IS EXTREMELY IMPORTANT*
61724+
61725+config GRKERNSEC_SYSCTL_DISTRO
61726+ bool "Extra sysctl support for distro makers (READ HELP)"
61727+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
61728+ help
61729+ If you say Y here, additional sysctl options will be created
61730+ for features that affect processes running as root. Therefore,
61731+ it is critical when using this option that the grsec_lock entry be
61732+ enabled after boot. Only distros with prebuilt kernel packages
61733+ with this option enabled that can ensure grsec_lock is enabled
61734+ after boot should use this option.
61735+ *Failure to set grsec_lock after boot makes all grsec features
61736+ this option covers useless*
61737+
61738+ Currently this option creates the following sysctl entries:
61739+ "Disable Privileged I/O": "disable_priv_io"
61740+
61741+config GRKERNSEC_SYSCTL_ON
61742+ bool "Turn on features by default"
61743+ default y if GRKERNSEC_CONFIG_AUTO
61744+ depends on GRKERNSEC_SYSCTL
61745+ help
61746+ If you say Y here, instead of having all features enabled in the
61747+ kernel configuration disabled at boot time, the features will be
61748+ enabled at boot time. It is recommended you say Y here unless
61749+ there is some reason you would want all sysctl-tunable features to
61750+ be disabled by default. As mentioned elsewhere, it is important
61751+ to enable the grsec_lock entry once you have finished modifying
61752+ the sysctl entries.
61753+
61754+endmenu
61755+menu "Logging Options"
61756+depends on GRKERNSEC
61757+
61758+config GRKERNSEC_FLOODTIME
61759+ int "Seconds in between log messages (minimum)"
61760+ default 10
61761+ help
61762+ This option allows you to enforce the number of seconds between
61763+ grsecurity log messages. The default should be suitable for most
61764+ people, however, if you choose to change it, choose a value small enough
61765+ to allow informative logs to be produced, but large enough to
61766+ prevent flooding.
61767+
61768+config GRKERNSEC_FLOODBURST
61769+ int "Number of messages in a burst (maximum)"
61770+ default 6
61771+ help
61772+ This option allows you to choose the maximum number of messages allowed
61773+ within the flood time interval you chose in a separate option. The
61774+ default should be suitable for most people, however if you find that
61775+ many of your logs are being interpreted as flooding, you may want to
61776+ raise this value.
61777+
61778+endmenu
61779diff --git a/grsecurity/Makefile b/grsecurity/Makefile
61780new file mode 100644
61781index 0000000..b0b77d5
61782--- /dev/null
61783+++ b/grsecurity/Makefile
61784@@ -0,0 +1,43 @@
61785+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
61786+# during 2001-2009 it has been completely redesigned by Brad Spengler
61787+# into an RBAC system
61788+#
61789+# All code in this directory and various hooks inserted throughout the kernel
61790+# are copyright Brad Spengler - Open Source Security, Inc., and released
61791+# under the GPL v2 or higher
61792+
61793+KBUILD_CFLAGS += -Werror
61794+
61795+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
61796+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
61797+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
61798+ grsec_usb.o
61799+
61800+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
61801+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
61802+ gracl_learn.o grsec_log.o
61803+ifdef CONFIG_COMPAT
61804+obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
61805+endif
61806+
61807+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
61808+
61809+ifdef CONFIG_NET
61810+obj-y += grsec_sock.o
61811+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
61812+endif
61813+
61814+ifndef CONFIG_GRKERNSEC
61815+obj-y += grsec_disabled.o
61816+endif
61817+
61818+ifdef CONFIG_GRKERNSEC_HIDESYM
61819+extra-y := grsec_hidesym.o
61820+$(obj)/grsec_hidesym.o:
61821+ @-chmod -f 500 /boot
61822+ @-chmod -f 500 /lib/modules
61823+ @-chmod -f 500 /lib64/modules
61824+ @-chmod -f 500 /lib32/modules
61825+ @-chmod -f 700 .
61826+ @echo ' grsec: protected kernel image paths'
61827+endif
61828diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
61829new file mode 100644
61830index 0000000..c0793fd
61831--- /dev/null
61832+++ b/grsecurity/gracl.c
61833@@ -0,0 +1,4178 @@
61834+#include <linux/kernel.h>
61835+#include <linux/module.h>
61836+#include <linux/sched.h>
61837+#include <linux/mm.h>
61838+#include <linux/file.h>
61839+#include <linux/fs.h>
61840+#include <linux/namei.h>
61841+#include <linux/mount.h>
61842+#include <linux/tty.h>
61843+#include <linux/proc_fs.h>
61844+#include <linux/lglock.h>
61845+#include <linux/slab.h>
61846+#include <linux/vmalloc.h>
61847+#include <linux/types.h>
61848+#include <linux/sysctl.h>
61849+#include <linux/netdevice.h>
61850+#include <linux/ptrace.h>
61851+#include <linux/gracl.h>
61852+#include <linux/gralloc.h>
61853+#include <linux/security.h>
61854+#include <linux/grinternal.h>
61855+#include <linux/pid_namespace.h>
61856+#include <linux/stop_machine.h>
61857+#include <linux/fdtable.h>
61858+#include <linux/percpu.h>
61859+#include <linux/lglock.h>
61860+#include <linux/hugetlb.h>
61861+#include <linux/posix-timers.h>
61862+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
61863+#include <linux/magic.h>
61864+#include <linux/pagemap.h>
61865+#include "../fs/btrfs/async-thread.h"
61866+#include "../fs/btrfs/ctree.h"
61867+#include "../fs/btrfs/btrfs_inode.h"
61868+#endif
61869+#include "../fs/mount.h"
61870+
61871+#include <asm/uaccess.h>
61872+#include <asm/errno.h>
61873+#include <asm/mman.h>
61874+
61875+extern struct lglock vfsmount_lock;
61876+
61877+static struct acl_role_db acl_role_set;
61878+static struct name_db name_set;
61879+static struct inodev_db inodev_set;
61880+
61881+/* for keeping track of userspace pointers used for subjects, so we
61882+ can share references in the kernel as well
61883+*/
61884+
61885+static struct path real_root;
61886+
61887+static struct acl_subj_map_db subj_map_set;
61888+
61889+static struct acl_role_label *default_role;
61890+
61891+static struct acl_role_label *role_list;
61892+
61893+static u16 acl_sp_role_value;
61894+
61895+extern char *gr_shared_page[4];
61896+static DEFINE_MUTEX(gr_dev_mutex);
61897+DEFINE_RWLOCK(gr_inode_lock);
61898+
61899+struct gr_arg *gr_usermode;
61900+
61901+static unsigned int gr_status __read_only = GR_STATUS_INIT;
61902+
61903+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
61904+extern void gr_clear_learn_entries(void);
61905+
61906+unsigned char *gr_system_salt;
61907+unsigned char *gr_system_sum;
61908+
61909+static struct sprole_pw **acl_special_roles = NULL;
61910+static __u16 num_sprole_pws = 0;
61911+
61912+static struct acl_role_label *kernel_role = NULL;
61913+
61914+static unsigned int gr_auth_attempts = 0;
61915+static unsigned long gr_auth_expires = 0UL;
61916+
61917+#ifdef CONFIG_NET
61918+extern struct vfsmount *sock_mnt;
61919+#endif
61920+
61921+extern struct vfsmount *pipe_mnt;
61922+extern struct vfsmount *shm_mnt;
61923+
61924+#ifdef CONFIG_HUGETLBFS
61925+extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
61926+#endif
61927+
61928+static struct acl_object_label *fakefs_obj_rw;
61929+static struct acl_object_label *fakefs_obj_rwx;
61930+
61931+extern int gr_init_uidset(void);
61932+extern void gr_free_uidset(void);
61933+extern void gr_remove_uid(uid_t uid);
61934+extern int gr_find_uid(uid_t uid);
61935+
61936+static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
61937+{
61938+ if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
61939+ return -EFAULT;
61940+
61941+ return 0;
61942+}
61943+
61944+static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
61945+{
61946+ if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
61947+ return -EFAULT;
61948+
61949+ return 0;
61950+}
61951+
61952+static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
61953+{
61954+ if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
61955+ return -EFAULT;
61956+
61957+ return 0;
61958+}
61959+
61960+static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
61961+{
61962+ if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
61963+ return -EFAULT;
61964+
61965+ return 0;
61966+}
61967+
61968+static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
61969+{
61970+ if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
61971+ return -EFAULT;
61972+
61973+ return 0;
61974+}
61975+
61976+static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
61977+{
61978+ if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
61979+ return -EFAULT;
61980+
61981+ return 0;
61982+}
61983+
61984+static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
61985+{
61986+ if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
61987+ return -EFAULT;
61988+
61989+ return 0;
61990+}
61991+
61992+static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
61993+{
61994+ if (copy_from_user(trans, userp, sizeof(struct role_transition)))
61995+ return -EFAULT;
61996+
61997+ return 0;
61998+}
61999+
62000+int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
62001+{
62002+ if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
62003+ return -EFAULT;
62004+
62005+ return 0;
62006+}
62007+
62008+static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
62009+{
62010+ if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
62011+ return -EFAULT;
62012+
62013+ if ((uwrap->version != GRSECURITY_VERSION) || (uwrap->size != sizeof(struct gr_arg)))
62014+ return -EINVAL;
62015+
62016+ return 0;
62017+}
62018+
62019+static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
62020+{
62021+ if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
62022+ return -EFAULT;
62023+
62024+ return 0;
62025+}
62026+
62027+static size_t get_gr_arg_wrapper_size_normal(void)
62028+{
62029+ return sizeof(struct gr_arg_wrapper);
62030+}
62031+
62032+#ifdef CONFIG_COMPAT
62033+extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
62034+extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
62035+extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
62036+extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
62037+extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
62038+extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
62039+extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
62040+extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
62041+extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
62042+extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
62043+extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
62044+extern size_t get_gr_arg_wrapper_size_compat(void);
62045+
62046+int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
62047+int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
62048+int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
62049+int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
62050+int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
62051+int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
62052+int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
62053+int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
62054+int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
62055+int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
62056+int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
62057+size_t (* get_gr_arg_wrapper_size)(void) __read_only;
62058+
62059+#else
62060+#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
62061+#define copy_gr_arg copy_gr_arg_normal
62062+#define copy_gr_hash_struct copy_gr_hash_struct_normal
62063+#define copy_acl_object_label copy_acl_object_label_normal
62064+#define copy_acl_subject_label copy_acl_subject_label_normal
62065+#define copy_acl_role_label copy_acl_role_label_normal
62066+#define copy_acl_ip_label copy_acl_ip_label_normal
62067+#define copy_pointer_from_array copy_pointer_from_array_normal
62068+#define copy_sprole_pw copy_sprole_pw_normal
62069+#define copy_role_transition copy_role_transition_normal
62070+#define copy_role_allowed_ip copy_role_allowed_ip_normal
62071+#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
62072+#endif
62073+
62074+__inline__ int
62075+gr_acl_is_enabled(void)
62076+{
62077+ return (gr_status & GR_READY);
62078+}
62079+
62080+static inline dev_t __get_dev(const struct dentry *dentry)
62081+{
62082+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
62083+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
62084+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
62085+ else
62086+#endif
62087+ return dentry->d_sb->s_dev;
62088+}
62089+
62090+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
62091+{
62092+ return __get_dev(dentry);
62093+}
62094+
62095+static char gr_task_roletype_to_char(struct task_struct *task)
62096+{
62097+ switch (task->role->roletype &
62098+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
62099+ GR_ROLE_SPECIAL)) {
62100+ case GR_ROLE_DEFAULT:
62101+ return 'D';
62102+ case GR_ROLE_USER:
62103+ return 'U';
62104+ case GR_ROLE_GROUP:
62105+ return 'G';
62106+ case GR_ROLE_SPECIAL:
62107+ return 'S';
62108+ }
62109+
62110+ return 'X';
62111+}
62112+
62113+char gr_roletype_to_char(void)
62114+{
62115+ return gr_task_roletype_to_char(current);
62116+}
62117+
62118+__inline__ int
62119+gr_acl_tpe_check(void)
62120+{
62121+ if (unlikely(!(gr_status & GR_READY)))
62122+ return 0;
62123+ if (current->role->roletype & GR_ROLE_TPE)
62124+ return 1;
62125+ else
62126+ return 0;
62127+}
62128+
62129+int
62130+gr_handle_rawio(const struct inode *inode)
62131+{
62132+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
62133+ if (inode && S_ISBLK(inode->i_mode) &&
62134+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
62135+ !capable(CAP_SYS_RAWIO))
62136+ return 1;
62137+#endif
62138+ return 0;
62139+}
62140+
62141+static int
62142+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
62143+{
62144+ if (likely(lena != lenb))
62145+ return 0;
62146+
62147+ return !memcmp(a, b, lena);
62148+}
62149+
62150+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
62151+{
62152+ *buflen -= namelen;
62153+ if (*buflen < 0)
62154+ return -ENAMETOOLONG;
62155+ *buffer -= namelen;
62156+ memcpy(*buffer, str, namelen);
62157+ return 0;
62158+}
62159+
62160+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
62161+{
62162+ return prepend(buffer, buflen, name->name, name->len);
62163+}
62164+
62165+static int prepend_path(const struct path *path, struct path *root,
62166+ char **buffer, int *buflen)
62167+{
62168+ struct dentry *dentry = path->dentry;
62169+ struct vfsmount *vfsmnt = path->mnt;
62170+ struct mount *mnt = real_mount(vfsmnt);
62171+ bool slash = false;
62172+ int error = 0;
62173+
62174+ while (dentry != root->dentry || vfsmnt != root->mnt) {
62175+ struct dentry * parent;
62176+
62177+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
62178+ /* Global root? */
62179+ if (!mnt_has_parent(mnt)) {
62180+ goto out;
62181+ }
62182+ dentry = mnt->mnt_mountpoint;
62183+ mnt = mnt->mnt_parent;
62184+ vfsmnt = &mnt->mnt;
62185+ continue;
62186+ }
62187+ parent = dentry->d_parent;
62188+ prefetch(parent);
62189+ spin_lock(&dentry->d_lock);
62190+ error = prepend_name(buffer, buflen, &dentry->d_name);
62191+ spin_unlock(&dentry->d_lock);
62192+ if (!error)
62193+ error = prepend(buffer, buflen, "/", 1);
62194+ if (error)
62195+ break;
62196+
62197+ slash = true;
62198+ dentry = parent;
62199+ }
62200+
62201+out:
62202+ if (!error && !slash)
62203+ error = prepend(buffer, buflen, "/", 1);
62204+
62205+ return error;
62206+}
62207+
62208+/* this must be called with vfsmount_lock and rename_lock held */
62209+
62210+static char *__our_d_path(const struct path *path, struct path *root,
62211+ char *buf, int buflen)
62212+{
62213+ char *res = buf + buflen;
62214+ int error;
62215+
62216+ prepend(&res, &buflen, "\0", 1);
62217+ error = prepend_path(path, root, &res, &buflen);
62218+ if (error)
62219+ return ERR_PTR(error);
62220+
62221+ return res;
62222+}
62223+
62224+static char *
62225+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
62226+{
62227+ char *retval;
62228+
62229+ retval = __our_d_path(path, root, buf, buflen);
62230+ if (unlikely(IS_ERR(retval)))
62231+ retval = strcpy(buf, "<path too long>");
62232+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
62233+ retval[1] = '\0';
62234+
62235+ return retval;
62236+}
62237+
62238+static char *
62239+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
62240+ char *buf, int buflen)
62241+{
62242+ struct path path;
62243+ char *res;
62244+
62245+ path.dentry = (struct dentry *)dentry;
62246+ path.mnt = (struct vfsmount *)vfsmnt;
62247+
62248+ /* we can use real_root.dentry, real_root.mnt, because this is only called
62249+ by the RBAC system */
62250+ res = gen_full_path(&path, &real_root, buf, buflen);
62251+
62252+ return res;
62253+}
62254+
62255+static char *
62256+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
62257+ char *buf, int buflen)
62258+{
62259+ char *res;
62260+ struct path path;
62261+ struct path root;
62262+ struct task_struct *reaper = init_pid_ns.child_reaper;
62263+
62264+ path.dentry = (struct dentry *)dentry;
62265+ path.mnt = (struct vfsmount *)vfsmnt;
62266+
62267+ /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
62268+ get_fs_root(reaper->fs, &root);
62269+
62270+ br_read_lock(&vfsmount_lock);
62271+ write_seqlock(&rename_lock);
62272+ res = gen_full_path(&path, &root, buf, buflen);
62273+ write_sequnlock(&rename_lock);
62274+ br_read_unlock(&vfsmount_lock);
62275+
62276+ path_put(&root);
62277+ return res;
62278+}
62279+
62280+static char *
62281+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
62282+{
62283+ char *ret;
62284+ br_read_lock(&vfsmount_lock);
62285+ write_seqlock(&rename_lock);
62286+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
62287+ PAGE_SIZE);
62288+ write_sequnlock(&rename_lock);
62289+ br_read_unlock(&vfsmount_lock);
62290+ return ret;
62291+}
62292+
62293+static char *
62294+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
62295+{
62296+ char *ret;
62297+ char *buf;
62298+ int buflen;
62299+
62300+ br_read_lock(&vfsmount_lock);
62301+ write_seqlock(&rename_lock);
62302+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
62303+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
62304+ buflen = (int)(ret - buf);
62305+ if (buflen >= 5)
62306+ prepend(&ret, &buflen, "/proc", 5);
62307+ else
62308+ ret = strcpy(buf, "<path too long>");
62309+ write_sequnlock(&rename_lock);
62310+ br_read_unlock(&vfsmount_lock);
62311+ return ret;
62312+}
62313+
62314+char *
62315+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
62316+{
62317+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
62318+ PAGE_SIZE);
62319+}
62320+
62321+char *
62322+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
62323+{
62324+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
62325+ PAGE_SIZE);
62326+}
62327+
62328+char *
62329+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
62330+{
62331+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
62332+ PAGE_SIZE);
62333+}
62334+
62335+char *
62336+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
62337+{
62338+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
62339+ PAGE_SIZE);
62340+}
62341+
62342+char *
62343+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
62344+{
62345+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
62346+ PAGE_SIZE);
62347+}
62348+
62349+__inline__ __u32
62350+to_gr_audit(const __u32 reqmode)
62351+{
62352+ /* masks off auditable permission flags, then shifts them to create
62353+ auditing flags, and adds the special case of append auditing if
62354+ we're requesting write */
62355+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
62356+}
62357+
62358+struct acl_subject_label *
62359+lookup_subject_map(const struct acl_subject_label *userp)
62360+{
62361+ unsigned int index = gr_shash(userp, subj_map_set.s_size);
62362+ struct subject_map *match;
62363+
62364+ match = subj_map_set.s_hash[index];
62365+
62366+ while (match && match->user != userp)
62367+ match = match->next;
62368+
62369+ if (match != NULL)
62370+ return match->kernel;
62371+ else
62372+ return NULL;
62373+}
62374+
62375+static void
62376+insert_subj_map_entry(struct subject_map *subjmap)
62377+{
62378+ unsigned int index = gr_shash(subjmap->user, subj_map_set.s_size);
62379+ struct subject_map **curr;
62380+
62381+ subjmap->prev = NULL;
62382+
62383+ curr = &subj_map_set.s_hash[index];
62384+ if (*curr != NULL)
62385+ (*curr)->prev = subjmap;
62386+
62387+ subjmap->next = *curr;
62388+ *curr = subjmap;
62389+
62390+ return;
62391+}
62392+
62393+static struct acl_role_label *
62394+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
62395+ const gid_t gid)
62396+{
62397+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
62398+ struct acl_role_label *match;
62399+ struct role_allowed_ip *ipp;
62400+ unsigned int x;
62401+ u32 curr_ip = task->signal->curr_ip;
62402+
62403+ task->signal->saved_ip = curr_ip;
62404+
62405+ match = acl_role_set.r_hash[index];
62406+
62407+ while (match) {
62408+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
62409+ for (x = 0; x < match->domain_child_num; x++) {
62410+ if (match->domain_children[x] == uid)
62411+ goto found;
62412+ }
62413+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
62414+ break;
62415+ match = match->next;
62416+ }
62417+found:
62418+ if (match == NULL) {
62419+ try_group:
62420+ index = gr_rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
62421+ match = acl_role_set.r_hash[index];
62422+
62423+ while (match) {
62424+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
62425+ for (x = 0; x < match->domain_child_num; x++) {
62426+ if (match->domain_children[x] == gid)
62427+ goto found2;
62428+ }
62429+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
62430+ break;
62431+ match = match->next;
62432+ }
62433+found2:
62434+ if (match == NULL)
62435+ match = default_role;
62436+ if (match->allowed_ips == NULL)
62437+ return match;
62438+ else {
62439+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
62440+ if (likely
62441+ ((ntohl(curr_ip) & ipp->netmask) ==
62442+ (ntohl(ipp->addr) & ipp->netmask)))
62443+ return match;
62444+ }
62445+ match = default_role;
62446+ }
62447+ } else if (match->allowed_ips == NULL) {
62448+ return match;
62449+ } else {
62450+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
62451+ if (likely
62452+ ((ntohl(curr_ip) & ipp->netmask) ==
62453+ (ntohl(ipp->addr) & ipp->netmask)))
62454+ return match;
62455+ }
62456+ goto try_group;
62457+ }
62458+
62459+ return match;
62460+}
62461+
62462+struct acl_subject_label *
62463+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
62464+ const struct acl_role_label *role)
62465+{
62466+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
62467+ struct acl_subject_label *match;
62468+
62469+ match = role->subj_hash[index];
62470+
62471+ while (match && (match->inode != ino || match->device != dev ||
62472+ (match->mode & GR_DELETED))) {
62473+ match = match->next;
62474+ }
62475+
62476+ if (match && !(match->mode & GR_DELETED))
62477+ return match;
62478+ else
62479+ return NULL;
62480+}
62481+
62482+struct acl_subject_label *
62483+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
62484+ const struct acl_role_label *role)
62485+{
62486+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
62487+ struct acl_subject_label *match;
62488+
62489+ match = role->subj_hash[index];
62490+
62491+ while (match && (match->inode != ino || match->device != dev ||
62492+ !(match->mode & GR_DELETED))) {
62493+ match = match->next;
62494+ }
62495+
62496+ if (match && (match->mode & GR_DELETED))
62497+ return match;
62498+ else
62499+ return NULL;
62500+}
62501+
62502+static struct acl_object_label *
62503+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
62504+ const struct acl_subject_label *subj)
62505+{
62506+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
62507+ struct acl_object_label *match;
62508+
62509+ match = subj->obj_hash[index];
62510+
62511+ while (match && (match->inode != ino || match->device != dev ||
62512+ (match->mode & GR_DELETED))) {
62513+ match = match->next;
62514+ }
62515+
62516+ if (match && !(match->mode & GR_DELETED))
62517+ return match;
62518+ else
62519+ return NULL;
62520+}
62521+
62522+static struct acl_object_label *
62523+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
62524+ const struct acl_subject_label *subj)
62525+{
62526+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
62527+ struct acl_object_label *match;
62528+
62529+ match = subj->obj_hash[index];
62530+
62531+ while (match && (match->inode != ino || match->device != dev ||
62532+ !(match->mode & GR_DELETED))) {
62533+ match = match->next;
62534+ }
62535+
62536+ if (match && (match->mode & GR_DELETED))
62537+ return match;
62538+
62539+ match = subj->obj_hash[index];
62540+
62541+ while (match && (match->inode != ino || match->device != dev ||
62542+ (match->mode & GR_DELETED))) {
62543+ match = match->next;
62544+ }
62545+
62546+ if (match && !(match->mode & GR_DELETED))
62547+ return match;
62548+ else
62549+ return NULL;
62550+}
62551+
62552+static struct name_entry *
62553+lookup_name_entry(const char *name)
62554+{
62555+ unsigned int len = strlen(name);
62556+ unsigned int key = full_name_hash(name, len);
62557+ unsigned int index = key % name_set.n_size;
62558+ struct name_entry *match;
62559+
62560+ match = name_set.n_hash[index];
62561+
62562+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
62563+ match = match->next;
62564+
62565+ return match;
62566+}
62567+
62568+static struct name_entry *
62569+lookup_name_entry_create(const char *name)
62570+{
62571+ unsigned int len = strlen(name);
62572+ unsigned int key = full_name_hash(name, len);
62573+ unsigned int index = key % name_set.n_size;
62574+ struct name_entry *match;
62575+
62576+ match = name_set.n_hash[index];
62577+
62578+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
62579+ !match->deleted))
62580+ match = match->next;
62581+
62582+ if (match && match->deleted)
62583+ return match;
62584+
62585+ match = name_set.n_hash[index];
62586+
62587+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
62588+ match->deleted))
62589+ match = match->next;
62590+
62591+ if (match && !match->deleted)
62592+ return match;
62593+ else
62594+ return NULL;
62595+}
62596+
62597+static struct inodev_entry *
62598+lookup_inodev_entry(const ino_t ino, const dev_t dev)
62599+{
62600+ unsigned int index = gr_fhash(ino, dev, inodev_set.i_size);
62601+ struct inodev_entry *match;
62602+
62603+ match = inodev_set.i_hash[index];
62604+
62605+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
62606+ match = match->next;
62607+
62608+ return match;
62609+}
62610+
62611+static void
62612+insert_inodev_entry(struct inodev_entry *entry)
62613+{
62614+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
62615+ inodev_set.i_size);
62616+ struct inodev_entry **curr;
62617+
62618+ entry->prev = NULL;
62619+
62620+ curr = &inodev_set.i_hash[index];
62621+ if (*curr != NULL)
62622+ (*curr)->prev = entry;
62623+
62624+ entry->next = *curr;
62625+ *curr = entry;
62626+
62627+ return;
62628+}
62629+
62630+static void
62631+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
62632+{
62633+ unsigned int index =
62634+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
62635+ struct acl_role_label **curr;
62636+ struct acl_role_label *tmp, *tmp2;
62637+
62638+ curr = &acl_role_set.r_hash[index];
62639+
62640+ /* simple case, slot is empty, just set it to our role */
62641+ if (*curr == NULL) {
62642+ *curr = role;
62643+ } else {
62644+ /* example:
62645+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
62646+ 2 -> 3
62647+ */
62648+ /* first check to see if we can already be reached via this slot */
62649+ tmp = *curr;
62650+ while (tmp && tmp != role)
62651+ tmp = tmp->next;
62652+ if (tmp == role) {
62653+ /* we don't need to add ourselves to this slot's chain */
62654+ return;
62655+ }
62656+ /* we need to add ourselves to this chain, two cases */
62657+ if (role->next == NULL) {
62658+ /* simple case, append the current chain to our role */
62659+ role->next = *curr;
62660+ *curr = role;
62661+ } else {
62662+ /* 1 -> 2 -> 3 -> 4
62663+ 2 -> 3 -> 4
62664+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
62665+ */
62666+ /* trickier case: walk our role's chain until we find
62667+ the role for the start of the current slot's chain */
62668+ tmp = role;
62669+ tmp2 = *curr;
62670+ while (tmp->next && tmp->next != tmp2)
62671+ tmp = tmp->next;
62672+ if (tmp->next == tmp2) {
62673+ /* from example above, we found 3, so just
62674+ replace this slot's chain with ours */
62675+ *curr = role;
62676+ } else {
62677+ /* we didn't find a subset of our role's chain
62678+ in the current slot's chain, so append their
62679+ chain to ours, and set us as the first role in
62680+ the slot's chain
62681+
62682+ we could fold this case with the case above,
62683+ but making it explicit for clarity
62684+ */
62685+ tmp->next = tmp2;
62686+ *curr = role;
62687+ }
62688+ }
62689+ }
62690+
62691+ return;
62692+}
62693+
62694+static void
62695+insert_acl_role_label(struct acl_role_label *role)
62696+{
62697+ int i;
62698+
62699+ if (role_list == NULL) {
62700+ role_list = role;
62701+ role->prev = NULL;
62702+ } else {
62703+ role->prev = role_list;
62704+ role_list = role;
62705+ }
62706+
62707+ /* used for hash chains */
62708+ role->next = NULL;
62709+
62710+ if (role->roletype & GR_ROLE_DOMAIN) {
62711+ for (i = 0; i < role->domain_child_num; i++)
62712+ __insert_acl_role_label(role, role->domain_children[i]);
62713+ } else
62714+ __insert_acl_role_label(role, role->uidgid);
62715+}
62716+
62717+static int
62718+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
62719+{
62720+ struct name_entry **curr, *nentry;
62721+ struct inodev_entry *ientry;
62722+ unsigned int len = strlen(name);
62723+ unsigned int key = full_name_hash(name, len);
62724+ unsigned int index = key % name_set.n_size;
62725+
62726+ curr = &name_set.n_hash[index];
62727+
62728+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
62729+ curr = &((*curr)->next);
62730+
62731+ if (*curr != NULL)
62732+ return 1;
62733+
62734+ nentry = acl_alloc(sizeof (struct name_entry));
62735+ if (nentry == NULL)
62736+ return 0;
62737+ ientry = acl_alloc(sizeof (struct inodev_entry));
62738+ if (ientry == NULL)
62739+ return 0;
62740+ ientry->nentry = nentry;
62741+
62742+ nentry->key = key;
62743+ nentry->name = name;
62744+ nentry->inode = inode;
62745+ nentry->device = device;
62746+ nentry->len = len;
62747+ nentry->deleted = deleted;
62748+
62749+ nentry->prev = NULL;
62750+ curr = &name_set.n_hash[index];
62751+ if (*curr != NULL)
62752+ (*curr)->prev = nentry;
62753+ nentry->next = *curr;
62754+ *curr = nentry;
62755+
62756+ /* insert us into the table searchable by inode/dev */
62757+ insert_inodev_entry(ientry);
62758+
62759+ return 1;
62760+}
62761+
62762+static void
62763+insert_acl_obj_label(struct acl_object_label *obj,
62764+ struct acl_subject_label *subj)
62765+{
62766+ unsigned int index =
62767+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
62768+ struct acl_object_label **curr;
62769+
62770+
62771+ obj->prev = NULL;
62772+
62773+ curr = &subj->obj_hash[index];
62774+ if (*curr != NULL)
62775+ (*curr)->prev = obj;
62776+
62777+ obj->next = *curr;
62778+ *curr = obj;
62779+
62780+ return;
62781+}
62782+
62783+static void
62784+insert_acl_subj_label(struct acl_subject_label *obj,
62785+ struct acl_role_label *role)
62786+{
62787+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
62788+ struct acl_subject_label **curr;
62789+
62790+ obj->prev = NULL;
62791+
62792+ curr = &role->subj_hash[index];
62793+ if (*curr != NULL)
62794+ (*curr)->prev = obj;
62795+
62796+ obj->next = *curr;
62797+ *curr = obj;
62798+
62799+ return;
62800+}
62801+
62802+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
62803+
62804+static void *
62805+create_table(__u32 * len, int elementsize)
62806+{
62807+ unsigned int table_sizes[] = {
62808+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
62809+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
62810+ 4194301, 8388593, 16777213, 33554393, 67108859
62811+ };
62812+ void *newtable = NULL;
62813+ unsigned int pwr = 0;
62814+
62815+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
62816+ table_sizes[pwr] <= *len)
62817+ pwr++;
62818+
62819+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
62820+ return newtable;
62821+
62822+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
62823+ newtable =
62824+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
62825+ else
62826+ newtable = vmalloc(table_sizes[pwr] * elementsize);
62827+
62828+ *len = table_sizes[pwr];
62829+
62830+ return newtable;
62831+}
62832+
62833+static int
62834+init_variables(const struct gr_arg *arg)
62835+{
62836+ struct task_struct *reaper = init_pid_ns.child_reaper;
62837+ unsigned int stacksize;
62838+
62839+ subj_map_set.s_size = arg->role_db.num_subjects;
62840+ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
62841+ name_set.n_size = arg->role_db.num_objects;
62842+ inodev_set.i_size = arg->role_db.num_objects;
62843+
62844+ if (!subj_map_set.s_size || !acl_role_set.r_size ||
62845+ !name_set.n_size || !inodev_set.i_size)
62846+ return 1;
62847+
62848+ if (!gr_init_uidset())
62849+ return 1;
62850+
62851+ /* set up the stack that holds allocation info */
62852+
62853+ stacksize = arg->role_db.num_pointers + 5;
62854+
62855+ if (!acl_alloc_stack_init(stacksize))
62856+ return 1;
62857+
62858+ /* grab reference for the real root dentry and vfsmount */
62859+ get_fs_root(reaper->fs, &real_root);
62860+
62861+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
62862+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
62863+#endif
62864+
62865+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
62866+ if (fakefs_obj_rw == NULL)
62867+ return 1;
62868+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
62869+
62870+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
62871+ if (fakefs_obj_rwx == NULL)
62872+ return 1;
62873+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
62874+
62875+ subj_map_set.s_hash =
62876+ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
62877+ acl_role_set.r_hash =
62878+ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
62879+ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
62880+ inodev_set.i_hash =
62881+ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
62882+
62883+ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
62884+ !name_set.n_hash || !inodev_set.i_hash)
62885+ return 1;
62886+
62887+ memset(subj_map_set.s_hash, 0,
62888+ sizeof(struct subject_map *) * subj_map_set.s_size);
62889+ memset(acl_role_set.r_hash, 0,
62890+ sizeof (struct acl_role_label *) * acl_role_set.r_size);
62891+ memset(name_set.n_hash, 0,
62892+ sizeof (struct name_entry *) * name_set.n_size);
62893+ memset(inodev_set.i_hash, 0,
62894+ sizeof (struct inodev_entry *) * inodev_set.i_size);
62895+
62896+ return 0;
62897+}
62898+
62899+/* free information not needed after startup
62900+ currently contains user->kernel pointer mappings for subjects
62901+*/
62902+
62903+static void
62904+free_init_variables(void)
62905+{
62906+ __u32 i;
62907+
62908+ if (subj_map_set.s_hash) {
62909+ for (i = 0; i < subj_map_set.s_size; i++) {
62910+ if (subj_map_set.s_hash[i]) {
62911+ kfree(subj_map_set.s_hash[i]);
62912+ subj_map_set.s_hash[i] = NULL;
62913+ }
62914+ }
62915+
62916+ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
62917+ PAGE_SIZE)
62918+ kfree(subj_map_set.s_hash);
62919+ else
62920+ vfree(subj_map_set.s_hash);
62921+ }
62922+
62923+ return;
62924+}
62925+
62926+static void
62927+free_variables(void)
62928+{
62929+ struct acl_subject_label *s;
62930+ struct acl_role_label *r;
62931+ struct task_struct *task, *task2;
62932+ unsigned int x;
62933+
62934+ gr_clear_learn_entries();
62935+
62936+ read_lock(&tasklist_lock);
62937+ do_each_thread(task2, task) {
62938+ task->acl_sp_role = 0;
62939+ task->acl_role_id = 0;
62940+ task->acl = NULL;
62941+ task->role = NULL;
62942+ } while_each_thread(task2, task);
62943+ read_unlock(&tasklist_lock);
62944+
62945+ /* release the reference to the real root dentry and vfsmount */
62946+ path_put(&real_root);
62947+ memset(&real_root, 0, sizeof(real_root));
62948+
62949+ /* free all object hash tables */
62950+
62951+ FOR_EACH_ROLE_START(r)
62952+ if (r->subj_hash == NULL)
62953+ goto next_role;
62954+ FOR_EACH_SUBJECT_START(r, s, x)
62955+ if (s->obj_hash == NULL)
62956+ break;
62957+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
62958+ kfree(s->obj_hash);
62959+ else
62960+ vfree(s->obj_hash);
62961+ FOR_EACH_SUBJECT_END(s, x)
62962+ FOR_EACH_NESTED_SUBJECT_START(r, s)
62963+ if (s->obj_hash == NULL)
62964+ break;
62965+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
62966+ kfree(s->obj_hash);
62967+ else
62968+ vfree(s->obj_hash);
62969+ FOR_EACH_NESTED_SUBJECT_END(s)
62970+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
62971+ kfree(r->subj_hash);
62972+ else
62973+ vfree(r->subj_hash);
62974+ r->subj_hash = NULL;
62975+next_role:
62976+ FOR_EACH_ROLE_END(r)
62977+
62978+ acl_free_all();
62979+
62980+ if (acl_role_set.r_hash) {
62981+ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
62982+ PAGE_SIZE)
62983+ kfree(acl_role_set.r_hash);
62984+ else
62985+ vfree(acl_role_set.r_hash);
62986+ }
62987+ if (name_set.n_hash) {
62988+ if ((name_set.n_size * sizeof (struct name_entry *)) <=
62989+ PAGE_SIZE)
62990+ kfree(name_set.n_hash);
62991+ else
62992+ vfree(name_set.n_hash);
62993+ }
62994+
62995+ if (inodev_set.i_hash) {
62996+ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
62997+ PAGE_SIZE)
62998+ kfree(inodev_set.i_hash);
62999+ else
63000+ vfree(inodev_set.i_hash);
63001+ }
63002+
63003+ gr_free_uidset();
63004+
63005+ memset(&name_set, 0, sizeof (struct name_db));
63006+ memset(&inodev_set, 0, sizeof (struct inodev_db));
63007+ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
63008+ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
63009+
63010+ default_role = NULL;
63011+ kernel_role = NULL;
63012+ role_list = NULL;
63013+
63014+ return;
63015+}
63016+
63017+static struct acl_subject_label *
63018+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
63019+
63020+static int alloc_and_copy_string(char **name, unsigned int maxlen)
63021+{
63022+ unsigned int len = strnlen_user(*name, maxlen);
63023+ char *tmp;
63024+
63025+ if (!len || len >= maxlen)
63026+ return -EINVAL;
63027+
63028+ if ((tmp = (char *) acl_alloc(len)) == NULL)
63029+ return -ENOMEM;
63030+
63031+ if (copy_from_user(tmp, *name, len))
63032+ return -EFAULT;
63033+
63034+ tmp[len-1] = '\0';
63035+ *name = tmp;
63036+
63037+ return 0;
63038+}
63039+
63040+static int
63041+copy_user_glob(struct acl_object_label *obj)
63042+{
63043+ struct acl_object_label *g_tmp, **guser;
63044+ int error;
63045+
63046+ if (obj->globbed == NULL)
63047+ return 0;
63048+
63049+ guser = &obj->globbed;
63050+ while (*guser) {
63051+ g_tmp = (struct acl_object_label *)
63052+ acl_alloc(sizeof (struct acl_object_label));
63053+ if (g_tmp == NULL)
63054+ return -ENOMEM;
63055+
63056+ if (copy_acl_object_label(g_tmp, *guser))
63057+ return -EFAULT;
63058+
63059+ error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
63060+ if (error)
63061+ return error;
63062+
63063+ *guser = g_tmp;
63064+ guser = &(g_tmp->next);
63065+ }
63066+
63067+ return 0;
63068+}
63069+
63070+static int
63071+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
63072+ struct acl_role_label *role)
63073+{
63074+ struct acl_object_label *o_tmp;
63075+ int ret;
63076+
63077+ while (userp) {
63078+ if ((o_tmp = (struct acl_object_label *)
63079+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
63080+ return -ENOMEM;
63081+
63082+ if (copy_acl_object_label(o_tmp, userp))
63083+ return -EFAULT;
63084+
63085+ userp = o_tmp->prev;
63086+
63087+ ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
63088+ if (ret)
63089+ return ret;
63090+
63091+ insert_acl_obj_label(o_tmp, subj);
63092+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
63093+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
63094+ return -ENOMEM;
63095+
63096+ ret = copy_user_glob(o_tmp);
63097+ if (ret)
63098+ return ret;
63099+
63100+ if (o_tmp->nested) {
63101+ int already_copied;
63102+
63103+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
63104+ if (IS_ERR(o_tmp->nested))
63105+ return PTR_ERR(o_tmp->nested);
63106+
63107+ /* insert into nested subject list if we haven't copied this one yet
63108+ to prevent duplicate entries */
63109+ if (!already_copied) {
63110+ o_tmp->nested->next = role->hash->first;
63111+ role->hash->first = o_tmp->nested;
63112+ }
63113+ }
63114+ }
63115+
63116+ return 0;
63117+}
63118+
63119+static __u32
63120+count_user_subjs(struct acl_subject_label *userp)
63121+{
63122+ struct acl_subject_label s_tmp;
63123+ __u32 num = 0;
63124+
63125+ while (userp) {
63126+ if (copy_acl_subject_label(&s_tmp, userp))
63127+ break;
63128+
63129+ userp = s_tmp.prev;
63130+ }
63131+
63132+ return num;
63133+}
63134+
63135+static int
63136+copy_user_allowedips(struct acl_role_label *rolep)
63137+{
63138+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
63139+
63140+ ruserip = rolep->allowed_ips;
63141+
63142+ while (ruserip) {
63143+ rlast = rtmp;
63144+
63145+ if ((rtmp = (struct role_allowed_ip *)
63146+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
63147+ return -ENOMEM;
63148+
63149+ if (copy_role_allowed_ip(rtmp, ruserip))
63150+ return -EFAULT;
63151+
63152+ ruserip = rtmp->prev;
63153+
63154+ if (!rlast) {
63155+ rtmp->prev = NULL;
63156+ rolep->allowed_ips = rtmp;
63157+ } else {
63158+ rlast->next = rtmp;
63159+ rtmp->prev = rlast;
63160+ }
63161+
63162+ if (!ruserip)
63163+ rtmp->next = NULL;
63164+ }
63165+
63166+ return 0;
63167+}
63168+
63169+static int
63170+copy_user_transitions(struct acl_role_label *rolep)
63171+{
63172+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
63173+ int error;
63174+
63175+ rusertp = rolep->transitions;
63176+
63177+ while (rusertp) {
63178+ rlast = rtmp;
63179+
63180+ if ((rtmp = (struct role_transition *)
63181+ acl_alloc(sizeof (struct role_transition))) == NULL)
63182+ return -ENOMEM;
63183+
63184+ if (copy_role_transition(rtmp, rusertp))
63185+ return -EFAULT;
63186+
63187+ rusertp = rtmp->prev;
63188+
63189+ error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
63190+ if (error)
63191+ return error;
63192+
63193+ if (!rlast) {
63194+ rtmp->prev = NULL;
63195+ rolep->transitions = rtmp;
63196+ } else {
63197+ rlast->next = rtmp;
63198+ rtmp->prev = rlast;
63199+ }
63200+
63201+ if (!rusertp)
63202+ rtmp->next = NULL;
63203+ }
63204+
63205+ return 0;
63206+}
63207+
63208+static __u32 count_user_objs(const struct acl_object_label __user *userp)
63209+{
63210+ struct acl_object_label o_tmp;
63211+ __u32 num = 0;
63212+
63213+ while (userp) {
63214+ if (copy_acl_object_label(&o_tmp, userp))
63215+ break;
63216+
63217+ userp = o_tmp.prev;
63218+ num++;
63219+ }
63220+
63221+ return num;
63222+}
63223+
63224+static struct acl_subject_label *
63225+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
63226+{
63227+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
63228+ __u32 num_objs;
63229+ struct acl_ip_label **i_tmp, *i_utmp2;
63230+ struct gr_hash_struct ghash;
63231+ struct subject_map *subjmap;
63232+ unsigned int i_num;
63233+ int err;
63234+
63235+ if (already_copied != NULL)
63236+ *already_copied = 0;
63237+
63238+ s_tmp = lookup_subject_map(userp);
63239+
63240+ /* we've already copied this subject into the kernel, just return
63241+ the reference to it, and don't copy it over again
63242+ */
63243+ if (s_tmp) {
63244+ if (already_copied != NULL)
63245+ *already_copied = 1;
63246+ return(s_tmp);
63247+ }
63248+
63249+ if ((s_tmp = (struct acl_subject_label *)
63250+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
63251+ return ERR_PTR(-ENOMEM);
63252+
63253+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
63254+ if (subjmap == NULL)
63255+ return ERR_PTR(-ENOMEM);
63256+
63257+ subjmap->user = userp;
63258+ subjmap->kernel = s_tmp;
63259+ insert_subj_map_entry(subjmap);
63260+
63261+ if (copy_acl_subject_label(s_tmp, userp))
63262+ return ERR_PTR(-EFAULT);
63263+
63264+ err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
63265+ if (err)
63266+ return ERR_PTR(err);
63267+
63268+ if (!strcmp(s_tmp->filename, "/"))
63269+ role->root_label = s_tmp;
63270+
63271+ if (copy_gr_hash_struct(&ghash, s_tmp->hash))
63272+ return ERR_PTR(-EFAULT);
63273+
63274+ /* copy user and group transition tables */
63275+
63276+ if (s_tmp->user_trans_num) {
63277+ uid_t *uidlist;
63278+
63279+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
63280+ if (uidlist == NULL)
63281+ return ERR_PTR(-ENOMEM);
63282+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
63283+ return ERR_PTR(-EFAULT);
63284+
63285+ s_tmp->user_transitions = uidlist;
63286+ }
63287+
63288+ if (s_tmp->group_trans_num) {
63289+ gid_t *gidlist;
63290+
63291+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
63292+ if (gidlist == NULL)
63293+ return ERR_PTR(-ENOMEM);
63294+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
63295+ return ERR_PTR(-EFAULT);
63296+
63297+ s_tmp->group_transitions = gidlist;
63298+ }
63299+
63300+ /* set up object hash table */
63301+ num_objs = count_user_objs(ghash.first);
63302+
63303+ s_tmp->obj_hash_size = num_objs;
63304+ s_tmp->obj_hash =
63305+ (struct acl_object_label **)
63306+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
63307+
63308+ if (!s_tmp->obj_hash)
63309+ return ERR_PTR(-ENOMEM);
63310+
63311+ memset(s_tmp->obj_hash, 0,
63312+ s_tmp->obj_hash_size *
63313+ sizeof (struct acl_object_label *));
63314+
63315+ /* add in objects */
63316+ err = copy_user_objs(ghash.first, s_tmp, role);
63317+
63318+ if (err)
63319+ return ERR_PTR(err);
63320+
63321+ /* set pointer for parent subject */
63322+ if (s_tmp->parent_subject) {
63323+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
63324+
63325+ if (IS_ERR(s_tmp2))
63326+ return s_tmp2;
63327+
63328+ s_tmp->parent_subject = s_tmp2;
63329+ }
63330+
63331+ /* add in ip acls */
63332+
63333+ if (!s_tmp->ip_num) {
63334+ s_tmp->ips = NULL;
63335+ goto insert;
63336+ }
63337+
63338+ i_tmp =
63339+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
63340+ sizeof (struct acl_ip_label *));
63341+
63342+ if (!i_tmp)
63343+ return ERR_PTR(-ENOMEM);
63344+
63345+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
63346+ *(i_tmp + i_num) =
63347+ (struct acl_ip_label *)
63348+ acl_alloc(sizeof (struct acl_ip_label));
63349+ if (!*(i_tmp + i_num))
63350+ return ERR_PTR(-ENOMEM);
63351+
63352+ if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
63353+ return ERR_PTR(-EFAULT);
63354+
63355+ if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
63356+ return ERR_PTR(-EFAULT);
63357+
63358+ if ((*(i_tmp + i_num))->iface == NULL)
63359+ continue;
63360+
63361+ err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
63362+ if (err)
63363+ return ERR_PTR(err);
63364+ }
63365+
63366+ s_tmp->ips = i_tmp;
63367+
63368+insert:
63369+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
63370+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
63371+ return ERR_PTR(-ENOMEM);
63372+
63373+ return s_tmp;
63374+}
63375+
63376+static int
63377+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
63378+{
63379+ struct acl_subject_label s_pre;
63380+ struct acl_subject_label * ret;
63381+ int err;
63382+
63383+ while (userp) {
63384+ if (copy_acl_subject_label(&s_pre, userp))
63385+ return -EFAULT;
63386+
63387+ ret = do_copy_user_subj(userp, role, NULL);
63388+
63389+ err = PTR_ERR(ret);
63390+ if (IS_ERR(ret))
63391+ return err;
63392+
63393+ insert_acl_subj_label(ret, role);
63394+
63395+ userp = s_pre.prev;
63396+ }
63397+
63398+ return 0;
63399+}
63400+
63401+static int
63402+copy_user_acl(struct gr_arg *arg)
63403+{
63404+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
63405+ struct acl_subject_label *subj_list;
63406+ struct sprole_pw *sptmp;
63407+ struct gr_hash_struct *ghash;
63408+ uid_t *domainlist;
63409+ unsigned int r_num;
63410+ int err = 0;
63411+ __u16 i;
63412+ __u32 num_subjs;
63413+
63414+ /* we need a default and kernel role */
63415+ if (arg->role_db.num_roles < 2)
63416+ return -EINVAL;
63417+
63418+ /* copy special role authentication info from userspace */
63419+
63420+ num_sprole_pws = arg->num_sprole_pws;
63421+ acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
63422+
63423+ if (!acl_special_roles && num_sprole_pws)
63424+ return -ENOMEM;
63425+
63426+ for (i = 0; i < num_sprole_pws; i++) {
63427+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
63428+ if (!sptmp)
63429+ return -ENOMEM;
63430+ if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
63431+ return -EFAULT;
63432+
63433+ err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
63434+ if (err)
63435+ return err;
63436+
63437+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
63438+ printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
63439+#endif
63440+
63441+ acl_special_roles[i] = sptmp;
63442+ }
63443+
63444+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
63445+
63446+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
63447+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
63448+
63449+ if (!r_tmp)
63450+ return -ENOMEM;
63451+
63452+ if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
63453+ return -EFAULT;
63454+
63455+ if (copy_acl_role_label(r_tmp, r_utmp2))
63456+ return -EFAULT;
63457+
63458+ err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
63459+ if (err)
63460+ return err;
63461+
63462+ if (!strcmp(r_tmp->rolename, "default")
63463+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
63464+ default_role = r_tmp;
63465+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
63466+ kernel_role = r_tmp;
63467+ }
63468+
63469+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
63470+ return -ENOMEM;
63471+
63472+ if (copy_gr_hash_struct(ghash, r_tmp->hash))
63473+ return -EFAULT;
63474+
63475+ r_tmp->hash = ghash;
63476+
63477+ num_subjs = count_user_subjs(r_tmp->hash->first);
63478+
63479+ r_tmp->subj_hash_size = num_subjs;
63480+ r_tmp->subj_hash =
63481+ (struct acl_subject_label **)
63482+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
63483+
63484+ if (!r_tmp->subj_hash)
63485+ return -ENOMEM;
63486+
63487+ err = copy_user_allowedips(r_tmp);
63488+ if (err)
63489+ return err;
63490+
63491+ /* copy domain info */
63492+ if (r_tmp->domain_children != NULL) {
63493+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
63494+ if (domainlist == NULL)
63495+ return -ENOMEM;
63496+
63497+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
63498+ return -EFAULT;
63499+
63500+ r_tmp->domain_children = domainlist;
63501+ }
63502+
63503+ err = copy_user_transitions(r_tmp);
63504+ if (err)
63505+ return err;
63506+
63507+ memset(r_tmp->subj_hash, 0,
63508+ r_tmp->subj_hash_size *
63509+ sizeof (struct acl_subject_label *));
63510+
63511+ /* acquire the list of subjects, then NULL out
63512+ the list prior to parsing the subjects for this role,
63513+ as during this parsing the list is replaced with a list
63514+ of *nested* subjects for the role
63515+ */
63516+ subj_list = r_tmp->hash->first;
63517+
63518+ /* set nested subject list to null */
63519+ r_tmp->hash->first = NULL;
63520+
63521+ err = copy_user_subjs(subj_list, r_tmp);
63522+
63523+ if (err)
63524+ return err;
63525+
63526+ insert_acl_role_label(r_tmp);
63527+ }
63528+
63529+ if (default_role == NULL || kernel_role == NULL)
63530+ return -EINVAL;
63531+
63532+ return err;
63533+}
63534+
63535+static int
63536+gracl_init(struct gr_arg *args)
63537+{
63538+ int error = 0;
63539+
63540+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
63541+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
63542+
63543+ if (init_variables(args)) {
63544+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
63545+ error = -ENOMEM;
63546+ free_variables();
63547+ goto out;
63548+ }
63549+
63550+ error = copy_user_acl(args);
63551+ free_init_variables();
63552+ if (error) {
63553+ free_variables();
63554+ goto out;
63555+ }
63556+
63557+ if ((error = gr_set_acls(0))) {
63558+ free_variables();
63559+ goto out;
63560+ }
63561+
63562+ pax_open_kernel();
63563+ gr_status |= GR_READY;
63564+ pax_close_kernel();
63565+
63566+ out:
63567+ return error;
63568+}
63569+
63570+/* derived from glibc fnmatch() 0: match, 1: no match*/
63571+
63572+static int
63573+glob_match(const char *p, const char *n)
63574+{
63575+ char c;
63576+
63577+ while ((c = *p++) != '\0') {
63578+ switch (c) {
63579+ case '?':
63580+ if (*n == '\0')
63581+ return 1;
63582+ else if (*n == '/')
63583+ return 1;
63584+ break;
63585+ case '\\':
63586+ if (*n != c)
63587+ return 1;
63588+ break;
63589+ case '*':
63590+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
63591+ if (*n == '/')
63592+ return 1;
63593+ else if (c == '?') {
63594+ if (*n == '\0')
63595+ return 1;
63596+ else
63597+ ++n;
63598+ }
63599+ }
63600+ if (c == '\0') {
63601+ return 0;
63602+ } else {
63603+ const char *endp;
63604+
63605+ if ((endp = strchr(n, '/')) == NULL)
63606+ endp = n + strlen(n);
63607+
63608+ if (c == '[') {
63609+ for (--p; n < endp; ++n)
63610+ if (!glob_match(p, n))
63611+ return 0;
63612+ } else if (c == '/') {
63613+ while (*n != '\0' && *n != '/')
63614+ ++n;
63615+ if (*n == '/' && !glob_match(p, n + 1))
63616+ return 0;
63617+ } else {
63618+ for (--p; n < endp; ++n)
63619+ if (*n == c && !glob_match(p, n))
63620+ return 0;
63621+ }
63622+
63623+ return 1;
63624+ }
63625+ case '[':
63626+ {
63627+ int not;
63628+ char cold;
63629+
63630+ if (*n == '\0' || *n == '/')
63631+ return 1;
63632+
63633+ not = (*p == '!' || *p == '^');
63634+ if (not)
63635+ ++p;
63636+
63637+ c = *p++;
63638+ for (;;) {
63639+ unsigned char fn = (unsigned char)*n;
63640+
63641+ if (c == '\0')
63642+ return 1;
63643+ else {
63644+ if (c == fn)
63645+ goto matched;
63646+ cold = c;
63647+ c = *p++;
63648+
63649+ if (c == '-' && *p != ']') {
63650+ unsigned char cend = *p++;
63651+
63652+ if (cend == '\0')
63653+ return 1;
63654+
63655+ if (cold <= fn && fn <= cend)
63656+ goto matched;
63657+
63658+ c = *p++;
63659+ }
63660+ }
63661+
63662+ if (c == ']')
63663+ break;
63664+ }
63665+ if (!not)
63666+ return 1;
63667+ break;
63668+ matched:
63669+ while (c != ']') {
63670+ if (c == '\0')
63671+ return 1;
63672+
63673+ c = *p++;
63674+ }
63675+ if (not)
63676+ return 1;
63677+ }
63678+ break;
63679+ default:
63680+ if (c != *n)
63681+ return 1;
63682+ }
63683+
63684+ ++n;
63685+ }
63686+
63687+ if (*n == '\0')
63688+ return 0;
63689+
63690+ if (*n == '/')
63691+ return 0;
63692+
63693+ return 1;
63694+}
63695+
63696+static struct acl_object_label *
63697+chk_glob_label(struct acl_object_label *globbed,
63698+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
63699+{
63700+ struct acl_object_label *tmp;
63701+
63702+ if (*path == NULL)
63703+ *path = gr_to_filename_nolock(dentry, mnt);
63704+
63705+ tmp = globbed;
63706+
63707+ while (tmp) {
63708+ if (!glob_match(tmp->filename, *path))
63709+ return tmp;
63710+ tmp = tmp->next;
63711+ }
63712+
63713+ return NULL;
63714+}
63715+
63716+static struct acl_object_label *
63717+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
63718+ const ino_t curr_ino, const dev_t curr_dev,
63719+ const struct acl_subject_label *subj, char **path, const int checkglob)
63720+{
63721+ struct acl_subject_label *tmpsubj;
63722+ struct acl_object_label *retval;
63723+ struct acl_object_label *retval2;
63724+
63725+ tmpsubj = (struct acl_subject_label *) subj;
63726+ read_lock(&gr_inode_lock);
63727+ do {
63728+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
63729+ if (retval) {
63730+ if (checkglob && retval->globbed) {
63731+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
63732+ if (retval2)
63733+ retval = retval2;
63734+ }
63735+ break;
63736+ }
63737+ } while ((tmpsubj = tmpsubj->parent_subject));
63738+ read_unlock(&gr_inode_lock);
63739+
63740+ return retval;
63741+}
63742+
63743+static __inline__ struct acl_object_label *
63744+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
63745+ struct dentry *curr_dentry,
63746+ const struct acl_subject_label *subj, char **path, const int checkglob)
63747+{
63748+ int newglob = checkglob;
63749+ ino_t inode;
63750+ dev_t device;
63751+
63752+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
63753+ as we don't want a / * rule to match instead of the / object
63754+ don't do this for create lookups that call this function though, since they're looking up
63755+ on the parent and thus need globbing checks on all paths
63756+ */
63757+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
63758+ newglob = GR_NO_GLOB;
63759+
63760+ spin_lock(&curr_dentry->d_lock);
63761+ inode = curr_dentry->d_inode->i_ino;
63762+ device = __get_dev(curr_dentry);
63763+ spin_unlock(&curr_dentry->d_lock);
63764+
63765+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
63766+}
63767+
63768+#ifdef CONFIG_HUGETLBFS
63769+static inline bool
63770+is_hugetlbfs_mnt(const struct vfsmount *mnt)
63771+{
63772+ int i;
63773+ for (i = 0; i < HUGE_MAX_HSTATE; i++) {
63774+ if (unlikely(hugetlbfs_vfsmount[i] == mnt))
63775+ return true;
63776+ }
63777+
63778+ return false;
63779+}
63780+#endif
63781+
63782+static struct acl_object_label *
63783+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
63784+ const struct acl_subject_label *subj, char *path, const int checkglob)
63785+{
63786+ struct dentry *dentry = (struct dentry *) l_dentry;
63787+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
63788+ struct mount *real_mnt = real_mount(mnt);
63789+ struct acl_object_label *retval;
63790+ struct dentry *parent;
63791+
63792+ br_read_lock(&vfsmount_lock);
63793+ write_seqlock(&rename_lock);
63794+
63795+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
63796+#ifdef CONFIG_NET
63797+ mnt == sock_mnt ||
63798+#endif
63799+#ifdef CONFIG_HUGETLBFS
63800+ (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
63801+#endif
63802+ /* ignore Eric Biederman */
63803+ IS_PRIVATE(l_dentry->d_inode))) {
63804+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
63805+ goto out;
63806+ }
63807+
63808+ for (;;) {
63809+ if (dentry == real_root.dentry && mnt == real_root.mnt)
63810+ break;
63811+
63812+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
63813+ if (!mnt_has_parent(real_mnt))
63814+ break;
63815+
63816+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
63817+ if (retval != NULL)
63818+ goto out;
63819+
63820+ dentry = real_mnt->mnt_mountpoint;
63821+ real_mnt = real_mnt->mnt_parent;
63822+ mnt = &real_mnt->mnt;
63823+ continue;
63824+ }
63825+
63826+ parent = dentry->d_parent;
63827+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
63828+ if (retval != NULL)
63829+ goto out;
63830+
63831+ dentry = parent;
63832+ }
63833+
63834+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
63835+
63836+ /* real_root is pinned so we don't have to hold a reference */
63837+ if (retval == NULL)
63838+ retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
63839+out:
63840+ write_sequnlock(&rename_lock);
63841+ br_read_unlock(&vfsmount_lock);
63842+
63843+ BUG_ON(retval == NULL);
63844+
63845+ return retval;
63846+}
63847+
63848+static __inline__ struct acl_object_label *
63849+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
63850+ const struct acl_subject_label *subj)
63851+{
63852+ char *path = NULL;
63853+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
63854+}
63855+
63856+static __inline__ struct acl_object_label *
63857+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
63858+ const struct acl_subject_label *subj)
63859+{
63860+ char *path = NULL;
63861+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
63862+}
63863+
63864+static __inline__ struct acl_object_label *
63865+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
63866+ const struct acl_subject_label *subj, char *path)
63867+{
63868+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
63869+}
63870+
63871+static struct acl_subject_label *
63872+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
63873+ const struct acl_role_label *role)
63874+{
63875+ struct dentry *dentry = (struct dentry *) l_dentry;
63876+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
63877+ struct mount *real_mnt = real_mount(mnt);
63878+ struct acl_subject_label *retval;
63879+ struct dentry *parent;
63880+
63881+ br_read_lock(&vfsmount_lock);
63882+ write_seqlock(&rename_lock);
63883+
63884+ for (;;) {
63885+ if (dentry == real_root.dentry && mnt == real_root.mnt)
63886+ break;
63887+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
63888+ if (!mnt_has_parent(real_mnt))
63889+ break;
63890+
63891+ spin_lock(&dentry->d_lock);
63892+ read_lock(&gr_inode_lock);
63893+ retval =
63894+ lookup_acl_subj_label(dentry->d_inode->i_ino,
63895+ __get_dev(dentry), role);
63896+ read_unlock(&gr_inode_lock);
63897+ spin_unlock(&dentry->d_lock);
63898+ if (retval != NULL)
63899+ goto out;
63900+
63901+ dentry = real_mnt->mnt_mountpoint;
63902+ real_mnt = real_mnt->mnt_parent;
63903+ mnt = &real_mnt->mnt;
63904+ continue;
63905+ }
63906+
63907+ spin_lock(&dentry->d_lock);
63908+ read_lock(&gr_inode_lock);
63909+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
63910+ __get_dev(dentry), role);
63911+ read_unlock(&gr_inode_lock);
63912+ parent = dentry->d_parent;
63913+ spin_unlock(&dentry->d_lock);
63914+
63915+ if (retval != NULL)
63916+ goto out;
63917+
63918+ dentry = parent;
63919+ }
63920+
63921+ spin_lock(&dentry->d_lock);
63922+ read_lock(&gr_inode_lock);
63923+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
63924+ __get_dev(dentry), role);
63925+ read_unlock(&gr_inode_lock);
63926+ spin_unlock(&dentry->d_lock);
63927+
63928+ if (unlikely(retval == NULL)) {
63929+ /* real_root is pinned, we don't need to hold a reference */
63930+ read_lock(&gr_inode_lock);
63931+ retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
63932+ __get_dev(real_root.dentry), role);
63933+ read_unlock(&gr_inode_lock);
63934+ }
63935+out:
63936+ write_sequnlock(&rename_lock);
63937+ br_read_unlock(&vfsmount_lock);
63938+
63939+ BUG_ON(retval == NULL);
63940+
63941+ return retval;
63942+}
63943+
63944+static void
63945+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
63946+{
63947+ struct task_struct *task = current;
63948+ const struct cred *cred = current_cred();
63949+
63950+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
63951+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
63952+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
63953+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
63954+
63955+ return;
63956+}
63957+
63958+static void
63959+gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
63960+{
63961+ struct task_struct *task = current;
63962+ const struct cred *cred = current_cred();
63963+
63964+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
63965+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
63966+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
63967+ 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
63968+
63969+ return;
63970+}
63971+
63972+static void
63973+gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
63974+{
63975+ struct task_struct *task = current;
63976+ const struct cred *cred = current_cred();
63977+
63978+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
63979+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
63980+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
63981+ 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
63982+
63983+ return;
63984+}
63985+
63986+__u32
63987+gr_search_file(const struct dentry * dentry, const __u32 mode,
63988+ const struct vfsmount * mnt)
63989+{
63990+ __u32 retval = mode;
63991+ struct acl_subject_label *curracl;
63992+ struct acl_object_label *currobj;
63993+
63994+ if (unlikely(!(gr_status & GR_READY)))
63995+ return (mode & ~GR_AUDITS);
63996+
63997+ curracl = current->acl;
63998+
63999+ currobj = chk_obj_label(dentry, mnt, curracl);
64000+ retval = currobj->mode & mode;
64001+
64002+ /* if we're opening a specified transfer file for writing
64003+ (e.g. /dev/initctl), then transfer our role to init
64004+ */
64005+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
64006+ current->role->roletype & GR_ROLE_PERSIST)) {
64007+ struct task_struct *task = init_pid_ns.child_reaper;
64008+
64009+ if (task->role != current->role) {
64010+ task->acl_sp_role = 0;
64011+ task->acl_role_id = current->acl_role_id;
64012+ task->role = current->role;
64013+ rcu_read_lock();
64014+ read_lock(&grsec_exec_file_lock);
64015+ gr_apply_subject_to_task(task);
64016+ read_unlock(&grsec_exec_file_lock);
64017+ rcu_read_unlock();
64018+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
64019+ }
64020+ }
64021+
64022+ if (unlikely
64023+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
64024+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
64025+ __u32 new_mode = mode;
64026+
64027+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
64028+
64029+ retval = new_mode;
64030+
64031+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
64032+ new_mode |= GR_INHERIT;
64033+
64034+ if (!(mode & GR_NOLEARN))
64035+ gr_log_learn(dentry, mnt, new_mode);
64036+ }
64037+
64038+ return retval;
64039+}
64040+
64041+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
64042+ const struct dentry *parent,
64043+ const struct vfsmount *mnt)
64044+{
64045+ struct name_entry *match;
64046+ struct acl_object_label *matchpo;
64047+ struct acl_subject_label *curracl;
64048+ char *path;
64049+
64050+ if (unlikely(!(gr_status & GR_READY)))
64051+ return NULL;
64052+
64053+ preempt_disable();
64054+ path = gr_to_filename_rbac(new_dentry, mnt);
64055+ match = lookup_name_entry_create(path);
64056+
64057+ curracl = current->acl;
64058+
64059+ if (match) {
64060+ read_lock(&gr_inode_lock);
64061+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
64062+ read_unlock(&gr_inode_lock);
64063+
64064+ if (matchpo) {
64065+ preempt_enable();
64066+ return matchpo;
64067+ }
64068+ }
64069+
64070+ // lookup parent
64071+
64072+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
64073+
64074+ preempt_enable();
64075+ return matchpo;
64076+}
64077+
64078+__u32
64079+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
64080+ const struct vfsmount * mnt, const __u32 mode)
64081+{
64082+ struct acl_object_label *matchpo;
64083+ __u32 retval;
64084+
64085+ if (unlikely(!(gr_status & GR_READY)))
64086+ return (mode & ~GR_AUDITS);
64087+
64088+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
64089+
64090+ retval = matchpo->mode & mode;
64091+
64092+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
64093+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
64094+ __u32 new_mode = mode;
64095+
64096+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
64097+
64098+ gr_log_learn(new_dentry, mnt, new_mode);
64099+ return new_mode;
64100+ }
64101+
64102+ return retval;
64103+}
64104+
64105+__u32
64106+gr_check_link(const struct dentry * new_dentry,
64107+ const struct dentry * parent_dentry,
64108+ const struct vfsmount * parent_mnt,
64109+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
64110+{
64111+ struct acl_object_label *obj;
64112+ __u32 oldmode, newmode;
64113+ __u32 needmode;
64114+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
64115+ GR_DELETE | GR_INHERIT;
64116+
64117+ if (unlikely(!(gr_status & GR_READY)))
64118+ return (GR_CREATE | GR_LINK);
64119+
64120+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
64121+ oldmode = obj->mode;
64122+
64123+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
64124+ newmode = obj->mode;
64125+
64126+ needmode = newmode & checkmodes;
64127+
64128+ // old name for hardlink must have at least the permissions of the new name
64129+ if ((oldmode & needmode) != needmode)
64130+ goto bad;
64131+
64132+ // if old name had restrictions/auditing, make sure the new name does as well
64133+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
64134+
64135+ // don't allow hardlinking of suid/sgid/fcapped files without permission
64136+ if (is_privileged_binary(old_dentry))
64137+ needmode |= GR_SETID;
64138+
64139+ if ((newmode & needmode) != needmode)
64140+ goto bad;
64141+
64142+ // enforce minimum permissions
64143+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
64144+ return newmode;
64145+bad:
64146+ needmode = oldmode;
64147+ if (is_privileged_binary(old_dentry))
64148+ needmode |= GR_SETID;
64149+
64150+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
64151+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
64152+ return (GR_CREATE | GR_LINK);
64153+ } else if (newmode & GR_SUPPRESS)
64154+ return GR_SUPPRESS;
64155+ else
64156+ return 0;
64157+}
64158+
64159+int
64160+gr_check_hidden_task(const struct task_struct *task)
64161+{
64162+ if (unlikely(!(gr_status & GR_READY)))
64163+ return 0;
64164+
64165+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
64166+ return 1;
64167+
64168+ return 0;
64169+}
64170+
64171+int
64172+gr_check_protected_task(const struct task_struct *task)
64173+{
64174+ if (unlikely(!(gr_status & GR_READY) || !task))
64175+ return 0;
64176+
64177+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
64178+ task->acl != current->acl)
64179+ return 1;
64180+
64181+ return 0;
64182+}
64183+
64184+int
64185+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
64186+{
64187+ struct task_struct *p;
64188+ int ret = 0;
64189+
64190+ if (unlikely(!(gr_status & GR_READY) || !pid))
64191+ return ret;
64192+
64193+ read_lock(&tasklist_lock);
64194+ do_each_pid_task(pid, type, p) {
64195+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
64196+ p->acl != current->acl) {
64197+ ret = 1;
64198+ goto out;
64199+ }
64200+ } while_each_pid_task(pid, type, p);
64201+out:
64202+ read_unlock(&tasklist_lock);
64203+
64204+ return ret;
64205+}
64206+
64207+void
64208+gr_copy_label(struct task_struct *tsk)
64209+{
64210+ tsk->signal->used_accept = 0;
64211+ tsk->acl_sp_role = 0;
64212+ tsk->acl_role_id = current->acl_role_id;
64213+ tsk->acl = current->acl;
64214+ tsk->role = current->role;
64215+ tsk->signal->curr_ip = current->signal->curr_ip;
64216+ tsk->signal->saved_ip = current->signal->saved_ip;
64217+ if (current->exec_file)
64218+ get_file(current->exec_file);
64219+ tsk->exec_file = current->exec_file;
64220+ tsk->is_writable = current->is_writable;
64221+ if (unlikely(current->signal->used_accept)) {
64222+ current->signal->curr_ip = 0;
64223+ current->signal->saved_ip = 0;
64224+ }
64225+
64226+ return;
64227+}
64228+
64229+static void
64230+gr_set_proc_res(struct task_struct *task)
64231+{
64232+ struct acl_subject_label *proc;
64233+ unsigned short i;
64234+
64235+ proc = task->acl;
64236+
64237+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
64238+ return;
64239+
64240+ for (i = 0; i < RLIM_NLIMITS; i++) {
64241+ if (!(proc->resmask & (1U << i)))
64242+ continue;
64243+
64244+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
64245+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
64246+
64247+ if (i == RLIMIT_CPU)
64248+ update_rlimit_cpu(task, proc->res[i].rlim_cur);
64249+ }
64250+
64251+ return;
64252+}
64253+
64254+extern int gr_process_kernel_setuid_ban(struct user_struct *user);
64255+
64256+int
64257+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
64258+{
64259+ unsigned int i;
64260+ __u16 num;
64261+ uid_t *uidlist;
64262+ uid_t curuid;
64263+ int realok = 0;
64264+ int effectiveok = 0;
64265+ int fsok = 0;
64266+ uid_t globalreal, globaleffective, globalfs;
64267+
64268+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
64269+ struct user_struct *user;
64270+
64271+ if (!uid_valid(real))
64272+ goto skipit;
64273+
64274+ /* find user based on global namespace */
64275+
64276+ globalreal = GR_GLOBAL_UID(real);
64277+
64278+ user = find_user(make_kuid(&init_user_ns, globalreal));
64279+ if (user == NULL)
64280+ goto skipit;
64281+
64282+ if (gr_process_kernel_setuid_ban(user)) {
64283+ /* for find_user */
64284+ free_uid(user);
64285+ return 1;
64286+ }
64287+
64288+ /* for find_user */
64289+ free_uid(user);
64290+
64291+skipit:
64292+#endif
64293+
64294+ if (unlikely(!(gr_status & GR_READY)))
64295+ return 0;
64296+
64297+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
64298+ gr_log_learn_uid_change(real, effective, fs);
64299+
64300+ num = current->acl->user_trans_num;
64301+ uidlist = current->acl->user_transitions;
64302+
64303+ if (uidlist == NULL)
64304+ return 0;
64305+
64306+ if (!uid_valid(real)) {
64307+ realok = 1;
64308+ globalreal = (uid_t)-1;
64309+ } else {
64310+ globalreal = GR_GLOBAL_UID(real);
64311+ }
64312+ if (!uid_valid(effective)) {
64313+ effectiveok = 1;
64314+ globaleffective = (uid_t)-1;
64315+ } else {
64316+ globaleffective = GR_GLOBAL_UID(effective);
64317+ }
64318+ if (!uid_valid(fs)) {
64319+ fsok = 1;
64320+ globalfs = (uid_t)-1;
64321+ } else {
64322+ globalfs = GR_GLOBAL_UID(fs);
64323+ }
64324+
64325+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
64326+ for (i = 0; i < num; i++) {
64327+ curuid = uidlist[i];
64328+ if (globalreal == curuid)
64329+ realok = 1;
64330+ if (globaleffective == curuid)
64331+ effectiveok = 1;
64332+ if (globalfs == curuid)
64333+ fsok = 1;
64334+ }
64335+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
64336+ for (i = 0; i < num; i++) {
64337+ curuid = uidlist[i];
64338+ if (globalreal == curuid)
64339+ break;
64340+ if (globaleffective == curuid)
64341+ break;
64342+ if (globalfs == curuid)
64343+ break;
64344+ }
64345+ /* not in deny list */
64346+ if (i == num) {
64347+ realok = 1;
64348+ effectiveok = 1;
64349+ fsok = 1;
64350+ }
64351+ }
64352+
64353+ if (realok && effectiveok && fsok)
64354+ return 0;
64355+ else {
64356+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
64357+ return 1;
64358+ }
64359+}
64360+
64361+int
64362+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
64363+{
64364+ unsigned int i;
64365+ __u16 num;
64366+ gid_t *gidlist;
64367+ gid_t curgid;
64368+ int realok = 0;
64369+ int effectiveok = 0;
64370+ int fsok = 0;
64371+ gid_t globalreal, globaleffective, globalfs;
64372+
64373+ if (unlikely(!(gr_status & GR_READY)))
64374+ return 0;
64375+
64376+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
64377+ gr_log_learn_gid_change(real, effective, fs);
64378+
64379+ num = current->acl->group_trans_num;
64380+ gidlist = current->acl->group_transitions;
64381+
64382+ if (gidlist == NULL)
64383+ return 0;
64384+
64385+ if (!gid_valid(real)) {
64386+ realok = 1;
64387+ globalreal = (gid_t)-1;
64388+ } else {
64389+ globalreal = GR_GLOBAL_GID(real);
64390+ }
64391+ if (!gid_valid(effective)) {
64392+ effectiveok = 1;
64393+ globaleffective = (gid_t)-1;
64394+ } else {
64395+ globaleffective = GR_GLOBAL_GID(effective);
64396+ }
64397+ if (!gid_valid(fs)) {
64398+ fsok = 1;
64399+ globalfs = (gid_t)-1;
64400+ } else {
64401+ globalfs = GR_GLOBAL_GID(fs);
64402+ }
64403+
64404+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
64405+ for (i = 0; i < num; i++) {
64406+ curgid = gidlist[i];
64407+ if (globalreal == curgid)
64408+ realok = 1;
64409+ if (globaleffective == curgid)
64410+ effectiveok = 1;
64411+ if (globalfs == curgid)
64412+ fsok = 1;
64413+ }
64414+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
64415+ for (i = 0; i < num; i++) {
64416+ curgid = gidlist[i];
64417+ if (globalreal == curgid)
64418+ break;
64419+ if (globaleffective == curgid)
64420+ break;
64421+ if (globalfs == curgid)
64422+ break;
64423+ }
64424+ /* not in deny list */
64425+ if (i == num) {
64426+ realok = 1;
64427+ effectiveok = 1;
64428+ fsok = 1;
64429+ }
64430+ }
64431+
64432+ if (realok && effectiveok && fsok)
64433+ return 0;
64434+ else {
64435+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
64436+ return 1;
64437+ }
64438+}
64439+
64440+extern int gr_acl_is_capable(const int cap);
64441+
64442+void
64443+gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
64444+{
64445+ struct acl_role_label *role = task->role;
64446+ struct acl_subject_label *subj = NULL;
64447+ struct acl_object_label *obj;
64448+ struct file *filp;
64449+ uid_t uid;
64450+ gid_t gid;
64451+
64452+ if (unlikely(!(gr_status & GR_READY)))
64453+ return;
64454+
64455+ uid = GR_GLOBAL_UID(kuid);
64456+ gid = GR_GLOBAL_GID(kgid);
64457+
64458+ filp = task->exec_file;
64459+
64460+ /* kernel process, we'll give them the kernel role */
64461+ if (unlikely(!filp)) {
64462+ task->role = kernel_role;
64463+ task->acl = kernel_role->root_label;
64464+ return;
64465+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
64466+ role = lookup_acl_role_label(task, uid, gid);
64467+
64468+ /* don't change the role if we're not a privileged process */
64469+ if (role && task->role != role &&
64470+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
64471+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
64472+ return;
64473+
64474+ /* perform subject lookup in possibly new role
64475+ we can use this result below in the case where role == task->role
64476+ */
64477+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
64478+
64479+ /* if we changed uid/gid, but result in the same role
64480+ and are using inheritance, don't lose the inherited subject
64481+ if current subject is other than what normal lookup
64482+ would result in, we arrived via inheritance, don't
64483+ lose subject
64484+ */
64485+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
64486+ (subj == task->acl)))
64487+ task->acl = subj;
64488+
64489+ task->role = role;
64490+
64491+ task->is_writable = 0;
64492+
64493+ /* ignore additional mmap checks for processes that are writable
64494+ by the default ACL */
64495+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
64496+ if (unlikely(obj->mode & GR_WRITE))
64497+ task->is_writable = 1;
64498+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
64499+ if (unlikely(obj->mode & GR_WRITE))
64500+ task->is_writable = 1;
64501+
64502+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
64503+ 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);
64504+#endif
64505+
64506+ gr_set_proc_res(task);
64507+
64508+ return;
64509+}
64510+
64511+int
64512+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
64513+ const int unsafe_flags)
64514+{
64515+ struct task_struct *task = current;
64516+ struct acl_subject_label *newacl;
64517+ struct acl_object_label *obj;
64518+ __u32 retmode;
64519+
64520+ if (unlikely(!(gr_status & GR_READY)))
64521+ return 0;
64522+
64523+ newacl = chk_subj_label(dentry, mnt, task->role);
64524+
64525+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
64526+ did an exec
64527+ */
64528+ rcu_read_lock();
64529+ read_lock(&tasklist_lock);
64530+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
64531+ (task->parent->acl->mode & GR_POVERRIDE))) {
64532+ read_unlock(&tasklist_lock);
64533+ rcu_read_unlock();
64534+ goto skip_check;
64535+ }
64536+ read_unlock(&tasklist_lock);
64537+ rcu_read_unlock();
64538+
64539+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
64540+ !(task->role->roletype & GR_ROLE_GOD) &&
64541+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
64542+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
64543+ if (unsafe_flags & LSM_UNSAFE_SHARE)
64544+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
64545+ else
64546+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
64547+ return -EACCES;
64548+ }
64549+
64550+skip_check:
64551+
64552+ obj = chk_obj_label(dentry, mnt, task->acl);
64553+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
64554+
64555+ if (!(task->acl->mode & GR_INHERITLEARN) &&
64556+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
64557+ if (obj->nested)
64558+ task->acl = obj->nested;
64559+ else
64560+ task->acl = newacl;
64561+ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
64562+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
64563+
64564+ task->is_writable = 0;
64565+
64566+ /* ignore additional mmap checks for processes that are writable
64567+ by the default ACL */
64568+ obj = chk_obj_label(dentry, mnt, default_role->root_label);
64569+ if (unlikely(obj->mode & GR_WRITE))
64570+ task->is_writable = 1;
64571+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
64572+ if (unlikely(obj->mode & GR_WRITE))
64573+ task->is_writable = 1;
64574+
64575+ gr_set_proc_res(task);
64576+
64577+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
64578+ 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);
64579+#endif
64580+ return 0;
64581+}
64582+
64583+/* always called with valid inodev ptr */
64584+static void
64585+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
64586+{
64587+ struct acl_object_label *matchpo;
64588+ struct acl_subject_label *matchps;
64589+ struct acl_subject_label *subj;
64590+ struct acl_role_label *role;
64591+ unsigned int x;
64592+
64593+ FOR_EACH_ROLE_START(role)
64594+ FOR_EACH_SUBJECT_START(role, subj, x)
64595+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
64596+ matchpo->mode |= GR_DELETED;
64597+ FOR_EACH_SUBJECT_END(subj,x)
64598+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
64599+ /* nested subjects aren't in the role's subj_hash table */
64600+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
64601+ matchpo->mode |= GR_DELETED;
64602+ FOR_EACH_NESTED_SUBJECT_END(subj)
64603+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
64604+ matchps->mode |= GR_DELETED;
64605+ FOR_EACH_ROLE_END(role)
64606+
64607+ inodev->nentry->deleted = 1;
64608+
64609+ return;
64610+}
64611+
64612+void
64613+gr_handle_delete(const ino_t ino, const dev_t dev)
64614+{
64615+ struct inodev_entry *inodev;
64616+
64617+ if (unlikely(!(gr_status & GR_READY)))
64618+ return;
64619+
64620+ write_lock(&gr_inode_lock);
64621+ inodev = lookup_inodev_entry(ino, dev);
64622+ if (inodev != NULL)
64623+ do_handle_delete(inodev, ino, dev);
64624+ write_unlock(&gr_inode_lock);
64625+
64626+ return;
64627+}
64628+
64629+static void
64630+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
64631+ const ino_t newinode, const dev_t newdevice,
64632+ struct acl_subject_label *subj)
64633+{
64634+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
64635+ struct acl_object_label *match;
64636+
64637+ match = subj->obj_hash[index];
64638+
64639+ while (match && (match->inode != oldinode ||
64640+ match->device != olddevice ||
64641+ !(match->mode & GR_DELETED)))
64642+ match = match->next;
64643+
64644+ if (match && (match->inode == oldinode)
64645+ && (match->device == olddevice)
64646+ && (match->mode & GR_DELETED)) {
64647+ if (match->prev == NULL) {
64648+ subj->obj_hash[index] = match->next;
64649+ if (match->next != NULL)
64650+ match->next->prev = NULL;
64651+ } else {
64652+ match->prev->next = match->next;
64653+ if (match->next != NULL)
64654+ match->next->prev = match->prev;
64655+ }
64656+ match->prev = NULL;
64657+ match->next = NULL;
64658+ match->inode = newinode;
64659+ match->device = newdevice;
64660+ match->mode &= ~GR_DELETED;
64661+
64662+ insert_acl_obj_label(match, subj);
64663+ }
64664+
64665+ return;
64666+}
64667+
64668+static void
64669+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
64670+ const ino_t newinode, const dev_t newdevice,
64671+ struct acl_role_label *role)
64672+{
64673+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
64674+ struct acl_subject_label *match;
64675+
64676+ match = role->subj_hash[index];
64677+
64678+ while (match && (match->inode != oldinode ||
64679+ match->device != olddevice ||
64680+ !(match->mode & GR_DELETED)))
64681+ match = match->next;
64682+
64683+ if (match && (match->inode == oldinode)
64684+ && (match->device == olddevice)
64685+ && (match->mode & GR_DELETED)) {
64686+ if (match->prev == NULL) {
64687+ role->subj_hash[index] = match->next;
64688+ if (match->next != NULL)
64689+ match->next->prev = NULL;
64690+ } else {
64691+ match->prev->next = match->next;
64692+ if (match->next != NULL)
64693+ match->next->prev = match->prev;
64694+ }
64695+ match->prev = NULL;
64696+ match->next = NULL;
64697+ match->inode = newinode;
64698+ match->device = newdevice;
64699+ match->mode &= ~GR_DELETED;
64700+
64701+ insert_acl_subj_label(match, role);
64702+ }
64703+
64704+ return;
64705+}
64706+
64707+static void
64708+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
64709+ const ino_t newinode, const dev_t newdevice)
64710+{
64711+ unsigned int index = gr_fhash(oldinode, olddevice, inodev_set.i_size);
64712+ struct inodev_entry *match;
64713+
64714+ match = inodev_set.i_hash[index];
64715+
64716+ while (match && (match->nentry->inode != oldinode ||
64717+ match->nentry->device != olddevice || !match->nentry->deleted))
64718+ match = match->next;
64719+
64720+ if (match && (match->nentry->inode == oldinode)
64721+ && (match->nentry->device == olddevice) &&
64722+ match->nentry->deleted) {
64723+ if (match->prev == NULL) {
64724+ inodev_set.i_hash[index] = match->next;
64725+ if (match->next != NULL)
64726+ match->next->prev = NULL;
64727+ } else {
64728+ match->prev->next = match->next;
64729+ if (match->next != NULL)
64730+ match->next->prev = match->prev;
64731+ }
64732+ match->prev = NULL;
64733+ match->next = NULL;
64734+ match->nentry->inode = newinode;
64735+ match->nentry->device = newdevice;
64736+ match->nentry->deleted = 0;
64737+
64738+ insert_inodev_entry(match);
64739+ }
64740+
64741+ return;
64742+}
64743+
64744+static void
64745+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
64746+{
64747+ struct acl_subject_label *subj;
64748+ struct acl_role_label *role;
64749+ unsigned int x;
64750+
64751+ FOR_EACH_ROLE_START(role)
64752+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
64753+
64754+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
64755+ if ((subj->inode == ino) && (subj->device == dev)) {
64756+ subj->inode = ino;
64757+ subj->device = dev;
64758+ }
64759+ /* nested subjects aren't in the role's subj_hash table */
64760+ update_acl_obj_label(matchn->inode, matchn->device,
64761+ ino, dev, subj);
64762+ FOR_EACH_NESTED_SUBJECT_END(subj)
64763+ FOR_EACH_SUBJECT_START(role, subj, x)
64764+ update_acl_obj_label(matchn->inode, matchn->device,
64765+ ino, dev, subj);
64766+ FOR_EACH_SUBJECT_END(subj,x)
64767+ FOR_EACH_ROLE_END(role)
64768+
64769+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
64770+
64771+ return;
64772+}
64773+
64774+static void
64775+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
64776+ const struct vfsmount *mnt)
64777+{
64778+ ino_t ino = dentry->d_inode->i_ino;
64779+ dev_t dev = __get_dev(dentry);
64780+
64781+ __do_handle_create(matchn, ino, dev);
64782+
64783+ return;
64784+}
64785+
64786+void
64787+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
64788+{
64789+ struct name_entry *matchn;
64790+
64791+ if (unlikely(!(gr_status & GR_READY)))
64792+ return;
64793+
64794+ preempt_disable();
64795+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
64796+
64797+ if (unlikely((unsigned long)matchn)) {
64798+ write_lock(&gr_inode_lock);
64799+ do_handle_create(matchn, dentry, mnt);
64800+ write_unlock(&gr_inode_lock);
64801+ }
64802+ preempt_enable();
64803+
64804+ return;
64805+}
64806+
64807+void
64808+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
64809+{
64810+ struct name_entry *matchn;
64811+
64812+ if (unlikely(!(gr_status & GR_READY)))
64813+ return;
64814+
64815+ preempt_disable();
64816+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
64817+
64818+ if (unlikely((unsigned long)matchn)) {
64819+ write_lock(&gr_inode_lock);
64820+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
64821+ write_unlock(&gr_inode_lock);
64822+ }
64823+ preempt_enable();
64824+
64825+ return;
64826+}
64827+
64828+void
64829+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
64830+ struct dentry *old_dentry,
64831+ struct dentry *new_dentry,
64832+ struct vfsmount *mnt, const __u8 replace)
64833+{
64834+ struct name_entry *matchn;
64835+ struct inodev_entry *inodev;
64836+ struct inode *inode = new_dentry->d_inode;
64837+ ino_t old_ino = old_dentry->d_inode->i_ino;
64838+ dev_t old_dev = __get_dev(old_dentry);
64839+
64840+ /* vfs_rename swaps the name and parent link for old_dentry and
64841+ new_dentry
64842+ at this point, old_dentry has the new name, parent link, and inode
64843+ for the renamed file
64844+ if a file is being replaced by a rename, new_dentry has the inode
64845+ and name for the replaced file
64846+ */
64847+
64848+ if (unlikely(!(gr_status & GR_READY)))
64849+ return;
64850+
64851+ preempt_disable();
64852+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
64853+
64854+ /* we wouldn't have to check d_inode if it weren't for
64855+ NFS silly-renaming
64856+ */
64857+
64858+ write_lock(&gr_inode_lock);
64859+ if (unlikely(replace && inode)) {
64860+ ino_t new_ino = inode->i_ino;
64861+ dev_t new_dev = __get_dev(new_dentry);
64862+
64863+ inodev = lookup_inodev_entry(new_ino, new_dev);
64864+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
64865+ do_handle_delete(inodev, new_ino, new_dev);
64866+ }
64867+
64868+ inodev = lookup_inodev_entry(old_ino, old_dev);
64869+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
64870+ do_handle_delete(inodev, old_ino, old_dev);
64871+
64872+ if (unlikely((unsigned long)matchn))
64873+ do_handle_create(matchn, old_dentry, mnt);
64874+
64875+ write_unlock(&gr_inode_lock);
64876+ preempt_enable();
64877+
64878+ return;
64879+}
64880+
64881+static int
64882+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
64883+ unsigned char **sum)
64884+{
64885+ struct acl_role_label *r;
64886+ struct role_allowed_ip *ipp;
64887+ struct role_transition *trans;
64888+ unsigned int i;
64889+ int found = 0;
64890+ u32 curr_ip = current->signal->curr_ip;
64891+
64892+ current->signal->saved_ip = curr_ip;
64893+
64894+ /* check transition table */
64895+
64896+ for (trans = current->role->transitions; trans; trans = trans->next) {
64897+ if (!strcmp(rolename, trans->rolename)) {
64898+ found = 1;
64899+ break;
64900+ }
64901+ }
64902+
64903+ if (!found)
64904+ return 0;
64905+
64906+ /* handle special roles that do not require authentication
64907+ and check ip */
64908+
64909+ FOR_EACH_ROLE_START(r)
64910+ if (!strcmp(rolename, r->rolename) &&
64911+ (r->roletype & GR_ROLE_SPECIAL)) {
64912+ found = 0;
64913+ if (r->allowed_ips != NULL) {
64914+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
64915+ if ((ntohl(curr_ip) & ipp->netmask) ==
64916+ (ntohl(ipp->addr) & ipp->netmask))
64917+ found = 1;
64918+ }
64919+ } else
64920+ found = 2;
64921+ if (!found)
64922+ return 0;
64923+
64924+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
64925+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
64926+ *salt = NULL;
64927+ *sum = NULL;
64928+ return 1;
64929+ }
64930+ }
64931+ FOR_EACH_ROLE_END(r)
64932+
64933+ for (i = 0; i < num_sprole_pws; i++) {
64934+ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
64935+ *salt = acl_special_roles[i]->salt;
64936+ *sum = acl_special_roles[i]->sum;
64937+ return 1;
64938+ }
64939+ }
64940+
64941+ return 0;
64942+}
64943+
64944+static void
64945+assign_special_role(char *rolename)
64946+{
64947+ struct acl_object_label *obj;
64948+ struct acl_role_label *r;
64949+ struct acl_role_label *assigned = NULL;
64950+ struct task_struct *tsk;
64951+ struct file *filp;
64952+
64953+ FOR_EACH_ROLE_START(r)
64954+ if (!strcmp(rolename, r->rolename) &&
64955+ (r->roletype & GR_ROLE_SPECIAL)) {
64956+ assigned = r;
64957+ break;
64958+ }
64959+ FOR_EACH_ROLE_END(r)
64960+
64961+ if (!assigned)
64962+ return;
64963+
64964+ read_lock(&tasklist_lock);
64965+ read_lock(&grsec_exec_file_lock);
64966+
64967+ tsk = current->real_parent;
64968+ if (tsk == NULL)
64969+ goto out_unlock;
64970+
64971+ filp = tsk->exec_file;
64972+ if (filp == NULL)
64973+ goto out_unlock;
64974+
64975+ tsk->is_writable = 0;
64976+
64977+ tsk->acl_sp_role = 1;
64978+ tsk->acl_role_id = ++acl_sp_role_value;
64979+ tsk->role = assigned;
64980+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
64981+
64982+ /* ignore additional mmap checks for processes that are writable
64983+ by the default ACL */
64984+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
64985+ if (unlikely(obj->mode & GR_WRITE))
64986+ tsk->is_writable = 1;
64987+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
64988+ if (unlikely(obj->mode & GR_WRITE))
64989+ tsk->is_writable = 1;
64990+
64991+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
64992+ 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));
64993+#endif
64994+
64995+out_unlock:
64996+ read_unlock(&grsec_exec_file_lock);
64997+ read_unlock(&tasklist_lock);
64998+ return;
64999+}
65000+
65001+int gr_check_secure_terminal(struct task_struct *task)
65002+{
65003+ struct task_struct *p, *p2, *p3;
65004+ struct files_struct *files;
65005+ struct fdtable *fdt;
65006+ struct file *our_file = NULL, *file;
65007+ int i;
65008+
65009+ if (task->signal->tty == NULL)
65010+ return 1;
65011+
65012+ files = get_files_struct(task);
65013+ if (files != NULL) {
65014+ rcu_read_lock();
65015+ fdt = files_fdtable(files);
65016+ for (i=0; i < fdt->max_fds; i++) {
65017+ file = fcheck_files(files, i);
65018+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
65019+ get_file(file);
65020+ our_file = file;
65021+ }
65022+ }
65023+ rcu_read_unlock();
65024+ put_files_struct(files);
65025+ }
65026+
65027+ if (our_file == NULL)
65028+ return 1;
65029+
65030+ read_lock(&tasklist_lock);
65031+ do_each_thread(p2, p) {
65032+ files = get_files_struct(p);
65033+ if (files == NULL ||
65034+ (p->signal && p->signal->tty == task->signal->tty)) {
65035+ if (files != NULL)
65036+ put_files_struct(files);
65037+ continue;
65038+ }
65039+ rcu_read_lock();
65040+ fdt = files_fdtable(files);
65041+ for (i=0; i < fdt->max_fds; i++) {
65042+ file = fcheck_files(files, i);
65043+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
65044+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
65045+ p3 = task;
65046+ while (task_pid_nr(p3) > 0) {
65047+ if (p3 == p)
65048+ break;
65049+ p3 = p3->real_parent;
65050+ }
65051+ if (p3 == p)
65052+ break;
65053+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
65054+ gr_handle_alertkill(p);
65055+ rcu_read_unlock();
65056+ put_files_struct(files);
65057+ read_unlock(&tasklist_lock);
65058+ fput(our_file);
65059+ return 0;
65060+ }
65061+ }
65062+ rcu_read_unlock();
65063+ put_files_struct(files);
65064+ } while_each_thread(p2, p);
65065+ read_unlock(&tasklist_lock);
65066+
65067+ fput(our_file);
65068+ return 1;
65069+}
65070+
65071+static int gr_rbac_disable(void *unused)
65072+{
65073+ pax_open_kernel();
65074+ gr_status &= ~GR_READY;
65075+ pax_close_kernel();
65076+
65077+ return 0;
65078+}
65079+
65080+ssize_t
65081+write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
65082+{
65083+ struct gr_arg_wrapper uwrap;
65084+ unsigned char *sprole_salt = NULL;
65085+ unsigned char *sprole_sum = NULL;
65086+ int error = 0;
65087+ int error2 = 0;
65088+ size_t req_count = 0;
65089+
65090+ mutex_lock(&gr_dev_mutex);
65091+
65092+ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
65093+ error = -EPERM;
65094+ goto out;
65095+ }
65096+
65097+#ifdef CONFIG_COMPAT
65098+ pax_open_kernel();
65099+ if (is_compat_task()) {
65100+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
65101+ copy_gr_arg = &copy_gr_arg_compat;
65102+ copy_acl_object_label = &copy_acl_object_label_compat;
65103+ copy_acl_subject_label = &copy_acl_subject_label_compat;
65104+ copy_acl_role_label = &copy_acl_role_label_compat;
65105+ copy_acl_ip_label = &copy_acl_ip_label_compat;
65106+ copy_role_allowed_ip = &copy_role_allowed_ip_compat;
65107+ copy_role_transition = &copy_role_transition_compat;
65108+ copy_sprole_pw = &copy_sprole_pw_compat;
65109+ copy_gr_hash_struct = &copy_gr_hash_struct_compat;
65110+ copy_pointer_from_array = &copy_pointer_from_array_compat;
65111+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
65112+ } else {
65113+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
65114+ copy_gr_arg = &copy_gr_arg_normal;
65115+ copy_acl_object_label = &copy_acl_object_label_normal;
65116+ copy_acl_subject_label = &copy_acl_subject_label_normal;
65117+ copy_acl_role_label = &copy_acl_role_label_normal;
65118+ copy_acl_ip_label = &copy_acl_ip_label_normal;
65119+ copy_role_allowed_ip = &copy_role_allowed_ip_normal;
65120+ copy_role_transition = &copy_role_transition_normal;
65121+ copy_sprole_pw = &copy_sprole_pw_normal;
65122+ copy_gr_hash_struct = &copy_gr_hash_struct_normal;
65123+ copy_pointer_from_array = &copy_pointer_from_array_normal;
65124+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
65125+ }
65126+ pax_close_kernel();
65127+#endif
65128+
65129+ req_count = get_gr_arg_wrapper_size();
65130+
65131+ if (count != req_count) {
65132+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
65133+ error = -EINVAL;
65134+ goto out;
65135+ }
65136+
65137+
65138+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
65139+ gr_auth_expires = 0;
65140+ gr_auth_attempts = 0;
65141+ }
65142+
65143+ error = copy_gr_arg_wrapper(buf, &uwrap);
65144+ if (error)
65145+ goto out;
65146+
65147+ error = copy_gr_arg(uwrap.arg, gr_usermode);
65148+ if (error)
65149+ goto out;
65150+
65151+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
65152+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
65153+ time_after(gr_auth_expires, get_seconds())) {
65154+ error = -EBUSY;
65155+ goto out;
65156+ }
65157+
65158+ /* if non-root trying to do anything other than use a special role,
65159+ do not attempt authentication, do not count towards authentication
65160+ locking
65161+ */
65162+
65163+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
65164+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
65165+ gr_is_global_nonroot(current_uid())) {
65166+ error = -EPERM;
65167+ goto out;
65168+ }
65169+
65170+ /* ensure pw and special role name are null terminated */
65171+
65172+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
65173+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
65174+
65175+ /* Okay.
65176+ * We have our enough of the argument structure..(we have yet
65177+ * to copy_from_user the tables themselves) . Copy the tables
65178+ * only if we need them, i.e. for loading operations. */
65179+
65180+ switch (gr_usermode->mode) {
65181+ case GR_STATUS:
65182+ if (gr_status & GR_READY) {
65183+ error = 1;
65184+ if (!gr_check_secure_terminal(current))
65185+ error = 3;
65186+ } else
65187+ error = 2;
65188+ goto out;
65189+ case GR_SHUTDOWN:
65190+ if ((gr_status & GR_READY)
65191+ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
65192+ stop_machine(gr_rbac_disable, NULL, NULL);
65193+ free_variables();
65194+ memset(gr_usermode, 0, sizeof (struct gr_arg));
65195+ memset(gr_system_salt, 0, GR_SALT_LEN);
65196+ memset(gr_system_sum, 0, GR_SHA_LEN);
65197+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
65198+ } else if (gr_status & GR_READY) {
65199+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
65200+ error = -EPERM;
65201+ } else {
65202+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
65203+ error = -EAGAIN;
65204+ }
65205+ break;
65206+ case GR_ENABLE:
65207+ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
65208+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
65209+ else {
65210+ if (gr_status & GR_READY)
65211+ error = -EAGAIN;
65212+ else
65213+ error = error2;
65214+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
65215+ }
65216+ break;
65217+ case GR_RELOAD:
65218+ if (!(gr_status & GR_READY)) {
65219+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
65220+ error = -EAGAIN;
65221+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
65222+ stop_machine(gr_rbac_disable, NULL, NULL);
65223+ free_variables();
65224+ error2 = gracl_init(gr_usermode);
65225+ if (!error2)
65226+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
65227+ else {
65228+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
65229+ error = error2;
65230+ }
65231+ } else {
65232+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
65233+ error = -EPERM;
65234+ }
65235+ break;
65236+ case GR_SEGVMOD:
65237+ if (unlikely(!(gr_status & GR_READY))) {
65238+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
65239+ error = -EAGAIN;
65240+ break;
65241+ }
65242+
65243+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
65244+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
65245+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
65246+ struct acl_subject_label *segvacl;
65247+ segvacl =
65248+ lookup_acl_subj_label(gr_usermode->segv_inode,
65249+ gr_usermode->segv_device,
65250+ current->role);
65251+ if (segvacl) {
65252+ segvacl->crashes = 0;
65253+ segvacl->expires = 0;
65254+ }
65255+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
65256+ gr_remove_uid(gr_usermode->segv_uid);
65257+ }
65258+ } else {
65259+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
65260+ error = -EPERM;
65261+ }
65262+ break;
65263+ case GR_SPROLE:
65264+ case GR_SPROLEPAM:
65265+ if (unlikely(!(gr_status & GR_READY))) {
65266+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
65267+ error = -EAGAIN;
65268+ break;
65269+ }
65270+
65271+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
65272+ current->role->expires = 0;
65273+ current->role->auth_attempts = 0;
65274+ }
65275+
65276+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
65277+ time_after(current->role->expires, get_seconds())) {
65278+ error = -EBUSY;
65279+ goto out;
65280+ }
65281+
65282+ if (lookup_special_role_auth
65283+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
65284+ && ((!sprole_salt && !sprole_sum)
65285+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
65286+ char *p = "";
65287+ assign_special_role(gr_usermode->sp_role);
65288+ read_lock(&tasklist_lock);
65289+ if (current->real_parent)
65290+ p = current->real_parent->role->rolename;
65291+ read_unlock(&tasklist_lock);
65292+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
65293+ p, acl_sp_role_value);
65294+ } else {
65295+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
65296+ error = -EPERM;
65297+ if(!(current->role->auth_attempts++))
65298+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
65299+
65300+ goto out;
65301+ }
65302+ break;
65303+ case GR_UNSPROLE:
65304+ if (unlikely(!(gr_status & GR_READY))) {
65305+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
65306+ error = -EAGAIN;
65307+ break;
65308+ }
65309+
65310+ if (current->role->roletype & GR_ROLE_SPECIAL) {
65311+ char *p = "";
65312+ int i = 0;
65313+
65314+ read_lock(&tasklist_lock);
65315+ if (current->real_parent) {
65316+ p = current->real_parent->role->rolename;
65317+ i = current->real_parent->acl_role_id;
65318+ }
65319+ read_unlock(&tasklist_lock);
65320+
65321+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
65322+ gr_set_acls(1);
65323+ } else {
65324+ error = -EPERM;
65325+ goto out;
65326+ }
65327+ break;
65328+ default:
65329+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
65330+ error = -EINVAL;
65331+ break;
65332+ }
65333+
65334+ if (error != -EPERM)
65335+ goto out;
65336+
65337+ if(!(gr_auth_attempts++))
65338+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
65339+
65340+ out:
65341+ mutex_unlock(&gr_dev_mutex);
65342+
65343+ if (!error)
65344+ error = req_count;
65345+
65346+ return error;
65347+}
65348+
65349+/* must be called with
65350+ rcu_read_lock();
65351+ read_lock(&tasklist_lock);
65352+ read_lock(&grsec_exec_file_lock);
65353+*/
65354+int gr_apply_subject_to_task(struct task_struct *task)
65355+{
65356+ struct acl_object_label *obj;
65357+ char *tmpname;
65358+ struct acl_subject_label *tmpsubj;
65359+ struct file *filp;
65360+ struct name_entry *nmatch;
65361+
65362+ filp = task->exec_file;
65363+ if (filp == NULL)
65364+ return 0;
65365+
65366+ /* the following is to apply the correct subject
65367+ on binaries running when the RBAC system
65368+ is enabled, when the binaries have been
65369+ replaced or deleted since their execution
65370+ -----
65371+ when the RBAC system starts, the inode/dev
65372+ from exec_file will be one the RBAC system
65373+ is unaware of. It only knows the inode/dev
65374+ of the present file on disk, or the absence
65375+ of it.
65376+ */
65377+ preempt_disable();
65378+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
65379+
65380+ nmatch = lookup_name_entry(tmpname);
65381+ preempt_enable();
65382+ tmpsubj = NULL;
65383+ if (nmatch) {
65384+ if (nmatch->deleted)
65385+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
65386+ else
65387+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
65388+ if (tmpsubj != NULL)
65389+ task->acl = tmpsubj;
65390+ }
65391+ if (tmpsubj == NULL)
65392+ task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
65393+ task->role);
65394+ if (task->acl) {
65395+ task->is_writable = 0;
65396+ /* ignore additional mmap checks for processes that are writable
65397+ by the default ACL */
65398+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
65399+ if (unlikely(obj->mode & GR_WRITE))
65400+ task->is_writable = 1;
65401+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
65402+ if (unlikely(obj->mode & GR_WRITE))
65403+ task->is_writable = 1;
65404+
65405+ gr_set_proc_res(task);
65406+
65407+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
65408+ 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);
65409+#endif
65410+ } else {
65411+ return 1;
65412+ }
65413+
65414+ return 0;
65415+}
65416+
65417+int
65418+gr_set_acls(const int type)
65419+{
65420+ struct task_struct *task, *task2;
65421+ struct acl_role_label *role = current->role;
65422+ __u16 acl_role_id = current->acl_role_id;
65423+ const struct cred *cred;
65424+ int ret;
65425+
65426+ rcu_read_lock();
65427+ read_lock(&tasklist_lock);
65428+ read_lock(&grsec_exec_file_lock);
65429+ do_each_thread(task2, task) {
65430+ /* check to see if we're called from the exit handler,
65431+ if so, only replace ACLs that have inherited the admin
65432+ ACL */
65433+
65434+ if (type && (task->role != role ||
65435+ task->acl_role_id != acl_role_id))
65436+ continue;
65437+
65438+ task->acl_role_id = 0;
65439+ task->acl_sp_role = 0;
65440+
65441+ if (task->exec_file) {
65442+ cred = __task_cred(task);
65443+ task->role = lookup_acl_role_label(task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
65444+ ret = gr_apply_subject_to_task(task);
65445+ if (ret) {
65446+ read_unlock(&grsec_exec_file_lock);
65447+ read_unlock(&tasklist_lock);
65448+ rcu_read_unlock();
65449+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
65450+ return ret;
65451+ }
65452+ } else {
65453+ // it's a kernel process
65454+ task->role = kernel_role;
65455+ task->acl = kernel_role->root_label;
65456+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
65457+ task->acl->mode &= ~GR_PROCFIND;
65458+#endif
65459+ }
65460+ } while_each_thread(task2, task);
65461+ read_unlock(&grsec_exec_file_lock);
65462+ read_unlock(&tasklist_lock);
65463+ rcu_read_unlock();
65464+
65465+ return 0;
65466+}
65467+
65468+#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
65469+static const unsigned long res_learn_bumps[GR_NLIMITS] = {
65470+ [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
65471+ [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
65472+ [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
65473+ [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
65474+ [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
65475+ [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
65476+ [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
65477+ [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
65478+ [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
65479+ [RLIMIT_AS] = GR_RLIM_AS_BUMP,
65480+ [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
65481+ [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
65482+ [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
65483+ [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
65484+ [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
65485+ [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
65486+};
65487+
65488+void
65489+gr_learn_resource(const struct task_struct *task,
65490+ const int res, const unsigned long wanted, const int gt)
65491+{
65492+ struct acl_subject_label *acl;
65493+ const struct cred *cred;
65494+
65495+ if (unlikely((gr_status & GR_READY) &&
65496+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
65497+ goto skip_reslog;
65498+
65499+ gr_log_resource(task, res, wanted, gt);
65500+skip_reslog:
65501+
65502+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
65503+ return;
65504+
65505+ acl = task->acl;
65506+
65507+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
65508+ !(acl->resmask & (1U << (unsigned short) res))))
65509+ return;
65510+
65511+ if (wanted >= acl->res[res].rlim_cur) {
65512+ unsigned long res_add;
65513+
65514+ res_add = wanted + res_learn_bumps[res];
65515+
65516+ acl->res[res].rlim_cur = res_add;
65517+
65518+ if (wanted > acl->res[res].rlim_max)
65519+ acl->res[res].rlim_max = res_add;
65520+
65521+ /* only log the subject filename, since resource logging is supported for
65522+ single-subject learning only */
65523+ rcu_read_lock();
65524+ cred = __task_cred(task);
65525+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
65526+ task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
65527+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
65528+ "", (unsigned long) res, &task->signal->saved_ip);
65529+ rcu_read_unlock();
65530+ }
65531+
65532+ return;
65533+}
65534+EXPORT_SYMBOL(gr_learn_resource);
65535+#endif
65536+
65537+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
65538+void
65539+pax_set_initial_flags(struct linux_binprm *bprm)
65540+{
65541+ struct task_struct *task = current;
65542+ struct acl_subject_label *proc;
65543+ unsigned long flags;
65544+
65545+ if (unlikely(!(gr_status & GR_READY)))
65546+ return;
65547+
65548+ flags = pax_get_flags(task);
65549+
65550+ proc = task->acl;
65551+
65552+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
65553+ flags &= ~MF_PAX_PAGEEXEC;
65554+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
65555+ flags &= ~MF_PAX_SEGMEXEC;
65556+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
65557+ flags &= ~MF_PAX_RANDMMAP;
65558+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
65559+ flags &= ~MF_PAX_EMUTRAMP;
65560+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
65561+ flags &= ~MF_PAX_MPROTECT;
65562+
65563+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
65564+ flags |= MF_PAX_PAGEEXEC;
65565+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
65566+ flags |= MF_PAX_SEGMEXEC;
65567+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
65568+ flags |= MF_PAX_RANDMMAP;
65569+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
65570+ flags |= MF_PAX_EMUTRAMP;
65571+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
65572+ flags |= MF_PAX_MPROTECT;
65573+
65574+ pax_set_flags(task, flags);
65575+
65576+ return;
65577+}
65578+#endif
65579+
65580+int
65581+gr_handle_proc_ptrace(struct task_struct *task)
65582+{
65583+ struct file *filp;
65584+ struct task_struct *tmp = task;
65585+ struct task_struct *curtemp = current;
65586+ __u32 retmode;
65587+
65588+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
65589+ if (unlikely(!(gr_status & GR_READY)))
65590+ return 0;
65591+#endif
65592+
65593+ read_lock(&tasklist_lock);
65594+ read_lock(&grsec_exec_file_lock);
65595+ filp = task->exec_file;
65596+
65597+ while (task_pid_nr(tmp) > 0) {
65598+ if (tmp == curtemp)
65599+ break;
65600+ tmp = tmp->real_parent;
65601+ }
65602+
65603+ if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
65604+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
65605+ read_unlock(&grsec_exec_file_lock);
65606+ read_unlock(&tasklist_lock);
65607+ return 1;
65608+ }
65609+
65610+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
65611+ if (!(gr_status & GR_READY)) {
65612+ read_unlock(&grsec_exec_file_lock);
65613+ read_unlock(&tasklist_lock);
65614+ return 0;
65615+ }
65616+#endif
65617+
65618+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
65619+ read_unlock(&grsec_exec_file_lock);
65620+ read_unlock(&tasklist_lock);
65621+
65622+ if (retmode & GR_NOPTRACE)
65623+ return 1;
65624+
65625+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
65626+ && (current->acl != task->acl || (current->acl != current->role->root_label
65627+ && task_pid_nr(current) != task_pid_nr(task))))
65628+ return 1;
65629+
65630+ return 0;
65631+}
65632+
65633+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
65634+{
65635+ if (unlikely(!(gr_status & GR_READY)))
65636+ return;
65637+
65638+ if (!(current->role->roletype & GR_ROLE_GOD))
65639+ return;
65640+
65641+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
65642+ p->role->rolename, gr_task_roletype_to_char(p),
65643+ p->acl->filename);
65644+}
65645+
65646+int
65647+gr_handle_ptrace(struct task_struct *task, const long request)
65648+{
65649+ struct task_struct *tmp = task;
65650+ struct task_struct *curtemp = current;
65651+ __u32 retmode;
65652+
65653+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
65654+ if (unlikely(!(gr_status & GR_READY)))
65655+ return 0;
65656+#endif
65657+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
65658+ read_lock(&tasklist_lock);
65659+ while (task_pid_nr(tmp) > 0) {
65660+ if (tmp == curtemp)
65661+ break;
65662+ tmp = tmp->real_parent;
65663+ }
65664+
65665+ if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
65666+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
65667+ read_unlock(&tasklist_lock);
65668+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
65669+ return 1;
65670+ }
65671+ read_unlock(&tasklist_lock);
65672+ }
65673+
65674+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
65675+ if (!(gr_status & GR_READY))
65676+ return 0;
65677+#endif
65678+
65679+ read_lock(&grsec_exec_file_lock);
65680+ if (unlikely(!task->exec_file)) {
65681+ read_unlock(&grsec_exec_file_lock);
65682+ return 0;
65683+ }
65684+
65685+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
65686+ read_unlock(&grsec_exec_file_lock);
65687+
65688+ if (retmode & GR_NOPTRACE) {
65689+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
65690+ return 1;
65691+ }
65692+
65693+ if (retmode & GR_PTRACERD) {
65694+ switch (request) {
65695+ case PTRACE_SEIZE:
65696+ case PTRACE_POKETEXT:
65697+ case PTRACE_POKEDATA:
65698+ case PTRACE_POKEUSR:
65699+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
65700+ case PTRACE_SETREGS:
65701+ case PTRACE_SETFPREGS:
65702+#endif
65703+#ifdef CONFIG_X86
65704+ case PTRACE_SETFPXREGS:
65705+#endif
65706+#ifdef CONFIG_ALTIVEC
65707+ case PTRACE_SETVRREGS:
65708+#endif
65709+ return 1;
65710+ default:
65711+ return 0;
65712+ }
65713+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
65714+ !(current->role->roletype & GR_ROLE_GOD) &&
65715+ (current->acl != task->acl)) {
65716+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
65717+ return 1;
65718+ }
65719+
65720+ return 0;
65721+}
65722+
65723+static int is_writable_mmap(const struct file *filp)
65724+{
65725+ struct task_struct *task = current;
65726+ struct acl_object_label *obj, *obj2;
65727+
65728+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
65729+ !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))) {
65730+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
65731+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
65732+ task->role->root_label);
65733+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
65734+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
65735+ return 1;
65736+ }
65737+ }
65738+ return 0;
65739+}
65740+
65741+int
65742+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
65743+{
65744+ __u32 mode;
65745+
65746+ if (unlikely(!file || !(prot & PROT_EXEC)))
65747+ return 1;
65748+
65749+ if (is_writable_mmap(file))
65750+ return 0;
65751+
65752+ mode =
65753+ gr_search_file(file->f_path.dentry,
65754+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
65755+ file->f_path.mnt);
65756+
65757+ if (!gr_tpe_allow(file))
65758+ return 0;
65759+
65760+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
65761+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
65762+ return 0;
65763+ } else if (unlikely(!(mode & GR_EXEC))) {
65764+ return 0;
65765+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
65766+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
65767+ return 1;
65768+ }
65769+
65770+ return 1;
65771+}
65772+
65773+int
65774+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
65775+{
65776+ __u32 mode;
65777+
65778+ if (unlikely(!file || !(prot & PROT_EXEC)))
65779+ return 1;
65780+
65781+ if (is_writable_mmap(file))
65782+ return 0;
65783+
65784+ mode =
65785+ gr_search_file(file->f_path.dentry,
65786+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
65787+ file->f_path.mnt);
65788+
65789+ if (!gr_tpe_allow(file))
65790+ return 0;
65791+
65792+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
65793+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
65794+ return 0;
65795+ } else if (unlikely(!(mode & GR_EXEC))) {
65796+ return 0;
65797+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
65798+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
65799+ return 1;
65800+ }
65801+
65802+ return 1;
65803+}
65804+
65805+void
65806+gr_acl_handle_psacct(struct task_struct *task, const long code)
65807+{
65808+ unsigned long runtime;
65809+ unsigned long cputime;
65810+ unsigned int wday, cday;
65811+ __u8 whr, chr;
65812+ __u8 wmin, cmin;
65813+ __u8 wsec, csec;
65814+ struct timespec timeval;
65815+
65816+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
65817+ !(task->acl->mode & GR_PROCACCT)))
65818+ return;
65819+
65820+ do_posix_clock_monotonic_gettime(&timeval);
65821+ runtime = timeval.tv_sec - task->start_time.tv_sec;
65822+ wday = runtime / (3600 * 24);
65823+ runtime -= wday * (3600 * 24);
65824+ whr = runtime / 3600;
65825+ runtime -= whr * 3600;
65826+ wmin = runtime / 60;
65827+ runtime -= wmin * 60;
65828+ wsec = runtime;
65829+
65830+ cputime = (task->utime + task->stime) / HZ;
65831+ cday = cputime / (3600 * 24);
65832+ cputime -= cday * (3600 * 24);
65833+ chr = cputime / 3600;
65834+ cputime -= chr * 3600;
65835+ cmin = cputime / 60;
65836+ cputime -= cmin * 60;
65837+ csec = cputime;
65838+
65839+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
65840+
65841+ return;
65842+}
65843+
65844+void gr_set_kernel_label(struct task_struct *task)
65845+{
65846+ if (gr_status & GR_READY) {
65847+ task->role = kernel_role;
65848+ task->acl = kernel_role->root_label;
65849+ }
65850+ return;
65851+}
65852+
65853+#ifdef CONFIG_TASKSTATS
65854+int gr_is_taskstats_denied(int pid)
65855+{
65856+ struct task_struct *task;
65857+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65858+ const struct cred *cred;
65859+#endif
65860+ int ret = 0;
65861+
65862+ /* restrict taskstats viewing to un-chrooted root users
65863+ who have the 'view' subject flag if the RBAC system is enabled
65864+ */
65865+
65866+ rcu_read_lock();
65867+ read_lock(&tasklist_lock);
65868+ task = find_task_by_vpid(pid);
65869+ if (task) {
65870+#ifdef CONFIG_GRKERNSEC_CHROOT
65871+ if (proc_is_chrooted(task))
65872+ ret = -EACCES;
65873+#endif
65874+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65875+ cred = __task_cred(task);
65876+#ifdef CONFIG_GRKERNSEC_PROC_USER
65877+ if (gr_is_global_nonroot(cred->uid))
65878+ ret = -EACCES;
65879+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65880+ if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
65881+ ret = -EACCES;
65882+#endif
65883+#endif
65884+ if (gr_status & GR_READY) {
65885+ if (!(task->acl->mode & GR_VIEW))
65886+ ret = -EACCES;
65887+ }
65888+ } else
65889+ ret = -ENOENT;
65890+
65891+ read_unlock(&tasklist_lock);
65892+ rcu_read_unlock();
65893+
65894+ return ret;
65895+}
65896+#endif
65897+
65898+/* AUXV entries are filled via a descendant of search_binary_handler
65899+ after we've already applied the subject for the target
65900+*/
65901+int gr_acl_enable_at_secure(void)
65902+{
65903+ if (unlikely(!(gr_status & GR_READY)))
65904+ return 0;
65905+
65906+ if (current->acl->mode & GR_ATSECURE)
65907+ return 1;
65908+
65909+ return 0;
65910+}
65911+
65912+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
65913+{
65914+ struct task_struct *task = current;
65915+ struct dentry *dentry = file->f_path.dentry;
65916+ struct vfsmount *mnt = file->f_path.mnt;
65917+ struct acl_object_label *obj, *tmp;
65918+ struct acl_subject_label *subj;
65919+ unsigned int bufsize;
65920+ int is_not_root;
65921+ char *path;
65922+ dev_t dev = __get_dev(dentry);
65923+
65924+ if (unlikely(!(gr_status & GR_READY)))
65925+ return 1;
65926+
65927+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
65928+ return 1;
65929+
65930+ /* ignore Eric Biederman */
65931+ if (IS_PRIVATE(dentry->d_inode))
65932+ return 1;
65933+
65934+ subj = task->acl;
65935+ read_lock(&gr_inode_lock);
65936+ do {
65937+ obj = lookup_acl_obj_label(ino, dev, subj);
65938+ if (obj != NULL) {
65939+ read_unlock(&gr_inode_lock);
65940+ return (obj->mode & GR_FIND) ? 1 : 0;
65941+ }
65942+ } while ((subj = subj->parent_subject));
65943+ read_unlock(&gr_inode_lock);
65944+
65945+ /* this is purely an optimization since we're looking for an object
65946+ for the directory we're doing a readdir on
65947+ if it's possible for any globbed object to match the entry we're
65948+ filling into the directory, then the object we find here will be
65949+ an anchor point with attached globbed objects
65950+ */
65951+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
65952+ if (obj->globbed == NULL)
65953+ return (obj->mode & GR_FIND) ? 1 : 0;
65954+
65955+ is_not_root = ((obj->filename[0] == '/') &&
65956+ (obj->filename[1] == '\0')) ? 0 : 1;
65957+ bufsize = PAGE_SIZE - namelen - is_not_root;
65958+
65959+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
65960+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
65961+ return 1;
65962+
65963+ preempt_disable();
65964+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
65965+ bufsize);
65966+
65967+ bufsize = strlen(path);
65968+
65969+ /* if base is "/", don't append an additional slash */
65970+ if (is_not_root)
65971+ *(path + bufsize) = '/';
65972+ memcpy(path + bufsize + is_not_root, name, namelen);
65973+ *(path + bufsize + namelen + is_not_root) = '\0';
65974+
65975+ tmp = obj->globbed;
65976+ while (tmp) {
65977+ if (!glob_match(tmp->filename, path)) {
65978+ preempt_enable();
65979+ return (tmp->mode & GR_FIND) ? 1 : 0;
65980+ }
65981+ tmp = tmp->next;
65982+ }
65983+ preempt_enable();
65984+ return (obj->mode & GR_FIND) ? 1 : 0;
65985+}
65986+
65987+void gr_put_exec_file(struct task_struct *task)
65988+{
65989+ struct file *filp;
65990+
65991+ write_lock(&grsec_exec_file_lock);
65992+ filp = task->exec_file;
65993+ task->exec_file = NULL;
65994+ write_unlock(&grsec_exec_file_lock);
65995+
65996+ if (filp)
65997+ fput(filp);
65998+
65999+ return;
66000+}
66001+
66002+
66003+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
66004+EXPORT_SYMBOL(gr_acl_is_enabled);
66005+#endif
66006+EXPORT_SYMBOL(gr_set_kernel_label);
66007+#ifdef CONFIG_SECURITY
66008+EXPORT_SYMBOL(gr_check_user_change);
66009+EXPORT_SYMBOL(gr_check_group_change);
66010+#endif
66011+
66012diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
66013new file mode 100644
66014index 0000000..34fefda
66015--- /dev/null
66016+++ b/grsecurity/gracl_alloc.c
66017@@ -0,0 +1,105 @@
66018+#include <linux/kernel.h>
66019+#include <linux/mm.h>
66020+#include <linux/slab.h>
66021+#include <linux/vmalloc.h>
66022+#include <linux/gracl.h>
66023+#include <linux/grsecurity.h>
66024+
66025+static unsigned long alloc_stack_next = 1;
66026+static unsigned long alloc_stack_size = 1;
66027+static void **alloc_stack;
66028+
66029+static __inline__ int
66030+alloc_pop(void)
66031+{
66032+ if (alloc_stack_next == 1)
66033+ return 0;
66034+
66035+ kfree(alloc_stack[alloc_stack_next - 2]);
66036+
66037+ alloc_stack_next--;
66038+
66039+ return 1;
66040+}
66041+
66042+static __inline__ int
66043+alloc_push(void *buf)
66044+{
66045+ if (alloc_stack_next >= alloc_stack_size)
66046+ return 1;
66047+
66048+ alloc_stack[alloc_stack_next - 1] = buf;
66049+
66050+ alloc_stack_next++;
66051+
66052+ return 0;
66053+}
66054+
66055+void *
66056+acl_alloc(unsigned long len)
66057+{
66058+ void *ret = NULL;
66059+
66060+ if (!len || len > PAGE_SIZE)
66061+ goto out;
66062+
66063+ ret = kmalloc(len, GFP_KERNEL);
66064+
66065+ if (ret) {
66066+ if (alloc_push(ret)) {
66067+ kfree(ret);
66068+ ret = NULL;
66069+ }
66070+ }
66071+
66072+out:
66073+ return ret;
66074+}
66075+
66076+void *
66077+acl_alloc_num(unsigned long num, unsigned long len)
66078+{
66079+ if (!len || (num > (PAGE_SIZE / len)))
66080+ return NULL;
66081+
66082+ return acl_alloc(num * len);
66083+}
66084+
66085+void
66086+acl_free_all(void)
66087+{
66088+ if (gr_acl_is_enabled() || !alloc_stack)
66089+ return;
66090+
66091+ while (alloc_pop()) ;
66092+
66093+ if (alloc_stack) {
66094+ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
66095+ kfree(alloc_stack);
66096+ else
66097+ vfree(alloc_stack);
66098+ }
66099+
66100+ alloc_stack = NULL;
66101+ alloc_stack_size = 1;
66102+ alloc_stack_next = 1;
66103+
66104+ return;
66105+}
66106+
66107+int
66108+acl_alloc_stack_init(unsigned long size)
66109+{
66110+ if ((size * sizeof (void *)) <= PAGE_SIZE)
66111+ alloc_stack =
66112+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
66113+ else
66114+ alloc_stack = (void **) vmalloc(size * sizeof (void *));
66115+
66116+ alloc_stack_size = size;
66117+
66118+ if (!alloc_stack)
66119+ return 0;
66120+ else
66121+ return 1;
66122+}
66123diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
66124new file mode 100644
66125index 0000000..bdd51ea
66126--- /dev/null
66127+++ b/grsecurity/gracl_cap.c
66128@@ -0,0 +1,110 @@
66129+#include <linux/kernel.h>
66130+#include <linux/module.h>
66131+#include <linux/sched.h>
66132+#include <linux/gracl.h>
66133+#include <linux/grsecurity.h>
66134+#include <linux/grinternal.h>
66135+
66136+extern const char *captab_log[];
66137+extern int captab_log_entries;
66138+
66139+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
66140+{
66141+ struct acl_subject_label *curracl;
66142+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
66143+ kernel_cap_t cap_audit = __cap_empty_set;
66144+
66145+ if (!gr_acl_is_enabled())
66146+ return 1;
66147+
66148+ curracl = task->acl;
66149+
66150+ cap_drop = curracl->cap_lower;
66151+ cap_mask = curracl->cap_mask;
66152+ cap_audit = curracl->cap_invert_audit;
66153+
66154+ while ((curracl = curracl->parent_subject)) {
66155+ /* if the cap isn't specified in the current computed mask but is specified in the
66156+ current level subject, and is lowered in the current level subject, then add
66157+ it to the set of dropped capabilities
66158+ otherwise, add the current level subject's mask to the current computed mask
66159+ */
66160+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
66161+ cap_raise(cap_mask, cap);
66162+ if (cap_raised(curracl->cap_lower, cap))
66163+ cap_raise(cap_drop, cap);
66164+ if (cap_raised(curracl->cap_invert_audit, cap))
66165+ cap_raise(cap_audit, cap);
66166+ }
66167+ }
66168+
66169+ if (!cap_raised(cap_drop, cap)) {
66170+ if (cap_raised(cap_audit, cap))
66171+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
66172+ return 1;
66173+ }
66174+
66175+ curracl = task->acl;
66176+
66177+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
66178+ && cap_raised(cred->cap_effective, cap)) {
66179+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
66180+ task->role->roletype, GR_GLOBAL_UID(cred->uid),
66181+ GR_GLOBAL_GID(cred->gid), task->exec_file ?
66182+ gr_to_filename(task->exec_file->f_path.dentry,
66183+ task->exec_file->f_path.mnt) : curracl->filename,
66184+ curracl->filename, 0UL,
66185+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
66186+ return 1;
66187+ }
66188+
66189+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
66190+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
66191+
66192+ return 0;
66193+}
66194+
66195+int
66196+gr_acl_is_capable(const int cap)
66197+{
66198+ return gr_task_acl_is_capable(current, current_cred(), cap);
66199+}
66200+
66201+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
66202+{
66203+ struct acl_subject_label *curracl;
66204+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
66205+
66206+ if (!gr_acl_is_enabled())
66207+ return 1;
66208+
66209+ curracl = task->acl;
66210+
66211+ cap_drop = curracl->cap_lower;
66212+ cap_mask = curracl->cap_mask;
66213+
66214+ while ((curracl = curracl->parent_subject)) {
66215+ /* if the cap isn't specified in the current computed mask but is specified in the
66216+ current level subject, and is lowered in the current level subject, then add
66217+ it to the set of dropped capabilities
66218+ otherwise, add the current level subject's mask to the current computed mask
66219+ */
66220+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
66221+ cap_raise(cap_mask, cap);
66222+ if (cap_raised(curracl->cap_lower, cap))
66223+ cap_raise(cap_drop, cap);
66224+ }
66225+ }
66226+
66227+ if (!cap_raised(cap_drop, cap))
66228+ return 1;
66229+
66230+ return 0;
66231+}
66232+
66233+int
66234+gr_acl_is_capable_nolog(const int cap)
66235+{
66236+ return gr_task_acl_is_capable_nolog(current, cap);
66237+}
66238+
66239diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
66240new file mode 100644
66241index 0000000..a43dd06
66242--- /dev/null
66243+++ b/grsecurity/gracl_compat.c
66244@@ -0,0 +1,269 @@
66245+#include <linux/kernel.h>
66246+#include <linux/gracl.h>
66247+#include <linux/compat.h>
66248+#include <linux/gracl_compat.h>
66249+
66250+#include <asm/uaccess.h>
66251+
66252+int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
66253+{
66254+ struct gr_arg_wrapper_compat uwrapcompat;
66255+
66256+ if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
66257+ return -EFAULT;
66258+
66259+ if ((uwrapcompat.version != GRSECURITY_VERSION) ||
66260+ (uwrapcompat.size != sizeof(struct gr_arg_compat)))
66261+ return -EINVAL;
66262+
66263+ uwrap->arg = compat_ptr(uwrapcompat.arg);
66264+ uwrap->version = uwrapcompat.version;
66265+ uwrap->size = sizeof(struct gr_arg);
66266+
66267+ return 0;
66268+}
66269+
66270+int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
66271+{
66272+ struct gr_arg_compat argcompat;
66273+
66274+ if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
66275+ return -EFAULT;
66276+
66277+ arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
66278+ arg->role_db.num_pointers = argcompat.role_db.num_pointers;
66279+ arg->role_db.num_roles = argcompat.role_db.num_roles;
66280+ arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
66281+ arg->role_db.num_subjects = argcompat.role_db.num_subjects;
66282+ arg->role_db.num_objects = argcompat.role_db.num_objects;
66283+
66284+ memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
66285+ memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
66286+ memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
66287+ memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
66288+ arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
66289+ arg->segv_device = argcompat.segv_device;
66290+ arg->segv_inode = argcompat.segv_inode;
66291+ arg->segv_uid = argcompat.segv_uid;
66292+ arg->num_sprole_pws = argcompat.num_sprole_pws;
66293+ arg->mode = argcompat.mode;
66294+
66295+ return 0;
66296+}
66297+
66298+int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
66299+{
66300+ struct acl_object_label_compat objcompat;
66301+
66302+ if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
66303+ return -EFAULT;
66304+
66305+ obj->filename = compat_ptr(objcompat.filename);
66306+ obj->inode = objcompat.inode;
66307+ obj->device = objcompat.device;
66308+ obj->mode = objcompat.mode;
66309+
66310+ obj->nested = compat_ptr(objcompat.nested);
66311+ obj->globbed = compat_ptr(objcompat.globbed);
66312+
66313+ obj->prev = compat_ptr(objcompat.prev);
66314+ obj->next = compat_ptr(objcompat.next);
66315+
66316+ return 0;
66317+}
66318+
66319+int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
66320+{
66321+ unsigned int i;
66322+ struct acl_subject_label_compat subjcompat;
66323+
66324+ if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
66325+ return -EFAULT;
66326+
66327+ subj->filename = compat_ptr(subjcompat.filename);
66328+ subj->inode = subjcompat.inode;
66329+ subj->device = subjcompat.device;
66330+ subj->mode = subjcompat.mode;
66331+ subj->cap_mask = subjcompat.cap_mask;
66332+ subj->cap_lower = subjcompat.cap_lower;
66333+ subj->cap_invert_audit = subjcompat.cap_invert_audit;
66334+
66335+ for (i = 0; i < GR_NLIMITS; i++) {
66336+ if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
66337+ subj->res[i].rlim_cur = RLIM_INFINITY;
66338+ else
66339+ subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
66340+ if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
66341+ subj->res[i].rlim_max = RLIM_INFINITY;
66342+ else
66343+ subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
66344+ }
66345+ subj->resmask = subjcompat.resmask;
66346+
66347+ subj->user_trans_type = subjcompat.user_trans_type;
66348+ subj->group_trans_type = subjcompat.group_trans_type;
66349+ subj->user_transitions = compat_ptr(subjcompat.user_transitions);
66350+ subj->group_transitions = compat_ptr(subjcompat.group_transitions);
66351+ subj->user_trans_num = subjcompat.user_trans_num;
66352+ subj->group_trans_num = subjcompat.group_trans_num;
66353+
66354+ memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
66355+ memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
66356+ subj->ip_type = subjcompat.ip_type;
66357+ subj->ips = compat_ptr(subjcompat.ips);
66358+ subj->ip_num = subjcompat.ip_num;
66359+ subj->inaddr_any_override = subjcompat.inaddr_any_override;
66360+
66361+ subj->crashes = subjcompat.crashes;
66362+ subj->expires = subjcompat.expires;
66363+
66364+ subj->parent_subject = compat_ptr(subjcompat.parent_subject);
66365+ subj->hash = compat_ptr(subjcompat.hash);
66366+ subj->prev = compat_ptr(subjcompat.prev);
66367+ subj->next = compat_ptr(subjcompat.next);
66368+
66369+ subj->obj_hash = compat_ptr(subjcompat.obj_hash);
66370+ subj->obj_hash_size = subjcompat.obj_hash_size;
66371+ subj->pax_flags = subjcompat.pax_flags;
66372+
66373+ return 0;
66374+}
66375+
66376+int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
66377+{
66378+ struct acl_role_label_compat rolecompat;
66379+
66380+ if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
66381+ return -EFAULT;
66382+
66383+ role->rolename = compat_ptr(rolecompat.rolename);
66384+ role->uidgid = rolecompat.uidgid;
66385+ role->roletype = rolecompat.roletype;
66386+
66387+ role->auth_attempts = rolecompat.auth_attempts;
66388+ role->expires = rolecompat.expires;
66389+
66390+ role->root_label = compat_ptr(rolecompat.root_label);
66391+ role->hash = compat_ptr(rolecompat.hash);
66392+
66393+ role->prev = compat_ptr(rolecompat.prev);
66394+ role->next = compat_ptr(rolecompat.next);
66395+
66396+ role->transitions = compat_ptr(rolecompat.transitions);
66397+ role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
66398+ role->domain_children = compat_ptr(rolecompat.domain_children);
66399+ role->domain_child_num = rolecompat.domain_child_num;
66400+
66401+ role->umask = rolecompat.umask;
66402+
66403+ role->subj_hash = compat_ptr(rolecompat.subj_hash);
66404+ role->subj_hash_size = rolecompat.subj_hash_size;
66405+
66406+ return 0;
66407+}
66408+
66409+int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
66410+{
66411+ struct role_allowed_ip_compat roleip_compat;
66412+
66413+ if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
66414+ return -EFAULT;
66415+
66416+ roleip->addr = roleip_compat.addr;
66417+ roleip->netmask = roleip_compat.netmask;
66418+
66419+ roleip->prev = compat_ptr(roleip_compat.prev);
66420+ roleip->next = compat_ptr(roleip_compat.next);
66421+
66422+ return 0;
66423+}
66424+
66425+int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
66426+{
66427+ struct role_transition_compat trans_compat;
66428+
66429+ if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
66430+ return -EFAULT;
66431+
66432+ trans->rolename = compat_ptr(trans_compat.rolename);
66433+
66434+ trans->prev = compat_ptr(trans_compat.prev);
66435+ trans->next = compat_ptr(trans_compat.next);
66436+
66437+ return 0;
66438+
66439+}
66440+
66441+int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
66442+{
66443+ struct gr_hash_struct_compat hash_compat;
66444+
66445+ if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
66446+ return -EFAULT;
66447+
66448+ hash->table = compat_ptr(hash_compat.table);
66449+ hash->nametable = compat_ptr(hash_compat.nametable);
66450+ hash->first = compat_ptr(hash_compat.first);
66451+
66452+ hash->table_size = hash_compat.table_size;
66453+ hash->used_size = hash_compat.used_size;
66454+
66455+ hash->type = hash_compat.type;
66456+
66457+ return 0;
66458+}
66459+
66460+int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
66461+{
66462+ compat_uptr_t ptrcompat;
66463+
66464+ if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
66465+ return -EFAULT;
66466+
66467+ *(void **)ptr = compat_ptr(ptrcompat);
66468+
66469+ return 0;
66470+}
66471+
66472+int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
66473+{
66474+ struct acl_ip_label_compat ip_compat;
66475+
66476+ if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
66477+ return -EFAULT;
66478+
66479+ ip->iface = compat_ptr(ip_compat.iface);
66480+ ip->addr = ip_compat.addr;
66481+ ip->netmask = ip_compat.netmask;
66482+ ip->low = ip_compat.low;
66483+ ip->high = ip_compat.high;
66484+ ip->mode = ip_compat.mode;
66485+ ip->type = ip_compat.type;
66486+
66487+ memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
66488+
66489+ ip->prev = compat_ptr(ip_compat.prev);
66490+ ip->next = compat_ptr(ip_compat.next);
66491+
66492+ return 0;
66493+}
66494+
66495+int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
66496+{
66497+ struct sprole_pw_compat pw_compat;
66498+
66499+ if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
66500+ return -EFAULT;
66501+
66502+ pw->rolename = compat_ptr(pw_compat.rolename);
66503+ memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
66504+ memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
66505+
66506+ return 0;
66507+}
66508+
66509+size_t get_gr_arg_wrapper_size_compat(void)
66510+{
66511+ return sizeof(struct gr_arg_wrapper_compat);
66512+}
66513+
66514diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
66515new file mode 100644
66516index 0000000..a340c17
66517--- /dev/null
66518+++ b/grsecurity/gracl_fs.c
66519@@ -0,0 +1,431 @@
66520+#include <linux/kernel.h>
66521+#include <linux/sched.h>
66522+#include <linux/types.h>
66523+#include <linux/fs.h>
66524+#include <linux/file.h>
66525+#include <linux/stat.h>
66526+#include <linux/grsecurity.h>
66527+#include <linux/grinternal.h>
66528+#include <linux/gracl.h>
66529+
66530+umode_t
66531+gr_acl_umask(void)
66532+{
66533+ if (unlikely(!gr_acl_is_enabled()))
66534+ return 0;
66535+
66536+ return current->role->umask;
66537+}
66538+
66539+__u32
66540+gr_acl_handle_hidden_file(const struct dentry * dentry,
66541+ const struct vfsmount * mnt)
66542+{
66543+ __u32 mode;
66544+
66545+ if (unlikely(!dentry->d_inode))
66546+ return GR_FIND;
66547+
66548+ mode =
66549+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
66550+
66551+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
66552+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
66553+ return mode;
66554+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
66555+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
66556+ return 0;
66557+ } else if (unlikely(!(mode & GR_FIND)))
66558+ return 0;
66559+
66560+ return GR_FIND;
66561+}
66562+
66563+__u32
66564+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
66565+ int acc_mode)
66566+{
66567+ __u32 reqmode = GR_FIND;
66568+ __u32 mode;
66569+
66570+ if (unlikely(!dentry->d_inode))
66571+ return reqmode;
66572+
66573+ if (acc_mode & MAY_APPEND)
66574+ reqmode |= GR_APPEND;
66575+ else if (acc_mode & MAY_WRITE)
66576+ reqmode |= GR_WRITE;
66577+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
66578+ reqmode |= GR_READ;
66579+
66580+ mode =
66581+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
66582+ mnt);
66583+
66584+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
66585+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
66586+ reqmode & GR_READ ? " reading" : "",
66587+ reqmode & GR_WRITE ? " writing" : reqmode &
66588+ GR_APPEND ? " appending" : "");
66589+ return reqmode;
66590+ } else
66591+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
66592+ {
66593+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
66594+ reqmode & GR_READ ? " reading" : "",
66595+ reqmode & GR_WRITE ? " writing" : reqmode &
66596+ GR_APPEND ? " appending" : "");
66597+ return 0;
66598+ } else if (unlikely((mode & reqmode) != reqmode))
66599+ return 0;
66600+
66601+ return reqmode;
66602+}
66603+
66604+__u32
66605+gr_acl_handle_creat(const struct dentry * dentry,
66606+ const struct dentry * p_dentry,
66607+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
66608+ const int imode)
66609+{
66610+ __u32 reqmode = GR_WRITE | GR_CREATE;
66611+ __u32 mode;
66612+
66613+ if (acc_mode & MAY_APPEND)
66614+ reqmode |= GR_APPEND;
66615+ // if a directory was required or the directory already exists, then
66616+ // don't count this open as a read
66617+ if ((acc_mode & MAY_READ) &&
66618+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
66619+ reqmode |= GR_READ;
66620+ if ((open_flags & O_CREAT) &&
66621+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
66622+ reqmode |= GR_SETID;
66623+
66624+ mode =
66625+ gr_check_create(dentry, p_dentry, p_mnt,
66626+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
66627+
66628+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
66629+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
66630+ reqmode & GR_READ ? " reading" : "",
66631+ reqmode & GR_WRITE ? " writing" : reqmode &
66632+ GR_APPEND ? " appending" : "");
66633+ return reqmode;
66634+ } else
66635+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
66636+ {
66637+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
66638+ reqmode & GR_READ ? " reading" : "",
66639+ reqmode & GR_WRITE ? " writing" : reqmode &
66640+ GR_APPEND ? " appending" : "");
66641+ return 0;
66642+ } else if (unlikely((mode & reqmode) != reqmode))
66643+ return 0;
66644+
66645+ return reqmode;
66646+}
66647+
66648+__u32
66649+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
66650+ const int fmode)
66651+{
66652+ __u32 mode, reqmode = GR_FIND;
66653+
66654+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
66655+ reqmode |= GR_EXEC;
66656+ if (fmode & S_IWOTH)
66657+ reqmode |= GR_WRITE;
66658+ if (fmode & S_IROTH)
66659+ reqmode |= GR_READ;
66660+
66661+ mode =
66662+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
66663+ mnt);
66664+
66665+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
66666+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
66667+ reqmode & GR_READ ? " reading" : "",
66668+ reqmode & GR_WRITE ? " writing" : "",
66669+ reqmode & GR_EXEC ? " executing" : "");
66670+ return reqmode;
66671+ } else
66672+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
66673+ {
66674+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
66675+ reqmode & GR_READ ? " reading" : "",
66676+ reqmode & GR_WRITE ? " writing" : "",
66677+ reqmode & GR_EXEC ? " executing" : "");
66678+ return 0;
66679+ } else if (unlikely((mode & reqmode) != reqmode))
66680+ return 0;
66681+
66682+ return reqmode;
66683+}
66684+
66685+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
66686+{
66687+ __u32 mode;
66688+
66689+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
66690+
66691+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
66692+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
66693+ return mode;
66694+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
66695+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
66696+ return 0;
66697+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
66698+ return 0;
66699+
66700+ return (reqmode);
66701+}
66702+
66703+__u32
66704+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
66705+{
66706+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
66707+}
66708+
66709+__u32
66710+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
66711+{
66712+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
66713+}
66714+
66715+__u32
66716+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
66717+{
66718+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
66719+}
66720+
66721+__u32
66722+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
66723+{
66724+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
66725+}
66726+
66727+__u32
66728+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
66729+ umode_t *modeptr)
66730+{
66731+ umode_t mode;
66732+
66733+ *modeptr &= ~gr_acl_umask();
66734+ mode = *modeptr;
66735+
66736+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
66737+ return 1;
66738+
66739+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
66740+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
66741+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
66742+ GR_CHMOD_ACL_MSG);
66743+ } else {
66744+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
66745+ }
66746+}
66747+
66748+__u32
66749+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
66750+{
66751+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
66752+}
66753+
66754+__u32
66755+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
66756+{
66757+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
66758+}
66759+
66760+__u32
66761+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
66762+{
66763+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
66764+}
66765+
66766+__u32
66767+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
66768+{
66769+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
66770+ GR_UNIXCONNECT_ACL_MSG);
66771+}
66772+
66773+/* hardlinks require at minimum create and link permission,
66774+ any additional privilege required is based on the
66775+ privilege of the file being linked to
66776+*/
66777+__u32
66778+gr_acl_handle_link(const struct dentry * new_dentry,
66779+ const struct dentry * parent_dentry,
66780+ const struct vfsmount * parent_mnt,
66781+ const struct dentry * old_dentry,
66782+ const struct vfsmount * old_mnt, const struct filename *to)
66783+{
66784+ __u32 mode;
66785+ __u32 needmode = GR_CREATE | GR_LINK;
66786+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
66787+
66788+ mode =
66789+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
66790+ old_mnt);
66791+
66792+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
66793+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
66794+ return mode;
66795+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
66796+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
66797+ return 0;
66798+ } else if (unlikely((mode & needmode) != needmode))
66799+ return 0;
66800+
66801+ return 1;
66802+}
66803+
66804+__u32
66805+gr_acl_handle_symlink(const struct dentry * new_dentry,
66806+ const struct dentry * parent_dentry,
66807+ const struct vfsmount * parent_mnt, const struct filename *from)
66808+{
66809+ __u32 needmode = GR_WRITE | GR_CREATE;
66810+ __u32 mode;
66811+
66812+ mode =
66813+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
66814+ GR_CREATE | GR_AUDIT_CREATE |
66815+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
66816+
66817+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
66818+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
66819+ return mode;
66820+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
66821+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
66822+ return 0;
66823+ } else if (unlikely((mode & needmode) != needmode))
66824+ return 0;
66825+
66826+ return (GR_WRITE | GR_CREATE);
66827+}
66828+
66829+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)
66830+{
66831+ __u32 mode;
66832+
66833+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
66834+
66835+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
66836+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
66837+ return mode;
66838+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
66839+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
66840+ return 0;
66841+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
66842+ return 0;
66843+
66844+ return (reqmode);
66845+}
66846+
66847+__u32
66848+gr_acl_handle_mknod(const struct dentry * new_dentry,
66849+ const struct dentry * parent_dentry,
66850+ const struct vfsmount * parent_mnt,
66851+ const int mode)
66852+{
66853+ __u32 reqmode = GR_WRITE | GR_CREATE;
66854+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
66855+ reqmode |= GR_SETID;
66856+
66857+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
66858+ reqmode, GR_MKNOD_ACL_MSG);
66859+}
66860+
66861+__u32
66862+gr_acl_handle_mkdir(const struct dentry *new_dentry,
66863+ const struct dentry *parent_dentry,
66864+ const struct vfsmount *parent_mnt)
66865+{
66866+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
66867+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
66868+}
66869+
66870+#define RENAME_CHECK_SUCCESS(old, new) \
66871+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
66872+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
66873+
66874+int
66875+gr_acl_handle_rename(struct dentry *new_dentry,
66876+ struct dentry *parent_dentry,
66877+ const struct vfsmount *parent_mnt,
66878+ struct dentry *old_dentry,
66879+ struct inode *old_parent_inode,
66880+ struct vfsmount *old_mnt, const struct filename *newname)
66881+{
66882+ __u32 comp1, comp2;
66883+ int error = 0;
66884+
66885+ if (unlikely(!gr_acl_is_enabled()))
66886+ return 0;
66887+
66888+ if (!new_dentry->d_inode) {
66889+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
66890+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
66891+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
66892+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
66893+ GR_DELETE | GR_AUDIT_DELETE |
66894+ GR_AUDIT_READ | GR_AUDIT_WRITE |
66895+ GR_SUPPRESS, old_mnt);
66896+ } else {
66897+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
66898+ GR_CREATE | GR_DELETE |
66899+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
66900+ GR_AUDIT_READ | GR_AUDIT_WRITE |
66901+ GR_SUPPRESS, parent_mnt);
66902+ comp2 =
66903+ gr_search_file(old_dentry,
66904+ GR_READ | GR_WRITE | GR_AUDIT_READ |
66905+ GR_DELETE | GR_AUDIT_DELETE |
66906+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
66907+ }
66908+
66909+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
66910+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
66911+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
66912+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
66913+ && !(comp2 & GR_SUPPRESS)) {
66914+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
66915+ error = -EACCES;
66916+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
66917+ error = -EACCES;
66918+
66919+ return error;
66920+}
66921+
66922+void
66923+gr_acl_handle_exit(void)
66924+{
66925+ u16 id;
66926+ char *rolename;
66927+
66928+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
66929+ !(current->role->roletype & GR_ROLE_PERSIST))) {
66930+ id = current->acl_role_id;
66931+ rolename = current->role->rolename;
66932+ gr_set_acls(1);
66933+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
66934+ }
66935+
66936+ gr_put_exec_file(current);
66937+ return;
66938+}
66939+
66940+int
66941+gr_acl_handle_procpidmem(const struct task_struct *task)
66942+{
66943+ if (unlikely(!gr_acl_is_enabled()))
66944+ return 0;
66945+
66946+ if (task != current && task->acl->mode & GR_PROTPROCFD)
66947+ return -EACCES;
66948+
66949+ return 0;
66950+}
66951diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
66952new file mode 100644
66953index 0000000..f056b81
66954--- /dev/null
66955+++ b/grsecurity/gracl_ip.c
66956@@ -0,0 +1,386 @@
66957+#include <linux/kernel.h>
66958+#include <asm/uaccess.h>
66959+#include <asm/errno.h>
66960+#include <net/sock.h>
66961+#include <linux/file.h>
66962+#include <linux/fs.h>
66963+#include <linux/net.h>
66964+#include <linux/in.h>
66965+#include <linux/skbuff.h>
66966+#include <linux/ip.h>
66967+#include <linux/udp.h>
66968+#include <linux/types.h>
66969+#include <linux/sched.h>
66970+#include <linux/netdevice.h>
66971+#include <linux/inetdevice.h>
66972+#include <linux/gracl.h>
66973+#include <linux/grsecurity.h>
66974+#include <linux/grinternal.h>
66975+
66976+#define GR_BIND 0x01
66977+#define GR_CONNECT 0x02
66978+#define GR_INVERT 0x04
66979+#define GR_BINDOVERRIDE 0x08
66980+#define GR_CONNECTOVERRIDE 0x10
66981+#define GR_SOCK_FAMILY 0x20
66982+
66983+static const char * gr_protocols[IPPROTO_MAX] = {
66984+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
66985+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
66986+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
66987+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
66988+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
66989+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
66990+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
66991+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
66992+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
66993+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
66994+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
66995+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
66996+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
66997+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
66998+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
66999+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
67000+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
67001+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
67002+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
67003+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
67004+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
67005+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
67006+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
67007+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
67008+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
67009+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
67010+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
67011+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
67012+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
67013+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
67014+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
67015+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
67016+ };
67017+
67018+static const char * gr_socktypes[SOCK_MAX] = {
67019+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
67020+ "unknown:7", "unknown:8", "unknown:9", "packet"
67021+ };
67022+
67023+static const char * gr_sockfamilies[AF_MAX+1] = {
67024+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
67025+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
67026+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
67027+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
67028+ };
67029+
67030+const char *
67031+gr_proto_to_name(unsigned char proto)
67032+{
67033+ return gr_protocols[proto];
67034+}
67035+
67036+const char *
67037+gr_socktype_to_name(unsigned char type)
67038+{
67039+ return gr_socktypes[type];
67040+}
67041+
67042+const char *
67043+gr_sockfamily_to_name(unsigned char family)
67044+{
67045+ return gr_sockfamilies[family];
67046+}
67047+
67048+extern const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
67049+
67050+int
67051+gr_search_socket(const int domain, const int type, const int protocol)
67052+{
67053+ struct acl_subject_label *curr;
67054+ const struct cred *cred = current_cred();
67055+
67056+ if (unlikely(!gr_acl_is_enabled()))
67057+ goto exit;
67058+
67059+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
67060+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
67061+ goto exit; // let the kernel handle it
67062+
67063+ curr = current->acl;
67064+
67065+ if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
67066+ /* the family is allowed, if this is PF_INET allow it only if
67067+ the extra sock type/protocol checks pass */
67068+ if (domain == PF_INET)
67069+ goto inet_check;
67070+ goto exit;
67071+ } else {
67072+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
67073+ __u32 fakeip = 0;
67074+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
67075+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
67076+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
67077+ gr_to_filename(current->exec_file->f_path.dentry,
67078+ current->exec_file->f_path.mnt) :
67079+ curr->filename, curr->filename,
67080+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
67081+ &current->signal->saved_ip);
67082+ goto exit;
67083+ }
67084+ goto exit_fail;
67085+ }
67086+
67087+inet_check:
67088+ /* the rest of this checking is for IPv4 only */
67089+ if (!curr->ips)
67090+ goto exit;
67091+
67092+ if ((curr->ip_type & (1U << type)) &&
67093+ (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
67094+ goto exit;
67095+
67096+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
67097+ /* we don't place acls on raw sockets , and sometimes
67098+ dgram/ip sockets are opened for ioctl and not
67099+ bind/connect, so we'll fake a bind learn log */
67100+ if (type == SOCK_RAW || type == SOCK_PACKET) {
67101+ __u32 fakeip = 0;
67102+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
67103+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
67104+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
67105+ gr_to_filename(current->exec_file->f_path.dentry,
67106+ current->exec_file->f_path.mnt) :
67107+ curr->filename, curr->filename,
67108+ &fakeip, 0, type,
67109+ protocol, GR_CONNECT, &current->signal->saved_ip);
67110+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
67111+ __u32 fakeip = 0;
67112+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
67113+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
67114+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
67115+ gr_to_filename(current->exec_file->f_path.dentry,
67116+ current->exec_file->f_path.mnt) :
67117+ curr->filename, curr->filename,
67118+ &fakeip, 0, type,
67119+ protocol, GR_BIND, &current->signal->saved_ip);
67120+ }
67121+ /* we'll log when they use connect or bind */
67122+ goto exit;
67123+ }
67124+
67125+exit_fail:
67126+ if (domain == PF_INET)
67127+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
67128+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
67129+ else if (rcu_access_pointer(net_families[domain]) != NULL)
67130+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
67131+ gr_socktype_to_name(type), protocol);
67132+
67133+ return 0;
67134+exit:
67135+ return 1;
67136+}
67137+
67138+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)
67139+{
67140+ if ((ip->mode & mode) &&
67141+ (ip_port >= ip->low) &&
67142+ (ip_port <= ip->high) &&
67143+ ((ntohl(ip_addr) & our_netmask) ==
67144+ (ntohl(our_addr) & our_netmask))
67145+ && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
67146+ && (ip->type & (1U << type))) {
67147+ if (ip->mode & GR_INVERT)
67148+ return 2; // specifically denied
67149+ else
67150+ return 1; // allowed
67151+ }
67152+
67153+ return 0; // not specifically allowed, may continue parsing
67154+}
67155+
67156+static int
67157+gr_search_connectbind(const int full_mode, struct sock *sk,
67158+ struct sockaddr_in *addr, const int type)
67159+{
67160+ char iface[IFNAMSIZ] = {0};
67161+ struct acl_subject_label *curr;
67162+ struct acl_ip_label *ip;
67163+ struct inet_sock *isk;
67164+ struct net_device *dev;
67165+ struct in_device *idev;
67166+ unsigned long i;
67167+ int ret;
67168+ int mode = full_mode & (GR_BIND | GR_CONNECT);
67169+ __u32 ip_addr = 0;
67170+ __u32 our_addr;
67171+ __u32 our_netmask;
67172+ char *p;
67173+ __u16 ip_port = 0;
67174+ const struct cred *cred = current_cred();
67175+
67176+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
67177+ return 0;
67178+
67179+ curr = current->acl;
67180+ isk = inet_sk(sk);
67181+
67182+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
67183+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
67184+ addr->sin_addr.s_addr = curr->inaddr_any_override;
67185+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
67186+ struct sockaddr_in saddr;
67187+ int err;
67188+
67189+ saddr.sin_family = AF_INET;
67190+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
67191+ saddr.sin_port = isk->inet_sport;
67192+
67193+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
67194+ if (err)
67195+ return err;
67196+
67197+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
67198+ if (err)
67199+ return err;
67200+ }
67201+
67202+ if (!curr->ips)
67203+ return 0;
67204+
67205+ ip_addr = addr->sin_addr.s_addr;
67206+ ip_port = ntohs(addr->sin_port);
67207+
67208+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
67209+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
67210+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
67211+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
67212+ gr_to_filename(current->exec_file->f_path.dentry,
67213+ current->exec_file->f_path.mnt) :
67214+ curr->filename, curr->filename,
67215+ &ip_addr, ip_port, type,
67216+ sk->sk_protocol, mode, &current->signal->saved_ip);
67217+ return 0;
67218+ }
67219+
67220+ for (i = 0; i < curr->ip_num; i++) {
67221+ ip = *(curr->ips + i);
67222+ if (ip->iface != NULL) {
67223+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
67224+ p = strchr(iface, ':');
67225+ if (p != NULL)
67226+ *p = '\0';
67227+ dev = dev_get_by_name(sock_net(sk), iface);
67228+ if (dev == NULL)
67229+ continue;
67230+ idev = in_dev_get(dev);
67231+ if (idev == NULL) {
67232+ dev_put(dev);
67233+ continue;
67234+ }
67235+ rcu_read_lock();
67236+ for_ifa(idev) {
67237+ if (!strcmp(ip->iface, ifa->ifa_label)) {
67238+ our_addr = ifa->ifa_address;
67239+ our_netmask = 0xffffffff;
67240+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
67241+ if (ret == 1) {
67242+ rcu_read_unlock();
67243+ in_dev_put(idev);
67244+ dev_put(dev);
67245+ return 0;
67246+ } else if (ret == 2) {
67247+ rcu_read_unlock();
67248+ in_dev_put(idev);
67249+ dev_put(dev);
67250+ goto denied;
67251+ }
67252+ }
67253+ } endfor_ifa(idev);
67254+ rcu_read_unlock();
67255+ in_dev_put(idev);
67256+ dev_put(dev);
67257+ } else {
67258+ our_addr = ip->addr;
67259+ our_netmask = ip->netmask;
67260+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
67261+ if (ret == 1)
67262+ return 0;
67263+ else if (ret == 2)
67264+ goto denied;
67265+ }
67266+ }
67267+
67268+denied:
67269+ if (mode == GR_BIND)
67270+ 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));
67271+ else if (mode == GR_CONNECT)
67272+ 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));
67273+
67274+ return -EACCES;
67275+}
67276+
67277+int
67278+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
67279+{
67280+ /* always allow disconnection of dgram sockets with connect */
67281+ if (addr->sin_family == AF_UNSPEC)
67282+ return 0;
67283+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
67284+}
67285+
67286+int
67287+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
67288+{
67289+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
67290+}
67291+
67292+int gr_search_listen(struct socket *sock)
67293+{
67294+ struct sock *sk = sock->sk;
67295+ struct sockaddr_in addr;
67296+
67297+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
67298+ addr.sin_port = inet_sk(sk)->inet_sport;
67299+
67300+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
67301+}
67302+
67303+int gr_search_accept(struct socket *sock)
67304+{
67305+ struct sock *sk = sock->sk;
67306+ struct sockaddr_in addr;
67307+
67308+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
67309+ addr.sin_port = inet_sk(sk)->inet_sport;
67310+
67311+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
67312+}
67313+
67314+int
67315+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
67316+{
67317+ if (addr)
67318+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
67319+ else {
67320+ struct sockaddr_in sin;
67321+ const struct inet_sock *inet = inet_sk(sk);
67322+
67323+ sin.sin_addr.s_addr = inet->inet_daddr;
67324+ sin.sin_port = inet->inet_dport;
67325+
67326+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
67327+ }
67328+}
67329+
67330+int
67331+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
67332+{
67333+ struct sockaddr_in sin;
67334+
67335+ if (unlikely(skb->len < sizeof (struct udphdr)))
67336+ return 0; // skip this packet
67337+
67338+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
67339+ sin.sin_port = udp_hdr(skb)->source;
67340+
67341+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
67342+}
67343diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
67344new file mode 100644
67345index 0000000..25f54ef
67346--- /dev/null
67347+++ b/grsecurity/gracl_learn.c
67348@@ -0,0 +1,207 @@
67349+#include <linux/kernel.h>
67350+#include <linux/mm.h>
67351+#include <linux/sched.h>
67352+#include <linux/poll.h>
67353+#include <linux/string.h>
67354+#include <linux/file.h>
67355+#include <linux/types.h>
67356+#include <linux/vmalloc.h>
67357+#include <linux/grinternal.h>
67358+
67359+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
67360+ size_t count, loff_t *ppos);
67361+extern int gr_acl_is_enabled(void);
67362+
67363+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
67364+static int gr_learn_attached;
67365+
67366+/* use a 512k buffer */
67367+#define LEARN_BUFFER_SIZE (512 * 1024)
67368+
67369+static DEFINE_SPINLOCK(gr_learn_lock);
67370+static DEFINE_MUTEX(gr_learn_user_mutex);
67371+
67372+/* we need to maintain two buffers, so that the kernel context of grlearn
67373+ uses a semaphore around the userspace copying, and the other kernel contexts
67374+ use a spinlock when copying into the buffer, since they cannot sleep
67375+*/
67376+static char *learn_buffer;
67377+static char *learn_buffer_user;
67378+static int learn_buffer_len;
67379+static int learn_buffer_user_len;
67380+
67381+static ssize_t
67382+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
67383+{
67384+ DECLARE_WAITQUEUE(wait, current);
67385+ ssize_t retval = 0;
67386+
67387+ add_wait_queue(&learn_wait, &wait);
67388+ set_current_state(TASK_INTERRUPTIBLE);
67389+ do {
67390+ mutex_lock(&gr_learn_user_mutex);
67391+ spin_lock(&gr_learn_lock);
67392+ if (learn_buffer_len)
67393+ break;
67394+ spin_unlock(&gr_learn_lock);
67395+ mutex_unlock(&gr_learn_user_mutex);
67396+ if (file->f_flags & O_NONBLOCK) {
67397+ retval = -EAGAIN;
67398+ goto out;
67399+ }
67400+ if (signal_pending(current)) {
67401+ retval = -ERESTARTSYS;
67402+ goto out;
67403+ }
67404+
67405+ schedule();
67406+ } while (1);
67407+
67408+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
67409+ learn_buffer_user_len = learn_buffer_len;
67410+ retval = learn_buffer_len;
67411+ learn_buffer_len = 0;
67412+
67413+ spin_unlock(&gr_learn_lock);
67414+
67415+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
67416+ retval = -EFAULT;
67417+
67418+ mutex_unlock(&gr_learn_user_mutex);
67419+out:
67420+ set_current_state(TASK_RUNNING);
67421+ remove_wait_queue(&learn_wait, &wait);
67422+ return retval;
67423+}
67424+
67425+static unsigned int
67426+poll_learn(struct file * file, poll_table * wait)
67427+{
67428+ poll_wait(file, &learn_wait, wait);
67429+
67430+ if (learn_buffer_len)
67431+ return (POLLIN | POLLRDNORM);
67432+
67433+ return 0;
67434+}
67435+
67436+void
67437+gr_clear_learn_entries(void)
67438+{
67439+ char *tmp;
67440+
67441+ mutex_lock(&gr_learn_user_mutex);
67442+ spin_lock(&gr_learn_lock);
67443+ tmp = learn_buffer;
67444+ learn_buffer = NULL;
67445+ spin_unlock(&gr_learn_lock);
67446+ if (tmp)
67447+ vfree(tmp);
67448+ if (learn_buffer_user != NULL) {
67449+ vfree(learn_buffer_user);
67450+ learn_buffer_user = NULL;
67451+ }
67452+ learn_buffer_len = 0;
67453+ mutex_unlock(&gr_learn_user_mutex);
67454+
67455+ return;
67456+}
67457+
67458+void
67459+gr_add_learn_entry(const char *fmt, ...)
67460+{
67461+ va_list args;
67462+ unsigned int len;
67463+
67464+ if (!gr_learn_attached)
67465+ return;
67466+
67467+ spin_lock(&gr_learn_lock);
67468+
67469+ /* leave a gap at the end so we know when it's "full" but don't have to
67470+ compute the exact length of the string we're trying to append
67471+ */
67472+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
67473+ spin_unlock(&gr_learn_lock);
67474+ wake_up_interruptible(&learn_wait);
67475+ return;
67476+ }
67477+ if (learn_buffer == NULL) {
67478+ spin_unlock(&gr_learn_lock);
67479+ return;
67480+ }
67481+
67482+ va_start(args, fmt);
67483+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
67484+ va_end(args);
67485+
67486+ learn_buffer_len += len + 1;
67487+
67488+ spin_unlock(&gr_learn_lock);
67489+ wake_up_interruptible(&learn_wait);
67490+
67491+ return;
67492+}
67493+
67494+static int
67495+open_learn(struct inode *inode, struct file *file)
67496+{
67497+ if (file->f_mode & FMODE_READ && gr_learn_attached)
67498+ return -EBUSY;
67499+ if (file->f_mode & FMODE_READ) {
67500+ int retval = 0;
67501+ mutex_lock(&gr_learn_user_mutex);
67502+ if (learn_buffer == NULL)
67503+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
67504+ if (learn_buffer_user == NULL)
67505+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
67506+ if (learn_buffer == NULL) {
67507+ retval = -ENOMEM;
67508+ goto out_error;
67509+ }
67510+ if (learn_buffer_user == NULL) {
67511+ retval = -ENOMEM;
67512+ goto out_error;
67513+ }
67514+ learn_buffer_len = 0;
67515+ learn_buffer_user_len = 0;
67516+ gr_learn_attached = 1;
67517+out_error:
67518+ mutex_unlock(&gr_learn_user_mutex);
67519+ return retval;
67520+ }
67521+ return 0;
67522+}
67523+
67524+static int
67525+close_learn(struct inode *inode, struct file *file)
67526+{
67527+ if (file->f_mode & FMODE_READ) {
67528+ char *tmp = NULL;
67529+ mutex_lock(&gr_learn_user_mutex);
67530+ spin_lock(&gr_learn_lock);
67531+ tmp = learn_buffer;
67532+ learn_buffer = NULL;
67533+ spin_unlock(&gr_learn_lock);
67534+ if (tmp)
67535+ vfree(tmp);
67536+ if (learn_buffer_user != NULL) {
67537+ vfree(learn_buffer_user);
67538+ learn_buffer_user = NULL;
67539+ }
67540+ learn_buffer_len = 0;
67541+ learn_buffer_user_len = 0;
67542+ gr_learn_attached = 0;
67543+ mutex_unlock(&gr_learn_user_mutex);
67544+ }
67545+
67546+ return 0;
67547+}
67548+
67549+const struct file_operations grsec_fops = {
67550+ .read = read_learn,
67551+ .write = write_grsec_handler,
67552+ .open = open_learn,
67553+ .release = close_learn,
67554+ .poll = poll_learn,
67555+};
67556diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
67557new file mode 100644
67558index 0000000..39645c9
67559--- /dev/null
67560+++ b/grsecurity/gracl_res.c
67561@@ -0,0 +1,68 @@
67562+#include <linux/kernel.h>
67563+#include <linux/sched.h>
67564+#include <linux/gracl.h>
67565+#include <linux/grinternal.h>
67566+
67567+static const char *restab_log[] = {
67568+ [RLIMIT_CPU] = "RLIMIT_CPU",
67569+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
67570+ [RLIMIT_DATA] = "RLIMIT_DATA",
67571+ [RLIMIT_STACK] = "RLIMIT_STACK",
67572+ [RLIMIT_CORE] = "RLIMIT_CORE",
67573+ [RLIMIT_RSS] = "RLIMIT_RSS",
67574+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
67575+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
67576+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
67577+ [RLIMIT_AS] = "RLIMIT_AS",
67578+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
67579+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
67580+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
67581+ [RLIMIT_NICE] = "RLIMIT_NICE",
67582+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
67583+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
67584+ [GR_CRASH_RES] = "RLIMIT_CRASH"
67585+};
67586+
67587+void
67588+gr_log_resource(const struct task_struct *task,
67589+ const int res, const unsigned long wanted, const int gt)
67590+{
67591+ const struct cred *cred;
67592+ unsigned long rlim;
67593+
67594+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
67595+ return;
67596+
67597+ // not yet supported resource
67598+ if (unlikely(!restab_log[res]))
67599+ return;
67600+
67601+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
67602+ rlim = task_rlimit_max(task, res);
67603+ else
67604+ rlim = task_rlimit(task, res);
67605+
67606+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
67607+ return;
67608+
67609+ rcu_read_lock();
67610+ cred = __task_cred(task);
67611+
67612+ if (res == RLIMIT_NPROC &&
67613+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
67614+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
67615+ goto out_rcu_unlock;
67616+ else if (res == RLIMIT_MEMLOCK &&
67617+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
67618+ goto out_rcu_unlock;
67619+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
67620+ goto out_rcu_unlock;
67621+ rcu_read_unlock();
67622+
67623+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
67624+
67625+ return;
67626+out_rcu_unlock:
67627+ rcu_read_unlock();
67628+ return;
67629+}
67630diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
67631new file mode 100644
67632index 0000000..3c38bfe
67633--- /dev/null
67634+++ b/grsecurity/gracl_segv.c
67635@@ -0,0 +1,305 @@
67636+#include <linux/kernel.h>
67637+#include <linux/mm.h>
67638+#include <asm/uaccess.h>
67639+#include <asm/errno.h>
67640+#include <asm/mman.h>
67641+#include <net/sock.h>
67642+#include <linux/file.h>
67643+#include <linux/fs.h>
67644+#include <linux/net.h>
67645+#include <linux/in.h>
67646+#include <linux/slab.h>
67647+#include <linux/types.h>
67648+#include <linux/sched.h>
67649+#include <linux/timer.h>
67650+#include <linux/gracl.h>
67651+#include <linux/grsecurity.h>
67652+#include <linux/grinternal.h>
67653+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
67654+#include <linux/magic.h>
67655+#include <linux/pagemap.h>
67656+#include "../fs/btrfs/async-thread.h"
67657+#include "../fs/btrfs/ctree.h"
67658+#include "../fs/btrfs/btrfs_inode.h"
67659+#endif
67660+
67661+static struct crash_uid *uid_set;
67662+static unsigned short uid_used;
67663+static DEFINE_SPINLOCK(gr_uid_lock);
67664+extern rwlock_t gr_inode_lock;
67665+extern struct acl_subject_label *
67666+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
67667+ struct acl_role_label *role);
67668+
67669+static inline dev_t __get_dev(const struct dentry *dentry)
67670+{
67671+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
67672+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
67673+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
67674+ else
67675+#endif
67676+ return dentry->d_sb->s_dev;
67677+}
67678+
67679+int
67680+gr_init_uidset(void)
67681+{
67682+ uid_set =
67683+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
67684+ uid_used = 0;
67685+
67686+ return uid_set ? 1 : 0;
67687+}
67688+
67689+void
67690+gr_free_uidset(void)
67691+{
67692+ if (uid_set)
67693+ kfree(uid_set);
67694+
67695+ return;
67696+}
67697+
67698+int
67699+gr_find_uid(const uid_t uid)
67700+{
67701+ struct crash_uid *tmp = uid_set;
67702+ uid_t buid;
67703+ int low = 0, high = uid_used - 1, mid;
67704+
67705+ while (high >= low) {
67706+ mid = (low + high) >> 1;
67707+ buid = tmp[mid].uid;
67708+ if (buid == uid)
67709+ return mid;
67710+ if (buid > uid)
67711+ high = mid - 1;
67712+ if (buid < uid)
67713+ low = mid + 1;
67714+ }
67715+
67716+ return -1;
67717+}
67718+
67719+static __inline__ void
67720+gr_insertsort(void)
67721+{
67722+ unsigned short i, j;
67723+ struct crash_uid index;
67724+
67725+ for (i = 1; i < uid_used; i++) {
67726+ index = uid_set[i];
67727+ j = i;
67728+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
67729+ uid_set[j] = uid_set[j - 1];
67730+ j--;
67731+ }
67732+ uid_set[j] = index;
67733+ }
67734+
67735+ return;
67736+}
67737+
67738+static __inline__ void
67739+gr_insert_uid(const kuid_t kuid, const unsigned long expires)
67740+{
67741+ int loc;
67742+ uid_t uid = GR_GLOBAL_UID(kuid);
67743+
67744+ if (uid_used == GR_UIDTABLE_MAX)
67745+ return;
67746+
67747+ loc = gr_find_uid(uid);
67748+
67749+ if (loc >= 0) {
67750+ uid_set[loc].expires = expires;
67751+ return;
67752+ }
67753+
67754+ uid_set[uid_used].uid = uid;
67755+ uid_set[uid_used].expires = expires;
67756+ uid_used++;
67757+
67758+ gr_insertsort();
67759+
67760+ return;
67761+}
67762+
67763+void
67764+gr_remove_uid(const unsigned short loc)
67765+{
67766+ unsigned short i;
67767+
67768+ for (i = loc + 1; i < uid_used; i++)
67769+ uid_set[i - 1] = uid_set[i];
67770+
67771+ uid_used--;
67772+
67773+ return;
67774+}
67775+
67776+int
67777+gr_check_crash_uid(const kuid_t kuid)
67778+{
67779+ int loc;
67780+ int ret = 0;
67781+ uid_t uid;
67782+
67783+ if (unlikely(!gr_acl_is_enabled()))
67784+ return 0;
67785+
67786+ uid = GR_GLOBAL_UID(kuid);
67787+
67788+ spin_lock(&gr_uid_lock);
67789+ loc = gr_find_uid(uid);
67790+
67791+ if (loc < 0)
67792+ goto out_unlock;
67793+
67794+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
67795+ gr_remove_uid(loc);
67796+ else
67797+ ret = 1;
67798+
67799+out_unlock:
67800+ spin_unlock(&gr_uid_lock);
67801+ return ret;
67802+}
67803+
67804+static __inline__ int
67805+proc_is_setxid(const struct cred *cred)
67806+{
67807+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
67808+ !uid_eq(cred->uid, cred->fsuid))
67809+ return 1;
67810+ if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
67811+ !gid_eq(cred->gid, cred->fsgid))
67812+ return 1;
67813+
67814+ return 0;
67815+}
67816+
67817+extern int gr_fake_force_sig(int sig, struct task_struct *t);
67818+
67819+void
67820+gr_handle_crash(struct task_struct *task, const int sig)
67821+{
67822+ struct acl_subject_label *curr;
67823+ struct task_struct *tsk, *tsk2;
67824+ const struct cred *cred;
67825+ const struct cred *cred2;
67826+
67827+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
67828+ return;
67829+
67830+ if (unlikely(!gr_acl_is_enabled()))
67831+ return;
67832+
67833+ curr = task->acl;
67834+
67835+ if (!(curr->resmask & (1U << GR_CRASH_RES)))
67836+ return;
67837+
67838+ if (time_before_eq(curr->expires, get_seconds())) {
67839+ curr->expires = 0;
67840+ curr->crashes = 0;
67841+ }
67842+
67843+ curr->crashes++;
67844+
67845+ if (!curr->expires)
67846+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
67847+
67848+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
67849+ time_after(curr->expires, get_seconds())) {
67850+ rcu_read_lock();
67851+ cred = __task_cred(task);
67852+ if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
67853+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
67854+ spin_lock(&gr_uid_lock);
67855+ gr_insert_uid(cred->uid, curr->expires);
67856+ spin_unlock(&gr_uid_lock);
67857+ curr->expires = 0;
67858+ curr->crashes = 0;
67859+ read_lock(&tasklist_lock);
67860+ do_each_thread(tsk2, tsk) {
67861+ cred2 = __task_cred(tsk);
67862+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
67863+ gr_fake_force_sig(SIGKILL, tsk);
67864+ } while_each_thread(tsk2, tsk);
67865+ read_unlock(&tasklist_lock);
67866+ } else {
67867+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
67868+ read_lock(&tasklist_lock);
67869+ read_lock(&grsec_exec_file_lock);
67870+ do_each_thread(tsk2, tsk) {
67871+ if (likely(tsk != task)) {
67872+ // if this thread has the same subject as the one that triggered
67873+ // RES_CRASH and it's the same binary, kill it
67874+ if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
67875+ gr_fake_force_sig(SIGKILL, tsk);
67876+ }
67877+ } while_each_thread(tsk2, tsk);
67878+ read_unlock(&grsec_exec_file_lock);
67879+ read_unlock(&tasklist_lock);
67880+ }
67881+ rcu_read_unlock();
67882+ }
67883+
67884+ return;
67885+}
67886+
67887+int
67888+gr_check_crash_exec(const struct file *filp)
67889+{
67890+ struct acl_subject_label *curr;
67891+
67892+ if (unlikely(!gr_acl_is_enabled()))
67893+ return 0;
67894+
67895+ read_lock(&gr_inode_lock);
67896+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
67897+ __get_dev(filp->f_path.dentry),
67898+ current->role);
67899+ read_unlock(&gr_inode_lock);
67900+
67901+ if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
67902+ (!curr->crashes && !curr->expires))
67903+ return 0;
67904+
67905+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
67906+ time_after(curr->expires, get_seconds()))
67907+ return 1;
67908+ else if (time_before_eq(curr->expires, get_seconds())) {
67909+ curr->crashes = 0;
67910+ curr->expires = 0;
67911+ }
67912+
67913+ return 0;
67914+}
67915+
67916+void
67917+gr_handle_alertkill(struct task_struct *task)
67918+{
67919+ struct acl_subject_label *curracl;
67920+ __u32 curr_ip;
67921+ struct task_struct *p, *p2;
67922+
67923+ if (unlikely(!gr_acl_is_enabled()))
67924+ return;
67925+
67926+ curracl = task->acl;
67927+ curr_ip = task->signal->curr_ip;
67928+
67929+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
67930+ read_lock(&tasklist_lock);
67931+ do_each_thread(p2, p) {
67932+ if (p->signal->curr_ip == curr_ip)
67933+ gr_fake_force_sig(SIGKILL, p);
67934+ } while_each_thread(p2, p);
67935+ read_unlock(&tasklist_lock);
67936+ } else if (curracl->mode & GR_KILLPROC)
67937+ gr_fake_force_sig(SIGKILL, task);
67938+
67939+ return;
67940+}
67941diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
67942new file mode 100644
67943index 0000000..98011b0
67944--- /dev/null
67945+++ b/grsecurity/gracl_shm.c
67946@@ -0,0 +1,40 @@
67947+#include <linux/kernel.h>
67948+#include <linux/mm.h>
67949+#include <linux/sched.h>
67950+#include <linux/file.h>
67951+#include <linux/ipc.h>
67952+#include <linux/gracl.h>
67953+#include <linux/grsecurity.h>
67954+#include <linux/grinternal.h>
67955+
67956+int
67957+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
67958+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
67959+{
67960+ struct task_struct *task;
67961+
67962+ if (!gr_acl_is_enabled())
67963+ return 1;
67964+
67965+ rcu_read_lock();
67966+ read_lock(&tasklist_lock);
67967+
67968+ task = find_task_by_vpid(shm_cprid);
67969+
67970+ if (unlikely(!task))
67971+ task = find_task_by_vpid(shm_lapid);
67972+
67973+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
67974+ (task_pid_nr(task) == shm_lapid)) &&
67975+ (task->acl->mode & GR_PROTSHM) &&
67976+ (task->acl != current->acl))) {
67977+ read_unlock(&tasklist_lock);
67978+ rcu_read_unlock();
67979+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
67980+ return 0;
67981+ }
67982+ read_unlock(&tasklist_lock);
67983+ rcu_read_unlock();
67984+
67985+ return 1;
67986+}
67987diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
67988new file mode 100644
67989index 0000000..bc0be01
67990--- /dev/null
67991+++ b/grsecurity/grsec_chdir.c
67992@@ -0,0 +1,19 @@
67993+#include <linux/kernel.h>
67994+#include <linux/sched.h>
67995+#include <linux/fs.h>
67996+#include <linux/file.h>
67997+#include <linux/grsecurity.h>
67998+#include <linux/grinternal.h>
67999+
68000+void
68001+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
68002+{
68003+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
68004+ if ((grsec_enable_chdir && grsec_enable_group &&
68005+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
68006+ !grsec_enable_group)) {
68007+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
68008+ }
68009+#endif
68010+ return;
68011+}
68012diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
68013new file mode 100644
68014index 0000000..bd6e105
68015--- /dev/null
68016+++ b/grsecurity/grsec_chroot.c
68017@@ -0,0 +1,370 @@
68018+#include <linux/kernel.h>
68019+#include <linux/module.h>
68020+#include <linux/sched.h>
68021+#include <linux/file.h>
68022+#include <linux/fs.h>
68023+#include <linux/mount.h>
68024+#include <linux/types.h>
68025+#include "../fs/mount.h"
68026+#include <linux/grsecurity.h>
68027+#include <linux/grinternal.h>
68028+
68029+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
68030+static int gr_init_ran;
68031+#endif
68032+
68033+void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
68034+{
68035+#ifdef CONFIG_GRKERNSEC
68036+ if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
68037+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
68038+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
68039+ && gr_init_ran
68040+#endif
68041+ )
68042+ task->gr_is_chrooted = 1;
68043+ else {
68044+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
68045+ if (task_pid_nr(task) == 1 && !gr_init_ran)
68046+ gr_init_ran = 1;
68047+#endif
68048+ task->gr_is_chrooted = 0;
68049+ }
68050+
68051+ task->gr_chroot_dentry = path->dentry;
68052+#endif
68053+ return;
68054+}
68055+
68056+void gr_clear_chroot_entries(struct task_struct *task)
68057+{
68058+#ifdef CONFIG_GRKERNSEC
68059+ task->gr_is_chrooted = 0;
68060+ task->gr_chroot_dentry = NULL;
68061+#endif
68062+ return;
68063+}
68064+
68065+int
68066+gr_handle_chroot_unix(const pid_t pid)
68067+{
68068+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
68069+ struct task_struct *p;
68070+
68071+ if (unlikely(!grsec_enable_chroot_unix))
68072+ return 1;
68073+
68074+ if (likely(!proc_is_chrooted(current)))
68075+ return 1;
68076+
68077+ rcu_read_lock();
68078+ read_lock(&tasklist_lock);
68079+ p = find_task_by_vpid_unrestricted(pid);
68080+ if (unlikely(p && !have_same_root(current, p))) {
68081+ read_unlock(&tasklist_lock);
68082+ rcu_read_unlock();
68083+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
68084+ return 0;
68085+ }
68086+ read_unlock(&tasklist_lock);
68087+ rcu_read_unlock();
68088+#endif
68089+ return 1;
68090+}
68091+
68092+int
68093+gr_handle_chroot_nice(void)
68094+{
68095+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
68096+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
68097+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
68098+ return -EPERM;
68099+ }
68100+#endif
68101+ return 0;
68102+}
68103+
68104+int
68105+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
68106+{
68107+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
68108+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
68109+ && proc_is_chrooted(current)) {
68110+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
68111+ return -EACCES;
68112+ }
68113+#endif
68114+ return 0;
68115+}
68116+
68117+int
68118+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
68119+{
68120+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
68121+ struct task_struct *p;
68122+ int ret = 0;
68123+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
68124+ return ret;
68125+
68126+ read_lock(&tasklist_lock);
68127+ do_each_pid_task(pid, type, p) {
68128+ if (!have_same_root(current, p)) {
68129+ ret = 1;
68130+ goto out;
68131+ }
68132+ } while_each_pid_task(pid, type, p);
68133+out:
68134+ read_unlock(&tasklist_lock);
68135+ return ret;
68136+#endif
68137+ return 0;
68138+}
68139+
68140+int
68141+gr_pid_is_chrooted(struct task_struct *p)
68142+{
68143+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
68144+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
68145+ return 0;
68146+
68147+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
68148+ !have_same_root(current, p)) {
68149+ return 1;
68150+ }
68151+#endif
68152+ return 0;
68153+}
68154+
68155+EXPORT_SYMBOL(gr_pid_is_chrooted);
68156+
68157+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
68158+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
68159+{
68160+ struct path path, currentroot;
68161+ int ret = 0;
68162+
68163+ path.dentry = (struct dentry *)u_dentry;
68164+ path.mnt = (struct vfsmount *)u_mnt;
68165+ get_fs_root(current->fs, &currentroot);
68166+ if (path_is_under(&path, &currentroot))
68167+ ret = 1;
68168+ path_put(&currentroot);
68169+
68170+ return ret;
68171+}
68172+#endif
68173+
68174+int
68175+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
68176+{
68177+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
68178+ if (!grsec_enable_chroot_fchdir)
68179+ return 1;
68180+
68181+ if (!proc_is_chrooted(current))
68182+ return 1;
68183+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
68184+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
68185+ return 0;
68186+ }
68187+#endif
68188+ return 1;
68189+}
68190+
68191+int
68192+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
68193+ const time_t shm_createtime)
68194+{
68195+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
68196+ struct task_struct *p;
68197+ time_t starttime;
68198+
68199+ if (unlikely(!grsec_enable_chroot_shmat))
68200+ return 1;
68201+
68202+ if (likely(!proc_is_chrooted(current)))
68203+ return 1;
68204+
68205+ rcu_read_lock();
68206+ read_lock(&tasklist_lock);
68207+
68208+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
68209+ starttime = p->start_time.tv_sec;
68210+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
68211+ if (have_same_root(current, p)) {
68212+ goto allow;
68213+ } else {
68214+ read_unlock(&tasklist_lock);
68215+ rcu_read_unlock();
68216+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
68217+ return 0;
68218+ }
68219+ }
68220+ /* creator exited, pid reuse, fall through to next check */
68221+ }
68222+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
68223+ if (unlikely(!have_same_root(current, p))) {
68224+ read_unlock(&tasklist_lock);
68225+ rcu_read_unlock();
68226+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
68227+ return 0;
68228+ }
68229+ }
68230+
68231+allow:
68232+ read_unlock(&tasklist_lock);
68233+ rcu_read_unlock();
68234+#endif
68235+ return 1;
68236+}
68237+
68238+void
68239+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
68240+{
68241+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
68242+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
68243+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
68244+#endif
68245+ return;
68246+}
68247+
68248+int
68249+gr_handle_chroot_mknod(const struct dentry *dentry,
68250+ const struct vfsmount *mnt, const int mode)
68251+{
68252+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
68253+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
68254+ proc_is_chrooted(current)) {
68255+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
68256+ return -EPERM;
68257+ }
68258+#endif
68259+ return 0;
68260+}
68261+
68262+int
68263+gr_handle_chroot_mount(const struct dentry *dentry,
68264+ const struct vfsmount *mnt, const char *dev_name)
68265+{
68266+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
68267+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
68268+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
68269+ return -EPERM;
68270+ }
68271+#endif
68272+ return 0;
68273+}
68274+
68275+int
68276+gr_handle_chroot_pivot(void)
68277+{
68278+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
68279+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
68280+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
68281+ return -EPERM;
68282+ }
68283+#endif
68284+ return 0;
68285+}
68286+
68287+int
68288+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
68289+{
68290+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
68291+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
68292+ !gr_is_outside_chroot(dentry, mnt)) {
68293+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
68294+ return -EPERM;
68295+ }
68296+#endif
68297+ return 0;
68298+}
68299+
68300+extern const char *captab_log[];
68301+extern int captab_log_entries;
68302+
68303+int
68304+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
68305+{
68306+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
68307+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
68308+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
68309+ if (cap_raised(chroot_caps, cap)) {
68310+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
68311+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
68312+ }
68313+ return 0;
68314+ }
68315+ }
68316+#endif
68317+ return 1;
68318+}
68319+
68320+int
68321+gr_chroot_is_capable(const int cap)
68322+{
68323+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
68324+ return gr_task_chroot_is_capable(current, current_cred(), cap);
68325+#endif
68326+ return 1;
68327+}
68328+
68329+int
68330+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
68331+{
68332+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
68333+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
68334+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
68335+ if (cap_raised(chroot_caps, cap)) {
68336+ return 0;
68337+ }
68338+ }
68339+#endif
68340+ return 1;
68341+}
68342+
68343+int
68344+gr_chroot_is_capable_nolog(const int cap)
68345+{
68346+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
68347+ return gr_task_chroot_is_capable_nolog(current, cap);
68348+#endif
68349+ return 1;
68350+}
68351+
68352+int
68353+gr_handle_chroot_sysctl(const int op)
68354+{
68355+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
68356+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
68357+ proc_is_chrooted(current))
68358+ return -EACCES;
68359+#endif
68360+ return 0;
68361+}
68362+
68363+void
68364+gr_handle_chroot_chdir(const struct path *path)
68365+{
68366+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
68367+ if (grsec_enable_chroot_chdir)
68368+ set_fs_pwd(current->fs, path);
68369+#endif
68370+ return;
68371+}
68372+
68373+int
68374+gr_handle_chroot_chmod(const struct dentry *dentry,
68375+ const struct vfsmount *mnt, const int mode)
68376+{
68377+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
68378+ /* allow chmod +s on directories, but not files */
68379+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
68380+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
68381+ proc_is_chrooted(current)) {
68382+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
68383+ return -EPERM;
68384+ }
68385+#endif
68386+ return 0;
68387+}
68388diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
68389new file mode 100644
68390index 0000000..ce65ceb
68391--- /dev/null
68392+++ b/grsecurity/grsec_disabled.c
68393@@ -0,0 +1,434 @@
68394+#include <linux/kernel.h>
68395+#include <linux/module.h>
68396+#include <linux/sched.h>
68397+#include <linux/file.h>
68398+#include <linux/fs.h>
68399+#include <linux/kdev_t.h>
68400+#include <linux/net.h>
68401+#include <linux/in.h>
68402+#include <linux/ip.h>
68403+#include <linux/skbuff.h>
68404+#include <linux/sysctl.h>
68405+
68406+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
68407+void
68408+pax_set_initial_flags(struct linux_binprm *bprm)
68409+{
68410+ return;
68411+}
68412+#endif
68413+
68414+#ifdef CONFIG_SYSCTL
68415+__u32
68416+gr_handle_sysctl(const struct ctl_table * table, const int op)
68417+{
68418+ return 0;
68419+}
68420+#endif
68421+
68422+#ifdef CONFIG_TASKSTATS
68423+int gr_is_taskstats_denied(int pid)
68424+{
68425+ return 0;
68426+}
68427+#endif
68428+
68429+int
68430+gr_acl_is_enabled(void)
68431+{
68432+ return 0;
68433+}
68434+
68435+void
68436+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
68437+{
68438+ return;
68439+}
68440+
68441+int
68442+gr_handle_rawio(const struct inode *inode)
68443+{
68444+ return 0;
68445+}
68446+
68447+void
68448+gr_acl_handle_psacct(struct task_struct *task, const long code)
68449+{
68450+ return;
68451+}
68452+
68453+int
68454+gr_handle_ptrace(struct task_struct *task, const long request)
68455+{
68456+ return 0;
68457+}
68458+
68459+int
68460+gr_handle_proc_ptrace(struct task_struct *task)
68461+{
68462+ return 0;
68463+}
68464+
68465+int
68466+gr_set_acls(const int type)
68467+{
68468+ return 0;
68469+}
68470+
68471+int
68472+gr_check_hidden_task(const struct task_struct *tsk)
68473+{
68474+ return 0;
68475+}
68476+
68477+int
68478+gr_check_protected_task(const struct task_struct *task)
68479+{
68480+ return 0;
68481+}
68482+
68483+int
68484+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
68485+{
68486+ return 0;
68487+}
68488+
68489+void
68490+gr_copy_label(struct task_struct *tsk)
68491+{
68492+ return;
68493+}
68494+
68495+void
68496+gr_set_pax_flags(struct task_struct *task)
68497+{
68498+ return;
68499+}
68500+
68501+int
68502+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
68503+ const int unsafe_share)
68504+{
68505+ return 0;
68506+}
68507+
68508+void
68509+gr_handle_delete(const ino_t ino, const dev_t dev)
68510+{
68511+ return;
68512+}
68513+
68514+void
68515+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
68516+{
68517+ return;
68518+}
68519+
68520+void
68521+gr_handle_crash(struct task_struct *task, const int sig)
68522+{
68523+ return;
68524+}
68525+
68526+int
68527+gr_check_crash_exec(const struct file *filp)
68528+{
68529+ return 0;
68530+}
68531+
68532+int
68533+gr_check_crash_uid(const kuid_t uid)
68534+{
68535+ return 0;
68536+}
68537+
68538+void
68539+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
68540+ struct dentry *old_dentry,
68541+ struct dentry *new_dentry,
68542+ struct vfsmount *mnt, const __u8 replace)
68543+{
68544+ return;
68545+}
68546+
68547+int
68548+gr_search_socket(const int family, const int type, const int protocol)
68549+{
68550+ return 1;
68551+}
68552+
68553+int
68554+gr_search_connectbind(const int mode, const struct socket *sock,
68555+ const struct sockaddr_in *addr)
68556+{
68557+ return 0;
68558+}
68559+
68560+void
68561+gr_handle_alertkill(struct task_struct *task)
68562+{
68563+ return;
68564+}
68565+
68566+__u32
68567+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
68568+{
68569+ return 1;
68570+}
68571+
68572+__u32
68573+gr_acl_handle_hidden_file(const struct dentry * dentry,
68574+ const struct vfsmount * mnt)
68575+{
68576+ return 1;
68577+}
68578+
68579+__u32
68580+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
68581+ int acc_mode)
68582+{
68583+ return 1;
68584+}
68585+
68586+__u32
68587+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
68588+{
68589+ return 1;
68590+}
68591+
68592+__u32
68593+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
68594+{
68595+ return 1;
68596+}
68597+
68598+int
68599+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
68600+ unsigned int *vm_flags)
68601+{
68602+ return 1;
68603+}
68604+
68605+__u32
68606+gr_acl_handle_truncate(const struct dentry * dentry,
68607+ const struct vfsmount * mnt)
68608+{
68609+ return 1;
68610+}
68611+
68612+__u32
68613+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
68614+{
68615+ return 1;
68616+}
68617+
68618+__u32
68619+gr_acl_handle_access(const struct dentry * dentry,
68620+ const struct vfsmount * mnt, const int fmode)
68621+{
68622+ return 1;
68623+}
68624+
68625+__u32
68626+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
68627+ umode_t *mode)
68628+{
68629+ return 1;
68630+}
68631+
68632+__u32
68633+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
68634+{
68635+ return 1;
68636+}
68637+
68638+__u32
68639+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
68640+{
68641+ return 1;
68642+}
68643+
68644+void
68645+grsecurity_init(void)
68646+{
68647+ return;
68648+}
68649+
68650+umode_t gr_acl_umask(void)
68651+{
68652+ return 0;
68653+}
68654+
68655+__u32
68656+gr_acl_handle_mknod(const struct dentry * new_dentry,
68657+ const struct dentry * parent_dentry,
68658+ const struct vfsmount * parent_mnt,
68659+ const int mode)
68660+{
68661+ return 1;
68662+}
68663+
68664+__u32
68665+gr_acl_handle_mkdir(const struct dentry * new_dentry,
68666+ const struct dentry * parent_dentry,
68667+ const struct vfsmount * parent_mnt)
68668+{
68669+ return 1;
68670+}
68671+
68672+__u32
68673+gr_acl_handle_symlink(const struct dentry * new_dentry,
68674+ const struct dentry * parent_dentry,
68675+ const struct vfsmount * parent_mnt, const struct filename *from)
68676+{
68677+ return 1;
68678+}
68679+
68680+__u32
68681+gr_acl_handle_link(const struct dentry * new_dentry,
68682+ const struct dentry * parent_dentry,
68683+ const struct vfsmount * parent_mnt,
68684+ const struct dentry * old_dentry,
68685+ const struct vfsmount * old_mnt, const struct filename *to)
68686+{
68687+ return 1;
68688+}
68689+
68690+int
68691+gr_acl_handle_rename(const struct dentry *new_dentry,
68692+ const struct dentry *parent_dentry,
68693+ const struct vfsmount *parent_mnt,
68694+ const struct dentry *old_dentry,
68695+ const struct inode *old_parent_inode,
68696+ const struct vfsmount *old_mnt, const struct filename *newname)
68697+{
68698+ return 0;
68699+}
68700+
68701+int
68702+gr_acl_handle_filldir(const struct file *file, const char *name,
68703+ const int namelen, const ino_t ino)
68704+{
68705+ return 1;
68706+}
68707+
68708+int
68709+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
68710+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
68711+{
68712+ return 1;
68713+}
68714+
68715+int
68716+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
68717+{
68718+ return 0;
68719+}
68720+
68721+int
68722+gr_search_accept(const struct socket *sock)
68723+{
68724+ return 0;
68725+}
68726+
68727+int
68728+gr_search_listen(const struct socket *sock)
68729+{
68730+ return 0;
68731+}
68732+
68733+int
68734+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
68735+{
68736+ return 0;
68737+}
68738+
68739+__u32
68740+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
68741+{
68742+ return 1;
68743+}
68744+
68745+__u32
68746+gr_acl_handle_creat(const struct dentry * dentry,
68747+ const struct dentry * p_dentry,
68748+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
68749+ const int imode)
68750+{
68751+ return 1;
68752+}
68753+
68754+void
68755+gr_acl_handle_exit(void)
68756+{
68757+ return;
68758+}
68759+
68760+int
68761+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
68762+{
68763+ return 1;
68764+}
68765+
68766+void
68767+gr_set_role_label(const kuid_t uid, const kgid_t gid)
68768+{
68769+ return;
68770+}
68771+
68772+int
68773+gr_acl_handle_procpidmem(const struct task_struct *task)
68774+{
68775+ return 0;
68776+}
68777+
68778+int
68779+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
68780+{
68781+ return 0;
68782+}
68783+
68784+int
68785+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
68786+{
68787+ return 0;
68788+}
68789+
68790+void
68791+gr_set_kernel_label(struct task_struct *task)
68792+{
68793+ return;
68794+}
68795+
68796+int
68797+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
68798+{
68799+ return 0;
68800+}
68801+
68802+int
68803+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
68804+{
68805+ return 0;
68806+}
68807+
68808+int gr_acl_enable_at_secure(void)
68809+{
68810+ return 0;
68811+}
68812+
68813+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
68814+{
68815+ return dentry->d_sb->s_dev;
68816+}
68817+
68818+void gr_put_exec_file(struct task_struct *task)
68819+{
68820+ return;
68821+}
68822+
68823+EXPORT_SYMBOL(gr_set_kernel_label);
68824+#ifdef CONFIG_SECURITY
68825+EXPORT_SYMBOL(gr_check_user_change);
68826+EXPORT_SYMBOL(gr_check_group_change);
68827+#endif
68828diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
68829new file mode 100644
68830index 0000000..387032b
68831--- /dev/null
68832+++ b/grsecurity/grsec_exec.c
68833@@ -0,0 +1,187 @@
68834+#include <linux/kernel.h>
68835+#include <linux/sched.h>
68836+#include <linux/file.h>
68837+#include <linux/binfmts.h>
68838+#include <linux/fs.h>
68839+#include <linux/types.h>
68840+#include <linux/grdefs.h>
68841+#include <linux/grsecurity.h>
68842+#include <linux/grinternal.h>
68843+#include <linux/capability.h>
68844+#include <linux/module.h>
68845+#include <linux/compat.h>
68846+
68847+#include <asm/uaccess.h>
68848+
68849+#ifdef CONFIG_GRKERNSEC_EXECLOG
68850+static char gr_exec_arg_buf[132];
68851+static DEFINE_MUTEX(gr_exec_arg_mutex);
68852+#endif
68853+
68854+struct user_arg_ptr {
68855+#ifdef CONFIG_COMPAT
68856+ bool is_compat;
68857+#endif
68858+ union {
68859+ const char __user *const __user *native;
68860+#ifdef CONFIG_COMPAT
68861+ const compat_uptr_t __user *compat;
68862+#endif
68863+ } ptr;
68864+};
68865+
68866+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
68867+
68868+void
68869+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
68870+{
68871+#ifdef CONFIG_GRKERNSEC_EXECLOG
68872+ char *grarg = gr_exec_arg_buf;
68873+ unsigned int i, x, execlen = 0;
68874+ char c;
68875+
68876+ if (!((grsec_enable_execlog && grsec_enable_group &&
68877+ in_group_p(grsec_audit_gid))
68878+ || (grsec_enable_execlog && !grsec_enable_group)))
68879+ return;
68880+
68881+ mutex_lock(&gr_exec_arg_mutex);
68882+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
68883+
68884+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
68885+ const char __user *p;
68886+ unsigned int len;
68887+
68888+ p = get_user_arg_ptr(argv, i);
68889+ if (IS_ERR(p))
68890+ goto log;
68891+
68892+ len = strnlen_user(p, 128 - execlen);
68893+ if (len > 128 - execlen)
68894+ len = 128 - execlen;
68895+ else if (len > 0)
68896+ len--;
68897+ if (copy_from_user(grarg + execlen, p, len))
68898+ goto log;
68899+
68900+ /* rewrite unprintable characters */
68901+ for (x = 0; x < len; x++) {
68902+ c = *(grarg + execlen + x);
68903+ if (c < 32 || c > 126)
68904+ *(grarg + execlen + x) = ' ';
68905+ }
68906+
68907+ execlen += len;
68908+ *(grarg + execlen) = ' ';
68909+ *(grarg + execlen + 1) = '\0';
68910+ execlen++;
68911+ }
68912+
68913+ log:
68914+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
68915+ bprm->file->f_path.mnt, grarg);
68916+ mutex_unlock(&gr_exec_arg_mutex);
68917+#endif
68918+ return;
68919+}
68920+
68921+#ifdef CONFIG_GRKERNSEC
68922+extern int gr_acl_is_capable(const int cap);
68923+extern int gr_acl_is_capable_nolog(const int cap);
68924+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
68925+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
68926+extern int gr_chroot_is_capable(const int cap);
68927+extern int gr_chroot_is_capable_nolog(const int cap);
68928+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
68929+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
68930+#endif
68931+
68932+const char *captab_log[] = {
68933+ "CAP_CHOWN",
68934+ "CAP_DAC_OVERRIDE",
68935+ "CAP_DAC_READ_SEARCH",
68936+ "CAP_FOWNER",
68937+ "CAP_FSETID",
68938+ "CAP_KILL",
68939+ "CAP_SETGID",
68940+ "CAP_SETUID",
68941+ "CAP_SETPCAP",
68942+ "CAP_LINUX_IMMUTABLE",
68943+ "CAP_NET_BIND_SERVICE",
68944+ "CAP_NET_BROADCAST",
68945+ "CAP_NET_ADMIN",
68946+ "CAP_NET_RAW",
68947+ "CAP_IPC_LOCK",
68948+ "CAP_IPC_OWNER",
68949+ "CAP_SYS_MODULE",
68950+ "CAP_SYS_RAWIO",
68951+ "CAP_SYS_CHROOT",
68952+ "CAP_SYS_PTRACE",
68953+ "CAP_SYS_PACCT",
68954+ "CAP_SYS_ADMIN",
68955+ "CAP_SYS_BOOT",
68956+ "CAP_SYS_NICE",
68957+ "CAP_SYS_RESOURCE",
68958+ "CAP_SYS_TIME",
68959+ "CAP_SYS_TTY_CONFIG",
68960+ "CAP_MKNOD",
68961+ "CAP_LEASE",
68962+ "CAP_AUDIT_WRITE",
68963+ "CAP_AUDIT_CONTROL",
68964+ "CAP_SETFCAP",
68965+ "CAP_MAC_OVERRIDE",
68966+ "CAP_MAC_ADMIN",
68967+ "CAP_SYSLOG",
68968+ "CAP_WAKE_ALARM"
68969+};
68970+
68971+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
68972+
68973+int gr_is_capable(const int cap)
68974+{
68975+#ifdef CONFIG_GRKERNSEC
68976+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
68977+ return 1;
68978+ return 0;
68979+#else
68980+ return 1;
68981+#endif
68982+}
68983+
68984+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
68985+{
68986+#ifdef CONFIG_GRKERNSEC
68987+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
68988+ return 1;
68989+ return 0;
68990+#else
68991+ return 1;
68992+#endif
68993+}
68994+
68995+int gr_is_capable_nolog(const int cap)
68996+{
68997+#ifdef CONFIG_GRKERNSEC
68998+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
68999+ return 1;
69000+ return 0;
69001+#else
69002+ return 1;
69003+#endif
69004+}
69005+
69006+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
69007+{
69008+#ifdef CONFIG_GRKERNSEC
69009+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
69010+ return 1;
69011+ return 0;
69012+#else
69013+ return 1;
69014+#endif
69015+}
69016+
69017+EXPORT_SYMBOL(gr_is_capable);
69018+EXPORT_SYMBOL(gr_is_capable_nolog);
69019+EXPORT_SYMBOL(gr_task_is_capable);
69020+EXPORT_SYMBOL(gr_task_is_capable_nolog);
69021diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
69022new file mode 100644
69023index 0000000..06cc6ea
69024--- /dev/null
69025+++ b/grsecurity/grsec_fifo.c
69026@@ -0,0 +1,24 @@
69027+#include <linux/kernel.h>
69028+#include <linux/sched.h>
69029+#include <linux/fs.h>
69030+#include <linux/file.h>
69031+#include <linux/grinternal.h>
69032+
69033+int
69034+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
69035+ const struct dentry *dir, const int flag, const int acc_mode)
69036+{
69037+#ifdef CONFIG_GRKERNSEC_FIFO
69038+ const struct cred *cred = current_cred();
69039+
69040+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
69041+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
69042+ !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
69043+ !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
69044+ if (!inode_permission(dentry->d_inode, acc_mode))
69045+ 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));
69046+ return -EACCES;
69047+ }
69048+#endif
69049+ return 0;
69050+}
69051diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
69052new file mode 100644
69053index 0000000..8ca18bf
69054--- /dev/null
69055+++ b/grsecurity/grsec_fork.c
69056@@ -0,0 +1,23 @@
69057+#include <linux/kernel.h>
69058+#include <linux/sched.h>
69059+#include <linux/grsecurity.h>
69060+#include <linux/grinternal.h>
69061+#include <linux/errno.h>
69062+
69063+void
69064+gr_log_forkfail(const int retval)
69065+{
69066+#ifdef CONFIG_GRKERNSEC_FORKFAIL
69067+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
69068+ switch (retval) {
69069+ case -EAGAIN:
69070+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
69071+ break;
69072+ case -ENOMEM:
69073+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
69074+ break;
69075+ }
69076+ }
69077+#endif
69078+ return;
69079+}
69080diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
69081new file mode 100644
69082index 0000000..99a0cb9
69083--- /dev/null
69084+++ b/grsecurity/grsec_init.c
69085@@ -0,0 +1,283 @@
69086+#include <linux/kernel.h>
69087+#include <linux/sched.h>
69088+#include <linux/mm.h>
69089+#include <linux/gracl.h>
69090+#include <linux/slab.h>
69091+#include <linux/vmalloc.h>
69092+#include <linux/percpu.h>
69093+#include <linux/module.h>
69094+
69095+int grsec_enable_ptrace_readexec;
69096+int grsec_enable_setxid;
69097+int grsec_enable_symlinkown;
69098+kgid_t grsec_symlinkown_gid;
69099+int grsec_enable_brute;
69100+int grsec_enable_link;
69101+int grsec_enable_dmesg;
69102+int grsec_enable_harden_ptrace;
69103+int grsec_enable_fifo;
69104+int grsec_enable_execlog;
69105+int grsec_enable_signal;
69106+int grsec_enable_forkfail;
69107+int grsec_enable_audit_ptrace;
69108+int grsec_enable_time;
69109+int grsec_enable_group;
69110+kgid_t grsec_audit_gid;
69111+int grsec_enable_chdir;
69112+int grsec_enable_mount;
69113+int grsec_enable_rofs;
69114+int grsec_deny_new_usb;
69115+int grsec_enable_chroot_findtask;
69116+int grsec_enable_chroot_mount;
69117+int grsec_enable_chroot_shmat;
69118+int grsec_enable_chroot_fchdir;
69119+int grsec_enable_chroot_double;
69120+int grsec_enable_chroot_pivot;
69121+int grsec_enable_chroot_chdir;
69122+int grsec_enable_chroot_chmod;
69123+int grsec_enable_chroot_mknod;
69124+int grsec_enable_chroot_nice;
69125+int grsec_enable_chroot_execlog;
69126+int grsec_enable_chroot_caps;
69127+int grsec_enable_chroot_sysctl;
69128+int grsec_enable_chroot_unix;
69129+int grsec_enable_tpe;
69130+kgid_t grsec_tpe_gid;
69131+int grsec_enable_blackhole;
69132+#ifdef CONFIG_IPV6_MODULE
69133+EXPORT_SYMBOL(grsec_enable_blackhole);
69134+#endif
69135+int grsec_lastack_retries;
69136+int grsec_enable_tpe_all;
69137+int grsec_enable_tpe_invert;
69138+int grsec_enable_socket_all;
69139+kgid_t grsec_socket_all_gid;
69140+int grsec_enable_socket_client;
69141+kgid_t grsec_socket_client_gid;
69142+int grsec_enable_socket_server;
69143+kgid_t grsec_socket_server_gid;
69144+int grsec_resource_logging;
69145+int grsec_disable_privio;
69146+int grsec_enable_log_rwxmaps;
69147+int grsec_lock;
69148+
69149+DEFINE_SPINLOCK(grsec_alert_lock);
69150+unsigned long grsec_alert_wtime = 0;
69151+unsigned long grsec_alert_fyet = 0;
69152+
69153+DEFINE_SPINLOCK(grsec_audit_lock);
69154+
69155+DEFINE_RWLOCK(grsec_exec_file_lock);
69156+
69157+char *gr_shared_page[4];
69158+
69159+char *gr_alert_log_fmt;
69160+char *gr_audit_log_fmt;
69161+char *gr_alert_log_buf;
69162+char *gr_audit_log_buf;
69163+
69164+extern struct gr_arg *gr_usermode;
69165+extern unsigned char *gr_system_salt;
69166+extern unsigned char *gr_system_sum;
69167+
69168+void __init
69169+grsecurity_init(void)
69170+{
69171+ int j;
69172+ /* create the per-cpu shared pages */
69173+
69174+#ifdef CONFIG_X86
69175+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
69176+#endif
69177+
69178+ for (j = 0; j < 4; j++) {
69179+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
69180+ if (gr_shared_page[j] == NULL) {
69181+ panic("Unable to allocate grsecurity shared page");
69182+ return;
69183+ }
69184+ }
69185+
69186+ /* allocate log buffers */
69187+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
69188+ if (!gr_alert_log_fmt) {
69189+ panic("Unable to allocate grsecurity alert log format buffer");
69190+ return;
69191+ }
69192+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
69193+ if (!gr_audit_log_fmt) {
69194+ panic("Unable to allocate grsecurity audit log format buffer");
69195+ return;
69196+ }
69197+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
69198+ if (!gr_alert_log_buf) {
69199+ panic("Unable to allocate grsecurity alert log buffer");
69200+ return;
69201+ }
69202+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
69203+ if (!gr_audit_log_buf) {
69204+ panic("Unable to allocate grsecurity audit log buffer");
69205+ return;
69206+ }
69207+
69208+ /* allocate memory for authentication structure */
69209+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
69210+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
69211+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
69212+
69213+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
69214+ panic("Unable to allocate grsecurity authentication structure");
69215+ return;
69216+ }
69217+
69218+
69219+#ifdef CONFIG_GRKERNSEC_IO
69220+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
69221+ grsec_disable_privio = 1;
69222+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
69223+ grsec_disable_privio = 1;
69224+#else
69225+ grsec_disable_privio = 0;
69226+#endif
69227+#endif
69228+
69229+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
69230+ /* for backward compatibility, tpe_invert always defaults to on if
69231+ enabled in the kernel
69232+ */
69233+ grsec_enable_tpe_invert = 1;
69234+#endif
69235+
69236+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
69237+#ifndef CONFIG_GRKERNSEC_SYSCTL
69238+ grsec_lock = 1;
69239+#endif
69240+
69241+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
69242+ grsec_enable_log_rwxmaps = 1;
69243+#endif
69244+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
69245+ grsec_enable_group = 1;
69246+ grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
69247+#endif
69248+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
69249+ grsec_enable_ptrace_readexec = 1;
69250+#endif
69251+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
69252+ grsec_enable_chdir = 1;
69253+#endif
69254+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
69255+ grsec_enable_harden_ptrace = 1;
69256+#endif
69257+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
69258+ grsec_enable_mount = 1;
69259+#endif
69260+#ifdef CONFIG_GRKERNSEC_LINK
69261+ grsec_enable_link = 1;
69262+#endif
69263+#ifdef CONFIG_GRKERNSEC_BRUTE
69264+ grsec_enable_brute = 1;
69265+#endif
69266+#ifdef CONFIG_GRKERNSEC_DMESG
69267+ grsec_enable_dmesg = 1;
69268+#endif
69269+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
69270+ grsec_enable_blackhole = 1;
69271+ grsec_lastack_retries = 4;
69272+#endif
69273+#ifdef CONFIG_GRKERNSEC_FIFO
69274+ grsec_enable_fifo = 1;
69275+#endif
69276+#ifdef CONFIG_GRKERNSEC_EXECLOG
69277+ grsec_enable_execlog = 1;
69278+#endif
69279+#ifdef CONFIG_GRKERNSEC_SETXID
69280+ grsec_enable_setxid = 1;
69281+#endif
69282+#ifdef CONFIG_GRKERNSEC_SIGNAL
69283+ grsec_enable_signal = 1;
69284+#endif
69285+#ifdef CONFIG_GRKERNSEC_FORKFAIL
69286+ grsec_enable_forkfail = 1;
69287+#endif
69288+#ifdef CONFIG_GRKERNSEC_TIME
69289+ grsec_enable_time = 1;
69290+#endif
69291+#ifdef CONFIG_GRKERNSEC_RESLOG
69292+ grsec_resource_logging = 1;
69293+#endif
69294+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
69295+ grsec_enable_chroot_findtask = 1;
69296+#endif
69297+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
69298+ grsec_enable_chroot_unix = 1;
69299+#endif
69300+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
69301+ grsec_enable_chroot_mount = 1;
69302+#endif
69303+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
69304+ grsec_enable_chroot_fchdir = 1;
69305+#endif
69306+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
69307+ grsec_enable_chroot_shmat = 1;
69308+#endif
69309+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
69310+ grsec_enable_audit_ptrace = 1;
69311+#endif
69312+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
69313+ grsec_enable_chroot_double = 1;
69314+#endif
69315+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
69316+ grsec_enable_chroot_pivot = 1;
69317+#endif
69318+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
69319+ grsec_enable_chroot_chdir = 1;
69320+#endif
69321+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
69322+ grsec_enable_chroot_chmod = 1;
69323+#endif
69324+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
69325+ grsec_enable_chroot_mknod = 1;
69326+#endif
69327+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
69328+ grsec_enable_chroot_nice = 1;
69329+#endif
69330+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
69331+ grsec_enable_chroot_execlog = 1;
69332+#endif
69333+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
69334+ grsec_enable_chroot_caps = 1;
69335+#endif
69336+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
69337+ grsec_enable_chroot_sysctl = 1;
69338+#endif
69339+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
69340+ grsec_enable_symlinkown = 1;
69341+ grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
69342+#endif
69343+#ifdef CONFIG_GRKERNSEC_TPE
69344+ grsec_enable_tpe = 1;
69345+ grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
69346+#ifdef CONFIG_GRKERNSEC_TPE_ALL
69347+ grsec_enable_tpe_all = 1;
69348+#endif
69349+#endif
69350+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
69351+ grsec_enable_socket_all = 1;
69352+ grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
69353+#endif
69354+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
69355+ grsec_enable_socket_client = 1;
69356+ grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
69357+#endif
69358+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
69359+ grsec_enable_socket_server = 1;
69360+ grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
69361+#endif
69362+#endif
69363+#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
69364+ grsec_deny_new_usb = 1;
69365+#endif
69366+
69367+ return;
69368+}
69369diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
69370new file mode 100644
69371index 0000000..5e05e20
69372--- /dev/null
69373+++ b/grsecurity/grsec_link.c
69374@@ -0,0 +1,58 @@
69375+#include <linux/kernel.h>
69376+#include <linux/sched.h>
69377+#include <linux/fs.h>
69378+#include <linux/file.h>
69379+#include <linux/grinternal.h>
69380+
69381+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
69382+{
69383+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
69384+ const struct inode *link_inode = link->dentry->d_inode;
69385+
69386+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
69387+ /* ignore root-owned links, e.g. /proc/self */
69388+ gr_is_global_nonroot(link_inode->i_uid) && target &&
69389+ !uid_eq(link_inode->i_uid, target->i_uid)) {
69390+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
69391+ return 1;
69392+ }
69393+#endif
69394+ return 0;
69395+}
69396+
69397+int
69398+gr_handle_follow_link(const struct inode *parent,
69399+ const struct inode *inode,
69400+ const struct dentry *dentry, const struct vfsmount *mnt)
69401+{
69402+#ifdef CONFIG_GRKERNSEC_LINK
69403+ const struct cred *cred = current_cred();
69404+
69405+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
69406+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
69407+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
69408+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
69409+ return -EACCES;
69410+ }
69411+#endif
69412+ return 0;
69413+}
69414+
69415+int
69416+gr_handle_hardlink(const struct dentry *dentry,
69417+ const struct vfsmount *mnt,
69418+ struct inode *inode, const int mode, const struct filename *to)
69419+{
69420+#ifdef CONFIG_GRKERNSEC_LINK
69421+ const struct cred *cred = current_cred();
69422+
69423+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
69424+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
69425+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
69426+ !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
69427+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
69428+ return -EPERM;
69429+ }
69430+#endif
69431+ return 0;
69432+}
69433diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
69434new file mode 100644
69435index 0000000..dbe0a6b
69436--- /dev/null
69437+++ b/grsecurity/grsec_log.c
69438@@ -0,0 +1,341 @@
69439+#include <linux/kernel.h>
69440+#include <linux/sched.h>
69441+#include <linux/file.h>
69442+#include <linux/tty.h>
69443+#include <linux/fs.h>
69444+#include <linux/mm.h>
69445+#include <linux/grinternal.h>
69446+
69447+#ifdef CONFIG_TREE_PREEMPT_RCU
69448+#define DISABLE_PREEMPT() preempt_disable()
69449+#define ENABLE_PREEMPT() preempt_enable()
69450+#else
69451+#define DISABLE_PREEMPT()
69452+#define ENABLE_PREEMPT()
69453+#endif
69454+
69455+#define BEGIN_LOCKS(x) \
69456+ DISABLE_PREEMPT(); \
69457+ rcu_read_lock(); \
69458+ read_lock(&tasklist_lock); \
69459+ read_lock(&grsec_exec_file_lock); \
69460+ if (x != GR_DO_AUDIT) \
69461+ spin_lock(&grsec_alert_lock); \
69462+ else \
69463+ spin_lock(&grsec_audit_lock)
69464+
69465+#define END_LOCKS(x) \
69466+ if (x != GR_DO_AUDIT) \
69467+ spin_unlock(&grsec_alert_lock); \
69468+ else \
69469+ spin_unlock(&grsec_audit_lock); \
69470+ read_unlock(&grsec_exec_file_lock); \
69471+ read_unlock(&tasklist_lock); \
69472+ rcu_read_unlock(); \
69473+ ENABLE_PREEMPT(); \
69474+ if (x == GR_DONT_AUDIT) \
69475+ gr_handle_alertkill(current)
69476+
69477+enum {
69478+ FLOODING,
69479+ NO_FLOODING
69480+};
69481+
69482+extern char *gr_alert_log_fmt;
69483+extern char *gr_audit_log_fmt;
69484+extern char *gr_alert_log_buf;
69485+extern char *gr_audit_log_buf;
69486+
69487+static int gr_log_start(int audit)
69488+{
69489+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
69490+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
69491+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
69492+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
69493+ unsigned long curr_secs = get_seconds();
69494+
69495+ if (audit == GR_DO_AUDIT)
69496+ goto set_fmt;
69497+
69498+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
69499+ grsec_alert_wtime = curr_secs;
69500+ grsec_alert_fyet = 0;
69501+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
69502+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
69503+ grsec_alert_fyet++;
69504+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
69505+ grsec_alert_wtime = curr_secs;
69506+ grsec_alert_fyet++;
69507+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
69508+ return FLOODING;
69509+ }
69510+ else return FLOODING;
69511+
69512+set_fmt:
69513+#endif
69514+ memset(buf, 0, PAGE_SIZE);
69515+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
69516+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
69517+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
69518+ } else if (current->signal->curr_ip) {
69519+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
69520+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
69521+ } else if (gr_acl_is_enabled()) {
69522+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
69523+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
69524+ } else {
69525+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
69526+ strcpy(buf, fmt);
69527+ }
69528+
69529+ return NO_FLOODING;
69530+}
69531+
69532+static void gr_log_middle(int audit, const char *msg, va_list ap)
69533+ __attribute__ ((format (printf, 2, 0)));
69534+
69535+static void gr_log_middle(int audit, const char *msg, va_list ap)
69536+{
69537+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
69538+ unsigned int len = strlen(buf);
69539+
69540+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
69541+
69542+ return;
69543+}
69544+
69545+static void gr_log_middle_varargs(int audit, const char *msg, ...)
69546+ __attribute__ ((format (printf, 2, 3)));
69547+
69548+static void gr_log_middle_varargs(int audit, const char *msg, ...)
69549+{
69550+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
69551+ unsigned int len = strlen(buf);
69552+ va_list ap;
69553+
69554+ va_start(ap, msg);
69555+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
69556+ va_end(ap);
69557+
69558+ return;
69559+}
69560+
69561+static void gr_log_end(int audit, int append_default)
69562+{
69563+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
69564+ if (append_default) {
69565+ struct task_struct *task = current;
69566+ struct task_struct *parent = task->real_parent;
69567+ const struct cred *cred = __task_cred(task);
69568+ const struct cred *pcred = __task_cred(parent);
69569+ unsigned int len = strlen(buf);
69570+
69571+ 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));
69572+ }
69573+
69574+ printk("%s\n", buf);
69575+
69576+ return;
69577+}
69578+
69579+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
69580+{
69581+ int logtype;
69582+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
69583+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
69584+ void *voidptr = NULL;
69585+ int num1 = 0, num2 = 0;
69586+ unsigned long ulong1 = 0, ulong2 = 0;
69587+ struct dentry *dentry = NULL;
69588+ struct vfsmount *mnt = NULL;
69589+ struct file *file = NULL;
69590+ struct task_struct *task = NULL;
69591+ struct vm_area_struct *vma = NULL;
69592+ const struct cred *cred, *pcred;
69593+ va_list ap;
69594+
69595+ BEGIN_LOCKS(audit);
69596+ logtype = gr_log_start(audit);
69597+ if (logtype == FLOODING) {
69598+ END_LOCKS(audit);
69599+ return;
69600+ }
69601+ va_start(ap, argtypes);
69602+ switch (argtypes) {
69603+ case GR_TTYSNIFF:
69604+ task = va_arg(ap, struct task_struct *);
69605+ 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));
69606+ break;
69607+ case GR_SYSCTL_HIDDEN:
69608+ str1 = va_arg(ap, char *);
69609+ gr_log_middle_varargs(audit, msg, result, str1);
69610+ break;
69611+ case GR_RBAC:
69612+ dentry = va_arg(ap, struct dentry *);
69613+ mnt = va_arg(ap, struct vfsmount *);
69614+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
69615+ break;
69616+ case GR_RBAC_STR:
69617+ dentry = va_arg(ap, struct dentry *);
69618+ mnt = va_arg(ap, struct vfsmount *);
69619+ str1 = va_arg(ap, char *);
69620+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
69621+ break;
69622+ case GR_STR_RBAC:
69623+ str1 = va_arg(ap, char *);
69624+ dentry = va_arg(ap, struct dentry *);
69625+ mnt = va_arg(ap, struct vfsmount *);
69626+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
69627+ break;
69628+ case GR_RBAC_MODE2:
69629+ dentry = va_arg(ap, struct dentry *);
69630+ mnt = va_arg(ap, struct vfsmount *);
69631+ str1 = va_arg(ap, char *);
69632+ str2 = va_arg(ap, char *);
69633+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
69634+ break;
69635+ case GR_RBAC_MODE3:
69636+ dentry = va_arg(ap, struct dentry *);
69637+ mnt = va_arg(ap, struct vfsmount *);
69638+ str1 = va_arg(ap, char *);
69639+ str2 = va_arg(ap, char *);
69640+ str3 = va_arg(ap, char *);
69641+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
69642+ break;
69643+ case GR_FILENAME:
69644+ dentry = va_arg(ap, struct dentry *);
69645+ mnt = va_arg(ap, struct vfsmount *);
69646+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
69647+ break;
69648+ case GR_STR_FILENAME:
69649+ str1 = va_arg(ap, char *);
69650+ dentry = va_arg(ap, struct dentry *);
69651+ mnt = va_arg(ap, struct vfsmount *);
69652+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
69653+ break;
69654+ case GR_FILENAME_STR:
69655+ dentry = va_arg(ap, struct dentry *);
69656+ mnt = va_arg(ap, struct vfsmount *);
69657+ str1 = va_arg(ap, char *);
69658+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
69659+ break;
69660+ case GR_FILENAME_TWO_INT:
69661+ dentry = va_arg(ap, struct dentry *);
69662+ mnt = va_arg(ap, struct vfsmount *);
69663+ num1 = va_arg(ap, int);
69664+ num2 = va_arg(ap, int);
69665+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
69666+ break;
69667+ case GR_FILENAME_TWO_INT_STR:
69668+ dentry = va_arg(ap, struct dentry *);
69669+ mnt = va_arg(ap, struct vfsmount *);
69670+ num1 = va_arg(ap, int);
69671+ num2 = va_arg(ap, int);
69672+ str1 = va_arg(ap, char *);
69673+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
69674+ break;
69675+ case GR_TEXTREL:
69676+ file = va_arg(ap, struct file *);
69677+ ulong1 = va_arg(ap, unsigned long);
69678+ ulong2 = va_arg(ap, unsigned long);
69679+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
69680+ break;
69681+ case GR_PTRACE:
69682+ task = va_arg(ap, struct task_struct *);
69683+ 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));
69684+ break;
69685+ case GR_RESOURCE:
69686+ task = va_arg(ap, struct task_struct *);
69687+ cred = __task_cred(task);
69688+ pcred = __task_cred(task->real_parent);
69689+ ulong1 = va_arg(ap, unsigned long);
69690+ str1 = va_arg(ap, char *);
69691+ ulong2 = va_arg(ap, unsigned long);
69692+ 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));
69693+ break;
69694+ case GR_CAP:
69695+ task = va_arg(ap, struct task_struct *);
69696+ cred = __task_cred(task);
69697+ pcred = __task_cred(task->real_parent);
69698+ str1 = va_arg(ap, char *);
69699+ 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));
69700+ break;
69701+ case GR_SIG:
69702+ str1 = va_arg(ap, char *);
69703+ voidptr = va_arg(ap, void *);
69704+ gr_log_middle_varargs(audit, msg, str1, voidptr);
69705+ break;
69706+ case GR_SIG2:
69707+ task = va_arg(ap, struct task_struct *);
69708+ cred = __task_cred(task);
69709+ pcred = __task_cred(task->real_parent);
69710+ num1 = va_arg(ap, int);
69711+ 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));
69712+ break;
69713+ case GR_CRASH1:
69714+ task = va_arg(ap, struct task_struct *);
69715+ cred = __task_cred(task);
69716+ pcred = __task_cred(task->real_parent);
69717+ ulong1 = va_arg(ap, unsigned long);
69718+ 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);
69719+ break;
69720+ case GR_CRASH2:
69721+ task = va_arg(ap, struct task_struct *);
69722+ cred = __task_cred(task);
69723+ pcred = __task_cred(task->real_parent);
69724+ ulong1 = va_arg(ap, unsigned long);
69725+ 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);
69726+ break;
69727+ case GR_RWXMAP:
69728+ file = va_arg(ap, struct file *);
69729+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
69730+ break;
69731+ case GR_RWXMAPVMA:
69732+ vma = va_arg(ap, struct vm_area_struct *);
69733+ if (vma->vm_file)
69734+ str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
69735+ else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
69736+ str1 = "<stack>";
69737+ else if (vma->vm_start <= current->mm->brk &&
69738+ vma->vm_end >= current->mm->start_brk)
69739+ str1 = "<heap>";
69740+ else
69741+ str1 = "<anonymous mapping>";
69742+ gr_log_middle_varargs(audit, msg, str1);
69743+ break;
69744+ case GR_PSACCT:
69745+ {
69746+ unsigned int wday, cday;
69747+ __u8 whr, chr;
69748+ __u8 wmin, cmin;
69749+ __u8 wsec, csec;
69750+ char cur_tty[64] = { 0 };
69751+ char parent_tty[64] = { 0 };
69752+
69753+ task = va_arg(ap, struct task_struct *);
69754+ wday = va_arg(ap, unsigned int);
69755+ cday = va_arg(ap, unsigned int);
69756+ whr = va_arg(ap, int);
69757+ chr = va_arg(ap, int);
69758+ wmin = va_arg(ap, int);
69759+ cmin = va_arg(ap, int);
69760+ wsec = va_arg(ap, int);
69761+ csec = va_arg(ap, int);
69762+ ulong1 = va_arg(ap, unsigned long);
69763+ cred = __task_cred(task);
69764+ pcred = __task_cred(task->real_parent);
69765+
69766+ 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));
69767+ }
69768+ break;
69769+ default:
69770+ gr_log_middle(audit, msg, ap);
69771+ }
69772+ va_end(ap);
69773+ // these don't need DEFAULTSECARGS printed on the end
69774+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
69775+ gr_log_end(audit, 0);
69776+ else
69777+ gr_log_end(audit, 1);
69778+ END_LOCKS(audit);
69779+}
69780diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
69781new file mode 100644
69782index 0000000..f536303
69783--- /dev/null
69784+++ b/grsecurity/grsec_mem.c
69785@@ -0,0 +1,40 @@
69786+#include <linux/kernel.h>
69787+#include <linux/sched.h>
69788+#include <linux/mm.h>
69789+#include <linux/mman.h>
69790+#include <linux/grinternal.h>
69791+
69792+void
69793+gr_handle_ioperm(void)
69794+{
69795+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
69796+ return;
69797+}
69798+
69799+void
69800+gr_handle_iopl(void)
69801+{
69802+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
69803+ return;
69804+}
69805+
69806+void
69807+gr_handle_mem_readwrite(u64 from, u64 to)
69808+{
69809+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
69810+ return;
69811+}
69812+
69813+void
69814+gr_handle_vm86(void)
69815+{
69816+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
69817+ return;
69818+}
69819+
69820+void
69821+gr_log_badprocpid(const char *entry)
69822+{
69823+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
69824+ return;
69825+}
69826diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
69827new file mode 100644
69828index 0000000..2131422
69829--- /dev/null
69830+++ b/grsecurity/grsec_mount.c
69831@@ -0,0 +1,62 @@
69832+#include <linux/kernel.h>
69833+#include <linux/sched.h>
69834+#include <linux/mount.h>
69835+#include <linux/grsecurity.h>
69836+#include <linux/grinternal.h>
69837+
69838+void
69839+gr_log_remount(const char *devname, const int retval)
69840+{
69841+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
69842+ if (grsec_enable_mount && (retval >= 0))
69843+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
69844+#endif
69845+ return;
69846+}
69847+
69848+void
69849+gr_log_unmount(const char *devname, const int retval)
69850+{
69851+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
69852+ if (grsec_enable_mount && (retval >= 0))
69853+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
69854+#endif
69855+ return;
69856+}
69857+
69858+void
69859+gr_log_mount(const char *from, const char *to, const int retval)
69860+{
69861+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
69862+ if (grsec_enable_mount && (retval >= 0))
69863+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
69864+#endif
69865+ return;
69866+}
69867+
69868+int
69869+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
69870+{
69871+#ifdef CONFIG_GRKERNSEC_ROFS
69872+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
69873+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
69874+ return -EPERM;
69875+ } else
69876+ return 0;
69877+#endif
69878+ return 0;
69879+}
69880+
69881+int
69882+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
69883+{
69884+#ifdef CONFIG_GRKERNSEC_ROFS
69885+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
69886+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
69887+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
69888+ return -EPERM;
69889+ } else
69890+ return 0;
69891+#endif
69892+ return 0;
69893+}
69894diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
69895new file mode 100644
69896index 0000000..6ee9d50
69897--- /dev/null
69898+++ b/grsecurity/grsec_pax.c
69899@@ -0,0 +1,45 @@
69900+#include <linux/kernel.h>
69901+#include <linux/sched.h>
69902+#include <linux/mm.h>
69903+#include <linux/file.h>
69904+#include <linux/grinternal.h>
69905+#include <linux/grsecurity.h>
69906+
69907+void
69908+gr_log_textrel(struct vm_area_struct * vma)
69909+{
69910+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
69911+ if (grsec_enable_log_rwxmaps)
69912+ gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
69913+#endif
69914+ return;
69915+}
69916+
69917+void gr_log_ptgnustack(struct file *file)
69918+{
69919+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
69920+ if (grsec_enable_log_rwxmaps)
69921+ gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
69922+#endif
69923+ return;
69924+}
69925+
69926+void
69927+gr_log_rwxmmap(struct file *file)
69928+{
69929+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
69930+ if (grsec_enable_log_rwxmaps)
69931+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
69932+#endif
69933+ return;
69934+}
69935+
69936+void
69937+gr_log_rwxmprotect(struct vm_area_struct *vma)
69938+{
69939+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
69940+ if (grsec_enable_log_rwxmaps)
69941+ gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
69942+#endif
69943+ return;
69944+}
69945diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
69946new file mode 100644
69947index 0000000..f7f29aa
69948--- /dev/null
69949+++ b/grsecurity/grsec_ptrace.c
69950@@ -0,0 +1,30 @@
69951+#include <linux/kernel.h>
69952+#include <linux/sched.h>
69953+#include <linux/grinternal.h>
69954+#include <linux/security.h>
69955+
69956+void
69957+gr_audit_ptrace(struct task_struct *task)
69958+{
69959+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
69960+ if (grsec_enable_audit_ptrace)
69961+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
69962+#endif
69963+ return;
69964+}
69965+
69966+int
69967+gr_ptrace_readexec(struct file *file, int unsafe_flags)
69968+{
69969+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
69970+ const struct dentry *dentry = file->f_path.dentry;
69971+ const struct vfsmount *mnt = file->f_path.mnt;
69972+
69973+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
69974+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
69975+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
69976+ return -EACCES;
69977+ }
69978+#endif
69979+ return 0;
69980+}
69981diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
69982new file mode 100644
69983index 0000000..4e29cc7
69984--- /dev/null
69985+++ b/grsecurity/grsec_sig.c
69986@@ -0,0 +1,246 @@
69987+#include <linux/kernel.h>
69988+#include <linux/sched.h>
69989+#include <linux/fs.h>
69990+#include <linux/delay.h>
69991+#include <linux/grsecurity.h>
69992+#include <linux/grinternal.h>
69993+#include <linux/hardirq.h>
69994+
69995+char *signames[] = {
69996+ [SIGSEGV] = "Segmentation fault",
69997+ [SIGILL] = "Illegal instruction",
69998+ [SIGABRT] = "Abort",
69999+ [SIGBUS] = "Invalid alignment/Bus error"
70000+};
70001+
70002+void
70003+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
70004+{
70005+#ifdef CONFIG_GRKERNSEC_SIGNAL
70006+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
70007+ (sig == SIGABRT) || (sig == SIGBUS))) {
70008+ if (task_pid_nr(t) == task_pid_nr(current)) {
70009+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
70010+ } else {
70011+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
70012+ }
70013+ }
70014+#endif
70015+ return;
70016+}
70017+
70018+int
70019+gr_handle_signal(const struct task_struct *p, const int sig)
70020+{
70021+#ifdef CONFIG_GRKERNSEC
70022+ /* ignore the 0 signal for protected task checks */
70023+ if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
70024+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
70025+ return -EPERM;
70026+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
70027+ return -EPERM;
70028+ }
70029+#endif
70030+ return 0;
70031+}
70032+
70033+#ifdef CONFIG_GRKERNSEC
70034+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
70035+
70036+int gr_fake_force_sig(int sig, struct task_struct *t)
70037+{
70038+ unsigned long int flags;
70039+ int ret, blocked, ignored;
70040+ struct k_sigaction *action;
70041+
70042+ spin_lock_irqsave(&t->sighand->siglock, flags);
70043+ action = &t->sighand->action[sig-1];
70044+ ignored = action->sa.sa_handler == SIG_IGN;
70045+ blocked = sigismember(&t->blocked, sig);
70046+ if (blocked || ignored) {
70047+ action->sa.sa_handler = SIG_DFL;
70048+ if (blocked) {
70049+ sigdelset(&t->blocked, sig);
70050+ recalc_sigpending_and_wake(t);
70051+ }
70052+ }
70053+ if (action->sa.sa_handler == SIG_DFL)
70054+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
70055+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
70056+
70057+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
70058+
70059+ return ret;
70060+}
70061+#endif
70062+
70063+#ifdef CONFIG_GRKERNSEC_BRUTE
70064+#define GR_USER_BAN_TIME (15 * 60)
70065+#define GR_DAEMON_BRUTE_TIME (30 * 60)
70066+
70067+static int __get_dumpable(unsigned long mm_flags)
70068+{
70069+ int ret;
70070+
70071+ ret = mm_flags & MMF_DUMPABLE_MASK;
70072+ return (ret >= 2) ? 2 : ret;
70073+}
70074+#endif
70075+
70076+void gr_handle_brute_attach(unsigned long mm_flags)
70077+{
70078+#ifdef CONFIG_GRKERNSEC_BRUTE
70079+ struct task_struct *p = current;
70080+ kuid_t uid = GLOBAL_ROOT_UID;
70081+ int daemon = 0;
70082+
70083+ if (!grsec_enable_brute)
70084+ return;
70085+
70086+ rcu_read_lock();
70087+ read_lock(&tasklist_lock);
70088+ read_lock(&grsec_exec_file_lock);
70089+ if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
70090+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
70091+ p->real_parent->brute = 1;
70092+ daemon = 1;
70093+ } else {
70094+ const struct cred *cred = __task_cred(p), *cred2;
70095+ struct task_struct *tsk, *tsk2;
70096+
70097+ if (!__get_dumpable(mm_flags) && gr_is_global_nonroot(cred->uid)) {
70098+ struct user_struct *user;
70099+
70100+ uid = cred->uid;
70101+
70102+ /* this is put upon execution past expiration */
70103+ user = find_user(uid);
70104+ if (user == NULL)
70105+ goto unlock;
70106+ user->suid_banned = 1;
70107+ user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
70108+ if (user->suid_ban_expires == ~0UL)
70109+ user->suid_ban_expires--;
70110+
70111+ /* only kill other threads of the same binary, from the same user */
70112+ do_each_thread(tsk2, tsk) {
70113+ cred2 = __task_cred(tsk);
70114+ if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
70115+ gr_fake_force_sig(SIGKILL, tsk);
70116+ } while_each_thread(tsk2, tsk);
70117+ }
70118+ }
70119+unlock:
70120+ read_unlock(&grsec_exec_file_lock);
70121+ read_unlock(&tasklist_lock);
70122+ rcu_read_unlock();
70123+
70124+ if (gr_is_global_nonroot(uid))
70125+ 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);
70126+ else if (daemon)
70127+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
70128+
70129+#endif
70130+ return;
70131+}
70132+
70133+void gr_handle_brute_check(void)
70134+{
70135+#ifdef CONFIG_GRKERNSEC_BRUTE
70136+ struct task_struct *p = current;
70137+
70138+ if (unlikely(p->brute)) {
70139+ if (!grsec_enable_brute)
70140+ p->brute = 0;
70141+ else if (time_before(get_seconds(), p->brute_expires))
70142+ msleep(30 * 1000);
70143+ }
70144+#endif
70145+ return;
70146+}
70147+
70148+void gr_handle_kernel_exploit(void)
70149+{
70150+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
70151+ const struct cred *cred;
70152+ struct task_struct *tsk, *tsk2;
70153+ struct user_struct *user;
70154+ kuid_t uid;
70155+
70156+ if (in_irq() || in_serving_softirq() || in_nmi())
70157+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
70158+
70159+ uid = current_uid();
70160+
70161+ if (gr_is_global_root(uid))
70162+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
70163+ else {
70164+ /* kill all the processes of this user, hold a reference
70165+ to their creds struct, and prevent them from creating
70166+ another process until system reset
70167+ */
70168+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
70169+ GR_GLOBAL_UID(uid));
70170+ /* we intentionally leak this ref */
70171+ user = get_uid(current->cred->user);
70172+ if (user)
70173+ user->kernel_banned = 1;
70174+
70175+ /* kill all processes of this user */
70176+ read_lock(&tasklist_lock);
70177+ do_each_thread(tsk2, tsk) {
70178+ cred = __task_cred(tsk);
70179+ if (uid_eq(cred->uid, uid))
70180+ gr_fake_force_sig(SIGKILL, tsk);
70181+ } while_each_thread(tsk2, tsk);
70182+ read_unlock(&tasklist_lock);
70183+ }
70184+#endif
70185+}
70186+
70187+#ifdef CONFIG_GRKERNSEC_BRUTE
70188+static bool suid_ban_expired(struct user_struct *user)
70189+{
70190+ if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
70191+ user->suid_banned = 0;
70192+ user->suid_ban_expires = 0;
70193+ free_uid(user);
70194+ return true;
70195+ }
70196+
70197+ return false;
70198+}
70199+#endif
70200+
70201+int gr_process_kernel_exec_ban(void)
70202+{
70203+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
70204+ if (unlikely(current->cred->user->kernel_banned))
70205+ return -EPERM;
70206+#endif
70207+ return 0;
70208+}
70209+
70210+int gr_process_kernel_setuid_ban(struct user_struct *user)
70211+{
70212+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
70213+ if (unlikely(user->kernel_banned))
70214+ gr_fake_force_sig(SIGKILL, current);
70215+#endif
70216+ return 0;
70217+}
70218+
70219+int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
70220+{
70221+#ifdef CONFIG_GRKERNSEC_BRUTE
70222+ struct user_struct *user = current->cred->user;
70223+ if (unlikely(user->suid_banned)) {
70224+ if (suid_ban_expired(user))
70225+ return 0;
70226+ /* disallow execution of suid binaries only */
70227+ else if (!uid_eq(bprm->cred->euid, current->cred->uid))
70228+ return -EPERM;
70229+ }
70230+#endif
70231+ return 0;
70232+}
70233diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
70234new file mode 100644
70235index 0000000..4030d57
70236--- /dev/null
70237+++ b/grsecurity/grsec_sock.c
70238@@ -0,0 +1,244 @@
70239+#include <linux/kernel.h>
70240+#include <linux/module.h>
70241+#include <linux/sched.h>
70242+#include <linux/file.h>
70243+#include <linux/net.h>
70244+#include <linux/in.h>
70245+#include <linux/ip.h>
70246+#include <net/sock.h>
70247+#include <net/inet_sock.h>
70248+#include <linux/grsecurity.h>
70249+#include <linux/grinternal.h>
70250+#include <linux/gracl.h>
70251+
70252+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
70253+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
70254+
70255+EXPORT_SYMBOL(gr_search_udp_recvmsg);
70256+EXPORT_SYMBOL(gr_search_udp_sendmsg);
70257+
70258+#ifdef CONFIG_UNIX_MODULE
70259+EXPORT_SYMBOL(gr_acl_handle_unix);
70260+EXPORT_SYMBOL(gr_acl_handle_mknod);
70261+EXPORT_SYMBOL(gr_handle_chroot_unix);
70262+EXPORT_SYMBOL(gr_handle_create);
70263+#endif
70264+
70265+#ifdef CONFIG_GRKERNSEC
70266+#define gr_conn_table_size 32749
70267+struct conn_table_entry {
70268+ struct conn_table_entry *next;
70269+ struct signal_struct *sig;
70270+};
70271+
70272+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
70273+DEFINE_SPINLOCK(gr_conn_table_lock);
70274+
70275+extern const char * gr_socktype_to_name(unsigned char type);
70276+extern const char * gr_proto_to_name(unsigned char proto);
70277+extern const char * gr_sockfamily_to_name(unsigned char family);
70278+
70279+static __inline__ int
70280+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
70281+{
70282+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
70283+}
70284+
70285+static __inline__ int
70286+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
70287+ __u16 sport, __u16 dport)
70288+{
70289+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
70290+ sig->gr_sport == sport && sig->gr_dport == dport))
70291+ return 1;
70292+ else
70293+ return 0;
70294+}
70295+
70296+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
70297+{
70298+ struct conn_table_entry **match;
70299+ unsigned int index;
70300+
70301+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
70302+ sig->gr_sport, sig->gr_dport,
70303+ gr_conn_table_size);
70304+
70305+ newent->sig = sig;
70306+
70307+ match = &gr_conn_table[index];
70308+ newent->next = *match;
70309+ *match = newent;
70310+
70311+ return;
70312+}
70313+
70314+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
70315+{
70316+ struct conn_table_entry *match, *last = NULL;
70317+ unsigned int index;
70318+
70319+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
70320+ sig->gr_sport, sig->gr_dport,
70321+ gr_conn_table_size);
70322+
70323+ match = gr_conn_table[index];
70324+ while (match && !conn_match(match->sig,
70325+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
70326+ sig->gr_dport)) {
70327+ last = match;
70328+ match = match->next;
70329+ }
70330+
70331+ if (match) {
70332+ if (last)
70333+ last->next = match->next;
70334+ else
70335+ gr_conn_table[index] = NULL;
70336+ kfree(match);
70337+ }
70338+
70339+ return;
70340+}
70341+
70342+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
70343+ __u16 sport, __u16 dport)
70344+{
70345+ struct conn_table_entry *match;
70346+ unsigned int index;
70347+
70348+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
70349+
70350+ match = gr_conn_table[index];
70351+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
70352+ match = match->next;
70353+
70354+ if (match)
70355+ return match->sig;
70356+ else
70357+ return NULL;
70358+}
70359+
70360+#endif
70361+
70362+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
70363+{
70364+#ifdef CONFIG_GRKERNSEC
70365+ struct signal_struct *sig = task->signal;
70366+ struct conn_table_entry *newent;
70367+
70368+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
70369+ if (newent == NULL)
70370+ return;
70371+ /* no bh lock needed since we are called with bh disabled */
70372+ spin_lock(&gr_conn_table_lock);
70373+ gr_del_task_from_ip_table_nolock(sig);
70374+ sig->gr_saddr = inet->inet_rcv_saddr;
70375+ sig->gr_daddr = inet->inet_daddr;
70376+ sig->gr_sport = inet->inet_sport;
70377+ sig->gr_dport = inet->inet_dport;
70378+ gr_add_to_task_ip_table_nolock(sig, newent);
70379+ spin_unlock(&gr_conn_table_lock);
70380+#endif
70381+ return;
70382+}
70383+
70384+void gr_del_task_from_ip_table(struct task_struct *task)
70385+{
70386+#ifdef CONFIG_GRKERNSEC
70387+ spin_lock_bh(&gr_conn_table_lock);
70388+ gr_del_task_from_ip_table_nolock(task->signal);
70389+ spin_unlock_bh(&gr_conn_table_lock);
70390+#endif
70391+ return;
70392+}
70393+
70394+void
70395+gr_attach_curr_ip(const struct sock *sk)
70396+{
70397+#ifdef CONFIG_GRKERNSEC
70398+ struct signal_struct *p, *set;
70399+ const struct inet_sock *inet = inet_sk(sk);
70400+
70401+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
70402+ return;
70403+
70404+ set = current->signal;
70405+
70406+ spin_lock_bh(&gr_conn_table_lock);
70407+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
70408+ inet->inet_dport, inet->inet_sport);
70409+ if (unlikely(p != NULL)) {
70410+ set->curr_ip = p->curr_ip;
70411+ set->used_accept = 1;
70412+ gr_del_task_from_ip_table_nolock(p);
70413+ spin_unlock_bh(&gr_conn_table_lock);
70414+ return;
70415+ }
70416+ spin_unlock_bh(&gr_conn_table_lock);
70417+
70418+ set->curr_ip = inet->inet_daddr;
70419+ set->used_accept = 1;
70420+#endif
70421+ return;
70422+}
70423+
70424+int
70425+gr_handle_sock_all(const int family, const int type, const int protocol)
70426+{
70427+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
70428+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
70429+ (family != AF_UNIX)) {
70430+ if (family == AF_INET)
70431+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
70432+ else
70433+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
70434+ return -EACCES;
70435+ }
70436+#endif
70437+ return 0;
70438+}
70439+
70440+int
70441+gr_handle_sock_server(const struct sockaddr *sck)
70442+{
70443+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
70444+ if (grsec_enable_socket_server &&
70445+ in_group_p(grsec_socket_server_gid) &&
70446+ sck && (sck->sa_family != AF_UNIX) &&
70447+ (sck->sa_family != AF_LOCAL)) {
70448+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
70449+ return -EACCES;
70450+ }
70451+#endif
70452+ return 0;
70453+}
70454+
70455+int
70456+gr_handle_sock_server_other(const struct sock *sck)
70457+{
70458+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
70459+ if (grsec_enable_socket_server &&
70460+ in_group_p(grsec_socket_server_gid) &&
70461+ sck && (sck->sk_family != AF_UNIX) &&
70462+ (sck->sk_family != AF_LOCAL)) {
70463+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
70464+ return -EACCES;
70465+ }
70466+#endif
70467+ return 0;
70468+}
70469+
70470+int
70471+gr_handle_sock_client(const struct sockaddr *sck)
70472+{
70473+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
70474+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
70475+ sck && (sck->sa_family != AF_UNIX) &&
70476+ (sck->sa_family != AF_LOCAL)) {
70477+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
70478+ return -EACCES;
70479+ }
70480+#endif
70481+ return 0;
70482+}
70483diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
70484new file mode 100644
70485index 0000000..a147ae7
70486--- /dev/null
70487+++ b/grsecurity/grsec_sysctl.c
70488@@ -0,0 +1,470 @@
70489+#include <linux/kernel.h>
70490+#include <linux/sched.h>
70491+#include <linux/sysctl.h>
70492+#include <linux/grsecurity.h>
70493+#include <linux/grinternal.h>
70494+
70495+int
70496+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
70497+{
70498+#ifdef CONFIG_GRKERNSEC_SYSCTL
70499+ if (dirname == NULL || name == NULL)
70500+ return 0;
70501+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
70502+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
70503+ return -EACCES;
70504+ }
70505+#endif
70506+ return 0;
70507+}
70508+
70509+#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
70510+static int __maybe_unused __read_only one = 1;
70511+#endif
70512+
70513+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
70514+ defined(CONFIG_GRKERNSEC_DENYUSB)
70515+struct ctl_table grsecurity_table[] = {
70516+#ifdef CONFIG_GRKERNSEC_SYSCTL
70517+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
70518+#ifdef CONFIG_GRKERNSEC_IO
70519+ {
70520+ .procname = "disable_priv_io",
70521+ .data = &grsec_disable_privio,
70522+ .maxlen = sizeof(int),
70523+ .mode = 0600,
70524+ .proc_handler = &proc_dointvec,
70525+ },
70526+#endif
70527+#endif
70528+#ifdef CONFIG_GRKERNSEC_LINK
70529+ {
70530+ .procname = "linking_restrictions",
70531+ .data = &grsec_enable_link,
70532+ .maxlen = sizeof(int),
70533+ .mode = 0600,
70534+ .proc_handler = &proc_dointvec,
70535+ },
70536+#endif
70537+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
70538+ {
70539+ .procname = "enforce_symlinksifowner",
70540+ .data = &grsec_enable_symlinkown,
70541+ .maxlen = sizeof(int),
70542+ .mode = 0600,
70543+ .proc_handler = &proc_dointvec,
70544+ },
70545+ {
70546+ .procname = "symlinkown_gid",
70547+ .data = &grsec_symlinkown_gid,
70548+ .maxlen = sizeof(int),
70549+ .mode = 0600,
70550+ .proc_handler = &proc_dointvec,
70551+ },
70552+#endif
70553+#ifdef CONFIG_GRKERNSEC_BRUTE
70554+ {
70555+ .procname = "deter_bruteforce",
70556+ .data = &grsec_enable_brute,
70557+ .maxlen = sizeof(int),
70558+ .mode = 0600,
70559+ .proc_handler = &proc_dointvec,
70560+ },
70561+#endif
70562+#ifdef CONFIG_GRKERNSEC_FIFO
70563+ {
70564+ .procname = "fifo_restrictions",
70565+ .data = &grsec_enable_fifo,
70566+ .maxlen = sizeof(int),
70567+ .mode = 0600,
70568+ .proc_handler = &proc_dointvec,
70569+ },
70570+#endif
70571+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
70572+ {
70573+ .procname = "ptrace_readexec",
70574+ .data = &grsec_enable_ptrace_readexec,
70575+ .maxlen = sizeof(int),
70576+ .mode = 0600,
70577+ .proc_handler = &proc_dointvec,
70578+ },
70579+#endif
70580+#ifdef CONFIG_GRKERNSEC_SETXID
70581+ {
70582+ .procname = "consistent_setxid",
70583+ .data = &grsec_enable_setxid,
70584+ .maxlen = sizeof(int),
70585+ .mode = 0600,
70586+ .proc_handler = &proc_dointvec,
70587+ },
70588+#endif
70589+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
70590+ {
70591+ .procname = "ip_blackhole",
70592+ .data = &grsec_enable_blackhole,
70593+ .maxlen = sizeof(int),
70594+ .mode = 0600,
70595+ .proc_handler = &proc_dointvec,
70596+ },
70597+ {
70598+ .procname = "lastack_retries",
70599+ .data = &grsec_lastack_retries,
70600+ .maxlen = sizeof(int),
70601+ .mode = 0600,
70602+ .proc_handler = &proc_dointvec,
70603+ },
70604+#endif
70605+#ifdef CONFIG_GRKERNSEC_EXECLOG
70606+ {
70607+ .procname = "exec_logging",
70608+ .data = &grsec_enable_execlog,
70609+ .maxlen = sizeof(int),
70610+ .mode = 0600,
70611+ .proc_handler = &proc_dointvec,
70612+ },
70613+#endif
70614+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
70615+ {
70616+ .procname = "rwxmap_logging",
70617+ .data = &grsec_enable_log_rwxmaps,
70618+ .maxlen = sizeof(int),
70619+ .mode = 0600,
70620+ .proc_handler = &proc_dointvec,
70621+ },
70622+#endif
70623+#ifdef CONFIG_GRKERNSEC_SIGNAL
70624+ {
70625+ .procname = "signal_logging",
70626+ .data = &grsec_enable_signal,
70627+ .maxlen = sizeof(int),
70628+ .mode = 0600,
70629+ .proc_handler = &proc_dointvec,
70630+ },
70631+#endif
70632+#ifdef CONFIG_GRKERNSEC_FORKFAIL
70633+ {
70634+ .procname = "forkfail_logging",
70635+ .data = &grsec_enable_forkfail,
70636+ .maxlen = sizeof(int),
70637+ .mode = 0600,
70638+ .proc_handler = &proc_dointvec,
70639+ },
70640+#endif
70641+#ifdef CONFIG_GRKERNSEC_TIME
70642+ {
70643+ .procname = "timechange_logging",
70644+ .data = &grsec_enable_time,
70645+ .maxlen = sizeof(int),
70646+ .mode = 0600,
70647+ .proc_handler = &proc_dointvec,
70648+ },
70649+#endif
70650+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
70651+ {
70652+ .procname = "chroot_deny_shmat",
70653+ .data = &grsec_enable_chroot_shmat,
70654+ .maxlen = sizeof(int),
70655+ .mode = 0600,
70656+ .proc_handler = &proc_dointvec,
70657+ },
70658+#endif
70659+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
70660+ {
70661+ .procname = "chroot_deny_unix",
70662+ .data = &grsec_enable_chroot_unix,
70663+ .maxlen = sizeof(int),
70664+ .mode = 0600,
70665+ .proc_handler = &proc_dointvec,
70666+ },
70667+#endif
70668+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
70669+ {
70670+ .procname = "chroot_deny_mount",
70671+ .data = &grsec_enable_chroot_mount,
70672+ .maxlen = sizeof(int),
70673+ .mode = 0600,
70674+ .proc_handler = &proc_dointvec,
70675+ },
70676+#endif
70677+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
70678+ {
70679+ .procname = "chroot_deny_fchdir",
70680+ .data = &grsec_enable_chroot_fchdir,
70681+ .maxlen = sizeof(int),
70682+ .mode = 0600,
70683+ .proc_handler = &proc_dointvec,
70684+ },
70685+#endif
70686+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
70687+ {
70688+ .procname = "chroot_deny_chroot",
70689+ .data = &grsec_enable_chroot_double,
70690+ .maxlen = sizeof(int),
70691+ .mode = 0600,
70692+ .proc_handler = &proc_dointvec,
70693+ },
70694+#endif
70695+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
70696+ {
70697+ .procname = "chroot_deny_pivot",
70698+ .data = &grsec_enable_chroot_pivot,
70699+ .maxlen = sizeof(int),
70700+ .mode = 0600,
70701+ .proc_handler = &proc_dointvec,
70702+ },
70703+#endif
70704+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
70705+ {
70706+ .procname = "chroot_enforce_chdir",
70707+ .data = &grsec_enable_chroot_chdir,
70708+ .maxlen = sizeof(int),
70709+ .mode = 0600,
70710+ .proc_handler = &proc_dointvec,
70711+ },
70712+#endif
70713+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
70714+ {
70715+ .procname = "chroot_deny_chmod",
70716+ .data = &grsec_enable_chroot_chmod,
70717+ .maxlen = sizeof(int),
70718+ .mode = 0600,
70719+ .proc_handler = &proc_dointvec,
70720+ },
70721+#endif
70722+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
70723+ {
70724+ .procname = "chroot_deny_mknod",
70725+ .data = &grsec_enable_chroot_mknod,
70726+ .maxlen = sizeof(int),
70727+ .mode = 0600,
70728+ .proc_handler = &proc_dointvec,
70729+ },
70730+#endif
70731+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
70732+ {
70733+ .procname = "chroot_restrict_nice",
70734+ .data = &grsec_enable_chroot_nice,
70735+ .maxlen = sizeof(int),
70736+ .mode = 0600,
70737+ .proc_handler = &proc_dointvec,
70738+ },
70739+#endif
70740+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
70741+ {
70742+ .procname = "chroot_execlog",
70743+ .data = &grsec_enable_chroot_execlog,
70744+ .maxlen = sizeof(int),
70745+ .mode = 0600,
70746+ .proc_handler = &proc_dointvec,
70747+ },
70748+#endif
70749+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
70750+ {
70751+ .procname = "chroot_caps",
70752+ .data = &grsec_enable_chroot_caps,
70753+ .maxlen = sizeof(int),
70754+ .mode = 0600,
70755+ .proc_handler = &proc_dointvec,
70756+ },
70757+#endif
70758+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
70759+ {
70760+ .procname = "chroot_deny_sysctl",
70761+ .data = &grsec_enable_chroot_sysctl,
70762+ .maxlen = sizeof(int),
70763+ .mode = 0600,
70764+ .proc_handler = &proc_dointvec,
70765+ },
70766+#endif
70767+#ifdef CONFIG_GRKERNSEC_TPE
70768+ {
70769+ .procname = "tpe",
70770+ .data = &grsec_enable_tpe,
70771+ .maxlen = sizeof(int),
70772+ .mode = 0600,
70773+ .proc_handler = &proc_dointvec,
70774+ },
70775+ {
70776+ .procname = "tpe_gid",
70777+ .data = &grsec_tpe_gid,
70778+ .maxlen = sizeof(int),
70779+ .mode = 0600,
70780+ .proc_handler = &proc_dointvec,
70781+ },
70782+#endif
70783+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
70784+ {
70785+ .procname = "tpe_invert",
70786+ .data = &grsec_enable_tpe_invert,
70787+ .maxlen = sizeof(int),
70788+ .mode = 0600,
70789+ .proc_handler = &proc_dointvec,
70790+ },
70791+#endif
70792+#ifdef CONFIG_GRKERNSEC_TPE_ALL
70793+ {
70794+ .procname = "tpe_restrict_all",
70795+ .data = &grsec_enable_tpe_all,
70796+ .maxlen = sizeof(int),
70797+ .mode = 0600,
70798+ .proc_handler = &proc_dointvec,
70799+ },
70800+#endif
70801+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
70802+ {
70803+ .procname = "socket_all",
70804+ .data = &grsec_enable_socket_all,
70805+ .maxlen = sizeof(int),
70806+ .mode = 0600,
70807+ .proc_handler = &proc_dointvec,
70808+ },
70809+ {
70810+ .procname = "socket_all_gid",
70811+ .data = &grsec_socket_all_gid,
70812+ .maxlen = sizeof(int),
70813+ .mode = 0600,
70814+ .proc_handler = &proc_dointvec,
70815+ },
70816+#endif
70817+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
70818+ {
70819+ .procname = "socket_client",
70820+ .data = &grsec_enable_socket_client,
70821+ .maxlen = sizeof(int),
70822+ .mode = 0600,
70823+ .proc_handler = &proc_dointvec,
70824+ },
70825+ {
70826+ .procname = "socket_client_gid",
70827+ .data = &grsec_socket_client_gid,
70828+ .maxlen = sizeof(int),
70829+ .mode = 0600,
70830+ .proc_handler = &proc_dointvec,
70831+ },
70832+#endif
70833+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
70834+ {
70835+ .procname = "socket_server",
70836+ .data = &grsec_enable_socket_server,
70837+ .maxlen = sizeof(int),
70838+ .mode = 0600,
70839+ .proc_handler = &proc_dointvec,
70840+ },
70841+ {
70842+ .procname = "socket_server_gid",
70843+ .data = &grsec_socket_server_gid,
70844+ .maxlen = sizeof(int),
70845+ .mode = 0600,
70846+ .proc_handler = &proc_dointvec,
70847+ },
70848+#endif
70849+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
70850+ {
70851+ .procname = "audit_group",
70852+ .data = &grsec_enable_group,
70853+ .maxlen = sizeof(int),
70854+ .mode = 0600,
70855+ .proc_handler = &proc_dointvec,
70856+ },
70857+ {
70858+ .procname = "audit_gid",
70859+ .data = &grsec_audit_gid,
70860+ .maxlen = sizeof(int),
70861+ .mode = 0600,
70862+ .proc_handler = &proc_dointvec,
70863+ },
70864+#endif
70865+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
70866+ {
70867+ .procname = "audit_chdir",
70868+ .data = &grsec_enable_chdir,
70869+ .maxlen = sizeof(int),
70870+ .mode = 0600,
70871+ .proc_handler = &proc_dointvec,
70872+ },
70873+#endif
70874+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
70875+ {
70876+ .procname = "audit_mount",
70877+ .data = &grsec_enable_mount,
70878+ .maxlen = sizeof(int),
70879+ .mode = 0600,
70880+ .proc_handler = &proc_dointvec,
70881+ },
70882+#endif
70883+#ifdef CONFIG_GRKERNSEC_DMESG
70884+ {
70885+ .procname = "dmesg",
70886+ .data = &grsec_enable_dmesg,
70887+ .maxlen = sizeof(int),
70888+ .mode = 0600,
70889+ .proc_handler = &proc_dointvec,
70890+ },
70891+#endif
70892+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
70893+ {
70894+ .procname = "chroot_findtask",
70895+ .data = &grsec_enable_chroot_findtask,
70896+ .maxlen = sizeof(int),
70897+ .mode = 0600,
70898+ .proc_handler = &proc_dointvec,
70899+ },
70900+#endif
70901+#ifdef CONFIG_GRKERNSEC_RESLOG
70902+ {
70903+ .procname = "resource_logging",
70904+ .data = &grsec_resource_logging,
70905+ .maxlen = sizeof(int),
70906+ .mode = 0600,
70907+ .proc_handler = &proc_dointvec,
70908+ },
70909+#endif
70910+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
70911+ {
70912+ .procname = "audit_ptrace",
70913+ .data = &grsec_enable_audit_ptrace,
70914+ .maxlen = sizeof(int),
70915+ .mode = 0600,
70916+ .proc_handler = &proc_dointvec,
70917+ },
70918+#endif
70919+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
70920+ {
70921+ .procname = "harden_ptrace",
70922+ .data = &grsec_enable_harden_ptrace,
70923+ .maxlen = sizeof(int),
70924+ .mode = 0600,
70925+ .proc_handler = &proc_dointvec,
70926+ },
70927+#endif
70928+ {
70929+ .procname = "grsec_lock",
70930+ .data = &grsec_lock,
70931+ .maxlen = sizeof(int),
70932+ .mode = 0600,
70933+ .proc_handler = &proc_dointvec,
70934+ },
70935+#endif
70936+#ifdef CONFIG_GRKERNSEC_ROFS
70937+ {
70938+ .procname = "romount_protect",
70939+ .data = &grsec_enable_rofs,
70940+ .maxlen = sizeof(int),
70941+ .mode = 0600,
70942+ .proc_handler = &proc_dointvec_minmax,
70943+ .extra1 = &one,
70944+ .extra2 = &one,
70945+ },
70946+#endif
70947+#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
70948+ {
70949+ .procname = "deny_new_usb",
70950+ .data = &grsec_deny_new_usb,
70951+ .maxlen = sizeof(int),
70952+ .mode = 0600,
70953+ .proc_handler = &proc_dointvec,
70954+ },
70955+#endif
70956+ { }
70957+};
70958+#endif
70959diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
70960new file mode 100644
70961index 0000000..0dc13c3
70962--- /dev/null
70963+++ b/grsecurity/grsec_time.c
70964@@ -0,0 +1,16 @@
70965+#include <linux/kernel.h>
70966+#include <linux/sched.h>
70967+#include <linux/grinternal.h>
70968+#include <linux/module.h>
70969+
70970+void
70971+gr_log_timechange(void)
70972+{
70973+#ifdef CONFIG_GRKERNSEC_TIME
70974+ if (grsec_enable_time)
70975+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
70976+#endif
70977+ return;
70978+}
70979+
70980+EXPORT_SYMBOL(gr_log_timechange);
70981diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
70982new file mode 100644
70983index 0000000..ee57dcf
70984--- /dev/null
70985+++ b/grsecurity/grsec_tpe.c
70986@@ -0,0 +1,73 @@
70987+#include <linux/kernel.h>
70988+#include <linux/sched.h>
70989+#include <linux/file.h>
70990+#include <linux/fs.h>
70991+#include <linux/grinternal.h>
70992+
70993+extern int gr_acl_tpe_check(void);
70994+
70995+int
70996+gr_tpe_allow(const struct file *file)
70997+{
70998+#ifdef CONFIG_GRKERNSEC
70999+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
71000+ const struct cred *cred = current_cred();
71001+ char *msg = NULL;
71002+ char *msg2 = NULL;
71003+
71004+ // never restrict root
71005+ if (gr_is_global_root(cred->uid))
71006+ return 1;
71007+
71008+ if (grsec_enable_tpe) {
71009+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
71010+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
71011+ msg = "not being in trusted group";
71012+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
71013+ msg = "being in untrusted group";
71014+#else
71015+ if (in_group_p(grsec_tpe_gid))
71016+ msg = "being in untrusted group";
71017+#endif
71018+ }
71019+ if (!msg && gr_acl_tpe_check())
71020+ msg = "being in untrusted role";
71021+
71022+ // not in any affected group/role
71023+ if (!msg)
71024+ goto next_check;
71025+
71026+ if (gr_is_global_nonroot(inode->i_uid))
71027+ msg2 = "file in non-root-owned directory";
71028+ else if (inode->i_mode & S_IWOTH)
71029+ msg2 = "file in world-writable directory";
71030+ else if (inode->i_mode & S_IWGRP)
71031+ msg2 = "file in group-writable directory";
71032+
71033+ if (msg && msg2) {
71034+ char fullmsg[70] = {0};
71035+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
71036+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
71037+ return 0;
71038+ }
71039+ msg = NULL;
71040+next_check:
71041+#ifdef CONFIG_GRKERNSEC_TPE_ALL
71042+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
71043+ return 1;
71044+
71045+ if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
71046+ msg = "directory not owned by user";
71047+ else if (inode->i_mode & S_IWOTH)
71048+ msg = "file in world-writable directory";
71049+ else if (inode->i_mode & S_IWGRP)
71050+ msg = "file in group-writable directory";
71051+
71052+ if (msg) {
71053+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
71054+ return 0;
71055+ }
71056+#endif
71057+#endif
71058+ return 1;
71059+}
71060diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
71061new file mode 100644
71062index 0000000..ae02d8e
71063--- /dev/null
71064+++ b/grsecurity/grsec_usb.c
71065@@ -0,0 +1,15 @@
71066+#include <linux/kernel.h>
71067+#include <linux/grinternal.h>
71068+#include <linux/module.h>
71069+
71070+int gr_handle_new_usb(void)
71071+{
71072+#ifdef CONFIG_GRKERNSEC_DENYUSB
71073+ if (grsec_deny_new_usb) {
71074+ printk(KERN_ALERT "grsec: denied insert of new USB device\n");
71075+ return 1;
71076+ }
71077+#endif
71078+ return 0;
71079+}
71080+EXPORT_SYMBOL_GPL(gr_handle_new_usb);
71081diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
71082new file mode 100644
71083index 0000000..9f7b1ac
71084--- /dev/null
71085+++ b/grsecurity/grsum.c
71086@@ -0,0 +1,61 @@
71087+#include <linux/err.h>
71088+#include <linux/kernel.h>
71089+#include <linux/sched.h>
71090+#include <linux/mm.h>
71091+#include <linux/scatterlist.h>
71092+#include <linux/crypto.h>
71093+#include <linux/gracl.h>
71094+
71095+
71096+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
71097+#error "crypto and sha256 must be built into the kernel"
71098+#endif
71099+
71100+int
71101+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
71102+{
71103+ char *p;
71104+ struct crypto_hash *tfm;
71105+ struct hash_desc desc;
71106+ struct scatterlist sg;
71107+ unsigned char temp_sum[GR_SHA_LEN];
71108+ volatile int retval = 0;
71109+ volatile int dummy = 0;
71110+ unsigned int i;
71111+
71112+ sg_init_table(&sg, 1);
71113+
71114+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
71115+ if (IS_ERR(tfm)) {
71116+ /* should never happen, since sha256 should be built in */
71117+ return 1;
71118+ }
71119+
71120+ desc.tfm = tfm;
71121+ desc.flags = 0;
71122+
71123+ crypto_hash_init(&desc);
71124+
71125+ p = salt;
71126+ sg_set_buf(&sg, p, GR_SALT_LEN);
71127+ crypto_hash_update(&desc, &sg, sg.length);
71128+
71129+ p = entry->pw;
71130+ sg_set_buf(&sg, p, strlen(p));
71131+
71132+ crypto_hash_update(&desc, &sg, sg.length);
71133+
71134+ crypto_hash_final(&desc, temp_sum);
71135+
71136+ memset(entry->pw, 0, GR_PW_LEN);
71137+
71138+ for (i = 0; i < GR_SHA_LEN; i++)
71139+ if (sum[i] != temp_sum[i])
71140+ retval = 1;
71141+ else
71142+ dummy = 1; // waste a cycle
71143+
71144+ crypto_free_hash(tfm);
71145+
71146+ return retval;
71147+}
71148diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
71149index 77ff547..181834f 100644
71150--- a/include/asm-generic/4level-fixup.h
71151+++ b/include/asm-generic/4level-fixup.h
71152@@ -13,8 +13,10 @@
71153 #define pmd_alloc(mm, pud, address) \
71154 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
71155 NULL: pmd_offset(pud, address))
71156+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
71157
71158 #define pud_alloc(mm, pgd, address) (pgd)
71159+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
71160 #define pud_offset(pgd, start) (pgd)
71161 #define pud_none(pud) 0
71162 #define pud_bad(pud) 0
71163diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
71164index b7babf0..04ad282 100644
71165--- a/include/asm-generic/atomic-long.h
71166+++ b/include/asm-generic/atomic-long.h
71167@@ -22,6 +22,12 @@
71168
71169 typedef atomic64_t atomic_long_t;
71170
71171+#ifdef CONFIG_PAX_REFCOUNT
71172+typedef atomic64_unchecked_t atomic_long_unchecked_t;
71173+#else
71174+typedef atomic64_t atomic_long_unchecked_t;
71175+#endif
71176+
71177 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
71178
71179 static inline long atomic_long_read(atomic_long_t *l)
71180@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
71181 return (long)atomic64_read(v);
71182 }
71183
71184+#ifdef CONFIG_PAX_REFCOUNT
71185+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
71186+{
71187+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71188+
71189+ return (long)atomic64_read_unchecked(v);
71190+}
71191+#endif
71192+
71193 static inline void atomic_long_set(atomic_long_t *l, long i)
71194 {
71195 atomic64_t *v = (atomic64_t *)l;
71196@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
71197 atomic64_set(v, i);
71198 }
71199
71200+#ifdef CONFIG_PAX_REFCOUNT
71201+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
71202+{
71203+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71204+
71205+ atomic64_set_unchecked(v, i);
71206+}
71207+#endif
71208+
71209 static inline void atomic_long_inc(atomic_long_t *l)
71210 {
71211 atomic64_t *v = (atomic64_t *)l;
71212@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
71213 atomic64_inc(v);
71214 }
71215
71216+#ifdef CONFIG_PAX_REFCOUNT
71217+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
71218+{
71219+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71220+
71221+ atomic64_inc_unchecked(v);
71222+}
71223+#endif
71224+
71225 static inline void atomic_long_dec(atomic_long_t *l)
71226 {
71227 atomic64_t *v = (atomic64_t *)l;
71228@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
71229 atomic64_dec(v);
71230 }
71231
71232+#ifdef CONFIG_PAX_REFCOUNT
71233+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
71234+{
71235+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71236+
71237+ atomic64_dec_unchecked(v);
71238+}
71239+#endif
71240+
71241 static inline void atomic_long_add(long i, atomic_long_t *l)
71242 {
71243 atomic64_t *v = (atomic64_t *)l;
71244@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
71245 atomic64_add(i, v);
71246 }
71247
71248+#ifdef CONFIG_PAX_REFCOUNT
71249+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
71250+{
71251+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71252+
71253+ atomic64_add_unchecked(i, v);
71254+}
71255+#endif
71256+
71257 static inline void atomic_long_sub(long i, atomic_long_t *l)
71258 {
71259 atomic64_t *v = (atomic64_t *)l;
71260@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
71261 atomic64_sub(i, v);
71262 }
71263
71264+#ifdef CONFIG_PAX_REFCOUNT
71265+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
71266+{
71267+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71268+
71269+ atomic64_sub_unchecked(i, v);
71270+}
71271+#endif
71272+
71273 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
71274 {
71275 atomic64_t *v = (atomic64_t *)l;
71276@@ -101,6 +161,15 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
71277 return (long)atomic64_add_return(i, v);
71278 }
71279
71280+#ifdef CONFIG_PAX_REFCOUNT
71281+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
71282+{
71283+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71284+
71285+ return (long)atomic64_add_return_unchecked(i, v);
71286+}
71287+#endif
71288+
71289 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
71290 {
71291 atomic64_t *v = (atomic64_t *)l;
71292@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
71293 return (long)atomic64_inc_return(v);
71294 }
71295
71296+#ifdef CONFIG_PAX_REFCOUNT
71297+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
71298+{
71299+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71300+
71301+ return (long)atomic64_inc_return_unchecked(v);
71302+}
71303+#endif
71304+
71305 static inline long atomic_long_dec_return(atomic_long_t *l)
71306 {
71307 atomic64_t *v = (atomic64_t *)l;
71308@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
71309
71310 typedef atomic_t atomic_long_t;
71311
71312+#ifdef CONFIG_PAX_REFCOUNT
71313+typedef atomic_unchecked_t atomic_long_unchecked_t;
71314+#else
71315+typedef atomic_t atomic_long_unchecked_t;
71316+#endif
71317+
71318 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
71319 static inline long atomic_long_read(atomic_long_t *l)
71320 {
71321@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
71322 return (long)atomic_read(v);
71323 }
71324
71325+#ifdef CONFIG_PAX_REFCOUNT
71326+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
71327+{
71328+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71329+
71330+ return (long)atomic_read_unchecked(v);
71331+}
71332+#endif
71333+
71334 static inline void atomic_long_set(atomic_long_t *l, long i)
71335 {
71336 atomic_t *v = (atomic_t *)l;
71337@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
71338 atomic_set(v, i);
71339 }
71340
71341+#ifdef CONFIG_PAX_REFCOUNT
71342+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
71343+{
71344+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71345+
71346+ atomic_set_unchecked(v, i);
71347+}
71348+#endif
71349+
71350 static inline void atomic_long_inc(atomic_long_t *l)
71351 {
71352 atomic_t *v = (atomic_t *)l;
71353@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
71354 atomic_inc(v);
71355 }
71356
71357+#ifdef CONFIG_PAX_REFCOUNT
71358+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
71359+{
71360+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71361+
71362+ atomic_inc_unchecked(v);
71363+}
71364+#endif
71365+
71366 static inline void atomic_long_dec(atomic_long_t *l)
71367 {
71368 atomic_t *v = (atomic_t *)l;
71369@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
71370 atomic_dec(v);
71371 }
71372
71373+#ifdef CONFIG_PAX_REFCOUNT
71374+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
71375+{
71376+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71377+
71378+ atomic_dec_unchecked(v);
71379+}
71380+#endif
71381+
71382 static inline void atomic_long_add(long i, atomic_long_t *l)
71383 {
71384 atomic_t *v = (atomic_t *)l;
71385@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
71386 atomic_add(i, v);
71387 }
71388
71389+#ifdef CONFIG_PAX_REFCOUNT
71390+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
71391+{
71392+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71393+
71394+ atomic_add_unchecked(i, v);
71395+}
71396+#endif
71397+
71398 static inline void atomic_long_sub(long i, atomic_long_t *l)
71399 {
71400 atomic_t *v = (atomic_t *)l;
71401@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
71402 atomic_sub(i, v);
71403 }
71404
71405+#ifdef CONFIG_PAX_REFCOUNT
71406+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
71407+{
71408+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71409+
71410+ atomic_sub_unchecked(i, v);
71411+}
71412+#endif
71413+
71414 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
71415 {
71416 atomic_t *v = (atomic_t *)l;
71417@@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
71418 return (long)atomic_add_return(i, v);
71419 }
71420
71421+#ifdef CONFIG_PAX_REFCOUNT
71422+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
71423+{
71424+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71425+
71426+ return (long)atomic_add_return_unchecked(i, v);
71427+}
71428+
71429+#endif
71430+
71431 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
71432 {
71433 atomic_t *v = (atomic_t *)l;
71434@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
71435 return (long)atomic_inc_return(v);
71436 }
71437
71438+#ifdef CONFIG_PAX_REFCOUNT
71439+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
71440+{
71441+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71442+
71443+ return (long)atomic_inc_return_unchecked(v);
71444+}
71445+#endif
71446+
71447 static inline long atomic_long_dec_return(atomic_long_t *l)
71448 {
71449 atomic_t *v = (atomic_t *)l;
71450@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
71451
71452 #endif /* BITS_PER_LONG == 64 */
71453
71454+#ifdef CONFIG_PAX_REFCOUNT
71455+static inline void pax_refcount_needs_these_functions(void)
71456+{
71457+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
71458+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
71459+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
71460+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
71461+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
71462+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
71463+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
71464+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
71465+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
71466+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
71467+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
71468+#ifdef CONFIG_X86
71469+ atomic_clear_mask_unchecked(0, NULL);
71470+ atomic_set_mask_unchecked(0, NULL);
71471+#endif
71472+
71473+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
71474+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
71475+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
71476+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
71477+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
71478+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
71479+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
71480+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
71481+}
71482+#else
71483+#define atomic_read_unchecked(v) atomic_read(v)
71484+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
71485+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
71486+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
71487+#define atomic_inc_unchecked(v) atomic_inc(v)
71488+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
71489+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
71490+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
71491+#define atomic_dec_unchecked(v) atomic_dec(v)
71492+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
71493+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
71494+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
71495+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
71496+
71497+#define atomic_long_read_unchecked(v) atomic_long_read(v)
71498+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
71499+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
71500+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
71501+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
71502+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
71503+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
71504+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
71505+#endif
71506+
71507 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
71508diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
71509index 33bd2de..f31bff97 100644
71510--- a/include/asm-generic/atomic.h
71511+++ b/include/asm-generic/atomic.h
71512@@ -153,7 +153,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
71513 * Atomically clears the bits set in @mask from @v
71514 */
71515 #ifndef atomic_clear_mask
71516-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
71517+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
71518 {
71519 unsigned long flags;
71520
71521diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
71522index b18ce4f..2ee2843 100644
71523--- a/include/asm-generic/atomic64.h
71524+++ b/include/asm-generic/atomic64.h
71525@@ -16,6 +16,8 @@ typedef struct {
71526 long long counter;
71527 } atomic64_t;
71528
71529+typedef atomic64_t atomic64_unchecked_t;
71530+
71531 #define ATOMIC64_INIT(i) { (i) }
71532
71533 extern long long atomic64_read(const atomic64_t *v);
71534@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
71535 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
71536 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
71537
71538+#define atomic64_read_unchecked(v) atomic64_read(v)
71539+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
71540+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
71541+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
71542+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
71543+#define atomic64_inc_unchecked(v) atomic64_inc(v)
71544+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
71545+#define atomic64_dec_unchecked(v) atomic64_dec(v)
71546+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
71547+
71548 #endif /* _ASM_GENERIC_ATOMIC64_H */
71549diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
71550index 1bfcfe5..e04c5c9 100644
71551--- a/include/asm-generic/cache.h
71552+++ b/include/asm-generic/cache.h
71553@@ -6,7 +6,7 @@
71554 * cache lines need to provide their own cache.h.
71555 */
71556
71557-#define L1_CACHE_SHIFT 5
71558-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
71559+#define L1_CACHE_SHIFT 5UL
71560+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
71561
71562 #endif /* __ASM_GENERIC_CACHE_H */
71563diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
71564index 0d68a1e..b74a761 100644
71565--- a/include/asm-generic/emergency-restart.h
71566+++ b/include/asm-generic/emergency-restart.h
71567@@ -1,7 +1,7 @@
71568 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
71569 #define _ASM_GENERIC_EMERGENCY_RESTART_H
71570
71571-static inline void machine_emergency_restart(void)
71572+static inline __noreturn void machine_emergency_restart(void)
71573 {
71574 machine_restart(NULL);
71575 }
71576diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
71577index 90f99c7..00ce236 100644
71578--- a/include/asm-generic/kmap_types.h
71579+++ b/include/asm-generic/kmap_types.h
71580@@ -2,9 +2,9 @@
71581 #define _ASM_GENERIC_KMAP_TYPES_H
71582
71583 #ifdef __WITH_KM_FENCE
71584-# define KM_TYPE_NR 41
71585+# define KM_TYPE_NR 42
71586 #else
71587-# define KM_TYPE_NR 20
71588+# define KM_TYPE_NR 21
71589 #endif
71590
71591 #endif
71592diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
71593index 9ceb03b..62b0b8f 100644
71594--- a/include/asm-generic/local.h
71595+++ b/include/asm-generic/local.h
71596@@ -23,24 +23,37 @@ typedef struct
71597 atomic_long_t a;
71598 } local_t;
71599
71600+typedef struct {
71601+ atomic_long_unchecked_t a;
71602+} local_unchecked_t;
71603+
71604 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
71605
71606 #define local_read(l) atomic_long_read(&(l)->a)
71607+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
71608 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
71609+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
71610 #define local_inc(l) atomic_long_inc(&(l)->a)
71611+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
71612 #define local_dec(l) atomic_long_dec(&(l)->a)
71613+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
71614 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
71615+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
71616 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
71617+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
71618
71619 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
71620 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
71621 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
71622 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
71623 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
71624+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
71625 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
71626 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
71627+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
71628
71629 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
71630+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
71631 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
71632 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
71633 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
71634diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
71635index 725612b..9cc513a 100644
71636--- a/include/asm-generic/pgtable-nopmd.h
71637+++ b/include/asm-generic/pgtable-nopmd.h
71638@@ -1,14 +1,19 @@
71639 #ifndef _PGTABLE_NOPMD_H
71640 #define _PGTABLE_NOPMD_H
71641
71642-#ifndef __ASSEMBLY__
71643-
71644 #include <asm-generic/pgtable-nopud.h>
71645
71646-struct mm_struct;
71647-
71648 #define __PAGETABLE_PMD_FOLDED
71649
71650+#define PMD_SHIFT PUD_SHIFT
71651+#define PTRS_PER_PMD 1
71652+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
71653+#define PMD_MASK (~(PMD_SIZE-1))
71654+
71655+#ifndef __ASSEMBLY__
71656+
71657+struct mm_struct;
71658+
71659 /*
71660 * Having the pmd type consist of a pud gets the size right, and allows
71661 * us to conceptually access the pud entry that this pmd is folded into
71662@@ -16,11 +21,6 @@ struct mm_struct;
71663 */
71664 typedef struct { pud_t pud; } pmd_t;
71665
71666-#define PMD_SHIFT PUD_SHIFT
71667-#define PTRS_PER_PMD 1
71668-#define PMD_SIZE (1UL << PMD_SHIFT)
71669-#define PMD_MASK (~(PMD_SIZE-1))
71670-
71671 /*
71672 * The "pud_xxx()" functions here are trivial for a folded two-level
71673 * setup: the pmd is never bad, and a pmd always exists (as it's folded
71674diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
71675index 810431d..0ec4804f 100644
71676--- a/include/asm-generic/pgtable-nopud.h
71677+++ b/include/asm-generic/pgtable-nopud.h
71678@@ -1,10 +1,15 @@
71679 #ifndef _PGTABLE_NOPUD_H
71680 #define _PGTABLE_NOPUD_H
71681
71682-#ifndef __ASSEMBLY__
71683-
71684 #define __PAGETABLE_PUD_FOLDED
71685
71686+#define PUD_SHIFT PGDIR_SHIFT
71687+#define PTRS_PER_PUD 1
71688+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
71689+#define PUD_MASK (~(PUD_SIZE-1))
71690+
71691+#ifndef __ASSEMBLY__
71692+
71693 /*
71694 * Having the pud type consist of a pgd gets the size right, and allows
71695 * us to conceptually access the pgd entry that this pud is folded into
71696@@ -12,11 +17,6 @@
71697 */
71698 typedef struct { pgd_t pgd; } pud_t;
71699
71700-#define PUD_SHIFT PGDIR_SHIFT
71701-#define PTRS_PER_PUD 1
71702-#define PUD_SIZE (1UL << PUD_SHIFT)
71703-#define PUD_MASK (~(PUD_SIZE-1))
71704-
71705 /*
71706 * The "pgd_xxx()" functions here are trivial for a folded two-level
71707 * setup: the pud is never bad, and a pud always exists (as it's folded
71708@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
71709 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
71710
71711 #define pgd_populate(mm, pgd, pud) do { } while (0)
71712+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
71713 /*
71714 * (puds are folded into pgds so this doesn't get actually called,
71715 * but the define is needed for a generic inline function.)
71716diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
71717index 0807ddf..cd67747 100644
71718--- a/include/asm-generic/pgtable.h
71719+++ b/include/asm-generic/pgtable.h
71720@@ -741,6 +741,22 @@ static inline pmd_t pmd_mknuma(pmd_t pmd)
71721 }
71722 #endif /* CONFIG_NUMA_BALANCING */
71723
71724+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
71725+#ifdef CONFIG_PAX_KERNEXEC
71726+#error KERNEXEC requires pax_open_kernel
71727+#else
71728+static inline unsigned long pax_open_kernel(void) { return 0; }
71729+#endif
71730+#endif
71731+
71732+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
71733+#ifdef CONFIG_PAX_KERNEXEC
71734+#error KERNEXEC requires pax_close_kernel
71735+#else
71736+static inline unsigned long pax_close_kernel(void) { return 0; }
71737+#endif
71738+#endif
71739+
71740 #endif /* CONFIG_MMU */
71741
71742 #endif /* !__ASSEMBLY__ */
71743diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
71744index dc1269c..48a4f51 100644
71745--- a/include/asm-generic/uaccess.h
71746+++ b/include/asm-generic/uaccess.h
71747@@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
71748 return __clear_user(to, n);
71749 }
71750
71751+#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
71752+#ifdef CONFIG_PAX_MEMORY_UDEREF
71753+#error UDEREF requires pax_open_userland
71754+#else
71755+static inline unsigned long pax_open_userland(void) { return 0; }
71756+#endif
71757+#endif
71758+
71759+#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
71760+#ifdef CONFIG_PAX_MEMORY_UDEREF
71761+#error UDEREF requires pax_close_userland
71762+#else
71763+static inline unsigned long pax_close_userland(void) { return 0; }
71764+#endif
71765+#endif
71766+
71767 #endif /* __ASM_GENERIC_UACCESS_H */
71768diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
71769index 69732d2..cbe16d9 100644
71770--- a/include/asm-generic/vmlinux.lds.h
71771+++ b/include/asm-generic/vmlinux.lds.h
71772@@ -227,6 +227,7 @@
71773 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
71774 VMLINUX_SYMBOL(__start_rodata) = .; \
71775 *(.rodata) *(.rodata.*) \
71776+ *(.data..read_only) \
71777 *(__vermagic) /* Kernel version magic */ \
71778 . = ALIGN(8); \
71779 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
71780@@ -710,17 +711,18 @@
71781 * section in the linker script will go there too. @phdr should have
71782 * a leading colon.
71783 *
71784- * Note that this macros defines __per_cpu_load as an absolute symbol.
71785+ * Note that this macros defines per_cpu_load as an absolute symbol.
71786 * If there is no need to put the percpu section at a predetermined
71787 * address, use PERCPU_SECTION.
71788 */
71789 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
71790- VMLINUX_SYMBOL(__per_cpu_load) = .; \
71791- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
71792+ per_cpu_load = .; \
71793+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
71794 - LOAD_OFFSET) { \
71795+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
71796 PERCPU_INPUT(cacheline) \
71797 } phdr \
71798- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
71799+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
71800
71801 /**
71802 * PERCPU_SECTION - define output section for percpu area, simple version
71803diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
71804index 418d270..bfd2794 100644
71805--- a/include/crypto/algapi.h
71806+++ b/include/crypto/algapi.h
71807@@ -34,7 +34,7 @@ struct crypto_type {
71808 unsigned int maskclear;
71809 unsigned int maskset;
71810 unsigned int tfmsize;
71811-};
71812+} __do_const;
71813
71814 struct crypto_instance {
71815 struct crypto_alg alg;
71816diff --git a/include/drm/drmP.h b/include/drm/drmP.h
71817index 12083dc..39740ec 100644
71818--- a/include/drm/drmP.h
71819+++ b/include/drm/drmP.h
71820@@ -69,6 +69,7 @@
71821 #include <linux/workqueue.h>
71822 #include <linux/poll.h>
71823 #include <asm/pgalloc.h>
71824+#include <asm/local.h>
71825 #include <drm/drm.h>
71826 #include <drm/drm_sarea.h>
71827
71828@@ -293,10 +294,12 @@ do { \
71829 * \param cmd command.
71830 * \param arg argument.
71831 */
71832-typedef int drm_ioctl_t(struct drm_device *dev, void *data,
71833+typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
71834+ struct drm_file *file_priv);
71835+typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
71836 struct drm_file *file_priv);
71837
71838-typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
71839+typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
71840 unsigned long arg);
71841
71842 #define DRM_IOCTL_NR(n) _IOC_NR(n)
71843@@ -311,10 +314,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
71844 struct drm_ioctl_desc {
71845 unsigned int cmd;
71846 int flags;
71847- drm_ioctl_t *func;
71848+ drm_ioctl_t func;
71849 unsigned int cmd_drv;
71850 const char *name;
71851-};
71852+} __do_const;
71853
71854 /**
71855 * Creates a driver or general drm_ioctl_desc array entry for the given
71856@@ -1015,7 +1018,7 @@ struct drm_info_list {
71857 int (*show)(struct seq_file*, void*); /** show callback */
71858 u32 driver_features; /**< Required driver features for this entry */
71859 void *data;
71860-};
71861+} __do_const;
71862
71863 /**
71864 * debugfs node structure. This structure represents a debugfs file.
71865@@ -1088,7 +1091,7 @@ struct drm_device {
71866
71867 /** \name Usage Counters */
71868 /*@{ */
71869- int open_count; /**< Outstanding files open */
71870+ local_t open_count; /**< Outstanding files open */
71871 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
71872 atomic_t vma_count; /**< Outstanding vma areas open */
71873 int buf_use; /**< Buffers in use -- cannot alloc */
71874@@ -1099,7 +1102,7 @@ struct drm_device {
71875 /*@{ */
71876 unsigned long counters;
71877 enum drm_stat_type types[15];
71878- atomic_t counts[15];
71879+ atomic_unchecked_t counts[15];
71880 /*@} */
71881
71882 struct list_head filelist;
71883diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
71884index f43d556..94d9343 100644
71885--- a/include/drm/drm_crtc_helper.h
71886+++ b/include/drm/drm_crtc_helper.h
71887@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
71888 struct drm_connector *connector);
71889 /* disable encoder when not in use - more explicit than dpms off */
71890 void (*disable)(struct drm_encoder *encoder);
71891-};
71892+} __no_const;
71893
71894 /**
71895 * drm_connector_helper_funcs - helper operations for connectors
71896diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
71897index 72dcbe8..8db58d7 100644
71898--- a/include/drm/ttm/ttm_memory.h
71899+++ b/include/drm/ttm/ttm_memory.h
71900@@ -48,7 +48,7 @@
71901
71902 struct ttm_mem_shrink {
71903 int (*do_shrink) (struct ttm_mem_shrink *);
71904-};
71905+} __no_const;
71906
71907 /**
71908 * struct ttm_mem_global - Global memory accounting structure.
71909diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
71910index 4b840e8..155d235 100644
71911--- a/include/keys/asymmetric-subtype.h
71912+++ b/include/keys/asymmetric-subtype.h
71913@@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
71914 /* Verify the signature on a key of this subtype (optional) */
71915 int (*verify_signature)(const struct key *key,
71916 const struct public_key_signature *sig);
71917-};
71918+} __do_const;
71919
71920 /**
71921 * asymmetric_key_subtype - Get the subtype from an asymmetric key
71922diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
71923index c1da539..1dcec55 100644
71924--- a/include/linux/atmdev.h
71925+++ b/include/linux/atmdev.h
71926@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
71927 #endif
71928
71929 struct k_atm_aal_stats {
71930-#define __HANDLE_ITEM(i) atomic_t i
71931+#define __HANDLE_ITEM(i) atomic_unchecked_t i
71932 __AAL_STAT_ITEMS
71933 #undef __HANDLE_ITEM
71934 };
71935@@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
71936 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
71937 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
71938 struct module *owner;
71939-};
71940+} __do_const ;
71941
71942 struct atmphy_ops {
71943 int (*start)(struct atm_dev *dev);
71944diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
71945index 70cf138..0418ee2 100644
71946--- a/include/linux/binfmts.h
71947+++ b/include/linux/binfmts.h
71948@@ -73,8 +73,10 @@ struct linux_binfmt {
71949 int (*load_binary)(struct linux_binprm *);
71950 int (*load_shlib)(struct file *);
71951 int (*core_dump)(struct coredump_params *cprm);
71952+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
71953+ void (*handle_mmap)(struct file *);
71954 unsigned long min_coredump; /* minimal dump size */
71955-};
71956+} __do_const;
71957
71958 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
71959
71960diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
71961index 2fdb4a4..54aad7e 100644
71962--- a/include/linux/blkdev.h
71963+++ b/include/linux/blkdev.h
71964@@ -1526,7 +1526,7 @@ struct block_device_operations {
71965 /* this callback is with swap_lock and sometimes page table lock held */
71966 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
71967 struct module *owner;
71968-};
71969+} __do_const;
71970
71971 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
71972 unsigned long);
71973diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
71974index 7c2e030..b72475d 100644
71975--- a/include/linux/blktrace_api.h
71976+++ b/include/linux/blktrace_api.h
71977@@ -23,7 +23,7 @@ struct blk_trace {
71978 struct dentry *dir;
71979 struct dentry *dropped_file;
71980 struct dentry *msg_file;
71981- atomic_t dropped;
71982+ atomic_unchecked_t dropped;
71983 };
71984
71985 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
71986diff --git a/include/linux/cache.h b/include/linux/cache.h
71987index 4c57065..40346da 100644
71988--- a/include/linux/cache.h
71989+++ b/include/linux/cache.h
71990@@ -16,6 +16,14 @@
71991 #define __read_mostly
71992 #endif
71993
71994+#ifndef __read_only
71995+#ifdef CONFIG_PAX_KERNEXEC
71996+#error KERNEXEC requires __read_only
71997+#else
71998+#define __read_only __read_mostly
71999+#endif
72000+#endif
72001+
72002 #ifndef ____cacheline_aligned
72003 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
72004 #endif
72005diff --git a/include/linux/capability.h b/include/linux/capability.h
72006index d9a4f7f4..19f77d6 100644
72007--- a/include/linux/capability.h
72008+++ b/include/linux/capability.h
72009@@ -213,8 +213,13 @@ extern bool ns_capable(struct user_namespace *ns, int cap);
72010 extern bool nsown_capable(int cap);
72011 extern bool inode_capable(const struct inode *inode, int cap);
72012 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
72013+extern bool capable_nolog(int cap);
72014+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
72015+extern bool inode_capable_nolog(const struct inode *inode, int cap);
72016
72017 /* audit system wants to get cap info from files as well */
72018 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
72019
72020+extern int is_privileged_binary(const struct dentry *dentry);
72021+
72022 #endif /* !_LINUX_CAPABILITY_H */
72023diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
72024index 8609d57..86e4d79 100644
72025--- a/include/linux/cdrom.h
72026+++ b/include/linux/cdrom.h
72027@@ -87,7 +87,6 @@ struct cdrom_device_ops {
72028
72029 /* driver specifications */
72030 const int capability; /* capability flags */
72031- int n_minors; /* number of active minor devices */
72032 /* handle uniform packets for scsi type devices (scsi,atapi) */
72033 int (*generic_packet) (struct cdrom_device_info *,
72034 struct packet_command *);
72035diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
72036index 4ce9056..86caac6 100644
72037--- a/include/linux/cleancache.h
72038+++ b/include/linux/cleancache.h
72039@@ -31,7 +31,7 @@ struct cleancache_ops {
72040 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
72041 void (*invalidate_inode)(int, struct cleancache_filekey);
72042 void (*invalidate_fs)(int);
72043-};
72044+} __no_const;
72045
72046 extern struct cleancache_ops *
72047 cleancache_register_ops(struct cleancache_ops *ops);
72048diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
72049index 1ec14a7..d0654a2 100644
72050--- a/include/linux/clk-provider.h
72051+++ b/include/linux/clk-provider.h
72052@@ -132,6 +132,7 @@ struct clk_ops {
72053 unsigned long);
72054 void (*init)(struct clk_hw *hw);
72055 };
72056+typedef struct clk_ops __no_const clk_ops_no_const;
72057
72058 /**
72059 * struct clk_init_data - holds init data that's common to all clocks and is
72060diff --git a/include/linux/compat.h b/include/linux/compat.h
72061index ec1aee4..1077986 100644
72062--- a/include/linux/compat.h
72063+++ b/include/linux/compat.h
72064@@ -312,7 +312,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
72065 compat_size_t __user *len_ptr);
72066
72067 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
72068-asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
72069+asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
72070 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
72071 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
72072 compat_ssize_t msgsz, int msgflg);
72073@@ -419,7 +419,7 @@ extern int compat_ptrace_request(struct task_struct *child,
72074 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
72075 compat_ulong_t addr, compat_ulong_t data);
72076 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
72077- compat_long_t addr, compat_long_t data);
72078+ compat_ulong_t addr, compat_ulong_t data);
72079
72080 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, size_t);
72081 /*
72082diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
72083index 842de22..7f3a41f 100644
72084--- a/include/linux/compiler-gcc4.h
72085+++ b/include/linux/compiler-gcc4.h
72086@@ -39,9 +39,29 @@
72087 # define __compiletime_warning(message) __attribute__((warning(message)))
72088 # define __compiletime_error(message) __attribute__((error(message)))
72089 #endif /* __CHECKER__ */
72090+
72091+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
72092+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
72093+#define __bos0(ptr) __bos((ptr), 0)
72094+#define __bos1(ptr) __bos((ptr), 1)
72095 #endif /* GCC_VERSION >= 40300 */
72096
72097 #if GCC_VERSION >= 40500
72098+
72099+#ifdef CONSTIFY_PLUGIN
72100+#define __no_const __attribute__((no_const))
72101+#define __do_const __attribute__((do_const))
72102+#endif
72103+
72104+#ifdef SIZE_OVERFLOW_PLUGIN
72105+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
72106+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
72107+#endif
72108+
72109+#ifdef LATENT_ENTROPY_PLUGIN
72110+#define __latent_entropy __attribute__((latent_entropy))
72111+#endif
72112+
72113 /*
72114 * Mark a position in code as unreachable. This can be used to
72115 * suppress control flow warnings after asm blocks that transfer
72116diff --git a/include/linux/compiler.h b/include/linux/compiler.h
72117index 92669cd..1771a15 100644
72118--- a/include/linux/compiler.h
72119+++ b/include/linux/compiler.h
72120@@ -5,11 +5,14 @@
72121
72122 #ifdef __CHECKER__
72123 # define __user __attribute__((noderef, address_space(1)))
72124+# define __force_user __force __user
72125 # define __kernel __attribute__((address_space(0)))
72126+# define __force_kernel __force __kernel
72127 # define __safe __attribute__((safe))
72128 # define __force __attribute__((force))
72129 # define __nocast __attribute__((nocast))
72130 # define __iomem __attribute__((noderef, address_space(2)))
72131+# define __force_iomem __force __iomem
72132 # define __must_hold(x) __attribute__((context(x,1,1)))
72133 # define __acquires(x) __attribute__((context(x,0,1)))
72134 # define __releases(x) __attribute__((context(x,1,0)))
72135@@ -17,20 +20,37 @@
72136 # define __release(x) __context__(x,-1)
72137 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
72138 # define __percpu __attribute__((noderef, address_space(3)))
72139+# define __force_percpu __force __percpu
72140 #ifdef CONFIG_SPARSE_RCU_POINTER
72141 # define __rcu __attribute__((noderef, address_space(4)))
72142+# define __force_rcu __force __rcu
72143 #else
72144 # define __rcu
72145+# define __force_rcu
72146 #endif
72147 extern void __chk_user_ptr(const volatile void __user *);
72148 extern void __chk_io_ptr(const volatile void __iomem *);
72149 #else
72150-# define __user
72151-# define __kernel
72152+# ifdef CHECKER_PLUGIN
72153+//# define __user
72154+//# define __force_user
72155+//# define __kernel
72156+//# define __force_kernel
72157+# else
72158+# ifdef STRUCTLEAK_PLUGIN
72159+# define __user __attribute__((user))
72160+# else
72161+# define __user
72162+# endif
72163+# define __force_user
72164+# define __kernel
72165+# define __force_kernel
72166+# endif
72167 # define __safe
72168 # define __force
72169 # define __nocast
72170 # define __iomem
72171+# define __force_iomem
72172 # define __chk_user_ptr(x) (void)0
72173 # define __chk_io_ptr(x) (void)0
72174 # define __builtin_warning(x, y...) (1)
72175@@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
72176 # define __release(x) (void)0
72177 # define __cond_lock(x,c) (c)
72178 # define __percpu
72179+# define __force_percpu
72180 # define __rcu
72181+# define __force_rcu
72182 #endif
72183
72184 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
72185@@ -275,6 +297,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
72186 # define __attribute_const__ /* unimplemented */
72187 #endif
72188
72189+#ifndef __no_const
72190+# define __no_const
72191+#endif
72192+
72193+#ifndef __do_const
72194+# define __do_const
72195+#endif
72196+
72197+#ifndef __size_overflow
72198+# define __size_overflow(...)
72199+#endif
72200+
72201+#ifndef __intentional_overflow
72202+# define __intentional_overflow(...)
72203+#endif
72204+
72205+#ifndef __latent_entropy
72206+# define __latent_entropy
72207+#endif
72208+
72209 /*
72210 * Tell gcc if a function is cold. The compiler will assume any path
72211 * directly leading to the call is unlikely.
72212@@ -284,6 +326,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
72213 #define __cold
72214 #endif
72215
72216+#ifndef __alloc_size
72217+#define __alloc_size(...)
72218+#endif
72219+
72220+#ifndef __bos
72221+#define __bos(ptr, arg)
72222+#endif
72223+
72224+#ifndef __bos0
72225+#define __bos0(ptr)
72226+#endif
72227+
72228+#ifndef __bos1
72229+#define __bos1(ptr)
72230+#endif
72231+
72232 /* Simple shorthand for a section definition */
72233 #ifndef __section
72234 # define __section(S) __attribute__ ((__section__(#S)))
72235@@ -349,7 +407,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
72236 * use is to mediate communication between process-level code and irq/NMI
72237 * handlers, all running on the same CPU.
72238 */
72239-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
72240+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
72241+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
72242
72243 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
72244 #ifdef CONFIG_KPROBES
72245diff --git a/include/linux/completion.h b/include/linux/completion.h
72246index 3cd574d..adce5fa 100644
72247--- a/include/linux/completion.h
72248+++ b/include/linux/completion.h
72249@@ -79,15 +79,15 @@ static inline void init_completion(struct completion *x)
72250 extern void wait_for_completion(struct completion *);
72251 extern void wait_for_completion_io(struct completion *);
72252 extern int wait_for_completion_interruptible(struct completion *x);
72253-extern int wait_for_completion_killable(struct completion *x);
72254+extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
72255 extern unsigned long wait_for_completion_timeout(struct completion *x,
72256 unsigned long timeout);
72257 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
72258 unsigned long timeout);
72259 extern long wait_for_completion_interruptible_timeout(
72260- struct completion *x, unsigned long timeout);
72261+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
72262 extern long wait_for_completion_killable_timeout(
72263- struct completion *x, unsigned long timeout);
72264+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
72265 extern bool try_wait_for_completion(struct completion *x);
72266 extern bool completion_done(struct completion *x);
72267
72268diff --git a/include/linux/configfs.h b/include/linux/configfs.h
72269index 34025df..d94bbbc 100644
72270--- a/include/linux/configfs.h
72271+++ b/include/linux/configfs.h
72272@@ -125,7 +125,7 @@ struct configfs_attribute {
72273 const char *ca_name;
72274 struct module *ca_owner;
72275 umode_t ca_mode;
72276-};
72277+} __do_const;
72278
72279 /*
72280 * Users often need to create attribute structures for their configurable
72281diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
72282index 90d5a15..950cb80 100644
72283--- a/include/linux/cpufreq.h
72284+++ b/include/linux/cpufreq.h
72285@@ -266,7 +266,7 @@ struct cpufreq_driver {
72286 int (*suspend) (struct cpufreq_policy *policy);
72287 int (*resume) (struct cpufreq_policy *policy);
72288 struct freq_attr **attr;
72289-};
72290+} __do_const;
72291
72292 /* flags */
72293
72294@@ -325,6 +325,7 @@ struct global_attr {
72295 ssize_t (*store)(struct kobject *a, struct attribute *b,
72296 const char *c, size_t count);
72297 };
72298+typedef struct global_attr __no_const global_attr_no_const;
72299
72300 #define define_one_global_ro(_name) \
72301 static struct global_attr _name = \
72302diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
72303index 0bc4b74..973b368 100644
72304--- a/include/linux/cpuidle.h
72305+++ b/include/linux/cpuidle.h
72306@@ -52,7 +52,8 @@ struct cpuidle_state {
72307 int index);
72308
72309 int (*enter_dead) (struct cpuidle_device *dev, int index);
72310-};
72311+} __do_const;
72312+typedef struct cpuidle_state __no_const cpuidle_state_no_const;
72313
72314 /* Idle State Flags */
72315 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
72316@@ -191,7 +192,7 @@ struct cpuidle_governor {
72317 void (*reflect) (struct cpuidle_device *dev, int index);
72318
72319 struct module *owner;
72320-};
72321+} __do_const;
72322
72323 #ifdef CONFIG_CPU_IDLE
72324
72325diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
72326index d08e4d2..95fad61 100644
72327--- a/include/linux/cpumask.h
72328+++ b/include/linux/cpumask.h
72329@@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
72330 }
72331
72332 /* Valid inputs for n are -1 and 0. */
72333-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
72334+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
72335 {
72336 return n+1;
72337 }
72338
72339-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
72340+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
72341 {
72342 return n+1;
72343 }
72344
72345-static inline unsigned int cpumask_next_and(int n,
72346+static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
72347 const struct cpumask *srcp,
72348 const struct cpumask *andp)
72349 {
72350@@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
72351 *
72352 * Returns >= nr_cpu_ids if no further cpus set.
72353 */
72354-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
72355+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
72356 {
72357 /* -1 is a legal arg here. */
72358 if (n != -1)
72359@@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
72360 *
72361 * Returns >= nr_cpu_ids if no further cpus unset.
72362 */
72363-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
72364+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
72365 {
72366 /* -1 is a legal arg here. */
72367 if (n != -1)
72368@@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
72369 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
72370 }
72371
72372-int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
72373+int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
72374 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
72375
72376 /**
72377diff --git a/include/linux/cred.h b/include/linux/cred.h
72378index 04421e8..6bce4ef 100644
72379--- a/include/linux/cred.h
72380+++ b/include/linux/cred.h
72381@@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
72382 static inline void validate_process_creds(void)
72383 {
72384 }
72385+static inline void validate_task_creds(struct task_struct *task)
72386+{
72387+}
72388 #endif
72389
72390 /**
72391diff --git a/include/linux/crypto.h b/include/linux/crypto.h
72392index b92eadf..b4ecdc1 100644
72393--- a/include/linux/crypto.h
72394+++ b/include/linux/crypto.h
72395@@ -373,7 +373,7 @@ struct cipher_tfm {
72396 const u8 *key, unsigned int keylen);
72397 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
72398 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
72399-};
72400+} __no_const;
72401
72402 struct hash_tfm {
72403 int (*init)(struct hash_desc *desc);
72404@@ -394,13 +394,13 @@ struct compress_tfm {
72405 int (*cot_decompress)(struct crypto_tfm *tfm,
72406 const u8 *src, unsigned int slen,
72407 u8 *dst, unsigned int *dlen);
72408-};
72409+} __no_const;
72410
72411 struct rng_tfm {
72412 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
72413 unsigned int dlen);
72414 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
72415-};
72416+} __no_const;
72417
72418 #define crt_ablkcipher crt_u.ablkcipher
72419 #define crt_aead crt_u.aead
72420diff --git a/include/linux/ctype.h b/include/linux/ctype.h
72421index 653589e..4ef254a 100644
72422--- a/include/linux/ctype.h
72423+++ b/include/linux/ctype.h
72424@@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
72425 * Fast implementation of tolower() for internal usage. Do not use in your
72426 * code.
72427 */
72428-static inline char _tolower(const char c)
72429+static inline unsigned char _tolower(const unsigned char c)
72430 {
72431 return c | 0x20;
72432 }
72433diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
72434index 7925bf0..d5143d2 100644
72435--- a/include/linux/decompress/mm.h
72436+++ b/include/linux/decompress/mm.h
72437@@ -77,7 +77,7 @@ static void free(void *where)
72438 * warnings when not needed (indeed large_malloc / large_free are not
72439 * needed by inflate */
72440
72441-#define malloc(a) kmalloc(a, GFP_KERNEL)
72442+#define malloc(a) kmalloc((a), GFP_KERNEL)
72443 #define free(a) kfree(a)
72444
72445 #define large_malloc(a) vmalloc(a)
72446diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
72447index 5f1ab92..39c35ae 100644
72448--- a/include/linux/devfreq.h
72449+++ b/include/linux/devfreq.h
72450@@ -114,7 +114,7 @@ struct devfreq_governor {
72451 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
72452 int (*event_handler)(struct devfreq *devfreq,
72453 unsigned int event, void *data);
72454-};
72455+} __do_const;
72456
72457 /**
72458 * struct devfreq - Device devfreq structure
72459diff --git a/include/linux/device.h b/include/linux/device.h
72460index 22b546a..a573dc9 100644
72461--- a/include/linux/device.h
72462+++ b/include/linux/device.h
72463@@ -305,7 +305,7 @@ struct subsys_interface {
72464 struct list_head node;
72465 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
72466 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
72467-};
72468+} __do_const;
72469
72470 int subsys_interface_register(struct subsys_interface *sif);
72471 void subsys_interface_unregister(struct subsys_interface *sif);
72472@@ -493,7 +493,7 @@ struct device_type {
72473 void (*release)(struct device *dev);
72474
72475 const struct dev_pm_ops *pm;
72476-};
72477+} __do_const;
72478
72479 /* interface for exporting device attributes */
72480 struct device_attribute {
72481@@ -503,11 +503,12 @@ struct device_attribute {
72482 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
72483 const char *buf, size_t count);
72484 };
72485+typedef struct device_attribute __no_const device_attribute_no_const;
72486
72487 struct dev_ext_attribute {
72488 struct device_attribute attr;
72489 void *var;
72490-};
72491+} __do_const;
72492
72493 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
72494 char *buf);
72495diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
72496index 94af418..b1ca7a2 100644
72497--- a/include/linux/dma-mapping.h
72498+++ b/include/linux/dma-mapping.h
72499@@ -54,7 +54,7 @@ struct dma_map_ops {
72500 u64 (*get_required_mask)(struct device *dev);
72501 #endif
72502 int is_phys;
72503-};
72504+} __do_const;
72505
72506 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
72507
72508diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
72509index cb286b1..923d066 100644
72510--- a/include/linux/dmaengine.h
72511+++ b/include/linux/dmaengine.h
72512@@ -1030,9 +1030,9 @@ struct dma_pinned_list {
72513 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
72514 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
72515
72516-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
72517+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
72518 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
72519-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
72520+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
72521 struct dma_pinned_list *pinned_list, struct page *page,
72522 unsigned int offset, size_t len);
72523
72524diff --git a/include/linux/efi.h b/include/linux/efi.h
72525index 5f8f176..62a0556 100644
72526--- a/include/linux/efi.h
72527+++ b/include/linux/efi.h
72528@@ -745,6 +745,7 @@ struct efivar_operations {
72529 efi_set_variable_t *set_variable;
72530 efi_query_variable_store_t *query_variable_store;
72531 };
72532+typedef struct efivar_operations __no_const efivar_operations_no_const;
72533
72534 struct efivars {
72535 /*
72536diff --git a/include/linux/elf.h b/include/linux/elf.h
72537index 40a3c0e..4c45a38 100644
72538--- a/include/linux/elf.h
72539+++ b/include/linux/elf.h
72540@@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
72541 #define elf_note elf32_note
72542 #define elf_addr_t Elf32_Off
72543 #define Elf_Half Elf32_Half
72544+#define elf_dyn Elf32_Dyn
72545
72546 #else
72547
72548@@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
72549 #define elf_note elf64_note
72550 #define elf_addr_t Elf64_Off
72551 #define Elf_Half Elf64_Half
72552+#define elf_dyn Elf64_Dyn
72553
72554 #endif
72555
72556diff --git a/include/linux/err.h b/include/linux/err.h
72557index 221fcfb..f29e5e2 100644
72558--- a/include/linux/err.h
72559+++ b/include/linux/err.h
72560@@ -19,12 +19,12 @@
72561
72562 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
72563
72564-static inline void * __must_check ERR_PTR(long error)
72565+static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
72566 {
72567 return (void *) error;
72568 }
72569
72570-static inline long __must_check PTR_ERR(__force const void *ptr)
72571+static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
72572 {
72573 return (long) ptr;
72574 }
72575diff --git a/include/linux/extcon.h b/include/linux/extcon.h
72576index fcb51c8..bdafcf6 100644
72577--- a/include/linux/extcon.h
72578+++ b/include/linux/extcon.h
72579@@ -134,7 +134,7 @@ struct extcon_dev {
72580 /* /sys/class/extcon/.../mutually_exclusive/... */
72581 struct attribute_group attr_g_muex;
72582 struct attribute **attrs_muex;
72583- struct device_attribute *d_attrs_muex;
72584+ device_attribute_no_const *d_attrs_muex;
72585 };
72586
72587 /**
72588diff --git a/include/linux/fb.h b/include/linux/fb.h
72589index ffac70a..ca3e711 100644
72590--- a/include/linux/fb.h
72591+++ b/include/linux/fb.h
72592@@ -304,7 +304,7 @@ struct fb_ops {
72593 /* called at KDB enter and leave time to prepare the console */
72594 int (*fb_debug_enter)(struct fb_info *info);
72595 int (*fb_debug_leave)(struct fb_info *info);
72596-};
72597+} __do_const;
72598
72599 #ifdef CONFIG_FB_TILEBLITTING
72600 #define FB_TILE_CURSOR_NONE 0
72601diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
72602index 085197b..0fa6f0b 100644
72603--- a/include/linux/fdtable.h
72604+++ b/include/linux/fdtable.h
72605@@ -95,7 +95,7 @@ struct files_struct *get_files_struct(struct task_struct *);
72606 void put_files_struct(struct files_struct *fs);
72607 void reset_files_struct(struct files_struct *);
72608 int unshare_files(struct files_struct **);
72609-struct files_struct *dup_fd(struct files_struct *, int *);
72610+struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
72611 void do_close_on_exec(struct files_struct *);
72612 int iterate_fd(struct files_struct *, unsigned,
72613 int (*)(const void *, struct file *, unsigned),
72614diff --git a/include/linux/filter.h b/include/linux/filter.h
72615index a6ac848..a104a76 100644
72616--- a/include/linux/filter.h
72617+++ b/include/linux/filter.h
72618@@ -20,6 +20,7 @@ struct compat_sock_fprog {
72619
72620 struct sk_buff;
72621 struct sock;
72622+struct bpf_jit_work;
72623
72624 struct sk_filter
72625 {
72626@@ -27,6 +28,9 @@ struct sk_filter
72627 unsigned int len; /* Number of filter blocks */
72628 unsigned int (*bpf_func)(const struct sk_buff *skb,
72629 const struct sock_filter *filter);
72630+#ifdef CONFIG_BPF_JIT
72631+ struct bpf_jit_work *work;
72632+#endif
72633 struct rcu_head rcu;
72634 struct sock_filter insns[0];
72635 };
72636diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
72637index 8293262..2b3b8bd 100644
72638--- a/include/linux/frontswap.h
72639+++ b/include/linux/frontswap.h
72640@@ -11,7 +11,7 @@ struct frontswap_ops {
72641 int (*load)(unsigned, pgoff_t, struct page *);
72642 void (*invalidate_page)(unsigned, pgoff_t);
72643 void (*invalidate_area)(unsigned);
72644-};
72645+} __no_const;
72646
72647 extern bool frontswap_enabled;
72648 extern struct frontswap_ops *
72649diff --git a/include/linux/fs.h b/include/linux/fs.h
72650index 9818747..788bfbd 100644
72651--- a/include/linux/fs.h
72652+++ b/include/linux/fs.h
72653@@ -1554,7 +1554,8 @@ struct file_operations {
72654 long (*fallocate)(struct file *file, int mode, loff_t offset,
72655 loff_t len);
72656 int (*show_fdinfo)(struct seq_file *m, struct file *f);
72657-};
72658+} __do_const;
72659+typedef struct file_operations __no_const file_operations_no_const;
72660
72661 struct inode_operations {
72662 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
72663@@ -2740,4 +2741,14 @@ static inline bool dir_relax(struct inode *inode)
72664 return !IS_DEADDIR(inode);
72665 }
72666
72667+static inline bool is_sidechannel_device(const struct inode *inode)
72668+{
72669+#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
72670+ umode_t mode = inode->i_mode;
72671+ return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
72672+#else
72673+ return false;
72674+#endif
72675+}
72676+
72677 #endif /* _LINUX_FS_H */
72678diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
72679index 2b93a9a..855d94a 100644
72680--- a/include/linux/fs_struct.h
72681+++ b/include/linux/fs_struct.h
72682@@ -6,7 +6,7 @@
72683 #include <linux/seqlock.h>
72684
72685 struct fs_struct {
72686- int users;
72687+ atomic_t users;
72688 spinlock_t lock;
72689 seqcount_t seq;
72690 int umask;
72691diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
72692index a9ff9a3..1ba1788 100644
72693--- a/include/linux/fscache-cache.h
72694+++ b/include/linux/fscache-cache.h
72695@@ -113,7 +113,7 @@ struct fscache_operation {
72696 fscache_operation_release_t release;
72697 };
72698
72699-extern atomic_t fscache_op_debug_id;
72700+extern atomic_unchecked_t fscache_op_debug_id;
72701 extern void fscache_op_work_func(struct work_struct *work);
72702
72703 extern void fscache_enqueue_operation(struct fscache_operation *);
72704@@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
72705 INIT_WORK(&op->work, fscache_op_work_func);
72706 atomic_set(&op->usage, 1);
72707 op->state = FSCACHE_OP_ST_INITIALISED;
72708- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
72709+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
72710 op->processor = processor;
72711 op->release = release;
72712 INIT_LIST_HEAD(&op->pend_link);
72713diff --git a/include/linux/fscache.h b/include/linux/fscache.h
72714index 7a08623..4c07b0f 100644
72715--- a/include/linux/fscache.h
72716+++ b/include/linux/fscache.h
72717@@ -152,7 +152,7 @@ struct fscache_cookie_def {
72718 * - this is mandatory for any object that may have data
72719 */
72720 void (*now_uncached)(void *cookie_netfs_data);
72721-};
72722+} __do_const;
72723
72724 /*
72725 * fscache cached network filesystem type
72726diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
72727index 1c804b0..1432c2b 100644
72728--- a/include/linux/fsnotify.h
72729+++ b/include/linux/fsnotify.h
72730@@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
72731 struct inode *inode = file_inode(file);
72732 __u32 mask = FS_ACCESS;
72733
72734+ if (is_sidechannel_device(inode))
72735+ return;
72736+
72737 if (S_ISDIR(inode->i_mode))
72738 mask |= FS_ISDIR;
72739
72740@@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
72741 struct inode *inode = file_inode(file);
72742 __u32 mask = FS_MODIFY;
72743
72744+ if (is_sidechannel_device(inode))
72745+ return;
72746+
72747 if (S_ISDIR(inode->i_mode))
72748 mask |= FS_ISDIR;
72749
72750@@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
72751 */
72752 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
72753 {
72754- return kstrdup(name, GFP_KERNEL);
72755+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
72756 }
72757
72758 /*
72759diff --git a/include/linux/genhd.h b/include/linux/genhd.h
72760index 9f3c275..8bdff5d 100644
72761--- a/include/linux/genhd.h
72762+++ b/include/linux/genhd.h
72763@@ -194,7 +194,7 @@ struct gendisk {
72764 struct kobject *slave_dir;
72765
72766 struct timer_rand_state *random;
72767- atomic_t sync_io; /* RAID */
72768+ atomic_unchecked_t sync_io; /* RAID */
72769 struct disk_events *ev;
72770 #ifdef CONFIG_BLK_DEV_INTEGRITY
72771 struct blk_integrity *integrity;
72772@@ -435,7 +435,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
72773 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
72774
72775 /* drivers/char/random.c */
72776-extern void add_disk_randomness(struct gendisk *disk);
72777+extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
72778 extern void rand_initialize_disk(struct gendisk *disk);
72779
72780 static inline sector_t get_start_sect(struct block_device *bdev)
72781diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
72782index 023bc34..b02b46a 100644
72783--- a/include/linux/genl_magic_func.h
72784+++ b/include/linux/genl_magic_func.h
72785@@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
72786 },
72787
72788 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
72789-static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
72790+static struct genl_ops ZZZ_genl_ops[] = {
72791 #include GENL_MAGIC_INCLUDE_FILE
72792 };
72793
72794diff --git a/include/linux/gfp.h b/include/linux/gfp.h
72795index 9b4dd49..61fd41d 100644
72796--- a/include/linux/gfp.h
72797+++ b/include/linux/gfp.h
72798@@ -35,6 +35,13 @@ struct vm_area_struct;
72799 #define ___GFP_NO_KSWAPD 0x400000u
72800 #define ___GFP_OTHER_NODE 0x800000u
72801 #define ___GFP_WRITE 0x1000000u
72802+
72803+#ifdef CONFIG_PAX_USERCOPY_SLABS
72804+#define ___GFP_USERCOPY 0x2000000u
72805+#else
72806+#define ___GFP_USERCOPY 0
72807+#endif
72808+
72809 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
72810
72811 /*
72812@@ -92,6 +99,7 @@ struct vm_area_struct;
72813 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
72814 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
72815 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
72816+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
72817
72818 /*
72819 * This may seem redundant, but it's a way of annotating false positives vs.
72820@@ -99,7 +107,7 @@ struct vm_area_struct;
72821 */
72822 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
72823
72824-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
72825+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
72826 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
72827
72828 /* This equals 0, but use constants in case they ever change */
72829@@ -153,6 +161,8 @@ struct vm_area_struct;
72830 /* 4GB DMA on some platforms */
72831 #define GFP_DMA32 __GFP_DMA32
72832
72833+#define GFP_USERCOPY __GFP_USERCOPY
72834+
72835 /* Convert GFP flags to their corresponding migrate type */
72836 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
72837 {
72838diff --git a/include/linux/gracl.h b/include/linux/gracl.h
72839new file mode 100644
72840index 0000000..ebe6d72
72841--- /dev/null
72842+++ b/include/linux/gracl.h
72843@@ -0,0 +1,319 @@
72844+#ifndef GR_ACL_H
72845+#define GR_ACL_H
72846+
72847+#include <linux/grdefs.h>
72848+#include <linux/resource.h>
72849+#include <linux/capability.h>
72850+#include <linux/dcache.h>
72851+#include <asm/resource.h>
72852+
72853+/* Major status information */
72854+
72855+#define GR_VERSION "grsecurity 2.9.1"
72856+#define GRSECURITY_VERSION 0x2901
72857+
72858+enum {
72859+ GR_SHUTDOWN = 0,
72860+ GR_ENABLE = 1,
72861+ GR_SPROLE = 2,
72862+ GR_RELOAD = 3,
72863+ GR_SEGVMOD = 4,
72864+ GR_STATUS = 5,
72865+ GR_UNSPROLE = 6,
72866+ GR_PASSSET = 7,
72867+ GR_SPROLEPAM = 8,
72868+};
72869+
72870+/* Password setup definitions
72871+ * kernel/grhash.c */
72872+enum {
72873+ GR_PW_LEN = 128,
72874+ GR_SALT_LEN = 16,
72875+ GR_SHA_LEN = 32,
72876+};
72877+
72878+enum {
72879+ GR_SPROLE_LEN = 64,
72880+};
72881+
72882+enum {
72883+ GR_NO_GLOB = 0,
72884+ GR_REG_GLOB,
72885+ GR_CREATE_GLOB
72886+};
72887+
72888+#define GR_NLIMITS 32
72889+
72890+/* Begin Data Structures */
72891+
72892+struct sprole_pw {
72893+ unsigned char *rolename;
72894+ unsigned char salt[GR_SALT_LEN];
72895+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
72896+};
72897+
72898+struct name_entry {
72899+ __u32 key;
72900+ ino_t inode;
72901+ dev_t device;
72902+ char *name;
72903+ __u16 len;
72904+ __u8 deleted;
72905+ struct name_entry *prev;
72906+ struct name_entry *next;
72907+};
72908+
72909+struct inodev_entry {
72910+ struct name_entry *nentry;
72911+ struct inodev_entry *prev;
72912+ struct inodev_entry *next;
72913+};
72914+
72915+struct acl_role_db {
72916+ struct acl_role_label **r_hash;
72917+ __u32 r_size;
72918+};
72919+
72920+struct inodev_db {
72921+ struct inodev_entry **i_hash;
72922+ __u32 i_size;
72923+};
72924+
72925+struct name_db {
72926+ struct name_entry **n_hash;
72927+ __u32 n_size;
72928+};
72929+
72930+struct crash_uid {
72931+ uid_t uid;
72932+ unsigned long expires;
72933+};
72934+
72935+struct gr_hash_struct {
72936+ void **table;
72937+ void **nametable;
72938+ void *first;
72939+ __u32 table_size;
72940+ __u32 used_size;
72941+ int type;
72942+};
72943+
72944+/* Userspace Grsecurity ACL data structures */
72945+
72946+struct acl_subject_label {
72947+ char *filename;
72948+ ino_t inode;
72949+ dev_t device;
72950+ __u32 mode;
72951+ kernel_cap_t cap_mask;
72952+ kernel_cap_t cap_lower;
72953+ kernel_cap_t cap_invert_audit;
72954+
72955+ struct rlimit res[GR_NLIMITS];
72956+ __u32 resmask;
72957+
72958+ __u8 user_trans_type;
72959+ __u8 group_trans_type;
72960+ uid_t *user_transitions;
72961+ gid_t *group_transitions;
72962+ __u16 user_trans_num;
72963+ __u16 group_trans_num;
72964+
72965+ __u32 sock_families[2];
72966+ __u32 ip_proto[8];
72967+ __u32 ip_type;
72968+ struct acl_ip_label **ips;
72969+ __u32 ip_num;
72970+ __u32 inaddr_any_override;
72971+
72972+ __u32 crashes;
72973+ unsigned long expires;
72974+
72975+ struct acl_subject_label *parent_subject;
72976+ struct gr_hash_struct *hash;
72977+ struct acl_subject_label *prev;
72978+ struct acl_subject_label *next;
72979+
72980+ struct acl_object_label **obj_hash;
72981+ __u32 obj_hash_size;
72982+ __u16 pax_flags;
72983+};
72984+
72985+struct role_allowed_ip {
72986+ __u32 addr;
72987+ __u32 netmask;
72988+
72989+ struct role_allowed_ip *prev;
72990+ struct role_allowed_ip *next;
72991+};
72992+
72993+struct role_transition {
72994+ char *rolename;
72995+
72996+ struct role_transition *prev;
72997+ struct role_transition *next;
72998+};
72999+
73000+struct acl_role_label {
73001+ char *rolename;
73002+ uid_t uidgid;
73003+ __u16 roletype;
73004+
73005+ __u16 auth_attempts;
73006+ unsigned long expires;
73007+
73008+ struct acl_subject_label *root_label;
73009+ struct gr_hash_struct *hash;
73010+
73011+ struct acl_role_label *prev;
73012+ struct acl_role_label *next;
73013+
73014+ struct role_transition *transitions;
73015+ struct role_allowed_ip *allowed_ips;
73016+ uid_t *domain_children;
73017+ __u16 domain_child_num;
73018+
73019+ umode_t umask;
73020+
73021+ struct acl_subject_label **subj_hash;
73022+ __u32 subj_hash_size;
73023+};
73024+
73025+struct user_acl_role_db {
73026+ struct acl_role_label **r_table;
73027+ __u32 num_pointers; /* Number of allocations to track */
73028+ __u32 num_roles; /* Number of roles */
73029+ __u32 num_domain_children; /* Number of domain children */
73030+ __u32 num_subjects; /* Number of subjects */
73031+ __u32 num_objects; /* Number of objects */
73032+};
73033+
73034+struct acl_object_label {
73035+ char *filename;
73036+ ino_t inode;
73037+ dev_t device;
73038+ __u32 mode;
73039+
73040+ struct acl_subject_label *nested;
73041+ struct acl_object_label *globbed;
73042+
73043+ /* next two structures not used */
73044+
73045+ struct acl_object_label *prev;
73046+ struct acl_object_label *next;
73047+};
73048+
73049+struct acl_ip_label {
73050+ char *iface;
73051+ __u32 addr;
73052+ __u32 netmask;
73053+ __u16 low, high;
73054+ __u8 mode;
73055+ __u32 type;
73056+ __u32 proto[8];
73057+
73058+ /* next two structures not used */
73059+
73060+ struct acl_ip_label *prev;
73061+ struct acl_ip_label *next;
73062+};
73063+
73064+struct gr_arg {
73065+ struct user_acl_role_db role_db;
73066+ unsigned char pw[GR_PW_LEN];
73067+ unsigned char salt[GR_SALT_LEN];
73068+ unsigned char sum[GR_SHA_LEN];
73069+ unsigned char sp_role[GR_SPROLE_LEN];
73070+ struct sprole_pw *sprole_pws;
73071+ dev_t segv_device;
73072+ ino_t segv_inode;
73073+ uid_t segv_uid;
73074+ __u16 num_sprole_pws;
73075+ __u16 mode;
73076+};
73077+
73078+struct gr_arg_wrapper {
73079+ struct gr_arg *arg;
73080+ __u32 version;
73081+ __u32 size;
73082+};
73083+
73084+struct subject_map {
73085+ struct acl_subject_label *user;
73086+ struct acl_subject_label *kernel;
73087+ struct subject_map *prev;
73088+ struct subject_map *next;
73089+};
73090+
73091+struct acl_subj_map_db {
73092+ struct subject_map **s_hash;
73093+ __u32 s_size;
73094+};
73095+
73096+/* End Data Structures Section */
73097+
73098+/* Hash functions generated by empirical testing by Brad Spengler
73099+ Makes good use of the low bits of the inode. Generally 0-1 times
73100+ in loop for successful match. 0-3 for unsuccessful match.
73101+ Shift/add algorithm with modulus of table size and an XOR*/
73102+
73103+static __inline__ unsigned int
73104+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
73105+{
73106+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
73107+}
73108+
73109+ static __inline__ unsigned int
73110+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
73111+{
73112+ return ((const unsigned long)userp % sz);
73113+}
73114+
73115+static __inline__ unsigned int
73116+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
73117+{
73118+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
73119+}
73120+
73121+static __inline__ unsigned int
73122+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
73123+{
73124+ return full_name_hash((const unsigned char *)name, len) % sz;
73125+}
73126+
73127+#define FOR_EACH_ROLE_START(role) \
73128+ role = role_list; \
73129+ while (role) {
73130+
73131+#define FOR_EACH_ROLE_END(role) \
73132+ role = role->prev; \
73133+ }
73134+
73135+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
73136+ subj = NULL; \
73137+ iter = 0; \
73138+ while (iter < role->subj_hash_size) { \
73139+ if (subj == NULL) \
73140+ subj = role->subj_hash[iter]; \
73141+ if (subj == NULL) { \
73142+ iter++; \
73143+ continue; \
73144+ }
73145+
73146+#define FOR_EACH_SUBJECT_END(subj,iter) \
73147+ subj = subj->next; \
73148+ if (subj == NULL) \
73149+ iter++; \
73150+ }
73151+
73152+
73153+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
73154+ subj = role->hash->first; \
73155+ while (subj != NULL) {
73156+
73157+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
73158+ subj = subj->next; \
73159+ }
73160+
73161+#endif
73162+
73163diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
73164new file mode 100644
73165index 0000000..33ebd1f
73166--- /dev/null
73167+++ b/include/linux/gracl_compat.h
73168@@ -0,0 +1,156 @@
73169+#ifndef GR_ACL_COMPAT_H
73170+#define GR_ACL_COMPAT_H
73171+
73172+#include <linux/resource.h>
73173+#include <asm/resource.h>
73174+
73175+struct sprole_pw_compat {
73176+ compat_uptr_t rolename;
73177+ unsigned char salt[GR_SALT_LEN];
73178+ unsigned char sum[GR_SHA_LEN];
73179+};
73180+
73181+struct gr_hash_struct_compat {
73182+ compat_uptr_t table;
73183+ compat_uptr_t nametable;
73184+ compat_uptr_t first;
73185+ __u32 table_size;
73186+ __u32 used_size;
73187+ int type;
73188+};
73189+
73190+struct acl_subject_label_compat {
73191+ compat_uptr_t filename;
73192+ compat_ino_t inode;
73193+ __u32 device;
73194+ __u32 mode;
73195+ kernel_cap_t cap_mask;
73196+ kernel_cap_t cap_lower;
73197+ kernel_cap_t cap_invert_audit;
73198+
73199+ struct compat_rlimit res[GR_NLIMITS];
73200+ __u32 resmask;
73201+
73202+ __u8 user_trans_type;
73203+ __u8 group_trans_type;
73204+ compat_uptr_t user_transitions;
73205+ compat_uptr_t group_transitions;
73206+ __u16 user_trans_num;
73207+ __u16 group_trans_num;
73208+
73209+ __u32 sock_families[2];
73210+ __u32 ip_proto[8];
73211+ __u32 ip_type;
73212+ compat_uptr_t ips;
73213+ __u32 ip_num;
73214+ __u32 inaddr_any_override;
73215+
73216+ __u32 crashes;
73217+ compat_ulong_t expires;
73218+
73219+ compat_uptr_t parent_subject;
73220+ compat_uptr_t hash;
73221+ compat_uptr_t prev;
73222+ compat_uptr_t next;
73223+
73224+ compat_uptr_t obj_hash;
73225+ __u32 obj_hash_size;
73226+ __u16 pax_flags;
73227+};
73228+
73229+struct role_allowed_ip_compat {
73230+ __u32 addr;
73231+ __u32 netmask;
73232+
73233+ compat_uptr_t prev;
73234+ compat_uptr_t next;
73235+};
73236+
73237+struct role_transition_compat {
73238+ compat_uptr_t rolename;
73239+
73240+ compat_uptr_t prev;
73241+ compat_uptr_t next;
73242+};
73243+
73244+struct acl_role_label_compat {
73245+ compat_uptr_t rolename;
73246+ uid_t uidgid;
73247+ __u16 roletype;
73248+
73249+ __u16 auth_attempts;
73250+ compat_ulong_t expires;
73251+
73252+ compat_uptr_t root_label;
73253+ compat_uptr_t hash;
73254+
73255+ compat_uptr_t prev;
73256+ compat_uptr_t next;
73257+
73258+ compat_uptr_t transitions;
73259+ compat_uptr_t allowed_ips;
73260+ compat_uptr_t domain_children;
73261+ __u16 domain_child_num;
73262+
73263+ umode_t umask;
73264+
73265+ compat_uptr_t subj_hash;
73266+ __u32 subj_hash_size;
73267+};
73268+
73269+struct user_acl_role_db_compat {
73270+ compat_uptr_t r_table;
73271+ __u32 num_pointers;
73272+ __u32 num_roles;
73273+ __u32 num_domain_children;
73274+ __u32 num_subjects;
73275+ __u32 num_objects;
73276+};
73277+
73278+struct acl_object_label_compat {
73279+ compat_uptr_t filename;
73280+ compat_ino_t inode;
73281+ __u32 device;
73282+ __u32 mode;
73283+
73284+ compat_uptr_t nested;
73285+ compat_uptr_t globbed;
73286+
73287+ compat_uptr_t prev;
73288+ compat_uptr_t next;
73289+};
73290+
73291+struct acl_ip_label_compat {
73292+ compat_uptr_t iface;
73293+ __u32 addr;
73294+ __u32 netmask;
73295+ __u16 low, high;
73296+ __u8 mode;
73297+ __u32 type;
73298+ __u32 proto[8];
73299+
73300+ compat_uptr_t prev;
73301+ compat_uptr_t next;
73302+};
73303+
73304+struct gr_arg_compat {
73305+ struct user_acl_role_db_compat role_db;
73306+ unsigned char pw[GR_PW_LEN];
73307+ unsigned char salt[GR_SALT_LEN];
73308+ unsigned char sum[GR_SHA_LEN];
73309+ unsigned char sp_role[GR_SPROLE_LEN];
73310+ compat_uptr_t sprole_pws;
73311+ __u32 segv_device;
73312+ compat_ino_t segv_inode;
73313+ uid_t segv_uid;
73314+ __u16 num_sprole_pws;
73315+ __u16 mode;
73316+};
73317+
73318+struct gr_arg_wrapper_compat {
73319+ compat_uptr_t arg;
73320+ __u32 version;
73321+ __u32 size;
73322+};
73323+
73324+#endif
73325diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
73326new file mode 100644
73327index 0000000..323ecf2
73328--- /dev/null
73329+++ b/include/linux/gralloc.h
73330@@ -0,0 +1,9 @@
73331+#ifndef __GRALLOC_H
73332+#define __GRALLOC_H
73333+
73334+void acl_free_all(void);
73335+int acl_alloc_stack_init(unsigned long size);
73336+void *acl_alloc(unsigned long len);
73337+void *acl_alloc_num(unsigned long num, unsigned long len);
73338+
73339+#endif
73340diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
73341new file mode 100644
73342index 0000000..be66033
73343--- /dev/null
73344+++ b/include/linux/grdefs.h
73345@@ -0,0 +1,140 @@
73346+#ifndef GRDEFS_H
73347+#define GRDEFS_H
73348+
73349+/* Begin grsecurity status declarations */
73350+
73351+enum {
73352+ GR_READY = 0x01,
73353+ GR_STATUS_INIT = 0x00 // disabled state
73354+};
73355+
73356+/* Begin ACL declarations */
73357+
73358+/* Role flags */
73359+
73360+enum {
73361+ GR_ROLE_USER = 0x0001,
73362+ GR_ROLE_GROUP = 0x0002,
73363+ GR_ROLE_DEFAULT = 0x0004,
73364+ GR_ROLE_SPECIAL = 0x0008,
73365+ GR_ROLE_AUTH = 0x0010,
73366+ GR_ROLE_NOPW = 0x0020,
73367+ GR_ROLE_GOD = 0x0040,
73368+ GR_ROLE_LEARN = 0x0080,
73369+ GR_ROLE_TPE = 0x0100,
73370+ GR_ROLE_DOMAIN = 0x0200,
73371+ GR_ROLE_PAM = 0x0400,
73372+ GR_ROLE_PERSIST = 0x0800
73373+};
73374+
73375+/* ACL Subject and Object mode flags */
73376+enum {
73377+ GR_DELETED = 0x80000000
73378+};
73379+
73380+/* ACL Object-only mode flags */
73381+enum {
73382+ GR_READ = 0x00000001,
73383+ GR_APPEND = 0x00000002,
73384+ GR_WRITE = 0x00000004,
73385+ GR_EXEC = 0x00000008,
73386+ GR_FIND = 0x00000010,
73387+ GR_INHERIT = 0x00000020,
73388+ GR_SETID = 0x00000040,
73389+ GR_CREATE = 0x00000080,
73390+ GR_DELETE = 0x00000100,
73391+ GR_LINK = 0x00000200,
73392+ GR_AUDIT_READ = 0x00000400,
73393+ GR_AUDIT_APPEND = 0x00000800,
73394+ GR_AUDIT_WRITE = 0x00001000,
73395+ GR_AUDIT_EXEC = 0x00002000,
73396+ GR_AUDIT_FIND = 0x00004000,
73397+ GR_AUDIT_INHERIT= 0x00008000,
73398+ GR_AUDIT_SETID = 0x00010000,
73399+ GR_AUDIT_CREATE = 0x00020000,
73400+ GR_AUDIT_DELETE = 0x00040000,
73401+ GR_AUDIT_LINK = 0x00080000,
73402+ GR_PTRACERD = 0x00100000,
73403+ GR_NOPTRACE = 0x00200000,
73404+ GR_SUPPRESS = 0x00400000,
73405+ GR_NOLEARN = 0x00800000,
73406+ GR_INIT_TRANSFER= 0x01000000
73407+};
73408+
73409+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
73410+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
73411+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
73412+
73413+/* ACL subject-only mode flags */
73414+enum {
73415+ GR_KILL = 0x00000001,
73416+ GR_VIEW = 0x00000002,
73417+ GR_PROTECTED = 0x00000004,
73418+ GR_LEARN = 0x00000008,
73419+ GR_OVERRIDE = 0x00000010,
73420+ /* just a placeholder, this mode is only used in userspace */
73421+ GR_DUMMY = 0x00000020,
73422+ GR_PROTSHM = 0x00000040,
73423+ GR_KILLPROC = 0x00000080,
73424+ GR_KILLIPPROC = 0x00000100,
73425+ /* just a placeholder, this mode is only used in userspace */
73426+ GR_NOTROJAN = 0x00000200,
73427+ GR_PROTPROCFD = 0x00000400,
73428+ GR_PROCACCT = 0x00000800,
73429+ GR_RELAXPTRACE = 0x00001000,
73430+ //GR_NESTED = 0x00002000,
73431+ GR_INHERITLEARN = 0x00004000,
73432+ GR_PROCFIND = 0x00008000,
73433+ GR_POVERRIDE = 0x00010000,
73434+ GR_KERNELAUTH = 0x00020000,
73435+ GR_ATSECURE = 0x00040000,
73436+ GR_SHMEXEC = 0x00080000
73437+};
73438+
73439+enum {
73440+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
73441+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
73442+ GR_PAX_ENABLE_MPROTECT = 0x0004,
73443+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
73444+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
73445+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
73446+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
73447+ GR_PAX_DISABLE_MPROTECT = 0x0400,
73448+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
73449+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
73450+};
73451+
73452+enum {
73453+ GR_ID_USER = 0x01,
73454+ GR_ID_GROUP = 0x02,
73455+};
73456+
73457+enum {
73458+ GR_ID_ALLOW = 0x01,
73459+ GR_ID_DENY = 0x02,
73460+};
73461+
73462+#define GR_CRASH_RES 31
73463+#define GR_UIDTABLE_MAX 500
73464+
73465+/* begin resource learning section */
73466+enum {
73467+ GR_RLIM_CPU_BUMP = 60,
73468+ GR_RLIM_FSIZE_BUMP = 50000,
73469+ GR_RLIM_DATA_BUMP = 10000,
73470+ GR_RLIM_STACK_BUMP = 1000,
73471+ GR_RLIM_CORE_BUMP = 10000,
73472+ GR_RLIM_RSS_BUMP = 500000,
73473+ GR_RLIM_NPROC_BUMP = 1,
73474+ GR_RLIM_NOFILE_BUMP = 5,
73475+ GR_RLIM_MEMLOCK_BUMP = 50000,
73476+ GR_RLIM_AS_BUMP = 500000,
73477+ GR_RLIM_LOCKS_BUMP = 2,
73478+ GR_RLIM_SIGPENDING_BUMP = 5,
73479+ GR_RLIM_MSGQUEUE_BUMP = 10000,
73480+ GR_RLIM_NICE_BUMP = 1,
73481+ GR_RLIM_RTPRIO_BUMP = 1,
73482+ GR_RLIM_RTTIME_BUMP = 1000000
73483+};
73484+
73485+#endif
73486diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
73487new file mode 100644
73488index 0000000..e337683
73489--- /dev/null
73490+++ b/include/linux/grinternal.h
73491@@ -0,0 +1,229 @@
73492+#ifndef __GRINTERNAL_H
73493+#define __GRINTERNAL_H
73494+
73495+#ifdef CONFIG_GRKERNSEC
73496+
73497+#include <linux/fs.h>
73498+#include <linux/mnt_namespace.h>
73499+#include <linux/nsproxy.h>
73500+#include <linux/gracl.h>
73501+#include <linux/grdefs.h>
73502+#include <linux/grmsg.h>
73503+
73504+void gr_add_learn_entry(const char *fmt, ...)
73505+ __attribute__ ((format (printf, 1, 2)));
73506+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
73507+ const struct vfsmount *mnt);
73508+__u32 gr_check_create(const struct dentry *new_dentry,
73509+ const struct dentry *parent,
73510+ const struct vfsmount *mnt, const __u32 mode);
73511+int gr_check_protected_task(const struct task_struct *task);
73512+__u32 to_gr_audit(const __u32 reqmode);
73513+int gr_set_acls(const int type);
73514+int gr_apply_subject_to_task(struct task_struct *task);
73515+int gr_acl_is_enabled(void);
73516+char gr_roletype_to_char(void);
73517+
73518+void gr_handle_alertkill(struct task_struct *task);
73519+char *gr_to_filename(const struct dentry *dentry,
73520+ const struct vfsmount *mnt);
73521+char *gr_to_filename1(const struct dentry *dentry,
73522+ const struct vfsmount *mnt);
73523+char *gr_to_filename2(const struct dentry *dentry,
73524+ const struct vfsmount *mnt);
73525+char *gr_to_filename3(const struct dentry *dentry,
73526+ const struct vfsmount *mnt);
73527+
73528+extern int grsec_enable_ptrace_readexec;
73529+extern int grsec_enable_harden_ptrace;
73530+extern int grsec_enable_link;
73531+extern int grsec_enable_fifo;
73532+extern int grsec_enable_execve;
73533+extern int grsec_enable_shm;
73534+extern int grsec_enable_execlog;
73535+extern int grsec_enable_signal;
73536+extern int grsec_enable_audit_ptrace;
73537+extern int grsec_enable_forkfail;
73538+extern int grsec_enable_time;
73539+extern int grsec_enable_rofs;
73540+extern int grsec_deny_new_usb;
73541+extern int grsec_enable_chroot_shmat;
73542+extern int grsec_enable_chroot_mount;
73543+extern int grsec_enable_chroot_double;
73544+extern int grsec_enable_chroot_pivot;
73545+extern int grsec_enable_chroot_chdir;
73546+extern int grsec_enable_chroot_chmod;
73547+extern int grsec_enable_chroot_mknod;
73548+extern int grsec_enable_chroot_fchdir;
73549+extern int grsec_enable_chroot_nice;
73550+extern int grsec_enable_chroot_execlog;
73551+extern int grsec_enable_chroot_caps;
73552+extern int grsec_enable_chroot_sysctl;
73553+extern int grsec_enable_chroot_unix;
73554+extern int grsec_enable_symlinkown;
73555+extern kgid_t grsec_symlinkown_gid;
73556+extern int grsec_enable_tpe;
73557+extern kgid_t grsec_tpe_gid;
73558+extern int grsec_enable_tpe_all;
73559+extern int grsec_enable_tpe_invert;
73560+extern int grsec_enable_socket_all;
73561+extern kgid_t grsec_socket_all_gid;
73562+extern int grsec_enable_socket_client;
73563+extern kgid_t grsec_socket_client_gid;
73564+extern int grsec_enable_socket_server;
73565+extern kgid_t grsec_socket_server_gid;
73566+extern kgid_t grsec_audit_gid;
73567+extern int grsec_enable_group;
73568+extern int grsec_enable_log_rwxmaps;
73569+extern int grsec_enable_mount;
73570+extern int grsec_enable_chdir;
73571+extern int grsec_resource_logging;
73572+extern int grsec_enable_blackhole;
73573+extern int grsec_lastack_retries;
73574+extern int grsec_enable_brute;
73575+extern int grsec_lock;
73576+
73577+extern spinlock_t grsec_alert_lock;
73578+extern unsigned long grsec_alert_wtime;
73579+extern unsigned long grsec_alert_fyet;
73580+
73581+extern spinlock_t grsec_audit_lock;
73582+
73583+extern rwlock_t grsec_exec_file_lock;
73584+
73585+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
73586+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
73587+ (tsk)->exec_file->f_path.mnt) : "/")
73588+
73589+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
73590+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
73591+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
73592+
73593+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
73594+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
73595+ (tsk)->exec_file->f_path.mnt) : "/")
73596+
73597+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
73598+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
73599+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
73600+
73601+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
73602+
73603+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
73604+
73605+static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
73606+{
73607+ if (file1 && file2) {
73608+ const struct inode *inode1 = file1->f_path.dentry->d_inode;
73609+ const struct inode *inode2 = file2->f_path.dentry->d_inode;
73610+ if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
73611+ return true;
73612+ }
73613+
73614+ return false;
73615+}
73616+
73617+#define GR_CHROOT_CAPS {{ \
73618+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
73619+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
73620+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
73621+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
73622+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
73623+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
73624+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
73625+
73626+#define security_learn(normal_msg,args...) \
73627+({ \
73628+ read_lock(&grsec_exec_file_lock); \
73629+ gr_add_learn_entry(normal_msg "\n", ## args); \
73630+ read_unlock(&grsec_exec_file_lock); \
73631+})
73632+
73633+enum {
73634+ GR_DO_AUDIT,
73635+ GR_DONT_AUDIT,
73636+ /* used for non-audit messages that we shouldn't kill the task on */
73637+ GR_DONT_AUDIT_GOOD
73638+};
73639+
73640+enum {
73641+ GR_TTYSNIFF,
73642+ GR_RBAC,
73643+ GR_RBAC_STR,
73644+ GR_STR_RBAC,
73645+ GR_RBAC_MODE2,
73646+ GR_RBAC_MODE3,
73647+ GR_FILENAME,
73648+ GR_SYSCTL_HIDDEN,
73649+ GR_NOARGS,
73650+ GR_ONE_INT,
73651+ GR_ONE_INT_TWO_STR,
73652+ GR_ONE_STR,
73653+ GR_STR_INT,
73654+ GR_TWO_STR_INT,
73655+ GR_TWO_INT,
73656+ GR_TWO_U64,
73657+ GR_THREE_INT,
73658+ GR_FIVE_INT_TWO_STR,
73659+ GR_TWO_STR,
73660+ GR_THREE_STR,
73661+ GR_FOUR_STR,
73662+ GR_STR_FILENAME,
73663+ GR_FILENAME_STR,
73664+ GR_FILENAME_TWO_INT,
73665+ GR_FILENAME_TWO_INT_STR,
73666+ GR_TEXTREL,
73667+ GR_PTRACE,
73668+ GR_RESOURCE,
73669+ GR_CAP,
73670+ GR_SIG,
73671+ GR_SIG2,
73672+ GR_CRASH1,
73673+ GR_CRASH2,
73674+ GR_PSACCT,
73675+ GR_RWXMAP,
73676+ GR_RWXMAPVMA
73677+};
73678+
73679+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
73680+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
73681+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
73682+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
73683+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
73684+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
73685+#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)
73686+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
73687+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
73688+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
73689+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
73690+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
73691+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
73692+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
73693+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
73694+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
73695+#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)
73696+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
73697+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
73698+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
73699+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
73700+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
73701+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
73702+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
73703+#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)
73704+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
73705+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
73706+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
73707+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
73708+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
73709+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
73710+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
73711+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
73712+#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)
73713+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
73714+#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
73715+
73716+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
73717+
73718+#endif
73719+
73720+#endif
73721diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
73722new file mode 100644
73723index 0000000..a4396b5
73724--- /dev/null
73725+++ b/include/linux/grmsg.h
73726@@ -0,0 +1,113 @@
73727+#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"
73728+#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"
73729+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
73730+#define GR_STOPMOD_MSG "denied modification of module state by "
73731+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
73732+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
73733+#define GR_IOPERM_MSG "denied use of ioperm() by "
73734+#define GR_IOPL_MSG "denied use of iopl() by "
73735+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
73736+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
73737+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
73738+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
73739+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
73740+#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"
73741+#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"
73742+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
73743+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
73744+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
73745+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
73746+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
73747+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
73748+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
73749+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
73750+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
73751+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
73752+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
73753+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
73754+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
73755+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
73756+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
73757+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
73758+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
73759+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
73760+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
73761+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
73762+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
73763+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
73764+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
73765+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
73766+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
73767+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
73768+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
73769+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
73770+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
73771+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
73772+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
73773+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
73774+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
73775+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
73776+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
73777+#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"
73778+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
73779+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
73780+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
73781+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
73782+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
73783+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
73784+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
73785+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
73786+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
73787+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
73788+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
73789+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
73790+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
73791+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
73792+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
73793+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
73794+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
73795+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
73796+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
73797+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
73798+#define GR_FAILFORK_MSG "failed fork with errno %s by "
73799+#define GR_NICE_CHROOT_MSG "denied priority change by "
73800+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
73801+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
73802+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
73803+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
73804+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
73805+#define GR_TIME_MSG "time set by "
73806+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
73807+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
73808+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
73809+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
73810+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
73811+#define GR_BIND_MSG "denied bind() by "
73812+#define GR_CONNECT_MSG "denied connect() by "
73813+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
73814+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
73815+#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"
73816+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
73817+#define GR_CAP_ACL_MSG "use of %s denied for "
73818+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
73819+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
73820+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
73821+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
73822+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
73823+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
73824+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
73825+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
73826+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
73827+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
73828+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
73829+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
73830+#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
73831+#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
73832+#define GR_VM86_MSG "denied use of vm86 by "
73833+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
73834+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
73835+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
73836+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
73837+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
73838+#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 "
73839+#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 "
73840diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
73841new file mode 100644
73842index 0000000..d6f5a21
73843--- /dev/null
73844+++ b/include/linux/grsecurity.h
73845@@ -0,0 +1,244 @@
73846+#ifndef GR_SECURITY_H
73847+#define GR_SECURITY_H
73848+#include <linux/fs.h>
73849+#include <linux/fs_struct.h>
73850+#include <linux/binfmts.h>
73851+#include <linux/gracl.h>
73852+
73853+/* notify of brain-dead configs */
73854+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
73855+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
73856+#endif
73857+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
73858+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
73859+#endif
73860+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
73861+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
73862+#endif
73863+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
73864+#error "CONFIG_PAX enabled, but no PaX options are enabled."
73865+#endif
73866+
73867+int gr_handle_new_usb(void);
73868+
73869+void gr_handle_brute_attach(unsigned long mm_flags);
73870+void gr_handle_brute_check(void);
73871+void gr_handle_kernel_exploit(void);
73872+
73873+char gr_roletype_to_char(void);
73874+
73875+int gr_acl_enable_at_secure(void);
73876+
73877+int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
73878+int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
73879+
73880+void gr_del_task_from_ip_table(struct task_struct *p);
73881+
73882+int gr_pid_is_chrooted(struct task_struct *p);
73883+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
73884+int gr_handle_chroot_nice(void);
73885+int gr_handle_chroot_sysctl(const int op);
73886+int gr_handle_chroot_setpriority(struct task_struct *p,
73887+ const int niceval);
73888+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
73889+int gr_handle_chroot_chroot(const struct dentry *dentry,
73890+ const struct vfsmount *mnt);
73891+void gr_handle_chroot_chdir(const struct path *path);
73892+int gr_handle_chroot_chmod(const struct dentry *dentry,
73893+ const struct vfsmount *mnt, const int mode);
73894+int gr_handle_chroot_mknod(const struct dentry *dentry,
73895+ const struct vfsmount *mnt, const int mode);
73896+int gr_handle_chroot_mount(const struct dentry *dentry,
73897+ const struct vfsmount *mnt,
73898+ const char *dev_name);
73899+int gr_handle_chroot_pivot(void);
73900+int gr_handle_chroot_unix(const pid_t pid);
73901+
73902+int gr_handle_rawio(const struct inode *inode);
73903+
73904+void gr_handle_ioperm(void);
73905+void gr_handle_iopl(void);
73906+
73907+umode_t gr_acl_umask(void);
73908+
73909+int gr_tpe_allow(const struct file *file);
73910+
73911+void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
73912+void gr_clear_chroot_entries(struct task_struct *task);
73913+
73914+void gr_log_forkfail(const int retval);
73915+void gr_log_timechange(void);
73916+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
73917+void gr_log_chdir(const struct dentry *dentry,
73918+ const struct vfsmount *mnt);
73919+void gr_log_chroot_exec(const struct dentry *dentry,
73920+ const struct vfsmount *mnt);
73921+void gr_log_remount(const char *devname, const int retval);
73922+void gr_log_unmount(const char *devname, const int retval);
73923+void gr_log_mount(const char *from, const char *to, const int retval);
73924+void gr_log_textrel(struct vm_area_struct *vma);
73925+void gr_log_ptgnustack(struct file *file);
73926+void gr_log_rwxmmap(struct file *file);
73927+void gr_log_rwxmprotect(struct vm_area_struct *vma);
73928+
73929+int gr_handle_follow_link(const struct inode *parent,
73930+ const struct inode *inode,
73931+ const struct dentry *dentry,
73932+ const struct vfsmount *mnt);
73933+int gr_handle_fifo(const struct dentry *dentry,
73934+ const struct vfsmount *mnt,
73935+ const struct dentry *dir, const int flag,
73936+ const int acc_mode);
73937+int gr_handle_hardlink(const struct dentry *dentry,
73938+ const struct vfsmount *mnt,
73939+ struct inode *inode,
73940+ const int mode, const struct filename *to);
73941+
73942+int gr_is_capable(const int cap);
73943+int gr_is_capable_nolog(const int cap);
73944+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
73945+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
73946+
73947+void gr_copy_label(struct task_struct *tsk);
73948+void gr_handle_crash(struct task_struct *task, const int sig);
73949+int gr_handle_signal(const struct task_struct *p, const int sig);
73950+int gr_check_crash_uid(const kuid_t uid);
73951+int gr_check_protected_task(const struct task_struct *task);
73952+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
73953+int gr_acl_handle_mmap(const struct file *file,
73954+ const unsigned long prot);
73955+int gr_acl_handle_mprotect(const struct file *file,
73956+ const unsigned long prot);
73957+int gr_check_hidden_task(const struct task_struct *tsk);
73958+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
73959+ const struct vfsmount *mnt);
73960+__u32 gr_acl_handle_utime(const struct dentry *dentry,
73961+ const struct vfsmount *mnt);
73962+__u32 gr_acl_handle_access(const struct dentry *dentry,
73963+ const struct vfsmount *mnt, const int fmode);
73964+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
73965+ const struct vfsmount *mnt, umode_t *mode);
73966+__u32 gr_acl_handle_chown(const struct dentry *dentry,
73967+ const struct vfsmount *mnt);
73968+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
73969+ const struct vfsmount *mnt);
73970+int gr_handle_ptrace(struct task_struct *task, const long request);
73971+int gr_handle_proc_ptrace(struct task_struct *task);
73972+__u32 gr_acl_handle_execve(const struct dentry *dentry,
73973+ const struct vfsmount *mnt);
73974+int gr_check_crash_exec(const struct file *filp);
73975+int gr_acl_is_enabled(void);
73976+void gr_set_kernel_label(struct task_struct *task);
73977+void gr_set_role_label(struct task_struct *task, const kuid_t uid,
73978+ const kgid_t gid);
73979+int gr_set_proc_label(const struct dentry *dentry,
73980+ const struct vfsmount *mnt,
73981+ const int unsafe_flags);
73982+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
73983+ const struct vfsmount *mnt);
73984+__u32 gr_acl_handle_open(const struct dentry *dentry,
73985+ const struct vfsmount *mnt, int acc_mode);
73986+__u32 gr_acl_handle_creat(const struct dentry *dentry,
73987+ const struct dentry *p_dentry,
73988+ const struct vfsmount *p_mnt,
73989+ int open_flags, int acc_mode, const int imode);
73990+void gr_handle_create(const struct dentry *dentry,
73991+ const struct vfsmount *mnt);
73992+void gr_handle_proc_create(const struct dentry *dentry,
73993+ const struct inode *inode);
73994+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
73995+ const struct dentry *parent_dentry,
73996+ const struct vfsmount *parent_mnt,
73997+ const int mode);
73998+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
73999+ const struct dentry *parent_dentry,
74000+ const struct vfsmount *parent_mnt);
74001+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
74002+ const struct vfsmount *mnt);
74003+void gr_handle_delete(const ino_t ino, const dev_t dev);
74004+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
74005+ const struct vfsmount *mnt);
74006+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
74007+ const struct dentry *parent_dentry,
74008+ const struct vfsmount *parent_mnt,
74009+ const struct filename *from);
74010+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
74011+ const struct dentry *parent_dentry,
74012+ const struct vfsmount *parent_mnt,
74013+ const struct dentry *old_dentry,
74014+ const struct vfsmount *old_mnt, const struct filename *to);
74015+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
74016+int gr_acl_handle_rename(struct dentry *new_dentry,
74017+ struct dentry *parent_dentry,
74018+ const struct vfsmount *parent_mnt,
74019+ struct dentry *old_dentry,
74020+ struct inode *old_parent_inode,
74021+ struct vfsmount *old_mnt, const struct filename *newname);
74022+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
74023+ struct dentry *old_dentry,
74024+ struct dentry *new_dentry,
74025+ struct vfsmount *mnt, const __u8 replace);
74026+__u32 gr_check_link(const struct dentry *new_dentry,
74027+ const struct dentry *parent_dentry,
74028+ const struct vfsmount *parent_mnt,
74029+ const struct dentry *old_dentry,
74030+ const struct vfsmount *old_mnt);
74031+int gr_acl_handle_filldir(const struct file *file, const char *name,
74032+ const unsigned int namelen, const ino_t ino);
74033+
74034+__u32 gr_acl_handle_unix(const struct dentry *dentry,
74035+ const struct vfsmount *mnt);
74036+void gr_acl_handle_exit(void);
74037+void gr_acl_handle_psacct(struct task_struct *task, const long code);
74038+int gr_acl_handle_procpidmem(const struct task_struct *task);
74039+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
74040+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
74041+void gr_audit_ptrace(struct task_struct *task);
74042+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
74043+void gr_put_exec_file(struct task_struct *task);
74044+
74045+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
74046+
74047+#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
74048+extern void gr_learn_resource(const struct task_struct *task, const int res,
74049+ const unsigned long wanted, const int gt);
74050+#else
74051+static inline void gr_learn_resource(const struct task_struct *task, const int res,
74052+ const unsigned long wanted, const int gt)
74053+{
74054+}
74055+#endif
74056+
74057+#ifdef CONFIG_GRKERNSEC_RESLOG
74058+extern void gr_log_resource(const struct task_struct *task, const int res,
74059+ const unsigned long wanted, const int gt);
74060+#else
74061+static inline void gr_log_resource(const struct task_struct *task, const int res,
74062+ const unsigned long wanted, const int gt)
74063+{
74064+}
74065+#endif
74066+
74067+#ifdef CONFIG_GRKERNSEC
74068+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
74069+void gr_handle_vm86(void);
74070+void gr_handle_mem_readwrite(u64 from, u64 to);
74071+
74072+void gr_log_badprocpid(const char *entry);
74073+
74074+extern int grsec_enable_dmesg;
74075+extern int grsec_disable_privio;
74076+
74077+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
74078+extern kgid_t grsec_proc_gid;
74079+#endif
74080+
74081+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
74082+extern int grsec_enable_chroot_findtask;
74083+#endif
74084+#ifdef CONFIG_GRKERNSEC_SETXID
74085+extern int grsec_enable_setxid;
74086+#endif
74087+#endif
74088+
74089+#endif
74090diff --git a/include/linux/grsock.h b/include/linux/grsock.h
74091new file mode 100644
74092index 0000000..e7ffaaf
74093--- /dev/null
74094+++ b/include/linux/grsock.h
74095@@ -0,0 +1,19 @@
74096+#ifndef __GRSOCK_H
74097+#define __GRSOCK_H
74098+
74099+extern void gr_attach_curr_ip(const struct sock *sk);
74100+extern int gr_handle_sock_all(const int family, const int type,
74101+ const int protocol);
74102+extern int gr_handle_sock_server(const struct sockaddr *sck);
74103+extern int gr_handle_sock_server_other(const struct sock *sck);
74104+extern int gr_handle_sock_client(const struct sockaddr *sck);
74105+extern int gr_search_connect(struct socket * sock,
74106+ struct sockaddr_in * addr);
74107+extern int gr_search_bind(struct socket * sock,
74108+ struct sockaddr_in * addr);
74109+extern int gr_search_listen(struct socket * sock);
74110+extern int gr_search_accept(struct socket * sock);
74111+extern int gr_search_socket(const int domain, const int type,
74112+ const int protocol);
74113+
74114+#endif
74115diff --git a/include/linux/highmem.h b/include/linux/highmem.h
74116index 7fb31da..08b5114 100644
74117--- a/include/linux/highmem.h
74118+++ b/include/linux/highmem.h
74119@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
74120 kunmap_atomic(kaddr);
74121 }
74122
74123+static inline void sanitize_highpage(struct page *page)
74124+{
74125+ void *kaddr;
74126+ unsigned long flags;
74127+
74128+ local_irq_save(flags);
74129+ kaddr = kmap_atomic(page);
74130+ clear_page(kaddr);
74131+ kunmap_atomic(kaddr);
74132+ local_irq_restore(flags);
74133+}
74134+
74135 static inline void zero_user_segments(struct page *page,
74136 unsigned start1, unsigned end1,
74137 unsigned start2, unsigned end2)
74138diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
74139index 1c7b89a..7f52502 100644
74140--- a/include/linux/hwmon-sysfs.h
74141+++ b/include/linux/hwmon-sysfs.h
74142@@ -25,7 +25,8 @@
74143 struct sensor_device_attribute{
74144 struct device_attribute dev_attr;
74145 int index;
74146-};
74147+} __do_const;
74148+typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
74149 #define to_sensor_dev_attr(_dev_attr) \
74150 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
74151
74152@@ -41,7 +42,7 @@ struct sensor_device_attribute_2 {
74153 struct device_attribute dev_attr;
74154 u8 index;
74155 u8 nr;
74156-};
74157+} __do_const;
74158 #define to_sensor_dev_attr_2(_dev_attr) \
74159 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
74160
74161diff --git a/include/linux/i2c.h b/include/linux/i2c.h
74162index e988fa9..ff9f17e 100644
74163--- a/include/linux/i2c.h
74164+++ b/include/linux/i2c.h
74165@@ -366,6 +366,7 @@ struct i2c_algorithm {
74166 /* To determine what the adapter supports */
74167 u32 (*functionality) (struct i2c_adapter *);
74168 };
74169+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
74170
74171 /**
74172 * struct i2c_bus_recovery_info - I2C bus recovery information
74173diff --git a/include/linux/i2o.h b/include/linux/i2o.h
74174index d23c3c2..eb63c81 100644
74175--- a/include/linux/i2o.h
74176+++ b/include/linux/i2o.h
74177@@ -565,7 +565,7 @@ struct i2o_controller {
74178 struct i2o_device *exec; /* Executive */
74179 #if BITS_PER_LONG == 64
74180 spinlock_t context_list_lock; /* lock for context_list */
74181- atomic_t context_list_counter; /* needed for unique contexts */
74182+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
74183 struct list_head context_list; /* list of context id's
74184 and pointers */
74185 #endif
74186diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
74187index aff7ad8..3942bbd 100644
74188--- a/include/linux/if_pppox.h
74189+++ b/include/linux/if_pppox.h
74190@@ -76,7 +76,7 @@ struct pppox_proto {
74191 int (*ioctl)(struct socket *sock, unsigned int cmd,
74192 unsigned long arg);
74193 struct module *owner;
74194-};
74195+} __do_const;
74196
74197 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
74198 extern void unregister_pppox_proto(int proto_num);
74199diff --git a/include/linux/init.h b/include/linux/init.h
74200index e73f2b7..cc996e0 100644
74201--- a/include/linux/init.h
74202+++ b/include/linux/init.h
74203@@ -39,9 +39,17 @@
74204 * Also note, that this data cannot be "const".
74205 */
74206
74207+#define add_init_latent_entropy __latent_entropy
74208+
74209+#ifdef CONFIG_MEMORY_HOTPLUG
74210+#define add_meminit_latent_entropy
74211+#else
74212+#define add_meminit_latent_entropy __latent_entropy
74213+#endif
74214+
74215 /* These are for everybody (although not all archs will actually
74216 discard it in modules) */
74217-#define __init __section(.init.text) __cold notrace
74218+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
74219 #define __initdata __section(.init.data)
74220 #define __initconst __constsection(.init.rodata)
74221 #define __exitdata __section(.exit.data)
74222@@ -102,7 +110,7 @@
74223 #define __cpuexitconst
74224
74225 /* Used for MEMORY_HOTPLUG */
74226-#define __meminit __section(.meminit.text) __cold notrace
74227+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
74228 #define __meminitdata __section(.meminit.data)
74229 #define __meminitconst __constsection(.meminit.rodata)
74230 #define __memexit __section(.memexit.text) __exitused __cold notrace
74231diff --git a/include/linux/init_task.h b/include/linux/init_task.h
74232index 5cd0f09..c9f67cc 100644
74233--- a/include/linux/init_task.h
74234+++ b/include/linux/init_task.h
74235@@ -154,6 +154,12 @@ extern struct task_group root_task_group;
74236
74237 #define INIT_TASK_COMM "swapper"
74238
74239+#ifdef CONFIG_X86
74240+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
74241+#else
74242+#define INIT_TASK_THREAD_INFO
74243+#endif
74244+
74245 /*
74246 * INIT_TASK is used to set up the first task table, touch at
74247 * your own risk!. Base=0, limit=0x1fffff (=2MB)
74248@@ -193,6 +199,7 @@ extern struct task_group root_task_group;
74249 RCU_POINTER_INITIALIZER(cred, &init_cred), \
74250 .comm = INIT_TASK_COMM, \
74251 .thread = INIT_THREAD, \
74252+ INIT_TASK_THREAD_INFO \
74253 .fs = &init_fs, \
74254 .files = &init_files, \
74255 .signal = &init_signals, \
74256diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
74257index 5fa5afe..ac55b25 100644
74258--- a/include/linux/interrupt.h
74259+++ b/include/linux/interrupt.h
74260@@ -430,7 +430,7 @@ enum
74261 /* map softirq index to softirq name. update 'softirq_to_name' in
74262 * kernel/softirq.c when adding a new softirq.
74263 */
74264-extern char *softirq_to_name[NR_SOFTIRQS];
74265+extern const char * const softirq_to_name[NR_SOFTIRQS];
74266
74267 /* softirq mask and active fields moved to irq_cpustat_t in
74268 * asm/hardirq.h to get better cache usage. KAO
74269@@ -438,12 +438,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
74270
74271 struct softirq_action
74272 {
74273- void (*action)(struct softirq_action *);
74274-};
74275+ void (*action)(void);
74276+} __no_const;
74277
74278 asmlinkage void do_softirq(void);
74279 asmlinkage void __do_softirq(void);
74280-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
74281+extern void open_softirq(int nr, void (*action)(void));
74282 extern void softirq_init(void);
74283 extern void __raise_softirq_irqoff(unsigned int nr);
74284
74285diff --git a/include/linux/iommu.h b/include/linux/iommu.h
74286index 3aeb730..2177f39 100644
74287--- a/include/linux/iommu.h
74288+++ b/include/linux/iommu.h
74289@@ -113,7 +113,7 @@ struct iommu_ops {
74290 u32 (*domain_get_windows)(struct iommu_domain *domain);
74291
74292 unsigned long pgsize_bitmap;
74293-};
74294+} __do_const;
74295
74296 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
74297 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
74298diff --git a/include/linux/ioport.h b/include/linux/ioport.h
74299index 89b7c24..382af74 100644
74300--- a/include/linux/ioport.h
74301+++ b/include/linux/ioport.h
74302@@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
74303 int adjust_resource(struct resource *res, resource_size_t start,
74304 resource_size_t size);
74305 resource_size_t resource_alignment(struct resource *res);
74306-static inline resource_size_t resource_size(const struct resource *res)
74307+static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
74308 {
74309 return res->end - res->start + 1;
74310 }
74311diff --git a/include/linux/irq.h b/include/linux/irq.h
74312index f04d3ba..bcf2cfb 100644
74313--- a/include/linux/irq.h
74314+++ b/include/linux/irq.h
74315@@ -333,7 +333,8 @@ struct irq_chip {
74316 void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
74317
74318 unsigned long flags;
74319-};
74320+} __do_const;
74321+typedef struct irq_chip __no_const irq_chip_no_const;
74322
74323 /*
74324 * irq_chip specific flags
74325diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
74326index 3e203eb..3fe68d0 100644
74327--- a/include/linux/irqchip/arm-gic.h
74328+++ b/include/linux/irqchip/arm-gic.h
74329@@ -59,9 +59,11 @@
74330
74331 #ifndef __ASSEMBLY__
74332
74333+#include <linux/irq.h>
74334+
74335 struct device_node;
74336
74337-extern struct irq_chip gic_arch_extn;
74338+extern irq_chip_no_const gic_arch_extn;
74339
74340 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
74341 u32 offset, struct device_node *);
74342diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
74343index 6883e19..e854fcb 100644
74344--- a/include/linux/kallsyms.h
74345+++ b/include/linux/kallsyms.h
74346@@ -15,7 +15,8 @@
74347
74348 struct module;
74349
74350-#ifdef CONFIG_KALLSYMS
74351+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
74352+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
74353 /* Lookup the address for a symbol. Returns 0 if not found. */
74354 unsigned long kallsyms_lookup_name(const char *name);
74355
74356@@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
74357 /* Stupid that this does nothing, but I didn't create this mess. */
74358 #define __print_symbol(fmt, addr)
74359 #endif /*CONFIG_KALLSYMS*/
74360+#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
74361+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
74362+extern unsigned long kallsyms_lookup_name(const char *name);
74363+extern void __print_symbol(const char *fmt, unsigned long address);
74364+extern int sprint_backtrace(char *buffer, unsigned long address);
74365+extern int sprint_symbol(char *buffer, unsigned long address);
74366+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
74367+const char *kallsyms_lookup(unsigned long addr,
74368+ unsigned long *symbolsize,
74369+ unsigned long *offset,
74370+ char **modname, char *namebuf);
74371+extern int kallsyms_lookup_size_offset(unsigned long addr,
74372+ unsigned long *symbolsize,
74373+ unsigned long *offset);
74374+#endif
74375
74376 /* This macro allows us to keep printk typechecking */
74377 static __printf(1, 2)
74378diff --git a/include/linux/key-type.h b/include/linux/key-type.h
74379index 518a53a..5e28358 100644
74380--- a/include/linux/key-type.h
74381+++ b/include/linux/key-type.h
74382@@ -125,7 +125,7 @@ struct key_type {
74383 /* internal fields */
74384 struct list_head link; /* link in types list */
74385 struct lock_class_key lock_class; /* key->sem lock class */
74386-};
74387+} __do_const;
74388
74389 extern struct key_type key_type_keyring;
74390
74391diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
74392index c6e091b..a940adf 100644
74393--- a/include/linux/kgdb.h
74394+++ b/include/linux/kgdb.h
74395@@ -52,7 +52,7 @@ extern int kgdb_connected;
74396 extern int kgdb_io_module_registered;
74397
74398 extern atomic_t kgdb_setting_breakpoint;
74399-extern atomic_t kgdb_cpu_doing_single_step;
74400+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
74401
74402 extern struct task_struct *kgdb_usethread;
74403 extern struct task_struct *kgdb_contthread;
74404@@ -254,7 +254,7 @@ struct kgdb_arch {
74405 void (*correct_hw_break)(void);
74406
74407 void (*enable_nmi)(bool on);
74408-};
74409+} __do_const;
74410
74411 /**
74412 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
74413@@ -279,7 +279,7 @@ struct kgdb_io {
74414 void (*pre_exception) (void);
74415 void (*post_exception) (void);
74416 int is_console;
74417-};
74418+} __do_const;
74419
74420 extern struct kgdb_arch arch_kgdb_ops;
74421
74422diff --git a/include/linux/kmod.h b/include/linux/kmod.h
74423index 0555cc6..b16a7a4 100644
74424--- a/include/linux/kmod.h
74425+++ b/include/linux/kmod.h
74426@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
74427 * usually useless though. */
74428 extern __printf(2, 3)
74429 int __request_module(bool wait, const char *name, ...);
74430+extern __printf(3, 4)
74431+int ___request_module(bool wait, char *param_name, const char *name, ...);
74432 #define request_module(mod...) __request_module(true, mod)
74433 #define request_module_nowait(mod...) __request_module(false, mod)
74434 #define try_then_request_module(x, mod...) \
74435diff --git a/include/linux/kobject.h b/include/linux/kobject.h
74436index 939b112..ed6ed51 100644
74437--- a/include/linux/kobject.h
74438+++ b/include/linux/kobject.h
74439@@ -111,7 +111,7 @@ struct kobj_type {
74440 struct attribute **default_attrs;
74441 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
74442 const void *(*namespace)(struct kobject *kobj);
74443-};
74444+} __do_const;
74445
74446 struct kobj_uevent_env {
74447 char *envp[UEVENT_NUM_ENVP];
74448@@ -134,6 +134,7 @@ struct kobj_attribute {
74449 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
74450 const char *buf, size_t count);
74451 };
74452+typedef struct kobj_attribute __no_const kobj_attribute_no_const;
74453
74454 extern const struct sysfs_ops kobj_sysfs_ops;
74455
74456diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
74457index f66b065..c2c29b4 100644
74458--- a/include/linux/kobject_ns.h
74459+++ b/include/linux/kobject_ns.h
74460@@ -43,7 +43,7 @@ struct kobj_ns_type_operations {
74461 const void *(*netlink_ns)(struct sock *sk);
74462 const void *(*initial_ns)(void);
74463 void (*drop_ns)(void *);
74464-};
74465+} __do_const;
74466
74467 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
74468 int kobj_ns_type_registered(enum kobj_ns_type type);
74469diff --git a/include/linux/kref.h b/include/linux/kref.h
74470index 484604d..0f6c5b6 100644
74471--- a/include/linux/kref.h
74472+++ b/include/linux/kref.h
74473@@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
74474 static inline int kref_sub(struct kref *kref, unsigned int count,
74475 void (*release)(struct kref *kref))
74476 {
74477- WARN_ON(release == NULL);
74478+ BUG_ON(release == NULL);
74479
74480 if (atomic_sub_and_test((int) count, &kref->refcount)) {
74481 release(kref);
74482diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
74483index a63d83e..77fd685 100644
74484--- a/include/linux/kvm_host.h
74485+++ b/include/linux/kvm_host.h
74486@@ -446,7 +446,7 @@ static inline void kvm_irqfd_exit(void)
74487 {
74488 }
74489 #endif
74490-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
74491+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
74492 struct module *module);
74493 void kvm_exit(void);
74494
74495@@ -618,7 +618,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
74496 struct kvm_guest_debug *dbg);
74497 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
74498
74499-int kvm_arch_init(void *opaque);
74500+int kvm_arch_init(const void *opaque);
74501 void kvm_arch_exit(void);
74502
74503 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
74504diff --git a/include/linux/libata.h b/include/linux/libata.h
74505index 4ea55bb..dcd2601 100644
74506--- a/include/linux/libata.h
74507+++ b/include/linux/libata.h
74508@@ -924,7 +924,7 @@ struct ata_port_operations {
74509 * fields must be pointers.
74510 */
74511 const struct ata_port_operations *inherits;
74512-};
74513+} __do_const;
74514
74515 struct ata_port_info {
74516 unsigned long flags;
74517diff --git a/include/linux/linkage.h b/include/linux/linkage.h
74518index d3e8ad2..a949f68 100644
74519--- a/include/linux/linkage.h
74520+++ b/include/linux/linkage.h
74521@@ -31,6 +31,7 @@
74522 #endif
74523
74524 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
74525+#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
74526 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
74527
74528 /*
74529diff --git a/include/linux/list.h b/include/linux/list.h
74530index f4d8a2f..38e6e46 100644
74531--- a/include/linux/list.h
74532+++ b/include/linux/list.h
74533@@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
74534 extern void list_del(struct list_head *entry);
74535 #endif
74536
74537+extern void __pax_list_add(struct list_head *new,
74538+ struct list_head *prev,
74539+ struct list_head *next);
74540+static inline void pax_list_add(struct list_head *new, struct list_head *head)
74541+{
74542+ __pax_list_add(new, head, head->next);
74543+}
74544+static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
74545+{
74546+ __pax_list_add(new, head->prev, head);
74547+}
74548+extern void pax_list_del(struct list_head *entry);
74549+
74550 /**
74551 * list_replace - replace old entry by new one
74552 * @old : the element to be replaced
74553@@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
74554 INIT_LIST_HEAD(entry);
74555 }
74556
74557+extern void pax_list_del_init(struct list_head *entry);
74558+
74559 /**
74560 * list_move - delete from one list and add as another's head
74561 * @list: the entry to move
74562diff --git a/include/linux/math64.h b/include/linux/math64.h
74563index 2913b86..8dcbb1e 100644
74564--- a/include/linux/math64.h
74565+++ b/include/linux/math64.h
74566@@ -15,7 +15,7 @@
74567 * This is commonly provided by 32bit archs to provide an optimized 64bit
74568 * divide.
74569 */
74570-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
74571+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
74572 {
74573 *remainder = dividend % divisor;
74574 return dividend / divisor;
74575@@ -33,7 +33,7 @@ static inline s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
74576 /**
74577 * div64_u64 - unsigned 64bit divide with 64bit divisor
74578 */
74579-static inline u64 div64_u64(u64 dividend, u64 divisor)
74580+static inline u64 __intentional_overflow(0) div64_u64(u64 dividend, u64 divisor)
74581 {
74582 return dividend / divisor;
74583 }
74584@@ -52,7 +52,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
74585 #define div64_ul(x, y) div_u64((x), (y))
74586
74587 #ifndef div_u64_rem
74588-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
74589+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
74590 {
74591 *remainder = do_div(dividend, divisor);
74592 return dividend;
74593@@ -81,7 +81,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
74594 * divide.
74595 */
74596 #ifndef div_u64
74597-static inline u64 div_u64(u64 dividend, u32 divisor)
74598+static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
74599 {
74600 u32 remainder;
74601 return div_u64_rem(dividend, divisor, &remainder);
74602diff --git a/include/linux/mm.h b/include/linux/mm.h
74603index f022460..6ecf4f9 100644
74604--- a/include/linux/mm.h
74605+++ b/include/linux/mm.h
74606@@ -113,6 +113,11 @@ extern unsigned int kobjsize(const void *objp);
74607 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
74608 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
74609 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
74610+
74611+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
74612+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
74613+#endif
74614+
74615 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
74616
74617 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
74618@@ -208,8 +213,8 @@ struct vm_operations_struct {
74619 /* called by access_process_vm when get_user_pages() fails, typically
74620 * for use by special VMAs that can switch between memory and hardware
74621 */
74622- int (*access)(struct vm_area_struct *vma, unsigned long addr,
74623- void *buf, int len, int write);
74624+ ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
74625+ void *buf, size_t len, int write);
74626 #ifdef CONFIG_NUMA
74627 /*
74628 * set_policy() op must add a reference to any non-NULL @new mempolicy
74629@@ -239,6 +244,7 @@ struct vm_operations_struct {
74630 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
74631 unsigned long size, pgoff_t pgoff);
74632 };
74633+typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
74634
74635 struct mmu_gather;
74636 struct inode;
74637@@ -983,8 +989,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
74638 unsigned long *pfn);
74639 int follow_phys(struct vm_area_struct *vma, unsigned long address,
74640 unsigned int flags, unsigned long *prot, resource_size_t *phys);
74641-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
74642- void *buf, int len, int write);
74643+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
74644+ void *buf, size_t len, int write);
74645
74646 static inline void unmap_shared_mapping_range(struct address_space *mapping,
74647 loff_t const holebegin, loff_t const holelen)
74648@@ -1023,9 +1029,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
74649 }
74650 #endif
74651
74652-extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
74653-extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
74654- void *buf, int len, int write);
74655+extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
74656+extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
74657+ void *buf, size_t len, int write);
74658
74659 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
74660 unsigned long start, unsigned long nr_pages,
74661@@ -1057,34 +1063,6 @@ int set_page_dirty(struct page *page);
74662 int set_page_dirty_lock(struct page *page);
74663 int clear_page_dirty_for_io(struct page *page);
74664
74665-/* Is the vma a continuation of the stack vma above it? */
74666-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
74667-{
74668- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
74669-}
74670-
74671-static inline int stack_guard_page_start(struct vm_area_struct *vma,
74672- unsigned long addr)
74673-{
74674- return (vma->vm_flags & VM_GROWSDOWN) &&
74675- (vma->vm_start == addr) &&
74676- !vma_growsdown(vma->vm_prev, addr);
74677-}
74678-
74679-/* Is the vma a continuation of the stack vma below it? */
74680-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
74681-{
74682- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
74683-}
74684-
74685-static inline int stack_guard_page_end(struct vm_area_struct *vma,
74686- unsigned long addr)
74687-{
74688- return (vma->vm_flags & VM_GROWSUP) &&
74689- (vma->vm_end == addr) &&
74690- !vma_growsup(vma->vm_next, addr);
74691-}
74692-
74693 extern pid_t
74694 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
74695
74696@@ -1184,6 +1162,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
74697 }
74698 #endif
74699
74700+#ifdef CONFIG_MMU
74701+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
74702+#else
74703+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
74704+{
74705+ return __pgprot(0);
74706+}
74707+#endif
74708+
74709 int vma_wants_writenotify(struct vm_area_struct *vma);
74710
74711 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
74712@@ -1202,8 +1189,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
74713 {
74714 return 0;
74715 }
74716+
74717+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
74718+ unsigned long address)
74719+{
74720+ return 0;
74721+}
74722 #else
74723 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
74724+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
74725 #endif
74726
74727 #ifdef __PAGETABLE_PMD_FOLDED
74728@@ -1212,8 +1206,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
74729 {
74730 return 0;
74731 }
74732+
74733+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
74734+ unsigned long address)
74735+{
74736+ return 0;
74737+}
74738 #else
74739 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
74740+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
74741 #endif
74742
74743 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
74744@@ -1231,11 +1232,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
74745 NULL: pud_offset(pgd, address);
74746 }
74747
74748+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
74749+{
74750+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
74751+ NULL: pud_offset(pgd, address);
74752+}
74753+
74754 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
74755 {
74756 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
74757 NULL: pmd_offset(pud, address);
74758 }
74759+
74760+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
74761+{
74762+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
74763+ NULL: pmd_offset(pud, address);
74764+}
74765 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
74766
74767 #if USE_SPLIT_PTLOCKS
74768@@ -1531,6 +1544,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
74769 unsigned long len, unsigned long prot, unsigned long flags,
74770 unsigned long pgoff, unsigned long *populate);
74771 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
74772+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
74773
74774 #ifdef CONFIG_MMU
74775 extern int __mm_populate(unsigned long addr, unsigned long len,
74776@@ -1559,10 +1573,11 @@ struct vm_unmapped_area_info {
74777 unsigned long high_limit;
74778 unsigned long align_mask;
74779 unsigned long align_offset;
74780+ unsigned long threadstack_offset;
74781 };
74782
74783-extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
74784-extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
74785+extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
74786+extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
74787
74788 /*
74789 * Search for an unmapped address range.
74790@@ -1574,7 +1589,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
74791 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
74792 */
74793 static inline unsigned long
74794-vm_unmapped_area(struct vm_unmapped_area_info *info)
74795+vm_unmapped_area(const struct vm_unmapped_area_info *info)
74796 {
74797 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
74798 return unmapped_area(info);
74799@@ -1637,6 +1652,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
74800 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
74801 struct vm_area_struct **pprev);
74802
74803+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
74804+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
74805+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
74806+
74807 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
74808 NULL if none. Assume start_addr < end_addr. */
74809 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
74810@@ -1665,15 +1684,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
74811 return vma;
74812 }
74813
74814-#ifdef CONFIG_MMU
74815-pgprot_t vm_get_page_prot(unsigned long vm_flags);
74816-#else
74817-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
74818-{
74819- return __pgprot(0);
74820-}
74821-#endif
74822-
74823 #ifdef CONFIG_ARCH_USES_NUMA_PROT_NONE
74824 unsigned long change_prot_numa(struct vm_area_struct *vma,
74825 unsigned long start, unsigned long end);
74826@@ -1725,6 +1735,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
74827 static inline void vm_stat_account(struct mm_struct *mm,
74828 unsigned long flags, struct file *file, long pages)
74829 {
74830+
74831+#ifdef CONFIG_PAX_RANDMMAP
74832+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
74833+#endif
74834+
74835 mm->total_vm += pages;
74836 }
74837 #endif /* CONFIG_PROC_FS */
74838@@ -1805,7 +1820,7 @@ extern int unpoison_memory(unsigned long pfn);
74839 extern int sysctl_memory_failure_early_kill;
74840 extern int sysctl_memory_failure_recovery;
74841 extern void shake_page(struct page *p, int access);
74842-extern atomic_long_t num_poisoned_pages;
74843+extern atomic_long_unchecked_t num_poisoned_pages;
74844 extern int soft_offline_page(struct page *page, int flags);
74845
74846 extern void dump_page(struct page *page);
74847@@ -1842,5 +1857,11 @@ void __init setup_nr_node_ids(void);
74848 static inline void setup_nr_node_ids(void) {}
74849 #endif
74850
74851+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
74852+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
74853+#else
74854+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
74855+#endif
74856+
74857 #endif /* __KERNEL__ */
74858 #endif /* _LINUX_MM_H */
74859diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
74860index faf4b7c..1e70c6e 100644
74861--- a/include/linux/mm_types.h
74862+++ b/include/linux/mm_types.h
74863@@ -289,6 +289,8 @@ struct vm_area_struct {
74864 #ifdef CONFIG_NUMA
74865 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
74866 #endif
74867+
74868+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
74869 };
74870
74871 struct core_thread {
74872@@ -435,6 +437,24 @@ struct mm_struct {
74873 int first_nid;
74874 #endif
74875 struct uprobes_state uprobes_state;
74876+
74877+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
74878+ unsigned long pax_flags;
74879+#endif
74880+
74881+#ifdef CONFIG_PAX_DLRESOLVE
74882+ unsigned long call_dl_resolve;
74883+#endif
74884+
74885+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
74886+ unsigned long call_syscall;
74887+#endif
74888+
74889+#ifdef CONFIG_PAX_ASLR
74890+ unsigned long delta_mmap; /* randomized offset */
74891+ unsigned long delta_stack; /* randomized offset */
74892+#endif
74893+
74894 };
74895
74896 /* first nid will either be a valid NID or one of these values */
74897diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
74898index c5d5278..f0b68c8 100644
74899--- a/include/linux/mmiotrace.h
74900+++ b/include/linux/mmiotrace.h
74901@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
74902 /* Called from ioremap.c */
74903 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
74904 void __iomem *addr);
74905-extern void mmiotrace_iounmap(volatile void __iomem *addr);
74906+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
74907
74908 /* For anyone to insert markers. Remember trailing newline. */
74909 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
74910@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
74911 {
74912 }
74913
74914-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
74915+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
74916 {
74917 }
74918
74919diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
74920index af4a3b7..9ad8889 100644
74921--- a/include/linux/mmzone.h
74922+++ b/include/linux/mmzone.h
74923@@ -396,7 +396,7 @@ struct zone {
74924 unsigned long flags; /* zone flags, see below */
74925
74926 /* Zone statistics */
74927- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
74928+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
74929
74930 /*
74931 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
74932diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
74933index 45e9214..a7227d6 100644
74934--- a/include/linux/mod_devicetable.h
74935+++ b/include/linux/mod_devicetable.h
74936@@ -13,7 +13,7 @@
74937 typedef unsigned long kernel_ulong_t;
74938 #endif
74939
74940-#define PCI_ANY_ID (~0)
74941+#define PCI_ANY_ID ((__u16)~0)
74942
74943 struct pci_device_id {
74944 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
74945@@ -139,7 +139,7 @@ struct usb_device_id {
74946 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
74947 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
74948
74949-#define HID_ANY_ID (~0)
74950+#define HID_ANY_ID (~0U)
74951 #define HID_BUS_ANY 0xffff
74952 #define HID_GROUP_ANY 0x0000
74953
74954@@ -467,7 +467,7 @@ struct dmi_system_id {
74955 const char *ident;
74956 struct dmi_strmatch matches[4];
74957 void *driver_data;
74958-};
74959+} __do_const;
74960 /*
74961 * struct dmi_device_id appears during expansion of
74962 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
74963diff --git a/include/linux/module.h b/include/linux/module.h
74964index 46f1ea0..a34ca37 100644
74965--- a/include/linux/module.h
74966+++ b/include/linux/module.h
74967@@ -17,9 +17,11 @@
74968 #include <linux/moduleparam.h>
74969 #include <linux/tracepoint.h>
74970 #include <linux/export.h>
74971+#include <linux/fs.h>
74972
74973 #include <linux/percpu.h>
74974 #include <asm/module.h>
74975+#include <asm/pgtable.h>
74976
74977 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
74978 #define MODULE_SIG_STRING "~Module signature appended~\n"
74979@@ -54,12 +56,13 @@ struct module_attribute {
74980 int (*test)(struct module *);
74981 void (*free)(struct module *);
74982 };
74983+typedef struct module_attribute __no_const module_attribute_no_const;
74984
74985 struct module_version_attribute {
74986 struct module_attribute mattr;
74987 const char *module_name;
74988 const char *version;
74989-} __attribute__ ((__aligned__(sizeof(void *))));
74990+} __do_const __attribute__ ((__aligned__(sizeof(void *))));
74991
74992 extern ssize_t __modver_version_show(struct module_attribute *,
74993 struct module_kobject *, char *);
74994@@ -232,7 +235,7 @@ struct module
74995
74996 /* Sysfs stuff. */
74997 struct module_kobject mkobj;
74998- struct module_attribute *modinfo_attrs;
74999+ module_attribute_no_const *modinfo_attrs;
75000 const char *version;
75001 const char *srcversion;
75002 struct kobject *holders_dir;
75003@@ -281,19 +284,16 @@ struct module
75004 int (*init)(void);
75005
75006 /* If this is non-NULL, vfree after init() returns */
75007- void *module_init;
75008+ void *module_init_rx, *module_init_rw;
75009
75010 /* Here is the actual code + data, vfree'd on unload. */
75011- void *module_core;
75012+ void *module_core_rx, *module_core_rw;
75013
75014 /* Here are the sizes of the init and core sections */
75015- unsigned int init_size, core_size;
75016+ unsigned int init_size_rw, core_size_rw;
75017
75018 /* The size of the executable code in each section. */
75019- unsigned int init_text_size, core_text_size;
75020-
75021- /* Size of RO sections of the module (text+rodata) */
75022- unsigned int init_ro_size, core_ro_size;
75023+ unsigned int init_size_rx, core_size_rx;
75024
75025 /* Arch-specific module values */
75026 struct mod_arch_specific arch;
75027@@ -349,6 +349,10 @@ struct module
75028 #ifdef CONFIG_EVENT_TRACING
75029 struct ftrace_event_call **trace_events;
75030 unsigned int num_trace_events;
75031+ struct file_operations trace_id;
75032+ struct file_operations trace_enable;
75033+ struct file_operations trace_format;
75034+ struct file_operations trace_filter;
75035 #endif
75036 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
75037 unsigned int num_ftrace_callsites;
75038@@ -396,16 +400,46 @@ bool is_module_address(unsigned long addr);
75039 bool is_module_percpu_address(unsigned long addr);
75040 bool is_module_text_address(unsigned long addr);
75041
75042+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
75043+{
75044+
75045+#ifdef CONFIG_PAX_KERNEXEC
75046+ if (ktla_ktva(addr) >= (unsigned long)start &&
75047+ ktla_ktva(addr) < (unsigned long)start + size)
75048+ return 1;
75049+#endif
75050+
75051+ return ((void *)addr >= start && (void *)addr < start + size);
75052+}
75053+
75054+static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
75055+{
75056+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
75057+}
75058+
75059+static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
75060+{
75061+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
75062+}
75063+
75064+static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
75065+{
75066+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
75067+}
75068+
75069+static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
75070+{
75071+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
75072+}
75073+
75074 static inline int within_module_core(unsigned long addr, const struct module *mod)
75075 {
75076- return (unsigned long)mod->module_core <= addr &&
75077- addr < (unsigned long)mod->module_core + mod->core_size;
75078+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
75079 }
75080
75081 static inline int within_module_init(unsigned long addr, const struct module *mod)
75082 {
75083- return (unsigned long)mod->module_init <= addr &&
75084- addr < (unsigned long)mod->module_init + mod->init_size;
75085+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
75086 }
75087
75088 /* Search for module by name: must hold module_mutex. */
75089diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
75090index 560ca53..ef621ef 100644
75091--- a/include/linux/moduleloader.h
75092+++ b/include/linux/moduleloader.h
75093@@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
75094 sections. Returns NULL on failure. */
75095 void *module_alloc(unsigned long size);
75096
75097+#ifdef CONFIG_PAX_KERNEXEC
75098+void *module_alloc_exec(unsigned long size);
75099+#else
75100+#define module_alloc_exec(x) module_alloc(x)
75101+#endif
75102+
75103 /* Free memory returned from module_alloc. */
75104 void module_free(struct module *mod, void *module_region);
75105
75106+#ifdef CONFIG_PAX_KERNEXEC
75107+void module_free_exec(struct module *mod, void *module_region);
75108+#else
75109+#define module_free_exec(x, y) module_free((x), (y))
75110+#endif
75111+
75112 /*
75113 * Apply the given relocation to the (simplified) ELF. Return -error
75114 * or 0.
75115@@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
75116 unsigned int relsec,
75117 struct module *me)
75118 {
75119+#ifdef CONFIG_MODULES
75120 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
75121+#endif
75122 return -ENOEXEC;
75123 }
75124 #endif
75125@@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
75126 unsigned int relsec,
75127 struct module *me)
75128 {
75129+#ifdef CONFIG_MODULES
75130 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
75131+#endif
75132 return -ENOEXEC;
75133 }
75134 #endif
75135diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
75136index 27d9da3..5d94aa3 100644
75137--- a/include/linux/moduleparam.h
75138+++ b/include/linux/moduleparam.h
75139@@ -284,7 +284,7 @@ static inline void __kernel_param_unlock(void)
75140 * @len is usually just sizeof(string).
75141 */
75142 #define module_param_string(name, string, len, perm) \
75143- static const struct kparam_string __param_string_##name \
75144+ static const struct kparam_string __param_string_##name __used \
75145 = { len, string }; \
75146 __module_param_call(MODULE_PARAM_PREFIX, name, \
75147 &param_ops_string, \
75148@@ -423,7 +423,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
75149 */
75150 #define module_param_array_named(name, array, type, nump, perm) \
75151 param_check_##type(name, &(array)[0]); \
75152- static const struct kparam_array __param_arr_##name \
75153+ static const struct kparam_array __param_arr_##name __used \
75154 = { .max = ARRAY_SIZE(array), .num = nump, \
75155 .ops = &param_ops_##type, \
75156 .elemsize = sizeof(array[0]), .elem = array }; \
75157diff --git a/include/linux/namei.h b/include/linux/namei.h
75158index 5a5ff57..5ae5070 100644
75159--- a/include/linux/namei.h
75160+++ b/include/linux/namei.h
75161@@ -19,7 +19,7 @@ struct nameidata {
75162 unsigned seq;
75163 int last_type;
75164 unsigned depth;
75165- char *saved_names[MAX_NESTED_LINKS + 1];
75166+ const char *saved_names[MAX_NESTED_LINKS + 1];
75167 };
75168
75169 /*
75170@@ -84,12 +84,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
75171
75172 extern void nd_jump_link(struct nameidata *nd, struct path *path);
75173
75174-static inline void nd_set_link(struct nameidata *nd, char *path)
75175+static inline void nd_set_link(struct nameidata *nd, const char *path)
75176 {
75177 nd->saved_names[nd->depth] = path;
75178 }
75179
75180-static inline char *nd_get_link(struct nameidata *nd)
75181+static inline const char *nd_get_link(const struct nameidata *nd)
75182 {
75183 return nd->saved_names[nd->depth];
75184 }
75185diff --git a/include/linux/net.h b/include/linux/net.h
75186index 4f27575..fc8a65f 100644
75187--- a/include/linux/net.h
75188+++ b/include/linux/net.h
75189@@ -183,7 +183,7 @@ struct net_proto_family {
75190 int (*create)(struct net *net, struct socket *sock,
75191 int protocol, int kern);
75192 struct module *owner;
75193-};
75194+} __do_const;
75195
75196 struct iovec;
75197 struct kvec;
75198diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
75199index 9a41568..203d903 100644
75200--- a/include/linux/netdevice.h
75201+++ b/include/linux/netdevice.h
75202@@ -1061,6 +1061,7 @@ struct net_device_ops {
75203 int (*ndo_change_carrier)(struct net_device *dev,
75204 bool new_carrier);
75205 };
75206+typedef struct net_device_ops __no_const net_device_ops_no_const;
75207
75208 /*
75209 * The DEVICE structure.
75210@@ -1131,7 +1132,7 @@ struct net_device {
75211 int iflink;
75212
75213 struct net_device_stats stats;
75214- atomic_long_t rx_dropped; /* dropped packets by core network
75215+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
75216 * Do not use this in drivers.
75217 */
75218
75219diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
75220index de70f7b..2675e91 100644
75221--- a/include/linux/netfilter.h
75222+++ b/include/linux/netfilter.h
75223@@ -82,7 +82,7 @@ struct nf_sockopt_ops {
75224 #endif
75225 /* Use the module struct to lock set/get code in place */
75226 struct module *owner;
75227-};
75228+} __do_const;
75229
75230 /* Function to register/unregister hook points. */
75231 int nf_register_hook(struct nf_hook_ops *reg);
75232diff --git a/include/linux/netfilter/ipset/ip_set.h b/include/linux/netfilter/ipset/ip_set.h
75233index d80e275..c3510b8 100644
75234--- a/include/linux/netfilter/ipset/ip_set.h
75235+++ b/include/linux/netfilter/ipset/ip_set.h
75236@@ -124,7 +124,7 @@ struct ip_set_type_variant {
75237 /* Return true if "b" set is the same as "a"
75238 * according to the create set parameters */
75239 bool (*same_set)(const struct ip_set *a, const struct ip_set *b);
75240-};
75241+} __do_const;
75242
75243 /* The core set type structure */
75244 struct ip_set_type {
75245diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
75246index cadb740..d7c37c0 100644
75247--- a/include/linux/netfilter/nfnetlink.h
75248+++ b/include/linux/netfilter/nfnetlink.h
75249@@ -16,7 +16,7 @@ struct nfnl_callback {
75250 const struct nlattr * const cda[]);
75251 const struct nla_policy *policy; /* netlink attribute policy */
75252 const u_int16_t attr_count; /* number of nlattr's */
75253-};
75254+} __do_const;
75255
75256 struct nfnetlink_subsystem {
75257 const char *name;
75258diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
75259new file mode 100644
75260index 0000000..33f4af8
75261--- /dev/null
75262+++ b/include/linux/netfilter/xt_gradm.h
75263@@ -0,0 +1,9 @@
75264+#ifndef _LINUX_NETFILTER_XT_GRADM_H
75265+#define _LINUX_NETFILTER_XT_GRADM_H 1
75266+
75267+struct xt_gradm_mtinfo {
75268+ __u16 flags;
75269+ __u16 invflags;
75270+};
75271+
75272+#endif
75273diff --git a/include/linux/nls.h b/include/linux/nls.h
75274index 5dc635f..35f5e11 100644
75275--- a/include/linux/nls.h
75276+++ b/include/linux/nls.h
75277@@ -31,7 +31,7 @@ struct nls_table {
75278 const unsigned char *charset2upper;
75279 struct module *owner;
75280 struct nls_table *next;
75281-};
75282+} __do_const;
75283
75284 /* this value hold the maximum octet of charset */
75285 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
75286diff --git a/include/linux/notifier.h b/include/linux/notifier.h
75287index d14a4c3..a078786 100644
75288--- a/include/linux/notifier.h
75289+++ b/include/linux/notifier.h
75290@@ -54,7 +54,8 @@ struct notifier_block {
75291 notifier_fn_t notifier_call;
75292 struct notifier_block __rcu *next;
75293 int priority;
75294-};
75295+} __do_const;
75296+typedef struct notifier_block __no_const notifier_block_no_const;
75297
75298 struct atomic_notifier_head {
75299 spinlock_t lock;
75300diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
75301index a4c5624..79d6d88 100644
75302--- a/include/linux/oprofile.h
75303+++ b/include/linux/oprofile.h
75304@@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
75305 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
75306 char const * name, ulong * val);
75307
75308-/** Create a file for read-only access to an atomic_t. */
75309+/** Create a file for read-only access to an atomic_unchecked_t. */
75310 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
75311- char const * name, atomic_t * val);
75312+ char const * name, atomic_unchecked_t * val);
75313
75314 /** create a directory */
75315 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
75316diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
75317index 8db71dc..a76bf2c 100644
75318--- a/include/linux/pci_hotplug.h
75319+++ b/include/linux/pci_hotplug.h
75320@@ -80,7 +80,8 @@ struct hotplug_slot_ops {
75321 int (*get_attention_status) (struct hotplug_slot *slot, u8 *value);
75322 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
75323 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
75324-};
75325+} __do_const;
75326+typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
75327
75328 /**
75329 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
75330diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
75331index c43f6ea..2d4416f 100644
75332--- a/include/linux/perf_event.h
75333+++ b/include/linux/perf_event.h
75334@@ -328,8 +328,8 @@ struct perf_event {
75335
75336 enum perf_event_active_state state;
75337 unsigned int attach_state;
75338- local64_t count;
75339- atomic64_t child_count;
75340+ local64_t count; /* PaX: fix it one day */
75341+ atomic64_unchecked_t child_count;
75342
75343 /*
75344 * These are the total time in nanoseconds that the event
75345@@ -380,8 +380,8 @@ struct perf_event {
75346 * These accumulate total time (in nanoseconds) that children
75347 * events have been enabled and running, respectively.
75348 */
75349- atomic64_t child_total_time_enabled;
75350- atomic64_t child_total_time_running;
75351+ atomic64_unchecked_t child_total_time_enabled;
75352+ atomic64_unchecked_t child_total_time_running;
75353
75354 /*
75355 * Protect attach/detach and child_list:
75356@@ -703,7 +703,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
75357 entry->ip[entry->nr++] = ip;
75358 }
75359
75360-extern int sysctl_perf_event_paranoid;
75361+extern int sysctl_perf_event_legitimately_concerned;
75362 extern int sysctl_perf_event_mlock;
75363 extern int sysctl_perf_event_sample_rate;
75364 extern int sysctl_perf_cpu_time_max_percent;
75365@@ -718,19 +718,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
75366 loff_t *ppos);
75367
75368
75369+static inline bool perf_paranoid_any(void)
75370+{
75371+ return sysctl_perf_event_legitimately_concerned > 2;
75372+}
75373+
75374 static inline bool perf_paranoid_tracepoint_raw(void)
75375 {
75376- return sysctl_perf_event_paranoid > -1;
75377+ return sysctl_perf_event_legitimately_concerned > -1;
75378 }
75379
75380 static inline bool perf_paranoid_cpu(void)
75381 {
75382- return sysctl_perf_event_paranoid > 0;
75383+ return sysctl_perf_event_legitimately_concerned > 0;
75384 }
75385
75386 static inline bool perf_paranoid_kernel(void)
75387 {
75388- return sysctl_perf_event_paranoid > 1;
75389+ return sysctl_perf_event_legitimately_concerned > 1;
75390 }
75391
75392 extern void perf_event_init(void);
75393@@ -846,7 +851,7 @@ struct perf_pmu_events_attr {
75394 struct device_attribute attr;
75395 u64 id;
75396 const char *event_str;
75397-};
75398+} __do_const;
75399
75400 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
75401 static struct perf_pmu_events_attr _var = { \
75402diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
75403index b8809fe..ae4ccd0 100644
75404--- a/include/linux/pipe_fs_i.h
75405+++ b/include/linux/pipe_fs_i.h
75406@@ -47,10 +47,10 @@ struct pipe_inode_info {
75407 struct mutex mutex;
75408 wait_queue_head_t wait;
75409 unsigned int nrbufs, curbuf, buffers;
75410- unsigned int readers;
75411- unsigned int writers;
75412- unsigned int files;
75413- unsigned int waiting_writers;
75414+ atomic_t readers;
75415+ atomic_t writers;
75416+ atomic_t files;
75417+ atomic_t waiting_writers;
75418 unsigned int r_counter;
75419 unsigned int w_counter;
75420 struct page *tmp_page;
75421diff --git a/include/linux/platform_data/usb-ehci-s5p.h b/include/linux/platform_data/usb-ehci-s5p.h
75422index 5f28cae..3d23723 100644
75423--- a/include/linux/platform_data/usb-ehci-s5p.h
75424+++ b/include/linux/platform_data/usb-ehci-s5p.h
75425@@ -14,7 +14,7 @@
75426 struct s5p_ehci_platdata {
75427 int (*phy_init)(struct platform_device *pdev, int type);
75428 int (*phy_exit)(struct platform_device *pdev, int type);
75429-};
75430+} __no_const;
75431
75432 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
75433
75434diff --git a/include/linux/platform_data/usb-ohci-exynos.h b/include/linux/platform_data/usb-ohci-exynos.h
75435index c256c59..8ea94c7 100644
75436--- a/include/linux/platform_data/usb-ohci-exynos.h
75437+++ b/include/linux/platform_data/usb-ohci-exynos.h
75438@@ -14,7 +14,7 @@
75439 struct exynos4_ohci_platdata {
75440 int (*phy_init)(struct platform_device *pdev, int type);
75441 int (*phy_exit)(struct platform_device *pdev, int type);
75442-};
75443+} __no_const;
75444
75445 extern void exynos4_ohci_set_platdata(struct exynos4_ohci_platdata *pd);
75446
75447diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
75448index 7c1d252..c5c773e 100644
75449--- a/include/linux/pm_domain.h
75450+++ b/include/linux/pm_domain.h
75451@@ -48,7 +48,7 @@ struct gpd_dev_ops {
75452
75453 struct gpd_cpu_data {
75454 unsigned int saved_exit_latency;
75455- struct cpuidle_state *idle_state;
75456+ cpuidle_state_no_const *idle_state;
75457 };
75458
75459 struct generic_pm_domain {
75460diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
75461index 6fa7cea..7bf6415 100644
75462--- a/include/linux/pm_runtime.h
75463+++ b/include/linux/pm_runtime.h
75464@@ -103,7 +103,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
75465
75466 static inline void pm_runtime_mark_last_busy(struct device *dev)
75467 {
75468- ACCESS_ONCE(dev->power.last_busy) = jiffies;
75469+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
75470 }
75471
75472 #else /* !CONFIG_PM_RUNTIME */
75473diff --git a/include/linux/pnp.h b/include/linux/pnp.h
75474index 195aafc..49a7bc2 100644
75475--- a/include/linux/pnp.h
75476+++ b/include/linux/pnp.h
75477@@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
75478 struct pnp_fixup {
75479 char id[7];
75480 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
75481-};
75482+} __do_const;
75483
75484 /* config parameters */
75485 #define PNP_CONFIG_NORMAL 0x0001
75486diff --git a/include/linux/poison.h b/include/linux/poison.h
75487index 2110a81..13a11bb 100644
75488--- a/include/linux/poison.h
75489+++ b/include/linux/poison.h
75490@@ -19,8 +19,8 @@
75491 * under normal circumstances, used to verify that nobody uses
75492 * non-initialized list entries.
75493 */
75494-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
75495-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
75496+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
75497+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
75498
75499 /********** include/linux/timer.h **********/
75500 /*
75501diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
75502index d8b187c3..9a9257a 100644
75503--- a/include/linux/power/smartreflex.h
75504+++ b/include/linux/power/smartreflex.h
75505@@ -238,7 +238,7 @@ struct omap_sr_class_data {
75506 int (*notify)(struct omap_sr *sr, u32 status);
75507 u8 notify_flags;
75508 u8 class_type;
75509-};
75510+} __do_const;
75511
75512 /**
75513 * struct omap_sr_nvalue_table - Smartreflex n-target value info
75514diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
75515index 4ea1d37..80f4b33 100644
75516--- a/include/linux/ppp-comp.h
75517+++ b/include/linux/ppp-comp.h
75518@@ -84,7 +84,7 @@ struct compressor {
75519 struct module *owner;
75520 /* Extra skb space needed by the compressor algorithm */
75521 unsigned int comp_extra;
75522-};
75523+} __do_const;
75524
75525 /*
75526 * The return value from decompress routine is the length of the
75527diff --git a/include/linux/preempt.h b/include/linux/preempt.h
75528index f5d4723..a6ea2fa 100644
75529--- a/include/linux/preempt.h
75530+++ b/include/linux/preempt.h
75531@@ -18,8 +18,13 @@
75532 # define sub_preempt_count(val) do { preempt_count() -= (val); } while (0)
75533 #endif
75534
75535+#define raw_add_preempt_count(val) do { preempt_count() += (val); } while (0)
75536+#define raw_sub_preempt_count(val) do { preempt_count() -= (val); } while (0)
75537+
75538 #define inc_preempt_count() add_preempt_count(1)
75539+#define raw_inc_preempt_count() raw_add_preempt_count(1)
75540 #define dec_preempt_count() sub_preempt_count(1)
75541+#define raw_dec_preempt_count() raw_sub_preempt_count(1)
75542
75543 #define preempt_count() (current_thread_info()->preempt_count)
75544
75545@@ -64,6 +69,12 @@ do { \
75546 barrier(); \
75547 } while (0)
75548
75549+#define raw_preempt_disable() \
75550+do { \
75551+ raw_inc_preempt_count(); \
75552+ barrier(); \
75553+} while (0)
75554+
75555 #define sched_preempt_enable_no_resched() \
75556 do { \
75557 barrier(); \
75558@@ -72,6 +83,12 @@ do { \
75559
75560 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
75561
75562+#define raw_preempt_enable_no_resched() \
75563+do { \
75564+ barrier(); \
75565+ raw_dec_preempt_count(); \
75566+} while (0)
75567+
75568 #define preempt_enable() \
75569 do { \
75570 preempt_enable_no_resched(); \
75571@@ -116,8 +133,10 @@ do { \
75572 * region.
75573 */
75574 #define preempt_disable() barrier()
75575+#define raw_preempt_disable() barrier()
75576 #define sched_preempt_enable_no_resched() barrier()
75577 #define preempt_enable_no_resched() barrier()
75578+#define raw_preempt_enable_no_resched() barrier()
75579 #define preempt_enable() barrier()
75580
75581 #define preempt_disable_notrace() barrier()
75582diff --git a/include/linux/printk.h b/include/linux/printk.h
75583index 22c7052..ad3fa0a 100644
75584--- a/include/linux/printk.h
75585+++ b/include/linux/printk.h
75586@@ -106,6 +106,8 @@ static inline __printf(1, 2) __cold
75587 void early_printk(const char *s, ...) { }
75588 #endif
75589
75590+extern int kptr_restrict;
75591+
75592 #ifdef CONFIG_PRINTK
75593 asmlinkage __printf(5, 0)
75594 int vprintk_emit(int facility, int level,
75595@@ -140,7 +142,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
75596
75597 extern int printk_delay_msec;
75598 extern int dmesg_restrict;
75599-extern int kptr_restrict;
75600
75601 extern void wake_up_klogd(void);
75602
75603diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
75604index 608e60a..c26f864 100644
75605--- a/include/linux/proc_fs.h
75606+++ b/include/linux/proc_fs.h
75607@@ -34,6 +34,19 @@ static inline struct proc_dir_entry *proc_create(
75608 return proc_create_data(name, mode, parent, proc_fops, NULL);
75609 }
75610
75611+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
75612+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
75613+{
75614+#ifdef CONFIG_GRKERNSEC_PROC_USER
75615+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
75616+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
75617+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
75618+#else
75619+ return proc_create_data(name, mode, parent, proc_fops, NULL);
75620+#endif
75621+}
75622+
75623+
75624 extern void proc_set_size(struct proc_dir_entry *, loff_t);
75625 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
75626 extern void *PDE_DATA(const struct inode *);
75627diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
75628index 34a1e10..03a6d03 100644
75629--- a/include/linux/proc_ns.h
75630+++ b/include/linux/proc_ns.h
75631@@ -14,7 +14,7 @@ struct proc_ns_operations {
75632 void (*put)(void *ns);
75633 int (*install)(struct nsproxy *nsproxy, void *ns);
75634 unsigned int (*inum)(void *ns);
75635-};
75636+} __do_const;
75637
75638 struct proc_ns {
75639 void *ns;
75640diff --git a/include/linux/random.h b/include/linux/random.h
75641index 3b9377d..e418336 100644
75642--- a/include/linux/random.h
75643+++ b/include/linux/random.h
75644@@ -10,9 +10,19 @@
75645
75646
75647 extern void add_device_randomness(const void *, unsigned int);
75648+
75649+static inline void add_latent_entropy(void)
75650+{
75651+
75652+#ifdef LATENT_ENTROPY_PLUGIN
75653+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
75654+#endif
75655+
75656+}
75657+
75658 extern void add_input_randomness(unsigned int type, unsigned int code,
75659- unsigned int value);
75660-extern void add_interrupt_randomness(int irq, int irq_flags);
75661+ unsigned int value) __latent_entropy;
75662+extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
75663
75664 extern void get_random_bytes(void *buf, int nbytes);
75665 extern void get_random_bytes_arch(void *buf, int nbytes);
75666@@ -32,6 +42,11 @@ void prandom_seed(u32 seed);
75667 u32 prandom_u32_state(struct rnd_state *);
75668 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
75669
75670+static inline unsigned long pax_get_random_long(void)
75671+{
75672+ return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
75673+}
75674+
75675 /*
75676 * Handle minimum values for seeds
75677 */
75678diff --git a/include/linux/rculist.h b/include/linux/rculist.h
75679index 4106721..132d42c 100644
75680--- a/include/linux/rculist.h
75681+++ b/include/linux/rculist.h
75682@@ -44,6 +44,9 @@ extern void __list_add_rcu(struct list_head *new,
75683 struct list_head *prev, struct list_head *next);
75684 #endif
75685
75686+extern void __pax_list_add_rcu(struct list_head *new,
75687+ struct list_head *prev, struct list_head *next);
75688+
75689 /**
75690 * list_add_rcu - add a new entry to rcu-protected list
75691 * @new: new entry to be added
75692@@ -65,6 +68,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
75693 __list_add_rcu(new, head, head->next);
75694 }
75695
75696+static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
75697+{
75698+ __pax_list_add_rcu(new, head, head->next);
75699+}
75700+
75701 /**
75702 * list_add_tail_rcu - add a new entry to rcu-protected list
75703 * @new: new entry to be added
75704@@ -87,6 +95,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
75705 __list_add_rcu(new, head->prev, head);
75706 }
75707
75708+static inline void pax_list_add_tail_rcu(struct list_head *new,
75709+ struct list_head *head)
75710+{
75711+ __pax_list_add_rcu(new, head->prev, head);
75712+}
75713+
75714 /**
75715 * list_del_rcu - deletes entry from list without re-initialization
75716 * @entry: the element to delete from the list.
75717@@ -117,6 +131,8 @@ static inline void list_del_rcu(struct list_head *entry)
75718 entry->prev = LIST_POISON2;
75719 }
75720
75721+extern void pax_list_del_rcu(struct list_head *entry);
75722+
75723 /**
75724 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
75725 * @n: the element to delete from the hash list.
75726diff --git a/include/linux/reboot.h b/include/linux/reboot.h
75727index 8e00f9f..9449b55 100644
75728--- a/include/linux/reboot.h
75729+++ b/include/linux/reboot.h
75730@@ -43,9 +43,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
75731 * Architecture-specific implementations of sys_reboot commands.
75732 */
75733
75734-extern void machine_restart(char *cmd);
75735-extern void machine_halt(void);
75736-extern void machine_power_off(void);
75737+extern void machine_restart(char *cmd) __noreturn;
75738+extern void machine_halt(void) __noreturn;
75739+extern void machine_power_off(void) __noreturn;
75740
75741 extern void machine_shutdown(void);
75742 struct pt_regs;
75743@@ -56,9 +56,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
75744 */
75745
75746 extern void kernel_restart_prepare(char *cmd);
75747-extern void kernel_restart(char *cmd);
75748-extern void kernel_halt(void);
75749-extern void kernel_power_off(void);
75750+extern void kernel_restart(char *cmd) __noreturn;
75751+extern void kernel_halt(void) __noreturn;
75752+extern void kernel_power_off(void) __noreturn;
75753
75754 extern int C_A_D; /* for sysctl */
75755 void ctrl_alt_del(void);
75756@@ -72,7 +72,7 @@ extern int orderly_poweroff(bool force);
75757 * Emergency restart, callable from an interrupt handler.
75758 */
75759
75760-extern void emergency_restart(void);
75761+extern void emergency_restart(void) __noreturn;
75762 #include <asm/emergency-restart.h>
75763
75764 #endif /* _LINUX_REBOOT_H */
75765diff --git a/include/linux/regset.h b/include/linux/regset.h
75766index 8e0c9fe..ac4d221 100644
75767--- a/include/linux/regset.h
75768+++ b/include/linux/regset.h
75769@@ -161,7 +161,8 @@ struct user_regset {
75770 unsigned int align;
75771 unsigned int bias;
75772 unsigned int core_note_type;
75773-};
75774+} __do_const;
75775+typedef struct user_regset __no_const user_regset_no_const;
75776
75777 /**
75778 * struct user_regset_view - available regsets
75779diff --git a/include/linux/relay.h b/include/linux/relay.h
75780index d7c8359..818daf5 100644
75781--- a/include/linux/relay.h
75782+++ b/include/linux/relay.h
75783@@ -157,7 +157,7 @@ struct rchan_callbacks
75784 * The callback should return 0 if successful, negative if not.
75785 */
75786 int (*remove_buf_file)(struct dentry *dentry);
75787-};
75788+} __no_const;
75789
75790 /*
75791 * CONFIG_RELAY kernel API, kernel/relay.c
75792diff --git a/include/linux/rio.h b/include/linux/rio.h
75793index b71d573..2f940bd 100644
75794--- a/include/linux/rio.h
75795+++ b/include/linux/rio.h
75796@@ -355,7 +355,7 @@ struct rio_ops {
75797 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
75798 u64 rstart, u32 size, u32 flags);
75799 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
75800-};
75801+} __no_const;
75802
75803 #define RIO_RESOURCE_MEM 0x00000100
75804 #define RIO_RESOURCE_DOORBELL 0x00000200
75805diff --git a/include/linux/rmap.h b/include/linux/rmap.h
75806index 6dacb93..6174423 100644
75807--- a/include/linux/rmap.h
75808+++ b/include/linux/rmap.h
75809@@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
75810 void anon_vma_init(void); /* create anon_vma_cachep */
75811 int anon_vma_prepare(struct vm_area_struct *);
75812 void unlink_anon_vmas(struct vm_area_struct *);
75813-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
75814-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
75815+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
75816+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
75817
75818 static inline void anon_vma_merge(struct vm_area_struct *vma,
75819 struct vm_area_struct *next)
75820diff --git a/include/linux/sched.h b/include/linux/sched.h
75821index 078066d..4090b3b 100644
75822--- a/include/linux/sched.h
75823+++ b/include/linux/sched.h
75824@@ -62,6 +62,7 @@ struct bio_list;
75825 struct fs_struct;
75826 struct perf_event_context;
75827 struct blk_plug;
75828+struct linux_binprm;
75829
75830 /*
75831 * List of flags we want to share for kernel threads,
75832@@ -303,7 +304,7 @@ extern char __sched_text_start[], __sched_text_end[];
75833 extern int in_sched_functions(unsigned long addr);
75834
75835 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
75836-extern signed long schedule_timeout(signed long timeout);
75837+extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
75838 extern signed long schedule_timeout_interruptible(signed long timeout);
75839 extern signed long schedule_timeout_killable(signed long timeout);
75840 extern signed long schedule_timeout_uninterruptible(signed long timeout);
75841@@ -314,6 +315,19 @@ struct nsproxy;
75842 struct user_namespace;
75843
75844 #ifdef CONFIG_MMU
75845+
75846+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
75847+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
75848+#else
75849+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
75850+{
75851+ return 0;
75852+}
75853+#endif
75854+
75855+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
75856+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
75857+
75858 extern void arch_pick_mmap_layout(struct mm_struct *mm);
75859 extern unsigned long
75860 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
75861@@ -589,6 +603,17 @@ struct signal_struct {
75862 #ifdef CONFIG_TASKSTATS
75863 struct taskstats *stats;
75864 #endif
75865+
75866+#ifdef CONFIG_GRKERNSEC
75867+ u32 curr_ip;
75868+ u32 saved_ip;
75869+ u32 gr_saddr;
75870+ u32 gr_daddr;
75871+ u16 gr_sport;
75872+ u16 gr_dport;
75873+ u8 used_accept:1;
75874+#endif
75875+
75876 #ifdef CONFIG_AUDIT
75877 unsigned audit_tty;
75878 unsigned audit_tty_log_passwd;
75879@@ -669,6 +694,14 @@ struct user_struct {
75880 struct key *session_keyring; /* UID's default session keyring */
75881 #endif
75882
75883+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
75884+ unsigned char kernel_banned;
75885+#endif
75886+#ifdef CONFIG_GRKERNSEC_BRUTE
75887+ unsigned char suid_banned;
75888+ unsigned long suid_ban_expires;
75889+#endif
75890+
75891 /* Hash table maintenance information */
75892 struct hlist_node uidhash_node;
75893 kuid_t uid;
75894@@ -1151,8 +1184,8 @@ struct task_struct {
75895 struct list_head thread_group;
75896
75897 struct completion *vfork_done; /* for vfork() */
75898- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
75899- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
75900+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
75901+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
75902
75903 cputime_t utime, stime, utimescaled, stimescaled;
75904 cputime_t gtime;
75905@@ -1177,11 +1210,6 @@ struct task_struct {
75906 struct task_cputime cputime_expires;
75907 struct list_head cpu_timers[3];
75908
75909-/* process credentials */
75910- const struct cred __rcu *real_cred; /* objective and real subjective task
75911- * credentials (COW) */
75912- const struct cred __rcu *cred; /* effective (overridable) subjective task
75913- * credentials (COW) */
75914 char comm[TASK_COMM_LEN]; /* executable name excluding path
75915 - access with [gs]et_task_comm (which lock
75916 it with task_lock())
75917@@ -1198,6 +1226,10 @@ struct task_struct {
75918 #endif
75919 /* CPU-specific state of this task */
75920 struct thread_struct thread;
75921+/* thread_info moved to task_struct */
75922+#ifdef CONFIG_X86
75923+ struct thread_info tinfo;
75924+#endif
75925 /* filesystem information */
75926 struct fs_struct *fs;
75927 /* open file information */
75928@@ -1271,6 +1303,10 @@ struct task_struct {
75929 gfp_t lockdep_reclaim_gfp;
75930 #endif
75931
75932+/* process credentials */
75933+ const struct cred __rcu *real_cred; /* objective and real subjective task
75934+ * credentials (COW) */
75935+
75936 /* journalling filesystem info */
75937 void *journal_info;
75938
75939@@ -1309,6 +1345,10 @@ struct task_struct {
75940 /* cg_list protected by css_set_lock and tsk->alloc_lock */
75941 struct list_head cg_list;
75942 #endif
75943+
75944+ const struct cred __rcu *cred; /* effective (overridable) subjective task
75945+ * credentials (COW) */
75946+
75947 #ifdef CONFIG_FUTEX
75948 struct robust_list_head __user *robust_list;
75949 #ifdef CONFIG_COMPAT
75950@@ -1406,8 +1446,76 @@ struct task_struct {
75951 unsigned int sequential_io;
75952 unsigned int sequential_io_avg;
75953 #endif
75954+
75955+#ifdef CONFIG_GRKERNSEC
75956+ /* grsecurity */
75957+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
75958+ u64 exec_id;
75959+#endif
75960+#ifdef CONFIG_GRKERNSEC_SETXID
75961+ const struct cred *delayed_cred;
75962+#endif
75963+ struct dentry *gr_chroot_dentry;
75964+ struct acl_subject_label *acl;
75965+ struct acl_role_label *role;
75966+ struct file *exec_file;
75967+ unsigned long brute_expires;
75968+ u16 acl_role_id;
75969+ /* is this the task that authenticated to the special role */
75970+ u8 acl_sp_role;
75971+ u8 is_writable;
75972+ u8 brute;
75973+ u8 gr_is_chrooted;
75974+#endif
75975+
75976 };
75977
75978+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
75979+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
75980+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
75981+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
75982+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
75983+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
75984+
75985+#ifdef CONFIG_PAX_SOFTMODE
75986+extern int pax_softmode;
75987+#endif
75988+
75989+extern int pax_check_flags(unsigned long *);
75990+
75991+/* if tsk != current then task_lock must be held on it */
75992+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
75993+static inline unsigned long pax_get_flags(struct task_struct *tsk)
75994+{
75995+ if (likely(tsk->mm))
75996+ return tsk->mm->pax_flags;
75997+ else
75998+ return 0UL;
75999+}
76000+
76001+/* if tsk != current then task_lock must be held on it */
76002+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
76003+{
76004+ if (likely(tsk->mm)) {
76005+ tsk->mm->pax_flags = flags;
76006+ return 0;
76007+ }
76008+ return -EINVAL;
76009+}
76010+#endif
76011+
76012+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
76013+extern void pax_set_initial_flags(struct linux_binprm *bprm);
76014+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
76015+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
76016+#endif
76017+
76018+struct path;
76019+extern char *pax_get_path(const struct path *path, char *buf, int buflen);
76020+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
76021+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
76022+extern void pax_report_refcount_overflow(struct pt_regs *regs);
76023+
76024 /* Future-safe accessor for struct task_struct's cpus_allowed. */
76025 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
76026
76027@@ -1466,7 +1574,7 @@ struct pid_namespace;
76028 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
76029 struct pid_namespace *ns);
76030
76031-static inline pid_t task_pid_nr(struct task_struct *tsk)
76032+static inline pid_t task_pid_nr(const struct task_struct *tsk)
76033 {
76034 return tsk->pid;
76035 }
76036@@ -1916,7 +2024,9 @@ void yield(void);
76037 extern struct exec_domain default_exec_domain;
76038
76039 union thread_union {
76040+#ifndef CONFIG_X86
76041 struct thread_info thread_info;
76042+#endif
76043 unsigned long stack[THREAD_SIZE/sizeof(long)];
76044 };
76045
76046@@ -1949,6 +2059,7 @@ extern struct pid_namespace init_pid_ns;
76047 */
76048
76049 extern struct task_struct *find_task_by_vpid(pid_t nr);
76050+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
76051 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
76052 struct pid_namespace *ns);
76053
76054@@ -2113,7 +2224,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
76055 extern void exit_itimers(struct signal_struct *);
76056 extern void flush_itimer_signals(void);
76057
76058-extern void do_group_exit(int);
76059+extern __noreturn void do_group_exit(int);
76060
76061 extern int allow_signal(int);
76062 extern int disallow_signal(int);
76063@@ -2304,9 +2415,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
76064
76065 #endif
76066
76067-static inline int object_is_on_stack(void *obj)
76068+static inline int object_starts_on_stack(void *obj)
76069 {
76070- void *stack = task_stack_page(current);
76071+ const void *stack = task_stack_page(current);
76072
76073 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
76074 }
76075diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
76076index bf8086b..962b035 100644
76077--- a/include/linux/sched/sysctl.h
76078+++ b/include/linux/sched/sysctl.h
76079@@ -30,6 +30,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
76080 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
76081
76082 extern int sysctl_max_map_count;
76083+extern unsigned long sysctl_heap_stack_gap;
76084
76085 extern unsigned int sysctl_sched_latency;
76086 extern unsigned int sysctl_sched_min_granularity;
76087diff --git a/include/linux/security.h b/include/linux/security.h
76088index 7ce53ae..8ee24a5 100644
76089--- a/include/linux/security.h
76090+++ b/include/linux/security.h
76091@@ -27,6 +27,7 @@
76092 #include <linux/slab.h>
76093 #include <linux/err.h>
76094 #include <linux/string.h>
76095+#include <linux/grsecurity.h>
76096
76097 struct linux_binprm;
76098 struct cred;
76099@@ -116,8 +117,6 @@ struct seq_file;
76100
76101 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
76102
76103-void reset_security_ops(void);
76104-
76105 #ifdef CONFIG_MMU
76106 extern unsigned long mmap_min_addr;
76107 extern unsigned long dac_mmap_min_addr;
76108diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
76109index 4e32edc..f8f2d18 100644
76110--- a/include/linux/seq_file.h
76111+++ b/include/linux/seq_file.h
76112@@ -26,6 +26,9 @@ struct seq_file {
76113 struct mutex lock;
76114 const struct seq_operations *op;
76115 int poll_event;
76116+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
76117+ u64 exec_id;
76118+#endif
76119 #ifdef CONFIG_USER_NS
76120 struct user_namespace *user_ns;
76121 #endif
76122@@ -38,6 +41,7 @@ struct seq_operations {
76123 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
76124 int (*show) (struct seq_file *m, void *v);
76125 };
76126+typedef struct seq_operations __no_const seq_operations_no_const;
76127
76128 #define SEQ_SKIP 1
76129
76130diff --git a/include/linux/shm.h b/include/linux/shm.h
76131index 429c199..4d42e38 100644
76132--- a/include/linux/shm.h
76133+++ b/include/linux/shm.h
76134@@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
76135
76136 /* The task created the shm object. NULL if the task is dead. */
76137 struct task_struct *shm_creator;
76138+#ifdef CONFIG_GRKERNSEC
76139+ time_t shm_createtime;
76140+ pid_t shm_lapid;
76141+#endif
76142 };
76143
76144 /* shm_mode upper byte flags */
76145diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
76146index 3b71a4e..5c9f309 100644
76147--- a/include/linux/skbuff.h
76148+++ b/include/linux/skbuff.h
76149@@ -648,7 +648,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
76150 extern struct sk_buff *__alloc_skb(unsigned int size,
76151 gfp_t priority, int flags, int node);
76152 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
76153-static inline struct sk_buff *alloc_skb(unsigned int size,
76154+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
76155 gfp_t priority)
76156 {
76157 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
76158@@ -764,7 +764,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
76159 */
76160 static inline int skb_queue_empty(const struct sk_buff_head *list)
76161 {
76162- return list->next == (struct sk_buff *)list;
76163+ return list->next == (const struct sk_buff *)list;
76164 }
76165
76166 /**
76167@@ -777,7 +777,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
76168 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
76169 const struct sk_buff *skb)
76170 {
76171- return skb->next == (struct sk_buff *)list;
76172+ return skb->next == (const struct sk_buff *)list;
76173 }
76174
76175 /**
76176@@ -790,7 +790,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
76177 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
76178 const struct sk_buff *skb)
76179 {
76180- return skb->prev == (struct sk_buff *)list;
76181+ return skb->prev == (const struct sk_buff *)list;
76182 }
76183
76184 /**
76185@@ -1750,7 +1750,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
76186 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
76187 */
76188 #ifndef NET_SKB_PAD
76189-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
76190+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
76191 #endif
76192
76193 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
76194@@ -2345,7 +2345,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
76195 int noblock, int *err);
76196 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
76197 struct poll_table_struct *wait);
76198-extern int skb_copy_datagram_iovec(const struct sk_buff *from,
76199+extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
76200 int offset, struct iovec *to,
76201 int size);
76202 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
76203@@ -2636,6 +2636,9 @@ static inline void nf_reset(struct sk_buff *skb)
76204 nf_bridge_put(skb->nf_bridge);
76205 skb->nf_bridge = NULL;
76206 #endif
76207+#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
76208+ skb->nf_trace = 0;
76209+#endif
76210 }
76211
76212 static inline void nf_reset_trace(struct sk_buff *skb)
76213diff --git a/include/linux/slab.h b/include/linux/slab.h
76214index 6c5cc0e..9ca0fd6 100644
76215--- a/include/linux/slab.h
76216+++ b/include/linux/slab.h
76217@@ -12,15 +12,29 @@
76218 #include <linux/gfp.h>
76219 #include <linux/types.h>
76220 #include <linux/workqueue.h>
76221-
76222+#include <linux/err.h>
76223
76224 /*
76225 * Flags to pass to kmem_cache_create().
76226 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
76227 */
76228 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
76229+
76230+#ifdef CONFIG_PAX_USERCOPY_SLABS
76231+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
76232+#else
76233+#define SLAB_USERCOPY 0x00000000UL
76234+#endif
76235+
76236 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
76237 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
76238+
76239+#ifdef CONFIG_PAX_MEMORY_SANITIZE
76240+#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
76241+#else
76242+#define SLAB_NO_SANITIZE 0x00000000UL
76243+#endif
76244+
76245 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
76246 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
76247 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
76248@@ -89,10 +103,13 @@
76249 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
76250 * Both make kfree a no-op.
76251 */
76252-#define ZERO_SIZE_PTR ((void *)16)
76253+#define ZERO_SIZE_PTR \
76254+({ \
76255+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
76256+ (void *)(-MAX_ERRNO-1L); \
76257+})
76258
76259-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
76260- (unsigned long)ZERO_SIZE_PTR)
76261+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
76262
76263
76264 struct mem_cgroup;
76265@@ -132,6 +149,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
76266 void kfree(const void *);
76267 void kzfree(const void *);
76268 size_t ksize(const void *);
76269+const char *check_heap_object(const void *ptr, unsigned long n);
76270+bool is_usercopy_object(const void *ptr);
76271
76272 /*
76273 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
76274@@ -164,7 +183,7 @@ struct kmem_cache {
76275 unsigned int align; /* Alignment as calculated */
76276 unsigned long flags; /* Active flags on the slab */
76277 const char *name; /* Slab name for sysfs */
76278- int refcount; /* Use counter */
76279+ atomic_t refcount; /* Use counter */
76280 void (*ctor)(void *); /* Called on object slot creation */
76281 struct list_head list; /* List of all slab caches on the system */
76282 };
76283@@ -238,6 +257,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
76284 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
76285 #endif
76286
76287+#ifdef CONFIG_PAX_USERCOPY_SLABS
76288+extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
76289+#endif
76290+
76291 /*
76292 * Figure out which kmalloc slab an allocation of a certain size
76293 * belongs to.
76294@@ -246,7 +269,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
76295 * 2 = 120 .. 192 bytes
76296 * n = 2^(n-1) .. 2^n -1
76297 */
76298-static __always_inline int kmalloc_index(size_t size)
76299+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
76300 {
76301 if (!size)
76302 return 0;
76303@@ -492,7 +515,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
76304 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
76305 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
76306 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
76307-extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
76308+extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
76309 #define kmalloc_track_caller(size, flags) \
76310 __kmalloc_track_caller(size, flags, _RET_IP_)
76311 #else
76312@@ -512,7 +535,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
76313 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
76314 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
76315 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
76316-extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
76317+extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
76318 #define kmalloc_node_track_caller(size, flags, node) \
76319 __kmalloc_node_track_caller(size, flags, node, \
76320 _RET_IP_)
76321diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
76322index cd40158..4e2f7af 100644
76323--- a/include/linux/slab_def.h
76324+++ b/include/linux/slab_def.h
76325@@ -50,7 +50,7 @@ struct kmem_cache {
76326 /* 4) cache creation/removal */
76327 const char *name;
76328 struct list_head list;
76329- int refcount;
76330+ atomic_t refcount;
76331 int object_size;
76332 int align;
76333
76334@@ -66,10 +66,14 @@ struct kmem_cache {
76335 unsigned long node_allocs;
76336 unsigned long node_frees;
76337 unsigned long node_overflow;
76338- atomic_t allochit;
76339- atomic_t allocmiss;
76340- atomic_t freehit;
76341- atomic_t freemiss;
76342+ atomic_unchecked_t allochit;
76343+ atomic_unchecked_t allocmiss;
76344+ atomic_unchecked_t freehit;
76345+ atomic_unchecked_t freemiss;
76346+#ifdef CONFIG_PAX_MEMORY_SANITIZE
76347+ atomic_unchecked_t sanitized;
76348+ atomic_unchecked_t not_sanitized;
76349+#endif
76350
76351 /*
76352 * If debugging is enabled, then the allocator can add additional
76353@@ -103,7 +107,7 @@ struct kmem_cache {
76354 };
76355
76356 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
76357-void *__kmalloc(size_t size, gfp_t flags);
76358+void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
76359
76360 #ifdef CONFIG_TRACING
76361 extern void *kmem_cache_alloc_trace(struct kmem_cache *, gfp_t, size_t);
76362@@ -136,6 +140,13 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
76363 cachep = kmalloc_dma_caches[i];
76364 else
76365 #endif
76366+
76367+#ifdef CONFIG_PAX_USERCOPY_SLABS
76368+ if (flags & GFP_USERCOPY)
76369+ cachep = kmalloc_usercopy_caches[i];
76370+ else
76371+#endif
76372+
76373 cachep = kmalloc_caches[i];
76374
76375 ret = kmem_cache_alloc_trace(cachep, flags, size);
76376@@ -146,7 +157,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
76377 }
76378
76379 #ifdef CONFIG_NUMA
76380-extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
76381+extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
76382 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
76383
76384 #ifdef CONFIG_TRACING
76385@@ -185,6 +196,13 @@ static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
76386 cachep = kmalloc_dma_caches[i];
76387 else
76388 #endif
76389+
76390+#ifdef CONFIG_PAX_USERCOPY_SLABS
76391+ if (flags & GFP_USERCOPY)
76392+ cachep = kmalloc_usercopy_caches[i];
76393+ else
76394+#endif
76395+
76396 cachep = kmalloc_caches[i];
76397
76398 return kmem_cache_alloc_node_trace(cachep, flags, node, size);
76399diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
76400index 095a5a4..4b82027 100644
76401--- a/include/linux/slob_def.h
76402+++ b/include/linux/slob_def.h
76403@@ -11,7 +11,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
76404 return kmem_cache_alloc_node(cachep, flags, NUMA_NO_NODE);
76405 }
76406
76407-void *__kmalloc_node(size_t size, gfp_t flags, int node);
76408+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
76409
76410 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
76411 {
76412@@ -23,7 +23,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
76413 return __kmalloc_node(size, flags, NUMA_NO_NODE);
76414 }
76415
76416-static __always_inline void *__kmalloc(size_t size, gfp_t flags)
76417+static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
76418 {
76419 return kmalloc(size, flags);
76420 }
76421diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
76422index 027276f..092bfe8 100644
76423--- a/include/linux/slub_def.h
76424+++ b/include/linux/slub_def.h
76425@@ -80,7 +80,7 @@ struct kmem_cache {
76426 struct kmem_cache_order_objects max;
76427 struct kmem_cache_order_objects min;
76428 gfp_t allocflags; /* gfp flags to use on each alloc */
76429- int refcount; /* Refcount for slab cache destroy */
76430+ atomic_t refcount; /* Refcount for slab cache destroy */
76431 void (*ctor)(void *);
76432 int inuse; /* Offset to metadata */
76433 int align; /* Alignment */
76434@@ -105,7 +105,7 @@ struct kmem_cache {
76435 };
76436
76437 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
76438-void *__kmalloc(size_t size, gfp_t flags);
76439+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
76440
76441 static __always_inline void *
76442 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
76443@@ -149,7 +149,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
76444 }
76445 #endif
76446
76447-static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
76448+static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
76449 {
76450 unsigned int order = get_order(size);
76451 return kmalloc_order_trace(size, flags, order);
76452@@ -175,7 +175,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
76453 }
76454
76455 #ifdef CONFIG_NUMA
76456-void *__kmalloc_node(size_t size, gfp_t flags, int node);
76457+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
76458 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
76459
76460 #ifdef CONFIG_TRACING
76461diff --git a/include/linux/smp.h b/include/linux/smp.h
76462index c181399..09d7b92 100644
76463--- a/include/linux/smp.h
76464+++ b/include/linux/smp.h
76465@@ -217,7 +217,9 @@ static inline void kick_all_cpus_sync(void) { }
76466 #endif
76467
76468 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
76469+#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
76470 #define put_cpu() preempt_enable()
76471+#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
76472
76473 /*
76474 * Callback to arch code if there's nosmp or maxcpus=0 on the
76475diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
76476index 54f91d3..be2c379 100644
76477--- a/include/linux/sock_diag.h
76478+++ b/include/linux/sock_diag.h
76479@@ -11,7 +11,7 @@ struct sock;
76480 struct sock_diag_handler {
76481 __u8 family;
76482 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
76483-};
76484+} __do_const;
76485
76486 int sock_diag_register(const struct sock_diag_handler *h);
76487 void sock_diag_unregister(const struct sock_diag_handler *h);
76488diff --git a/include/linux/sonet.h b/include/linux/sonet.h
76489index 680f9a3..f13aeb0 100644
76490--- a/include/linux/sonet.h
76491+++ b/include/linux/sonet.h
76492@@ -7,7 +7,7 @@
76493 #include <uapi/linux/sonet.h>
76494
76495 struct k_sonet_stats {
76496-#define __HANDLE_ITEM(i) atomic_t i
76497+#define __HANDLE_ITEM(i) atomic_unchecked_t i
76498 __SONET_ITEMS
76499 #undef __HANDLE_ITEM
76500 };
76501diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
76502index 07d8e53..dc934c9 100644
76503--- a/include/linux/sunrpc/addr.h
76504+++ b/include/linux/sunrpc/addr.h
76505@@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
76506 {
76507 switch (sap->sa_family) {
76508 case AF_INET:
76509- return ntohs(((struct sockaddr_in *)sap)->sin_port);
76510+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
76511 case AF_INET6:
76512- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
76513+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
76514 }
76515 return 0;
76516 }
76517@@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
76518 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
76519 const struct sockaddr *src)
76520 {
76521- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
76522+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
76523 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
76524
76525 dsin->sin_family = ssin->sin_family;
76526@@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
76527 if (sa->sa_family != AF_INET6)
76528 return 0;
76529
76530- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
76531+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
76532 }
76533
76534 #endif /* _LINUX_SUNRPC_ADDR_H */
76535diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
76536index bfe11be..12bc8c4 100644
76537--- a/include/linux/sunrpc/clnt.h
76538+++ b/include/linux/sunrpc/clnt.h
76539@@ -96,7 +96,7 @@ struct rpc_procinfo {
76540 unsigned int p_timer; /* Which RTT timer to use */
76541 u32 p_statidx; /* Which procedure to account */
76542 const char * p_name; /* name of procedure */
76543-};
76544+} __do_const;
76545
76546 #ifdef __KERNEL__
76547
76548diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
76549index 1f0216b..6a4fa50 100644
76550--- a/include/linux/sunrpc/svc.h
76551+++ b/include/linux/sunrpc/svc.h
76552@@ -411,7 +411,7 @@ struct svc_procedure {
76553 unsigned int pc_count; /* call count */
76554 unsigned int pc_cachetype; /* cache info (NFS) */
76555 unsigned int pc_xdrressize; /* maximum size of XDR reply */
76556-};
76557+} __do_const;
76558
76559 /*
76560 * Function prototypes.
76561diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
76562index 0b8e3e6..33e0a01 100644
76563--- a/include/linux/sunrpc/svc_rdma.h
76564+++ b/include/linux/sunrpc/svc_rdma.h
76565@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
76566 extern unsigned int svcrdma_max_requests;
76567 extern unsigned int svcrdma_max_req_size;
76568
76569-extern atomic_t rdma_stat_recv;
76570-extern atomic_t rdma_stat_read;
76571-extern atomic_t rdma_stat_write;
76572-extern atomic_t rdma_stat_sq_starve;
76573-extern atomic_t rdma_stat_rq_starve;
76574-extern atomic_t rdma_stat_rq_poll;
76575-extern atomic_t rdma_stat_rq_prod;
76576-extern atomic_t rdma_stat_sq_poll;
76577-extern atomic_t rdma_stat_sq_prod;
76578+extern atomic_unchecked_t rdma_stat_recv;
76579+extern atomic_unchecked_t rdma_stat_read;
76580+extern atomic_unchecked_t rdma_stat_write;
76581+extern atomic_unchecked_t rdma_stat_sq_starve;
76582+extern atomic_unchecked_t rdma_stat_rq_starve;
76583+extern atomic_unchecked_t rdma_stat_rq_poll;
76584+extern atomic_unchecked_t rdma_stat_rq_prod;
76585+extern atomic_unchecked_t rdma_stat_sq_poll;
76586+extern atomic_unchecked_t rdma_stat_sq_prod;
76587
76588 #define RPCRDMA_VERSION 1
76589
76590diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
76591index 8d71d65..f79586e 100644
76592--- a/include/linux/sunrpc/svcauth.h
76593+++ b/include/linux/sunrpc/svcauth.h
76594@@ -120,7 +120,7 @@ struct auth_ops {
76595 int (*release)(struct svc_rqst *rq);
76596 void (*domain_release)(struct auth_domain *);
76597 int (*set_client)(struct svc_rqst *rq);
76598-};
76599+} __do_const;
76600
76601 #define SVC_GARBAGE 1
76602 #define SVC_SYSERR 2
76603diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
76604index a5ffd32..0935dea 100644
76605--- a/include/linux/swiotlb.h
76606+++ b/include/linux/swiotlb.h
76607@@ -60,7 +60,8 @@ extern void
76608
76609 extern void
76610 swiotlb_free_coherent(struct device *hwdev, size_t size,
76611- void *vaddr, dma_addr_t dma_handle);
76612+ void *vaddr, dma_addr_t dma_handle,
76613+ struct dma_attrs *attrs);
76614
76615 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
76616 unsigned long offset, size_t size,
76617diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
76618index 84662ec..5271947 100644
76619--- a/include/linux/syscalls.h
76620+++ b/include/linux/syscalls.h
76621@@ -97,8 +97,14 @@ struct sigaltstack;
76622 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
76623
76624 #define __SC_DECL(t, a) t a
76625+#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))
76626 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
76627-#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
76628+#define __SC_LONG(t, a) __typeof( \
76629+ __builtin_choose_expr( \
76630+ sizeof(t) > sizeof(int), \
76631+ (t) 0, \
76632+ __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
76633+ )) a
76634 #define __SC_CAST(t, a) (t) a
76635 #define __SC_ARGS(t, a) a
76636 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
76637@@ -362,11 +368,11 @@ asmlinkage long sys_sync(void);
76638 asmlinkage long sys_fsync(unsigned int fd);
76639 asmlinkage long sys_fdatasync(unsigned int fd);
76640 asmlinkage long sys_bdflush(int func, long data);
76641-asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
76642- char __user *type, unsigned long flags,
76643+asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
76644+ const char __user *type, unsigned long flags,
76645 void __user *data);
76646-asmlinkage long sys_umount(char __user *name, int flags);
76647-asmlinkage long sys_oldumount(char __user *name);
76648+asmlinkage long sys_umount(const char __user *name, int flags);
76649+asmlinkage long sys_oldumount(const char __user *name);
76650 asmlinkage long sys_truncate(const char __user *path, long length);
76651 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
76652 asmlinkage long sys_stat(const char __user *filename,
76653@@ -578,7 +584,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
76654 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
76655 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
76656 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
76657- struct sockaddr __user *, int);
76658+ struct sockaddr __user *, int) __intentional_overflow(0);
76659 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
76660 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
76661 unsigned int vlen, unsigned flags);
76662diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
76663index 27b3b0b..e093dd9 100644
76664--- a/include/linux/syscore_ops.h
76665+++ b/include/linux/syscore_ops.h
76666@@ -16,7 +16,7 @@ struct syscore_ops {
76667 int (*suspend)(void);
76668 void (*resume)(void);
76669 void (*shutdown)(void);
76670-};
76671+} __do_const;
76672
76673 extern void register_syscore_ops(struct syscore_ops *ops);
76674 extern void unregister_syscore_ops(struct syscore_ops *ops);
76675diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
76676index 14a8ff2..af52bad 100644
76677--- a/include/linux/sysctl.h
76678+++ b/include/linux/sysctl.h
76679@@ -34,13 +34,13 @@ struct ctl_table_root;
76680 struct ctl_table_header;
76681 struct ctl_dir;
76682
76683-typedef struct ctl_table ctl_table;
76684-
76685 typedef int proc_handler (struct ctl_table *ctl, int write,
76686 void __user *buffer, size_t *lenp, loff_t *ppos);
76687
76688 extern int proc_dostring(struct ctl_table *, int,
76689 void __user *, size_t *, loff_t *);
76690+extern int proc_dostring_modpriv(struct ctl_table *, int,
76691+ void __user *, size_t *, loff_t *);
76692 extern int proc_dointvec(struct ctl_table *, int,
76693 void __user *, size_t *, loff_t *);
76694 extern int proc_dointvec_minmax(struct ctl_table *, int,
76695@@ -115,7 +115,9 @@ struct ctl_table
76696 struct ctl_table_poll *poll;
76697 void *extra1;
76698 void *extra2;
76699-};
76700+} __do_const;
76701+typedef struct ctl_table __no_const ctl_table_no_const;
76702+typedef struct ctl_table ctl_table;
76703
76704 struct ctl_node {
76705 struct rb_node node;
76706diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
76707index 9e8a9b5..753de68 100644
76708--- a/include/linux/sysfs.h
76709+++ b/include/linux/sysfs.h
76710@@ -33,7 +33,8 @@ struct attribute {
76711 struct lock_class_key *key;
76712 struct lock_class_key skey;
76713 #endif
76714-};
76715+} __do_const;
76716+typedef struct attribute __no_const attribute_no_const;
76717
76718 /**
76719 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
76720@@ -62,7 +63,8 @@ struct attribute_group {
76721 struct attribute *, int);
76722 struct attribute **attrs;
76723 struct bin_attribute **bin_attrs;
76724-};
76725+} __do_const;
76726+typedef struct attribute_group __no_const attribute_group_no_const;
76727
76728 /**
76729 * Use these macros to make defining attributes easier. See include/linux/device.h
76730@@ -123,7 +125,8 @@ struct bin_attribute {
76731 char *, loff_t, size_t);
76732 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
76733 struct vm_area_struct *vma);
76734-};
76735+} __do_const;
76736+typedef struct bin_attribute __no_const bin_attribute_no_const;
76737
76738 /**
76739 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
76740diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
76741index 7faf933..9b85a0c 100644
76742--- a/include/linux/sysrq.h
76743+++ b/include/linux/sysrq.h
76744@@ -16,6 +16,7 @@
76745
76746 #include <linux/errno.h>
76747 #include <linux/types.h>
76748+#include <linux/compiler.h>
76749
76750 /* Enable/disable SYSRQ support by default (0==no, 1==yes). */
76751 #define SYSRQ_DEFAULT_ENABLE 1
76752@@ -36,7 +37,7 @@ struct sysrq_key_op {
76753 char *help_msg;
76754 char *action_msg;
76755 int enable_mask;
76756-};
76757+} __do_const;
76758
76759 #ifdef CONFIG_MAGIC_SYSRQ
76760
76761diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
76762index e7e0473..7989295 100644
76763--- a/include/linux/thread_info.h
76764+++ b/include/linux/thread_info.h
76765@@ -148,6 +148,15 @@ static inline bool test_and_clear_restore_sigmask(void)
76766 #error "no set_restore_sigmask() provided and default one won't work"
76767 #endif
76768
76769+extern void __check_object_size(const void *ptr, unsigned long n, bool to_user);
76770+static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
76771+{
76772+#ifndef CONFIG_PAX_USERCOPY_DEBUG
76773+ if (!__builtin_constant_p(n))
76774+#endif
76775+ __check_object_size(ptr, n, to_user);
76776+}
76777+
76778 #endif /* __KERNEL__ */
76779
76780 #endif /* _LINUX_THREAD_INFO_H */
76781diff --git a/include/linux/tty.h b/include/linux/tty.h
76782index 01ac30e..bf18a71 100644
76783--- a/include/linux/tty.h
76784+++ b/include/linux/tty.h
76785@@ -194,7 +194,7 @@ struct tty_port {
76786 const struct tty_port_operations *ops; /* Port operations */
76787 spinlock_t lock; /* Lock protecting tty field */
76788 int blocked_open; /* Waiting to open */
76789- int count; /* Usage count */
76790+ atomic_t count; /* Usage count */
76791 wait_queue_head_t open_wait; /* Open waiters */
76792 wait_queue_head_t close_wait; /* Close waiters */
76793 wait_queue_head_t delta_msr_wait; /* Modem status change */
76794@@ -547,7 +547,7 @@ extern int tty_port_open(struct tty_port *port,
76795 struct tty_struct *tty, struct file *filp);
76796 static inline int tty_port_users(struct tty_port *port)
76797 {
76798- return port->count + port->blocked_open;
76799+ return atomic_read(&port->count) + port->blocked_open;
76800 }
76801
76802 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
76803diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
76804index 756a609..b302dd6 100644
76805--- a/include/linux/tty_driver.h
76806+++ b/include/linux/tty_driver.h
76807@@ -285,7 +285,7 @@ struct tty_operations {
76808 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
76809 #endif
76810 const struct file_operations *proc_fops;
76811-};
76812+} __do_const;
76813
76814 struct tty_driver {
76815 int magic; /* magic number for this structure */
76816diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
76817index a1b0489..f02e17c 100644
76818--- a/include/linux/tty_ldisc.h
76819+++ b/include/linux/tty_ldisc.h
76820@@ -198,7 +198,7 @@ struct tty_ldisc_ops {
76821
76822 struct module *owner;
76823
76824- int refcount;
76825+ atomic_t refcount;
76826 };
76827
76828 struct tty_ldisc {
76829diff --git a/include/linux/types.h b/include/linux/types.h
76830index 4d118ba..c3ee9bf 100644
76831--- a/include/linux/types.h
76832+++ b/include/linux/types.h
76833@@ -176,10 +176,26 @@ typedef struct {
76834 int counter;
76835 } atomic_t;
76836
76837+#ifdef CONFIG_PAX_REFCOUNT
76838+typedef struct {
76839+ int counter;
76840+} atomic_unchecked_t;
76841+#else
76842+typedef atomic_t atomic_unchecked_t;
76843+#endif
76844+
76845 #ifdef CONFIG_64BIT
76846 typedef struct {
76847 long counter;
76848 } atomic64_t;
76849+
76850+#ifdef CONFIG_PAX_REFCOUNT
76851+typedef struct {
76852+ long counter;
76853+} atomic64_unchecked_t;
76854+#else
76855+typedef atomic64_t atomic64_unchecked_t;
76856+#endif
76857 #endif
76858
76859 struct list_head {
76860diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
76861index 5ca0951..ab496a5 100644
76862--- a/include/linux/uaccess.h
76863+++ b/include/linux/uaccess.h
76864@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
76865 long ret; \
76866 mm_segment_t old_fs = get_fs(); \
76867 \
76868- set_fs(KERNEL_DS); \
76869 pagefault_disable(); \
76870- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
76871- pagefault_enable(); \
76872+ set_fs(KERNEL_DS); \
76873+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
76874 set_fs(old_fs); \
76875+ pagefault_enable(); \
76876 ret; \
76877 })
76878
76879diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
76880index 8e522cbc..aa8572d 100644
76881--- a/include/linux/uidgid.h
76882+++ b/include/linux/uidgid.h
76883@@ -197,4 +197,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
76884
76885 #endif /* CONFIG_USER_NS */
76886
76887+#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
76888+#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
76889+#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
76890+#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
76891+
76892 #endif /* _LINUX_UIDGID_H */
76893diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
76894index 99c1b4d..562e6f3 100644
76895--- a/include/linux/unaligned/access_ok.h
76896+++ b/include/linux/unaligned/access_ok.h
76897@@ -4,34 +4,34 @@
76898 #include <linux/kernel.h>
76899 #include <asm/byteorder.h>
76900
76901-static inline u16 get_unaligned_le16(const void *p)
76902+static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
76903 {
76904- return le16_to_cpup((__le16 *)p);
76905+ return le16_to_cpup((const __le16 *)p);
76906 }
76907
76908-static inline u32 get_unaligned_le32(const void *p)
76909+static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
76910 {
76911- return le32_to_cpup((__le32 *)p);
76912+ return le32_to_cpup((const __le32 *)p);
76913 }
76914
76915-static inline u64 get_unaligned_le64(const void *p)
76916+static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
76917 {
76918- return le64_to_cpup((__le64 *)p);
76919+ return le64_to_cpup((const __le64 *)p);
76920 }
76921
76922-static inline u16 get_unaligned_be16(const void *p)
76923+static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
76924 {
76925- return be16_to_cpup((__be16 *)p);
76926+ return be16_to_cpup((const __be16 *)p);
76927 }
76928
76929-static inline u32 get_unaligned_be32(const void *p)
76930+static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
76931 {
76932- return be32_to_cpup((__be32 *)p);
76933+ return be32_to_cpup((const __be32 *)p);
76934 }
76935
76936-static inline u64 get_unaligned_be64(const void *p)
76937+static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
76938 {
76939- return be64_to_cpup((__be64 *)p);
76940+ return be64_to_cpup((const __be64 *)p);
76941 }
76942
76943 static inline void put_unaligned_le16(u16 val, void *p)
76944diff --git a/include/linux/usb.h b/include/linux/usb.h
76945index 0eec268..4496526 100644
76946--- a/include/linux/usb.h
76947+++ b/include/linux/usb.h
76948@@ -560,7 +560,7 @@ struct usb_device {
76949 int maxchild;
76950
76951 u32 quirks;
76952- atomic_t urbnum;
76953+ atomic_unchecked_t urbnum;
76954
76955 unsigned long active_duration;
76956
76957@@ -1617,7 +1617,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
76958
76959 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
76960 __u8 request, __u8 requesttype, __u16 value, __u16 index,
76961- void *data, __u16 size, int timeout);
76962+ void *data, __u16 size, int timeout) __intentional_overflow(-1);
76963 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
76964 void *data, int len, int *actual_length, int timeout);
76965 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
76966diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
76967index e452ba6..78f8e80 100644
76968--- a/include/linux/usb/renesas_usbhs.h
76969+++ b/include/linux/usb/renesas_usbhs.h
76970@@ -39,7 +39,7 @@ enum {
76971 */
76972 struct renesas_usbhs_driver_callback {
76973 int (*notify_hotplug)(struct platform_device *pdev);
76974-};
76975+} __no_const;
76976
76977 /*
76978 * callback functions for platform
76979diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
76980index 6f8fbcf..8259001 100644
76981--- a/include/linux/vermagic.h
76982+++ b/include/linux/vermagic.h
76983@@ -25,9 +25,35 @@
76984 #define MODULE_ARCH_VERMAGIC ""
76985 #endif
76986
76987+#ifdef CONFIG_PAX_REFCOUNT
76988+#define MODULE_PAX_REFCOUNT "REFCOUNT "
76989+#else
76990+#define MODULE_PAX_REFCOUNT ""
76991+#endif
76992+
76993+#ifdef CONSTIFY_PLUGIN
76994+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
76995+#else
76996+#define MODULE_CONSTIFY_PLUGIN ""
76997+#endif
76998+
76999+#ifdef STACKLEAK_PLUGIN
77000+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
77001+#else
77002+#define MODULE_STACKLEAK_PLUGIN ""
77003+#endif
77004+
77005+#ifdef CONFIG_GRKERNSEC
77006+#define MODULE_GRSEC "GRSEC "
77007+#else
77008+#define MODULE_GRSEC ""
77009+#endif
77010+
77011 #define VERMAGIC_STRING \
77012 UTS_RELEASE " " \
77013 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
77014 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
77015- MODULE_ARCH_VERMAGIC
77016+ MODULE_ARCH_VERMAGIC \
77017+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
77018+ MODULE_GRSEC
77019
77020diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
77021index 4b8a891..c20e936 100644
77022--- a/include/linux/vmalloc.h
77023+++ b/include/linux/vmalloc.h
77024@@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
77025 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
77026 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
77027 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
77028+
77029+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
77030+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
77031+#endif
77032+
77033 /* bits [20..32] reserved for arch specific ioremap internals */
77034
77035 /*
77036@@ -75,7 +80,7 @@ extern void *vmalloc_32_user(unsigned long size);
77037 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
77038 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
77039 unsigned long start, unsigned long end, gfp_t gfp_mask,
77040- pgprot_t prot, int node, const void *caller);
77041+ pgprot_t prot, int node, const void *caller) __size_overflow(1);
77042 extern void vfree(const void *addr);
77043
77044 extern void *vmap(struct page **pages, unsigned int count,
77045@@ -141,8 +146,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
77046 extern void free_vm_area(struct vm_struct *area);
77047
77048 /* for /dev/kmem */
77049-extern long vread(char *buf, char *addr, unsigned long count);
77050-extern long vwrite(char *buf, char *addr, unsigned long count);
77051+extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
77052+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
77053
77054 /*
77055 * Internals. Dont't use..
77056diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
77057index c586679..f06b389 100644
77058--- a/include/linux/vmstat.h
77059+++ b/include/linux/vmstat.h
77060@@ -90,18 +90,18 @@ static inline void vm_events_fold_cpu(int cpu)
77061 /*
77062 * Zone based page accounting with per cpu differentials.
77063 */
77064-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
77065+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
77066
77067 static inline void zone_page_state_add(long x, struct zone *zone,
77068 enum zone_stat_item item)
77069 {
77070- atomic_long_add(x, &zone->vm_stat[item]);
77071- atomic_long_add(x, &vm_stat[item]);
77072+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
77073+ atomic_long_add_unchecked(x, &vm_stat[item]);
77074 }
77075
77076 static inline unsigned long global_page_state(enum zone_stat_item item)
77077 {
77078- long x = atomic_long_read(&vm_stat[item]);
77079+ long x = atomic_long_read_unchecked(&vm_stat[item]);
77080 #ifdef CONFIG_SMP
77081 if (x < 0)
77082 x = 0;
77083@@ -112,7 +112,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
77084 static inline unsigned long zone_page_state(struct zone *zone,
77085 enum zone_stat_item item)
77086 {
77087- long x = atomic_long_read(&zone->vm_stat[item]);
77088+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
77089 #ifdef CONFIG_SMP
77090 if (x < 0)
77091 x = 0;
77092@@ -129,7 +129,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
77093 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
77094 enum zone_stat_item item)
77095 {
77096- long x = atomic_long_read(&zone->vm_stat[item]);
77097+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
77098
77099 #ifdef CONFIG_SMP
77100 int cpu;
77101@@ -221,8 +221,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
77102
77103 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
77104 {
77105- atomic_long_inc(&zone->vm_stat[item]);
77106- atomic_long_inc(&vm_stat[item]);
77107+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
77108+ atomic_long_inc_unchecked(&vm_stat[item]);
77109 }
77110
77111 static inline void __inc_zone_page_state(struct page *page,
77112@@ -233,8 +233,8 @@ static inline void __inc_zone_page_state(struct page *page,
77113
77114 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
77115 {
77116- atomic_long_dec(&zone->vm_stat[item]);
77117- atomic_long_dec(&vm_stat[item]);
77118+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
77119+ atomic_long_dec_unchecked(&vm_stat[item]);
77120 }
77121
77122 static inline void __dec_zone_page_state(struct page *page,
77123diff --git a/include/linux/xattr.h b/include/linux/xattr.h
77124index fdbafc6..49dfe4f 100644
77125--- a/include/linux/xattr.h
77126+++ b/include/linux/xattr.h
77127@@ -28,7 +28,7 @@ struct xattr_handler {
77128 size_t size, int handler_flags);
77129 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
77130 size_t size, int flags, int handler_flags);
77131-};
77132+} __do_const;
77133
77134 struct xattr {
77135 char *name;
77136@@ -37,6 +37,9 @@ struct xattr {
77137 };
77138
77139 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
77140+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
77141+ssize_t pax_getxattr(struct dentry *, void *, size_t);
77142+#endif
77143 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
77144 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
77145 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
77146diff --git a/include/linux/zlib.h b/include/linux/zlib.h
77147index 9c5a6b4..09c9438 100644
77148--- a/include/linux/zlib.h
77149+++ b/include/linux/zlib.h
77150@@ -31,6 +31,7 @@
77151 #define _ZLIB_H
77152
77153 #include <linux/zconf.h>
77154+#include <linux/compiler.h>
77155
77156 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
77157 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
77158@@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
77159
77160 /* basic functions */
77161
77162-extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
77163+extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
77164 /*
77165 Returns the number of bytes that needs to be allocated for a per-
77166 stream workspace with the specified parameters. A pointer to this
77167diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
77168index c768c9f..bdcaa5a 100644
77169--- a/include/media/v4l2-dev.h
77170+++ b/include/media/v4l2-dev.h
77171@@ -76,7 +76,7 @@ struct v4l2_file_operations {
77172 int (*mmap) (struct file *, struct vm_area_struct *);
77173 int (*open) (struct file *);
77174 int (*release) (struct file *);
77175-};
77176+} __do_const;
77177
77178 /*
77179 * Newer version of video_device, handled by videodev2.c
77180diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
77181index c9b1593..a572459 100644
77182--- a/include/media/v4l2-device.h
77183+++ b/include/media/v4l2-device.h
77184@@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
77185 this function returns 0. If the name ends with a digit (e.g. cx18),
77186 then the name will be set to cx18-0 since cx180 looks really odd. */
77187 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
77188- atomic_t *instance);
77189+ atomic_unchecked_t *instance);
77190
77191 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
77192 Since the parent disappears this ensures that v4l2_dev doesn't have an
77193diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
77194index d9fa68f..45c88d1 100644
77195--- a/include/net/9p/transport.h
77196+++ b/include/net/9p/transport.h
77197@@ -63,7 +63,7 @@ struct p9_trans_module {
77198 int (*cancelled)(struct p9_client *, struct p9_req_t *req);
77199 int (*zc_request)(struct p9_client *, struct p9_req_t *,
77200 char *, char *, int , int, int, int);
77201-};
77202+} __do_const;
77203
77204 void v9fs_register_trans(struct p9_trans_module *m);
77205 void v9fs_unregister_trans(struct p9_trans_module *m);
77206diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
77207index 1a966af..2767cf6 100644
77208--- a/include/net/bluetooth/l2cap.h
77209+++ b/include/net/bluetooth/l2cap.h
77210@@ -551,7 +551,7 @@ struct l2cap_ops {
77211 void (*defer) (struct l2cap_chan *chan);
77212 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
77213 unsigned long len, int nb);
77214-};
77215+} __do_const;
77216
77217 struct l2cap_conn {
77218 struct hci_conn *hcon;
77219diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
77220index f2ae33d..c457cf0 100644
77221--- a/include/net/caif/cfctrl.h
77222+++ b/include/net/caif/cfctrl.h
77223@@ -52,7 +52,7 @@ struct cfctrl_rsp {
77224 void (*radioset_rsp)(void);
77225 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
77226 struct cflayer *client_layer);
77227-};
77228+} __no_const;
77229
77230 /* Link Setup Parameters for CAIF-Links. */
77231 struct cfctrl_link_param {
77232@@ -101,8 +101,8 @@ struct cfctrl_request_info {
77233 struct cfctrl {
77234 struct cfsrvl serv;
77235 struct cfctrl_rsp res;
77236- atomic_t req_seq_no;
77237- atomic_t rsp_seq_no;
77238+ atomic_unchecked_t req_seq_no;
77239+ atomic_unchecked_t rsp_seq_no;
77240 struct list_head list;
77241 /* Protects from simultaneous access to first_req list */
77242 spinlock_t info_list_lock;
77243diff --git a/include/net/flow.h b/include/net/flow.h
77244index 628e11b..4c475df 100644
77245--- a/include/net/flow.h
77246+++ b/include/net/flow.h
77247@@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
77248
77249 extern void flow_cache_flush(void);
77250 extern void flow_cache_flush_deferred(void);
77251-extern atomic_t flow_cache_genid;
77252+extern atomic_unchecked_t flow_cache_genid;
77253
77254 #endif
77255diff --git a/include/net/genetlink.h b/include/net/genetlink.h
77256index 8e0b6c8..73cf605 100644
77257--- a/include/net/genetlink.h
77258+++ b/include/net/genetlink.h
77259@@ -120,7 +120,7 @@ struct genl_ops {
77260 struct netlink_callback *cb);
77261 int (*done)(struct netlink_callback *cb);
77262 struct list_head ops_list;
77263-};
77264+} __do_const;
77265
77266 extern int __genl_register_family(struct genl_family *family);
77267
77268diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
77269index 734d9b5..48a9a4b 100644
77270--- a/include/net/gro_cells.h
77271+++ b/include/net/gro_cells.h
77272@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
77273 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
77274
77275 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
77276- atomic_long_inc(&dev->rx_dropped);
77277+ atomic_long_inc_unchecked(&dev->rx_dropped);
77278 kfree_skb(skb);
77279 return;
77280 }
77281diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
77282index de2c785..0588a6b 100644
77283--- a/include/net/inet_connection_sock.h
77284+++ b/include/net/inet_connection_sock.h
77285@@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
77286 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
77287 int (*bind_conflict)(const struct sock *sk,
77288 const struct inet_bind_bucket *tb, bool relax);
77289-};
77290+} __do_const;
77291
77292 /** inet_connection_sock - INET connection oriented sock
77293 *
77294diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
77295index 53f464d..0bd0b49 100644
77296--- a/include/net/inetpeer.h
77297+++ b/include/net/inetpeer.h
77298@@ -47,8 +47,8 @@ struct inet_peer {
77299 */
77300 union {
77301 struct {
77302- atomic_t rid; /* Frag reception counter */
77303- atomic_t ip_id_count; /* IP ID for the next packet */
77304+ atomic_unchecked_t rid; /* Frag reception counter */
77305+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
77306 };
77307 struct rcu_head rcu;
77308 struct inet_peer *gc_next;
77309@@ -178,16 +178,13 @@ static inline void inet_peer_refcheck(const struct inet_peer *p)
77310 /* can be called with or without local BH being disabled */
77311 static inline int inet_getid(struct inet_peer *p, int more)
77312 {
77313- int old, new;
77314+ int id;
77315 more++;
77316 inet_peer_refcheck(p);
77317- do {
77318- old = atomic_read(&p->ip_id_count);
77319- new = old + more;
77320- if (!new)
77321- new = 1;
77322- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
77323- return new;
77324+ id = atomic_add_return_unchecked(more, &p->ip_id_count);
77325+ if (!id)
77326+ id = atomic_inc_return_unchecked(&p->ip_id_count);
77327+ return id;
77328 }
77329
77330 #endif /* _NET_INETPEER_H */
77331diff --git a/include/net/ip.h b/include/net/ip.h
77332index a68f838..74518ab 100644
77333--- a/include/net/ip.h
77334+++ b/include/net/ip.h
77335@@ -202,7 +202,7 @@ extern struct local_ports {
77336 } sysctl_local_ports;
77337 extern void inet_get_local_port_range(int *low, int *high);
77338
77339-extern unsigned long *sysctl_local_reserved_ports;
77340+extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
77341 static inline int inet_is_reserved_local_port(int port)
77342 {
77343 return test_bit(port, sysctl_local_reserved_ports);
77344diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
77345index cbf2be3..3683f6d 100644
77346--- a/include/net/ip_fib.h
77347+++ b/include/net/ip_fib.h
77348@@ -169,7 +169,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
77349
77350 #define FIB_RES_SADDR(net, res) \
77351 ((FIB_RES_NH(res).nh_saddr_genid == \
77352- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
77353+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
77354 FIB_RES_NH(res).nh_saddr : \
77355 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
77356 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
77357diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
77358index f0d70f0..185f15b 100644
77359--- a/include/net/ip_vs.h
77360+++ b/include/net/ip_vs.h
77361@@ -588,7 +588,7 @@ struct ip_vs_conn {
77362 struct ip_vs_conn *control; /* Master control connection */
77363 atomic_t n_control; /* Number of controlled ones */
77364 struct ip_vs_dest *dest; /* real server */
77365- atomic_t in_pkts; /* incoming packet counter */
77366+ atomic_unchecked_t in_pkts; /* incoming packet counter */
77367
77368 /* packet transmitter for different forwarding methods. If it
77369 mangles the packet, it must return NF_DROP or better NF_STOLEN,
77370@@ -737,7 +737,7 @@ struct ip_vs_dest {
77371 __be16 port; /* port number of the server */
77372 union nf_inet_addr addr; /* IP address of the server */
77373 volatile unsigned int flags; /* dest status flags */
77374- atomic_t conn_flags; /* flags to copy to conn */
77375+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
77376 atomic_t weight; /* server weight */
77377
77378 atomic_t refcnt; /* reference counter */
77379@@ -993,11 +993,11 @@ struct netns_ipvs {
77380 /* ip_vs_lblc */
77381 int sysctl_lblc_expiration;
77382 struct ctl_table_header *lblc_ctl_header;
77383- struct ctl_table *lblc_ctl_table;
77384+ ctl_table_no_const *lblc_ctl_table;
77385 /* ip_vs_lblcr */
77386 int sysctl_lblcr_expiration;
77387 struct ctl_table_header *lblcr_ctl_header;
77388- struct ctl_table *lblcr_ctl_table;
77389+ ctl_table_no_const *lblcr_ctl_table;
77390 /* ip_vs_est */
77391 struct list_head est_list; /* estimator list */
77392 spinlock_t est_lock;
77393diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
77394index 80ffde3..968b0f4 100644
77395--- a/include/net/irda/ircomm_tty.h
77396+++ b/include/net/irda/ircomm_tty.h
77397@@ -35,6 +35,7 @@
77398 #include <linux/termios.h>
77399 #include <linux/timer.h>
77400 #include <linux/tty.h> /* struct tty_struct */
77401+#include <asm/local.h>
77402
77403 #include <net/irda/irias_object.h>
77404 #include <net/irda/ircomm_core.h>
77405diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
77406index 714cc9a..ea05f3e 100644
77407--- a/include/net/iucv/af_iucv.h
77408+++ b/include/net/iucv/af_iucv.h
77409@@ -149,7 +149,7 @@ struct iucv_skb_cb {
77410 struct iucv_sock_list {
77411 struct hlist_head head;
77412 rwlock_t lock;
77413- atomic_t autobind_name;
77414+ atomic_unchecked_t autobind_name;
77415 };
77416
77417 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
77418diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
77419index df83f69..9b640b8 100644
77420--- a/include/net/llc_c_ac.h
77421+++ b/include/net/llc_c_ac.h
77422@@ -87,7 +87,7 @@
77423 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
77424 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
77425
77426-typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
77427+typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
77428
77429 extern int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
77430 extern int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
77431diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
77432index 6ca3113..f8026dd 100644
77433--- a/include/net/llc_c_ev.h
77434+++ b/include/net/llc_c_ev.h
77435@@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
77436 return (struct llc_conn_state_ev *)skb->cb;
77437 }
77438
77439-typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
77440-typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
77441+typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
77442+typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
77443
77444 extern int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
77445 extern int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
77446diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
77447index 0e79cfb..f46db31 100644
77448--- a/include/net/llc_c_st.h
77449+++ b/include/net/llc_c_st.h
77450@@ -37,7 +37,7 @@ struct llc_conn_state_trans {
77451 u8 next_state;
77452 llc_conn_ev_qfyr_t *ev_qualifiers;
77453 llc_conn_action_t *ev_actions;
77454-};
77455+} __do_const;
77456
77457 struct llc_conn_state {
77458 u8 current_state;
77459diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
77460index 37a3bbd..55a4241 100644
77461--- a/include/net/llc_s_ac.h
77462+++ b/include/net/llc_s_ac.h
77463@@ -23,7 +23,7 @@
77464 #define SAP_ACT_TEST_IND 9
77465
77466 /* All action functions must look like this */
77467-typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
77468+typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
77469
77470 extern int llc_sap_action_unitdata_ind(struct llc_sap *sap,
77471 struct sk_buff *skb);
77472diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
77473index 567c681..cd73ac0 100644
77474--- a/include/net/llc_s_st.h
77475+++ b/include/net/llc_s_st.h
77476@@ -20,7 +20,7 @@ struct llc_sap_state_trans {
77477 llc_sap_ev_t ev;
77478 u8 next_state;
77479 llc_sap_action_t *ev_actions;
77480-};
77481+} __do_const;
77482
77483 struct llc_sap_state {
77484 u8 curr_state;
77485diff --git a/include/net/mac80211.h b/include/net/mac80211.h
77486index 551ba6a..11c99c1 100644
77487--- a/include/net/mac80211.h
77488+++ b/include/net/mac80211.h
77489@@ -4221,7 +4221,7 @@ struct rate_control_ops {
77490 void (*add_sta_debugfs)(void *priv, void *priv_sta,
77491 struct dentry *dir);
77492 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
77493-};
77494+} __do_const;
77495
77496 static inline int rate_supported(struct ieee80211_sta *sta,
77497 enum ieee80211_band band,
77498diff --git a/include/net/neighbour.h b/include/net/neighbour.h
77499index 7e748ad..5c6229b 100644
77500--- a/include/net/neighbour.h
77501+++ b/include/net/neighbour.h
77502@@ -123,7 +123,7 @@ struct neigh_ops {
77503 void (*error_report)(struct neighbour *, struct sk_buff *);
77504 int (*output)(struct neighbour *, struct sk_buff *);
77505 int (*connected_output)(struct neighbour *, struct sk_buff *);
77506-};
77507+} __do_const;
77508
77509 struct pneigh_entry {
77510 struct pneigh_entry *next;
77511diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
77512index 84e37b1..8eba19a 100644
77513--- a/include/net/net_namespace.h
77514+++ b/include/net/net_namespace.h
77515@@ -119,8 +119,8 @@ struct net {
77516 struct netns_ipvs *ipvs;
77517 #endif
77518 struct sock *diag_nlsk;
77519- atomic_t rt_genid;
77520- atomic_t fnhe_genid;
77521+ atomic_unchecked_t rt_genid;
77522+ atomic_unchecked_t fnhe_genid;
77523 };
77524
77525 /*
77526@@ -277,7 +277,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
77527 #define __net_init __init
77528 #define __net_exit __exit_refok
77529 #define __net_initdata __initdata
77530+#ifdef CONSTIFY_PLUGIN
77531 #define __net_initconst __initconst
77532+#else
77533+#define __net_initconst __initdata
77534+#endif
77535 #endif
77536
77537 struct pernet_operations {
77538@@ -287,7 +291,7 @@ struct pernet_operations {
77539 void (*exit_batch)(struct list_head *net_exit_list);
77540 int *id;
77541 size_t size;
77542-};
77543+} __do_const;
77544
77545 /*
77546 * Use these carefully. If you implement a network device and it
77547@@ -335,22 +339,22 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
77548
77549 static inline int rt_genid(struct net *net)
77550 {
77551- return atomic_read(&net->rt_genid);
77552+ return atomic_read_unchecked(&net->rt_genid);
77553 }
77554
77555 static inline void rt_genid_bump(struct net *net)
77556 {
77557- atomic_inc(&net->rt_genid);
77558+ atomic_inc_unchecked(&net->rt_genid);
77559 }
77560
77561 static inline int fnhe_genid(struct net *net)
77562 {
77563- return atomic_read(&net->fnhe_genid);
77564+ return atomic_read_unchecked(&net->fnhe_genid);
77565 }
77566
77567 static inline void fnhe_genid_bump(struct net *net)
77568 {
77569- atomic_inc(&net->fnhe_genid);
77570+ atomic_inc_unchecked(&net->fnhe_genid);
77571 }
77572
77573 #endif /* __NET_NET_NAMESPACE_H */
77574diff --git a/include/net/netdma.h b/include/net/netdma.h
77575index 8ba8ce2..99b7fff 100644
77576--- a/include/net/netdma.h
77577+++ b/include/net/netdma.h
77578@@ -24,7 +24,7 @@
77579 #include <linux/dmaengine.h>
77580 #include <linux/skbuff.h>
77581
77582-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
77583+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
77584 struct sk_buff *skb, int offset, struct iovec *to,
77585 size_t len, struct dma_pinned_list *pinned_list);
77586
77587diff --git a/include/net/netlink.h b/include/net/netlink.h
77588index 9690b0f..87aded7 100644
77589--- a/include/net/netlink.h
77590+++ b/include/net/netlink.h
77591@@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
77592 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
77593 {
77594 if (mark)
77595- skb_trim(skb, (unsigned char *) mark - skb->data);
77596+ skb_trim(skb, (const unsigned char *) mark - skb->data);
77597 }
77598
77599 /**
77600diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
77601index c9c0c53..53f24c3 100644
77602--- a/include/net/netns/conntrack.h
77603+++ b/include/net/netns/conntrack.h
77604@@ -12,10 +12,10 @@ struct nf_conntrack_ecache;
77605 struct nf_proto_net {
77606 #ifdef CONFIG_SYSCTL
77607 struct ctl_table_header *ctl_table_header;
77608- struct ctl_table *ctl_table;
77609+ ctl_table_no_const *ctl_table;
77610 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
77611 struct ctl_table_header *ctl_compat_header;
77612- struct ctl_table *ctl_compat_table;
77613+ ctl_table_no_const *ctl_compat_table;
77614 #endif
77615 #endif
77616 unsigned int users;
77617@@ -58,7 +58,7 @@ struct nf_ip_net {
77618 struct nf_icmp_net icmpv6;
77619 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
77620 struct ctl_table_header *ctl_table_header;
77621- struct ctl_table *ctl_table;
77622+ ctl_table_no_const *ctl_table;
77623 #endif
77624 };
77625
77626diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
77627index 2ba9de8..47bd6c7 100644
77628--- a/include/net/netns/ipv4.h
77629+++ b/include/net/netns/ipv4.h
77630@@ -67,7 +67,7 @@ struct netns_ipv4 {
77631 kgid_t sysctl_ping_group_range[2];
77632 long sysctl_tcp_mem[3];
77633
77634- atomic_t dev_addr_genid;
77635+ atomic_unchecked_t dev_addr_genid;
77636
77637 #ifdef CONFIG_IP_MROUTE
77638 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
77639diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
77640index 005e2c2..023d340 100644
77641--- a/include/net/netns/ipv6.h
77642+++ b/include/net/netns/ipv6.h
77643@@ -71,7 +71,7 @@ struct netns_ipv6 {
77644 struct fib_rules_ops *mr6_rules_ops;
77645 #endif
77646 #endif
77647- atomic_t dev_addr_genid;
77648+ atomic_unchecked_t dev_addr_genid;
77649 };
77650
77651 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
77652diff --git a/include/net/ping.h b/include/net/ping.h
77653index 5db0224..0d65365 100644
77654--- a/include/net/ping.h
77655+++ b/include/net/ping.h
77656@@ -55,7 +55,7 @@ struct ping_iter_state {
77657 extern struct proto ping_prot;
77658 extern struct ping_table ping_table;
77659 #if IS_ENABLED(CONFIG_IPV6)
77660-extern struct pingv6_ops pingv6_ops;
77661+extern struct pingv6_ops *pingv6_ops;
77662 #endif
77663
77664 struct pingfakehdr {
77665diff --git a/include/net/protocol.h b/include/net/protocol.h
77666index 047c047..b9dad15 100644
77667--- a/include/net/protocol.h
77668+++ b/include/net/protocol.h
77669@@ -44,7 +44,7 @@ struct net_protocol {
77670 void (*err_handler)(struct sk_buff *skb, u32 info);
77671 unsigned int no_policy:1,
77672 netns_ok:1;
77673-};
77674+} __do_const;
77675
77676 #if IS_ENABLED(CONFIG_IPV6)
77677 struct inet6_protocol {
77678@@ -57,7 +57,7 @@ struct inet6_protocol {
77679 u8 type, u8 code, int offset,
77680 __be32 info);
77681 unsigned int flags; /* INET6_PROTO_xxx */
77682-};
77683+} __do_const;
77684
77685 #define INET6_PROTO_NOPOLICY 0x1
77686 #define INET6_PROTO_FINAL 0x2
77687diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
77688index 7026648..584cc8c 100644
77689--- a/include/net/rtnetlink.h
77690+++ b/include/net/rtnetlink.h
77691@@ -81,7 +81,7 @@ struct rtnl_link_ops {
77692 const struct net_device *dev);
77693 unsigned int (*get_num_tx_queues)(void);
77694 unsigned int (*get_num_rx_queues)(void);
77695-};
77696+} __do_const;
77697
77698 extern int __rtnl_link_register(struct rtnl_link_ops *ops);
77699 extern void __rtnl_link_unregister(struct rtnl_link_ops *ops);
77700diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
77701index 2a82d13..62a31c2 100644
77702--- a/include/net/sctp/sm.h
77703+++ b/include/net/sctp/sm.h
77704@@ -87,7 +87,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
77705 typedef struct {
77706 sctp_state_fn_t *fn;
77707 const char *name;
77708-} sctp_sm_table_entry_t;
77709+} __do_const sctp_sm_table_entry_t;
77710
77711 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
77712 * currently in use.
77713@@ -299,7 +299,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
77714 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
77715
77716 /* Extern declarations for major data structures. */
77717-extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
77718+extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
77719
77720
77721 /* Get the size of a DATA chunk payload. */
77722diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
77723index e745c92..3641448 100644
77724--- a/include/net/sctp/structs.h
77725+++ b/include/net/sctp/structs.h
77726@@ -516,7 +516,7 @@ struct sctp_pf {
77727 struct sctp_association *asoc);
77728 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
77729 struct sctp_af *af;
77730-};
77731+} __do_const;
77732
77733
77734 /* Structure to track chunk fragments that have been acked, but peer
77735diff --git a/include/net/sock.h b/include/net/sock.h
77736index 31d5cfb..9ee0602 100644
77737--- a/include/net/sock.h
77738+++ b/include/net/sock.h
77739@@ -331,7 +331,7 @@ struct sock {
77740 unsigned int sk_napi_id;
77741 unsigned int sk_ll_usec;
77742 #endif
77743- atomic_t sk_drops;
77744+ atomic_unchecked_t sk_drops;
77745 int sk_rcvbuf;
77746
77747 struct sk_filter __rcu *sk_filter;
77748@@ -1803,7 +1803,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
77749 }
77750
77751 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
77752- char __user *from, char *to,
77753+ char __user *from, unsigned char *to,
77754 int copy, int offset)
77755 {
77756 if (skb->ip_summed == CHECKSUM_NONE) {
77757@@ -2065,7 +2065,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
77758 }
77759 }
77760
77761-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
77762+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
77763
77764 /**
77765 * sk_page_frag - return an appropriate page_frag
77766diff --git a/include/net/tcp.h b/include/net/tcp.h
77767index d198005..c974a393 100644
77768--- a/include/net/tcp.h
77769+++ b/include/net/tcp.h
77770@@ -521,7 +521,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
77771 extern void tcp_xmit_retransmit_queue(struct sock *);
77772 extern void tcp_simple_retransmit(struct sock *);
77773 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
77774-extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
77775+extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
77776
77777 extern void tcp_send_probe0(struct sock *);
77778 extern void tcp_send_partial(struct sock *);
77779@@ -694,8 +694,8 @@ struct tcp_skb_cb {
77780 struct inet6_skb_parm h6;
77781 #endif
77782 } header; /* For incoming frames */
77783- __u32 seq; /* Starting sequence number */
77784- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
77785+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
77786+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
77787 __u32 when; /* used to compute rtt's */
77788 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
77789
77790@@ -709,7 +709,7 @@ struct tcp_skb_cb {
77791
77792 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
77793 /* 1 byte hole */
77794- __u32 ack_seq; /* Sequence number ACK'd */
77795+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
77796 };
77797
77798 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
77799diff --git a/include/net/xfrm.h b/include/net/xfrm.h
77800index e823786..53b0608 100644
77801--- a/include/net/xfrm.h
77802+++ b/include/net/xfrm.h
77803@@ -287,7 +287,6 @@ struct xfrm_dst;
77804 struct xfrm_policy_afinfo {
77805 unsigned short family;
77806 struct dst_ops *dst_ops;
77807- void (*garbage_collect)(struct net *net);
77808 struct dst_entry *(*dst_lookup)(struct net *net, int tos,
77809 const xfrm_address_t *saddr,
77810 const xfrm_address_t *daddr);
77811@@ -305,7 +304,7 @@ struct xfrm_policy_afinfo {
77812 struct net_device *dev,
77813 const struct flowi *fl);
77814 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
77815-};
77816+} __do_const;
77817
77818 extern int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
77819 extern int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
77820@@ -342,7 +341,7 @@ struct xfrm_state_afinfo {
77821 int (*transport_finish)(struct sk_buff *skb,
77822 int async);
77823 void (*local_error)(struct sk_buff *skb, u32 mtu);
77824-};
77825+} __do_const;
77826
77827 extern int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
77828 extern int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
77829@@ -427,7 +426,7 @@ struct xfrm_mode {
77830 struct module *owner;
77831 unsigned int encap;
77832 int flags;
77833-};
77834+} __do_const;
77835
77836 /* Flags for xfrm_mode. */
77837 enum {
77838@@ -524,7 +523,7 @@ struct xfrm_policy {
77839 struct timer_list timer;
77840
77841 struct flow_cache_object flo;
77842- atomic_t genid;
77843+ atomic_unchecked_t genid;
77844 u32 priority;
77845 u32 index;
77846 struct xfrm_mark mark;
77847@@ -1164,6 +1163,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
77848 }
77849
77850 extern void xfrm_garbage_collect(struct net *net);
77851+extern void xfrm_garbage_collect_deferred(struct net *net);
77852
77853 #else
77854
77855@@ -1202,6 +1202,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
77856 static inline void xfrm_garbage_collect(struct net *net)
77857 {
77858 }
77859+static inline void xfrm_garbage_collect_deferred(struct net *net)
77860+{
77861+}
77862 #endif
77863
77864 static __inline__
77865diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
77866index 1a046b1..ee0bef0 100644
77867--- a/include/rdma/iw_cm.h
77868+++ b/include/rdma/iw_cm.h
77869@@ -122,7 +122,7 @@ struct iw_cm_verbs {
77870 int backlog);
77871
77872 int (*destroy_listen)(struct iw_cm_id *cm_id);
77873-};
77874+} __no_const;
77875
77876 /**
77877 * iw_create_cm_id - Create an IW CM identifier.
77878diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
77879index e1379b4..67eafbe 100644
77880--- a/include/scsi/libfc.h
77881+++ b/include/scsi/libfc.h
77882@@ -762,6 +762,7 @@ struct libfc_function_template {
77883 */
77884 void (*disc_stop_final) (struct fc_lport *);
77885 };
77886+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
77887
77888 /**
77889 * struct fc_disc - Discovery context
77890@@ -866,7 +867,7 @@ struct fc_lport {
77891 struct fc_vport *vport;
77892
77893 /* Operational Information */
77894- struct libfc_function_template tt;
77895+ libfc_function_template_no_const tt;
77896 u8 link_up;
77897 u8 qfull;
77898 enum fc_lport_state state;
77899diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
77900index a44954c..5da04b2 100644
77901--- a/include/scsi/scsi_device.h
77902+++ b/include/scsi/scsi_device.h
77903@@ -172,9 +172,9 @@ struct scsi_device {
77904 unsigned int max_device_blocked; /* what device_blocked counts down from */
77905 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
77906
77907- atomic_t iorequest_cnt;
77908- atomic_t iodone_cnt;
77909- atomic_t ioerr_cnt;
77910+ atomic_unchecked_t iorequest_cnt;
77911+ atomic_unchecked_t iodone_cnt;
77912+ atomic_unchecked_t ioerr_cnt;
77913
77914 struct device sdev_gendev,
77915 sdev_dev;
77916diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
77917index b797e8f..8e2c3aa 100644
77918--- a/include/scsi/scsi_transport_fc.h
77919+++ b/include/scsi/scsi_transport_fc.h
77920@@ -751,7 +751,8 @@ struct fc_function_template {
77921 unsigned long show_host_system_hostname:1;
77922
77923 unsigned long disable_target_scan:1;
77924-};
77925+} __do_const;
77926+typedef struct fc_function_template __no_const fc_function_template_no_const;
77927
77928
77929 /**
77930diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
77931index 9031a26..750d592 100644
77932--- a/include/sound/compress_driver.h
77933+++ b/include/sound/compress_driver.h
77934@@ -128,7 +128,7 @@ struct snd_compr_ops {
77935 struct snd_compr_caps *caps);
77936 int (*get_codec_caps) (struct snd_compr_stream *stream,
77937 struct snd_compr_codec_caps *codec);
77938-};
77939+} __no_const;
77940
77941 /**
77942 * struct snd_compr: Compressed device
77943diff --git a/include/sound/soc.h b/include/sound/soc.h
77944index 6eabee7..58afb50 100644
77945--- a/include/sound/soc.h
77946+++ b/include/sound/soc.h
77947@@ -783,7 +783,7 @@ struct snd_soc_codec_driver {
77948 /* probe ordering - for components with runtime dependencies */
77949 int probe_order;
77950 int remove_order;
77951-};
77952+} __do_const;
77953
77954 /* SoC platform interface */
77955 struct snd_soc_platform_driver {
77956@@ -829,7 +829,7 @@ struct snd_soc_platform_driver {
77957 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
77958 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
77959 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
77960-};
77961+} __do_const;
77962
77963 struct snd_soc_platform {
77964 const char *name;
77965diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
77966index e34fc90..ecefa2c 100644
77967--- a/include/target/target_core_base.h
77968+++ b/include/target/target_core_base.h
77969@@ -643,7 +643,7 @@ struct se_device {
77970 spinlock_t stats_lock;
77971 /* Active commands on this virtual SE device */
77972 atomic_t simple_cmds;
77973- atomic_t dev_ordered_id;
77974+ atomic_unchecked_t dev_ordered_id;
77975 atomic_t dev_ordered_sync;
77976 atomic_t dev_qf_count;
77977 int export_count;
77978diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
77979new file mode 100644
77980index 0000000..fb634b7
77981--- /dev/null
77982+++ b/include/trace/events/fs.h
77983@@ -0,0 +1,53 @@
77984+#undef TRACE_SYSTEM
77985+#define TRACE_SYSTEM fs
77986+
77987+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
77988+#define _TRACE_FS_H
77989+
77990+#include <linux/fs.h>
77991+#include <linux/tracepoint.h>
77992+
77993+TRACE_EVENT(do_sys_open,
77994+
77995+ TP_PROTO(const char *filename, int flags, int mode),
77996+
77997+ TP_ARGS(filename, flags, mode),
77998+
77999+ TP_STRUCT__entry(
78000+ __string( filename, filename )
78001+ __field( int, flags )
78002+ __field( int, mode )
78003+ ),
78004+
78005+ TP_fast_assign(
78006+ __assign_str(filename, filename);
78007+ __entry->flags = flags;
78008+ __entry->mode = mode;
78009+ ),
78010+
78011+ TP_printk("\"%s\" %x %o",
78012+ __get_str(filename), __entry->flags, __entry->mode)
78013+);
78014+
78015+TRACE_EVENT(open_exec,
78016+
78017+ TP_PROTO(const char *filename),
78018+
78019+ TP_ARGS(filename),
78020+
78021+ TP_STRUCT__entry(
78022+ __string( filename, filename )
78023+ ),
78024+
78025+ TP_fast_assign(
78026+ __assign_str(filename, filename);
78027+ ),
78028+
78029+ TP_printk("\"%s\"",
78030+ __get_str(filename))
78031+);
78032+
78033+#endif /* _TRACE_FS_H */
78034+
78035+/* This part must be outside protection */
78036+#include <trace/define_trace.h>
78037diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
78038index 1c09820..7f5ec79 100644
78039--- a/include/trace/events/irq.h
78040+++ b/include/trace/events/irq.h
78041@@ -36,7 +36,7 @@ struct softirq_action;
78042 */
78043 TRACE_EVENT(irq_handler_entry,
78044
78045- TP_PROTO(int irq, struct irqaction *action),
78046+ TP_PROTO(int irq, const struct irqaction *action),
78047
78048 TP_ARGS(irq, action),
78049
78050@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
78051 */
78052 TRACE_EVENT(irq_handler_exit,
78053
78054- TP_PROTO(int irq, struct irqaction *action, int ret),
78055+ TP_PROTO(int irq, const struct irqaction *action, int ret),
78056
78057 TP_ARGS(irq, action, ret),
78058
78059diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
78060index 7caf44c..23c6f27 100644
78061--- a/include/uapi/linux/a.out.h
78062+++ b/include/uapi/linux/a.out.h
78063@@ -39,6 +39,14 @@ enum machine_type {
78064 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
78065 };
78066
78067+/* Constants for the N_FLAGS field */
78068+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
78069+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
78070+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
78071+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
78072+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
78073+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
78074+
78075 #if !defined (N_MAGIC)
78076 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
78077 #endif
78078diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
78079index d876736..ccce5c0 100644
78080--- a/include/uapi/linux/byteorder/little_endian.h
78081+++ b/include/uapi/linux/byteorder/little_endian.h
78082@@ -42,51 +42,51 @@
78083
78084 static inline __le64 __cpu_to_le64p(const __u64 *p)
78085 {
78086- return (__force __le64)*p;
78087+ return (__force const __le64)*p;
78088 }
78089-static inline __u64 __le64_to_cpup(const __le64 *p)
78090+static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
78091 {
78092- return (__force __u64)*p;
78093+ return (__force const __u64)*p;
78094 }
78095 static inline __le32 __cpu_to_le32p(const __u32 *p)
78096 {
78097- return (__force __le32)*p;
78098+ return (__force const __le32)*p;
78099 }
78100 static inline __u32 __le32_to_cpup(const __le32 *p)
78101 {
78102- return (__force __u32)*p;
78103+ return (__force const __u32)*p;
78104 }
78105 static inline __le16 __cpu_to_le16p(const __u16 *p)
78106 {
78107- return (__force __le16)*p;
78108+ return (__force const __le16)*p;
78109 }
78110 static inline __u16 __le16_to_cpup(const __le16 *p)
78111 {
78112- return (__force __u16)*p;
78113+ return (__force const __u16)*p;
78114 }
78115 static inline __be64 __cpu_to_be64p(const __u64 *p)
78116 {
78117- return (__force __be64)__swab64p(p);
78118+ return (__force const __be64)__swab64p(p);
78119 }
78120 static inline __u64 __be64_to_cpup(const __be64 *p)
78121 {
78122- return __swab64p((__u64 *)p);
78123+ return __swab64p((const __u64 *)p);
78124 }
78125 static inline __be32 __cpu_to_be32p(const __u32 *p)
78126 {
78127- return (__force __be32)__swab32p(p);
78128+ return (__force const __be32)__swab32p(p);
78129 }
78130-static inline __u32 __be32_to_cpup(const __be32 *p)
78131+static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
78132 {
78133- return __swab32p((__u32 *)p);
78134+ return __swab32p((const __u32 *)p);
78135 }
78136 static inline __be16 __cpu_to_be16p(const __u16 *p)
78137 {
78138- return (__force __be16)__swab16p(p);
78139+ return (__force const __be16)__swab16p(p);
78140 }
78141 static inline __u16 __be16_to_cpup(const __be16 *p)
78142 {
78143- return __swab16p((__u16 *)p);
78144+ return __swab16p((const __u16 *)p);
78145 }
78146 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
78147 #define __le64_to_cpus(x) do { (void)(x); } while (0)
78148diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
78149index ef6103b..d4e65dd 100644
78150--- a/include/uapi/linux/elf.h
78151+++ b/include/uapi/linux/elf.h
78152@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
78153 #define PT_GNU_EH_FRAME 0x6474e550
78154
78155 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
78156+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
78157+
78158+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
78159+
78160+/* Constants for the e_flags field */
78161+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
78162+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
78163+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
78164+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
78165+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
78166+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
78167
78168 /*
78169 * Extended Numbering
78170@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
78171 #define DT_DEBUG 21
78172 #define DT_TEXTREL 22
78173 #define DT_JMPREL 23
78174+#define DT_FLAGS 30
78175+ #define DF_TEXTREL 0x00000004
78176 #define DT_ENCODING 32
78177 #define OLD_DT_LOOS 0x60000000
78178 #define DT_LOOS 0x6000000d
78179@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
78180 #define PF_W 0x2
78181 #define PF_X 0x1
78182
78183+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
78184+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
78185+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
78186+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
78187+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
78188+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
78189+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
78190+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
78191+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
78192+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
78193+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
78194+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
78195+
78196 typedef struct elf32_phdr{
78197 Elf32_Word p_type;
78198 Elf32_Off p_offset;
78199@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
78200 #define EI_OSABI 7
78201 #define EI_PAD 8
78202
78203+#define EI_PAX 14
78204+
78205 #define ELFMAG0 0x7f /* EI_MAG */
78206 #define ELFMAG1 'E'
78207 #define ELFMAG2 'L'
78208diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
78209index aa169c4..6a2771d 100644
78210--- a/include/uapi/linux/personality.h
78211+++ b/include/uapi/linux/personality.h
78212@@ -30,6 +30,7 @@ enum {
78213 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
78214 ADDR_NO_RANDOMIZE | \
78215 ADDR_COMPAT_LAYOUT | \
78216+ ADDR_LIMIT_3GB | \
78217 MMAP_PAGE_ZERO)
78218
78219 /*
78220diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
78221index 7530e74..e714828 100644
78222--- a/include/uapi/linux/screen_info.h
78223+++ b/include/uapi/linux/screen_info.h
78224@@ -43,7 +43,8 @@ struct screen_info {
78225 __u16 pages; /* 0x32 */
78226 __u16 vesa_attributes; /* 0x34 */
78227 __u32 capabilities; /* 0x36 */
78228- __u8 _reserved[6]; /* 0x3a */
78229+ __u16 vesapm_size; /* 0x3a */
78230+ __u8 _reserved[4]; /* 0x3c */
78231 } __attribute__((packed));
78232
78233 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
78234diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
78235index 0e011eb..82681b1 100644
78236--- a/include/uapi/linux/swab.h
78237+++ b/include/uapi/linux/swab.h
78238@@ -43,7 +43,7 @@
78239 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
78240 */
78241
78242-static inline __attribute_const__ __u16 __fswab16(__u16 val)
78243+static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
78244 {
78245 #ifdef __HAVE_BUILTIN_BSWAP16__
78246 return __builtin_bswap16(val);
78247@@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
78248 #endif
78249 }
78250
78251-static inline __attribute_const__ __u32 __fswab32(__u32 val)
78252+static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
78253 {
78254 #ifdef __HAVE_BUILTIN_BSWAP32__
78255 return __builtin_bswap32(val);
78256@@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
78257 #endif
78258 }
78259
78260-static inline __attribute_const__ __u64 __fswab64(__u64 val)
78261+static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
78262 {
78263 #ifdef __HAVE_BUILTIN_BSWAP64__
78264 return __builtin_bswap64(val);
78265diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
78266index 6d67213..8dab561 100644
78267--- a/include/uapi/linux/sysctl.h
78268+++ b/include/uapi/linux/sysctl.h
78269@@ -155,7 +155,11 @@ enum
78270 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
78271 };
78272
78273-
78274+#ifdef CONFIG_PAX_SOFTMODE
78275+enum {
78276+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
78277+};
78278+#endif
78279
78280 /* CTL_VM names: */
78281 enum
78282diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
78283index e4629b9..6958086 100644
78284--- a/include/uapi/linux/xattr.h
78285+++ b/include/uapi/linux/xattr.h
78286@@ -63,5 +63,9 @@
78287 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
78288 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
78289
78290+/* User namespace */
78291+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
78292+#define XATTR_PAX_FLAGS_SUFFIX "flags"
78293+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
78294
78295 #endif /* _UAPI_LINUX_XATTR_H */
78296diff --git a/include/video/udlfb.h b/include/video/udlfb.h
78297index f9466fa..f4e2b81 100644
78298--- a/include/video/udlfb.h
78299+++ b/include/video/udlfb.h
78300@@ -53,10 +53,10 @@ struct dlfb_data {
78301 u32 pseudo_palette[256];
78302 int blank_mode; /*one of FB_BLANK_ */
78303 /* blit-only rendering path metrics, exposed through sysfs */
78304- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
78305- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
78306- atomic_t bytes_sent; /* to usb, after compression including overhead */
78307- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
78308+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
78309+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
78310+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
78311+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
78312 };
78313
78314 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
78315diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
78316index 30f5362..8ed8ac9 100644
78317--- a/include/video/uvesafb.h
78318+++ b/include/video/uvesafb.h
78319@@ -122,6 +122,7 @@ struct uvesafb_par {
78320 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
78321 u8 pmi_setpal; /* PMI for palette changes */
78322 u16 *pmi_base; /* protected mode interface location */
78323+ u8 *pmi_code; /* protected mode code location */
78324 void *pmi_start;
78325 void *pmi_pal;
78326 u8 *vbe_state_orig; /*
78327diff --git a/init/Kconfig b/init/Kconfig
78328index fed81b5..0d3b964 100644
78329--- a/init/Kconfig
78330+++ b/init/Kconfig
78331@@ -1069,6 +1069,7 @@ endif # CGROUPS
78332
78333 config CHECKPOINT_RESTORE
78334 bool "Checkpoint/restore support" if EXPERT
78335+ depends on !GRKERNSEC
78336 default n
78337 help
78338 Enables additional kernel features in a sake of checkpoint/restore.
78339@@ -1553,7 +1554,7 @@ config SLUB_DEBUG
78340
78341 config COMPAT_BRK
78342 bool "Disable heap randomization"
78343- default y
78344+ default n
78345 help
78346 Randomizing heap placement makes heap exploits harder, but it
78347 also breaks ancient binaries (including anything libc5 based).
78348@@ -1827,7 +1828,7 @@ config INIT_ALL_POSSIBLE
78349 config STOP_MACHINE
78350 bool
78351 default y
78352- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
78353+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
78354 help
78355 Need stop_machine() primitive.
78356
78357diff --git a/init/Makefile b/init/Makefile
78358index 7bc47ee..6da2dc7 100644
78359--- a/init/Makefile
78360+++ b/init/Makefile
78361@@ -2,6 +2,9 @@
78362 # Makefile for the linux kernel.
78363 #
78364
78365+ccflags-y := $(GCC_PLUGINS_CFLAGS)
78366+asflags-y := $(GCC_PLUGINS_AFLAGS)
78367+
78368 obj-y := main.o version.o mounts.o
78369 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
78370 obj-y += noinitramfs.o
78371diff --git a/init/do_mounts.c b/init/do_mounts.c
78372index 816014c..c2054db 100644
78373--- a/init/do_mounts.c
78374+++ b/init/do_mounts.c
78375@@ -355,11 +355,11 @@ static void __init get_fs_names(char *page)
78376 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
78377 {
78378 struct super_block *s;
78379- int err = sys_mount(name, "/root", fs, flags, data);
78380+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
78381 if (err)
78382 return err;
78383
78384- sys_chdir("/root");
78385+ sys_chdir((const char __force_user *)"/root");
78386 s = current->fs->pwd.dentry->d_sb;
78387 ROOT_DEV = s->s_dev;
78388 printk(KERN_INFO
78389@@ -480,18 +480,18 @@ void __init change_floppy(char *fmt, ...)
78390 va_start(args, fmt);
78391 vsprintf(buf, fmt, args);
78392 va_end(args);
78393- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
78394+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
78395 if (fd >= 0) {
78396 sys_ioctl(fd, FDEJECT, 0);
78397 sys_close(fd);
78398 }
78399 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
78400- fd = sys_open("/dev/console", O_RDWR, 0);
78401+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
78402 if (fd >= 0) {
78403 sys_ioctl(fd, TCGETS, (long)&termios);
78404 termios.c_lflag &= ~ICANON;
78405 sys_ioctl(fd, TCSETSF, (long)&termios);
78406- sys_read(fd, &c, 1);
78407+ sys_read(fd, (char __user *)&c, 1);
78408 termios.c_lflag |= ICANON;
78409 sys_ioctl(fd, TCSETSF, (long)&termios);
78410 sys_close(fd);
78411@@ -585,6 +585,6 @@ void __init prepare_namespace(void)
78412 mount_root();
78413 out:
78414 devtmpfs_mount("dev");
78415- sys_mount(".", "/", NULL, MS_MOVE, NULL);
78416- sys_chroot(".");
78417+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
78418+ sys_chroot((const char __force_user *)".");
78419 }
78420diff --git a/init/do_mounts.h b/init/do_mounts.h
78421index f5b978a..69dbfe8 100644
78422--- a/init/do_mounts.h
78423+++ b/init/do_mounts.h
78424@@ -15,15 +15,15 @@ extern int root_mountflags;
78425
78426 static inline int create_dev(char *name, dev_t dev)
78427 {
78428- sys_unlink(name);
78429- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
78430+ sys_unlink((char __force_user *)name);
78431+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
78432 }
78433
78434 #if BITS_PER_LONG == 32
78435 static inline u32 bstat(char *name)
78436 {
78437 struct stat64 stat;
78438- if (sys_stat64(name, &stat) != 0)
78439+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
78440 return 0;
78441 if (!S_ISBLK(stat.st_mode))
78442 return 0;
78443@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
78444 static inline u32 bstat(char *name)
78445 {
78446 struct stat stat;
78447- if (sys_newstat(name, &stat) != 0)
78448+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
78449 return 0;
78450 if (!S_ISBLK(stat.st_mode))
78451 return 0;
78452diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
78453index 3e0878e..8a9d7a0 100644
78454--- a/init/do_mounts_initrd.c
78455+++ b/init/do_mounts_initrd.c
78456@@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
78457 {
78458 sys_unshare(CLONE_FS | CLONE_FILES);
78459 /* stdin/stdout/stderr for /linuxrc */
78460- sys_open("/dev/console", O_RDWR, 0);
78461+ sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
78462 sys_dup(0);
78463 sys_dup(0);
78464 /* move initrd over / and chdir/chroot in initrd root */
78465- sys_chdir("/root");
78466- sys_mount(".", "/", NULL, MS_MOVE, NULL);
78467- sys_chroot(".");
78468+ sys_chdir((const char __force_user *)"/root");
78469+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
78470+ sys_chroot((const char __force_user *)".");
78471 sys_setsid();
78472 return 0;
78473 }
78474@@ -59,8 +59,8 @@ static void __init handle_initrd(void)
78475 create_dev("/dev/root.old", Root_RAM0);
78476 /* mount initrd on rootfs' /root */
78477 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
78478- sys_mkdir("/old", 0700);
78479- sys_chdir("/old");
78480+ sys_mkdir((const char __force_user *)"/old", 0700);
78481+ sys_chdir((const char __force_user *)"/old");
78482
78483 /* try loading default modules from initrd */
78484 load_default_modules();
78485@@ -80,31 +80,31 @@ static void __init handle_initrd(void)
78486 current->flags &= ~PF_FREEZER_SKIP;
78487
78488 /* move initrd to rootfs' /old */
78489- sys_mount("..", ".", NULL, MS_MOVE, NULL);
78490+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
78491 /* switch root and cwd back to / of rootfs */
78492- sys_chroot("..");
78493+ sys_chroot((const char __force_user *)"..");
78494
78495 if (new_decode_dev(real_root_dev) == Root_RAM0) {
78496- sys_chdir("/old");
78497+ sys_chdir((const char __force_user *)"/old");
78498 return;
78499 }
78500
78501- sys_chdir("/");
78502+ sys_chdir((const char __force_user *)"/");
78503 ROOT_DEV = new_decode_dev(real_root_dev);
78504 mount_root();
78505
78506 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
78507- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
78508+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
78509 if (!error)
78510 printk("okay\n");
78511 else {
78512- int fd = sys_open("/dev/root.old", O_RDWR, 0);
78513+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
78514 if (error == -ENOENT)
78515 printk("/initrd does not exist. Ignored.\n");
78516 else
78517 printk("failed\n");
78518 printk(KERN_NOTICE "Unmounting old root\n");
78519- sys_umount("/old", MNT_DETACH);
78520+ sys_umount((char __force_user *)"/old", MNT_DETACH);
78521 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
78522 if (fd < 0) {
78523 error = fd;
78524@@ -127,11 +127,11 @@ int __init initrd_load(void)
78525 * mounted in the normal path.
78526 */
78527 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
78528- sys_unlink("/initrd.image");
78529+ sys_unlink((const char __force_user *)"/initrd.image");
78530 handle_initrd();
78531 return 1;
78532 }
78533 }
78534- sys_unlink("/initrd.image");
78535+ sys_unlink((const char __force_user *)"/initrd.image");
78536 return 0;
78537 }
78538diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
78539index 8cb6db5..d729f50 100644
78540--- a/init/do_mounts_md.c
78541+++ b/init/do_mounts_md.c
78542@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
78543 partitioned ? "_d" : "", minor,
78544 md_setup_args[ent].device_names);
78545
78546- fd = sys_open(name, 0, 0);
78547+ fd = sys_open((char __force_user *)name, 0, 0);
78548 if (fd < 0) {
78549 printk(KERN_ERR "md: open failed - cannot start "
78550 "array %s\n", name);
78551@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
78552 * array without it
78553 */
78554 sys_close(fd);
78555- fd = sys_open(name, 0, 0);
78556+ fd = sys_open((char __force_user *)name, 0, 0);
78557 sys_ioctl(fd, BLKRRPART, 0);
78558 }
78559 sys_close(fd);
78560@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
78561
78562 wait_for_device_probe();
78563
78564- fd = sys_open("/dev/md0", 0, 0);
78565+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
78566 if (fd >= 0) {
78567 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
78568 sys_close(fd);
78569diff --git a/init/init_task.c b/init/init_task.c
78570index ba0a7f36..2bcf1d5 100644
78571--- a/init/init_task.c
78572+++ b/init/init_task.c
78573@@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
78574 * Initial thread structure. Alignment of this is handled by a special
78575 * linker map entry.
78576 */
78577+#ifdef CONFIG_X86
78578+union thread_union init_thread_union __init_task_data;
78579+#else
78580 union thread_union init_thread_union __init_task_data =
78581 { INIT_THREAD_INFO(init_task) };
78582+#endif
78583diff --git a/init/initramfs.c b/init/initramfs.c
78584index a67ef9d..2d17ed9 100644
78585--- a/init/initramfs.c
78586+++ b/init/initramfs.c
78587@@ -84,7 +84,7 @@ static void __init free_hash(void)
78588 }
78589 }
78590
78591-static long __init do_utime(char *filename, time_t mtime)
78592+static long __init do_utime(char __force_user *filename, time_t mtime)
78593 {
78594 struct timespec t[2];
78595
78596@@ -119,7 +119,7 @@ static void __init dir_utime(void)
78597 struct dir_entry *de, *tmp;
78598 list_for_each_entry_safe(de, tmp, &dir_list, list) {
78599 list_del(&de->list);
78600- do_utime(de->name, de->mtime);
78601+ do_utime((char __force_user *)de->name, de->mtime);
78602 kfree(de->name);
78603 kfree(de);
78604 }
78605@@ -281,7 +281,7 @@ static int __init maybe_link(void)
78606 if (nlink >= 2) {
78607 char *old = find_link(major, minor, ino, mode, collected);
78608 if (old)
78609- return (sys_link(old, collected) < 0) ? -1 : 1;
78610+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
78611 }
78612 return 0;
78613 }
78614@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
78615 {
78616 struct stat st;
78617
78618- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
78619+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
78620 if (S_ISDIR(st.st_mode))
78621- sys_rmdir(path);
78622+ sys_rmdir((char __force_user *)path);
78623 else
78624- sys_unlink(path);
78625+ sys_unlink((char __force_user *)path);
78626 }
78627 }
78628
78629@@ -315,7 +315,7 @@ static int __init do_name(void)
78630 int openflags = O_WRONLY|O_CREAT;
78631 if (ml != 1)
78632 openflags |= O_TRUNC;
78633- wfd = sys_open(collected, openflags, mode);
78634+ wfd = sys_open((char __force_user *)collected, openflags, mode);
78635
78636 if (wfd >= 0) {
78637 sys_fchown(wfd, uid, gid);
78638@@ -327,17 +327,17 @@ static int __init do_name(void)
78639 }
78640 }
78641 } else if (S_ISDIR(mode)) {
78642- sys_mkdir(collected, mode);
78643- sys_chown(collected, uid, gid);
78644- sys_chmod(collected, mode);
78645+ sys_mkdir((char __force_user *)collected, mode);
78646+ sys_chown((char __force_user *)collected, uid, gid);
78647+ sys_chmod((char __force_user *)collected, mode);
78648 dir_add(collected, mtime);
78649 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
78650 S_ISFIFO(mode) || S_ISSOCK(mode)) {
78651 if (maybe_link() == 0) {
78652- sys_mknod(collected, mode, rdev);
78653- sys_chown(collected, uid, gid);
78654- sys_chmod(collected, mode);
78655- do_utime(collected, mtime);
78656+ sys_mknod((char __force_user *)collected, mode, rdev);
78657+ sys_chown((char __force_user *)collected, uid, gid);
78658+ sys_chmod((char __force_user *)collected, mode);
78659+ do_utime((char __force_user *)collected, mtime);
78660 }
78661 }
78662 return 0;
78663@@ -346,15 +346,15 @@ static int __init do_name(void)
78664 static int __init do_copy(void)
78665 {
78666 if (count >= body_len) {
78667- sys_write(wfd, victim, body_len);
78668+ sys_write(wfd, (char __force_user *)victim, body_len);
78669 sys_close(wfd);
78670- do_utime(vcollected, mtime);
78671+ do_utime((char __force_user *)vcollected, mtime);
78672 kfree(vcollected);
78673 eat(body_len);
78674 state = SkipIt;
78675 return 0;
78676 } else {
78677- sys_write(wfd, victim, count);
78678+ sys_write(wfd, (char __force_user *)victim, count);
78679 body_len -= count;
78680 eat(count);
78681 return 1;
78682@@ -365,9 +365,9 @@ static int __init do_symlink(void)
78683 {
78684 collected[N_ALIGN(name_len) + body_len] = '\0';
78685 clean_path(collected, 0);
78686- sys_symlink(collected + N_ALIGN(name_len), collected);
78687- sys_lchown(collected, uid, gid);
78688- do_utime(collected, mtime);
78689+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
78690+ sys_lchown((char __force_user *)collected, uid, gid);
78691+ do_utime((char __force_user *)collected, mtime);
78692 state = SkipIt;
78693 next_state = Reset;
78694 return 0;
78695@@ -583,7 +583,7 @@ static int __init populate_rootfs(void)
78696 {
78697 char *err = unpack_to_rootfs(__initramfs_start, __initramfs_size);
78698 if (err)
78699- panic(err); /* Failed to decompress INTERNAL initramfs */
78700+ panic("%s", err); /* Failed to decompress INTERNAL initramfs */
78701 if (initrd_start) {
78702 #ifdef CONFIG_BLK_DEV_RAM
78703 int fd;
78704diff --git a/init/main.c b/init/main.c
78705index d03d2ec..9fc4737 100644
78706--- a/init/main.c
78707+++ b/init/main.c
78708@@ -101,6 +101,8 @@ static inline void mark_rodata_ro(void) { }
78709 extern void tc_init(void);
78710 #endif
78711
78712+extern void grsecurity_init(void);
78713+
78714 /*
78715 * Debug helper: via this flag we know that we are in 'early bootup code'
78716 * where only the boot processor is running with IRQ disabled. This means
78717@@ -154,6 +156,74 @@ static int __init set_reset_devices(char *str)
78718
78719 __setup("reset_devices", set_reset_devices);
78720
78721+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
78722+kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
78723+static int __init setup_grsec_proc_gid(char *str)
78724+{
78725+ grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
78726+ return 1;
78727+}
78728+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
78729+#endif
78730+
78731+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
78732+unsigned long pax_user_shadow_base __read_only;
78733+EXPORT_SYMBOL(pax_user_shadow_base);
78734+extern char pax_enter_kernel_user[];
78735+extern char pax_exit_kernel_user[];
78736+#endif
78737+
78738+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
78739+static int __init setup_pax_nouderef(char *str)
78740+{
78741+#ifdef CONFIG_X86_32
78742+ unsigned int cpu;
78743+ struct desc_struct *gdt;
78744+
78745+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
78746+ gdt = get_cpu_gdt_table(cpu);
78747+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
78748+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
78749+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
78750+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
78751+ }
78752+ loadsegment(ds, __KERNEL_DS);
78753+ loadsegment(es, __KERNEL_DS);
78754+ loadsegment(ss, __KERNEL_DS);
78755+#else
78756+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
78757+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
78758+ clone_pgd_mask = ~(pgdval_t)0UL;
78759+ pax_user_shadow_base = 0UL;
78760+ setup_clear_cpu_cap(X86_FEATURE_PCID);
78761+#endif
78762+
78763+ return 0;
78764+}
78765+early_param("pax_nouderef", setup_pax_nouderef);
78766+
78767+#ifdef CONFIG_X86_64
78768+static int __init setup_pax_weakuderef(char *str)
78769+{
78770+ if (clone_pgd_mask != ~(pgdval_t)0UL)
78771+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
78772+ return 1;
78773+}
78774+__setup("pax_weakuderef", setup_pax_weakuderef);
78775+#endif
78776+#endif
78777+
78778+#ifdef CONFIG_PAX_SOFTMODE
78779+int pax_softmode;
78780+
78781+static int __init setup_pax_softmode(char *str)
78782+{
78783+ get_option(&str, &pax_softmode);
78784+ return 1;
78785+}
78786+__setup("pax_softmode=", setup_pax_softmode);
78787+#endif
78788+
78789 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
78790 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
78791 static const char *panic_later, *panic_param;
78792@@ -679,25 +749,24 @@ int __init_or_module do_one_initcall(initcall_t fn)
78793 {
78794 int count = preempt_count();
78795 int ret;
78796- char msgbuf[64];
78797+ const char *msg1 = "", *msg2 = "";
78798
78799 if (initcall_debug)
78800 ret = do_one_initcall_debug(fn);
78801 else
78802 ret = fn();
78803
78804- msgbuf[0] = 0;
78805-
78806 if (preempt_count() != count) {
78807- sprintf(msgbuf, "preemption imbalance ");
78808+ msg1 = " preemption imbalance";
78809 preempt_count() = count;
78810 }
78811 if (irqs_disabled()) {
78812- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
78813+ msg2 = " disabled interrupts";
78814 local_irq_enable();
78815 }
78816- WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
78817+ WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
78818
78819+ add_latent_entropy();
78820 return ret;
78821 }
78822
78823@@ -803,8 +872,8 @@ static int run_init_process(const char *init_filename)
78824 {
78825 argv_init[0] = init_filename;
78826 return do_execve(init_filename,
78827- (const char __user *const __user *)argv_init,
78828- (const char __user *const __user *)envp_init);
78829+ (const char __user *const __force_user *)argv_init,
78830+ (const char __user *const __force_user *)envp_init);
78831 }
78832
78833 static noinline void __init kernel_init_freeable(void);
78834@@ -881,7 +950,7 @@ static noinline void __init kernel_init_freeable(void)
78835 do_basic_setup();
78836
78837 /* Open the /dev/console on the rootfs, this should never fail */
78838- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
78839+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
78840 pr_err("Warning: unable to open an initial console.\n");
78841
78842 (void) sys_dup(0);
78843@@ -894,11 +963,13 @@ static noinline void __init kernel_init_freeable(void)
78844 if (!ramdisk_execute_command)
78845 ramdisk_execute_command = "/init";
78846
78847- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
78848+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
78849 ramdisk_execute_command = NULL;
78850 prepare_namespace();
78851 }
78852
78853+ grsecurity_init();
78854+
78855 /*
78856 * Ok, we have completed the initial bootup, and
78857 * we're essentially up and running. Get rid of the
78858diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
78859index 130dfec..cc88451 100644
78860--- a/ipc/ipc_sysctl.c
78861+++ b/ipc/ipc_sysctl.c
78862@@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
78863 static int proc_ipc_dointvec(ctl_table *table, int write,
78864 void __user *buffer, size_t *lenp, loff_t *ppos)
78865 {
78866- struct ctl_table ipc_table;
78867+ ctl_table_no_const ipc_table;
78868
78869 memcpy(&ipc_table, table, sizeof(ipc_table));
78870 ipc_table.data = get_ipc(table);
78871@@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
78872 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
78873 void __user *buffer, size_t *lenp, loff_t *ppos)
78874 {
78875- struct ctl_table ipc_table;
78876+ ctl_table_no_const ipc_table;
78877
78878 memcpy(&ipc_table, table, sizeof(ipc_table));
78879 ipc_table.data = get_ipc(table);
78880@@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
78881 static int proc_ipc_callback_dointvec(ctl_table *table, int write,
78882 void __user *buffer, size_t *lenp, loff_t *ppos)
78883 {
78884- struct ctl_table ipc_table;
78885+ ctl_table_no_const ipc_table;
78886 size_t lenp_bef = *lenp;
78887 int rc;
78888
78889@@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec(ctl_table *table, int write,
78890 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
78891 void __user *buffer, size_t *lenp, loff_t *ppos)
78892 {
78893- struct ctl_table ipc_table;
78894+ ctl_table_no_const ipc_table;
78895 memcpy(&ipc_table, table, sizeof(ipc_table));
78896 ipc_table.data = get_ipc(table);
78897
78898@@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
78899 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
78900 void __user *buffer, size_t *lenp, loff_t *ppos)
78901 {
78902- struct ctl_table ipc_table;
78903+ ctl_table_no_const ipc_table;
78904 size_t lenp_bef = *lenp;
78905 int oldval;
78906 int rc;
78907diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
78908index 383d638..943fdbb 100644
78909--- a/ipc/mq_sysctl.c
78910+++ b/ipc/mq_sysctl.c
78911@@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
78912 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
78913 void __user *buffer, size_t *lenp, loff_t *ppos)
78914 {
78915- struct ctl_table mq_table;
78916+ ctl_table_no_const mq_table;
78917 memcpy(&mq_table, table, sizeof(mq_table));
78918 mq_table.data = get_mq(table);
78919
78920diff --git a/ipc/mqueue.c b/ipc/mqueue.c
78921index ae1996d..a35f2cc 100644
78922--- a/ipc/mqueue.c
78923+++ b/ipc/mqueue.c
78924@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
78925 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
78926 info->attr.mq_msgsize);
78927
78928+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
78929 spin_lock(&mq_lock);
78930 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
78931 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
78932diff --git a/ipc/msg.c b/ipc/msg.c
78933index b65fdf1..89ec2b1 100644
78934--- a/ipc/msg.c
78935+++ b/ipc/msg.c
78936@@ -291,18 +291,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
78937 return security_msg_queue_associate(msq, msgflg);
78938 }
78939
78940+static struct ipc_ops msg_ops = {
78941+ .getnew = newque,
78942+ .associate = msg_security,
78943+ .more_checks = NULL
78944+};
78945+
78946 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
78947 {
78948 struct ipc_namespace *ns;
78949- struct ipc_ops msg_ops;
78950 struct ipc_params msg_params;
78951
78952 ns = current->nsproxy->ipc_ns;
78953
78954- msg_ops.getnew = newque;
78955- msg_ops.associate = msg_security;
78956- msg_ops.more_checks = NULL;
78957-
78958 msg_params.key = key;
78959 msg_params.flg = msgflg;
78960
78961diff --git a/ipc/sem.c b/ipc/sem.c
78962index 4108889..511ada1 100644
78963--- a/ipc/sem.c
78964+++ b/ipc/sem.c
78965@@ -517,10 +517,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
78966 return 0;
78967 }
78968
78969+static struct ipc_ops sem_ops = {
78970+ .getnew = newary,
78971+ .associate = sem_security,
78972+ .more_checks = sem_more_checks
78973+};
78974+
78975 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
78976 {
78977 struct ipc_namespace *ns;
78978- struct ipc_ops sem_ops;
78979 struct ipc_params sem_params;
78980
78981 ns = current->nsproxy->ipc_ns;
78982@@ -528,10 +533,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
78983 if (nsems < 0 || nsems > ns->sc_semmsl)
78984 return -EINVAL;
78985
78986- sem_ops.getnew = newary;
78987- sem_ops.associate = sem_security;
78988- sem_ops.more_checks = sem_more_checks;
78989-
78990 sem_params.key = key;
78991 sem_params.flg = semflg;
78992 sem_params.u.nsems = nsems;
78993diff --git a/ipc/shm.c b/ipc/shm.c
78994index c6b4ad5..3ec3254 100644
78995--- a/ipc/shm.c
78996+++ b/ipc/shm.c
78997@@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
78998 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
78999 #endif
79000
79001+#ifdef CONFIG_GRKERNSEC
79002+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
79003+ const time_t shm_createtime, const kuid_t cuid,
79004+ const int shmid);
79005+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
79006+ const time_t shm_createtime);
79007+#endif
79008+
79009 void shm_init_ns(struct ipc_namespace *ns)
79010 {
79011 ns->shm_ctlmax = SHMMAX;
79012@@ -531,6 +539,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
79013 shp->shm_lprid = 0;
79014 shp->shm_atim = shp->shm_dtim = 0;
79015 shp->shm_ctim = get_seconds();
79016+#ifdef CONFIG_GRKERNSEC
79017+ {
79018+ struct timespec timeval;
79019+ do_posix_clock_monotonic_gettime(&timeval);
79020+
79021+ shp->shm_createtime = timeval.tv_sec;
79022+ }
79023+#endif
79024 shp->shm_segsz = size;
79025 shp->shm_nattch = 0;
79026 shp->shm_file = file;
79027@@ -585,18 +601,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
79028 return 0;
79029 }
79030
79031+static struct ipc_ops shm_ops = {
79032+ .getnew = newseg,
79033+ .associate = shm_security,
79034+ .more_checks = shm_more_checks
79035+};
79036+
79037 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
79038 {
79039 struct ipc_namespace *ns;
79040- struct ipc_ops shm_ops;
79041 struct ipc_params shm_params;
79042
79043 ns = current->nsproxy->ipc_ns;
79044
79045- shm_ops.getnew = newseg;
79046- shm_ops.associate = shm_security;
79047- shm_ops.more_checks = shm_more_checks;
79048-
79049 shm_params.key = key;
79050 shm_params.flg = shmflg;
79051 shm_params.u.size = size;
79052@@ -1028,6 +1045,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
79053 f_mode = FMODE_READ | FMODE_WRITE;
79054 }
79055 if (shmflg & SHM_EXEC) {
79056+
79057+#ifdef CONFIG_PAX_MPROTECT
79058+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
79059+ goto out;
79060+#endif
79061+
79062 prot |= PROT_EXEC;
79063 acc_mode |= S_IXUGO;
79064 }
79065@@ -1051,9 +1074,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
79066 if (err)
79067 goto out_unlock;
79068
79069+#ifdef CONFIG_GRKERNSEC
79070+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
79071+ shp->shm_perm.cuid, shmid) ||
79072+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
79073+ err = -EACCES;
79074+ goto out_unlock;
79075+ }
79076+#endif
79077+
79078 path = shp->shm_file->f_path;
79079 path_get(&path);
79080 shp->shm_nattch++;
79081+#ifdef CONFIG_GRKERNSEC
79082+ shp->shm_lapid = current->pid;
79083+#endif
79084 size = i_size_read(path.dentry->d_inode);
79085 shm_unlock(shp);
79086
79087diff --git a/kernel/acct.c b/kernel/acct.c
79088index 8d6e145..33e0b1e 100644
79089--- a/kernel/acct.c
79090+++ b/kernel/acct.c
79091@@ -556,7 +556,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
79092 */
79093 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
79094 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
79095- file->f_op->write(file, (char *)&ac,
79096+ file->f_op->write(file, (char __force_user *)&ac,
79097 sizeof(acct_t), &file->f_pos);
79098 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
79099 set_fs(fs);
79100diff --git a/kernel/audit.c b/kernel/audit.c
79101index 7b0e23a..861041e 100644
79102--- a/kernel/audit.c
79103+++ b/kernel/audit.c
79104@@ -118,7 +118,7 @@ u32 audit_sig_sid = 0;
79105 3) suppressed due to audit_rate_limit
79106 4) suppressed due to audit_backlog_limit
79107 */
79108-static atomic_t audit_lost = ATOMIC_INIT(0);
79109+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
79110
79111 /* The netlink socket. */
79112 static struct sock *audit_sock;
79113@@ -240,7 +240,7 @@ void audit_log_lost(const char *message)
79114 unsigned long now;
79115 int print;
79116
79117- atomic_inc(&audit_lost);
79118+ atomic_inc_unchecked(&audit_lost);
79119
79120 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
79121
79122@@ -259,7 +259,7 @@ void audit_log_lost(const char *message)
79123 printk(KERN_WARNING
79124 "audit: audit_lost=%d audit_rate_limit=%d "
79125 "audit_backlog_limit=%d\n",
79126- atomic_read(&audit_lost),
79127+ atomic_read_unchecked(&audit_lost),
79128 audit_rate_limit,
79129 audit_backlog_limit);
79130 audit_panic(message);
79131@@ -664,7 +664,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
79132 status_set.pid = audit_pid;
79133 status_set.rate_limit = audit_rate_limit;
79134 status_set.backlog_limit = audit_backlog_limit;
79135- status_set.lost = atomic_read(&audit_lost);
79136+ status_set.lost = atomic_read_unchecked(&audit_lost);
79137 status_set.backlog = skb_queue_len(&audit_skb_queue);
79138 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
79139 &status_set, sizeof(status_set));
79140diff --git a/kernel/auditsc.c b/kernel/auditsc.c
79141index 9845cb3..3ec9369 100644
79142--- a/kernel/auditsc.c
79143+++ b/kernel/auditsc.c
79144@@ -1962,7 +1962,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
79145 }
79146
79147 /* global counter which is incremented every time something logs in */
79148-static atomic_t session_id = ATOMIC_INIT(0);
79149+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
79150
79151 /**
79152 * audit_set_loginuid - set current task's audit_context loginuid
79153@@ -1986,7 +1986,7 @@ int audit_set_loginuid(kuid_t loginuid)
79154 return -EPERM;
79155 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
79156
79157- sessionid = atomic_inc_return(&session_id);
79158+ sessionid = atomic_inc_return_unchecked(&session_id);
79159 if (context && context->in_syscall) {
79160 struct audit_buffer *ab;
79161
79162diff --git a/kernel/capability.c b/kernel/capability.c
79163index f6c2ce5..982c0f9 100644
79164--- a/kernel/capability.c
79165+++ b/kernel/capability.c
79166@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
79167 * before modification is attempted and the application
79168 * fails.
79169 */
79170+ if (tocopy > ARRAY_SIZE(kdata))
79171+ return -EFAULT;
79172+
79173 if (copy_to_user(dataptr, kdata, tocopy
79174 * sizeof(struct __user_cap_data_struct))) {
79175 return -EFAULT;
79176@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
79177 int ret;
79178
79179 rcu_read_lock();
79180- ret = security_capable(__task_cred(t), ns, cap);
79181+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
79182+ gr_task_is_capable(t, __task_cred(t), cap);
79183 rcu_read_unlock();
79184
79185- return (ret == 0);
79186+ return ret;
79187 }
79188
79189 /**
79190@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
79191 int ret;
79192
79193 rcu_read_lock();
79194- ret = security_capable_noaudit(__task_cred(t), ns, cap);
79195+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
79196 rcu_read_unlock();
79197
79198- return (ret == 0);
79199+ return ret;
79200 }
79201
79202 /**
79203@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
79204 BUG();
79205 }
79206
79207- if (security_capable(current_cred(), ns, cap) == 0) {
79208+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
79209 current->flags |= PF_SUPERPRIV;
79210 return true;
79211 }
79212@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
79213 }
79214 EXPORT_SYMBOL(ns_capable);
79215
79216+bool ns_capable_nolog(struct user_namespace *ns, int cap)
79217+{
79218+ if (unlikely(!cap_valid(cap))) {
79219+ printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
79220+ BUG();
79221+ }
79222+
79223+ if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
79224+ current->flags |= PF_SUPERPRIV;
79225+ return true;
79226+ }
79227+ return false;
79228+}
79229+EXPORT_SYMBOL(ns_capable_nolog);
79230+
79231 /**
79232 * file_ns_capable - Determine if the file's opener had a capability in effect
79233 * @file: The file we want to check
79234@@ -432,6 +451,12 @@ bool capable(int cap)
79235 }
79236 EXPORT_SYMBOL(capable);
79237
79238+bool capable_nolog(int cap)
79239+{
79240+ return ns_capable_nolog(&init_user_ns, cap);
79241+}
79242+EXPORT_SYMBOL(capable_nolog);
79243+
79244 /**
79245 * nsown_capable - Check superior capability to one's own user_ns
79246 * @cap: The capability in question
79247@@ -464,3 +489,10 @@ bool inode_capable(const struct inode *inode, int cap)
79248
79249 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
79250 }
79251+
79252+bool inode_capable_nolog(const struct inode *inode, int cap)
79253+{
79254+ struct user_namespace *ns = current_user_ns();
79255+
79256+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
79257+}
79258diff --git a/kernel/cgroup.c b/kernel/cgroup.c
79259index e919633..f46b08f 100644
79260--- a/kernel/cgroup.c
79261+++ b/kernel/cgroup.c
79262@@ -5623,7 +5623,7 @@ static int cgroup_css_links_read(struct cgroup *cgrp,
79263 struct css_set *cset = link->cset;
79264 struct task_struct *task;
79265 int count = 0;
79266- seq_printf(seq, "css_set %p\n", cset);
79267+ seq_printf(seq, "css_set %pK\n", cset);
79268 list_for_each_entry(task, &cset->tasks, cg_list) {
79269 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
79270 seq_puts(seq, " ...\n");
79271diff --git a/kernel/compat.c b/kernel/compat.c
79272index 0a09e48..f44f3f0 100644
79273--- a/kernel/compat.c
79274+++ b/kernel/compat.c
79275@@ -13,6 +13,7 @@
79276
79277 #include <linux/linkage.h>
79278 #include <linux/compat.h>
79279+#include <linux/module.h>
79280 #include <linux/errno.h>
79281 #include <linux/time.h>
79282 #include <linux/signal.h>
79283@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
79284 mm_segment_t oldfs;
79285 long ret;
79286
79287- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
79288+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
79289 oldfs = get_fs();
79290 set_fs(KERNEL_DS);
79291 ret = hrtimer_nanosleep_restart(restart);
79292@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
79293 oldfs = get_fs();
79294 set_fs(KERNEL_DS);
79295 ret = hrtimer_nanosleep(&tu,
79296- rmtp ? (struct timespec __user *)&rmt : NULL,
79297+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
79298 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
79299 set_fs(oldfs);
79300
79301@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
79302 mm_segment_t old_fs = get_fs();
79303
79304 set_fs(KERNEL_DS);
79305- ret = sys_sigpending((old_sigset_t __user *) &s);
79306+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
79307 set_fs(old_fs);
79308 if (ret == 0)
79309 ret = put_user(s, set);
79310@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
79311 mm_segment_t old_fs = get_fs();
79312
79313 set_fs(KERNEL_DS);
79314- ret = sys_old_getrlimit(resource, &r);
79315+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
79316 set_fs(old_fs);
79317
79318 if (!ret) {
79319@@ -533,8 +534,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
79320 set_fs (KERNEL_DS);
79321 ret = sys_wait4(pid,
79322 (stat_addr ?
79323- (unsigned int __user *) &status : NULL),
79324- options, (struct rusage __user *) &r);
79325+ (unsigned int __force_user *) &status : NULL),
79326+ options, (struct rusage __force_user *) &r);
79327 set_fs (old_fs);
79328
79329 if (ret > 0) {
79330@@ -560,8 +561,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
79331 memset(&info, 0, sizeof(info));
79332
79333 set_fs(KERNEL_DS);
79334- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
79335- uru ? (struct rusage __user *)&ru : NULL);
79336+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
79337+ uru ? (struct rusage __force_user *)&ru : NULL);
79338 set_fs(old_fs);
79339
79340 if ((ret < 0) || (info.si_signo == 0))
79341@@ -695,8 +696,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
79342 oldfs = get_fs();
79343 set_fs(KERNEL_DS);
79344 err = sys_timer_settime(timer_id, flags,
79345- (struct itimerspec __user *) &newts,
79346- (struct itimerspec __user *) &oldts);
79347+ (struct itimerspec __force_user *) &newts,
79348+ (struct itimerspec __force_user *) &oldts);
79349 set_fs(oldfs);
79350 if (!err && old && put_compat_itimerspec(old, &oldts))
79351 return -EFAULT;
79352@@ -713,7 +714,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
79353 oldfs = get_fs();
79354 set_fs(KERNEL_DS);
79355 err = sys_timer_gettime(timer_id,
79356- (struct itimerspec __user *) &ts);
79357+ (struct itimerspec __force_user *) &ts);
79358 set_fs(oldfs);
79359 if (!err && put_compat_itimerspec(setting, &ts))
79360 return -EFAULT;
79361@@ -732,7 +733,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
79362 oldfs = get_fs();
79363 set_fs(KERNEL_DS);
79364 err = sys_clock_settime(which_clock,
79365- (struct timespec __user *) &ts);
79366+ (struct timespec __force_user *) &ts);
79367 set_fs(oldfs);
79368 return err;
79369 }
79370@@ -747,7 +748,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
79371 oldfs = get_fs();
79372 set_fs(KERNEL_DS);
79373 err = sys_clock_gettime(which_clock,
79374- (struct timespec __user *) &ts);
79375+ (struct timespec __force_user *) &ts);
79376 set_fs(oldfs);
79377 if (!err && put_compat_timespec(&ts, tp))
79378 return -EFAULT;
79379@@ -767,7 +768,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
79380
79381 oldfs = get_fs();
79382 set_fs(KERNEL_DS);
79383- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
79384+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
79385 set_fs(oldfs);
79386
79387 err = compat_put_timex(utp, &txc);
79388@@ -787,7 +788,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
79389 oldfs = get_fs();
79390 set_fs(KERNEL_DS);
79391 err = sys_clock_getres(which_clock,
79392- (struct timespec __user *) &ts);
79393+ (struct timespec __force_user *) &ts);
79394 set_fs(oldfs);
79395 if (!err && tp && put_compat_timespec(&ts, tp))
79396 return -EFAULT;
79397@@ -799,9 +800,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
79398 long err;
79399 mm_segment_t oldfs;
79400 struct timespec tu;
79401- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
79402+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
79403
79404- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
79405+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
79406 oldfs = get_fs();
79407 set_fs(KERNEL_DS);
79408 err = clock_nanosleep_restart(restart);
79409@@ -833,8 +834,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
79410 oldfs = get_fs();
79411 set_fs(KERNEL_DS);
79412 err = sys_clock_nanosleep(which_clock, flags,
79413- (struct timespec __user *) &in,
79414- (struct timespec __user *) &out);
79415+ (struct timespec __force_user *) &in,
79416+ (struct timespec __force_user *) &out);
79417 set_fs(oldfs);
79418
79419 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
79420diff --git a/kernel/configs.c b/kernel/configs.c
79421index c18b1f1..b9a0132 100644
79422--- a/kernel/configs.c
79423+++ b/kernel/configs.c
79424@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
79425 struct proc_dir_entry *entry;
79426
79427 /* create the current config file */
79428+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
79429+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
79430+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
79431+ &ikconfig_file_ops);
79432+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
79433+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
79434+ &ikconfig_file_ops);
79435+#endif
79436+#else
79437 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
79438 &ikconfig_file_ops);
79439+#endif
79440+
79441 if (!entry)
79442 return -ENOMEM;
79443
79444diff --git a/kernel/cred.c b/kernel/cred.c
79445index e0573a4..3874e41 100644
79446--- a/kernel/cred.c
79447+++ b/kernel/cred.c
79448@@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
79449 validate_creds(cred);
79450 alter_cred_subscribers(cred, -1);
79451 put_cred(cred);
79452+
79453+#ifdef CONFIG_GRKERNSEC_SETXID
79454+ cred = (struct cred *) tsk->delayed_cred;
79455+ if (cred != NULL) {
79456+ tsk->delayed_cred = NULL;
79457+ validate_creds(cred);
79458+ alter_cred_subscribers(cred, -1);
79459+ put_cred(cred);
79460+ }
79461+#endif
79462 }
79463
79464 /**
79465@@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
79466 * Always returns 0 thus allowing this function to be tail-called at the end
79467 * of, say, sys_setgid().
79468 */
79469-int commit_creds(struct cred *new)
79470+static int __commit_creds(struct cred *new)
79471 {
79472 struct task_struct *task = current;
79473 const struct cred *old = task->real_cred;
79474@@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
79475
79476 get_cred(new); /* we will require a ref for the subj creds too */
79477
79478+ gr_set_role_label(task, new->uid, new->gid);
79479+
79480 /* dumpability changes */
79481 if (!uid_eq(old->euid, new->euid) ||
79482 !gid_eq(old->egid, new->egid) ||
79483@@ -479,6 +491,102 @@ int commit_creds(struct cred *new)
79484 put_cred(old);
79485 return 0;
79486 }
79487+#ifdef CONFIG_GRKERNSEC_SETXID
79488+extern int set_user(struct cred *new);
79489+
79490+void gr_delayed_cred_worker(void)
79491+{
79492+ const struct cred *new = current->delayed_cred;
79493+ struct cred *ncred;
79494+
79495+ current->delayed_cred = NULL;
79496+
79497+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
79498+ // from doing get_cred on it when queueing this
79499+ put_cred(new);
79500+ return;
79501+ } else if (new == NULL)
79502+ return;
79503+
79504+ ncred = prepare_creds();
79505+ if (!ncred)
79506+ goto die;
79507+ // uids
79508+ ncred->uid = new->uid;
79509+ ncred->euid = new->euid;
79510+ ncred->suid = new->suid;
79511+ ncred->fsuid = new->fsuid;
79512+ // gids
79513+ ncred->gid = new->gid;
79514+ ncred->egid = new->egid;
79515+ ncred->sgid = new->sgid;
79516+ ncred->fsgid = new->fsgid;
79517+ // groups
79518+ if (set_groups(ncred, new->group_info) < 0) {
79519+ abort_creds(ncred);
79520+ goto die;
79521+ }
79522+ // caps
79523+ ncred->securebits = new->securebits;
79524+ ncred->cap_inheritable = new->cap_inheritable;
79525+ ncred->cap_permitted = new->cap_permitted;
79526+ ncred->cap_effective = new->cap_effective;
79527+ ncred->cap_bset = new->cap_bset;
79528+
79529+ if (set_user(ncred)) {
79530+ abort_creds(ncred);
79531+ goto die;
79532+ }
79533+
79534+ // from doing get_cred on it when queueing this
79535+ put_cred(new);
79536+
79537+ __commit_creds(ncred);
79538+ return;
79539+die:
79540+ // from doing get_cred on it when queueing this
79541+ put_cred(new);
79542+ do_group_exit(SIGKILL);
79543+}
79544+#endif
79545+
79546+int commit_creds(struct cred *new)
79547+{
79548+#ifdef CONFIG_GRKERNSEC_SETXID
79549+ int ret;
79550+ int schedule_it = 0;
79551+ struct task_struct *t;
79552+
79553+ /* we won't get called with tasklist_lock held for writing
79554+ and interrupts disabled as the cred struct in that case is
79555+ init_cred
79556+ */
79557+ if (grsec_enable_setxid && !current_is_single_threaded() &&
79558+ uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
79559+ !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
79560+ schedule_it = 1;
79561+ }
79562+ ret = __commit_creds(new);
79563+ if (schedule_it) {
79564+ rcu_read_lock();
79565+ read_lock(&tasklist_lock);
79566+ for (t = next_thread(current); t != current;
79567+ t = next_thread(t)) {
79568+ if (t->delayed_cred == NULL) {
79569+ t->delayed_cred = get_cred(new);
79570+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
79571+ set_tsk_need_resched(t);
79572+ }
79573+ }
79574+ read_unlock(&tasklist_lock);
79575+ rcu_read_unlock();
79576+ }
79577+ return ret;
79578+#else
79579+ return __commit_creds(new);
79580+#endif
79581+}
79582+
79583 EXPORT_SYMBOL(commit_creds);
79584
79585 /**
79586diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
79587index 0506d44..2c20034 100644
79588--- a/kernel/debug/debug_core.c
79589+++ b/kernel/debug/debug_core.c
79590@@ -123,7 +123,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
79591 */
79592 static atomic_t masters_in_kgdb;
79593 static atomic_t slaves_in_kgdb;
79594-static atomic_t kgdb_break_tasklet_var;
79595+static atomic_unchecked_t kgdb_break_tasklet_var;
79596 atomic_t kgdb_setting_breakpoint;
79597
79598 struct task_struct *kgdb_usethread;
79599@@ -133,7 +133,7 @@ int kgdb_single_step;
79600 static pid_t kgdb_sstep_pid;
79601
79602 /* to keep track of the CPU which is doing the single stepping*/
79603-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
79604+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
79605
79606 /*
79607 * If you are debugging a problem where roundup (the collection of
79608@@ -541,7 +541,7 @@ return_normal:
79609 * kernel will only try for the value of sstep_tries before
79610 * giving up and continuing on.
79611 */
79612- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
79613+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
79614 (kgdb_info[cpu].task &&
79615 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
79616 atomic_set(&kgdb_active, -1);
79617@@ -635,8 +635,8 @@ cpu_master_loop:
79618 }
79619
79620 kgdb_restore:
79621- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
79622- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
79623+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
79624+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
79625 if (kgdb_info[sstep_cpu].task)
79626 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
79627 else
79628@@ -888,18 +888,18 @@ static void kgdb_unregister_callbacks(void)
79629 static void kgdb_tasklet_bpt(unsigned long ing)
79630 {
79631 kgdb_breakpoint();
79632- atomic_set(&kgdb_break_tasklet_var, 0);
79633+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
79634 }
79635
79636 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
79637
79638 void kgdb_schedule_breakpoint(void)
79639 {
79640- if (atomic_read(&kgdb_break_tasklet_var) ||
79641+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
79642 atomic_read(&kgdb_active) != -1 ||
79643 atomic_read(&kgdb_setting_breakpoint))
79644 return;
79645- atomic_inc(&kgdb_break_tasklet_var);
79646+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
79647 tasklet_schedule(&kgdb_tasklet_breakpoint);
79648 }
79649 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
79650diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
79651index 00eb8f7..d7e3244 100644
79652--- a/kernel/debug/kdb/kdb_main.c
79653+++ b/kernel/debug/kdb/kdb_main.c
79654@@ -1974,7 +1974,7 @@ static int kdb_lsmod(int argc, const char **argv)
79655 continue;
79656
79657 kdb_printf("%-20s%8u 0x%p ", mod->name,
79658- mod->core_size, (void *)mod);
79659+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
79660 #ifdef CONFIG_MODULE_UNLOAD
79661 kdb_printf("%4ld ", module_refcount(mod));
79662 #endif
79663@@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
79664 kdb_printf(" (Loading)");
79665 else
79666 kdb_printf(" (Live)");
79667- kdb_printf(" 0x%p", mod->module_core);
79668+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
79669
79670 #ifdef CONFIG_MODULE_UNLOAD
79671 {
79672diff --git a/kernel/events/core.c b/kernel/events/core.c
79673index f86599e..b18b180 100644
79674--- a/kernel/events/core.c
79675+++ b/kernel/events/core.c
79676@@ -156,8 +156,15 @@ static struct srcu_struct pmus_srcu;
79677 * 0 - disallow raw tracepoint access for unpriv
79678 * 1 - disallow cpu events for unpriv
79679 * 2 - disallow kernel profiling for unpriv
79680+ * 3 - disallow all unpriv perf event use
79681 */
79682-int sysctl_perf_event_paranoid __read_mostly = 1;
79683+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
79684+int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
79685+#elif defined(CONFIG_GRKERNSEC_HIDESYM)
79686+int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
79687+#else
79688+int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
79689+#endif
79690
79691 /* Minimum for 512 kiB + 1 user control page */
79692 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
79693@@ -270,7 +277,7 @@ void perf_sample_event_took(u64 sample_len_ns)
79694 update_perf_cpu_limits();
79695 }
79696
79697-static atomic64_t perf_event_id;
79698+static atomic64_unchecked_t perf_event_id;
79699
79700 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
79701 enum event_type_t event_type);
79702@@ -2936,7 +2943,7 @@ static void __perf_event_read(void *info)
79703
79704 static inline u64 perf_event_count(struct perf_event *event)
79705 {
79706- return local64_read(&event->count) + atomic64_read(&event->child_count);
79707+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
79708 }
79709
79710 static u64 perf_event_read(struct perf_event *event)
79711@@ -3282,9 +3289,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
79712 mutex_lock(&event->child_mutex);
79713 total += perf_event_read(event);
79714 *enabled += event->total_time_enabled +
79715- atomic64_read(&event->child_total_time_enabled);
79716+ atomic64_read_unchecked(&event->child_total_time_enabled);
79717 *running += event->total_time_running +
79718- atomic64_read(&event->child_total_time_running);
79719+ atomic64_read_unchecked(&event->child_total_time_running);
79720
79721 list_for_each_entry(child, &event->child_list, child_list) {
79722 total += perf_event_read(child);
79723@@ -3670,10 +3677,10 @@ void perf_event_update_userpage(struct perf_event *event)
79724 userpg->offset -= local64_read(&event->hw.prev_count);
79725
79726 userpg->time_enabled = enabled +
79727- atomic64_read(&event->child_total_time_enabled);
79728+ atomic64_read_unchecked(&event->child_total_time_enabled);
79729
79730 userpg->time_running = running +
79731- atomic64_read(&event->child_total_time_running);
79732+ atomic64_read_unchecked(&event->child_total_time_running);
79733
79734 arch_perf_update_userpage(userpg, now);
79735
79736@@ -4223,7 +4230,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
79737
79738 /* Data. */
79739 sp = perf_user_stack_pointer(regs);
79740- rem = __output_copy_user(handle, (void *) sp, dump_size);
79741+ rem = __output_copy_user(handle, (void __user *) sp, dump_size);
79742 dyn_size = dump_size - rem;
79743
79744 perf_output_skip(handle, rem);
79745@@ -4311,11 +4318,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
79746 values[n++] = perf_event_count(event);
79747 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
79748 values[n++] = enabled +
79749- atomic64_read(&event->child_total_time_enabled);
79750+ atomic64_read_unchecked(&event->child_total_time_enabled);
79751 }
79752 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
79753 values[n++] = running +
79754- atomic64_read(&event->child_total_time_running);
79755+ atomic64_read_unchecked(&event->child_total_time_running);
79756 }
79757 if (read_format & PERF_FORMAT_ID)
79758 values[n++] = primary_event_id(event);
79759@@ -5024,12 +5031,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
79760 * need to add enough zero bytes after the string to handle
79761 * the 64bit alignment we do later.
79762 */
79763- buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
79764+ buf = kzalloc(PATH_MAX, GFP_KERNEL);
79765 if (!buf) {
79766 name = strncpy(tmp, "//enomem", sizeof(tmp));
79767 goto got_name;
79768 }
79769- name = d_path(&file->f_path, buf, PATH_MAX);
79770+ name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
79771 if (IS_ERR(name)) {
79772 name = strncpy(tmp, "//toolong", sizeof(tmp));
79773 goto got_name;
79774@@ -6498,7 +6505,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
79775 event->parent = parent_event;
79776
79777 event->ns = get_pid_ns(task_active_pid_ns(current));
79778- event->id = atomic64_inc_return(&perf_event_id);
79779+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
79780
79781 event->state = PERF_EVENT_STATE_INACTIVE;
79782
79783@@ -6807,6 +6814,11 @@ SYSCALL_DEFINE5(perf_event_open,
79784 if (flags & ~PERF_FLAG_ALL)
79785 return -EINVAL;
79786
79787+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
79788+ if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
79789+ return -EACCES;
79790+#endif
79791+
79792 err = perf_copy_attr(attr_uptr, &attr);
79793 if (err)
79794 return err;
79795@@ -7139,10 +7151,10 @@ static void sync_child_event(struct perf_event *child_event,
79796 /*
79797 * Add back the child's count to the parent's count:
79798 */
79799- atomic64_add(child_val, &parent_event->child_count);
79800- atomic64_add(child_event->total_time_enabled,
79801+ atomic64_add_unchecked(child_val, &parent_event->child_count);
79802+ atomic64_add_unchecked(child_event->total_time_enabled,
79803 &parent_event->child_total_time_enabled);
79804- atomic64_add(child_event->total_time_running,
79805+ atomic64_add_unchecked(child_event->total_time_running,
79806 &parent_event->child_total_time_running);
79807
79808 /*
79809diff --git a/kernel/events/internal.h b/kernel/events/internal.h
79810index ca65997..60df03d 100644
79811--- a/kernel/events/internal.h
79812+++ b/kernel/events/internal.h
79813@@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
79814 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
79815 }
79816
79817-#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
79818-static inline unsigned int \
79819+#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
79820+static inline unsigned long \
79821 func_name(struct perf_output_handle *handle, \
79822- const void *buf, unsigned int len) \
79823+ const void user *buf, unsigned long len) \
79824 { \
79825 unsigned long size, written; \
79826 \
79827@@ -116,17 +116,17 @@ static inline int memcpy_common(void *dst, const void *src, size_t n)
79828 return n;
79829 }
79830
79831-DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
79832+DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
79833
79834 #define MEMCPY_SKIP(dst, src, n) (n)
79835
79836-DEFINE_OUTPUT_COPY(__output_skip, MEMCPY_SKIP)
79837+DEFINE_OUTPUT_COPY(__output_skip, MEMCPY_SKIP, )
79838
79839 #ifndef arch_perf_out_copy_user
79840 #define arch_perf_out_copy_user __copy_from_user_inatomic
79841 #endif
79842
79843-DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
79844+DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
79845
79846 /* Callchain handling */
79847 extern struct perf_callchain_entry *
79848diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
79849index ad8e1bd..fed7ba9 100644
79850--- a/kernel/events/uprobes.c
79851+++ b/kernel/events/uprobes.c
79852@@ -1556,7 +1556,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
79853 {
79854 struct page *page;
79855 uprobe_opcode_t opcode;
79856- int result;
79857+ long result;
79858
79859 pagefault_disable();
79860 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
79861diff --git a/kernel/exit.c b/kernel/exit.c
79862index a949819..a5f127d 100644
79863--- a/kernel/exit.c
79864+++ b/kernel/exit.c
79865@@ -172,6 +172,10 @@ void release_task(struct task_struct * p)
79866 struct task_struct *leader;
79867 int zap_leader;
79868 repeat:
79869+#ifdef CONFIG_NET
79870+ gr_del_task_from_ip_table(p);
79871+#endif
79872+
79873 /* don't need to get the RCU readlock here - the process is dead and
79874 * can't be modifying its own credentials. But shut RCU-lockdep up */
79875 rcu_read_lock();
79876@@ -329,7 +333,7 @@ int allow_signal(int sig)
79877 * know it'll be handled, so that they don't get converted to
79878 * SIGKILL or just silently dropped.
79879 */
79880- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
79881+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
79882 recalc_sigpending();
79883 spin_unlock_irq(&current->sighand->siglock);
79884 return 0;
79885@@ -698,6 +702,8 @@ void do_exit(long code)
79886 struct task_struct *tsk = current;
79887 int group_dead;
79888
79889+ set_fs(USER_DS);
79890+
79891 profile_task_exit(tsk);
79892
79893 WARN_ON(blk_needs_flush_plug(tsk));
79894@@ -714,7 +720,6 @@ void do_exit(long code)
79895 * mm_release()->clear_child_tid() from writing to a user-controlled
79896 * kernel address.
79897 */
79898- set_fs(USER_DS);
79899
79900 ptrace_event(PTRACE_EVENT_EXIT, code);
79901
79902@@ -773,6 +778,9 @@ void do_exit(long code)
79903 tsk->exit_code = code;
79904 taskstats_exit(tsk, group_dead);
79905
79906+ gr_acl_handle_psacct(tsk, code);
79907+ gr_acl_handle_exit();
79908+
79909 exit_mm(tsk);
79910
79911 if (group_dead)
79912@@ -894,7 +902,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
79913 * Take down every thread in the group. This is called by fatal signals
79914 * as well as by sys_exit_group (below).
79915 */
79916-void
79917+__noreturn void
79918 do_group_exit(int exit_code)
79919 {
79920 struct signal_struct *sig = current->signal;
79921diff --git a/kernel/fork.c b/kernel/fork.c
79922index 200a7a2..43e52da 100644
79923--- a/kernel/fork.c
79924+++ b/kernel/fork.c
79925@@ -319,7 +319,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
79926 *stackend = STACK_END_MAGIC; /* for overflow detection */
79927
79928 #ifdef CONFIG_CC_STACKPROTECTOR
79929- tsk->stack_canary = get_random_int();
79930+ tsk->stack_canary = pax_get_random_long();
79931 #endif
79932
79933 /*
79934@@ -345,13 +345,81 @@ free_tsk:
79935 }
79936
79937 #ifdef CONFIG_MMU
79938-static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
79939+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
79940 {
79941- struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
79942- struct rb_node **rb_link, *rb_parent;
79943- int retval;
79944+ struct vm_area_struct *tmp;
79945 unsigned long charge;
79946 struct mempolicy *pol;
79947+ struct file *file;
79948+
79949+ charge = 0;
79950+ if (mpnt->vm_flags & VM_ACCOUNT) {
79951+ unsigned long len = vma_pages(mpnt);
79952+
79953+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
79954+ goto fail_nomem;
79955+ charge = len;
79956+ }
79957+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
79958+ if (!tmp)
79959+ goto fail_nomem;
79960+ *tmp = *mpnt;
79961+ tmp->vm_mm = mm;
79962+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
79963+ pol = mpol_dup(vma_policy(mpnt));
79964+ if (IS_ERR(pol))
79965+ goto fail_nomem_policy;
79966+ vma_set_policy(tmp, pol);
79967+ if (anon_vma_fork(tmp, mpnt))
79968+ goto fail_nomem_anon_vma_fork;
79969+ tmp->vm_flags &= ~VM_LOCKED;
79970+ tmp->vm_next = tmp->vm_prev = NULL;
79971+ tmp->vm_mirror = NULL;
79972+ file = tmp->vm_file;
79973+ if (file) {
79974+ struct inode *inode = file_inode(file);
79975+ struct address_space *mapping = file->f_mapping;
79976+
79977+ get_file(file);
79978+ if (tmp->vm_flags & VM_DENYWRITE)
79979+ atomic_dec(&inode->i_writecount);
79980+ mutex_lock(&mapping->i_mmap_mutex);
79981+ if (tmp->vm_flags & VM_SHARED)
79982+ mapping->i_mmap_writable++;
79983+ flush_dcache_mmap_lock(mapping);
79984+ /* insert tmp into the share list, just after mpnt */
79985+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
79986+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
79987+ else
79988+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
79989+ flush_dcache_mmap_unlock(mapping);
79990+ mutex_unlock(&mapping->i_mmap_mutex);
79991+ }
79992+
79993+ /*
79994+ * Clear hugetlb-related page reserves for children. This only
79995+ * affects MAP_PRIVATE mappings. Faults generated by the child
79996+ * are not guaranteed to succeed, even if read-only
79997+ */
79998+ if (is_vm_hugetlb_page(tmp))
79999+ reset_vma_resv_huge_pages(tmp);
80000+
80001+ return tmp;
80002+
80003+fail_nomem_anon_vma_fork:
80004+ mpol_put(pol);
80005+fail_nomem_policy:
80006+ kmem_cache_free(vm_area_cachep, tmp);
80007+fail_nomem:
80008+ vm_unacct_memory(charge);
80009+ return NULL;
80010+}
80011+
80012+static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
80013+{
80014+ struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
80015+ struct rb_node **rb_link, *rb_parent;
80016+ int retval;
80017
80018 uprobe_start_dup_mmap();
80019 down_write(&oldmm->mmap_sem);
80020@@ -380,57 +448,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
80021
80022 prev = NULL;
80023 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
80024- struct file *file;
80025-
80026 if (mpnt->vm_flags & VM_DONTCOPY) {
80027 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
80028 -vma_pages(mpnt));
80029 continue;
80030 }
80031- charge = 0;
80032- if (mpnt->vm_flags & VM_ACCOUNT) {
80033- unsigned long len = vma_pages(mpnt);
80034-
80035- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
80036- goto fail_nomem;
80037- charge = len;
80038- }
80039- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
80040- if (!tmp)
80041- goto fail_nomem;
80042- *tmp = *mpnt;
80043- INIT_LIST_HEAD(&tmp->anon_vma_chain);
80044- pol = mpol_dup(vma_policy(mpnt));
80045- retval = PTR_ERR(pol);
80046- if (IS_ERR(pol))
80047- goto fail_nomem_policy;
80048- vma_set_policy(tmp, pol);
80049- tmp->vm_mm = mm;
80050- if (anon_vma_fork(tmp, mpnt))
80051- goto fail_nomem_anon_vma_fork;
80052- tmp->vm_flags &= ~VM_LOCKED;
80053- tmp->vm_next = tmp->vm_prev = NULL;
80054- file = tmp->vm_file;
80055- if (file) {
80056- struct inode *inode = file_inode(file);
80057- struct address_space *mapping = file->f_mapping;
80058-
80059- get_file(file);
80060- if (tmp->vm_flags & VM_DENYWRITE)
80061- atomic_dec(&inode->i_writecount);
80062- mutex_lock(&mapping->i_mmap_mutex);
80063- if (tmp->vm_flags & VM_SHARED)
80064- mapping->i_mmap_writable++;
80065- flush_dcache_mmap_lock(mapping);
80066- /* insert tmp into the share list, just after mpnt */
80067- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
80068- vma_nonlinear_insert(tmp,
80069- &mapping->i_mmap_nonlinear);
80070- else
80071- vma_interval_tree_insert_after(tmp, mpnt,
80072- &mapping->i_mmap);
80073- flush_dcache_mmap_unlock(mapping);
80074- mutex_unlock(&mapping->i_mmap_mutex);
80075+ tmp = dup_vma(mm, oldmm, mpnt);
80076+ if (!tmp) {
80077+ retval = -ENOMEM;
80078+ goto out;
80079 }
80080
80081 /*
80082@@ -462,6 +488,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
80083 if (retval)
80084 goto out;
80085 }
80086+
80087+#ifdef CONFIG_PAX_SEGMEXEC
80088+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
80089+ struct vm_area_struct *mpnt_m;
80090+
80091+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
80092+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
80093+
80094+ if (!mpnt->vm_mirror)
80095+ continue;
80096+
80097+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
80098+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
80099+ mpnt->vm_mirror = mpnt_m;
80100+ } else {
80101+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
80102+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
80103+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
80104+ mpnt->vm_mirror->vm_mirror = mpnt;
80105+ }
80106+ }
80107+ BUG_ON(mpnt_m);
80108+ }
80109+#endif
80110+
80111 /* a new mm has just been created */
80112 arch_dup_mmap(oldmm, mm);
80113 retval = 0;
80114@@ -471,14 +522,6 @@ out:
80115 up_write(&oldmm->mmap_sem);
80116 uprobe_end_dup_mmap();
80117 return retval;
80118-fail_nomem_anon_vma_fork:
80119- mpol_put(pol);
80120-fail_nomem_policy:
80121- kmem_cache_free(vm_area_cachep, tmp);
80122-fail_nomem:
80123- retval = -ENOMEM;
80124- vm_unacct_memory(charge);
80125- goto out;
80126 }
80127
80128 static inline int mm_alloc_pgd(struct mm_struct *mm)
80129@@ -691,8 +734,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
80130 return ERR_PTR(err);
80131
80132 mm = get_task_mm(task);
80133- if (mm && mm != current->mm &&
80134- !ptrace_may_access(task, mode)) {
80135+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
80136+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
80137 mmput(mm);
80138 mm = ERR_PTR(-EACCES);
80139 }
80140@@ -914,13 +957,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
80141 spin_unlock(&fs->lock);
80142 return -EAGAIN;
80143 }
80144- fs->users++;
80145+ atomic_inc(&fs->users);
80146 spin_unlock(&fs->lock);
80147 return 0;
80148 }
80149 tsk->fs = copy_fs_struct(fs);
80150 if (!tsk->fs)
80151 return -ENOMEM;
80152+ /* Carry through gr_chroot_dentry and is_chrooted instead
80153+ of recomputing it here. Already copied when the task struct
80154+ is duplicated. This allows pivot_root to not be treated as
80155+ a chroot
80156+ */
80157+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
80158+
80159 return 0;
80160 }
80161
80162@@ -1131,7 +1181,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
80163 * parts of the process environment (as per the clone
80164 * flags). The actual kick-off is left to the caller.
80165 */
80166-static struct task_struct *copy_process(unsigned long clone_flags,
80167+static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
80168 unsigned long stack_start,
80169 unsigned long stack_size,
80170 int __user *child_tidptr,
80171@@ -1201,6 +1251,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
80172 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
80173 #endif
80174 retval = -EAGAIN;
80175+
80176+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
80177+
80178 if (atomic_read(&p->real_cred->user->processes) >=
80179 task_rlimit(p, RLIMIT_NPROC)) {
80180 if (p->real_cred->user != INIT_USER &&
80181@@ -1450,6 +1503,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
80182 goto bad_fork_free_pid;
80183 }
80184
80185+ /* synchronizes with gr_set_acls()
80186+ we need to call this past the point of no return for fork()
80187+ */
80188+ gr_copy_label(p);
80189+
80190 if (likely(p->pid)) {
80191 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
80192
80193@@ -1535,6 +1593,8 @@ bad_fork_cleanup_count:
80194 bad_fork_free:
80195 free_task(p);
80196 fork_out:
80197+ gr_log_forkfail(retval);
80198+
80199 return ERR_PTR(retval);
80200 }
80201
80202@@ -1605,6 +1665,7 @@ long do_fork(unsigned long clone_flags,
80203
80204 p = copy_process(clone_flags, stack_start, stack_size,
80205 child_tidptr, NULL, trace);
80206+ add_latent_entropy();
80207 /*
80208 * Do this prior waking up the new thread - the thread pointer
80209 * might get invalid after that point, if the thread exits quickly.
80210@@ -1619,6 +1680,8 @@ long do_fork(unsigned long clone_flags,
80211 if (clone_flags & CLONE_PARENT_SETTID)
80212 put_user(nr, parent_tidptr);
80213
80214+ gr_handle_brute_check();
80215+
80216 if (clone_flags & CLONE_VFORK) {
80217 p->vfork_done = &vfork;
80218 init_completion(&vfork);
80219@@ -1735,7 +1798,7 @@ void __init proc_caches_init(void)
80220 mm_cachep = kmem_cache_create("mm_struct",
80221 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
80222 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
80223- vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
80224+ vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
80225 mmap_init();
80226 nsproxy_cache_init();
80227 }
80228@@ -1775,7 +1838,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
80229 return 0;
80230
80231 /* don't need lock here; in the worst case we'll do useless copy */
80232- if (fs->users == 1)
80233+ if (atomic_read(&fs->users) == 1)
80234 return 0;
80235
80236 *new_fsp = copy_fs_struct(fs);
80237@@ -1887,7 +1950,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
80238 fs = current->fs;
80239 spin_lock(&fs->lock);
80240 current->fs = new_fs;
80241- if (--fs->users)
80242+ gr_set_chroot_entries(current, &current->fs->root);
80243+ if (atomic_dec_return(&fs->users))
80244 new_fs = NULL;
80245 else
80246 new_fs = fs;
80247diff --git a/kernel/futex.c b/kernel/futex.c
80248index c3a1a55..e32b4a98 100644
80249--- a/kernel/futex.c
80250+++ b/kernel/futex.c
80251@@ -54,6 +54,7 @@
80252 #include <linux/mount.h>
80253 #include <linux/pagemap.h>
80254 #include <linux/syscalls.h>
80255+#include <linux/ptrace.h>
80256 #include <linux/signal.h>
80257 #include <linux/export.h>
80258 #include <linux/magic.h>
80259@@ -243,6 +244,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
80260 struct page *page, *page_head;
80261 int err, ro = 0;
80262
80263+#ifdef CONFIG_PAX_SEGMEXEC
80264+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
80265+ return -EFAULT;
80266+#endif
80267+
80268 /*
80269 * The futex address must be "naturally" aligned.
80270 */
80271@@ -441,7 +447,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
80272
80273 static int get_futex_value_locked(u32 *dest, u32 __user *from)
80274 {
80275- int ret;
80276+ unsigned long ret;
80277
80278 pagefault_disable();
80279 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
80280@@ -2734,6 +2740,7 @@ static int __init futex_init(void)
80281 {
80282 u32 curval;
80283 int i;
80284+ mm_segment_t oldfs;
80285
80286 /*
80287 * This will fail and we want it. Some arch implementations do
80288@@ -2745,8 +2752,11 @@ static int __init futex_init(void)
80289 * implementation, the non-functional ones will return
80290 * -ENOSYS.
80291 */
80292+ oldfs = get_fs();
80293+ set_fs(USER_DS);
80294 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
80295 futex_cmpxchg_enabled = 1;
80296+ set_fs(oldfs);
80297
80298 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
80299 plist_head_init(&futex_queues[i].chain);
80300diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
80301index f9f44fd..29885e4 100644
80302--- a/kernel/futex_compat.c
80303+++ b/kernel/futex_compat.c
80304@@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
80305 return 0;
80306 }
80307
80308-static void __user *futex_uaddr(struct robust_list __user *entry,
80309+static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
80310 compat_long_t futex_offset)
80311 {
80312 compat_uptr_t base = ptr_to_compat(entry);
80313diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
80314index 9b22d03..6295b62 100644
80315--- a/kernel/gcov/base.c
80316+++ b/kernel/gcov/base.c
80317@@ -102,11 +102,6 @@ void gcov_enable_events(void)
80318 }
80319
80320 #ifdef CONFIG_MODULES
80321-static inline int within(void *addr, void *start, unsigned long size)
80322-{
80323- return ((addr >= start) && (addr < start + size));
80324-}
80325-
80326 /* Update list and generate events when modules are unloaded. */
80327 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
80328 void *data)
80329@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
80330 prev = NULL;
80331 /* Remove entries located in module from linked list. */
80332 for (info = gcov_info_head; info; info = info->next) {
80333- if (within(info, mod->module_core, mod->core_size)) {
80334+ if (within_module_core_rw((unsigned long)info, mod)) {
80335 if (prev)
80336 prev->next = info->next;
80337 else
80338diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
80339index 383319b..56ebb13 100644
80340--- a/kernel/hrtimer.c
80341+++ b/kernel/hrtimer.c
80342@@ -1438,7 +1438,7 @@ void hrtimer_peek_ahead_timers(void)
80343 local_irq_restore(flags);
80344 }
80345
80346-static void run_hrtimer_softirq(struct softirq_action *h)
80347+static __latent_entropy void run_hrtimer_softirq(void)
80348 {
80349 hrtimer_peek_ahead_timers();
80350 }
80351diff --git a/kernel/irq_work.c b/kernel/irq_work.c
80352index 55fcce6..0e4cf34 100644
80353--- a/kernel/irq_work.c
80354+++ b/kernel/irq_work.c
80355@@ -189,12 +189,13 @@ static int irq_work_cpu_notify(struct notifier_block *self,
80356 return NOTIFY_OK;
80357 }
80358
80359-static struct notifier_block cpu_notify;
80360+static struct notifier_block cpu_notify = {
80361+ .notifier_call = irq_work_cpu_notify,
80362+ .priority = 0,
80363+};
80364
80365 static __init int irq_work_init_cpu_notifier(void)
80366 {
80367- cpu_notify.notifier_call = irq_work_cpu_notify;
80368- cpu_notify.priority = 0;
80369 register_cpu_notifier(&cpu_notify);
80370 return 0;
80371 }
80372diff --git a/kernel/jump_label.c b/kernel/jump_label.c
80373index 60f48fa..7f3a770 100644
80374--- a/kernel/jump_label.c
80375+++ b/kernel/jump_label.c
80376@@ -13,6 +13,7 @@
80377 #include <linux/sort.h>
80378 #include <linux/err.h>
80379 #include <linux/static_key.h>
80380+#include <linux/mm.h>
80381
80382 #ifdef HAVE_JUMP_LABEL
80383
80384@@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
80385
80386 size = (((unsigned long)stop - (unsigned long)start)
80387 / sizeof(struct jump_entry));
80388+ pax_open_kernel();
80389 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
80390+ pax_close_kernel();
80391 }
80392
80393 static void jump_label_update(struct static_key *key, int enable);
80394@@ -357,10 +360,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
80395 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
80396 struct jump_entry *iter;
80397
80398+ pax_open_kernel();
80399 for (iter = iter_start; iter < iter_stop; iter++) {
80400 if (within_module_init(iter->code, mod))
80401 iter->code = 0;
80402 }
80403+ pax_close_kernel();
80404 }
80405
80406 static int
80407diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
80408index 3127ad5..159d880 100644
80409--- a/kernel/kallsyms.c
80410+++ b/kernel/kallsyms.c
80411@@ -11,6 +11,9 @@
80412 * Changed the compression method from stem compression to "table lookup"
80413 * compression (see scripts/kallsyms.c for a more complete description)
80414 */
80415+#ifdef CONFIG_GRKERNSEC_HIDESYM
80416+#define __INCLUDED_BY_HIDESYM 1
80417+#endif
80418 #include <linux/kallsyms.h>
80419 #include <linux/module.h>
80420 #include <linux/init.h>
80421@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
80422
80423 static inline int is_kernel_inittext(unsigned long addr)
80424 {
80425+ if (system_state != SYSTEM_BOOTING)
80426+ return 0;
80427+
80428 if (addr >= (unsigned long)_sinittext
80429 && addr <= (unsigned long)_einittext)
80430 return 1;
80431 return 0;
80432 }
80433
80434+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
80435+#ifdef CONFIG_MODULES
80436+static inline int is_module_text(unsigned long addr)
80437+{
80438+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
80439+ return 1;
80440+
80441+ addr = ktla_ktva(addr);
80442+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
80443+}
80444+#else
80445+static inline int is_module_text(unsigned long addr)
80446+{
80447+ return 0;
80448+}
80449+#endif
80450+#endif
80451+
80452 static inline int is_kernel_text(unsigned long addr)
80453 {
80454 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
80455@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
80456
80457 static inline int is_kernel(unsigned long addr)
80458 {
80459+
80460+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
80461+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
80462+ return 1;
80463+
80464+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
80465+#else
80466 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
80467+#endif
80468+
80469 return 1;
80470 return in_gate_area_no_mm(addr);
80471 }
80472
80473 static int is_ksym_addr(unsigned long addr)
80474 {
80475+
80476+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
80477+ if (is_module_text(addr))
80478+ return 0;
80479+#endif
80480+
80481 if (all_var)
80482 return is_kernel(addr);
80483
80484@@ -480,7 +519,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
80485
80486 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
80487 {
80488- iter->name[0] = '\0';
80489 iter->nameoff = get_symbol_offset(new_pos);
80490 iter->pos = new_pos;
80491 }
80492@@ -528,6 +566,11 @@ static int s_show(struct seq_file *m, void *p)
80493 {
80494 struct kallsym_iter *iter = m->private;
80495
80496+#ifdef CONFIG_GRKERNSEC_HIDESYM
80497+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
80498+ return 0;
80499+#endif
80500+
80501 /* Some debugging symbols have no name. Ignore them. */
80502 if (!iter->name[0])
80503 return 0;
80504@@ -541,6 +584,7 @@ static int s_show(struct seq_file *m, void *p)
80505 */
80506 type = iter->exported ? toupper(iter->type) :
80507 tolower(iter->type);
80508+
80509 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
80510 type, iter->name, iter->module_name);
80511 } else
80512@@ -566,7 +610,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
80513 struct kallsym_iter *iter;
80514 int ret;
80515
80516- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
80517+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
80518 if (!iter)
80519 return -ENOMEM;
80520 reset_iter(iter, 0);
80521diff --git a/kernel/kcmp.c b/kernel/kcmp.c
80522index e30ac0f..3528cac 100644
80523--- a/kernel/kcmp.c
80524+++ b/kernel/kcmp.c
80525@@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
80526 struct task_struct *task1, *task2;
80527 int ret;
80528
80529+#ifdef CONFIG_GRKERNSEC
80530+ return -ENOSYS;
80531+#endif
80532+
80533 rcu_read_lock();
80534
80535 /*
80536diff --git a/kernel/kexec.c b/kernel/kexec.c
80537index 59f7b55..4022f65 100644
80538--- a/kernel/kexec.c
80539+++ b/kernel/kexec.c
80540@@ -1041,7 +1041,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
80541 unsigned long flags)
80542 {
80543 struct compat_kexec_segment in;
80544- struct kexec_segment out, __user *ksegments;
80545+ struct kexec_segment out;
80546+ struct kexec_segment __user *ksegments;
80547 unsigned long i, result;
80548
80549 /* Don't allow clients that don't understand the native
80550diff --git a/kernel/kmod.c b/kernel/kmod.c
80551index fb32636..2fe8775 100644
80552--- a/kernel/kmod.c
80553+++ b/kernel/kmod.c
80554@@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
80555 kfree(info->argv);
80556 }
80557
80558-static int call_modprobe(char *module_name, int wait)
80559+static int call_modprobe(char *module_name, char *module_param, int wait)
80560 {
80561 struct subprocess_info *info;
80562 static char *envp[] = {
80563@@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
80564 NULL
80565 };
80566
80567- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
80568+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
80569 if (!argv)
80570 goto out;
80571
80572@@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
80573 argv[1] = "-q";
80574 argv[2] = "--";
80575 argv[3] = module_name; /* check free_modprobe_argv() */
80576- argv[4] = NULL;
80577+ argv[4] = module_param;
80578+ argv[5] = NULL;
80579
80580 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
80581 NULL, free_modprobe_argv, NULL);
80582@@ -129,9 +130,8 @@ out:
80583 * If module auto-loading support is disabled then this function
80584 * becomes a no-operation.
80585 */
80586-int __request_module(bool wait, const char *fmt, ...)
80587+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
80588 {
80589- va_list args;
80590 char module_name[MODULE_NAME_LEN];
80591 unsigned int max_modprobes;
80592 int ret;
80593@@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
80594 if (!modprobe_path[0])
80595 return 0;
80596
80597- va_start(args, fmt);
80598- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
80599- va_end(args);
80600+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
80601 if (ret >= MODULE_NAME_LEN)
80602 return -ENAMETOOLONG;
80603
80604@@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
80605 if (ret)
80606 return ret;
80607
80608+#ifdef CONFIG_GRKERNSEC_MODHARDEN
80609+ if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
80610+ /* hack to workaround consolekit/udisks stupidity */
80611+ read_lock(&tasklist_lock);
80612+ if (!strcmp(current->comm, "mount") &&
80613+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
80614+ read_unlock(&tasklist_lock);
80615+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
80616+ return -EPERM;
80617+ }
80618+ read_unlock(&tasklist_lock);
80619+ }
80620+#endif
80621+
80622 /* If modprobe needs a service that is in a module, we get a recursive
80623 * loop. Limit the number of running kmod threads to max_threads/2 or
80624 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
80625@@ -188,11 +200,52 @@ int __request_module(bool wait, const char *fmt, ...)
80626
80627 trace_module_request(module_name, wait, _RET_IP_);
80628
80629- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
80630+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
80631
80632 atomic_dec(&kmod_concurrent);
80633 return ret;
80634 }
80635+
80636+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
80637+{
80638+ va_list args;
80639+ int ret;
80640+
80641+ va_start(args, fmt);
80642+ ret = ____request_module(wait, module_param, fmt, args);
80643+ va_end(args);
80644+
80645+ return ret;
80646+}
80647+
80648+int __request_module(bool wait, const char *fmt, ...)
80649+{
80650+ va_list args;
80651+ int ret;
80652+
80653+#ifdef CONFIG_GRKERNSEC_MODHARDEN
80654+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
80655+ char module_param[MODULE_NAME_LEN];
80656+
80657+ memset(module_param, 0, sizeof(module_param));
80658+
80659+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
80660+
80661+ va_start(args, fmt);
80662+ ret = ____request_module(wait, module_param, fmt, args);
80663+ va_end(args);
80664+
80665+ return ret;
80666+ }
80667+#endif
80668+
80669+ va_start(args, fmt);
80670+ ret = ____request_module(wait, NULL, fmt, args);
80671+ va_end(args);
80672+
80673+ return ret;
80674+}
80675+
80676 EXPORT_SYMBOL(__request_module);
80677 #endif /* CONFIG_MODULES */
80678
80679@@ -303,7 +356,7 @@ static int wait_for_helper(void *data)
80680 *
80681 * Thus the __user pointer cast is valid here.
80682 */
80683- sys_wait4(pid, (int __user *)&ret, 0, NULL);
80684+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
80685
80686 /*
80687 * If ret is 0, either ____call_usermodehelper failed and the
80688@@ -646,7 +699,7 @@ EXPORT_SYMBOL(call_usermodehelper);
80689 static int proc_cap_handler(struct ctl_table *table, int write,
80690 void __user *buffer, size_t *lenp, loff_t *ppos)
80691 {
80692- struct ctl_table t;
80693+ ctl_table_no_const t;
80694 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
80695 kernel_cap_t new_cap;
80696 int err, i;
80697diff --git a/kernel/kprobes.c b/kernel/kprobes.c
80698index 6e33498..3133bd3 100644
80699--- a/kernel/kprobes.c
80700+++ b/kernel/kprobes.c
80701@@ -31,6 +31,9 @@
80702 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
80703 * <prasanna@in.ibm.com> added function-return probes.
80704 */
80705+#ifdef CONFIG_GRKERNSEC_HIDESYM
80706+#define __INCLUDED_BY_HIDESYM 1
80707+#endif
80708 #include <linux/kprobes.h>
80709 #include <linux/hash.h>
80710 #include <linux/init.h>
80711@@ -185,7 +188,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
80712 * kernel image and loaded module images reside. This is required
80713 * so x86_64 can correctly handle the %rip-relative fixups.
80714 */
80715- kip->insns = module_alloc(PAGE_SIZE);
80716+ kip->insns = module_alloc_exec(PAGE_SIZE);
80717 if (!kip->insns) {
80718 kfree(kip);
80719 return NULL;
80720@@ -225,7 +228,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
80721 */
80722 if (!list_is_singular(&kip->list)) {
80723 list_del(&kip->list);
80724- module_free(NULL, kip->insns);
80725+ module_free_exec(NULL, kip->insns);
80726 kfree(kip);
80727 }
80728 return 1;
80729@@ -2083,7 +2086,7 @@ static int __init init_kprobes(void)
80730 {
80731 int i, err = 0;
80732 unsigned long offset = 0, size = 0;
80733- char *modname, namebuf[128];
80734+ char *modname, namebuf[KSYM_NAME_LEN];
80735 const char *symbol_name;
80736 void *addr;
80737 struct kprobe_blackpoint *kb;
80738@@ -2168,11 +2171,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
80739 kprobe_type = "k";
80740
80741 if (sym)
80742- seq_printf(pi, "%p %s %s+0x%x %s ",
80743+ seq_printf(pi, "%pK %s %s+0x%x %s ",
80744 p->addr, kprobe_type, sym, offset,
80745 (modname ? modname : " "));
80746 else
80747- seq_printf(pi, "%p %s %p ",
80748+ seq_printf(pi, "%pK %s %pK ",
80749 p->addr, kprobe_type, p->addr);
80750
80751 if (!pp)
80752@@ -2209,7 +2212,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
80753 const char *sym = NULL;
80754 unsigned int i = *(loff_t *) v;
80755 unsigned long offset = 0;
80756- char *modname, namebuf[128];
80757+ char *modname, namebuf[KSYM_NAME_LEN];
80758
80759 head = &kprobe_table[i];
80760 preempt_disable();
80761diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
80762index 6ada93c..dce7d5d 100644
80763--- a/kernel/ksysfs.c
80764+++ b/kernel/ksysfs.c
80765@@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
80766 {
80767 if (count+1 > UEVENT_HELPER_PATH_LEN)
80768 return -ENOENT;
80769+ if (!capable(CAP_SYS_ADMIN))
80770+ return -EPERM;
80771 memcpy(uevent_helper, buf, count);
80772 uevent_helper[count] = '\0';
80773 if (count && uevent_helper[count-1] == '\n')
80774@@ -172,7 +174,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
80775 return count;
80776 }
80777
80778-static struct bin_attribute notes_attr = {
80779+static bin_attribute_no_const notes_attr __read_only = {
80780 .attr = {
80781 .name = "notes",
80782 .mode = S_IRUGO,
80783diff --git a/kernel/lockdep.c b/kernel/lockdep.c
80784index e16c45b..6f49c48 100644
80785--- a/kernel/lockdep.c
80786+++ b/kernel/lockdep.c
80787@@ -596,6 +596,10 @@ static int static_obj(void *obj)
80788 end = (unsigned long) &_end,
80789 addr = (unsigned long) obj;
80790
80791+#ifdef CONFIG_PAX_KERNEXEC
80792+ start = ktla_ktva(start);
80793+#endif
80794+
80795 /*
80796 * static variable?
80797 */
80798@@ -736,6 +740,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
80799 if (!static_obj(lock->key)) {
80800 debug_locks_off();
80801 printk("INFO: trying to register non-static key.\n");
80802+ printk("lock:%pS key:%pS.\n", lock, lock->key);
80803 printk("the code is fine but needs lockdep annotation.\n");
80804 printk("turning off the locking correctness validator.\n");
80805 dump_stack();
80806@@ -3080,7 +3085,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
80807 if (!class)
80808 return 0;
80809 }
80810- atomic_inc((atomic_t *)&class->ops);
80811+ atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
80812 if (very_verbose(class)) {
80813 printk("\nacquire class [%p] %s", class->key, class->name);
80814 if (class->name_version > 1)
80815diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
80816index b2c71c5..7b88d63 100644
80817--- a/kernel/lockdep_proc.c
80818+++ b/kernel/lockdep_proc.c
80819@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
80820 return 0;
80821 }
80822
80823- seq_printf(m, "%p", class->key);
80824+ seq_printf(m, "%pK", class->key);
80825 #ifdef CONFIG_DEBUG_LOCKDEP
80826 seq_printf(m, " OPS:%8ld", class->ops);
80827 #endif
80828@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
80829
80830 list_for_each_entry(entry, &class->locks_after, entry) {
80831 if (entry->distance == 1) {
80832- seq_printf(m, " -> [%p] ", entry->class->key);
80833+ seq_printf(m, " -> [%pK] ", entry->class->key);
80834 print_name(m, entry->class);
80835 seq_puts(m, "\n");
80836 }
80837@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
80838 if (!class->key)
80839 continue;
80840
80841- seq_printf(m, "[%p] ", class->key);
80842+ seq_printf(m, "[%pK] ", class->key);
80843 print_name(m, class);
80844 seq_puts(m, "\n");
80845 }
80846@@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
80847 if (!i)
80848 seq_line(m, '-', 40-namelen, namelen);
80849
80850- snprintf(ip, sizeof(ip), "[<%p>]",
80851+ snprintf(ip, sizeof(ip), "[<%pK>]",
80852 (void *)class->contention_point[i]);
80853 seq_printf(m, "%40s %14lu %29s %pS\n",
80854 name, stats->contention_point[i],
80855@@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
80856 if (!i)
80857 seq_line(m, '-', 40-namelen, namelen);
80858
80859- snprintf(ip, sizeof(ip), "[<%p>]",
80860+ snprintf(ip, sizeof(ip), "[<%pK>]",
80861 (void *)class->contending_point[i]);
80862 seq_printf(m, "%40s %14lu %29s %pS\n",
80863 name, stats->contending_point[i],
80864diff --git a/kernel/module.c b/kernel/module.c
80865index 2069158..71101bb 100644
80866--- a/kernel/module.c
80867+++ b/kernel/module.c
80868@@ -61,6 +61,7 @@
80869 #include <linux/pfn.h>
80870 #include <linux/bsearch.h>
80871 #include <linux/fips.h>
80872+#include <linux/grsecurity.h>
80873 #include <uapi/linux/module.h>
80874 #include "module-internal.h"
80875
80876@@ -156,7 +157,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
80877
80878 /* Bounds of module allocation, for speeding __module_address.
80879 * Protected by module_mutex. */
80880-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
80881+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
80882+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
80883
80884 int register_module_notifier(struct notifier_block * nb)
80885 {
80886@@ -323,7 +325,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
80887 return true;
80888
80889 list_for_each_entry_rcu(mod, &modules, list) {
80890- struct symsearch arr[] = {
80891+ struct symsearch modarr[] = {
80892 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
80893 NOT_GPL_ONLY, false },
80894 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
80895@@ -348,7 +350,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
80896 if (mod->state == MODULE_STATE_UNFORMED)
80897 continue;
80898
80899- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
80900+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
80901 return true;
80902 }
80903 return false;
80904@@ -490,7 +492,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
80905 if (!pcpusec->sh_size)
80906 return 0;
80907
80908- if (align > PAGE_SIZE) {
80909+ if (align-1 >= PAGE_SIZE) {
80910 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
80911 mod->name, align, PAGE_SIZE);
80912 align = PAGE_SIZE;
80913@@ -1096,7 +1098,7 @@ struct module_attribute module_uevent =
80914 static ssize_t show_coresize(struct module_attribute *mattr,
80915 struct module_kobject *mk, char *buffer)
80916 {
80917- return sprintf(buffer, "%u\n", mk->mod->core_size);
80918+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
80919 }
80920
80921 static struct module_attribute modinfo_coresize =
80922@@ -1105,7 +1107,7 @@ static struct module_attribute modinfo_coresize =
80923 static ssize_t show_initsize(struct module_attribute *mattr,
80924 struct module_kobject *mk, char *buffer)
80925 {
80926- return sprintf(buffer, "%u\n", mk->mod->init_size);
80927+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
80928 }
80929
80930 static struct module_attribute modinfo_initsize =
80931@@ -1320,7 +1322,7 @@ resolve_symbol_wait(struct module *mod,
80932 */
80933 #ifdef CONFIG_SYSFS
80934
80935-#ifdef CONFIG_KALLSYMS
80936+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
80937 static inline bool sect_empty(const Elf_Shdr *sect)
80938 {
80939 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
80940@@ -1460,7 +1462,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
80941 {
80942 unsigned int notes, loaded, i;
80943 struct module_notes_attrs *notes_attrs;
80944- struct bin_attribute *nattr;
80945+ bin_attribute_no_const *nattr;
80946
80947 /* failed to create section attributes, so can't create notes */
80948 if (!mod->sect_attrs)
80949@@ -1572,7 +1574,7 @@ static void del_usage_links(struct module *mod)
80950 static int module_add_modinfo_attrs(struct module *mod)
80951 {
80952 struct module_attribute *attr;
80953- struct module_attribute *temp_attr;
80954+ module_attribute_no_const *temp_attr;
80955 int error = 0;
80956 int i;
80957
80958@@ -1786,21 +1788,21 @@ static void set_section_ro_nx(void *base,
80959
80960 static void unset_module_core_ro_nx(struct module *mod)
80961 {
80962- set_page_attributes(mod->module_core + mod->core_text_size,
80963- mod->module_core + mod->core_size,
80964+ set_page_attributes(mod->module_core_rw,
80965+ mod->module_core_rw + mod->core_size_rw,
80966 set_memory_x);
80967- set_page_attributes(mod->module_core,
80968- mod->module_core + mod->core_ro_size,
80969+ set_page_attributes(mod->module_core_rx,
80970+ mod->module_core_rx + mod->core_size_rx,
80971 set_memory_rw);
80972 }
80973
80974 static void unset_module_init_ro_nx(struct module *mod)
80975 {
80976- set_page_attributes(mod->module_init + mod->init_text_size,
80977- mod->module_init + mod->init_size,
80978+ set_page_attributes(mod->module_init_rw,
80979+ mod->module_init_rw + mod->init_size_rw,
80980 set_memory_x);
80981- set_page_attributes(mod->module_init,
80982- mod->module_init + mod->init_ro_size,
80983+ set_page_attributes(mod->module_init_rx,
80984+ mod->module_init_rx + mod->init_size_rx,
80985 set_memory_rw);
80986 }
80987
80988@@ -1813,14 +1815,14 @@ void set_all_modules_text_rw(void)
80989 list_for_each_entry_rcu(mod, &modules, list) {
80990 if (mod->state == MODULE_STATE_UNFORMED)
80991 continue;
80992- if ((mod->module_core) && (mod->core_text_size)) {
80993- set_page_attributes(mod->module_core,
80994- mod->module_core + mod->core_text_size,
80995+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
80996+ set_page_attributes(mod->module_core_rx,
80997+ mod->module_core_rx + mod->core_size_rx,
80998 set_memory_rw);
80999 }
81000- if ((mod->module_init) && (mod->init_text_size)) {
81001- set_page_attributes(mod->module_init,
81002- mod->module_init + mod->init_text_size,
81003+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
81004+ set_page_attributes(mod->module_init_rx,
81005+ mod->module_init_rx + mod->init_size_rx,
81006 set_memory_rw);
81007 }
81008 }
81009@@ -1836,14 +1838,14 @@ void set_all_modules_text_ro(void)
81010 list_for_each_entry_rcu(mod, &modules, list) {
81011 if (mod->state == MODULE_STATE_UNFORMED)
81012 continue;
81013- if ((mod->module_core) && (mod->core_text_size)) {
81014- set_page_attributes(mod->module_core,
81015- mod->module_core + mod->core_text_size,
81016+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
81017+ set_page_attributes(mod->module_core_rx,
81018+ mod->module_core_rx + mod->core_size_rx,
81019 set_memory_ro);
81020 }
81021- if ((mod->module_init) && (mod->init_text_size)) {
81022- set_page_attributes(mod->module_init,
81023- mod->module_init + mod->init_text_size,
81024+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
81025+ set_page_attributes(mod->module_init_rx,
81026+ mod->module_init_rx + mod->init_size_rx,
81027 set_memory_ro);
81028 }
81029 }
81030@@ -1894,16 +1896,19 @@ static void free_module(struct module *mod)
81031
81032 /* This may be NULL, but that's OK */
81033 unset_module_init_ro_nx(mod);
81034- module_free(mod, mod->module_init);
81035+ module_free(mod, mod->module_init_rw);
81036+ module_free_exec(mod, mod->module_init_rx);
81037 kfree(mod->args);
81038 percpu_modfree(mod);
81039
81040 /* Free lock-classes: */
81041- lockdep_free_key_range(mod->module_core, mod->core_size);
81042+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
81043+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
81044
81045 /* Finally, free the core (containing the module structure) */
81046 unset_module_core_ro_nx(mod);
81047- module_free(mod, mod->module_core);
81048+ module_free_exec(mod, mod->module_core_rx);
81049+ module_free(mod, mod->module_core_rw);
81050
81051 #ifdef CONFIG_MPU
81052 update_protections(current->mm);
81053@@ -1973,9 +1978,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
81054 int ret = 0;
81055 const struct kernel_symbol *ksym;
81056
81057+#ifdef CONFIG_GRKERNSEC_MODHARDEN
81058+ int is_fs_load = 0;
81059+ int register_filesystem_found = 0;
81060+ char *p;
81061+
81062+ p = strstr(mod->args, "grsec_modharden_fs");
81063+ if (p) {
81064+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
81065+ /* copy \0 as well */
81066+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
81067+ is_fs_load = 1;
81068+ }
81069+#endif
81070+
81071 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
81072 const char *name = info->strtab + sym[i].st_name;
81073
81074+#ifdef CONFIG_GRKERNSEC_MODHARDEN
81075+ /* it's a real shame this will never get ripped and copied
81076+ upstream! ;(
81077+ */
81078+ if (is_fs_load && !strcmp(name, "register_filesystem"))
81079+ register_filesystem_found = 1;
81080+#endif
81081+
81082 switch (sym[i].st_shndx) {
81083 case SHN_COMMON:
81084 /* We compiled with -fno-common. These are not
81085@@ -1996,7 +2023,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
81086 ksym = resolve_symbol_wait(mod, info, name);
81087 /* Ok if resolved. */
81088 if (ksym && !IS_ERR(ksym)) {
81089+ pax_open_kernel();
81090 sym[i].st_value = ksym->value;
81091+ pax_close_kernel();
81092 break;
81093 }
81094
81095@@ -2015,11 +2044,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
81096 secbase = (unsigned long)mod_percpu(mod);
81097 else
81098 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
81099+ pax_open_kernel();
81100 sym[i].st_value += secbase;
81101+ pax_close_kernel();
81102 break;
81103 }
81104 }
81105
81106+#ifdef CONFIG_GRKERNSEC_MODHARDEN
81107+ if (is_fs_load && !register_filesystem_found) {
81108+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
81109+ ret = -EPERM;
81110+ }
81111+#endif
81112+
81113 return ret;
81114 }
81115
81116@@ -2103,22 +2141,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
81117 || s->sh_entsize != ~0UL
81118 || strstarts(sname, ".init"))
81119 continue;
81120- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
81121+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
81122+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
81123+ else
81124+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
81125 pr_debug("\t%s\n", sname);
81126 }
81127- switch (m) {
81128- case 0: /* executable */
81129- mod->core_size = debug_align(mod->core_size);
81130- mod->core_text_size = mod->core_size;
81131- break;
81132- case 1: /* RO: text and ro-data */
81133- mod->core_size = debug_align(mod->core_size);
81134- mod->core_ro_size = mod->core_size;
81135- break;
81136- case 3: /* whole core */
81137- mod->core_size = debug_align(mod->core_size);
81138- break;
81139- }
81140 }
81141
81142 pr_debug("Init section allocation order:\n");
81143@@ -2132,23 +2160,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
81144 || s->sh_entsize != ~0UL
81145 || !strstarts(sname, ".init"))
81146 continue;
81147- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
81148- | INIT_OFFSET_MASK);
81149+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
81150+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
81151+ else
81152+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
81153+ s->sh_entsize |= INIT_OFFSET_MASK;
81154 pr_debug("\t%s\n", sname);
81155 }
81156- switch (m) {
81157- case 0: /* executable */
81158- mod->init_size = debug_align(mod->init_size);
81159- mod->init_text_size = mod->init_size;
81160- break;
81161- case 1: /* RO: text and ro-data */
81162- mod->init_size = debug_align(mod->init_size);
81163- mod->init_ro_size = mod->init_size;
81164- break;
81165- case 3: /* whole init */
81166- mod->init_size = debug_align(mod->init_size);
81167- break;
81168- }
81169 }
81170 }
81171
81172@@ -2321,7 +2339,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
81173
81174 /* Put symbol section at end of init part of module. */
81175 symsect->sh_flags |= SHF_ALLOC;
81176- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
81177+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
81178 info->index.sym) | INIT_OFFSET_MASK;
81179 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
81180
81181@@ -2338,13 +2356,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
81182 }
81183
81184 /* Append room for core symbols at end of core part. */
81185- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
81186- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
81187- mod->core_size += strtab_size;
81188+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
81189+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
81190+ mod->core_size_rx += strtab_size;
81191
81192 /* Put string table section at end of init part of module. */
81193 strsect->sh_flags |= SHF_ALLOC;
81194- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
81195+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
81196 info->index.str) | INIT_OFFSET_MASK;
81197 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
81198 }
81199@@ -2362,12 +2380,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
81200 /* Make sure we get permanent strtab: don't use info->strtab. */
81201 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
81202
81203+ pax_open_kernel();
81204+
81205 /* Set types up while we still have access to sections. */
81206 for (i = 0; i < mod->num_symtab; i++)
81207 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
81208
81209- mod->core_symtab = dst = mod->module_core + info->symoffs;
81210- mod->core_strtab = s = mod->module_core + info->stroffs;
81211+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
81212+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
81213 src = mod->symtab;
81214 for (ndst = i = 0; i < mod->num_symtab; i++) {
81215 if (i == 0 ||
81216@@ -2379,6 +2399,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
81217 }
81218 }
81219 mod->core_num_syms = ndst;
81220+
81221+ pax_close_kernel();
81222 }
81223 #else
81224 static inline void layout_symtab(struct module *mod, struct load_info *info)
81225@@ -2412,17 +2434,33 @@ void * __weak module_alloc(unsigned long size)
81226 return vmalloc_exec(size);
81227 }
81228
81229-static void *module_alloc_update_bounds(unsigned long size)
81230+static void *module_alloc_update_bounds_rw(unsigned long size)
81231 {
81232 void *ret = module_alloc(size);
81233
81234 if (ret) {
81235 mutex_lock(&module_mutex);
81236 /* Update module bounds. */
81237- if ((unsigned long)ret < module_addr_min)
81238- module_addr_min = (unsigned long)ret;
81239- if ((unsigned long)ret + size > module_addr_max)
81240- module_addr_max = (unsigned long)ret + size;
81241+ if ((unsigned long)ret < module_addr_min_rw)
81242+ module_addr_min_rw = (unsigned long)ret;
81243+ if ((unsigned long)ret + size > module_addr_max_rw)
81244+ module_addr_max_rw = (unsigned long)ret + size;
81245+ mutex_unlock(&module_mutex);
81246+ }
81247+ return ret;
81248+}
81249+
81250+static void *module_alloc_update_bounds_rx(unsigned long size)
81251+{
81252+ void *ret = module_alloc_exec(size);
81253+
81254+ if (ret) {
81255+ mutex_lock(&module_mutex);
81256+ /* Update module bounds. */
81257+ if ((unsigned long)ret < module_addr_min_rx)
81258+ module_addr_min_rx = (unsigned long)ret;
81259+ if ((unsigned long)ret + size > module_addr_max_rx)
81260+ module_addr_max_rx = (unsigned long)ret + size;
81261 mutex_unlock(&module_mutex);
81262 }
81263 return ret;
81264@@ -2698,8 +2736,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
81265 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
81266 {
81267 const char *modmagic = get_modinfo(info, "vermagic");
81268+ const char *license = get_modinfo(info, "license");
81269 int err;
81270
81271+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
81272+ if (!license || !license_is_gpl_compatible(license))
81273+ return -ENOEXEC;
81274+#endif
81275+
81276 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
81277 modmagic = NULL;
81278
81279@@ -2725,7 +2769,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
81280 }
81281
81282 /* Set up license info based on the info section */
81283- set_license(mod, get_modinfo(info, "license"));
81284+ set_license(mod, license);
81285
81286 return 0;
81287 }
81288@@ -2806,7 +2850,7 @@ static int move_module(struct module *mod, struct load_info *info)
81289 void *ptr;
81290
81291 /* Do the allocs. */
81292- ptr = module_alloc_update_bounds(mod->core_size);
81293+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
81294 /*
81295 * The pointer to this block is stored in the module structure
81296 * which is inside the block. Just mark it as not being a
81297@@ -2816,11 +2860,11 @@ static int move_module(struct module *mod, struct load_info *info)
81298 if (!ptr)
81299 return -ENOMEM;
81300
81301- memset(ptr, 0, mod->core_size);
81302- mod->module_core = ptr;
81303+ memset(ptr, 0, mod->core_size_rw);
81304+ mod->module_core_rw = ptr;
81305
81306- if (mod->init_size) {
81307- ptr = module_alloc_update_bounds(mod->init_size);
81308+ if (mod->init_size_rw) {
81309+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
81310 /*
81311 * The pointer to this block is stored in the module structure
81312 * which is inside the block. This block doesn't need to be
81313@@ -2829,13 +2873,45 @@ static int move_module(struct module *mod, struct load_info *info)
81314 */
81315 kmemleak_ignore(ptr);
81316 if (!ptr) {
81317- module_free(mod, mod->module_core);
81318+ module_free(mod, mod->module_core_rw);
81319 return -ENOMEM;
81320 }
81321- memset(ptr, 0, mod->init_size);
81322- mod->module_init = ptr;
81323+ memset(ptr, 0, mod->init_size_rw);
81324+ mod->module_init_rw = ptr;
81325 } else
81326- mod->module_init = NULL;
81327+ mod->module_init_rw = NULL;
81328+
81329+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
81330+ kmemleak_not_leak(ptr);
81331+ if (!ptr) {
81332+ if (mod->module_init_rw)
81333+ module_free(mod, mod->module_init_rw);
81334+ module_free(mod, mod->module_core_rw);
81335+ return -ENOMEM;
81336+ }
81337+
81338+ pax_open_kernel();
81339+ memset(ptr, 0, mod->core_size_rx);
81340+ pax_close_kernel();
81341+ mod->module_core_rx = ptr;
81342+
81343+ if (mod->init_size_rx) {
81344+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
81345+ kmemleak_ignore(ptr);
81346+ if (!ptr && mod->init_size_rx) {
81347+ module_free_exec(mod, mod->module_core_rx);
81348+ if (mod->module_init_rw)
81349+ module_free(mod, mod->module_init_rw);
81350+ module_free(mod, mod->module_core_rw);
81351+ return -ENOMEM;
81352+ }
81353+
81354+ pax_open_kernel();
81355+ memset(ptr, 0, mod->init_size_rx);
81356+ pax_close_kernel();
81357+ mod->module_init_rx = ptr;
81358+ } else
81359+ mod->module_init_rx = NULL;
81360
81361 /* Transfer each section which specifies SHF_ALLOC */
81362 pr_debug("final section addresses:\n");
81363@@ -2846,16 +2922,45 @@ static int move_module(struct module *mod, struct load_info *info)
81364 if (!(shdr->sh_flags & SHF_ALLOC))
81365 continue;
81366
81367- if (shdr->sh_entsize & INIT_OFFSET_MASK)
81368- dest = mod->module_init
81369- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
81370- else
81371- dest = mod->module_core + shdr->sh_entsize;
81372+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
81373+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
81374+ dest = mod->module_init_rw
81375+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
81376+ else
81377+ dest = mod->module_init_rx
81378+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
81379+ } else {
81380+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
81381+ dest = mod->module_core_rw + shdr->sh_entsize;
81382+ else
81383+ dest = mod->module_core_rx + shdr->sh_entsize;
81384+ }
81385+
81386+ if (shdr->sh_type != SHT_NOBITS) {
81387+
81388+#ifdef CONFIG_PAX_KERNEXEC
81389+#ifdef CONFIG_X86_64
81390+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
81391+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
81392+#endif
81393+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
81394+ pax_open_kernel();
81395+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
81396+ pax_close_kernel();
81397+ } else
81398+#endif
81399
81400- if (shdr->sh_type != SHT_NOBITS)
81401 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
81402+ }
81403 /* Update sh_addr to point to copy in image. */
81404- shdr->sh_addr = (unsigned long)dest;
81405+
81406+#ifdef CONFIG_PAX_KERNEXEC
81407+ if (shdr->sh_flags & SHF_EXECINSTR)
81408+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
81409+ else
81410+#endif
81411+
81412+ shdr->sh_addr = (unsigned long)dest;
81413 pr_debug("\t0x%lx %s\n",
81414 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
81415 }
81416@@ -2912,12 +3017,12 @@ static void flush_module_icache(const struct module *mod)
81417 * Do it before processing of module parameters, so the module
81418 * can provide parameter accessor functions of its own.
81419 */
81420- if (mod->module_init)
81421- flush_icache_range((unsigned long)mod->module_init,
81422- (unsigned long)mod->module_init
81423- + mod->init_size);
81424- flush_icache_range((unsigned long)mod->module_core,
81425- (unsigned long)mod->module_core + mod->core_size);
81426+ if (mod->module_init_rx)
81427+ flush_icache_range((unsigned long)mod->module_init_rx,
81428+ (unsigned long)mod->module_init_rx
81429+ + mod->init_size_rx);
81430+ flush_icache_range((unsigned long)mod->module_core_rx,
81431+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
81432
81433 set_fs(old_fs);
81434 }
81435@@ -2974,8 +3079,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
81436 static void module_deallocate(struct module *mod, struct load_info *info)
81437 {
81438 percpu_modfree(mod);
81439- module_free(mod, mod->module_init);
81440- module_free(mod, mod->module_core);
81441+ module_free_exec(mod, mod->module_init_rx);
81442+ module_free_exec(mod, mod->module_core_rx);
81443+ module_free(mod, mod->module_init_rw);
81444+ module_free(mod, mod->module_core_rw);
81445 }
81446
81447 int __weak module_finalize(const Elf_Ehdr *hdr,
81448@@ -2988,7 +3095,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
81449 static int post_relocation(struct module *mod, const struct load_info *info)
81450 {
81451 /* Sort exception table now relocations are done. */
81452+ pax_open_kernel();
81453 sort_extable(mod->extable, mod->extable + mod->num_exentries);
81454+ pax_close_kernel();
81455
81456 /* Copy relocated percpu area over. */
81457 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
81458@@ -3042,16 +3151,16 @@ static int do_init_module(struct module *mod)
81459 MODULE_STATE_COMING, mod);
81460
81461 /* Set RO and NX regions for core */
81462- set_section_ro_nx(mod->module_core,
81463- mod->core_text_size,
81464- mod->core_ro_size,
81465- mod->core_size);
81466+ set_section_ro_nx(mod->module_core_rx,
81467+ mod->core_size_rx,
81468+ mod->core_size_rx,
81469+ mod->core_size_rx);
81470
81471 /* Set RO and NX regions for init */
81472- set_section_ro_nx(mod->module_init,
81473- mod->init_text_size,
81474- mod->init_ro_size,
81475- mod->init_size);
81476+ set_section_ro_nx(mod->module_init_rx,
81477+ mod->init_size_rx,
81478+ mod->init_size_rx,
81479+ mod->init_size_rx);
81480
81481 do_mod_ctors(mod);
81482 /* Start the module */
81483@@ -3113,11 +3222,12 @@ static int do_init_module(struct module *mod)
81484 mod->strtab = mod->core_strtab;
81485 #endif
81486 unset_module_init_ro_nx(mod);
81487- module_free(mod, mod->module_init);
81488- mod->module_init = NULL;
81489- mod->init_size = 0;
81490- mod->init_ro_size = 0;
81491- mod->init_text_size = 0;
81492+ module_free(mod, mod->module_init_rw);
81493+ module_free_exec(mod, mod->module_init_rx);
81494+ mod->module_init_rw = NULL;
81495+ mod->module_init_rx = NULL;
81496+ mod->init_size_rw = 0;
81497+ mod->init_size_rx = 0;
81498 mutex_unlock(&module_mutex);
81499 wake_up_all(&module_wq);
81500
81501@@ -3261,9 +3371,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
81502 if (err)
81503 goto free_unload;
81504
81505+ /* Now copy in args */
81506+ mod->args = strndup_user(uargs, ~0UL >> 1);
81507+ if (IS_ERR(mod->args)) {
81508+ err = PTR_ERR(mod->args);
81509+ goto free_unload;
81510+ }
81511+
81512 /* Set up MODINFO_ATTR fields */
81513 setup_modinfo(mod, info);
81514
81515+#ifdef CONFIG_GRKERNSEC_MODHARDEN
81516+ {
81517+ char *p, *p2;
81518+
81519+ if (strstr(mod->args, "grsec_modharden_netdev")) {
81520+ 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);
81521+ err = -EPERM;
81522+ goto free_modinfo;
81523+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
81524+ p += sizeof("grsec_modharden_normal") - 1;
81525+ p2 = strstr(p, "_");
81526+ if (p2) {
81527+ *p2 = '\0';
81528+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
81529+ *p2 = '_';
81530+ }
81531+ err = -EPERM;
81532+ goto free_modinfo;
81533+ }
81534+ }
81535+#endif
81536+
81537 /* Fix up syms, so that st_value is a pointer to location. */
81538 err = simplify_symbols(mod, info);
81539 if (err < 0)
81540@@ -3279,13 +3418,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
81541
81542 flush_module_icache(mod);
81543
81544- /* Now copy in args */
81545- mod->args = strndup_user(uargs, ~0UL >> 1);
81546- if (IS_ERR(mod->args)) {
81547- err = PTR_ERR(mod->args);
81548- goto free_arch_cleanup;
81549- }
81550-
81551 dynamic_debug_setup(info->debug, info->num_debug);
81552
81553 /* Finally it's fully formed, ready to start executing. */
81554@@ -3320,11 +3452,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
81555 ddebug_cleanup:
81556 dynamic_debug_remove(info->debug);
81557 synchronize_sched();
81558- kfree(mod->args);
81559- free_arch_cleanup:
81560 module_arch_cleanup(mod);
81561 free_modinfo:
81562 free_modinfo(mod);
81563+ kfree(mod->args);
81564 free_unload:
81565 module_unload_free(mod);
81566 unlink_mod:
81567@@ -3407,10 +3538,16 @@ static const char *get_ksymbol(struct module *mod,
81568 unsigned long nextval;
81569
81570 /* At worse, next value is at end of module */
81571- if (within_module_init(addr, mod))
81572- nextval = (unsigned long)mod->module_init+mod->init_text_size;
81573+ if (within_module_init_rx(addr, mod))
81574+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
81575+ else if (within_module_init_rw(addr, mod))
81576+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
81577+ else if (within_module_core_rx(addr, mod))
81578+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
81579+ else if (within_module_core_rw(addr, mod))
81580+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
81581 else
81582- nextval = (unsigned long)mod->module_core+mod->core_text_size;
81583+ return NULL;
81584
81585 /* Scan for closest preceding symbol, and next symbol. (ELF
81586 starts real symbols at 1). */
81587@@ -3661,7 +3798,7 @@ static int m_show(struct seq_file *m, void *p)
81588 return 0;
81589
81590 seq_printf(m, "%s %u",
81591- mod->name, mod->init_size + mod->core_size);
81592+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
81593 print_unload_info(m, mod);
81594
81595 /* Informative for users. */
81596@@ -3670,7 +3807,7 @@ static int m_show(struct seq_file *m, void *p)
81597 mod->state == MODULE_STATE_COMING ? "Loading":
81598 "Live");
81599 /* Used by oprofile and other similar tools. */
81600- seq_printf(m, " 0x%pK", mod->module_core);
81601+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
81602
81603 /* Taints info */
81604 if (mod->taints)
81605@@ -3706,7 +3843,17 @@ static const struct file_operations proc_modules_operations = {
81606
81607 static int __init proc_modules_init(void)
81608 {
81609+#ifndef CONFIG_GRKERNSEC_HIDESYM
81610+#ifdef CONFIG_GRKERNSEC_PROC_USER
81611+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
81612+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
81613+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
81614+#else
81615 proc_create("modules", 0, NULL, &proc_modules_operations);
81616+#endif
81617+#else
81618+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
81619+#endif
81620 return 0;
81621 }
81622 module_init(proc_modules_init);
81623@@ -3767,14 +3914,14 @@ struct module *__module_address(unsigned long addr)
81624 {
81625 struct module *mod;
81626
81627- if (addr < module_addr_min || addr > module_addr_max)
81628+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
81629+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
81630 return NULL;
81631
81632 list_for_each_entry_rcu(mod, &modules, list) {
81633 if (mod->state == MODULE_STATE_UNFORMED)
81634 continue;
81635- if (within_module_core(addr, mod)
81636- || within_module_init(addr, mod))
81637+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
81638 return mod;
81639 }
81640 return NULL;
81641@@ -3809,11 +3956,20 @@ bool is_module_text_address(unsigned long addr)
81642 */
81643 struct module *__module_text_address(unsigned long addr)
81644 {
81645- struct module *mod = __module_address(addr);
81646+ struct module *mod;
81647+
81648+#ifdef CONFIG_X86_32
81649+ addr = ktla_ktva(addr);
81650+#endif
81651+
81652+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
81653+ return NULL;
81654+
81655+ mod = __module_address(addr);
81656+
81657 if (mod) {
81658 /* Make sure it's within the text section. */
81659- if (!within(addr, mod->module_init, mod->init_text_size)
81660- && !within(addr, mod->module_core, mod->core_text_size))
81661+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
81662 mod = NULL;
81663 }
81664 return mod;
81665diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
81666index 7e3443f..b2a1e6b 100644
81667--- a/kernel/mutex-debug.c
81668+++ b/kernel/mutex-debug.c
81669@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
81670 }
81671
81672 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
81673- struct thread_info *ti)
81674+ struct task_struct *task)
81675 {
81676 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
81677
81678 /* Mark the current thread as blocked on the lock: */
81679- ti->task->blocked_on = waiter;
81680+ task->blocked_on = waiter;
81681 }
81682
81683 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
81684- struct thread_info *ti)
81685+ struct task_struct *task)
81686 {
81687 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
81688- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
81689- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
81690- ti->task->blocked_on = NULL;
81691+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
81692+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
81693+ task->blocked_on = NULL;
81694
81695 list_del_init(&waiter->list);
81696 waiter->task = NULL;
81697diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
81698index 0799fd3..d06ae3b 100644
81699--- a/kernel/mutex-debug.h
81700+++ b/kernel/mutex-debug.h
81701@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
81702 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
81703 extern void debug_mutex_add_waiter(struct mutex *lock,
81704 struct mutex_waiter *waiter,
81705- struct thread_info *ti);
81706+ struct task_struct *task);
81707 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
81708- struct thread_info *ti);
81709+ struct task_struct *task);
81710 extern void debug_mutex_unlock(struct mutex *lock);
81711 extern void debug_mutex_init(struct mutex *lock, const char *name,
81712 struct lock_class_key *key);
81713diff --git a/kernel/mutex.c b/kernel/mutex.c
81714index a52ee7bb..f361f16 100644
81715--- a/kernel/mutex.c
81716+++ b/kernel/mutex.c
81717@@ -135,7 +135,7 @@ void mspin_lock(struct mspin_node **lock, struct mspin_node *node)
81718 node->locked = 1;
81719 return;
81720 }
81721- ACCESS_ONCE(prev->next) = node;
81722+ ACCESS_ONCE_RW(prev->next) = node;
81723 smp_wmb();
81724 /* Wait until the lock holder passes the lock down */
81725 while (!ACCESS_ONCE(node->locked))
81726@@ -156,7 +156,7 @@ static void mspin_unlock(struct mspin_node **lock, struct mspin_node *node)
81727 while (!(next = ACCESS_ONCE(node->next)))
81728 arch_mutex_cpu_relax();
81729 }
81730- ACCESS_ONCE(next->locked) = 1;
81731+ ACCESS_ONCE_RW(next->locked) = 1;
81732 smp_wmb();
81733 }
81734
81735@@ -514,7 +514,7 @@ slowpath:
81736 spin_lock_mutex(&lock->wait_lock, flags);
81737
81738 debug_mutex_lock_common(lock, &waiter);
81739- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
81740+ debug_mutex_add_waiter(lock, &waiter, task);
81741
81742 /* add waiting tasks to the end of the waitqueue (FIFO): */
81743 list_add_tail(&waiter.list, &lock->wait_list);
81744@@ -565,7 +565,7 @@ slowpath:
81745 done:
81746 lock_acquired(&lock->dep_map, ip);
81747 /* got the lock - rejoice! */
81748- mutex_remove_waiter(lock, &waiter, current_thread_info());
81749+ mutex_remove_waiter(lock, &waiter, task);
81750 mutex_set_owner(lock);
81751
81752 if (!__builtin_constant_p(ww_ctx == NULL)) {
81753@@ -604,7 +604,7 @@ done:
81754 return 0;
81755
81756 err:
81757- mutex_remove_waiter(lock, &waiter, task_thread_info(task));
81758+ mutex_remove_waiter(lock, &waiter, task);
81759 spin_unlock_mutex(&lock->wait_lock, flags);
81760 debug_mutex_free_waiter(&waiter);
81761 mutex_release(&lock->dep_map, 1, ip);
81762diff --git a/kernel/notifier.c b/kernel/notifier.c
81763index 2d5cc4c..d9ea600 100644
81764--- a/kernel/notifier.c
81765+++ b/kernel/notifier.c
81766@@ -5,6 +5,7 @@
81767 #include <linux/rcupdate.h>
81768 #include <linux/vmalloc.h>
81769 #include <linux/reboot.h>
81770+#include <linux/mm.h>
81771
81772 /*
81773 * Notifier list for kernel code which wants to be called
81774@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
81775 while ((*nl) != NULL) {
81776 if (n->priority > (*nl)->priority)
81777 break;
81778- nl = &((*nl)->next);
81779+ nl = (struct notifier_block **)&((*nl)->next);
81780 }
81781- n->next = *nl;
81782+ pax_open_kernel();
81783+ *(const void **)&n->next = *nl;
81784 rcu_assign_pointer(*nl, n);
81785+ pax_close_kernel();
81786 return 0;
81787 }
81788
81789@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
81790 return 0;
81791 if (n->priority > (*nl)->priority)
81792 break;
81793- nl = &((*nl)->next);
81794+ nl = (struct notifier_block **)&((*nl)->next);
81795 }
81796- n->next = *nl;
81797+ pax_open_kernel();
81798+ *(const void **)&n->next = *nl;
81799 rcu_assign_pointer(*nl, n);
81800+ pax_close_kernel();
81801 return 0;
81802 }
81803
81804@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
81805 {
81806 while ((*nl) != NULL) {
81807 if ((*nl) == n) {
81808+ pax_open_kernel();
81809 rcu_assign_pointer(*nl, n->next);
81810+ pax_close_kernel();
81811 return 0;
81812 }
81813- nl = &((*nl)->next);
81814+ nl = (struct notifier_block **)&((*nl)->next);
81815 }
81816 return -ENOENT;
81817 }
81818diff --git a/kernel/panic.c b/kernel/panic.c
81819index 8018646..b6a5b4f 100644
81820--- a/kernel/panic.c
81821+++ b/kernel/panic.c
81822@@ -403,7 +403,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
81823 disable_trace_on_warning();
81824
81825 pr_warn("------------[ cut here ]------------\n");
81826- pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
81827+ pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
81828 raw_smp_processor_id(), current->pid, file, line, caller);
81829
81830 if (args)
81831@@ -457,7 +457,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
81832 */
81833 void __stack_chk_fail(void)
81834 {
81835- panic("stack-protector: Kernel stack is corrupted in: %p\n",
81836+ dump_stack();
81837+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
81838 __builtin_return_address(0));
81839 }
81840 EXPORT_SYMBOL(__stack_chk_fail);
81841diff --git a/kernel/pid.c b/kernel/pid.c
81842index ebe5e80..5d6d634 100644
81843--- a/kernel/pid.c
81844+++ b/kernel/pid.c
81845@@ -33,6 +33,7 @@
81846 #include <linux/rculist.h>
81847 #include <linux/bootmem.h>
81848 #include <linux/hash.h>
81849+#include <linux/security.h>
81850 #include <linux/pid_namespace.h>
81851 #include <linux/init_task.h>
81852 #include <linux/syscalls.h>
81853@@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
81854
81855 int pid_max = PID_MAX_DEFAULT;
81856
81857-#define RESERVED_PIDS 300
81858+#define RESERVED_PIDS 500
81859
81860 int pid_max_min = RESERVED_PIDS + 1;
81861 int pid_max_max = PID_MAX_LIMIT;
81862@@ -440,10 +441,18 @@ EXPORT_SYMBOL(pid_task);
81863 */
81864 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
81865 {
81866+ struct task_struct *task;
81867+
81868 rcu_lockdep_assert(rcu_read_lock_held(),
81869 "find_task_by_pid_ns() needs rcu_read_lock()"
81870 " protection");
81871- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
81872+
81873+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
81874+
81875+ if (gr_pid_is_chrooted(task))
81876+ return NULL;
81877+
81878+ return task;
81879 }
81880
81881 struct task_struct *find_task_by_vpid(pid_t vnr)
81882@@ -451,6 +460,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
81883 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
81884 }
81885
81886+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
81887+{
81888+ rcu_lockdep_assert(rcu_read_lock_held(),
81889+ "find_task_by_pid_ns() needs rcu_read_lock()"
81890+ " protection");
81891+ return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
81892+}
81893+
81894 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
81895 {
81896 struct pid *pid;
81897diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
81898index 601bb36..f7e6f34 100644
81899--- a/kernel/pid_namespace.c
81900+++ b/kernel/pid_namespace.c
81901@@ -247,7 +247,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
81902 void __user *buffer, size_t *lenp, loff_t *ppos)
81903 {
81904 struct pid_namespace *pid_ns = task_active_pid_ns(current);
81905- struct ctl_table tmp = *table;
81906+ ctl_table_no_const tmp = *table;
81907
81908 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
81909 return -EPERM;
81910diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
81911index c7f31aa..2b44977 100644
81912--- a/kernel/posix-cpu-timers.c
81913+++ b/kernel/posix-cpu-timers.c
81914@@ -1521,14 +1521,14 @@ struct k_clock clock_posix_cpu = {
81915
81916 static __init int init_posix_cpu_timers(void)
81917 {
81918- struct k_clock process = {
81919+ static struct k_clock process = {
81920 .clock_getres = process_cpu_clock_getres,
81921 .clock_get = process_cpu_clock_get,
81922 .timer_create = process_cpu_timer_create,
81923 .nsleep = process_cpu_nsleep,
81924 .nsleep_restart = process_cpu_nsleep_restart,
81925 };
81926- struct k_clock thread = {
81927+ static struct k_clock thread = {
81928 .clock_getres = thread_cpu_clock_getres,
81929 .clock_get = thread_cpu_clock_get,
81930 .timer_create = thread_cpu_timer_create,
81931diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
81932index 424c2d4..679242f 100644
81933--- a/kernel/posix-timers.c
81934+++ b/kernel/posix-timers.c
81935@@ -43,6 +43,7 @@
81936 #include <linux/hash.h>
81937 #include <linux/posix-clock.h>
81938 #include <linux/posix-timers.h>
81939+#include <linux/grsecurity.h>
81940 #include <linux/syscalls.h>
81941 #include <linux/wait.h>
81942 #include <linux/workqueue.h>
81943@@ -122,7 +123,7 @@ static DEFINE_SPINLOCK(hash_lock);
81944 * which we beg off on and pass to do_sys_settimeofday().
81945 */
81946
81947-static struct k_clock posix_clocks[MAX_CLOCKS];
81948+static struct k_clock *posix_clocks[MAX_CLOCKS];
81949
81950 /*
81951 * These ones are defined below.
81952@@ -275,7 +276,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
81953 */
81954 static __init int init_posix_timers(void)
81955 {
81956- struct k_clock clock_realtime = {
81957+ static struct k_clock clock_realtime = {
81958 .clock_getres = hrtimer_get_res,
81959 .clock_get = posix_clock_realtime_get,
81960 .clock_set = posix_clock_realtime_set,
81961@@ -287,7 +288,7 @@ static __init int init_posix_timers(void)
81962 .timer_get = common_timer_get,
81963 .timer_del = common_timer_del,
81964 };
81965- struct k_clock clock_monotonic = {
81966+ static struct k_clock clock_monotonic = {
81967 .clock_getres = hrtimer_get_res,
81968 .clock_get = posix_ktime_get_ts,
81969 .nsleep = common_nsleep,
81970@@ -297,19 +298,19 @@ static __init int init_posix_timers(void)
81971 .timer_get = common_timer_get,
81972 .timer_del = common_timer_del,
81973 };
81974- struct k_clock clock_monotonic_raw = {
81975+ static struct k_clock clock_monotonic_raw = {
81976 .clock_getres = hrtimer_get_res,
81977 .clock_get = posix_get_monotonic_raw,
81978 };
81979- struct k_clock clock_realtime_coarse = {
81980+ static struct k_clock clock_realtime_coarse = {
81981 .clock_getres = posix_get_coarse_res,
81982 .clock_get = posix_get_realtime_coarse,
81983 };
81984- struct k_clock clock_monotonic_coarse = {
81985+ static struct k_clock clock_monotonic_coarse = {
81986 .clock_getres = posix_get_coarse_res,
81987 .clock_get = posix_get_monotonic_coarse,
81988 };
81989- struct k_clock clock_tai = {
81990+ static struct k_clock clock_tai = {
81991 .clock_getres = hrtimer_get_res,
81992 .clock_get = posix_get_tai,
81993 .nsleep = common_nsleep,
81994@@ -319,7 +320,7 @@ static __init int init_posix_timers(void)
81995 .timer_get = common_timer_get,
81996 .timer_del = common_timer_del,
81997 };
81998- struct k_clock clock_boottime = {
81999+ static struct k_clock clock_boottime = {
82000 .clock_getres = hrtimer_get_res,
82001 .clock_get = posix_get_boottime,
82002 .nsleep = common_nsleep,
82003@@ -531,7 +532,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
82004 return;
82005 }
82006
82007- posix_clocks[clock_id] = *new_clock;
82008+ posix_clocks[clock_id] = new_clock;
82009 }
82010 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
82011
82012@@ -577,9 +578,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
82013 return (id & CLOCKFD_MASK) == CLOCKFD ?
82014 &clock_posix_dynamic : &clock_posix_cpu;
82015
82016- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
82017+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
82018 return NULL;
82019- return &posix_clocks[id];
82020+ return posix_clocks[id];
82021 }
82022
82023 static int common_timer_create(struct k_itimer *new_timer)
82024@@ -597,7 +598,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
82025 struct k_clock *kc = clockid_to_kclock(which_clock);
82026 struct k_itimer *new_timer;
82027 int error, new_timer_id;
82028- sigevent_t event;
82029+ sigevent_t event = { };
82030 int it_id_set = IT_ID_NOT_SET;
82031
82032 if (!kc)
82033@@ -1011,6 +1012,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
82034 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
82035 return -EFAULT;
82036
82037+ /* only the CLOCK_REALTIME clock can be set, all other clocks
82038+ have their clock_set fptr set to a nosettime dummy function
82039+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
82040+ call common_clock_set, which calls do_sys_settimeofday, which
82041+ we hook
82042+ */
82043+
82044 return kc->clock_set(which_clock, &new_tp);
82045 }
82046
82047diff --git a/kernel/power/process.c b/kernel/power/process.c
82048index 06ec886..9dba35e 100644
82049--- a/kernel/power/process.c
82050+++ b/kernel/power/process.c
82051@@ -34,6 +34,7 @@ static int try_to_freeze_tasks(bool user_only)
82052 unsigned int elapsed_msecs;
82053 bool wakeup = false;
82054 int sleep_usecs = USEC_PER_MSEC;
82055+ bool timedout = false;
82056
82057 do_gettimeofday(&start);
82058
82059@@ -44,13 +45,20 @@ static int try_to_freeze_tasks(bool user_only)
82060
82061 while (true) {
82062 todo = 0;
82063+ if (time_after(jiffies, end_time))
82064+ timedout = true;
82065 read_lock(&tasklist_lock);
82066 do_each_thread(g, p) {
82067 if (p == current || !freeze_task(p))
82068 continue;
82069
82070- if (!freezer_should_skip(p))
82071+ if (!freezer_should_skip(p)) {
82072 todo++;
82073+ if (timedout) {
82074+ printk(KERN_ERR "Task refusing to freeze:\n");
82075+ sched_show_task(p);
82076+ }
82077+ }
82078 } while_each_thread(g, p);
82079 read_unlock(&tasklist_lock);
82080
82081@@ -59,7 +67,7 @@ static int try_to_freeze_tasks(bool user_only)
82082 todo += wq_busy;
82083 }
82084
82085- if (!todo || time_after(jiffies, end_time))
82086+ if (!todo || timedout)
82087 break;
82088
82089 if (pm_wakeup_pending()) {
82090diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
82091index 5b5a708..ec7637e 100644
82092--- a/kernel/printk/printk.c
82093+++ b/kernel/printk/printk.c
82094@@ -385,6 +385,11 @@ static int check_syslog_permissions(int type, bool from_file)
82095 if (from_file && type != SYSLOG_ACTION_OPEN)
82096 return 0;
82097
82098+#ifdef CONFIG_GRKERNSEC_DMESG
82099+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
82100+ return -EPERM;
82101+#endif
82102+
82103 if (syslog_action_restricted(type)) {
82104 if (capable(CAP_SYSLOG))
82105 return 0;
82106diff --git a/kernel/profile.c b/kernel/profile.c
82107index 6631e1e..310c266 100644
82108--- a/kernel/profile.c
82109+++ b/kernel/profile.c
82110@@ -37,7 +37,7 @@ struct profile_hit {
82111 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
82112 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
82113
82114-static atomic_t *prof_buffer;
82115+static atomic_unchecked_t *prof_buffer;
82116 static unsigned long prof_len, prof_shift;
82117
82118 int prof_on __read_mostly;
82119@@ -260,7 +260,7 @@ static void profile_flip_buffers(void)
82120 hits[i].pc = 0;
82121 continue;
82122 }
82123- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
82124+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
82125 hits[i].hits = hits[i].pc = 0;
82126 }
82127 }
82128@@ -321,9 +321,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
82129 * Add the current hit(s) and flush the write-queue out
82130 * to the global buffer:
82131 */
82132- atomic_add(nr_hits, &prof_buffer[pc]);
82133+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
82134 for (i = 0; i < NR_PROFILE_HIT; ++i) {
82135- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
82136+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
82137 hits[i].pc = hits[i].hits = 0;
82138 }
82139 out:
82140@@ -398,7 +398,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
82141 {
82142 unsigned long pc;
82143 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
82144- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
82145+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
82146 }
82147 #endif /* !CONFIG_SMP */
82148
82149@@ -494,7 +494,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
82150 return -EFAULT;
82151 buf++; p++; count--; read++;
82152 }
82153- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
82154+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
82155 if (copy_to_user(buf, (void *)pnt, count))
82156 return -EFAULT;
82157 read += count;
82158@@ -525,7 +525,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
82159 }
82160 #endif
82161 profile_discard_flip_buffers();
82162- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
82163+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
82164 return count;
82165 }
82166
82167diff --git a/kernel/ptrace.c b/kernel/ptrace.c
82168index a146ee3..ffed4c3 100644
82169--- a/kernel/ptrace.c
82170+++ b/kernel/ptrace.c
82171@@ -326,7 +326,7 @@ static int ptrace_attach(struct task_struct *task, long request,
82172 if (seize)
82173 flags |= PT_SEIZED;
82174 rcu_read_lock();
82175- if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
82176+ if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
82177 flags |= PT_PTRACE_CAP;
82178 rcu_read_unlock();
82179 task->ptrace = flags;
82180@@ -537,7 +537,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
82181 break;
82182 return -EIO;
82183 }
82184- if (copy_to_user(dst, buf, retval))
82185+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
82186 return -EFAULT;
82187 copied += retval;
82188 src += retval;
82189@@ -805,7 +805,7 @@ int ptrace_request(struct task_struct *child, long request,
82190 bool seized = child->ptrace & PT_SEIZED;
82191 int ret = -EIO;
82192 siginfo_t siginfo, *si;
82193- void __user *datavp = (void __user *) data;
82194+ void __user *datavp = (__force void __user *) data;
82195 unsigned long __user *datalp = datavp;
82196 unsigned long flags;
82197
82198@@ -1051,14 +1051,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
82199 goto out;
82200 }
82201
82202+ if (gr_handle_ptrace(child, request)) {
82203+ ret = -EPERM;
82204+ goto out_put_task_struct;
82205+ }
82206+
82207 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
82208 ret = ptrace_attach(child, request, addr, data);
82209 /*
82210 * Some architectures need to do book-keeping after
82211 * a ptrace attach.
82212 */
82213- if (!ret)
82214+ if (!ret) {
82215 arch_ptrace_attach(child);
82216+ gr_audit_ptrace(child);
82217+ }
82218 goto out_put_task_struct;
82219 }
82220
82221@@ -1086,7 +1093,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
82222 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
82223 if (copied != sizeof(tmp))
82224 return -EIO;
82225- return put_user(tmp, (unsigned long __user *)data);
82226+ return put_user(tmp, (__force unsigned long __user *)data);
82227 }
82228
82229 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
82230@@ -1180,7 +1187,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
82231 }
82232
82233 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
82234- compat_long_t addr, compat_long_t data)
82235+ compat_ulong_t addr, compat_ulong_t data)
82236 {
82237 struct task_struct *child;
82238 long ret;
82239@@ -1196,14 +1203,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
82240 goto out;
82241 }
82242
82243+ if (gr_handle_ptrace(child, request)) {
82244+ ret = -EPERM;
82245+ goto out_put_task_struct;
82246+ }
82247+
82248 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
82249 ret = ptrace_attach(child, request, addr, data);
82250 /*
82251 * Some architectures need to do book-keeping after
82252 * a ptrace attach.
82253 */
82254- if (!ret)
82255+ if (!ret) {
82256 arch_ptrace_attach(child);
82257+ gr_audit_ptrace(child);
82258+ }
82259 goto out_put_task_struct;
82260 }
82261
82262diff --git a/kernel/rcupdate.c b/kernel/rcupdate.c
82263index cce6ba8..7c758b1f 100644
82264--- a/kernel/rcupdate.c
82265+++ b/kernel/rcupdate.c
82266@@ -412,10 +412,10 @@ int rcu_jiffies_till_stall_check(void)
82267 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
82268 */
82269 if (till_stall_check < 3) {
82270- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
82271+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
82272 till_stall_check = 3;
82273 } else if (till_stall_check > 300) {
82274- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
82275+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
82276 till_stall_check = 300;
82277 }
82278 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
82279diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
82280index aa34411..4832cd4 100644
82281--- a/kernel/rcutiny.c
82282+++ b/kernel/rcutiny.c
82283@@ -45,7 +45,7 @@
82284 /* Forward declarations for rcutiny_plugin.h. */
82285 struct rcu_ctrlblk;
82286 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
82287-static void rcu_process_callbacks(struct softirq_action *unused);
82288+static void rcu_process_callbacks(void);
82289 static void __call_rcu(struct rcu_head *head,
82290 void (*func)(struct rcu_head *rcu),
82291 struct rcu_ctrlblk *rcp);
82292@@ -309,7 +309,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
82293 false));
82294 }
82295
82296-static void rcu_process_callbacks(struct softirq_action *unused)
82297+static __latent_entropy void rcu_process_callbacks(void)
82298 {
82299 __rcu_process_callbacks(&rcu_sched_ctrlblk);
82300 __rcu_process_callbacks(&rcu_bh_ctrlblk);
82301diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
82302index f4871e5..8ef5741 100644
82303--- a/kernel/rcutorture.c
82304+++ b/kernel/rcutorture.c
82305@@ -164,12 +164,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
82306 { 0 };
82307 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
82308 { 0 };
82309-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
82310-static atomic_t n_rcu_torture_alloc;
82311-static atomic_t n_rcu_torture_alloc_fail;
82312-static atomic_t n_rcu_torture_free;
82313-static atomic_t n_rcu_torture_mberror;
82314-static atomic_t n_rcu_torture_error;
82315+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
82316+static atomic_unchecked_t n_rcu_torture_alloc;
82317+static atomic_unchecked_t n_rcu_torture_alloc_fail;
82318+static atomic_unchecked_t n_rcu_torture_free;
82319+static atomic_unchecked_t n_rcu_torture_mberror;
82320+static atomic_unchecked_t n_rcu_torture_error;
82321 static long n_rcu_torture_barrier_error;
82322 static long n_rcu_torture_boost_ktrerror;
82323 static long n_rcu_torture_boost_rterror;
82324@@ -287,11 +287,11 @@ rcu_torture_alloc(void)
82325
82326 spin_lock_bh(&rcu_torture_lock);
82327 if (list_empty(&rcu_torture_freelist)) {
82328- atomic_inc(&n_rcu_torture_alloc_fail);
82329+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
82330 spin_unlock_bh(&rcu_torture_lock);
82331 return NULL;
82332 }
82333- atomic_inc(&n_rcu_torture_alloc);
82334+ atomic_inc_unchecked(&n_rcu_torture_alloc);
82335 p = rcu_torture_freelist.next;
82336 list_del_init(p);
82337 spin_unlock_bh(&rcu_torture_lock);
82338@@ -304,7 +304,7 @@ rcu_torture_alloc(void)
82339 static void
82340 rcu_torture_free(struct rcu_torture *p)
82341 {
82342- atomic_inc(&n_rcu_torture_free);
82343+ atomic_inc_unchecked(&n_rcu_torture_free);
82344 spin_lock_bh(&rcu_torture_lock);
82345 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
82346 spin_unlock_bh(&rcu_torture_lock);
82347@@ -424,7 +424,7 @@ rcu_torture_cb(struct rcu_head *p)
82348 i = rp->rtort_pipe_count;
82349 if (i > RCU_TORTURE_PIPE_LEN)
82350 i = RCU_TORTURE_PIPE_LEN;
82351- atomic_inc(&rcu_torture_wcount[i]);
82352+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
82353 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
82354 rp->rtort_mbtest = 0;
82355 rcu_torture_free(rp);
82356@@ -472,7 +472,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
82357 i = rp->rtort_pipe_count;
82358 if (i > RCU_TORTURE_PIPE_LEN)
82359 i = RCU_TORTURE_PIPE_LEN;
82360- atomic_inc(&rcu_torture_wcount[i]);
82361+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
82362 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
82363 rp->rtort_mbtest = 0;
82364 list_del(&rp->rtort_free);
82365@@ -952,7 +952,7 @@ rcu_torture_writer(void *arg)
82366 i = old_rp->rtort_pipe_count;
82367 if (i > RCU_TORTURE_PIPE_LEN)
82368 i = RCU_TORTURE_PIPE_LEN;
82369- atomic_inc(&rcu_torture_wcount[i]);
82370+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
82371 old_rp->rtort_pipe_count++;
82372 cur_ops->deferred_free(old_rp);
82373 }
82374@@ -1038,7 +1038,7 @@ static void rcu_torture_timer(unsigned long unused)
82375 return;
82376 }
82377 if (p->rtort_mbtest == 0)
82378- atomic_inc(&n_rcu_torture_mberror);
82379+ atomic_inc_unchecked(&n_rcu_torture_mberror);
82380 spin_lock(&rand_lock);
82381 cur_ops->read_delay(&rand);
82382 n_rcu_torture_timers++;
82383@@ -1108,7 +1108,7 @@ rcu_torture_reader(void *arg)
82384 continue;
82385 }
82386 if (p->rtort_mbtest == 0)
82387- atomic_inc(&n_rcu_torture_mberror);
82388+ atomic_inc_unchecked(&n_rcu_torture_mberror);
82389 cur_ops->read_delay(&rand);
82390 preempt_disable();
82391 pipe_count = p->rtort_pipe_count;
82392@@ -1171,11 +1171,11 @@ rcu_torture_printk(char *page)
82393 rcu_torture_current,
82394 rcu_torture_current_version,
82395 list_empty(&rcu_torture_freelist),
82396- atomic_read(&n_rcu_torture_alloc),
82397- atomic_read(&n_rcu_torture_alloc_fail),
82398- atomic_read(&n_rcu_torture_free));
82399+ atomic_read_unchecked(&n_rcu_torture_alloc),
82400+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
82401+ atomic_read_unchecked(&n_rcu_torture_free));
82402 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
82403- atomic_read(&n_rcu_torture_mberror),
82404+ atomic_read_unchecked(&n_rcu_torture_mberror),
82405 n_rcu_torture_boost_ktrerror,
82406 n_rcu_torture_boost_rterror);
82407 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
82408@@ -1194,14 +1194,14 @@ rcu_torture_printk(char *page)
82409 n_barrier_attempts,
82410 n_rcu_torture_barrier_error);
82411 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
82412- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
82413+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
82414 n_rcu_torture_barrier_error != 0 ||
82415 n_rcu_torture_boost_ktrerror != 0 ||
82416 n_rcu_torture_boost_rterror != 0 ||
82417 n_rcu_torture_boost_failure != 0 ||
82418 i > 1) {
82419 cnt += sprintf(&page[cnt], "!!! ");
82420- atomic_inc(&n_rcu_torture_error);
82421+ atomic_inc_unchecked(&n_rcu_torture_error);
82422 WARN_ON_ONCE(1);
82423 }
82424 cnt += sprintf(&page[cnt], "Reader Pipe: ");
82425@@ -1215,7 +1215,7 @@ rcu_torture_printk(char *page)
82426 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
82427 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
82428 cnt += sprintf(&page[cnt], " %d",
82429- atomic_read(&rcu_torture_wcount[i]));
82430+ atomic_read_unchecked(&rcu_torture_wcount[i]));
82431 }
82432 cnt += sprintf(&page[cnt], "\n");
82433 if (cur_ops->stats)
82434@@ -1924,7 +1924,7 @@ rcu_torture_cleanup(void)
82435
82436 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
82437
82438- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
82439+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
82440 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
82441 else if (n_online_successes != n_online_attempts ||
82442 n_offline_successes != n_offline_attempts)
82443@@ -1992,18 +1992,18 @@ rcu_torture_init(void)
82444
82445 rcu_torture_current = NULL;
82446 rcu_torture_current_version = 0;
82447- atomic_set(&n_rcu_torture_alloc, 0);
82448- atomic_set(&n_rcu_torture_alloc_fail, 0);
82449- atomic_set(&n_rcu_torture_free, 0);
82450- atomic_set(&n_rcu_torture_mberror, 0);
82451- atomic_set(&n_rcu_torture_error, 0);
82452+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
82453+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
82454+ atomic_set_unchecked(&n_rcu_torture_free, 0);
82455+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
82456+ atomic_set_unchecked(&n_rcu_torture_error, 0);
82457 n_rcu_torture_barrier_error = 0;
82458 n_rcu_torture_boost_ktrerror = 0;
82459 n_rcu_torture_boost_rterror = 0;
82460 n_rcu_torture_boost_failure = 0;
82461 n_rcu_torture_boosts = 0;
82462 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
82463- atomic_set(&rcu_torture_wcount[i], 0);
82464+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
82465 for_each_possible_cpu(cpu) {
82466 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
82467 per_cpu(rcu_torture_count, cpu)[i] = 0;
82468diff --git a/kernel/rcutree.c b/kernel/rcutree.c
82469index 068de3a..5e7db2f 100644
82470--- a/kernel/rcutree.c
82471+++ b/kernel/rcutree.c
82472@@ -358,9 +358,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
82473 rcu_prepare_for_idle(smp_processor_id());
82474 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
82475 smp_mb__before_atomic_inc(); /* See above. */
82476- atomic_inc(&rdtp->dynticks);
82477+ atomic_inc_unchecked(&rdtp->dynticks);
82478 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
82479- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
82480+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
82481
82482 /*
82483 * It is illegal to enter an extended quiescent state while
82484@@ -496,10 +496,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
82485 int user)
82486 {
82487 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
82488- atomic_inc(&rdtp->dynticks);
82489+ atomic_inc_unchecked(&rdtp->dynticks);
82490 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
82491 smp_mb__after_atomic_inc(); /* See above. */
82492- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
82493+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
82494 rcu_cleanup_after_idle(smp_processor_id());
82495 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
82496 if (!user && !is_idle_task(current)) {
82497@@ -638,14 +638,14 @@ void rcu_nmi_enter(void)
82498 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
82499
82500 if (rdtp->dynticks_nmi_nesting == 0 &&
82501- (atomic_read(&rdtp->dynticks) & 0x1))
82502+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
82503 return;
82504 rdtp->dynticks_nmi_nesting++;
82505 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
82506- atomic_inc(&rdtp->dynticks);
82507+ atomic_inc_unchecked(&rdtp->dynticks);
82508 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
82509 smp_mb__after_atomic_inc(); /* See above. */
82510- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
82511+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
82512 }
82513
82514 /**
82515@@ -664,9 +664,9 @@ void rcu_nmi_exit(void)
82516 return;
82517 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
82518 smp_mb__before_atomic_inc(); /* See above. */
82519- atomic_inc(&rdtp->dynticks);
82520+ atomic_inc_unchecked(&rdtp->dynticks);
82521 smp_mb__after_atomic_inc(); /* Force delay to next write. */
82522- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
82523+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
82524 }
82525
82526 /**
82527@@ -680,7 +680,7 @@ int rcu_is_cpu_idle(void)
82528 int ret;
82529
82530 preempt_disable();
82531- ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
82532+ ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
82533 preempt_enable();
82534 return ret;
82535 }
82536@@ -748,7 +748,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
82537 */
82538 static int dyntick_save_progress_counter(struct rcu_data *rdp)
82539 {
82540- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
82541+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
82542 return (rdp->dynticks_snap & 0x1) == 0;
82543 }
82544
82545@@ -763,7 +763,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
82546 unsigned int curr;
82547 unsigned int snap;
82548
82549- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
82550+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
82551 snap = (unsigned int)rdp->dynticks_snap;
82552
82553 /*
82554@@ -1351,9 +1351,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
82555 rdp = this_cpu_ptr(rsp->rda);
82556 rcu_preempt_check_blocked_tasks(rnp);
82557 rnp->qsmask = rnp->qsmaskinit;
82558- ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
82559+ ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
82560 WARN_ON_ONCE(rnp->completed != rsp->completed);
82561- ACCESS_ONCE(rnp->completed) = rsp->completed;
82562+ ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
82563 if (rnp == rdp->mynode)
82564 __note_gp_changes(rsp, rnp, rdp);
82565 rcu_preempt_boost_start_gp(rnp);
82566@@ -1435,7 +1435,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
82567 */
82568 rcu_for_each_node_breadth_first(rsp, rnp) {
82569 raw_spin_lock_irq(&rnp->lock);
82570- ACCESS_ONCE(rnp->completed) = rsp->gpnum;
82571+ ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
82572 rdp = this_cpu_ptr(rsp->rda);
82573 if (rnp == rdp->mynode)
82574 __note_gp_changes(rsp, rnp, rdp);
82575@@ -1765,7 +1765,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
82576 rsp->qlen += rdp->qlen;
82577 rdp->n_cbs_orphaned += rdp->qlen;
82578 rdp->qlen_lazy = 0;
82579- ACCESS_ONCE(rdp->qlen) = 0;
82580+ ACCESS_ONCE_RW(rdp->qlen) = 0;
82581 }
82582
82583 /*
82584@@ -2011,7 +2011,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
82585 }
82586 smp_mb(); /* List handling before counting for rcu_barrier(). */
82587 rdp->qlen_lazy -= count_lazy;
82588- ACCESS_ONCE(rdp->qlen) -= count;
82589+ ACCESS_ONCE_RW(rdp->qlen) -= count;
82590 rdp->n_cbs_invoked += count;
82591
82592 /* Reinstate batch limit if we have worked down the excess. */
82593@@ -2202,7 +2202,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
82594 /*
82595 * Do RCU core processing for the current CPU.
82596 */
82597-static void rcu_process_callbacks(struct softirq_action *unused)
82598+static __latent_entropy void rcu_process_callbacks(void)
82599 {
82600 struct rcu_state *rsp;
82601
82602@@ -2325,7 +2325,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
82603 local_irq_restore(flags);
82604 return;
82605 }
82606- ACCESS_ONCE(rdp->qlen)++;
82607+ ACCESS_ONCE_RW(rdp->qlen)++;
82608 if (lazy)
82609 rdp->qlen_lazy++;
82610 else
82611@@ -2534,11 +2534,11 @@ void synchronize_sched_expedited(void)
82612 * counter wrap on a 32-bit system. Quite a few more CPUs would of
82613 * course be required on a 64-bit system.
82614 */
82615- if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
82616+ if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
82617 (ulong)atomic_long_read(&rsp->expedited_done) +
82618 ULONG_MAX / 8)) {
82619 synchronize_sched();
82620- atomic_long_inc(&rsp->expedited_wrap);
82621+ atomic_long_inc_unchecked(&rsp->expedited_wrap);
82622 return;
82623 }
82624
82625@@ -2546,7 +2546,7 @@ void synchronize_sched_expedited(void)
82626 * Take a ticket. Note that atomic_inc_return() implies a
82627 * full memory barrier.
82628 */
82629- snap = atomic_long_inc_return(&rsp->expedited_start);
82630+ snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
82631 firstsnap = snap;
82632 get_online_cpus();
82633 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
82634@@ -2559,14 +2559,14 @@ void synchronize_sched_expedited(void)
82635 synchronize_sched_expedited_cpu_stop,
82636 NULL) == -EAGAIN) {
82637 put_online_cpus();
82638- atomic_long_inc(&rsp->expedited_tryfail);
82639+ atomic_long_inc_unchecked(&rsp->expedited_tryfail);
82640
82641 /* Check to see if someone else did our work for us. */
82642 s = atomic_long_read(&rsp->expedited_done);
82643 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
82644 /* ensure test happens before caller kfree */
82645 smp_mb__before_atomic_inc(); /* ^^^ */
82646- atomic_long_inc(&rsp->expedited_workdone1);
82647+ atomic_long_inc_unchecked(&rsp->expedited_workdone1);
82648 return;
82649 }
82650
82651@@ -2575,7 +2575,7 @@ void synchronize_sched_expedited(void)
82652 udelay(trycount * num_online_cpus());
82653 } else {
82654 wait_rcu_gp(call_rcu_sched);
82655- atomic_long_inc(&rsp->expedited_normal);
82656+ atomic_long_inc_unchecked(&rsp->expedited_normal);
82657 return;
82658 }
82659
82660@@ -2584,7 +2584,7 @@ void synchronize_sched_expedited(void)
82661 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
82662 /* ensure test happens before caller kfree */
82663 smp_mb__before_atomic_inc(); /* ^^^ */
82664- atomic_long_inc(&rsp->expedited_workdone2);
82665+ atomic_long_inc_unchecked(&rsp->expedited_workdone2);
82666 return;
82667 }
82668
82669@@ -2596,10 +2596,10 @@ void synchronize_sched_expedited(void)
82670 * period works for us.
82671 */
82672 get_online_cpus();
82673- snap = atomic_long_read(&rsp->expedited_start);
82674+ snap = atomic_long_read_unchecked(&rsp->expedited_start);
82675 smp_mb(); /* ensure read is before try_stop_cpus(). */
82676 }
82677- atomic_long_inc(&rsp->expedited_stoppedcpus);
82678+ atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
82679
82680 /*
82681 * Everyone up to our most recent fetch is covered by our grace
82682@@ -2608,16 +2608,16 @@ void synchronize_sched_expedited(void)
82683 * than we did already did their update.
82684 */
82685 do {
82686- atomic_long_inc(&rsp->expedited_done_tries);
82687+ atomic_long_inc_unchecked(&rsp->expedited_done_tries);
82688 s = atomic_long_read(&rsp->expedited_done);
82689 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
82690 /* ensure test happens before caller kfree */
82691 smp_mb__before_atomic_inc(); /* ^^^ */
82692- atomic_long_inc(&rsp->expedited_done_lost);
82693+ atomic_long_inc_unchecked(&rsp->expedited_done_lost);
82694 break;
82695 }
82696 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
82697- atomic_long_inc(&rsp->expedited_done_exit);
82698+ atomic_long_inc_unchecked(&rsp->expedited_done_exit);
82699
82700 put_online_cpus();
82701 }
82702@@ -2799,7 +2799,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
82703 * ACCESS_ONCE() to prevent the compiler from speculating
82704 * the increment to precede the early-exit check.
82705 */
82706- ACCESS_ONCE(rsp->n_barrier_done)++;
82707+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
82708 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
82709 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
82710 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
82711@@ -2849,7 +2849,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
82712
82713 /* Increment ->n_barrier_done to prevent duplicate work. */
82714 smp_mb(); /* Keep increment after above mechanism. */
82715- ACCESS_ONCE(rsp->n_barrier_done)++;
82716+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
82717 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
82718 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
82719 smp_mb(); /* Keep increment before caller's subsequent code. */
82720@@ -2894,10 +2894,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
82721 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
82722 init_callback_list(rdp);
82723 rdp->qlen_lazy = 0;
82724- ACCESS_ONCE(rdp->qlen) = 0;
82725+ ACCESS_ONCE_RW(rdp->qlen) = 0;
82726 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
82727 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
82728- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
82729+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
82730 rdp->cpu = cpu;
82731 rdp->rsp = rsp;
82732 rcu_boot_init_nocb_percpu_data(rdp);
82733@@ -2930,8 +2930,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
82734 rdp->blimit = blimit;
82735 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
82736 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
82737- atomic_set(&rdp->dynticks->dynticks,
82738- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
82739+ atomic_set_unchecked(&rdp->dynticks->dynticks,
82740+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
82741 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
82742
82743 /* Add CPU to rcu_node bitmasks. */
82744diff --git a/kernel/rcutree.h b/kernel/rcutree.h
82745index b383258..2440c1e 100644
82746--- a/kernel/rcutree.h
82747+++ b/kernel/rcutree.h
82748@@ -87,7 +87,7 @@ struct rcu_dynticks {
82749 long long dynticks_nesting; /* Track irq/process nesting level. */
82750 /* Process level is worth LLONG_MAX/2. */
82751 int dynticks_nmi_nesting; /* Track NMI nesting level. */
82752- atomic_t dynticks; /* Even value for idle, else odd. */
82753+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
82754 #ifdef CONFIG_RCU_FAST_NO_HZ
82755 bool all_lazy; /* Are all CPU's CBs lazy? */
82756 unsigned long nonlazy_posted;
82757@@ -419,17 +419,17 @@ struct rcu_state {
82758 /* _rcu_barrier(). */
82759 /* End of fields guarded by barrier_mutex. */
82760
82761- atomic_long_t expedited_start; /* Starting ticket. */
82762- atomic_long_t expedited_done; /* Done ticket. */
82763- atomic_long_t expedited_wrap; /* # near-wrap incidents. */
82764- atomic_long_t expedited_tryfail; /* # acquisition failures. */
82765- atomic_long_t expedited_workdone1; /* # done by others #1. */
82766- atomic_long_t expedited_workdone2; /* # done by others #2. */
82767- atomic_long_t expedited_normal; /* # fallbacks to normal. */
82768- atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
82769- atomic_long_t expedited_done_tries; /* # tries to update _done. */
82770- atomic_long_t expedited_done_lost; /* # times beaten to _done. */
82771- atomic_long_t expedited_done_exit; /* # times exited _done loop. */
82772+ atomic_long_unchecked_t expedited_start; /* Starting ticket. */
82773+ atomic_long_t expedited_done; /* Done ticket. */
82774+ atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
82775+ atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
82776+ atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
82777+ atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
82778+ atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
82779+ atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
82780+ atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
82781+ atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
82782+ atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
82783
82784 unsigned long jiffies_force_qs; /* Time at which to invoke */
82785 /* force_quiescent_state(). */
82786diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
82787index 769e12e..7b2139b 100644
82788--- a/kernel/rcutree_plugin.h
82789+++ b/kernel/rcutree_plugin.h
82790@@ -902,7 +902,7 @@ void synchronize_rcu_expedited(void)
82791
82792 /* Clean up and exit. */
82793 smp_mb(); /* ensure expedited GP seen before counter increment. */
82794- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
82795+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
82796 unlock_mb_ret:
82797 mutex_unlock(&sync_rcu_preempt_exp_mutex);
82798 mb_ret:
82799@@ -1476,7 +1476,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
82800 free_cpumask_var(cm);
82801 }
82802
82803-static struct smp_hotplug_thread rcu_cpu_thread_spec = {
82804+static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
82805 .store = &rcu_cpu_kthread_task,
82806 .thread_should_run = rcu_cpu_kthread_should_run,
82807 .thread_fn = rcu_cpu_kthread,
82808@@ -1941,7 +1941,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
82809 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
82810 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
82811 cpu, ticks_value, ticks_title,
82812- atomic_read(&rdtp->dynticks) & 0xfff,
82813+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
82814 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
82815 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
82816 fast_no_hz);
82817@@ -2104,7 +2104,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
82818
82819 /* Enqueue the callback on the nocb list and update counts. */
82820 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
82821- ACCESS_ONCE(*old_rhpp) = rhp;
82822+ ACCESS_ONCE_RW(*old_rhpp) = rhp;
82823 atomic_long_add(rhcount, &rdp->nocb_q_count);
82824 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
82825
82826@@ -2244,12 +2244,12 @@ static int rcu_nocb_kthread(void *arg)
82827 * Extract queued callbacks, update counts, and wait
82828 * for a grace period to elapse.
82829 */
82830- ACCESS_ONCE(rdp->nocb_head) = NULL;
82831+ ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
82832 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
82833 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
82834 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
82835- ACCESS_ONCE(rdp->nocb_p_count) += c;
82836- ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
82837+ ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
82838+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
82839 rcu_nocb_wait_gp(rdp);
82840
82841 /* Each pass through the following loop invokes a callback. */
82842@@ -2271,8 +2271,8 @@ static int rcu_nocb_kthread(void *arg)
82843 list = next;
82844 }
82845 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
82846- ACCESS_ONCE(rdp->nocb_p_count) -= c;
82847- ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
82848+ ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
82849+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
82850 rdp->n_nocbs_invoked += c;
82851 }
82852 return 0;
82853@@ -2299,7 +2299,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
82854 t = kthread_run(rcu_nocb_kthread, rdp,
82855 "rcuo%c/%d", rsp->abbr, cpu);
82856 BUG_ON(IS_ERR(t));
82857- ACCESS_ONCE(rdp->nocb_kthread) = t;
82858+ ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
82859 }
82860 }
82861
82862diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
82863index cf6c174..a8f4b50 100644
82864--- a/kernel/rcutree_trace.c
82865+++ b/kernel/rcutree_trace.c
82866@@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
82867 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
82868 rdp->passed_quiesce, rdp->qs_pending);
82869 seq_printf(m, " dt=%d/%llx/%d df=%lu",
82870- atomic_read(&rdp->dynticks->dynticks),
82871+ atomic_read_unchecked(&rdp->dynticks->dynticks),
82872 rdp->dynticks->dynticks_nesting,
82873 rdp->dynticks->dynticks_nmi_nesting,
82874 rdp->dynticks_fqs);
82875@@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
82876 struct rcu_state *rsp = (struct rcu_state *)m->private;
82877
82878 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",
82879- atomic_long_read(&rsp->expedited_start),
82880+ atomic_long_read_unchecked(&rsp->expedited_start),
82881 atomic_long_read(&rsp->expedited_done),
82882- atomic_long_read(&rsp->expedited_wrap),
82883- atomic_long_read(&rsp->expedited_tryfail),
82884- atomic_long_read(&rsp->expedited_workdone1),
82885- atomic_long_read(&rsp->expedited_workdone2),
82886- atomic_long_read(&rsp->expedited_normal),
82887- atomic_long_read(&rsp->expedited_stoppedcpus),
82888- atomic_long_read(&rsp->expedited_done_tries),
82889- atomic_long_read(&rsp->expedited_done_lost),
82890- atomic_long_read(&rsp->expedited_done_exit));
82891+ atomic_long_read_unchecked(&rsp->expedited_wrap),
82892+ atomic_long_read_unchecked(&rsp->expedited_tryfail),
82893+ atomic_long_read_unchecked(&rsp->expedited_workdone1),
82894+ atomic_long_read_unchecked(&rsp->expedited_workdone2),
82895+ atomic_long_read_unchecked(&rsp->expedited_normal),
82896+ atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
82897+ atomic_long_read_unchecked(&rsp->expedited_done_tries),
82898+ atomic_long_read_unchecked(&rsp->expedited_done_lost),
82899+ atomic_long_read_unchecked(&rsp->expedited_done_exit));
82900 return 0;
82901 }
82902
82903diff --git a/kernel/resource.c b/kernel/resource.c
82904index 3f285dc..5755f62 100644
82905--- a/kernel/resource.c
82906+++ b/kernel/resource.c
82907@@ -152,8 +152,18 @@ static const struct file_operations proc_iomem_operations = {
82908
82909 static int __init ioresources_init(void)
82910 {
82911+#ifdef CONFIG_GRKERNSEC_PROC_ADD
82912+#ifdef CONFIG_GRKERNSEC_PROC_USER
82913+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
82914+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
82915+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
82916+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
82917+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
82918+#endif
82919+#else
82920 proc_create("ioports", 0, NULL, &proc_ioports_operations);
82921 proc_create("iomem", 0, NULL, &proc_iomem_operations);
82922+#endif
82923 return 0;
82924 }
82925 __initcall(ioresources_init);
82926diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
82927index 1d96dd0..994ff19 100644
82928--- a/kernel/rtmutex-tester.c
82929+++ b/kernel/rtmutex-tester.c
82930@@ -22,7 +22,7 @@
82931 #define MAX_RT_TEST_MUTEXES 8
82932
82933 static spinlock_t rttest_lock;
82934-static atomic_t rttest_event;
82935+static atomic_unchecked_t rttest_event;
82936
82937 struct test_thread_data {
82938 int opcode;
82939@@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
82940
82941 case RTTEST_LOCKCONT:
82942 td->mutexes[td->opdata] = 1;
82943- td->event = atomic_add_return(1, &rttest_event);
82944+ td->event = atomic_add_return_unchecked(1, &rttest_event);
82945 return 0;
82946
82947 case RTTEST_RESET:
82948@@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
82949 return 0;
82950
82951 case RTTEST_RESETEVENT:
82952- atomic_set(&rttest_event, 0);
82953+ atomic_set_unchecked(&rttest_event, 0);
82954 return 0;
82955
82956 default:
82957@@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
82958 return ret;
82959
82960 td->mutexes[id] = 1;
82961- td->event = atomic_add_return(1, &rttest_event);
82962+ td->event = atomic_add_return_unchecked(1, &rttest_event);
82963 rt_mutex_lock(&mutexes[id]);
82964- td->event = atomic_add_return(1, &rttest_event);
82965+ td->event = atomic_add_return_unchecked(1, &rttest_event);
82966 td->mutexes[id] = 4;
82967 return 0;
82968
82969@@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
82970 return ret;
82971
82972 td->mutexes[id] = 1;
82973- td->event = atomic_add_return(1, &rttest_event);
82974+ td->event = atomic_add_return_unchecked(1, &rttest_event);
82975 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
82976- td->event = atomic_add_return(1, &rttest_event);
82977+ td->event = atomic_add_return_unchecked(1, &rttest_event);
82978 td->mutexes[id] = ret ? 0 : 4;
82979 return ret ? -EINTR : 0;
82980
82981@@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
82982 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
82983 return ret;
82984
82985- td->event = atomic_add_return(1, &rttest_event);
82986+ td->event = atomic_add_return_unchecked(1, &rttest_event);
82987 rt_mutex_unlock(&mutexes[id]);
82988- td->event = atomic_add_return(1, &rttest_event);
82989+ td->event = atomic_add_return_unchecked(1, &rttest_event);
82990 td->mutexes[id] = 0;
82991 return 0;
82992
82993@@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
82994 break;
82995
82996 td->mutexes[dat] = 2;
82997- td->event = atomic_add_return(1, &rttest_event);
82998+ td->event = atomic_add_return_unchecked(1, &rttest_event);
82999 break;
83000
83001 default:
83002@@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
83003 return;
83004
83005 td->mutexes[dat] = 3;
83006- td->event = atomic_add_return(1, &rttest_event);
83007+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83008 break;
83009
83010 case RTTEST_LOCKNOWAIT:
83011@@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
83012 return;
83013
83014 td->mutexes[dat] = 1;
83015- td->event = atomic_add_return(1, &rttest_event);
83016+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83017 return;
83018
83019 default:
83020diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
83021index 4a07353..66b5291 100644
83022--- a/kernel/sched/auto_group.c
83023+++ b/kernel/sched/auto_group.c
83024@@ -11,7 +11,7 @@
83025
83026 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
83027 static struct autogroup autogroup_default;
83028-static atomic_t autogroup_seq_nr;
83029+static atomic_unchecked_t autogroup_seq_nr;
83030
83031 void __init autogroup_init(struct task_struct *init_task)
83032 {
83033@@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
83034
83035 kref_init(&ag->kref);
83036 init_rwsem(&ag->lock);
83037- ag->id = atomic_inc_return(&autogroup_seq_nr);
83038+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
83039 ag->tg = tg;
83040 #ifdef CONFIG_RT_GROUP_SCHED
83041 /*
83042diff --git a/kernel/sched/core.c b/kernel/sched/core.c
83043index 05c39f0..442e6fe 100644
83044--- a/kernel/sched/core.c
83045+++ b/kernel/sched/core.c
83046@@ -2885,7 +2885,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
83047 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
83048 * or number of jiffies left till timeout) if completed.
83049 */
83050-long __sched
83051+long __sched __intentional_overflow(-1)
83052 wait_for_completion_interruptible_timeout(struct completion *x,
83053 unsigned long timeout)
83054 {
83055@@ -2902,7 +2902,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
83056 *
83057 * Return: -ERESTARTSYS if interrupted, 0 if completed.
83058 */
83059-int __sched wait_for_completion_killable(struct completion *x)
83060+int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
83061 {
83062 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
83063 if (t == -ERESTARTSYS)
83064@@ -2923,7 +2923,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
83065 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
83066 * or number of jiffies left till timeout) if completed.
83067 */
83068-long __sched
83069+long __sched __intentional_overflow(-1)
83070 wait_for_completion_killable_timeout(struct completion *x,
83071 unsigned long timeout)
83072 {
83073@@ -3149,6 +3149,8 @@ int can_nice(const struct task_struct *p, const int nice)
83074 /* convert nice value [19,-20] to rlimit style value [1,40] */
83075 int nice_rlim = 20 - nice;
83076
83077+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
83078+
83079 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
83080 capable(CAP_SYS_NICE));
83081 }
83082@@ -3182,7 +3184,8 @@ SYSCALL_DEFINE1(nice, int, increment)
83083 if (nice > 19)
83084 nice = 19;
83085
83086- if (increment < 0 && !can_nice(current, nice))
83087+ if (increment < 0 && (!can_nice(current, nice) ||
83088+ gr_handle_chroot_nice()))
83089 return -EPERM;
83090
83091 retval = security_task_setnice(current, nice);
83092@@ -3344,6 +3347,7 @@ recheck:
83093 unsigned long rlim_rtprio =
83094 task_rlimit(p, RLIMIT_RTPRIO);
83095
83096+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
83097 /* can't set/change the rt policy */
83098 if (policy != p->policy && !rlim_rtprio)
83099 return -EPERM;
83100@@ -4473,7 +4477,7 @@ static void migrate_tasks(unsigned int dead_cpu)
83101
83102 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
83103
83104-static struct ctl_table sd_ctl_dir[] = {
83105+static ctl_table_no_const sd_ctl_dir[] __read_only = {
83106 {
83107 .procname = "sched_domain",
83108 .mode = 0555,
83109@@ -4490,17 +4494,17 @@ static struct ctl_table sd_ctl_root[] = {
83110 {}
83111 };
83112
83113-static struct ctl_table *sd_alloc_ctl_entry(int n)
83114+static ctl_table_no_const *sd_alloc_ctl_entry(int n)
83115 {
83116- struct ctl_table *entry =
83117+ ctl_table_no_const *entry =
83118 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
83119
83120 return entry;
83121 }
83122
83123-static void sd_free_ctl_entry(struct ctl_table **tablep)
83124+static void sd_free_ctl_entry(ctl_table_no_const *tablep)
83125 {
83126- struct ctl_table *entry;
83127+ ctl_table_no_const *entry;
83128
83129 /*
83130 * In the intermediate directories, both the child directory and
83131@@ -4508,22 +4512,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
83132 * will always be set. In the lowest directory the names are
83133 * static strings and all have proc handlers.
83134 */
83135- for (entry = *tablep; entry->mode; entry++) {
83136- if (entry->child)
83137- sd_free_ctl_entry(&entry->child);
83138+ for (entry = tablep; entry->mode; entry++) {
83139+ if (entry->child) {
83140+ sd_free_ctl_entry(entry->child);
83141+ pax_open_kernel();
83142+ entry->child = NULL;
83143+ pax_close_kernel();
83144+ }
83145 if (entry->proc_handler == NULL)
83146 kfree(entry->procname);
83147 }
83148
83149- kfree(*tablep);
83150- *tablep = NULL;
83151+ kfree(tablep);
83152 }
83153
83154 static int min_load_idx = 0;
83155 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
83156
83157 static void
83158-set_table_entry(struct ctl_table *entry,
83159+set_table_entry(ctl_table_no_const *entry,
83160 const char *procname, void *data, int maxlen,
83161 umode_t mode, proc_handler *proc_handler,
83162 bool load_idx)
83163@@ -4543,7 +4550,7 @@ set_table_entry(struct ctl_table *entry,
83164 static struct ctl_table *
83165 sd_alloc_ctl_domain_table(struct sched_domain *sd)
83166 {
83167- struct ctl_table *table = sd_alloc_ctl_entry(13);
83168+ ctl_table_no_const *table = sd_alloc_ctl_entry(13);
83169
83170 if (table == NULL)
83171 return NULL;
83172@@ -4578,9 +4585,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
83173 return table;
83174 }
83175
83176-static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
83177+static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
83178 {
83179- struct ctl_table *entry, *table;
83180+ ctl_table_no_const *entry, *table;
83181 struct sched_domain *sd;
83182 int domain_num = 0, i;
83183 char buf[32];
83184@@ -4607,11 +4614,13 @@ static struct ctl_table_header *sd_sysctl_header;
83185 static void register_sched_domain_sysctl(void)
83186 {
83187 int i, cpu_num = num_possible_cpus();
83188- struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
83189+ ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
83190 char buf[32];
83191
83192 WARN_ON(sd_ctl_dir[0].child);
83193+ pax_open_kernel();
83194 sd_ctl_dir[0].child = entry;
83195+ pax_close_kernel();
83196
83197 if (entry == NULL)
83198 return;
83199@@ -4634,8 +4643,12 @@ static void unregister_sched_domain_sysctl(void)
83200 if (sd_sysctl_header)
83201 unregister_sysctl_table(sd_sysctl_header);
83202 sd_sysctl_header = NULL;
83203- if (sd_ctl_dir[0].child)
83204- sd_free_ctl_entry(&sd_ctl_dir[0].child);
83205+ if (sd_ctl_dir[0].child) {
83206+ sd_free_ctl_entry(sd_ctl_dir[0].child);
83207+ pax_open_kernel();
83208+ sd_ctl_dir[0].child = NULL;
83209+ pax_close_kernel();
83210+ }
83211 }
83212 #else
83213 static void register_sched_domain_sysctl(void)
83214diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
83215index 31cbc15..ba68c15 100644
83216--- a/kernel/sched/fair.c
83217+++ b/kernel/sched/fair.c
83218@@ -869,7 +869,7 @@ void task_numa_fault(int node, int pages, bool migrated)
83219
83220 static void reset_ptenuma_scan(struct task_struct *p)
83221 {
83222- ACCESS_ONCE(p->mm->numa_scan_seq)++;
83223+ ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
83224 p->mm->numa_scan_offset = 0;
83225 }
83226
83227@@ -5727,7 +5727,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
83228 * run_rebalance_domains is triggered when needed from the scheduler tick.
83229 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
83230 */
83231-static void run_rebalance_domains(struct softirq_action *h)
83232+static __latent_entropy void run_rebalance_domains(void)
83233 {
83234 int this_cpu = smp_processor_id();
83235 struct rq *this_rq = cpu_rq(this_cpu);
83236diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
83237index ef0a7b2..1b728c1 100644
83238--- a/kernel/sched/sched.h
83239+++ b/kernel/sched/sched.h
83240@@ -1004,7 +1004,7 @@ struct sched_class {
83241 #ifdef CONFIG_FAIR_GROUP_SCHED
83242 void (*task_move_group) (struct task_struct *p, int on_rq);
83243 #endif
83244-};
83245+} __do_const;
83246
83247 #define sched_class_highest (&stop_sched_class)
83248 #define for_each_class(class) \
83249diff --git a/kernel/signal.c b/kernel/signal.c
83250index 50e4107..9409983 100644
83251--- a/kernel/signal.c
83252+++ b/kernel/signal.c
83253@@ -51,12 +51,12 @@ static struct kmem_cache *sigqueue_cachep;
83254
83255 int print_fatal_signals __read_mostly;
83256
83257-static void __user *sig_handler(struct task_struct *t, int sig)
83258+static __sighandler_t sig_handler(struct task_struct *t, int sig)
83259 {
83260 return t->sighand->action[sig - 1].sa.sa_handler;
83261 }
83262
83263-static int sig_handler_ignored(void __user *handler, int sig)
83264+static int sig_handler_ignored(__sighandler_t handler, int sig)
83265 {
83266 /* Is it explicitly or implicitly ignored? */
83267 return handler == SIG_IGN ||
83268@@ -65,7 +65,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
83269
83270 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
83271 {
83272- void __user *handler;
83273+ __sighandler_t handler;
83274
83275 handler = sig_handler(t, sig);
83276
83277@@ -369,6 +369,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
83278 atomic_inc(&user->sigpending);
83279 rcu_read_unlock();
83280
83281+ if (!override_rlimit)
83282+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
83283+
83284 if (override_rlimit ||
83285 atomic_read(&user->sigpending) <=
83286 task_rlimit(t, RLIMIT_SIGPENDING)) {
83287@@ -496,7 +499,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
83288
83289 int unhandled_signal(struct task_struct *tsk, int sig)
83290 {
83291- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
83292+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
83293 if (is_global_init(tsk))
83294 return 1;
83295 if (handler != SIG_IGN && handler != SIG_DFL)
83296@@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
83297 }
83298 }
83299
83300+ /* allow glibc communication via tgkill to other threads in our
83301+ thread group */
83302+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
83303+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
83304+ && gr_handle_signal(t, sig))
83305+ return -EPERM;
83306+
83307 return security_task_kill(t, info, sig, 0);
83308 }
83309
83310@@ -1199,7 +1209,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
83311 return send_signal(sig, info, p, 1);
83312 }
83313
83314-static int
83315+int
83316 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
83317 {
83318 return send_signal(sig, info, t, 0);
83319@@ -1236,6 +1246,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
83320 unsigned long int flags;
83321 int ret, blocked, ignored;
83322 struct k_sigaction *action;
83323+ int is_unhandled = 0;
83324
83325 spin_lock_irqsave(&t->sighand->siglock, flags);
83326 action = &t->sighand->action[sig-1];
83327@@ -1250,9 +1261,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
83328 }
83329 if (action->sa.sa_handler == SIG_DFL)
83330 t->signal->flags &= ~SIGNAL_UNKILLABLE;
83331+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
83332+ is_unhandled = 1;
83333 ret = specific_send_sig_info(sig, info, t);
83334 spin_unlock_irqrestore(&t->sighand->siglock, flags);
83335
83336+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
83337+ normal operation */
83338+ if (is_unhandled) {
83339+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
83340+ gr_handle_crash(t, sig);
83341+ }
83342+
83343 return ret;
83344 }
83345
83346@@ -1319,8 +1339,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
83347 ret = check_kill_permission(sig, info, p);
83348 rcu_read_unlock();
83349
83350- if (!ret && sig)
83351+ if (!ret && sig) {
83352 ret = do_send_sig_info(sig, info, p, true);
83353+ if (!ret)
83354+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
83355+ }
83356
83357 return ret;
83358 }
83359@@ -2926,7 +2949,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
83360 int error = -ESRCH;
83361
83362 rcu_read_lock();
83363- p = find_task_by_vpid(pid);
83364+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
83365+ /* allow glibc communication via tgkill to other threads in our
83366+ thread group */
83367+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
83368+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
83369+ p = find_task_by_vpid_unrestricted(pid);
83370+ else
83371+#endif
83372+ p = find_task_by_vpid(pid);
83373 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
83374 error = check_kill_permission(sig, info, p);
83375 /*
83376@@ -3240,8 +3271,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
83377 }
83378 seg = get_fs();
83379 set_fs(KERNEL_DS);
83380- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
83381- (stack_t __force __user *) &uoss,
83382+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
83383+ (stack_t __force_user *) &uoss,
83384 compat_user_stack_pointer());
83385 set_fs(seg);
83386 if (ret >= 0 && uoss_ptr) {
83387diff --git a/kernel/smpboot.c b/kernel/smpboot.c
83388index eb89e18..a4e6792 100644
83389--- a/kernel/smpboot.c
83390+++ b/kernel/smpboot.c
83391@@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
83392 }
83393 smpboot_unpark_thread(plug_thread, cpu);
83394 }
83395- list_add(&plug_thread->list, &hotplug_threads);
83396+ pax_list_add(&plug_thread->list, &hotplug_threads);
83397 out:
83398 mutex_unlock(&smpboot_threads_lock);
83399 return ret;
83400@@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
83401 {
83402 get_online_cpus();
83403 mutex_lock(&smpboot_threads_lock);
83404- list_del(&plug_thread->list);
83405+ pax_list_del(&plug_thread->list);
83406 smpboot_destroy_threads(plug_thread);
83407 mutex_unlock(&smpboot_threads_lock);
83408 put_online_cpus();
83409diff --git a/kernel/softirq.c b/kernel/softirq.c
83410index be3d351..e57af82 100644
83411--- a/kernel/softirq.c
83412+++ b/kernel/softirq.c
83413@@ -53,11 +53,11 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
83414 EXPORT_SYMBOL(irq_stat);
83415 #endif
83416
83417-static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
83418+static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
83419
83420 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
83421
83422-char *softirq_to_name[NR_SOFTIRQS] = {
83423+const char * const softirq_to_name[NR_SOFTIRQS] = {
83424 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
83425 "TASKLET", "SCHED", "HRTIMER", "RCU"
83426 };
83427@@ -248,7 +248,7 @@ restart:
83428 kstat_incr_softirqs_this_cpu(vec_nr);
83429
83430 trace_softirq_entry(vec_nr);
83431- h->action(h);
83432+ h->action();
83433 trace_softirq_exit(vec_nr);
83434 if (unlikely(prev_count != preempt_count())) {
83435 printk(KERN_ERR "huh, entered softirq %u %s %p"
83436@@ -403,7 +403,7 @@ void __raise_softirq_irqoff(unsigned int nr)
83437 or_softirq_pending(1UL << nr);
83438 }
83439
83440-void open_softirq(int nr, void (*action)(struct softirq_action *))
83441+void __init open_softirq(int nr, void (*action)(void))
83442 {
83443 softirq_vec[nr].action = action;
83444 }
83445@@ -459,7 +459,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
83446
83447 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
83448
83449-static void tasklet_action(struct softirq_action *a)
83450+static __latent_entropy void tasklet_action(void)
83451 {
83452 struct tasklet_struct *list;
83453
83454@@ -494,7 +494,7 @@ static void tasklet_action(struct softirq_action *a)
83455 }
83456 }
83457
83458-static void tasklet_hi_action(struct softirq_action *a)
83459+static __latent_entropy void tasklet_hi_action(void)
83460 {
83461 struct tasklet_struct *list;
83462
83463@@ -849,7 +849,7 @@ static struct notifier_block cpu_nfb = {
83464 .notifier_call = cpu_callback
83465 };
83466
83467-static struct smp_hotplug_thread softirq_threads = {
83468+static struct smp_hotplug_thread softirq_threads __read_only = {
83469 .store = &ksoftirqd,
83470 .thread_should_run = ksoftirqd_should_run,
83471 .thread_fn = run_ksoftirqd,
83472diff --git a/kernel/srcu.c b/kernel/srcu.c
83473index 01d5ccb..cdcbee6 100644
83474--- a/kernel/srcu.c
83475+++ b/kernel/srcu.c
83476@@ -300,9 +300,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
83477
83478 idx = ACCESS_ONCE(sp->completed) & 0x1;
83479 preempt_disable();
83480- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
83481+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
83482 smp_mb(); /* B */ /* Avoid leaking the critical section. */
83483- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
83484+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
83485 preempt_enable();
83486 return idx;
83487 }
83488diff --git a/kernel/sys.c b/kernel/sys.c
83489index 771129b..dc0c7e3 100644
83490--- a/kernel/sys.c
83491+++ b/kernel/sys.c
83492@@ -149,6 +149,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
83493 error = -EACCES;
83494 goto out;
83495 }
83496+
83497+ if (gr_handle_chroot_setpriority(p, niceval)) {
83498+ error = -EACCES;
83499+ goto out;
83500+ }
83501+
83502 no_nice = security_task_setnice(p, niceval);
83503 if (no_nice) {
83504 error = no_nice;
83505@@ -352,6 +358,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
83506 goto error;
83507 }
83508
83509+ if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
83510+ goto error;
83511+
83512 if (rgid != (gid_t) -1 ||
83513 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
83514 new->sgid = new->egid;
83515@@ -387,6 +396,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
83516 old = current_cred();
83517
83518 retval = -EPERM;
83519+
83520+ if (gr_check_group_change(kgid, kgid, kgid))
83521+ goto error;
83522+
83523 if (nsown_capable(CAP_SETGID))
83524 new->gid = new->egid = new->sgid = new->fsgid = kgid;
83525 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
83526@@ -404,7 +417,7 @@ error:
83527 /*
83528 * change the user struct in a credentials set to match the new UID
83529 */
83530-static int set_user(struct cred *new)
83531+int set_user(struct cred *new)
83532 {
83533 struct user_struct *new_user;
83534
83535@@ -484,6 +497,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
83536 goto error;
83537 }
83538
83539+ if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
83540+ goto error;
83541+
83542 if (!uid_eq(new->uid, old->uid)) {
83543 retval = set_user(new);
83544 if (retval < 0)
83545@@ -534,6 +550,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
83546 old = current_cred();
83547
83548 retval = -EPERM;
83549+
83550+ if (gr_check_crash_uid(kuid))
83551+ goto error;
83552+ if (gr_check_user_change(kuid, kuid, kuid))
83553+ goto error;
83554+
83555 if (nsown_capable(CAP_SETUID)) {
83556 new->suid = new->uid = kuid;
83557 if (!uid_eq(kuid, old->uid)) {
83558@@ -603,6 +625,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
83559 goto error;
83560 }
83561
83562+ if (gr_check_user_change(kruid, keuid, INVALID_UID))
83563+ goto error;
83564+
83565 if (ruid != (uid_t) -1) {
83566 new->uid = kruid;
83567 if (!uid_eq(kruid, old->uid)) {
83568@@ -685,6 +710,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
83569 goto error;
83570 }
83571
83572+ if (gr_check_group_change(krgid, kegid, INVALID_GID))
83573+ goto error;
83574+
83575 if (rgid != (gid_t) -1)
83576 new->gid = krgid;
83577 if (egid != (gid_t) -1)
83578@@ -746,12 +774,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
83579 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
83580 nsown_capable(CAP_SETUID)) {
83581 if (!uid_eq(kuid, old->fsuid)) {
83582+ if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
83583+ goto error;
83584+
83585 new->fsuid = kuid;
83586 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
83587 goto change_okay;
83588 }
83589 }
83590
83591+error:
83592 abort_creds(new);
83593 return old_fsuid;
83594
83595@@ -784,12 +816,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
83596 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
83597 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
83598 nsown_capable(CAP_SETGID)) {
83599+ if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
83600+ goto error;
83601+
83602 if (!gid_eq(kgid, old->fsgid)) {
83603 new->fsgid = kgid;
83604 goto change_okay;
83605 }
83606 }
83607
83608+error:
83609 abort_creds(new);
83610 return old_fsgid;
83611
83612@@ -1169,19 +1205,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
83613 return -EFAULT;
83614
83615 down_read(&uts_sem);
83616- error = __copy_to_user(&name->sysname, &utsname()->sysname,
83617+ error = __copy_to_user(name->sysname, &utsname()->sysname,
83618 __OLD_UTS_LEN);
83619 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
83620- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
83621+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
83622 __OLD_UTS_LEN);
83623 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
83624- error |= __copy_to_user(&name->release, &utsname()->release,
83625+ error |= __copy_to_user(name->release, &utsname()->release,
83626 __OLD_UTS_LEN);
83627 error |= __put_user(0, name->release + __OLD_UTS_LEN);
83628- error |= __copy_to_user(&name->version, &utsname()->version,
83629+ error |= __copy_to_user(name->version, &utsname()->version,
83630 __OLD_UTS_LEN);
83631 error |= __put_user(0, name->version + __OLD_UTS_LEN);
83632- error |= __copy_to_user(&name->machine, &utsname()->machine,
83633+ error |= __copy_to_user(name->machine, &utsname()->machine,
83634 __OLD_UTS_LEN);
83635 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
83636 up_read(&uts_sem);
83637@@ -1383,6 +1419,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
83638 */
83639 new_rlim->rlim_cur = 1;
83640 }
83641+ /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
83642+ is changed to a lower value. Since tasks can be created by the same
83643+ user in between this limit change and an execve by this task, force
83644+ a recheck only for this task by setting PF_NPROC_EXCEEDED
83645+ */
83646+ if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
83647+ tsk->flags |= PF_NPROC_EXCEEDED;
83648 }
83649 if (!retval) {
83650 if (old_rlim)
83651diff --git a/kernel/sysctl.c b/kernel/sysctl.c
83652index 07f6fc4..65fb3d4 100644
83653--- a/kernel/sysctl.c
83654+++ b/kernel/sysctl.c
83655@@ -93,7 +93,6 @@
83656
83657
83658 #if defined(CONFIG_SYSCTL)
83659-
83660 /* External variables not in a header file. */
83661 extern int sysctl_overcommit_memory;
83662 extern int sysctl_overcommit_ratio;
83663@@ -119,17 +118,18 @@ extern int blk_iopoll_enabled;
83664
83665 /* Constants used for minimum and maximum */
83666 #ifdef CONFIG_LOCKUP_DETECTOR
83667-static int sixty = 60;
83668+static int sixty __read_only = 60;
83669 #endif
83670
83671-static int zero;
83672-static int __maybe_unused one = 1;
83673-static int __maybe_unused two = 2;
83674-static int __maybe_unused three = 3;
83675-static unsigned long one_ul = 1;
83676-static int one_hundred = 100;
83677+static int neg_one __read_only = -1;
83678+static int zero __read_only = 0;
83679+static int __maybe_unused one __read_only = 1;
83680+static int __maybe_unused two __read_only = 2;
83681+static int __maybe_unused three __read_only = 3;
83682+static unsigned long one_ul __read_only = 1;
83683+static int one_hundred __read_only = 100;
83684 #ifdef CONFIG_PRINTK
83685-static int ten_thousand = 10000;
83686+static int ten_thousand __read_only = 10000;
83687 #endif
83688
83689 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
83690@@ -176,10 +176,8 @@ static int proc_taint(struct ctl_table *table, int write,
83691 void __user *buffer, size_t *lenp, loff_t *ppos);
83692 #endif
83693
83694-#ifdef CONFIG_PRINTK
83695 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
83696 void __user *buffer, size_t *lenp, loff_t *ppos);
83697-#endif
83698
83699 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
83700 void __user *buffer, size_t *lenp, loff_t *ppos);
83701@@ -210,6 +208,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
83702
83703 #endif
83704
83705+extern struct ctl_table grsecurity_table[];
83706+
83707 static struct ctl_table kern_table[];
83708 static struct ctl_table vm_table[];
83709 static struct ctl_table fs_table[];
83710@@ -224,6 +224,20 @@ extern struct ctl_table epoll_table[];
83711 int sysctl_legacy_va_layout;
83712 #endif
83713
83714+#ifdef CONFIG_PAX_SOFTMODE
83715+static ctl_table pax_table[] = {
83716+ {
83717+ .procname = "softmode",
83718+ .data = &pax_softmode,
83719+ .maxlen = sizeof(unsigned int),
83720+ .mode = 0600,
83721+ .proc_handler = &proc_dointvec,
83722+ },
83723+
83724+ { }
83725+};
83726+#endif
83727+
83728 /* The default sysctl tables: */
83729
83730 static struct ctl_table sysctl_base_table[] = {
83731@@ -272,6 +286,22 @@ static int max_extfrag_threshold = 1000;
83732 #endif
83733
83734 static struct ctl_table kern_table[] = {
83735+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
83736+ {
83737+ .procname = "grsecurity",
83738+ .mode = 0500,
83739+ .child = grsecurity_table,
83740+ },
83741+#endif
83742+
83743+#ifdef CONFIG_PAX_SOFTMODE
83744+ {
83745+ .procname = "pax",
83746+ .mode = 0500,
83747+ .child = pax_table,
83748+ },
83749+#endif
83750+
83751 {
83752 .procname = "sched_child_runs_first",
83753 .data = &sysctl_sched_child_runs_first,
83754@@ -613,7 +643,7 @@ static struct ctl_table kern_table[] = {
83755 .data = &modprobe_path,
83756 .maxlen = KMOD_PATH_LEN,
83757 .mode = 0644,
83758- .proc_handler = proc_dostring,
83759+ .proc_handler = proc_dostring_modpriv,
83760 },
83761 {
83762 .procname = "modules_disabled",
83763@@ -780,16 +810,20 @@ static struct ctl_table kern_table[] = {
83764 .extra1 = &zero,
83765 .extra2 = &one,
83766 },
83767+#endif
83768 {
83769 .procname = "kptr_restrict",
83770 .data = &kptr_restrict,
83771 .maxlen = sizeof(int),
83772 .mode = 0644,
83773 .proc_handler = proc_dointvec_minmax_sysadmin,
83774+#ifdef CONFIG_GRKERNSEC_HIDESYM
83775+ .extra1 = &two,
83776+#else
83777 .extra1 = &zero,
83778+#endif
83779 .extra2 = &two,
83780 },
83781-#endif
83782 {
83783 .procname = "ngroups_max",
83784 .data = &ngroups_max,
83785@@ -1031,10 +1065,17 @@ static struct ctl_table kern_table[] = {
83786 */
83787 {
83788 .procname = "perf_event_paranoid",
83789- .data = &sysctl_perf_event_paranoid,
83790- .maxlen = sizeof(sysctl_perf_event_paranoid),
83791+ .data = &sysctl_perf_event_legitimately_concerned,
83792+ .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
83793 .mode = 0644,
83794- .proc_handler = proc_dointvec,
83795+ /* go ahead, be a hero */
83796+ .proc_handler = proc_dointvec_minmax_sysadmin,
83797+ .extra1 = &neg_one,
83798+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
83799+ .extra2 = &three,
83800+#else
83801+ .extra2 = &two,
83802+#endif
83803 },
83804 {
83805 .procname = "perf_event_mlock_kb",
83806@@ -1297,6 +1338,13 @@ static struct ctl_table vm_table[] = {
83807 .proc_handler = proc_dointvec_minmax,
83808 .extra1 = &zero,
83809 },
83810+ {
83811+ .procname = "heap_stack_gap",
83812+ .data = &sysctl_heap_stack_gap,
83813+ .maxlen = sizeof(sysctl_heap_stack_gap),
83814+ .mode = 0644,
83815+ .proc_handler = proc_doulongvec_minmax,
83816+ },
83817 #else
83818 {
83819 .procname = "nr_trim_pages",
83820@@ -1761,6 +1809,16 @@ int proc_dostring(struct ctl_table *table, int write,
83821 buffer, lenp, ppos);
83822 }
83823
83824+int proc_dostring_modpriv(struct ctl_table *table, int write,
83825+ void __user *buffer, size_t *lenp, loff_t *ppos)
83826+{
83827+ if (write && !capable(CAP_SYS_MODULE))
83828+ return -EPERM;
83829+
83830+ return _proc_do_string(table->data, table->maxlen, write,
83831+ buffer, lenp, ppos);
83832+}
83833+
83834 static size_t proc_skip_spaces(char **buf)
83835 {
83836 size_t ret;
83837@@ -1866,6 +1924,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
83838 len = strlen(tmp);
83839 if (len > *size)
83840 len = *size;
83841+ if (len > sizeof(tmp))
83842+ len = sizeof(tmp);
83843 if (copy_to_user(*buf, tmp, len))
83844 return -EFAULT;
83845 *size -= len;
83846@@ -2030,7 +2090,7 @@ int proc_dointvec(struct ctl_table *table, int write,
83847 static int proc_taint(struct ctl_table *table, int write,
83848 void __user *buffer, size_t *lenp, loff_t *ppos)
83849 {
83850- struct ctl_table t;
83851+ ctl_table_no_const t;
83852 unsigned long tmptaint = get_taint();
83853 int err;
83854
83855@@ -2058,7 +2118,6 @@ static int proc_taint(struct ctl_table *table, int write,
83856 return err;
83857 }
83858
83859-#ifdef CONFIG_PRINTK
83860 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
83861 void __user *buffer, size_t *lenp, loff_t *ppos)
83862 {
83863@@ -2067,7 +2126,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
83864
83865 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
83866 }
83867-#endif
83868
83869 struct do_proc_dointvec_minmax_conv_param {
83870 int *min;
83871@@ -2214,8 +2272,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
83872 *i = val;
83873 } else {
83874 val = convdiv * (*i) / convmul;
83875- if (!first)
83876+ if (!first) {
83877 err = proc_put_char(&buffer, &left, '\t');
83878+ if (err)
83879+ break;
83880+ }
83881 err = proc_put_long(&buffer, &left, val, false);
83882 if (err)
83883 break;
83884@@ -2611,6 +2672,12 @@ int proc_dostring(struct ctl_table *table, int write,
83885 return -ENOSYS;
83886 }
83887
83888+int proc_dostring_modpriv(struct ctl_table *table, int write,
83889+ void __user *buffer, size_t *lenp, loff_t *ppos)
83890+{
83891+ return -ENOSYS;
83892+}
83893+
83894 int proc_dointvec(struct ctl_table *table, int write,
83895 void __user *buffer, size_t *lenp, loff_t *ppos)
83896 {
83897@@ -2667,5 +2734,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
83898 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
83899 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
83900 EXPORT_SYMBOL(proc_dostring);
83901+EXPORT_SYMBOL(proc_dostring_modpriv);
83902 EXPORT_SYMBOL(proc_doulongvec_minmax);
83903 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
83904diff --git a/kernel/taskstats.c b/kernel/taskstats.c
83905index 145bb4d..b2aa969 100644
83906--- a/kernel/taskstats.c
83907+++ b/kernel/taskstats.c
83908@@ -28,9 +28,12 @@
83909 #include <linux/fs.h>
83910 #include <linux/file.h>
83911 #include <linux/pid_namespace.h>
83912+#include <linux/grsecurity.h>
83913 #include <net/genetlink.h>
83914 #include <linux/atomic.h>
83915
83916+extern int gr_is_taskstats_denied(int pid);
83917+
83918 /*
83919 * Maximum length of a cpumask that can be specified in
83920 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
83921@@ -570,6 +573,9 @@ err:
83922
83923 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
83924 {
83925+ if (gr_is_taskstats_denied(current->pid))
83926+ return -EACCES;
83927+
83928 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
83929 return cmd_attr_register_cpumask(info);
83930 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
83931diff --git a/kernel/time.c b/kernel/time.c
83932index 7c7964c..784a599 100644
83933--- a/kernel/time.c
83934+++ b/kernel/time.c
83935@@ -172,6 +172,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
83936 return error;
83937
83938 if (tz) {
83939+ /* we log in do_settimeofday called below, so don't log twice
83940+ */
83941+ if (!tv)
83942+ gr_log_timechange();
83943+
83944 sys_tz = *tz;
83945 update_vsyscall_tz();
83946 if (firsttime) {
83947@@ -502,7 +507,7 @@ EXPORT_SYMBOL(usecs_to_jiffies);
83948 * The >> (NSEC_JIFFIE_SC - SEC_JIFFIE_SC) converts the scaled nsec
83949 * value to a scaled second value.
83950 */
83951-unsigned long
83952+unsigned long __intentional_overflow(-1)
83953 timespec_to_jiffies(const struct timespec *value)
83954 {
83955 unsigned long sec = value->tv_sec;
83956diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
83957index eec50fc..65e5df6 100644
83958--- a/kernel/time/alarmtimer.c
83959+++ b/kernel/time/alarmtimer.c
83960@@ -795,7 +795,7 @@ static int __init alarmtimer_init(void)
83961 struct platform_device *pdev;
83962 int error = 0;
83963 int i;
83964- struct k_clock alarm_clock = {
83965+ static struct k_clock alarm_clock = {
83966 .clock_getres = alarm_clock_getres,
83967 .clock_get = alarm_clock_get,
83968 .timer_create = alarm_timer_create,
83969diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
83970index 947ba25..20cbade 100644
83971--- a/kernel/time/timekeeping.c
83972+++ b/kernel/time/timekeeping.c
83973@@ -15,6 +15,7 @@
83974 #include <linux/init.h>
83975 #include <linux/mm.h>
83976 #include <linux/sched.h>
83977+#include <linux/grsecurity.h>
83978 #include <linux/syscore_ops.h>
83979 #include <linux/clocksource.h>
83980 #include <linux/jiffies.h>
83981@@ -500,6 +501,8 @@ int do_settimeofday(const struct timespec *tv)
83982 if (!timespec_valid_strict(tv))
83983 return -EINVAL;
83984
83985+ gr_log_timechange();
83986+
83987 raw_spin_lock_irqsave(&timekeeper_lock, flags);
83988 write_seqcount_begin(&timekeeper_seq);
83989
83990diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
83991index 61ed862..3b52c65 100644
83992--- a/kernel/time/timer_list.c
83993+++ b/kernel/time/timer_list.c
83994@@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
83995
83996 static void print_name_offset(struct seq_file *m, void *sym)
83997 {
83998+#ifdef CONFIG_GRKERNSEC_HIDESYM
83999+ SEQ_printf(m, "<%p>", NULL);
84000+#else
84001 char symname[KSYM_NAME_LEN];
84002
84003 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
84004 SEQ_printf(m, "<%pK>", sym);
84005 else
84006 SEQ_printf(m, "%s", symname);
84007+#endif
84008 }
84009
84010 static void
84011@@ -119,7 +123,11 @@ next_one:
84012 static void
84013 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
84014 {
84015+#ifdef CONFIG_GRKERNSEC_HIDESYM
84016+ SEQ_printf(m, " .base: %p\n", NULL);
84017+#else
84018 SEQ_printf(m, " .base: %pK\n", base);
84019+#endif
84020 SEQ_printf(m, " .index: %d\n",
84021 base->index);
84022 SEQ_printf(m, " .resolution: %Lu nsecs\n",
84023@@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
84024 {
84025 struct proc_dir_entry *pe;
84026
84027+#ifdef CONFIG_GRKERNSEC_PROC_ADD
84028+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
84029+#else
84030 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
84031+#endif
84032 if (!pe)
84033 return -ENOMEM;
84034 return 0;
84035diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
84036index 0b537f2..40d6c20 100644
84037--- a/kernel/time/timer_stats.c
84038+++ b/kernel/time/timer_stats.c
84039@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
84040 static unsigned long nr_entries;
84041 static struct entry entries[MAX_ENTRIES];
84042
84043-static atomic_t overflow_count;
84044+static atomic_unchecked_t overflow_count;
84045
84046 /*
84047 * The entries are in a hash-table, for fast lookup:
84048@@ -140,7 +140,7 @@ static void reset_entries(void)
84049 nr_entries = 0;
84050 memset(entries, 0, sizeof(entries));
84051 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
84052- atomic_set(&overflow_count, 0);
84053+ atomic_set_unchecked(&overflow_count, 0);
84054 }
84055
84056 static struct entry *alloc_entry(void)
84057@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
84058 if (likely(entry))
84059 entry->count++;
84060 else
84061- atomic_inc(&overflow_count);
84062+ atomic_inc_unchecked(&overflow_count);
84063
84064 out_unlock:
84065 raw_spin_unlock_irqrestore(lock, flags);
84066@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
84067
84068 static void print_name_offset(struct seq_file *m, unsigned long addr)
84069 {
84070+#ifdef CONFIG_GRKERNSEC_HIDESYM
84071+ seq_printf(m, "<%p>", NULL);
84072+#else
84073 char symname[KSYM_NAME_LEN];
84074
84075 if (lookup_symbol_name(addr, symname) < 0)
84076- seq_printf(m, "<%p>", (void *)addr);
84077+ seq_printf(m, "<%pK>", (void *)addr);
84078 else
84079 seq_printf(m, "%s", symname);
84080+#endif
84081 }
84082
84083 static int tstats_show(struct seq_file *m, void *v)
84084@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
84085
84086 seq_puts(m, "Timer Stats Version: v0.2\n");
84087 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
84088- if (atomic_read(&overflow_count))
84089+ if (atomic_read_unchecked(&overflow_count))
84090 seq_printf(m, "Overflow: %d entries\n",
84091- atomic_read(&overflow_count));
84092+ atomic_read_unchecked(&overflow_count));
84093
84094 for (i = 0; i < nr_entries; i++) {
84095 entry = entries + i;
84096@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
84097 {
84098 struct proc_dir_entry *pe;
84099
84100+#ifdef CONFIG_GRKERNSEC_PROC_ADD
84101+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
84102+#else
84103 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
84104+#endif
84105 if (!pe)
84106 return -ENOMEM;
84107 return 0;
84108diff --git a/kernel/timer.c b/kernel/timer.c
84109index 4296d13..0164b04 100644
84110--- a/kernel/timer.c
84111+++ b/kernel/timer.c
84112@@ -1366,7 +1366,7 @@ void update_process_times(int user_tick)
84113 /*
84114 * This function runs timers and the timer-tq in bottom half context.
84115 */
84116-static void run_timer_softirq(struct softirq_action *h)
84117+static __latent_entropy void run_timer_softirq(void)
84118 {
84119 struct tvec_base *base = __this_cpu_read(tvec_bases);
84120
84121@@ -1429,7 +1429,7 @@ static void process_timeout(unsigned long __data)
84122 *
84123 * In all cases the return value is guaranteed to be non-negative.
84124 */
84125-signed long __sched schedule_timeout(signed long timeout)
84126+signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
84127 {
84128 struct timer_list timer;
84129 unsigned long expire;
84130diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
84131index b8b8560..75b1a09 100644
84132--- a/kernel/trace/blktrace.c
84133+++ b/kernel/trace/blktrace.c
84134@@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
84135 struct blk_trace *bt = filp->private_data;
84136 char buf[16];
84137
84138- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
84139+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
84140
84141 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
84142 }
84143@@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
84144 return 1;
84145
84146 bt = buf->chan->private_data;
84147- atomic_inc(&bt->dropped);
84148+ atomic_inc_unchecked(&bt->dropped);
84149 return 0;
84150 }
84151
84152@@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
84153
84154 bt->dir = dir;
84155 bt->dev = dev;
84156- atomic_set(&bt->dropped, 0);
84157+ atomic_set_unchecked(&bt->dropped, 0);
84158
84159 ret = -EIO;
84160 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
84161diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
84162index a6d098c..bb8cf65 100644
84163--- a/kernel/trace/ftrace.c
84164+++ b/kernel/trace/ftrace.c
84165@@ -1950,12 +1950,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
84166 if (unlikely(ftrace_disabled))
84167 return 0;
84168
84169+ ret = ftrace_arch_code_modify_prepare();
84170+ FTRACE_WARN_ON(ret);
84171+ if (ret)
84172+ return 0;
84173+
84174 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
84175+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
84176 if (ret) {
84177 ftrace_bug(ret, ip);
84178- return 0;
84179 }
84180- return 1;
84181+ return ret ? 0 : 1;
84182 }
84183
84184 /*
84185@@ -4028,8 +4033,10 @@ static int ftrace_process_locs(struct module *mod,
84186 if (!count)
84187 return 0;
84188
84189+ pax_open_kernel();
84190 sort(start, count, sizeof(*start),
84191 ftrace_cmp_ips, ftrace_swap_ips);
84192+ pax_close_kernel();
84193
84194 start_pg = ftrace_allocate_pages(count);
84195 if (!start_pg)
84196@@ -4752,8 +4759,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
84197 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
84198
84199 static int ftrace_graph_active;
84200-static struct notifier_block ftrace_suspend_notifier;
84201-
84202 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
84203 {
84204 return 0;
84205@@ -4897,6 +4902,10 @@ ftrace_suspend_notifier_call(struct notifier_block *bl, unsigned long state,
84206 return NOTIFY_DONE;
84207 }
84208
84209+static struct notifier_block ftrace_suspend_notifier = {
84210+ .notifier_call = ftrace_suspend_notifier_call
84211+};
84212+
84213 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
84214 trace_func_graph_ent_t entryfunc)
84215 {
84216@@ -4910,7 +4919,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
84217 goto out;
84218 }
84219
84220- ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
84221 register_pm_notifier(&ftrace_suspend_notifier);
84222
84223 ftrace_graph_active++;
84224diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
84225index cc2f66f..05edd54 100644
84226--- a/kernel/trace/ring_buffer.c
84227+++ b/kernel/trace/ring_buffer.c
84228@@ -352,9 +352,9 @@ struct buffer_data_page {
84229 */
84230 struct buffer_page {
84231 struct list_head list; /* list of buffer pages */
84232- local_t write; /* index for next write */
84233+ local_unchecked_t write; /* index for next write */
84234 unsigned read; /* index for next read */
84235- local_t entries; /* entries on this page */
84236+ local_unchecked_t entries; /* entries on this page */
84237 unsigned long real_end; /* real end of data */
84238 struct buffer_data_page *page; /* Actual data page */
84239 };
84240@@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
84241 unsigned long last_overrun;
84242 local_t entries_bytes;
84243 local_t entries;
84244- local_t overrun;
84245- local_t commit_overrun;
84246+ local_unchecked_t overrun;
84247+ local_unchecked_t commit_overrun;
84248 local_t dropped_events;
84249 local_t committing;
84250 local_t commits;
84251@@ -992,8 +992,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
84252 *
84253 * We add a counter to the write field to denote this.
84254 */
84255- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
84256- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
84257+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
84258+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
84259
84260 /*
84261 * Just make sure we have seen our old_write and synchronize
84262@@ -1021,8 +1021,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
84263 * cmpxchg to only update if an interrupt did not already
84264 * do it for us. If the cmpxchg fails, we don't care.
84265 */
84266- (void)local_cmpxchg(&next_page->write, old_write, val);
84267- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
84268+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
84269+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
84270
84271 /*
84272 * No need to worry about races with clearing out the commit.
84273@@ -1386,12 +1386,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
84274
84275 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
84276 {
84277- return local_read(&bpage->entries) & RB_WRITE_MASK;
84278+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
84279 }
84280
84281 static inline unsigned long rb_page_write(struct buffer_page *bpage)
84282 {
84283- return local_read(&bpage->write) & RB_WRITE_MASK;
84284+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
84285 }
84286
84287 static int
84288@@ -1486,7 +1486,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
84289 * bytes consumed in ring buffer from here.
84290 * Increment overrun to account for the lost events.
84291 */
84292- local_add(page_entries, &cpu_buffer->overrun);
84293+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
84294 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
84295 }
84296
84297@@ -2064,7 +2064,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
84298 * it is our responsibility to update
84299 * the counters.
84300 */
84301- local_add(entries, &cpu_buffer->overrun);
84302+ local_add_unchecked(entries, &cpu_buffer->overrun);
84303 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
84304
84305 /*
84306@@ -2214,7 +2214,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
84307 if (tail == BUF_PAGE_SIZE)
84308 tail_page->real_end = 0;
84309
84310- local_sub(length, &tail_page->write);
84311+ local_sub_unchecked(length, &tail_page->write);
84312 return;
84313 }
84314
84315@@ -2249,7 +2249,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
84316 rb_event_set_padding(event);
84317
84318 /* Set the write back to the previous setting */
84319- local_sub(length, &tail_page->write);
84320+ local_sub_unchecked(length, &tail_page->write);
84321 return;
84322 }
84323
84324@@ -2261,7 +2261,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
84325
84326 /* Set write to end of buffer */
84327 length = (tail + length) - BUF_PAGE_SIZE;
84328- local_sub(length, &tail_page->write);
84329+ local_sub_unchecked(length, &tail_page->write);
84330 }
84331
84332 /*
84333@@ -2287,7 +2287,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
84334 * about it.
84335 */
84336 if (unlikely(next_page == commit_page)) {
84337- local_inc(&cpu_buffer->commit_overrun);
84338+ local_inc_unchecked(&cpu_buffer->commit_overrun);
84339 goto out_reset;
84340 }
84341
84342@@ -2343,7 +2343,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
84343 cpu_buffer->tail_page) &&
84344 (cpu_buffer->commit_page ==
84345 cpu_buffer->reader_page))) {
84346- local_inc(&cpu_buffer->commit_overrun);
84347+ local_inc_unchecked(&cpu_buffer->commit_overrun);
84348 goto out_reset;
84349 }
84350 }
84351@@ -2391,7 +2391,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
84352 length += RB_LEN_TIME_EXTEND;
84353
84354 tail_page = cpu_buffer->tail_page;
84355- write = local_add_return(length, &tail_page->write);
84356+ write = local_add_return_unchecked(length, &tail_page->write);
84357
84358 /* set write to only the index of the write */
84359 write &= RB_WRITE_MASK;
84360@@ -2408,7 +2408,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
84361 kmemcheck_annotate_bitfield(event, bitfield);
84362 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
84363
84364- local_inc(&tail_page->entries);
84365+ local_inc_unchecked(&tail_page->entries);
84366
84367 /*
84368 * If this is the first commit on the page, then update
84369@@ -2441,7 +2441,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
84370
84371 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
84372 unsigned long write_mask =
84373- local_read(&bpage->write) & ~RB_WRITE_MASK;
84374+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
84375 unsigned long event_length = rb_event_length(event);
84376 /*
84377 * This is on the tail page. It is possible that
84378@@ -2451,7 +2451,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
84379 */
84380 old_index += write_mask;
84381 new_index += write_mask;
84382- index = local_cmpxchg(&bpage->write, old_index, new_index);
84383+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
84384 if (index == old_index) {
84385 /* update counters */
84386 local_sub(event_length, &cpu_buffer->entries_bytes);
84387@@ -2843,7 +2843,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
84388
84389 /* Do the likely case first */
84390 if (likely(bpage->page == (void *)addr)) {
84391- local_dec(&bpage->entries);
84392+ local_dec_unchecked(&bpage->entries);
84393 return;
84394 }
84395
84396@@ -2855,7 +2855,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
84397 start = bpage;
84398 do {
84399 if (bpage->page == (void *)addr) {
84400- local_dec(&bpage->entries);
84401+ local_dec_unchecked(&bpage->entries);
84402 return;
84403 }
84404 rb_inc_page(cpu_buffer, &bpage);
84405@@ -3139,7 +3139,7 @@ static inline unsigned long
84406 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
84407 {
84408 return local_read(&cpu_buffer->entries) -
84409- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
84410+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
84411 }
84412
84413 /**
84414@@ -3228,7 +3228,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
84415 return 0;
84416
84417 cpu_buffer = buffer->buffers[cpu];
84418- ret = local_read(&cpu_buffer->overrun);
84419+ ret = local_read_unchecked(&cpu_buffer->overrun);
84420
84421 return ret;
84422 }
84423@@ -3251,7 +3251,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
84424 return 0;
84425
84426 cpu_buffer = buffer->buffers[cpu];
84427- ret = local_read(&cpu_buffer->commit_overrun);
84428+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
84429
84430 return ret;
84431 }
84432@@ -3336,7 +3336,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
84433 /* if you care about this being correct, lock the buffer */
84434 for_each_buffer_cpu(buffer, cpu) {
84435 cpu_buffer = buffer->buffers[cpu];
84436- overruns += local_read(&cpu_buffer->overrun);
84437+ overruns += local_read_unchecked(&cpu_buffer->overrun);
84438 }
84439
84440 return overruns;
84441@@ -3512,8 +3512,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
84442 /*
84443 * Reset the reader page to size zero.
84444 */
84445- local_set(&cpu_buffer->reader_page->write, 0);
84446- local_set(&cpu_buffer->reader_page->entries, 0);
84447+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
84448+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
84449 local_set(&cpu_buffer->reader_page->page->commit, 0);
84450 cpu_buffer->reader_page->real_end = 0;
84451
84452@@ -3547,7 +3547,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
84453 * want to compare with the last_overrun.
84454 */
84455 smp_mb();
84456- overwrite = local_read(&(cpu_buffer->overrun));
84457+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
84458
84459 /*
84460 * Here's the tricky part.
84461@@ -4117,8 +4117,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
84462
84463 cpu_buffer->head_page
84464 = list_entry(cpu_buffer->pages, struct buffer_page, list);
84465- local_set(&cpu_buffer->head_page->write, 0);
84466- local_set(&cpu_buffer->head_page->entries, 0);
84467+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
84468+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
84469 local_set(&cpu_buffer->head_page->page->commit, 0);
84470
84471 cpu_buffer->head_page->read = 0;
84472@@ -4128,14 +4128,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
84473
84474 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
84475 INIT_LIST_HEAD(&cpu_buffer->new_pages);
84476- local_set(&cpu_buffer->reader_page->write, 0);
84477- local_set(&cpu_buffer->reader_page->entries, 0);
84478+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
84479+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
84480 local_set(&cpu_buffer->reader_page->page->commit, 0);
84481 cpu_buffer->reader_page->read = 0;
84482
84483 local_set(&cpu_buffer->entries_bytes, 0);
84484- local_set(&cpu_buffer->overrun, 0);
84485- local_set(&cpu_buffer->commit_overrun, 0);
84486+ local_set_unchecked(&cpu_buffer->overrun, 0);
84487+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
84488 local_set(&cpu_buffer->dropped_events, 0);
84489 local_set(&cpu_buffer->entries, 0);
84490 local_set(&cpu_buffer->committing, 0);
84491@@ -4540,8 +4540,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
84492 rb_init_page(bpage);
84493 bpage = reader->page;
84494 reader->page = *data_page;
84495- local_set(&reader->write, 0);
84496- local_set(&reader->entries, 0);
84497+ local_set_unchecked(&reader->write, 0);
84498+ local_set_unchecked(&reader->entries, 0);
84499 reader->read = 0;
84500 *data_page = bpage;
84501
84502diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
84503index 496f94d..754aeea 100644
84504--- a/kernel/trace/trace.c
84505+++ b/kernel/trace/trace.c
84506@@ -3335,7 +3335,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
84507 return 0;
84508 }
84509
84510-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
84511+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
84512 {
84513 /* do nothing if flag is already set */
84514 if (!!(trace_flags & mask) == !!enabled)
84515diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
84516index afaae41..64871f8 100644
84517--- a/kernel/trace/trace.h
84518+++ b/kernel/trace/trace.h
84519@@ -1025,7 +1025,7 @@ extern const char *__stop___trace_bprintk_fmt[];
84520 void trace_printk_init_buffers(void);
84521 void trace_printk_start_comm(void);
84522 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
84523-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
84524+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
84525
84526 /*
84527 * Normal trace_printk() and friends allocates special buffers
84528diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
84529index 26dc348..8708ca7 100644
84530--- a/kernel/trace/trace_clock.c
84531+++ b/kernel/trace/trace_clock.c
84532@@ -123,7 +123,7 @@ u64 notrace trace_clock_global(void)
84533 return now;
84534 }
84535
84536-static atomic64_t trace_counter;
84537+static atomic64_unchecked_t trace_counter;
84538
84539 /*
84540 * trace_clock_counter(): simply an atomic counter.
84541@@ -132,5 +132,5 @@ static atomic64_t trace_counter;
84542 */
84543 u64 notrace trace_clock_counter(void)
84544 {
84545- return atomic64_add_return(1, &trace_counter);
84546+ return atomic64_inc_return_unchecked(&trace_counter);
84547 }
84548diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
84549index 29a7ebc..eb473cf 100644
84550--- a/kernel/trace/trace_events.c
84551+++ b/kernel/trace/trace_events.c
84552@@ -1778,10 +1778,6 @@ static LIST_HEAD(ftrace_module_file_list);
84553 struct ftrace_module_file_ops {
84554 struct list_head list;
84555 struct module *mod;
84556- struct file_operations id;
84557- struct file_operations enable;
84558- struct file_operations format;
84559- struct file_operations filter;
84560 };
84561
84562 static struct ftrace_module_file_ops *
84563@@ -1822,17 +1818,12 @@ trace_create_file_ops(struct module *mod)
84564
84565 file_ops->mod = mod;
84566
84567- file_ops->id = ftrace_event_id_fops;
84568- file_ops->id.owner = mod;
84569-
84570- file_ops->enable = ftrace_enable_fops;
84571- file_ops->enable.owner = mod;
84572-
84573- file_ops->filter = ftrace_event_filter_fops;
84574- file_ops->filter.owner = mod;
84575-
84576- file_ops->format = ftrace_event_format_fops;
84577- file_ops->format.owner = mod;
84578+ pax_open_kernel();
84579+ mod->trace_id.owner = mod;
84580+ mod->trace_enable.owner = mod;
84581+ mod->trace_filter.owner = mod;
84582+ mod->trace_format.owner = mod;
84583+ pax_close_kernel();
84584
84585 list_add(&file_ops->list, &ftrace_module_file_list);
84586
84587@@ -1925,8 +1916,8 @@ __trace_add_new_mod_event(struct ftrace_event_call *call,
84588 struct ftrace_module_file_ops *file_ops)
84589 {
84590 return __trace_add_new_event(call, tr,
84591- &file_ops->id, &file_ops->enable,
84592- &file_ops->filter, &file_ops->format);
84593+ &file_ops->mod->trace_id, &file_ops->mod->trace_enable,
84594+ &file_ops->mod->trace_filter, &file_ops->mod->trace_format);
84595 }
84596
84597 #else
84598diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
84599index b3dcfb2..ebee344 100644
84600--- a/kernel/trace/trace_mmiotrace.c
84601+++ b/kernel/trace/trace_mmiotrace.c
84602@@ -24,7 +24,7 @@ struct header_iter {
84603 static struct trace_array *mmio_trace_array;
84604 static bool overrun_detected;
84605 static unsigned long prev_overruns;
84606-static atomic_t dropped_count;
84607+static atomic_unchecked_t dropped_count;
84608
84609 static void mmio_reset_data(struct trace_array *tr)
84610 {
84611@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
84612
84613 static unsigned long count_overruns(struct trace_iterator *iter)
84614 {
84615- unsigned long cnt = atomic_xchg(&dropped_count, 0);
84616+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
84617 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
84618
84619 if (over > prev_overruns)
84620@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
84621 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
84622 sizeof(*entry), 0, pc);
84623 if (!event) {
84624- atomic_inc(&dropped_count);
84625+ atomic_inc_unchecked(&dropped_count);
84626 return;
84627 }
84628 entry = ring_buffer_event_data(event);
84629@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
84630 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
84631 sizeof(*entry), 0, pc);
84632 if (!event) {
84633- atomic_inc(&dropped_count);
84634+ atomic_inc_unchecked(&dropped_count);
84635 return;
84636 }
84637 entry = ring_buffer_event_data(event);
84638diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
84639index 34e7cba..6f9a729 100644
84640--- a/kernel/trace/trace_output.c
84641+++ b/kernel/trace/trace_output.c
84642@@ -294,7 +294,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
84643
84644 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
84645 if (!IS_ERR(p)) {
84646- p = mangle_path(s->buffer + s->len, p, "\n");
84647+ p = mangle_path(s->buffer + s->len, p, "\n\\");
84648 if (p) {
84649 s->len = p - s->buffer;
84650 return 1;
84651@@ -893,14 +893,16 @@ int register_ftrace_event(struct trace_event *event)
84652 goto out;
84653 }
84654
84655+ pax_open_kernel();
84656 if (event->funcs->trace == NULL)
84657- event->funcs->trace = trace_nop_print;
84658+ *(void **)&event->funcs->trace = trace_nop_print;
84659 if (event->funcs->raw == NULL)
84660- event->funcs->raw = trace_nop_print;
84661+ *(void **)&event->funcs->raw = trace_nop_print;
84662 if (event->funcs->hex == NULL)
84663- event->funcs->hex = trace_nop_print;
84664+ *(void **)&event->funcs->hex = trace_nop_print;
84665 if (event->funcs->binary == NULL)
84666- event->funcs->binary = trace_nop_print;
84667+ *(void **)&event->funcs->binary = trace_nop_print;
84668+ pax_close_kernel();
84669
84670 key = event->type & (EVENT_HASHSIZE - 1);
84671
84672diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
84673index b20428c..4845a10 100644
84674--- a/kernel/trace/trace_stack.c
84675+++ b/kernel/trace/trace_stack.c
84676@@ -68,7 +68,7 @@ check_stack(unsigned long ip, unsigned long *stack)
84677 return;
84678
84679 /* we do not handle interrupt stacks yet */
84680- if (!object_is_on_stack(stack))
84681+ if (!object_starts_on_stack(stack))
84682 return;
84683
84684 local_irq_save(flags);
84685diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
84686index 9064b91..1f5d2f8 100644
84687--- a/kernel/user_namespace.c
84688+++ b/kernel/user_namespace.c
84689@@ -82,6 +82,21 @@ int create_user_ns(struct cred *new)
84690 !kgid_has_mapping(parent_ns, group))
84691 return -EPERM;
84692
84693+#ifdef CONFIG_GRKERNSEC
84694+ /*
84695+ * This doesn't really inspire confidence:
84696+ * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
84697+ * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
84698+ * Increases kernel attack surface in areas developers
84699+ * previously cared little about ("low importance due
84700+ * to requiring "root" capability")
84701+ * To be removed when this code receives *proper* review
84702+ */
84703+ if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
84704+ !capable(CAP_SETGID))
84705+ return -EPERM;
84706+#endif
84707+
84708 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
84709 if (!ns)
84710 return -ENOMEM;
84711@@ -862,7 +877,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
84712 if (atomic_read(&current->mm->mm_users) > 1)
84713 return -EINVAL;
84714
84715- if (current->fs->users != 1)
84716+ if (atomic_read(&current->fs->users) != 1)
84717 return -EINVAL;
84718
84719 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
84720diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
84721index 4f69f9a..7c6f8f8 100644
84722--- a/kernel/utsname_sysctl.c
84723+++ b/kernel/utsname_sysctl.c
84724@@ -47,7 +47,7 @@ static void put_uts(ctl_table *table, int write, void *which)
84725 static int proc_do_uts_string(ctl_table *table, int write,
84726 void __user *buffer, size_t *lenp, loff_t *ppos)
84727 {
84728- struct ctl_table uts_table;
84729+ ctl_table_no_const uts_table;
84730 int r;
84731 memcpy(&uts_table, table, sizeof(uts_table));
84732 uts_table.data = get_uts(table, write);
84733diff --git a/kernel/watchdog.c b/kernel/watchdog.c
84734index 1241d8c..d5cfc28 100644
84735--- a/kernel/watchdog.c
84736+++ b/kernel/watchdog.c
84737@@ -475,7 +475,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
84738 static void watchdog_nmi_disable(unsigned int cpu) { return; }
84739 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
84740
84741-static struct smp_hotplug_thread watchdog_threads = {
84742+static struct smp_hotplug_thread watchdog_threads __read_only = {
84743 .store = &softlockup_watchdog,
84744 .thread_should_run = watchdog_should_run,
84745 .thread_fn = watchdog,
84746diff --git a/kernel/workqueue.c b/kernel/workqueue.c
84747index e93f7b9..989fcd7 100644
84748--- a/kernel/workqueue.c
84749+++ b/kernel/workqueue.c
84750@@ -4627,7 +4627,7 @@ static void rebind_workers(struct worker_pool *pool)
84751 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
84752 worker_flags |= WORKER_REBOUND;
84753 worker_flags &= ~WORKER_UNBOUND;
84754- ACCESS_ONCE(worker->flags) = worker_flags;
84755+ ACCESS_ONCE_RW(worker->flags) = worker_flags;
84756 }
84757
84758 spin_unlock_irq(&pool->lock);
84759diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
84760index 1501aa5..e771896 100644
84761--- a/lib/Kconfig.debug
84762+++ b/lib/Kconfig.debug
84763@@ -836,7 +836,7 @@ config DEBUG_MUTEXES
84764
84765 config DEBUG_WW_MUTEX_SLOWPATH
84766 bool "Wait/wound mutex debugging: Slowpath testing"
84767- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
84768+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
84769 select DEBUG_LOCK_ALLOC
84770 select DEBUG_SPINLOCK
84771 select DEBUG_MUTEXES
84772@@ -849,7 +849,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
84773
84774 config DEBUG_LOCK_ALLOC
84775 bool "Lock debugging: detect incorrect freeing of live locks"
84776- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
84777+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
84778 select DEBUG_SPINLOCK
84779 select DEBUG_MUTEXES
84780 select LOCKDEP
84781@@ -863,7 +863,7 @@ config DEBUG_LOCK_ALLOC
84782
84783 config PROVE_LOCKING
84784 bool "Lock debugging: prove locking correctness"
84785- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
84786+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
84787 select LOCKDEP
84788 select DEBUG_SPINLOCK
84789 select DEBUG_MUTEXES
84790@@ -914,7 +914,7 @@ config LOCKDEP
84791
84792 config LOCK_STAT
84793 bool "Lock usage statistics"
84794- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
84795+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
84796 select LOCKDEP
84797 select DEBUG_SPINLOCK
84798 select DEBUG_MUTEXES
84799@@ -1357,6 +1357,7 @@ config LATENCYTOP
84800 depends on DEBUG_KERNEL
84801 depends on STACKTRACE_SUPPORT
84802 depends on PROC_FS
84803+ depends on !GRKERNSEC_HIDESYM
84804 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
84805 select KALLSYMS
84806 select KALLSYMS_ALL
84807@@ -1373,7 +1374,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
84808 config DEBUG_STRICT_USER_COPY_CHECKS
84809 bool "Strict user copy size checks"
84810 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
84811- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
84812+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
84813 help
84814 Enabling this option turns a certain set of sanity checks for user
84815 copy operations into compile time failures.
84816@@ -1483,7 +1484,7 @@ endmenu # runtime tests
84817
84818 config PROVIDE_OHCI1394_DMA_INIT
84819 bool "Remote debugging over FireWire early on boot"
84820- depends on PCI && X86
84821+ depends on PCI && X86 && !GRKERNSEC
84822 help
84823 If you want to debug problems which hang or crash the kernel early
84824 on boot and the crashing machine has a FireWire port, you can use
84825@@ -1512,7 +1513,7 @@ config PROVIDE_OHCI1394_DMA_INIT
84826
84827 config FIREWIRE_OHCI_REMOTE_DMA
84828 bool "Remote debugging over FireWire with firewire-ohci"
84829- depends on FIREWIRE_OHCI
84830+ depends on FIREWIRE_OHCI && !GRKERNSEC
84831 help
84832 This option lets you use the FireWire bus for remote debugging
84833 with help of the firewire-ohci driver. It enables unfiltered
84834diff --git a/lib/Makefile b/lib/Makefile
84835index 7baccfd..3ceb95f 100644
84836--- a/lib/Makefile
84837+++ b/lib/Makefile
84838@@ -50,7 +50,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
84839
84840 obj-$(CONFIG_BTREE) += btree.o
84841 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
84842-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
84843+obj-y += list_debug.o
84844 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
84845
84846 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
84847diff --git a/lib/bitmap.c b/lib/bitmap.c
84848index 06f7e4f..f3cf2b0 100644
84849--- a/lib/bitmap.c
84850+++ b/lib/bitmap.c
84851@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
84852 {
84853 int c, old_c, totaldigits, ndigits, nchunks, nbits;
84854 u32 chunk;
84855- const char __user __force *ubuf = (const char __user __force *)buf;
84856+ const char __user *ubuf = (const char __force_user *)buf;
84857
84858 bitmap_zero(maskp, nmaskbits);
84859
84860@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
84861 {
84862 if (!access_ok(VERIFY_READ, ubuf, ulen))
84863 return -EFAULT;
84864- return __bitmap_parse((const char __force *)ubuf,
84865+ return __bitmap_parse((const char __force_kernel *)ubuf,
84866 ulen, 1, maskp, nmaskbits);
84867
84868 }
84869@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
84870 {
84871 unsigned a, b;
84872 int c, old_c, totaldigits;
84873- const char __user __force *ubuf = (const char __user __force *)buf;
84874+ const char __user *ubuf = (const char __force_user *)buf;
84875 int exp_digit, in_range;
84876
84877 totaldigits = c = 0;
84878@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
84879 {
84880 if (!access_ok(VERIFY_READ, ubuf, ulen))
84881 return -EFAULT;
84882- return __bitmap_parselist((const char __force *)ubuf,
84883+ return __bitmap_parselist((const char __force_kernel *)ubuf,
84884 ulen, 1, maskp, nmaskbits);
84885 }
84886 EXPORT_SYMBOL(bitmap_parselist_user);
84887diff --git a/lib/bug.c b/lib/bug.c
84888index 1686034..a9c00c8 100644
84889--- a/lib/bug.c
84890+++ b/lib/bug.c
84891@@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
84892 return BUG_TRAP_TYPE_NONE;
84893
84894 bug = find_bug(bugaddr);
84895+ if (!bug)
84896+ return BUG_TRAP_TYPE_NONE;
84897
84898 file = NULL;
84899 line = 0;
84900diff --git a/lib/debugobjects.c b/lib/debugobjects.c
84901index 37061ed..da83f48 100644
84902--- a/lib/debugobjects.c
84903+++ b/lib/debugobjects.c
84904@@ -286,7 +286,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
84905 if (limit > 4)
84906 return;
84907
84908- is_on_stack = object_is_on_stack(addr);
84909+ is_on_stack = object_starts_on_stack(addr);
84910 if (is_on_stack == onstack)
84911 return;
84912
84913diff --git a/lib/devres.c b/lib/devres.c
84914index 8235331..5881053 100644
84915--- a/lib/devres.c
84916+++ b/lib/devres.c
84917@@ -81,7 +81,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
84918 void devm_iounmap(struct device *dev, void __iomem *addr)
84919 {
84920 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
84921- (void *)addr));
84922+ (void __force *)addr));
84923 iounmap(addr);
84924 }
84925 EXPORT_SYMBOL(devm_iounmap);
84926@@ -224,7 +224,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
84927 {
84928 ioport_unmap(addr);
84929 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
84930- devm_ioport_map_match, (void *)addr));
84931+ devm_ioport_map_match, (void __force *)addr));
84932 }
84933 EXPORT_SYMBOL(devm_ioport_unmap);
84934 #endif /* CONFIG_HAS_IOPORT */
84935diff --git a/lib/div64.c b/lib/div64.c
84936index a163b6c..9618fa5 100644
84937--- a/lib/div64.c
84938+++ b/lib/div64.c
84939@@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
84940 EXPORT_SYMBOL(__div64_32);
84941
84942 #ifndef div_s64_rem
84943-s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
84944+s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
84945 {
84946 u64 quotient;
84947
84948@@ -90,7 +90,7 @@ EXPORT_SYMBOL(div_s64_rem);
84949 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
84950 */
84951 #ifndef div64_u64
84952-u64 div64_u64(u64 dividend, u64 divisor)
84953+u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
84954 {
84955 u32 high = divisor >> 32;
84956 u64 quot;
84957diff --git a/lib/dma-debug.c b/lib/dma-debug.c
84958index d87a17a..ac0d79a 100644
84959--- a/lib/dma-debug.c
84960+++ b/lib/dma-debug.c
84961@@ -768,7 +768,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
84962
84963 void dma_debug_add_bus(struct bus_type *bus)
84964 {
84965- struct notifier_block *nb;
84966+ notifier_block_no_const *nb;
84967
84968 if (global_disable)
84969 return;
84970@@ -945,7 +945,7 @@ static void check_unmap(struct dma_debug_entry *ref)
84971
84972 static void check_for_stack(struct device *dev, void *addr)
84973 {
84974- if (object_is_on_stack(addr))
84975+ if (object_starts_on_stack(addr))
84976 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
84977 "stack [addr=%p]\n", addr);
84978 }
84979diff --git a/lib/inflate.c b/lib/inflate.c
84980index 013a761..c28f3fc 100644
84981--- a/lib/inflate.c
84982+++ b/lib/inflate.c
84983@@ -269,7 +269,7 @@ static void free(void *where)
84984 malloc_ptr = free_mem_ptr;
84985 }
84986 #else
84987-#define malloc(a) kmalloc(a, GFP_KERNEL)
84988+#define malloc(a) kmalloc((a), GFP_KERNEL)
84989 #define free(a) kfree(a)
84990 #endif
84991
84992diff --git a/lib/ioremap.c b/lib/ioremap.c
84993index 0c9216c..863bd89 100644
84994--- a/lib/ioremap.c
84995+++ b/lib/ioremap.c
84996@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
84997 unsigned long next;
84998
84999 phys_addr -= addr;
85000- pmd = pmd_alloc(&init_mm, pud, addr);
85001+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
85002 if (!pmd)
85003 return -ENOMEM;
85004 do {
85005@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
85006 unsigned long next;
85007
85008 phys_addr -= addr;
85009- pud = pud_alloc(&init_mm, pgd, addr);
85010+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
85011 if (!pud)
85012 return -ENOMEM;
85013 do {
85014diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
85015index bd2bea9..6b3c95e 100644
85016--- a/lib/is_single_threaded.c
85017+++ b/lib/is_single_threaded.c
85018@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
85019 struct task_struct *p, *t;
85020 bool ret;
85021
85022+ if (!mm)
85023+ return true;
85024+
85025 if (atomic_read(&task->signal->live) != 1)
85026 return false;
85027
85028diff --git a/lib/kobject.c b/lib/kobject.c
85029index 4a1f33d..2f3ca75 100644
85030--- a/lib/kobject.c
85031+++ b/lib/kobject.c
85032@@ -859,9 +859,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
85033
85034
85035 static DEFINE_SPINLOCK(kobj_ns_type_lock);
85036-static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
85037+static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
85038
85039-int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
85040+int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
85041 {
85042 enum kobj_ns_type type = ops->type;
85043 int error;
85044diff --git a/lib/list_debug.c b/lib/list_debug.c
85045index c24c2f7..06e070b 100644
85046--- a/lib/list_debug.c
85047+++ b/lib/list_debug.c
85048@@ -11,7 +11,9 @@
85049 #include <linux/bug.h>
85050 #include <linux/kernel.h>
85051 #include <linux/rculist.h>
85052+#include <linux/mm.h>
85053
85054+#ifdef CONFIG_DEBUG_LIST
85055 /*
85056 * Insert a new entry between two known consecutive entries.
85057 *
85058@@ -19,21 +21,32 @@
85059 * the prev/next entries already!
85060 */
85061
85062-void __list_add(struct list_head *new,
85063- struct list_head *prev,
85064- struct list_head *next)
85065+static bool __list_add_debug(struct list_head *new,
85066+ struct list_head *prev,
85067+ struct list_head *next)
85068 {
85069- WARN(next->prev != prev,
85070+ if (WARN(next->prev != prev,
85071 "list_add corruption. next->prev should be "
85072 "prev (%p), but was %p. (next=%p).\n",
85073- prev, next->prev, next);
85074- WARN(prev->next != next,
85075+ prev, next->prev, next) ||
85076+ WARN(prev->next != next,
85077 "list_add corruption. prev->next should be "
85078 "next (%p), but was %p. (prev=%p).\n",
85079- next, prev->next, prev);
85080- WARN(new == prev || new == next,
85081- "list_add double add: new=%p, prev=%p, next=%p.\n",
85082- new, prev, next);
85083+ next, prev->next, prev) ||
85084+ WARN(new == prev || new == next,
85085+ "list_add double add: new=%p, prev=%p, next=%p.\n",
85086+ new, prev, next))
85087+ return false;
85088+ return true;
85089+}
85090+
85091+void __list_add(struct list_head *new,
85092+ struct list_head *prev,
85093+ struct list_head *next)
85094+{
85095+ if (!__list_add_debug(new, prev, next))
85096+ return;
85097+
85098 next->prev = new;
85099 new->next = next;
85100 new->prev = prev;
85101@@ -41,7 +54,7 @@ void __list_add(struct list_head *new,
85102 }
85103 EXPORT_SYMBOL(__list_add);
85104
85105-void __list_del_entry(struct list_head *entry)
85106+static bool __list_del_entry_debug(struct list_head *entry)
85107 {
85108 struct list_head *prev, *next;
85109
85110@@ -60,9 +73,16 @@ void __list_del_entry(struct list_head *entry)
85111 WARN(next->prev != entry,
85112 "list_del corruption. next->prev should be %p, "
85113 "but was %p\n", entry, next->prev))
85114+ return false;
85115+ return true;
85116+}
85117+
85118+void __list_del_entry(struct list_head *entry)
85119+{
85120+ if (!__list_del_entry_debug(entry))
85121 return;
85122
85123- __list_del(prev, next);
85124+ __list_del(entry->prev, entry->next);
85125 }
85126 EXPORT_SYMBOL(__list_del_entry);
85127
85128@@ -86,15 +106,85 @@ EXPORT_SYMBOL(list_del);
85129 void __list_add_rcu(struct list_head *new,
85130 struct list_head *prev, struct list_head *next)
85131 {
85132- WARN(next->prev != prev,
85133- "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
85134- prev, next->prev, next);
85135- WARN(prev->next != next,
85136- "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
85137- next, prev->next, prev);
85138+ if (!__list_add_debug(new, prev, next))
85139+ return;
85140+
85141 new->next = next;
85142 new->prev = prev;
85143 rcu_assign_pointer(list_next_rcu(prev), new);
85144 next->prev = new;
85145 }
85146 EXPORT_SYMBOL(__list_add_rcu);
85147+#endif
85148+
85149+void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
85150+{
85151+#ifdef CONFIG_DEBUG_LIST
85152+ if (!__list_add_debug(new, prev, next))
85153+ return;
85154+#endif
85155+
85156+ pax_open_kernel();
85157+ next->prev = new;
85158+ new->next = next;
85159+ new->prev = prev;
85160+ prev->next = new;
85161+ pax_close_kernel();
85162+}
85163+EXPORT_SYMBOL(__pax_list_add);
85164+
85165+void pax_list_del(struct list_head *entry)
85166+{
85167+#ifdef CONFIG_DEBUG_LIST
85168+ if (!__list_del_entry_debug(entry))
85169+ return;
85170+#endif
85171+
85172+ pax_open_kernel();
85173+ __list_del(entry->prev, entry->next);
85174+ entry->next = LIST_POISON1;
85175+ entry->prev = LIST_POISON2;
85176+ pax_close_kernel();
85177+}
85178+EXPORT_SYMBOL(pax_list_del);
85179+
85180+void pax_list_del_init(struct list_head *entry)
85181+{
85182+ pax_open_kernel();
85183+ __list_del(entry->prev, entry->next);
85184+ INIT_LIST_HEAD(entry);
85185+ pax_close_kernel();
85186+}
85187+EXPORT_SYMBOL(pax_list_del_init);
85188+
85189+void __pax_list_add_rcu(struct list_head *new,
85190+ struct list_head *prev, struct list_head *next)
85191+{
85192+#ifdef CONFIG_DEBUG_LIST
85193+ if (!__list_add_debug(new, prev, next))
85194+ return;
85195+#endif
85196+
85197+ pax_open_kernel();
85198+ new->next = next;
85199+ new->prev = prev;
85200+ rcu_assign_pointer(list_next_rcu(prev), new);
85201+ next->prev = new;
85202+ pax_close_kernel();
85203+}
85204+EXPORT_SYMBOL(__pax_list_add_rcu);
85205+
85206+void pax_list_del_rcu(struct list_head *entry)
85207+{
85208+#ifdef CONFIG_DEBUG_LIST
85209+ if (!__list_del_entry_debug(entry))
85210+ return;
85211+#endif
85212+
85213+ pax_open_kernel();
85214+ __list_del(entry->prev, entry->next);
85215+ entry->next = LIST_POISON1;
85216+ entry->prev = LIST_POISON2;
85217+ pax_close_kernel();
85218+}
85219+EXPORT_SYMBOL(pax_list_del_rcu);
85220diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
85221index 7deeb62..144eb47 100644
85222--- a/lib/percpu-refcount.c
85223+++ b/lib/percpu-refcount.c
85224@@ -29,7 +29,7 @@
85225 * can't hit 0 before we've added up all the percpu refs.
85226 */
85227
85228-#define PCPU_COUNT_BIAS (1U << 31)
85229+#define PCPU_COUNT_BIAS (1U << 30)
85230
85231 /**
85232 * percpu_ref_init - initialize a percpu refcount
85233diff --git a/lib/radix-tree.c b/lib/radix-tree.c
85234index e796429..6e38f9f 100644
85235--- a/lib/radix-tree.c
85236+++ b/lib/radix-tree.c
85237@@ -92,7 +92,7 @@ struct radix_tree_preload {
85238 int nr;
85239 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
85240 };
85241-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
85242+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
85243
85244 static inline void *ptr_to_indirect(void *ptr)
85245 {
85246diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
85247index bb2b201..46abaf9 100644
85248--- a/lib/strncpy_from_user.c
85249+++ b/lib/strncpy_from_user.c
85250@@ -21,7 +21,7 @@
85251 */
85252 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
85253 {
85254- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
85255+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
85256 long res = 0;
85257
85258 /*
85259diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
85260index a28df52..3d55877 100644
85261--- a/lib/strnlen_user.c
85262+++ b/lib/strnlen_user.c
85263@@ -26,7 +26,7 @@
85264 */
85265 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
85266 {
85267- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
85268+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
85269 long align, res = 0;
85270 unsigned long c;
85271
85272diff --git a/lib/swiotlb.c b/lib/swiotlb.c
85273index d23762e..e21eab2 100644
85274--- a/lib/swiotlb.c
85275+++ b/lib/swiotlb.c
85276@@ -664,7 +664,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
85277
85278 void
85279 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
85280- dma_addr_t dev_addr)
85281+ dma_addr_t dev_addr, struct dma_attrs *attrs)
85282 {
85283 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
85284
85285diff --git a/lib/usercopy.c b/lib/usercopy.c
85286index 4f5b1dd..7cab418 100644
85287--- a/lib/usercopy.c
85288+++ b/lib/usercopy.c
85289@@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
85290 WARN(1, "Buffer overflow detected!\n");
85291 }
85292 EXPORT_SYMBOL(copy_from_user_overflow);
85293+
85294+void copy_to_user_overflow(void)
85295+{
85296+ WARN(1, "Buffer overflow detected!\n");
85297+}
85298+EXPORT_SYMBOL(copy_to_user_overflow);
85299diff --git a/lib/vsprintf.c b/lib/vsprintf.c
85300index 739a363..aa668d7 100644
85301--- a/lib/vsprintf.c
85302+++ b/lib/vsprintf.c
85303@@ -16,6 +16,9 @@
85304 * - scnprintf and vscnprintf
85305 */
85306
85307+#ifdef CONFIG_GRKERNSEC_HIDESYM
85308+#define __INCLUDED_BY_HIDESYM 1
85309+#endif
85310 #include <stdarg.h>
85311 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
85312 #include <linux/types.h>
85313@@ -1078,7 +1081,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
85314 return number(buf, end, *(const netdev_features_t *)addr, spec);
85315 }
85316
85317+#ifdef CONFIG_GRKERNSEC_HIDESYM
85318+int kptr_restrict __read_mostly = 2;
85319+#else
85320 int kptr_restrict __read_mostly;
85321+#endif
85322
85323 /*
85324 * Show a '%p' thing. A kernel extension is that the '%p' is followed
85325@@ -1091,6 +1098,7 @@ int kptr_restrict __read_mostly;
85326 * - 'f' For simple symbolic function names without offset
85327 * - 'S' For symbolic direct pointers with offset
85328 * - 's' For symbolic direct pointers without offset
85329+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
85330 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
85331 * - 'B' For backtraced symbolic direct pointers with offset
85332 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
85333@@ -1155,12 +1163,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
85334
85335 if (!ptr && *fmt != 'K') {
85336 /*
85337- * Print (null) with the same width as a pointer so it makes
85338+ * Print (nil) with the same width as a pointer so it makes
85339 * tabular output look nice.
85340 */
85341 if (spec.field_width == -1)
85342 spec.field_width = default_width;
85343- return string(buf, end, "(null)", spec);
85344+ return string(buf, end, "(nil)", spec);
85345 }
85346
85347 switch (*fmt) {
85348@@ -1170,6 +1178,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
85349 /* Fallthrough */
85350 case 'S':
85351 case 's':
85352+#ifdef CONFIG_GRKERNSEC_HIDESYM
85353+ break;
85354+#else
85355+ return symbol_string(buf, end, ptr, spec, fmt);
85356+#endif
85357+ case 'A':
85358 case 'B':
85359 return symbol_string(buf, end, ptr, spec, fmt);
85360 case 'R':
85361@@ -1225,6 +1239,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
85362 va_end(va);
85363 return buf;
85364 }
85365+ case 'P':
85366+ break;
85367 case 'K':
85368 /*
85369 * %pK cannot be used in IRQ context because its test
85370@@ -1254,6 +1270,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
85371 return number(buf, end,
85372 (unsigned long long) *((phys_addr_t *)ptr), spec);
85373 }
85374+
85375+#ifdef CONFIG_GRKERNSEC_HIDESYM
85376+ /* 'P' = approved pointers to copy to userland,
85377+ as in the /proc/kallsyms case, as we make it display nothing
85378+ for non-root users, and the real contents for root users
85379+ Also ignore 'K' pointers, since we force their NULLing for non-root users
85380+ above
85381+ */
85382+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
85383+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
85384+ dump_stack();
85385+ ptr = NULL;
85386+ }
85387+#endif
85388+
85389 spec.flags |= SMALL;
85390 if (spec.field_width == -1) {
85391 spec.field_width = default_width;
85392@@ -1977,11 +2008,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
85393 typeof(type) value; \
85394 if (sizeof(type) == 8) { \
85395 args = PTR_ALIGN(args, sizeof(u32)); \
85396- *(u32 *)&value = *(u32 *)args; \
85397- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
85398+ *(u32 *)&value = *(const u32 *)args; \
85399+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
85400 } else { \
85401 args = PTR_ALIGN(args, sizeof(type)); \
85402- value = *(typeof(type) *)args; \
85403+ value = *(const typeof(type) *)args; \
85404 } \
85405 args += sizeof(type); \
85406 value; \
85407@@ -2044,7 +2075,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
85408 case FORMAT_TYPE_STR: {
85409 const char *str_arg = args;
85410 args += strlen(str_arg) + 1;
85411- str = string(str, end, (char *)str_arg, spec);
85412+ str = string(str, end, str_arg, spec);
85413 break;
85414 }
85415
85416diff --git a/localversion-grsec b/localversion-grsec
85417new file mode 100644
85418index 0000000..7cd6065
85419--- /dev/null
85420+++ b/localversion-grsec
85421@@ -0,0 +1 @@
85422+-grsec
85423diff --git a/mm/Kconfig b/mm/Kconfig
85424index 8028dcc..9a2dbe7 100644
85425--- a/mm/Kconfig
85426+++ b/mm/Kconfig
85427@@ -317,10 +317,10 @@ config KSM
85428 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
85429
85430 config DEFAULT_MMAP_MIN_ADDR
85431- int "Low address space to protect from user allocation"
85432+ int "Low address space to protect from user allocation"
85433 depends on MMU
85434- default 4096
85435- help
85436+ default 65536
85437+ help
85438 This is the portion of low virtual memory which should be protected
85439 from userspace allocation. Keeping a user from writing to low pages
85440 can help reduce the impact of kernel NULL pointer bugs.
85441@@ -351,7 +351,7 @@ config MEMORY_FAILURE
85442
85443 config HWPOISON_INJECT
85444 tristate "HWPoison pages injector"
85445- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
85446+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
85447 select PROC_PAGE_MONITOR
85448
85449 config NOMMU_INITIAL_TRIM_EXCESS
85450diff --git a/mm/backing-dev.c b/mm/backing-dev.c
85451index e04454c..ca5be3e 100644
85452--- a/mm/backing-dev.c
85453+++ b/mm/backing-dev.c
85454@@ -12,7 +12,7 @@
85455 #include <linux/device.h>
85456 #include <trace/events/writeback.h>
85457
85458-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
85459+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
85460
85461 struct backing_dev_info default_backing_dev_info = {
85462 .name = "default",
85463@@ -522,7 +522,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
85464 return err;
85465
85466 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
85467- atomic_long_inc_return(&bdi_seq));
85468+ atomic_long_inc_return_unchecked(&bdi_seq));
85469 if (err) {
85470 bdi_destroy(bdi);
85471 return err;
85472diff --git a/mm/filemap.c b/mm/filemap.c
85473index 4b51ac1..5aa90ff 100644
85474--- a/mm/filemap.c
85475+++ b/mm/filemap.c
85476@@ -1766,7 +1766,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
85477 struct address_space *mapping = file->f_mapping;
85478
85479 if (!mapping->a_ops->readpage)
85480- return -ENOEXEC;
85481+ return -ENODEV;
85482 file_accessed(file);
85483 vma->vm_ops = &generic_file_vm_ops;
85484 return 0;
85485@@ -1948,7 +1948,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
85486
85487 while (bytes) {
85488 char __user *buf = iov->iov_base + base;
85489- int copy = min(bytes, iov->iov_len - base);
85490+ size_t copy = min(bytes, iov->iov_len - base);
85491
85492 base = 0;
85493 left = __copy_from_user_inatomic(vaddr, buf, copy);
85494@@ -1977,7 +1977,7 @@ size_t iov_iter_copy_from_user_atomic(struct page *page,
85495 BUG_ON(!in_atomic());
85496 kaddr = kmap_atomic(page);
85497 if (likely(i->nr_segs == 1)) {
85498- int left;
85499+ size_t left;
85500 char __user *buf = i->iov->iov_base + i->iov_offset;
85501 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
85502 copied = bytes - left;
85503@@ -2005,7 +2005,7 @@ size_t iov_iter_copy_from_user(struct page *page,
85504
85505 kaddr = kmap(page);
85506 if (likely(i->nr_segs == 1)) {
85507- int left;
85508+ size_t left;
85509 char __user *buf = i->iov->iov_base + i->iov_offset;
85510 left = __copy_from_user(kaddr + offset, buf, bytes);
85511 copied = bytes - left;
85512@@ -2035,7 +2035,7 @@ void iov_iter_advance(struct iov_iter *i, size_t bytes)
85513 * zero-length segments (without overruning the iovec).
85514 */
85515 while (bytes || unlikely(i->count && !iov->iov_len)) {
85516- int copy;
85517+ size_t copy;
85518
85519 copy = min(bytes, iov->iov_len - base);
85520 BUG_ON(!i->count || i->count < copy);
85521@@ -2106,6 +2106,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
85522 *pos = i_size_read(inode);
85523
85524 if (limit != RLIM_INFINITY) {
85525+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
85526 if (*pos >= limit) {
85527 send_sig(SIGXFSZ, current, 0);
85528 return -EFBIG;
85529diff --git a/mm/fremap.c b/mm/fremap.c
85530index 5bff081..d8189a9 100644
85531--- a/mm/fremap.c
85532+++ b/mm/fremap.c
85533@@ -163,6 +163,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
85534 retry:
85535 vma = find_vma(mm, start);
85536
85537+#ifdef CONFIG_PAX_SEGMEXEC
85538+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
85539+ goto out;
85540+#endif
85541+
85542 /*
85543 * Make sure the vma is shared, that it supports prefaulting,
85544 * and that the remapped range is valid and fully within
85545diff --git a/mm/highmem.c b/mm/highmem.c
85546index b32b70c..e512eb0 100644
85547--- a/mm/highmem.c
85548+++ b/mm/highmem.c
85549@@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
85550 * So no dangers, even with speculative execution.
85551 */
85552 page = pte_page(pkmap_page_table[i]);
85553+ pax_open_kernel();
85554 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
85555-
85556+ pax_close_kernel();
85557 set_page_address(page, NULL);
85558 need_flush = 1;
85559 }
85560@@ -198,9 +199,11 @@ start:
85561 }
85562 }
85563 vaddr = PKMAP_ADDR(last_pkmap_nr);
85564+
85565+ pax_open_kernel();
85566 set_pte_at(&init_mm, vaddr,
85567 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
85568-
85569+ pax_close_kernel();
85570 pkmap_count[last_pkmap_nr] = 1;
85571 set_page_address(page, (void *)vaddr);
85572
85573diff --git a/mm/hugetlb.c b/mm/hugetlb.c
85574index b60f330..ee7de7e 100644
85575--- a/mm/hugetlb.c
85576+++ b/mm/hugetlb.c
85577@@ -2022,15 +2022,17 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
85578 struct hstate *h = &default_hstate;
85579 unsigned long tmp;
85580 int ret;
85581+ ctl_table_no_const hugetlb_table;
85582
85583 tmp = h->max_huge_pages;
85584
85585 if (write && h->order >= MAX_ORDER)
85586 return -EINVAL;
85587
85588- table->data = &tmp;
85589- table->maxlen = sizeof(unsigned long);
85590- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
85591+ hugetlb_table = *table;
85592+ hugetlb_table.data = &tmp;
85593+ hugetlb_table.maxlen = sizeof(unsigned long);
85594+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
85595 if (ret)
85596 goto out;
85597
85598@@ -2087,15 +2089,17 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
85599 struct hstate *h = &default_hstate;
85600 unsigned long tmp;
85601 int ret;
85602+ ctl_table_no_const hugetlb_table;
85603
85604 tmp = h->nr_overcommit_huge_pages;
85605
85606 if (write && h->order >= MAX_ORDER)
85607 return -EINVAL;
85608
85609- table->data = &tmp;
85610- table->maxlen = sizeof(unsigned long);
85611- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
85612+ hugetlb_table = *table;
85613+ hugetlb_table.data = &tmp;
85614+ hugetlb_table.maxlen = sizeof(unsigned long);
85615+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
85616 if (ret)
85617 goto out;
85618
85619@@ -2545,6 +2549,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
85620 return 1;
85621 }
85622
85623+#ifdef CONFIG_PAX_SEGMEXEC
85624+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
85625+{
85626+ struct mm_struct *mm = vma->vm_mm;
85627+ struct vm_area_struct *vma_m;
85628+ unsigned long address_m;
85629+ pte_t *ptep_m;
85630+
85631+ vma_m = pax_find_mirror_vma(vma);
85632+ if (!vma_m)
85633+ return;
85634+
85635+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
85636+ address_m = address + SEGMEXEC_TASK_SIZE;
85637+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
85638+ get_page(page_m);
85639+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
85640+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
85641+}
85642+#endif
85643+
85644 /*
85645 * Hugetlb_cow() should be called with page lock of the original hugepage held.
85646 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
85647@@ -2663,6 +2688,11 @@ retry_avoidcopy:
85648 make_huge_pte(vma, new_page, 1));
85649 page_remove_rmap(old_page);
85650 hugepage_add_new_anon_rmap(new_page, vma, address);
85651+
85652+#ifdef CONFIG_PAX_SEGMEXEC
85653+ pax_mirror_huge_pte(vma, address, new_page);
85654+#endif
85655+
85656 /* Make the old page be freed below */
85657 new_page = old_page;
85658 }
85659@@ -2821,6 +2851,10 @@ retry:
85660 && (vma->vm_flags & VM_SHARED)));
85661 set_huge_pte_at(mm, address, ptep, new_pte);
85662
85663+#ifdef CONFIG_PAX_SEGMEXEC
85664+ pax_mirror_huge_pte(vma, address, page);
85665+#endif
85666+
85667 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
85668 /* Optimization, do the COW without a second fault */
85669 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
85670@@ -2850,6 +2884,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
85671 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
85672 struct hstate *h = hstate_vma(vma);
85673
85674+#ifdef CONFIG_PAX_SEGMEXEC
85675+ struct vm_area_struct *vma_m;
85676+#endif
85677+
85678 address &= huge_page_mask(h);
85679
85680 ptep = huge_pte_offset(mm, address);
85681@@ -2863,6 +2901,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
85682 VM_FAULT_SET_HINDEX(hstate_index(h));
85683 }
85684
85685+#ifdef CONFIG_PAX_SEGMEXEC
85686+ vma_m = pax_find_mirror_vma(vma);
85687+ if (vma_m) {
85688+ unsigned long address_m;
85689+
85690+ if (vma->vm_start > vma_m->vm_start) {
85691+ address_m = address;
85692+ address -= SEGMEXEC_TASK_SIZE;
85693+ vma = vma_m;
85694+ h = hstate_vma(vma);
85695+ } else
85696+ address_m = address + SEGMEXEC_TASK_SIZE;
85697+
85698+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
85699+ return VM_FAULT_OOM;
85700+ address_m &= HPAGE_MASK;
85701+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
85702+ }
85703+#endif
85704+
85705 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
85706 if (!ptep)
85707 return VM_FAULT_OOM;
85708diff --git a/mm/internal.h b/mm/internal.h
85709index 4390ac6..fc60373c 100644
85710--- a/mm/internal.h
85711+++ b/mm/internal.h
85712@@ -95,6 +95,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
85713 * in mm/page_alloc.c
85714 */
85715 extern void __free_pages_bootmem(struct page *page, unsigned int order);
85716+extern void free_compound_page(struct page *page);
85717 extern void prep_compound_page(struct page *page, unsigned long order);
85718 #ifdef CONFIG_MEMORY_FAILURE
85719 extern bool is_free_buddy_page(struct page *page);
85720@@ -350,7 +351,7 @@ extern u32 hwpoison_filter_enable;
85721
85722 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
85723 unsigned long, unsigned long,
85724- unsigned long, unsigned long);
85725+ unsigned long, unsigned long) __intentional_overflow(-1);
85726
85727 extern void set_pageblock_order(void);
85728 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
85729diff --git a/mm/kmemleak.c b/mm/kmemleak.c
85730index c8d7f31..2dbeffd 100644
85731--- a/mm/kmemleak.c
85732+++ b/mm/kmemleak.c
85733@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
85734
85735 for (i = 0; i < object->trace_len; i++) {
85736 void *ptr = (void *)object->trace[i];
85737- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
85738+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
85739 }
85740 }
85741
85742@@ -1851,7 +1851,7 @@ static int __init kmemleak_late_init(void)
85743 return -ENOMEM;
85744 }
85745
85746- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
85747+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
85748 &kmemleak_fops);
85749 if (!dentry)
85750 pr_warning("Failed to create the debugfs kmemleak file\n");
85751diff --git a/mm/maccess.c b/mm/maccess.c
85752index d53adf9..03a24bf 100644
85753--- a/mm/maccess.c
85754+++ b/mm/maccess.c
85755@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
85756 set_fs(KERNEL_DS);
85757 pagefault_disable();
85758 ret = __copy_from_user_inatomic(dst,
85759- (__force const void __user *)src, size);
85760+ (const void __force_user *)src, size);
85761 pagefault_enable();
85762 set_fs(old_fs);
85763
85764@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
85765
85766 set_fs(KERNEL_DS);
85767 pagefault_disable();
85768- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
85769+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
85770 pagefault_enable();
85771 set_fs(old_fs);
85772
85773diff --git a/mm/madvise.c b/mm/madvise.c
85774index 7055883..aafb1ed 100644
85775--- a/mm/madvise.c
85776+++ b/mm/madvise.c
85777@@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
85778 pgoff_t pgoff;
85779 unsigned long new_flags = vma->vm_flags;
85780
85781+#ifdef CONFIG_PAX_SEGMEXEC
85782+ struct vm_area_struct *vma_m;
85783+#endif
85784+
85785 switch (behavior) {
85786 case MADV_NORMAL:
85787 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
85788@@ -126,6 +130,13 @@ success:
85789 /*
85790 * vm_flags is protected by the mmap_sem held in write mode.
85791 */
85792+
85793+#ifdef CONFIG_PAX_SEGMEXEC
85794+ vma_m = pax_find_mirror_vma(vma);
85795+ if (vma_m)
85796+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
85797+#endif
85798+
85799 vma->vm_flags = new_flags;
85800
85801 out:
85802@@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
85803 struct vm_area_struct ** prev,
85804 unsigned long start, unsigned long end)
85805 {
85806+
85807+#ifdef CONFIG_PAX_SEGMEXEC
85808+ struct vm_area_struct *vma_m;
85809+#endif
85810+
85811 *prev = vma;
85812 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
85813 return -EINVAL;
85814@@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
85815 zap_page_range(vma, start, end - start, &details);
85816 } else
85817 zap_page_range(vma, start, end - start, NULL);
85818+
85819+#ifdef CONFIG_PAX_SEGMEXEC
85820+ vma_m = pax_find_mirror_vma(vma);
85821+ if (vma_m) {
85822+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
85823+ struct zap_details details = {
85824+ .nonlinear_vma = vma_m,
85825+ .last_index = ULONG_MAX,
85826+ };
85827+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
85828+ } else
85829+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
85830+ }
85831+#endif
85832+
85833 return 0;
85834 }
85835
85836@@ -485,6 +516,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
85837 if (end < start)
85838 return error;
85839
85840+#ifdef CONFIG_PAX_SEGMEXEC
85841+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
85842+ if (end > SEGMEXEC_TASK_SIZE)
85843+ return error;
85844+ } else
85845+#endif
85846+
85847+ if (end > TASK_SIZE)
85848+ return error;
85849+
85850 error = 0;
85851 if (end == start)
85852 return error;
85853diff --git a/mm/memory-failure.c b/mm/memory-failure.c
85854index 2c13aa7..64cbc3f 100644
85855--- a/mm/memory-failure.c
85856+++ b/mm/memory-failure.c
85857@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
85858
85859 int sysctl_memory_failure_recovery __read_mostly = 1;
85860
85861-atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
85862+atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
85863
85864 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
85865
85866@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
85867 pfn, t->comm, t->pid);
85868 si.si_signo = SIGBUS;
85869 si.si_errno = 0;
85870- si.si_addr = (void *)addr;
85871+ si.si_addr = (void __user *)addr;
85872 #ifdef __ARCH_SI_TRAPNO
85873 si.si_trapno = trapno;
85874 #endif
85875@@ -760,7 +760,7 @@ static struct page_state {
85876 unsigned long res;
85877 char *msg;
85878 int (*action)(struct page *p, unsigned long pfn);
85879-} error_states[] = {
85880+} __do_const error_states[] = {
85881 { reserved, reserved, "reserved kernel", me_kernel },
85882 /*
85883 * free pages are specially detected outside this table:
85884@@ -1051,7 +1051,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
85885 nr_pages = 1 << compound_order(hpage);
85886 else /* normal page or thp */
85887 nr_pages = 1;
85888- atomic_long_add(nr_pages, &num_poisoned_pages);
85889+ atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
85890
85891 /*
85892 * We need/can do nothing about count=0 pages.
85893@@ -1081,7 +1081,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
85894 if (!PageHWPoison(hpage)
85895 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
85896 || (p != hpage && TestSetPageHWPoison(hpage))) {
85897- atomic_long_sub(nr_pages, &num_poisoned_pages);
85898+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
85899 return 0;
85900 }
85901 set_page_hwpoison_huge_page(hpage);
85902@@ -1148,7 +1148,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
85903 }
85904 if (hwpoison_filter(p)) {
85905 if (TestClearPageHWPoison(p))
85906- atomic_long_sub(nr_pages, &num_poisoned_pages);
85907+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
85908 unlock_page(hpage);
85909 put_page(hpage);
85910 return 0;
85911@@ -1350,7 +1350,7 @@ int unpoison_memory(unsigned long pfn)
85912 return 0;
85913 }
85914 if (TestClearPageHWPoison(p))
85915- atomic_long_sub(nr_pages, &num_poisoned_pages);
85916+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
85917 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
85918 return 0;
85919 }
85920@@ -1364,7 +1364,7 @@ int unpoison_memory(unsigned long pfn)
85921 */
85922 if (TestClearPageHWPoison(page)) {
85923 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
85924- atomic_long_sub(nr_pages, &num_poisoned_pages);
85925+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
85926 freeit = 1;
85927 if (PageHuge(page))
85928 clear_page_hwpoison_huge_page(page);
85929@@ -1491,7 +1491,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
85930 } else {
85931 set_page_hwpoison_huge_page(hpage);
85932 dequeue_hwpoisoned_huge_page(hpage);
85933- atomic_long_add(1 << compound_trans_order(hpage),
85934+ atomic_long_add_unchecked(1 << compound_trans_order(hpage),
85935 &num_poisoned_pages);
85936 }
85937 return ret;
85938@@ -1551,11 +1551,11 @@ int soft_offline_page(struct page *page, int flags)
85939 if (PageHuge(page)) {
85940 set_page_hwpoison_huge_page(hpage);
85941 dequeue_hwpoisoned_huge_page(hpage);
85942- atomic_long_add(1 << compound_trans_order(hpage),
85943+ atomic_long_add_unchecked(1 << compound_trans_order(hpage),
85944 &num_poisoned_pages);
85945 } else {
85946 SetPageHWPoison(page);
85947- atomic_long_inc(&num_poisoned_pages);
85948+ atomic_long_inc_unchecked(&num_poisoned_pages);
85949 }
85950 }
85951 unset_migratetype_isolate(page, MIGRATE_MOVABLE);
85952@@ -1595,7 +1595,7 @@ static int __soft_offline_page(struct page *page, int flags)
85953 put_page(page);
85954 pr_info("soft_offline: %#lx: invalidated\n", pfn);
85955 SetPageHWPoison(page);
85956- atomic_long_inc(&num_poisoned_pages);
85957+ atomic_long_inc_unchecked(&num_poisoned_pages);
85958 return 0;
85959 }
85960
85961@@ -1640,7 +1640,7 @@ static int __soft_offline_page(struct page *page, int flags)
85962 if (!is_free_buddy_page(page))
85963 pr_info("soft offline: %#lx: page leaked\n",
85964 pfn);
85965- atomic_long_inc(&num_poisoned_pages);
85966+ atomic_long_inc_unchecked(&num_poisoned_pages);
85967 }
85968 } else {
85969 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
85970diff --git a/mm/memory.c b/mm/memory.c
85971index af84bc0..2ed0816 100644
85972--- a/mm/memory.c
85973+++ b/mm/memory.c
85974@@ -426,6 +426,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
85975 free_pte_range(tlb, pmd, addr);
85976 } while (pmd++, addr = next, addr != end);
85977
85978+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
85979 start &= PUD_MASK;
85980 if (start < floor)
85981 return;
85982@@ -440,6 +441,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
85983 pmd = pmd_offset(pud, start);
85984 pud_clear(pud);
85985 pmd_free_tlb(tlb, pmd, start);
85986+#endif
85987+
85988 }
85989
85990 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
85991@@ -459,6 +462,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
85992 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
85993 } while (pud++, addr = next, addr != end);
85994
85995+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
85996 start &= PGDIR_MASK;
85997 if (start < floor)
85998 return;
85999@@ -473,6 +477,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
86000 pud = pud_offset(pgd, start);
86001 pgd_clear(pgd);
86002 pud_free_tlb(tlb, pud, start);
86003+#endif
86004+
86005 }
86006
86007 /*
86008@@ -1645,12 +1651,6 @@ no_page_table:
86009 return page;
86010 }
86011
86012-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
86013-{
86014- return stack_guard_page_start(vma, addr) ||
86015- stack_guard_page_end(vma, addr+PAGE_SIZE);
86016-}
86017-
86018 /**
86019 * __get_user_pages() - pin user pages in memory
86020 * @tsk: task_struct of target task
86021@@ -1737,10 +1737,10 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
86022
86023 i = 0;
86024
86025- do {
86026+ while (nr_pages) {
86027 struct vm_area_struct *vma;
86028
86029- vma = find_extend_vma(mm, start);
86030+ vma = find_vma(mm, start);
86031 if (!vma && in_gate_area(mm, start)) {
86032 unsigned long pg = start & PAGE_MASK;
86033 pgd_t *pgd;
86034@@ -1789,7 +1789,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
86035 goto next_page;
86036 }
86037
86038- if (!vma ||
86039+ if (!vma || start < vma->vm_start ||
86040 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
86041 !(vm_flags & vma->vm_flags))
86042 return i ? : -EFAULT;
86043@@ -1818,11 +1818,6 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
86044 int ret;
86045 unsigned int fault_flags = 0;
86046
86047- /* For mlock, just skip the stack guard page. */
86048- if (foll_flags & FOLL_MLOCK) {
86049- if (stack_guard_page(vma, start))
86050- goto next_page;
86051- }
86052 if (foll_flags & FOLL_WRITE)
86053 fault_flags |= FAULT_FLAG_WRITE;
86054 if (nonblocking)
86055@@ -1902,7 +1897,7 @@ next_page:
86056 start += page_increm * PAGE_SIZE;
86057 nr_pages -= page_increm;
86058 } while (nr_pages && start < vma->vm_end);
86059- } while (nr_pages);
86060+ }
86061 return i;
86062 }
86063 EXPORT_SYMBOL(__get_user_pages);
86064@@ -2109,6 +2104,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
86065 page_add_file_rmap(page);
86066 set_pte_at(mm, addr, pte, mk_pte(page, prot));
86067
86068+#ifdef CONFIG_PAX_SEGMEXEC
86069+ pax_mirror_file_pte(vma, addr, page, ptl);
86070+#endif
86071+
86072 retval = 0;
86073 pte_unmap_unlock(pte, ptl);
86074 return retval;
86075@@ -2153,9 +2152,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
86076 if (!page_count(page))
86077 return -EINVAL;
86078 if (!(vma->vm_flags & VM_MIXEDMAP)) {
86079+
86080+#ifdef CONFIG_PAX_SEGMEXEC
86081+ struct vm_area_struct *vma_m;
86082+#endif
86083+
86084 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
86085 BUG_ON(vma->vm_flags & VM_PFNMAP);
86086 vma->vm_flags |= VM_MIXEDMAP;
86087+
86088+#ifdef CONFIG_PAX_SEGMEXEC
86089+ vma_m = pax_find_mirror_vma(vma);
86090+ if (vma_m)
86091+ vma_m->vm_flags |= VM_MIXEDMAP;
86092+#endif
86093+
86094 }
86095 return insert_page(vma, addr, page, vma->vm_page_prot);
86096 }
86097@@ -2238,6 +2249,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
86098 unsigned long pfn)
86099 {
86100 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
86101+ BUG_ON(vma->vm_mirror);
86102
86103 if (addr < vma->vm_start || addr >= vma->vm_end)
86104 return -EFAULT;
86105@@ -2485,7 +2497,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
86106
86107 BUG_ON(pud_huge(*pud));
86108
86109- pmd = pmd_alloc(mm, pud, addr);
86110+ pmd = (mm == &init_mm) ?
86111+ pmd_alloc_kernel(mm, pud, addr) :
86112+ pmd_alloc(mm, pud, addr);
86113 if (!pmd)
86114 return -ENOMEM;
86115 do {
86116@@ -2505,7 +2519,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
86117 unsigned long next;
86118 int err;
86119
86120- pud = pud_alloc(mm, pgd, addr);
86121+ pud = (mm == &init_mm) ?
86122+ pud_alloc_kernel(mm, pgd, addr) :
86123+ pud_alloc(mm, pgd, addr);
86124 if (!pud)
86125 return -ENOMEM;
86126 do {
86127@@ -2593,6 +2609,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
86128 copy_user_highpage(dst, src, va, vma);
86129 }
86130
86131+#ifdef CONFIG_PAX_SEGMEXEC
86132+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
86133+{
86134+ struct mm_struct *mm = vma->vm_mm;
86135+ spinlock_t *ptl;
86136+ pte_t *pte, entry;
86137+
86138+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
86139+ entry = *pte;
86140+ if (!pte_present(entry)) {
86141+ if (!pte_none(entry)) {
86142+ BUG_ON(pte_file(entry));
86143+ free_swap_and_cache(pte_to_swp_entry(entry));
86144+ pte_clear_not_present_full(mm, address, pte, 0);
86145+ }
86146+ } else {
86147+ struct page *page;
86148+
86149+ flush_cache_page(vma, address, pte_pfn(entry));
86150+ entry = ptep_clear_flush(vma, address, pte);
86151+ BUG_ON(pte_dirty(entry));
86152+ page = vm_normal_page(vma, address, entry);
86153+ if (page) {
86154+ update_hiwater_rss(mm);
86155+ if (PageAnon(page))
86156+ dec_mm_counter_fast(mm, MM_ANONPAGES);
86157+ else
86158+ dec_mm_counter_fast(mm, MM_FILEPAGES);
86159+ page_remove_rmap(page);
86160+ page_cache_release(page);
86161+ }
86162+ }
86163+ pte_unmap_unlock(pte, ptl);
86164+}
86165+
86166+/* PaX: if vma is mirrored, synchronize the mirror's PTE
86167+ *
86168+ * the ptl of the lower mapped page is held on entry and is not released on exit
86169+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
86170+ */
86171+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
86172+{
86173+ struct mm_struct *mm = vma->vm_mm;
86174+ unsigned long address_m;
86175+ spinlock_t *ptl_m;
86176+ struct vm_area_struct *vma_m;
86177+ pmd_t *pmd_m;
86178+ pte_t *pte_m, entry_m;
86179+
86180+ BUG_ON(!page_m || !PageAnon(page_m));
86181+
86182+ vma_m = pax_find_mirror_vma(vma);
86183+ if (!vma_m)
86184+ return;
86185+
86186+ BUG_ON(!PageLocked(page_m));
86187+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
86188+ address_m = address + SEGMEXEC_TASK_SIZE;
86189+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
86190+ pte_m = pte_offset_map(pmd_m, address_m);
86191+ ptl_m = pte_lockptr(mm, pmd_m);
86192+ if (ptl != ptl_m) {
86193+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
86194+ if (!pte_none(*pte_m))
86195+ goto out;
86196+ }
86197+
86198+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
86199+ page_cache_get(page_m);
86200+ page_add_anon_rmap(page_m, vma_m, address_m);
86201+ inc_mm_counter_fast(mm, MM_ANONPAGES);
86202+ set_pte_at(mm, address_m, pte_m, entry_m);
86203+ update_mmu_cache(vma_m, address_m, pte_m);
86204+out:
86205+ if (ptl != ptl_m)
86206+ spin_unlock(ptl_m);
86207+ pte_unmap(pte_m);
86208+ unlock_page(page_m);
86209+}
86210+
86211+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
86212+{
86213+ struct mm_struct *mm = vma->vm_mm;
86214+ unsigned long address_m;
86215+ spinlock_t *ptl_m;
86216+ struct vm_area_struct *vma_m;
86217+ pmd_t *pmd_m;
86218+ pte_t *pte_m, entry_m;
86219+
86220+ BUG_ON(!page_m || PageAnon(page_m));
86221+
86222+ vma_m = pax_find_mirror_vma(vma);
86223+ if (!vma_m)
86224+ return;
86225+
86226+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
86227+ address_m = address + SEGMEXEC_TASK_SIZE;
86228+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
86229+ pte_m = pte_offset_map(pmd_m, address_m);
86230+ ptl_m = pte_lockptr(mm, pmd_m);
86231+ if (ptl != ptl_m) {
86232+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
86233+ if (!pte_none(*pte_m))
86234+ goto out;
86235+ }
86236+
86237+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
86238+ page_cache_get(page_m);
86239+ page_add_file_rmap(page_m);
86240+ inc_mm_counter_fast(mm, MM_FILEPAGES);
86241+ set_pte_at(mm, address_m, pte_m, entry_m);
86242+ update_mmu_cache(vma_m, address_m, pte_m);
86243+out:
86244+ if (ptl != ptl_m)
86245+ spin_unlock(ptl_m);
86246+ pte_unmap(pte_m);
86247+}
86248+
86249+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
86250+{
86251+ struct mm_struct *mm = vma->vm_mm;
86252+ unsigned long address_m;
86253+ spinlock_t *ptl_m;
86254+ struct vm_area_struct *vma_m;
86255+ pmd_t *pmd_m;
86256+ pte_t *pte_m, entry_m;
86257+
86258+ vma_m = pax_find_mirror_vma(vma);
86259+ if (!vma_m)
86260+ return;
86261+
86262+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
86263+ address_m = address + SEGMEXEC_TASK_SIZE;
86264+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
86265+ pte_m = pte_offset_map(pmd_m, address_m);
86266+ ptl_m = pte_lockptr(mm, pmd_m);
86267+ if (ptl != ptl_m) {
86268+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
86269+ if (!pte_none(*pte_m))
86270+ goto out;
86271+ }
86272+
86273+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
86274+ set_pte_at(mm, address_m, pte_m, entry_m);
86275+out:
86276+ if (ptl != ptl_m)
86277+ spin_unlock(ptl_m);
86278+ pte_unmap(pte_m);
86279+}
86280+
86281+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
86282+{
86283+ struct page *page_m;
86284+ pte_t entry;
86285+
86286+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
86287+ goto out;
86288+
86289+ entry = *pte;
86290+ page_m = vm_normal_page(vma, address, entry);
86291+ if (!page_m)
86292+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
86293+ else if (PageAnon(page_m)) {
86294+ if (pax_find_mirror_vma(vma)) {
86295+ pte_unmap_unlock(pte, ptl);
86296+ lock_page(page_m);
86297+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
86298+ if (pte_same(entry, *pte))
86299+ pax_mirror_anon_pte(vma, address, page_m, ptl);
86300+ else
86301+ unlock_page(page_m);
86302+ }
86303+ } else
86304+ pax_mirror_file_pte(vma, address, page_m, ptl);
86305+
86306+out:
86307+ pte_unmap_unlock(pte, ptl);
86308+}
86309+#endif
86310+
86311 /*
86312 * This routine handles present pages, when users try to write
86313 * to a shared page. It is done by copying the page to a new address
86314@@ -2809,6 +3005,12 @@ gotten:
86315 */
86316 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
86317 if (likely(pte_same(*page_table, orig_pte))) {
86318+
86319+#ifdef CONFIG_PAX_SEGMEXEC
86320+ if (pax_find_mirror_vma(vma))
86321+ BUG_ON(!trylock_page(new_page));
86322+#endif
86323+
86324 if (old_page) {
86325 if (!PageAnon(old_page)) {
86326 dec_mm_counter_fast(mm, MM_FILEPAGES);
86327@@ -2860,6 +3062,10 @@ gotten:
86328 page_remove_rmap(old_page);
86329 }
86330
86331+#ifdef CONFIG_PAX_SEGMEXEC
86332+ pax_mirror_anon_pte(vma, address, new_page, ptl);
86333+#endif
86334+
86335 /* Free the old page.. */
86336 new_page = old_page;
86337 ret |= VM_FAULT_WRITE;
86338@@ -3137,6 +3343,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
86339 swap_free(entry);
86340 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
86341 try_to_free_swap(page);
86342+
86343+#ifdef CONFIG_PAX_SEGMEXEC
86344+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
86345+#endif
86346+
86347 unlock_page(page);
86348 if (page != swapcache) {
86349 /*
86350@@ -3160,6 +3371,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
86351
86352 /* No need to invalidate - it was non-present before */
86353 update_mmu_cache(vma, address, page_table);
86354+
86355+#ifdef CONFIG_PAX_SEGMEXEC
86356+ pax_mirror_anon_pte(vma, address, page, ptl);
86357+#endif
86358+
86359 unlock:
86360 pte_unmap_unlock(page_table, ptl);
86361 out:
86362@@ -3179,40 +3395,6 @@ out_release:
86363 }
86364
86365 /*
86366- * This is like a special single-page "expand_{down|up}wards()",
86367- * except we must first make sure that 'address{-|+}PAGE_SIZE'
86368- * doesn't hit another vma.
86369- */
86370-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
86371-{
86372- address &= PAGE_MASK;
86373- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
86374- struct vm_area_struct *prev = vma->vm_prev;
86375-
86376- /*
86377- * Is there a mapping abutting this one below?
86378- *
86379- * That's only ok if it's the same stack mapping
86380- * that has gotten split..
86381- */
86382- if (prev && prev->vm_end == address)
86383- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
86384-
86385- expand_downwards(vma, address - PAGE_SIZE);
86386- }
86387- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
86388- struct vm_area_struct *next = vma->vm_next;
86389-
86390- /* As VM_GROWSDOWN but s/below/above/ */
86391- if (next && next->vm_start == address + PAGE_SIZE)
86392- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
86393-
86394- expand_upwards(vma, address + PAGE_SIZE);
86395- }
86396- return 0;
86397-}
86398-
86399-/*
86400 * We enter with non-exclusive mmap_sem (to exclude vma changes,
86401 * but allow concurrent faults), and pte mapped but not yet locked.
86402 * We return with mmap_sem still held, but pte unmapped and unlocked.
86403@@ -3221,27 +3403,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
86404 unsigned long address, pte_t *page_table, pmd_t *pmd,
86405 unsigned int flags)
86406 {
86407- struct page *page;
86408+ struct page *page = NULL;
86409 spinlock_t *ptl;
86410 pte_t entry;
86411
86412- pte_unmap(page_table);
86413-
86414- /* Check if we need to add a guard page to the stack */
86415- if (check_stack_guard_page(vma, address) < 0)
86416- return VM_FAULT_SIGBUS;
86417-
86418- /* Use the zero-page for reads */
86419 if (!(flags & FAULT_FLAG_WRITE)) {
86420 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
86421 vma->vm_page_prot));
86422- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
86423+ ptl = pte_lockptr(mm, pmd);
86424+ spin_lock(ptl);
86425 if (!pte_none(*page_table))
86426 goto unlock;
86427 goto setpte;
86428 }
86429
86430 /* Allocate our own private page. */
86431+ pte_unmap(page_table);
86432+
86433 if (unlikely(anon_vma_prepare(vma)))
86434 goto oom;
86435 page = alloc_zeroed_user_highpage_movable(vma, address);
86436@@ -3265,6 +3443,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
86437 if (!pte_none(*page_table))
86438 goto release;
86439
86440+#ifdef CONFIG_PAX_SEGMEXEC
86441+ if (pax_find_mirror_vma(vma))
86442+ BUG_ON(!trylock_page(page));
86443+#endif
86444+
86445 inc_mm_counter_fast(mm, MM_ANONPAGES);
86446 page_add_new_anon_rmap(page, vma, address);
86447 setpte:
86448@@ -3272,6 +3455,12 @@ setpte:
86449
86450 /* No need to invalidate - it was non-present before */
86451 update_mmu_cache(vma, address, page_table);
86452+
86453+#ifdef CONFIG_PAX_SEGMEXEC
86454+ if (page)
86455+ pax_mirror_anon_pte(vma, address, page, ptl);
86456+#endif
86457+
86458 unlock:
86459 pte_unmap_unlock(page_table, ptl);
86460 return 0;
86461@@ -3415,6 +3604,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
86462 */
86463 /* Only go through if we didn't race with anybody else... */
86464 if (likely(pte_same(*page_table, orig_pte))) {
86465+
86466+#ifdef CONFIG_PAX_SEGMEXEC
86467+ if (anon && pax_find_mirror_vma(vma))
86468+ BUG_ON(!trylock_page(page));
86469+#endif
86470+
86471 flush_icache_page(vma, page);
86472 entry = mk_pte(page, vma->vm_page_prot);
86473 if (flags & FAULT_FLAG_WRITE)
86474@@ -3436,6 +3631,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
86475
86476 /* no need to invalidate: a not-present page won't be cached */
86477 update_mmu_cache(vma, address, page_table);
86478+
86479+#ifdef CONFIG_PAX_SEGMEXEC
86480+ if (anon)
86481+ pax_mirror_anon_pte(vma, address, page, ptl);
86482+ else
86483+ pax_mirror_file_pte(vma, address, page, ptl);
86484+#endif
86485+
86486 } else {
86487 if (cow_page)
86488 mem_cgroup_uncharge_page(cow_page);
86489@@ -3757,6 +3960,12 @@ int handle_pte_fault(struct mm_struct *mm,
86490 if (flags & FAULT_FLAG_WRITE)
86491 flush_tlb_fix_spurious_fault(vma, address);
86492 }
86493+
86494+#ifdef CONFIG_PAX_SEGMEXEC
86495+ pax_mirror_pte(vma, address, pte, pmd, ptl);
86496+ return 0;
86497+#endif
86498+
86499 unlock:
86500 pte_unmap_unlock(pte, ptl);
86501 return 0;
86502@@ -3773,6 +3982,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
86503 pmd_t *pmd;
86504 pte_t *pte;
86505
86506+#ifdef CONFIG_PAX_SEGMEXEC
86507+ struct vm_area_struct *vma_m;
86508+#endif
86509+
86510 __set_current_state(TASK_RUNNING);
86511
86512 count_vm_event(PGFAULT);
86513@@ -3784,6 +3997,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
86514 if (unlikely(is_vm_hugetlb_page(vma)))
86515 return hugetlb_fault(mm, vma, address, flags);
86516
86517+#ifdef CONFIG_PAX_SEGMEXEC
86518+ vma_m = pax_find_mirror_vma(vma);
86519+ if (vma_m) {
86520+ unsigned long address_m;
86521+ pgd_t *pgd_m;
86522+ pud_t *pud_m;
86523+ pmd_t *pmd_m;
86524+
86525+ if (vma->vm_start > vma_m->vm_start) {
86526+ address_m = address;
86527+ address -= SEGMEXEC_TASK_SIZE;
86528+ vma = vma_m;
86529+ } else
86530+ address_m = address + SEGMEXEC_TASK_SIZE;
86531+
86532+ pgd_m = pgd_offset(mm, address_m);
86533+ pud_m = pud_alloc(mm, pgd_m, address_m);
86534+ if (!pud_m)
86535+ return VM_FAULT_OOM;
86536+ pmd_m = pmd_alloc(mm, pud_m, address_m);
86537+ if (!pmd_m)
86538+ return VM_FAULT_OOM;
86539+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
86540+ return VM_FAULT_OOM;
86541+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
86542+ }
86543+#endif
86544+
86545 retry:
86546 pgd = pgd_offset(mm, address);
86547 pud = pud_alloc(mm, pgd, address);
86548@@ -3882,6 +4123,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
86549 spin_unlock(&mm->page_table_lock);
86550 return 0;
86551 }
86552+
86553+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
86554+{
86555+ pud_t *new = pud_alloc_one(mm, address);
86556+ if (!new)
86557+ return -ENOMEM;
86558+
86559+ smp_wmb(); /* See comment in __pte_alloc */
86560+
86561+ spin_lock(&mm->page_table_lock);
86562+ if (pgd_present(*pgd)) /* Another has populated it */
86563+ pud_free(mm, new);
86564+ else
86565+ pgd_populate_kernel(mm, pgd, new);
86566+ spin_unlock(&mm->page_table_lock);
86567+ return 0;
86568+}
86569 #endif /* __PAGETABLE_PUD_FOLDED */
86570
86571 #ifndef __PAGETABLE_PMD_FOLDED
86572@@ -3912,6 +4170,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
86573 spin_unlock(&mm->page_table_lock);
86574 return 0;
86575 }
86576+
86577+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
86578+{
86579+ pmd_t *new = pmd_alloc_one(mm, address);
86580+ if (!new)
86581+ return -ENOMEM;
86582+
86583+ smp_wmb(); /* See comment in __pte_alloc */
86584+
86585+ spin_lock(&mm->page_table_lock);
86586+#ifndef __ARCH_HAS_4LEVEL_HACK
86587+ if (pud_present(*pud)) /* Another has populated it */
86588+ pmd_free(mm, new);
86589+ else
86590+ pud_populate_kernel(mm, pud, new);
86591+#else
86592+ if (pgd_present(*pud)) /* Another has populated it */
86593+ pmd_free(mm, new);
86594+ else
86595+ pgd_populate_kernel(mm, pud, new);
86596+#endif /* __ARCH_HAS_4LEVEL_HACK */
86597+ spin_unlock(&mm->page_table_lock);
86598+ return 0;
86599+}
86600 #endif /* __PAGETABLE_PMD_FOLDED */
86601
86602 #if !defined(__HAVE_ARCH_GATE_AREA)
86603@@ -3925,7 +4207,7 @@ static int __init gate_vma_init(void)
86604 gate_vma.vm_start = FIXADDR_USER_START;
86605 gate_vma.vm_end = FIXADDR_USER_END;
86606 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
86607- gate_vma.vm_page_prot = __P101;
86608+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
86609
86610 return 0;
86611 }
86612@@ -4059,8 +4341,8 @@ out:
86613 return ret;
86614 }
86615
86616-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
86617- void *buf, int len, int write)
86618+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
86619+ void *buf, size_t len, int write)
86620 {
86621 resource_size_t phys_addr;
86622 unsigned long prot = 0;
86623@@ -4085,8 +4367,8 @@ int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
86624 * Access another process' address space as given in mm. If non-NULL, use the
86625 * given task for page fault accounting.
86626 */
86627-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
86628- unsigned long addr, void *buf, int len, int write)
86629+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
86630+ unsigned long addr, void *buf, size_t len, int write)
86631 {
86632 struct vm_area_struct *vma;
86633 void *old_buf = buf;
86634@@ -4094,7 +4376,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
86635 down_read(&mm->mmap_sem);
86636 /* ignore errors, just check how much was successfully transferred */
86637 while (len) {
86638- int bytes, ret, offset;
86639+ ssize_t bytes, ret, offset;
86640 void *maddr;
86641 struct page *page = NULL;
86642
86643@@ -4153,8 +4435,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
86644 *
86645 * The caller must hold a reference on @mm.
86646 */
86647-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
86648- void *buf, int len, int write)
86649+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
86650+ void *buf, size_t len, int write)
86651 {
86652 return __access_remote_vm(NULL, mm, addr, buf, len, write);
86653 }
86654@@ -4164,11 +4446,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
86655 * Source/target buffer must be kernel space,
86656 * Do not walk the page table directly, use get_user_pages
86657 */
86658-int access_process_vm(struct task_struct *tsk, unsigned long addr,
86659- void *buf, int len, int write)
86660+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
86661+ void *buf, size_t len, int write)
86662 {
86663 struct mm_struct *mm;
86664- int ret;
86665+ ssize_t ret;
86666
86667 mm = get_task_mm(tsk);
86668 if (!mm)
86669diff --git a/mm/mempolicy.c b/mm/mempolicy.c
86670index 4baf12e..5497066 100644
86671--- a/mm/mempolicy.c
86672+++ b/mm/mempolicy.c
86673@@ -708,6 +708,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
86674 unsigned long vmstart;
86675 unsigned long vmend;
86676
86677+#ifdef CONFIG_PAX_SEGMEXEC
86678+ struct vm_area_struct *vma_m;
86679+#endif
86680+
86681 vma = find_vma(mm, start);
86682 if (!vma || vma->vm_start > start)
86683 return -EFAULT;
86684@@ -751,6 +755,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
86685 err = vma_replace_policy(vma, new_pol);
86686 if (err)
86687 goto out;
86688+
86689+#ifdef CONFIG_PAX_SEGMEXEC
86690+ vma_m = pax_find_mirror_vma(vma);
86691+ if (vma_m) {
86692+ err = vma_replace_policy(vma_m, new_pol);
86693+ if (err)
86694+ goto out;
86695+ }
86696+#endif
86697+
86698 }
86699
86700 out:
86701@@ -1206,6 +1220,17 @@ static long do_mbind(unsigned long start, unsigned long len,
86702
86703 if (end < start)
86704 return -EINVAL;
86705+
86706+#ifdef CONFIG_PAX_SEGMEXEC
86707+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
86708+ if (end > SEGMEXEC_TASK_SIZE)
86709+ return -EINVAL;
86710+ } else
86711+#endif
86712+
86713+ if (end > TASK_SIZE)
86714+ return -EINVAL;
86715+
86716 if (end == start)
86717 return 0;
86718
86719@@ -1434,8 +1459,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
86720 */
86721 tcred = __task_cred(task);
86722 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
86723- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
86724- !capable(CAP_SYS_NICE)) {
86725+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
86726 rcu_read_unlock();
86727 err = -EPERM;
86728 goto out_put;
86729@@ -1466,6 +1490,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
86730 goto out;
86731 }
86732
86733+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
86734+ if (mm != current->mm &&
86735+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
86736+ mmput(mm);
86737+ err = -EPERM;
86738+ goto out;
86739+ }
86740+#endif
86741+
86742 err = do_migrate_pages(mm, old, new,
86743 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
86744
86745diff --git a/mm/migrate.c b/mm/migrate.c
86746index 6f0c244..6d1ae32 100644
86747--- a/mm/migrate.c
86748+++ b/mm/migrate.c
86749@@ -1399,8 +1399,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
86750 */
86751 tcred = __task_cred(task);
86752 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
86753- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
86754- !capable(CAP_SYS_NICE)) {
86755+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
86756 rcu_read_unlock();
86757 err = -EPERM;
86758 goto out;
86759diff --git a/mm/mlock.c b/mm/mlock.c
86760index 79b7cf7..37472bf 100644
86761--- a/mm/mlock.c
86762+++ b/mm/mlock.c
86763@@ -13,6 +13,7 @@
86764 #include <linux/pagemap.h>
86765 #include <linux/mempolicy.h>
86766 #include <linux/syscalls.h>
86767+#include <linux/security.h>
86768 #include <linux/sched.h>
86769 #include <linux/export.h>
86770 #include <linux/rmap.h>
86771@@ -334,7 +335,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
86772 {
86773 unsigned long nstart, end, tmp;
86774 struct vm_area_struct * vma, * prev;
86775- int error;
86776+ int error = 0;
86777
86778 VM_BUG_ON(start & ~PAGE_MASK);
86779 VM_BUG_ON(len != PAGE_ALIGN(len));
86780@@ -343,6 +344,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
86781 return -EINVAL;
86782 if (end == start)
86783 return 0;
86784+ if (end > TASK_SIZE)
86785+ return -EINVAL;
86786+
86787 vma = find_vma(current->mm, start);
86788 if (!vma || vma->vm_start > start)
86789 return -ENOMEM;
86790@@ -354,6 +358,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
86791 for (nstart = start ; ; ) {
86792 vm_flags_t newflags;
86793
86794+#ifdef CONFIG_PAX_SEGMEXEC
86795+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
86796+ break;
86797+#endif
86798+
86799 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
86800
86801 newflags = vma->vm_flags & ~VM_LOCKED;
86802@@ -466,6 +475,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
86803 lock_limit >>= PAGE_SHIFT;
86804
86805 /* check against resource limits */
86806+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
86807 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
86808 error = do_mlock(start, len, 1);
86809 up_write(&current->mm->mmap_sem);
86810@@ -500,12 +510,18 @@ static int do_mlockall(int flags)
86811 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
86812 vm_flags_t newflags;
86813
86814+#ifdef CONFIG_PAX_SEGMEXEC
86815+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
86816+ break;
86817+#endif
86818+
86819 newflags = vma->vm_flags & ~VM_LOCKED;
86820 if (flags & MCL_CURRENT)
86821 newflags |= VM_LOCKED;
86822
86823 /* Ignore errors */
86824 mlock_fixup(vma, &prev, vma->vm_start, vma->vm_end, newflags);
86825+ cond_resched();
86826 }
86827 out:
86828 return 0;
86829@@ -532,6 +548,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
86830 lock_limit >>= PAGE_SHIFT;
86831
86832 ret = -ENOMEM;
86833+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
86834 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
86835 capable(CAP_IPC_LOCK))
86836 ret = do_mlockall(flags);
86837diff --git a/mm/mmap.c b/mm/mmap.c
86838index f9c97d1..3468d3b 100644
86839--- a/mm/mmap.c
86840+++ b/mm/mmap.c
86841@@ -36,6 +36,7 @@
86842 #include <linux/sched/sysctl.h>
86843 #include <linux/notifier.h>
86844 #include <linux/memory.h>
86845+#include <linux/random.h>
86846
86847 #include <asm/uaccess.h>
86848 #include <asm/cacheflush.h>
86849@@ -52,6 +53,16 @@
86850 #define arch_rebalance_pgtables(addr, len) (addr)
86851 #endif
86852
86853+static inline void verify_mm_writelocked(struct mm_struct *mm)
86854+{
86855+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
86856+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
86857+ up_read(&mm->mmap_sem);
86858+ BUG();
86859+ }
86860+#endif
86861+}
86862+
86863 static void unmap_region(struct mm_struct *mm,
86864 struct vm_area_struct *vma, struct vm_area_struct *prev,
86865 unsigned long start, unsigned long end);
86866@@ -71,16 +82,25 @@ static void unmap_region(struct mm_struct *mm,
86867 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
86868 *
86869 */
86870-pgprot_t protection_map[16] = {
86871+pgprot_t protection_map[16] __read_only = {
86872 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
86873 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
86874 };
86875
86876-pgprot_t vm_get_page_prot(unsigned long vm_flags)
86877+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
86878 {
86879- return __pgprot(pgprot_val(protection_map[vm_flags &
86880+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
86881 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
86882 pgprot_val(arch_vm_get_page_prot(vm_flags)));
86883+
86884+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
86885+ if (!(__supported_pte_mask & _PAGE_NX) &&
86886+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
86887+ (vm_flags & (VM_READ | VM_WRITE)))
86888+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
86889+#endif
86890+
86891+ return prot;
86892 }
86893 EXPORT_SYMBOL(vm_get_page_prot);
86894
86895@@ -89,6 +109,7 @@ int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
86896 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
86897 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
86898 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
86899+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
86900 /*
86901 * Make sure vm_committed_as in one cacheline and not cacheline shared with
86902 * other variables. It can be updated by several CPUs frequently.
86903@@ -247,6 +268,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
86904 struct vm_area_struct *next = vma->vm_next;
86905
86906 might_sleep();
86907+ BUG_ON(vma->vm_mirror);
86908 if (vma->vm_ops && vma->vm_ops->close)
86909 vma->vm_ops->close(vma);
86910 if (vma->vm_file)
86911@@ -291,6 +313,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
86912 * not page aligned -Ram Gupta
86913 */
86914 rlim = rlimit(RLIMIT_DATA);
86915+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
86916 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
86917 (mm->end_data - mm->start_data) > rlim)
86918 goto out;
86919@@ -933,6 +956,12 @@ static int
86920 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
86921 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
86922 {
86923+
86924+#ifdef CONFIG_PAX_SEGMEXEC
86925+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
86926+ return 0;
86927+#endif
86928+
86929 if (is_mergeable_vma(vma, file, vm_flags) &&
86930 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
86931 if (vma->vm_pgoff == vm_pgoff)
86932@@ -952,6 +981,12 @@ static int
86933 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
86934 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
86935 {
86936+
86937+#ifdef CONFIG_PAX_SEGMEXEC
86938+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
86939+ return 0;
86940+#endif
86941+
86942 if (is_mergeable_vma(vma, file, vm_flags) &&
86943 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
86944 pgoff_t vm_pglen;
86945@@ -994,13 +1029,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
86946 struct vm_area_struct *vma_merge(struct mm_struct *mm,
86947 struct vm_area_struct *prev, unsigned long addr,
86948 unsigned long end, unsigned long vm_flags,
86949- struct anon_vma *anon_vma, struct file *file,
86950+ struct anon_vma *anon_vma, struct file *file,
86951 pgoff_t pgoff, struct mempolicy *policy)
86952 {
86953 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
86954 struct vm_area_struct *area, *next;
86955 int err;
86956
86957+#ifdef CONFIG_PAX_SEGMEXEC
86958+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
86959+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
86960+
86961+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
86962+#endif
86963+
86964 /*
86965 * We later require that vma->vm_flags == vm_flags,
86966 * so this tests vma->vm_flags & VM_SPECIAL, too.
86967@@ -1016,6 +1058,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
86968 if (next && next->vm_end == end) /* cases 6, 7, 8 */
86969 next = next->vm_next;
86970
86971+#ifdef CONFIG_PAX_SEGMEXEC
86972+ if (prev)
86973+ prev_m = pax_find_mirror_vma(prev);
86974+ if (area)
86975+ area_m = pax_find_mirror_vma(area);
86976+ if (next)
86977+ next_m = pax_find_mirror_vma(next);
86978+#endif
86979+
86980 /*
86981 * Can it merge with the predecessor?
86982 */
86983@@ -1035,9 +1086,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
86984 /* cases 1, 6 */
86985 err = vma_adjust(prev, prev->vm_start,
86986 next->vm_end, prev->vm_pgoff, NULL);
86987- } else /* cases 2, 5, 7 */
86988+
86989+#ifdef CONFIG_PAX_SEGMEXEC
86990+ if (!err && prev_m)
86991+ err = vma_adjust(prev_m, prev_m->vm_start,
86992+ next_m->vm_end, prev_m->vm_pgoff, NULL);
86993+#endif
86994+
86995+ } else { /* cases 2, 5, 7 */
86996 err = vma_adjust(prev, prev->vm_start,
86997 end, prev->vm_pgoff, NULL);
86998+
86999+#ifdef CONFIG_PAX_SEGMEXEC
87000+ if (!err && prev_m)
87001+ err = vma_adjust(prev_m, prev_m->vm_start,
87002+ end_m, prev_m->vm_pgoff, NULL);
87003+#endif
87004+
87005+ }
87006 if (err)
87007 return NULL;
87008 khugepaged_enter_vma_merge(prev);
87009@@ -1051,12 +1117,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
87010 mpol_equal(policy, vma_policy(next)) &&
87011 can_vma_merge_before(next, vm_flags,
87012 anon_vma, file, pgoff+pglen)) {
87013- if (prev && addr < prev->vm_end) /* case 4 */
87014+ if (prev && addr < prev->vm_end) { /* case 4 */
87015 err = vma_adjust(prev, prev->vm_start,
87016 addr, prev->vm_pgoff, NULL);
87017- else /* cases 3, 8 */
87018+
87019+#ifdef CONFIG_PAX_SEGMEXEC
87020+ if (!err && prev_m)
87021+ err = vma_adjust(prev_m, prev_m->vm_start,
87022+ addr_m, prev_m->vm_pgoff, NULL);
87023+#endif
87024+
87025+ } else { /* cases 3, 8 */
87026 err = vma_adjust(area, addr, next->vm_end,
87027 next->vm_pgoff - pglen, NULL);
87028+
87029+#ifdef CONFIG_PAX_SEGMEXEC
87030+ if (!err && area_m)
87031+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
87032+ next_m->vm_pgoff - pglen, NULL);
87033+#endif
87034+
87035+ }
87036 if (err)
87037 return NULL;
87038 khugepaged_enter_vma_merge(area);
87039@@ -1165,8 +1246,10 @@ none:
87040 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
87041 struct file *file, long pages)
87042 {
87043- const unsigned long stack_flags
87044- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
87045+
87046+#ifdef CONFIG_PAX_RANDMMAP
87047+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
87048+#endif
87049
87050 mm->total_vm += pages;
87051
87052@@ -1174,7 +1257,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
87053 mm->shared_vm += pages;
87054 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
87055 mm->exec_vm += pages;
87056- } else if (flags & stack_flags)
87057+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
87058 mm->stack_vm += pages;
87059 }
87060 #endif /* CONFIG_PROC_FS */
87061@@ -1213,7 +1296,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
87062 * (the exception is when the underlying filesystem is noexec
87063 * mounted, in which case we dont add PROT_EXEC.)
87064 */
87065- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
87066+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
87067 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
87068 prot |= PROT_EXEC;
87069
87070@@ -1239,7 +1322,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
87071 /* Obtain the address to map to. we verify (or select) it and ensure
87072 * that it represents a valid section of the address space.
87073 */
87074- addr = get_unmapped_area(file, addr, len, pgoff, flags);
87075+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
87076 if (addr & ~PAGE_MASK)
87077 return addr;
87078
87079@@ -1250,6 +1333,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
87080 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
87081 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
87082
87083+#ifdef CONFIG_PAX_MPROTECT
87084+ if (mm->pax_flags & MF_PAX_MPROTECT) {
87085+
87086+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
87087+ if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
87088+ mm->binfmt->handle_mmap)
87089+ mm->binfmt->handle_mmap(file);
87090+#endif
87091+
87092+#ifndef CONFIG_PAX_MPROTECT_COMPAT
87093+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
87094+ gr_log_rwxmmap(file);
87095+
87096+#ifdef CONFIG_PAX_EMUPLT
87097+ vm_flags &= ~VM_EXEC;
87098+#else
87099+ return -EPERM;
87100+#endif
87101+
87102+ }
87103+
87104+ if (!(vm_flags & VM_EXEC))
87105+ vm_flags &= ~VM_MAYEXEC;
87106+#else
87107+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
87108+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
87109+#endif
87110+ else
87111+ vm_flags &= ~VM_MAYWRITE;
87112+ }
87113+#endif
87114+
87115+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
87116+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
87117+ vm_flags &= ~VM_PAGEEXEC;
87118+#endif
87119+
87120 if (flags & MAP_LOCKED)
87121 if (!can_do_mlock())
87122 return -EPERM;
87123@@ -1261,6 +1381,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
87124 locked += mm->locked_vm;
87125 lock_limit = rlimit(RLIMIT_MEMLOCK);
87126 lock_limit >>= PAGE_SHIFT;
87127+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
87128 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
87129 return -EAGAIN;
87130 }
87131@@ -1341,6 +1462,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
87132 vm_flags |= VM_NORESERVE;
87133 }
87134
87135+ if (!gr_acl_handle_mmap(file, prot))
87136+ return -EACCES;
87137+
87138 addr = mmap_region(file, addr, len, vm_flags, pgoff);
87139 if (!IS_ERR_VALUE(addr) &&
87140 ((vm_flags & VM_LOCKED) ||
87141@@ -1434,7 +1558,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
87142 vm_flags_t vm_flags = vma->vm_flags;
87143
87144 /* If it was private or non-writable, the write bit is already clear */
87145- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
87146+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
87147 return 0;
87148
87149 /* The backer wishes to know when pages are first written to? */
87150@@ -1482,7 +1606,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
87151 unsigned long charged = 0;
87152 struct inode *inode = file ? file_inode(file) : NULL;
87153
87154+#ifdef CONFIG_PAX_SEGMEXEC
87155+ struct vm_area_struct *vma_m = NULL;
87156+#endif
87157+
87158+ /*
87159+ * mm->mmap_sem is required to protect against another thread
87160+ * changing the mappings in case we sleep.
87161+ */
87162+ verify_mm_writelocked(mm);
87163+
87164 /* Check against address space limit. */
87165+
87166+#ifdef CONFIG_PAX_RANDMMAP
87167+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
87168+#endif
87169+
87170 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
87171 unsigned long nr_pages;
87172
87173@@ -1501,11 +1640,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
87174
87175 /* Clear old maps */
87176 error = -ENOMEM;
87177-munmap_back:
87178 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
87179 if (do_munmap(mm, addr, len))
87180 return -ENOMEM;
87181- goto munmap_back;
87182+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
87183 }
87184
87185 /*
87186@@ -1536,6 +1674,16 @@ munmap_back:
87187 goto unacct_error;
87188 }
87189
87190+#ifdef CONFIG_PAX_SEGMEXEC
87191+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
87192+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
87193+ if (!vma_m) {
87194+ error = -ENOMEM;
87195+ goto free_vma;
87196+ }
87197+ }
87198+#endif
87199+
87200 vma->vm_mm = mm;
87201 vma->vm_start = addr;
87202 vma->vm_end = addr + len;
87203@@ -1560,6 +1708,13 @@ munmap_back:
87204 if (error)
87205 goto unmap_and_free_vma;
87206
87207+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
87208+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
87209+ vma->vm_flags |= VM_PAGEEXEC;
87210+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
87211+ }
87212+#endif
87213+
87214 /* Can addr have changed??
87215 *
87216 * Answer: Yes, several device drivers can do it in their
87217@@ -1598,6 +1753,11 @@ munmap_back:
87218 vma_link(mm, vma, prev, rb_link, rb_parent);
87219 file = vma->vm_file;
87220
87221+#ifdef CONFIG_PAX_SEGMEXEC
87222+ if (vma_m)
87223+ BUG_ON(pax_mirror_vma(vma_m, vma));
87224+#endif
87225+
87226 /* Once vma denies write, undo our temporary denial count */
87227 if (correct_wcount)
87228 atomic_inc(&inode->i_writecount);
87229@@ -1605,6 +1765,7 @@ out:
87230 perf_event_mmap(vma);
87231
87232 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
87233+ track_exec_limit(mm, addr, addr + len, vm_flags);
87234 if (vm_flags & VM_LOCKED) {
87235 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
87236 vma == get_gate_vma(current->mm)))
87237@@ -1628,6 +1789,12 @@ unmap_and_free_vma:
87238 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
87239 charged = 0;
87240 free_vma:
87241+
87242+#ifdef CONFIG_PAX_SEGMEXEC
87243+ if (vma_m)
87244+ kmem_cache_free(vm_area_cachep, vma_m);
87245+#endif
87246+
87247 kmem_cache_free(vm_area_cachep, vma);
87248 unacct_error:
87249 if (charged)
87250@@ -1635,7 +1802,63 @@ unacct_error:
87251 return error;
87252 }
87253
87254-unsigned long unmapped_area(struct vm_unmapped_area_info *info)
87255+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
87256+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
87257+{
87258+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
87259+ return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
87260+
87261+ return 0;
87262+}
87263+#endif
87264+
87265+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
87266+{
87267+ if (!vma) {
87268+#ifdef CONFIG_STACK_GROWSUP
87269+ if (addr > sysctl_heap_stack_gap)
87270+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
87271+ else
87272+ vma = find_vma(current->mm, 0);
87273+ if (vma && (vma->vm_flags & VM_GROWSUP))
87274+ return false;
87275+#endif
87276+ return true;
87277+ }
87278+
87279+ if (addr + len > vma->vm_start)
87280+ return false;
87281+
87282+ if (vma->vm_flags & VM_GROWSDOWN)
87283+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
87284+#ifdef CONFIG_STACK_GROWSUP
87285+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
87286+ return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
87287+#endif
87288+ else if (offset)
87289+ return offset <= vma->vm_start - addr - len;
87290+
87291+ return true;
87292+}
87293+
87294+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
87295+{
87296+ if (vma->vm_start < len)
87297+ return -ENOMEM;
87298+
87299+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
87300+ if (offset <= vma->vm_start - len)
87301+ return vma->vm_start - len - offset;
87302+ else
87303+ return -ENOMEM;
87304+ }
87305+
87306+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
87307+ return vma->vm_start - len - sysctl_heap_stack_gap;
87308+ return -ENOMEM;
87309+}
87310+
87311+unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
87312 {
87313 /*
87314 * We implement the search by looking for an rbtree node that
87315@@ -1683,11 +1906,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
87316 }
87317 }
87318
87319- gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
87320+ gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
87321 check_current:
87322 /* Check if current node has a suitable gap */
87323 if (gap_start > high_limit)
87324 return -ENOMEM;
87325+
87326+ if (gap_end - gap_start > info->threadstack_offset)
87327+ gap_start += info->threadstack_offset;
87328+ else
87329+ gap_start = gap_end;
87330+
87331+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
87332+ if (gap_end - gap_start > sysctl_heap_stack_gap)
87333+ gap_start += sysctl_heap_stack_gap;
87334+ else
87335+ gap_start = gap_end;
87336+ }
87337+ if (vma->vm_flags & VM_GROWSDOWN) {
87338+ if (gap_end - gap_start > sysctl_heap_stack_gap)
87339+ gap_end -= sysctl_heap_stack_gap;
87340+ else
87341+ gap_end = gap_start;
87342+ }
87343 if (gap_end >= low_limit && gap_end - gap_start >= length)
87344 goto found;
87345
87346@@ -1737,7 +1978,7 @@ found:
87347 return gap_start;
87348 }
87349
87350-unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
87351+unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
87352 {
87353 struct mm_struct *mm = current->mm;
87354 struct vm_area_struct *vma;
87355@@ -1791,6 +2032,24 @@ check_current:
87356 gap_end = vma->vm_start;
87357 if (gap_end < low_limit)
87358 return -ENOMEM;
87359+
87360+ if (gap_end - gap_start > info->threadstack_offset)
87361+ gap_end -= info->threadstack_offset;
87362+ else
87363+ gap_end = gap_start;
87364+
87365+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
87366+ if (gap_end - gap_start > sysctl_heap_stack_gap)
87367+ gap_start += sysctl_heap_stack_gap;
87368+ else
87369+ gap_start = gap_end;
87370+ }
87371+ if (vma->vm_flags & VM_GROWSDOWN) {
87372+ if (gap_end - gap_start > sysctl_heap_stack_gap)
87373+ gap_end -= sysctl_heap_stack_gap;
87374+ else
87375+ gap_end = gap_start;
87376+ }
87377 if (gap_start <= high_limit && gap_end - gap_start >= length)
87378 goto found;
87379
87380@@ -1854,6 +2113,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
87381 struct mm_struct *mm = current->mm;
87382 struct vm_area_struct *vma;
87383 struct vm_unmapped_area_info info;
87384+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
87385
87386 if (len > TASK_SIZE)
87387 return -ENOMEM;
87388@@ -1861,19 +2121,29 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
87389 if (flags & MAP_FIXED)
87390 return addr;
87391
87392+#ifdef CONFIG_PAX_RANDMMAP
87393+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
87394+#endif
87395+
87396 if (addr) {
87397 addr = PAGE_ALIGN(addr);
87398 vma = find_vma(mm, addr);
87399- if (TASK_SIZE - len >= addr &&
87400- (!vma || addr + len <= vma->vm_start))
87401+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
87402 return addr;
87403 }
87404
87405 info.flags = 0;
87406 info.length = len;
87407 info.low_limit = TASK_UNMAPPED_BASE;
87408+
87409+#ifdef CONFIG_PAX_RANDMMAP
87410+ if (mm->pax_flags & MF_PAX_RANDMMAP)
87411+ info.low_limit += mm->delta_mmap;
87412+#endif
87413+
87414 info.high_limit = TASK_SIZE;
87415 info.align_mask = 0;
87416+ info.threadstack_offset = offset;
87417 return vm_unmapped_area(&info);
87418 }
87419 #endif
87420@@ -1892,6 +2162,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
87421 struct mm_struct *mm = current->mm;
87422 unsigned long addr = addr0;
87423 struct vm_unmapped_area_info info;
87424+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
87425
87426 /* requested length too big for entire address space */
87427 if (len > TASK_SIZE)
87428@@ -1900,12 +2171,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
87429 if (flags & MAP_FIXED)
87430 return addr;
87431
87432+#ifdef CONFIG_PAX_RANDMMAP
87433+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
87434+#endif
87435+
87436 /* requesting a specific address */
87437 if (addr) {
87438 addr = PAGE_ALIGN(addr);
87439 vma = find_vma(mm, addr);
87440- if (TASK_SIZE - len >= addr &&
87441- (!vma || addr + len <= vma->vm_start))
87442+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
87443 return addr;
87444 }
87445
87446@@ -1914,6 +2188,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
87447 info.low_limit = PAGE_SIZE;
87448 info.high_limit = mm->mmap_base;
87449 info.align_mask = 0;
87450+ info.threadstack_offset = offset;
87451 addr = vm_unmapped_area(&info);
87452
87453 /*
87454@@ -1926,6 +2201,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
87455 VM_BUG_ON(addr != -ENOMEM);
87456 info.flags = 0;
87457 info.low_limit = TASK_UNMAPPED_BASE;
87458+
87459+#ifdef CONFIG_PAX_RANDMMAP
87460+ if (mm->pax_flags & MF_PAX_RANDMMAP)
87461+ info.low_limit += mm->delta_mmap;
87462+#endif
87463+
87464 info.high_limit = TASK_SIZE;
87465 addr = vm_unmapped_area(&info);
87466 }
87467@@ -2027,6 +2308,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
87468 return vma;
87469 }
87470
87471+#ifdef CONFIG_PAX_SEGMEXEC
87472+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
87473+{
87474+ struct vm_area_struct *vma_m;
87475+
87476+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
87477+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
87478+ BUG_ON(vma->vm_mirror);
87479+ return NULL;
87480+ }
87481+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
87482+ vma_m = vma->vm_mirror;
87483+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
87484+ BUG_ON(vma->vm_file != vma_m->vm_file);
87485+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
87486+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
87487+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
87488+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
87489+ return vma_m;
87490+}
87491+#endif
87492+
87493 /*
87494 * Verify that the stack growth is acceptable and
87495 * update accounting. This is shared with both the
87496@@ -2043,6 +2346,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
87497 return -ENOMEM;
87498
87499 /* Stack limit test */
87500+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
87501 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
87502 return -ENOMEM;
87503
87504@@ -2053,6 +2357,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
87505 locked = mm->locked_vm + grow;
87506 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
87507 limit >>= PAGE_SHIFT;
87508+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
87509 if (locked > limit && !capable(CAP_IPC_LOCK))
87510 return -ENOMEM;
87511 }
87512@@ -2082,37 +2387,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
87513 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
87514 * vma is the last one with address > vma->vm_end. Have to extend vma.
87515 */
87516+#ifndef CONFIG_IA64
87517+static
87518+#endif
87519 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
87520 {
87521 int error;
87522+ bool locknext;
87523
87524 if (!(vma->vm_flags & VM_GROWSUP))
87525 return -EFAULT;
87526
87527+ /* Also guard against wrapping around to address 0. */
87528+ if (address < PAGE_ALIGN(address+1))
87529+ address = PAGE_ALIGN(address+1);
87530+ else
87531+ return -ENOMEM;
87532+
87533 /*
87534 * We must make sure the anon_vma is allocated
87535 * so that the anon_vma locking is not a noop.
87536 */
87537 if (unlikely(anon_vma_prepare(vma)))
87538 return -ENOMEM;
87539+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
87540+ if (locknext && anon_vma_prepare(vma->vm_next))
87541+ return -ENOMEM;
87542 vma_lock_anon_vma(vma);
87543+ if (locknext)
87544+ vma_lock_anon_vma(vma->vm_next);
87545
87546 /*
87547 * vma->vm_start/vm_end cannot change under us because the caller
87548 * is required to hold the mmap_sem in read mode. We need the
87549- * anon_vma lock to serialize against concurrent expand_stacks.
87550- * Also guard against wrapping around to address 0.
87551+ * anon_vma locks to serialize against concurrent expand_stacks
87552+ * and expand_upwards.
87553 */
87554- if (address < PAGE_ALIGN(address+4))
87555- address = PAGE_ALIGN(address+4);
87556- else {
87557- vma_unlock_anon_vma(vma);
87558- return -ENOMEM;
87559- }
87560 error = 0;
87561
87562 /* Somebody else might have raced and expanded it already */
87563- if (address > vma->vm_end) {
87564+ 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)
87565+ error = -ENOMEM;
87566+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
87567 unsigned long size, grow;
87568
87569 size = address - vma->vm_start;
87570@@ -2147,6 +2463,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
87571 }
87572 }
87573 }
87574+ if (locknext)
87575+ vma_unlock_anon_vma(vma->vm_next);
87576 vma_unlock_anon_vma(vma);
87577 khugepaged_enter_vma_merge(vma);
87578 validate_mm(vma->vm_mm);
87579@@ -2161,6 +2479,8 @@ int expand_downwards(struct vm_area_struct *vma,
87580 unsigned long address)
87581 {
87582 int error;
87583+ bool lockprev = false;
87584+ struct vm_area_struct *prev;
87585
87586 /*
87587 * We must make sure the anon_vma is allocated
87588@@ -2174,6 +2494,15 @@ int expand_downwards(struct vm_area_struct *vma,
87589 if (error)
87590 return error;
87591
87592+ prev = vma->vm_prev;
87593+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
87594+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
87595+#endif
87596+ if (lockprev && anon_vma_prepare(prev))
87597+ return -ENOMEM;
87598+ if (lockprev)
87599+ vma_lock_anon_vma(prev);
87600+
87601 vma_lock_anon_vma(vma);
87602
87603 /*
87604@@ -2183,9 +2512,17 @@ int expand_downwards(struct vm_area_struct *vma,
87605 */
87606
87607 /* Somebody else might have raced and expanded it already */
87608- if (address < vma->vm_start) {
87609+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
87610+ error = -ENOMEM;
87611+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
87612 unsigned long size, grow;
87613
87614+#ifdef CONFIG_PAX_SEGMEXEC
87615+ struct vm_area_struct *vma_m;
87616+
87617+ vma_m = pax_find_mirror_vma(vma);
87618+#endif
87619+
87620 size = vma->vm_end - address;
87621 grow = (vma->vm_start - address) >> PAGE_SHIFT;
87622
87623@@ -2210,13 +2547,27 @@ int expand_downwards(struct vm_area_struct *vma,
87624 vma->vm_pgoff -= grow;
87625 anon_vma_interval_tree_post_update_vma(vma);
87626 vma_gap_update(vma);
87627+
87628+#ifdef CONFIG_PAX_SEGMEXEC
87629+ if (vma_m) {
87630+ anon_vma_interval_tree_pre_update_vma(vma_m);
87631+ vma_m->vm_start -= grow << PAGE_SHIFT;
87632+ vma_m->vm_pgoff -= grow;
87633+ anon_vma_interval_tree_post_update_vma(vma_m);
87634+ vma_gap_update(vma_m);
87635+ }
87636+#endif
87637+
87638 spin_unlock(&vma->vm_mm->page_table_lock);
87639
87640+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
87641 perf_event_mmap(vma);
87642 }
87643 }
87644 }
87645 vma_unlock_anon_vma(vma);
87646+ if (lockprev)
87647+ vma_unlock_anon_vma(prev);
87648 khugepaged_enter_vma_merge(vma);
87649 validate_mm(vma->vm_mm);
87650 return error;
87651@@ -2314,6 +2665,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
87652 do {
87653 long nrpages = vma_pages(vma);
87654
87655+#ifdef CONFIG_PAX_SEGMEXEC
87656+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
87657+ vma = remove_vma(vma);
87658+ continue;
87659+ }
87660+#endif
87661+
87662 if (vma->vm_flags & VM_ACCOUNT)
87663 nr_accounted += nrpages;
87664 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
87665@@ -2358,6 +2716,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
87666 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
87667 vma->vm_prev = NULL;
87668 do {
87669+
87670+#ifdef CONFIG_PAX_SEGMEXEC
87671+ if (vma->vm_mirror) {
87672+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
87673+ vma->vm_mirror->vm_mirror = NULL;
87674+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
87675+ vma->vm_mirror = NULL;
87676+ }
87677+#endif
87678+
87679 vma_rb_erase(vma, &mm->mm_rb);
87680 mm->map_count--;
87681 tail_vma = vma;
87682@@ -2384,14 +2752,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
87683 struct vm_area_struct *new;
87684 int err = -ENOMEM;
87685
87686+#ifdef CONFIG_PAX_SEGMEXEC
87687+ struct vm_area_struct *vma_m, *new_m = NULL;
87688+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
87689+#endif
87690+
87691 if (is_vm_hugetlb_page(vma) && (addr &
87692 ~(huge_page_mask(hstate_vma(vma)))))
87693 return -EINVAL;
87694
87695+#ifdef CONFIG_PAX_SEGMEXEC
87696+ vma_m = pax_find_mirror_vma(vma);
87697+#endif
87698+
87699 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
87700 if (!new)
87701 goto out_err;
87702
87703+#ifdef CONFIG_PAX_SEGMEXEC
87704+ if (vma_m) {
87705+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
87706+ if (!new_m) {
87707+ kmem_cache_free(vm_area_cachep, new);
87708+ goto out_err;
87709+ }
87710+ }
87711+#endif
87712+
87713 /* most fields are the same, copy all, and then fixup */
87714 *new = *vma;
87715
87716@@ -2404,6 +2791,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
87717 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
87718 }
87719
87720+#ifdef CONFIG_PAX_SEGMEXEC
87721+ if (vma_m) {
87722+ *new_m = *vma_m;
87723+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
87724+ new_m->vm_mirror = new;
87725+ new->vm_mirror = new_m;
87726+
87727+ if (new_below)
87728+ new_m->vm_end = addr_m;
87729+ else {
87730+ new_m->vm_start = addr_m;
87731+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
87732+ }
87733+ }
87734+#endif
87735+
87736 pol = mpol_dup(vma_policy(vma));
87737 if (IS_ERR(pol)) {
87738 err = PTR_ERR(pol);
87739@@ -2426,6 +2829,36 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
87740 else
87741 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
87742
87743+#ifdef CONFIG_PAX_SEGMEXEC
87744+ if (!err && vma_m) {
87745+ if (anon_vma_clone(new_m, vma_m))
87746+ goto out_free_mpol;
87747+
87748+ mpol_get(pol);
87749+ vma_set_policy(new_m, pol);
87750+
87751+ if (new_m->vm_file)
87752+ get_file(new_m->vm_file);
87753+
87754+ if (new_m->vm_ops && new_m->vm_ops->open)
87755+ new_m->vm_ops->open(new_m);
87756+
87757+ if (new_below)
87758+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
87759+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
87760+ else
87761+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
87762+
87763+ if (err) {
87764+ if (new_m->vm_ops && new_m->vm_ops->close)
87765+ new_m->vm_ops->close(new_m);
87766+ if (new_m->vm_file)
87767+ fput(new_m->vm_file);
87768+ mpol_put(pol);
87769+ }
87770+ }
87771+#endif
87772+
87773 /* Success. */
87774 if (!err)
87775 return 0;
87776@@ -2435,10 +2868,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
87777 new->vm_ops->close(new);
87778 if (new->vm_file)
87779 fput(new->vm_file);
87780- unlink_anon_vmas(new);
87781 out_free_mpol:
87782 mpol_put(pol);
87783 out_free_vma:
87784+
87785+#ifdef CONFIG_PAX_SEGMEXEC
87786+ if (new_m) {
87787+ unlink_anon_vmas(new_m);
87788+ kmem_cache_free(vm_area_cachep, new_m);
87789+ }
87790+#endif
87791+
87792+ unlink_anon_vmas(new);
87793 kmem_cache_free(vm_area_cachep, new);
87794 out_err:
87795 return err;
87796@@ -2451,6 +2892,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
87797 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
87798 unsigned long addr, int new_below)
87799 {
87800+
87801+#ifdef CONFIG_PAX_SEGMEXEC
87802+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
87803+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
87804+ if (mm->map_count >= sysctl_max_map_count-1)
87805+ return -ENOMEM;
87806+ } else
87807+#endif
87808+
87809 if (mm->map_count >= sysctl_max_map_count)
87810 return -ENOMEM;
87811
87812@@ -2462,11 +2912,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
87813 * work. This now handles partial unmappings.
87814 * Jeremy Fitzhardinge <jeremy@goop.org>
87815 */
87816+#ifdef CONFIG_PAX_SEGMEXEC
87817 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
87818 {
87819+ int ret = __do_munmap(mm, start, len);
87820+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
87821+ return ret;
87822+
87823+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
87824+}
87825+
87826+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
87827+#else
87828+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
87829+#endif
87830+{
87831 unsigned long end;
87832 struct vm_area_struct *vma, *prev, *last;
87833
87834+ /*
87835+ * mm->mmap_sem is required to protect against another thread
87836+ * changing the mappings in case we sleep.
87837+ */
87838+ verify_mm_writelocked(mm);
87839+
87840 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
87841 return -EINVAL;
87842
87843@@ -2541,6 +3010,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
87844 /* Fix up all other VM information */
87845 remove_vma_list(mm, vma);
87846
87847+ track_exec_limit(mm, start, end, 0UL);
87848+
87849 return 0;
87850 }
87851
87852@@ -2549,6 +3020,13 @@ int vm_munmap(unsigned long start, size_t len)
87853 int ret;
87854 struct mm_struct *mm = current->mm;
87855
87856+
87857+#ifdef CONFIG_PAX_SEGMEXEC
87858+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
87859+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
87860+ return -EINVAL;
87861+#endif
87862+
87863 down_write(&mm->mmap_sem);
87864 ret = do_munmap(mm, start, len);
87865 up_write(&mm->mmap_sem);
87866@@ -2562,16 +3040,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
87867 return vm_munmap(addr, len);
87868 }
87869
87870-static inline void verify_mm_writelocked(struct mm_struct *mm)
87871-{
87872-#ifdef CONFIG_DEBUG_VM
87873- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
87874- WARN_ON(1);
87875- up_read(&mm->mmap_sem);
87876- }
87877-#endif
87878-}
87879-
87880 /*
87881 * this is really a simplified "do_mmap". it only handles
87882 * anonymous maps. eventually we may be able to do some
87883@@ -2585,6 +3053,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
87884 struct rb_node ** rb_link, * rb_parent;
87885 pgoff_t pgoff = addr >> PAGE_SHIFT;
87886 int error;
87887+ unsigned long charged;
87888
87889 len = PAGE_ALIGN(len);
87890 if (!len)
87891@@ -2592,16 +3061,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
87892
87893 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
87894
87895+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
87896+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
87897+ flags &= ~VM_EXEC;
87898+
87899+#ifdef CONFIG_PAX_MPROTECT
87900+ if (mm->pax_flags & MF_PAX_MPROTECT)
87901+ flags &= ~VM_MAYEXEC;
87902+#endif
87903+
87904+ }
87905+#endif
87906+
87907 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
87908 if (error & ~PAGE_MASK)
87909 return error;
87910
87911+ charged = len >> PAGE_SHIFT;
87912+
87913 /*
87914 * mlock MCL_FUTURE?
87915 */
87916 if (mm->def_flags & VM_LOCKED) {
87917 unsigned long locked, lock_limit;
87918- locked = len >> PAGE_SHIFT;
87919+ locked = charged;
87920 locked += mm->locked_vm;
87921 lock_limit = rlimit(RLIMIT_MEMLOCK);
87922 lock_limit >>= PAGE_SHIFT;
87923@@ -2618,21 +3101,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
87924 /*
87925 * Clear old maps. this also does some error checking for us
87926 */
87927- munmap_back:
87928 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
87929 if (do_munmap(mm, addr, len))
87930 return -ENOMEM;
87931- goto munmap_back;
87932+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
87933 }
87934
87935 /* Check against address space limits *after* clearing old maps... */
87936- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
87937+ if (!may_expand_vm(mm, charged))
87938 return -ENOMEM;
87939
87940 if (mm->map_count > sysctl_max_map_count)
87941 return -ENOMEM;
87942
87943- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
87944+ if (security_vm_enough_memory_mm(mm, charged))
87945 return -ENOMEM;
87946
87947 /* Can we just expand an old private anonymous mapping? */
87948@@ -2646,7 +3128,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
87949 */
87950 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
87951 if (!vma) {
87952- vm_unacct_memory(len >> PAGE_SHIFT);
87953+ vm_unacct_memory(charged);
87954 return -ENOMEM;
87955 }
87956
87957@@ -2660,9 +3142,10 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
87958 vma_link(mm, vma, prev, rb_link, rb_parent);
87959 out:
87960 perf_event_mmap(vma);
87961- mm->total_vm += len >> PAGE_SHIFT;
87962+ mm->total_vm += charged;
87963 if (flags & VM_LOCKED)
87964- mm->locked_vm += (len >> PAGE_SHIFT);
87965+ mm->locked_vm += charged;
87966+ track_exec_limit(mm, addr, addr + len, flags);
87967 return addr;
87968 }
87969
87970@@ -2724,6 +3207,7 @@ void exit_mmap(struct mm_struct *mm)
87971 while (vma) {
87972 if (vma->vm_flags & VM_ACCOUNT)
87973 nr_accounted += vma_pages(vma);
87974+ vma->vm_mirror = NULL;
87975 vma = remove_vma(vma);
87976 }
87977 vm_unacct_memory(nr_accounted);
87978@@ -2740,6 +3224,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
87979 struct vm_area_struct *prev;
87980 struct rb_node **rb_link, *rb_parent;
87981
87982+#ifdef CONFIG_PAX_SEGMEXEC
87983+ struct vm_area_struct *vma_m = NULL;
87984+#endif
87985+
87986+ if (security_mmap_addr(vma->vm_start))
87987+ return -EPERM;
87988+
87989 /*
87990 * The vm_pgoff of a purely anonymous vma should be irrelevant
87991 * until its first write fault, when page's anon_vma and index
87992@@ -2763,7 +3254,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
87993 security_vm_enough_memory_mm(mm, vma_pages(vma)))
87994 return -ENOMEM;
87995
87996+#ifdef CONFIG_PAX_SEGMEXEC
87997+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
87998+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
87999+ if (!vma_m)
88000+ return -ENOMEM;
88001+ }
88002+#endif
88003+
88004 vma_link(mm, vma, prev, rb_link, rb_parent);
88005+
88006+#ifdef CONFIG_PAX_SEGMEXEC
88007+ if (vma_m)
88008+ BUG_ON(pax_mirror_vma(vma_m, vma));
88009+#endif
88010+
88011 return 0;
88012 }
88013
88014@@ -2783,6 +3288,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
88015 struct mempolicy *pol;
88016 bool faulted_in_anon_vma = true;
88017
88018+ BUG_ON(vma->vm_mirror);
88019+
88020 /*
88021 * If anonymous vma has not yet been faulted, update new pgoff
88022 * to match new location, to increase its chance of merging.
88023@@ -2849,6 +3356,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
88024 return NULL;
88025 }
88026
88027+#ifdef CONFIG_PAX_SEGMEXEC
88028+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
88029+{
88030+ struct vm_area_struct *prev_m;
88031+ struct rb_node **rb_link_m, *rb_parent_m;
88032+ struct mempolicy *pol_m;
88033+
88034+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
88035+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
88036+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
88037+ *vma_m = *vma;
88038+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
88039+ if (anon_vma_clone(vma_m, vma))
88040+ return -ENOMEM;
88041+ pol_m = vma_policy(vma_m);
88042+ mpol_get(pol_m);
88043+ vma_set_policy(vma_m, pol_m);
88044+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
88045+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
88046+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
88047+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
88048+ if (vma_m->vm_file)
88049+ get_file(vma_m->vm_file);
88050+ if (vma_m->vm_ops && vma_m->vm_ops->open)
88051+ vma_m->vm_ops->open(vma_m);
88052+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
88053+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
88054+ vma_m->vm_mirror = vma;
88055+ vma->vm_mirror = vma_m;
88056+ return 0;
88057+}
88058+#endif
88059+
88060 /*
88061 * Return true if the calling process may expand its vm space by the passed
88062 * number of pages
88063@@ -2860,6 +3400,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
88064
88065 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
88066
88067+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
88068 if (cur + npages > lim)
88069 return 0;
88070 return 1;
88071@@ -2930,6 +3471,22 @@ int install_special_mapping(struct mm_struct *mm,
88072 vma->vm_start = addr;
88073 vma->vm_end = addr + len;
88074
88075+#ifdef CONFIG_PAX_MPROTECT
88076+ if (mm->pax_flags & MF_PAX_MPROTECT) {
88077+#ifndef CONFIG_PAX_MPROTECT_COMPAT
88078+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
88079+ return -EPERM;
88080+ if (!(vm_flags & VM_EXEC))
88081+ vm_flags &= ~VM_MAYEXEC;
88082+#else
88083+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
88084+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
88085+#endif
88086+ else
88087+ vm_flags &= ~VM_MAYWRITE;
88088+ }
88089+#endif
88090+
88091 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
88092 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
88093
88094diff --git a/mm/mprotect.c b/mm/mprotect.c
88095index 94722a4..e661e29 100644
88096--- a/mm/mprotect.c
88097+++ b/mm/mprotect.c
88098@@ -23,10 +23,18 @@
88099 #include <linux/mmu_notifier.h>
88100 #include <linux/migrate.h>
88101 #include <linux/perf_event.h>
88102+#include <linux/sched/sysctl.h>
88103+
88104+#ifdef CONFIG_PAX_MPROTECT
88105+#include <linux/elf.h>
88106+#include <linux/binfmts.h>
88107+#endif
88108+
88109 #include <asm/uaccess.h>
88110 #include <asm/pgtable.h>
88111 #include <asm/cacheflush.h>
88112 #include <asm/tlbflush.h>
88113+#include <asm/mmu_context.h>
88114
88115 #ifndef pgprot_modify
88116 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
88117@@ -233,6 +241,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
88118 return pages;
88119 }
88120
88121+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
88122+/* called while holding the mmap semaphor for writing except stack expansion */
88123+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
88124+{
88125+ unsigned long oldlimit, newlimit = 0UL;
88126+
88127+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
88128+ return;
88129+
88130+ spin_lock(&mm->page_table_lock);
88131+ oldlimit = mm->context.user_cs_limit;
88132+ if ((prot & VM_EXEC) && oldlimit < end)
88133+ /* USER_CS limit moved up */
88134+ newlimit = end;
88135+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
88136+ /* USER_CS limit moved down */
88137+ newlimit = start;
88138+
88139+ if (newlimit) {
88140+ mm->context.user_cs_limit = newlimit;
88141+
88142+#ifdef CONFIG_SMP
88143+ wmb();
88144+ cpus_clear(mm->context.cpu_user_cs_mask);
88145+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
88146+#endif
88147+
88148+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
88149+ }
88150+ spin_unlock(&mm->page_table_lock);
88151+ if (newlimit == end) {
88152+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
88153+
88154+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
88155+ if (is_vm_hugetlb_page(vma))
88156+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
88157+ else
88158+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
88159+ }
88160+}
88161+#endif
88162+
88163 int
88164 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
88165 unsigned long start, unsigned long end, unsigned long newflags)
88166@@ -245,11 +295,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
88167 int error;
88168 int dirty_accountable = 0;
88169
88170+#ifdef CONFIG_PAX_SEGMEXEC
88171+ struct vm_area_struct *vma_m = NULL;
88172+ unsigned long start_m, end_m;
88173+
88174+ start_m = start + SEGMEXEC_TASK_SIZE;
88175+ end_m = end + SEGMEXEC_TASK_SIZE;
88176+#endif
88177+
88178 if (newflags == oldflags) {
88179 *pprev = vma;
88180 return 0;
88181 }
88182
88183+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
88184+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
88185+
88186+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
88187+ return -ENOMEM;
88188+
88189+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
88190+ return -ENOMEM;
88191+ }
88192+
88193 /*
88194 * If we make a private mapping writable we increase our commit;
88195 * but (without finer accounting) cannot reduce our commit if we
88196@@ -266,6 +334,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
88197 }
88198 }
88199
88200+#ifdef CONFIG_PAX_SEGMEXEC
88201+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
88202+ if (start != vma->vm_start) {
88203+ error = split_vma(mm, vma, start, 1);
88204+ if (error)
88205+ goto fail;
88206+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
88207+ *pprev = (*pprev)->vm_next;
88208+ }
88209+
88210+ if (end != vma->vm_end) {
88211+ error = split_vma(mm, vma, end, 0);
88212+ if (error)
88213+ goto fail;
88214+ }
88215+
88216+ if (pax_find_mirror_vma(vma)) {
88217+ error = __do_munmap(mm, start_m, end_m - start_m);
88218+ if (error)
88219+ goto fail;
88220+ } else {
88221+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
88222+ if (!vma_m) {
88223+ error = -ENOMEM;
88224+ goto fail;
88225+ }
88226+ vma->vm_flags = newflags;
88227+ error = pax_mirror_vma(vma_m, vma);
88228+ if (error) {
88229+ vma->vm_flags = oldflags;
88230+ goto fail;
88231+ }
88232+ }
88233+ }
88234+#endif
88235+
88236 /*
88237 * First try to merge with previous and/or next vma.
88238 */
88239@@ -296,9 +400,21 @@ success:
88240 * vm_flags and vm_page_prot are protected by the mmap_sem
88241 * held in write mode.
88242 */
88243+
88244+#ifdef CONFIG_PAX_SEGMEXEC
88245+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
88246+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
88247+#endif
88248+
88249 vma->vm_flags = newflags;
88250+
88251+#ifdef CONFIG_PAX_MPROTECT
88252+ if (mm->binfmt && mm->binfmt->handle_mprotect)
88253+ mm->binfmt->handle_mprotect(vma, newflags);
88254+#endif
88255+
88256 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
88257- vm_get_page_prot(newflags));
88258+ vm_get_page_prot(vma->vm_flags));
88259
88260 if (vma_wants_writenotify(vma)) {
88261 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
88262@@ -337,6 +453,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
88263 end = start + len;
88264 if (end <= start)
88265 return -ENOMEM;
88266+
88267+#ifdef CONFIG_PAX_SEGMEXEC
88268+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
88269+ if (end > SEGMEXEC_TASK_SIZE)
88270+ return -EINVAL;
88271+ } else
88272+#endif
88273+
88274+ if (end > TASK_SIZE)
88275+ return -EINVAL;
88276+
88277 if (!arch_validate_prot(prot))
88278 return -EINVAL;
88279
88280@@ -344,7 +471,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
88281 /*
88282 * Does the application expect PROT_READ to imply PROT_EXEC:
88283 */
88284- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
88285+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
88286 prot |= PROT_EXEC;
88287
88288 vm_flags = calc_vm_prot_bits(prot);
88289@@ -376,6 +503,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
88290 if (start > vma->vm_start)
88291 prev = vma;
88292
88293+#ifdef CONFIG_PAX_MPROTECT
88294+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
88295+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
88296+#endif
88297+
88298 for (nstart = start ; ; ) {
88299 unsigned long newflags;
88300
88301@@ -386,6 +518,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
88302
88303 /* newflags >> 4 shift VM_MAY% in place of VM_% */
88304 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
88305+ if (prot & (PROT_WRITE | PROT_EXEC))
88306+ gr_log_rwxmprotect(vma);
88307+
88308+ error = -EACCES;
88309+ goto out;
88310+ }
88311+
88312+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
88313 error = -EACCES;
88314 goto out;
88315 }
88316@@ -400,6 +540,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
88317 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
88318 if (error)
88319 goto out;
88320+
88321+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
88322+
88323 nstart = tmp;
88324
88325 if (nstart < prev->vm_end)
88326diff --git a/mm/mremap.c b/mm/mremap.c
88327index 0843feb..5607f47 100644
88328--- a/mm/mremap.c
88329+++ b/mm/mremap.c
88330@@ -25,6 +25,7 @@
88331 #include <asm/uaccess.h>
88332 #include <asm/cacheflush.h>
88333 #include <asm/tlbflush.h>
88334+#include <asm/pgalloc.h>
88335
88336 #include "internal.h"
88337
88338@@ -62,8 +63,10 @@ static pmd_t *alloc_new_pmd(struct mm_struct *mm, struct vm_area_struct *vma,
88339 return NULL;
88340
88341 pmd = pmd_alloc(mm, pud, addr);
88342- if (!pmd)
88343+ if (!pmd) {
88344+ pud_free(mm, pud);
88345 return NULL;
88346+ }
88347
88348 VM_BUG_ON(pmd_trans_huge(*pmd));
88349
88350@@ -144,6 +147,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
88351 continue;
88352 pte = ptep_get_and_clear(mm, old_addr, old_pte);
88353 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
88354+
88355+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
88356+ if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
88357+ pte = pte_exprotect(pte);
88358+#endif
88359+
88360 pte = move_soft_dirty_pte(pte);
88361 set_pte_at(mm, new_addr, new_pte, pte);
88362 }
88363@@ -337,6 +346,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
88364 if (is_vm_hugetlb_page(vma))
88365 goto Einval;
88366
88367+#ifdef CONFIG_PAX_SEGMEXEC
88368+ if (pax_find_mirror_vma(vma))
88369+ goto Einval;
88370+#endif
88371+
88372 /* We can't remap across vm area boundaries */
88373 if (old_len > vma->vm_end - addr)
88374 goto Efault;
88375@@ -392,20 +406,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
88376 unsigned long ret = -EINVAL;
88377 unsigned long charged = 0;
88378 unsigned long map_flags;
88379+ unsigned long pax_task_size = TASK_SIZE;
88380
88381 if (new_addr & ~PAGE_MASK)
88382 goto out;
88383
88384- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
88385+#ifdef CONFIG_PAX_SEGMEXEC
88386+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
88387+ pax_task_size = SEGMEXEC_TASK_SIZE;
88388+#endif
88389+
88390+ pax_task_size -= PAGE_SIZE;
88391+
88392+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
88393 goto out;
88394
88395 /* Check if the location we're moving into overlaps the
88396 * old location at all, and fail if it does.
88397 */
88398- if ((new_addr <= addr) && (new_addr+new_len) > addr)
88399- goto out;
88400-
88401- if ((addr <= new_addr) && (addr+old_len) > new_addr)
88402+ if (addr + old_len > new_addr && new_addr + new_len > addr)
88403 goto out;
88404
88405 ret = do_munmap(mm, new_addr, new_len);
88406@@ -474,6 +493,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
88407 unsigned long ret = -EINVAL;
88408 unsigned long charged = 0;
88409 bool locked = false;
88410+ unsigned long pax_task_size = TASK_SIZE;
88411
88412 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
88413 return ret;
88414@@ -495,6 +515,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
88415 if (!new_len)
88416 return ret;
88417
88418+#ifdef CONFIG_PAX_SEGMEXEC
88419+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
88420+ pax_task_size = SEGMEXEC_TASK_SIZE;
88421+#endif
88422+
88423+ pax_task_size -= PAGE_SIZE;
88424+
88425+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
88426+ old_len > pax_task_size || addr > pax_task_size-old_len)
88427+ return ret;
88428+
88429 down_write(&current->mm->mmap_sem);
88430
88431 if (flags & MREMAP_FIXED) {
88432@@ -545,6 +576,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
88433 new_addr = addr;
88434 }
88435 ret = addr;
88436+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
88437 goto out;
88438 }
88439 }
88440@@ -568,7 +600,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
88441 goto out;
88442 }
88443
88444+ map_flags = vma->vm_flags;
88445 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
88446+ if (!(ret & ~PAGE_MASK)) {
88447+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
88448+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
88449+ }
88450 }
88451 out:
88452 if (ret & ~PAGE_MASK)
88453diff --git a/mm/nommu.c b/mm/nommu.c
88454index ecd1f15..77039bd 100644
88455--- a/mm/nommu.c
88456+++ b/mm/nommu.c
88457@@ -64,7 +64,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
88458 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
88459 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
88460 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
88461-int heap_stack_gap = 0;
88462
88463 atomic_long_t mmap_pages_allocated;
88464
88465@@ -844,15 +843,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
88466 EXPORT_SYMBOL(find_vma);
88467
88468 /*
88469- * find a VMA
88470- * - we don't extend stack VMAs under NOMMU conditions
88471- */
88472-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
88473-{
88474- return find_vma(mm, addr);
88475-}
88476-
88477-/*
88478 * expand a stack to a given address
88479 * - not supported under NOMMU conditions
88480 */
88481@@ -1563,6 +1553,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
88482
88483 /* most fields are the same, copy all, and then fixup */
88484 *new = *vma;
88485+ INIT_LIST_HEAD(&new->anon_vma_chain);
88486 *region = *vma->vm_region;
88487 new->vm_region = region;
88488
88489@@ -1993,8 +1984,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
88490 }
88491 EXPORT_SYMBOL(generic_file_remap_pages);
88492
88493-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
88494- unsigned long addr, void *buf, int len, int write)
88495+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
88496+ unsigned long addr, void *buf, size_t len, int write)
88497 {
88498 struct vm_area_struct *vma;
88499
88500@@ -2035,8 +2026,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
88501 *
88502 * The caller must hold a reference on @mm.
88503 */
88504-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
88505- void *buf, int len, int write)
88506+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
88507+ void *buf, size_t len, int write)
88508 {
88509 return __access_remote_vm(NULL, mm, addr, buf, len, write);
88510 }
88511@@ -2045,7 +2036,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
88512 * Access another process' address space.
88513 * - source/target buffer must be kernel space
88514 */
88515-int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
88516+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
88517 {
88518 struct mm_struct *mm;
88519
88520diff --git a/mm/page-writeback.c b/mm/page-writeback.c
88521index 3f0c895..60cd104 100644
88522--- a/mm/page-writeback.c
88523+++ b/mm/page-writeback.c
88524@@ -659,7 +659,7 @@ unsigned long bdi_dirty_limit(struct backing_dev_info *bdi, unsigned long dirty)
88525 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
88526 * - the bdi dirty thresh drops quickly due to change of JBOD workload
88527 */
88528-static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
88529+static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
88530 unsigned long thresh,
88531 unsigned long bg_thresh,
88532 unsigned long dirty,
88533diff --git a/mm/page_alloc.c b/mm/page_alloc.c
88534index b100255..fba1254 100644
88535--- a/mm/page_alloc.c
88536+++ b/mm/page_alloc.c
88537@@ -60,6 +60,7 @@
88538 #include <linux/page-debug-flags.h>
88539 #include <linux/hugetlb.h>
88540 #include <linux/sched/rt.h>
88541+#include <linux/random.h>
88542
88543 #include <asm/sections.h>
88544 #include <asm/tlbflush.h>
88545@@ -353,7 +354,7 @@ out:
88546 * This usage means that zero-order pages may not be compound.
88547 */
88548
88549-static void free_compound_page(struct page *page)
88550+void free_compound_page(struct page *page)
88551 {
88552 __free_pages_ok(page, compound_order(page));
88553 }
88554@@ -710,6 +711,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
88555 int i;
88556 int bad = 0;
88557
88558+#ifdef CONFIG_PAX_MEMORY_SANITIZE
88559+ unsigned long index = 1UL << order;
88560+#endif
88561+
88562 trace_mm_page_free(page, order);
88563 kmemcheck_free_shadow(page, order);
88564
88565@@ -725,6 +730,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
88566 debug_check_no_obj_freed(page_address(page),
88567 PAGE_SIZE << order);
88568 }
88569+
88570+#ifdef CONFIG_PAX_MEMORY_SANITIZE
88571+ for (; index; --index)
88572+ sanitize_highpage(page + index - 1);
88573+#endif
88574+
88575 arch_free_page(page, order);
88576 kernel_map_pages(page, 1 << order, 0);
88577
88578@@ -747,6 +758,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
88579 local_irq_restore(flags);
88580 }
88581
88582+#ifdef CONFIG_PAX_LATENT_ENTROPY
88583+bool __meminitdata extra_latent_entropy;
88584+
88585+static int __init setup_pax_extra_latent_entropy(char *str)
88586+{
88587+ extra_latent_entropy = true;
88588+ return 0;
88589+}
88590+early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
88591+
88592+volatile u64 latent_entropy;
88593+EXPORT_SYMBOL(latent_entropy);
88594+#endif
88595+
88596 void __init __free_pages_bootmem(struct page *page, unsigned int order)
88597 {
88598 unsigned int nr_pages = 1 << order;
88599@@ -762,6 +787,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
88600 set_page_count(p, 0);
88601 }
88602
88603+#ifdef CONFIG_PAX_LATENT_ENTROPY
88604+ if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
88605+ u64 hash = 0;
88606+ size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
88607+ const u64 *data = lowmem_page_address(page);
88608+
88609+ for (index = 0; index < end; index++)
88610+ hash ^= hash + data[index];
88611+ latent_entropy ^= hash;
88612+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
88613+ }
88614+#endif
88615+
88616 page_zone(page)->managed_pages += 1 << order;
88617 set_page_refcounted(page);
88618 __free_pages(page, order);
88619@@ -867,8 +905,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
88620 arch_alloc_page(page, order);
88621 kernel_map_pages(page, 1 << order, 1);
88622
88623+#ifndef CONFIG_PAX_MEMORY_SANITIZE
88624 if (gfp_flags & __GFP_ZERO)
88625 prep_zero_page(page, order, gfp_flags);
88626+#endif
88627
88628 if (order && (gfp_flags & __GFP_COMP))
88629 prep_compound_page(page, order);
88630diff --git a/mm/page_io.c b/mm/page_io.c
88631index ba05b64..ef2f314 100644
88632--- a/mm/page_io.c
88633+++ b/mm/page_io.c
88634@@ -260,7 +260,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
88635 struct file *swap_file = sis->swap_file;
88636 struct address_space *mapping = swap_file->f_mapping;
88637 struct iovec iov = {
88638- .iov_base = kmap(page),
88639+ .iov_base = (void __force_user *)kmap(page),
88640 .iov_len = PAGE_SIZE,
88641 };
88642
88643diff --git a/mm/percpu.c b/mm/percpu.c
88644index 8c8e08f..73a5cda 100644
88645--- a/mm/percpu.c
88646+++ b/mm/percpu.c
88647@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
88648 static unsigned int pcpu_high_unit_cpu __read_mostly;
88649
88650 /* the address of the first chunk which starts with the kernel static area */
88651-void *pcpu_base_addr __read_mostly;
88652+void *pcpu_base_addr __read_only;
88653 EXPORT_SYMBOL_GPL(pcpu_base_addr);
88654
88655 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
88656diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
88657index fd26d04..0cea1b0 100644
88658--- a/mm/process_vm_access.c
88659+++ b/mm/process_vm_access.c
88660@@ -13,6 +13,7 @@
88661 #include <linux/uio.h>
88662 #include <linux/sched.h>
88663 #include <linux/highmem.h>
88664+#include <linux/security.h>
88665 #include <linux/ptrace.h>
88666 #include <linux/slab.h>
88667 #include <linux/syscalls.h>
88668@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
88669 size_t iov_l_curr_offset = 0;
88670 ssize_t iov_len;
88671
88672+ return -ENOSYS; // PaX: until properly audited
88673+
88674 /*
88675 * Work out how many pages of struct pages we're going to need
88676 * when eventually calling get_user_pages
88677 */
88678 for (i = 0; i < riovcnt; i++) {
88679 iov_len = rvec[i].iov_len;
88680- if (iov_len > 0) {
88681- nr_pages_iov = ((unsigned long)rvec[i].iov_base
88682- + iov_len)
88683- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
88684- / PAGE_SIZE + 1;
88685- nr_pages = max(nr_pages, nr_pages_iov);
88686- }
88687+ if (iov_len <= 0)
88688+ continue;
88689+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
88690+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
88691+ nr_pages = max(nr_pages, nr_pages_iov);
88692 }
88693
88694 if (nr_pages == 0)
88695@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
88696 goto free_proc_pages;
88697 }
88698
88699+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
88700+ rc = -EPERM;
88701+ goto put_task_struct;
88702+ }
88703+
88704 mm = mm_access(task, PTRACE_MODE_ATTACH);
88705 if (!mm || IS_ERR(mm)) {
88706 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
88707diff --git a/mm/rmap.c b/mm/rmap.c
88708index b2e29ac..4168491 100644
88709--- a/mm/rmap.c
88710+++ b/mm/rmap.c
88711@@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
88712 struct anon_vma *anon_vma = vma->anon_vma;
88713 struct anon_vma_chain *avc;
88714
88715+#ifdef CONFIG_PAX_SEGMEXEC
88716+ struct anon_vma_chain *avc_m = NULL;
88717+#endif
88718+
88719 might_sleep();
88720 if (unlikely(!anon_vma)) {
88721 struct mm_struct *mm = vma->vm_mm;
88722@@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
88723 if (!avc)
88724 goto out_enomem;
88725
88726+#ifdef CONFIG_PAX_SEGMEXEC
88727+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
88728+ if (!avc_m)
88729+ goto out_enomem_free_avc;
88730+#endif
88731+
88732 anon_vma = find_mergeable_anon_vma(vma);
88733 allocated = NULL;
88734 if (!anon_vma) {
88735@@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
88736 /* page_table_lock to protect against threads */
88737 spin_lock(&mm->page_table_lock);
88738 if (likely(!vma->anon_vma)) {
88739+
88740+#ifdef CONFIG_PAX_SEGMEXEC
88741+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
88742+
88743+ if (vma_m) {
88744+ BUG_ON(vma_m->anon_vma);
88745+ vma_m->anon_vma = anon_vma;
88746+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
88747+ avc_m = NULL;
88748+ }
88749+#endif
88750+
88751 vma->anon_vma = anon_vma;
88752 anon_vma_chain_link(vma, avc, anon_vma);
88753 allocated = NULL;
88754@@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
88755
88756 if (unlikely(allocated))
88757 put_anon_vma(allocated);
88758+
88759+#ifdef CONFIG_PAX_SEGMEXEC
88760+ if (unlikely(avc_m))
88761+ anon_vma_chain_free(avc_m);
88762+#endif
88763+
88764 if (unlikely(avc))
88765 anon_vma_chain_free(avc);
88766 }
88767 return 0;
88768
88769 out_enomem_free_avc:
88770+
88771+#ifdef CONFIG_PAX_SEGMEXEC
88772+ if (avc_m)
88773+ anon_vma_chain_free(avc_m);
88774+#endif
88775+
88776 anon_vma_chain_free(avc);
88777 out_enomem:
88778 return -ENOMEM;
88779@@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
88780 * Attach the anon_vmas from src to dst.
88781 * Returns 0 on success, -ENOMEM on failure.
88782 */
88783-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
88784+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
88785 {
88786 struct anon_vma_chain *avc, *pavc;
88787 struct anon_vma *root = NULL;
88788@@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
88789 * the corresponding VMA in the parent process is attached to.
88790 * Returns 0 on success, non-zero on failure.
88791 */
88792-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
88793+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
88794 {
88795 struct anon_vma_chain *avc;
88796 struct anon_vma *anon_vma;
88797@@ -373,8 +407,10 @@ static void anon_vma_ctor(void *data)
88798 void __init anon_vma_init(void)
88799 {
88800 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
88801- 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
88802- anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
88803+ 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
88804+ anon_vma_ctor);
88805+ anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
88806+ SLAB_PANIC|SLAB_NO_SANITIZE);
88807 }
88808
88809 /*
88810diff --git a/mm/shmem.c b/mm/shmem.c
88811index e43dc55..930e3a2 100644
88812--- a/mm/shmem.c
88813+++ b/mm/shmem.c
88814@@ -33,7 +33,7 @@
88815 #include <linux/swap.h>
88816 #include <linux/aio.h>
88817
88818-static struct vfsmount *shm_mnt;
88819+struct vfsmount *shm_mnt;
88820
88821 #ifdef CONFIG_SHMEM
88822 /*
88823@@ -77,7 +77,7 @@ static struct vfsmount *shm_mnt;
88824 #define BOGO_DIRENT_SIZE 20
88825
88826 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
88827-#define SHORT_SYMLINK_LEN 128
88828+#define SHORT_SYMLINK_LEN 64
88829
88830 /*
88831 * shmem_fallocate and shmem_writepage communicate via inode->i_private
88832@@ -2232,6 +2232,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
88833 static int shmem_xattr_validate(const char *name)
88834 {
88835 struct { const char *prefix; size_t len; } arr[] = {
88836+
88837+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
88838+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
88839+#endif
88840+
88841 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
88842 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
88843 };
88844@@ -2287,6 +2292,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
88845 if (err)
88846 return err;
88847
88848+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
88849+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
88850+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
88851+ return -EOPNOTSUPP;
88852+ if (size > 8)
88853+ return -EINVAL;
88854+ }
88855+#endif
88856+
88857 return simple_xattr_set(&info->xattrs, name, value, size, flags);
88858 }
88859
88860@@ -2599,8 +2613,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
88861 int err = -ENOMEM;
88862
88863 /* Round up to L1_CACHE_BYTES to resist false sharing */
88864- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
88865- L1_CACHE_BYTES), GFP_KERNEL);
88866+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
88867 if (!sbinfo)
88868 return -ENOMEM;
88869
88870diff --git a/mm/slab.c b/mm/slab.c
88871index 2580db0..0523956 100644
88872--- a/mm/slab.c
88873+++ b/mm/slab.c
88874@@ -366,10 +366,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
88875 if ((x)->max_freeable < i) \
88876 (x)->max_freeable = i; \
88877 } while (0)
88878-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
88879-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
88880-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
88881-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
88882+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
88883+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
88884+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
88885+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
88886+#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
88887+#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
88888 #else
88889 #define STATS_INC_ACTIVE(x) do { } while (0)
88890 #define STATS_DEC_ACTIVE(x) do { } while (0)
88891@@ -386,6 +388,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
88892 #define STATS_INC_ALLOCMISS(x) do { } while (0)
88893 #define STATS_INC_FREEHIT(x) do { } while (0)
88894 #define STATS_INC_FREEMISS(x) do { } while (0)
88895+#define STATS_INC_SANITIZED(x) do { } while (0)
88896+#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
88897 #endif
88898
88899 #if DEBUG
88900@@ -477,7 +481,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
88901 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
88902 */
88903 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
88904- const struct slab *slab, void *obj)
88905+ const struct slab *slab, const void *obj)
88906 {
88907 u32 offset = (obj - slab->s_mem);
88908 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
88909@@ -1571,12 +1575,12 @@ void __init kmem_cache_init(void)
88910 */
88911
88912 kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
88913- kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
88914+ kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
88915
88916 if (INDEX_AC != INDEX_NODE)
88917 kmalloc_caches[INDEX_NODE] =
88918 create_kmalloc_cache("kmalloc-node",
88919- kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
88920+ kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
88921
88922 slab_early_init = 0;
88923
88924@@ -3577,6 +3581,21 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
88925 struct array_cache *ac = cpu_cache_get(cachep);
88926
88927 check_irq_off();
88928+
88929+#ifdef CONFIG_PAX_MEMORY_SANITIZE
88930+ if (pax_sanitize_slab) {
88931+ if (!(cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))) {
88932+ memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
88933+
88934+ if (cachep->ctor)
88935+ cachep->ctor(objp);
88936+
88937+ STATS_INC_SANITIZED(cachep);
88938+ } else
88939+ STATS_INC_NOT_SANITIZED(cachep);
88940+ }
88941+#endif
88942+
88943 kmemleak_free_recursive(objp, cachep->flags);
88944 objp = cache_free_debugcheck(cachep, objp, caller);
88945
88946@@ -3805,6 +3824,7 @@ void kfree(const void *objp)
88947
88948 if (unlikely(ZERO_OR_NULL_PTR(objp)))
88949 return;
88950+ VM_BUG_ON(!virt_addr_valid(objp));
88951 local_irq_save(flags);
88952 kfree_debugcheck(objp);
88953 c = virt_to_cache(objp);
88954@@ -4246,14 +4266,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
88955 }
88956 /* cpu stats */
88957 {
88958- unsigned long allochit = atomic_read(&cachep->allochit);
88959- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
88960- unsigned long freehit = atomic_read(&cachep->freehit);
88961- unsigned long freemiss = atomic_read(&cachep->freemiss);
88962+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
88963+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
88964+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
88965+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
88966
88967 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
88968 allochit, allocmiss, freehit, freemiss);
88969 }
88970+#ifdef CONFIG_PAX_MEMORY_SANITIZE
88971+ {
88972+ unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
88973+ unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
88974+
88975+ seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
88976+ }
88977+#endif
88978 #endif
88979 }
88980
88981@@ -4471,13 +4499,71 @@ static const struct file_operations proc_slabstats_operations = {
88982 static int __init slab_proc_init(void)
88983 {
88984 #ifdef CONFIG_DEBUG_SLAB_LEAK
88985- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
88986+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
88987 #endif
88988 return 0;
88989 }
88990 module_init(slab_proc_init);
88991 #endif
88992
88993+bool is_usercopy_object(const void *ptr)
88994+{
88995+ struct page *page;
88996+ struct kmem_cache *cachep;
88997+
88998+ if (ZERO_OR_NULL_PTR(ptr))
88999+ return false;
89000+
89001+ if (!slab_is_available())
89002+ return false;
89003+
89004+ if (!virt_addr_valid(ptr))
89005+ return false;
89006+
89007+ page = virt_to_head_page(ptr);
89008+
89009+ if (!PageSlab(page))
89010+ return false;
89011+
89012+ cachep = page->slab_cache;
89013+ return cachep->flags & SLAB_USERCOPY;
89014+}
89015+
89016+#ifdef CONFIG_PAX_USERCOPY
89017+const char *check_heap_object(const void *ptr, unsigned long n)
89018+{
89019+ struct page *page;
89020+ struct kmem_cache *cachep;
89021+ struct slab *slabp;
89022+ unsigned int objnr;
89023+ unsigned long offset;
89024+
89025+ if (ZERO_OR_NULL_PTR(ptr))
89026+ return "<null>";
89027+
89028+ if (!virt_addr_valid(ptr))
89029+ return NULL;
89030+
89031+ page = virt_to_head_page(ptr);
89032+
89033+ if (!PageSlab(page))
89034+ return NULL;
89035+
89036+ cachep = page->slab_cache;
89037+ if (!(cachep->flags & SLAB_USERCOPY))
89038+ return cachep->name;
89039+
89040+ slabp = page->slab_page;
89041+ objnr = obj_to_index(cachep, slabp, ptr);
89042+ BUG_ON(objnr >= cachep->num);
89043+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
89044+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
89045+ return NULL;
89046+
89047+ return cachep->name;
89048+}
89049+#endif
89050+
89051 /**
89052 * ksize - get the actual amount of memory allocated for a given object
89053 * @objp: Pointer to the object
89054diff --git a/mm/slab.h b/mm/slab.h
89055index a535033..2f98fe5 100644
89056--- a/mm/slab.h
89057+++ b/mm/slab.h
89058@@ -32,6 +32,15 @@ extern struct list_head slab_caches;
89059 /* The slab cache that manages slab cache information */
89060 extern struct kmem_cache *kmem_cache;
89061
89062+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89063+#ifdef CONFIG_X86_64
89064+#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
89065+#else
89066+#define PAX_MEMORY_SANITIZE_VALUE '\xff'
89067+#endif
89068+extern bool pax_sanitize_slab;
89069+#endif
89070+
89071 unsigned long calculate_alignment(unsigned long flags,
89072 unsigned long align, unsigned long size);
89073
89074@@ -67,7 +76,8 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
89075
89076 /* Legal flag mask for kmem_cache_create(), for various configurations */
89077 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
89078- SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
89079+ SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
89080+ SLAB_USERCOPY | SLAB_NO_SANITIZE)
89081
89082 #if defined(CONFIG_DEBUG_SLAB)
89083 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
89084@@ -231,6 +241,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
89085 return s;
89086
89087 page = virt_to_head_page(x);
89088+
89089+ BUG_ON(!PageSlab(page));
89090+
89091 cachep = page->slab_cache;
89092 if (slab_equal_or_root(cachep, s))
89093 return cachep;
89094diff --git a/mm/slab_common.c b/mm/slab_common.c
89095index 538bade..36fed99 100644
89096--- a/mm/slab_common.c
89097+++ b/mm/slab_common.c
89098@@ -22,11 +22,22 @@
89099
89100 #include "slab.h"
89101
89102-enum slab_state slab_state;
89103+enum slab_state slab_state __read_only;
89104 LIST_HEAD(slab_caches);
89105 DEFINE_MUTEX(slab_mutex);
89106 struct kmem_cache *kmem_cache;
89107
89108+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89109+bool pax_sanitize_slab __read_only = true;
89110+static int __init pax_sanitize_slab_setup(char *str)
89111+{
89112+ pax_sanitize_slab = !!simple_strtol(str, NULL, 0);
89113+ printk("%sabled PaX slab sanitization\n", pax_sanitize_slab ? "En" : "Dis");
89114+ return 1;
89115+}
89116+__setup("pax_sanitize_slab=", pax_sanitize_slab_setup);
89117+#endif
89118+
89119 #ifdef CONFIG_DEBUG_VM
89120 static int kmem_cache_sanity_check(struct mem_cgroup *memcg, const char *name,
89121 size_t size)
89122@@ -209,7 +220,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
89123
89124 err = __kmem_cache_create(s, flags);
89125 if (!err) {
89126- s->refcount = 1;
89127+ atomic_set(&s->refcount, 1);
89128 list_add(&s->list, &slab_caches);
89129 memcg_cache_list_add(memcg, s);
89130 } else {
89131@@ -255,8 +266,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
89132
89133 get_online_cpus();
89134 mutex_lock(&slab_mutex);
89135- s->refcount--;
89136- if (!s->refcount) {
89137+ if (atomic_dec_and_test(&s->refcount)) {
89138 list_del(&s->list);
89139
89140 if (!__kmem_cache_shutdown(s)) {
89141@@ -302,7 +312,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
89142 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
89143 name, size, err);
89144
89145- s->refcount = -1; /* Exempt from merging for now */
89146+ atomic_set(&s->refcount, -1); /* Exempt from merging for now */
89147 }
89148
89149 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
89150@@ -315,7 +325,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
89151
89152 create_boot_cache(s, name, size, flags);
89153 list_add(&s->list, &slab_caches);
89154- s->refcount = 1;
89155+ atomic_set(&s->refcount, 1);
89156 return s;
89157 }
89158
89159@@ -327,6 +337,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
89160 EXPORT_SYMBOL(kmalloc_dma_caches);
89161 #endif
89162
89163+#ifdef CONFIG_PAX_USERCOPY_SLABS
89164+struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
89165+EXPORT_SYMBOL(kmalloc_usercopy_caches);
89166+#endif
89167+
89168 /*
89169 * Conversion table for small slabs sizes / 8 to the index in the
89170 * kmalloc array. This is necessary for slabs < 192 since we have non power
89171@@ -391,6 +406,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
89172 return kmalloc_dma_caches[index];
89173
89174 #endif
89175+
89176+#ifdef CONFIG_PAX_USERCOPY_SLABS
89177+ if (unlikely((flags & GFP_USERCOPY)))
89178+ return kmalloc_usercopy_caches[index];
89179+
89180+#endif
89181+
89182 return kmalloc_caches[index];
89183 }
89184
89185@@ -447,7 +469,7 @@ void __init create_kmalloc_caches(unsigned long flags)
89186 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
89187 if (!kmalloc_caches[i]) {
89188 kmalloc_caches[i] = create_kmalloc_cache(NULL,
89189- 1 << i, flags);
89190+ 1 << i, SLAB_USERCOPY | flags);
89191 }
89192
89193 /*
89194@@ -456,10 +478,10 @@ void __init create_kmalloc_caches(unsigned long flags)
89195 * earlier power of two caches
89196 */
89197 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
89198- kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
89199+ kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
89200
89201 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
89202- kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
89203+ kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
89204 }
89205
89206 /* Kmalloc array is now usable */
89207@@ -492,6 +514,23 @@ void __init create_kmalloc_caches(unsigned long flags)
89208 }
89209 }
89210 #endif
89211+
89212+#ifdef CONFIG_PAX_USERCOPY_SLABS
89213+ for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
89214+ struct kmem_cache *s = kmalloc_caches[i];
89215+
89216+ if (s) {
89217+ int size = kmalloc_size(i);
89218+ char *n = kasprintf(GFP_NOWAIT,
89219+ "usercopy-kmalloc-%d", size);
89220+
89221+ BUG_ON(!n);
89222+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
89223+ size, SLAB_USERCOPY | flags);
89224+ }
89225+ }
89226+#endif
89227+
89228 }
89229 #endif /* !CONFIG_SLOB */
89230
89231@@ -523,6 +562,9 @@ void print_slabinfo_header(struct seq_file *m)
89232 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
89233 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
89234 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
89235+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89236+ seq_puts(m, " : pax <sanitized> <not_sanitized>");
89237+#endif
89238 #endif
89239 seq_putc(m, '\n');
89240 }
89241diff --git a/mm/slob.c b/mm/slob.c
89242index 91bd3f2..e2f549e 100644
89243--- a/mm/slob.c
89244+++ b/mm/slob.c
89245@@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
89246 /*
89247 * Return the size of a slob block.
89248 */
89249-static slobidx_t slob_units(slob_t *s)
89250+static slobidx_t slob_units(const slob_t *s)
89251 {
89252 if (s->units > 0)
89253 return s->units;
89254@@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
89255 /*
89256 * Return the next free slob block pointer after this one.
89257 */
89258-static slob_t *slob_next(slob_t *s)
89259+static slob_t *slob_next(const slob_t *s)
89260 {
89261 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
89262 slobidx_t next;
89263@@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
89264 /*
89265 * Returns true if s is the last free block in its page.
89266 */
89267-static int slob_last(slob_t *s)
89268+static int slob_last(const slob_t *s)
89269 {
89270 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
89271 }
89272
89273-static void *slob_new_pages(gfp_t gfp, int order, int node)
89274+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
89275 {
89276- void *page;
89277+ struct page *page;
89278
89279 #ifdef CONFIG_NUMA
89280 if (node != NUMA_NO_NODE)
89281@@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
89282 if (!page)
89283 return NULL;
89284
89285- return page_address(page);
89286+ __SetPageSlab(page);
89287+ return page;
89288 }
89289
89290-static void slob_free_pages(void *b, int order)
89291+static void slob_free_pages(struct page *sp, int order)
89292 {
89293 if (current->reclaim_state)
89294 current->reclaim_state->reclaimed_slab += 1 << order;
89295- free_pages((unsigned long)b, order);
89296+ __ClearPageSlab(sp);
89297+ page_mapcount_reset(sp);
89298+ sp->private = 0;
89299+ __free_pages(sp, order);
89300 }
89301
89302 /*
89303@@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
89304
89305 /* Not enough space: must allocate a new page */
89306 if (!b) {
89307- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
89308- if (!b)
89309+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
89310+ if (!sp)
89311 return NULL;
89312- sp = virt_to_page(b);
89313- __SetPageSlab(sp);
89314+ b = page_address(sp);
89315
89316 spin_lock_irqsave(&slob_lock, flags);
89317 sp->units = SLOB_UNITS(PAGE_SIZE);
89318 sp->freelist = b;
89319+ sp->private = 0;
89320 INIT_LIST_HEAD(&sp->list);
89321 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
89322 set_slob_page_free(sp, slob_list);
89323@@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
89324 if (slob_page_free(sp))
89325 clear_slob_page_free(sp);
89326 spin_unlock_irqrestore(&slob_lock, flags);
89327- __ClearPageSlab(sp);
89328- page_mapcount_reset(sp);
89329- slob_free_pages(b, 0);
89330+ slob_free_pages(sp, 0);
89331 return;
89332 }
89333
89334+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89335+ if (pax_sanitize_slab)
89336+ memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
89337+#endif
89338+
89339 if (!slob_page_free(sp)) {
89340 /* This slob page is about to become partially free. Easy! */
89341 sp->units = units;
89342@@ -424,11 +431,10 @@ out:
89343 */
89344
89345 static __always_inline void *
89346-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
89347+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
89348 {
89349- unsigned int *m;
89350- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
89351- void *ret;
89352+ slob_t *m;
89353+ void *ret = NULL;
89354
89355 gfp &= gfp_allowed_mask;
89356
89357@@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
89358
89359 if (!m)
89360 return NULL;
89361- *m = size;
89362+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
89363+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
89364+ m[0].units = size;
89365+ m[1].units = align;
89366 ret = (void *)m + align;
89367
89368 trace_kmalloc_node(caller, ret,
89369 size, size + align, gfp, node);
89370 } else {
89371 unsigned int order = get_order(size);
89372+ struct page *page;
89373
89374 if (likely(order))
89375 gfp |= __GFP_COMP;
89376- ret = slob_new_pages(gfp, order, node);
89377+ page = slob_new_pages(gfp, order, node);
89378+ if (page) {
89379+ ret = page_address(page);
89380+ page->private = size;
89381+ }
89382
89383 trace_kmalloc_node(caller, ret,
89384 size, PAGE_SIZE << order, gfp, node);
89385 }
89386
89387- kmemleak_alloc(ret, size, 1, gfp);
89388+ return ret;
89389+}
89390+
89391+static __always_inline void *
89392+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
89393+{
89394+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
89395+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
89396+
89397+ if (!ZERO_OR_NULL_PTR(ret))
89398+ kmemleak_alloc(ret, size, 1, gfp);
89399 return ret;
89400 }
89401
89402@@ -493,34 +517,112 @@ void kfree(const void *block)
89403 return;
89404 kmemleak_free(block);
89405
89406+ VM_BUG_ON(!virt_addr_valid(block));
89407 sp = virt_to_page(block);
89408- if (PageSlab(sp)) {
89409+ VM_BUG_ON(!PageSlab(sp));
89410+ if (!sp->private) {
89411 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
89412- unsigned int *m = (unsigned int *)(block - align);
89413- slob_free(m, *m + align);
89414- } else
89415+ slob_t *m = (slob_t *)(block - align);
89416+ slob_free(m, m[0].units + align);
89417+ } else {
89418+ __ClearPageSlab(sp);
89419+ page_mapcount_reset(sp);
89420+ sp->private = 0;
89421 __free_pages(sp, compound_order(sp));
89422+ }
89423 }
89424 EXPORT_SYMBOL(kfree);
89425
89426+bool is_usercopy_object(const void *ptr)
89427+{
89428+ if (!slab_is_available())
89429+ return false;
89430+
89431+ // PAX: TODO
89432+
89433+ return false;
89434+}
89435+
89436+#ifdef CONFIG_PAX_USERCOPY
89437+const char *check_heap_object(const void *ptr, unsigned long n)
89438+{
89439+ struct page *page;
89440+ const slob_t *free;
89441+ const void *base;
89442+ unsigned long flags;
89443+
89444+ if (ZERO_OR_NULL_PTR(ptr))
89445+ return "<null>";
89446+
89447+ if (!virt_addr_valid(ptr))
89448+ return NULL;
89449+
89450+ page = virt_to_head_page(ptr);
89451+ if (!PageSlab(page))
89452+ return NULL;
89453+
89454+ if (page->private) {
89455+ base = page;
89456+ if (base <= ptr && n <= page->private - (ptr - base))
89457+ return NULL;
89458+ return "<slob>";
89459+ }
89460+
89461+ /* some tricky double walking to find the chunk */
89462+ spin_lock_irqsave(&slob_lock, flags);
89463+ base = (void *)((unsigned long)ptr & PAGE_MASK);
89464+ free = page->freelist;
89465+
89466+ while (!slob_last(free) && (void *)free <= ptr) {
89467+ base = free + slob_units(free);
89468+ free = slob_next(free);
89469+ }
89470+
89471+ while (base < (void *)free) {
89472+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
89473+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
89474+ int offset;
89475+
89476+ if (ptr < base + align)
89477+ break;
89478+
89479+ offset = ptr - base - align;
89480+ if (offset >= m) {
89481+ base += size;
89482+ continue;
89483+ }
89484+
89485+ if (n > m - offset)
89486+ break;
89487+
89488+ spin_unlock_irqrestore(&slob_lock, flags);
89489+ return NULL;
89490+ }
89491+
89492+ spin_unlock_irqrestore(&slob_lock, flags);
89493+ return "<slob>";
89494+}
89495+#endif
89496+
89497 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
89498 size_t ksize(const void *block)
89499 {
89500 struct page *sp;
89501 int align;
89502- unsigned int *m;
89503+ slob_t *m;
89504
89505 BUG_ON(!block);
89506 if (unlikely(block == ZERO_SIZE_PTR))
89507 return 0;
89508
89509 sp = virt_to_page(block);
89510- if (unlikely(!PageSlab(sp)))
89511- return PAGE_SIZE << compound_order(sp);
89512+ VM_BUG_ON(!PageSlab(sp));
89513+ if (sp->private)
89514+ return sp->private;
89515
89516 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
89517- m = (unsigned int *)(block - align);
89518- return SLOB_UNITS(*m) * SLOB_UNIT;
89519+ m = (slob_t *)(block - align);
89520+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
89521 }
89522 EXPORT_SYMBOL(ksize);
89523
89524@@ -536,23 +638,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
89525
89526 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
89527 {
89528- void *b;
89529+ void *b = NULL;
89530
89531 flags &= gfp_allowed_mask;
89532
89533 lockdep_trace_alloc(flags);
89534
89535+#ifdef CONFIG_PAX_USERCOPY_SLABS
89536+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
89537+#else
89538 if (c->size < PAGE_SIZE) {
89539 b = slob_alloc(c->size, flags, c->align, node);
89540 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
89541 SLOB_UNITS(c->size) * SLOB_UNIT,
89542 flags, node);
89543 } else {
89544- b = slob_new_pages(flags, get_order(c->size), node);
89545+ struct page *sp;
89546+
89547+ sp = slob_new_pages(flags, get_order(c->size), node);
89548+ if (sp) {
89549+ b = page_address(sp);
89550+ sp->private = c->size;
89551+ }
89552 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
89553 PAGE_SIZE << get_order(c->size),
89554 flags, node);
89555 }
89556+#endif
89557
89558 if (b && c->ctor)
89559 c->ctor(b);
89560@@ -564,10 +676,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
89561
89562 static void __kmem_cache_free(void *b, int size)
89563 {
89564- if (size < PAGE_SIZE)
89565+ struct page *sp;
89566+
89567+ sp = virt_to_page(b);
89568+ BUG_ON(!PageSlab(sp));
89569+ if (!sp->private)
89570 slob_free(b, size);
89571 else
89572- slob_free_pages(b, get_order(size));
89573+ slob_free_pages(sp, get_order(size));
89574 }
89575
89576 static void kmem_rcu_free(struct rcu_head *head)
89577@@ -580,17 +696,31 @@ static void kmem_rcu_free(struct rcu_head *head)
89578
89579 void kmem_cache_free(struct kmem_cache *c, void *b)
89580 {
89581+ int size = c->size;
89582+
89583+#ifdef CONFIG_PAX_USERCOPY_SLABS
89584+ if (size + c->align < PAGE_SIZE) {
89585+ size += c->align;
89586+ b -= c->align;
89587+ }
89588+#endif
89589+
89590 kmemleak_free_recursive(b, c->flags);
89591 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
89592 struct slob_rcu *slob_rcu;
89593- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
89594- slob_rcu->size = c->size;
89595+ slob_rcu = b + (size - sizeof(struct slob_rcu));
89596+ slob_rcu->size = size;
89597 call_rcu(&slob_rcu->head, kmem_rcu_free);
89598 } else {
89599- __kmem_cache_free(b, c->size);
89600+ __kmem_cache_free(b, size);
89601 }
89602
89603+#ifdef CONFIG_PAX_USERCOPY_SLABS
89604+ trace_kfree(_RET_IP_, b);
89605+#else
89606 trace_kmem_cache_free(_RET_IP_, b);
89607+#endif
89608+
89609 }
89610 EXPORT_SYMBOL(kmem_cache_free);
89611
89612diff --git a/mm/slub.c b/mm/slub.c
89613index e3ba1f2..bd45dac 100644
89614--- a/mm/slub.c
89615+++ b/mm/slub.c
89616@@ -207,7 +207,7 @@ struct track {
89617
89618 enum track_item { TRACK_ALLOC, TRACK_FREE };
89619
89620-#ifdef CONFIG_SYSFS
89621+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
89622 static int sysfs_slab_add(struct kmem_cache *);
89623 static int sysfs_slab_alias(struct kmem_cache *, const char *);
89624 static void sysfs_slab_remove(struct kmem_cache *);
89625@@ -528,7 +528,7 @@ static void print_track(const char *s, struct track *t)
89626 if (!t->addr)
89627 return;
89628
89629- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
89630+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
89631 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
89632 #ifdef CONFIG_STACKTRACE
89633 {
89634@@ -2609,6 +2609,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
89635
89636 slab_free_hook(s, x);
89637
89638+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89639+ if (pax_sanitize_slab && !(s->flags & SLAB_NO_SANITIZE)) {
89640+ memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
89641+ if (s->ctor)
89642+ s->ctor(x);
89643+ }
89644+#endif
89645+
89646 redo:
89647 /*
89648 * Determine the currently cpus per cpu slab.
89649@@ -2676,7 +2684,7 @@ static int slub_min_objects;
89650 * Merge control. If this is set then no merging of slab caches will occur.
89651 * (Could be removed. This was introduced to pacify the merge skeptics.)
89652 */
89653-static int slub_nomerge;
89654+static int slub_nomerge = 1;
89655
89656 /*
89657 * Calculate the order of allocation given an slab object size.
89658@@ -2953,6 +2961,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
89659 s->inuse = size;
89660
89661 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
89662+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89663+ (pax_sanitize_slab && !(flags & SLAB_NO_SANITIZE)) ||
89664+#endif
89665 s->ctor)) {
89666 /*
89667 * Relocate free pointer after the object if it is not
89668@@ -3298,6 +3309,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
89669 EXPORT_SYMBOL(__kmalloc_node);
89670 #endif
89671
89672+bool is_usercopy_object(const void *ptr)
89673+{
89674+ struct page *page;
89675+ struct kmem_cache *s;
89676+
89677+ if (ZERO_OR_NULL_PTR(ptr))
89678+ return false;
89679+
89680+ if (!slab_is_available())
89681+ return false;
89682+
89683+ if (!virt_addr_valid(ptr))
89684+ return false;
89685+
89686+ page = virt_to_head_page(ptr);
89687+
89688+ if (!PageSlab(page))
89689+ return false;
89690+
89691+ s = page->slab_cache;
89692+ return s->flags & SLAB_USERCOPY;
89693+}
89694+
89695+#ifdef CONFIG_PAX_USERCOPY
89696+const char *check_heap_object(const void *ptr, unsigned long n)
89697+{
89698+ struct page *page;
89699+ struct kmem_cache *s;
89700+ unsigned long offset;
89701+
89702+ if (ZERO_OR_NULL_PTR(ptr))
89703+ return "<null>";
89704+
89705+ if (!virt_addr_valid(ptr))
89706+ return NULL;
89707+
89708+ page = virt_to_head_page(ptr);
89709+
89710+ if (!PageSlab(page))
89711+ return NULL;
89712+
89713+ s = page->slab_cache;
89714+ if (!(s->flags & SLAB_USERCOPY))
89715+ return s->name;
89716+
89717+ offset = (ptr - page_address(page)) % s->size;
89718+ if (offset <= s->object_size && n <= s->object_size - offset)
89719+ return NULL;
89720+
89721+ return s->name;
89722+}
89723+#endif
89724+
89725 size_t ksize(const void *object)
89726 {
89727 struct page *page;
89728@@ -3362,6 +3426,7 @@ void kfree(const void *x)
89729 if (unlikely(ZERO_OR_NULL_PTR(x)))
89730 return;
89731
89732+ VM_BUG_ON(!virt_addr_valid(x));
89733 page = virt_to_head_page(x);
89734 if (unlikely(!PageSlab(page))) {
89735 BUG_ON(!PageCompound(page));
89736@@ -3667,7 +3732,7 @@ static int slab_unmergeable(struct kmem_cache *s)
89737 /*
89738 * We may have set a slab to be unmergeable during bootstrap.
89739 */
89740- if (s->refcount < 0)
89741+ if (atomic_read(&s->refcount) < 0)
89742 return 1;
89743
89744 return 0;
89745@@ -3725,7 +3790,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
89746
89747 s = find_mergeable(memcg, size, align, flags, name, ctor);
89748 if (s) {
89749- s->refcount++;
89750+ atomic_inc(&s->refcount);
89751 /*
89752 * Adjust the object sizes so that we clear
89753 * the complete object on kzalloc.
89754@@ -3734,7 +3799,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
89755 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
89756
89757 if (sysfs_slab_alias(s, name)) {
89758- s->refcount--;
89759+ atomic_dec(&s->refcount);
89760 s = NULL;
89761 }
89762 }
89763@@ -3854,7 +3919,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
89764 }
89765 #endif
89766
89767-#ifdef CONFIG_SYSFS
89768+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
89769 static int count_inuse(struct page *page)
89770 {
89771 return page->inuse;
89772@@ -4241,12 +4306,12 @@ static void resiliency_test(void)
89773 validate_slab_cache(kmalloc_caches[9]);
89774 }
89775 #else
89776-#ifdef CONFIG_SYSFS
89777+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
89778 static void resiliency_test(void) {};
89779 #endif
89780 #endif
89781
89782-#ifdef CONFIG_SYSFS
89783+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
89784 enum slab_stat_type {
89785 SL_ALL, /* All slabs */
89786 SL_PARTIAL, /* Only partially allocated slabs */
89787@@ -4490,7 +4555,7 @@ SLAB_ATTR_RO(ctor);
89788
89789 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
89790 {
89791- return sprintf(buf, "%d\n", s->refcount - 1);
89792+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
89793 }
89794 SLAB_ATTR_RO(aliases);
89795
89796@@ -4578,6 +4643,14 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
89797 SLAB_ATTR_RO(cache_dma);
89798 #endif
89799
89800+#ifdef CONFIG_PAX_USERCOPY_SLABS
89801+static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
89802+{
89803+ return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
89804+}
89805+SLAB_ATTR_RO(usercopy);
89806+#endif
89807+
89808 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
89809 {
89810 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
89811@@ -4912,6 +4985,9 @@ static struct attribute *slab_attrs[] = {
89812 #ifdef CONFIG_ZONE_DMA
89813 &cache_dma_attr.attr,
89814 #endif
89815+#ifdef CONFIG_PAX_USERCOPY_SLABS
89816+ &usercopy_attr.attr,
89817+#endif
89818 #ifdef CONFIG_NUMA
89819 &remote_node_defrag_ratio_attr.attr,
89820 #endif
89821@@ -5143,6 +5219,7 @@ static char *create_unique_id(struct kmem_cache *s)
89822 return name;
89823 }
89824
89825+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
89826 static int sysfs_slab_add(struct kmem_cache *s)
89827 {
89828 int err;
89829@@ -5166,7 +5243,7 @@ static int sysfs_slab_add(struct kmem_cache *s)
89830 }
89831
89832 s->kobj.kset = slab_kset;
89833- err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, name);
89834+ err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, "%s", name);
89835 if (err) {
89836 kobject_put(&s->kobj);
89837 return err;
89838@@ -5200,6 +5277,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
89839 kobject_del(&s->kobj);
89840 kobject_put(&s->kobj);
89841 }
89842+#endif
89843
89844 /*
89845 * Need to buffer aliases during bootup until sysfs becomes
89846@@ -5213,6 +5291,7 @@ struct saved_alias {
89847
89848 static struct saved_alias *alias_list;
89849
89850+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
89851 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
89852 {
89853 struct saved_alias *al;
89854@@ -5235,6 +5314,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
89855 alias_list = al;
89856 return 0;
89857 }
89858+#endif
89859
89860 static int __init slab_sysfs_init(void)
89861 {
89862diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
89863index 27eeab3..7c3f7f2 100644
89864--- a/mm/sparse-vmemmap.c
89865+++ b/mm/sparse-vmemmap.c
89866@@ -130,7 +130,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
89867 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
89868 if (!p)
89869 return NULL;
89870- pud_populate(&init_mm, pud, p);
89871+ pud_populate_kernel(&init_mm, pud, p);
89872 }
89873 return pud;
89874 }
89875@@ -142,7 +142,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
89876 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
89877 if (!p)
89878 return NULL;
89879- pgd_populate(&init_mm, pgd, p);
89880+ pgd_populate_kernel(&init_mm, pgd, p);
89881 }
89882 return pgd;
89883 }
89884diff --git a/mm/sparse.c b/mm/sparse.c
89885index 308d503..3dbbd04 100644
89886--- a/mm/sparse.c
89887+++ b/mm/sparse.c
89888@@ -764,7 +764,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
89889
89890 for (i = 0; i < PAGES_PER_SECTION; i++) {
89891 if (PageHWPoison(&memmap[i])) {
89892- atomic_long_sub(1, &num_poisoned_pages);
89893+ atomic_long_sub_unchecked(1, &num_poisoned_pages);
89894 ClearPageHWPoison(&memmap[i]);
89895 }
89896 }
89897diff --git a/mm/swap.c b/mm/swap.c
89898index c899502..d4dc2cd 100644
89899--- a/mm/swap.c
89900+++ b/mm/swap.c
89901@@ -77,6 +77,8 @@ static void __put_compound_page(struct page *page)
89902
89903 __page_cache_release(page);
89904 dtor = get_compound_page_dtor(page);
89905+ if (!PageHuge(page))
89906+ BUG_ON(dtor != free_compound_page);
89907 (*dtor)(page);
89908 }
89909
89910diff --git a/mm/swapfile.c b/mm/swapfile.c
89911index 6cf2e60..d204b3e 100644
89912--- a/mm/swapfile.c
89913+++ b/mm/swapfile.c
89914@@ -66,7 +66,7 @@ static DEFINE_MUTEX(swapon_mutex);
89915
89916 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
89917 /* Activity counter to indicate that a swapon or swapoff has occurred */
89918-static atomic_t proc_poll_event = ATOMIC_INIT(0);
89919+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
89920
89921 static inline unsigned char swap_count(unsigned char ent)
89922 {
89923@@ -1699,7 +1699,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
89924 }
89925 filp_close(swap_file, NULL);
89926 err = 0;
89927- atomic_inc(&proc_poll_event);
89928+ atomic_inc_unchecked(&proc_poll_event);
89929 wake_up_interruptible(&proc_poll_wait);
89930
89931 out_dput:
89932@@ -1716,8 +1716,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
89933
89934 poll_wait(file, &proc_poll_wait, wait);
89935
89936- if (seq->poll_event != atomic_read(&proc_poll_event)) {
89937- seq->poll_event = atomic_read(&proc_poll_event);
89938+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
89939+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
89940 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
89941 }
89942
89943@@ -1815,7 +1815,7 @@ static int swaps_open(struct inode *inode, struct file *file)
89944 return ret;
89945
89946 seq = file->private_data;
89947- seq->poll_event = atomic_read(&proc_poll_event);
89948+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
89949 return 0;
89950 }
89951
89952@@ -2203,7 +2203,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
89953 (frontswap_map) ? "FS" : "");
89954
89955 mutex_unlock(&swapon_mutex);
89956- atomic_inc(&proc_poll_event);
89957+ atomic_inc_unchecked(&proc_poll_event);
89958 wake_up_interruptible(&proc_poll_wait);
89959
89960 if (S_ISREG(inode->i_mode))
89961diff --git a/mm/util.c b/mm/util.c
89962index 7441c41..c3de793 100644
89963--- a/mm/util.c
89964+++ b/mm/util.c
89965@@ -294,6 +294,12 @@ done:
89966 void arch_pick_mmap_layout(struct mm_struct *mm)
89967 {
89968 mm->mmap_base = TASK_UNMAPPED_BASE;
89969+
89970+#ifdef CONFIG_PAX_RANDMMAP
89971+ if (mm->pax_flags & MF_PAX_RANDMMAP)
89972+ mm->mmap_base += mm->delta_mmap;
89973+#endif
89974+
89975 mm->get_unmapped_area = arch_get_unmapped_area;
89976 }
89977 #endif
89978diff --git a/mm/vmalloc.c b/mm/vmalloc.c
89979index 13a5495..6707d97 100644
89980--- a/mm/vmalloc.c
89981+++ b/mm/vmalloc.c
89982@@ -59,8 +59,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
89983
89984 pte = pte_offset_kernel(pmd, addr);
89985 do {
89986- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
89987- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
89988+
89989+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
89990+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
89991+ BUG_ON(!pte_exec(*pte));
89992+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
89993+ continue;
89994+ }
89995+#endif
89996+
89997+ {
89998+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
89999+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
90000+ }
90001 } while (pte++, addr += PAGE_SIZE, addr != end);
90002 }
90003
90004@@ -120,16 +131,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
90005 pte = pte_alloc_kernel(pmd, addr);
90006 if (!pte)
90007 return -ENOMEM;
90008+
90009+ pax_open_kernel();
90010 do {
90011 struct page *page = pages[*nr];
90012
90013- if (WARN_ON(!pte_none(*pte)))
90014+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
90015+ if (pgprot_val(prot) & _PAGE_NX)
90016+#endif
90017+
90018+ if (!pte_none(*pte)) {
90019+ pax_close_kernel();
90020+ WARN_ON(1);
90021 return -EBUSY;
90022- if (WARN_ON(!page))
90023+ }
90024+ if (!page) {
90025+ pax_close_kernel();
90026+ WARN_ON(1);
90027 return -ENOMEM;
90028+ }
90029 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
90030 (*nr)++;
90031 } while (pte++, addr += PAGE_SIZE, addr != end);
90032+ pax_close_kernel();
90033 return 0;
90034 }
90035
90036@@ -139,7 +163,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
90037 pmd_t *pmd;
90038 unsigned long next;
90039
90040- pmd = pmd_alloc(&init_mm, pud, addr);
90041+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
90042 if (!pmd)
90043 return -ENOMEM;
90044 do {
90045@@ -156,7 +180,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
90046 pud_t *pud;
90047 unsigned long next;
90048
90049- pud = pud_alloc(&init_mm, pgd, addr);
90050+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
90051 if (!pud)
90052 return -ENOMEM;
90053 do {
90054@@ -216,6 +240,12 @@ int is_vmalloc_or_module_addr(const void *x)
90055 if (addr >= MODULES_VADDR && addr < MODULES_END)
90056 return 1;
90057 #endif
90058+
90059+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
90060+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
90061+ return 1;
90062+#endif
90063+
90064 return is_vmalloc_addr(x);
90065 }
90066
90067@@ -236,8 +266,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
90068
90069 if (!pgd_none(*pgd)) {
90070 pud_t *pud = pud_offset(pgd, addr);
90071+#ifdef CONFIG_X86
90072+ if (!pud_large(*pud))
90073+#endif
90074 if (!pud_none(*pud)) {
90075 pmd_t *pmd = pmd_offset(pud, addr);
90076+#ifdef CONFIG_X86
90077+ if (!pmd_large(*pmd))
90078+#endif
90079 if (!pmd_none(*pmd)) {
90080 pte_t *ptep, pte;
90081
90082@@ -339,7 +375,7 @@ static void purge_vmap_area_lazy(void);
90083 * Allocate a region of KVA of the specified size and alignment, within the
90084 * vstart and vend.
90085 */
90086-static struct vmap_area *alloc_vmap_area(unsigned long size,
90087+static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
90088 unsigned long align,
90089 unsigned long vstart, unsigned long vend,
90090 int node, gfp_t gfp_mask)
90091@@ -1308,6 +1344,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
90092 struct vm_struct *area;
90093
90094 BUG_ON(in_interrupt());
90095+
90096+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
90097+ if (flags & VM_KERNEXEC) {
90098+ if (start != VMALLOC_START || end != VMALLOC_END)
90099+ return NULL;
90100+ start = (unsigned long)MODULES_EXEC_VADDR;
90101+ end = (unsigned long)MODULES_EXEC_END;
90102+ }
90103+#endif
90104+
90105 if (flags & VM_IOREMAP)
90106 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
90107
90108@@ -1533,6 +1579,11 @@ void *vmap(struct page **pages, unsigned int count,
90109 if (count > totalram_pages)
90110 return NULL;
90111
90112+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
90113+ if (!(pgprot_val(prot) & _PAGE_NX))
90114+ flags |= VM_KERNEXEC;
90115+#endif
90116+
90117 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
90118 __builtin_return_address(0));
90119 if (!area)
90120@@ -1634,6 +1685,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
90121 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
90122 goto fail;
90123
90124+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
90125+ if (!(pgprot_val(prot) & _PAGE_NX))
90126+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
90127+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
90128+ else
90129+#endif
90130+
90131 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
90132 start, end, node, gfp_mask, caller);
90133 if (!area)
90134@@ -1810,10 +1868,9 @@ EXPORT_SYMBOL(vzalloc_node);
90135 * For tight control over page level allocator and protection flags
90136 * use __vmalloc() instead.
90137 */
90138-
90139 void *vmalloc_exec(unsigned long size)
90140 {
90141- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
90142+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
90143 NUMA_NO_NODE, __builtin_return_address(0));
90144 }
90145
90146@@ -2120,6 +2177,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
90147 {
90148 struct vm_struct *area;
90149
90150+ BUG_ON(vma->vm_mirror);
90151+
90152 size = PAGE_ALIGN(size);
90153
90154 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
90155@@ -2605,7 +2664,11 @@ static int s_show(struct seq_file *m, void *p)
90156 v->addr, v->addr + v->size, v->size);
90157
90158 if (v->caller)
90159+#ifdef CONFIG_GRKERNSEC_HIDESYM
90160+ seq_printf(m, " %pK", v->caller);
90161+#else
90162 seq_printf(m, " %pS", v->caller);
90163+#endif
90164
90165 if (v->nr_pages)
90166 seq_printf(m, " pages=%d", v->nr_pages);
90167diff --git a/mm/vmstat.c b/mm/vmstat.c
90168index 20c2ef4..15e7ab7 100644
90169--- a/mm/vmstat.c
90170+++ b/mm/vmstat.c
90171@@ -76,7 +76,7 @@ void vm_events_fold_cpu(int cpu)
90172 *
90173 * vm_stat contains the global counters
90174 */
90175-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
90176+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
90177 EXPORT_SYMBOL(vm_stat);
90178
90179 #ifdef CONFIG_SMP
90180@@ -452,7 +452,7 @@ void refresh_cpu_vm_stats(int cpu)
90181 v = p->vm_stat_diff[i];
90182 p->vm_stat_diff[i] = 0;
90183 local_irq_restore(flags);
90184- atomic_long_add(v, &zone->vm_stat[i]);
90185+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
90186 global_diff[i] += v;
90187 #ifdef CONFIG_NUMA
90188 /* 3 seconds idle till flush */
90189@@ -490,7 +490,7 @@ void refresh_cpu_vm_stats(int cpu)
90190
90191 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
90192 if (global_diff[i])
90193- atomic_long_add(global_diff[i], &vm_stat[i]);
90194+ atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
90195 }
90196
90197 /*
90198@@ -505,8 +505,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
90199 if (pset->vm_stat_diff[i]) {
90200 int v = pset->vm_stat_diff[i];
90201 pset->vm_stat_diff[i] = 0;
90202- atomic_long_add(v, &zone->vm_stat[i]);
90203- atomic_long_add(v, &vm_stat[i]);
90204+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
90205+ atomic_long_add_unchecked(v, &vm_stat[i]);
90206 }
90207 }
90208 #endif
90209@@ -1241,10 +1241,20 @@ static int __init setup_vmstat(void)
90210 start_cpu_timer(cpu);
90211 #endif
90212 #ifdef CONFIG_PROC_FS
90213- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
90214- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
90215- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
90216- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
90217+ {
90218+ mode_t gr_mode = S_IRUGO;
90219+#ifdef CONFIG_GRKERNSEC_PROC_ADD
90220+ gr_mode = S_IRUSR;
90221+#endif
90222+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
90223+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
90224+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
90225+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
90226+#else
90227+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
90228+#endif
90229+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
90230+ }
90231 #endif
90232 return 0;
90233 }
90234diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
90235index 2fb2d88..8c06e40 100644
90236--- a/net/8021q/vlan.c
90237+++ b/net/8021q/vlan.c
90238@@ -469,7 +469,7 @@ out:
90239 return NOTIFY_DONE;
90240 }
90241
90242-static struct notifier_block vlan_notifier_block __read_mostly = {
90243+static struct notifier_block vlan_notifier_block = {
90244 .notifier_call = vlan_device_event,
90245 };
90246
90247@@ -544,8 +544,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
90248 err = -EPERM;
90249 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
90250 break;
90251- if ((args.u.name_type >= 0) &&
90252- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
90253+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
90254 struct vlan_net *vn;
90255
90256 vn = net_generic(net, vlan_net_id);
90257diff --git a/net/9p/mod.c b/net/9p/mod.c
90258index 6ab36ae..6f1841b 100644
90259--- a/net/9p/mod.c
90260+++ b/net/9p/mod.c
90261@@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
90262 void v9fs_register_trans(struct p9_trans_module *m)
90263 {
90264 spin_lock(&v9fs_trans_lock);
90265- list_add_tail(&m->list, &v9fs_trans_list);
90266+ pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
90267 spin_unlock(&v9fs_trans_lock);
90268 }
90269 EXPORT_SYMBOL(v9fs_register_trans);
90270@@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
90271 void v9fs_unregister_trans(struct p9_trans_module *m)
90272 {
90273 spin_lock(&v9fs_trans_lock);
90274- list_del_init(&m->list);
90275+ pax_list_del_init((struct list_head *)&m->list);
90276 spin_unlock(&v9fs_trans_lock);
90277 }
90278 EXPORT_SYMBOL(v9fs_unregister_trans);
90279diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
90280index 3ffda1b..fceac96 100644
90281--- a/net/9p/trans_fd.c
90282+++ b/net/9p/trans_fd.c
90283@@ -432,7 +432,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
90284 oldfs = get_fs();
90285 set_fs(get_ds());
90286 /* The cast to a user pointer is valid due to the set_fs() */
90287- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
90288+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
90289 set_fs(oldfs);
90290
90291 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
90292diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
90293index 876fbe8..8bbea9f 100644
90294--- a/net/atm/atm_misc.c
90295+++ b/net/atm/atm_misc.c
90296@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
90297 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
90298 return 1;
90299 atm_return(vcc, truesize);
90300- atomic_inc(&vcc->stats->rx_drop);
90301+ atomic_inc_unchecked(&vcc->stats->rx_drop);
90302 return 0;
90303 }
90304 EXPORT_SYMBOL(atm_charge);
90305@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
90306 }
90307 }
90308 atm_return(vcc, guess);
90309- atomic_inc(&vcc->stats->rx_drop);
90310+ atomic_inc_unchecked(&vcc->stats->rx_drop);
90311 return NULL;
90312 }
90313 EXPORT_SYMBOL(atm_alloc_charge);
90314@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
90315
90316 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
90317 {
90318-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
90319+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
90320 __SONET_ITEMS
90321 #undef __HANDLE_ITEM
90322 }
90323@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
90324
90325 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
90326 {
90327-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
90328+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
90329 __SONET_ITEMS
90330 #undef __HANDLE_ITEM
90331 }
90332diff --git a/net/atm/lec.h b/net/atm/lec.h
90333index 4149db1..f2ab682 100644
90334--- a/net/atm/lec.h
90335+++ b/net/atm/lec.h
90336@@ -48,7 +48,7 @@ struct lane2_ops {
90337 const u8 *tlvs, u32 sizeoftlvs);
90338 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
90339 const u8 *tlvs, u32 sizeoftlvs);
90340-};
90341+} __no_const;
90342
90343 /*
90344 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
90345diff --git a/net/atm/proc.c b/net/atm/proc.c
90346index bbb6461..cf04016 100644
90347--- a/net/atm/proc.c
90348+++ b/net/atm/proc.c
90349@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
90350 const struct k_atm_aal_stats *stats)
90351 {
90352 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
90353- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
90354- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
90355- atomic_read(&stats->rx_drop));
90356+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
90357+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
90358+ atomic_read_unchecked(&stats->rx_drop));
90359 }
90360
90361 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
90362diff --git a/net/atm/resources.c b/net/atm/resources.c
90363index 0447d5d..3cf4728 100644
90364--- a/net/atm/resources.c
90365+++ b/net/atm/resources.c
90366@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
90367 static void copy_aal_stats(struct k_atm_aal_stats *from,
90368 struct atm_aal_stats *to)
90369 {
90370-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
90371+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
90372 __AAL_STAT_ITEMS
90373 #undef __HANDLE_ITEM
90374 }
90375@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
90376 static void subtract_aal_stats(struct k_atm_aal_stats *from,
90377 struct atm_aal_stats *to)
90378 {
90379-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
90380+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
90381 __AAL_STAT_ITEMS
90382 #undef __HANDLE_ITEM
90383 }
90384diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
90385index 919a5ce..cc6b444 100644
90386--- a/net/ax25/sysctl_net_ax25.c
90387+++ b/net/ax25/sysctl_net_ax25.c
90388@@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
90389 {
90390 char path[sizeof("net/ax25/") + IFNAMSIZ];
90391 int k;
90392- struct ctl_table *table;
90393+ ctl_table_no_const *table;
90394
90395 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
90396 if (!table)
90397diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
90398index 62da527..aa27535 100644
90399--- a/net/batman-adv/bat_iv_ogm.c
90400+++ b/net/batman-adv/bat_iv_ogm.c
90401@@ -120,7 +120,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
90402
90403 /* randomize initial seqno to avoid collision */
90404 get_random_bytes(&random_seqno, sizeof(random_seqno));
90405- atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
90406+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
90407
90408 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
90409 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
90410@@ -701,9 +701,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
90411 batadv_ogm_packet = (struct batadv_ogm_packet *)(*ogm_buff);
90412
90413 /* change sequence number to network order */
90414- seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
90415+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
90416 batadv_ogm_packet->seqno = htonl(seqno);
90417- atomic_inc(&hard_iface->bat_iv.ogm_seqno);
90418+ atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
90419
90420 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->tt.vn);
90421 batadv_ogm_packet->tt_crc = htons(bat_priv->tt.local_crc);
90422@@ -1109,7 +1109,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
90423 return;
90424
90425 /* could be changed by schedule_own_packet() */
90426- if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
90427+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
90428
90429 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
90430 has_directlink_flag = 1;
90431diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
90432index c478e6b..469fd2f 100644
90433--- a/net/batman-adv/hard-interface.c
90434+++ b/net/batman-adv/hard-interface.c
90435@@ -453,7 +453,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
90436 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
90437 dev_add_pack(&hard_iface->batman_adv_ptype);
90438
90439- atomic_set(&hard_iface->frag_seqno, 1);
90440+ atomic_set_unchecked(&hard_iface->frag_seqno, 1);
90441 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
90442 hard_iface->net_dev->name);
90443
90444diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
90445index 0f04e1c..9c0ac11 100644
90446--- a/net/batman-adv/soft-interface.c
90447+++ b/net/batman-adv/soft-interface.c
90448@@ -260,7 +260,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
90449 primary_if->net_dev->dev_addr, ETH_ALEN);
90450
90451 /* set broadcast sequence number */
90452- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
90453+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
90454 bcast_packet->seqno = htonl(seqno);
90455
90456 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
90457@@ -479,7 +479,7 @@ static int batadv_softif_init_late(struct net_device *dev)
90458 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
90459
90460 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
90461- atomic_set(&bat_priv->bcast_seqno, 1);
90462+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
90463 atomic_set(&bat_priv->tt.vn, 0);
90464 atomic_set(&bat_priv->tt.local_changes, 0);
90465 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
90466diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
90467index b2c94e1..3d47e07 100644
90468--- a/net/batman-adv/types.h
90469+++ b/net/batman-adv/types.h
90470@@ -51,7 +51,7 @@
90471 struct batadv_hard_iface_bat_iv {
90472 unsigned char *ogm_buff;
90473 int ogm_buff_len;
90474- atomic_t ogm_seqno;
90475+ atomic_unchecked_t ogm_seqno;
90476 };
90477
90478 /**
90479@@ -76,7 +76,7 @@ struct batadv_hard_iface {
90480 int16_t if_num;
90481 char if_status;
90482 struct net_device *net_dev;
90483- atomic_t frag_seqno;
90484+ atomic_unchecked_t frag_seqno;
90485 uint8_t num_bcasts;
90486 struct kobject *hardif_obj;
90487 atomic_t refcount;
90488@@ -560,7 +560,7 @@ struct batadv_priv {
90489 #ifdef CONFIG_BATMAN_ADV_DEBUG
90490 atomic_t log_level;
90491 #endif
90492- atomic_t bcast_seqno;
90493+ atomic_unchecked_t bcast_seqno;
90494 atomic_t bcast_queue_left;
90495 atomic_t batman_queue_left;
90496 char num_ifaces;
90497diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
90498index 857e1b8..5ad07b2 100644
90499--- a/net/batman-adv/unicast.c
90500+++ b/net/batman-adv/unicast.c
90501@@ -270,7 +270,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
90502 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
90503 frag2->flags = large_tail;
90504
90505- seqno = atomic_add_return(2, &hard_iface->frag_seqno);
90506+ seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
90507 frag1->seqno = htons(seqno - 1);
90508 frag2->seqno = htons(seqno);
90509
90510diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
90511index 9bd7d95..6c4884f 100644
90512--- a/net/bluetooth/hci_sock.c
90513+++ b/net/bluetooth/hci_sock.c
90514@@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
90515 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
90516 }
90517
90518- len = min_t(unsigned int, len, sizeof(uf));
90519+ len = min((size_t)len, sizeof(uf));
90520 if (copy_from_user(&uf, optval, len)) {
90521 err = -EFAULT;
90522 break;
90523diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
90524index 8c3499b..2661c6a 100644
90525--- a/net/bluetooth/l2cap_core.c
90526+++ b/net/bluetooth/l2cap_core.c
90527@@ -3510,8 +3510,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
90528 break;
90529
90530 case L2CAP_CONF_RFC:
90531- if (olen == sizeof(rfc))
90532- memcpy(&rfc, (void *)val, olen);
90533+ if (olen != sizeof(rfc))
90534+ break;
90535+
90536+ memcpy(&rfc, (void *)val, olen);
90537
90538 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
90539 rfc.mode != chan->mode)
90540diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
90541index 0098af8..fb5a31f 100644
90542--- a/net/bluetooth/l2cap_sock.c
90543+++ b/net/bluetooth/l2cap_sock.c
90544@@ -485,7 +485,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
90545 struct sock *sk = sock->sk;
90546 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
90547 struct l2cap_options opts;
90548- int len, err = 0;
90549+ int err = 0;
90550+ size_t len = optlen;
90551 u32 opt;
90552
90553 BT_DBG("sk %p", sk);
90554@@ -507,7 +508,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
90555 opts.max_tx = chan->max_tx;
90556 opts.txwin_size = chan->tx_win;
90557
90558- len = min_t(unsigned int, sizeof(opts), optlen);
90559+ len = min(sizeof(opts), len);
90560 if (copy_from_user((char *) &opts, optval, len)) {
90561 err = -EFAULT;
90562 break;
90563@@ -587,7 +588,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
90564 struct bt_security sec;
90565 struct bt_power pwr;
90566 struct l2cap_conn *conn;
90567- int len, err = 0;
90568+ int err = 0;
90569+ size_t len = optlen;
90570 u32 opt;
90571
90572 BT_DBG("sk %p", sk);
90573@@ -610,7 +612,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
90574
90575 sec.level = BT_SECURITY_LOW;
90576
90577- len = min_t(unsigned int, sizeof(sec), optlen);
90578+ len = min(sizeof(sec), len);
90579 if (copy_from_user((char *) &sec, optval, len)) {
90580 err = -EFAULT;
90581 break;
90582@@ -707,7 +709,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
90583
90584 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
90585
90586- len = min_t(unsigned int, sizeof(pwr), optlen);
90587+ len = min(sizeof(pwr), len);
90588 if (copy_from_user((char *) &pwr, optval, len)) {
90589 err = -EFAULT;
90590 break;
90591diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
90592index 30b3721..c1bd0a0 100644
90593--- a/net/bluetooth/rfcomm/sock.c
90594+++ b/net/bluetooth/rfcomm/sock.c
90595@@ -666,7 +666,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
90596 struct sock *sk = sock->sk;
90597 struct bt_security sec;
90598 int err = 0;
90599- size_t len;
90600+ size_t len = optlen;
90601 u32 opt;
90602
90603 BT_DBG("sk %p", sk);
90604@@ -688,7 +688,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
90605
90606 sec.level = BT_SECURITY_LOW;
90607
90608- len = min_t(unsigned int, sizeof(sec), optlen);
90609+ len = min(sizeof(sec), len);
90610 if (copy_from_user((char *) &sec, optval, len)) {
90611 err = -EFAULT;
90612 break;
90613diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
90614index b6e44ad..5b0d514 100644
90615--- a/net/bluetooth/rfcomm/tty.c
90616+++ b/net/bluetooth/rfcomm/tty.c
90617@@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
90618 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
90619
90620 spin_lock_irqsave(&dev->port.lock, flags);
90621- if (dev->port.count > 0) {
90622+ if (atomic_read(&dev->port.count) > 0) {
90623 spin_unlock_irqrestore(&dev->port.lock, flags);
90624 return;
90625 }
90626@@ -659,10 +659,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
90627 return -ENODEV;
90628
90629 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
90630- dev->channel, dev->port.count);
90631+ dev->channel, atomic_read(&dev->port.count));
90632
90633 spin_lock_irqsave(&dev->port.lock, flags);
90634- if (++dev->port.count > 1) {
90635+ if (atomic_inc_return(&dev->port.count) > 1) {
90636 spin_unlock_irqrestore(&dev->port.lock, flags);
90637 return 0;
90638 }
90639@@ -727,10 +727,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
90640 return;
90641
90642 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
90643- dev->port.count);
90644+ atomic_read(&dev->port.count));
90645
90646 spin_lock_irqsave(&dev->port.lock, flags);
90647- if (!--dev->port.count) {
90648+ if (!atomic_dec_return(&dev->port.count)) {
90649 spin_unlock_irqrestore(&dev->port.lock, flags);
90650 if (dev->tty_dev->parent)
90651 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
90652diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
90653index ac78024..161a80c 100644
90654--- a/net/bridge/netfilter/ebtables.c
90655+++ b/net/bridge/netfilter/ebtables.c
90656@@ -1525,7 +1525,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
90657 tmp.valid_hooks = t->table->valid_hooks;
90658 }
90659 mutex_unlock(&ebt_mutex);
90660- if (copy_to_user(user, &tmp, *len) != 0){
90661+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
90662 BUGPRINT("c2u Didn't work\n");
90663 ret = -EFAULT;
90664 break;
90665@@ -2331,7 +2331,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
90666 goto out;
90667 tmp.valid_hooks = t->valid_hooks;
90668
90669- if (copy_to_user(user, &tmp, *len) != 0) {
90670+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
90671 ret = -EFAULT;
90672 break;
90673 }
90674@@ -2342,7 +2342,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
90675 tmp.entries_size = t->table->entries_size;
90676 tmp.valid_hooks = t->table->valid_hooks;
90677
90678- if (copy_to_user(user, &tmp, *len) != 0) {
90679+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
90680 ret = -EFAULT;
90681 break;
90682 }
90683diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
90684index 2bd4b58..0dc30a1 100644
90685--- a/net/caif/cfctrl.c
90686+++ b/net/caif/cfctrl.c
90687@@ -10,6 +10,7 @@
90688 #include <linux/spinlock.h>
90689 #include <linux/slab.h>
90690 #include <linux/pkt_sched.h>
90691+#include <linux/sched.h>
90692 #include <net/caif/caif_layer.h>
90693 #include <net/caif/cfpkt.h>
90694 #include <net/caif/cfctrl.h>
90695@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
90696 memset(&dev_info, 0, sizeof(dev_info));
90697 dev_info.id = 0xff;
90698 cfsrvl_init(&this->serv, 0, &dev_info, false);
90699- atomic_set(&this->req_seq_no, 1);
90700- atomic_set(&this->rsp_seq_no, 1);
90701+ atomic_set_unchecked(&this->req_seq_no, 1);
90702+ atomic_set_unchecked(&this->rsp_seq_no, 1);
90703 this->serv.layer.receive = cfctrl_recv;
90704 sprintf(this->serv.layer.name, "ctrl");
90705 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
90706@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
90707 struct cfctrl_request_info *req)
90708 {
90709 spin_lock_bh(&ctrl->info_list_lock);
90710- atomic_inc(&ctrl->req_seq_no);
90711- req->sequence_no = atomic_read(&ctrl->req_seq_no);
90712+ atomic_inc_unchecked(&ctrl->req_seq_no);
90713+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
90714 list_add_tail(&req->list, &ctrl->list);
90715 spin_unlock_bh(&ctrl->info_list_lock);
90716 }
90717@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
90718 if (p != first)
90719 pr_warn("Requests are not received in order\n");
90720
90721- atomic_set(&ctrl->rsp_seq_no,
90722+ atomic_set_unchecked(&ctrl->rsp_seq_no,
90723 p->sequence_no);
90724 list_del(&p->list);
90725 goto out;
90726diff --git a/net/can/af_can.c b/net/can/af_can.c
90727index 3ab8dd2..b9aef13 100644
90728--- a/net/can/af_can.c
90729+++ b/net/can/af_can.c
90730@@ -862,7 +862,7 @@ static const struct net_proto_family can_family_ops = {
90731 };
90732
90733 /* notifier block for netdevice event */
90734-static struct notifier_block can_netdev_notifier __read_mostly = {
90735+static struct notifier_block can_netdev_notifier = {
90736 .notifier_call = can_notifier,
90737 };
90738
90739diff --git a/net/can/gw.c b/net/can/gw.c
90740index 2f291f9..98c986a 100644
90741--- a/net/can/gw.c
90742+++ b/net/can/gw.c
90743@@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
90744 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
90745
90746 static HLIST_HEAD(cgw_list);
90747-static struct notifier_block notifier;
90748
90749 static struct kmem_cache *cgw_cache __read_mostly;
90750
90751@@ -927,6 +926,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
90752 return err;
90753 }
90754
90755+static struct notifier_block notifier = {
90756+ .notifier_call = cgw_notifier
90757+};
90758+
90759 static __init int cgw_module_init(void)
90760 {
90761 /* sanitize given module parameter */
90762@@ -942,7 +945,6 @@ static __init int cgw_module_init(void)
90763 return -ENOMEM;
90764
90765 /* set notifier */
90766- notifier.notifier_call = cgw_notifier;
90767 register_netdevice_notifier(&notifier);
90768
90769 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
90770diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
90771index eb0a46a..5f3bae8 100644
90772--- a/net/ceph/messenger.c
90773+++ b/net/ceph/messenger.c
90774@@ -186,7 +186,7 @@ static void con_fault(struct ceph_connection *con);
90775 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
90776
90777 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
90778-static atomic_t addr_str_seq = ATOMIC_INIT(0);
90779+static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
90780
90781 static struct page *zero_page; /* used in certain error cases */
90782
90783@@ -197,7 +197,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
90784 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
90785 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
90786
90787- i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
90788+ i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
90789 s = addr_str[i];
90790
90791 switch (ss->ss_family) {
90792diff --git a/net/compat.c b/net/compat.c
90793index f0a1ba6..0541331 100644
90794--- a/net/compat.c
90795+++ b/net/compat.c
90796@@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
90797 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
90798 __get_user(kmsg->msg_flags, &umsg->msg_flags))
90799 return -EFAULT;
90800- kmsg->msg_name = compat_ptr(tmp1);
90801- kmsg->msg_iov = compat_ptr(tmp2);
90802- kmsg->msg_control = compat_ptr(tmp3);
90803+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
90804+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
90805+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
90806 return 0;
90807 }
90808
90809@@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
90810
90811 if (kern_msg->msg_namelen) {
90812 if (mode == VERIFY_READ) {
90813- int err = move_addr_to_kernel(kern_msg->msg_name,
90814+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
90815 kern_msg->msg_namelen,
90816 kern_address);
90817 if (err < 0)
90818@@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
90819 kern_msg->msg_name = NULL;
90820
90821 tot_len = iov_from_user_compat_to_kern(kern_iov,
90822- (struct compat_iovec __user *)kern_msg->msg_iov,
90823+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
90824 kern_msg->msg_iovlen);
90825 if (tot_len >= 0)
90826 kern_msg->msg_iov = kern_iov;
90827@@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
90828
90829 #define CMSG_COMPAT_FIRSTHDR(msg) \
90830 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
90831- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
90832+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
90833 (struct compat_cmsghdr __user *)NULL)
90834
90835 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
90836 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
90837 (ucmlen) <= (unsigned long) \
90838 ((mhdr)->msg_controllen - \
90839- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
90840+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
90841
90842 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
90843 struct compat_cmsghdr __user *cmsg, int cmsg_len)
90844 {
90845 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
90846- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
90847+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
90848 msg->msg_controllen)
90849 return NULL;
90850 return (struct compat_cmsghdr __user *)ptr;
90851@@ -219,7 +219,7 @@ Efault:
90852
90853 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
90854 {
90855- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
90856+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
90857 struct compat_cmsghdr cmhdr;
90858 struct compat_timeval ctv;
90859 struct compat_timespec cts[3];
90860@@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
90861
90862 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
90863 {
90864- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
90865+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
90866 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
90867 int fdnum = scm->fp->count;
90868 struct file **fp = scm->fp->fp;
90869@@ -363,7 +363,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
90870 return -EFAULT;
90871 old_fs = get_fs();
90872 set_fs(KERNEL_DS);
90873- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
90874+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
90875 set_fs(old_fs);
90876
90877 return err;
90878@@ -424,7 +424,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
90879 len = sizeof(ktime);
90880 old_fs = get_fs();
90881 set_fs(KERNEL_DS);
90882- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
90883+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
90884 set_fs(old_fs);
90885
90886 if (!err) {
90887@@ -567,7 +567,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
90888 case MCAST_JOIN_GROUP:
90889 case MCAST_LEAVE_GROUP:
90890 {
90891- struct compat_group_req __user *gr32 = (void *)optval;
90892+ struct compat_group_req __user *gr32 = (void __user *)optval;
90893 struct group_req __user *kgr =
90894 compat_alloc_user_space(sizeof(struct group_req));
90895 u32 interface;
90896@@ -588,7 +588,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
90897 case MCAST_BLOCK_SOURCE:
90898 case MCAST_UNBLOCK_SOURCE:
90899 {
90900- struct compat_group_source_req __user *gsr32 = (void *)optval;
90901+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
90902 struct group_source_req __user *kgsr = compat_alloc_user_space(
90903 sizeof(struct group_source_req));
90904 u32 interface;
90905@@ -609,7 +609,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
90906 }
90907 case MCAST_MSFILTER:
90908 {
90909- struct compat_group_filter __user *gf32 = (void *)optval;
90910+ struct compat_group_filter __user *gf32 = (void __user *)optval;
90911 struct group_filter __user *kgf;
90912 u32 interface, fmode, numsrc;
90913
90914@@ -647,7 +647,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
90915 char __user *optval, int __user *optlen,
90916 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
90917 {
90918- struct compat_group_filter __user *gf32 = (void *)optval;
90919+ struct compat_group_filter __user *gf32 = (void __user *)optval;
90920 struct group_filter __user *kgf;
90921 int __user *koptlen;
90922 u32 interface, fmode, numsrc;
90923@@ -805,7 +805,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
90924
90925 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
90926 return -EINVAL;
90927- if (copy_from_user(a, args, nas[call]))
90928+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
90929 return -EFAULT;
90930 a0 = a[0];
90931 a1 = a[1];
90932diff --git a/net/core/datagram.c b/net/core/datagram.c
90933index 8ab48cd..57b1a80 100644
90934--- a/net/core/datagram.c
90935+++ b/net/core/datagram.c
90936@@ -300,7 +300,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
90937 }
90938
90939 kfree_skb(skb);
90940- atomic_inc(&sk->sk_drops);
90941+ atomic_inc_unchecked(&sk->sk_drops);
90942 sk_mem_reclaim_partial(sk);
90943
90944 return err;
90945diff --git a/net/core/dev.c b/net/core/dev.c
90946index 26755dd..2a232de 100644
90947--- a/net/core/dev.c
90948+++ b/net/core/dev.c
90949@@ -1680,14 +1680,14 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
90950 {
90951 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
90952 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
90953- atomic_long_inc(&dev->rx_dropped);
90954+ atomic_long_inc_unchecked(&dev->rx_dropped);
90955 kfree_skb(skb);
90956 return NET_RX_DROP;
90957 }
90958 }
90959
90960 if (unlikely(!is_skb_forwardable(dev, skb))) {
90961- atomic_long_inc(&dev->rx_dropped);
90962+ atomic_long_inc_unchecked(&dev->rx_dropped);
90963 kfree_skb(skb);
90964 return NET_RX_DROP;
90965 }
90966@@ -2431,7 +2431,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
90967
90968 struct dev_gso_cb {
90969 void (*destructor)(struct sk_buff *skb);
90970-};
90971+} __no_const;
90972
90973 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
90974
90975@@ -3206,7 +3206,7 @@ enqueue:
90976
90977 local_irq_restore(flags);
90978
90979- atomic_long_inc(&skb->dev->rx_dropped);
90980+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
90981 kfree_skb(skb);
90982 return NET_RX_DROP;
90983 }
90984@@ -3278,7 +3278,7 @@ int netif_rx_ni(struct sk_buff *skb)
90985 }
90986 EXPORT_SYMBOL(netif_rx_ni);
90987
90988-static void net_tx_action(struct softirq_action *h)
90989+static __latent_entropy void net_tx_action(void)
90990 {
90991 struct softnet_data *sd = &__get_cpu_var(softnet_data);
90992
90993@@ -3612,7 +3612,7 @@ ncls:
90994 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
90995 } else {
90996 drop:
90997- atomic_long_inc(&skb->dev->rx_dropped);
90998+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
90999 kfree_skb(skb);
91000 /* Jamal, now you will not able to escape explaining
91001 * me how you were going to use this. :-)
91002@@ -4272,7 +4272,7 @@ void netif_napi_del(struct napi_struct *napi)
91003 }
91004 EXPORT_SYMBOL(netif_napi_del);
91005
91006-static void net_rx_action(struct softirq_action *h)
91007+static __latent_entropy void net_rx_action(void)
91008 {
91009 struct softnet_data *sd = &__get_cpu_var(softnet_data);
91010 unsigned long time_limit = jiffies + 2;
91011@@ -5730,7 +5730,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
91012 } else {
91013 netdev_stats_to_stats64(storage, &dev->stats);
91014 }
91015- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
91016+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
91017 return storage;
91018 }
91019 EXPORT_SYMBOL(dev_get_stats);
91020diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
91021index 5b7d0e1..cb960fc 100644
91022--- a/net/core/dev_ioctl.c
91023+++ b/net/core/dev_ioctl.c
91024@@ -365,9 +365,13 @@ void dev_load(struct net *net, const char *name)
91025 if (no_module && capable(CAP_NET_ADMIN))
91026 no_module = request_module("netdev-%s", name);
91027 if (no_module && capable(CAP_SYS_MODULE)) {
91028+#ifdef CONFIG_GRKERNSEC_MODHARDEN
91029+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
91030+#else
91031 if (!request_module("%s", name))
91032 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
91033 name);
91034+#endif
91035 }
91036 }
91037 EXPORT_SYMBOL(dev_load);
91038diff --git a/net/core/flow.c b/net/core/flow.c
91039index dfa602c..3103d88 100644
91040--- a/net/core/flow.c
91041+++ b/net/core/flow.c
91042@@ -61,7 +61,7 @@ struct flow_cache {
91043 struct timer_list rnd_timer;
91044 };
91045
91046-atomic_t flow_cache_genid = ATOMIC_INIT(0);
91047+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
91048 EXPORT_SYMBOL(flow_cache_genid);
91049 static struct flow_cache flow_cache_global;
91050 static struct kmem_cache *flow_cachep __read_mostly;
91051@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
91052
91053 static int flow_entry_valid(struct flow_cache_entry *fle)
91054 {
91055- if (atomic_read(&flow_cache_genid) != fle->genid)
91056+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
91057 return 0;
91058 if (fle->object && !fle->object->ops->check(fle->object))
91059 return 0;
91060@@ -258,7 +258,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
91061 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
91062 fcp->hash_count++;
91063 }
91064- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
91065+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
91066 flo = fle->object;
91067 if (!flo)
91068 goto ret_object;
91069@@ -279,7 +279,7 @@ nocache:
91070 }
91071 flo = resolver(net, key, family, dir, flo, ctx);
91072 if (fle) {
91073- fle->genid = atomic_read(&flow_cache_genid);
91074+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
91075 if (!IS_ERR(flo))
91076 fle->object = flo;
91077 else
91078diff --git a/net/core/iovec.c b/net/core/iovec.c
91079index de178e4..1dabd8b 100644
91080--- a/net/core/iovec.c
91081+++ b/net/core/iovec.c
91082@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
91083 if (m->msg_namelen) {
91084 if (mode == VERIFY_READ) {
91085 void __user *namep;
91086- namep = (void __user __force *) m->msg_name;
91087+ namep = (void __force_user *) m->msg_name;
91088 err = move_addr_to_kernel(namep, m->msg_namelen,
91089 address);
91090 if (err < 0)
91091@@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
91092 }
91093
91094 size = m->msg_iovlen * sizeof(struct iovec);
91095- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
91096+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
91097 return -EFAULT;
91098
91099 m->msg_iov = iov;
91100diff --git a/net/core/neighbour.c b/net/core/neighbour.c
91101index 60533db..14842cc 100644
91102--- a/net/core/neighbour.c
91103+++ b/net/core/neighbour.c
91104@@ -2776,7 +2776,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
91105 void __user *buffer, size_t *lenp, loff_t *ppos)
91106 {
91107 int size, ret;
91108- struct ctl_table tmp = *ctl;
91109+ ctl_table_no_const tmp = *ctl;
91110
91111 tmp.extra1 = &zero;
91112 tmp.extra2 = &unres_qlen_max;
91113diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
91114index 2bf8329..7960607 100644
91115--- a/net/core/net-procfs.c
91116+++ b/net/core/net-procfs.c
91117@@ -283,8 +283,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
91118 else
91119 seq_printf(seq, "%04x", ntohs(pt->type));
91120
91121+#ifdef CONFIG_GRKERNSEC_HIDESYM
91122+ seq_printf(seq, " %-8s %pf\n",
91123+ pt->dev ? pt->dev->name : "", NULL);
91124+#else
91125 seq_printf(seq, " %-8s %pf\n",
91126 pt->dev ? pt->dev->name : "", pt->func);
91127+#endif
91128 }
91129
91130 return 0;
91131diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
91132index 981fed3..536af34 100644
91133--- a/net/core/net-sysfs.c
91134+++ b/net/core/net-sysfs.c
91135@@ -1311,7 +1311,7 @@ void netdev_class_remove_file(struct class_attribute *class_attr)
91136 }
91137 EXPORT_SYMBOL(netdev_class_remove_file);
91138
91139-int netdev_kobject_init(void)
91140+int __init netdev_kobject_init(void)
91141 {
91142 kobj_ns_type_register(&net_ns_type_operations);
91143 return class_register(&net_class);
91144diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
91145index f9765203..9feaef8 100644
91146--- a/net/core/net_namespace.c
91147+++ b/net/core/net_namespace.c
91148@@ -443,7 +443,7 @@ static int __register_pernet_operations(struct list_head *list,
91149 int error;
91150 LIST_HEAD(net_exit_list);
91151
91152- list_add_tail(&ops->list, list);
91153+ pax_list_add_tail((struct list_head *)&ops->list, list);
91154 if (ops->init || (ops->id && ops->size)) {
91155 for_each_net(net) {
91156 error = ops_init(ops, net);
91157@@ -456,7 +456,7 @@ static int __register_pernet_operations(struct list_head *list,
91158
91159 out_undo:
91160 /* If I have an error cleanup all namespaces I initialized */
91161- list_del(&ops->list);
91162+ pax_list_del((struct list_head *)&ops->list);
91163 ops_exit_list(ops, &net_exit_list);
91164 ops_free_list(ops, &net_exit_list);
91165 return error;
91166@@ -467,7 +467,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
91167 struct net *net;
91168 LIST_HEAD(net_exit_list);
91169
91170- list_del(&ops->list);
91171+ pax_list_del((struct list_head *)&ops->list);
91172 for_each_net(net)
91173 list_add_tail(&net->exit_list, &net_exit_list);
91174 ops_exit_list(ops, &net_exit_list);
91175@@ -601,7 +601,7 @@ int register_pernet_device(struct pernet_operations *ops)
91176 mutex_lock(&net_mutex);
91177 error = register_pernet_operations(&pernet_list, ops);
91178 if (!error && (first_device == &pernet_list))
91179- first_device = &ops->list;
91180+ first_device = (struct list_head *)&ops->list;
91181 mutex_unlock(&net_mutex);
91182 return error;
91183 }
91184diff --git a/net/core/netpoll.c b/net/core/netpoll.c
91185index 2c637e9..68c9087 100644
91186--- a/net/core/netpoll.c
91187+++ b/net/core/netpoll.c
91188@@ -428,7 +428,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
91189 struct udphdr *udph;
91190 struct iphdr *iph;
91191 struct ethhdr *eth;
91192- static atomic_t ip_ident;
91193+ static atomic_unchecked_t ip_ident;
91194 struct ipv6hdr *ip6h;
91195
91196 udp_len = len + sizeof(*udph);
91197@@ -499,7 +499,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
91198 put_unaligned(0x45, (unsigned char *)iph);
91199 iph->tos = 0;
91200 put_unaligned(htons(ip_len), &(iph->tot_len));
91201- iph->id = htons(atomic_inc_return(&ip_ident));
91202+ iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
91203 iph->frag_off = 0;
91204 iph->ttl = 64;
91205 iph->protocol = IPPROTO_UDP;
91206diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
91207index ca198c1d1..125372f 100644
91208--- a/net/core/rtnetlink.c
91209+++ b/net/core/rtnetlink.c
91210@@ -58,7 +58,7 @@ struct rtnl_link {
91211 rtnl_doit_func doit;
91212 rtnl_dumpit_func dumpit;
91213 rtnl_calcit_func calcit;
91214-};
91215+} __no_const;
91216
91217 static DEFINE_MUTEX(rtnl_mutex);
91218
91219@@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
91220 if (rtnl_link_ops_get(ops->kind))
91221 return -EEXIST;
91222
91223- if (!ops->dellink)
91224- ops->dellink = unregister_netdevice_queue;
91225+ if (!ops->dellink) {
91226+ pax_open_kernel();
91227+ *(void **)&ops->dellink = unregister_netdevice_queue;
91228+ pax_close_kernel();
91229+ }
91230
91231- list_add_tail(&ops->list, &link_ops);
91232+ pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
91233 return 0;
91234 }
91235 EXPORT_SYMBOL_GPL(__rtnl_link_register);
91236@@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
91237 for_each_net(net) {
91238 __rtnl_kill_links(net, ops);
91239 }
91240- list_del(&ops->list);
91241+ pax_list_del((struct list_head *)&ops->list);
91242 }
91243 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
91244
91245diff --git a/net/core/scm.c b/net/core/scm.c
91246index b4da80b..98d6bdb 100644
91247--- a/net/core/scm.c
91248+++ b/net/core/scm.c
91249@@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
91250 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
91251 {
91252 struct cmsghdr __user *cm
91253- = (__force struct cmsghdr __user *)msg->msg_control;
91254+ = (struct cmsghdr __force_user *)msg->msg_control;
91255 struct cmsghdr cmhdr;
91256 int cmlen = CMSG_LEN(len);
91257 int err;
91258@@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
91259 err = -EFAULT;
91260 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
91261 goto out;
91262- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
91263+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
91264 goto out;
91265 cmlen = CMSG_SPACE(len);
91266 if (msg->msg_controllen < cmlen)
91267@@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
91268 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
91269 {
91270 struct cmsghdr __user *cm
91271- = (__force struct cmsghdr __user*)msg->msg_control;
91272+ = (struct cmsghdr __force_user *)msg->msg_control;
91273
91274 int fdmax = 0;
91275 int fdnum = scm->fp->count;
91276@@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
91277 if (fdnum < fdmax)
91278 fdmax = fdnum;
91279
91280- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
91281+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
91282 i++, cmfptr++)
91283 {
91284 struct socket *sock;
91285diff --git a/net/core/skbuff.c b/net/core/skbuff.c
91286index 2c3d0f5..f5a326f 100644
91287--- a/net/core/skbuff.c
91288+++ b/net/core/skbuff.c
91289@@ -3082,13 +3082,15 @@ void __init skb_init(void)
91290 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
91291 sizeof(struct sk_buff),
91292 0,
91293- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
91294+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
91295+ SLAB_NO_SANITIZE,
91296 NULL);
91297 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
91298 (2*sizeof(struct sk_buff)) +
91299 sizeof(atomic_t),
91300 0,
91301- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
91302+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
91303+ SLAB_NO_SANITIZE,
91304 NULL);
91305 }
91306
91307diff --git a/net/core/sock.c b/net/core/sock.c
91308index 2c097c5..bf72858 100644
91309--- a/net/core/sock.c
91310+++ b/net/core/sock.c
91311@@ -392,7 +392,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
91312 struct sk_buff_head *list = &sk->sk_receive_queue;
91313
91314 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
91315- atomic_inc(&sk->sk_drops);
91316+ atomic_inc_unchecked(&sk->sk_drops);
91317 trace_sock_rcvqueue_full(sk, skb);
91318 return -ENOMEM;
91319 }
91320@@ -402,7 +402,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
91321 return err;
91322
91323 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
91324- atomic_inc(&sk->sk_drops);
91325+ atomic_inc_unchecked(&sk->sk_drops);
91326 return -ENOBUFS;
91327 }
91328
91329@@ -422,7 +422,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
91330 skb_dst_force(skb);
91331
91332 spin_lock_irqsave(&list->lock, flags);
91333- skb->dropcount = atomic_read(&sk->sk_drops);
91334+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
91335 __skb_queue_tail(list, skb);
91336 spin_unlock_irqrestore(&list->lock, flags);
91337
91338@@ -442,7 +442,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
91339 skb->dev = NULL;
91340
91341 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
91342- atomic_inc(&sk->sk_drops);
91343+ atomic_inc_unchecked(&sk->sk_drops);
91344 goto discard_and_relse;
91345 }
91346 if (nested)
91347@@ -460,7 +460,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
91348 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
91349 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
91350 bh_unlock_sock(sk);
91351- atomic_inc(&sk->sk_drops);
91352+ atomic_inc_unchecked(&sk->sk_drops);
91353 goto discard_and_relse;
91354 }
91355
91356@@ -948,12 +948,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
91357 struct timeval tm;
91358 } v;
91359
91360- int lv = sizeof(int);
91361- int len;
91362+ unsigned int lv = sizeof(int);
91363+ unsigned int len;
91364
91365 if (get_user(len, optlen))
91366 return -EFAULT;
91367- if (len < 0)
91368+ if (len > INT_MAX)
91369 return -EINVAL;
91370
91371 memset(&v, 0, sizeof(v));
91372@@ -1105,11 +1105,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
91373
91374 case SO_PEERNAME:
91375 {
91376- char address[128];
91377+ char address[_K_SS_MAXSIZE];
91378
91379 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
91380 return -ENOTCONN;
91381- if (lv < len)
91382+ if (lv < len || sizeof address < len)
91383 return -EINVAL;
91384 if (copy_to_user(optval, address, len))
91385 return -EFAULT;
91386@@ -1182,7 +1182,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
91387
91388 if (len > lv)
91389 len = lv;
91390- if (copy_to_user(optval, &v, len))
91391+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
91392 return -EFAULT;
91393 lenout:
91394 if (put_user(len, optlen))
91395@@ -2303,7 +2303,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
91396 */
91397 smp_wmb();
91398 atomic_set(&sk->sk_refcnt, 1);
91399- atomic_set(&sk->sk_drops, 0);
91400+ atomic_set_unchecked(&sk->sk_drops, 0);
91401 }
91402 EXPORT_SYMBOL(sock_init_data);
91403
91404diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
91405index a0e9cf6..ef7f9ed 100644
91406--- a/net/core/sock_diag.c
91407+++ b/net/core/sock_diag.c
91408@@ -9,26 +9,33 @@
91409 #include <linux/inet_diag.h>
91410 #include <linux/sock_diag.h>
91411
91412-static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
91413+static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
91414 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
91415 static DEFINE_MUTEX(sock_diag_table_mutex);
91416
91417 int sock_diag_check_cookie(void *sk, __u32 *cookie)
91418 {
91419+#ifndef CONFIG_GRKERNSEC_HIDESYM
91420 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
91421 cookie[1] != INET_DIAG_NOCOOKIE) &&
91422 ((u32)(unsigned long)sk != cookie[0] ||
91423 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
91424 return -ESTALE;
91425 else
91426+#endif
91427 return 0;
91428 }
91429 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
91430
91431 void sock_diag_save_cookie(void *sk, __u32 *cookie)
91432 {
91433+#ifdef CONFIG_GRKERNSEC_HIDESYM
91434+ cookie[0] = 0;
91435+ cookie[1] = 0;
91436+#else
91437 cookie[0] = (u32)(unsigned long)sk;
91438 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
91439+#endif
91440 }
91441 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
91442
91443@@ -113,8 +120,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
91444 mutex_lock(&sock_diag_table_mutex);
91445 if (sock_diag_handlers[hndl->family])
91446 err = -EBUSY;
91447- else
91448+ else {
91449+ pax_open_kernel();
91450 sock_diag_handlers[hndl->family] = hndl;
91451+ pax_close_kernel();
91452+ }
91453 mutex_unlock(&sock_diag_table_mutex);
91454
91455 return err;
91456@@ -130,7 +140,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
91457
91458 mutex_lock(&sock_diag_table_mutex);
91459 BUG_ON(sock_diag_handlers[family] != hnld);
91460+ pax_open_kernel();
91461 sock_diag_handlers[family] = NULL;
91462+ pax_close_kernel();
91463 mutex_unlock(&sock_diag_table_mutex);
91464 }
91465 EXPORT_SYMBOL_GPL(sock_diag_unregister);
91466diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
91467index 31107ab..ae03d5a 100644
91468--- a/net/core/sysctl_net_core.c
91469+++ b/net/core/sysctl_net_core.c
91470@@ -31,7 +31,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
91471 {
91472 unsigned int orig_size, size;
91473 int ret, i;
91474- struct ctl_table tmp = {
91475+ ctl_table_no_const tmp = {
91476 .data = &size,
91477 .maxlen = sizeof(size),
91478 .mode = table->mode
91479@@ -350,13 +350,12 @@ static struct ctl_table netns_core_table[] = {
91480
91481 static __net_init int sysctl_core_net_init(struct net *net)
91482 {
91483- struct ctl_table *tbl;
91484+ ctl_table_no_const *tbl = NULL;
91485
91486 net->core.sysctl_somaxconn = SOMAXCONN;
91487
91488- tbl = netns_core_table;
91489 if (!net_eq(net, &init_net)) {
91490- tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
91491+ tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
91492 if (tbl == NULL)
91493 goto err_dup;
91494
91495@@ -366,17 +365,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
91496 if (net->user_ns != &init_user_ns) {
91497 tbl[0].procname = NULL;
91498 }
91499- }
91500-
91501- net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
91502+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
91503+ } else
91504+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
91505 if (net->core.sysctl_hdr == NULL)
91506 goto err_reg;
91507
91508 return 0;
91509
91510 err_reg:
91511- if (tbl != netns_core_table)
91512- kfree(tbl);
91513+ kfree(tbl);
91514 err_dup:
91515 return -ENOMEM;
91516 }
91517@@ -391,7 +389,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
91518 kfree(tbl);
91519 }
91520
91521-static __net_initdata struct pernet_operations sysctl_core_ops = {
91522+static __net_initconst struct pernet_operations sysctl_core_ops = {
91523 .init = sysctl_core_net_init,
91524 .exit = sysctl_core_net_exit,
91525 };
91526diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
91527index dd4d506..fb2fb87 100644
91528--- a/net/decnet/af_decnet.c
91529+++ b/net/decnet/af_decnet.c
91530@@ -465,6 +465,7 @@ static struct proto dn_proto = {
91531 .sysctl_rmem = sysctl_decnet_rmem,
91532 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
91533 .obj_size = sizeof(struct dn_sock),
91534+ .slab_flags = SLAB_USERCOPY,
91535 };
91536
91537 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
91538diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
91539index 5325b54..a0d4d69 100644
91540--- a/net/decnet/sysctl_net_decnet.c
91541+++ b/net/decnet/sysctl_net_decnet.c
91542@@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
91543
91544 if (len > *lenp) len = *lenp;
91545
91546- if (copy_to_user(buffer, addr, len))
91547+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
91548 return -EFAULT;
91549
91550 *lenp = len;
91551@@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
91552
91553 if (len > *lenp) len = *lenp;
91554
91555- if (copy_to_user(buffer, devname, len))
91556+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
91557 return -EFAULT;
91558
91559 *lenp = len;
91560diff --git a/net/ieee802154/6lowpan.c b/net/ieee802154/6lowpan.c
91561index 3b9d5f2..d7015c6 100644
91562--- a/net/ieee802154/6lowpan.c
91563+++ b/net/ieee802154/6lowpan.c
91564@@ -459,7 +459,7 @@ static int lowpan_header_create(struct sk_buff *skb,
91565 hc06_ptr += 3;
91566 } else {
91567 /* compress nothing */
91568- memcpy(hc06_ptr, &hdr, 4);
91569+ memcpy(hc06_ptr, hdr, 4);
91570 /* replace the top byte with new ECN | DSCP format */
91571 *hc06_ptr = tmp;
91572 hc06_ptr += 4;
91573diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
91574index b4d0be2..443d0f0 100644
91575--- a/net/ipv4/af_inet.c
91576+++ b/net/ipv4/af_inet.c
91577@@ -1689,13 +1689,9 @@ static int __init inet_init(void)
91578
91579 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb));
91580
91581- sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
91582- if (!sysctl_local_reserved_ports)
91583- goto out;
91584-
91585 rc = proto_register(&tcp_prot, 1);
91586 if (rc)
91587- goto out_free_reserved_ports;
91588+ goto out;
91589
91590 rc = proto_register(&udp_prot, 1);
91591 if (rc)
91592@@ -1804,8 +1800,6 @@ out_unregister_udp_proto:
91593 proto_unregister(&udp_prot);
91594 out_unregister_tcp_proto:
91595 proto_unregister(&tcp_prot);
91596-out_free_reserved_ports:
91597- kfree(sysctl_local_reserved_ports);
91598 goto out;
91599 }
91600
91601diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
91602index 34ca6d5..b6421e8 100644
91603--- a/net/ipv4/devinet.c
91604+++ b/net/ipv4/devinet.c
91605@@ -1532,7 +1532,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
91606 idx = 0;
91607 head = &net->dev_index_head[h];
91608 rcu_read_lock();
91609- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
91610+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
91611 net->dev_base_seq;
91612 hlist_for_each_entry_rcu(dev, head, index_hlist) {
91613 if (idx < s_idx)
91614@@ -1843,7 +1843,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
91615 idx = 0;
91616 head = &net->dev_index_head[h];
91617 rcu_read_lock();
91618- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
91619+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
91620 net->dev_base_seq;
91621 hlist_for_each_entry_rcu(dev, head, index_hlist) {
91622 if (idx < s_idx)
91623@@ -2068,7 +2068,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
91624 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
91625 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
91626
91627-static struct devinet_sysctl_table {
91628+static const struct devinet_sysctl_table {
91629 struct ctl_table_header *sysctl_header;
91630 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
91631 } devinet_sysctl = {
91632@@ -2186,7 +2186,7 @@ static __net_init int devinet_init_net(struct net *net)
91633 int err;
91634 struct ipv4_devconf *all, *dflt;
91635 #ifdef CONFIG_SYSCTL
91636- struct ctl_table *tbl = ctl_forward_entry;
91637+ ctl_table_no_const *tbl = NULL;
91638 struct ctl_table_header *forw_hdr;
91639 #endif
91640
91641@@ -2204,7 +2204,7 @@ static __net_init int devinet_init_net(struct net *net)
91642 goto err_alloc_dflt;
91643
91644 #ifdef CONFIG_SYSCTL
91645- tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
91646+ tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
91647 if (tbl == NULL)
91648 goto err_alloc_ctl;
91649
91650@@ -2224,7 +2224,10 @@ static __net_init int devinet_init_net(struct net *net)
91651 goto err_reg_dflt;
91652
91653 err = -ENOMEM;
91654- forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
91655+ if (!net_eq(net, &init_net))
91656+ forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
91657+ else
91658+ forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
91659 if (forw_hdr == NULL)
91660 goto err_reg_ctl;
91661 net->ipv4.forw_hdr = forw_hdr;
91662@@ -2240,8 +2243,7 @@ err_reg_ctl:
91663 err_reg_dflt:
91664 __devinet_sysctl_unregister(all);
91665 err_reg_all:
91666- if (tbl != ctl_forward_entry)
91667- kfree(tbl);
91668+ kfree(tbl);
91669 err_alloc_ctl:
91670 #endif
91671 if (dflt != &ipv4_devconf_dflt)
91672diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
91673index b3f627a..b0f3e99 100644
91674--- a/net/ipv4/fib_frontend.c
91675+++ b/net/ipv4/fib_frontend.c
91676@@ -1017,12 +1017,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
91677 #ifdef CONFIG_IP_ROUTE_MULTIPATH
91678 fib_sync_up(dev);
91679 #endif
91680- atomic_inc(&net->ipv4.dev_addr_genid);
91681+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
91682 rt_cache_flush(dev_net(dev));
91683 break;
91684 case NETDEV_DOWN:
91685 fib_del_ifaddr(ifa, NULL);
91686- atomic_inc(&net->ipv4.dev_addr_genid);
91687+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
91688 if (ifa->ifa_dev->ifa_list == NULL) {
91689 /* Last address was deleted from this interface.
91690 * Disable IP.
91691@@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
91692 #ifdef CONFIG_IP_ROUTE_MULTIPATH
91693 fib_sync_up(dev);
91694 #endif
91695- atomic_inc(&net->ipv4.dev_addr_genid);
91696+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
91697 rt_cache_flush(net);
91698 break;
91699 case NETDEV_DOWN:
91700diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
91701index d5dbca5..6251d5f 100644
91702--- a/net/ipv4/fib_semantics.c
91703+++ b/net/ipv4/fib_semantics.c
91704@@ -766,7 +766,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
91705 nh->nh_saddr = inet_select_addr(nh->nh_dev,
91706 nh->nh_gw,
91707 nh->nh_parent->fib_scope);
91708- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
91709+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
91710
91711 return nh->nh_saddr;
91712 }
91713diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
91714index 6acb541..9ea617d 100644
91715--- a/net/ipv4/inet_connection_sock.c
91716+++ b/net/ipv4/inet_connection_sock.c
91717@@ -37,7 +37,7 @@ struct local_ports sysctl_local_ports __read_mostly = {
91718 .range = { 32768, 61000 },
91719 };
91720
91721-unsigned long *sysctl_local_reserved_ports;
91722+unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
91723 EXPORT_SYMBOL(sysctl_local_reserved_ports);
91724
91725 void inet_get_local_port_range(int *low, int *high)
91726diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
91727index 7bd8983..3abdcf6 100644
91728--- a/net/ipv4/inet_hashtables.c
91729+++ b/net/ipv4/inet_hashtables.c
91730@@ -18,12 +18,15 @@
91731 #include <linux/sched.h>
91732 #include <linux/slab.h>
91733 #include <linux/wait.h>
91734+#include <linux/security.h>
91735
91736 #include <net/inet_connection_sock.h>
91737 #include <net/inet_hashtables.h>
91738 #include <net/secure_seq.h>
91739 #include <net/ip.h>
91740
91741+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
91742+
91743 /*
91744 * Allocate and initialize a new local port bind bucket.
91745 * The bindhash mutex for snum's hash chain must be held here.
91746@@ -554,6 +557,8 @@ ok:
91747 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
91748 spin_unlock(&head->lock);
91749
91750+ gr_update_task_in_ip_table(current, inet_sk(sk));
91751+
91752 if (tw) {
91753 inet_twsk_deschedule(tw, death_row);
91754 while (twrefcnt) {
91755diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
91756index 000e3d2..5472da3 100644
91757--- a/net/ipv4/inetpeer.c
91758+++ b/net/ipv4/inetpeer.c
91759@@ -503,8 +503,8 @@ relookup:
91760 if (p) {
91761 p->daddr = *daddr;
91762 atomic_set(&p->refcnt, 1);
91763- atomic_set(&p->rid, 0);
91764- atomic_set(&p->ip_id_count,
91765+ atomic_set_unchecked(&p->rid, 0);
91766+ atomic_set_unchecked(&p->ip_id_count,
91767 (daddr->family == AF_INET) ?
91768 secure_ip_id(daddr->addr.a4) :
91769 secure_ipv6_id(daddr->addr.a6));
91770diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
91771index b66910a..cfe416e 100644
91772--- a/net/ipv4/ip_fragment.c
91773+++ b/net/ipv4/ip_fragment.c
91774@@ -282,7 +282,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
91775 return 0;
91776
91777 start = qp->rid;
91778- end = atomic_inc_return(&peer->rid);
91779+ end = atomic_inc_return_unchecked(&peer->rid);
91780 qp->rid = end;
91781
91782 rc = qp->q.fragments && (end - start) > max;
91783@@ -759,12 +759,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
91784
91785 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
91786 {
91787- struct ctl_table *table;
91788+ ctl_table_no_const *table = NULL;
91789 struct ctl_table_header *hdr;
91790
91791- table = ip4_frags_ns_ctl_table;
91792 if (!net_eq(net, &init_net)) {
91793- table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
91794+ table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
91795 if (table == NULL)
91796 goto err_alloc;
91797
91798@@ -775,9 +774,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
91799 /* Don't export sysctls to unprivileged users */
91800 if (net->user_ns != &init_user_ns)
91801 table[0].procname = NULL;
91802- }
91803+ hdr = register_net_sysctl(net, "net/ipv4", table);
91804+ } else
91805+ hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
91806
91807- hdr = register_net_sysctl(net, "net/ipv4", table);
91808 if (hdr == NULL)
91809 goto err_reg;
91810
91811@@ -785,8 +785,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
91812 return 0;
91813
91814 err_reg:
91815- if (!net_eq(net, &init_net))
91816- kfree(table);
91817+ kfree(table);
91818 err_alloc:
91819 return -ENOMEM;
91820 }
91821diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
91822index 8d6939e..19d0a95 100644
91823--- a/net/ipv4/ip_gre.c
91824+++ b/net/ipv4/ip_gre.c
91825@@ -115,7 +115,7 @@ static bool log_ecn_error = true;
91826 module_param(log_ecn_error, bool, 0644);
91827 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
91828
91829-static struct rtnl_link_ops ipgre_link_ops __read_mostly;
91830+static struct rtnl_link_ops ipgre_link_ops;
91831 static int ipgre_tunnel_init(struct net_device *dev);
91832
91833 static int ipgre_net_id __read_mostly;
91834@@ -731,7 +731,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
91835 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
91836 };
91837
91838-static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
91839+static struct rtnl_link_ops ipgre_link_ops = {
91840 .kind = "gre",
91841 .maxtype = IFLA_GRE_MAX,
91842 .policy = ipgre_policy,
91843@@ -745,7 +745,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
91844 .fill_info = ipgre_fill_info,
91845 };
91846
91847-static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
91848+static struct rtnl_link_ops ipgre_tap_ops = {
91849 .kind = "gretap",
91850 .maxtype = IFLA_GRE_MAX,
91851 .policy = ipgre_policy,
91852diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
91853index d9c4f11..02b82dbc 100644
91854--- a/net/ipv4/ip_sockglue.c
91855+++ b/net/ipv4/ip_sockglue.c
91856@@ -1152,7 +1152,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
91857 len = min_t(unsigned int, len, opt->optlen);
91858 if (put_user(len, optlen))
91859 return -EFAULT;
91860- if (copy_to_user(optval, opt->__data, len))
91861+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
91862+ copy_to_user(optval, opt->__data, len))
91863 return -EFAULT;
91864 return 0;
91865 }
91866@@ -1283,7 +1284,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
91867 if (sk->sk_type != SOCK_STREAM)
91868 return -ENOPROTOOPT;
91869
91870- msg.msg_control = optval;
91871+ msg.msg_control = (void __force_kernel *)optval;
91872 msg.msg_controllen = len;
91873 msg.msg_flags = flags;
91874
91875diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
91876index 17cc0ff..63856c4 100644
91877--- a/net/ipv4/ip_vti.c
91878+++ b/net/ipv4/ip_vti.c
91879@@ -47,7 +47,7 @@
91880 #define HASH_SIZE 16
91881 #define HASH(addr) (((__force u32)addr^((__force u32)addr>>4))&(HASH_SIZE-1))
91882
91883-static struct rtnl_link_ops vti_link_ops __read_mostly;
91884+static struct rtnl_link_ops vti_link_ops;
91885
91886 static int vti_net_id __read_mostly;
91887 struct vti_net {
91888@@ -840,7 +840,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
91889 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
91890 };
91891
91892-static struct rtnl_link_ops vti_link_ops __read_mostly = {
91893+static struct rtnl_link_ops vti_link_ops = {
91894 .kind = "vti",
91895 .maxtype = IFLA_VTI_MAX,
91896 .policy = vti_policy,
91897diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
91898index efa1138..20dbba0 100644
91899--- a/net/ipv4/ipconfig.c
91900+++ b/net/ipv4/ipconfig.c
91901@@ -334,7 +334,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
91902
91903 mm_segment_t oldfs = get_fs();
91904 set_fs(get_ds());
91905- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
91906+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
91907 set_fs(oldfs);
91908 return res;
91909 }
91910@@ -345,7 +345,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
91911
91912 mm_segment_t oldfs = get_fs();
91913 set_fs(get_ds());
91914- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
91915+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
91916 set_fs(oldfs);
91917 return res;
91918 }
91919@@ -356,7 +356,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
91920
91921 mm_segment_t oldfs = get_fs();
91922 set_fs(get_ds());
91923- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
91924+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
91925 set_fs(oldfs);
91926 return res;
91927 }
91928diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
91929index b3ac3c3..ec6bd95 100644
91930--- a/net/ipv4/ipip.c
91931+++ b/net/ipv4/ipip.c
91932@@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
91933 static int ipip_net_id __read_mostly;
91934
91935 static int ipip_tunnel_init(struct net_device *dev);
91936-static struct rtnl_link_ops ipip_link_ops __read_mostly;
91937+static struct rtnl_link_ops ipip_link_ops;
91938
91939 static int ipip_err(struct sk_buff *skb, u32 info)
91940 {
91941@@ -409,7 +409,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
91942 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
91943 };
91944
91945-static struct rtnl_link_ops ipip_link_ops __read_mostly = {
91946+static struct rtnl_link_ops ipip_link_ops = {
91947 .kind = "ipip",
91948 .maxtype = IFLA_IPTUN_MAX,
91949 .policy = ipip_policy,
91950diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
91951index 85a4f21..1beb1f5 100644
91952--- a/net/ipv4/netfilter/arp_tables.c
91953+++ b/net/ipv4/netfilter/arp_tables.c
91954@@ -880,14 +880,14 @@ static int compat_table_info(const struct xt_table_info *info,
91955 #endif
91956
91957 static int get_info(struct net *net, void __user *user,
91958- const int *len, int compat)
91959+ int len, int compat)
91960 {
91961 char name[XT_TABLE_MAXNAMELEN];
91962 struct xt_table *t;
91963 int ret;
91964
91965- if (*len != sizeof(struct arpt_getinfo)) {
91966- duprintf("length %u != %Zu\n", *len,
91967+ if (len != sizeof(struct arpt_getinfo)) {
91968+ duprintf("length %u != %Zu\n", len,
91969 sizeof(struct arpt_getinfo));
91970 return -EINVAL;
91971 }
91972@@ -924,7 +924,7 @@ static int get_info(struct net *net, void __user *user,
91973 info.size = private->size;
91974 strcpy(info.name, name);
91975
91976- if (copy_to_user(user, &info, *len) != 0)
91977+ if (copy_to_user(user, &info, len) != 0)
91978 ret = -EFAULT;
91979 else
91980 ret = 0;
91981@@ -1683,7 +1683,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
91982
91983 switch (cmd) {
91984 case ARPT_SO_GET_INFO:
91985- ret = get_info(sock_net(sk), user, len, 1);
91986+ ret = get_info(sock_net(sk), user, *len, 1);
91987 break;
91988 case ARPT_SO_GET_ENTRIES:
91989 ret = compat_get_entries(sock_net(sk), user, len);
91990@@ -1728,7 +1728,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
91991
91992 switch (cmd) {
91993 case ARPT_SO_GET_INFO:
91994- ret = get_info(sock_net(sk), user, len, 0);
91995+ ret = get_info(sock_net(sk), user, *len, 0);
91996 break;
91997
91998 case ARPT_SO_GET_ENTRIES:
91999diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
92000index d23118d..6ad7277 100644
92001--- a/net/ipv4/netfilter/ip_tables.c
92002+++ b/net/ipv4/netfilter/ip_tables.c
92003@@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
92004 #endif
92005
92006 static int get_info(struct net *net, void __user *user,
92007- const int *len, int compat)
92008+ int len, int compat)
92009 {
92010 char name[XT_TABLE_MAXNAMELEN];
92011 struct xt_table *t;
92012 int ret;
92013
92014- if (*len != sizeof(struct ipt_getinfo)) {
92015- duprintf("length %u != %zu\n", *len,
92016+ if (len != sizeof(struct ipt_getinfo)) {
92017+ duprintf("length %u != %zu\n", len,
92018 sizeof(struct ipt_getinfo));
92019 return -EINVAL;
92020 }
92021@@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
92022 info.size = private->size;
92023 strcpy(info.name, name);
92024
92025- if (copy_to_user(user, &info, *len) != 0)
92026+ if (copy_to_user(user, &info, len) != 0)
92027 ret = -EFAULT;
92028 else
92029 ret = 0;
92030@@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
92031
92032 switch (cmd) {
92033 case IPT_SO_GET_INFO:
92034- ret = get_info(sock_net(sk), user, len, 1);
92035+ ret = get_info(sock_net(sk), user, *len, 1);
92036 break;
92037 case IPT_SO_GET_ENTRIES:
92038 ret = compat_get_entries(sock_net(sk), user, len);
92039@@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
92040
92041 switch (cmd) {
92042 case IPT_SO_GET_INFO:
92043- ret = get_info(sock_net(sk), user, len, 0);
92044+ ret = get_info(sock_net(sk), user, *len, 0);
92045 break;
92046
92047 case IPT_SO_GET_ENTRIES:
92048diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
92049index 746427c..80eab72 100644
92050--- a/net/ipv4/ping.c
92051+++ b/net/ipv4/ping.c
92052@@ -55,7 +55,7 @@
92053
92054
92055 struct ping_table ping_table;
92056-struct pingv6_ops pingv6_ops;
92057+struct pingv6_ops *pingv6_ops;
92058 EXPORT_SYMBOL_GPL(pingv6_ops);
92059
92060 static u16 ping_port_rover;
92061@@ -335,7 +335,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
92062 return -ENODEV;
92063 }
92064 }
92065- has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
92066+ has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
92067 scoped);
92068 rcu_read_unlock();
92069
92070@@ -541,7 +541,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
92071 }
92072 #if IS_ENABLED(CONFIG_IPV6)
92073 } else if (skb->protocol == htons(ETH_P_IPV6)) {
92074- harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
92075+ harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
92076 #endif
92077 }
92078
92079@@ -559,7 +559,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
92080 info, (u8 *)icmph);
92081 #if IS_ENABLED(CONFIG_IPV6)
92082 } else if (family == AF_INET6) {
92083- pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
92084+ pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
92085 info, (u8 *)icmph);
92086 #endif
92087 }
92088@@ -850,7 +850,7 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
92089 return ip_recv_error(sk, msg, len);
92090 #if IS_ENABLED(CONFIG_IPV6)
92091 } else if (family == AF_INET6) {
92092- return pingv6_ops.ipv6_recv_error(sk, msg, len);
92093+ return pingv6_ops->ipv6_recv_error(sk, msg, len);
92094 #endif
92095 }
92096 }
92097@@ -900,7 +900,7 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
92098 IP6CB(skb)->iif);
92099
92100 if (inet6_sk(sk)->rxopt.all)
92101- pingv6_ops.ip6_datagram_recv_ctl(sk, msg, skb);
92102+ pingv6_ops->ip6_datagram_recv_ctl(sk, msg, skb);
92103 #endif
92104 } else {
92105 BUG();
92106@@ -1090,7 +1090,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
92107 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
92108 0, sock_i_ino(sp),
92109 atomic_read(&sp->sk_refcnt), sp,
92110- atomic_read(&sp->sk_drops), len);
92111+ atomic_read_unchecked(&sp->sk_drops), len);
92112 }
92113
92114 static int ping_v4_seq_show(struct seq_file *seq, void *v)
92115diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
92116index 61e60d6..d6996cd 100644
92117--- a/net/ipv4/raw.c
92118+++ b/net/ipv4/raw.c
92119@@ -309,7 +309,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
92120 int raw_rcv(struct sock *sk, struct sk_buff *skb)
92121 {
92122 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
92123- atomic_inc(&sk->sk_drops);
92124+ atomic_inc_unchecked(&sk->sk_drops);
92125 kfree_skb(skb);
92126 return NET_RX_DROP;
92127 }
92128@@ -746,16 +746,20 @@ static int raw_init(struct sock *sk)
92129
92130 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
92131 {
92132+ struct icmp_filter filter;
92133+
92134 if (optlen > sizeof(struct icmp_filter))
92135 optlen = sizeof(struct icmp_filter);
92136- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
92137+ if (copy_from_user(&filter, optval, optlen))
92138 return -EFAULT;
92139+ raw_sk(sk)->filter = filter;
92140 return 0;
92141 }
92142
92143 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
92144 {
92145 int len, ret = -EFAULT;
92146+ struct icmp_filter filter;
92147
92148 if (get_user(len, optlen))
92149 goto out;
92150@@ -765,8 +769,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
92151 if (len > sizeof(struct icmp_filter))
92152 len = sizeof(struct icmp_filter);
92153 ret = -EFAULT;
92154- if (put_user(len, optlen) ||
92155- copy_to_user(optval, &raw_sk(sk)->filter, len))
92156+ filter = raw_sk(sk)->filter;
92157+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
92158 goto out;
92159 ret = 0;
92160 out: return ret;
92161@@ -995,7 +999,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
92162 0, 0L, 0,
92163 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
92164 0, sock_i_ino(sp),
92165- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
92166+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
92167 }
92168
92169 static int raw_seq_show(struct seq_file *seq, void *v)
92170diff --git a/net/ipv4/route.c b/net/ipv4/route.c
92171index a9a54a2..647316e 100644
92172--- a/net/ipv4/route.c
92173+++ b/net/ipv4/route.c
92174@@ -2615,34 +2615,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
92175 .maxlen = sizeof(int),
92176 .mode = 0200,
92177 .proc_handler = ipv4_sysctl_rtcache_flush,
92178+ .extra1 = &init_net,
92179 },
92180 { },
92181 };
92182
92183 static __net_init int sysctl_route_net_init(struct net *net)
92184 {
92185- struct ctl_table *tbl;
92186+ ctl_table_no_const *tbl = NULL;
92187
92188- tbl = ipv4_route_flush_table;
92189 if (!net_eq(net, &init_net)) {
92190- tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
92191+ tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
92192 if (tbl == NULL)
92193 goto err_dup;
92194
92195 /* Don't export sysctls to unprivileged users */
92196 if (net->user_ns != &init_user_ns)
92197 tbl[0].procname = NULL;
92198- }
92199- tbl[0].extra1 = net;
92200+ tbl[0].extra1 = net;
92201+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
92202+ } else
92203+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
92204
92205- net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
92206 if (net->ipv4.route_hdr == NULL)
92207 goto err_reg;
92208 return 0;
92209
92210 err_reg:
92211- if (tbl != ipv4_route_flush_table)
92212- kfree(tbl);
92213+ kfree(tbl);
92214 err_dup:
92215 return -ENOMEM;
92216 }
92217@@ -2665,8 +2665,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
92218
92219 static __net_init int rt_genid_init(struct net *net)
92220 {
92221- atomic_set(&net->rt_genid, 0);
92222- atomic_set(&net->fnhe_genid, 0);
92223+ atomic_set_unchecked(&net->rt_genid, 0);
92224+ atomic_set_unchecked(&net->fnhe_genid, 0);
92225 get_random_bytes(&net->ipv4.dev_addr_genid,
92226 sizeof(net->ipv4.dev_addr_genid));
92227 return 0;
92228diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
92229index 610e324..fd42e75 100644
92230--- a/net/ipv4/sysctl_net_ipv4.c
92231+++ b/net/ipv4/sysctl_net_ipv4.c
92232@@ -57,7 +57,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
92233 {
92234 int ret;
92235 int range[2];
92236- struct ctl_table tmp = {
92237+ ctl_table_no_const tmp = {
92238 .data = &range,
92239 .maxlen = sizeof(range),
92240 .mode = table->mode,
92241@@ -110,7 +110,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
92242 int ret;
92243 gid_t urange[2];
92244 kgid_t low, high;
92245- struct ctl_table tmp = {
92246+ ctl_table_no_const tmp = {
92247 .data = &urange,
92248 .maxlen = sizeof(urange),
92249 .mode = table->mode,
92250@@ -141,7 +141,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
92251 void __user *buffer, size_t *lenp, loff_t *ppos)
92252 {
92253 char val[TCP_CA_NAME_MAX];
92254- struct ctl_table tbl = {
92255+ ctl_table_no_const tbl = {
92256 .data = val,
92257 .maxlen = TCP_CA_NAME_MAX,
92258 };
92259@@ -160,7 +160,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
92260 void __user *buffer, size_t *lenp,
92261 loff_t *ppos)
92262 {
92263- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
92264+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
92265 int ret;
92266
92267 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
92268@@ -177,7 +177,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
92269 void __user *buffer, size_t *lenp,
92270 loff_t *ppos)
92271 {
92272- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
92273+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
92274 int ret;
92275
92276 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
92277@@ -203,15 +203,17 @@ static int ipv4_tcp_mem(struct ctl_table *ctl, int write,
92278 struct mem_cgroup *memcg;
92279 #endif
92280
92281- struct ctl_table tmp = {
92282+ ctl_table_no_const tmp = {
92283 .data = &vec,
92284 .maxlen = sizeof(vec),
92285 .mode = ctl->mode,
92286 };
92287
92288 if (!write) {
92289- ctl->data = &net->ipv4.sysctl_tcp_mem;
92290- return proc_doulongvec_minmax(ctl, write, buffer, lenp, ppos);
92291+ ctl_table_no_const tcp_mem = *ctl;
92292+
92293+ tcp_mem.data = &net->ipv4.sysctl_tcp_mem;
92294+ return proc_doulongvec_minmax(&tcp_mem, write, buffer, lenp, ppos);
92295 }
92296
92297 ret = proc_doulongvec_minmax(&tmp, write, buffer, lenp, ppos);
92298@@ -239,7 +241,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
92299 void __user *buffer, size_t *lenp,
92300 loff_t *ppos)
92301 {
92302- struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
92303+ ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
92304 struct tcp_fastopen_context *ctxt;
92305 int ret;
92306 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
92307@@ -482,7 +484,7 @@ static struct ctl_table ipv4_table[] = {
92308 },
92309 {
92310 .procname = "ip_local_reserved_ports",
92311- .data = NULL, /* initialized in sysctl_ipv4_init */
92312+ .data = sysctl_local_reserved_ports,
92313 .maxlen = 65536,
92314 .mode = 0644,
92315 .proc_handler = proc_do_large_bitmap,
92316@@ -847,11 +849,10 @@ static struct ctl_table ipv4_net_table[] = {
92317
92318 static __net_init int ipv4_sysctl_init_net(struct net *net)
92319 {
92320- struct ctl_table *table;
92321+ ctl_table_no_const *table = NULL;
92322
92323- table = ipv4_net_table;
92324 if (!net_eq(net, &init_net)) {
92325- table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
92326+ table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
92327 if (table == NULL)
92328 goto err_alloc;
92329
92330@@ -886,15 +887,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
92331
92332 tcp_init_mem(net);
92333
92334- net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
92335+ if (!net_eq(net, &init_net))
92336+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
92337+ else
92338+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
92339 if (net->ipv4.ipv4_hdr == NULL)
92340 goto err_reg;
92341
92342 return 0;
92343
92344 err_reg:
92345- if (!net_eq(net, &init_net))
92346- kfree(table);
92347+ kfree(table);
92348 err_alloc:
92349 return -ENOMEM;
92350 }
92351@@ -916,16 +919,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
92352 static __init int sysctl_ipv4_init(void)
92353 {
92354 struct ctl_table_header *hdr;
92355- struct ctl_table *i;
92356-
92357- for (i = ipv4_table; i->procname; i++) {
92358- if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
92359- i->data = sysctl_local_reserved_ports;
92360- break;
92361- }
92362- }
92363- if (!i->procname)
92364- return -EINVAL;
92365
92366 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
92367 if (hdr == NULL)
92368diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
92369index 3ca2139..c4cc060 100644
92370--- a/net/ipv4/tcp_input.c
92371+++ b/net/ipv4/tcp_input.c
92372@@ -4379,7 +4379,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
92373 * simplifies code)
92374 */
92375 static void
92376-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
92377+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
92378 struct sk_buff *head, struct sk_buff *tail,
92379 u32 start, u32 end)
92380 {
92381@@ -5465,6 +5465,7 @@ discard:
92382 tcp_paws_reject(&tp->rx_opt, 0))
92383 goto discard_and_undo;
92384
92385+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
92386 if (th->syn) {
92387 /* We see SYN without ACK. It is attempt of
92388 * simultaneous connect with crossed SYNs.
92389@@ -5515,6 +5516,7 @@ discard:
92390 goto discard;
92391 #endif
92392 }
92393+#endif
92394 /* "fifth, if neither of the SYN or RST bits is set then
92395 * drop the segment and return."
92396 */
92397@@ -5560,7 +5562,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
92398 goto discard;
92399
92400 if (th->syn) {
92401- if (th->fin)
92402+ if (th->fin || th->urg || th->psh)
92403 goto discard;
92404 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
92405 return 1;
92406diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
92407index b299da5..097db06 100644
92408--- a/net/ipv4/tcp_ipv4.c
92409+++ b/net/ipv4/tcp_ipv4.c
92410@@ -91,6 +91,10 @@ int sysctl_tcp_low_latency __read_mostly;
92411 EXPORT_SYMBOL(sysctl_tcp_low_latency);
92412
92413
92414+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92415+extern int grsec_enable_blackhole;
92416+#endif
92417+
92418 #ifdef CONFIG_TCP_MD5SIG
92419 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
92420 __be32 daddr, __be32 saddr, const struct tcphdr *th);
92421@@ -1830,6 +1834,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
92422 return 0;
92423
92424 reset:
92425+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92426+ if (!grsec_enable_blackhole)
92427+#endif
92428 tcp_v4_send_reset(rsk, skb);
92429 discard:
92430 kfree_skb(skb);
92431@@ -1975,12 +1982,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
92432 TCP_SKB_CB(skb)->sacked = 0;
92433
92434 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
92435- if (!sk)
92436+ if (!sk) {
92437+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92438+ ret = 1;
92439+#endif
92440 goto no_tcp_socket;
92441-
92442+ }
92443 process:
92444- if (sk->sk_state == TCP_TIME_WAIT)
92445+ if (sk->sk_state == TCP_TIME_WAIT) {
92446+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92447+ ret = 2;
92448+#endif
92449 goto do_time_wait;
92450+ }
92451
92452 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
92453 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
92454@@ -2034,6 +2048,10 @@ csum_error:
92455 bad_packet:
92456 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
92457 } else {
92458+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92459+ if (!grsec_enable_blackhole || (ret == 1 &&
92460+ (skb->dev->flags & IFF_LOOPBACK)))
92461+#endif
92462 tcp_v4_send_reset(NULL, skb);
92463 }
92464
92465diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
92466index ab1c086..2a8d76b 100644
92467--- a/net/ipv4/tcp_minisocks.c
92468+++ b/net/ipv4/tcp_minisocks.c
92469@@ -27,6 +27,10 @@
92470 #include <net/inet_common.h>
92471 #include <net/xfrm.h>
92472
92473+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92474+extern int grsec_enable_blackhole;
92475+#endif
92476+
92477 int sysctl_tcp_syncookies __read_mostly = 1;
92478 EXPORT_SYMBOL(sysctl_tcp_syncookies);
92479
92480@@ -715,7 +719,10 @@ embryonic_reset:
92481 * avoid becoming vulnerable to outside attack aiming at
92482 * resetting legit local connections.
92483 */
92484- req->rsk_ops->send_reset(sk, skb);
92485+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92486+ if (!grsec_enable_blackhole)
92487+#endif
92488+ req->rsk_ops->send_reset(sk, skb);
92489 } else if (fastopen) { /* received a valid RST pkt */
92490 reqsk_fastopen_remove(sk, req, true);
92491 tcp_reset(sk);
92492diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
92493index d4943f6..e7a74a5 100644
92494--- a/net/ipv4/tcp_probe.c
92495+++ b/net/ipv4/tcp_probe.c
92496@@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
92497 if (cnt + width >= len)
92498 break;
92499
92500- if (copy_to_user(buf + cnt, tbuf, width))
92501+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
92502 return -EFAULT;
92503 cnt += width;
92504 }
92505diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
92506index 4b85e6f..22f9ac9 100644
92507--- a/net/ipv4/tcp_timer.c
92508+++ b/net/ipv4/tcp_timer.c
92509@@ -22,6 +22,10 @@
92510 #include <linux/gfp.h>
92511 #include <net/tcp.h>
92512
92513+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92514+extern int grsec_lastack_retries;
92515+#endif
92516+
92517 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
92518 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
92519 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
92520@@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
92521 }
92522 }
92523
92524+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92525+ if ((sk->sk_state == TCP_LAST_ACK) &&
92526+ (grsec_lastack_retries > 0) &&
92527+ (grsec_lastack_retries < retry_until))
92528+ retry_until = grsec_lastack_retries;
92529+#endif
92530+
92531 if (retransmits_timed_out(sk, retry_until,
92532 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
92533 /* Has it gone just too far? */
92534diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
92535index 766e6ba..aff2f8d 100644
92536--- a/net/ipv4/udp.c
92537+++ b/net/ipv4/udp.c
92538@@ -87,6 +87,7 @@
92539 #include <linux/types.h>
92540 #include <linux/fcntl.h>
92541 #include <linux/module.h>
92542+#include <linux/security.h>
92543 #include <linux/socket.h>
92544 #include <linux/sockios.h>
92545 #include <linux/igmp.h>
92546@@ -112,6 +113,10 @@
92547 #include <net/busy_poll.h>
92548 #include "udp_impl.h"
92549
92550+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92551+extern int grsec_enable_blackhole;
92552+#endif
92553+
92554 struct udp_table udp_table __read_mostly;
92555 EXPORT_SYMBOL(udp_table);
92556
92557@@ -595,6 +600,9 @@ found:
92558 return s;
92559 }
92560
92561+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
92562+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
92563+
92564 /*
92565 * This routine is called by the ICMP module when it gets some
92566 * sort of error condition. If err < 0 then the socket should
92567@@ -891,9 +899,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
92568 dport = usin->sin_port;
92569 if (dport == 0)
92570 return -EINVAL;
92571+
92572+ err = gr_search_udp_sendmsg(sk, usin);
92573+ if (err)
92574+ return err;
92575 } else {
92576 if (sk->sk_state != TCP_ESTABLISHED)
92577 return -EDESTADDRREQ;
92578+
92579+ err = gr_search_udp_sendmsg(sk, NULL);
92580+ if (err)
92581+ return err;
92582+
92583 daddr = inet->inet_daddr;
92584 dport = inet->inet_dport;
92585 /* Open fast path for connected socket.
92586@@ -1137,7 +1154,7 @@ static unsigned int first_packet_length(struct sock *sk)
92587 IS_UDPLITE(sk));
92588 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
92589 IS_UDPLITE(sk));
92590- atomic_inc(&sk->sk_drops);
92591+ atomic_inc_unchecked(&sk->sk_drops);
92592 __skb_unlink(skb, rcvq);
92593 __skb_queue_tail(&list_kill, skb);
92594 }
92595@@ -1223,6 +1240,10 @@ try_again:
92596 if (!skb)
92597 goto out;
92598
92599+ err = gr_search_udp_recvmsg(sk, skb);
92600+ if (err)
92601+ goto out_free;
92602+
92603 ulen = skb->len - sizeof(struct udphdr);
92604 copied = len;
92605 if (copied > ulen)
92606@@ -1256,7 +1277,7 @@ try_again:
92607 if (unlikely(err)) {
92608 trace_kfree_skb(skb, udp_recvmsg);
92609 if (!peeked) {
92610- atomic_inc(&sk->sk_drops);
92611+ atomic_inc_unchecked(&sk->sk_drops);
92612 UDP_INC_STATS_USER(sock_net(sk),
92613 UDP_MIB_INERRORS, is_udplite);
92614 }
92615@@ -1543,7 +1564,7 @@ csum_error:
92616 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
92617 drop:
92618 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
92619- atomic_inc(&sk->sk_drops);
92620+ atomic_inc_unchecked(&sk->sk_drops);
92621 kfree_skb(skb);
92622 return -1;
92623 }
92624@@ -1562,7 +1583,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
92625 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
92626
92627 if (!skb1) {
92628- atomic_inc(&sk->sk_drops);
92629+ atomic_inc_unchecked(&sk->sk_drops);
92630 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
92631 IS_UDPLITE(sk));
92632 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
92633@@ -1734,6 +1755,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
92634 goto csum_error;
92635
92636 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
92637+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92638+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
92639+#endif
92640 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
92641
92642 /*
92643@@ -2166,7 +2190,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
92644 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
92645 0, sock_i_ino(sp),
92646 atomic_read(&sp->sk_refcnt), sp,
92647- atomic_read(&sp->sk_drops), len);
92648+ atomic_read_unchecked(&sp->sk_drops), len);
92649 }
92650
92651 int udp4_seq_show(struct seq_file *seq, void *v)
92652diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
92653index 9a459be..c7bc04c 100644
92654--- a/net/ipv4/xfrm4_policy.c
92655+++ b/net/ipv4/xfrm4_policy.c
92656@@ -181,11 +181,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
92657 fl4->flowi4_tos = iph->tos;
92658 }
92659
92660-static inline int xfrm4_garbage_collect(struct dst_ops *ops)
92661+static int xfrm4_garbage_collect(struct dst_ops *ops)
92662 {
92663 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
92664
92665- xfrm4_policy_afinfo.garbage_collect(net);
92666+ xfrm_garbage_collect_deferred(net);
92667 return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
92668 }
92669
92670@@ -264,19 +264,18 @@ static struct ctl_table xfrm4_policy_table[] = {
92671
92672 static int __net_init xfrm4_net_init(struct net *net)
92673 {
92674- struct ctl_table *table;
92675+ ctl_table_no_const *table = NULL;
92676 struct ctl_table_header *hdr;
92677
92678- table = xfrm4_policy_table;
92679 if (!net_eq(net, &init_net)) {
92680- table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
92681+ table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
92682 if (!table)
92683 goto err_alloc;
92684
92685 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
92686- }
92687-
92688- hdr = register_net_sysctl(net, "net/ipv4", table);
92689+ hdr = register_net_sysctl(net, "net/ipv4", table);
92690+ } else
92691+ hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
92692 if (!hdr)
92693 goto err_reg;
92694
92695@@ -284,8 +283,7 @@ static int __net_init xfrm4_net_init(struct net *net)
92696 return 0;
92697
92698 err_reg:
92699- if (!net_eq(net, &init_net))
92700- kfree(table);
92701+ kfree(table);
92702 err_alloc:
92703 return -ENOMEM;
92704 }
92705diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
92706index 498ea99..42501bc 100644
92707--- a/net/ipv6/addrconf.c
92708+++ b/net/ipv6/addrconf.c
92709@@ -618,7 +618,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
92710 idx = 0;
92711 head = &net->dev_index_head[h];
92712 rcu_read_lock();
92713- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
92714+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
92715 net->dev_base_seq;
92716 hlist_for_each_entry_rcu(dev, head, index_hlist) {
92717 if (idx < s_idx)
92718@@ -2381,7 +2381,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
92719 p.iph.ihl = 5;
92720 p.iph.protocol = IPPROTO_IPV6;
92721 p.iph.ttl = 64;
92722- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
92723+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
92724
92725 if (ops->ndo_do_ioctl) {
92726 mm_segment_t oldfs = get_fs();
92727@@ -4030,7 +4030,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
92728 s_ip_idx = ip_idx = cb->args[2];
92729
92730 rcu_read_lock();
92731- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
92732+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
92733 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
92734 idx = 0;
92735 head = &net->dev_index_head[h];
92736@@ -4651,7 +4651,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
92737 dst_free(&ifp->rt->dst);
92738 break;
92739 }
92740- atomic_inc(&net->ipv6.dev_addr_genid);
92741+ atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
92742 }
92743
92744 static void ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
92745@@ -4671,7 +4671,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
92746 int *valp = ctl->data;
92747 int val = *valp;
92748 loff_t pos = *ppos;
92749- struct ctl_table lctl;
92750+ ctl_table_no_const lctl;
92751 int ret;
92752
92753 /*
92754@@ -4756,7 +4756,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
92755 int *valp = ctl->data;
92756 int val = *valp;
92757 loff_t pos = *ppos;
92758- struct ctl_table lctl;
92759+ ctl_table_no_const lctl;
92760 int ret;
92761
92762 /*
92763diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
92764index 197e6f4..16d8396 100644
92765--- a/net/ipv6/datagram.c
92766+++ b/net/ipv6/datagram.c
92767@@ -904,5 +904,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
92768 0,
92769 sock_i_ino(sp),
92770 atomic_read(&sp->sk_refcnt), sp,
92771- atomic_read(&sp->sk_drops));
92772+ atomic_read_unchecked(&sp->sk_drops));
92773 }
92774diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
92775index 7cfc8d2..c5394b6 100644
92776--- a/net/ipv6/icmp.c
92777+++ b/net/ipv6/icmp.c
92778@@ -989,7 +989,7 @@ struct ctl_table ipv6_icmp_table_template[] = {
92779
92780 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
92781 {
92782- struct ctl_table *table;
92783+ ctl_table_no_const *table;
92784
92785 table = kmemdup(ipv6_icmp_table_template,
92786 sizeof(ipv6_icmp_table_template),
92787diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
92788index 90747f1..76fbb5d 100644
92789--- a/net/ipv6/ip6_gre.c
92790+++ b/net/ipv6/ip6_gre.c
92791@@ -74,7 +74,7 @@ struct ip6gre_net {
92792 struct net_device *fb_tunnel_dev;
92793 };
92794
92795-static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
92796+static struct rtnl_link_ops ip6gre_link_ops;
92797 static int ip6gre_tunnel_init(struct net_device *dev);
92798 static void ip6gre_tunnel_setup(struct net_device *dev);
92799 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
92800@@ -620,7 +620,7 @@ static netdev_tx_t ip6gre_xmit2(struct sk_buff *skb,
92801 struct ip6_tnl *tunnel = netdev_priv(dev);
92802 struct net_device *tdev; /* Device to other host */
92803 struct ipv6hdr *ipv6h; /* Our new IP header */
92804- unsigned int max_headroom; /* The extra header space needed */
92805+ unsigned int max_headroom = 0; /* The extra header space needed */
92806 int gre_hlen;
92807 struct ipv6_tel_txoption opt;
92808 int mtu;
92809@@ -693,7 +693,7 @@ static netdev_tx_t ip6gre_xmit2(struct sk_buff *skb,
92810 tunnel->err_count = 0;
92811 }
92812
92813- max_headroom = LL_RESERVED_SPACE(tdev) + gre_hlen + dst->header_len;
92814+ max_headroom += LL_RESERVED_SPACE(tdev) + gre_hlen + dst->header_len;
92815
92816 if (skb_headroom(skb) < max_headroom || skb_shared(skb) ||
92817 (skb_cloned(skb) && !skb_clone_writable(skb, 0))) {
92818@@ -1288,7 +1288,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
92819 }
92820
92821
92822-static struct inet6_protocol ip6gre_protocol __read_mostly = {
92823+static struct inet6_protocol ip6gre_protocol = {
92824 .handler = ip6gre_rcv,
92825 .err_handler = ip6gre_err,
92826 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
92827@@ -1622,7 +1622,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
92828 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
92829 };
92830
92831-static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
92832+static struct rtnl_link_ops ip6gre_link_ops = {
92833 .kind = "ip6gre",
92834 .maxtype = IFLA_GRE_MAX,
92835 .policy = ip6gre_policy,
92836@@ -1635,7 +1635,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
92837 .fill_info = ip6gre_fill_info,
92838 };
92839
92840-static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
92841+static struct rtnl_link_ops ip6gre_tap_ops = {
92842 .kind = "ip6gretap",
92843 .maxtype = IFLA_GRE_MAX,
92844 .policy = ip6gre_policy,
92845diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c
92846index e7ceb6c..44df1c9 100644
92847--- a/net/ipv6/ip6_output.c
92848+++ b/net/ipv6/ip6_output.c
92849@@ -1040,6 +1040,8 @@ static inline int ip6_ufo_append_data(struct sock *sk,
92850 * udp datagram
92851 */
92852 if ((skb = skb_peek_tail(&sk->sk_write_queue)) == NULL) {
92853+ struct frag_hdr fhdr;
92854+
92855 skb = sock_alloc_send_skb(sk,
92856 hh_len + fragheaderlen + transhdrlen + 20,
92857 (flags & MSG_DONTWAIT), &err);
92858@@ -1061,12 +1063,6 @@ static inline int ip6_ufo_append_data(struct sock *sk,
92859 skb->protocol = htons(ETH_P_IPV6);
92860 skb->ip_summed = CHECKSUM_PARTIAL;
92861 skb->csum = 0;
92862- }
92863-
92864- err = skb_append_datato_frags(sk,skb, getfrag, from,
92865- (length - transhdrlen));
92866- if (!err) {
92867- struct frag_hdr fhdr;
92868
92869 /* Specify the length of each IPv6 datagram fragment.
92870 * It has to be a multiple of 8.
92871@@ -1077,15 +1073,10 @@ static inline int ip6_ufo_append_data(struct sock *sk,
92872 ipv6_select_ident(&fhdr, rt);
92873 skb_shinfo(skb)->ip6_frag_id = fhdr.identification;
92874 __skb_queue_tail(&sk->sk_write_queue, skb);
92875-
92876- return 0;
92877 }
92878- /* There is not enough support do UPD LSO,
92879- * so follow normal path
92880- */
92881- kfree_skb(skb);
92882
92883- return err;
92884+ return skb_append_datato_frags(sk, skb, getfrag, from,
92885+ (length - transhdrlen));
92886 }
92887
92888 static inline struct ipv6_opt_hdr *ip6_opt_dup(struct ipv6_opt_hdr *src,
92889@@ -1252,27 +1243,27 @@ int ip6_append_data(struct sock *sk, int getfrag(void *from, char *to,
92890 * --yoshfuji
92891 */
92892
92893+ if ((length > mtu) && dontfrag && (sk->sk_protocol == IPPROTO_UDP ||
92894+ sk->sk_protocol == IPPROTO_RAW)) {
92895+ ipv6_local_rxpmtu(sk, fl6, mtu-exthdrlen);
92896+ return -EMSGSIZE;
92897+ }
92898+
92899+ skb = skb_peek_tail(&sk->sk_write_queue);
92900 cork->length += length;
92901- if (length > mtu) {
92902- int proto = sk->sk_protocol;
92903- if (dontfrag && (proto == IPPROTO_UDP || proto == IPPROTO_RAW)){
92904- ipv6_local_rxpmtu(sk, fl6, mtu-exthdrlen);
92905- return -EMSGSIZE;
92906- }
92907-
92908- if (proto == IPPROTO_UDP &&
92909- (rt->dst.dev->features & NETIF_F_UFO)) {
92910-
92911- err = ip6_ufo_append_data(sk, getfrag, from, length,
92912- hh_len, fragheaderlen,
92913- transhdrlen, mtu, flags, rt);
92914- if (err)
92915- goto error;
92916- return 0;
92917- }
92918+ if (((length > mtu) ||
92919+ (skb && skb_is_gso(skb))) &&
92920+ (sk->sk_protocol == IPPROTO_UDP) &&
92921+ (rt->dst.dev->features & NETIF_F_UFO)) {
92922+ err = ip6_ufo_append_data(sk, getfrag, from, length,
92923+ hh_len, fragheaderlen,
92924+ transhdrlen, mtu, flags, rt);
92925+ if (err)
92926+ goto error;
92927+ return 0;
92928 }
92929
92930- if ((skb = skb_peek_tail(&sk->sk_write_queue)) == NULL)
92931+ if (!skb)
92932 goto alloc_new_skb;
92933
92934 while (length > 0) {
92935diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
92936index 46ba243..576f50e 100644
92937--- a/net/ipv6/ip6_tunnel.c
92938+++ b/net/ipv6/ip6_tunnel.c
92939@@ -88,7 +88,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
92940
92941 static int ip6_tnl_dev_init(struct net_device *dev);
92942 static void ip6_tnl_dev_setup(struct net_device *dev);
92943-static struct rtnl_link_ops ip6_link_ops __read_mostly;
92944+static struct rtnl_link_ops ip6_link_ops;
92945
92946 static int ip6_tnl_net_id __read_mostly;
92947 struct ip6_tnl_net {
92948@@ -1678,7 +1678,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
92949 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
92950 };
92951
92952-static struct rtnl_link_ops ip6_link_ops __read_mostly = {
92953+static struct rtnl_link_ops ip6_link_ops = {
92954 .kind = "ip6tnl",
92955 .maxtype = IFLA_IPTUN_MAX,
92956 .policy = ip6_tnl_policy,
92957diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
92958index d1e2e8e..51c19ae 100644
92959--- a/net/ipv6/ipv6_sockglue.c
92960+++ b/net/ipv6/ipv6_sockglue.c
92961@@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
92962 if (sk->sk_type != SOCK_STREAM)
92963 return -ENOPROTOOPT;
92964
92965- msg.msg_control = optval;
92966+ msg.msg_control = (void __force_kernel *)optval;
92967 msg.msg_controllen = len;
92968 msg.msg_flags = flags;
92969
92970diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
92971index 44400c2..8e11f52 100644
92972--- a/net/ipv6/netfilter/ip6_tables.c
92973+++ b/net/ipv6/netfilter/ip6_tables.c
92974@@ -1078,14 +1078,14 @@ static int compat_table_info(const struct xt_table_info *info,
92975 #endif
92976
92977 static int get_info(struct net *net, void __user *user,
92978- const int *len, int compat)
92979+ int len, int compat)
92980 {
92981 char name[XT_TABLE_MAXNAMELEN];
92982 struct xt_table *t;
92983 int ret;
92984
92985- if (*len != sizeof(struct ip6t_getinfo)) {
92986- duprintf("length %u != %zu\n", *len,
92987+ if (len != sizeof(struct ip6t_getinfo)) {
92988+ duprintf("length %u != %zu\n", len,
92989 sizeof(struct ip6t_getinfo));
92990 return -EINVAL;
92991 }
92992@@ -1122,7 +1122,7 @@ static int get_info(struct net *net, void __user *user,
92993 info.size = private->size;
92994 strcpy(info.name, name);
92995
92996- if (copy_to_user(user, &info, *len) != 0)
92997+ if (copy_to_user(user, &info, len) != 0)
92998 ret = -EFAULT;
92999 else
93000 ret = 0;
93001@@ -1976,7 +1976,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
93002
93003 switch (cmd) {
93004 case IP6T_SO_GET_INFO:
93005- ret = get_info(sock_net(sk), user, len, 1);
93006+ ret = get_info(sock_net(sk), user, *len, 1);
93007 break;
93008 case IP6T_SO_GET_ENTRIES:
93009 ret = compat_get_entries(sock_net(sk), user, len);
93010@@ -2023,7 +2023,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
93011
93012 switch (cmd) {
93013 case IP6T_SO_GET_INFO:
93014- ret = get_info(sock_net(sk), user, len, 0);
93015+ ret = get_info(sock_net(sk), user, *len, 0);
93016 break;
93017
93018 case IP6T_SO_GET_ENTRIES:
93019diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
93020index dffdc1a..ccc6678 100644
93021--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
93022+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
93023@@ -90,12 +90,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
93024
93025 static int nf_ct_frag6_sysctl_register(struct net *net)
93026 {
93027- struct ctl_table *table;
93028+ ctl_table_no_const *table = NULL;
93029 struct ctl_table_header *hdr;
93030
93031- table = nf_ct_frag6_sysctl_table;
93032 if (!net_eq(net, &init_net)) {
93033- table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
93034+ table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
93035 GFP_KERNEL);
93036 if (table == NULL)
93037 goto err_alloc;
93038@@ -103,9 +102,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
93039 table[0].data = &net->nf_frag.frags.timeout;
93040 table[1].data = &net->nf_frag.frags.low_thresh;
93041 table[2].data = &net->nf_frag.frags.high_thresh;
93042- }
93043-
93044- hdr = register_net_sysctl(net, "net/netfilter", table);
93045+ hdr = register_net_sysctl(net, "net/netfilter", table);
93046+ } else
93047+ hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
93048 if (hdr == NULL)
93049 goto err_reg;
93050
93051@@ -113,8 +112,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
93052 return 0;
93053
93054 err_reg:
93055- if (!net_eq(net, &init_net))
93056- kfree(table);
93057+ kfree(table);
93058 err_alloc:
93059 return -ENOMEM;
93060 }
93061diff --git a/net/ipv6/output_core.c b/net/ipv6/output_core.c
93062index ab92a36..bb4a528 100644
93063--- a/net/ipv6/output_core.c
93064+++ b/net/ipv6/output_core.c
93065@@ -8,8 +8,8 @@
93066
93067 void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
93068 {
93069- static atomic_t ipv6_fragmentation_id;
93070- int old, new;
93071+ static atomic_unchecked_t ipv6_fragmentation_id;
93072+ int id;
93073
93074 #if IS_ENABLED(CONFIG_IPV6)
93075 if (rt && !(rt->dst.flags & DST_NOPEER)) {
93076@@ -25,13 +25,10 @@ void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
93077 }
93078 }
93079 #endif
93080- do {
93081- old = atomic_read(&ipv6_fragmentation_id);
93082- new = old + 1;
93083- if (!new)
93084- new = 1;
93085- } while (atomic_cmpxchg(&ipv6_fragmentation_id, old, new) != old);
93086- fhdr->identification = htonl(new);
93087+ id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
93088+ if (!id)
93089+ id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
93090+ fhdr->identification = htonl(id);
93091 }
93092 EXPORT_SYMBOL(ipv6_select_ident);
93093
93094diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
93095index 18f19df..b46ada1 100644
93096--- a/net/ipv6/ping.c
93097+++ b/net/ipv6/ping.c
93098@@ -245,6 +245,22 @@ static struct pernet_operations ping_v6_net_ops = {
93099 };
93100 #endif
93101
93102+static struct pingv6_ops real_pingv6_ops = {
93103+ .ipv6_recv_error = ipv6_recv_error,
93104+ .ip6_datagram_recv_ctl = ip6_datagram_recv_ctl,
93105+ .icmpv6_err_convert = icmpv6_err_convert,
93106+ .ipv6_icmp_error = ipv6_icmp_error,
93107+ .ipv6_chk_addr = ipv6_chk_addr,
93108+};
93109+
93110+static struct pingv6_ops dummy_pingv6_ops = {
93111+ .ipv6_recv_error = dummy_ipv6_recv_error,
93112+ .ip6_datagram_recv_ctl = dummy_ip6_datagram_recv_ctl,
93113+ .icmpv6_err_convert = dummy_icmpv6_err_convert,
93114+ .ipv6_icmp_error = dummy_ipv6_icmp_error,
93115+ .ipv6_chk_addr = dummy_ipv6_chk_addr,
93116+};
93117+
93118 int __init pingv6_init(void)
93119 {
93120 #ifdef CONFIG_PROC_FS
93121@@ -252,11 +268,7 @@ int __init pingv6_init(void)
93122 if (ret)
93123 return ret;
93124 #endif
93125- pingv6_ops.ipv6_recv_error = ipv6_recv_error;
93126- pingv6_ops.ip6_datagram_recv_ctl = ip6_datagram_recv_ctl;
93127- pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
93128- pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
93129- pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
93130+ pingv6_ops = &real_pingv6_ops;
93131 return inet6_register_protosw(&pingv6_protosw);
93132 }
93133
93134@@ -265,11 +277,7 @@ int __init pingv6_init(void)
93135 */
93136 void pingv6_exit(void)
93137 {
93138- pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
93139- pingv6_ops.ip6_datagram_recv_ctl = dummy_ip6_datagram_recv_ctl;
93140- pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
93141- pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
93142- pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
93143+ pingv6_ops = &dummy_pingv6_ops;
93144 #ifdef CONFIG_PROC_FS
93145 unregister_pernet_subsys(&ping_v6_net_ops);
93146 #endif
93147diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
93148index cdaed47..515edde9 100644
93149--- a/net/ipv6/raw.c
93150+++ b/net/ipv6/raw.c
93151@@ -108,7 +108,7 @@ found:
93152 */
93153 static int icmpv6_filter(const struct sock *sk, const struct sk_buff *skb)
93154 {
93155- struct icmp6hdr *_hdr;
93156+ struct icmp6hdr _hdr;
93157 const struct icmp6hdr *hdr;
93158
93159 hdr = skb_header_pointer(skb, skb_transport_offset(skb),
93160@@ -378,7 +378,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
93161 {
93162 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
93163 skb_checksum_complete(skb)) {
93164- atomic_inc(&sk->sk_drops);
93165+ atomic_inc_unchecked(&sk->sk_drops);
93166 kfree_skb(skb);
93167 return NET_RX_DROP;
93168 }
93169@@ -406,7 +406,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
93170 struct raw6_sock *rp = raw6_sk(sk);
93171
93172 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
93173- atomic_inc(&sk->sk_drops);
93174+ atomic_inc_unchecked(&sk->sk_drops);
93175 kfree_skb(skb);
93176 return NET_RX_DROP;
93177 }
93178@@ -430,7 +430,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
93179
93180 if (inet->hdrincl) {
93181 if (skb_checksum_complete(skb)) {
93182- atomic_inc(&sk->sk_drops);
93183+ atomic_inc_unchecked(&sk->sk_drops);
93184 kfree_skb(skb);
93185 return NET_RX_DROP;
93186 }
93187@@ -602,7 +602,7 @@ out:
93188 return err;
93189 }
93190
93191-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
93192+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
93193 struct flowi6 *fl6, struct dst_entry **dstp,
93194 unsigned int flags)
93195 {
93196@@ -915,12 +915,15 @@ do_confirm:
93197 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
93198 char __user *optval, int optlen)
93199 {
93200+ struct icmp6_filter filter;
93201+
93202 switch (optname) {
93203 case ICMPV6_FILTER:
93204 if (optlen > sizeof(struct icmp6_filter))
93205 optlen = sizeof(struct icmp6_filter);
93206- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
93207+ if (copy_from_user(&filter, optval, optlen))
93208 return -EFAULT;
93209+ raw6_sk(sk)->filter = filter;
93210 return 0;
93211 default:
93212 return -ENOPROTOOPT;
93213@@ -933,6 +936,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
93214 char __user *optval, int __user *optlen)
93215 {
93216 int len;
93217+ struct icmp6_filter filter;
93218
93219 switch (optname) {
93220 case ICMPV6_FILTER:
93221@@ -944,7 +948,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
93222 len = sizeof(struct icmp6_filter);
93223 if (put_user(len, optlen))
93224 return -EFAULT;
93225- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
93226+ filter = raw6_sk(sk)->filter;
93227+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
93228 return -EFAULT;
93229 return 0;
93230 default:
93231diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
93232index 1aeb473..bea761c 100644
93233--- a/net/ipv6/reassembly.c
93234+++ b/net/ipv6/reassembly.c
93235@@ -626,12 +626,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
93236
93237 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
93238 {
93239- struct ctl_table *table;
93240+ ctl_table_no_const *table = NULL;
93241 struct ctl_table_header *hdr;
93242
93243- table = ip6_frags_ns_ctl_table;
93244 if (!net_eq(net, &init_net)) {
93245- table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
93246+ table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
93247 if (table == NULL)
93248 goto err_alloc;
93249
93250@@ -642,9 +641,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
93251 /* Don't export sysctls to unprivileged users */
93252 if (net->user_ns != &init_user_ns)
93253 table[0].procname = NULL;
93254- }
93255+ hdr = register_net_sysctl(net, "net/ipv6", table);
93256+ } else
93257+ hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
93258
93259- hdr = register_net_sysctl(net, "net/ipv6", table);
93260 if (hdr == NULL)
93261 goto err_reg;
93262
93263@@ -652,8 +652,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
93264 return 0;
93265
93266 err_reg:
93267- if (!net_eq(net, &init_net))
93268- kfree(table);
93269+ kfree(table);
93270 err_alloc:
93271 return -ENOMEM;
93272 }
93273diff --git a/net/ipv6/route.c b/net/ipv6/route.c
93274index 8d9a93ed..cd89616 100644
93275--- a/net/ipv6/route.c
93276+++ b/net/ipv6/route.c
93277@@ -2926,7 +2926,7 @@ struct ctl_table ipv6_route_table_template[] = {
93278
93279 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
93280 {
93281- struct ctl_table *table;
93282+ ctl_table_no_const *table;
93283
93284 table = kmemdup(ipv6_route_table_template,
93285 sizeof(ipv6_route_table_template),
93286diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
93287index 21b25dd..9a43e37 100644
93288--- a/net/ipv6/sit.c
93289+++ b/net/ipv6/sit.c
93290@@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
93291 static void ipip6_dev_free(struct net_device *dev);
93292 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
93293 __be32 *v4dst);
93294-static struct rtnl_link_ops sit_link_ops __read_mostly;
93295+static struct rtnl_link_ops sit_link_ops;
93296
93297 static int sit_net_id __read_mostly;
93298 struct sit_net {
93299@@ -1547,7 +1547,7 @@ static const struct nla_policy ipip6_policy[IFLA_IPTUN_MAX + 1] = {
93300 #endif
93301 };
93302
93303-static struct rtnl_link_ops sit_link_ops __read_mostly = {
93304+static struct rtnl_link_ops sit_link_ops = {
93305 .kind = "sit",
93306 .maxtype = IFLA_IPTUN_MAX,
93307 .policy = ipip6_policy,
93308diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
93309index 107b2f1..72741a9 100644
93310--- a/net/ipv6/sysctl_net_ipv6.c
93311+++ b/net/ipv6/sysctl_net_ipv6.c
93312@@ -40,7 +40,7 @@ static struct ctl_table ipv6_rotable[] = {
93313
93314 static int __net_init ipv6_sysctl_net_init(struct net *net)
93315 {
93316- struct ctl_table *ipv6_table;
93317+ ctl_table_no_const *ipv6_table;
93318 struct ctl_table *ipv6_route_table;
93319 struct ctl_table *ipv6_icmp_table;
93320 int err;
93321diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
93322index 6e1649d..75ddb4c 100644
93323--- a/net/ipv6/tcp_ipv6.c
93324+++ b/net/ipv6/tcp_ipv6.c
93325@@ -104,6 +104,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
93326 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
93327 }
93328
93329+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93330+extern int grsec_enable_blackhole;
93331+#endif
93332+
93333 static void tcp_v6_hash(struct sock *sk)
93334 {
93335 if (sk->sk_state != TCP_CLOSE) {
93336@@ -1399,6 +1403,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
93337 return 0;
93338
93339 reset:
93340+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93341+ if (!grsec_enable_blackhole)
93342+#endif
93343 tcp_v6_send_reset(sk, skb);
93344 discard:
93345 if (opt_skb)
93346@@ -1427,7 +1434,7 @@ ipv6_pktoptions:
93347 if (np->rxopt.bits.rxhlim || np->rxopt.bits.rxohlim)
93348 np->mcast_hops = ipv6_hdr(opt_skb)->hop_limit;
93349 if (np->rxopt.bits.rxtclass)
93350- np->rcv_tclass = ipv6_get_dsfield(ipv6_hdr(skb));
93351+ np->rcv_tclass = ipv6_get_dsfield(ipv6_hdr(opt_skb));
93352 if (ipv6_opt_accepted(sk, opt_skb)) {
93353 skb_set_owner_r(opt_skb, sk);
93354 opt_skb = xchg(&np->pktoptions, opt_skb);
93355@@ -1481,12 +1488,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
93356 TCP_SKB_CB(skb)->sacked = 0;
93357
93358 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
93359- if (!sk)
93360+ if (!sk) {
93361+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93362+ ret = 1;
93363+#endif
93364 goto no_tcp_socket;
93365+ }
93366
93367 process:
93368- if (sk->sk_state == TCP_TIME_WAIT)
93369+ if (sk->sk_state == TCP_TIME_WAIT) {
93370+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93371+ ret = 2;
93372+#endif
93373 goto do_time_wait;
93374+ }
93375
93376 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
93377 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
93378@@ -1538,6 +1553,10 @@ csum_error:
93379 bad_packet:
93380 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
93381 } else {
93382+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93383+ if (!grsec_enable_blackhole || (ret == 1 &&
93384+ (skb->dev->flags & IFF_LOOPBACK)))
93385+#endif
93386 tcp_v6_send_reset(NULL, skb);
93387 }
93388
93389diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
93390index f405815..45a68a6 100644
93391--- a/net/ipv6/udp.c
93392+++ b/net/ipv6/udp.c
93393@@ -53,6 +53,10 @@
93394 #include <trace/events/skb.h>
93395 #include "udp_impl.h"
93396
93397+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93398+extern int grsec_enable_blackhole;
93399+#endif
93400+
93401 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
93402 {
93403 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
93404@@ -420,7 +424,7 @@ try_again:
93405 if (unlikely(err)) {
93406 trace_kfree_skb(skb, udpv6_recvmsg);
93407 if (!peeked) {
93408- atomic_inc(&sk->sk_drops);
93409+ atomic_inc_unchecked(&sk->sk_drops);
93410 if (is_udp4)
93411 UDP_INC_STATS_USER(sock_net(sk),
93412 UDP_MIB_INERRORS,
93413@@ -666,7 +670,7 @@ csum_error:
93414 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
93415 drop:
93416 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
93417- atomic_inc(&sk->sk_drops);
93418+ atomic_inc_unchecked(&sk->sk_drops);
93419 kfree_skb(skb);
93420 return -1;
93421 }
93422@@ -724,7 +728,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
93423 if (likely(skb1 == NULL))
93424 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
93425 if (!skb1) {
93426- atomic_inc(&sk->sk_drops);
93427+ atomic_inc_unchecked(&sk->sk_drops);
93428 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
93429 IS_UDPLITE(sk));
93430 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
93431@@ -864,6 +868,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
93432 goto csum_error;
93433
93434 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
93435+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93436+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
93437+#endif
93438 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
93439
93440 kfree_skb(skb);
93441diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
93442index 23ed03d..6532e67 100644
93443--- a/net/ipv6/xfrm6_policy.c
93444+++ b/net/ipv6/xfrm6_policy.c
93445@@ -207,11 +207,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
93446 }
93447 }
93448
93449-static inline int xfrm6_garbage_collect(struct dst_ops *ops)
93450+static int xfrm6_garbage_collect(struct dst_ops *ops)
93451 {
93452 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
93453
93454- xfrm6_policy_afinfo.garbage_collect(net);
93455+ xfrm_garbage_collect_deferred(net);
93456 return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
93457 }
93458
93459@@ -324,19 +324,19 @@ static struct ctl_table xfrm6_policy_table[] = {
93460
93461 static int __net_init xfrm6_net_init(struct net *net)
93462 {
93463- struct ctl_table *table;
93464+ ctl_table_no_const *table = NULL;
93465 struct ctl_table_header *hdr;
93466
93467- table = xfrm6_policy_table;
93468 if (!net_eq(net, &init_net)) {
93469- table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
93470+ table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
93471 if (!table)
93472 goto err_alloc;
93473
93474 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
93475- }
93476+ hdr = register_net_sysctl(net, "net/ipv6", table);
93477+ } else
93478+ hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
93479
93480- hdr = register_net_sysctl(net, "net/ipv6", table);
93481 if (!hdr)
93482 goto err_reg;
93483
93484@@ -344,8 +344,7 @@ static int __net_init xfrm6_net_init(struct net *net)
93485 return 0;
93486
93487 err_reg:
93488- if (!net_eq(net, &init_net))
93489- kfree(table);
93490+ kfree(table);
93491 err_alloc:
93492 return -ENOMEM;
93493 }
93494diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
93495index 41ac7938..75e3bb1 100644
93496--- a/net/irda/ircomm/ircomm_tty.c
93497+++ b/net/irda/ircomm/ircomm_tty.c
93498@@ -319,11 +319,11 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
93499 add_wait_queue(&port->open_wait, &wait);
93500
93501 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
93502- __FILE__, __LINE__, tty->driver->name, port->count);
93503+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
93504
93505 spin_lock_irqsave(&port->lock, flags);
93506 if (!tty_hung_up_p(filp))
93507- port->count--;
93508+ atomic_dec(&port->count);
93509 port->blocked_open++;
93510 spin_unlock_irqrestore(&port->lock, flags);
93511
93512@@ -358,7 +358,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
93513 }
93514
93515 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
93516- __FILE__, __LINE__, tty->driver->name, port->count);
93517+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
93518
93519 schedule();
93520 }
93521@@ -368,12 +368,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
93522
93523 spin_lock_irqsave(&port->lock, flags);
93524 if (!tty_hung_up_p(filp))
93525- port->count++;
93526+ atomic_inc(&port->count);
93527 port->blocked_open--;
93528 spin_unlock_irqrestore(&port->lock, flags);
93529
93530 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
93531- __FILE__, __LINE__, tty->driver->name, port->count);
93532+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
93533
93534 if (!retval)
93535 port->flags |= ASYNC_NORMAL_ACTIVE;
93536@@ -447,12 +447,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
93537
93538 /* ++ is not atomic, so this should be protected - Jean II */
93539 spin_lock_irqsave(&self->port.lock, flags);
93540- self->port.count++;
93541+ atomic_inc(&self->port.count);
93542 spin_unlock_irqrestore(&self->port.lock, flags);
93543 tty_port_tty_set(&self->port, tty);
93544
93545 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
93546- self->line, self->port.count);
93547+ self->line, atomic_read(&self->port.count));
93548
93549 /* Not really used by us, but lets do it anyway */
93550 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
93551@@ -989,7 +989,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
93552 tty_kref_put(port->tty);
93553 }
93554 port->tty = NULL;
93555- port->count = 0;
93556+ atomic_set(&port->count, 0);
93557 spin_unlock_irqrestore(&port->lock, flags);
93558
93559 wake_up_interruptible(&port->open_wait);
93560@@ -1346,7 +1346,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
93561 seq_putc(m, '\n');
93562
93563 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
93564- seq_printf(m, "Open count: %d\n", self->port.count);
93565+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
93566 seq_printf(m, "Max data size: %d\n", self->max_data_size);
93567 seq_printf(m, "Max header size: %d\n", self->max_header_size);
93568
93569diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
93570index 168aff5..9d43132 100644
93571--- a/net/iucv/af_iucv.c
93572+++ b/net/iucv/af_iucv.c
93573@@ -773,10 +773,10 @@ static int iucv_sock_autobind(struct sock *sk)
93574
93575 write_lock_bh(&iucv_sk_list.lock);
93576
93577- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
93578+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
93579 while (__iucv_get_sock_by_name(name)) {
93580 sprintf(name, "%08x",
93581- atomic_inc_return(&iucv_sk_list.autobind_name));
93582+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
93583 }
93584
93585 write_unlock_bh(&iucv_sk_list.lock);
93586diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
93587index cd5b8ec..f205e6b 100644
93588--- a/net/iucv/iucv.c
93589+++ b/net/iucv/iucv.c
93590@@ -690,7 +690,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
93591 return NOTIFY_OK;
93592 }
93593
93594-static struct notifier_block __refdata iucv_cpu_notifier = {
93595+static struct notifier_block iucv_cpu_notifier = {
93596 .notifier_call = iucv_cpu_notify,
93597 };
93598
93599diff --git a/net/key/af_key.c b/net/key/af_key.c
93600index ab8bd2c..cd2d641 100644
93601--- a/net/key/af_key.c
93602+++ b/net/key/af_key.c
93603@@ -3048,10 +3048,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
93604 static u32 get_acqseq(void)
93605 {
93606 u32 res;
93607- static atomic_t acqseq;
93608+ static atomic_unchecked_t acqseq;
93609
93610 do {
93611- res = atomic_inc_return(&acqseq);
93612+ res = atomic_inc_return_unchecked(&acqseq);
93613 } while (!res);
93614 return res;
93615 }
93616diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
93617index 43dd752..63a23bc 100644
93618--- a/net/mac80211/cfg.c
93619+++ b/net/mac80211/cfg.c
93620@@ -820,7 +820,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
93621 ret = ieee80211_vif_use_channel(sdata, chandef,
93622 IEEE80211_CHANCTX_EXCLUSIVE);
93623 }
93624- } else if (local->open_count == local->monitors) {
93625+ } else if (local_read(&local->open_count) == local->monitors) {
93626 local->_oper_chandef = *chandef;
93627 ieee80211_hw_config(local, 0);
93628 }
93629@@ -2941,7 +2941,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
93630 else
93631 local->probe_req_reg--;
93632
93633- if (!local->open_count)
93634+ if (!local_read(&local->open_count))
93635 break;
93636
93637 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
93638@@ -3404,8 +3404,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
93639 if (chanctx_conf) {
93640 *chandef = chanctx_conf->def;
93641 ret = 0;
93642- } else if (local->open_count > 0 &&
93643- local->open_count == local->monitors &&
93644+ } else if (local_read(&local->open_count) > 0 &&
93645+ local_read(&local->open_count) == local->monitors &&
93646 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
93647 if (local->use_chanctx)
93648 *chandef = local->monitor_chandef;
93649diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
93650index 8412a30..6e00181 100644
93651--- a/net/mac80211/ieee80211_i.h
93652+++ b/net/mac80211/ieee80211_i.h
93653@@ -28,6 +28,7 @@
93654 #include <net/ieee80211_radiotap.h>
93655 #include <net/cfg80211.h>
93656 #include <net/mac80211.h>
93657+#include <asm/local.h>
93658 #include "key.h"
93659 #include "sta_info.h"
93660 #include "debug.h"
93661@@ -907,7 +908,7 @@ struct ieee80211_local {
93662 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
93663 spinlock_t queue_stop_reason_lock;
93664
93665- int open_count;
93666+ local_t open_count;
93667 int monitors, cooked_mntrs;
93668 /* number of interfaces with corresponding FIF_ flags */
93669 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
93670diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
93671index cc11759..11d5541 100644
93672--- a/net/mac80211/iface.c
93673+++ b/net/mac80211/iface.c
93674@@ -511,7 +511,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
93675 break;
93676 }
93677
93678- if (local->open_count == 0) {
93679+ if (local_read(&local->open_count) == 0) {
93680 res = drv_start(local);
93681 if (res)
93682 goto err_del_bss;
93683@@ -558,7 +558,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
93684 res = drv_add_interface(local, sdata);
93685 if (res)
93686 goto err_stop;
93687- } else if (local->monitors == 0 && local->open_count == 0) {
93688+ } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
93689 res = ieee80211_add_virtual_monitor(local);
93690 if (res)
93691 goto err_stop;
93692@@ -666,7 +666,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
93693 atomic_inc(&local->iff_promiscs);
93694
93695 if (coming_up)
93696- local->open_count++;
93697+ local_inc(&local->open_count);
93698
93699 if (hw_reconf_flags)
93700 ieee80211_hw_config(local, hw_reconf_flags);
93701@@ -704,7 +704,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
93702 err_del_interface:
93703 drv_remove_interface(local, sdata);
93704 err_stop:
93705- if (!local->open_count)
93706+ if (!local_read(&local->open_count))
93707 drv_stop(local);
93708 err_del_bss:
93709 sdata->bss = NULL;
93710@@ -841,7 +841,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
93711 }
93712
93713 if (going_down)
93714- local->open_count--;
93715+ local_dec(&local->open_count);
93716
93717 switch (sdata->vif.type) {
93718 case NL80211_IFTYPE_AP_VLAN:
93719@@ -908,7 +908,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
93720 }
93721 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
93722
93723- if (local->open_count == 0)
93724+ if (local_read(&local->open_count) == 0)
93725 ieee80211_clear_tx_pending(local);
93726
93727 /*
93728@@ -948,7 +948,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
93729
93730 ieee80211_recalc_ps(local, -1);
93731
93732- if (local->open_count == 0) {
93733+ if (local_read(&local->open_count) == 0) {
93734 ieee80211_stop_device(local);
93735
93736 /* no reconfiguring after stop! */
93737@@ -959,7 +959,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
93738 ieee80211_configure_filter(local);
93739 ieee80211_hw_config(local, hw_reconf_flags);
93740
93741- if (local->monitors == local->open_count)
93742+ if (local->monitors == local_read(&local->open_count))
93743 ieee80211_add_virtual_monitor(local);
93744 }
93745
93746diff --git a/net/mac80211/main.c b/net/mac80211/main.c
93747index 091088a..daf43c7 100644
93748--- a/net/mac80211/main.c
93749+++ b/net/mac80211/main.c
93750@@ -181,7 +181,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
93751 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
93752 IEEE80211_CONF_CHANGE_POWER);
93753
93754- if (changed && local->open_count) {
93755+ if (changed && local_read(&local->open_count)) {
93756 ret = drv_config(local, changed);
93757 /*
93758 * Goal:
93759diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
93760index 3401262..d5cd68d 100644
93761--- a/net/mac80211/pm.c
93762+++ b/net/mac80211/pm.c
93763@@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
93764 struct ieee80211_sub_if_data *sdata;
93765 struct sta_info *sta;
93766
93767- if (!local->open_count)
93768+ if (!local_read(&local->open_count))
93769 goto suspend;
93770
93771 ieee80211_scan_cancel(local);
93772@@ -59,7 +59,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
93773 cancel_work_sync(&local->dynamic_ps_enable_work);
93774 del_timer_sync(&local->dynamic_ps_timer);
93775
93776- local->wowlan = wowlan && local->open_count;
93777+ local->wowlan = wowlan && local_read(&local->open_count);
93778 if (local->wowlan) {
93779 int err = drv_suspend(local, wowlan);
93780 if (err < 0) {
93781@@ -116,7 +116,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
93782 WARN_ON(!list_empty(&local->chanctx_list));
93783
93784 /* stop hardware - this must stop RX */
93785- if (local->open_count)
93786+ if (local_read(&local->open_count))
93787 ieee80211_stop_device(local);
93788
93789 suspend:
93790diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
93791index 30d58d2..449ac8e 100644
93792--- a/net/mac80211/rate.c
93793+++ b/net/mac80211/rate.c
93794@@ -718,7 +718,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
93795
93796 ASSERT_RTNL();
93797
93798- if (local->open_count)
93799+ if (local_read(&local->open_count))
93800 return -EBUSY;
93801
93802 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
93803diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
93804index c97a065..ff61928 100644
93805--- a/net/mac80211/rc80211_pid_debugfs.c
93806+++ b/net/mac80211/rc80211_pid_debugfs.c
93807@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
93808
93809 spin_unlock_irqrestore(&events->lock, status);
93810
93811- if (copy_to_user(buf, pb, p))
93812+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
93813 return -EFAULT;
93814
93815 return p;
93816diff --git a/net/mac80211/util.c b/net/mac80211/util.c
93817index 2265445..ba14971 100644
93818--- a/net/mac80211/util.c
93819+++ b/net/mac80211/util.c
93820@@ -1452,7 +1452,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
93821 }
93822 #endif
93823 /* everything else happens only if HW was up & running */
93824- if (!local->open_count)
93825+ if (!local_read(&local->open_count))
93826 goto wake_up;
93827
93828 /*
93829@@ -1677,7 +1677,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
93830 local->in_reconfig = false;
93831 barrier();
93832
93833- if (local->monitors == local->open_count && local->monitors > 0)
93834+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
93835 ieee80211_add_virtual_monitor(local);
93836
93837 /*
93838diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
93839index 56d22ca..87c778f 100644
93840--- a/net/netfilter/Kconfig
93841+++ b/net/netfilter/Kconfig
93842@@ -958,6 +958,16 @@ config NETFILTER_XT_MATCH_ESP
93843
93844 To compile it as a module, choose M here. If unsure, say N.
93845
93846+config NETFILTER_XT_MATCH_GRADM
93847+ tristate '"gradm" match support'
93848+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
93849+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
93850+ ---help---
93851+ The gradm match allows to match on grsecurity RBAC being enabled.
93852+ It is useful when iptables rules are applied early on bootup to
93853+ prevent connections to the machine (except from a trusted host)
93854+ while the RBAC system is disabled.
93855+
93856 config NETFILTER_XT_MATCH_HASHLIMIT
93857 tristate '"hashlimit" match support'
93858 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
93859diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
93860index a1abf87..dbcb7ee 100644
93861--- a/net/netfilter/Makefile
93862+++ b/net/netfilter/Makefile
93863@@ -112,6 +112,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
93864 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
93865 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
93866 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
93867+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
93868 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
93869 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
93870 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
93871diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
93872index f771390..145b765 100644
93873--- a/net/netfilter/ipset/ip_set_core.c
93874+++ b/net/netfilter/ipset/ip_set_core.c
93875@@ -1820,7 +1820,7 @@ done:
93876 return ret;
93877 }
93878
93879-static struct nf_sockopt_ops so_set __read_mostly = {
93880+static struct nf_sockopt_ops so_set = {
93881 .pf = PF_INET,
93882 .get_optmin = SO_IP_SET,
93883 .get_optmax = SO_IP_SET + 1,
93884diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
93885index 4c8e5c0..5a79b4d 100644
93886--- a/net/netfilter/ipvs/ip_vs_conn.c
93887+++ b/net/netfilter/ipvs/ip_vs_conn.c
93888@@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
93889 /* Increase the refcnt counter of the dest */
93890 ip_vs_dest_hold(dest);
93891
93892- conn_flags = atomic_read(&dest->conn_flags);
93893+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
93894 if (cp->protocol != IPPROTO_UDP)
93895 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
93896 flags = cp->flags;
93897@@ -900,7 +900,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
93898
93899 cp->control = NULL;
93900 atomic_set(&cp->n_control, 0);
93901- atomic_set(&cp->in_pkts, 0);
93902+ atomic_set_unchecked(&cp->in_pkts, 0);
93903
93904 cp->packet_xmit = NULL;
93905 cp->app = NULL;
93906@@ -1188,7 +1188,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
93907
93908 /* Don't drop the entry if its number of incoming packets is not
93909 located in [0, 8] */
93910- i = atomic_read(&cp->in_pkts);
93911+ i = atomic_read_unchecked(&cp->in_pkts);
93912 if (i > 8 || i < 0) return 0;
93913
93914 if (!todrop_rate[i]) return 0;
93915diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
93916index 4f69e83..da2d8bf 100644
93917--- a/net/netfilter/ipvs/ip_vs_core.c
93918+++ b/net/netfilter/ipvs/ip_vs_core.c
93919@@ -559,7 +559,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
93920 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
93921 /* do not touch skb anymore */
93922
93923- atomic_inc(&cp->in_pkts);
93924+ atomic_inc_unchecked(&cp->in_pkts);
93925 ip_vs_conn_put(cp);
93926 return ret;
93927 }
93928@@ -1711,7 +1711,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
93929 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
93930 pkts = sysctl_sync_threshold(ipvs);
93931 else
93932- pkts = atomic_add_return(1, &cp->in_pkts);
93933+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
93934
93935 if (ipvs->sync_state & IP_VS_STATE_MASTER)
93936 ip_vs_sync_conn(net, cp, pkts);
93937diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
93938index c8148e4..eff604f 100644
93939--- a/net/netfilter/ipvs/ip_vs_ctl.c
93940+++ b/net/netfilter/ipvs/ip_vs_ctl.c
93941@@ -789,7 +789,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
93942 */
93943 ip_vs_rs_hash(ipvs, dest);
93944 }
93945- atomic_set(&dest->conn_flags, conn_flags);
93946+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
93947
93948 /* bind the service */
93949 if (!dest->svc) {
93950@@ -1657,7 +1657,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
93951 * align with netns init in ip_vs_control_net_init()
93952 */
93953
93954-static struct ctl_table vs_vars[] = {
93955+static ctl_table_no_const vs_vars[] __read_only = {
93956 {
93957 .procname = "amemthresh",
93958 .maxlen = sizeof(int),
93959@@ -2078,7 +2078,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
93960 " %-7s %-6d %-10d %-10d\n",
93961 &dest->addr.in6,
93962 ntohs(dest->port),
93963- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
93964+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
93965 atomic_read(&dest->weight),
93966 atomic_read(&dest->activeconns),
93967 atomic_read(&dest->inactconns));
93968@@ -2089,7 +2089,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
93969 "%-7s %-6d %-10d %-10d\n",
93970 ntohl(dest->addr.ip),
93971 ntohs(dest->port),
93972- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
93973+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
93974 atomic_read(&dest->weight),
93975 atomic_read(&dest->activeconns),
93976 atomic_read(&dest->inactconns));
93977@@ -2567,7 +2567,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
93978
93979 entry.addr = dest->addr.ip;
93980 entry.port = dest->port;
93981- entry.conn_flags = atomic_read(&dest->conn_flags);
93982+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
93983 entry.weight = atomic_read(&dest->weight);
93984 entry.u_threshold = dest->u_threshold;
93985 entry.l_threshold = dest->l_threshold;
93986@@ -3110,7 +3110,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
93987 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
93988 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
93989 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
93990- (atomic_read(&dest->conn_flags) &
93991+ (atomic_read_unchecked(&dest->conn_flags) &
93992 IP_VS_CONN_F_FWD_MASK)) ||
93993 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
93994 atomic_read(&dest->weight)) ||
93995@@ -3700,7 +3700,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
93996 {
93997 int idx;
93998 struct netns_ipvs *ipvs = net_ipvs(net);
93999- struct ctl_table *tbl;
94000+ ctl_table_no_const *tbl;
94001
94002 atomic_set(&ipvs->dropentry, 0);
94003 spin_lock_init(&ipvs->dropentry_lock);
94004diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
94005index 1383b0e..a486da1 100644
94006--- a/net/netfilter/ipvs/ip_vs_lblc.c
94007+++ b/net/netfilter/ipvs/ip_vs_lblc.c
94008@@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
94009 * IPVS LBLC sysctl table
94010 */
94011 #ifdef CONFIG_SYSCTL
94012-static struct ctl_table vs_vars_table[] = {
94013+static ctl_table_no_const vs_vars_table[] __read_only = {
94014 {
94015 .procname = "lblc_expiration",
94016 .data = NULL,
94017diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
94018index 3cd85b2..dfab2b8 100644
94019--- a/net/netfilter/ipvs/ip_vs_lblcr.c
94020+++ b/net/netfilter/ipvs/ip_vs_lblcr.c
94021@@ -299,7 +299,7 @@ struct ip_vs_lblcr_table {
94022 * IPVS LBLCR sysctl table
94023 */
94024
94025-static struct ctl_table vs_vars_table[] = {
94026+static ctl_table_no_const vs_vars_table[] __read_only = {
94027 {
94028 .procname = "lblcr_expiration",
94029 .data = NULL,
94030diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
94031index f448471..995f131 100644
94032--- a/net/netfilter/ipvs/ip_vs_sync.c
94033+++ b/net/netfilter/ipvs/ip_vs_sync.c
94034@@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
94035 cp = cp->control;
94036 if (cp) {
94037 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
94038- pkts = atomic_add_return(1, &cp->in_pkts);
94039+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
94040 else
94041 pkts = sysctl_sync_threshold(ipvs);
94042 ip_vs_sync_conn(net, cp->control, pkts);
94043@@ -771,7 +771,7 @@ control:
94044 if (!cp)
94045 return;
94046 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
94047- pkts = atomic_add_return(1, &cp->in_pkts);
94048+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
94049 else
94050 pkts = sysctl_sync_threshold(ipvs);
94051 goto sloop;
94052@@ -895,7 +895,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
94053
94054 if (opt)
94055 memcpy(&cp->in_seq, opt, sizeof(*opt));
94056- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
94057+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
94058 cp->state = state;
94059 cp->old_state = cp->state;
94060 /*
94061diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
94062index b75ff64..0c51bbe 100644
94063--- a/net/netfilter/ipvs/ip_vs_xmit.c
94064+++ b/net/netfilter/ipvs/ip_vs_xmit.c
94065@@ -1102,7 +1102,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
94066 else
94067 rc = NF_ACCEPT;
94068 /* do not touch skb anymore */
94069- atomic_inc(&cp->in_pkts);
94070+ atomic_inc_unchecked(&cp->in_pkts);
94071 goto out;
94072 }
94073
94074@@ -1194,7 +1194,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
94075 else
94076 rc = NF_ACCEPT;
94077 /* do not touch skb anymore */
94078- atomic_inc(&cp->in_pkts);
94079+ atomic_inc_unchecked(&cp->in_pkts);
94080 goto out;
94081 }
94082
94083diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
94084index 2d3030a..7ba1c0a 100644
94085--- a/net/netfilter/nf_conntrack_acct.c
94086+++ b/net/netfilter/nf_conntrack_acct.c
94087@@ -60,7 +60,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
94088 #ifdef CONFIG_SYSCTL
94089 static int nf_conntrack_acct_init_sysctl(struct net *net)
94090 {
94091- struct ctl_table *table;
94092+ ctl_table_no_const *table;
94093
94094 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
94095 GFP_KERNEL);
94096diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
94097index 0283bae..5febcb0 100644
94098--- a/net/netfilter/nf_conntrack_core.c
94099+++ b/net/netfilter/nf_conntrack_core.c
94100@@ -1614,6 +1614,10 @@ void nf_conntrack_init_end(void)
94101 #define DYING_NULLS_VAL ((1<<30)+1)
94102 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
94103
94104+#ifdef CONFIG_GRKERNSEC_HIDESYM
94105+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
94106+#endif
94107+
94108 int nf_conntrack_init_net(struct net *net)
94109 {
94110 int ret;
94111@@ -1628,7 +1632,11 @@ int nf_conntrack_init_net(struct net *net)
94112 goto err_stat;
94113 }
94114
94115+#ifdef CONFIG_GRKERNSEC_HIDESYM
94116+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
94117+#else
94118 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
94119+#endif
94120 if (!net->ct.slabname) {
94121 ret = -ENOMEM;
94122 goto err_slabname;
94123diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
94124index 1df1761..ce8b88a 100644
94125--- a/net/netfilter/nf_conntrack_ecache.c
94126+++ b/net/netfilter/nf_conntrack_ecache.c
94127@@ -188,7 +188,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
94128 #ifdef CONFIG_SYSCTL
94129 static int nf_conntrack_event_init_sysctl(struct net *net)
94130 {
94131- struct ctl_table *table;
94132+ ctl_table_no_const *table;
94133
94134 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
94135 GFP_KERNEL);
94136diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
94137index 974a2a4..52cc6ff 100644
94138--- a/net/netfilter/nf_conntrack_helper.c
94139+++ b/net/netfilter/nf_conntrack_helper.c
94140@@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
94141
94142 static int nf_conntrack_helper_init_sysctl(struct net *net)
94143 {
94144- struct ctl_table *table;
94145+ ctl_table_no_const *table;
94146
94147 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
94148 GFP_KERNEL);
94149diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
94150index 0ab9636..cea3c6a 100644
94151--- a/net/netfilter/nf_conntrack_proto.c
94152+++ b/net/netfilter/nf_conntrack_proto.c
94153@@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
94154
94155 static void
94156 nf_ct_unregister_sysctl(struct ctl_table_header **header,
94157- struct ctl_table **table,
94158+ ctl_table_no_const **table,
94159 unsigned int users)
94160 {
94161 if (users > 0)
94162diff --git a/net/netfilter/nf_conntrack_proto_dccp.c b/net/netfilter/nf_conntrack_proto_dccp.c
94163index a99b6c3..cb372f9 100644
94164--- a/net/netfilter/nf_conntrack_proto_dccp.c
94165+++ b/net/netfilter/nf_conntrack_proto_dccp.c
94166@@ -428,7 +428,7 @@ static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
94167 const char *msg;
94168 u_int8_t state;
94169
94170- dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
94171+ dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
94172 BUG_ON(dh == NULL);
94173
94174 state = dccp_state_table[CT_DCCP_ROLE_CLIENT][dh->dccph_type][CT_DCCP_NONE];
94175@@ -457,7 +457,7 @@ static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
94176 out_invalid:
94177 if (LOG_INVALID(net, IPPROTO_DCCP))
94178 nf_log_packet(net, nf_ct_l3num(ct), 0, skb, NULL, NULL,
94179- NULL, msg);
94180+ NULL, "%s", msg);
94181 return false;
94182 }
94183
94184@@ -486,7 +486,7 @@ static int dccp_packet(struct nf_conn *ct, const struct sk_buff *skb,
94185 u_int8_t type, old_state, new_state;
94186 enum ct_dccp_roles role;
94187
94188- dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
94189+ dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
94190 BUG_ON(dh == NULL);
94191 type = dh->dccph_type;
94192
94193@@ -577,7 +577,7 @@ static int dccp_error(struct net *net, struct nf_conn *tmpl,
94194 unsigned int cscov;
94195 const char *msg;
94196
94197- dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
94198+ dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
94199 if (dh == NULL) {
94200 msg = "nf_ct_dccp: short packet ";
94201 goto out_invalid;
94202@@ -614,7 +614,7 @@ static int dccp_error(struct net *net, struct nf_conn *tmpl,
94203
94204 out_invalid:
94205 if (LOG_INVALID(net, IPPROTO_DCCP))
94206- nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, msg);
94207+ nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, "%s", msg);
94208 return -NF_ACCEPT;
94209 }
94210
94211diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
94212index f641751..d3c5b51 100644
94213--- a/net/netfilter/nf_conntrack_standalone.c
94214+++ b/net/netfilter/nf_conntrack_standalone.c
94215@@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
94216
94217 static int nf_conntrack_standalone_init_sysctl(struct net *net)
94218 {
94219- struct ctl_table *table;
94220+ ctl_table_no_const *table;
94221
94222 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
94223 GFP_KERNEL);
94224diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
94225index 902fb0a..87f7fdb 100644
94226--- a/net/netfilter/nf_conntrack_timestamp.c
94227+++ b/net/netfilter/nf_conntrack_timestamp.c
94228@@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
94229 #ifdef CONFIG_SYSCTL
94230 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
94231 {
94232- struct ctl_table *table;
94233+ ctl_table_no_const *table;
94234
94235 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
94236 GFP_KERNEL);
94237diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
94238index 85296d4..8becdec 100644
94239--- a/net/netfilter/nf_log.c
94240+++ b/net/netfilter/nf_log.c
94241@@ -243,7 +243,7 @@ static const struct file_operations nflog_file_ops = {
94242
94243 #ifdef CONFIG_SYSCTL
94244 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
94245-static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
94246+static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
94247
94248 static int nf_log_proc_dostring(struct ctl_table *table, int write,
94249 void __user *buffer, size_t *lenp, loff_t *ppos)
94250@@ -274,14 +274,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
94251 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
94252 mutex_unlock(&nf_log_mutex);
94253 } else {
94254+ ctl_table_no_const nf_log_table = *table;
94255+
94256 mutex_lock(&nf_log_mutex);
94257 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
94258 lockdep_is_held(&nf_log_mutex));
94259 if (!logger)
94260- table->data = "NONE";
94261+ nf_log_table.data = "NONE";
94262 else
94263- table->data = logger->name;
94264- r = proc_dostring(table, write, buffer, lenp, ppos);
94265+ nf_log_table.data = logger->name;
94266+ r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
94267 mutex_unlock(&nf_log_mutex);
94268 }
94269
94270diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
94271index f042ae5..30ea486 100644
94272--- a/net/netfilter/nf_sockopt.c
94273+++ b/net/netfilter/nf_sockopt.c
94274@@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
94275 }
94276 }
94277
94278- list_add(&reg->list, &nf_sockopts);
94279+ pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
94280 out:
94281 mutex_unlock(&nf_sockopt_mutex);
94282 return ret;
94283@@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
94284 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
94285 {
94286 mutex_lock(&nf_sockopt_mutex);
94287- list_del(&reg->list);
94288+ pax_list_del((struct list_head *)&reg->list);
94289 mutex_unlock(&nf_sockopt_mutex);
94290 }
94291 EXPORT_SYMBOL(nf_unregister_sockopt);
94292diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
94293index d92cc31..e46f350 100644
94294--- a/net/netfilter/nfnetlink_log.c
94295+++ b/net/netfilter/nfnetlink_log.c
94296@@ -82,7 +82,7 @@ static int nfnl_log_net_id __read_mostly;
94297 struct nfnl_log_net {
94298 spinlock_t instances_lock;
94299 struct hlist_head instance_table[INSTANCE_BUCKETS];
94300- atomic_t global_seq;
94301+ atomic_unchecked_t global_seq;
94302 };
94303
94304 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
94305@@ -563,7 +563,7 @@ __build_packet_message(struct nfnl_log_net *log,
94306 /* global sequence number */
94307 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
94308 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
94309- htonl(atomic_inc_return(&log->global_seq))))
94310+ htonl(atomic_inc_return_unchecked(&log->global_seq))))
94311 goto nla_put_failure;
94312
94313 if (data_len) {
94314diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
94315new file mode 100644
94316index 0000000..c566332
94317--- /dev/null
94318+++ b/net/netfilter/xt_gradm.c
94319@@ -0,0 +1,51 @@
94320+/*
94321+ * gradm match for netfilter
94322